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