xref: /freebsd/sys/powerpc/powerpc/db_interface.c (revision 71625ec9ad2a9bc8c09784fbd23b759830e0ee5f)
1 /*	$NetBSD: db_interface.c,v 1.20 2002/05/13 20:30:09 matt Exp $ */
2 /*	$OpenBSD: db_interface.c,v 1.2 1996/12/28 06:21:50 rahnds Exp $	*/
3 
4 #include <sys/param.h>
5 #include <sys/systm.h>
6 #include <sys/cons.h>
7 #include <sys/kdb.h>
8 #include <sys/ktr.h>
9 #include <sys/lock.h>
10 #include <sys/pcpu.h>
11 #include <sys/proc.h>
12 #include <sys/smp.h>
13 
14 #include <machine/kdb.h>
15 #include <machine/md_var.h>
16 
17 #include <vm/vm.h>
18 #include <vm/pmap.h>
19 
20 #include <ddb/ddb.h>
21 #include <ddb/db_sym.h>
22 #include <ddb/db_command.h>
23 #include <ddb/db_access.h>
24 #include <ddb/db_output.h>
25 
26 #include <dev/ofw/openfirm.h>
27 
28 int
db_read_bytes(vm_offset_t addr,size_t size,char * data)29 db_read_bytes(vm_offset_t addr, size_t size, char *data)
30 {
31 	jmp_buf jb;
32 	void *prev_jb;
33 	char *src;
34 	int ret;
35 
36 	prev_jb = kdb_jmpbuf(jb);
37 	ret = setjmp(jb);
38 	if (ret == 0) {
39 		src = (char *)addr;
40 
41 		if (size == 8)
42 			*((uint64_t*)data) = *((uint64_t*)src);
43 		if (size == 4)
44 			*((int *)data) = *((int *)src);
45 		else if (size == 2)
46 			*((short *)data) = *((short *)src);
47 		else
48 			while (size-- > 0)
49 				*data++ = *src++;
50 	}
51 	(void)kdb_jmpbuf(prev_jb);
52 	return (ret);
53 }
54 
55 int
db_write_bytes(vm_offset_t addr,size_t size,char * data)56 db_write_bytes(vm_offset_t addr, size_t size, char *data)
57 {
58 	jmp_buf jb;
59 	void *prev_jb;
60 	char *dst;
61 	size_t cnt;
62 	int ret;
63 
64 	prev_jb = kdb_jmpbuf(jb);
65 	ret = setjmp(jb);
66 	if (ret == 0) {
67 		dst = (char *)addr;
68 		cnt = size;
69 
70 		if (size == 8)
71 			*((uint64_t*)dst) = *((uint64_t*)data);
72 		if (size == 4)
73 			*((int*)dst) = *((int*)data);
74 		else
75 		if (size == 2)
76 			*((short*)dst) = *((short*)data);
77 		else
78 			while (cnt-- > 0)
79 				*dst++ = *data++;
80 		kdb_cpu_sync_icache((void *)addr, size);
81 	}
82 	(void)kdb_jmpbuf(prev_jb);
83 	return (ret);
84 }
85 
86 void
db_show_mdpcpu(struct pcpu * pc)87 db_show_mdpcpu(struct pcpu *pc)
88 {
89 
90 	db_printf("PPC: hwref   = %#zx\n", pc->pc_hwref);
91 	db_printf("PPC: ipimask = %#x\n", pc->pc_ipimask);
92 	db_printf("PPC: flags   = %#x\n", pc->pc_flags);
93 }
94