ARM System Calls: Difference between revisions

Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
No edit summary
Line 38: Line 38:
void __attribute__ ((interrupt ("SWI"))) swi_handler (int r0, int r1, int r2, int r3) {}
void __attribute__ ((interrupt ("SWI"))) swi_handler (int r0, int r1, int r2, int r3) {}
</source>
</source>
You have probably noticed from the first example (<span style="font-family:monospace">swi 0x420000</span>), that swi takes an integer as an argument. For it to work in both ARM and THUMB modes of the processor, the integer must be left shifted by 16. To get this integer in the C code, do this:
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:
<source lang="c">
<source lang="c">
uint8_t int_vector = 0;
uint8_t int_vector = 0;
asm volatile ("ldrb %0, [lr, #-2]" : "=r" (int_vector));
asm volatile ("ldrb %0, [lr, #-2]" : "=r" (int_vector));
</source>
</source>
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.
[[Category:ARM]]
[[Category:ARM]]
[[Category:In Progress]]
[[Category:In Progress]]