X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/c0fea4742e91338fffdcf79f86a7c1d5e2b97eb1..8ad349bb6ed4a0be06e34c92be0d98b92e078db4:/osfmk/kdp/ml/i386/kdp_machdep.c?ds=sidebyside diff --git a/osfmk/kdp/ml/i386/kdp_machdep.c b/osfmk/kdp/ml/i386/kdp_machdep.c index 09e93e2b4..5faa82a74 100644 --- a/osfmk/kdp/ml/i386/kdp_machdep.c +++ b/osfmk/kdp/ml/i386/kdp_machdep.c @@ -1,26 +1,33 @@ /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. - * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the + * License may not be used to create, or enable the creation or + * redistribution of, unlawful or unlicensed copies of an Apple operating + * system, or to circumvent, violate, or enable the circumvention or + * violation of, any terms of an Apple operating system software license + * agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ */ -#include #include #include #include @@ -28,15 +35,6 @@ #include #include #include -#include -#include -#include /* for PE_halt_restart */ -#include /* for halt_all_cpus */ - -#include -#include -#include -#include #define KDP_TEST_HARNESS 0 #if KDP_TEST_HARNESS @@ -45,8 +43,7 @@ #define dprintf(x) #endif -extern cpu_type_t cpuid_cputype(void); -extern cpu_subtype_t cpuid_cpusubtype(void); +extern void kdreboot(void); void print_saved_state(void *); void kdp_call(void); @@ -55,14 +52,12 @@ boolean_t kdp_call_kdb(void); void kdp_getstate(i386_thread_state_t *); void kdp_setstate(i386_thread_state_t *); void kdp_print_phys(int); - -int -machine_trace_thread(thread_t thread, uint32_t tracepos, uint32_t tracebound, int nframes, boolean_t user_p); - -int -machine_trace_thread64(thread_t thread, uint32_t tracepos, uint32_t tracebound, int nframes, boolean_t user_p); - -extern unsigned kdp_vm_read(caddr_t src, caddr_t dst, unsigned len); +void kdp_i386_backtrace(void *, int); +void kdp_i386_trap( + unsigned int, + struct i386_saved_state *, + kern_return_t, + vm_offset_t); void kdp_exception( @@ -123,13 +118,13 @@ kdp_exception_ack( void kdp_getstate( - x86_thread_state32_t *state + i386_thread_state_t *state ) { - static x86_thread_state32_t null_state; - x86_saved_state32_t *saved_state; + static i386_thread_state_t null_state; + struct i386_saved_state *saved_state; - saved_state = (x86_saved_state32_t *)kdp.saved_state; + saved_state = (struct i386_saved_state *)kdp.saved_state; *state = null_state; state->eax = saved_state->eax; @@ -160,12 +155,12 @@ kdp_getstate( void kdp_setstate( - x86_thread_state32_t *state + i386_thread_state_t *state ) { - x86_saved_state32_t *saved_state; + struct i386_saved_state *saved_state; - saved_state = (x86_saved_state32_t *)kdp.saved_state; + saved_state = (struct i386_saved_state *)kdp.saved_state; saved_state->eax = state->eax; saved_state->ebx = state->ebx; @@ -193,21 +188,20 @@ kdp_machine_read_regs( __unused int *size ) { - static struct i386_float_state null_fpstate; + static i386_thread_fpstate_t null_fpstate; switch (flavor) { - case OLD_i386_THREAD_STATE: - case x86_THREAD_STATE32: + case i386_THREAD_STATE: dprintf(("kdp_readregs THREAD_STATE\n")); - kdp_getstate((x86_thread_state32_t *)data); - *size = sizeof (x86_thread_state32_t); + kdp_getstate((i386_thread_state_t *)data); + *size = sizeof (i386_thread_state_t); return KDPERR_NO_ERROR; - case x86_FLOAT_STATE32: + case i386_THREAD_FPSTATE: dprintf(("kdp_readregs THREAD_FPSTATE\n")); - *(x86_float_state32_t *)data = null_fpstate; - *size = sizeof (x86_float_state32_t); + *(i386_thread_fpstate_t *)data = null_fpstate; + *size = sizeof (i386_thread_fpstate_t); return KDPERR_NO_ERROR; default: @@ -227,13 +221,12 @@ kdp_machine_write_regs( { switch (flavor) { - case OLD_i386_THREAD_STATE: - case x86_THREAD_STATE32: + case i386_THREAD_STATE: dprintf(("kdp_writeregs THREAD_STATE\n")); - kdp_setstate((x86_thread_state32_t *)data); + kdp_setstate((i386_thread_state_t *)data); return KDPERR_NO_ERROR; - case x86_FLOAT_STATE32: + case i386_THREAD_FPSTATE: dprintf(("kdp_writeregs THREAD_FPSTATE\n")); return KDPERR_NO_ERROR; @@ -261,8 +254,9 @@ kdp_machine_hostinfo( hostinfo->cpus_mask |= (1 << i); } - hostinfo->cpu_type = cpuid_cputype(); - hostinfo->cpu_subtype = cpuid_cpusubtype(); + /* FIXME?? */ + hostinfo->cpu_type = CPU_TYPE_I386; + hostinfo->cpu_subtype = CPU_SUBTYPE_486; } void @@ -278,12 +272,7 @@ kdp_panic( void kdp_reboot(void) { - printf("Attempting system restart..."); - /* Call the platform specific restart*/ - if (PE_halt_restart) - (*PE_halt_restart)(kPERestartCPU); - /* If we do reach this, give up */ - halt_all_cpus(TRUE); + kdreboot(); } int @@ -312,14 +301,14 @@ kdp_us_spin(int usec) void print_saved_state(void *state) { - x86_saved_state32_t *saved_state; + struct i386_saved_state *saved_state; saved_state = state; kprintf("pc = 0x%x\n", saved_state->eip); - kprintf("cr2= 0x%x\n", saved_state->cr2); + kprintf("cr3= 0x%x\n", saved_state->cr2); kprintf("rp = TODO FIXME\n"); - kprintf("sp = 0x%x\n", saved_state); + kprintf("sp = 0x%x\n", saved_state->esp); } @@ -365,25 +354,52 @@ kdp_print_phys(int src) } -boolean_t + +#define MAX_FRAME_DELTA 65536 + +void +kdp_i386_backtrace(void *_frame, int nframes) +{ + cframe_t *frame = (cframe_t *)_frame; + int i; + + for (i=0; i VM_MAX_KERNEL_ADDRESS) { + goto invalid; + } + kprintf("frame 0x%x called by 0x%x ", + frame, frame->caller); + kprintf("args 0x%x 0x%x 0x%x 0x%x\n", + frame->args[0], frame->args[1], + frame->args[2], frame->args[3]); + if ((frame->prev < frame) || /* wrong direction */ + ((frame->prev - frame) > MAX_FRAME_DELTA)) { + goto invalid; + } + frame = frame->prev; + } + return; +invalid: + kprintf("invalid frame pointer 0x%x\n",frame); +} + +void kdp_i386_trap( - unsigned int trapno, - x86_saved_state32_t *saved_state, + unsigned int trapno, + struct i386_saved_state *saved_state, kern_return_t result, vm_offset_t va ) { unsigned int exception, subcode = 0, code; - if (trapno != T_INT3 && trapno != T_DEBUG) { - kprintf("unexpected kernel trap 0x%x eip 0x%x cr2 0x%x \n", - trapno, saved_state->eip, saved_state->cr2); - if (!kdp.is_conn) - return FALSE; - } - mp_kdp_enter(); + if (trapno != T_INT3 && trapno != T_DEBUG) + kprintf("unexpected kernel trap 0x%x eip 0x%x cr2 0x%x \n", + trapno, saved_state->eip, saved_state->esp); + switch (trapno) { case T_DIVIDE_ERROR: @@ -447,11 +463,11 @@ kdp_i386_trap( break; } + kdp_i386_backtrace((void *) saved_state->ebp, 10); + kdp_raise_exception(exception, code, subcode, saved_state); mp_kdp_exit(); - - return TRUE; } boolean_t @@ -466,84 +482,3 @@ kdp_ml_get_breakinsn(void) { return 0xcc; } -extern pmap_t kdp_pmap; - -#define RETURN_OFFSET 4 -int -machine_trace_thread(thread_t thread, uint32_t tracepos, uint32_t tracebound, int nframes, boolean_t user_p) -{ - uint32_t *tracebuf = (uint32_t *)tracepos; - uint32_t fence = 0; - uint32_t stackptr = 0; - uint32_t stacklimit = 0xfc000000; - int framecount = 0; - uint32_t init_eip = 0; - uint32_t prevsp = 0; - uint32_t framesize = 2 * sizeof(vm_offset_t); - - if (user_p) { - x86_saved_state32_t *iss32; - - iss32 = USER_REGS32(thread); - - init_eip = iss32->eip; - stackptr = iss32->ebp; - - /* This bound isn't useful, but it doesn't hinder us*/ - stacklimit = 0xffffffff; - kdp_pmap = thread->task->map->pmap; - } - else { - /*Examine the i386_saved_state at the base of the kernel stack*/ - stackptr = STACK_IKS(thread->kernel_stack)->k_ebp; - init_eip = STACK_IKS(thread->kernel_stack)->k_eip; - } - - *tracebuf++ = init_eip; - - for (framecount = 0; framecount < nframes; framecount++) { - - if ((tracebound - ((uint32_t) tracebuf)) < (4 * framesize)) { - tracebuf--; - break; - } - - *tracebuf++ = stackptr; -/* Invalid frame, or hit fence */ - if (!stackptr || (stackptr == fence)) { - break; - } - /* Stack grows downward */ - if (stackptr < prevsp) { - break; - } - /* Unaligned frame */ - if (stackptr & 0x0000003) { - break; - } - if (stackptr > stacklimit) { - break; - } - - if (kdp_vm_read((caddr_t) (stackptr + RETURN_OFFSET), (caddr_t) tracebuf, sizeof(caddr_t)) != sizeof(caddr_t)) { - break; - } - tracebuf++; - - prevsp = stackptr; - if (kdp_vm_read((caddr_t) stackptr, (caddr_t) &stackptr, sizeof(caddr_t)) != sizeof(caddr_t)) { - *tracebuf++ = 0; - break; - } - } - - kdp_pmap = 0; - - return ((uint32_t) tracebuf - tracepos); -} - -/* This is a stub until the x86 64-bit model becomes clear */ -int -machine_trace_thread64(__unused thread_t thread, __unused uint32_t tracepos, __unused uint32_t tracebound, __unused int nframes, __unused boolean_t user_p) { - return 0; -}