|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* ! 26: * Copyright (c) 1993 NeXT Computer, Inc. All rights reserved. ! 27: * ! 28: * kdp_machdep.c -- Machine-dependent code for Remote Debugging Protocol ! 29: * ! 30: * History: ! 31: * ! 32: * 10 Nov 1997 Herb Ruth [[email protected]] ! 33: * Added extern declarations for implicit function ! 34: * declarations. Changed dprintf macro to call kprintf() ! 35: * instead of safe_prf() when KDP_TEST_HARNESS==1. ! 36: */ ! 37: ! 38: #import <sys/param.h> ! 39: #import <sys/systm.h> ! 40: #import <sys/mbuf.h> ! 41: #import <sys/socket.h> ! 42: #import <net/if.h> ! 43: #import <net/route.h> ! 44: #import <netinet/in.h> ! 45: #import <netinet/in_systm.h> ! 46: #import <netinet/ip.h> ! 47: #import <netinet/ip_var.h> ! 48: #import <netinet/in_pcb.h> ! 49: ! 50: #import <mach/mach_types.h> ! 51: ! 52: #import <kern/kdp_internal.h> ! 53: #import <kern/miniMon.h> ! 54: ! 55: #import <machdep/i386/sel_inline.h> ! 56: #import <machdep/i386/intr_exported.h> ! 57: ! 58: #import <bsd/sys/conf.h> ! 59: ! 60: #define KDP_TEST_HARNESS 0 ! 61: #if KDP_TEST_HARNESS ! 62: /*#define dprintf(x) safe_prf(x)*/ ! 63: #define dprintf(x) kprintf x ! 64: #else ! 65: #define dprintf(x) ! 66: #endif ! 67: ! 68: void ! 69: kdp_getstate( ! 70: i386_thread_state_t *state ! 71: ) ! 72: { ! 73: thread_saved_state_t *saved_state; ! 74: ! 75: saved_state = (thread_saved_state_t *)kdp.saved_state; ! 76: ! 77: *state = (i386_thread_state_t) { 0 }; ! 78: state->eax = saved_state->regs.eax; ! 79: state->ebx = saved_state->regs.ebx; ! 80: state->ecx = saved_state->regs.ecx; ! 81: state->edx = saved_state->regs.edx; ! 82: state->edi = saved_state->regs.edi; ! 83: state->esi = saved_state->regs.esi; ! 84: state->ebp = saved_state->regs.ebp; ! 85: state->esp = (unsigned int)&saved_state->frame.esp; /* XXX */ ! 86: state->ss = sel_to_selector(saved_state->frame.ss); ! 87: state->eflags = saved_state->frame.eflags; ! 88: state->eip = saved_state->frame.eip; ! 89: state->cs = sel_to_selector(saved_state->frame.cs); ! 90: state->ds = sel_to_selector(saved_state->regs.ds); ! 91: state->es = sel_to_selector(saved_state->regs.es); ! 92: state->fs = sel_to_selector(saved_state->regs.fs); ! 93: state->gs = sel_to_selector(saved_state->regs.gs); ! 94: } ! 95: ! 96: ! 97: void ! 98: kdp_setstate( ! 99: i386_thread_state_t *state ! 100: ) ! 101: { ! 102: thread_saved_state_t *saved_state; ! 103: ! 104: saved_state = (thread_saved_state_t *)kdp.saved_state; ! 105: ! 106: saved_state->regs.eax = state->eax; ! 107: saved_state->regs.ebx = state->ebx; ! 108: saved_state->regs.ecx = state->ecx; ! 109: saved_state->regs.edx = state->edx; ! 110: saved_state->regs.edi = state->edi; ! 111: saved_state->regs.esi = state->esi; ! 112: saved_state->regs.ebp = state->ebp; ! 113: saved_state->frame.eflags = state->eflags; ! 114: #if 0 ! 115: saved_state->frame.eflags &= ~( EFL_VM | EFL_NT | EFL_IOPL | EFL_CLR ); ! 116: saved_state->frame.eflags |= ( EFL_IF | EFL_SET ); ! 117: #endif ! 118: saved_state->frame.eip = state->eip; ! 119: saved_state->regs.fs = selector_to_sel(state->fs); ! 120: saved_state->regs.gs = selector_to_sel(state->gs); ! 121: } ! 122: ! 123: ! 124: void ! 125: kdp_exception( ! 126: unsigned char *pkt, ! 127: int *len, ! 128: unsigned short *remote_port, ! 129: unsigned int exception, ! 130: unsigned int code, ! 131: unsigned int subcode ! 132: ) ! 133: { ! 134: kdp_exception_t *rq = (kdp_exception_t *)pkt; ! 135: ! 136: rq->hdr.request = KDP_EXCEPTION; ! 137: rq->hdr.is_reply = 0; ! 138: rq->hdr.seq = kdp.exception_seq; ! 139: rq->hdr.key = 0; ! 140: rq->hdr.len = sizeof (*rq); ! 141: ! 142: rq->n_exc_info = 1; ! 143: rq->exc_info->cpu = 0; ! 144: rq->exc_info->exception = exception; ! 145: rq->exc_info->code = code; ! 146: rq->exc_info->subcode = subcode; ! 147: ! 148: rq->hdr.len += rq->n_exc_info * sizeof (kdp_exc_info_t); ! 149: ! 150: kdp.exception_ack_needed = TRUE; ! 151: ! 152: *remote_port = kdp.exception_port; ! 153: *len = rq->hdr.len; ! 154: } ! 155: ! 156: void ! 157: kdp_exception_ack( ! 158: unsigned char *pkt, ! 159: int len ! 160: ) ! 161: { ! 162: kdp_exception_ack_t *rq = (kdp_exception_ack_t *)pkt; ! 163: ! 164: if (len < sizeof (*rq)) ! 165: return; ! 166: ! 167: if (!rq->hdr.is_reply || rq->hdr.request != KDP_EXCEPTION) ! 168: return; ! 169: ! 170: dprintf(("kdp_exception_ack seq %x %x\n", rq->hdr.seq, kdp.exception_seq)); ! 171: ! 172: if (rq->hdr.seq == kdp.exception_seq) { ! 173: kdp.exception_ack_needed = FALSE; ! 174: kdp.exception_seq++; ! 175: } ! 176: } ! 177: ! 178: kdp_error_t ! 179: kdp_machine_read_regs( ! 180: unsigned int cpu, ! 181: unsigned int flavor, ! 182: char *data, ! 183: int *size ! 184: ) ! 185: { ! 186: switch (flavor) { ! 187: ! 188: case i386_THREAD_STATE: ! 189: ! 190: dprintf(("kdp_readregs THREAD_STATE\n")); ! 191: kdp_getstate((i386_thread_state_t *)data); ! 192: *size = sizeof (i386_thread_state_t); ! 193: return KDPERR_NO_ERROR; ! 194: ! 195: case i386_THREAD_FPSTATE: ! 196: dprintf(("kdp_readregs THREAD_FPSTATE\n")); ! 197: *(i386_thread_fpstate_t *)data = (i386_thread_fpstate_t) { 0 }; ! 198: *size = sizeof (i386_thread_fpstate_t); ! 199: return KDPERR_NO_ERROR; ! 200: ! 201: default: ! 202: dprintf(("kdp_readregs bad flavor %d\n")); ! 203: return KDPERR_BADFLAVOR; ! 204: } ! 205: } ! 206: ! 207: kdp_error_t ! 208: kdp_machine_write_regs( ! 209: unsigned int cpu, ! 210: unsigned int flavor, ! 211: char *data, ! 212: int *size ! 213: ) ! 214: { ! 215: switch (flavor) { ! 216: ! 217: case i386_THREAD_STATE: ! 218: dprintf(("kdp_writeregs THREAD_STATE\n")); ! 219: kdp_setstate((i386_thread_state_t *)data); ! 220: return KDPERR_NO_ERROR; ! 221: ! 222: case i386_THREAD_FPSTATE: ! 223: dprintf(("kdp_writeregs THREAD_FPSTATE\n")); ! 224: return KDPERR_NO_ERROR; ! 225: ! 226: default: ! 227: dprintf(("kdp_writeregs bad flavor %d\n")); ! 228: return KDPERR_BADFLAVOR; ! 229: } ! 230: } ! 231: ! 232: void ! 233: kdp_machine_hostinfo( ! 234: kdp_hostinfo_t *hostinfo ! 235: ) ! 236: { ! 237: hostinfo->cpus_mask = 1; ! 238: hostinfo->cpu_type = CPU_TYPE_I386; ! 239: hostinfo->cpu_subtype = CPU_SUBTYPE_486; ! 240: } ! 241: ! 242: void ! 243: kdp_panic( ! 244: const char *msg ! 245: ) ! 246: { ! 247: safe_prf("kdp panic: %s\n", msg); ! 248: ! 249: asm volatile("hlt"); ! 250: } ! 251: ! 252: ! 253: void ! 254: kdp_reboot(void) ! 255: { ! 256: keyboard_reboot(); ! 257: } ! 258: ! 259: int ! 260: kdp_intr_disbl(void) ! 261: { ! 262: return intr_disbl(); ! 263: } ! 264: ! 265: void ! 266: kdp_intr_enbl(int s) ! 267: { ! 268: intr_enbl(s); ! 269: } ! 270: ! 271: void ! 272: kdp_us_spin(int usec) ! 273: { ! 274: us_spin(usec); ! 275: } ! 276: ! 277: void ! 278: kdp_flush_cache(void) ! 279: { ! 280: /* no-op on i386 */ ! 281: } ! 282:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.