1/* 2 * File : contex_ck802.S 3 * This file is part of RT-Thread RTOS 4 * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License along 17 * with this program; if not, write to the Free Software Foundation, Inc., 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Change Logs: 21 * Date Author Notes 22 * 2017-01-01 Urey first version 23 * 2018-06-05 tanek clean code 24 */ 25 26.file "contex_ck802.S" 27 28#undef VIC_TSPDR 29#define VIC_TSPDR 0XE000EC08 30 31.global rt_thread_switch_interrupt_flag 32.global rt_interrupt_from_thread 33.global rt_interrupt_to_thread 34 35.text 36.align 2 37 38/* 39 * rt_base_t rt_hw_interrupt_disable(void); 40 */ 41.global rt_hw_interrupt_disable 42.type rt_hw_interrupt_disable, %function 43rt_hw_interrupt_disable: 44mfcr r0, psr 45psrclr ie 46rts 47 48/* 49 * void rt_hw_interrupt_enable(rt_base_t psr); 50 */ 51.global rt_hw_interrupt_enable 52.type rt_hw_interrupt_enable, %function 53rt_hw_interrupt_enable: 54mtcr r0, psr 55rts 56 57/* 58 * void rt_hw_context_switch_to(rt_uint32 to); 59 * R0 --> to 60 */ 61.global rt_hw_context_switch_to 62.type rt_hw_context_switch_to, %function 63rt_hw_context_switch_to: 64lrw r2, rt_interrupt_to_thread 65stw r0, (r2) 66 67/* set form thread = 0 */ 68lrw r2, rt_interrupt_from_thread 69movi r0, 0 70stw r0, (r2) 71 72psrclr ie 73jbr __tspend_handler_nosave 74 75/* 76 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to); 77 * r0 --> from 78 * r1 --> to 79 */ 80.global rt_hw_context_switch_interrupt 81.type rt_hw_context_switch_interrupt, %function 82rt_hw_context_switch_interrupt: 83lrw r2, rt_interrupt_from_thread /* set rt_interrupt_from_thread */ 84stw r0, (r2) 85 86lrw r2, rt_interrupt_to_thread /* set rt_interrupt_to_thread */ 87stw r1, (r2) 88 89lrw r0, VIC_TSPDR 90bgeni r1, 0 91stw r1, (r0) 92rts 93 94/* 95 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to) 96 * r0 --> from 97 * r1 --> to 98 */ 99.global rt_hw_context_switch 100.type rt_hw_context_switch, %function 101rt_hw_context_switch: 102lrw r2, rt_interrupt_from_thread /* set rt_interrupt_from_thread */ 103stw r0, (r2) 104 105lrw r2, rt_interrupt_to_thread /* set rt_interrupt_to_thread */ 106stw r1, (r2) 107 108lrw r0, VIC_TSPDR 109bgeni r1, 0 110stw r1, (r0) 111rts 112 113.global PendSV_Handler 114.type PendSV_Handler, %function 115PendSV_Handler: 116subi sp, 68 117stm r0-r13, (sp) 118stw r15, (sp, 56) 119mfcr r0, epsr 120stw r0, (sp, 60) 121mfcr r0, epc 122stw r0, (sp, 64) 123 124lrw r0, rt_interrupt_from_thread 125ldw r1, (r0) 126stw sp, (r1) 127 128__tspend_handler_nosave: 129lrw r6, rt_interrupt_to_thread 130lrw r7, rt_interrupt_from_thread 131ldw r8, (r6) 132stw r8, (r7) 133 134ldw sp, (r8) 135 136#ifdef CONFIG_STACK_GUARD 137mfcr r3, cr<0, 4> 138bseti r3, 0 139bseti r3, 1 140mtcr r3, cr<0, 4> 141#endif 142 143ldw r0, (sp, 64) 144mtcr r0, epc 145ldw r0, (sp, 60) 146bseti r0, 6 147mtcr r0, epsr 148ldw r15, (sp, 56) 149ldm r0-r13, (sp) 150addi sp, 68 151rte 152 153