summaryrefslogtreecommitdiff
path: root/libcpu/c-sky/ck802/contex_ck802_gcc.S
blob: a4431b0f74c03a7aee1c5b774eccf3c4e5f5afe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2017-01-01     Urey      first version
 * 2018-06-05     tanek     clean code
 */

.file     "contex_ck802.S"

#undef  VIC_TSPDR
#define VIC_TSPDR 0XE000EC08

.global  rt_thread_switch_interrupt_flag
.global  rt_interrupt_from_thread
.global  rt_interrupt_to_thread

.text
.align 2

/*
 * rt_base_t rt_hw_interrupt_disable(void);
 */
.global rt_hw_interrupt_disable
.type   rt_hw_interrupt_disable, %function
rt_hw_interrupt_disable:
mfcr    r0, psr
psrclr  ie
rts

/*
 * void rt_hw_interrupt_enable(rt_base_t psr);
 */
.global rt_hw_interrupt_enable
.type   rt_hw_interrupt_enable, %function
rt_hw_interrupt_enable:
mtcr    r0, psr
rts

/*
 * void rt_hw_context_switch_to(rt_uint32 to);
 * R0 --> to
 */
.global rt_hw_context_switch_to
.type rt_hw_context_switch_to, %function
rt_hw_context_switch_to:
lrw     r2, rt_interrupt_to_thread
stw     r0, (r2)

/* set form thread = 0 */
lrw     r2, rt_interrupt_from_thread
movi    r0, 0
stw     r0, (r2)

psrclr  ie
jbr     __tspend_handler_nosave

/*
 * void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
 * r0 --> from
 * r1 --> to
 */
.global rt_hw_context_switch_interrupt
.type   rt_hw_context_switch_interrupt, %function
rt_hw_context_switch_interrupt:
lrw    r2, rt_interrupt_from_thread     /* set rt_interrupt_from_thread */
stw    r0, (r2)

lrw    r2, rt_interrupt_to_thread       /* set rt_interrupt_to_thread */
stw    r1, (r2)

lrw    r0, VIC_TSPDR
bgeni  r1, 0
stw    r1, (r0)
rts

/*
 * void rt_hw_context_switch(rt_uint32 from, rt_uint32 to)
 * r0 --> from
 * r1 --> to
 */
.global rt_hw_context_switch
.type   rt_hw_context_switch, %function
rt_hw_context_switch:
lrw    r2, rt_interrupt_from_thread     /* set rt_interrupt_from_thread */
stw    r0, (r2)

lrw    r2, rt_interrupt_to_thread       /* set rt_interrupt_to_thread */
stw    r1, (r2)

lrw    r0, VIC_TSPDR
bgeni  r1, 0
stw    r1, (r0)
rts

.global PendSV_Handler
.type   PendSV_Handler, %function
PendSV_Handler:
subi    sp, 68
stm     r0-r13, (sp)
stw     r15, (sp, 56)
mfcr    r0, epsr
stw     r0, (sp, 60)
mfcr    r0, epc
stw     r0, (sp, 64)

lrw     r0, rt_interrupt_from_thread
ldw     r1, (r0)
stw     sp, (r1)

__tspend_handler_nosave:
lrw     r6, rt_interrupt_to_thread
lrw     r7, rt_interrupt_from_thread
ldw     r8, (r6)
stw     r8, (r7)

ldw     sp, (r8)

#ifdef CONFIG_STACK_GUARD
mfcr    r3, cr<0, 4>
bseti   r3, 0
bseti   r3, 1
mtcr    r3, cr<0, 4>
#endif

ldw     r0, (sp, 64)
mtcr    r0, epc
ldw     r0, (sp, 60)
bseti   r0, 6
mtcr    r0, epsr
ldw     r15, (sp, 56)
ldm     r0-r13, (sp)
addi    sp, 68
rte