source: trunk/minix/commands/mdb/kernel.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 5.0 KB
Line 
1/*
2 * kernel.c for mdb
3 */
4
5#include "mdb.h"
6#include <ctype.h>
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#define ptrace mdbtrace
11#include <sys/ptrace.h>
12#include "proto.h"
13
14#include <kernel/const.h>
15#include <kernel/type.h>
16#include <kernel/proc.h>
17
18/* Define these here */
19/* buffer for proc and pointer to proc */
20
21#define SIZ (1 + sizeof(struct proc)/sizeof(long))
22
23struct proc *prc;
24long lbuf[SIZ];
25
26PRIVATE char segment_name[] = "TDS";
27
28/*
29 * Display memory maps
30 */
31PUBLIC void disp_maps()
32{
33 int i;
34 long int vir, phy, len;
35
36 Printf("\t Virtual\t Physical\tLength\n");
37 Printf("\t address\t address\n");
38 for (i = 0; i < strlen(segment_name); i++) {
39 vir = (long) prc->p_memmap[i].mem_vir << CLICK_SHIFT;
40 phy = (long) prc->p_memmap[i].mem_phys << CLICK_SHIFT;
41 len = (long) prc->p_memmap[i].mem_len << CLICK_SHIFT;
42 Printf("%c:\t0x%08.8lx\t0x%08.8lx\t%8ld (0x%08.8lx)\n",
43 segment_name[i], vir, phy, len, len);
44 }
45}
46
47PUBLIC void update()
48{
49 int i;
50
51 for (i = 0; i < (SIZ - 1); i++)
52 lbuf[i] = ptrace(T_GETUSER, curpid, (long) (i * sizeof(long)), 0L);
53
54 st_addr = (long) prc->p_memmap[T].mem_vir << CLICK_SHIFT;
55 et_addr = st_addr + ( (long) prc->p_memmap[T].mem_len << CLICK_SHIFT );
56
57 sd_addr = (long) prc->p_memmap[D].mem_vir << CLICK_SHIFT;
58 ed_addr = end_addr =
59 sd_addr + ( (long) prc->p_memmap[D].mem_len << CLICK_SHIFT );
60
61 sk_addr = (long) prc->p_memmap[S].mem_vir << CLICK_SHIFT;
62 sk_size = (long) prc->p_memmap[S].mem_len << CLICK_SHIFT;
63
64#ifdef MINIX_PC
65 if ( end_addr < et_addr ) end_addr = et_addr;
66#endif
67
68}
69
70PUBLIC int disp_regs()
71{
72 int i;
73
74 if (curpid <= 0) {
75 Printf("No active process.\n");
76 return 1;
77 }
78
79/* Look at kernel/type.h see how this data from the stackframe is laid out */
80
81#if defined(MINIX_PC) && defined(__i86)
82 Printf("\
83 es ds di si bp bx dx cx ax ip cs psw sp ss\
84\n");
85 for (i = 0; i < 16; i++)
86 if ( i != 5 && i != 10 ) Printf("%04x ", ((reg_t *) &prc->p_reg)[i]);
87 Printf("\n");
88#endif
89
90#if defined(MINIX_PC) && defined(__i386)
91 Printf("\n");
92 Printf("\
93 fs gs ds es edi esi ebp ebx edx\n");
94 for (i = 0; i < 8; i++)
95 if ( i != 6 ) Printf("%08lx ", ((reg_t *) &prc->p_reg)[i]);
96 Printf("\n\
97 ecx eax eip cs psw esp ss\n");
98 for (; i < 16; i++)
99 if ( i != 10 ) Printf("%08lx ", ((reg_t *) &prc->p_reg)[i]);
100 Printf("\n");
101#endif
102
103#ifdef MINIX_ST
104 Printf("\npc=%lx psw=%x\n\n",(long)PC_MEMBER(prc), PSW_MEMBER(prc));
105 Printf(
106" 0 1 2 3 4 5 6 7\nD");
107 for (i = 0; i < 8; i++) Printf(" %08lx", ((reg_t *) &prc->p_reg)[i]);
108 Printf("\nA");
109 for (; i < NR_REGS; i++) Printf(" %08lx", ((reg_t *) &prc->p_reg)[i]);
110 Printf(" %08lx\n\n", (long)SP_MEMBER(prc));
111#endif
112 return 0;
113}
114
115/* System dependent core */
116
117#ifdef MINIX_PC
118
119#ifdef __i386
120PRIVATE char regs[] = "fs gs ds es di si bp bx dx cx ax ip cs ps sp ss";
121#else
122PRIVATE char regs[] = "es ds di si bp bx dx cx ax ip cs ps sp ss";
123#endif
124
125/* Get register for pid at offset k */
126PUBLIC long get_reg(pid, k)
127int pid;
128long k;
129{
130 long off;
131 long val;
132 int reg_size;
133
134 /* Calculate size of register */
135 reg_size = (k < N_REG16 * 2) ? 2 : sizeof(reg_t);
136
137 /* Adjust offset */
138 off = k - (k & (sizeof(long) - 1));
139
140 val = ptrace(T_GETUSER, pid, off, 0L);
141
142 if (k & (sizeof(long) - 1))
143 val >>= BITSIZE(reg_size);
144 else
145 val &= MASK(reg_size);
146 return val;
147}
148
149
150/* Set register for pid at offset k */
151PUBLIC void set_reg(pid, k, value)
152int pid;
153long k;
154long value;
155{
156 long off;
157
158 /* Adjust offset */
159 off = k - (k & (sizeof(long) - 1));
160
161 ptrace(T_SETUSER, pid, off, value);
162
163}
164
165
166PUBLIC long reg_addr(s)
167char *s;
168{
169 long val;
170 char *t;
171 char *send;
172 char q[3];
173
174 if (*s == ' ')
175 mdb_error("Invalid syntax\n");
176 q[0] = tolower(*s);
177 q[1] = tolower(*++s);
178 q[2] = '\0';
179
180 t = regs;
181 send = regs + sizeof(regs);
182 while (t < send) {
183 if (strncmp(q, t, 2) == 0) {
184 val = (long) (t - regs);
185 val /= 3L;
186 if (val < N_REG16 - 1)
187 val = val * 2;
188 else
189 val = (N_REG16 - 1) * 2 +
190 (val - N_REG16 + 1) * sizeof(reg_t);
191 return val;
192 }
193 t += 3;
194 }
195 Printf("Unknown register: %s", q);
196 mdb_error("\n");
197}
198
199
200PUBLIC int outsegreg(num)
201off_t num;
202{
203/* print segment register */
204
205 if ((num % HCLICK_SIZE) != 0 || num >= 0x100000)
206 {
207 Printf("%08x",num);
208 return 8;
209 }
210 Printf("%04x", (u16_t) (num / HCLICK_SIZE) );
211 return 4;
212}
213
214#endif
215
216#ifdef MINIX_ST
217
218/* Get register for pid at offset k */
219PUBLIC long get_reg(pid, k)
220int pid;
221long k;
222{
223 return ptrace(T_GETUSER, pid, k, 0L);
224}
225
226PUBLIC long reg_addr(s)
227char *s;
228{
229 long val;
230
231 switch (*s++) {
232 case 'a':
233 case 'A': val = 32; break;
234 case 'd':
235 case 'D': val = 0; break;
236 case 'P':
237 case 'p': if (*s != 'c' && *s != 'C') goto error;
238 return 64;
239 break;
240 default: goto error;
241 }
242 if (*s >= '0' && *s <= '7')
243 return val + 4 * (*s - '0');
244error:
245 Printf("Unknown register: %2.2s", s);
246 mdb_error("\n");
247}
248
249#endif
Note: See TracBrowser for help on using the repository browser.