LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Installing interrupt handler with sigaction. (http://www.linuxquestions.org/questions/programming-9/installing-interrupt-handler-with-sigaction-892106/)

stf92 07-16-2011 08:01 PM

Installing interrupt handler with sigaction.
 
kernel 2.6.21.5, slackware 12.0

Hi:
In a program I am writing, I want to install an interrupt handler for IRQ15, which is interrupt number 0x77 (IAx86). I suppose I can call sigaction(), whose first argument is signum:

int sigaction(int signum, ....)

My question is: do I call sigaction(0x77, ...)? It's been several days now that I have been searching with google but everywehre they seem to not want to speak about hardware interrupts. I also went through Linux Device Drivers, chapter 9, but couldn't answer my question in the affirmative or negative. I hope somebody in LQ knows about this. Thanks.

ta0kira 07-17-2011 02:32 PM

sigaction is for catching signals sent to a process. What you're looking for is having a signal sent to a process as a result of the interrupt. That's something entirely different, and I'm not exactly sure how that's done.
Kevin Barry

PS Some preliminary searching indicates that you must handle IRQs within kernel space, i.e. via a kernel module.

sundialsvcs 07-17-2011 09:37 PM

Hardware interrupts are handled only by the Linux kernel. What the kernel does in response to the interrupt could be, well, almost anything. It could, among other things, send a signal to a process.

Processes, though, respond to signals ... which, although they do "cause an asynchronous interruption of whatever the process in question had been doing," has nothing directly to do with hardware interrupts.

SigTerm 07-18-2011 12:20 AM

Quote:

Originally Posted by stf92 (Post 4416916)
kernel 2.6.21.5, slackware 12.0

Hi:
In a program I am writing, I want to install an interrupt handler for IRQ15, which is interrupt number 0x77 (IAx86). I suppose I can call sigaction(), whose first argument is signum:

int sigaction(int signum, ....)

My question is: do I call sigaction(0x77, ...)? It's been several days now that I have been searching with google but everywehre they seem to not want to speak about hardware interrupts. I also went through Linux Device Drivers, chapter 9, but couldn't answer my question in the affirmative or negative. I hope somebody in LQ knows about this. Thanks.

signals are not hardware interrupts. To handle interrupt, try writing kernel module (kernel source should have plenty of modules you can fork/tweak/modify or use as a base for your own module), or switch to MS-Dos/FreeDos (you could also try booting into some kind of custom kernel (written from scratch), but it isn't worth it). I'd recommend to search for solution that does not require dealing with interrupts.

stf92 07-19-2011 12:33 AM

Yes, I'll try to do it without interrupts. Thanks.

sundialsvcs 07-19-2011 08:16 AM

You never said what device is causing the interrupt, but device drivers often provide services (e.g. through the ioctl() call) such as arranging for a signal to be sent to your process when a particular status-change occurs. (Or a semaphore gets unlocked or what-have-you.)

Linux also offers asynchronous I/O, whereby you might start an I/O operation and then not wait for the operation to complete. (For example, a "read status" request of some kind might block until the status information is available, i.e. because of an interrupt, but you initiate the read asynchronously and therefore do not wait.

This mechanism handles many timing problems elegantly. You don't know exactly when an interrupt will come in, and maybe it has already come in at the precise nanosecond when your process makes its request. Well, the APIs will be designed to cover such timing-holes ... if properly used by you (heh...) o'course.

stf92 07-23-2011 08:25 AM

Thank you, sundialsvcs for your post. The interrupting device is an ATAPI optical drive. This program was originally written for a microcontroller directly driving the driive. It sends the drive a packet command and then it sits in a loop waiting for command completion. Within the loop, it interrogates the drive INTRQ line and exits the loop when the line is asserted, which happens upon completion.

I translated the program to make it run on an IBM PC under MS-DOS 5.00. Here, INTRQ is connected to the APIC (IRQ15). Hence, the new program installs an interrupt handler that sets a flag and transfers control to the original handler. Within the loop, I wait until the flag is set. Also, it makes no use of the device driver, but talks directly to the controller.

This program performs as expected (it plays an audio CD and has some non-standard features). Now, ten years later, I want to see if I can rewrite it to make it work in Linux. So, I shall reread the ATA-ATAPI standards and see if INTRQ can be dispensed with. In case it can, I'll see how to take advantage of the advices relative to ioctl's and asynchronous I/O. On the contrary case, I expect to spend a pleasant time reading Rubini's Linux Device Drivers.

Nominal Animal 07-23-2011 03:34 PM

So, what you are actually doing is communicating with the optical drive using raw ATA/ATAPI commands. You can simply open the device, and use ioctl()s on it, to achieve that. No need to delve into the kernel for this.

For the background, look at the Linux ATA wiki. Most of the ATA specifications are linked to on the Developer Resources page.

I recommend you look at the Documentation/cdrom/ide-cd file in the Linux kernel documentation. It contains example C source for cdchange.c, which does something pretty similar to what you wish to do.

All CD-ROM related ioctls available are listed in /usr/include/linux/cdrom.h. If you use nonstandard commands, I recommend you take a close look at the cdrom_generic_command (used via the CDROM_PACKET_COMMAND ioctl).

Hope this helps.

stf92 07-24-2011 10:34 AM

Thank you very much for the many references included in your post. They have been a great help. Best wishes.


All times are GMT -5. The time now is 08:33 AM.