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 * 2011-01-13 weety copy from mini2440 9 */ 10 11/*! 12 * \addtogroup ARMv6 13 */ 14/*@{*/ 15 16#include <rtconfig.h> 17 18#define NOINT 0xc0 19#define FPEXC_EN (1 << 30) /* VFP enable bit */ 20 21/* 22 * rt_base_t rt_hw_interrupt_disable(); 23 */ 24.globl rt_hw_interrupt_disable 25rt_hw_interrupt_disable: 26 mrs r0, cpsr 27 cpsid if 28 bx lr 29 30/* 31 * void rt_hw_interrupt_enable(rt_base_t level); 32 */ 33.globl rt_hw_interrupt_enable 34rt_hw_interrupt_enable: 35 msr cpsr_c, r0 36 bx lr 37 38/* 39 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to); 40 * r0 --> from 41 * r1 --> to 42 */ 43.globl rt_hw_context_switch 44rt_hw_context_switch: 45 stmfd sp!, {lr} @ push pc (lr should be pushed in place of PC) 46 stmfd sp!, {r0-r12, lr} @ push lr & register file 47 48 mrs r4, cpsr 49 tst lr, #0x01 50 orrne r4, r4, #0x20 @ it's thumb code 51 52 stmfd sp!, {r4} @ push cpsr 53 54 str sp, [r0] @ store sp in preempted tasks TCB 55 ldr sp, [r1] @ get new task stack pointer 56 57 ldmfd sp!, {r4} @ pop new task cpsr to spsr 58 msr spsr_cxsf, r4 59_do_switch: 60 ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc, copy spsr to cpsr 61 62/* 63 * void rt_hw_context_switch_to(rt_uint32 to); 64 * r0 --> to 65 */ 66.globl rt_hw_context_switch_to 67rt_hw_context_switch_to: 68 ldr sp, [r0] @ get new task stack pointer 69 70 ldmfd sp!, {r4} @ pop new task spsr 71 msr spsr_cxsf, r4 72 73 bic r4, r4, #0x20 @ must be ARM mode 74 msr cpsr_cxsf, r4 75 ldmfd sp!, {r0-r12, lr, pc}^ @ pop new task r0-r12, lr & pc 76 77/* 78 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); 79 */ 80.globl rt_thread_switch_interrupt_flag 81.globl rt_interrupt_from_thread 82.globl rt_interrupt_to_thread 83.globl rt_hw_context_switch_interrupt 84rt_hw_context_switch_interrupt: 85 ldr r2, =rt_thread_switch_interrupt_flag 86 ldr r3, [r2] 87 cmp r3, #1 88 beq _reswitch 89 mov r3, #1 @ set rt_thread_switch_interrupt_flag to 1 90 str r3, [r2] 91 ldr r2, =rt_interrupt_from_thread @ set rt_interrupt_from_thread 92 str r0, [r2] 93_reswitch: 94 ldr r2, =rt_interrupt_to_thread @ set rt_interrupt_to_thread 95 str r1, [r2] 96 bx lr 97