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 #include <linux/sys.h>
28 #include <linux/linkage.h>
29 #include <asm/asm-offsets.h>
30 #include <asm/asm-macros.h>
31 #include <asm/thread_info.h>
32 #include <asm/errno.h>
33 #include <asm/setup.h>
34 #include <asm/entry.h>
35 #include <asm/unistd.h>
36 #include <asm/processor.h>
37
38 .macro GET_THREAD_INFO reg
39 .if THREAD_SIZE & 0xffff0000
40 andhi \reg, sp, %hi(~(THREAD_SIZE-1))
41 .else
42 addi \reg, r0, %lo(~(THREAD_SIZE-1))
43 and \reg, \reg, sp
44 .endif
45 .endm
46
47 .macro kuser_cmpxchg_check
48
49
50
51
52
53
54
55
56
57
58 movui et, (KUSER_BASE + 4 + (cmpxchg_stw - __kuser_helper_start))
59 bgtu ea, et, 1f
60
61 subi et, et, (cmpxchg_stw - cmpxchg_ldw)
62 bltu ea, et, 1f
63 stw et, PT_EA(sp)
64 mov ea, et
65 1:
66 .endm
67
68 .section .rodata
69 .align 4
70 exception_table:
71 .word unhandled_exception
72 .word unhandled_exception
73 .word external_interrupt
74 .word handle_trap
75
76 .word instruction_trap
77 .word handle_illegal
78 .word handle_unaligned
79 .word handle_unaligned
80
81 .word handle_diverror
82 .word protection_exception_ba
83 .word protection_exception_instr
84 .word protection_exception_ba
85
86 .word unhandled_exception
87 .word protection_exception_pte
88 .word protection_exception_pte
89 .word protection_exception_pte
90
91 .word unhandled_exception
92
93 trap_table:
94 .word handle_system_call
95 .word handle_trap_1
96 .word handle_trap_2
97 .word handle_trap_3
98 .word handle_trap_reserved
99 .word handle_trap_reserved
100 .word handle_trap_reserved
101 .word handle_trap_reserved
102 .word handle_trap_reserved
103 .word handle_trap_reserved
104 .word handle_trap_reserved
105 .word handle_trap_reserved
106 .word handle_trap_reserved
107 .word handle_trap_reserved
108 .word handle_trap_reserved
109 .word handle_trap_reserved
110 .word handle_trap_reserved
111 .word handle_trap_reserved
112 .word handle_trap_reserved
113 .word handle_trap_reserved
114 .word handle_trap_reserved
115 .word handle_trap_reserved
116 .word handle_trap_reserved
117 .word handle_trap_reserved
118 .word handle_trap_reserved
119 .word handle_trap_reserved
120 .word handle_trap_reserved
121 .word handle_trap_reserved
122 .word handle_trap_reserved
123 .word handle_trap_reserved
124 #ifdef CONFIG_KGDB
125 .word handle_kgdb_breakpoint
126 #else
127 .word instruction_trap
128 #endif
129 .word handle_breakpoint
130
131 .text
132 .set noat
133 .set nobreak
134
135 ENTRY(inthandler)
136 SAVE_ALL
137
138 kuser_cmpxchg_check
139
140
141
142
143
144
145 rdctl r24, status
146 movi r9, %lo(~STATUS_EH)
147 and r24, r24, r9
148 wrctl status, r24
149
150
151 mov r4, sp
152 rdctl r5, exception
153 movia r9, exception_table
154 add r24, r9, r5
155 ldw r24, 0(r24)
156 jmp r24
157
158
159
160
161
162
163 ENTRY(handle_trap)
164 ldwio r24, -4(ea)
165 srli r24, r24, 4
166 andi r24, r24, 0x7c
167 movia r9,trap_table
168 add r24, r24, r9
169 ldw r24, 0(r24)
170 jmp r24
171
172
173
174
175
176
177 ENTRY(handle_system_call)
178
179 rdctl r10, status
180 ori r10, r10, STATUS_PIE
181 wrctl status, r10
182
183
184 ldw r4, PT_R4(sp)
185 ldw r5, PT_R5(sp)
186
187 local_restart:
188
189 movui r1, __NR_syscalls
190 bgeu r2, r1, ret_invsyscall
191 slli r1, r2, 2
192 movhi r11, %hiadj(sys_call_table)
193 add r1, r1, r11
194 ldw r1, %lo(sys_call_table)(r1)
195 beq r1, r0, ret_invsyscall
196
197
198 GET_THREAD_INFO r11
199 ldw r11,TI_FLAGS(r11)
200 BTBNZ r11,r11,TIF_SYSCALL_TRACE,traced_system_call
201
202
203 callr r1
204
205
206
207
208
209
210
211
212
213 translate_rc_and_ret:
214 movi r1, 0
215 bge r2, zero, 3f
216 sub r2, zero, r2
217 movi r1, 1
218 3:
219 stw r2, PT_R2(sp)
220 stw r1, PT_R7(sp)
221 end_translate_rc_and_ret:
222
223 ret_from_exception:
224 ldw r1, PT_ESTATUS(sp)
225
226 TSTBNZ r1, r1, ESTATUS_EU, Luser_return
227
228 restore_all:
229 rdctl r10, status
230 andi r10, r10, %lo(~STATUS_PIE)
231 wrctl status, r10
232 RESTORE_ALL
233 eret
234
235
236 ret_invsyscall:
237 movi r2, -ENOSYS
238 br translate_rc_and_ret
239
240
241
242
243
244 traced_system_call:
245 SAVE_SWITCH_STACK
246 call do_syscall_trace_enter
247 RESTORE_SWITCH_STACK
248
249
250
251
252 ldw r2, PT_R2(sp)
253 ldw r4, PT_R4(sp)
254 ldw r5, PT_R5(sp)
255 ldw r6, PT_R6(sp)
256 ldw r7, PT_R7(sp)
257
258
259
260
261 slli r1, r2, 2
262 movhi r11,%hiadj(sys_call_table)
263 add r1, r1, r11
264 ldw r1, %lo(sys_call_table)(r1)
265
266 callr r1
267
268
269
270
271
272
273
274
275
276 translate_rc_and_ret2:
277 movi r1, 0
278 bge r2, zero, 4f
279 sub r2, zero, r2
280 movi r1, 1
281 4:
282 stw r2, PT_R2(sp)
283 stw r1, PT_R7(sp)
284 end_translate_rc_and_ret2:
285 SAVE_SWITCH_STACK
286 call do_syscall_trace_exit
287 RESTORE_SWITCH_STACK
288 br ret_from_exception
289
290 Luser_return:
291 GET_THREAD_INFO r11
292 ldw r10, TI_FLAGS(r11)
293 ANDI32 r11, r10, _TIF_WORK_MASK
294 beq r11, r0, restore_all
295 BTBZ r1, r10, TIF_NEED_RESCHED, Lsignal_return
296
297
298 call schedule
299 br ret_from_exception
300
301 Lsignal_return:
302 ANDI32 r1, r10, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
303 beq r1, r0, restore_all
304 mov r4, sp
305 SAVE_SWITCH_STACK
306 call do_notify_resume
307 beq r2, r0, no_work_pending
308 RESTORE_SWITCH_STACK
309
310 ldw r2, PT_R2(sp)
311 ldw r4, PT_R4(sp)
312 ldw r5, PT_R5(sp)
313 ldw r6, PT_R6(sp)
314 ldw r7, PT_R7(sp)
315 ldw r8, PT_R8(sp)
316 ldw r9, PT_R9(sp)
317 br local_restart
318
319 no_work_pending:
320 RESTORE_SWITCH_STACK
321 br ret_from_exception
322
323
324
325
326
327
328
329
330
331
332 external_interrupt:
333 rdctl r12, ipending
334 rdctl r9, ienable
335 and r12, r12, r9
336
337 beq r12, r0, ret_from_interrupt
338
339 movi r24, -1
340 stw r24, PT_ORIG_R2(sp)
341
342
343
344
345
346 addi ea, ea, -4
347 stw ea, PT_EA(sp)
348 2: movi r4, %lo(-1)
349
350
351 1: andi r10, r12, 1
352 srli r12, r12, 1
353
354 addi r4, r4, 1
355 beq r10, r0, 1b
356 mov r5, sp
357 call do_IRQ
358 rdctl r12, ipending
359 rdctl r9, ienable
360 and r12, r12, r9
361 bne r12, r0, 2b
362
363
364 ENTRY(ret_from_interrupt)
365 ldw r1, PT_ESTATUS(sp)
366 TSTBNZ r1, r1, ESTATUS_EU, Luser_return
367
368 #ifdef CONFIG_PREEMPT
369 GET_THREAD_INFO r1
370 ldw r4, TI_PREEMPT_COUNT(r1)
371 bne r4, r0, restore_all
372 ldw r4, TI_FLAGS(r1)
373 BTBZ r10, r4, TIF_NEED_RESCHED, restore_all
374 ldw r4, PT_ESTATUS(sp)
375 andi r10, r4, ESTATUS_EPIE
376 beq r10, r0, restore_all
377 call preempt_schedule_irq
378 #endif
379 br restore_all
380
381
382
383
384
385
386
387
388
389
390 ENTRY(sys_clone)
391 SAVE_SWITCH_STACK
392 addi sp, sp, -4
393 stw r7, 0(sp)
394 mov r7, r6
395 mov r6, zero
396 call do_fork
397 addi sp, sp, 4
398 RESTORE_SWITCH_STACK
399 ret
400
401 ENTRY(sys_rt_sigreturn)
402 SAVE_SWITCH_STACK
403 mov r4, sp
404 call do_rt_sigreturn
405 RESTORE_SWITCH_STACK
406 addi ra, ra, (end_translate_rc_and_ret - translate_rc_and_ret)
407 ret
408
409
410
411
412
413 protection_exception_pte:
414 rdctl r6, pteaddr
415 slli r6, r6, 10
416 call do_page_fault
417 br ret_from_exception
418
419 protection_exception_ba:
420 rdctl r6, badaddr
421 call do_page_fault
422 br ret_from_exception
423
424 protection_exception_instr:
425 call handle_supervisor_instr
426 br ret_from_exception
427
428 handle_breakpoint:
429 call breakpoint_c
430 br ret_from_exception
431
432 #ifdef CONFIG_NIOS2_ALIGNMENT_TRAP
433 handle_unaligned:
434 SAVE_SWITCH_STACK
435 call handle_unaligned_c
436 RESTORE_SWITCH_STACK
437 br ret_from_exception
438 #else
439 handle_unaligned:
440 call handle_unaligned_c
441 br ret_from_exception
442 #endif
443
444 handle_illegal:
445 call handle_illegal_c
446 br ret_from_exception
447
448 handle_diverror:
449 call handle_diverror_c
450 br ret_from_exception
451
452 #ifdef CONFIG_KGDB
453 handle_kgdb_breakpoint:
454 call kgdb_breakpoint_c
455 br ret_from_exception
456 #endif
457
458 handle_trap_1:
459 call handle_trap_1_c
460 br ret_from_exception
461
462 handle_trap_2:
463 call handle_trap_2_c
464 br ret_from_exception
465
466 handle_trap_3:
467 handle_trap_reserved:
468 call handle_trap_3_c
469 br ret_from_exception
470
471
472
473
474
475
476 ENTRY(resume)
477
478 rdctl r7, status
479 stw r7, TASK_THREAD + THREAD_KPSR(r4)
480
481 andi r7, r7, %lo(~STATUS_PIE)
482 wrctl status, r7
483
484 SAVE_SWITCH_STACK
485 stw sp, TASK_THREAD + THREAD_KSP(r4)
486 ldw sp, TASK_THREAD + THREAD_KSP(r5)
487 movia r24, _current_thread
488 GET_THREAD_INFO r1
489 stw r1, 0(r24)
490 RESTORE_SWITCH_STACK
491
492 ldw r7, TASK_THREAD + THREAD_KPSR(r5)
493 wrctl status, r7
494 ret
495
496 ENTRY(ret_from_fork)
497 call schedule_tail
498 br ret_from_exception
499
500 ENTRY(ret_from_kernel_thread)
501 call schedule_tail
502 mov r4,r17
503 callr r16
504 br ret_from_exception
505
506
507
508
509
510
511
512
513
514
515
516
517 .macro kuser_pad sym size
518 .if ((. - \sym) & 3)
519 .rept (4 - (. - \sym) & 3)
520 .byte 0
521 .endr
522 .endif
523 .rept ((\size - (. - \sym)) / 4)
524 .word 0xdeadbeef
525 .endr
526 .endm
527
528 .align 6
529 .globl __kuser_helper_start
530 __kuser_helper_start:
531
532 __kuser_helper_version:
533 .word ((__kuser_helper_end - __kuser_helper_start) >> 6)
534
535 __kuser_cmpxchg:
536
537
538
539
540
541 cmpxchg_ldw:
542 ldw r2, 0(r4)
543 sub r2, r2, r5
544 bne r2, zero, cmpxchg_ret
545
546
547 cmpxchg_stw:
548 stw r6, 0(r4)
549 cmpxchg_ret:
550 ret
551
552 kuser_pad __kuser_cmpxchg, 64
553
554 .globl __kuser_sigtramp
555 __kuser_sigtramp:
556 movi r2, __NR_rt_sigreturn
557 trap
558
559 kuser_pad __kuser_sigtramp, 64
560
561 .globl __kuser_helper_end
562 __kuser_helper_end: