LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 07-16-2011, 08:01 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Rep: Reputation: 46
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.
 
Old 07-17-2011, 02:32 PM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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.

Last edited by ta0kira; 07-17-2011 at 02:39 PM.
 
Old 07-17-2011, 09:37 PM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,354

Rep: Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105
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.
 
Old 07-18-2011, 12:20 AM   #4
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 233Reputation: 233Reputation: 233
Quote:
Originally Posted by stf92 View Post
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.
 
Old 07-19-2011, 12:33 AM   #5
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
Yes, I'll try to do it without interrupts. Thanks.
 
Old 07-19-2011, 08:16 AM   #6
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,354

Rep: Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105Reputation: 1105
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.
 
Old 07-23-2011, 08:25 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
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.
 
Old 07-23-2011, 03:34 PM   #8
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
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.
 
Old 07-24-2011, 10:34 AM   #9
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,125

Original Poster
Rep: Reputation: 46
Thank you very much for the many references included in your post. They have been a great help. Best wishes.

Last edited by stf92; 07-24-2011 at 10:38 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kernel panic: killing interrupt handler! In interrupt handler - not syncing. divyashree Programming 26 05-15-2010 01:27 PM
Signal() sigaction() and IO interrupt Linuxprocess Programming 2 09-20-2006 09:38 AM
send arguments to a sigaction handler erwinfletch Programming 1 05-01-2006 07:19 PM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM


All times are GMT -5. The time now is 07:36 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration