2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
30 #include <mach/mach_types.h>
31 #include <mach/mach_traps.h>
32 #include <mach/thread_status.h>
34 #include <kern/processor.h>
35 #include <kern/thread.h>
36 #include <kern/exception.h>
37 #include <kern/syscall_sw.h>
38 #include <kern/cpu_data.h>
39 #include <kern/debug.h>
41 #include <vm/vm_fault.h>
42 #include <vm/vm_kern.h> /* For kernel_map */
44 #include <ppc/misc_protos.h>
46 #include <ppc/exception.h>
47 #include <ppc/proc_reg.h> /* for SR_xxx definitions */
50 #include <ppc/mappings.h>
51 #include <ppc/Firmware.h>
52 #include <ppc/low_trace.h>
53 #include <ppc/Diagnostics.h>
54 #include <ppc/hw_perfmon.h>
56 #include <sys/kdebug.h>
58 perfCallback perfTrapHook
= 0; /* Pointer to CHUD trap hook routine */
59 perfCallback perfASTHook
= 0; /* Pointer to CHUD AST hook routine */
62 #include <ddb/db_watch.h>
63 #include <ddb/db_run.h>
64 #include <ddb/db_break.h>
65 #include <ddb/db_trap.h>
67 boolean_t let_ddb_vm_fault
= FALSE
;
68 boolean_t debug_all_traps_with_kdb
= FALSE
;
69 extern struct db_watchpoint
*db_watchpoint_list
;
70 extern boolean_t db_watchpoints_inserted
;
71 extern boolean_t db_breakpoints_inserted
;
77 extern task_t bsd_init_task
;
78 extern char init_task_failure_data
[];
79 extern int not_in_kdp
;
81 #define PROT_EXEC (VM_PROT_EXECUTE)
82 #define PROT_RO (VM_PROT_READ)
83 #define PROT_RW (VM_PROT_READ|VM_PROT_WRITE)
86 /* A useful macro to update the ppc_exception_state in the PCB
87 * before calling doexception
89 #define UPDATE_PPC_EXCEPTION_STATE { \
90 thread_t _thread = current_thread(); \
91 _thread->machine.pcb->save_dar = (uint64_t)dar; \
92 _thread->machine.pcb->save_dsisr = dsisr; \
93 _thread->machine.pcb->save_exception = trapno / T_VECTOR_SIZE; /* back to powerpc */ \
96 void unresolved_kernel_trap(int trapno
,
100 const char *message
);
102 static void handleMck(struct savearea
*ssp
); /* Common machine check handler */
105 extern void get_procrustime(time_value_t
*);
106 extern void bsd_uprofil(time_value_t
*, user_addr_t
);
107 #endif /* MACH_BSD */
110 struct savearea
*trap(int trapno
,
111 struct savearea
*ssp
,
120 unsigned int space
, space2
;
121 vm_map_offset_t offset
;
122 thread_t thread
= current_thread();
128 #endif /* MACH_BSD */
130 myast
= ast_pending();
132 if(*myast
& AST_CHUD_ALL
) {
133 perfASTHook(trapno
, ssp
, dsisr
, (unsigned int)dar
);
136 *myast
&= ~AST_CHUD_ALL
;
139 if(perfTrapHook
) { /* Is there a hook? */
140 if(perfTrapHook(trapno
, ssp
, dsisr
, (unsigned int)dar
) == KERN_SUCCESS
) return ssp
; /* If it succeeds, we are done... */
145 extern void fctx_text(void);
150 exception
= 0; /* Clear exception for now */
153 * Remember that we are disabled for interruptions when we come in here. Because
154 * of latency concerns, we need to enable interruptions in the interrupted process
155 * was enabled itself as soon as we can.
158 intr
= (ssp
->save_srr1
& MASK(MSR_EE
)) != 0; /* Remember if we were enabled */
160 /* Handle kernel traps first */
162 if (!USER_MODE(ssp
->save_srr1
)) {
164 * Trap came from kernel
168 case T_PREEMPT
: /* Handle a preempt trap */
169 ast_taken(AST_PREEMPTION
, FALSE
);
173 perfmon_handle_pmi(ssp
);
176 case T_RESET
: /* Reset interruption */
177 if (!Call_Debugger(trapno
, ssp
))
178 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
179 break; /* We just ignore these */
182 * These trap types should never be seen by trap()
183 * in kernel mode, anyway.
184 * Some are interrupts that should be seen by
185 * interrupt() others just don't happen because they
186 * are handled elsewhere. Some could happen but are
187 * considered to be fatal in kernel mode.
190 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
191 case T_SYSTEM_MANAGEMENT
:
192 case T_ALTIVEC_ASSIST
:
194 case T_FP_UNAVAILABLE
:
198 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
203 * Here we handle a machine check in the kernel
206 case T_MACHINE_CHECK
:
207 handleMck(ssp
); /* Common to both user and kernel */
213 * If enaNotifyEMb is set, we get here, and
214 * we have actually already emulated the unaligned access.
215 * All that we want to do here is to ignore the interrupt. This is to allow logging or
216 * tracing of unaligned accesses.
219 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
220 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
); /* Go panic */
223 KERNEL_DEBUG_CONSTANT(
224 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
225 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
230 * If enaNotifyEMb is set we get here, and
231 * we have actually already emulated the instruction.
232 * All that we want to do here is to ignore the interrupt. This is to allow logging or
233 * tracing of emulated instructions.
236 KERNEL_DEBUG_CONSTANT(
237 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
238 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
246 case T_RUNMODE_TRACE
:
247 case T_INSTRUCTION_BKPT
:
248 if (!Call_Debugger(trapno
, ssp
))
249 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
253 if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
254 if (!Call_Debugger(trapno
, ssp
))
255 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
257 unresolved_kernel_trap(trapno
, ssp
,
264 mp_disable_preemption();
266 && getPerProc()->debugger_active
267 && !let_ddb_vm_fault
) {
269 * Force kdb to handle this one.
271 kdb_trap(trapno
, ssp
);
273 mp_enable_preemption();
274 #endif /* MACH_KDB */
275 /* can we take this during normal panic dump operation? */
277 && getPerProc()->debugger_active
280 * Access fault while in kernel core dump.
282 kdp_dump_trap(trapno
, ssp
);
286 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
287 panic("trap: disallowed access to cache inhibited memory - %016llX\n", dar
);
290 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
292 if(((dar
>> 28) < 0xE) | ((dar
>> 28) > 0xF)) { /* User memory window access? */
294 offset
= (vm_map_offset_t
)dar
; /* Set the failing address */
295 map
= kernel_map
; /* No, this is a normal kernel access */
298 * Note: Some ROM device drivers will access page 0 when they start. The IOKit will
299 * set a flag to tell us to ignore any access fault on page 0. After the driver is
300 * opened, it will clear the flag.
302 if((0 == (offset
& -PAGE_SIZE
)) && /* Check for access of page 0 and */
303 ((thread
->machine
.specFlags
) & ignoreZeroFault
)) { /* special case of ignoring page zero faults */
304 ssp
->save_srr0
+= 4; /* Point to next instruction */
308 code
= vm_fault(map
, vm_map_trunc_page(offset
),
309 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
310 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
312 if (code
!= KERN_SUCCESS
) {
313 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
315 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
316 ssp
->save_dsisr
= (ssp
->save_dsisr
&
317 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
322 /* If we get here, the fault was due to a user memory window access */
326 offset
= (vm_map_offset_t
)(thread
->machine
.umwRelo
+ dar
); /* Compute the user space address */
328 code
= vm_fault(map
, vm_map_trunc_page(offset
),
329 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
330 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
332 /* If we failed, there should be a recovery
335 if (code
!= KERN_SUCCESS
) {
336 if (thread
->recover
) {
337 ssp
->save_srr0
= thread
->recover
;
338 thread
->recover
= (vm_offset_t
)NULL
;
340 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "copyin/out has no recovery point");
344 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
345 ssp
->save_dsisr
= (ssp
->save_dsisr
&
346 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
351 case T_INSTRUCTION_ACCESS
:
355 && getPerProc()->debugger_active
356 && !let_ddb_vm_fault
) {
358 * Force kdb to handle this one.
360 kdb_trap(trapno
, ssp
);
362 #endif /* MACH_KDB */
364 /* Same as for data access, except fault type
365 * is PROT_EXEC and addr comes from srr0
368 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
372 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
373 (PROT_EXEC
| PROT_RO
), FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
375 if (code
!= KERN_SUCCESS
) {
376 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
378 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
379 ssp
->save_srr1
= (ssp
->save_srr1
&
380 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
384 /* Usually shandler handles all the system calls, but the
385 * atomic thread switcher may throwup (via thandler) and
386 * have to pass it up to the exception handler.
390 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
394 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
400 * Processing for user state traps with interrupt enabled
401 * For T_AST, interrupts are enabled in the AST delivery
404 ml_set_interrupts_enabled(TRUE
);
408 get_procrustime(&tv
);
410 #endif /* MACH_BSD */
414 * Trap came from user task
420 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
424 perfmon_handle_pmi(ssp
);
428 * These trap types should never be seen by trap()
429 * Some are interrupts that should be seen by
430 * interrupt() others just don't happen because they
431 * are handled elsewhere.
434 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
436 case T_FP_UNAVAILABLE
:
437 case T_SYSTEM_MANAGEMENT
:
443 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
445 panic("Unexpected user state trap(cpu %d): 0x%08X DSISR=0x%08X DAR=0x%016llX PC=0x%016llX, MSR=0x%016llX\n",
446 cpu_number(), trapno
, dsisr
, dar
, ssp
->save_srr0
, ssp
->save_srr1
);
451 * Here we handle a machine check in user state
454 case T_MACHINE_CHECK
:
455 handleMck(ssp
); /* Common to both user and kernel */
459 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
460 if (!Call_Debugger(trapno
, ssp
))
461 panic("Unexpected Reset exception: srr0 = %016llx, srr1 = %016llx\n",
462 ssp
->save_srr0
, ssp
->save_srr1
);
463 break; /* We just ignore these */
467 * If enaNotifyEMb is set, we get here, and
468 * we have actually already emulated the unaligned access.
469 * All that we want to do here is to ignore the interrupt. This is to allow logging or
470 * tracing of unaligned accesses.
473 KERNEL_DEBUG_CONSTANT(
474 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
475 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
477 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
478 exception
= EXC_BAD_ACCESS
; /* Yes, throw exception */
479 code
= EXC_PPC_UNALIGNED
;
480 subcode
= (unsigned int)dar
;
486 * If enaNotifyEMb is set we get here, and
487 * we have actually already emulated the instruction.
488 * All that we want to do here is to ignore the interrupt. This is to allow logging or
489 * tracing of emulated instructions.
492 KERNEL_DEBUG_CONSTANT(
493 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
494 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
497 case T_TRACE
: /* Real PPC chips */
504 case T_INSTRUCTION_BKPT
:
505 exception
= EXC_BREAKPOINT
;
506 code
= EXC_PPC_TRACE
;
507 subcode
= (unsigned int)ssp
->save_srr0
;
511 if (ssp
->save_srr1
& MASK(SRR1_PRG_FE
)) {
512 fpu_save(thread
->machine
.curctx
);
513 UPDATE_PPC_EXCEPTION_STATE
;
514 exception
= EXC_ARITHMETIC
;
515 code
= EXC_ARITHMETIC
;
517 mp_disable_preemption();
518 subcode
= ssp
->save_fpscr
;
519 mp_enable_preemption();
521 else if (ssp
->save_srr1
& MASK(SRR1_PRG_ILL_INS
)) {
523 UPDATE_PPC_EXCEPTION_STATE
524 exception
= EXC_BAD_INSTRUCTION
;
525 code
= EXC_PPC_UNIPL_INST
;
526 subcode
= (unsigned int)ssp
->save_srr0
;
527 } else if ((unsigned int)ssp
->save_srr1
& MASK(SRR1_PRG_PRV_INS
)) {
529 UPDATE_PPC_EXCEPTION_STATE
;
530 exception
= EXC_BAD_INSTRUCTION
;
531 code
= EXC_PPC_PRIVINST
;
532 subcode
= (unsigned int)ssp
->save_srr0
;
533 } else if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
537 //iaddr = CAST_DOWN(char *, ssp->save_srr0); /* Trim from long long and make a char pointer */
538 if (copyin(ssp
->save_srr0
, (char *) &inst
, 4 )) panic("copyin failed\n");
540 if(dgWork
.dgFlags
& enaDiagTrap
) { /* Is the diagnostic trap enabled? */
541 if((inst
& 0xFFFFFFF0) == 0x0FFFFFF0) { /* Is this a TWI 31,R31,0xFFFx? */
542 if(diagTrap(ssp
, inst
& 0xF)) { /* Call the trap code */
543 ssp
->save_srr0
+= 4ULL; /* If we eat the trap, bump pc */
544 exception
= 0; /* Clear exception */
545 break; /* All done here */
550 UPDATE_PPC_EXCEPTION_STATE
;
552 if (inst
== 0x7FE00008) {
553 exception
= EXC_BREAKPOINT
;
554 code
= EXC_PPC_BREAKPOINT
;
556 exception
= EXC_SOFTWARE
;
559 subcode
= (unsigned int)ssp
->save_srr0
;
563 case T_ALTIVEC_ASSIST
:
564 UPDATE_PPC_EXCEPTION_STATE
;
565 exception
= EXC_ARITHMETIC
;
566 code
= EXC_PPC_ALTIVECASSIST
;
567 subcode
= (unsigned int)ssp
->save_srr0
;
573 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
574 UPDATE_PPC_EXCEPTION_STATE
; /* Don't even bother VM with this one */
575 exception
= EXC_BAD_ACCESS
;
576 subcode
= (unsigned int)dar
;
580 code
= vm_fault(map
, vm_map_trunc_page(dar
),
581 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
582 FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
584 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
585 UPDATE_PPC_EXCEPTION_STATE
;
586 exception
= EXC_BAD_ACCESS
;
587 subcode
= (unsigned int)dar
;
589 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
590 ssp
->save_dsisr
= (ssp
->save_dsisr
&
591 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
595 case T_INSTRUCTION_ACCESS
:
596 /* Same as for data access, except fault type
597 * is PROT_EXEC and addr comes from srr0
601 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
602 (PROT_EXEC
| PROT_RO
), FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
604 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
605 UPDATE_PPC_EXCEPTION_STATE
;
606 exception
= EXC_BAD_ACCESS
;
607 subcode
= (unsigned int)ssp
->save_srr0
;
609 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
610 ssp
->save_srr1
= (ssp
->save_srr1
&
611 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
616 /* AST delivery is done below */
622 bsd_uprofil(&tv
, ssp
->save_srr0
);
624 #endif /* MACH_BSD */
628 /* if this is the init task, save the exception information */
629 /* this probably is a fatal exception */
631 if(bsd_init_task
== current_task()) {
635 buf
= init_task_failure_data
;
638 buf
+= sprintf(buf
, "Exception Code = 0x%x, Subcode = 0x%x\n", code
, subcode
);
639 buf
+= sprintf(buf
, "DSISR = 0x%08x, DAR = 0x%016llx\n"
642 for (i
=0; i
<32; i
++) {
644 buf
+= sprintf(buf
, "\n%4d :",i
);
646 buf
+= sprintf(buf
, " %08x",*(&ssp
->save_r0
+i
));
649 buf
+= sprintf(buf
, "\n\n");
650 buf
+= sprintf(buf
, "cr = 0x%08X\t\t",ssp
->save_cr
);
651 buf
+= sprintf(buf
, "xer = 0x%08X\n",ssp
->save_xer
);
652 buf
+= sprintf(buf
, "lr = 0x%016llX\t\t",ssp
->save_lr
);
653 buf
+= sprintf(buf
, "ctr = 0x%016llX\n",ssp
->save_ctr
);
654 buf
+= sprintf(buf
, "srr0(iar) = 0x%016llX\t\t",ssp
->save_srr0
);
655 buf
+= sprintf(buf
, "srr1(msr) = 0x%016llX\n",ssp
->save_srr1
,
656 "\x10\x11""EE\x12PR\x13""FP\x14ME\x15""FE0\x16SE\x18"
657 "FE1\x19""AL\x1a""EP\x1bIT\x1c""DT");
658 buf
+= sprintf(buf
, "\n\n");
660 /* generate some stack trace */
661 buf
+= sprintf(buf
, "Application level back trace:\n");
662 if (ssp
->save_srr1
& MASK(MSR_PR
)) {
663 char *addr
= (char*)ssp
->save_r1
;
664 unsigned int stack_buf
[3];
665 for (i
= 0; i
< 8; i
++) {
666 if (addr
== (char*)NULL
)
668 if (!copyin(ssp
->save_r1
,(char*)stack_buf
,
670 buf
+= sprintf(buf
, "0x%08X : 0x%08X\n"
672 addr
= (char*)stack_buf
[0];
681 doexception(exception
, code
, subcode
);
684 * Check to see if we need an AST, if so take care of it here
686 ml_set_interrupts_enabled(FALSE
);
688 if (USER_MODE(ssp
->save_srr1
)) {
689 myast
= ast_pending();
690 while (*myast
& AST_ALL
) {
691 ast_taken(AST_ALL
, intr
);
692 ml_set_interrupts_enabled(FALSE
);
693 myast
= ast_pending();
700 /* This routine is called from assembly before each and every system call.
701 * It must preserve r3.
704 extern int syscall_trace(int, struct savearea
*);
709 int syscall_trace(int retval
, struct savearea
*ssp
)
713 /* Always prepare to trace mach system calls */
719 argc
= mach_trap_table
[-((unsigned int)ssp
->save_r0
)].mach_trap_arg_count
;
724 for (i
=0; i
< argc
; i
++)
725 kdarg
[i
] = (int)*(&ssp
->save_r3
+ i
);
727 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
, (-(ssp
->save_r0
))) | DBG_FUNC_START
,
728 kdarg
[0], kdarg
[1], kdarg
[2], 0, 0);
733 /* This routine is called from assembly after each mach system call
734 * It must preserve r3.
737 extern int syscall_trace_end(int, struct savearea
*);
739 int syscall_trace_end(int retval
, struct savearea
*ssp
)
741 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-((unsigned int)ssp
->save_r0
))) | DBG_FUNC_END
,
747 * called from syscall if there is an error
754 struct savearea
*ssp
)
756 register thread_t thread
;
758 thread
= current_thread();
761 panic("syscall error in boot phase");
763 if (!USER_MODE(ssp
->save_srr1
))
764 panic("system call called from kernel");
766 doexception(exception
, code
, subcode
);
771 /* Pass up a server syscall/exception */
778 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
782 exception_triage(exc
, codes
, 2);
785 char *trap_type
[] = {
787 "0x100 - System reset",
788 "0x200 - Machine check",
789 "0x300 - Data access",
790 "0x400 - Inst access",
794 "0x800 - Floating point",
795 "0x900 - Decrementer",
798 "0xC00 - System call",
806 "0x1300 - Inst bkpnt",
808 "0x1600 - Altivec Assist",
819 "0x2000 - Run Mode/Trace",
826 int TRAP_TYPES
= sizeof (trap_type
) / sizeof (trap_type
[0]);
828 void unresolved_kernel_trap(int trapno
,
829 struct savearea
*ssp
,
835 extern void print_backtrace(struct savearea
*);
836 extern unsigned int debug_mode
, disableDebugOuput
;
837 extern unsigned long panic_caller
;
839 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
840 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
842 if( logPanicDataToScreen
)
843 disableDebugOuput
= FALSE
;
846 if ((unsigned)trapno
<= T_MAX
)
847 trap_name
= trap_type
[trapno
/ T_VECTOR_SIZE
];
849 trap_name
= "???? unrecognized exception";
853 kdb_printf("\n\nUnresolved kernel trap(cpu %d): %s DAR=0x%016llX PC=0x%016llX\n",
854 cpu_number(), trap_name
, dar
, ssp
->save_srr0
);
856 print_backtrace(ssp
);
858 panic_caller
= (0xFFFF0000 | (trapno
/ T_VECTOR_SIZE
) );
862 (void *)Call_Debugger(trapno
, ssp
);
866 const char *corr
[2] = {"uncorrected", "corrected "};
868 void handleMck(struct savearea
*ssp
) { /* Common machine check handler */
874 printf("Machine check (%d) - %s - pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n",
875 cpu
, corr
[ssp
->save_hdr
.save_misc3
], ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
); /* Tell us about it */
876 printf("Machine check (%d) - AsyncSrc = %016llX, CoreFIR = %016llx\n", cpu
, ssp
->save_xdat0
, ssp
->save_xdat1
);
877 printf("Machine check (%d) - L2FIR = %016llX, BusFir = %016llx\n", cpu
, ssp
->save_xdat2
, ssp
->save_xdat3
);
879 if(ssp
->save_hdr
.save_misc3
) return; /* Leave the the machine check was recovered */
881 panic("Uncorrectable machine check: pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n"
882 " AsyncSrc = %016llX, CoreFIR = %016llx\n"
883 " L2FIR = %016llX, BusFir = %016llx\n",
884 ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
,
885 ssp
->save_xdat0
, ssp
->save_xdat1
, ssp
->save_xdat2
, ssp
->save_xdat3
);
891 thread_syscall_return(
894 register thread_t thread
= current_thread();
895 register struct savearea
*regs
= USER_REGS(thread
);
897 if (kdebug_enable
&& ((unsigned int)regs
->save_r0
& 0x80000000)) {
899 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-(regs
->save_r0
))) | DBG_FUNC_END
,
904 thread_exception_return();
911 thread_kdb_return(void)
913 register thread_t thread
= current_thread();
914 register struct savearea
*regs
= USER_REGS(thread
);
916 Call_Debugger(thread
->machine
.pcb
->save_exception
, regs
);
917 thread_exception_return();
920 #endif /* MACH_KDB */