context_gcc.S
6.02 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
* File : context_gcc.S
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006-2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE
*
* Change Logs:
* Date Author Notes
* 2011-02-14 aozima first implementation for Nios II.
* 2011-02-20 aozima fix context&switch bug.
*/
/**
* @addtogroup NIOS_II
*/
/*@{*/
.text
.set noat
/*
* rt_base_t rt_hw_interrupt_disable();
*/
.global rt_hw_interrupt_disable
.type rt_hw_interrupt_disable, %function
rt_hw_interrupt_disable:
rdctl r2, status /* return status */
wrctl status, zero /* disable interrupt */
ret
/*
* void rt_hw_interrupt_enable(rt_base_t level);
*/
.global rt_hw_interrupt_enable
.type rt_hw_interrupt_enable, %function
rt_hw_interrupt_enable:
wrctl status, r4 /* enable interrupt by argument */
ret
/* void rt_hw_context_switch_interrupt_do(void) */
.global rt_hw_context_switch_interrupt_do
.type rt_hw_context_switch_interrupt_do, %function
rt_hw_context_switch_interrupt_do:
/* save from thread */
addi sp,sp,-72
/* frist save r2,so that save status */
stw r2, 4(sp)
/* save status */
/* when the interrupt happen,the interrupt is enable */
movi r2, 1
stw r2, 68(sp) /* status */
stw r3, 8(sp)
stw r4, 12(sp)
/* get & save from thread pc */
ldw r4,%gprel(rt_current_thread_entry)(gp)
stw r4, 0(sp) /* thread pc */
stw r5, 16(sp)
stw r6, 20(sp)
stw r7, 24(sp)
stw r16, 28(sp)
stw r17, 32(sp)
stw r18, 36(sp)
stw r19, 40(sp)
stw r20, 44(sp)
stw r21, 48(sp)
stw r22, 52(sp)
stw r23, 56(sp)
stw fp, 60(sp)
stw ra, 64(sp)
/* save from thread sp */
/* rt_interrupt_from_thread = &from_thread->sp */
ldw r4, %gprel(rt_interrupt_from_thread)(gp)
/* *r4(from_thread->sp) = sp */
stw sp, (r4)
/* clear rt_thread_switch_interrupt_flag */
/* rt_thread_switch_interrupt_flag = 0 */
stw zero,%gprel(rt_thread_switch_interrupt_flag)(gp)
/* load to thread sp */
/* r4 = rt_interrupt_to_thread(&to_thread->sp) */
ldw r4, %gprel(rt_interrupt_to_thread)(gp)
/* sp = to_thread->sp */
ldw sp, (r4)
ldw r2, 68(sp) /* status */
wrctl estatus, r2
ldw ea, 0(sp) /* thread pc */
ldw r2, 4(sp)
ldw r3, 8(sp)
ldw r4, 12(sp)
ldw r5, 16(sp)
ldw r6, 20(sp)
ldw r7, 24(sp)
ldw r16, 28(sp)
ldw r17, 32(sp)
ldw r18, 36(sp)
ldw r19, 40(sp)
ldw r20, 44(sp)
ldw r21, 48(sp)
ldw r22, 52(sp)
ldw r23, 56(sp)
ldw fp, 60(sp)
ldw ra, 64(sp)
addi sp, sp, 72
/* estatus --> status,ea --> pc */
eret
/*
* void rt_hw_context_switch(rt_uint32 from, rt_uint32 to);
* r4: from
* r5: to
*/
.global rt_hw_context_switch
.type rt_hw_context_switch, %function
rt_hw_context_switch:
/* save from thread */
addi sp,sp,-72
/* frist save r2,so that save status */
stw r2, 4(sp)
/* save status */
rdctl r2, status
stw r2, 68(sp) /* status */
stw ra, 0(sp) /* return from rt_hw_context_switch */
stw r3, 8(sp)
stw r4, 12(sp)
stw r5, 16(sp)
stw r6, 20(sp)
stw r7, 24(sp)
stw r16, 28(sp)
stw r17, 32(sp)
stw r18, 36(sp)
stw r19, 40(sp)
stw r20, 44(sp)
stw r21, 48(sp)
stw r22, 52(sp)
stw r23, 56(sp)
stw fp, 60(sp)
stw ra, 64(sp)
/* save form thread sp */
/* from_thread->sp(r4) = sp */
stw sp, (r4)
/* update rt_interrupt_from_thread */
/* rt_interrupt_from_thread = r4(from_thread->sp) */
stw r4,%gprel(rt_interrupt_from_thread)(gp)
/* update rt_interrupt_to_thread */
/* rt_interrupt_to_thread = r5 */
stw r5,%gprel(rt_interrupt_to_thread)(gp)
/* get to thread sp */
/* sp = rt_interrupt_to_thread(r5:to_thread->sp) */
ldw sp, (r5)
ldw r2, 68(sp) /* status */
wrctl estatus, r2
ldw ea, 0(sp) /* thread pc */
ldw r2, 4(sp)
ldw r3, 8(sp)
ldw r4, 12(sp)
ldw r5, 16(sp)
ldw r6, 20(sp)
ldw r7, 24(sp)
ldw r16, 28(sp)
ldw r17, 32(sp)
ldw r18, 36(sp)
ldw r19, 40(sp)
ldw r20, 44(sp)
ldw r21, 48(sp)
ldw r22, 52(sp)
ldw r23, 56(sp)
ldw fp, 60(sp)
ldw ra, 64(sp)
addi sp, sp, 72
/* estatus --> status,ea --> pc */
eret
/*
* void rt_hw_context_switch_interrupt(rt_uint32 from, rt_uint32 to);
* r4: from
* r5: to
*/
.global rt_hw_context_switch_interrupt
.type rt_hw_context_switch_interrupt, %function
rt_hw_context_switch_interrupt:
/* if( rt_thread_switch_interrupt_flag != 0 ) _from_thread_not_change */
ldw r2,%gprel(rt_thread_switch_interrupt_flag)(gp)
bne r2,zero,_from_thread_not_change
_from_thread_change:
/* save ea -> rt_current_thread_entry */
addi ea,ea,-4
stw ea,%gprel(rt_current_thread_entry)(gp)
/* set rt_thread_switch_interrupt_flag to 1 */
movi r2, 1
stw r2,%gprel(rt_thread_switch_interrupt_flag)(gp)
/* update rt_interrupt_from_thread */
stw r4,%gprel(rt_interrupt_from_thread)(gp)
_from_thread_not_change:
/* update rt_interrupt_to_thread */
stw r5,%gprel(rt_interrupt_to_thread)(gp)
ret
/*
* void rt_hw_context_switch_to(rt_uint32 to);
* r4: to
*/
.global rt_hw_context_switch_to
.type rt_hw_context_switch_to, %function
rt_hw_context_switch_to:
/* save to thread */
stw r4,%gprel(rt_interrupt_to_thread)(gp)
/* get sp */
ldw sp, (r4) // sp = *r4
ldw r2, 68(sp) /* status */
wrctl estatus, r2
ldw ea, 0(sp) /* thread entry */
ldw r2, 4(sp)
ldw r3, 8(sp)
ldw r4, 12(sp)
ldw r5, 16(sp)
ldw r6, 20(sp)
ldw r7, 24(sp)
ldw r16, 28(sp)
ldw r17, 32(sp)
ldw r18, 36(sp)
ldw r19, 40(sp)
ldw r20, 44(sp)
ldw r21, 48(sp)
ldw r22, 52(sp)
ldw r23, 56(sp)
ldw fp, 60(sp)
ldw ra, 64(sp)
addi sp, sp, 72
/* estatus --> status,ea --> pc */
eret
/*@}*/