🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #5412

Re: using int's in C

#5412
From: Adam Goldberg
Date: Sun, 24 Mar 1991 17:43
57 lines
3199 bytes
In article <1991Mar23.021231.21131@grebyn.com>,
 jmbj@grebyn.com (Jim Bittman) writes:
>I learned something quite interesting from Microsoft Tech Support today.
>It turns out that "outport(PORTID,PORTVALUE)" is not a "nice" function.
>They said it must access the BIOS or DOS or something which makes it
>non re-entrant (i.e. unavailable for interrupt routines).
>Excuse me?  Shouldn't this just translate to:
>  mov dx,PORTID
>  mov ax,PORTVALUE
>  out dx,ax

Yeah for Microsoft.  TurboC's outportb() function turns out to actually be
a macro (well, if you #undef it, it's a function), that does compile to
exactly the above code.

>
>Not to mention the fact that for a hardware interrupt, an outport(20,20)
>needs to be executed to "EOI" the 8259.  Anyway, this was their excuse
>for the fact that hardware ints don't seem to work properly.  I'm sorry
>that I haven't verified this yet, but I do know that a very simple
>program works just fine with Borland, but dies miserably with Microsoft.
>
>I hope this saves someone else the many, many, many, frustrating hours
>I have spent dealing with this problem.
>
>Jim Bittman, jmbj@grebyn.com

I'm not sure how you can do this (or if) with Microsoft C, but with TurboC,
you can use the command-line version of the compiler and do:

   tcc -S mysource.c

and it will create MYSOURCE.ASM, an MASM-compatible assembly listing of your
code with original source line numbers included as comments (I sure would like
the actual C source as comments, but you take what you can get).  Looking
at this code, a function of type INTERRUPT does something like this:

      1 - save all registers
      2 - change to a local stack
      3 - your code goes here (careful you don't use long-running DOS/BIOS
          calls--also realize that your interrupt routine MAY GET CONTROL
          DURING a DOS/BIOS routine, therefore you may be violating the
          non-reentrancy of DOS/BIOS)
      4 - change back to previous stack
      5 - pop all registers
      6 - IRET

Maybe Microsoft C will let you look at the code it compiles for you, and maybe
this will give you some light as to what the H*ll it's doing.


+----------------------------------------------------------------------------+
+ Adam Goldberg                         Bitnet:   tabu6@ISUVAX.BITNET        +
+ Iowa State University                 Internet: tabu6@CCVAX.IASTATE.EDU    +
+ H: (515) 233-5135
+          "It's simple!  Even a Pascal programmer could do it!"             +
+----------------------------------------------------------------------------+
Technical Details
Message-ID: <1991Mar24.174325.23812@news.iastate.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ceres.physics.uiowa.edu!news.iastate.edu!VAXF.IASTATE.EDU!TABU6
References: <hart.669469853@blackjack>,<1991Mar23.021231.21131@grebyn.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ceres.physics.uiowa.edu!news.iastate.edu!VAXF.IASTATE.EDU!TABU6
Newsgroups: comp.os.msdos.programmer
Subject: Re: using int's in C
Message-ID: <1991Mar24.174325.23812@news.iastate.edu>
From: tabu6@CCVAX.IASTATE.EDU (Adam Goldberg)
Date: Sun, 24 Mar 1991 17:43:25 GMT
Reply-To: tabu6@CCVAX.IASTATE.EDU
Sender: news@news.iastate.edu (USENET News System)
References: <hart.669469853@blackjack>,<1991Mar23.021231.21131@grebyn.com>
Organization: Iowa State University, Ames, IA.
Lines: 57