Search the web
Sign In
New User? Sign Up
gnuarm
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.

Messages

  Messages Help
Advanced
SWI handling using __attribute__ and return value   Message List  
Reply Message #2333 of 4948 |
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



Mon Jul 3, 2006 1:48 pm

mohamadyusri...
Offline Offline
Send Email Send Email

Message #2333 of 4948 |
Expand Messages Author Sort by Date

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....
Mohamad Yusri Mohamad...
mohamadyusri...
Offline Send Email
Jul 3, 2006
1:56 pm

... what makes you think GCC would handle SWI instructions including reasons and args? i could not find any reference to this, neither in the info files nor...
clemens fischer
numanao
Offline Send Email
Jul 6, 2006
4:52 pm

... *args) { ... reasons ... guys, it states from the arm reference manual that swi instruction ignores the 24 bits encoded in the instruction. also, whatever...
erichaukster
Offline Send Email
Jul 6, 2006
6:51 pm

Hi, GCC of course does not handle SWI calls. We would still need to tie up the ARM SWI vector to branch to the C function with the "SWI" interrupt attribute....
Mohamad Yusri Mohamad...
mohamadyusri...
Offline Send Email
Jul 7, 2006
10:31 am

... (shriek!) i was not aware of any newlib code using SWI! thanks for pointing this out. my project needs FreeRTOS, which has other plans for SWI. so i...
clemens fischer
numanao
Offline Send Email
Jul 9, 2006
11:54 am

... It depends on the adaptation layer. As an example of one that doesn't use SWI there is newlib_lpc ( see ...
Robert Adsett
robertadsett
Offline Send Email
Jul 9, 2006
3:06 pm

... thanks. i looked at the zip before, but didn't realize what it could be worth to me. before i forget: the declaration of FreeRTOS[1]' SWI stuff: /* ISR to...
clemens fischer
numanao
Offline Send Email
Jul 9, 2006
5:55 pm

Hi Clemens, Thanks for the suggestions. Actually, stdcalls.c was the place where I found out how newlib made SWI calls. I did not custom build GCC and newlib...
Mohamad Yusri Mohamad...
mohamadyusri...
Offline Send Email
Jul 10, 2006
5:15 am

... This is not really correct. Yes, the core **does** ignore the 24 least significant bits, but that is generally because those bits are used to pass a...
Charles Manning
embeddedjanitor
Offline Send Email
Jul 6, 2006
10:47 pm

... did you try and declare either the "interrupt" _or_ the "naked" attributes on the ISR? i figure one of them is bound to "win" in the sense that both insert...
clemens fischer
numanao
Offline Send Email
Jul 9, 2006
12:02 pm

Actually, I found out about the naked attribute later after posting my question here. But I would need to insert the prologue/epilogue thing via inline...
Mohamad Yusri Mohamad...
mohamadyusri...
Offline Send Email
Jul 10, 2006
1:19 am

... gcc is compiler, so you're correct. A compiler's job is not to provide exception handlers. gcc expects to be running on top of a system providing swi set...
Charles Manning
embeddedjanitor
Offline Send Email
Jul 9, 2006
9:34 pm

... yet another thing to watch out for. i've got lengthy math in my application, but i planned to do division-by-zero checking myself. ... unfortunately, it...
clemens fischer
numanao
Offline Send Email
Jul 10, 2006
5:37 pm
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help