olit123 wrote on Thursday, November 15, 2007:
Hi,
I had no luck with the .ltorg. Maybe because it is used inside an asm() statement.
I were able to work around it manually, but this requires a branch over the data definition.
I feel that there must be a more elegant solution using input and clobber lists to the asm statement.
This might not be optimal, but it works for now:
#define portSAVE_CONTEXT()
{
extern volatile void * volatile pxCurrentTCB;
extern volatile unsigned portLONG ulCriticalNesting;
asm volatile (
"b 2f /* skip pool */ \n\t"
"1: \n\t"
".word pxCurrentTCB \n\t"
".word ulCriticalNesting \n\t"
"2: \n\t"
/* Push R0 as we are going to use the register. */
"STMDB SP!, {R0} \n\t"
/* Set R0 to point to the task stack pointer. */
"STMDB SP,{SP}^ \n\t"
"NOP \n\t"
"SUB SP, SP, #4 \n\t"
"LDMIA SP!,{R0} \n\t"
/* Push the return address onto the stack. */
"STMDB R0!, {LR} \n\t"
/* Now we have saved LR we can use it instead of R0. */
"MOV LR, R0 \n\t"
/* Pop R0 so we can save it onto the system mode stack. */
"LDMIA SP!, {R0} \n\t"
/* Push all the system mode registers onto the task stack. */
"STMDB LR,{R0-LR}^ \n\t"
"NOP \n\t"
"SUB LR, LR, #60 \n\t"
/* Push the SPSR onto the task stack. */
"MRS R0, SPSR \n\t"
"STMDB LR!, {R0} \n\t"
"LDR R0, 1b+4 /* =ulCriticalNesting */ \n\t"
"LDR R0, [R0] \n\t"
"STMDB LR!, {R0} \n\t"
/* Store the new top of stack for the task. */
"LDR R0, 1b /* =pxCurrentTCB */ \n\t"
"LDR R0, [R0] \n\t"
"STR LR, [R0] \n\t"
);
( void ) ulCriticalNesting;
( void ) pxCurrentTCB;
}
#define portRESTORE_CONTEXT()
{
extern volatile void * volatile pxCurrentTCB;
extern volatile unsigned portLONG ulCriticalNesting;
asm volatile (
"b 2f /* skip pool */ \n\t"
"1: \n\t"
".word pxCurrentTCB \n\t"
".word ulCriticalNesting \n\t"
"2: \n\t"
/* Set the LR to the task stack. */
"LDR R0, 1b /* =pxCurrentTCB */ \n\t"
"LDR R0, [R0] \n\t"
"LDR LR, [R0] \n\t"
/* The critical nesting depth is the first item on the stack. */
/* Load it into the ulCriticalNesting variable. */
"LDR R0, 1b+4 /* =ulCriticalNesting */ \n\t"
"LDMFD LR!, {R1} \n\t"
"STR R1, [R0] \n\t"
/* Get the SPSR from the stack. */
"LDMFD LR!, {R0} \n\t"
"MSR SPSR, R0 \n\t"
/* Restore all system mode registers for the task. */
"LDMFD LR, {R0-R14}^ \n\t"
"NOP \n\t"
/* Restore the return address. */
"LDR LR, [LR, #+60] \n\t"
/* And return - correcting the offset in the LR to obtain the */
/* correct address. */
"SUBS PC, LR, #4 \n\t"
);
( void ) ulCriticalNesting;
( void ) pxCurrentTCB;
}
Regards,
Oliver