972
edits
[unchecked revision] | [unchecked revision] |
No edit summary |
m (Bot: Replace deprecated source tag with syntaxhighlight) |
||
Line 6:
<pre>mov pc, lr</pre>
Most of the time you won't need to worry about returning from the interrupt, as GCC, set up to cross compile for ARM, lets you code the interrupt handlers in C:
<
==Creating System Calls==
Line 31:
</pre>
We can code the interrupt handler like this:
<
void __attribute__ ((interrupt ("SWI"))) swi_handler (void) {}
</syntaxhighlight>
Parameters to functions on ARM, are passed in registers r0-r3, if follow the same convention for system calls, then our interrupt handler can take parameters:
<
void __attribute__ ((interrupt ("SWI"))) swi_handler (int r0, int r1, int r2, int r3) {}
</syntaxhighlight>
You've probably noticed that <span style="font-family:monospace">swi</span> takes an integer argument. To get this argument in C, we have to do this:
<
uint8_t int_vector = 0;
asm volatile ("ldrb %0, [lr, #-2]" : "=r" (int_vector));
</syntaxhighlight>
This loads the high 8 bits (16-23) of the argument into <span style="font-family:monospace">int_vector</span>, as loading the full 24-bits won't work using Thumb.
|