|
|
1.1 root 1: /* @(#)kas3.c 1.2 */
2: #undef vax
3: #define pdp11 1
4: #include <stdio.h>
5: #include "a.out.h"
6: #include <sys/kmc.h>
7: #include "kas.h"
8:
9: debug(in, x)
10: union {
11: int val;
12: char * ptr;
13: } x;
14: {
15: register i, j, cnt;
16: int flag, fd;
17: char s[8];
18: #ifdef vax
19: struct filehdr fhdr;
20: struct aouthdr hdr;
21: extern struct scnhdr scn;
22: #define a_magic magic
23: #define a_text tsize
24: #define a_data dsize
25: #endif
26: #ifdef pdp11
27: extern struct exec hdr;
28: #endif
29:
30: if (dbmode==0) {
31: yyerror("not in debug mode");
32: return;
33: }
34: switch(in) {
35: case DLOAD:
36: if (x.ptr == 0)
37: x.ptr = "a.out";
38: if ((fd = open(x.ptr, 0))<0) {
39: printf("can not open %s\n", x.ptr);
40: return;
41: }
42: for (i=0; i<NKMCI; i++) ispace[i] = 0;
43: for (i=0; i<NKMCD; i++) dspace[i] = 0;
44: #ifdef vax
45: read(fd, &fhdr, sizeof fhdr);
46: #endif
47: read(fd, &hdr, sizeof hdr);
48: if (hdr.a_magic==0440) {
49: hdr.a_magic = 0410;
50: #ifdef vax
51: lseek(fd, sizeof(struct ir), 1);
52: #endif
53: #ifdef pdp11
54: lseek(fd, 64L, 0);
55: #endif
56: }
57: if (hdr.a_magic!=0410) {
58: printf("bad format %s\n",x.ptr);
59: close(fd);
60: return;
61: }
62: #ifdef vax
63: lseek(fd, 2 * sizeof(struct scnhdr), 1);
64: #endif
65: read(fd, ispace, hdr.a_text);
66: read(fd, dspace, hdr.a_data);
67: lseek(dbfd, 0L, 0);
68: write(dbfd, ispace, sizeof ispace);
69: write(dbfd, dspace, sizeof dspace);
70: close(fd);
71: break;
72: case DDUMP:
73: if (x.ptr == 0)
74: x.ptr = "core";
75: if (getregs())
76: return;
77: if ((fd = creat(x.ptr, 0664))<0) {
78: printf("can not create %s\n", x.ptr);
79: return;
80: }
81: lseek(dbfd, 0L, 0);
82: #ifdef vax
83: fhdr.f_magic = VAXROMAGIC;
84: fhdr.f_nscns = 2;
85: fhdr.f_timdat = time(NULL);
86: fhdr.f_symptr = 0;
87: fhdr.f_nsyms = 0;
88: fhdr.f_opthdr = sizeof(struct aouthdr);
89: fhdr.f_flags = F_AR32WR|F_LNNO|F_RELFLG;
90: write(fd, &fhdr, sizeof fhdr);
91: #endif
92: hdr.a_magic = 0440;
93: hdr.a_text = read(dbfd, ispace, sizeof ispace);
94: hdr.a_data = read(dbfd, dspace, sizeof dspace);
95: #ifdef pdp11
96: hdr.a_syms = 0;
97: #endif
98: write(fd, &hdr, sizeof hdr);
99: #ifdef vax
100: strncpy(scn.s_name,_TEXT,sizeof(scn.s_name));
101: scn.s_size = hdr.tsize;
102: scn.s_scnptr = sizeof(struct filehdr) + sizeof(struct aouthdr)
103: + 2 * sizeof(struct scnhdr) + sizeof(struct ir);
104: write(fd, &scn, sizeof scn);
105: strncpy(scn.s_name,_DATA,sizeof(scn.s_name));
106: scn.s_size = hdr.dsize;
107: scn.s_scnptr += hdr.tsize;
108: write(fd, &scn, sizeof scn);
109: #endif
110: write(fd, &ir, sizeof ir);
111: write(fd, ispace, hdr.a_text);
112: write(fd, dspace, hdr.a_data);
113: close(fd);
114: break;
115: case DSTEP:
116: cnt = x.val?x.val:1;
117: s[1] = 0;
118: for (i=1; i<=cnt; i++) {
119: if (ksty(KSTEP, ir.csr, 0))
120: return;
121: flag = 0;
122: for (j=0; j<8; j++)
123: if (s[j]!=ir.csr[j]) {
124: flag++;
125: s[j] = ir.csr[j];
126: }
127: if (flag || i==cnt)
128: printf("%4d%4o%4o%4o%4o%4o%4o%4o%4o\n",i,
129: s[0]&0377,s[1]&0377,s[2]&0377,s[3]&0377,
130: s[4]&0377,s[5]&0377,s[6]&0377,s[7]&0377);
131: }
132: break;
133: case DRUN:
134: case DSTOP:
135: case DRESET:
136: case DWCSR:
137: case DCLEAR:
138: ksty(in, 0, x.val);
139: break;
140: case DREGS:
141: i = getregs();
142: printf("%4s:%4o%4o%4o%4o%4o%4o%4o%4o\n",
143: "csr",ir.csr[0]&0377,ir.csr[1]&0377,ir.csr[2]&0377,ir.csr[3]&0377,
144: ir.csr[4]&0377,ir.csr[5]&0377,ir.csr[6]&0377,ir.csr[7]&0377);
145: if (i)
146: break;
147: printf("%4s:%4o%4o%4o%4o%4o%4o%4o%4o\n",
148: "lur",ir.lur[0]&0377,ir.lur[1]&0377,ir.lur[2]&0377,ir.lur[3]&0377,
149: ir.lur[4]&0377,ir.lur[5]&0377,ir.lur[6]&0377,ir.lur[7]&0377);
150: printf("%4s:%4o%4o%4o%4o%4o%4o%4o%4o\n",
151: "reg",ir.reg[0]&0377,ir.reg[1]&0377,ir.reg[2]&0377,ir.reg[3]&0377,
152: ir.reg[4]&0377,ir.reg[5]&0377,ir.reg[6]&0377,ir.reg[7]&0377);
153: printf("%4s:%4o%4o%4o%4o%4o%4o%4o%4o\n",
154: "reg",ir.reg[8+0]&0377,ir.reg[8+1]&0377,ir.reg[8+2]&0377,ir.reg[8+3]&0377,
155: ir.reg[8+4]&0377,ir.reg[8+5]&0377,ir.reg[8+6]&0377,ir.reg[8+7]&0377);
156: printf("%4s:%4o%4o%4o%4o%4o%4o%4o%4o\n",
157: "io",ir.io[0]&0377,ir.io[1]&0377,ir.io[2]&0377,ir.io[3]&0377,
158: ir.io[4]&0377,ir.io[5]&0377,ir.io[6]&0377,ir.io[7]&0377);
159: printf("%4s:%4o%4o%7s:%4o%7s:%4o\n",
160: "npr",ir.npr[0]&0377, ir.npr[1]&0377,"brg",ir.brg&0377,"mem",ir.mem&0377);
161: break;
162: }
163: }
164:
165: mstep(ins)
166: {
167: char csr[8];
168:
169: ksty(KMS, csr, ins);
170: return(csr[2]);
171: }
172:
173: getregs()
174: {
175: register i;
176:
177: if (ksty(KCSR, ir.csr, 0))
178: return(1);
179: if (ir.csr[1]&0200)
180: return(1);
181: ir.brg = mstep(061222);
182: ir.mem = mstep(041222);
183: for (i=0; i<8; i++) {
184: ir.lur[i] = mstep(021202|(i<<4));
185: ir.io[i] = mstep(021002|(i<<4));
186: }
187: for (i=0; i<16; i++) {
188: mstep(060600|i);
189: ir.reg[i] = mstep(061222);
190: }
191: ir.npr[0] = mstep(0121202);
192: ir.npr[1] = mstep(0121222);
193: return(0);
194: }
195:
196: ksty(tab)
197: {
198: if (ioctl(dbfd, KCSETA, &tab) < 0) {
199: printf("%s not stopped\n",dbfile);
200: return(1);
201: }
202: return(0);
203: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.