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