* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / dis88 / distabs.c
blob5a6af5ee9d96ce5ba30ac41b383f1816cbdbae82
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 "\t.code\t386", sbhand, 1, 1, /* 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 "\tseg\tfs", sbhand, 1, 1, /* 0x64 */
196 "\tseg\tgs", sbhand, 1, 1, /* 0x65 */
197 "\tuse\top32", sbhand, 1, 1, /* 0x66 */
198 "\tuse\tadr32", sbhand, 1, 1, /* 0x67 */
199 "\tpush\t", mihand, 3, 3, /* 0x68 */
200 /* NULL, dfhand, 0, 0, /* 0x68 */
201 NULL, dfhand, 0, 0, /* 0x69 */
202 "\tpush\t", mihand, 2, 2, /* 0x6a */
203 /* NULL, dfhand, 0, 0, /* 0x6a */
204 NULL, dfhand, 0, 0, /* 0x6b */
205 NULL, dfhand, 0, 0, /* 0x6c */
206 NULL, dfhand, 0, 0, /* 0x6d */
207 NULL, dfhand, 0, 0, /* 0x6e */
208 NULL, dfhand, 0, 0, /* 0x6f */
209 "\tjo", sjhand, 2, 2, /* 0x70 */
210 "\tjno", sjhand, 2, 2, /* 0x71 */
211 "\tjc", sjhand, 2, 2, /* 0x72 */
212 "\tjnc", sjhand, 2, 2, /* 0x73 */
213 "\tjz", sjhand, 2, 2, /* 0x74 */
214 "\tjnz", sjhand, 2, 2, /* 0x75 */
215 "\tjna", sjhand, 2, 2, /* 0x76 */
216 "\tja", sjhand, 2, 2, /* 0x77 */
217 "\tjs", sjhand, 2, 2, /* 0x78 */
218 "\tjns", sjhand, 2, 2, /* 0x79 */
219 "\tjp", sjhand, 2, 2, /* 0x7a */
220 "\tjnp", sjhand, 2, 2, /* 0x7b */
221 "\tjl", sjhand, 2, 2, /* 0x7c */
222 "\tjnl", sjhand, 2, 2, /* 0x7d */
223 "\tjng", sjhand, 2, 2, /* 0x7e */
224 "\tjg", sjhand, 2, 2, /* 0x7f */
225 AMBIG, imhand, 3, 5, /* 0x80 */
226 AMBIG, imhand, 4, 6, /* 0x81 */
227 AMBIG, imhand, 3, 5, /* 0x82 */
228 AMBIG, imhand, 3, 5, /* 0x83 */
229 TEST, mvhand, 2, 4, /* 0x84 */
230 TEST, mvhand, 2, 4, /* 0x85 */
231 "\txchg", mvhand, 2, 4, /* 0x86 */
232 "\txchg", mvhand, 2, 4, /* 0x87 */
233 MOV, mvhand, 2, 4, /* 0x88 */
234 MOV, mvhand, 2, 4, /* 0x89 */
235 MOV, mvhand, 2, 4, /* 0x8a */
236 MOV, mvhand, 2, 4, /* 0x8b */
237 MOV, mshand, 2, 4, /* 0x8c */
238 "\tlea", mvhand, 2, 4, /* 0x8d */
239 MOV, mshand, 2, 4, /* 0x8e */
240 "\tpop", pohand, 2, 4, /* 0x8f */
241 "\tnop", sbhand, 1, 1, /* 0x90 */
242 "\txchg\tax,cx", sbhand, 1, 1, /* 0x91 */
243 "\txchg\tax,dx", sbhand, 1, 1, /* 0x92 */
244 "\txchg\tax,bx", sbhand, 1, 1, /* 0x93 */
245 "\txchg\tax,sp", sbhand, 1, 1, /* 0x94 */
246 "\txchg\tax,bp", sbhand, 1, 1, /* 0x95 */
247 "\txchg\tax,si", sbhand, 1, 1, /* 0x96 */
248 "\txchg\tax,di", sbhand, 1, 1, /* 0x97 */
249 "\tcbw", sbhand, 1, 1, /* 0x98 */
250 "\tcwd", sbhand, 1, 1, /* 0x99 */
251 "\tcalli", cihand, 5, 5, /* 0x9a */
252 "\twait", sbhand, 1, 1, /* 0x9b */
253 "\tpushf", sbhand, 1, 1, /* 0x9c */
254 "\tpopf", sbhand, 1, 1, /* 0x9d */
255 "\tsahf", sbhand, 1, 1, /* 0x9e */
256 "\tlahf", sbhand, 1, 1, /* 0x9f */
257 MOV, mqhand, 3, 3, /* 0xa0 */
258 MOV, mqhand, 3, 3, /* 0xa1 */
259 MOV, mqhand, 3, 3, /* 0xa2 */
260 MOV, mqhand, 3, 3, /* 0xa3 */
261 "\tmovb", sbhand, 1, 1, /* 0xa4 */
262 "\tmovw", sbhand, 1, 1, /* 0xa5 */
263 "\tcmpb", sbhand, 1, 1, /* 0xa6 */
264 "\tcmpw", sbhand, 1, 1, /* 0xa7 */
265 TEST, tqhand, 2, 2, /* 0xa8 */
266 TEST, tqhand, 3, 3, /* 0xa9 */
267 "\tstob", sbhand, 1, 1, /* 0xaa */
268 "\tstow", sbhand, 1, 1, /* 0xab */
269 "\tlodb", sbhand, 1, 1, /* 0xac */
270 "\tlodw", sbhand, 1, 1, /* 0xad */
271 "\tscab", sbhand, 1, 1, /* 0xae */
272 "\tscaw", sbhand, 1, 1, /* 0xaf */
273 "\tmov\tal,", mihand, 2, 2, /* 0xb0 */
274 "\tmov\tcl,", mihand, 2, 2, /* 0xb1 */
275 "\tmov\tdl,", mihand, 2, 2, /* 0xb2 */
276 "\tmov\tbl,", mihand, 2, 2, /* 0xb3 */
277 "\tmov\tah,", mihand, 2, 2, /* 0xb4 */
278 "\tmov\tch,", mihand, 2, 2, /* 0xb5 */
279 "\tmov\tdh,", mihand, 2, 2, /* 0xb6 */
280 "\tmov\tbh,", mihand, 2, 2, /* 0xb7 */
281 "\tmov\tax,", mihand, 3, 3, /* 0xb8 */
282 "\tmov\tcx,", mihand, 3, 3, /* 0xb9 */
283 "\tmov\tdx,", mihand, 3, 3, /* 0xba */
284 "\tmov\tbx,", mihand, 3, 3, /* 0xbb */
285 "\tmov\tsp,", mihand, 3, 3, /* 0xbc */
286 "\tmov\tbp,", mihand, 3, 3, /* 0xbd */
287 "\tmov\tsi,", mihand, 3, 3, /* 0xbe */
288 "\tmov\tdi,", mihand, 3, 3, /* 0xbf */
289 NULL, dfhand, 0, 0, /* 0xc0 */
290 NULL, dfhand, 0, 0, /* 0xc1 */
291 "\tret", rehand, 3, 3, /* 0xc2 */
292 "\tret", sbhand, 1, 1, /* 0xc3 */
293 "\tles", mvhand, 2, 4, /* 0xc4 */
294 "\tlds", mvhand, 2, 4, /* 0xc5 */
295 MOV, mmhand, 3, 5, /* 0xc6 */
296 MOV, mmhand, 4, 6, /* 0xc7 */
297 NULL, dfhand, 0, 0, /* 0xc8 */
298 NULL, dfhand, 0, 0, /* 0xc9 */
299 "\treti", rehand, 3, 3, /* 0xca */
300 "\treti", sbhand, 1, 1, /* 0xcb */
301 "\tint", sbhand, 1, 1, /* 0xcc */
302 "\tint", inhand, 2, 2, /* 0xcd */
303 "\tinto", sbhand, 1, 1, /* 0xce */
304 "\tiret", sbhand, 1, 1, /* 0xcf */
305 AMBIG, srhand, 2, 4, /* 0xd0 */
306 AMBIG, srhand, 2, 4, /* 0xd1 */
307 AMBIG, srhand, 2, 4, /* 0xd2 */
308 AMBIG, srhand, 2, 4, /* 0xd3 */
309 "\taam", aahand, 2, 2, /* 0xd4 */
310 "\taad", aahand, 2, 2, /* 0xd5 */
311 NULL, dfhand, 0, 0, /* 0xd6 */
312 "\txlat", sbhand, 1, 1, /* 0xd7 */
313 ESC, eshand, 2, 2, /* 0xd8 */
314 ESC, eshand, 2, 2, /* 0xd9 */
315 ESC, eshand, 2, 2, /* 0xda */
316 ESC, eshand, 2, 2, /* 0xdb */
317 ESC, eshand, 2, 2, /* 0xdc */
318 ESC, eshand, 2, 2, /* 0xdd */
319 ESC, eshand, 2, 2, /* 0xde */
320 ESC, eshand, 2, 2, /* 0xdf */
321 "\tloopne", sjhand, 2, 2, /* 0xe0 */
322 "\tloope", sjhand, 2, 2, /* 0xe1 */
323 "\tloop", sjhand, 2, 2, /* 0xe2 */
324 "\tjcxz", sjhand, 2, 2, /* 0xe3 */
325 "\tin", iohand, 2, 2, /* 0xe4 */
326 "\tinw", iohand, 2, 2, /* 0xe5 */
327 "\tout", iohand, 2, 2, /* 0xe6 */
328 "\toutw", iohand, 2, 2, /* 0xe7 */
329 "\tcall", ljhand, 3, 3, /* 0xe8 */
330 "\tjmp", ljhand, 3, 3, /* 0xe9 */
331 "\tjmpi", cihand, 5, 5, /* 0xea */
332 "\tj", sjhand, 2, 2, /* 0xeb */
333 "\tin", sbhand, 1, 1, /* 0xec */
334 "\tinw", sbhand, 1, 1, /* 0xed */
335 "\tout", sbhand, 1, 1, /* 0xee */
336 "\toutw", sbhand, 1, 1, /* 0xef */
337 "\tlock", sbhand, 1, 1, /* 0xf0 */
338 NULL, dfhand, 0, 0, /* 0xf1 */
339 "\trepnz", sbhand, 1, 1, /* 0xf2 */
340 "\trepz", sbhand, 1, 1, /* 0xf3 */
341 "\thlt", sbhand, 1, 1, /* 0xf4 */
342 "\tcmc", sbhand, 1, 1, /* 0xf5 */
343 AMBIG, mahand, 2, 5, /* 0xf6 */
344 AMBIG, mahand, 2, 6, /* 0xf7 */
345 "\tclc", sbhand, 1, 1, /* 0xf8 */
346 "\tstc", sbhand, 1, 1, /* 0xf9 */
347 "\tcli", sbhand, 1, 1, /* 0xfa */
348 "\tsti", sbhand, 1, 1, /* 0xfb */
349 "\tcld", sbhand, 1, 1, /* 0xfc */
350 "\tstd", sbhand, 1, 1, /* 0xfd */
351 AMBIG, mjhand, 2, 4, /* 0xfe */
352 AMBIG, mjhand, 2, 4 /* 0xff */
355 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
357 * This simple routine returns the name field of a symbol *
358 * table entry as a printable string. *
360 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
362 char *
363 getnam(k)
365 register int k;
367 {/* * * * * * * * * * START OF getnam() * * * * * * * * * */
369 register int j;
370 static char a[sizeof(symtab->n_name)+1];
372 for (j = 0; j < sizeof(symtab[k].n_name); ++j)
373 if ( ! symtab[k].n_name[j] )
374 break;
375 else
376 a[j] = symtab[k].n_name[j];
378 a[j] = '\0';
380 return (a);
382 }/* * * * * * * * * * * END OF getnam() * * * * * * * * * * */
384 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
386 * This function is responsible for mucking through the *
387 * relocation table in search of externally referenced *
388 * symbols to be output as operands. It accepts two long *
389 * arguments: the code-segment location at which an extern *
390 * reference is expected, and the offset value which is *
391 * embedded in the object code and used at link time to *
392 * bias the external value. In the most typical case, the *
393 * function will be called by lookup(), which always makes *
394 * a check for external names before searching the symbol *
395 * table proper. However, it may also be called directly *
396 * by any function (such as the move-immediate handler) *
397 * which wants to make an independent check for externals. *
398 * The caller is expected to supply, as the third argument *
399 * to the function, a pointer to a character buffer large *
400 * enough to hold any possible output string. Lookext() *
401 * will fill this buffer and return a logical TRUE if it *
402 * finds an extern reference; otherwise, it will return a *
403 * logical FALSE, leaving the buffer undisturbed. *
405 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
408 lookext(off,loc,buf)
410 long off, loc;
411 char *buf;
413 {/* * * * * * * * * * START OF lookext() * * * * * * * * * */
415 register int k;
416 char c[32];
418 if ((loc != -1L) && (relptr >= 0))
419 for (k = 0; k <= relptr; ++k)
420 if ((relo[k].r_vaddr == loc)
421 && (relo[k].r_symndx < S_BSS))
423 strcpy(buf,getnam(relo[k].r_symndx));
424 if (off)
426 if (off < 0)
427 sprintf(c,"%ld",off);
428 else
429 sprintf(c,"+%ld",off);
430 strcat(buf,c);
432 return (1);
435 return (0);
437 }/* * * * * * * * * * END OF lookext() * * * * * * * * * */
439 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
441 * This function finds an entry in the symbol table by *
442 * value. Its input is a (long) machine address, and its *
443 * output is a pointer to a string containing the corre- *
444 * sponding symbolic name. The function first searches the *
445 * relocation table for a possible external reference; if *
446 * none is found, a linear search of the symbol table is *
447 * undertaken. If no matching symbol has been found at the *
448 * end of these searches, the function returns a pointer *
449 * to a string containing the ASCII equivalent of the ad- *
450 * dress which was to be located, so that, regardless of *
451 * the success of the search, the function's return value *
452 * is suitable for use as a memory-reference operand. The *
453 * caller specifies the type of symbol to be found (text, *
454 * data, bss, undefined, absolute, or common) by means of *
455 * the function's second parameter. The third parameter *
456 * specifies the format to be used in the event of a nu- *
457 * meric output: zero for absolute format, one for short *
458 * relative format, two for long relative format. The *
459 * fourth parameter is the address which would appear in *
460 * the relocation table for the reference in question, or *
461 * -1 if the relocation table is not to be searched. The *
462 * function attempts to apply a certain amount of intelli- *
463 * gence in its selection of symbols, so it is possible *
464 * that, in the absence of a type match, a symbol of the *
465 * correct value but different type will be returned. *
467 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
469 char *
470 lookup(addr,type,kind,ext)
472 long addr; /* Machine address to be located */
474 int type, /* Type of symbol to be matched */
475 kind; /* Addressing output mode to use */
477 long ext; /* Value for extern ref, if any */
479 {/* * * * * * * * * * START OF lookup() * * * * * * * * * */
481 register int j, k;
482 static char b[80];
484 struct
486 int i;
487 int t;
489 best;
491 if (lookext(addr,ext,b))
492 return (b);
494 if (segflg)
495 if (segflg & 1)
496 type = N_TEXT;
497 else
498 type = N_DATA;
500 for (k = 0, best.i = -1; k <= symptr; ++k)
501 if (symtab[k].n_value == addr)
502 if ((j = symtab[k].n_sclass & N_SECT) == type)
504 best.t = j;
505 best.i = k;
506 break;
508 else if (segflg || (HDR.a_flags & A_SEP))
509 continue;
510 else if (best.i < 0)
511 best.t = j, best.i = k;
512 else if (symrank[type][j] > symrank[type][best.t])
513 best.t = j, best.i = k;
515 if (best.i >= 0)
516 return (getnam(best.i));
518 if (kind == LOOK_ABS)
519 sprintf(b,"$%04lx",addr);
520 else
522 long x = addr - (PC - kind);
523 if (x < 0)
524 sprintf(b,".%ld",x);
525 else
526 sprintf(b,".+%ld",x);
529 return (b);
531 }/* * * * * * * * * * * END OF lookup() * * * * * * * * * * */
533 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
535 * This function translates an 8088 addressing mode byte *
536 * to an equivalent assembler string, returning a pointer *
537 * thereto. If necessary, it performs successive inputs *
538 * of bytes from the object file in order to obtain offset *
539 * data, adjusting PC accordingly. (The addressing mode *
540 * byte appears in several 8088 opcodes; it is used to *
541 * specify source and destination operand locations.) The *
542 * third argument to the function is zero if the standard *
543 * registers are to be used, or eight if the segment reg- *
544 * isters are to be used; these constants are defined sym- *
545 * bolically in dis.h. NOTE: The mtrans() function must *
546 * NEVER be called except immediately after fetching the *
547 * mode byte. If any additional object bytes are fetched *
548 * after the fetch of the mode byte, mtrans() will not *
549 * produce correct output! *
551 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
553 #undef FRV
554 #define FRV ""
556 char *
557 mtrans(c,m,type)
559 register int c; /* Primary instruction byte */
560 register int m; /* Addressing mode byte */
562 int type; /* Type code: standard or seg */
564 {/* * * * * * * * * * START OF mtrans() * * * * * * * * * */
566 unsigned long pc;
567 int offset, oflag, dir, w, mod, reg, rm;
568 static char a[100];
569 static char b[30];
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;
579 if (type)
580 w = 1;
582 if ((oflag = mod) > 2)
583 oflag = 0;
585 if (oflag)
587 int j, k;
588 if (oflag == 2)
590 FETCH(j);
591 FETCH(k);
592 offset = (k << 8) | j;
594 else
596 FETCH(j);
597 if (j & 0x80)
598 k = 0xff00;
599 else
600 k = 0;
601 offset = k | j;
605 if (dir)
607 strcpy(a,REGS[type + ((w << 3) | reg)]);
608 strcat(a,",");
609 switch (mod)
611 case 0 :
612 if (rm == 6)
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));
621 else
623 sprintf(b,"(%s)",REGS0[rm]);
624 strcat(a,b);
626 break;
627 case 1 :
628 case 2 :
629 if (mod == 1)
630 strcat(a,"*");
631 else
632 strcat(a,"#");
633 sprintf(b,"%d(", (short)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;
643 else
645 switch (mod)
647 case 0 :
648 if (rm == 6)
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));
657 else
659 sprintf(b,"(%s)",REGS0[rm]);
660 strcpy(a,b);
662 break;
663 case 1 :
664 case 2 :
665 if (mod == 1)
666 strcpy(a,"*");
667 else
668 strcpy(a,"#");
669 sprintf(b,"%d(", (short)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;
678 strcat(a,",");
679 strcat(a,REGS[type + ((w << 3) | reg)]);
682 return (a);
684 }/* * * * * * * * * * * END OF mtrans() * * * * * * * * * * */
686 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
688 * This simple routine truncates a string returned by the *
689 * mtrans() function, removing its source operand. This is *
690 * useful in handlers which ignore the "reg" field of the *
691 * mode byte. *
693 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
695 void
696 mtrunc(a)
698 register char *a; /* Ptr. to string to truncate */
700 {/* * * * * * * * * * START OF mtrunc() * * * * * * * * * */
702 register int k;
704 for (k = strlen(a) - 1; k >= 0; --k)
705 if (a[k] == ',')
707 a[k] = '\0';
708 break;
711 }/* * * * * * * * * * * END OF mtrunc() * * * * * * * * * * */