LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Interrupt handling in gcc? (https://www.linuxquestions.org/questions/programming-9/interrupt-handling-in-gcc-72839/)

captainstorm 07-15-2003 03:15 AM

Interrupt handling in gcc?
 
Good morning everyone.
From what I know, gcc does not support the keyword like "interrupt" or "_interrupt". The only way to handle the interrupt is to write a small assembler to "call" the interrupt routin. But how to integrate this small piece of assembler into the final file? (to generate executable file) Thank you very much

kev82 07-15-2003 04:41 AM

im not quite sure what you want to do?

do you want to write an interupt handler then have the kernel call it when necessery in this case just write your handler then call request_irq

or do you want to generate an interupt, dont know why youd want to do this because no bios interupts are accessable and all the syscalls have wrappers but you would just do some inline assembly or write an assembly file and link it to your executable. theres lots of info about this if you look up operating system development.

captainstorm 07-15-2003 07:38 AM

Sorry for the obscure words. I have written a small program to test the serial port under windows some time before. Now I want to migrate it to Linux. From my understanding, there are two ways to do it: 1. to use the POSIX programming interface. 2. to directly access to the register and handle the interrupt.

I have read the relevant document about serial port programming by POSIX. While there is no informaition there about using interrupt to handle the "read" problem. (otherwise you have to use polling to system delay, which I am using in POSIX). So I am thinking of control directly the serial port register under Linux as well as the interrupt. But soon I realized that gcc does not have the structure to handle interrupt. The only way is to write a small piece of assembler and call the interrupt routin from it.
My problem is I don't know whether I need to write the interrupt vector for serial port interrupt, and I have no idea how to integrate the assembler to C.
Do you any ideas or suggestions? I'll appreciate any of them:)
Thank you very much

TheLinuxDuck 07-15-2003 08:01 AM

Could you not simply open the serial port device and deal with it that way, instead of using interrupts? I mean, that's what the devices are for. (=

captainstorm 07-15-2003 08:20 AM

Yeah. Actually, POSIX provides a reletive ready-to-use interface on the serial port(some knows POSIX on parallel?). It is user-frendly. I have built a small testing program around this and it works. However, as I posted earlier, there is no interrupt handling for the "reading" from the port, which usually is time-critical. It indeed utilizes a function "select", but you have to block the whole program before reading a byte, though there is timeout.
Under turbo C you could just "bind" the interrupt routin vector to the interrupt, using "interrupt" keyword, which is easiler. But gcc does not have this structure. That's what I am looking for.
Thank you.

mad_ady 07-15-2003 09:10 AM

IMHO, this is how you get asm code in C (if this is what you need):
Code:

void myFunction()
{
printf("Before asm\n");
asm{
xor ax, ax
}
printf("After asm");
}

However, I'm not sure it works! (never tried it!)
Question: Where can I find a list of the interrupts linux generates/uses? (something like a list of dos interrupts).
Thanks

captainstorm 07-15-2003 10:06 AM

I can't remember clearly but I think it is in /proc/interrupts (or interrupt). I think you might want to have a try.

I'll try your method and post the result here.

captainstorm 07-15-2003 10:16 AM

Oh, in that way, I'll have to build the interrupt vector myself. I did that 3 years ago. (and I remember that was a project using 8259) ooooooo

kev82 07-15-2003 11:20 AM

Quote:

2. to directly access to the register and handle the interrupt
in the days of turbo C the operating system was dos which in fact is nothing more than a set of api calls, when you ran a program in dos control of the computer(and all hardware) was transferred to that program. this is NOT the case in linux. programs do not have direct access to hardware and must go through the kernel syscalls. i dont know if any of the ioctls provided by the serial driver are adequate for your need but if not you will have to write your own serial port driver(this is what i think you are referring to with interrupt vector) and then call free_irq/request_irq to bind your driver to to the serial port but this can only be done in kernel mode and will have to be implemented as a kernel module.

TheLinuxDuck 07-15-2003 11:50 AM

captain:

I'm also remembering some dealings I had with select some time ago, and IIR, select also could be given a zero length, and it would return immediately if the item/device status has not changed. yep.. according to the man page:
Code:

timeout  is  an  upper bound on the amount of time elapsed
 before select returns. It may be zero, causing  select  to
 return  immediately.

Instead of having select wait, your code could simply poll the serial port every second or two looking for data.

That is assuming your program will run somewhat like a daemon.

captainstorm 07-16-2003 02:43 AM

Quote:

Originally posted by TheLinuxDuck
That is assuming your program will run somewhat like a daemon. [/B]
Really. Even using read(2) could result a immediate return, if you set the open(2) parameters to "NDELAY". And indeed I am using this method, but not polling. I simply send a byte to the Zilog microcontroller via RS232 and it will return a string. So usleep(4000) and then read(2) will get everything.
Anyhow this is a rather simple protocol to implement. But I have done something under windows, using the "interrupt" keyword and I am wondering whether gcc is also capable of it.

captainstorm 07-16-2003 02:45 AM

And also thank you kev82 I also realized a way to do this is to write the program in Kernel mode, for which I need to read something. Would you recommend some materials on the internet, including the "free_irq/request_irq" information? Many thanks.

kev82 07-16-2003 05:16 AM

Quote:

But I have done something under windows, using the "interrupt" keyword and I am wondering whether gcc is also capable of it.
as i explained in my earlier post you can ONLY handle irq requests in kernel mode not a normal program. so its got nothing to with whether gcc or any other compiler supports it the fact is the kernel will not allow you to handle an irq in userspace.

for free_irq request_irq i suggest the man pages from section 9, for module programming the module programmers guide is somewhere in www.tldp.org and i guess you know enough about the serial port already but heres a good link for serial/parallel port programming. http://www.nondot.org/sabre/os/artic...cationDevices/
you could also have a look at the current serial driver in the kernel. i however recommend a userspace solution if its possible.

captainstorm 07-16-2003 05:57 AM

Thanks again Dev82:D


All times are GMT -5. The time now is 12:43 PM.