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)
92 /* A useful macro to update the ppc_exception_state in the PCB
93 * before calling doexception
95 #define UPDATE_PPC_EXCEPTION_STATE { \
96 thread_t _thread = current_thread(); \
97 _thread->machine.pcb->save_dar = (uint64_t)dar; \
98 _thread->machine.pcb->save_dsisr = dsisr; \
99 _thread->machine.pcb->save_exception = trapno / T_VECTOR_SIZE; /* back to powerpc */ \
102 void unresolved_kernel_trap(int trapno
,
103 struct savearea
*ssp
,
106 const char *message
);
108 static void handleMck(struct savearea
*ssp
); /* Common machine check handler */
111 extern void get_procrustime(time_value_t
*);
112 extern void bsd_uprofil(time_value_t
*, user_addr_t
);
113 #endif /* MACH_BSD */
116 struct savearea
*trap(int trapno
,
117 struct savearea
*ssp
,
126 unsigned int space
, space2
;
127 vm_map_offset_t offset
;
128 thread_t thread
= current_thread();
134 #endif /* MACH_BSD */
136 myast
= ast_pending();
138 if(*myast
& AST_CHUD_ALL
) {
139 perfASTHook(trapno
, ssp
, dsisr
, (unsigned int)dar
);
142 *myast
&= ~AST_CHUD_ALL
;
145 if(perfTrapHook
) { /* Is there a hook? */
146 if(perfTrapHook(trapno
, ssp
, dsisr
, (unsigned int)dar
) == KERN_SUCCESS
) return ssp
; /* If it succeeds, we are done... */
151 extern void fctx_text(void);
156 exception
= 0; /* Clear exception for now */
159 * Remember that we are disabled for interruptions when we come in here. Because
160 * of latency concerns, we need to enable interruptions in the interrupted process
161 * was enabled itself as soon as we can.
164 intr
= (ssp
->save_srr1
& MASK(MSR_EE
)) != 0; /* Remember if we were enabled */
166 /* Handle kernel traps first */
168 if (!USER_MODE(ssp
->save_srr1
)) {
170 * Trap came from kernel
174 case T_PREEMPT
: /* Handle a preempt trap */
175 ast_taken(AST_PREEMPTION
, FALSE
);
179 perfmon_handle_pmi(ssp
);
182 case T_RESET
: /* Reset interruption */
183 if (!Call_Debugger(trapno
, ssp
))
184 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
185 break; /* We just ignore these */
188 * These trap types should never be seen by trap()
189 * in kernel mode, anyway.
190 * Some are interrupts that should be seen by
191 * interrupt() others just don't happen because they
192 * are handled elsewhere. Some could happen but are
193 * considered to be fatal in kernel mode.
196 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
197 case T_SYSTEM_MANAGEMENT
:
198 case T_ALTIVEC_ASSIST
:
200 case T_FP_UNAVAILABLE
:
204 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
209 * Here we handle a machine check in the kernel
212 case T_MACHINE_CHECK
:
213 handleMck(ssp
); /* Common to both user and kernel */
219 * If enaNotifyEMb is set, we get here, and
220 * we have actually already emulated the unaligned access.
221 * All that we want to do here is to ignore the interrupt. This is to allow logging or
222 * tracing of unaligned accesses.
225 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
226 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
); /* Go panic */
229 KERNEL_DEBUG_CONSTANT(
230 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
231 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
236 * If enaNotifyEMb is set we get here, and
237 * we have actually already emulated the instruction.
238 * All that we want to do here is to ignore the interrupt. This is to allow logging or
239 * tracing of emulated instructions.
242 KERNEL_DEBUG_CONSTANT(
243 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
244 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
252 case T_RUNMODE_TRACE
:
253 case T_INSTRUCTION_BKPT
:
254 if (!Call_Debugger(trapno
, ssp
))
255 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
259 if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
260 if (!Call_Debugger(trapno
, ssp
))
261 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
263 unresolved_kernel_trap(trapno
, ssp
,
270 mp_disable_preemption();
272 && getPerProc()->debugger_active
273 && !let_ddb_vm_fault
) {
275 * Force kdb to handle this one.
277 kdb_trap(trapno
, ssp
);
279 mp_enable_preemption();
280 #endif /* MACH_KDB */
281 /* can we take this during normal panic dump operation? */
283 && getPerProc()->debugger_active
286 * Access fault while in kernel core dump.
288 kdp_dump_trap(trapno
, ssp
);
292 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
293 panic("trap: disallowed access to cache inhibited memory - %016llX\n", dar
);
296 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
298 if(((dar
>> 28) < 0xE) | ((dar
>> 28) > 0xF)) { /* User memory window access? */
300 offset
= (vm_map_offset_t
)dar
; /* Set the failing address */
301 map
= kernel_map
; /* No, this is a normal kernel access */
304 * Note: Some ROM device drivers will access page 0 when they start. The IOKit will
305 * set a flag to tell us to ignore any access fault on page 0. After the driver is
306 * opened, it will clear the flag.
308 if((0 == (offset
& -PAGE_SIZE
)) && /* Check for access of page 0 and */
309 ((thread
->machine
.specFlags
) & ignoreZeroFault
)) { /* special case of ignoring page zero faults */
310 ssp
->save_srr0
+= 4; /* Point to next instruction */
314 code
= vm_fault(map
, vm_map_trunc_page(offset
),
315 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
316 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
318 if (code
!= KERN_SUCCESS
) {
319 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
321 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
322 ssp
->save_dsisr
= (ssp
->save_dsisr
&
323 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
328 /* If we get here, the fault was due to a user memory window access */
332 offset
= (vm_map_offset_t
)(thread
->machine
.umwRelo
+ dar
); /* Compute the user space address */
334 code
= vm_fault(map
, vm_map_trunc_page(offset
),
335 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
336 FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
338 /* If we failed, there should be a recovery
341 if (code
!= KERN_SUCCESS
) {
342 if (thread
->recover
) {
343 ssp
->save_srr0
= thread
->recover
;
344 thread
->recover
= (vm_offset_t
)NULL
;
346 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, "copyin/out has no recovery point");
350 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
351 ssp
->save_dsisr
= (ssp
->save_dsisr
&
352 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
357 case T_INSTRUCTION_ACCESS
:
361 && getPerProc()->debugger_active
362 && !let_ddb_vm_fault
) {
364 * Force kdb to handle this one.
366 kdb_trap(trapno
, ssp
);
368 #endif /* MACH_KDB */
370 /* Same as for data access, except fault type
371 * is PROT_EXEC and addr comes from srr0
374 if(intr
) ml_set_interrupts_enabled(TRUE
); /* Enable if we were */
378 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
379 (PROT_EXEC
| PROT_RO
), FALSE
, THREAD_UNINT
, NULL
, vm_map_trunc_page(0));
381 if (code
!= KERN_SUCCESS
) {
382 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
384 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
385 ssp
->save_srr1
= (ssp
->save_srr1
&
386 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
390 /* Usually shandler handles all the system calls, but the
391 * atomic thread switcher may throwup (via thandler) and
392 * have to pass it up to the exception handler.
396 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
400 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
406 * Processing for user state traps with interrupt enabled
407 * For T_AST, interrupts are enabled in the AST delivery
410 ml_set_interrupts_enabled(TRUE
);
414 get_procrustime(&tv
);
416 #endif /* MACH_BSD */
420 * Trap came from user task
426 unresolved_kernel_trap(trapno
, ssp
, dsisr
, dar
, NULL
);
430 perfmon_handle_pmi(ssp
);
434 * These trap types should never be seen by trap()
435 * Some are interrupts that should be seen by
436 * interrupt() others just don't happen because they
437 * are handled elsewhere.
440 case T_IN_VAIN
: /* Shouldn't ever see this, lowmem_vectors eats it */
442 case T_FP_UNAVAILABLE
:
443 case T_SYSTEM_MANAGEMENT
:
449 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
451 panic("Unexpected user state trap(cpu %d): 0x%08X DSISR=0x%08X DAR=0x%016llX PC=0x%016llX, MSR=0x%016llX\n",
452 cpu_number(), trapno
, dsisr
, dar
, ssp
->save_srr0
, ssp
->save_srr1
);
457 * Here we handle a machine check in user state
460 case T_MACHINE_CHECK
:
461 handleMck(ssp
); /* Common to both user and kernel */
465 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
466 if (!Call_Debugger(trapno
, ssp
))
467 panic("Unexpected Reset exception: srr0 = %016llx, srr1 = %016llx\n",
468 ssp
->save_srr0
, ssp
->save_srr1
);
469 break; /* We just ignore these */
473 * If enaNotifyEMb is set, we get here, and
474 * we have actually already emulated the unaligned access.
475 * All that we want to do here is to ignore the interrupt. This is to allow logging or
476 * tracing of unaligned accesses.
479 KERNEL_DEBUG_CONSTANT(
480 MACHDBG_CODE(DBG_MACH_EXCP_ALNG
, 0) | DBG_FUNC_NONE
,
481 (int)ssp
->save_srr0
- 4, (int)dar
, (int)dsisr
, (int)ssp
->save_lr
, 0);
483 if(ssp
->save_hdr
.save_misc3
) { /* Was it a handled exception? */
484 exception
= EXC_BAD_ACCESS
; /* Yes, throw exception */
485 code
= EXC_PPC_UNALIGNED
;
486 subcode
= (unsigned int)dar
;
492 * If enaNotifyEMb is set we get here, and
493 * we have actually already emulated the instruction.
494 * All that we want to do here is to ignore the interrupt. This is to allow logging or
495 * tracing of emulated instructions.
498 KERNEL_DEBUG_CONSTANT(
499 MACHDBG_CODE(DBG_MACH_EXCP_EMUL
, 0) | DBG_FUNC_NONE
,
500 (int)ssp
->save_srr0
- 4, (int)((savearea_comm
*)ssp
)->save_misc2
, (int)dsisr
, (int)ssp
->save_lr
, 0);
503 case T_TRACE
: /* Real PPC chips */
510 case T_INSTRUCTION_BKPT
:
511 exception
= EXC_BREAKPOINT
;
512 code
= EXC_PPC_TRACE
;
513 subcode
= (unsigned int)ssp
->save_srr0
;
517 if (ssp
->save_srr1
& MASK(SRR1_PRG_FE
)) {
518 fpu_save(thread
->machine
.curctx
);
519 UPDATE_PPC_EXCEPTION_STATE
;
520 exception
= EXC_ARITHMETIC
;
521 code
= EXC_ARITHMETIC
;
523 mp_disable_preemption();
524 subcode
= ssp
->save_fpscr
;
525 mp_enable_preemption();
527 else if (ssp
->save_srr1
& MASK(SRR1_PRG_ILL_INS
)) {
529 UPDATE_PPC_EXCEPTION_STATE
530 exception
= EXC_BAD_INSTRUCTION
;
531 code
= EXC_PPC_UNIPL_INST
;
532 subcode
= (unsigned int)ssp
->save_srr0
;
533 } else if ((unsigned int)ssp
->save_srr1
& MASK(SRR1_PRG_PRV_INS
)) {
535 UPDATE_PPC_EXCEPTION_STATE
;
536 exception
= EXC_BAD_INSTRUCTION
;
537 code
= EXC_PPC_PRIVINST
;
538 subcode
= (unsigned int)ssp
->save_srr0
;
539 } else if (ssp
->save_srr1
& MASK(SRR1_PRG_TRAP
)) {
543 //iaddr = CAST_DOWN(char *, ssp->save_srr0); /* Trim from long long and make a char pointer */
544 if (copyin(ssp
->save_srr0
, (char *) &inst
, 4 )) panic("copyin failed\n");
546 if(dgWork
.dgFlags
& enaDiagTrap
) { /* Is the diagnostic trap enabled? */
547 if((inst
& 0xFFFFFFF0) == 0x0FFFFFF0) { /* Is this a TWI 31,R31,0xFFFx? */
548 if(diagTrap(ssp
, inst
& 0xF)) { /* Call the trap code */
549 ssp
->save_srr0
+= 4ULL; /* If we eat the trap, bump pc */
550 exception
= 0; /* Clear exception */
551 break; /* All done here */
556 UPDATE_PPC_EXCEPTION_STATE
;
558 if (inst
== 0x7FE00008) {
559 exception
= EXC_BREAKPOINT
;
560 code
= EXC_PPC_BREAKPOINT
;
562 exception
= EXC_SOFTWARE
;
565 subcode
= (unsigned int)ssp
->save_srr0
;
569 case T_ALTIVEC_ASSIST
:
570 UPDATE_PPC_EXCEPTION_STATE
;
571 exception
= EXC_ARITHMETIC
;
572 code
= EXC_PPC_ALTIVECASSIST
;
573 subcode
= (unsigned int)ssp
->save_srr0
;
579 if(ssp
->save_dsisr
& dsiInvMode
) { /* Did someone try to reserve cache inhibited? */
580 UPDATE_PPC_EXCEPTION_STATE
; /* Don't even bother VM with this one */
581 exception
= EXC_BAD_ACCESS
;
582 subcode
= (unsigned int)dar
;
586 code
= vm_fault(map
, vm_map_trunc_page(dar
),
587 dsisr
& MASK(DSISR_WRITE
) ? PROT_RW
: PROT_RO
,
588 FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
590 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
591 UPDATE_PPC_EXCEPTION_STATE
;
592 exception
= EXC_BAD_ACCESS
;
593 subcode
= (unsigned int)dar
;
595 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
596 ssp
->save_dsisr
= (ssp
->save_dsisr
&
597 ~((MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
601 case T_INSTRUCTION_ACCESS
:
602 /* Same as for data access, except fault type
603 * is PROT_EXEC and addr comes from srr0
607 code
= vm_fault(map
, vm_map_trunc_page(ssp
->save_srr0
),
608 (PROT_EXEC
| PROT_RO
), FALSE
, THREAD_ABORTSAFE
, NULL
, vm_map_trunc_page(0));
610 if ((code
!= KERN_SUCCESS
) && (code
!= KERN_ABORTED
)) {
611 UPDATE_PPC_EXCEPTION_STATE
;
612 exception
= EXC_BAD_ACCESS
;
613 subcode
= (unsigned int)ssp
->save_srr0
;
615 ssp
->save_hdr
.save_flags
|= SAVredrive
; /* Tell low-level to re-try fault */
616 ssp
->save_srr1
= (ssp
->save_srr1
&
617 ~((unsigned long long)(MASK(DSISR_NOEX
) | MASK(DSISR_PROT
)))) | MASK(DSISR_HASH
); /* Make sure this is marked as a miss */
622 /* AST delivery is done below */
628 bsd_uprofil(&tv
, ssp
->save_srr0
);
630 #endif /* MACH_BSD */
634 /* if this is the init task, save the exception information */
635 /* this probably is a fatal exception */
637 if(bsd_init_task
== current_task()) {
641 buf
= init_task_failure_data
;
644 buf
+= sprintf(buf
, "Exception Code = 0x%x, Subcode = 0x%x\n", code
, subcode
);
645 buf
+= sprintf(buf
, "DSISR = 0x%08x, DAR = 0x%016llx\n"
648 for (i
=0; i
<32; i
++) {
650 buf
+= sprintf(buf
, "\n%4d :",i
);
652 buf
+= sprintf(buf
, " %08x",*(&ssp
->save_r0
+i
));
655 buf
+= sprintf(buf
, "\n\n");
656 buf
+= sprintf(buf
, "cr = 0x%08X\t\t",ssp
->save_cr
);
657 buf
+= sprintf(buf
, "xer = 0x%08X\n",ssp
->save_xer
);
658 buf
+= sprintf(buf
, "lr = 0x%016llX\t\t",ssp
->save_lr
);
659 buf
+= sprintf(buf
, "ctr = 0x%016llX\n",ssp
->save_ctr
);
660 buf
+= sprintf(buf
, "srr0(iar) = 0x%016llX\t\t",ssp
->save_srr0
);
661 buf
+= sprintf(buf
, "srr1(msr) = 0x%016llX\n",ssp
->save_srr1
,
662 "\x10\x11""EE\x12PR\x13""FP\x14ME\x15""FE0\x16SE\x18"
663 "FE1\x19""AL\x1a""EP\x1bIT\x1c""DT");
664 buf
+= sprintf(buf
, "\n\n");
666 /* generate some stack trace */
667 buf
+= sprintf(buf
, "Application level back trace:\n");
668 if (ssp
->save_srr1
& MASK(MSR_PR
)) {
669 char *addr
= (char*)ssp
->save_r1
;
670 unsigned int stack_buf
[3];
671 for (i
= 0; i
< 8; i
++) {
672 if (addr
== (char*)NULL
)
674 if (!copyin(ssp
->save_r1
,(char*)stack_buf
,
676 buf
+= sprintf(buf
, "0x%08X : 0x%08X\n"
678 addr
= (char*)stack_buf
[0];
687 doexception(exception
, code
, subcode
);
690 * Check to see if we need an AST, if so take care of it here
692 ml_set_interrupts_enabled(FALSE
);
694 if (USER_MODE(ssp
->save_srr1
)) {
695 myast
= ast_pending();
696 while (*myast
& AST_ALL
) {
697 ast_taken(AST_ALL
, intr
);
698 ml_set_interrupts_enabled(FALSE
);
699 myast
= ast_pending();
706 /* This routine is called from assembly before each and every system call.
707 * It must preserve r3.
710 extern int syscall_trace(int, struct savearea
*);
715 int syscall_trace(int retval
, struct savearea
*ssp
)
719 /* Always prepare to trace mach system calls */
725 argc
= mach_trap_table
[-((unsigned int)ssp
->save_r0
)].mach_trap_arg_count
;
730 for (i
=0; i
< argc
; i
++)
731 kdarg
[i
] = (int)*(&ssp
->save_r3
+ i
);
733 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
, (-(ssp
->save_r0
))) | DBG_FUNC_START
,
734 kdarg
[0], kdarg
[1], kdarg
[2], 0, 0);
739 /* This routine is called from assembly after each mach system call
740 * It must preserve r3.
743 extern int syscall_trace_end(int, struct savearea
*);
745 int syscall_trace_end(int retval
, struct savearea
*ssp
)
747 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-((unsigned int)ssp
->save_r0
))) | DBG_FUNC_END
,
753 * called from syscall if there is an error
760 struct savearea
*ssp
)
762 register thread_t thread
;
764 thread
= current_thread();
767 panic("syscall error in boot phase");
769 if (!USER_MODE(ssp
->save_srr1
))
770 panic("system call called from kernel");
772 doexception(exception
, code
, subcode
);
777 /* Pass up a server syscall/exception */
784 exception_data_type_t codes
[EXCEPTION_CODE_MAX
];
788 exception_triage(exc
, codes
, 2);
791 char *trap_type
[] = {
793 "0x100 - System reset",
794 "0x200 - Machine check",
795 "0x300 - Data access",
796 "0x400 - Inst access",
800 "0x800 - Floating point",
801 "0x900 - Decrementer",
804 "0xC00 - System call",
812 "0x1300 - Inst bkpnt",
814 "0x1600 - Altivec Assist",
825 "0x2000 - Run Mode/Trace",
832 int TRAP_TYPES
= sizeof (trap_type
) / sizeof (trap_type
[0]);
834 void unresolved_kernel_trap(int trapno
,
835 struct savearea
*ssp
,
841 extern void print_backtrace(struct savearea
*);
842 extern unsigned int debug_mode
, disableDebugOuput
;
843 extern unsigned long panic_caller
;
845 ml_set_interrupts_enabled(FALSE
); /* Turn off interruptions */
846 lastTrace
= LLTraceSet(0); /* Disable low-level tracing */
848 if( logPanicDataToScreen
)
849 disableDebugOuput
= FALSE
;
852 if ((unsigned)trapno
<= T_MAX
)
853 trap_name
= trap_type
[trapno
/ T_VECTOR_SIZE
];
855 trap_name
= "???? unrecognized exception";
859 kdb_printf("\n\nUnresolved kernel trap(cpu %d): %s DAR=0x%016llX PC=0x%016llX\n",
860 cpu_number(), trap_name
, dar
, ssp
->save_srr0
);
862 print_backtrace(ssp
);
864 panic_caller
= (0xFFFF0000 | (trapno
/ T_VECTOR_SIZE
) );
868 (void *)Call_Debugger(trapno
, ssp
);
872 const char *corr
[2] = {"uncorrected", "corrected "};
874 void handleMck(struct savearea
*ssp
) { /* Common machine check handler */
880 printf("Machine check (%d) - %s - pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n",
881 cpu
, corr
[ssp
->save_hdr
.save_misc3
], ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
); /* Tell us about it */
882 printf("Machine check (%d) - AsyncSrc = %016llX, CoreFIR = %016llx\n", cpu
, ssp
->save_xdat0
, ssp
->save_xdat1
);
883 printf("Machine check (%d) - L2FIR = %016llX, BusFir = %016llx\n", cpu
, ssp
->save_xdat2
, ssp
->save_xdat3
);
885 if(ssp
->save_hdr
.save_misc3
) return; /* Leave the the machine check was recovered */
887 panic("Uncorrectable machine check: pc = %016llX, msr = %016llX, dsisr = %08X, dar = %016llX\n"
888 " AsyncSrc = %016llX, CoreFIR = %016llx\n"
889 " L2FIR = %016llX, BusFir = %016llx\n",
890 ssp
->save_srr0
, ssp
->save_srr1
, ssp
->save_dsisr
, ssp
->save_dar
,
891 ssp
->save_xdat0
, ssp
->save_xdat1
, ssp
->save_xdat2
, ssp
->save_xdat3
);
897 thread_syscall_return(
900 register thread_t thread
= current_thread();
901 register struct savearea
*regs
= USER_REGS(thread
);
903 if (kdebug_enable
&& ((unsigned int)regs
->save_r0
& 0x80000000)) {
905 KERNEL_DEBUG_CONSTANT(MACHDBG_CODE(DBG_MACH_EXCP_SC
,(-(regs
->save_r0
))) | DBG_FUNC_END
,
910 thread_exception_return();
917 thread_kdb_return(void)
919 register thread_t thread
= current_thread();
920 register struct savearea
*regs
= USER_REGS(thread
);
922 Call_Debugger(thread
->machine
.pcb
->save_exception
, regs
);
923 thread_exception_return();
926 #endif /* MACH_KDB */