don't need to explicitly enable lance any more.
[minix.git] / commands / dis88 / distabs.c
blob6390cecc7d07186c704db72cc863420c78d6fdad
1 static char *sccsid =
2 "@(#) distabs.c, Ver. 2.1 created 00:00:00 87/09/01";
4 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
5 * *
6 * Copyright (C) 1987 G. M. Harding, all rights reserved *
7 * *
8 * Permission to copy and redistribute is hereby granted, *
9 * provided full source code, with all copyright notices, *
10 * accompanies any redistribution. *
11 * *
12 * This file contains the lookup tables and other data *
13 * structures for the Intel 8088 symbolic disassembler. It *
14 * also contains a few global routines which facilitate *
15 * access to the tables, for use primarily by the handler *
16 * functions. *
17 * *
18 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
20 #include "dis.h" /* Disassembler declarations */
22 struct exec HDR; /* Used to hold header info */
24 struct nlist symtab[MAXSYM]; /* Array of symbol table info */
26 struct reloc relo[MAXSYM]; /* Array of relocation info */
28 int symptr = -1, /* Index into symtab[] */
29 relptr = -1; /* Index into relo[] */
31 char *REGS[] = /* Table of register names */
33 "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh",
34 "ax", "cx", "dx", "bx", "sp", "bp", "si", "di",
35 "es", "cs", "ss", "ds"
38 char *REGS0[] = /* Mode 0 register name table */
40 "bx_si", "bx_di", "bp_si", "bp_di", "si", "di", "", "bx"
43 char *REGS1[] = /* Mode 1 register name table */
45 "bx_si", "bx_di", "bp_si", "bp_di", "si", "di", "bp", "bx"
48 int symrank[6][6] = /* Symbol type/rank matrix */
50 /* UND ABS TXT DAT BSS COM */
51 /* UND */ 5, 4, 1, 2, 3, 0,
52 /* ABS */ 1, 5, 4, 3, 2, 0,
53 /* TXT */ 4, 1, 5, 3, 2, 0,
54 /* DAT */ 3, 1, 2, 5, 4, 0,
55 /* BSS */ 3, 1, 2, 4, 5, 0,
56 /* COM */ 2, 0, 1, 3, 4, 5
59 /* * * * * * * * * * * * OPCODE DATA * * * * * * * * * * * */
61 char ADD[] = "\tadd", /* Mnemonics by family */
62 OR[] = "\tor",
63 ADC[] = "\tadc",
64 SBB[] = "\tsbb",
65 AND[] = "\tand",
66 SUB[] = "\tsub",
67 XOR[] = "\txor",
68 CMP[] = "\tcmp",
69 NOT[] = "\tnot",
70 NEG[] = "\tneg",
71 MUL[] = "\tmul",
72 DIV[] = "\tdiv",
73 MOV[] = "\tmov",
74 ESC[] = "\tesc",
75 TEST[] = "\ttest",
76 AMBIG[] = "",
77 ROL[] = "\trol",
78 ROR[] = "\tror",
79 RCL[] = "\trcl",
80 RCR[] = "\trcr",
81 SAL[] = "\tsal",
82 SHR[] = "\tshr",
83 SHL[] = "\tshl",
84 SAR[] = "\tsar";
86 char *OPFAM[] = /* Family lookup table */
88 ADD, OR, ADC, SBB, AND, SUB, XOR, CMP,
89 NOT, NEG, MUL, DIV, MOV, ESC, TEST, AMBIG,
90 ROL, ROR, RCL, RCR, SAL, SHR, SHL, SAR
93 struct opcode optab[] = /* Table of opcode data */
95 ADD, aohand, 2, 4, /* 0x00 */
96 ADD, aohand, 2, 4, /* 0x01 */
97 ADD, aohand, 2, 4, /* 0x02 */
98 ADD, aohand, 2, 4, /* 0x03 */
99 ADD, aohand, 2, 2, /* 0x04 */
100 ADD, aohand, 3, 3, /* 0x05 */
101 "\tpush\tes", sbhand, 1, 1, /* 0x06 */
102 "\tpop\tes", sbhand, 1, 1, /* 0x07 */
103 OR, aohand, 2, 4, /* 0x08 */
104 OR, aohand, 2, 4, /* 0x09 */
105 OR, aohand, 2, 4, /* 0x0a */
106 OR, aohand, 2, 4, /* 0x0b */
107 OR, aohand, 2, 2, /* 0x0c */
108 OR, aohand, 3, 3, /* 0x0d */
109 "\tpush\tcs", sbhand, 1, 1, /* 0x0e */
110 NULL, dfhand, 0, 0, /* 0x0f */
111 ADC, aohand, 2, 4, /* 0x10 */
112 ADC, aohand, 2, 4, /* 0x11 */
113 ADC, aohand, 2, 4, /* 0x12 */
114 ADC, aohand, 2, 4, /* 0x13 */
115 ADC, aohand, 2, 2, /* 0x14 */
116 ADC, aohand, 3, 3, /* 0x15 */
117 "\tpush\tss", sbhand, 1, 1, /* 0x16 */
118 "\tpop\tss", sbhand, 1, 1, /* 0x17 */
119 SBB, aohand, 2, 4, /* 0x18 */
120 SBB, aohand, 2, 4, /* 0x19 */
121 SBB, aohand, 2, 4, /* 0x1a */
122 SBB, aohand, 2, 4, /* 0x1b */
123 SBB, aohand, 2, 2, /* 0x1c */
124 SBB, aohand, 3, 3, /* 0x1d */
125 "\tpush\tds", sbhand, 1, 1, /* 0x1e */
126 "\tpop\tds", sbhand, 1, 1, /* 0x1f */
127 AND, aohand, 2, 4, /* 0x20 */
128 AND, aohand, 2, 4, /* 0x21 */
129 AND, aohand, 2, 4, /* 0x22 */
130 AND, aohand, 2, 4, /* 0x23 */
131 AND, aohand, 2, 2, /* 0x24 */
132 AND, aohand, 3, 3, /* 0x25 */
133 "\tseg\tes", sbhand, 1, 1, /* 0x26 */
134 "\tdaa", sbhand, 1, 1, /* 0x27 */
135 SUB, aohand, 2, 4, /* 0x28 */
136 SUB, aohand, 2, 4, /* 0x29 */
137 SUB, aohand, 2, 4, /* 0x2a */
138 SUB, aohand, 2, 4, /* 0x2b */
139 SUB, aohand, 2, 2, /* 0x2c */
140 SUB, aohand, 3, 3, /* 0x2d */
141 "\tseg\tcs", sbhand, 1, 1, /* 0x2e */
142 "\tdas", sbhand, 1, 1, /* 0x2f */
143 XOR, aohand, 2, 4, /* 0x30 */
144 XOR, aohand, 2, 4, /* 0x31 */
145 XOR, aohand, 2, 4, /* 0x32 */
146 XOR, aohand, 2, 4, /* 0x33 */
147 XOR, aohand, 2, 2, /* 0x34 */
148 XOR, aohand, 3, 3, /* 0x35 */
149 "\tseg\tss", sbhand, 1, 1, /* 0x36 */
150 "\taaa", sbhand, 1, 1, /* 0x37 */
151 CMP, aohand, 2, 4, /* 0x38 */
152 CMP, aohand, 2, 4, /* 0x39 */
153 CMP, aohand, 2, 4, /* 0x3a */
154 CMP, aohand, 2, 4, /* 0x3b */
155 CMP, aohand, 2, 2, /* 0x3c */
156 CMP, aohand, 3, 3, /* 0x3d */
157 "\tseg\tds", sbhand, 1, 1, /* 0x3e */
158 "\taas", sbhand, 1, 1, /* 0x3f */
159 "\tinc\tax", sbhand, 1, 1, /* 0x40 */
160 "\tinc\tcx", sbhand, 1, 1, /* 0x41 */
161 "\tinc\tdx", sbhand, 1, 1, /* 0x42 */
162 "\tinc\tbx", sbhand, 1, 1, /* 0x43 */
163 "\tinc\tsp", sbhand, 1, 1, /* 0x44 */
164 "\tinc\tbp", sbhand, 1, 1, /* 0x45 */
165 "\tinc\tsi", sbhand, 1, 1, /* 0x46 */
166 "\tinc\tdi", sbhand, 1, 1, /* 0x47 */
167 "\tdec\tax", sbhand, 1, 1, /* 0x48 */
168 "\tdec\tcx", sbhand, 1, 1, /* 0x49 */
169 "\tdec\tdx", sbhand, 1, 1, /* 0x4a */
170 "\tdec\tbx", sbhand, 1, 1, /* 0x4b */
171 "\tdec\tsp", sbhand, 1, 1, /* 0x4c */
172 "\tdec\tbp", sbhand, 1, 1, /* 0x4d */
173 "\tdec\tsi", sbhand, 1, 1, /* 0x4e */
174 "\tdec\tdi", sbhand, 1, 1, /* 0x4f */
175 "\tpush\tax", sbhand, 1, 1, /* 0x50 */
176 "\tpush\tcx", sbhand, 1, 1, /* 0x51 */
177 "\tpush\tdx", sbhand, 1, 1, /* 0x52 */
178 "\tpush\tbx", sbhand, 1, 1, /* 0x53 */
179 "\tpush\tsp", sbhand, 1, 1, /* 0x54 */
180 "\tpush\tbp", sbhand, 1, 1, /* 0x55 */
181 "\tpush\tsi", sbhand, 1, 1, /* 0x56 */
182 "\tpush\tdi", sbhand, 1, 1, /* 0x57 */
183 "\tpop\tax", sbhand, 1, 1, /* 0x58 */
184 "\tpop\tcx", sbhand, 1, 1, /* 0x59 */
185 "\tpop\tdx", sbhand, 1, 1, /* 0x5a */
186 "\tpop\tbx", sbhand, 1, 1, /* 0x5b */
187 "\tpop\tsp", sbhand, 1, 1, /* 0x5c */
188 "\tpop\tbp", sbhand, 1, 1, /* 0x5d */
189 "\tpop\tsi", sbhand, 1, 1, /* 0x5e */
190 "\tpop\tdi", sbhand, 1, 1, /* 0x5f */
191 NULL, dfhand, 0, 0, /* 0x60 */
192 NULL, dfhand, 0, 0, /* 0x61 */
193 NULL, dfhand, 0, 0, /* 0x62 */
194 NULL, dfhand, 0, 0, /* 0x63 */
195 NULL, dfhand, 0, 0, /* 0x64 */
196 NULL, dfhand, 0, 0, /* 0x65 */
197 NULL, dfhand, 0, 0, /* 0x66 */
198 NULL, dfhand, 0, 0, /* 0x67 */
199 NULL, dfhand, 0, 0, /* 0x68 */
200 NULL, dfhand, 0, 0, /* 0x69 */
201 NULL, dfhand, 0, 0, /* 0x6a */
202 NULL, dfhand, 0, 0, /* 0x6b */
203 NULL, dfhand, 0, 0, /* 0x6c */
204 NULL, dfhand, 0, 0, /* 0x6d */
205 NULL, dfhand, 0, 0, /* 0x6e */
206 NULL, dfhand, 0, 0, /* 0x6f */
207 "\tjo", sjhand, 2, 2, /* 0x70 */
208 "\tjno", sjhand, 2, 2, /* 0x71 */
209 "\tjc", sjhand, 2, 2, /* 0x72 */
210 "\tjnc", sjhand, 2, 2, /* 0x73 */
211 "\tjz", sjhand, 2, 2, /* 0x74 */
212 "\tjnz", sjhand, 2, 2, /* 0x75 */
213 "\tjna", sjhand, 2, 2, /* 0x76 */
214 "\tja", sjhand, 2, 2, /* 0x77 */
215 "\tjs", sjhand, 2, 2, /* 0x78 */
216 "\tjns", sjhand, 2, 2, /* 0x79 */
217 "\tjp", sjhand, 2, 2, /* 0x7a */
218 "\tjnp", sjhand, 2, 2, /* 0x7b */
219 "\tjl", sjhand, 2, 2, /* 0x7c */
220 "\tjnl", sjhand, 2, 2, /* 0x7d */
221 "\tjng", sjhand, 2, 2, /* 0x7e */
222 "\tjg", sjhand, 2, 2, /* 0x7f */
223 AMBIG, imhand, 3, 5, /* 0x80 */
224 AMBIG, imhand, 4, 6, /* 0x81 */
225 AMBIG, imhand, 3, 5, /* 0x82 */
226 AMBIG, imhand, 3, 5, /* 0x83 */
227 TEST, mvhand, 2, 4, /* 0x84 */
228 TEST, mvhand, 2, 4, /* 0x85 */
229 "\txchg", mvhand, 2, 4, /* 0x86 */
230 "\txchg", mvhand, 2, 4, /* 0x87 */
231 MOV, mvhand, 2, 4, /* 0x88 */
232 MOV, mvhand, 2, 4, /* 0x89 */
233 MOV, mvhand, 2, 4, /* 0x8a */
234 MOV, mvhand, 2, 4, /* 0x8b */
235 MOV, mshand, 2, 4, /* 0x8c */
236 "\tlea", mvhand, 2, 4, /* 0x8d */
237 MOV, mshand, 2, 4, /* 0x8e */
238 "\tpop", pohand, 2, 4, /* 0x8f */
239 "\tnop", sbhand, 1, 1, /* 0x90 */
240 "\txchg\tax,cx", sbhand, 1, 1, /* 0x91 */
241 "\txchg\tax,dx", sbhand, 1, 1, /* 0x92 */
242 "\txchg\tax,bx", sbhand, 1, 1, /* 0x93 */
243 "\txchg\tax,sp", sbhand, 1, 1, /* 0x94 */
244 "\txchg\tax,bp", sbhand, 1, 1, /* 0x95 */
245 "\txchg\tax,si", sbhand, 1, 1, /* 0x96 */
246 "\txchg\tax,di", sbhand, 1, 1, /* 0x97 */
247 "\tcbw", sbhand, 1, 1, /* 0x98 */
248 "\tcwd", sbhand, 1, 1, /* 0x99 */
249 "\tcalli", cihand, 5, 5, /* 0x9a */
250 "\twait", sbhand, 1, 1, /* 0x9b */
251 "\tpushf", sbhand, 1, 1, /* 0x9c */
252 "\tpopf", sbhand, 1, 1, /* 0x9d */
253 "\tsahf", sbhand, 1, 1, /* 0x9e */
254 "\tlahf", sbhand, 1, 1, /* 0x9f */
255 MOV, mqhand, 3, 3, /* 0xa0 */
256 MOV, mqhand, 3, 3, /* 0xa1 */
257 MOV, mqhand, 3, 3, /* 0xa2 */
258 MOV, mqhand, 3, 3, /* 0xa3 */
259 "\tmovb", sbhand, 1, 1, /* 0xa4 */
260 "\tmovw", sbhand, 1, 1, /* 0xa5 */
261 "\tcmpb", sbhand, 1, 1, /* 0xa6 */
262 "\tcmpw", sbhand, 1, 1, /* 0xa7 */
263 TEST, tqhand, 2, 2, /* 0xa8 */
264 TEST, tqhand, 3, 3, /* 0xa9 */
265 "\tstob", sbhand, 1, 1, /* 0xaa */
266 "\tstow", sbhand, 1, 1, /* 0xab */
267 "\tlodb", sbhand, 1, 1, /* 0xac */
268 "\tlodw", sbhand, 1, 1, /* 0xad */
269 "\tscab", sbhand, 1, 1, /* 0xae */
270 "\tscaw", sbhand, 1, 1, /* 0xaf */
271 "\tmov\tal,", mihand, 2, 2, /* 0xb0 */
272 "\tmov\tcl,", mihand, 2, 2, /* 0xb1 */
273 "\tmov\tdl,", mihand, 2, 2, /* 0xb2 */
274 "\tmov\tbl,", mihand, 2, 2, /* 0xb3 */
275 "\tmov\tah,", mihand, 2, 2, /* 0xb4 */
276 "\tmov\tch,", mihand, 2, 2, /* 0xb5 */
277 "\tmov\tdh,", mihand, 2, 2, /* 0xb6 */
278 "\tmov\tbh,", mihand, 2, 2, /* 0xb7 */
279 "\tmov\tax,", mihand, 3, 3, /* 0xb8 */
280 "\tmov\tcx,", mihand, 3, 3, /* 0xb9 */
281 "\tmov\tdx,", mihand, 3, 3, /* 0xba */
282 "\tmov\tbx,", mihand, 3, 3, /* 0xbb */
283 "\tmov\tsp,", mihand, 3, 3, /* 0xbc */
284 "\tmov\tbp,", mihand, 3, 3, /* 0xbd */
285 "\tmov\tsi,", mihand, 3, 3, /* 0xbe */
286 "\tmov\tdi,", mihand, 3, 3, /* 0xbf */
287 NULL, dfhand, 0, 0, /* 0xc0 */
288 NULL, dfhand, 0, 0, /* 0xc1 */
289 "\tret", rehand, 3, 3, /* 0xc2 */
290 "\tret", sbhand, 1, 1, /* 0xc3 */
291 "\tles", mvhand, 2, 4, /* 0xc4 */
292 "\tlds", mvhand, 2, 4, /* 0xc5 */
293 MOV, mmhand, 3, 5, /* 0xc6 */
294 MOV, mmhand, 4, 6, /* 0xc7 */
295 NULL, dfhand, 0, 0, /* 0xc8 */
296 NULL, dfhand, 0, 0, /* 0xc9 */
297 "\treti", rehand, 3, 3, /* 0xca */
298 "\treti", sbhand, 1, 1, /* 0xcb */
299 "\tint", sbhand, 1, 1, /* 0xcc */
300 "\tint", inhand, 2, 2, /* 0xcd */
301 "\tinto", sbhand, 1, 1, /* 0xce */
302 "\tiret", sbhand, 1, 1, /* 0xcf */
303 AMBIG, srhand, 2, 4, /* 0xd0 */
304 AMBIG, srhand, 2, 4, /* 0xd1 */
305 AMBIG, srhand, 2, 4, /* 0xd2 */
306 AMBIG, srhand, 2, 4, /* 0xd3 */
307 "\taam", aahand, 2, 2, /* 0xd4 */
308 "\taad", aahand, 2, 2, /* 0xd5 */
309 NULL, dfhand, 0, 0, /* 0xd6 */
310 "\txlat", sbhand, 1, 1, /* 0xd7 */
311 ESC, eshand, 2, 2, /* 0xd8 */
312 ESC, eshand, 2, 2, /* 0xd9 */
313 ESC, eshand, 2, 2, /* 0xda */
314 ESC, eshand, 2, 2, /* 0xdb */
315 ESC, eshand, 2, 2, /* 0xdc */
316 ESC, eshand, 2, 2, /* 0xdd */
317 ESC, eshand, 2, 2, /* 0xde */
318 ESC, eshand, 2, 2, /* 0xdf */
319 "\tloopne", sjhand, 2, 2, /* 0xe0 */
320 "\tloope", sjhand, 2, 2, /* 0xe1 */
321 "\tloop", sjhand, 2, 2, /* 0xe2 */
322 "\tjcxz", sjhand, 2, 2, /* 0xe3 */
323 "\tin", iohand, 2, 2, /* 0xe4 */
324 "\tinw", iohand, 2, 2, /* 0xe5 */
325 "\tout", iohand, 2, 2, /* 0xe6 */
326 "\toutw", iohand, 2, 2, /* 0xe7 */
327 "\tcall", ljhand, 3, 3, /* 0xe8 */
328 "\tjmp", ljhand, 3, 3, /* 0xe9 */
329 "\tjmpi", cihand, 5, 5, /* 0xea */
330 "\tj", sjhand, 2, 2, /* 0xeb */
331 "\tin", sbhand, 1, 1, /* 0xec */
332 "\tinw", sbhand, 1, 1, /* 0xed */
333 "\tout", sbhand, 1, 1, /* 0xee */
334 "\toutw", sbhand, 1, 1, /* 0xef */
335 "\tlock", sbhand, 1, 1, /* 0xf0 */
336 NULL, dfhand, 0, 0, /* 0xf1 */
337 "\trepnz", sbhand, 1, 1, /* 0xf2 */
338 "\trepz", sbhand, 1, 1, /* 0xf3 */
339 "\thlt", sbhand, 1, 1, /* 0xf4 */
340 "\tcmc", sbhand, 1, 1, /* 0xf5 */
341 AMBIG, mahand, 2, 5, /* 0xf6 */
342 AMBIG, mahand, 2, 6, /* 0xf7 */
343 "\tclc", sbhand, 1, 1, /* 0xf8 */
344 "\tstc", sbhand, 1, 1, /* 0xf9 */
345 "\tcli", sbhand, 1, 1, /* 0xfa */
346 "\tsti", sbhand, 1, 1, /* 0xfb */
347 "\tcld", sbhand, 1, 1, /* 0xfc */
348 "\tstd", sbhand, 1, 1, /* 0xfd */
349 AMBIG, mjhand, 2, 4, /* 0xfe */
350 AMBIG, mjhand, 2, 4 /* 0xff */
353 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
355 * This simple routine returns the name field of a symbol *
356 * table entry as a printable string. *
358 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
360 char *
361 getnam(k)
363 register int k;
365 {/* * * * * * * * * * START OF getnam() * * * * * * * * * */
367 register int j;
368 static char a[9];
370 for (j = 0; j < 8; ++j)
371 if ( ! symtab[k].n_name[j] )
372 break;
373 else
374 a[j] = symtab[k].n_name[j];
376 a[j] = '\0';
378 return (a);
380 }/* * * * * * * * * * * END OF getnam() * * * * * * * * * * */
382 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
384 * This function is responsible for mucking through the *
385 * relocation table in search of externally referenced *
386 * symbols to be output as operands. It accepts two long *
387 * arguments: the code-segment location at which an extern *
388 * reference is expected, and the offset value which is *
389 * embedded in the object code and used at link time to *
390 * bias the external value. In the most typical case, the *
391 * function will be called by lookup(), which always makes *
392 * a check for external names before searching the symbol *
393 * table proper. However, it may also be called directly *
394 * by any function (such as the move-immediate handler) *
395 * which wants to make an independent check for externals. *
396 * The caller is expected to supply, as the third argument *
397 * to the function, a pointer to a character buffer large *
398 * enough to hold any possible output string. Lookext() *
399 * will fill this buffer and return a logical TRUE if it *
400 * finds an extern reference; otherwise, it will return a *
401 * logical FALSE, leaving the buffer undisturbed. *
403 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
406 lookext(off,loc,buf)
408 long off, loc;
409 char *buf;
411 {/* * * * * * * * * * START OF lookext() * * * * * * * * * */
413 register int k;
414 char c[16];
416 if ((loc != -1L) && (relptr >= 0))
417 for (k = 0; k <= relptr; ++k)
418 if ((relo[k].r_vaddr == loc)
419 && (relo[k].r_symndx < S_BSS))
421 strcpy(buf,getnam(relo[k].r_symndx));
422 if (off)
424 if (off < 0)
425 sprintf(c,"%ld",off);
426 else
427 sprintf(c,"+%ld",off);
428 strcat(buf,c);
430 return (1);
433 return (0);
435 }/* * * * * * * * * * END OF lookext() * * * * * * * * * */
437 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
439 * This function finds an entry in the symbol table by *
440 * value. Its input is a (long) machine address, and its *
441 * output is a pointer to a string containing the corre- *
442 * sponding symbolic name. The function first searches the *
443 * relocation table for a possible external reference; if *
444 * none is found, a linear search of the symbol table is *
445 * undertaken. If no matching symbol has been found at the *
446 * end of these searches, the function returns a pointer *
447 * to a string containing the ASCII equivalent of the ad- *
448 * dress which was to be located, so that, regardless of *
449 * the success of the search, the function's return value *
450 * is suitable for use as a memory-reference operand. The *
451 * caller specifies the type of symbol to be found (text, *
452 * data, bss, undefined, absolute, or common) by means of *
453 * the function's second parameter. The third parameter *
454 * specifies the format to be used in the event of a nu- *
455 * meric output: zero for absolute format, one for short *
456 * relative format, two for long relative format. The *
457 * fourth parameter is the address which would appear in *
458 * the relocation table for the reference in question, or *
459 * -1 if the relocation table is not to be searched. The *
460 * function attempts to apply a certain amount of intelli- *
461 * gence in its selection of symbols, so it is possible *
462 * that, in the absence of a type match, a symbol of the *
463 * correct value but different type will be returned. *
465 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
467 char *
468 lookup(addr,type,kind,ext)
470 long addr; /* Machine address to be located */
472 int type, /* Type of symbol to be matched */
473 kind; /* Addressing output mode to use */
475 long ext; /* Value for extern ref, if any */
477 {/* * * * * * * * * * START OF lookup() * * * * * * * * * */
479 register int j, k;
480 static char b[64];
482 struct
484 int i;
485 int t;
487 best;
489 if (lookext(addr,ext,b))
490 return (b);
492 if (segflg)
493 if (segflg & 1)
494 type = N_TEXT;
495 else
496 type = N_DATA;
498 for (k = 0, best.i = -1; k <= symptr; ++k)
499 if (symtab[k].n_value == addr)
500 if ((j = symtab[k].n_sclass & N_SECT) == type)
502 best.t = j;
503 best.i = k;
504 break;
506 else if (segflg || (HDR.a_flags & A_SEP))
507 continue;
508 else if (best.i < 0)
509 best.t = j, best.i = k;
510 else if (symrank[type][j] > symrank[type][best.t])
511 best.t = j, best.i = k;
513 if (best.i >= 0)
514 return (getnam(best.i));
516 if (kind == LOOK_ABS)
517 sprintf(b,"0x%05.5x",addr);
518 else
520 long x = addr - (PC - kind);
521 if (x < 0)
522 sprintf(b,".%ld",x);
523 else
524 sprintf(b,".+%ld",x);
527 return (b);
529 }/* * * * * * * * * * * END OF lookup() * * * * * * * * * * */
531 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
533 * This function translates an 8088 addressing mode byte *
534 * to an equivalent assembler string, returning a pointer *
535 * thereto. If necessary, it performs successive inputs *
536 * of bytes from the object file in order to obtain offset *
537 * data, adjusting PC accordingly. (The addressing mode *
538 * byte appears in several 8088 opcodes; it is used to *
539 * specify source and destination operand locations.) The *
540 * third argument to the function is zero if the standard *
541 * registers are to be used, or eight if the segment reg- *
542 * isters are to be used; these constants are defined sym- *
543 * bolically in dis.h. NOTE: The mtrans() function must *
544 * NEVER be called except immediately after fetching the *
545 * mode byte. If any additional object bytes are fetched *
546 * after the fetch of the mode byte, mtrans() will not *
547 * produce correct output! *
549 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
551 char *
552 mtrans(c,m,type)
554 register int c; /* Primary instruction byte */
555 register int m; /* Addressing mode byte */
557 int type; /* Type code: standard or seg */
559 {/* * * * * * * * * * START OF mtrans() * * * * * * * * * */
561 unsigned long pc;
562 int offset, oflag, dir, w, mod, reg, rm;
563 static char a[100];
564 static char b[30];
566 offset = 0;
567 dir = c & 2;
568 w = c & 1;
569 mod = (m & 0xc0) >> 6;
570 reg = (m & 0x38) >> 3;
571 rm = m & 7;
572 pc = PC + 1;
574 if (type)
575 w = 1;
577 if ((oflag = mod) > 2)
578 oflag = 0;
580 if (oflag)
582 int j, k;
583 if (oflag == 2)
585 FETCH(j);
586 FETCH(k);
587 offset = (k << 8) | j;
589 else
591 FETCH(j);
592 if (j & 0x80)
593 k = 0xff00;
594 else
595 k = 0;
596 offset = k | j;
600 if (dir)
602 strcpy(a,REGS[type + ((w << 3) | reg)]);
603 strcat(a,",");
604 switch (mod)
606 case 0 :
607 if (rm == 6)
609 int j, k;
610 FETCH(j);
611 FETCH(k);
612 offset = (k << 8) | j;
613 strcat(a,
614 lookup((long)(offset),N_DATA,LOOK_ABS,pc));
616 else
618 sprintf(b,"(%s)",REGS0[rm]);
619 strcat(a,b);
621 break;
622 case 1 :
623 case 2 :
624 if (mod == 1)
625 strcat(a,"*");
626 else
627 strcat(a,"#");
628 sprintf(b,"%d(",offset);
629 strcat(a,b);
630 strcat(a,REGS1[rm]);
631 strcat(a,")");
632 break;
633 case 3 :
634 strcat(a,REGS[(w << 3) | rm]);
635 break;
638 else
640 switch (mod)
642 case 0 :
643 if (rm == 6)
645 int j, k;
646 FETCH(j);
647 FETCH(k);
648 offset = (k << 8) | j;
649 strcpy(a,
650 lookup((long)(offset),N_DATA,LOOK_ABS,pc));
652 else
654 sprintf(b,"(%s)",REGS0[rm]);
655 strcpy(a,b);
657 break;
658 case 1 :
659 case 2 :
660 if (mod == 1)
661 strcpy(a,"*");
662 else
663 strcpy(a,"#");
664 sprintf(b,"%d(",offset);
665 strcat(a,b);
666 strcat(a,REGS1[rm]);
667 strcat(a,")");
668 break;
669 case 3 :
670 strcpy(a,REGS[(w << 3) | rm]);
671 break;
673 strcat(a,",");
674 strcat(a,REGS[type + ((w << 3) | reg)]);
677 return (a);
679 }/* * * * * * * * * * * END OF mtrans() * * * * * * * * * * */
681 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
683 * This simple routine truncates a string returned by the *
684 * mtrans() function, removing its source operand. This is *
685 * useful in handlers which ignore the "reg" field of the *
686 * mode byte. *
688 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
690 void
691 mtrunc(a)
693 register char *a; /* Ptr. to string to truncate */
695 {/* * * * * * * * * * START OF mtrunc() * * * * * * * * * */
697 register int k;
699 for (k = strlen(a) - 1; k >= 0; --k)
700 if (a[k] == ',')
702 a[k] = '\0';
703 break;
706 }/* * * * * * * * * * * END OF mtrunc() * * * * * * * * * * */