1 /* break.S: Break interrupt handling (kept separate from entry.S)
3 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/sys.h>
13 #include <linux/config.h>
14 #include <linux/linkage.h>
15 #include <asm/setup.h>
16 #include <asm/segment.h>
17 #include <asm/ptrace.h>
18 #include <asm/spr-regs.h>
20 #include <asm/errno.h>
23 # the break handler has its own stack
26 .globl __break_user_context
29 .space (8192 - (USER_CONTEXT_SIZE + REG__DEBUG_XTRA)) & ~7
31 .space REG__DEBUG_XTRA
33 .space USER_CONTEXT_SIZE
36 # miscellaneous variables
40 .globl __break_tlb_miss_real_return_info
41 __break_tlb_miss_real_return_info:
43 .space 2*4 /* saved PCSR, PSR for TLB-miss handler fixup */
46 __break_trace_through_exceptions:
49 #define CS2_ECS1 0xe1200000
50 #define CS2_USERLED 0x4
53 # sethi.p %hi(CS2_ECS1+CS2_USERLED),gr30
54 # setlo %lo(CS2_ECS1+CS2_USERLED),gr30
58 # sethi.p %hi(0xffc00100),gr30
59 # setlo %lo(0xffc00100),gr30
60 # sth \reg,@(gr30,gr0)
64 ###############################################################################
66 # entry point for Break Exceptions/Interrupts
68 ###############################################################################
78 sethi.p %hi(__break_user_context),gr31
79 setlo %lo(__break_user_context),gr31
81 stdi gr2,@(gr31,#REG_GR(2))
83 sti gr3,@(gr31,#REG_CCR)
85 # catch the return from a TLB-miss handler that had single-step disabled
86 # traps will be enabled, so we have to do this now
89 sethi.p %hi(__break_tlb_miss_return_breaks_here),gr2
90 setlo %lo(__break_tlb_miss_return_breaks_here),gr2
91 subcc gr2,gr3,gr0,icc0
92 beq icc0,#2,__break_return_singlestep_tlbmiss
95 # determine whether we have stepped through into an exception
96 # - we need to take special action to suspend h/w single stepping if we've done
97 # that, so that the gdbstub doesn't get bogged down endlessly stepping through
98 # external interrupt handling
100 andicc gr3,#BPSR_BET,gr0,icc0
101 bne icc0,#2,__break_maybe_userspace /* jump if PSR.ET was 1 */
106 andicc gr3,#BRR_ST,gr0,icc0
107 andicc.p gr3,#BRR_SB,gr0,icc1
108 bne icc0,#2,__break_step /* jump if single-step caused break */
109 beq icc1,#2,__break_continue /* jump if BREAK didn't cause break */
113 # handle special breaks
116 sethi.p %hi(__entry_return_singlestep_breaks_here),gr2
117 setlo %lo(__entry_return_singlestep_breaks_here),gr2
118 subcc gr2,gr3,gr0,icc0
119 beq icc0,#2,__break_return_singlestep
124 ###############################################################################
126 # handle BREAK instruction in kernel-mode exception epilogue
128 ###############################################################################
129 __break_return_singlestep:
132 # special break insn requests single-stepping to be turned back on
137 # BPSR.ET 0 1 (can't have caused orig excep otherwise)
138 # BPSR.BS 1 old PSR.S
140 sethi.p %hi(DCR_SE),gr3
141 setlo %lo(DCR_SE),gr3
147 slli gr2,#11,gr2 /* PSR.PS -> BPSR.BS */
148 ori gr2,#BPSR_BET,gr2 /* 1 -> BPSR.BET */
151 # return to the invoker of the original kernel exception
157 ldi @(gr31,#REG_CCR),gr3
159 lddi.p @(gr31,#REG_GR(2)),gr2
167 ###############################################################################
169 # handle BREAK instruction in TLB-miss handler return path
171 ###############################################################################
173 __break_return_singlestep_tlbmiss:
176 sethi.p %hi(__break_tlb_miss_real_return_info),gr3
177 setlo %lo(__break_tlb_miss_real_return_info),gr3
182 bra __break_return_singlestep
186 ###############################################################################
188 # handle single stepping into an exception prologue from kernel mode
189 # - we try and catch it whilst it is still in the main vector table
190 # - if we catch it there, we have to jump to the fixup handler
191 # - there is a fixup table that has a pointer for every 16b slot in the trap
194 ###############################################################################
198 # external interrupts seem to escape from the trap table before single
199 # step catches up with them
201 sethi.p %hi(__entry_kernel_external_interrupt),gr3
202 setlo %lo(__entry_kernel_external_interrupt),gr3
203 subcc gr2,gr3,gr0,icc0
204 beq icc0,#2,__break_step_kernel_external_interrupt
205 sethi.p %hi(__entry_uspace_external_interrupt),gr3
206 setlo %lo(__entry_uspace_external_interrupt),gr3
207 subcc gr2,gr3,gr0,icc0
208 beq icc0,#2,__break_step_uspace_external_interrupt
212 # the two main vector tables are adjacent on one 8Kb slab
214 setlos #0xffffe000,gr3
216 sethi.p %hi(__trap_tables),gr3
217 setlo %lo(__trap_tables),gr3
218 subcc gr2,gr3,gr0,icc0
219 bne icc0,#2,__break_continue
223 # skip workaround if so requested by GDB
224 sethi.p %hi(__break_trace_through_exceptions),gr3
225 setlo %lo(__break_trace_through_exceptions),gr3
227 subcc gr3,gr0,gr0,icc0
228 bne icc0,#0,__break_continue
232 # access the fixup table - there's a 1:1 mapping between the slots in the trap tables and
233 # the slots in the trap fixup tables allowing us to simply divide the offset into the
234 # former by 4 to access the latter
235 sethi.p %hi(__trap_tables),gr3
236 setlo %lo(__trap_tables),gr3
241 sethi %hi(__trap_fixup_tables),gr3
242 setlo.p %lo(__trap_fixup_tables),gr3
247 # step through an internal exception from kernel mode
248 .globl __break_step_kernel_softprog_interrupt
249 __break_step_kernel_softprog_interrupt:
250 sethi.p %hi(__entry_kernel_softprog_interrupt_reentry),gr3
251 setlo %lo(__entry_kernel_softprog_interrupt_reentry),gr3
252 bra __break_return_as_kernel_prologue
254 # step through an external interrupt from kernel mode
255 .globl __break_step_kernel_external_interrupt
256 __break_step_kernel_external_interrupt:
257 sethi.p %hi(__entry_kernel_external_interrupt_reentry),gr3
258 setlo %lo(__entry_kernel_external_interrupt_reentry),gr3
260 __break_return_as_kernel_prologue:
265 # do the bit we had to skip
267 movsg ear0,gr2 /* EAR0 can get clobbered by gdb-stub (ICI/ICEI) */
271 or.p sp,gr0,gr2 /* set up the stack pointer */
273 sti.p gr2,@(sp,#REG_SP)
275 setlos #REG__STATUS_STEP,gr2
276 sti gr2,@(sp,#REG__STATUS) /* record single step status */
278 # cancel single-stepping mode
280 sethi.p %hi(~DCR_SE),gr3
281 setlo %lo(~DCR_SE),gr3
287 ldi @(gr31,#REG_CCR),gr3
289 lddi.p @(gr31,#REG_GR(2)),gr2
297 # step through an internal exception from uspace mode
298 .globl __break_step_uspace_softprog_interrupt
299 __break_step_uspace_softprog_interrupt:
300 sethi.p %hi(__entry_uspace_softprog_interrupt_reentry),gr3
301 setlo %lo(__entry_uspace_softprog_interrupt_reentry),gr3
302 bra __break_return_as_uspace_prologue
304 # step through an external interrupt from kernel mode
305 .globl __break_step_uspace_external_interrupt
306 __break_step_uspace_external_interrupt:
307 sethi.p %hi(__entry_uspace_external_interrupt_reentry),gr3
308 setlo %lo(__entry_uspace_external_interrupt_reentry),gr3
310 __break_return_as_uspace_prologue:
315 # do the bit we had to skip
316 sethi.p %hi(__kernel_frame0_ptr),gr28
317 setlo %lo(__kernel_frame0_ptr),gr28
318 ldi.p @(gr28,#0),gr28
320 setlos #REG__STATUS_STEP,gr2
321 sti gr2,@(gr28,#REG__STATUS) /* record single step status */
323 # cancel single-stepping mode
325 sethi.p %hi(~DCR_SE),gr3
326 setlo %lo(~DCR_SE),gr3
332 ldi @(gr31,#REG_CCR),gr3
334 lddi.p @(gr31,#REG_GR(2)),gr2
343 # step through an ITLB-miss handler from user mode
344 .globl __break_user_insn_tlb_miss
345 __break_user_insn_tlb_miss:
346 # we'll want to try the trap stub again
347 sethi.p %hi(__trap_user_insn_tlb_miss),gr2
348 setlo %lo(__trap_user_insn_tlb_miss),gr2
351 __break_tlb_miss_common:
354 # cancel single-stepping mode
356 sethi.p %hi(~DCR_SE),gr3
357 setlo %lo(~DCR_SE),gr3
361 # we'll swap the real return address for one with a BREAK insn so that we can re-enable
362 # single stepping on return
364 sethi.p %hi(__break_tlb_miss_real_return_info),gr3
365 setlo %lo(__break_tlb_miss_real_return_info),gr3
368 sethi.p %hi(__break_tlb_miss_return_break),gr2
369 setlo %lo(__break_tlb_miss_return_break),gr2
372 # we also have to fudge PSR because the return BREAK is in kernel space and we want
373 # to get a BREAK fault not an access violation should the return be to userspace
381 ldi @(gr31,#REG_CCR),gr3
383 lddi @(gr31,#REG_GR(2)),gr2
388 # step through a DTLB-miss handler from user mode
389 .globl __break_user_data_tlb_miss
390 __break_user_data_tlb_miss:
391 # we'll want to try the trap stub again
392 sethi.p %hi(__trap_user_data_tlb_miss),gr2
393 setlo %lo(__trap_user_data_tlb_miss),gr2
395 bra __break_tlb_miss_common
397 # step through an ITLB-miss handler from kernel mode
398 .globl __break_kernel_insn_tlb_miss
399 __break_kernel_insn_tlb_miss:
400 # we'll want to try the trap stub again
401 sethi.p %hi(__trap_kernel_insn_tlb_miss),gr2
402 setlo %lo(__trap_kernel_insn_tlb_miss),gr2
404 bra __break_tlb_miss_common
406 # step through a DTLB-miss handler from kernel mode
407 .globl __break_kernel_data_tlb_miss
408 __break_kernel_data_tlb_miss:
409 # we'll want to try the trap stub again
410 sethi.p %hi(__trap_kernel_data_tlb_miss),gr2
411 setlo %lo(__trap_kernel_data_tlb_miss),gr2
413 bra __break_tlb_miss_common
416 ###############################################################################
418 # handle debug events originating with userspace
420 ###############################################################################
421 __break_maybe_userspace:
425 andcc gr3,gr2,gr0,icc0
426 bne icc0,#0,__break_continue /* skip if PSR.S was 1 */
429 andicc gr2,#BRR_ST|BRR_SB,gr0,icc0
430 beq icc0,#0,__break_continue /* jump if not BREAK or single-step */
434 # do the first part of the exception prologue here
435 sethi.p %hi(__kernel_frame0_ptr),gr28
436 setlo %lo(__kernel_frame0_ptr),gr28
440 # set up the kernel stack pointer
441 sti sp ,@(gr28,#REG_SP)
443 sti gr0 ,@(gr28,#REG_GR(28))
445 stdi gr20,@(gr28,#REG_GR(20))
446 stdi gr22,@(gr28,#REG_GR(22))
452 # determine the exception type and cancel single-stepping mode
456 sethi.p %hi(DCR_SE),gr3
457 setlo %lo(DCR_SE),gr3
458 andcc gr2,gr3,gr0,icc0
459 beq icc0,#0,__break_no_user_sstep /* must have been a BREAK insn */
464 ori gr23,#REG__STATUS_STEP,gr23
466 __break_no_user_sstep:
470 andi gr2,#BRR_ST|BRR_SB,gr2
473 sti.p gr23,@(gr28,#REG__STATUS) /* record single step status */
475 # adjust the value acquired from TBR - this indicates the exception
478 setlos #TBR_TT_BREAK,gr2
481 # fudge PSR.PS and BPSR.BS to return to kernel mode through the trap
483 andi gr22,#~PSR_PS,gr22 /* PSR.PS should be 0 */
486 setlos #BPSR_BS,gr2 /* BPSR.BS should be 1 and BPSR.BET 0 */
489 # return through remainder of the exception prologue
490 # - need to load gr23 with return handler address
491 sethi.p %hi(__entry_return_from_user_exception),gr23
492 setlo %lo(__entry_return_from_user_exception),gr23
493 sethi.p %hi(__entry_common),gr3
494 setlo %lo(__entry_common),gr3
499 ldi @(gr31,#REG_CCR),gr3
501 lddi.p @(gr31,#REG_GR(2)),gr2
509 ###############################################################################
511 # resume normal debug-mode entry
513 ###############################################################################
517 # set up the kernel stack pointer
518 sti sp,@(gr31,#REG_SP)
520 sethi.p %hi(__break_stack_tos),sp
521 setlo %lo(__break_stack_tos),sp
523 # finish building the exception frame
524 stdi gr4 ,@(gr31,#REG_GR(4))
525 stdi gr6 ,@(gr31,#REG_GR(6))
526 stdi gr8 ,@(gr31,#REG_GR(8))
527 stdi gr10,@(gr31,#REG_GR(10))
528 stdi gr12,@(gr31,#REG_GR(12))
529 stdi gr14,@(gr31,#REG_GR(14))
530 stdi gr16,@(gr31,#REG_GR(16))
531 stdi gr18,@(gr31,#REG_GR(18))
532 stdi gr20,@(gr31,#REG_GR(20))
533 stdi gr22,@(gr31,#REG_GR(22))
534 stdi gr24,@(gr31,#REG_GR(24))
535 stdi gr26,@(gr31,#REG_GR(26))
536 sti gr0 ,@(gr31,#REG_GR(28)) /* NULL frame pointer */
537 sti gr29,@(gr31,#REG_GR(29))
538 sti gr30,@(gr31,#REG_GR(30))
539 sti gr8 ,@(gr31,#REG_ORIG_GR8)
543 sti gr19,@(gr31,#REG_GR(31))
555 andi.p gr22,#~(PSR_S|PSR_ET),gr5 /* rebuild PSR */
556 andi gr19,#PSR_ET,gr4
563 sti gr20,@(gr31,#REG_TBR)
564 sti gr21,@(gr31,#REG_PC)
565 sti gr5 ,@(gr31,#REG_PSR)
566 sti gr23,@(gr31,#REG_ISR)
567 sti gr25,@(gr31,#REG_CCCR)
568 stdi gr26,@(gr31,#REG_LR)
569 sti gr6 ,@(gr31,#REG_SYSCALLNO)
571 # store CPU-specific regs
574 stdi gr4,@(gr31,#REG_IACC0)
578 stdi gr4,@(gr31,#REG_GNER0)
580 # build the debug register frame
586 stdi gr4 ,@(gr31,#REG_BRR)
587 sti gr19,@(gr31,#REG_BPSR)
588 sti.p gr6 ,@(gr31,#REG_DCR)
590 # trap exceptions during break handling and disable h/w breakpoints/watchpoints
591 sethi %hi(DCR_EBE),gr5
592 setlo.p %lo(DCR_EBE),gr5
593 sethi %hi(__entry_breaktrap_table),gr4
594 setlo %lo(__entry_breaktrap_table),gr4
598 # set up kernel global registers
599 sethi.p %hi(__kernel_current_task),gr5
600 setlo %lo(__kernel_current_task),gr5
602 ldi.p @(gr29,#4),gr15 ; __current_thread_info = current->thread_info
605 setlo.p %lo(_gp),gr16
607 # make sure we (the kernel) get div-zero and misalignment exceptions
608 setlos #ISR_EDE|ISR_DTT_DIVBYZERO|ISR_EMAM_EXCEPTION,gr5
620 lddi @(gr31,#REG_IACC0),gr4
624 lddi @(gr31,#REG_GNER0),gr4
628 lddi @(gr31,#REG_LR) ,gr26
629 lddi @(gr31,#REG_CCR) ,gr24
630 lddi @(gr31,#REG_PSR) ,gr22
631 ldi @(gr31,#REG_PC) ,gr21
632 ldi @(gr31,#REG_TBR) ,gr20
633 ldi.p @(gr31,#REG_DCR) ,gr6
635 andi gr22,#PSR_S,gr19 /* rebuild BPSR */
636 andi.p gr22,#PSR_ET,gr5
653 ldi @(gr31,#REG_GR(31)),gr2
657 ldi @(gr31,#REG_GR(30)),gr30
658 ldi @(gr31,#REG_GR(29)),gr29
659 lddi @(gr31,#REG_GR(26)),gr26
660 lddi @(gr31,#REG_GR(24)),gr24
661 lddi @(gr31,#REG_GR(22)),gr22
662 lddi @(gr31,#REG_GR(20)),gr20
663 lddi @(gr31,#REG_GR(18)),gr18
664 lddi @(gr31,#REG_GR(16)),gr16
665 lddi @(gr31,#REG_GR(14)),gr14
666 lddi @(gr31,#REG_GR(12)),gr12
667 lddi @(gr31,#REG_GR(10)),gr10
668 lddi @(gr31,#REG_GR(8)) ,gr8
669 lddi @(gr31,#REG_GR(6)) ,gr6
670 lddi @(gr31,#REG_GR(4)) ,gr4
671 lddi @(gr31,#REG_GR(2)) ,gr2
672 ldi.p @(gr31,#REG_SP) ,sp
681 ###################################################################################################
683 # GDB stub "system calls"
685 ###################################################################################################
687 #ifdef CONFIG_GDBSTUB
688 # void gdbstub_console_write(struct console *con, const char *p, unsigned n)
689 .globl gdbstub_console_write
690 gdbstub_console_write:
695 # GDB stub BUG() trap
696 # GR8 is the proposed signal number
697 .globl __debug_bug_trap
702 # transfer kernel exeception to GDB for handling
703 .globl __break_hijack_kernel_event
704 __break_hijack_kernel_event:
706 .globl __break_hijack_kernel_event_breaks_here
707 __break_hijack_kernel_event_breaks_here:
711 # handle a return from TLB-miss that requires single-step reactivation
712 .globl __break_tlb_miss_return_break
713 __break_tlb_miss_return_break:
715 __break_tlb_miss_return_breaks_here:
719 # guard the first .text label in the next file from confusion