xref: /freebsd/sys/amd64/amd64/db_interface.c (revision 685dc743)
146280ae7SWarner Losh /*-
25b81b6b3SRodney W. Grimes  * Mach Operating System
35b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
45b81b6b3SRodney W. Grimes  * All Rights Reserved.
55b81b6b3SRodney W. Grimes  *
65b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
75b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
85b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
95b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
105b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
115b81b6b3SRodney W. Grimes  *
125b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
135b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
145b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
155b81b6b3SRodney W. Grimes  *
165b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
195b81b6b3SRodney W. Grimes  *  School of Computer Science
205b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
215b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
225b81b6b3SRodney W. Grimes  *
235b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
245b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
255b81b6b3SRodney W. Grimes  */
265b81b6b3SRodney W. Grimes 
2756ae44c5SDavid E. O'Brien #include <sys/cdefs.h>
285b81b6b3SRodney W. Grimes /*
295b81b6b3SRodney W. Grimes  * Interface to new debugger.
305b81b6b3SRodney W. Grimes  */
314e501eb7SBruce Evans 
32f540b106SGarrett Wollman #include <sys/param.h>
33f540b106SGarrett Wollman #include <sys/systm.h>
3437224cd3SMarcel Moolenaar #include <sys/kdb.h>
35ba228f6dSJohn Baldwin #include <sys/pcpu.h>
365b81b6b3SRodney W. Grimes 
37beb24065SJonathan T. Looney #include <machine/cpufunc.h>
382337dc64SKonstantin Belousov #include <machine/md_var.h>
39beb24065SJonathan T. Looney #include <machine/specialreg.h>
40beb24065SJonathan T. Looney 
41efeaf95aSDavid Greenman #include <ddb/ddb.h>
42b8fa61d1SBruce Evans 
435b81b6b3SRodney W. Grimes /*
445b81b6b3SRodney W. Grimes  * Read bytes from kernel address space for debugger.
455b81b6b3SRodney W. Grimes  */
4637224cd3SMarcel Moolenaar int
db_read_bytes(vm_offset_t addr,size_t size,char * data)4738a4de79SMark Murray db_read_bytes(vm_offset_t addr, size_t size, char *data)
485b81b6b3SRodney W. Grimes {
4937224cd3SMarcel Moolenaar 	jmp_buf jb;
5037224cd3SMarcel Moolenaar 	void *prev_jb;
5138a4de79SMark Murray 	char *src;
5237224cd3SMarcel Moolenaar 	int ret;
535b81b6b3SRodney W. Grimes 
5437224cd3SMarcel Moolenaar 	prev_jb = kdb_jmpbuf(jb);
5537224cd3SMarcel Moolenaar 	ret = setjmp(jb);
5637224cd3SMarcel Moolenaar 	if (ret == 0) {
575b81b6b3SRodney W. Grimes 		src = (char *)addr;
58c2a0fb74SDoug Rabson 		while (size-- > 0)
595b81b6b3SRodney W. Grimes 			*data++ = *src++;
6037224cd3SMarcel Moolenaar 	}
6137224cd3SMarcel Moolenaar 	(void)kdb_jmpbuf(prev_jb);
6237224cd3SMarcel Moolenaar 	return (ret);
635b81b6b3SRodney W. Grimes }
645b81b6b3SRodney W. Grimes 
655b81b6b3SRodney W. Grimes /*
665b81b6b3SRodney W. Grimes  * Write bytes to kernel address space for debugger.
67beb24065SJonathan T. Looney  * We need to disable write protection temporarily so we can write
68beb24065SJonathan T. Looney  * things (such as break points) that might be in write-protected
69beb24065SJonathan T. Looney  * memory.
705b81b6b3SRodney W. Grimes  */
7137224cd3SMarcel Moolenaar int
db_write_bytes(vm_offset_t addr,size_t size,char * data)7238a4de79SMark Murray db_write_bytes(vm_offset_t addr, size_t size, char *data)
735b81b6b3SRodney W. Grimes {
7437224cd3SMarcel Moolenaar 	jmp_buf jb;
7537224cd3SMarcel Moolenaar 	void *prev_jb;
7638a4de79SMark Murray 	char *dst;
772337dc64SKonstantin Belousov 	bool old_wp;
7837224cd3SMarcel Moolenaar 	int ret;
795b81b6b3SRodney W. Grimes 
802337dc64SKonstantin Belousov 	old_wp = false;
8137224cd3SMarcel Moolenaar 	prev_jb = kdb_jmpbuf(jb);
8237224cd3SMarcel Moolenaar 	ret = setjmp(jb);
8337224cd3SMarcel Moolenaar 	if (ret == 0) {
842337dc64SKonstantin Belousov 		old_wp = disable_wp();
855b81b6b3SRodney W. Grimes 		dst = (char *)addr;
86c2a0fb74SDoug Rabson 		while (size-- > 0)
875b81b6b3SRodney W. Grimes 			*dst++ = *data++;
8837224cd3SMarcel Moolenaar 	}
892337dc64SKonstantin Belousov 	restore_wp(old_wp);
9037224cd3SMarcel Moolenaar 	(void)kdb_jmpbuf(prev_jb);
9137224cd3SMarcel Moolenaar 	return (ret);
925b81b6b3SRodney W. Grimes }
93ed55a19fSJohn Baldwin 
940bbc8826SJohn Baldwin void
db_show_mdpcpu(struct pcpu * pc)950bbc8826SJohn Baldwin db_show_mdpcpu(struct pcpu *pc)
96ed55a19fSJohn Baldwin {
97ed55a19fSJohn Baldwin 
9898158c75SKonstantin Belousov 	db_printf("self         = %p\n", pc->pc_prvspace);
992c66cccaSKonstantin Belousov 	db_printf("curpmap      = %p\n", pc->pc_curpmap);
1002c66cccaSKonstantin Belousov 	db_printf("tssp         = %p\n", pc->pc_tssp);
1012c66cccaSKonstantin Belousov 	db_printf("rsp0         = 0x%lx\n", pc->pc_rsp0);
1027ccd639dSKonstantin Belousov 	db_printf("kcr3         = 0x%lx\n", pc->pc_kcr3);
1037ccd639dSKonstantin Belousov 	db_printf("ucr3         = 0x%lx\n", pc->pc_ucr3);
1047ccd639dSKonstantin Belousov 	db_printf("scr3         = 0x%lx\n", pc->pc_saved_ucr3);
1052c66cccaSKonstantin Belousov 	db_printf("gs32p        = %p\n", pc->pc_gs32p);
1062c66cccaSKonstantin Belousov 	db_printf("ldt          = %p\n", pc->pc_ldt);
1072c66cccaSKonstantin Belousov 	db_printf("tss          = %p\n", pc->pc_tss);
108ed55a19fSJohn Baldwin }
109