2 * Copyright (c) 2000-2004 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>
62 #include <sys/kdebug.h>
64 perfCallback perfTrapHook
= 0; /* Pointer to CHUD trap hook routine */
65 perfCallback perfASTHook
= 0; /* Pointer to CHUD AST hook routine */
68 #include <ddb/db_watch.h>
69 #include <ddb/db_run.h>
70 #include <ddb/db_break.h>
71 #include <ddb/db_trap.h>
73 boolean_t let_ddb_vm_fault
= FALSE
;
74 boolean_t debug_all_traps_with_kdb
= FALSE
;
75 extern struct db_watchpoint
*db_watchpoint_list
;
76 extern boolean_t db_watchpoints_inserted
;
77 extern boolean_t db_breakpoints_inserted
;
83 extern task_t bsd_init_task
;
84 extern char init_task_failure_data
[];
85 extern int not_in_kdp
;
87 #define PROT_EXEC (VM_PROT_EXECUTE)
88 #define PROT_RO (VM_PROT_READ)
89 #define PROT_RW (VM_PROT_READ|VM_PROT_WRITE)
91 /* A useful macro to update the ppc_exception_state in the PCB
92 * before calling doexception
94 #define UPDATE_PPC_EXCEPTION_STATE { \
95 thread_t _thread = current_thread(); \
96 _thread->machine.pcb->save_dar = (uint64_t)dar; \
97 _thread->machine.pcb->save_dsisr = dsisr; \
98 _thread->machine.pcb->save_exception = trapno / T_VECTOR_SIZE; /* back to powerpc */ \
101 void unresolved_kernel_trap(int trapno
,
102 struct savearea
*ssp
,
105 const char *message
);
107 static void handleMck(struct savearea
*ssp
); /* Common machine check handler */
110 extern void get_procrustime(time_value_t
*);
111 extern void bsd_uprofil(time_value_t
*, user_addr_t
);
112 #endif /* MACH_BSD */
115 struct savearea
*trap(int trapno
,
116 struct savearea
*ssp
,
125 unsigned int space
, space2
;
126 vm_map_offset_t offset
;
127 thread_t thread
= current_thread();
133 #endif /* MACH_BSD */
135 myast
= ast_pending();
137 if(*myast
& AST_PPC_CHUD_ALL
) {
138 perfASTHook(trapno
, ssp
, dsisr
, (unsigned int)dar
);
141 *myast
&= ~AST_PPC_CHUD_ALL
;
144 if(perfTrapHook
) { /* Is there a hook? */
145 if(perfTrapHook(trapno
, ssp
, dsisr
, (unsigned int)dar
) == KERN_SUCCESS
) return ssp
; /* If it succeeds, we are done... */
150 extern void fctx_text(void);
155 exception
= 0; /* Clear exception for now */
158 * Remember that we are disabled for interruptions when we come in here. Because
159 * of latency concerns, we need to enable interruptions in the interrupted process
160 * was enabled itself as soon as we can.
163 intr
= (ssp
->save_srr1
& MASK(MSR_EE
)) != 0; /* Remember if we were enabled */
165 /* Handle kernel traps first */
167 if (!USER_MODE(ssp
->save_srr1
)) {
169 * Trap came from kernel
173 case T_PREEMPT
: /* Handle a preempt trap */
174 ast_taken(AST_PREEMPTION
, FALSE
);
178 perfmon_handle_pmi(ssp
);
181 case T_RESET
: /* Reset interruption */
182 if (!Call_Debugger(trapno
, ssp
))
183 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
184 break; /* We just ignore these */
187 * These trap types should never be seen by trap()
188 * in kernel mode, anyway.
189 * Some are interrupts that should be seen by
190 * interrupt() others just don't happen because they
191 * are handled elsewhere. Some could happen but are
192 * considered to be fatal in kernel mode.
195 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
196 case T_SYSTEM_MANAGEMENT
:
197 case T_ALTIVEC_ASSIST
:
199 case T_FP_UNAVAILABLE
:
203 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
208 * Here we handle a machine check in the kernel
211 case T_MACHINE_CHECK
:
212 handleMck(ssp
); /* Common to both user and kernel */
218 * If enaNotifyEMb is set, we get here, and
219 * we have actually already emulated the unaligned access.
220 * All that we want to do here is to ignore the interrupt. This is to allow logging or
221 * tracing of unaligned accesses.
224 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
225 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
); /* Go panic */
228 KERNEL_DEBUG_CONSTANT(
229 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
230 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
235 * If enaNotifyEMb is set we get here, and
236 * we have actually already emulated the instruction.
237 * All that we want to do here is to ignore the interrupt. This is to allow logging or
238 * tracing of emulated instructions.
241 KERNEL_DEBUG_CONSTANT(
242 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
243 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
251 case T_RUNMODE_TRACE
:
252 case T_INSTRUCTION_BKPT
:
253 if (!Call_Debugger(trapno
, ssp
))
254 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
258 if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
259 if (!Call_Debugger(trapno
, ssp
))
260 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
262 unresolved_kernel_trap(trapno
, ssp
,
269 mp_disable_preemption();
271 && getPerProc()->debugger_active
272 && !let_ddb_vm_fault
) {
274 * Force kdb to handle this one.
276 kdb_trap(trapno
, ssp
);
278 mp_enable_preemption();
279 #endif /* MACH_KDB */
280 /* can we take this during normal panic dump operation? */
282 && getPerProc()->debugger_active
285 * Access fault while in kernel core dump.
287 kdp_dump_trap(trapno
, ssp
);
291 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
292 panic("trap: disallowed access to cache inhibited memory - %016llX\n", dar
);
295 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
297 if(((dar
>> 28) < 0xE) | ((dar
>> 28) > 0xF)) { /* User memory window access? */
299 offset
= (vm_map_offset_t
)dar
; /* Set the failing address */
300 map
= kernel_map
; /* No, this is a normal kernel access */
303 * Note: Some ROM device drivers will access page 0 when they start. The IOKit will
304 * set a flag to tell us to ignore any access fault on page 0. After the driver is
305 * opened, it will clear the flag.
307 if((0 == (offset
& -PAGE_SIZE
)) && /* Check for access of page 0 and */
308 ((thread
->machine
.specFlags
) & ignoreZeroFault
)) { /* special case of ignoring page zero faults */
309 ssp
->save_srr0
+= 4; /* Point to next instruction */
313 code
= vm_fault(map
, vm_map_trunc_page(offset
),
314 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
315 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
317 if (code
!= KERN_SUCCESS
) {
318 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
320 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
321 ssp
->save_dsisr
= (ssp
->save_dsisr
&
322 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
327 /* If we get here, the fault was due to a user memory window access */
331 offset
= (vm_map_offset_t
)(thread
->machine
.umwRelo
+ dar
); /* Compute the user space address */
333 code
= vm_fault(map
, vm_map_trunc_page(offset
),
334 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
335 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
337 /* If we failed, there should be a recovery
340 if (code
!= KERN_SUCCESS
) {
341 if (thread
->recover
) {
342 ssp
->save_srr0
= thread
->recover
;
343 thread
->recover
= (vm_offset_t
)NULL
;
345 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "copyin/out has no recovery point");
349 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
350 ssp
->save_dsisr
= (ssp
->save_dsisr
&
351 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
356 case T_INSTRUCTION_ACCESS
:
360 && getPerProc()->debugger_active
361 && !let_ddb_vm_fault
) {
363 * Force kdb to handle this one.
365 kdb_trap(trapno
, ssp
);
367 #endif /* MACH_KDB */
369 /* Same as for data access, except fault type
370 * is PROT_EXEC and addr comes from srr0
373 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
377 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
378 PROT_EXEC
, FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
380 if (code
!= KERN_SUCCESS
) {
381 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
383 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
384 ssp
->save_srr1
= (ssp
->save_srr1
&
385 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
389 /* Usually shandler handles all the system calls, but the
390 * atomic thread switcher may throwup (via thandler) and
391 * have to pass it up to the exception handler.
395 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
399 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
405 * Processing for user state traps with interrupt enabled
406 * For T_AST, interrupts are enabled in the AST delivery
409 ml_set_interrupts_enabled(TRUE
);
413 get_procrustime(&tv
);
415 #endif /* MACH_BSD */
419 * Trap came from user task
425 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
429 perfmon_handle_pmi(ssp
);
433 * These trap types should never be seen by trap()
434 * Some are interrupts that should be seen by
435 * interrupt() others just don't happen because they
436 * are handled elsewhere.
439 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
441 case T_FP_UNAVAILABLE
:
442 case T_SYSTEM_MANAGEMENT
:
448 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
450 panic("Unexpected user state trap(cpu %d): 0x%08X DSISR=0x%08X DAR=0x%016llX PC=0x%016llX, MSR=0x%016llX\n",
451 cpu_number(), trapno
, dsisr
, dar
, ssp
->save_srr0
, ssp
->save_srr1
);
456 * Here we handle a machine check in user state
459 case T_MACHINE_CHECK
:
460 handleMck(ssp
); /* Common to both user and kernel */
464 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
465 if (!Call_Debugger(trapno
, ssp
))
466 panic("Unexpected Reset exception: srr0 = %016llx, srr1 = %016llx\n",
467 ssp
->save_srr0
, ssp
->save_srr1
);
468 break; /* We just ignore these */
472 * If enaNotifyEMb is set, we get here, and
473 * we have actually already emulated the unaligned access.
474 * All that we want to do here is to ignore the interrupt. This is to allow logging or
475 * tracing of unaligned accesses.
478 KERNEL_DEBUG_CONSTANT(
479 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
480 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
482 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
483 exception
= EXC_BAD_ACCESS
; /* Yes, throw exception */
484 code
= EXC_PPC_UNALIGNED
;
485 subcode
= (unsigned int)dar
;
491 * If enaNotifyEMb is set we get here, and
492 * we have actually already emulated the instruction.
493 * All that we want to do here is to ignore the interrupt. This is to allow logging or
494 * tracing of emulated instructions.
497 KERNEL_DEBUG_CONSTANT(
498 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
499 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
502 case T_TRACE
: /* Real PPC chips */
509 case T_INSTRUCTION_BKPT
:
510 exception
= EXC_BREAKPOINT
;
511 code
= EXC_PPC_TRACE
;
512 subcode
= (unsigned int)ssp
->save_srr0
;
516 if (ssp
->save_srr1
& MASK(SRR1_PRG_FE
)) {
517 fpu_save(thread
->machine
.curctx
);
518 UPDATE_PPC_EXCEPTION_STATE
;
519 exception
= EXC_ARITHMETIC
;
520 code
= EXC_ARITHMETIC
;
522 mp_disable_preemption();
523 subcode
= ssp
->save_fpscr
;
524 mp_enable_preemption();
526 else if (ssp
->save_srr1
& MASK(SRR1_PRG_ILL_INS
)) {
528 UPDATE_PPC_EXCEPTION_STATE
529 exception
= EXC_BAD_INSTRUCTION
;
530 code
= EXC_PPC_UNIPL_INST
;
531 subcode
= (unsigned int)ssp
->save_srr0
;
532 } else if ((unsigned int)ssp
->save_srr1
& MASK(SRR1_PRG_PRV_INS
)) {
534 UPDATE_PPC_EXCEPTION_STATE
;
535 exception
= EXC_BAD_INSTRUCTION
;
536 code
= EXC_PPC_PRIVINST
;
537 subcode
= (unsigned int)ssp
->save_srr0
;
538 } else if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
542 //iaddr = CAST_DOWN(char *, ssp->save_srr0); /* Trim from long long and make a char pointer */
543 if (copyin(ssp
->save_srr0
, (char *) &inst
, 4 )) panic("copyin failed\n");
545 if(dgWork
.dgFlags
& enaDiagTrap
) { /* Is the diagnostic trap enabled? */
546 if((inst
& 0xFFFFFFF0) == 0x0FFFFFF0) { /* Is this a TWI 31,R31,0xFFFx? */
547 if(diagTrap(ssp
, inst
& 0xF)) { /* Call the trap code */
548 ssp
->save_srr0
+= 4ULL; /* If we eat the trap, bump pc */
549 exception
= 0; /* Clear exception */
550 break; /* All done here */
555 UPDATE_PPC_EXCEPTION_STATE
;
557 if (inst
== 0x7FE00008) {
558 exception
= EXC_BREAKPOINT
;
559 code
= EXC_PPC_BREAKPOINT
;
561 exception
= EXC_SOFTWARE
;
564 subcode
= (unsigned int)ssp
->save_srr0
;
568 case T_ALTIVEC_ASSIST
:
569 UPDATE_PPC_EXCEPTION_STATE
;
570 exception
= EXC_ARITHMETIC
;
571 code
= EXC_PPC_ALTIVECASSIST
;
572 subcode
= (unsigned int)ssp
->save_srr0
;
578 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
579 UPDATE_PPC_EXCEPTION_STATE
; /* Don't even bother VM with this one */
580 exception
= EXC_BAD_ACCESS
;
581 subcode
= (unsigned int)dar
;
585 code
= vm_fault(map
, vm_map_trunc_page(dar
),
586 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
587 FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
589 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
590 UPDATE_PPC_EXCEPTION_STATE
;
591 exception
= EXC_BAD_ACCESS
;
592 subcode
= (unsigned int)dar
;
594 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
595 ssp
->save_dsisr
= (ssp
->save_dsisr
&
596 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
600 case T_INSTRUCTION_ACCESS
:
601 /* Same as for data access, except fault type
602 * is PROT_EXEC and addr comes from srr0
606 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
607 PROT_EXEC
, FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
609 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
610 UPDATE_PPC_EXCEPTION_STATE
;
611 exception
= EXC_BAD_ACCESS
;
612 subcode
= (unsigned int)ssp
->save_srr0
;
614 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
615 ssp
->save_srr1
= (ssp
->save_srr1
&
616 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
621 /* AST delivery is done below */
627 bsd_uprofil(&tv
, ssp
->save_srr0
);
629 #endif /* MACH_BSD */
633 /* if this is the init task, save the exception information */
634 /* this probably is a fatal exception */
636 if(bsd_init_task
== current_task()) {
640 buf
= init_task_failure_data
;
643 buf
+= sprintf(buf
, "Exception Code = 0x%x, Subcode = 0x%x\n", code
, subcode
);
644 buf
+= sprintf(buf
, "DSISR = 0x%08x, DAR = 0x%016llx\n"
647 for (i
=0; i
<32; i
++) {
649 buf
+= sprintf(buf
, "\n%4d :",i
);
651 buf
+= sprintf(buf
, " %08x",*(&ssp
->save_r0
+i
));
654 buf
+= sprintf(buf
, "\n\n");
655 buf
+= sprintf(buf
, "cr = 0x%08X\t\t",ssp
->save_cr
);
656 buf
+= sprintf(buf
, "xer = 0x%08X\n",ssp
->save_xer
);
657 buf
+= sprintf(buf
, "lr = 0x%016llX\t\t",ssp
->save_lr
);
658 buf
+= sprintf(buf
, "ctr = 0x%016llX\n",ssp
->save_ctr
);
659 buf
+= sprintf(buf
, "srr0(iar) = 0x%016llX\t\t",ssp
->save_srr0
);
660 buf
+= sprintf(buf
, "srr1(msr) = 0x%016llX\n",ssp
->save_srr1
,
661 "\x10\x11""EE\x12PR\x13""FP\x14ME\x15""FE0\x16SE\x18"
662 "FE1\x19""AL\x1a""EP\x1bIT\x1c""DT");
663 buf
+= sprintf(buf
, "\n\n");
665 /* generate some stack trace */
666 buf
+= sprintf(buf
, "Application level back trace:\n");
667 if (ssp
->save_srr1
& MASK(MSR_PR
)) {
668 char *addr
= (char*)ssp
->save_r1
;
669 unsigned int stack_buf
[3];
670 for (i
= 0; i
< 8; i
++) {
671 if (addr
== (char*)NULL
)
673 if (!copyin(ssp
->save_r1
,(char*)stack_buf
,
675 buf
+= sprintf(buf
, "0x%08X : 0x%08X\n"
677 addr
= (char*)stack_buf
[0];
686 doexception(exception
, code
, subcode
);
689 * Check to see if we need an AST, if so take care of it here
691 ml_set_interrupts_enabled(FALSE
);
693 if (USER_MODE(ssp
->save_srr1
)) {
694 myast
= ast_pending();
695 while (*myast
& AST_ALL
) {
696 ast_taken(AST_ALL
, intr
);
697 ml_set_interrupts_enabled(FALSE
);
698 myast
= ast_pending();
705 /* This routine is called from assembly before each and every system call.
706 * It must preserve r3.
709 extern int syscall_trace(int, struct savearea
*);
714 int syscall_trace(int retval
, struct savearea
*ssp
)
718 /* Always prepare to trace mach system calls */
724 argc
= mach_trap_table
[-((unsigned int)ssp
->save_r0
)].mach_trap_arg_count
;
729 for (i
=0; i
< argc
; i
++)
730 kdarg
[i
] = (int)*(&ssp
->save_r3
+ i
);
732 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
, (-(ssp
->save_r0
))) | DBG_FUNC_START
,
733 kdarg
[0], kdarg
[1], kdarg
[2], 0, 0);
738 /* This routine is called from assembly after each mach system call
739 * It must preserve r3.
742 extern int syscall_trace_end(int, struct savearea
*);
744 int syscall_trace_end(int retval
, struct savearea
*ssp
)
746 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-((unsigned int)ssp
->save_r0
))) | DBG_FUNC_END
,
752 * called from syscall if there is an error
759 struct savearea
*ssp
)
761 register thread_t thread
;
763 thread
= current_thread();
766 panic("syscall error in boot phase");
768 if (!USER_MODE(ssp
->save_srr1
))
769 panic("system call called from kernel");
771 doexception(exception
, code
, subcode
);
776 /* Pass up a server syscall/exception */
783 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
787 exception_triage(exc
, codes
, 2);
790 char *trap_type
[] = {
792 "0x100 - System reset",
793 "0x200 - Machine check",
794 "0x300 - Data access",
795 "0x400 - Inst access",
799 "0x800 - Floating point",
800 "0x900 - Decrementer",
803 "0xC00 - System call",
811 "0x1300 - Inst bkpnt",
813 "0x1600 - Altivec Assist",
824 "0x2000 - Run Mode/Trace",
831 int TRAP_TYPES
= sizeof (trap_type
) / sizeof (trap_type
[0]);
833 void unresolved_kernel_trap(int trapno
,
834 struct savearea
*ssp
,
840 extern void print_backtrace(struct savearea
*);
841 extern unsigned int debug_mode
, disableDebugOuput
;
842 extern unsigned long panic_caller
;
844 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
845 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
847 if( logPanicDataToScreen
)
848 disableDebugOuput
= FALSE
;
851 if ((unsigned)trapno
<= T_MAX
)
852 trap_name
= trap_type
[trapno
/ T_VECTOR_SIZE
];
854 trap_name
= "???? unrecognized exception";
858 kdb_printf("\n\nUnresolved kernel trap(cpu %d): %s DAR=0x%016llX PC=0x%016llX\n",
859 cpu_number(), trap_name
, dar
, ssp
->save_srr0
);
861 print_backtrace(ssp
);
863 panic_caller
= (0xFFFF0000 | (trapno
/ T_VECTOR_SIZE
) );
867 (void *)Call_Debugger(trapno
, ssp
);
871 const char *corr
[2] = {"uncorrected", "corrected "};
873 void handleMck(struct savearea
*ssp
) { /* Common machine check handler */
879 printf("Machine check (%d) - %s - pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n",
880 cpu
, corr
[ssp
->save_hdr
.save_misc3
], ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
); /* Tell us about it */
881 printf("Machine check (%d) - AsyncSrc = %016llX, CoreFIR = %016llx\n", cpu
, ssp
->save_xdat0
, ssp
->save_xdat1
);
882 printf("Machine check (%d) - L2FIR = %016llX, BusFir = %016llx\n", cpu
, ssp
->save_xdat2
, ssp
->save_xdat3
);
884 if(ssp
->save_hdr
.save_misc3
) return; /* Leave the the machine check was recovered */
886 panic("Uncorrectable machine check: pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n"
887 " AsyncSrc = %016llX, CoreFIR = %016llx\n"
888 " L2FIR = %016llX, BusFir = %016llx\n",
889 ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
,
890 ssp
->save_xdat0
, ssp
->save_xdat1
, ssp
->save_xdat2
, ssp
->save_xdat3
);
896 thread_syscall_return(
899 register thread_t thread
= current_thread();
900 register struct savearea
*regs
= USER_REGS(thread
);
902 if (kdebug_enable
&& ((unsigned int)regs
->save_r0
& 0x80000000)) {
904 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-(regs
->save_r0
))) | DBG_FUNC_END
,
909 thread_exception_return();
916 thread_kdb_return(void)
918 register thread_t thread
= current_thread();
919 register struct savearea
*regs
= USER_REGS(thread
);
921 Call_Debugger(thread
->machine
.pcb
->save_exception
, regs
);
922 thread_exception_return();
925 #endif /* MACH_KDB */