Hi all,
I know I could implement SWI handling in assembly but since gcc support using
__attribute__ I thought I could use it to implement it completely in C. The
problem is, I could not return any value. Whatever the the value on the first
argument (r0) would be restored upon return cancelling the return value
set in the handler. For example if I have a C code like this:
int *out = (int *) 0x08000000;
int __attribute__((interrupt("SWI"))) handle_swi(int reason, void *args) {
int i, n, *a;
char *s;
if (reason != 5) return -1;
a = (int*) args;
s = (char *) a[1];
n = a[2];
for (i=0; i<n; ++i) *out = s[i];
return 0;
}
I would get assembly code that looks like below. Notice r0 is restored
upon return (address 8218). Is there any way to tell the compiler
to not save/restore r0? Thanks.
00008208 <handle_swi>:
8208: cmp r0, #5 ; 0x5
820c: stmdb sp!, {r0, r1, r2, r3, ip}
8210: mvnne r0, #0 ; 0x0
8214: beq 8220 <handle_swi+0x18>
8218: ldmia sp!, {r0, r1, r2, r3, ip}
821c: movs pc, lr
8220: ldr ip, [r1, #8]
8224: cmp ip, #0 ; 0x0
8228: ldr r1, [r1, #4]
822c: ble 8250 <handle_swi+0x48>
8230: ldr r3, [pc, #32] ; 8258 <.text+0x238>
8234: ldr r0, [r3]
8238: mov r2, #0 ; 0x0
823c: ldrb r3, [r1, r2]
8240: add r2, r2, #1 ; 0x1
8244: cmp ip, r2
8248: str r3, [r0]
824c: bne 823c <handle_swi+0x34>
8250: mov r0, #0 ; 0x0
8254: b 8218 <handle_swi+0x10>
--
Mohamad Yusri