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