From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,641105de50ec2788 X-Google-Attributes: gid103376,public From: Andi Kleen Subject: Re: 2nd help about handling HW interrupt and apologizes. Date: 1998/04/10 Message-ID: #1/1 X-Deja-AN: 342708035 Distribution: world Sender: andi@fred.muc.de References: <6gft3m$rib$1@nnrp1.dejanews.com> <352BB2AE.1DC7325E@cl.cam.ac.uk> Organization: [posted via] Leibniz-Rechenzentrum, Muenchen (Germany) Newsgroups: comp.lang.ada Date: 1998-04-10T00:00:00+00:00 List-Id: Markus Kuhn writes: > jtapasai@bipa162.bi.ehu.es wrote: > > Secondly, I would like to thank you for your help. > > My problem is that I must program an interrupt service routine that is > > executed when the predeterminated IRQ is rised, because the data adquisition > > card has finished the A/Dconversion. > > > > I have read all the responses, but there is already two doubts in my mind : > > - Does Linux allow to define a hardware interrupt service routine ? > > Yes, but only inside the kernel. > > > - Does GNAT for Linux support this feature ? > > Yes, because GNAT allows you to call all the C kernel functions > that you need to call to get this done and because the Linux > kernel is also compiled by gcc and therefore GNAT output can > easily be linked into the kernel. > > My previous reply still applies: > > Only code in the kernel, not normal user processes can handle > interrupt, this is completely independent of the programming > language. > > In the kernel, you have to call request_irq() in order to register > your interrupt handler. For instance, the keyboard driver > in /usr/src/linux/drivers/char/keyboard.c contains the line > > request_irq(KEYBOARD_IRQ, keyboard_interrupt, 0, "keyboard", NULL); > > to register its interrupt handler routine. You can call this > C routine also from Ada using pragma Import. The important thing > is that your Ada program has either to be compiled into the kernel > or you have to load your program as a loadable kernel module > using the system calls described on "man 2 modules". I would be careful with Ada programs in kernel space. GNAT has a rather complex runtime library that is required to work, and this library might not work completely in kernel space. For example there are several caveats: - Memory allocation works differently than in user space. - The kernel stack is limited to 4K (and it is only safe to use 2-3K to keep enough space for interrupt handlers) - There is no libc in kernel space, so the runtime library might need stubs. - Ada tasking and protected types probably won't work [unless it is especially ported] I'm not saying that it is impossible to write ada kernel drivers, just that it might require more work than one would naively think at first. Of course once the runtime library is ported it'll be easier. To just get the job done it is probably easier to just write a small stub kernel driver in C that communicates with the Ada program running in userspace over a device or a netlink socket. -Andi