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