]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/ThirdParty/CDK/T-HEAD_CK802/portasm.S
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Source / portable / ThirdParty / CDK / T-HEAD_CK802 / portasm.S
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of
5  * this software and associated documentation files (the "Software"), to deal in
6  * the Software without restriction, including without limitation the rights to
7  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8  * the Software, and to permit persons to whom the Software is furnished to do so,
9  * subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * 1 tab == 4 spaces!
22  */
23
24 //#include <csi_config.h>
25
26 /********************************************************************
27  * Functions: vPortStartTask
28  *
29  ********************************************************************/
30 .global vPortStartTask
31 .type   vPortStartTask, %function
32 vPortStartTask:
33     psrclr   ie
34     lrw      r4, pxCurrentTCB
35     ld.w     r4, (r4)                // the current task stack pointer is the first member
36     ld.w     sp, (r4)
37
38     ldw      r0, (sp, 64)
39     mtcr     r0, epc
40     ldw      r0, (sp, 60)
41     mtcr     r0, epsr
42     ldw      r15, (sp, 56)
43     ldm      r0-r13, (sp)
44     addi     sp, 68
45     rte
46
47 /********************************************************************
48  * Functions: vPortYield
49  *
50  ********************************************************************/
51 .global vPortYield
52 .type   vPortYield, %function
53 vPortYield:
54     psrclr  ee
55     subi    sp, 68
56     stm     r0-r13, (sp)
57     stw     r15, (sp, 56)
58     mfcr    r0, psr
59     bseti   r0, 8
60     stw     r0, (sp, 60)
61     stw     r15, (sp, 64)
62
63     lrw     r2, pxCurrentTCB
64     ld.w    r3, (r2)
65     st.w    sp, (r3)
66
67     jbsr    vTaskSwitchContext
68     lrw     r4, pxCurrentTCB
69     ld.w    r4, (r4)
70     ld.w    sp, (r4)
71
72     ldw     r0, (sp, 64)
73     mtcr    r0, epc
74     ldw     r0, (sp, 60)
75     mtcr    r0, epsr
76     ldw     r15, (sp, 56)
77     ldm     r0-r13, (sp)
78     addi    sp, 68
79
80     rte
81
82 /********************************************************************
83  * Functions: NOVIC_IRQ_Default_Handler
84  *
85  ********************************************************************/
86 .global NOVIC_IRQ_Default_Handler
87 .type   NOVIC_IRQ_Default_Handler, %function
88 NOVIC_IRQ_Default_Handler:
89     psrset  ee
90     subi    sp, 68
91     stm     r0-r13, (sp)
92     stw     r15, (sp, 56)
93     mfcr    r0, epsr
94     stw     r0, (sp, 60)
95     mfcr    r0, epc
96     stw     r0, (sp, 64)
97         
98     lrw     r7, pxCurrentTCB
99     ldw     r7, (r7)
100     stw     sp, (r7)
101
102     lrw     sp, g_top_irqstack
103
104     lrw     r1, g_irqvector
105     mfcr    r0, psr
106     lsri    r0, 16
107     sextb   r0
108     subi    r0, 32
109     lsli    r0, 2
110     add     r1, r0
111     ldw     r1, (r1)
112     lsri    r0, 2
113     jsr     r1
114
115     lrw     r7, pxCurrentTCB
116     ldw     r7, (r7)
117     ldw     sp, (r7)
118
119     ldw     r0, (sp, 64)
120     mtcr    r0, epc
121     ldw     r0, (sp, 60)
122     mtcr    r0, epsr
123     ldm     r0-r13, (sp)
124     ldw     r15, (sp, 56)
125     addi    sp, 68
126     rte