Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone explain this function pointer syntax?

I have been given some vendor supplied driver code written in C that runs on DOS (yes DOS) to access hardware. I am trying to work out what this code does, so far without much success. In particular I am having problems understanding the following code

void (interrupt *oldcan)(void);

void  interrupt far  can_isr(void)
{
    /* function body */
}

I am guessing the first line defines a function pointer but I have never seen the interrupt word which I am assuming is some kind of DOS API function. I have never used DOS before, and the function definition above looks to me that it has 3 return types - void, interrupt and far which clearly is not possible. The function actually has void return type, but what is the meaning of interrupt far ?? Any assistance will be gratefully received.

like image 593
mathematician1975 Avatar asked Oct 26 '25 04:10

mathematician1975


1 Answers

The interrupt keyword is (was) used to create an interrupt handler -- i.e., this function was intended to be invoked by an interrupt. far means when it returns, it expects both CS and IP to be on the stack, and the interrupt keyword means it expects the flags register to have been pushed as well (all a given for anything that's invoked via interrupt, but it's also possible to simulate an interrupt by pushing the flags register, then doing a far jump).

The most common use was probably for code that was going to use a serial port -- the BIOS/DOS serial port handler would lose characters at higher speeds (anything above about 300 bps, originally) so you had to install a handler of your own. When a character showed up at the serial port, the serial port hardware would assert a line that interrupted the processor. Based on that, your interrupt handler routine would be invoked. Your code needed to read the data in from the serial port into memory (and do a few things like re-enabling the interrupt) and return.

like image 53
Jerry Coffin Avatar answered Oct 28 '25 19:10

Jerry Coffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!