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