gcc compile
Yves Rutschle
y.rutschle@indigovision.com
Mon Jan 22 04:27:00 GMT 2001
Hallo,
> I have tested the code on the eb01. After swi the proc is in SV.
Therefore it's not because of the simulator :)
> 0x2018d28 <swi_handler__Fi>: mov r12, sp
> 0x2018d2c <swi_handler__Fi+4>: stmdb sp!, {r11, r12, lr, pc}
> 0x2018d30 <swi_handler__Fi+8>: sub r11, r12, #4 ; 0x4
> 0x2018d34 <swi_handler__Fi+12>: sub sp, sp, #12 ; 0xc
[snipped swi routine]
> 0x2018d98 <swi_handler__Fi+112>: ldmdb r11, {r11, sp, pc}
This code won't set CPSR back to SPSR; Try to add a hat
at the end of the return instruction:
ldmdb r11, {r11, sp, pc}^
(the hat activates the copy of SPSR to CPSR same as movs pc,lr)
>Don?t know what I am doing wrong. This does also not work:
>void swi_handler(int reason) {
> switch(reason) {
> case REASON_CHANGE_TO_SV :
> asm volatile ("mrs r0,cpsr": : :"r0");
> asm volatile ("orr r0, r0, #192": : :"r0");
> asm volatile ("msr cpsr, r0");
> default :
> break;
> }
> asm volatile("movs pc, lr");
>}
Huh. What do you think happens to the stack when you leave
like that? :-) (hint: you pushed 4 registers when entering
the routine...)
I don't think you can create a whole swi handler in C (unless
gcc has extensions I don't know about. the arm C doesn't
anyway).
I'd advise you to use an assembly top-level handler such
as:
stmdf sp!, {r0-r3, lr}
ldr r0, [lr,#-4]
bic r0, r0, #0xff000000
mov r1, sp ; r1 = SWI number
mrs r2, spsr
stmfd sp!, {r2} ; keep spsr in case of nested swi's
bl C_Handler
ldmfd sp!, {r2}
msr spsr, r2 ; restore spsr
ldmfd sp!, {r0-r3, pc}^ ; return, restore cpsr from spsr
(this is straight from ADS' developer guide, by the way)
Then your C handler looks like:
void C_Handler( int swi_number, unsigned int * stack )
{
printf( "got swi %d\n", swi_number );
}
Hope that helps!
Yves.
------
Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sourceware.cygnus.com
More information about the crossgcc
mailing list