Hi Alex,> Assuming that that support for Ada in LLVM is complete, I would look to > see if there is something that is done there. Ada provides two pragmas > (Interrupt_Handler & Attach_Handler) which allow you to both statically > and dynamically attach interrupts to procedures.the interrupt handler itself is a parameterless procedure that does not return a value. As such, I guess calling conventions and so forth are not very relevant for it :) In any case llvm-gcc and gcc mainline seem to output the interrupt handler as an ordinary function on x86-32-linux. Ciao, Duncan.
Jakob Stoklund Olesen
2009-Jul-24 15:47 UTC
[LLVMdev] LLVM and Interrupt Service Routines.
Duncan Sands <baldrick at free.fr> writes:> the interrupt handler itself is a parameterless procedure that does not > return a value. As such, I guess calling conventions and so forth are > not very relevant for it :) In any case llvm-gcc and gcc mainline seem > to output the interrupt handler as an ordinary function on > x86-32-linux.There can be significant differences between an interrupt handler and a void f(void) function. An interrupt handler may have to: - Save /all/ registers, including those that are normally caller saved. - Use a special return instruction (RETI). - Step over the "red zone" on the stack. - Set up a safe stack frame before calling normal functions. I usually write the first level interrupt handler in assembler, and then call normal C function from there.
On Jul 24, 2009, at 8:47 AM, Jakob Stoklund Olesen wrote:> Duncan Sands <baldrick at free.fr> writes: > >> the interrupt handler itself is a parameterless procedure that does >> not >> return a value. As such, I guess calling conventions and so forth >> are >> not very relevant for it :) In any case llvm-gcc and gcc mainline >> seem >> to output the interrupt handler as an ordinary function on >> x86-32-linux. > > There can be significant differences between an interrupt handler > and a > void f(void) function. An interrupt handler may have to: > > - Save /all/ registers, including those that are normally caller > saved. > - Use a special return instruction (RETI). > - Step over the "red zone" on the stack. > - Set up a safe stack frame before calling normal functions. > > I usually write the first level interrupt handler in assembler, and > then > call normal C function from there.Wouldn't a custom calling convention work for all of these requirements? -Chris
Hi Jakub,> There can be significant differences between an interrupt handler and a > void f(void) function. An interrupt handler may have to: > > - Save /all/ registers, including those that are normally caller saved. > - Use a special return instruction (RETI). > - Step over the "red zone" on the stack. > - Set up a safe stack frame before calling normal functions. > > I usually write the first level interrupt handler in assembler, and then > call normal C function from there.an Ada interrupt handler is registered using an Ada library routine. The library might in fact route the interrupt to some assembler code like you describe, which itself would then call the registered handler. I don't know the details of how it is all made to work. Ciao, Duncan.