add thumb mode support.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1629 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
86d6c01c9e
commit
1b9e80dc70
|
@ -49,20 +49,23 @@ rt_hw_context_switch PROC
|
||||||
STMFD sp!, {lr} ; push pc (lr should be pushed in place of PC)
|
STMFD sp!, {lr} ; push pc (lr should be pushed in place of PC)
|
||||||
STMFD sp!, {r0-r12, lr} ; push lr & register file
|
STMFD sp!, {r0-r12, lr} ; push lr & register file
|
||||||
|
|
||||||
MRS r4, cpsr
|
MRS r4, cpsr
|
||||||
|
TST lr, #0x01
|
||||||
|
BEQ _ARM_MODE
|
||||||
|
ORR r4, r4, #0x20 ; it's thumb code
|
||||||
|
|
||||||
|
_ARM_MODE
|
||||||
STMFD sp!, {r4} ; push cpsr
|
STMFD sp!, {r4} ; push cpsr
|
||||||
MRS r4, spsr
|
|
||||||
STMFD sp!, {r4} ; push spsr
|
|
||||||
|
|
||||||
STR sp, [r0] ; store sp in preempted tasks TCB
|
STR sp, [r0] ; store sp in preempted tasks TCB
|
||||||
LDR sp, [r1] ; get new task stack pointer
|
LDR sp, [r1] ; get new task stack pointer
|
||||||
|
|
||||||
LDMFD sp!, {r4} ; pop new task spsr
|
LDMFD sp!, {r4} ; pop new task cpsr to spsr
|
||||||
MSR spsr_cxsf, r4
|
MSR spsr_cxsf, r4
|
||||||
LDMFD sp!, {r4} ; pop new task cpsr
|
BIC r4, r4, #0x20 ; must be ARM mode
|
||||||
MSR cpsr_cxsf, r4
|
MSR cpsr_cxsf, r4
|
||||||
|
|
||||||
LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
|
LDMFD sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc, copy spsr to cpsr
|
||||||
ENDP
|
ENDP
|
||||||
|
|
||||||
;/*
|
;/*
|
||||||
|
@ -73,12 +76,12 @@ rt_hw_context_switch_to PROC
|
||||||
EXPORT rt_hw_context_switch_to
|
EXPORT rt_hw_context_switch_to
|
||||||
LDR sp, [r0] ; get new task stack pointer
|
LDR sp, [r0] ; get new task stack pointer
|
||||||
|
|
||||||
LDMFD sp!, {r4} ; pop new task spsr
|
LDMFD sp!, {r4} ; pop new task cpsr to spsr
|
||||||
MSR spsr_cxsf, r4
|
MSR spsr_cxsf, r4
|
||||||
LDMFD sp!, {r4} ; pop new task cpsr
|
BIC r4, r4, #0x20 ; must be ARM mode
|
||||||
MSR cpsr_cxsf, r4
|
MSR cpsr_cxsf, r4
|
||||||
|
|
||||||
LDMFD sp!, {r0-r12, lr, pc} ; pop new task r0-r12, lr & pc
|
LDMFD sp!, {r0-r12, lr, pc}^ ; pop new task r0-r12, lr & pc, copy spsr to cpsr
|
||||||
ENDP
|
ENDP
|
||||||
|
|
||||||
;/*
|
;/*
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
* 2008-12-11 XuXinming first version
|
* 2008-12-11 XuXinming first version
|
||||||
*/
|
*/
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include "LPC24xx.h"
|
#include "LPC24xx.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup LPC2478
|
* @addtogroup LPC2478
|
||||||
|
@ -49,9 +49,13 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
|
||||||
*(--stk) = 0; /* r3 */
|
*(--stk) = 0; /* r3 */
|
||||||
*(--stk) = 0; /* r2 */
|
*(--stk) = 0; /* r2 */
|
||||||
*(--stk) = 0; /* r1 */
|
*(--stk) = 0; /* r1 */
|
||||||
*(--stk) = (unsigned long)parameter; /* r0 : argument */
|
*(--stk) = (unsigned long)parameter; /* r0 : argument */
|
||||||
*(--stk) = SVCMODE; /* cpsr */
|
|
||||||
*(--stk) = SVCMODE; /* spsr */
|
/* cpsr */
|
||||||
|
if ((rt_uint32_t)tentry & 0x01)
|
||||||
|
*(--stk) = SVCMODE | 0x20; /* thumb mode */
|
||||||
|
else
|
||||||
|
*(--stk) = SVCMODE; /* arm mode */
|
||||||
|
|
||||||
/* return task's current stack address */
|
/* return task's current stack address */
|
||||||
return (rt_uint8_t *)stk;
|
return (rt_uint8_t *)stk;
|
||||||
|
|
|
@ -1538,8 +1538,6 @@ rt_hw_context_switch_interrupt_do PROC
|
||||||
LDMFD r4!, {r0-r3}
|
LDMFD r4!, {r0-r3}
|
||||||
STMFD sp!, {r0-r3} ; push old task's r3-r0
|
STMFD sp!, {r0-r3} ; push old task's r3-r0
|
||||||
STMFD sp!, {r5} ; push old task's cpsr
|
STMFD sp!, {r5} ; push old task's cpsr
|
||||||
MRS r4, spsr
|
|
||||||
STMFD sp!, {r4} ; push old task's spsr
|
|
||||||
|
|
||||||
LDR r4, =rt_interrupt_from_thread
|
LDR r4, =rt_interrupt_from_thread
|
||||||
LDR r5, [r4]
|
LDR r5, [r4]
|
||||||
|
@ -1548,13 +1546,13 @@ rt_hw_context_switch_interrupt_do PROC
|
||||||
LDR r6, =rt_interrupt_to_thread
|
LDR r6, =rt_interrupt_to_thread
|
||||||
LDR r6, [r6]
|
LDR r6, [r6]
|
||||||
LDR sp, [r6] ; get new task's stack pointer
|
LDR sp, [r6] ; get new task's stack pointer
|
||||||
|
|
||||||
LDMFD sp!, {r4} ; pop new task's spsr
|
LDMFD sp!, {r4} ; pop new task's cpsr to spsr
|
||||||
MSR spsr_cxsf, r4
|
MSR spsr_cxsf, r4
|
||||||
LDMFD sp!, {r4} ; pop new task's psr
|
BIC r4, r4, #0x20 ; must be ARM mode
|
||||||
MSR cpsr_cxsf, r4
|
MSR cpsr_cxsf, r4
|
||||||
|
|
||||||
LDMFD sp!, {r0-r12,lr,pc} ; pop new task's r0-r12,lr & pc
|
LDMFD sp!, {r0-r12,lr,pc}^ ; pop new task's r0-r12,lr & pc, copy spsr to cpsr
|
||||||
ENDP
|
ENDP
|
||||||
|
|
||||||
IF :DEF:__MICROLIB
|
IF :DEF:__MICROLIB
|
||||||
|
|
Loading…
Reference in New Issue