]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/trap_native.c
2 * Copyright (c) 2009-2012 Apple 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@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
60 * Hardware trap/fault handler.
64 #include <i386/eflags.h>
65 #include <i386/trap.h>
66 #include <i386/pmap.h>
68 #include <i386/misc_protos.h> /* panic_io_port_read() */
70 #include <mach/exception.h>
71 #include <mach/kern_return.h>
72 #include <mach/vm_param.h>
73 #include <mach/i386/thread_status.h>
75 #include <kern/kern_types.h>
76 #include <kern/processor.h>
77 #include <kern/thread.h>
78 #include <kern/task.h>
79 #include <kern/sched.h>
80 #include <kern/sched_prim.h>
81 #include <kern/exception.h>
83 #include <kern/misc_protos.h>
84 #include <kern/debug.h>
86 #include <sys/kdebug.h>
90 #include <i386/postcode.h>
91 #include <i386/mp_desc.h>
92 #include <i386/proc_reg.h>
94 #include <i386/machine_check.h>
96 #include <mach/i386/syscall_sw.h>
98 #include <machine/pal_routines.h>
99 #include <libkern/OSAtomic.h>
101 extern void kprintf_break_lock(void);
102 extern void kprint_state(x86_saved_state64_t
*saved_state
);
103 void panic_64(x86_saved_state_t
*, int, const char *, boolean_t
);
105 extern volatile int panic_double_fault_cpu
;
108 #if defined(__x86_64__) && DEBUG
110 * K64 debug - fatal handler for debug code in the trap vectors.
113 panic_idt64(x86_saved_state_t
*rsp
);
115 panic_idt64(x86_saved_state_t
*rsp
)
117 kprint_state(saved_state64(rsp
));
118 panic("panic_idt64");
124 panic_64(x86_saved_state_t
*sp
, __unused
int pc
, __unused
const char *msg
, boolean_t do_mca_dump
)
126 /* Set postcode (DEBUG only) */
130 * Issue an I/O port read if one has been requested - this is an
131 * event logic analyzers can use as a trigger point.
133 panic_io_port_read();
137 * Break kprintf lock in case of recursion,
138 * and record originally faulted instruction address.
140 kprintf_break_lock();
145 * Dump the contents of the machine check MSRs (if any).
151 x86_saved_state64_t
*regs
= saved_state64(sp
);
152 panic("%s at 0x%016llx, registers:\n"
153 "CR0: 0x%016lx, CR2: 0x%016lx, CR3: 0x%016lx, CR4: 0x%016lx\n"
154 "RAX: 0x%016llx, RBX: 0x%016llx, RCX: 0x%016llx, RDX: 0x%016llx\n"
155 "RSP: 0x%016llx, RBP: 0x%016llx, RSI: 0x%016llx, RDI: 0x%016llx\n"
156 "R8: 0x%016llx, R9: 0x%016llx, R10: 0x%016llx, R11: 0x%016llx\n"
157 "R12: 0x%016llx, R13: 0x%016llx, R14: 0x%016llx, R15: 0x%016llx\n"
158 "RFL: 0x%016llx, RIP: 0x%016llx, CS: 0x%016llx, SS: 0x%016llx\n"
159 "Error code: 0x%016llx%s\n",
162 get_cr0(), get_cr2(), get_cr3_raw(), get_cr4(),
163 regs
->rax
, regs
->rbx
, regs
->rcx
, regs
->rdx
,
164 regs
->isf
.rsp
, regs
->rbp
, regs
->rsi
, regs
->rdi
,
165 regs
->r8
, regs
->r9
, regs
->r10
, regs
->r11
,
166 regs
->r12
, regs
->r13
, regs
->r14
, regs
->r15
,
167 regs
->isf
.rflags
, regs
->isf
.rip
, regs
->isf
.cs
& 0xFFFF, regs
->isf
.ss
& 0xFFFF,
168 regs
->isf
.err
, virtualized
? " VMM" : "");
172 panic_double_fault64(x86_saved_state_t
*sp
)
174 (void)OSCompareAndSwap((UInt32
) -1, (UInt32
) cpu_number(), (volatile UInt32
*)&panic_double_fault_cpu
);
175 panic_64(sp
, PANIC_DOUBLE_FAULT
, "Double fault", FALSE
);
180 panic_machine_check64(x86_saved_state_t
*sp
)
182 panic_64(sp
, PANIC_MACHINE_CHECK
, "Machine Check", TRUE
);