1/* 2 * Copyright (c) 2006-2018, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2013-07-05 Bernard the first version 9 */ 10 11/* 12 * rt_base_t rt_hw_interrupt_disable(); 13 */ 14.globl rt_hw_interrupt_disable 15rt_hw_interrupt_disable: 16 mrs r0, cpsr 17 cpsid if 18 bx lr 19 20/* 21 * void rt_hw_interrupt_enable(rt_base_t level); 22 */ 23.globl rt_hw_interrupt_enable 24rt_hw_interrupt_enable: 25 msr cpsr_c, r0 26 bx lr 27 28/* 29 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to); 30 * r0 --> from 31 * r1 --> to 32 */ 33.globl rt_hw_context_switch 34rt_hw_context_switch: 35 stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC) 36 stmfd sp!, {r0-r12, lr} @ push lr & register file 37 38 mrs r4, cpsr 39 tst lr, #0x01 40 orrne r4, r4, #0x20 @ it's thumb code 41 42 stmfd sp!, {r4} @ push cpsr 43 44 str sp, [r0] @ store sp in preempted tasks TCB 45 ldr sp, [r1] @ get new task stack pointer 46 47 ldmfd sp!, {r4} @ pop new task cpsr to spsr 48 msr spsr_cxsf, r4 49 50_do_switch: 51 ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr 52 53/* 54 * void rt_hw_context_switch_to(rt_uint32 to); 55 * r0 --> to 56 */ 57.globl rt_hw_context_switch_to 58rt_hw_context_switch_to: 59 ldr sp, [r0] @ get new task stack pointer 60 61 ldmfd sp!, {r4} @ pop new task spsr 62 msr spsr_cxsf, r4 63 64 bic r4, r4, #0x20 @ must be ARM mode 65 msr cpsr_cxsf, r4 66 67 ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc 68 69/* 70 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); 71 */ 72.globl rt_thread_switch_interrupt_flag 73.globl rt_interrupt_from_thread 74.globl rt_interrupt_to_thread 75.globl rt_hw_context_switch_interrupt 76rt_hw_context_switch_interrupt: 77 ldr r2, =rt_thread_switch_interrupt_flag 78 ldr r3, [r2] 79 cmp r3, #1 80 beq _reswitch 81 mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1 82 str r3, [r2] 83 ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread 84 str r0, [r2] 85_reswitch: 86 ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread 87 str r1, [r2] 88 bx lr 89