1*2c2f96dcSApple OSS Distributions /* 2*2c2f96dcSApple OSS Distributions * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. 3*2c2f96dcSApple OSS Distributions * 4*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*2c2f96dcSApple OSS Distributions * 6*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*2c2f96dcSApple OSS Distributions * 15*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at 16*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*2c2f96dcSApple OSS Distributions * 18*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are 19*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and 24*2c2f96dcSApple OSS Distributions * limitations under the License. 25*2c2f96dcSApple OSS Distributions * 26*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*2c2f96dcSApple OSS Distributions */ 28*2c2f96dcSApple OSS Distributions 29*2c2f96dcSApple OSS Distributions /* 30*2c2f96dcSApple OSS Distributions * Internal definitions for kdp module 31*2c2f96dcSApple OSS Distributions */ 32*2c2f96dcSApple OSS Distributions 33*2c2f96dcSApple OSS Distributions #include <kdp/kdp.h> 34*2c2f96dcSApple OSS Distributions #include <kern/machine.h> 35*2c2f96dcSApple OSS Distributions #include <kdp/kdp_protocol.h> 36*2c2f96dcSApple OSS Distributions #include <mach/vm_types.h> 37*2c2f96dcSApple OSS Distributions #include <mach/boolean.h> 38*2c2f96dcSApple OSS Distributions #include <mach/mach_types.h> 39*2c2f96dcSApple OSS Distributions #include <libsa/types.h> 40*2c2f96dcSApple OSS Distributions 41*2c2f96dcSApple OSS Distributions typedef struct { 42*2c2f96dcSApple OSS Distributions void *saved_state; 43*2c2f96dcSApple OSS Distributions thread_t kdp_thread; 44*2c2f96dcSApple OSS Distributions int kdp_cpu; 45*2c2f96dcSApple OSS Distributions uint32_t session_key; 46*2c2f96dcSApple OSS Distributions unsigned int conn_seq; 47*2c2f96dcSApple OSS Distributions unsigned short reply_port; 48*2c2f96dcSApple OSS Distributions unsigned short exception_port; 49*2c2f96dcSApple OSS Distributions boolean_t is_conn; 50*2c2f96dcSApple OSS Distributions boolean_t is_halted; 51*2c2f96dcSApple OSS Distributions unsigned char exception_seq; 52*2c2f96dcSApple OSS Distributions boolean_t exception_ack_needed; 53*2c2f96dcSApple OSS Distributions } kdp_glob_t; 54*2c2f96dcSApple OSS Distributions 55*2c2f96dcSApple OSS Distributions extern kdp_glob_t kdp; 56*2c2f96dcSApple OSS Distributions 57*2c2f96dcSApple OSS Distributions extern volatile int kdp_flag; 58*2c2f96dcSApple OSS Distributions extern int noresume_on_disconnect; 59*2c2f96dcSApple OSS Distributions 60*2c2f96dcSApple OSS Distributions extern char kdp_kernelversion_string[256]; 61*2c2f96dcSApple OSS Distributions 62*2c2f96dcSApple OSS Distributions #define KDP_READY 0x1 63*2c2f96dcSApple OSS Distributions #define KDP_ARP 0x2 64*2c2f96dcSApple OSS Distributions #define KDP_BP_DIS 0x4 65*2c2f96dcSApple OSS Distributions #define KDP_GETC_ENA 0x8 66*2c2f96dcSApple OSS Distributions #define KDP_PANIC_DUMP_ENABLED 0x10 67*2c2f96dcSApple OSS Distributions #define PANIC_CORE_ON_NMI 0x20 68*2c2f96dcSApple OSS Distributions #define DBG_POST_CORE 0x40 69*2c2f96dcSApple OSS Distributions #define PANIC_LOG_DUMP 0x80 70*2c2f96dcSApple OSS Distributions #define REBOOT_POST_CORE 0x100 71*2c2f96dcSApple OSS Distributions #define SYSTEM_LOG_DUMP 0x200 72*2c2f96dcSApple OSS Distributions typedef boolean_t 73*2c2f96dcSApple OSS Distributions (*kdp_dispatch_t) ( 74*2c2f96dcSApple OSS Distributions kdp_pkt_t *, 75*2c2f96dcSApple OSS Distributions int *, 76*2c2f96dcSApple OSS Distributions unsigned short * 77*2c2f96dcSApple OSS Distributions ); 78*2c2f96dcSApple OSS Distributions 79*2c2f96dcSApple OSS Distributions extern 80*2c2f96dcSApple OSS Distributions boolean_t 81*2c2f96dcSApple OSS Distributions kdp_packet( 82*2c2f96dcSApple OSS Distributions unsigned char *, 83*2c2f96dcSApple OSS Distributions int *, 84*2c2f96dcSApple OSS Distributions unsigned short * 85*2c2f96dcSApple OSS Distributions ); 86*2c2f96dcSApple OSS Distributions 87*2c2f96dcSApple OSS Distributions extern 88*2c2f96dcSApple OSS Distributions boolean_t 89*2c2f96dcSApple OSS Distributions kdp_remove_all_breakpoints(void); 90*2c2f96dcSApple OSS Distributions 91*2c2f96dcSApple OSS Distributions extern 92*2c2f96dcSApple OSS Distributions void 93*2c2f96dcSApple OSS Distributions kdp_exception( 94*2c2f96dcSApple OSS Distributions unsigned char *, 95*2c2f96dcSApple OSS Distributions int *, 96*2c2f96dcSApple OSS Distributions unsigned short *, 97*2c2f96dcSApple OSS Distributions unsigned int, 98*2c2f96dcSApple OSS Distributions unsigned int, 99*2c2f96dcSApple OSS Distributions unsigned int 100*2c2f96dcSApple OSS Distributions ); 101*2c2f96dcSApple OSS Distributions 102*2c2f96dcSApple OSS Distributions extern 103*2c2f96dcSApple OSS Distributions boolean_t 104*2c2f96dcSApple OSS Distributions kdp_exception_ack( 105*2c2f96dcSApple OSS Distributions unsigned char *, 106*2c2f96dcSApple OSS Distributions int 107*2c2f96dcSApple OSS Distributions ); 108*2c2f96dcSApple OSS Distributions 109*2c2f96dcSApple OSS Distributions extern 110*2c2f96dcSApple OSS Distributions void 111*2c2f96dcSApple OSS Distributions kdp_panic( 112*2c2f96dcSApple OSS Distributions const char *fmt, 113*2c2f96dcSApple OSS Distributions ... 114*2c2f96dcSApple OSS Distributions ) __printflike(1, 2); 115*2c2f96dcSApple OSS Distributions 116*2c2f96dcSApple OSS Distributions extern 117*2c2f96dcSApple OSS Distributions void 118*2c2f96dcSApple OSS Distributions kdp_machine_reboot( 119*2c2f96dcSApple OSS Distributions void 120*2c2f96dcSApple OSS Distributions ); 121*2c2f96dcSApple OSS Distributions 122*2c2f96dcSApple OSS Distributions extern 123*2c2f96dcSApple OSS Distributions void 124*2c2f96dcSApple OSS Distributions kdp_us_spin( 125*2c2f96dcSApple OSS Distributions int usec 126*2c2f96dcSApple OSS Distributions ); 127*2c2f96dcSApple OSS Distributions 128*2c2f96dcSApple OSS Distributions extern 129*2c2f96dcSApple OSS Distributions int 130*2c2f96dcSApple OSS Distributions kdp_intr_disbl( 131*2c2f96dcSApple OSS Distributions void 132*2c2f96dcSApple OSS Distributions ); 133*2c2f96dcSApple OSS Distributions 134*2c2f96dcSApple OSS Distributions extern 135*2c2f96dcSApple OSS Distributions void 136*2c2f96dcSApple OSS Distributions kdp_intr_enbl( 137*2c2f96dcSApple OSS Distributions int s 138*2c2f96dcSApple OSS Distributions ); 139*2c2f96dcSApple OSS Distributions 140*2c2f96dcSApple OSS Distributions extern 141*2c2f96dcSApple OSS Distributions kdp_error_t 142*2c2f96dcSApple OSS Distributions kdp_machine_read_regs( 143*2c2f96dcSApple OSS Distributions unsigned int cpu, 144*2c2f96dcSApple OSS Distributions unsigned int flavor, 145*2c2f96dcSApple OSS Distributions char *data, 146*2c2f96dcSApple OSS Distributions int *size 147*2c2f96dcSApple OSS Distributions ); 148*2c2f96dcSApple OSS Distributions 149*2c2f96dcSApple OSS Distributions extern 150*2c2f96dcSApple OSS Distributions kdp_error_t 151*2c2f96dcSApple OSS Distributions kdp_machine_write_regs( 152*2c2f96dcSApple OSS Distributions unsigned int cpu, 153*2c2f96dcSApple OSS Distributions unsigned int flavor, 154*2c2f96dcSApple OSS Distributions char *data, 155*2c2f96dcSApple OSS Distributions int *size 156*2c2f96dcSApple OSS Distributions ); 157*2c2f96dcSApple OSS Distributions 158*2c2f96dcSApple OSS Distributions extern 159*2c2f96dcSApple OSS Distributions void 160*2c2f96dcSApple OSS Distributions kdp_machine_hostinfo( 161*2c2f96dcSApple OSS Distributions kdp_hostinfo_t *hostinfo 162*2c2f96dcSApple OSS Distributions ); 163*2c2f96dcSApple OSS Distributions 164*2c2f96dcSApple OSS Distributions extern 165*2c2f96dcSApple OSS Distributions void 166*2c2f96dcSApple OSS Distributions kdp_sync_cache( 167*2c2f96dcSApple OSS Distributions void 168*2c2f96dcSApple OSS Distributions ); 169*2c2f96dcSApple OSS Distributions 170*2c2f96dcSApple OSS Distributions /* Return a byte array that can be byte-copied to a memory address 171*2c2f96dcSApple OSS Distributions * to trap into the debugger. Must be 4 bytes or less in the current 172*2c2f96dcSApple OSS Distributions * implementation 173*2c2f96dcSApple OSS Distributions */ 174*2c2f96dcSApple OSS Distributions #define MAX_BREAKINSN_BYTES 4 175*2c2f96dcSApple OSS Distributions 176*2c2f96dcSApple OSS Distributions void 177*2c2f96dcSApple OSS Distributions kdp_machine_get_breakinsn( 178*2c2f96dcSApple OSS Distributions uint8_t *bytes, 179*2c2f96dcSApple OSS Distributions uint32_t *size 180*2c2f96dcSApple OSS Distributions ); 181*2c2f96dcSApple OSS Distributions 182*2c2f96dcSApple OSS Distributions extern void 183*2c2f96dcSApple OSS Distributions kdp_ml_enter_debugger( 184*2c2f96dcSApple OSS Distributions void 185*2c2f96dcSApple OSS Distributions ); 186*2c2f96dcSApple OSS Distributions 187*2c2f96dcSApple OSS Distributions mach_vm_size_t 188*2c2f96dcSApple OSS Distributions kdp_machine_vm_read( mach_vm_address_t, caddr_t, mach_vm_size_t); 189*2c2f96dcSApple OSS Distributions 190*2c2f96dcSApple OSS Distributions mach_vm_size_t 191*2c2f96dcSApple OSS Distributions kdp_machine_vm_write( caddr_t, mach_vm_address_t, mach_vm_size_t); 192*2c2f96dcSApple OSS Distributions 193*2c2f96dcSApple OSS Distributions mach_vm_size_t 194*2c2f96dcSApple OSS Distributions kdp_machine_phys_read(kdp_readphysmem64_req_t * rq, caddr_t /* data */, 195*2c2f96dcSApple OSS Distributions uint16_t /* lcpu */); 196*2c2f96dcSApple OSS Distributions 197*2c2f96dcSApple OSS Distributions mach_vm_size_t 198*2c2f96dcSApple OSS Distributions kdp_machine_phys_write(kdp_writephysmem64_req_t * rq, caddr_t /* data */, 199*2c2f96dcSApple OSS Distributions uint16_t /* lcpu */); 200*2c2f96dcSApple OSS Distributions 201*2c2f96dcSApple OSS Distributions int 202*2c2f96dcSApple OSS Distributions kdp_machine_ioport_read(kdp_readioport_req_t *, caddr_t /* data */, uint16_t /* lcpu */); 203*2c2f96dcSApple OSS Distributions 204*2c2f96dcSApple OSS Distributions int 205*2c2f96dcSApple OSS Distributions kdp_machine_ioport_write(kdp_writeioport_req_t *, caddr_t /* data */, uint16_t /* lcpu */); 206*2c2f96dcSApple OSS Distributions 207*2c2f96dcSApple OSS Distributions int 208*2c2f96dcSApple OSS Distributions kdp_machine_msr64_read(kdp_readmsr64_req_t *, caddr_t /* data */, uint16_t /* lcpu */); 209*2c2f96dcSApple OSS Distributions 210*2c2f96dcSApple OSS Distributions int 211*2c2f96dcSApple OSS Distributions kdp_machine_msr64_write(kdp_writemsr64_req_t *, caddr_t /* data */, uint16_t /* lcpu */); 212*2c2f96dcSApple OSS Distributions 213*2c2f96dcSApple OSS Distributions vm_map_offset_t 214*2c2f96dcSApple OSS Distributions kdp_core_start_addr(void); 215