2 * Copyright (c) 2000-2007 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
36 #include <mach/mach_types.h>
37 #include <mach/mach_traps.h>
38 #include <mach/thread_status.h>
40 #include <kern/processor.h>
41 #include <kern/thread.h>
42 #include <kern/exception.h>
43 #include <kern/syscall_sw.h>
44 #include <kern/cpu_data.h>
45 #include <kern/debug.h>
47 #include <vm/vm_fault.h>
48 #include <vm/vm_kern.h> /* For kernel_map */
50 #include <ppc/misc_protos.h>
52 #include <ppc/exception.h>
53 #include <ppc/proc_reg.h> /* for SR_xxx definitions */
56 #include <ppc/mappings.h>
57 #include <ppc/Firmware.h>
58 #include <ppc/low_trace.h>
59 #include <ppc/Diagnostics.h>
60 #include <ppc/hw_perfmon.h>
61 #include <ppc/fpu_protos.h>
63 #include <sys/kdebug.h>
65 perfCallback perfTrapHook
; /* Pointer to CHUD trap hook routine */
66 perfCallback perfASTHook
; /* Pointer to CHUD AST hook routine */
69 extern kern_return_t
dtrace_user_probe(ppc_saved_state_t
*sv
);
71 /* See <rdar://problem/4613924> */
72 perfCallback tempDTraceTrapHook
= NULL
; /* Pointer to DTrace fbt trap hook routine */
74 extern boolean_t
dtrace_tally_fault(user_addr_t
);
78 #include <ddb/db_watch.h>
79 #include <ddb/db_run.h>
80 #include <ddb/db_break.h>
81 #include <ddb/db_trap.h>
83 boolean_t let_ddb_vm_fault
= FALSE
;
84 boolean_t debug_all_traps_with_kdb
= FALSE
;
85 extern struct db_watchpoint
*db_watchpoint_list
;
86 extern boolean_t db_watchpoints_inserted
;
87 extern boolean_t db_breakpoints_inserted
;
93 extern task_t bsd_init_task
;
94 extern char init_task_failure_data
[];
95 extern int not_in_kdp
;
97 #define PROT_EXEC (VM_PROT_EXECUTE)
98 #define PROT_RO (VM_PROT_READ)
99 #define PROT_RW (VM_PROT_READ|VM_PROT_WRITE)
102 /* A useful macro to update the ppc_exception_state in the PCB
103 * before calling doexception
105 #define UPDATE_PPC_EXCEPTION_STATE { \
106 thread_t _thread = current_thread(); \
107 _thread->machine.pcb->save_dar = (uint64_t)dar; \
108 _thread->machine.pcb->save_dsisr = dsisr; \
109 _thread->machine.pcb->save_exception = trapno / T_VECTOR_SIZE; /* back to powerpc */ \
112 void unresolved_kernel_trap(int trapno
,
113 struct savearea
*ssp
,
116 const char *message
);
118 static void handleMck(struct savearea
*ssp
); /* Common machine check handler */
121 extern void get_procrustime(time_value_t
*);
122 extern void bsd_uprofil(time_value_t
*, user_addr_t
);
123 #endif /* MACH_BSD */
126 struct savearea
*trap(int trapno
,
127 struct savearea
*ssp
,
132 mach_exception_code_t code
= 0;
133 mach_exception_subcode_t subcode
= 0;
135 vm_map_offset_t offset
;
136 thread_t thread
= current_thread();
143 #endif /* MACH_BSD */
145 myast
= ast_pending();
147 if(*myast
& AST_CHUD_ALL
) {
148 perfASTHook(trapno
, ssp
, dsisr
, (unsigned int)dar
);
151 *myast
&= ~AST_CHUD_ALL
;
154 if(perfTrapHook
) { /* Is there a hook? */
155 if(perfTrapHook(trapno
, ssp
, dsisr
, (unsigned int)dar
) == KERN_SUCCESS
) return ssp
; /* If it succeeds, we are done... */
159 if(tempDTraceTrapHook
) { /* Is there a hook? */
160 if(tempDTraceTrapHook(trapno
, ssp
, dsisr
, (unsigned int)dar
) == KERN_SUCCESS
) return ssp
; /* If it succeeds, we are done... */
166 extern void fctx_text(void);
171 exception
= 0; /* Clear exception for now */
174 * Remember that we are disabled for interruptions when we come in here. Because
175 * of latency concerns, we need to enable interruptions in the interrupted process
176 * was enabled itself as soon as we can.
179 intr
= (ssp
->save_srr1
& MASK(MSR_EE
)) != 0; /* Remember if we were enabled */
181 /* Handle kernel traps first */
183 if (!USER_MODE(ssp
->save_srr1
)) {
185 * Trap came from kernel
189 case T_PREEMPT
: /* Handle a preempt trap */
190 ast_taken(AST_PREEMPTION
, FALSE
);
194 perfmon_handle_pmi(ssp
);
197 case T_RESET
: /* Reset interruption */
198 if (!Call_Debugger(trapno
, ssp
))
199 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
200 break; /* We just ignore these */
203 * These trap types should never be seen by trap()
204 * in kernel mode, anyway.
205 * Some are interrupts that should be seen by
206 * interrupt() others just don't happen because they
207 * are handled elsewhere. Some could happen but are
208 * considered to be fatal in kernel mode.
211 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
212 case T_SYSTEM_MANAGEMENT
:
213 case T_ALTIVEC_ASSIST
:
215 case T_FP_UNAVAILABLE
:
219 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
224 * Here we handle a machine check in the kernel
227 case T_MACHINE_CHECK
:
228 handleMck(ssp
); /* Common to both user and kernel */
234 * If enaNotifyEMb is set, we get here, and
235 * we have actually already emulated the unaligned access.
236 * All that we want to do here is to ignore the interrupt. This is to allow logging or
237 * tracing of unaligned accesses.
240 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
241 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
); /* Go panic */
244 KERNEL_DEBUG_CONSTANT(
245 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
246 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
251 * If enaNotifyEMb is set we get here, and
252 * we have actually already emulated the instruction.
253 * All that we want to do here is to ignore the interrupt. This is to allow logging or
254 * tracing of emulated instructions.
257 KERNEL_DEBUG_CONSTANT(
258 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
259 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
267 case T_RUNMODE_TRACE
:
268 case T_INSTRUCTION_BKPT
:
269 if (!Call_Debugger(trapno
, ssp
))
270 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
274 if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
275 if (!Call_Debugger(trapno
, ssp
))
276 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
278 unresolved_kernel_trap(trapno
, ssp
,
285 mp_disable_preemption();
287 && getPerProc()->debugger_active
288 && !let_ddb_vm_fault
) {
290 * Force kdb to handle this one.
292 kdb_trap(trapno
, ssp
);
294 mp_enable_preemption();
295 #endif /* MACH_KDB */
296 /* can we take this during normal panic dump operation? */
298 && getPerProc()->debugger_active
301 * Access fault while in kernel core dump.
303 kdp_dump_trap(trapno
, ssp
);
307 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
308 panic("trap: disallowed access to cache inhibited memory - %016llX\n", dar
);
311 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
313 if(((dar
>> 28) < 0xE) | ((dar
>> 28) > 0xF)) { /* User memory window access? */
315 offset
= (vm_map_offset_t
)dar
; /* Set the failing address */
316 map
= kernel_map
; /* No, this is a normal kernel access */
319 * Note: Some ROM device drivers will access page 0 when they start. The IOKit will
320 * set a flag to tell us to ignore any access fault on page 0. After the driver is
321 * opened, it will clear the flag.
323 if((0 == (offset
& -PAGE_SIZE
)) && /* Check for access of page 0 and */
324 ((thread
->machine
.specFlags
) & ignoreZeroFault
)) { /* special case of ignoring page zero faults */
325 ssp
->save_srr0
+= 4; /* Point to next instruction */
330 if (thread
->options
& TH_OPT_DTRACE
) { /* Executing under dtrace_probe? */
331 if (dtrace_tally_fault(dar
)) { /* Should a fault under dtrace be ignored? */
332 ssp
->save_srr0
+= 4; /* Point to next instruction */
335 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "Unexpected page fault under dtrace_probe");
340 code
= vm_fault(map
, vm_map_trunc_page(offset
),
341 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
342 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
344 if (code
!= KERN_SUCCESS
) {
345 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
347 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
348 ssp
->save_dsisr
= (ssp
->save_dsisr
&
349 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
354 /* If we get here, the fault was due to a user memory window access */
357 if (thread
->options
& TH_OPT_DTRACE
) { /* Executing under dtrace_probe? */
358 if (dtrace_tally_fault(dar
)) { /* Should a user memory window access fault under dtrace be ignored? */
359 if (thread
->recover
) {
360 ssp
->save_srr0
= thread
->recover
;
361 thread
->recover
= (vm_offset_t
)NULL
;
363 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "copyin/out has no recovery point");
367 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "Unexpected UMW page fault under dtrace_probe");
374 offset
= (vm_map_offset_t
)(thread
->machine
.umwRelo
+ dar
); /* Compute the user space address */
376 code
= vm_fault(map
, vm_map_trunc_page(offset
),
377 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
378 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
380 /* If we failed, there should be a recovery
383 if (code
!= KERN_SUCCESS
) {
384 if (thread
->recover
) {
385 ssp
->save_srr0
= thread
->recover
;
386 thread
->recover
= (vm_offset_t
)NULL
;
388 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "copyin/out has no recovery point");
392 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
393 ssp
->save_dsisr
= (ssp
->save_dsisr
&
394 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
399 case T_INSTRUCTION_ACCESS
:
403 && getPerProc()->debugger_active
404 && !let_ddb_vm_fault
) {
406 * Force kdb to handle this one.
408 kdb_trap(trapno
, ssp
);
410 #endif /* MACH_KDB */
412 /* Same as for data access, except fault type
413 * is PROT_EXEC and addr comes from srr0
416 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
420 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
421 (PROT_EXEC
| PROT_RO
), FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
423 if (code
!= KERN_SUCCESS
) {
424 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
426 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
427 ssp
->save_srr1
= (ssp
->save_srr1
&
428 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
432 /* Usually shandler handles all the system calls, but the
433 * atomic thread switcher may throwup (via thandler) and
434 * have to pass it up to the exception handler.
438 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
442 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
448 * Processing for user state traps with interrupt enabled
449 * For T_AST, interrupts are enabled in the AST delivery
452 ml_set_interrupts_enabled(TRUE
);
456 get_procrustime(&tv
);
458 #endif /* MACH_BSD */
462 * Trap came from user task
468 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
472 perfmon_handle_pmi(ssp
);
476 * These trap types should never be seen by trap()
477 * Some are interrupts that should be seen by
478 * interrupt() others just don't happen because they
479 * are handled elsewhere.
482 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
484 case T_FP_UNAVAILABLE
:
485 case T_SYSTEM_MANAGEMENT
:
491 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
493 panic("Unexpected user state trap(cpu %d): 0x%08X DSISR=0x%08X DAR=0x%016llX PC=0x%016llX, MSR=0x%016llX\n",
494 cpu_number(), trapno
, dsisr
, dar
, ssp
->save_srr0
, ssp
->save_srr1
);
499 * Here we handle a machine check in user state
502 case T_MACHINE_CHECK
:
503 handleMck(ssp
); /* Common to both user and kernel */
507 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
508 if (!Call_Debugger(trapno
, ssp
))
509 panic("Unexpected Reset exception: srr0 = %016llx, srr1 = %016llx\n",
510 ssp
->save_srr0
, ssp
->save_srr1
);
511 break; /* We just ignore these */
515 * If enaNotifyEMb is set, we get here, and
516 * we have actually already emulated the unaligned access.
517 * All that we want to do here is to ignore the interrupt. This is to allow logging or
518 * tracing of unaligned accesses.
521 KERNEL_DEBUG_CONSTANT(
522 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
523 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
525 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
526 exception
= EXC_BAD_ACCESS
; /* Yes, throw exception */
527 code
= EXC_PPC_UNALIGNED
;
534 * If enaNotifyEMb is set we get here, and
535 * we have actually already emulated the instruction.
536 * All that we want to do here is to ignore the interrupt. This is to allow logging or
537 * tracing of emulated instructions.
540 KERNEL_DEBUG_CONSTANT(
541 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
542 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
545 case T_TRACE
: /* Real PPC chips */
546 case T_INSTRUCTION_BKPT
:
547 exception
= EXC_BREAKPOINT
;
548 code
= EXC_PPC_TRACE
;
549 subcode
= ssp
->save_srr0
;
553 if (ssp
->save_srr1
& MASK(SRR1_PRG_FE
)) {
554 fpu_save(thread
->machine
.curctx
);
555 UPDATE_PPC_EXCEPTION_STATE
;
556 exception
= EXC_ARITHMETIC
;
557 code
= EXC_ARITHMETIC
;
559 mp_disable_preemption();
560 subcode
= ssp
->save_fpscr
;
561 mp_enable_preemption();
563 else if (ssp
->save_srr1
& MASK(SRR1_PRG_ILL_INS
)) {
565 UPDATE_PPC_EXCEPTION_STATE
566 exception
= EXC_BAD_INSTRUCTION
;
567 code
= EXC_PPC_UNIPL_INST
;
568 subcode
= ssp
->save_srr0
;
569 } else if ((unsigned int)ssp
->save_srr1
& MASK(SRR1_PRG_PRV_INS
)) {
571 UPDATE_PPC_EXCEPTION_STATE
;
572 exception
= EXC_BAD_INSTRUCTION
;
573 code
= EXC_PPC_PRIVINST
;
574 subcode
= ssp
->save_srr0
;
575 } else if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
578 if (copyin(ssp
->save_srr0
, (char *) &inst
, 4 )) panic("copyin failed\n");
580 if(dgWork
.dgFlags
& enaDiagTrap
) { /* Is the diagnostic trap enabled? */
581 if((inst
& 0xFFFFFFF0) == 0x0FFFFFF0) { /* Is this a TWI 31,R31,0xFFFx? */
582 if(diagTrap(ssp
, inst
& 0xF)) { /* Call the trap code */
583 ssp
->save_srr0
+= 4ULL; /* If we eat the trap, bump pc */
584 exception
= 0; /* Clear exception */
585 break; /* All done here */
591 if(inst
== 0x0FFFDDDD) { /* Is this the dtrace trap? */
592 ret
= dtrace_user_probe((ppc_saved_state_t
*)ssp
); /* Go check if it is for real and process if so... */
593 if(ret
== KERN_SUCCESS
) { /* Was it really? */
594 exception
= 0; /* Clear the exception */
595 break; /* Go flow through and out... */
600 UPDATE_PPC_EXCEPTION_STATE
;
602 if (inst
== 0x7FE00008) {
603 exception
= EXC_BREAKPOINT
;
604 code
= EXC_PPC_BREAKPOINT
;
606 exception
= EXC_SOFTWARE
;
609 subcode
= ssp
->save_srr0
;
614 case T_DTRACE_RET
: /* Are we returning from a dtrace injection? */
615 ret
= dtrace_user_probe((ppc_saved_state_t
*)ssp
); /* Call the probe function if so... */
616 if(ret
== KERN_SUCCESS
) { /* Did this actually work? */
617 exception
= 0; /* Clear the exception */
618 break; /* Go flow through and out... */
623 case T_ALTIVEC_ASSIST
:
624 UPDATE_PPC_EXCEPTION_STATE
;
625 exception
= EXC_ARITHMETIC
;
626 code
= EXC_PPC_ALTIVECASSIST
;
627 subcode
= ssp
->save_srr0
;
633 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
634 UPDATE_PPC_EXCEPTION_STATE
; /* Don't even bother VM with this one */
635 exception
= EXC_BAD_ACCESS
;
640 code
= vm_fault(map
, vm_map_trunc_page(dar
),
641 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
642 FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
644 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
645 UPDATE_PPC_EXCEPTION_STATE
;
646 exception
= EXC_BAD_ACCESS
;
649 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to retry fault */
650 ssp
->save_dsisr
= (ssp
->save_dsisr
&
651 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
655 case T_INSTRUCTION_ACCESS
:
656 /* Same as for data access, except fault type
657 * is PROT_EXEC and addr comes from srr0
661 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
662 (PROT_EXEC
| PROT_RO
), FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
664 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
665 UPDATE_PPC_EXCEPTION_STATE
;
666 exception
= EXC_BAD_ACCESS
;
667 subcode
= ssp
->save_srr0
;
669 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
670 ssp
->save_srr1
= (ssp
->save_srr1
&
671 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
676 /* AST delivery is done below */
683 bsd_uprofil(&tv
, ssp
->save_srr0
);
685 #endif /* MACH_BSD */
689 /* if this is the init task, save the exception information */
690 /* this probably is a fatal exception */
692 if(bsd_init_task
== current_task()) {
696 buf
= init_task_failure_data
;
699 buf
+= sprintf(buf
, "Exception Code = 0x%x, Subcode = 0x%x\n", code
, subcode
);
700 buf
+= sprintf(buf
, "DSISR = 0x%08x, DAR = 0x%016llx\n"
703 for (i
=0; i
<32; i
++) {
705 buf
+= sprintf(buf
, "\n%4d :",i
);
707 buf
+= sprintf(buf
, " %08x",*(&ssp
->save_r0
+i
));
710 buf
+= sprintf(buf
, "\n\n");
711 buf
+= sprintf(buf
, "cr = 0x%08X\t\t",ssp
->save_cr
);
712 buf
+= sprintf(buf
, "xer = 0x%08X\n",ssp
->save_xer
);
713 buf
+= sprintf(buf
, "lr = 0x%016llX\t\t",ssp
->save_lr
);
714 buf
+= sprintf(buf
, "ctr = 0x%016llX\n",ssp
->save_ctr
);
715 buf
+= sprintf(buf
, "srr0(iar) = 0x%016llX\t\t",ssp
->save_srr0
);
716 buf
+= sprintf(buf
, "srr1(msr) = 0x%016llX\n",ssp
->save_srr1
,
717 "\x10\x11""EE\x12PR\x13""FP\x14ME\x15""FE0\x16SE\x18"
718 "FE1\x19""AL\x1a""EP\x1bIT\x1c""DT");
719 buf
+= sprintf(buf
, "\n\n");
721 /* generate some stack trace */
722 buf
+= sprintf(buf
, "Application level back trace:\n");
723 if (ssp
->save_srr1
& MASK(MSR_PR
)) {
724 char *addr
= (char*)ssp
->save_r1
;
725 unsigned int stack_buf
[3];
726 for (i
= 0; i
< 8; i
++) {
727 if (addr
== (char*)NULL
)
729 if (!copyin(ssp
->save_r1
,(char*)stack_buf
,
731 buf
+= sprintf(buf
, "0x%08X : 0x%08X\n"
733 addr
= (char*)stack_buf
[0];
742 doexception(exception
, code
, subcode
);
745 * Check to see if we need an AST, if so take care of it here
747 ml_set_interrupts_enabled(FALSE
);
749 if (USER_MODE(ssp
->save_srr1
)) {
750 myast
= ast_pending();
751 while (*myast
& AST_ALL
) {
752 ast_taken(AST_ALL
, intr
);
753 ml_set_interrupts_enabled(FALSE
);
754 myast
= ast_pending();
761 /* This routine is called from assembly before each and every system call.
762 * It must preserve r3.
765 extern int syscall_trace(int, struct savearea
*);
770 int syscall_trace(int retval
, struct savearea
*ssp
)
774 /* Always prepare to trace mach system calls */
780 argc
= mach_trap_table
[-((unsigned int)ssp
->save_r0
)].mach_trap_arg_count
;
785 for (i
=0; i
< argc
; i
++)
786 kdarg
[i
] = (int)*(&ssp
->save_r3
+ i
);
788 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
, (-(ssp
->save_r0
))) | DBG_FUNC_START
,
789 kdarg
[0], kdarg
[1], kdarg
[2], 0, 0);
794 /* This routine is called from assembly after each mach system call
795 * It must preserve r3.
798 extern int syscall_trace_end(int, struct savearea
*);
800 int syscall_trace_end(int retval
, struct savearea
*ssp
)
802 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-((unsigned int)ssp
->save_r0
))) | DBG_FUNC_END
,
808 * called from syscall if there is an error
813 mach_exception_code_t code
,
814 mach_exception_subcode_t subcode
,
815 struct savearea
*ssp
)
817 register thread_t thread
;
819 thread
= current_thread();
822 panic("syscall error in boot phase");
824 if (!USER_MODE(ssp
->save_srr1
))
825 panic("system call called from kernel");
827 doexception(exception
, code
, subcode
);
832 /* Pass up a server syscall/exception */
836 mach_exception_code_t code
,
837 mach_exception_subcode_t sub
)
839 mach_exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
843 exception_triage(exc
, codes
, 2);
846 const char *trap_type
[] = {
848 "0x100 - System reset",
849 "0x200 - Machine check",
850 "0x300 - Data access",
851 "0x400 - Inst access",
855 "0x800 - Floating point",
856 "0x900 - Decrementer",
859 "0xC00 - System call",
867 "0x1300 - Inst bkpnt",
869 "0x1600 - Altivec Assist",
880 "0x2000 - Run Mode/Trace",
887 int TRAP_TYPES
= sizeof (trap_type
) / sizeof (trap_type
[0]);
889 void unresolved_kernel_trap(int trapno
,
890 struct savearea
*ssp
,
891 __unused
unsigned int dsisr
,
895 const char *trap_name
;
897 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
898 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
902 struct per_proc_info
*pp
;
903 kprintf(" srr0: %016llX\n", ssp
->save_srr0
); /* (TEST/DEBUG) */
904 kprintf(" srr1: %016llX\n", ssp
->save_srr1
); /* (TEST/DEBUG) */
905 kprintf(" dar: %016llX\n", ssp
->save_dar
); /* (TEST/DEBUG) */
906 kprintf(" xcp: %08X\n", ssp
->save_exception
); /* (TEST/DEBUG) */
907 kprintf(" ins0: %08X\n", ssp
->save_instr
[0]); /* (TEST/DEBUG) */
908 kprintf(" ins1: %08X\n", ssp
->save_instr
[1]); /* (TEST/DEBUG) */
909 kprintf(" ins2: %08X\n", ssp
->save_instr
[2]); /* (TEST/DEBUG) */
910 kprintf(" ins3: %08X\n", ssp
->save_instr
[3]); /* (TEST/DEBUG) */
911 kprintf(" ins4: %08X\n", ssp
->save_instr
[4]); /* (TEST/DEBUG) */
912 kprintf(" ins5: %08X\n", ssp
->save_instr
[5]); /* (TEST/DEBUG) */
913 kprintf(" ins6: %08X\n", ssp
->save_instr
[6]); /* (TEST/DEBUG) */
914 kprintf(" ins7: %08X\n", ssp
->save_instr
[7]); /* (TEST/DEBUG) */
915 pp
= getPerProc(); /* (TEST/DEBUG) */
916 kprintf("ijsave: %016llX\n", pp
->ijsave
); /* (TEST/DEBUG) */
920 if( logPanicDataToScreen
)
921 disable_debug_output
= FALSE
;
924 if ((unsigned)trapno
<= T_MAX
)
925 trap_name
= trap_type
[trapno
/ T_VECTOR_SIZE
];
927 trap_name
= "???? unrecognized exception";
931 kdb_printf("\n\nUnresolved kernel trap(cpu %d): %s DAR=0x%016llX PC=0x%016llX\n",
932 cpu_number(), trap_name
, dar
, ssp
->save_srr0
);
934 print_backtrace(ssp
);
936 panic_caller
= (0xFFFF0000 | (trapno
/ T_VECTOR_SIZE
) );
937 /* Commit the panic log buffer to NVRAM, unless otherwise
938 * specified via a boot-arg.
944 /* XXX: This is yet another codepath into the debugger, which should
945 * be reworked to enter the primary panic codepath instead.
946 * The idea appears to be to enter the debugger (performing a
947 * stack switch) as soon as possible, but we do have a
948 * savearea encapsulating state (accessible by walking the savearea
949 * chain), so that's superfluous.
952 (void)Call_Debugger(trapno
, ssp
);
953 panic_plain(message
);
956 const char *corr
[2] = {"uncorrected", "corrected "};
958 void handleMck(struct savearea
*ssp
) { /* Common machine check handler */
964 printf("Machine check (%d) - %s - pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n",
965 cpu
, corr
[ssp
->save_hdr
.save_misc3
], ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
); /* Tell us about it */
966 printf("Machine check (%d) - AsyncSrc = %016llX, CoreFIR = %016llx\n", cpu
, ssp
->save_xdat0
, ssp
->save_xdat1
);
967 printf("Machine check (%d) - L2FIR = %016llX, BusFir = %016llx\n", cpu
, ssp
->save_xdat2
, ssp
->save_xdat3
);
969 if(ssp
->save_hdr
.save_misc3
) return; /* Leave the the machine check was recovered */
971 panic("Uncorrectable machine check: pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n"
972 " AsyncSrc = %016llX, CoreFIR = %016llx\n"
973 " L2FIR = %016llX, BusFir = %016llx\n",
974 ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
,
975 ssp
->save_xdat0
, ssp
->save_xdat1
, ssp
->save_xdat2
, ssp
->save_xdat3
);
981 thread_syscall_return(
984 register thread_t thread
= current_thread();
985 register struct savearea
*regs
= USER_REGS(thread
);
987 if (kdebug_enable
&& ((unsigned int)regs
->save_r0
& 0x80000000)) {
989 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-(regs
->save_r0
))) | DBG_FUNC_END
,
994 thread_exception_return();
1001 thread_kdb_return(void)
1003 register thread_t thread
= current_thread();
1004 register struct savearea
*regs
= USER_REGS(thread
);
1006 Call_Debugger(thread
->machine
.pcb
->save_exception
, regs
);
1007 thread_exception_return();
1010 #endif /* MACH_KDB */