tc-pdp11.c revision 1.8 1 1.1 christos /* tc-pdp11.c - pdp11-specific -
2 1.8 christos Copyright (C) 2001-2022 Free Software Foundation, Inc.
3 1.1 christos
4 1.1 christos This file is part of GAS, the GNU Assembler.
5 1.1 christos
6 1.1 christos GAS is free software; you can redistribute it and/or modify
7 1.1 christos it under the terms of the GNU General Public License as published by
8 1.1 christos the Free Software Foundation; either version 3, or (at your option)
9 1.1 christos any later version.
10 1.1 christos
11 1.1 christos GAS is distributed in the hope that it will be useful,
12 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 christos GNU General Public License for more details.
15 1.1 christos
16 1.1 christos You should have received a copy of the GNU General Public License
17 1.1 christos along with GAS; see the file COPYING. If not, write to
18 1.1 christos the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 1.1 christos Boston, MA 02110-1301, USA. */
20 1.1 christos
21 1.1 christos #include "as.h"
22 1.1 christos #include "safe-ctype.h"
23 1.1 christos #include "opcode/pdp11.h"
24 1.1 christos
25 1.1 christos extern int flonum_gen2vax (int, FLONUM_TYPE * f, LITTLENUM_TYPE *);
26 1.1 christos
27 1.1 christos /* A representation for PDP-11 machine code. */
28 1.1 christos struct pdp11_code
29 1.1 christos {
30 1.5 christos const char *error;
31 1.1 christos int code;
32 1.1 christos int additional; /* Is there an additional word? */
33 1.1 christos int word; /* Additional word, if any. */
34 1.1 christos struct
35 1.1 christos {
36 1.1 christos bfd_reloc_code_real_type type;
37 1.1 christos expressionS exp;
38 1.1 christos int pc_rel;
39 1.1 christos } reloc;
40 1.1 christos };
41 1.1 christos
42 1.1 christos /* Instruction set extensions.
43 1.1 christos
44 1.1 christos If you change this from an array to something else, please update
45 1.1 christos the "PDP-11 instruction set extensions" comment in pdp11.h. */
46 1.1 christos int pdp11_extension[PDP11_EXT_NUM];
47 1.1 christos
48 1.1 christos /* Assembly options. */
49 1.1 christos
50 1.1 christos #define ASM_OPT_PIC 1
51 1.1 christos #define ASM_OPT_NUM 2
52 1.1 christos
53 1.1 christos int asm_option[ASM_OPT_NUM];
54 1.1 christos
55 1.1 christos /* These chars start a comment anywhere in a source file (except inside
56 1.1 christos another comment. */
57 1.1 christos const char comment_chars[] = "#/";
58 1.1 christos
59 1.1 christos /* These chars only start a comment at the beginning of a line. */
60 1.1 christos const char line_comment_chars[] = "#/";
61 1.1 christos
62 1.1 christos const char line_separator_chars[] = ";";
63 1.1 christos
64 1.1 christos /* Chars that can be used to separate mant from exp in floating point nums. */
65 1.1 christos const char EXP_CHARS[] = "eE";
66 1.1 christos
67 1.1 christos /* Chars that mean this number is a floating point constant. */
68 1.1 christos /* as in 0f123.456. */
69 1.1 christos /* or 0H1.234E-12 (see exp chars above). */
70 1.1 christos const char FLT_CHARS[] = "dDfF";
71 1.1 christos
72 1.1 christos void pseudo_even (int);
73 1.1 christos void pseudo_bss (int);
74 1.1 christos
75 1.1 christos const pseudo_typeS md_pseudo_table[] =
76 1.1 christos {
77 1.1 christos { "bss", pseudo_bss, 0 },
78 1.1 christos { "even", pseudo_even, 0 },
79 1.1 christos { 0, 0, 0 },
80 1.1 christos };
81 1.1 christos
82 1.8 christos static htab_t insn_hash = NULL;
83 1.1 christos
84 1.1 christos static int
86 1.1 christos set_option (const char *arg)
87 1.1 christos {
88 1.1 christos int yes = 1;
89 1.1 christos
90 1.1 christos if (strcmp (arg, "all-extensions") == 0
91 1.1 christos || strcmp (arg, "all") == 0)
92 1.1 christos {
93 1.1 christos memset (pdp11_extension, ~0, sizeof pdp11_extension);
94 1.1 christos pdp11_extension[PDP11_NONE] = 0;
95 1.1 christos return 1;
96 1.1 christos }
97 1.1 christos else if (strcmp (arg, "no-extensions") == 0)
98 1.1 christos {
99 1.1 christos memset (pdp11_extension, 0, sizeof pdp11_extension);
100 1.1 christos pdp11_extension[PDP11_BASIC] = 1;
101 1.1 christos return 1;
102 1.1 christos }
103 1.8 christos
104 1.1 christos if (startswith (arg, "no-"))
105 1.1 christos {
106 1.1 christos yes = 0;
107 1.1 christos arg += 3;
108 1.1 christos }
109 1.6 christos
110 1.1 christos /* Commercial instructions. */
111 1.1 christos if (strcmp (arg, "cis") == 0)
112 1.1 christos pdp11_extension[PDP11_CIS] = yes;
113 1.1 christos /* Call supervisor mode. */
114 1.1 christos else if (strcmp (arg, "csm") == 0)
115 1.1 christos pdp11_extension[PDP11_CSM] = yes;
116 1.1 christos /* Extended instruction set. */
117 1.1 christos else if (strcmp (arg, "eis") == 0)
118 1.1 christos pdp11_extension[PDP11_EIS] = pdp11_extension[PDP11_LEIS] = yes;
119 1.1 christos /* KEV11 floating-point. */
120 1.1 christos else if (strcmp (arg, "fis") == 0
121 1.1 christos || strcmp (arg, "kev11") == 0
122 1.1 christos || strcmp (arg, "kev-11") == 0)
123 1.1 christos pdp11_extension[PDP11_FIS] = yes;
124 1.1 christos /* FP-11 floating-point. */
125 1.1 christos else if (strcmp (arg, "fpp") == 0
126 1.1 christos || strcmp (arg, "fpu") == 0
127 1.1 christos || strcmp (arg, "fp11") == 0
128 1.1 christos || strcmp (arg, "fp-11") == 0
129 1.1 christos || strcmp (arg, "fpj11") == 0
130 1.1 christos || strcmp (arg, "fp-j11") == 0
131 1.1 christos || strcmp (arg, "fpj-11") == 0)
132 1.1 christos pdp11_extension[PDP11_FPP] = yes;
133 1.1 christos /* Limited extended insns. */
134 1.1 christos else if (strcmp (arg, "limited-eis") == 0)
135 1.1 christos {
136 1.1 christos pdp11_extension[PDP11_LEIS] = yes;
137 1.1 christos if (!pdp11_extension[PDP11_LEIS])
138 1.1 christos pdp11_extension[PDP11_EIS] = 0;
139 1.1 christos }
140 1.1 christos /* Move from processor type. */
141 1.1 christos else if (strcmp (arg, "mfpt") == 0)
142 1.1 christos pdp11_extension[PDP11_MFPT] = yes;
143 1.8 christos /* Multiprocessor insns: */
144 1.1 christos else if (startswith (arg, "mproc")
145 1.8 christos /* TSTSET, WRTLCK */
146 1.1 christos || startswith (arg, "multiproc"))
147 1.1 christos pdp11_extension[PDP11_MPROC] = yes;
148 1.1 christos /* Move from/to proc status. */
149 1.1 christos else if (strcmp (arg, "mxps") == 0)
150 1.1 christos pdp11_extension[PDP11_MXPS] = yes;
151 1.1 christos /* Position-independent code. */
152 1.1 christos else if (strcmp (arg, "pic") == 0)
153 1.1 christos asm_option[ASM_OPT_PIC] = yes;
154 1.1 christos /* Set priority level. */
155 1.1 christos else if (strcmp (arg, "spl") == 0)
156 1.1 christos pdp11_extension[PDP11_SPL] = yes;
157 1.1 christos /* Microcode instructions: */
158 1.1 christos else if (strcmp (arg, "ucode") == 0
159 1.1 christos /* LDUB, MED, XFC */
160 1.1 christos || strcmp (arg, "microcode") == 0)
161 1.1 christos pdp11_extension[PDP11_UCODE] = yes;
162 1.1 christos else
163 1.1 christos return 0;
164 1.1 christos
165 1.1 christos return 1;
166 1.1 christos }
167 1.1 christos
168 1.1 christos
169 1.1 christos static void
170 1.1 christos init_defaults (void)
171 1.1 christos {
172 1.1 christos static int first = 1;
173 1.1 christos
174 1.1 christos if (first)
175 1.1 christos {
176 1.1 christos set_option ("all-extensions");
177 1.1 christos set_option ("pic");
178 1.1 christos first = 0;
179 1.1 christos }
180 1.1 christos }
181 1.1 christos
182 1.1 christos void
183 1.1 christos md_begin (void)
184 1.1 christos {
185 1.1 christos int i;
186 1.1 christos
187 1.1 christos init_defaults ();
188 1.8 christos
189 1.1 christos insn_hash = str_htab_create ();
190 1.1 christos
191 1.8 christos for (i = 0; i < pdp11_num_opcodes; i++)
192 1.1 christos str_hash_insert (insn_hash, pdp11_opcodes[i].name, pdp11_opcodes + i, 0);
193 1.8 christos for (i = 0; i < pdp11_num_aliases; i++)
194 1.1 christos str_hash_insert (insn_hash, pdp11_aliases[i].name, pdp11_aliases + i, 0);
195 1.1 christos }
196 1.1 christos
197 1.1 christos void
198 1.1 christos md_number_to_chars (char con[], valueT value, int nbytes)
199 1.1 christos {
200 1.1 christos /* On a PDP-11, 0x1234 is stored as "\x12\x34", and
201 1.6 christos 0x12345678 is stored as "\x56\x78\x12\x34". It's
202 1.1 christos anyone's guess what 0x123456 would be stored like. */
203 1.1 christos
204 1.1 christos switch (nbytes)
205 1.1 christos {
206 1.1 christos case 0:
207 1.1 christos break;
208 1.1 christos case 1:
209 1.1 christos con[0] = value & 0xff;
210 1.1 christos break;
211 1.1 christos case 2:
212 1.1 christos con[0] = value & 0xff;
213 1.1 christos con[1] = (value >> 8) & 0xff;
214 1.1 christos break;
215 1.1 christos case 4:
216 1.1 christos con[0] = (value >> 16) & 0xff;
217 1.1 christos con[1] = (value >> 24) & 0xff;
218 1.1 christos con[2] = value & 0xff;
219 1.1 christos con[3] = (value >> 8) & 0xff;
220 1.8 christos break;
221 1.8 christos #ifdef BFD64
222 1.8 christos case 8:
223 1.8 christos con[0] = (value >> 48) & 0xff;
224 1.8 christos con[1] = (value >> 56) & 0xff;
225 1.8 christos con[2] = (value >> 32) & 0xff;
226 1.8 christos con[3] = (value >> 40) & 0xff;
227 1.8 christos con[4] = (value >> 16) & 0xff;
228 1.8 christos con[5] = (value >> 24) & 0xff;
229 1.8 christos con[6] = value & 0xff;
230 1.8 christos con[7] = (value >> 8) & 0xff;
231 1.8 christos break;
232 1.1 christos #endif
233 1.1 christos default:
234 1.1 christos BAD_CASE (nbytes);
235 1.1 christos }
236 1.1 christos }
237 1.1 christos
238 1.1 christos /* Fix up some data or instructions after we find out the value of a symbol
239 1.1 christos that they reference. Knows about order of bytes in address. */
240 1.1 christos
241 1.1 christos void
242 1.1 christos md_apply_fix (fixS *fixP,
243 1.1 christos valueT * valP,
244 1.1 christos segT seg ATTRIBUTE_UNUSED)
245 1.1 christos {
246 1.1 christos valueT code;
247 1.1 christos valueT mask;
248 1.1 christos valueT val = * valP;
249 1.1 christos char *buf;
250 1.1 christos int shift;
251 1.1 christos int size;
252 1.1 christos
253 1.1 christos buf = fixP->fx_where + fixP->fx_frag->fr_literal;
254 1.1 christos size = fixP->fx_size;
255 1.1 christos code = md_chars_to_number ((unsigned char *) buf, size);
256 1.1 christos
257 1.1 christos switch (fixP->fx_r_type)
258 1.7 christos {
259 1.7 christos case BFD_RELOC_8:
260 1.7 christos mask = 0xff;
261 1.7 christos shift = 0;
262 1.1 christos break;
263 1.1 christos case BFD_RELOC_16:
264 1.1 christos case BFD_RELOC_16_PCREL:
265 1.1 christos mask = 0xffff;
266 1.1 christos shift = 0;
267 1.8 christos break;
268 1.8 christos case BFD_RELOC_32:
269 1.8 christos mask = 0xffffffff;
270 1.8 christos shift = 0;
271 1.1 christos break;
272 1.1 christos case BFD_RELOC_PDP11_DISP_8_PCREL:
273 1.1 christos mask = 0x00ff;
274 1.1 christos shift = 1;
275 1.1 christos break;
276 1.1 christos case BFD_RELOC_PDP11_DISP_6_PCREL:
277 1.1 christos mask = 0x003f;
278 1.1 christos shift = 1;
279 1.1 christos val = -val;
280 1.1 christos break;
281 1.1 christos default:
282 1.1 christos BAD_CASE (fixP->fx_r_type);
283 1.1 christos }
284 1.1 christos
285 1.1 christos if (fixP->fx_addsy != NULL)
286 1.1 christos val += symbol_get_bfdsym (fixP->fx_addsy)->section->vma;
287 1.1 christos /* *value += fixP->fx_addsy->bsym->section->vma; */
288 1.1 christos
289 1.1 christos code &= ~mask;
290 1.1 christos code |= (val >> shift) & mask;
291 1.1 christos number_to_chars_littleendian (buf, code, size);
292 1.1 christos
293 1.1 christos if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
294 1.1 christos fixP->fx_done = 1;
295 1.1 christos }
296 1.1 christos
297 1.5 christos long
298 1.1 christos md_chars_to_number (unsigned char *con, int nbytes)
299 1.1 christos {
300 1.1 christos /* On a PDP-11, 0x1234 is stored as "\x12\x34", and
301 1.6 christos 0x12345678 is stored as "\x56\x78\x12\x34". It's
302 1.1 christos anyone's guess what 0x123456 would be stored like. */
303 1.1 christos switch (nbytes)
304 1.1 christos {
305 1.1 christos case 0:
306 1.1 christos return 0;
307 1.1 christos case 1:
308 1.1 christos return con[0];
309 1.1 christos case 2:
310 1.1 christos return (con[1] << BITS_PER_CHAR) | con[0];
311 1.1 christos case 4:
312 1.1 christos return
313 1.1 christos (((con[1] << BITS_PER_CHAR) | con[0]) << (2 * BITS_PER_CHAR))
314 1.1 christos |((con[3] << BITS_PER_CHAR) | con[2]);
315 1.1 christos default:
316 1.1 christos BAD_CASE (nbytes);
317 1.1 christos return 0;
318 1.1 christos }
319 1.1 christos }
320 1.1 christos
321 1.1 christos static char *
323 1.1 christos skip_whitespace (char *str)
324 1.1 christos {
325 1.1 christos while (*str == ' ' || *str == '\t')
326 1.1 christos str++;
327 1.1 christos return str;
328 1.1 christos }
329 1.1 christos
330 1.1 christos static char *
331 1.1 christos find_whitespace (char *str)
332 1.1 christos {
333 1.1 christos while (*str != ' ' && *str != '\t' && *str != 0)
334 1.1 christos str++;
335 1.1 christos return str;
336 1.1 christos }
337 1.1 christos
338 1.1 christos static char *
339 1.1 christos parse_reg (char *str, struct pdp11_code *operand)
340 1.1 christos {
341 1.1 christos str = skip_whitespace (str);
342 1.1 christos if (TOLOWER (*str) == 'r')
343 1.1 christos {
344 1.1 christos str++;
345 1.1 christos switch (*str)
346 1.1 christos {
347 1.1 christos case '0': case '1': case '2': case '3':
348 1.1 christos case '4': case '5': case '6': case '7':
349 1.1 christos operand->code = *str - '0';
350 1.1 christos str++;
351 1.1 christos break;
352 1.1 christos default:
353 1.1 christos operand->error = _("Bad register name");
354 1.1 christos return str - 1;
355 1.8 christos }
356 1.8 christos }
357 1.1 christos else if (startswith (str, "sp")
358 1.1 christos || startswith (str, "SP"))
359 1.1 christos {
360 1.1 christos operand->code = 6;
361 1.8 christos str += 2;
362 1.8 christos }
363 1.1 christos else if (startswith (str, "pc")
364 1.1 christos || startswith (str, "PC"))
365 1.1 christos {
366 1.1 christos operand->code = 7;
367 1.1 christos str += 2;
368 1.8 christos }
369 1.8 christos else
370 1.8 christos {
371 1.8 christos operand->error = _("Bad register name");
372 1.1 christos return str;
373 1.8 christos }
374 1.8 christos
375 1.8 christos if (ISALNUM (*str) || *str == '_' || *str == '.')
376 1.8 christos {
377 1.8 christos operand->error = _("Bad register name");
378 1.8 christos str -= 2;
379 1.1 christos }
380 1.1 christos
381 1.1 christos return str;
382 1.1 christos }
383 1.1 christos
384 1.1 christos static char *
385 1.1 christos parse_ac5 (char *str, struct pdp11_code *operand)
386 1.8 christos {
387 1.8 christos str = skip_whitespace (str);
388 1.8 christos if (startswith (str, "fr")
389 1.8 christos || startswith (str, "FR")
390 1.1 christos || startswith (str, "ac")
391 1.1 christos || startswith (str, "AC"))
392 1.1 christos {
393 1.1 christos str += 2;
394 1.1 christos switch (*str)
395 1.1 christos {
396 1.1 christos case '0': case '1': case '2': case '3':
397 1.1 christos case '4': case '5':
398 1.1 christos operand->code = *str - '0';
399 1.1 christos str++;
400 1.1 christos break;
401 1.1 christos default:
402 1.1 christos operand->error = _("Bad register name");
403 1.1 christos return str - 2;
404 1.1 christos }
405 1.1 christos }
406 1.1 christos else
407 1.1 christos {
408 1.1 christos operand->error = _("Bad register name");
409 1.1 christos return str;
410 1.1 christos }
411 1.1 christos
412 1.1 christos return str;
413 1.1 christos }
414 1.1 christos
415 1.1 christos static char *
416 1.1 christos parse_ac (char *str, struct pdp11_code *operand)
417 1.1 christos {
418 1.1 christos str = parse_ac5 (str, operand);
419 1.1 christos if (!operand->error && operand->code > 3)
420 1.1 christos {
421 1.1 christos operand->error = _("Bad register name");
422 1.1 christos return str - 3;
423 1.1 christos }
424 1.1 christos
425 1.1 christos return str;
426 1.1 christos }
427 1.1 christos
428 1.1 christos static char *
429 1.1 christos parse_expression (char *str, struct pdp11_code *operand)
430 1.1 christos {
431 1.1 christos char *save_input_line_pointer;
432 1.1 christos segT seg;
433 1.1 christos
434 1.1 christos save_input_line_pointer = input_line_pointer;
435 1.1 christos input_line_pointer = str;
436 1.1 christos seg = expression (&operand->reloc.exp);
437 1.1 christos if (seg == NULL)
438 1.1 christos {
439 1.1 christos input_line_pointer = save_input_line_pointer;
440 1.1 christos operand->error = _("Error in expression");
441 1.1 christos return str;
442 1.1 christos }
443 1.1 christos
444 1.1 christos str = input_line_pointer;
445 1.1 christos input_line_pointer = save_input_line_pointer;
446 1.1 christos
447 1.1 christos operand->reloc.pc_rel = 0;
448 1.1 christos
449 1.1 christos return str;
450 1.1 christos }
451 1.1 christos
452 1.1 christos static char *
453 1.1 christos parse_op_no_deferred (char *str, struct pdp11_code *operand)
454 1.1 christos {
455 1.1 christos LITTLENUM_TYPE literal_float[2];
456 1.1 christos
457 1.1 christos str = skip_whitespace (str);
458 1.1 christos
459 1.1 christos switch (*str)
460 1.1 christos {
461 1.1 christos case '(': /* (rn) and (rn)+ */
462 1.1 christos str = parse_reg (str + 1, operand);
463 1.1 christos if (operand->error)
464 1.1 christos return str;
465 1.1 christos str = skip_whitespace (str);
466 1.1 christos if (*str != ')')
467 1.1 christos {
468 1.1 christos operand->error = _("Missing ')'");
469 1.1 christos return str;
470 1.1 christos }
471 1.1 christos str++;
472 1.1 christos if (*str == '+')
473 1.1 christos {
474 1.1 christos operand->code |= 020;
475 1.1 christos str++;
476 1.1 christos }
477 1.1 christos else
478 1.1 christos {
479 1.1 christos operand->code |= 010;
480 1.1 christos }
481 1.1 christos break;
482 1.1 christos
483 1.1 christos /* Immediate. */
484 1.1 christos case '#':
485 1.1 christos case '$':
486 1.1 christos str = parse_expression (str + 1, operand);
487 1.8 christos if (operand->error)
488 1.1 christos return str;
489 1.1 christos operand->additional = true;
490 1.1 christos operand->word = operand->reloc.exp.X_add_number;
491 1.1 christos switch (operand->reloc.exp.X_op)
492 1.1 christos {
493 1.1 christos case O_constant:
494 1.1 christos break;
495 1.1 christos case O_symbol:
496 1.1 christos case O_add:
497 1.1 christos case O_subtract:
498 1.1 christos operand->reloc.type = BFD_RELOC_16;
499 1.1 christos operand->reloc.pc_rel = 0;
500 1.1 christos break;
501 1.1 christos case O_big:
502 1.1 christos if (operand->reloc.exp.X_add_number > 0)
503 1.1 christos {
504 1.1 christos operand->error = _("Error in expression");
505 1.1 christos break;
506 1.1 christos }
507 1.1 christos /* It's a floating literal... */
508 1.1 christos know (operand->reloc.exp.X_add_number < 0);
509 1.1 christos flonum_gen2vax ('f', &generic_floating_point_number, literal_float);
510 1.1 christos operand->word = literal_float[0];
511 1.1 christos if (literal_float[1] != 0)
512 1.1 christos as_warn (_("Low order bits truncated in immediate float operand"));
513 1.1 christos break;
514 1.1 christos default:
515 1.1 christos operand->error = _("Error in expression");
516 1.1 christos break;
517 1.1 christos }
518 1.1 christos operand->code = 027;
519 1.1 christos break;
520 1.1 christos
521 1.1 christos /* label, d(rn), -(rn) */
522 1.8 christos default:
523 1.1 christos {
524 1.1 christos if (startswith (str, "-(")) /* -(rn) */
525 1.1 christos {
526 1.1 christos str = parse_reg (str + 2, operand);
527 1.1 christos if (operand->error)
528 1.1 christos return str;
529 1.1 christos str = skip_whitespace (str);
530 1.1 christos if (*str != ')')
531 1.1 christos {
532 1.1 christos operand->error = _("Missing ')'");
533 1.1 christos return str;
534 1.1 christos }
535 1.1 christos operand->code |= 040;
536 1.1 christos str++;
537 1.1 christos break;
538 1.1 christos }
539 1.1 christos
540 1.1 christos str = parse_expression (str, operand);
541 1.1 christos if (operand->error)
542 1.1 christos return str;
543 1.1 christos
544 1.1 christos str = skip_whitespace (str);
545 1.1 christos
546 1.1 christos if (*str != '(')
547 1.1 christos {
548 1.1 christos operand->code = 067;
549 1.1 christos operand->additional = 1;
550 1.1 christos operand->word = 0;
551 1.1 christos operand->reloc.type = BFD_RELOC_16_PCREL;
552 1.1 christos operand->reloc.pc_rel = 1;
553 1.1 christos break;
554 1.1 christos }
555 1.1 christos
556 1.1 christos /* d(rn) */
557 1.1 christos str++;
558 1.1 christos str = parse_reg (str, operand);
559 1.1 christos if (operand->error)
560 1.1 christos return str;
561 1.1 christos
562 1.1 christos str = skip_whitespace (str);
563 1.1 christos
564 1.1 christos if (*str != ')')
565 1.1 christos {
566 1.1 christos operand->error = _("Missing ')'");
567 1.1 christos return str;
568 1.1 christos }
569 1.8 christos
570 1.1 christos str++;
571 1.1 christos operand->additional = true;
572 1.1 christos operand->code |= 060;
573 1.1 christos switch (operand->reloc.exp.X_op)
574 1.1 christos {
575 1.1 christos case O_symbol:
576 1.1 christos operand->reloc.type = BFD_RELOC_16;
577 1.1 christos operand->reloc.pc_rel = 0;
578 1.1 christos break;
579 1.1 christos case O_constant:
580 1.1 christos if ((operand->code & 7) == 7)
581 1.1 christos {
582 1.1 christos operand->reloc.pc_rel = 1;
583 1.1 christos operand->word = operand->reloc.exp.X_add_number;
584 1.1 christos }
585 1.1 christos else
586 1.1 christos operand->word = operand->reloc.exp.X_add_number;
587 1.1 christos
588 1.1 christos break;
589 1.1 christos default:
590 1.1 christos BAD_CASE (operand->reloc.exp.X_op);
591 1.1 christos }
592 1.1 christos break;
593 1.1 christos }
594 1.1 christos }
595 1.1 christos
596 1.1 christos return str;
597 1.1 christos }
598 1.1 christos
599 1.1 christos static char *
600 1.1 christos parse_op_noreg (char *str, struct pdp11_code *operand)
601 1.1 christos {
602 1.1 christos str = skip_whitespace (str);
603 1.1 christos operand->error = NULL;
604 1.1 christos
605 1.7 christos if (*str == '@' || *str == '*')
606 1.7 christos {
607 1.7 christos /* @(Rn) == @0(Rn): Mode 7, Indexed deferred.
608 1.7 christos Check for auto-increment deferred. */
609 1.7 christos if (str[1] == '('
610 1.7 christos && str[2] != 0
611 1.7 christos && str[3] != 0
612 1.7 christos && str[4] != 0
613 1.7 christos && str[5] != '+')
614 1.7 christos {
615 1.7 christos /* Change implied to explicit index deferred. */
616 1.7 christos *str = '0';
617 1.7 christos str = parse_op_no_deferred (str, operand);
618 1.7 christos }
619 1.7 christos else
620 1.7 christos {
621 1.7 christos /* @Rn == (Rn): Register deferred. */
622 1.7 christos str = parse_reg (str + 1, operand);
623 1.7 christos
624 1.7 christos /* Not @Rn */
625 1.7 christos if (operand->error)
626 1.7 christos {
627 1.7 christos operand->error = NULL;
628 1.7 christos str = parse_op_no_deferred (str, operand);
629 1.7 christos }
630 1.1 christos }
631 1.1 christos
632 1.7 christos if (operand->error)
633 1.1 christos return str;
634 1.1 christos
635 1.1 christos operand->code |= 010;
636 1.1 christos }
637 1.1 christos else
638 1.1 christos str = parse_op_no_deferred (str, operand);
639 1.1 christos
640 1.1 christos return str;
641 1.1 christos }
642 1.1 christos
643 1.1 christos static char *
644 1.1 christos parse_op (char *str, struct pdp11_code *operand)
645 1.1 christos {
646 1.1 christos str = skip_whitespace (str);
647 1.1 christos
648 1.1 christos str = parse_reg (str, operand);
649 1.1 christos if (!operand->error)
650 1.1 christos return str;
651 1.1 christos
652 1.1 christos operand->error = NULL;
653 1.1 christos parse_ac5 (str, operand);
654 1.1 christos if (!operand->error)
655 1.1 christos {
656 1.1 christos operand->error = _("Float AC not legal as integer operand");
657 1.1 christos return str;
658 1.1 christos }
659 1.1 christos
660 1.1 christos return parse_op_noreg (str, operand);
661 1.1 christos }
662 1.1 christos
663 1.1 christos static char *
664 1.1 christos parse_fop (char *str, struct pdp11_code *operand)
665 1.1 christos {
666 1.1 christos str = skip_whitespace (str);
667 1.1 christos
668 1.1 christos str = parse_ac5 (str, operand);
669 1.1 christos if (!operand->error)
670 1.1 christos return str;
671 1.1 christos
672 1.1 christos operand->error = NULL;
673 1.1 christos parse_reg (str, operand);
674 1.1 christos if (!operand->error)
675 1.1 christos {
676 1.1 christos operand->error = _("General register not legal as float operand");
677 1.1 christos return str;
678 1.1 christos }
679 1.1 christos
680 1.1 christos return parse_op_noreg (str, operand);
681 1.1 christos }
682 1.1 christos
683 1.1 christos static char *
684 1.1 christos parse_separator (char *str, int *error)
685 1.1 christos {
686 1.1 christos str = skip_whitespace (str);
687 1.1 christos *error = (*str != ',');
688 1.1 christos if (!*error)
689 1.1 christos str++;
690 1.1 christos return str;
691 1.1 christos }
692 1.1 christos
693 1.1 christos void
694 1.1 christos md_assemble (char *instruction_string)
695 1.1 christos {
696 1.1 christos const struct pdp11_opcode *op;
697 1.1 christos struct pdp11_code insn, op1, op2;
698 1.5 christos int error;
699 1.1 christos int size;
700 1.1 christos const char *err = NULL;
701 1.1 christos char *str;
702 1.1 christos char *p;
703 1.1 christos char c;
704 1.1 christos
705 1.1 christos str = skip_whitespace (instruction_string);
706 1.1 christos p = find_whitespace (str);
707 1.1 christos if (p - str == 0)
708 1.1 christos {
709 1.1 christos as_bad (_("No instruction found"));
710 1.1 christos return;
711 1.1 christos }
712 1.1 christos
713 1.8 christos c = *p;
714 1.1 christos *p = '\0';
715 1.1 christos op = (struct pdp11_opcode *)str_hash_find (insn_hash, str);
716 1.1 christos *p = c;
717 1.1 christos if (op == 0)
718 1.1 christos {
719 1.1 christos as_bad (_("Unknown instruction '%s'"), str);
720 1.1 christos return;
721 1.1 christos }
722 1.1 christos
723 1.1 christos if (!pdp11_extension[op->extension])
724 1.1 christos {
725 1.1 christos as_warn (_("Unsupported instruction set extension: %s"), op->name);
726 1.1 christos return;
727 1.1 christos }
728 1.1 christos
729 1.1 christos insn.error = NULL;
730 1.1 christos insn.code = op->opcode;
731 1.8 christos insn.reloc.type = BFD_RELOC_NONE;
732 1.1 christos op1.error = NULL;
733 1.1 christos op1.additional = false;
734 1.8 christos op1.reloc.type = BFD_RELOC_NONE;
735 1.1 christos op2.error = NULL;
736 1.1 christos op2.additional = false;
737 1.1 christos op2.reloc.type = BFD_RELOC_NONE;
738 1.1 christos
739 1.1 christos str = p;
740 1.1 christos size = 2;
741 1.1 christos
742 1.1 christos switch (op->type)
743 1.1 christos {
744 1.1 christos case PDP11_OPCODE_NO_OPS:
745 1.1 christos str = skip_whitespace (str);
746 1.1 christos break;
747 1.1 christos
748 1.1 christos case PDP11_OPCODE_IMM3:
749 1.1 christos case PDP11_OPCODE_IMM6:
750 1.1 christos case PDP11_OPCODE_IMM8:
751 1.1 christos str = skip_whitespace (str);
752 1.1 christos if (*str == '#' || *str == '$')
753 1.1 christos str++;
754 1.1 christos str = parse_expression (str, &op1);
755 1.1 christos if (op1.error)
756 1.1 christos break;
757 1.1 christos if (op1.reloc.exp.X_op != O_constant || op1.reloc.type != BFD_RELOC_NONE)
758 1.1 christos {
759 1.1 christos op1.error = _("operand is not an absolute constant");
760 1.1 christos break;
761 1.1 christos }
762 1.1 christos switch (op->type)
763 1.1 christos {
764 1.1 christos case PDP11_OPCODE_IMM3:
765 1.1 christos if (op1.reloc.exp.X_add_number & ~7)
766 1.1 christos {
767 1.1 christos op1.error = _("3-bit immediate out of range");
768 1.1 christos break;
769 1.1 christos }
770 1.1 christos break;
771 1.1 christos case PDP11_OPCODE_IMM6:
772 1.1 christos if (op1.reloc.exp.X_add_number & ~0x3f)
773 1.1 christos {
774 1.1 christos op1.error = _("6-bit immediate out of range");
775 1.1 christos break;
776 1.1 christos }
777 1.1 christos break;
778 1.1 christos case PDP11_OPCODE_IMM8:
779 1.1 christos if (op1.reloc.exp.X_add_number & ~0xff)
780 1.1 christos {
781 1.1 christos op1.error = _("8-bit immediate out of range");
782 1.1 christos break;
783 1.1 christos }
784 1.1 christos break;
785 1.1 christos }
786 1.1 christos insn.code |= op1.reloc.exp.X_add_number;
787 1.1 christos break;
788 1.1 christos
789 1.1 christos case PDP11_OPCODE_DISPL:
790 1.1 christos {
791 1.1 christos char *new_pointer;
792 1.1 christos new_pointer = parse_expression (str, &op1);
793 1.1 christos op1.code = 0;
794 1.1 christos op1.reloc.pc_rel = 1;
795 1.1 christos op1.reloc.type = BFD_RELOC_PDP11_DISP_8_PCREL;
796 1.1 christos if (op1.reloc.exp.X_op != O_symbol)
797 1.1 christos {
798 1.1 christos op1.error = _("Symbol expected");
799 1.1 christos break;
800 1.1 christos }
801 1.1 christos if (op1.code & ~0xff)
802 1.1 christos {
803 1.1 christos err = _("8-bit displacement out of range");
804 1.1 christos break;
805 1.1 christos }
806 1.1 christos str = new_pointer;
807 1.1 christos insn.code |= op1.code;
808 1.1 christos insn.reloc = op1.reloc;
809 1.1 christos }
810 1.1 christos break;
811 1.1 christos
812 1.1 christos case PDP11_OPCODE_REG:
813 1.1 christos str = parse_reg (str, &op1);
814 1.1 christos if (op1.error)
815 1.1 christos break;
816 1.1 christos insn.code |= op1.code;
817 1.1 christos break;
818 1.1 christos
819 1.1 christos case PDP11_OPCODE_OP:
820 1.1 christos str = parse_op (str, &op1);
821 1.1 christos if (op1.error)
822 1.1 christos break;
823 1.1 christos insn.code |= op1.code;
824 1.1 christos if (op1.additional)
825 1.1 christos size += 2;
826 1.1 christos break;
827 1.1 christos
828 1.1 christos case PDP11_OPCODE_FOP:
829 1.1 christos str = parse_fop (str, &op1);
830 1.1 christos if (op1.error)
831 1.1 christos break;
832 1.1 christos insn.code |= op1.code;
833 1.1 christos if (op1.additional)
834 1.1 christos size += 2;
835 1.1 christos break;
836 1.1 christos
837 1.1 christos case PDP11_OPCODE_REG_OP:
838 1.1 christos str = parse_reg (str, &op2);
839 1.1 christos if (op2.error)
840 1.1 christos break;
841 1.1 christos insn.code |= op2.code << 6;
842 1.1 christos str = parse_separator (str, &error);
843 1.1 christos if (error)
844 1.1 christos {
845 1.1 christos op2.error = _("Missing ','");
846 1.1 christos break;
847 1.1 christos }
848 1.1 christos str = parse_op (str, &op1);
849 1.1 christos if (op1.error)
850 1.1 christos break;
851 1.1 christos insn.code |= op1.code;
852 1.1 christos if (op1.additional)
853 1.1 christos size += 2;
854 1.1 christos break;
855 1.1 christos
856 1.1 christos case PDP11_OPCODE_REG_OP_REV:
857 1.1 christos str = parse_op (str, &op1);
858 1.1 christos if (op1.error)
859 1.1 christos break;
860 1.1 christos insn.code |= op1.code;
861 1.1 christos if (op1.additional)
862 1.1 christos size += 2;
863 1.1 christos str = parse_separator (str, &error);
864 1.1 christos if (error)
865 1.1 christos {
866 1.1 christos op2.error = _("Missing ','");
867 1.1 christos break;
868 1.1 christos }
869 1.1 christos str = parse_reg (str, &op2);
870 1.1 christos if (op2.error)
871 1.1 christos break;
872 1.1 christos insn.code |= op2.code << 6;
873 1.1 christos break;
874 1.1 christos
875 1.1 christos case PDP11_OPCODE_AC_FOP:
876 1.1 christos str = parse_ac (str, &op2);
877 1.1 christos if (op2.error)
878 1.1 christos break;
879 1.1 christos insn.code |= op2.code << 6;
880 1.1 christos str = parse_separator (str, &error);
881 1.1 christos if (error)
882 1.1 christos {
883 1.1 christos op1.error = _("Missing ','");
884 1.1 christos break;
885 1.1 christos }
886 1.1 christos str = parse_fop (str, &op1);
887 1.1 christos if (op1.error)
888 1.1 christos break;
889 1.1 christos insn.code |= op1.code;
890 1.1 christos if (op1.additional)
891 1.1 christos size += 2;
892 1.1 christos break;
893 1.1 christos
894 1.1 christos case PDP11_OPCODE_FOP_AC:
895 1.1 christos str = parse_fop (str, &op1);
896 1.1 christos if (op1.error)
897 1.1 christos break;
898 1.1 christos insn.code |= op1.code;
899 1.1 christos if (op1.additional)
900 1.1 christos size += 2;
901 1.1 christos str = parse_separator (str, &error);
902 1.1 christos if (error)
903 1.1 christos {
904 1.1 christos op1.error = _("Missing ','");
905 1.1 christos break;
906 1.1 christos }
907 1.1 christos str = parse_ac (str, &op2);
908 1.1 christos if (op2.error)
909 1.1 christos break;
910 1.1 christos insn.code |= op2.code << 6;
911 1.1 christos break;
912 1.1 christos
913 1.1 christos case PDP11_OPCODE_AC_OP:
914 1.1 christos str = parse_ac (str, &op2);
915 1.1 christos if (op2.error)
916 1.1 christos break;
917 1.1 christos insn.code |= op2.code << 6;
918 1.1 christos str = parse_separator (str, &error);
919 1.1 christos if (error)
920 1.1 christos {
921 1.1 christos op1.error = _("Missing ','");
922 1.1 christos break;
923 1.1 christos }
924 1.1 christos str = parse_op (str, &op1);
925 1.1 christos if (op1.error)
926 1.1 christos break;
927 1.1 christos insn.code |= op1.code;
928 1.1 christos if (op1.additional)
929 1.1 christos size += 2;
930 1.1 christos break;
931 1.1 christos
932 1.1 christos case PDP11_OPCODE_OP_AC:
933 1.1 christos str = parse_op (str, &op1);
934 1.1 christos if (op1.error)
935 1.1 christos break;
936 1.1 christos insn.code |= op1.code;
937 1.1 christos if (op1.additional)
938 1.1 christos size += 2;
939 1.1 christos str = parse_separator (str, &error);
940 1.1 christos if (error)
941 1.1 christos {
942 1.1 christos op1.error = _("Missing ','");
943 1.1 christos break;
944 1.1 christos }
945 1.1 christos str = parse_ac (str, &op2);
946 1.1 christos if (op2.error)
947 1.1 christos break;
948 1.1 christos insn.code |= op2.code << 6;
949 1.1 christos break;
950 1.1 christos
951 1.1 christos case PDP11_OPCODE_OP_OP:
952 1.1 christos str = parse_op (str, &op1);
953 1.1 christos if (op1.error)
954 1.1 christos break;
955 1.1 christos insn.code |= op1.code << 6;
956 1.1 christos if (op1.additional)
957 1.1 christos size += 2;
958 1.1 christos str = parse_separator (str, &error);
959 1.1 christos if (error)
960 1.1 christos {
961 1.1 christos op2.error = _("Missing ','");
962 1.1 christos break;
963 1.1 christos }
964 1.1 christos str = parse_op (str, &op2);
965 1.1 christos if (op2.error)
966 1.1 christos break;
967 1.1 christos insn.code |= op2.code;
968 1.1 christos if (op2.additional)
969 1.1 christos size += 2;
970 1.1 christos break;
971 1.1 christos
972 1.1 christos case PDP11_OPCODE_REG_DISPL:
973 1.1 christos {
974 1.1 christos char *new_pointer;
975 1.1 christos str = parse_reg (str, &op2);
976 1.1 christos if (op2.error)
977 1.1 christos break;
978 1.1 christos insn.code |= op2.code << 6;
979 1.1 christos str = parse_separator (str, &error);
980 1.1 christos if (error)
981 1.1 christos {
982 1.1 christos op1.error = _("Missing ','");
983 1.1 christos break;
984 1.1 christos }
985 1.1 christos new_pointer = parse_expression (str, &op1);
986 1.1 christos op1.code = 0;
987 1.1 christos op1.reloc.pc_rel = 1;
988 1.1 christos op1.reloc.type = BFD_RELOC_PDP11_DISP_6_PCREL;
989 1.1 christos if (op1.reloc.exp.X_op != O_symbol)
990 1.1 christos {
991 1.1 christos op1.error = _("Symbol expected");
992 1.1 christos break;
993 1.1 christos }
994 1.1 christos if (op1.code & ~0x3f)
995 1.1 christos {
996 1.1 christos err = _("6-bit displacement out of range");
997 1.1 christos break;
998 1.1 christos }
999 1.1 christos str = new_pointer;
1000 1.1 christos insn.code |= op1.code;
1001 1.1 christos insn.reloc = op1.reloc;
1002 1.1 christos }
1003 1.1 christos break;
1004 1.1 christos
1005 1.1 christos default:
1006 1.1 christos BAD_CASE (op->type);
1007 1.1 christos }
1008 1.1 christos
1009 1.1 christos if (op1.error)
1010 1.1 christos err = op1.error;
1011 1.1 christos else if (op2.error)
1012 1.1 christos err = op2.error;
1013 1.1 christos else
1014 1.1 christos {
1015 1.1 christos str = skip_whitespace (str);
1016 1.1 christos if (*str)
1017 1.1 christos err = _("Too many operands");
1018 1.1 christos }
1019 1.1 christos
1020 1.1 christos {
1021 1.1 christos char *to = NULL;
1022 1.1 christos
1023 1.1 christos if (err)
1024 1.1 christos {
1025 1.1 christos as_bad ("%s", err);
1026 1.1 christos return;
1027 1.1 christos }
1028 1.1 christos
1029 1.1 christos to = frag_more (size);
1030 1.1 christos
1031 1.1 christos md_number_to_chars (to, insn.code, 2);
1032 1.1 christos if (insn.reloc.type != BFD_RELOC_NONE)
1033 1.1 christos fix_new_exp (frag_now, to - frag_now->fr_literal, 2,
1034 1.1 christos &insn.reloc.exp, insn.reloc.pc_rel, insn.reloc.type);
1035 1.1 christos to += 2;
1036 1.1 christos
1037 1.1 christos if (op1.additional)
1038 1.1 christos {
1039 1.1 christos md_number_to_chars (to, op1.word, 2);
1040 1.1 christos if (op1.reloc.type != BFD_RELOC_NONE)
1041 1.1 christos fix_new_exp (frag_now, to - frag_now->fr_literal, 2,
1042 1.1 christos &op1.reloc.exp, op1.reloc.pc_rel, op1.reloc.type);
1043 1.1 christos to += 2;
1044 1.1 christos }
1045 1.1 christos
1046 1.1 christos if (op2.additional)
1047 1.1 christos {
1048 1.1 christos md_number_to_chars (to, op2.word, 2);
1049 1.1 christos if (op2.reloc.type != BFD_RELOC_NONE)
1050 1.1 christos fix_new_exp (frag_now, to - frag_now->fr_literal, 2,
1051 1.1 christos &op2.reloc.exp, op2.reloc.pc_rel, op2.reloc.type);
1052 1.1 christos }
1053 1.1 christos }
1054 1.1 christos }
1055 1.1 christos
1056 1.1 christos int
1057 1.1 christos md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED,
1058 1.1 christos segT segment ATTRIBUTE_UNUSED)
1059 1.1 christos {
1060 1.1 christos return 0;
1061 1.1 christos }
1062 1.1 christos
1063 1.1 christos void
1064 1.1 christos md_convert_frag (bfd *headers ATTRIBUTE_UNUSED,
1065 1.1 christos segT seg ATTRIBUTE_UNUSED,
1066 1.1 christos fragS *fragP ATTRIBUTE_UNUSED)
1067 1.1 christos {
1068 1.1 christos }
1069 1.1 christos
1070 1.1 christos int md_short_jump_size = 2;
1071 1.1 christos int md_long_jump_size = 4;
1072 1.1 christos
1073 1.1 christos void
1074 1.1 christos md_create_short_jump (char *ptr ATTRIBUTE_UNUSED,
1075 1.1 christos addressT from_addr ATTRIBUTE_UNUSED,
1076 1.1 christos addressT to_addr ATTRIBUTE_UNUSED,
1077 1.1 christos fragS *frag ATTRIBUTE_UNUSED,
1078 1.1 christos symbolS *to_symbol ATTRIBUTE_UNUSED)
1079 1.1 christos {
1080 1.1 christos }
1081 1.1 christos
1082 1.1 christos void
1083 1.1 christos md_create_long_jump (char *ptr ATTRIBUTE_UNUSED,
1084 1.1 christos addressT from_addr ATTRIBUTE_UNUSED,
1085 1.1 christos addressT to_addr ATTRIBUTE_UNUSED,
1086 1.1 christos fragS *frag ATTRIBUTE_UNUSED,
1087 1.1 christos symbolS *to_symbol ATTRIBUTE_UNUSED)
1088 1.1 christos {
1089 1.1 christos }
1090 1.5 christos
1091 1.1 christos static int
1092 1.1 christos set_cpu_model (const char *arg)
1093 1.1 christos {
1094 1.1 christos char buf[4];
1095 1.1 christos char *model = buf;
1096 1.1 christos
1097 1.1 christos if (arg[0] == 'k')
1098 1.1 christos arg++;
1099 1.1 christos
1100 1.1 christos *model++ = *arg++;
1101 1.1 christos
1102 1.1 christos if (strchr ("abdx", model[-1]) == NULL)
1103 1.1 christos return 0;
1104 1.1 christos
1105 1.1 christos if (model[-1] == 'd')
1106 1.1 christos {
1107 1.1 christos if (arg[0] == 'f' || arg[0] == 'j')
1108 1.1 christos model[-1] = *arg++;
1109 1.1 christos }
1110 1.1 christos else if (model[-1] == 'x')
1111 1.1 christos {
1112 1.1 christos if (arg[0] == 't')
1113 1.1 christos model[-1] = *arg++;
1114 1.1 christos }
1115 1.1 christos
1116 1.1 christos if (arg[0] == '-')
1117 1.8 christos arg++;
1118 1.1 christos
1119 1.1 christos if (!startswith (arg, "11"))
1120 1.1 christos return 0;
1121 1.1 christos arg += 2;
1122 1.1 christos
1123 1.1 christos if (arg[0] == '-')
1124 1.1 christos {
1125 1.1 christos if (*++arg == 0)
1126 1.1 christos return 0;
1127 1.1 christos }
1128 1.1 christos
1129 1.1 christos /* Allow up to two revision letters. */
1130 1.1 christos if (arg[0] != 0)
1131 1.1 christos *model++ = *arg++;
1132 1.1 christos if (arg[0] != 0)
1133 1.1 christos *model++ = *arg++;
1134 1.1 christos
1135 1.1 christos *model++ = 0;
1136 1.1 christos
1137 1.1 christos set_option ("no-extensions");
1138 1.8 christos
1139 1.1 christos /* KA11 (11/15/20). */
1140 1.1 christos if (startswith (buf, "a"))
1141 1.1 christos return 1; /* No extensions. */
1142 1.8 christos
1143 1.1 christos /* KB11 (11/45/50/55/70). */
1144 1.1 christos else if (startswith (buf, "b"))
1145 1.1 christos return set_option ("eis") && set_option ("spl");
1146 1.8 christos
1147 1.1 christos /* KD11-A (11/35/40). */
1148 1.1 christos else if (startswith (buf, "da"))
1149 1.1 christos return set_option ("limited-eis");
1150 1.8 christos
1151 1.1 christos /* KD11-B (11/05/10). */
1152 1.8 christos else if (startswith (buf, "db")
1153 1.1 christos /* KD11-D (11/04). */
1154 1.1 christos || startswith (buf, "dd"))
1155 1.1 christos return 1; /* no extensions */
1156 1.8 christos
1157 1.1 christos /* KD11-E (11/34). */
1158 1.1 christos else if (startswith (buf, "de"))
1159 1.1 christos return set_option ("eis") && set_option ("mxps");
1160 1.8 christos
1161 1.1 christos /* KD11-F (11/03). */
1162 1.8 christos else if (startswith (buf, "df")
1163 1.1 christos /* KD11-H (11/03). */
1164 1.8 christos || startswith (buf, "dh")
1165 1.1 christos /* KD11-Q (11/03). */
1166 1.1 christos || startswith (buf, "dq"))
1167 1.1 christos return set_option ("limited-eis") && set_option ("mxps");
1168 1.8 christos
1169 1.1 christos /* KD11-K (11/60). */
1170 1.1 christos else if (startswith (buf, "dk"))
1171 1.1 christos return set_option ("eis")
1172 1.1 christos && set_option ("mxps")
1173 1.1 christos && set_option ("ucode");
1174 1.8 christos
1175 1.1 christos /* KD11-Z (11/44). */
1176 1.1 christos else if (startswith (buf, "dz"))
1177 1.1 christos return set_option ("csm")
1178 1.1 christos && set_option ("eis")
1179 1.1 christos && set_option ("mfpt")
1180 1.1 christos && set_option ("mxps")
1181 1.1 christos && set_option ("spl");
1182 1.8 christos
1183 1.1 christos /* F11 (11/23/24). */
1184 1.1 christos else if (startswith (buf, "f"))
1185 1.1 christos return set_option ("eis")
1186 1.1 christos && set_option ("mfpt")
1187 1.1 christos && set_option ("mxps");
1188 1.8 christos
1189 1.1 christos /* J11 (11/53/73/83/84/93/94). */
1190 1.1 christos else if (startswith (buf, "j"))
1191 1.1 christos return set_option ("csm")
1192 1.1 christos && set_option ("eis")
1193 1.1 christos && set_option ("mfpt")
1194 1.1 christos && set_option ("multiproc")
1195 1.1 christos && set_option ("mxps")
1196 1.1 christos && set_option ("spl");
1197 1.8 christos
1198 1.1 christos /* T11 (11/21). */
1199 1.1 christos else if (startswith (buf, "t"))
1200 1.1 christos return set_option ("limited-eis")
1201 1.1 christos && set_option ("mxps");
1202 1.1 christos
1203 1.1 christos else
1204 1.1 christos return 0;
1205 1.1 christos }
1206 1.5 christos
1207 1.1 christos static int
1208 1.8 christos set_machine_model (const char *arg)
1209 1.8 christos {
1210 1.8 christos if (!startswith (arg, "pdp-11/")
1211 1.1 christos && !startswith (arg, "pdp11/")
1212 1.1 christos && !startswith (arg, "11/"))
1213 1.8 christos return 0;
1214 1.1 christos
1215 1.1 christos if (startswith (arg, "pdp"))
1216 1.1 christos arg += 3;
1217 1.8 christos if (arg[0] == '-')
1218 1.1 christos arg++;
1219 1.1 christos if (startswith (arg, "11/"))
1220 1.1 christos arg += 3;
1221 1.1 christos
1222 1.1 christos if (strcmp (arg, "03") == 0)
1223 1.1 christos return set_cpu_model ("kd11f");
1224 1.1 christos
1225 1.1 christos else if (strcmp (arg, "04") == 0)
1226 1.1 christos return set_cpu_model ("kd11d");
1227 1.1 christos
1228 1.1 christos else if (strcmp (arg, "05") == 0
1229 1.1 christos || strcmp (arg, "10") == 0)
1230 1.1 christos return set_cpu_model ("kd11b");
1231 1.1 christos
1232 1.1 christos else if (strcmp (arg, "15") == 0
1233 1.1 christos || strcmp (arg, "20") == 0)
1234 1.1 christos return set_cpu_model ("ka11");
1235 1.1 christos
1236 1.1 christos else if (strcmp (arg, "21") == 0)
1237 1.1 christos return set_cpu_model ("t11");
1238 1.1 christos
1239 1.1 christos else if (strcmp (arg, "23") == 0
1240 1.1 christos || strcmp (arg, "24") == 0)
1241 1.1 christos return set_cpu_model ("f11");
1242 1.1 christos
1243 1.1 christos else if (strcmp (arg, "34") == 0
1244 1.1 christos || strcmp (arg, "34a") == 0)
1245 1.1 christos return set_cpu_model ("kd11e");
1246 1.1 christos
1247 1.1 christos else if (strcmp (arg, "35") == 0
1248 1.1 christos || strcmp (arg, "40") == 0)
1249 1.1 christos return set_cpu_model ("kd11da");
1250 1.1 christos
1251 1.1 christos else if (strcmp (arg, "44") == 0)
1252 1.1 christos return set_cpu_model ("kd11dz");
1253 1.1 christos
1254 1.1 christos else if (strcmp (arg, "45") == 0
1255 1.1 christos || strcmp (arg, "50") == 0
1256 1.1 christos || strcmp (arg, "55") == 0
1257 1.1 christos || strcmp (arg, "70") == 0)
1258 1.1 christos return set_cpu_model ("kb11");
1259 1.1 christos
1260 1.1 christos else if (strcmp (arg, "60") == 0)
1261 1.1 christos return set_cpu_model ("kd11k");
1262 1.1 christos
1263 1.1 christos else if (strcmp (arg, "53") == 0
1264 1.1 christos || strcmp (arg, "73") == 0
1265 1.1 christos || strcmp (arg, "83") == 0
1266 1.1 christos || strcmp (arg, "84") == 0
1267 1.1 christos || strcmp (arg, "93") == 0
1268 1.1 christos || strcmp (arg, "94") == 0)
1269 1.1 christos return set_cpu_model ("j11")
1270 1.1 christos && set_option ("fpp");
1271 1.1 christos
1272 1.1 christos else
1273 1.1 christos return 0;
1274 1.1 christos }
1275 1.1 christos
1276 1.1 christos const char *md_shortopts = "m:";
1277 1.1 christos
1278 1.1 christos struct option md_longopts[] =
1279 1.1 christos {
1280 1.1 christos #define OPTION_CPU 257
1281 1.1 christos { "cpu", required_argument, NULL, OPTION_CPU },
1282 1.1 christos #define OPTION_MACHINE 258
1283 1.1 christos { "machine", required_argument, NULL, OPTION_MACHINE },
1284 1.1 christos #define OPTION_PIC 259
1285 1.1 christos { "pic", no_argument, NULL, OPTION_PIC },
1286 1.1 christos { NULL, no_argument, NULL, 0 }
1287 1.1 christos };
1288 1.1 christos
1289 1.1 christos size_t md_longopts_size = sizeof (md_longopts);
1290 1.1 christos
1291 1.1 christos /* Invocation line includes a switch not recognized by the base assembler.
1292 1.1 christos See if it's a processor-specific option. */
1293 1.5 christos
1294 1.1 christos int
1295 1.1 christos md_parse_option (int c, const char *arg)
1296 1.1 christos {
1297 1.1 christos init_defaults ();
1298 1.1 christos
1299 1.1 christos switch (c)
1300 1.1 christos {
1301 1.1 christos case 'm':
1302 1.1 christos if (set_option (arg))
1303 1.1 christos return 1;
1304 1.1 christos if (set_cpu_model (arg))
1305 1.1 christos return 1;
1306 1.1 christos if (set_machine_model (arg))
1307 1.1 christos return 1;
1308 1.1 christos break;
1309 1.1 christos
1310 1.1 christos case OPTION_CPU:
1311 1.1 christos if (set_cpu_model (arg))
1312 1.1 christos return 1;
1313 1.1 christos break;
1314 1.1 christos
1315 1.1 christos case OPTION_MACHINE:
1316 1.1 christos if (set_machine_model (arg))
1317 1.1 christos return 1;
1318 1.1 christos break;
1319 1.1 christos
1320 1.1 christos case OPTION_PIC:
1321 1.1 christos if (set_option ("pic"))
1322 1.1 christos return 1;
1323 1.1 christos break;
1324 1.1 christos
1325 1.1 christos default:
1326 1.1 christos break;
1327 1.1 christos }
1328 1.1 christos
1329 1.1 christos return 0;
1330 1.1 christos }
1331 1.1 christos
1332 1.1 christos void
1333 1.1 christos md_show_usage (FILE *stream)
1334 1.1 christos {
1335 1.6 christos fprintf (stream, "\
1336 1.1 christos \n\
1337 1.6 christos PDP-11 instruction set extensions:\n\
1338 1.1 christos \n\
1339 1.1 christos -m(no-)cis allow (disallow) commercial instruction set\n\
1340 1.1 christos -m(no-)csm allow (disallow) CSM instruction\n\
1341 1.1 christos -m(no-)eis allow (disallow) full extended instruction set\n\
1342 1.1 christos -m(no-)fis allow (disallow) KEV11 floating-point instructions\n\
1343 1.1 christos -m(no-)fpp allow (disallow) FP-11 floating-point instructions\n\
1344 1.1 christos -m(no-)fpu allow (disallow) FP-11 floating-point instructions\n\
1345 1.1 christos -m(no-)limited-eis allow (disallow) limited extended instruction set\n\
1346 1.1 christos -m(no-)mfpt allow (disallow) processor type instruction\n\
1347 1.1 christos -m(no-)multiproc allow (disallow) multiprocessor instructions\n\
1348 1.1 christos -m(no-)mxps allow (disallow) processor status instructions\n\
1349 1.1 christos -m(no-)spl allow (disallow) SPL instruction\n\
1350 1.1 christos -m(no-)ucode allow (disallow) microcode instructions\n\
1351 1.6 christos -mall-extensions allow all instruction set extensions\n\
1352 1.6 christos (this is the default)\n\
1353 1.1 christos -mno-extensions disallow all instruction set extensions\n\
1354 1.1 christos -pic generate position-independent code\n\
1355 1.1 christos \n\
1356 1.1 christos PDP-11 CPU model options:\n\
1357 1.1 christos \n\
1358 1.1 christos -mka11* KA11 CPU. base line instruction set only\n\
1359 1.1 christos -mkb11* KB11 CPU. enable full EIS and SPL\n\
1360 1.1 christos -mkd11a* KD11-A CPU. enable limited EIS\n\
1361 1.1 christos -mkd11b* KD11-B CPU. base line instruction set only\n\
1362 1.1 christos -mkd11d* KD11-D CPU. base line instruction set only\n\
1363 1.1 christos -mkd11e* KD11-E CPU. enable full EIS, MTPS, and MFPS\n\
1364 1.1 christos -mkd11f* KD11-F CPU. enable limited EIS, MTPS, and MFPS\n\
1365 1.1 christos -mkd11h* KD11-H CPU. enable limited EIS, MTPS, and MFPS\n\
1366 1.1 christos -mkd11q* KD11-Q CPU. enable limited EIS, MTPS, and MFPS\n\
1367 1.1 christos -mkd11k* KD11-K CPU. enable full EIS, MTPS, MFPS, LDUB, MED,\n\
1368 1.1 christos XFC, and MFPT\n\
1369 1.1 christos -mkd11z* KD11-Z CPU. enable full EIS, MTPS, MFPS, MFPT, SPL,\n\
1370 1.1 christos and CSM\n\
1371 1.1 christos -mf11* F11 CPU. enable full EIS, MFPS, MTPS, and MFPT\n\
1372 1.1 christos -mj11* J11 CPU. enable full EIS, MTPS, MFPS, MFPT, SPL,\n\
1373 1.1 christos CSM, TSTSET, and WRTLCK\n\
1374 1.1 christos -mt11* T11 CPU. enable limited EIS, MTPS, and MFPS\n\
1375 1.1 christos \n\
1376 1.1 christos PDP-11 machine model options:\n\
1377 1.1 christos \n\
1378 1.1 christos -m11/03 same as -mkd11f\n\
1379 1.1 christos -m11/04 same as -mkd11d\n\
1380 1.1 christos -m11/05 same as -mkd11b\n\
1381 1.1 christos -m11/10 same as -mkd11b\n\
1382 1.1 christos -m11/15 same as -mka11\n\
1383 1.1 christos -m11/20 same as -mka11\n\
1384 1.1 christos -m11/21 same as -mt11\n\
1385 1.1 christos -m11/23 same as -mf11\n\
1386 1.1 christos -m11/24 same as -mf11\n\
1387 1.1 christos -m11/34 same as -mkd11e\n\
1388 1.1 christos -m11/34a same as -mkd11e -mfpp\n\
1389 1.1 christos -m11/35 same as -mkd11a\n\
1390 1.1 christos -m11/40 same as -mkd11a\n\
1391 1.1 christos -m11/44 same as -mkd11z\n\
1392 1.1 christos -m11/45 same as -mkb11\n\
1393 1.1 christos -m11/50 same as -mkb11\n\
1394 1.1 christos -m11/53 same as -mj11\n\
1395 1.1 christos -m11/55 same as -mkb11\n\
1396 1.1 christos -m11/60 same as -mkd11k\n\
1397 1.1 christos -m11/70 same as -mkb11\n\
1398 1.1 christos -m11/73 same as -mj11\n\
1399 1.1 christos -m11/83 same as -mj11\n\
1400 1.1 christos -m11/84 same as -mj11\n\
1401 1.1 christos -m11/93 same as -mj11\n\
1402 1.1 christos -m11/94 same as -mj11\n\
1403 1.1 christos ");
1404 1.1 christos }
1405 1.1 christos
1406 1.1 christos symbolS *
1407 1.1 christos md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1408 1.1 christos {
1409 1.1 christos return 0;
1410 1.1 christos }
1411 1.1 christos
1412 1.1 christos valueT
1413 1.1 christos md_section_align (segT segment ATTRIBUTE_UNUSED,
1414 1.1 christos valueT size)
1415 1.1 christos {
1416 1.1 christos return (size + 1) & ~1;
1417 1.1 christos }
1418 1.1 christos
1419 1.1 christos long
1420 1.1 christos md_pcrel_from (fixS *fixP)
1421 1.1 christos {
1422 1.1 christos return fixP->fx_frag->fr_address + fixP->fx_where + fixP->fx_size;
1423 1.1 christos }
1424 1.1 christos
1425 1.1 christos /* Translate internal representation of relocation info to BFD target
1426 1.1 christos format. */
1427 1.1 christos
1428 1.1 christos arelent *
1429 1.1 christos tc_gen_reloc (asection *section ATTRIBUTE_UNUSED,
1430 1.1 christos fixS *fixp)
1431 1.1 christos {
1432 1.1 christos arelent *reloc;
1433 1.5 christos bfd_reloc_code_real_type code;
1434 1.1 christos
1435 1.5 christos reloc = XNEW (arelent);
1436 1.1 christos
1437 1.1 christos reloc->sym_ptr_ptr = XNEW (asymbol *);
1438 1.1 christos *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1439 1.1 christos reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1440 1.1 christos
1441 1.1 christos /* This is taken account for in md_apply_fix(). */
1442 1.8 christos reloc->addend = -symbol_get_bfdsym (fixp->fx_addsy)->section->vma;
1443 1.8 christos
1444 1.1 christos code = fixp->fx_r_type;
1445 1.8 christos if (fixp->fx_pcrel)
1446 1.8 christos {
1447 1.8 christos switch (code)
1448 1.8 christos {
1449 1.8 christos case BFD_RELOC_16:
1450 1.1 christos code = BFD_RELOC_16_PCREL;
1451 1.8 christos break;
1452 1.8 christos
1453 1.1 christos case BFD_RELOC_16_PCREL:
1454 1.8 christos break;
1455 1.8 christos
1456 1.8 christos default:
1457 1.8 christos BAD_CASE (code);
1458 1.1 christos return NULL;
1459 1.1 christos }
1460 1.1 christos }
1461 1.1 christos
1462 1.1 christos reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
1463 1.1 christos
1464 1.1 christos if (reloc->howto == NULL)
1465 1.1 christos {
1466 1.1 christos as_bad_where (fixp->fx_file, fixp->fx_line,
1467 1.1 christos _("Can not represent %s relocation in this object file format"),
1468 1.1 christos bfd_get_reloc_code_name (code));
1469 1.1 christos return NULL;
1470 1.1 christos }
1471 1.1 christos
1472 1.1 christos return reloc;
1473 1.1 christos }
1474 1.1 christos
1475 1.1 christos void
1476 1.1 christos pseudo_bss (int c ATTRIBUTE_UNUSED)
1477 1.1 christos {
1478 1.1 christos int temp;
1479 1.1 christos
1480 1.1 christos temp = get_absolute_expression ();
1481 1.1 christos subseg_set (bss_section, temp);
1482 1.1 christos demand_empty_rest_of_line ();
1483 1.1 christos }
1484 1.1 christos
1485 1.1 christos void
1486 1.1 christos pseudo_even (int c ATTRIBUTE_UNUSED)
1487 1.1 christos {
1488 1.1 christos int alignment = 1; /* 2^1 */
1489 1.1 christos frag_align (alignment, 0, 1);
1490 1.1 christos record_alignment (now_seg, alignment);
1491 1.5 christos }
1492 1.1 christos
1493 1.1 christos const char *
1494 1.1 christos md_atof (int type, char * litP, int * sizeP)
1495 1.1 christos {
1496 return vax_md_atof (type, litP, sizeP);
1497 }
1498