summaryrefslogtreecommitdiff
path: root/bsp/env/ventry.S
blob: 5c82c488c86808bde5e1f36c8c620487cec1313c (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
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
281
282
283
284
285
286
287
288
// See LICENSE for license details

#ifndef VENTRY_S
#define VENTRY_S

#include "encoding.h"
#include "sifive/bits.h"

#only save caller registers
.macro TRAP_ENTRY
  addi sp, sp, -16*REGBYTES

  STORE x1,  0*REGBYTES(sp)
  STORE x5,  1*REGBYTES(sp)
  STORE x6,  2*REGBYTES(sp)
  STORE x7,  3*REGBYTES(sp)
  STORE x10, 4*REGBYTES(sp)
  STORE x11, 5*REGBYTES(sp)
  STORE x12, 6*REGBYTES(sp)
  STORE x13, 7*REGBYTES(sp)
  STORE x14, 8*REGBYTES(sp)
  STORE x15, 9*REGBYTES(sp)
  STORE x16, 10*REGBYTES(sp)
  STORE x17, 11*REGBYTES(sp)
  STORE x28, 12*REGBYTES(sp)
  STORE x29, 13*REGBYTES(sp)
  STORE x30, 14*REGBYTES(sp)
  STORE x31, 15*REGBYTES(sp)
.endm

#restore caller registers
.macro TRAP_EXIT
# Remain in M-mode after mret
  li t0, MSTATUS_MPP
  csrs mstatus, t0

  LOAD x1,  0*REGBYTES(sp)
  LOAD x5,  1*REGBYTES(sp)
  LOAD x6,  2*REGBYTES(sp)
  LOAD x7,  3*REGBYTES(sp)
  LOAD x10, 4*REGBYTES(sp)
  LOAD x11, 5*REGBYTES(sp)
  LOAD x12, 6*REGBYTES(sp)
  LOAD x13, 7*REGBYTES(sp)
  LOAD x14, 8*REGBYTES(sp)
  LOAD x15, 9*REGBYTES(sp)
  LOAD x16, 10*REGBYTES(sp)
  LOAD x17, 11*REGBYTES(sp)
  LOAD x28, 12*REGBYTES(sp)
  LOAD x29, 13*REGBYTES(sp)
  LOAD x30, 14*REGBYTES(sp)
  LOAD x31, 15*REGBYTES(sp)

  addi sp, sp, 16*REGBYTES
  mret
.endm



#Vector table for E31/E51

  .section      .text.entry	
  .align 8
  .global vtrap_entry
vtrap_entry:
  j sync_trap
  .align 2
  j reserved
  .align 2
  j reserved
  .align 2
  j vmsi_Handler
  .align 2
  j reserved
  .align 2
  j reserved
  .align 2
  j reserved
  .align 2
  j vmti_Handler
  .align 2
  j reserved
  .align 2
  j reserved
  .align 2
  j reserved
  .align 2
  j vmei_Handler
  .align 2
  j reserved
  .align 2
  j reserved
  .align 2
  j reserved
   .align 2
  j reserved
  .align 2
  j vlip_Handler0
  .align 2
  j vlip_Handler1
  .align 2
  j vlip_Handler2
  .align 2
  j vlip_Handler3
  .align 2
  j vlip_Handler4
  .align 2
  j vlip_Handler5
  .align 2
  j vlip_Handler6
  .align 2
  j vlip_Handler7
  .align 2
  j vlip_Handler8
  .align 2
  j vlip_Handler9
  .align 2
  j vlip_Handler10
  .align 2
  j vlip_Handler11
  .align 2
  j vlip_Handler12
  .align 2
  j vlip_Handler13
  .align 2
  j vlip_Handler14
  .align 2
  j vlip_Handler15
  
#synchronous trap
sync_trap:
  TRAP_ENTRY
  jal handle_sync_trap
  TRAP_EXIT

#Machine Software Interrupt
vmsi_Handler:
  TRAP_ENTRY
  jal reserved
  TRAP_EXIT

#Machine Timer Interrupt
vmti_Handler:
  TRAP_ENTRY
  jal handle_m_time_interrupt
  TRAP_EXIT

#Machine External Interrupt
vmei_Handler:
  TRAP_ENTRY
  jal handle_m_external_interrupt
  TRAP_EXIT

#LIP0
vlip_Handler0:
  TRAP_ENTRY
  jal handle_local_interrupt0
  TRAP_EXIT

#LIP1
vlip_Handler1:
  TRAP_ENTRY
  jal handle_local_interrupt1
  TRAP_EXIT

#LIP2
vlip_Handler2:
  TRAP_ENTRY
  jal handle_local_interrupt2
  TRAP_EXIT

#LIP3
vlip_Handler3:
  TRAP_ENTRY
  jal handle_local_interrupt3
  TRAP_EXIT

#LIP4
vlip_Handler4:
  TRAP_ENTRY
  jal handle_local_interrupt4
  TRAP_EXIT

#LIP5
vlip_Handler5:
  TRAP_ENTRY
  jal handle_local_interrupt5
  TRAP_EXIT

#LIP6
vlip_Handler6:
  TRAP_ENTRY
  jal handle_local_interrupt6
  TRAP_EXIT

#LIP7
vlip_Handler7:
  TRAP_ENTRY
  jal handle_local_interrupt7
  TRAP_EXIT

#LIP8
vlip_Handler8:
  TRAP_ENTRY
  jal handle_local_interrupt8
  TRAP_EXIT

#LIP9
vlip_Handler9:
  TRAP_ENTRY
  jal handle_local_interrupt9
  TRAP_EXIT

#LIP10
vlip_Handler10:
  TRAP_ENTRY
  jal handle_local_interrupt10
  TRAP_EXIT

#LIP11
vlip_Handler11:
  TRAP_ENTRY
  jal handle_local_interrupt11
  TRAP_EXIT

#LIP12
vlip_Handler12:
  TRAP_ENTRY
  jal handle_local_interrupt12
  TRAP_EXIT

#LIP13
vlip_Handler13:
  TRAP_ENTRY
  jal handle_local_interrupt13
  TRAP_EXIT

#LIP14
vlip_Handler14:
  TRAP_ENTRY
  jal handle_local_interrupt14
  TRAP_EXIT

#LIP15
vlip_Handler15:
  TRAP_ENTRY
  jal handle_local_interrupt15
  TRAP_EXIT

#unimplemented ISRs trap here
.weak reserved
reserved:
.weak handle_local_interrupt0
handle_local_interrupt0:
.weak handle_local_interrupt1
handle_local_interrupt1:
.weak handle_local_interrupt2
handle_local_interrupt2:
.weak handle_local_interrupt3
handle_local_interrupt3:
.weak handle_local_interrupt4
handle_local_interrupt4:
.weak handle_local_interrupt5
handle_local_interrupt5:
.weak handle_local_interrupt6
handle_local_interrupt6:
.weak handle_local_interrupt7
handle_local_interrupt7:
.weak handle_local_interrupt8
handle_local_interrupt8:
.weak handle_local_interrupt9
handle_local_interrupt9:
.weak handle_local_interrupt10
handle_local_interrupt10:
.weak handle_local_interrupt11
handle_local_interrupt11:
.weak handle_local_interrupt12
handle_local_interrupt12:
.weak handle_local_interrupt13
handle_local_interrupt13:
.weak handle_local_interrupt14
handle_local_interrupt14:
.weak handle_local_interrupt15
handle_local_interrupt15:
1:
  j 1b
	
#endif