source: trunk/minix/commands/dis88/distabs.c@ 15

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

Minix 3.1.2a

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