00001
00002
00003
00004
00005 #include "mdb.h"
00006 #include <ctype.h>
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <string.h>
00010 #define ptrace mdbtrace
00011 #include <sys/ptrace.h>
00012 #include "proto.h"
00013
00014 #include <kernel/const.h>
00015 #include <kernel/type.h>
00016 #include <kernel/proc.h>
00017
00018
00019
00020
00021 #define SIZ (1 + sizeof(struct proc)/sizeof(long))
00022
00023 struct proc *prc;
00024 long lbuf[SIZ];
00025
00026 PRIVATE char segment_name[] = "TDS";
00027
00028
00029
00030
00031 PUBLIC void disp_maps()
00032 {
00033 int i;
00034 long int vir, phy, len;
00035
00036 Printf("\t Virtual\t Physical\tLength\n");
00037 Printf("\t address\t address\n");
00038 for (i = 0; i < strlen(segment_name); i++) {
00039 vir = (long) prc->p_memmap[i].mem_vir << CLICK_SHIFT;
00040 phy = (long) prc->p_memmap[i].mem_phys << CLICK_SHIFT;
00041 len = (long) prc->p_memmap[i].mem_len << CLICK_SHIFT;
00042 Printf("%c:\t0x%08.8lx\t0x%08.8lx\t%8ld (0x%08.8lx)\n",
00043 segment_name[i], vir, phy, len, len);
00044 }
00045 }
00046
00047 PUBLIC void update()
00048 {
00049 int i;
00050
00051 for (i = 0; i < (SIZ - 1); i++)
00052 lbuf[i] = ptrace(T_GETUSER, curpid, (long) (i * sizeof(long)), 0L);
00053
00054 st_addr = (long) prc->p_memmap[T].mem_vir << CLICK_SHIFT;
00055 et_addr = st_addr + ( (long) prc->p_memmap[T].mem_len << CLICK_SHIFT );
00056
00057 sd_addr = (long) prc->p_memmap[D].mem_vir << CLICK_SHIFT;
00058 ed_addr = end_addr =
00059 sd_addr + ( (long) prc->p_memmap[D].mem_len << CLICK_SHIFT );
00060
00061 sk_addr = (long) prc->p_memmap[S].mem_vir << CLICK_SHIFT;
00062 sk_size = (long) prc->p_memmap[S].mem_len << CLICK_SHIFT;
00063
00064 #ifdef MINIX_PC
00065 if ( end_addr < et_addr ) end_addr = et_addr;
00066 #endif
00067
00068 }
00069
00070 PUBLIC int disp_regs()
00071 {
00072 int i;
00073
00074 if (curpid <= 0) {
00075 Printf("No active process.\n");
00076 return 1;
00077 }
00078
00079
00080
00081 #if defined(MINIX_PC) && defined(__i86)
00082 Printf("\
00083 es ds di si bp bx dx cx ax ip cs psw sp ss\
00084 \n");
00085 for (i = 0; i < 16; i++)
00086 if ( i != 5 && i != 10 ) Printf("%04x ", ((reg_t *) &prc->p_reg)[i]);
00087 Printf("\n");
00088 #endif
00089
00090 #if defined(MINIX_PC) && defined(__i386)
00091 Printf("\n");
00092 Printf("\
00093 fs gs ds es edi esi ebp ebx edx\n");
00094 for (i = 0; i < 8; i++)
00095 if ( i != 6 ) Printf("%08lx ", ((reg_t *) &prc->p_reg)[i]);
00096 Printf("\n\
00097 ecx eax eip cs psw esp ss\n");
00098 for (; i < 16; i++)
00099 if ( i != 10 ) Printf("%08lx ", ((reg_t *) &prc->p_reg)[i]);
00100 Printf("\n");
00101 #endif
00102
00103 #ifdef MINIX_ST
00104 Printf("\npc=%lx psw=%x\n\n",(long)PC_MEMBER(prc), PSW_MEMBER(prc));
00105 Printf(
00106 " 0 1 2 3 4 5 6 7\nD");
00107 for (i = 0; i < 8; i++) Printf(" %08lx", ((reg_t *) &prc->p_reg)[i]);
00108 Printf("\nA");
00109 for (; i < NR_REGS; i++) Printf(" %08lx", ((reg_t *) &prc->p_reg)[i]);
00110 Printf(" %08lx\n\n", (long)SP_MEMBER(prc));
00111 #endif
00112 return 0;
00113 }
00114
00115
00116
00117 #ifdef MINIX_PC
00118
00119 #ifdef __i386
00120 PRIVATE char regs[] = "fs gs ds es di si bp bx dx cx ax ip cs ps sp ss";
00121 #else
00122 PRIVATE char regs[] = "es ds di si bp bx dx cx ax ip cs ps sp ss";
00123 #endif
00124
00125
00126 PUBLIC long get_reg(pid, k)
00127 int pid;
00128 long k;
00129 {
00130 long off;
00131 long val;
00132 int reg_size;
00133
00134
00135 reg_size = (k < N_REG16 * 2) ? 2 : sizeof(reg_t);
00136
00137
00138 off = k - (k & (sizeof(long) - 1));
00139
00140 val = ptrace(T_GETUSER, pid, off, 0L);
00141
00142 if (k & (sizeof(long) - 1))
00143 val >>= BITSIZE(reg_size);
00144 else
00145 val &= MASK(reg_size);
00146 return val;
00147 }
00148
00149
00150
00151 PUBLIC void set_reg(pid, k, value)
00152 int pid;
00153 long k;
00154 long value;
00155 {
00156 long off;
00157
00158
00159 off = k - (k & (sizeof(long) - 1));
00160
00161 ptrace(T_SETUSER, pid, off, value);
00162
00163 }
00164
00165
00166 PUBLIC long reg_addr(s)
00167 char *s;
00168 {
00169 long val;
00170 char *t;
00171 char *send;
00172 char q[3];
00173
00174 if (*s == ' ')
00175 mdb_error("Invalid syntax\n");
00176 q[0] = tolower(*s);
00177 q[1] = tolower(*++s);
00178 q[2] = '\0';
00179
00180 t = regs;
00181 send = regs + sizeof(regs);
00182 while (t < send) {
00183 if (strncmp(q, t, 2) == 0) {
00184 val = (long) (t - regs);
00185 val /= 3L;
00186 if (val < N_REG16 - 1)
00187 val = val * 2;
00188 else
00189 val = (N_REG16 - 1) * 2 +
00190 (val - N_REG16 + 1) * sizeof(reg_t);
00191 return val;
00192 }
00193 t += 3;
00194 }
00195 Printf("Unknown register: %s", q);
00196 mdb_error("\n");
00197 }
00198
00199
00200 PUBLIC int outsegreg(num)
00201 off_t num;
00202 {
00203
00204
00205 if ((num % HCLICK_SIZE) != 0 || num >= 0x100000)
00206 {
00207 Printf("%08x",num);
00208 return 8;
00209 }
00210 Printf("%04x", (u16_t) (num / HCLICK_SIZE) );
00211 return 4;
00212 }
00213
00214 #endif
00215
00216 #ifdef MINIX_ST
00217
00218
00219 PUBLIC long get_reg(pid, k)
00220 int pid;
00221 long k;
00222 {
00223 return ptrace(T_GETUSER, pid, k, 0L);
00224 }
00225
00226 PUBLIC long reg_addr(s)
00227 char *s;
00228 {
00229 long val;
00230
00231 switch (*s++) {
00232 case 'a':
00233 case 'A': val = 32; break;
00234 case 'd':
00235 case 'D': val = 0; break;
00236 case 'P':
00237 case 'p': if (*s != 'c' && *s != 'C') goto error;
00238 return 64;
00239 break;
00240 default: goto error;
00241 }
00242 if (*s >= '0' && *s <= '7')
00243 return val + 4 * (*s - '0');
00244 error:
00245 Printf("Unknown register: %2.2s", s);
00246 mdb_error("\n");
00247 }
00248
00249 #endif