1 /*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the 9 * software, derivative works or modified versions, and any portions 10 * thereof, and that both notices appear in supporting documentation. 11 * 12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 15 * 16 * Carnegie Mellon requests users of this software to return to 17 * 18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 * School of Computer Science 20 * Carnegie Mellon University 21 * Pittsburgh PA 15213-3890 22 * 23 * any improvements or extensions that they make and grant Carnegie the 24 * rights to redistribute these changes. 25 */ 26 27 #include <sys/cdefs.h> 28 /* 29 * Interface to new debugger. 30 */ 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/kdb.h> 35 #include <sys/pcpu.h> 36 37 #include <machine/cpufunc.h> 38 #include <machine/md_var.h> 39 #include <machine/specialreg.h> 40 41 #include <ddb/ddb.h> 42 43 /* 44 * Read bytes from kernel address space for debugger. 45 */ 46 int 47 db_read_bytes(vm_offset_t addr, size_t size, char *data) 48 { 49 jmp_buf jb; 50 void *prev_jb; 51 char *src; 52 int ret; 53 54 prev_jb = kdb_jmpbuf(jb); 55 ret = setjmp(jb); 56 if (ret == 0) { 57 src = (char *)addr; 58 while (size-- > 0) 59 *data++ = *src++; 60 } 61 (void)kdb_jmpbuf(prev_jb); 62 return (ret); 63 } 64 65 /* 66 * Write bytes to kernel address space for debugger. 67 * We need to disable write protection temporarily so we can write 68 * things (such as break points) that might be in write-protected 69 * memory. 70 */ 71 int 72 db_write_bytes(vm_offset_t addr, size_t size, char *data) 73 { 74 jmp_buf jb; 75 void *prev_jb; 76 char *dst; 77 bool old_wp; 78 int ret; 79 80 old_wp = false; 81 prev_jb = kdb_jmpbuf(jb); 82 ret = setjmp(jb); 83 if (ret == 0) { 84 old_wp = disable_wp(); 85 dst = (char *)addr; 86 while (size-- > 0) 87 *dst++ = *data++; 88 } 89 restore_wp(old_wp); 90 (void)kdb_jmpbuf(prev_jb); 91 return (ret); 92 } 93 94 void 95 db_show_mdpcpu(struct pcpu *pc) 96 { 97 98 db_printf("self = %p\n", pc->pc_prvspace); 99 db_printf("curpmap = %p\n", pc->pc_curpmap); 100 db_printf("tssp = %p\n", pc->pc_tssp); 101 db_printf("rsp0 = 0x%lx\n", pc->pc_rsp0); 102 db_printf("kcr3 = 0x%lx\n", pc->pc_kcr3); 103 db_printf("ucr3 = 0x%lx\n", pc->pc_ucr3); 104 db_printf("scr3 = 0x%lx\n", pc->pc_saved_ucr3); 105 db_printf("gs32p = %p\n", pc->pc_gs32p); 106 db_printf("ldt = %p\n", pc->pc_ldt); 107 db_printf("tss = %p\n", pc->pc_tss); 108 } 109