Mercurial > flash_v2
diff packages/hal/arm/arch/current/src/context.S @ 80:2085233a121a ecos-sw-2000-04-07
Merge from eCos master repository on 2000-04-07-07:52:29-BST
| author | jlarmour |
|---|---|
| date | Fri, 07 Apr 2000 07:45:04 +0000 |
| parents | 435cced73e2f |
| children | e0c0827131d1 |
line wrap: on
line diff
--- a/packages/hal/arm/arch/current/src/context.S +++ b/packages/hal/arm/arch/current/src/context.S @@ -1,10 +1,10 @@ -// #============================================================================= +// #=========================================================================== // # -// # context.S +// # context.S // # -// # ARM context switch code +// # ARM context switch code // # -// #============================================================================= +// #=========================================================================== // ####COPYRIGHTBEGIN#### // // ------------------------------------------- @@ -28,35 +28,50 @@ // ------------------------------------------- // // ####COPYRIGHTEND#### -// #============================================================================= +// #=========================================================================== // ######DESCRIPTIONBEGIN#### // # -// # Author(s): nickg, gthomas -// # Contributors: nickg, gthomas -// # Date: 1998-09-15 -// # Purpose: ARM context switch code -// # Description: This file contains implementations of the thread context -// # switch routines. It also contains the longjmp() and setjmp() -// # routines. +// # Author(s): nickg, gthomas +// # Contributors: nickg, gthomas +// # Date: 1998-09-15 +// # Purpose: ARM context switch code +// # Description: This file contains implementations of the thread context +// # switch routines. It also contains the longjmp() and setjmp() +// # routines. // # // #####DESCRIPTIONEND#### // # -// #============================================================================= +// #=========================================================================== #include <pkgconf/hal.h> #include "arm.inc" - .text + .text -// ------------------------------------------------------------------------------ -// function declaration macro - -#define FUNC_START(name) \ - .globl name; \ -name: - -// ------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- +// function declaration macro (start body in ARM mode) + +#ifdef __thumb__ +#define FUNC_START_ARM(_name_, _r_) \ + .code 16 ;\ + .thumb_func ;\ + .globl _name_ ;\ +_name_: ;\ + ldr _r_,=_name_ ## _ARM ;\ + bx _r_ ;\ + .code 32 ;\ +_name_ ## _ARM: + +#else + +#define FUNC_START_ARM(_name_, _r_) \ + .globl _name_; \ +_name_: + +#endif + +// ---------------------------------------------------------------------------- // hal_thread_switch_context // Switch thread contexts // R0 = address of sp of next thread to execute @@ -66,111 +81,69 @@ name: // Note: this is a little wasteful since r0..r3 don't need to be saved. // They are saved here though so that the information can match the HAL_SavedRegisters - -#ifdef __thumb__ - .code 16 - .thumb_func -#endif -FUNC_START(hal_thread_switch_context) + +FUNC_START_ARM(hal_thread_switch_context, r2) + mov ip,sp // saved stack pointer + stmfd sp!,{fp,ip,lr,pc} // filler + stmfd sp!,{r0-r10,fp,ip,lr,pc} + mrs r2,cpsr + str r2,[sp,#armreg_cpsr] + str sp,[r1] // return new stack pointer #ifdef __thumb__ - ldr r2,=hal_thread_switch_context_ARM - bx r2 - .code 32 -FUNC_START(hal_thread_switch_context_ARM) -#endif - mov ip,sp // saved stack pointer - stmfd sp!,{fp,ip,lr,pc} // filler - stmfd sp!,{r0-r10,fp,ip,lr,pc} - mrs r2,cpsr - str r2,[sp,#armreg_cpsr] - str sp,[r1] // return new stack pointer -#ifdef __thumb__ - b hal_thread_load_context_ARM // skip mode switch stuff + b hal_thread_load_context_ARM // skip mode switch stuff #endif - # Now load the destination thread by dropping through - # to hal_thread_load_context - -// ------------------------------------------------------------------------------ + # Now load the destination thread by dropping through + # to hal_thread_load_context + +// ---------------------------------------------------------------------------- // hal_thread_load_context // Load thread context // R0 = address of sp of next thread to execute -// Note that this function is also the second half of hal_thread_switch_context -// and is simply dropped into from it. - -#ifdef __thumb__ - .code 16 - .thumb_func -#endif -FUNC_START(hal_thread_load_context) +// Note that this function is also the second half of +// hal_thread_switch_context and is simply dropped into from it. + +FUNC_START_ARM(hal_thread_load_context, r2) + ldr fp,[r0] // get context to restore + mrs r0,cpsr // disable IRQ's + orr r0,r0,#CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE + msr cpsr,r0 + ldr r0,[fp,#armreg_cpsr] + msr spsr,r0 + ldmfd fp,{r0-r10,fp,sp,lr} #ifdef __thumb__ - ldr r2,=hal_thread_load_context_ARM - bx r2 - .code 32 -FUNC_START(hal_thread_load_context_ARM) -#endif - ldr fp,[r0] // get context to restore - mrs r0,cpsr // disable IRQ's - orr r0,r0,#CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE - msr cpsr,r0 - ldr r0,[fp,#armreg_cpsr] - msr spsr,r0 - ldmfd fp,{r0-r10,fp,sp,lr} -#ifdef __thumb__ - mrs r1,spsr // r1 is scratch + mrs r1,spsr // r1 is scratch // [r0 holds initial thread arg] - msr cpsr,r1 // hopefully no mode switch here! - bx lr + msr cpsr,r1 // hopefully no mode switch here! + bx lr #else - movs pc,lr // also restores saved PSR + movs pc,lr // also restores saved PSR #endif -// ------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- // HAL longjmp, setjmp implementations // hal_setjmp saves only to callee save registers 4-14 // and lr into buffer supplied in r0[arg0] -#ifdef __thumb__ - .code 16 - .thumb_func -#endif -FUNC_START(hal_setjmp) +FUNC_START_ARM(hal_setjmp, r2) + stmea r0,{r4-r14} + mov r0,#0 #ifdef __thumb__ - ldr r2,=hal_setjmp_ARM - bx r2 - .code 32 -FUNC_START(hal_setjmp_ARM) -#endif - stmea r0,{r4-r14} - mov r0,#0 -#ifdef __thumb__ - bx lr + bx lr #else - mov pc,lr; # return + mov pc,lr; # return #endif // hal_longjmp loads state from r0[arg0] and returns - -#ifdef __thumb__ - .code 16 - .thumb_func -#endif -FUNC_START(hal_longjmp) + +FUNC_START_ARM(hal_longjmp, r2) + ldmfd r0,{r4-r14} + mov r0,r1; # return [arg1] #ifdef __thumb__ - ldr r2,=hal_longjmp_ARM - bx r2 - .code 32 -FUNC_START(hal_longjmp_ARM) -#endif - ldmfd r0,{r4-r14} - mov r0,r1; # return [arg1] -#ifdef __thumb__ - bx lr + bx lr #else - mov pc,lr + mov pc,lr #endif -// ------------------------------------------------------------------------------ +// ---------------------------------------------------------------------------- // end of context.S - -
