1/* 2 * Copyright (c) 2006-2021, RT-Thread Development Team 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Change Logs: 7 * Date Author Notes 8 * 2017-01-01 Urey first version 9 * 2018-06-05 tanek clean code 10 */ 11 12.file "contex_ck802.S" 13 14#undef VIC_TSPDR 15#define VIC_TSPDR 0XE000EC08 16 17.global rt_thread_switch_interrupt_flag 18.global rt_interrupt_from_thread 19.global rt_interrupt_to_thread 20 21.text 22.align 2 23 24/* 25 * rt_base_t rt_hw_interrupt_disable(void); 26 */ 27.global rt_hw_interrupt_disable 28.type rt_hw_interrupt_disable, %function 29rt_hw_interrupt_disable: 30mfcr r0, psr 31psrclr ie 32rts 33 34/* 35 * void rt_hw_interrupt_enable(rt_base_t psr); 36 */ 37.global rt_hw_interrupt_enable 38.type rt_hw_interrupt_enable, %function 39rt_hw_interrupt_enable: 40mtcr r0, psr 41rts 42 43/* 44 * void rt_hw_context_switch_to(rt_uint32 to); 45 * R0 --> to 46 */ 47.global rt_hw_context_switch_to 48.type rt_hw_context_switch_to, %function 49rt_hw_context_switch_to: 50lrw r2, rt_interrupt_to_thread 51stw r0, (r2) 52 53/* set form thread = 0 */ 54lrw r2, rt_interrupt_from_thread 55movi r0, 0 56stw r0, (r2) 57 58psrclr ie 59jbr __tspend_handler_nosave 60 61/* 62 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); 63 * r0 --> from 64 * r1 --> to 65 */ 66.global rt_hw_context_switch_interrupt 67.type rt_hw_context_switch_interrupt, %function 68rt_hw_context_switch_interrupt: 69lrw r2, rt_interrupt_from_thread /* set rt_interrupt_from_thread */ 70stw r0, (r2) 71 72lrw r2, rt_interrupt_to_thread /* set rt_interrupt_to_thread */ 73stw r1, (r2) 74 75lrw r0, VIC_TSPDR 76bgeni r1, 0 77stw r1, (r0) 78rts 79 80/* 81 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to) 82 * r0 --> from 83 * r1 --> to 84 */ 85.global rt_hw_context_switch 86.type rt_hw_context_switch, %function 87rt_hw_context_switch: 88lrw r2, rt_interrupt_from_thread /* set rt_interrupt_from_thread */ 89stw r0, (r2) 90 91lrw r2, rt_interrupt_to_thread /* set rt_interrupt_to_thread */ 92stw r1, (r2) 93 94lrw r0, VIC_TSPDR 95bgeni r1, 0 96stw r1, (r0) 97rts 98 99.global PendSV_Handler 100.type PendSV_Handler, %function 101PendSV_Handler: 102subi sp, 68 103stm r0-r13, (sp) 104stw r15, (sp, 56) 105mfcr r0, epsr 106stw r0, (sp, 60) 107mfcr r0, epc 108stw r0, (sp, 64) 109 110lrw r0, rt_interrupt_from_thread 111ldw r1, (r0) 112stw sp, (r1) 113 114__tspend_handler_nosave: 115lrw r6, rt_interrupt_to_thread 116lrw r7, rt_interrupt_from_thread 117ldw r8, (r6) 118stw r8, (r7) 119 120ldw sp, (r8) 121 122#ifdef CONFIG_STACK_GUARD 123mfcr r3, cr<0, 4> 124bseti r3, 0 125bseti r3, 1 126mtcr r3, cr<0, 4> 127#endif 128 129ldw r0, (sp, 64) 130mtcr r0, epc 131ldw r0, (sp, 60) 132bseti r0, 6 133mtcr r0, epsr 134ldw r15, (sp, 56) 135ldm r0-r13, (sp) 136addi sp, 68 137rte 138 139