[comp.lang.c] microsoft c/ interrupt handler prob

lizac@maccs.dcss.mcmaster.ca (herman) (02/20/91)

Is there any reliable way to use a function written in microsoft c version 6.0
as an interrupt handler?  I tried the following...

void serial_handler(void)

{
     asm {pusha}
     t_serial_handler();  /* this function is void t_serial_handler(void) */ 
     asm {
       popa
       pop si    /* this line and the next are from memory ,but i am */ 
       pop di  /* sure that they are in the correct order in my prog */ 
       leave 
       iret }
}
(and then put the segment and offset of the serial_handler routine at 
interrupt 0ch vector location).
it sort of works.  I get characters from my t_serial_handler routine, but
intermittently, and after about 8 to 16, the computer either 1) locks up
2) returns to DOS, after which any DOS command locks up the computer.
My t_serial_handler routine is very simple.  I think the problem is 
the way that i link the interrupt vector to it.

Is there an easy way to point to an interrupt handler written in c 6.0?
Have I erred in my definition of serial_handler?

If you have any insight about this problem, could you please email me
and let me know what i've done wrong?

thanks.

   
-- 
herman     love your nails         lizac@maccs.dcss.mcmaster.ca or something

brianh@hpcvia.CV.HP.COM (brian_helterline) (02/26/91)

lizac@maccs.dcss.mcmaster.ca (herman) writes:
>Is there any reliable way to use a function written in microsoft c version 6.0
>as an interrupt handler?  I tried the following...
>
>void serial_handler(void)

if this function is an interrupt handler, you have to declare it using
the _interrupt type modifier (e.g. _interrupt void serial_handler(void))

>
>{
>     asm {pusha}
>     t_serial_handler();  /* this function is void t_serial_handler(void) */ 
>     asm {
>       popa
>       pop si    /* this line and the next are from memory ,but i am */ 
>       pop di  /* sure that they are in the correct order in my prog */ 
>       leave 
>       iret }
>}
>(and then put the segment and offset of the serial_handler routine at 
>interrupt 0ch vector location).
>it sort of works.  I get characters from my t_serial_handler routine, but
>intermittently, and after about 8 to 16, the computer either 1) locks up
>2) returns to DOS, after which any DOS command locks up the computer.
>My t_serial_handler routine is very simple.  I think the problem is 
>the way that i link the interrupt vector to it.

In general, you aren't free to do anything you like inside an interrupt
handler.  Only certain things can be done, especially anything that involves
calls to DOS (e.g. printf())

>Is there an easy way to point to an interrupt handler written in c 6.0?
>Have I erred in my definition of serial_handler?

The easiest way is to use _dos_getvect() & _dos_setvect().

>If you have any insight about this problem, could you please email me
>and let me know what i've done wrong?

>thanks.

   
>-- 
>herman     love your nails         lizac@maccs.dcss.mcmaster.ca or something
>----------