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