rt-thread/libcpu/arm/lpc214x/context_gcc.S

102 lines
3.0 KiB
ArmAsm
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

.global rt_hw_interrupt_disable
.global rt_hw_interrupt_enable
.global rt_hw_context_switch
.global rt_hw_context_switch_to
.global rt_hw_context_switch_interrupt
.equ NOINT, 0xc0
/*
* rt_base_t rt_hw_interrupt_disable();
CPSR
*/
rt_hw_interrupt_disable:
//EXPORT rt_hw_interrupt_disable
MRS r0, cpsr
ORR r1, r0, #NOINT
MSR cpsr_c, r1
BX lr
//ENDP
/*
* void rt_hw_interrupt_enable(rt_base_t level);
*/
rt_hw_interrupt_enable:
//EXPORT rt_hw_interrupt_enable
MSR cpsr_c, r0
BX lr
//ENDP
/*
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
* r0 --> from
* r1 --> to
线
*/
rt_hw_context_switch:
//EXPORT rt_hw_context_switch
STMFD sp!, {lr} /* push pc (lr should be pushed in place of PC) */
/* 把LR寄存器压入栈这个函数返回后的下一个执行处 */
STMFD sp!, {r0-r12, lr} /* push lr & register file */
/* 把R0 R12以及LR压入栈 */
MRS r4, cpsr /* CPSRR4 */
STMFD sp!, {r4} /* push cpsr */
/* 把R4寄存器压栈即上一指令取出的CPSR寄存器 */
MRS r4, spsr /* SPSRR4 */
STMFD sp!, {r4} /* push spsr */
/* 把R4寄存器压栈即SPSR寄存器 */
STR sp, [r0] /* store sp in preempted tasks TCB */
/* 把栈指针更新到TCB的sp是由R0传入此函数 */
/* 到这里换出线程的上下文都保存在栈中 */
LDR sp, [r1] /* get new task stack pointer */
/* 载入切换到线程的TCB的sp */
/* 从切换到线程的栈中恢复上下文,次序和保存的时候刚好相反 */
LDMFD sp!, {r4} /* pop new task spsr */
/* 出栈到R4寄存器保存了SPSR寄存器 */
MSR spsr_cxsf, r4 /* SPSR */
LDMFD sp!, {r4} /* pop new task cpsr */
/* 出栈到R4寄存器保存了CPSR寄存器 */
MSR cpsr_cxsf, r4 /* CPSR */
LDMFD sp!, {r0-r12, lr, pc} /* pop new task r0-r12, lr & pc */
/* 对R0 R12及LR、PC进行恢复 */
//ENDP
rt_hw_context_switch_to:
//EXPORT rt_hw_context_switch_to
LDR sp, [r0] /* get new task stack pointer */
/* 获得切换到线程的SP指针 */
LDMFD sp!, {r4} /* pop new task spsr */
/* 出栈R4寄存器保存了SPSR寄存器值 */
MSR spsr_cxsf, r4 /* SPSR */
LDMFD sp!, {r4} /* pop new task cpsr */
/* 出栈R4寄存器保存了CPSR寄存器值 */
MSR cpsr_cxsf, r4 /* CPSR */
LDMFD sp!, {r0-r12, lr, pc} /* pop new task r0-r12, lr & pc */
/* 恢复R0 R12LR及PC寄存器 */
//ENDP
rt_hw_context_switch_interrupt:
//EXPORT rt_hw_context_switch_interrupt
LDR r2, =rt_thread_switch_interrput_flag
LDR r3, [r2] /* */
CMP r3, #1 /* 1 */
BEQ _reswitch /* 1_reswitch*/
MOV r3, #1 /* set rt_thread_switch_interrput_flag to 1*/
/* 设置中断中切换标志位1 */
STR r3, [r2] /* */
LDR r2, =rt_interrupt_from_thread /* set rt_interrupt_from_thread*/
STR r0, [r2] /* 线*/
_reswitch:
LDR r2, =rt_interrupt_to_thread /* set rt_interrupt_to_thread*/
STR r1, [r2] /* 线*/
BX lr
//ENDP
//END