2018-10-15 01:35:07 +08:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2006-2018, RT-Thread Development Team
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*
|
|
|
|
|
* Change Logs:
|
|
|
|
|
* Date Author Notes
|
|
|
|
|
*/
|
2009-07-03 07:18:14 +08:00
|
|
|
|
.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();
|
2018-10-15 01:35:07 +08:00
|
|
|
|
关闭中断,关闭前返回CPSR寄存器值
|
2009-07-03 07:18:14 +08:00
|
|
|
|
*/
|
|
|
|
|
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);
|
2018-10-15 01:35:07 +08:00
|
|
|
|
恢复中断状态
|
2009-07-03 07:18:14 +08:00
|
|
|
|
*/
|
|
|
|
|
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
|
2018-10-15 01:35:07 +08:00
|
|
|
|
进行线程的上下文切换
|
2009-07-03 07:18:14 +08:00
|
|
|
|
*/
|
|
|
|
|
rt_hw_context_switch:
|
|
|
|
|
//EXPORT rt_hw_context_switch
|
|
|
|
|
STMFD sp!, {lr} /* push pc (lr should be pushed in place of PC) */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 把LR寄存器压入栈(这个函数返回后的下一个执行处) */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
STMFD sp!, {r0-r12, lr} /* push lr & register file */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 把R0 – R12以及LR压入栈 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
2018-10-15 01:35:07 +08:00
|
|
|
|
MRS r4, cpsr /* 读取CPSR寄存器到R4寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
STMFD sp!, {r4} /* push cpsr */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 把R4寄存器压栈(即上一指令取出的CPSR寄存器) */
|
|
|
|
|
MRS r4, spsr /* 读取SPSR寄存器到R4寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
STMFD sp!, {r4} /* push spsr */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 把R4寄存器压栈(即SPSR寄存器) */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
|
|
|
|
STR sp, [r0] /* store sp in preempted tasks TCB */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 把栈指针更新到TCB的sp,是由R0传入此函数 */
|
|
|
|
|
/* 到这里换出线程的上下文都保存在栈中 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
LDR sp, [r1] /* get new task stack pointer */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 载入切换到线程的TCB的sp */
|
|
|
|
|
/* 从切换到线程的栈中恢复上下文,次序和保存的时候刚好相反 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
|
|
|
|
LDMFD sp!, {r4} /* pop new task spsr */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 出栈到R4寄存器(保存了SPSR寄存器) */
|
|
|
|
|
MSR spsr_cxsf, r4 /* 恢复SPSR寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
LDMFD sp!, {r4} /* pop new task cpsr */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 出栈到R4寄存器(保存了CPSR寄存器) */
|
|
|
|
|
MSR cpsr_cxsf, r4 /* 恢复CPSR寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
|
|
|
|
LDMFD sp!, {r0-r12, lr, pc} /* pop new task r0-r12, lr & pc */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 对R0 – R12及LR、PC进行恢复 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
//ENDP
|
|
|
|
|
|
|
|
|
|
rt_hw_context_switch_to:
|
|
|
|
|
//EXPORT rt_hw_context_switch_to
|
|
|
|
|
LDR sp, [r0] /* get new task stack pointer */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 获得切换到线程的SP指针 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
|
|
|
|
LDMFD sp!, {r4} /* pop new task spsr */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 出栈R4寄存器(保存了SPSR寄存器值) */
|
|
|
|
|
MSR spsr_cxsf, r4 /* 恢复SPSR寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
LDMFD sp!, {r4} /* pop new task cpsr */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 出栈R4寄存器(保存了CPSR寄存器值) */
|
|
|
|
|
MSR cpsr_cxsf, r4 /* 恢复CPSR寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
|
|
|
|
LDMFD sp!, {r0-r12, lr, pc} /* pop new task r0-r12, lr & pc */
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 恢复R0 – R12,LR及PC寄存器 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
//ENDP
|
|
|
|
|
|
|
|
|
|
rt_hw_context_switch_interrupt:
|
|
|
|
|
//EXPORT rt_hw_context_switch_interrupt
|
2011-09-19 12:40:50 +08:00
|
|
|
|
LDR r2, =rt_thread_switch_interrupt_flag
|
2018-10-15 01:35:07 +08:00
|
|
|
|
LDR r3, [r2] /* 载入中断中切换标致地址 */
|
|
|
|
|
CMP r3, #1 /* 等于 1 ?*/
|
|
|
|
|
BEQ _reswitch /* 如果等于1,跳转到_reswitch*/
|
2011-09-19 12:40:50 +08:00
|
|
|
|
MOV r3, #1 /* set rt_thread_switch_interrupt_flag to 1*/
|
2018-10-15 01:35:07 +08:00
|
|
|
|
/* 设置中断中切换标志位1 */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
STR r3, [r2] /* */
|
|
|
|
|
LDR r2, =rt_interrupt_from_thread /* set rt_interrupt_from_thread*/
|
2018-10-15 01:35:07 +08:00
|
|
|
|
STR r0, [r2] /* 保存切换出线程栈指针*/
|
2009-07-03 07:18:14 +08:00
|
|
|
|
_reswitch:
|
|
|
|
|
LDR r2, =rt_interrupt_to_thread /* set rt_interrupt_to_thread*/
|
2018-10-15 01:35:07 +08:00
|
|
|
|
STR r1, [r2] /* 保存切换到线程栈指针*/
|
2009-07-03 07:18:14 +08:00
|
|
|
|
BX lr
|
|
|
|
|
//ENDP
|
|
|
|
|
|
|
|
|
|
//END
|