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