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