1 | /*
|
---|
2 | * TOPPERS/SSP Kernel
|
---|
3 | * Smallest Set Profile Kernel
|
---|
4 | *
|
---|
5 | * Copyright (C) 2018,2019 by Naoki Saito
|
---|
6 | * Nagoya Municipal Industrial Research Institute, JAPAN
|
---|
7 | *
|
---|
8 | * ä¸è¨èä½æ¨©è
|
---|
9 | ã¯ï¼ä»¥ä¸ã®(1)ã(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
10 | * ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
11 | * å¤ã»åé
|
---|
12 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
13 | * (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
14 | * 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
15 | * ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
16 | * (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
17 | * ç¨ã§ããå½¢ã§åé
|
---|
18 | å¸ããå ´åã«ã¯ï¼åé
|
---|
19 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
20 | * è
|
---|
21 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
22 | * ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
23 | * (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
24 | * ç¨ã§ããªãå½¢ã§åé
|
---|
25 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
26 | * ã¨ï¼
|
---|
27 | * (a) åé
|
---|
28 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
30 | * ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
31 | * (b) åé
|
---|
32 | å¸ã®å½¢æ
|
---|
33 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
34 | * å ±åãããã¨ï¼
|
---|
35 | * (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
36 | * 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
37 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
38 | 責ãããã¨ï¼
|
---|
39 | * ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
40 | * ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
41 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
42 | * å
|
---|
43 | 責ãããã¨ï¼
|
---|
44 | *
|
---|
45 | * æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
46 | ã
|
---|
47 | * ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
48 | * ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
49 | * ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
50 | * ã®è²¬ä»»ãè² ããªãï¼
|
---|
51 | *
|
---|
52 | */
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * ãããä¾åã¢ã¸ã¥ã¼ã« ã¢ã»ã³ããªè¨èªé¨(BCM2837)
|
---|
56 | */
|
---|
57 |
|
---|
58 | #define TOPPERS_MACRO_ONLY
|
---|
59 | #define UINT_C(val) (val) /* uint_tåã®å®æ°ãä½ããã¯ã */
|
---|
60 | #define ULONG_C(val) (val) /* ulong_tåã®å®æ°ãä½ããã¯ã */
|
---|
61 | #define UINT64_C(val) (val) /* uint64_tåã®å®æ°ãä½ããã¯ã */
|
---|
62 | #define CAST(type, val) (val) /* åãã£ã¹ããè¡ããã¯ã */
|
---|
63 |
|
---|
64 | #include "kernel_impl.h"
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * ä¾å¤å
|
---|
68 | ¥å£ã®æä½
|
---|
69 | * x22: excno(0..7)
|
---|
70 | */
|
---|
71 | .text
|
---|
72 | .align 2
|
---|
73 | .global chip_exc_entry
|
---|
74 | chip_exc_entry:
|
---|
75 | mov x0, sp
|
---|
76 | str x22, [x0, #8] // save excno in stack
|
---|
77 |
|
---|
78 | adrp x1, current_intpri // save int priority in stack
|
---|
79 | add x1, x1, :lo12:current_intpri
|
---|
80 | ldr w2, [x1]
|
---|
81 | str w2, [x0]
|
---|
82 |
|
---|
83 | mov x1, x22 // arg: excno
|
---|
84 | bl call_exc_handler
|
---|
85 |
|
---|
86 | // ä¾å¤çºçç´åã®Iãã©ã°ã¾ãã¯Fãã©ã°ã1ãªãã«ã¼ãã«ç®¡çå¤ã®CPUä¾å¤ã¨ã¿ãªã
|
---|
87 | ldr x3, [x0, #32] // SPSR --> x1
|
---|
88 | tst x3, #(3 << 6)
|
---|
89 | b.ne ret_exc
|
---|
90 |
|
---|
91 | // ã«ã¼ãã«ç®¡çã®CPUä¾å¤ã®å ´åã¯å²è¾¼ã¿ã®åºå£å¦çã¨å
|
---|
92 | ±é
|
---|
93 | msr daifclr, #AARCH64_DAIF_FIQ
|
---|
94 | b ret_int
|
---|
95 |
|
---|
96 | /*
|
---|
97 | * FIQã®å
|
---|
98 | ¥å£å¦ç
|
---|
99 | */
|
---|
100 | .text
|
---|
101 | .align 2
|
---|
102 | .global chip_fiq_entry
|
---|
103 | chip_fiq_entry:
|
---|
104 | ldr x30, =ret_fiq // return to ret_fiq
|
---|
105 | b call_fiq_handler
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * å²è¾¼ã¿å
|
---|
109 | ¥å£ã®æä½
|
---|
110 | */
|
---|
111 | .text
|
---|
112 | .align 2
|
---|
113 | .global chip_int_entry
|
---|
114 | chip_int_entry:
|
---|
115 | mov x0, sp
|
---|
116 | /*
|
---|
117 | * å²è¾¼ã¿è¦å ã®ç¹å®ã¨ä¿å
|
---|
118 | */
|
---|
119 | find_int_src_core: // find a interrupt source from core(core 0)
|
---|
120 | movz x1,#:abs_g1_nc:CORE0_IRQ_SRC
|
---|
121 | movk x1,#:abs_g0_nc:CORE0_IRQ_SRC
|
---|
122 | ldr w2, [x1]
|
---|
123 | mov x9, xzr
|
---|
124 | 1:
|
---|
125 | tst w2, #0x1
|
---|
126 | b.ne 2f
|
---|
127 | lsr w2, w2, #1
|
---|
128 | add w9, w9, #1
|
---|
129 | cmp w9, #32
|
---|
130 | b.ne 1b
|
---|
131 | 2:
|
---|
132 | cmp w9, #8 // pending interrupt is GPU interrupt
|
---|
133 | b.eq find_int_src_basic
|
---|
134 | cmp w9, #32 // pending interrupt is not found
|
---|
135 | b.eq find_int_src_basic
|
---|
136 | b find_int_src_exit
|
---|
137 |
|
---|
138 | find_int_src_basic: // basic pending register
|
---|
139 | mov w9, #32
|
---|
140 | movz x1,#:abs_g1_nc:IRQ_PEND_B
|
---|
141 | movk x1,#:abs_g0_nc:IRQ_PEND_B
|
---|
142 | ldr w2, [x1]
|
---|
143 | 1:
|
---|
144 | tst w2, #0x1
|
---|
145 | b.ne 2f
|
---|
146 | lsr w2, w2, #1
|
---|
147 | add w9, w9, #1
|
---|
148 | cmp w9, #64
|
---|
149 | b.ne 1b
|
---|
150 | 2:
|
---|
151 | cmp w9, #(32+8) // GPU pending register 1
|
---|
152 | b.eq find_int_src_gpu1
|
---|
153 | cmp w9, #(32+9) // GPU pending register 2
|
---|
154 | b.eq find_int_src_gpu2
|
---|
155 | cmp w9, #(32+10) // GPU irq 7
|
---|
156 | b.eq gpu_irq_7
|
---|
157 | cmp w9, #(32+11) // GPU irq 9
|
---|
158 | b.eq gpu_irq_9
|
---|
159 | cmp w9, #(32+12) // GPU irq 10
|
---|
160 | b.eq gpu_irq_10
|
---|
161 | cmp w9, #(32+13) // GPU irq 18
|
---|
162 | b.eq gpu_irq_18
|
---|
163 | cmp w9, #(32+14) // GPU irq 19
|
---|
164 | b.eq gpu_irq_19
|
---|
165 | cmp w9, #(32+15) // GPU irq 53
|
---|
166 | b.eq gpu_irq_53
|
---|
167 | cmp w9, #(32+16) // GPU irq 54
|
---|
168 | b.eq gpu_irq_54
|
---|
169 | cmp w9, #(32+17) // GPU irq 55
|
---|
170 | b.eq gpu_irq_55
|
---|
171 | cmp w9, #(32+18) // GPU irq 56
|
---|
172 | b.eq gpu_irq_56
|
---|
173 | cmp w9, #(32+19) // GPU irq 57
|
---|
174 | b.eq gpu_irq_57
|
---|
175 | cmp w9, #(32+20) // GPU irq 62
|
---|
176 | b.eq gpu_irq_62
|
---|
177 | cmp w9, #64 // pending interrupt is not found
|
---|
178 | b.eq find_int_src_gpu1
|
---|
179 |
|
---|
180 | b find_int_src_exit // others
|
---|
181 |
|
---|
182 | gpu_irq_7:
|
---|
183 | mov w9, #(64+7)
|
---|
184 | b find_int_src_exit
|
---|
185 | gpu_irq_9:
|
---|
186 | mov w9, #(64+9)
|
---|
187 | b find_int_src_exit
|
---|
188 | gpu_irq_10:
|
---|
189 | mov w9, #(64+10)
|
---|
190 | b find_int_src_exit
|
---|
191 | gpu_irq_18:
|
---|
192 | mov w9, #(64+18)
|
---|
193 | b find_int_src_exit
|
---|
194 | gpu_irq_19:
|
---|
195 | mov w9, #(64+19)
|
---|
196 | b find_int_src_exit
|
---|
197 | gpu_irq_53:
|
---|
198 | mov w9, #(64+53)
|
---|
199 | b find_int_src_exit
|
---|
200 | gpu_irq_54:
|
---|
201 | mov w9, #(64+54)
|
---|
202 | b find_int_src_exit
|
---|
203 | gpu_irq_55:
|
---|
204 | mov w9, #(64+55)
|
---|
205 | b find_int_src_exit
|
---|
206 | gpu_irq_56:
|
---|
207 | mov w9, #(64+56)
|
---|
208 | b find_int_src_exit
|
---|
209 | gpu_irq_57:
|
---|
210 | mov w9, #(64+57)
|
---|
211 | b find_int_src_exit
|
---|
212 | gpu_irq_62:
|
---|
213 | mov w9, #(64+62)
|
---|
214 | b find_int_src_exit
|
---|
215 |
|
---|
216 | find_int_src_gpu1: // GPU pending register 1
|
---|
217 | mov w9, #64
|
---|
218 | movz x1,#:abs_g1_nc:IRQ_PEND_1
|
---|
219 | movk x1,#:abs_g0_nc:IRQ_PEND_1
|
---|
220 | ldr w2, [x1]
|
---|
221 | 1:
|
---|
222 | tst w2, #0x1
|
---|
223 | b.ne 2f
|
---|
224 | lsr w2, w2, #1
|
---|
225 | add w9, w9, #1
|
---|
226 | cmp w9, #96
|
---|
227 | b.ne 1b
|
---|
228 | 2:
|
---|
229 | cmp w9, #96 // pending interrupt is not found
|
---|
230 | b.eq find_int_src_gpu2
|
---|
231 | b find_int_src_exit
|
---|
232 |
|
---|
233 | find_int_src_gpu2: // GPU pending register 2
|
---|
234 | mov w9, #96
|
---|
235 | movz x1,#:abs_g1_nc:IRQ_PEND_2
|
---|
236 | movk x1,#:abs_g0_nc:IRQ_PEND_2
|
---|
237 | ldr w2, [x1]
|
---|
238 | 1:
|
---|
239 | tst w2, #0x1
|
---|
240 | b.ne find_int_src_exit
|
---|
241 | lsr w2, w2, #1
|
---|
242 | add w9, w9, #1
|
---|
243 | cmp w9, #128 // pending interrupt is not found (and interrupt source is unknown)
|
---|
244 | b.ne 1b
|
---|
245 |
|
---|
246 | find_int_src_exit:
|
---|
247 | cmp w9, #128
|
---|
248 | b.eq ret_int
|
---|
249 | str w9, [x0, #8] // save intno to (sp+8)
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * å²è¾¼ã¿çºçç´åã®å²è¾¼ã¿åªå
|
---|
253 | 度ï¼å
|
---|
254 | é¨è¡¨ç¾ï¼ãä¿å
|
---|
255 | */
|
---|
256 | adrp x1, current_intpri
|
---|
257 | add x1, x1, :lo12:current_intpri
|
---|
258 | ldr w2, [x1]
|
---|
259 | str w2, [x0]
|
---|
260 |
|
---|
261 | /*
|
---|
262 | * å²è¾¼ã¿è¦å ã®åªå
|
---|
263 | 度ãåå¾
|
---|
264 | */
|
---|
265 | adrp x3, _kernel_intpri_table
|
---|
266 | add x3, x3, #:lo12:_kernel_intpri_table
|
---|
267 | ldr w4, [x3, x9, lsl #2]
|
---|
268 |
|
---|
269 | // çºçããå²è¾¼ã¿ã®åªå
|
---|
270 | 度ããã¨ã«å²è¾¼ã¿ããã¹ã¯
|
---|
271 | mov w0, w4 // arg: intpri
|
---|
272 | bl chip_mask_interrupt
|
---|
273 |
|
---|
274 | // D,A,F ãã©ã°ãã¯ãªã¢ãã¦ãã(CPUããã¯ç¸å½ã«ãã)
|
---|
275 | msr daifclr, #(AARCH64_DAIF_DBG | AARCH64_DAIF_SERR | AARCH64_DAIF_FIQ)
|
---|
276 |
|
---|
277 | // ãã³ãã©å¼ã³åºã
|
---|
278 | mov x0, sp
|
---|
279 | ldr w9, [x0, #8]
|
---|
280 | mov w0, w9 // arg: intno
|
---|
281 | bl call_int_handler
|
---|
282 | /* ãã®ã¾ã¾ chip_ret_int 㸠*/
|
---|
283 |
|
---|
284 | /*
|
---|
285 | * å²è¾¼ã¿åºå£ã®GICæä½
|
---|
286 | */
|
---|
287 | chip_ret_int:
|
---|
288 | // å²è¾¼ã¿çºçåã®åªå
|
---|
289 | 度ã«æ»ã
|
---|
290 | mov x0, sp
|
---|
291 | adrp x1, current_intpri
|
---|
292 | add x1, x1, :lo12:current_intpri
|
---|
293 | ldr w2, [x0] // previous int priority
|
---|
294 | str w2, [x1]
|
---|
295 |
|
---|
296 | // åªå
|
---|
297 | 度ãå
|
---|
298 | ã«å²è¾¼ã¿ã®ãã¹ã¯ãæ»ã
|
---|
299 | mov w0, w2
|
---|
300 | bl chip_unmask_interrupt
|
---|
301 |
|
---|
302 | b ret_int
|
---|