Replacing INT9 in C

Martin O'Nions martino at logitek.co.uk
Thu Jan 17 01:05:32 AEST 1991


ACPS2924 at Ryerson.Ca writes:

...

>So far I replace the INT9 with the following, in the new interrupt I call
>the old interrupt 9 to do good housekeeping and then call INT16 to get
>the key from the queue.  Low and behold big crash, why I dont know???
>All this is being written in Turbo C++.  Any help would be most helpfull.
>Anything Hints Suggestions Code fragments , even dread, assembler hints
>would help.

Not guarenteed, but stack problems are the most likely. Getting an asynchronous interrupt to call C is a problem, as your C code will use the stack present
when the H/W int was generated, rather than the one the compiler intended.
Couple this with the fact that all interrupts will do a far call, so small
model C wil look at the wrong place on the stack for the return address, and
the fact that your code almost certainly doesn't push all the registers it uses
and you end up with a real problem.....

I normally write an assembler 'wrapper' when I need to do this sort of thing.
You need to do:

	1. Restore Interrupts (unless you want to risk your clock ticks...)
	2. Store the stack segment and pointer SS/SP in local space
	3. Load SS and SP from local space (point them to an area reserved
	   by your code for the stack)
	4. Push everything your C uses! (compile to assembler first, then
	   check)
	5. Call your C code, using an appropriate model call (near or far)
	6. On return from the C, pop the saved registers
	7. Swap SS and SP back again
	8. Do an IRET to go back to the foreground process.

The above uses the phrase C code to refer to object code compiled from C - no
flames by request.

If you want any more detail, or just disagree, please feel free to mail me
( posting is not a guarenteed way to reach me - I woory about my News feed at
times!)

Have fun!

Martin

--
DISCLAIMER: All My Own Work (Unless stated otherwise)
--------------------------------------------------------------------------
Martin O'Nions            Logitek Group Support      martino at logitek.co.uk
--------------------------------------------------------------------------
There's been an accident they said/Your servant's cut in half - he's dead!
Indeed said Mr Jones, then please/Send me the half that's got my keys.
         (Harry Graham - Ruthless Rhymes for Heartless Homes)



More information about the Comp.lang.c mailing list