Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* tc-z8k.c -- Assemble code for the Zilog Z800n |
3c25c5f6 | 2 | Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2002 |
f7e42eb4 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GAS; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
e0c6ed95 AM |
22 | /* Written By Steve Chamberlain <sac@cygnus.com>. */ |
23 | ||
252b5132 RH |
24 | #define DEFINE_TABLE |
25 | #include <stdio.h> | |
26 | ||
252b5132 RH |
27 | #include "as.h" |
28 | #include "bfd.h" | |
3882b010 | 29 | #include "safe-ctype.h" |
a5d2034a | 30 | #include "opcodes/z8k-opc.h" |
252b5132 | 31 | |
63a0b638 AM |
32 | const char comment_chars[] = "!"; |
33 | const char line_comment_chars[] = "#"; | |
34 | const char line_separator_chars[] = ";"; | |
252b5132 RH |
35 | |
36 | extern int machine; | |
37 | extern int coff_flags; | |
38 | int segmented_mode; | |
39 | const int md_reloc_size; | |
40 | ||
252b5132 RH |
41 | void cons (); |
42 | ||
43 | void | |
44 | s_segm () | |
45 | { | |
46 | segmented_mode = 1; | |
47 | machine = bfd_mach_z8001; | |
48 | coff_flags = F_Z8001; | |
49 | } | |
50 | ||
51 | void | |
52 | s_unseg () | |
53 | { | |
54 | segmented_mode = 0; | |
55 | machine = bfd_mach_z8002; | |
56 | coff_flags = F_Z8002; | |
57 | } | |
58 | ||
e0c6ed95 | 59 | static void |
252b5132 RH |
60 | even () |
61 | { | |
62 | frag_align (1, 0, 0); | |
63 | record_alignment (now_seg, 1); | |
64 | } | |
65 | ||
66 | void obj_coff_section (); | |
67 | ||
68 | int | |
69 | tohex (c) | |
70 | int c; | |
71 | { | |
3882b010 | 72 | if (ISDIGIT (c)) |
252b5132 | 73 | return c - '0'; |
3882b010 | 74 | if (ISLOWER (c)) |
252b5132 RH |
75 | return c - 'a' + 10; |
76 | return c - 'A' + 10; | |
77 | } | |
78 | ||
79 | void | |
80 | sval () | |
81 | { | |
252b5132 RH |
82 | SKIP_WHITESPACE (); |
83 | if (*input_line_pointer == '\'') | |
84 | { | |
85 | int c; | |
86 | input_line_pointer++; | |
87 | c = *input_line_pointer++; | |
88 | while (c != '\'') | |
89 | { | |
90 | if (c == '%') | |
91 | { | |
92 | c = (tohex (input_line_pointer[0]) << 4) | |
93 | | tohex (input_line_pointer[1]); | |
94 | input_line_pointer += 2; | |
95 | } | |
96 | FRAG_APPEND_1_CHAR (c); | |
97 | c = *input_line_pointer++; | |
98 | } | |
99 | demand_empty_rest_of_line (); | |
100 | } | |
252b5132 | 101 | } |
e0c6ed95 AM |
102 | |
103 | /* This table describes all the machine specific pseudo-ops the assembler | |
104 | has to support. The fields are: | |
105 | pseudo-op name without dot | |
106 | function to call to execute this pseudo-op | |
107 | Integer arg to pass to the function | |
108 | */ | |
109 | ||
110 | const pseudo_typeS md_pseudo_table[] = { | |
111 | {"int" , cons , 2}, | |
112 | {"data.b" , cons , 1}, | |
113 | {"data.w" , cons , 2}, | |
114 | {"data.l" , cons , 4}, | |
115 | {"form" , listing_psize , 0}, | |
116 | {"heading", listing_title , 0}, | |
117 | {"import" , s_ignore , 0}, | |
118 | {"page" , listing_eject , 0}, | |
119 | {"program", s_ignore , 0}, | |
120 | {"z8001" , s_segm , 0}, | |
121 | {"z8002" , s_unseg , 0}, | |
122 | ||
123 | {"segm" , s_segm , 0}, | |
124 | {"unsegm" , s_unseg , 0}, | |
125 | {"unseg" , s_unseg , 0}, | |
126 | {"name" , s_app_file , 0}, | |
127 | {"global" , s_globl , 0}, | |
128 | {"wval" , cons , 2}, | |
129 | {"lval" , cons , 4}, | |
130 | {"bval" , cons , 1}, | |
131 | {"sval" , sval , 0}, | |
132 | {"rsect" , obj_coff_section, 0}, | |
133 | {"sect" , obj_coff_section, 0}, | |
134 | {"block" , s_space , 0}, | |
135 | {"even" , even , 0}, | |
136 | {0 , 0 , 0} | |
252b5132 RH |
137 | }; |
138 | ||
139 | const char EXP_CHARS[] = "eE"; | |
140 | ||
e0c6ed95 AM |
141 | /* Chars that mean this number is a floating point constant. |
142 | As in 0f12.456 | |
143 | or 0d1.2345e12 */ | |
252b5132 RH |
144 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; |
145 | ||
e0c6ed95 AM |
146 | /* Opcode mnemonics. */ |
147 | static struct hash_control *opcode_hash_control; | |
252b5132 RH |
148 | |
149 | void | |
150 | md_begin () | |
151 | { | |
152 | opcode_entry_type *opcode; | |
153 | char *prev_name = ""; | |
154 | int idx = 0; | |
155 | ||
156 | opcode_hash_control = hash_new (); | |
157 | ||
158 | for (opcode = z8k_table; opcode->name; opcode++) | |
159 | { | |
e0c6ed95 | 160 | /* Only enter unique codes into the table. */ |
252b5132 RH |
161 | if (strcmp (opcode->name, prev_name)) |
162 | { | |
163 | hash_insert (opcode_hash_control, opcode->name, (char *) opcode); | |
164 | idx++; | |
165 | } | |
166 | opcode->idx = idx; | |
167 | prev_name = opcode->name; | |
168 | } | |
169 | ||
e0c6ed95 | 170 | /* Default to z8002. */ |
252b5132 RH |
171 | s_unseg (); |
172 | ||
e0c6ed95 | 173 | /* Insert the pseudo ops, too. */ |
252b5132 RH |
174 | for (idx = 0; md_pseudo_table[idx].poc_name; idx++) |
175 | { | |
176 | opcode_entry_type *fake_opcode; | |
177 | fake_opcode = (opcode_entry_type *) malloc (sizeof (opcode_entry_type)); | |
879db8be NC |
178 | fake_opcode->name = md_pseudo_table[idx].poc_name; |
179 | fake_opcode->func = (void *) (md_pseudo_table + idx); | |
252b5132 RH |
180 | fake_opcode->opcode = 250; |
181 | hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode); | |
182 | } | |
183 | ||
184 | linkrelax = 1; | |
185 | } | |
186 | ||
19d63e5d | 187 | struct z8k_exp { |
252b5132 RH |
188 | char *e_beg; |
189 | char *e_end; | |
190 | expressionS e_exp; | |
191 | }; | |
e0c6ed95 | 192 | |
19d63e5d | 193 | typedef struct z8k_op { |
e0c6ed95 AM |
194 | /* 'b','w','r','q'. */ |
195 | char regsize; | |
196 | ||
197 | /* 0 .. 15. */ | |
198 | unsigned int reg; | |
252b5132 RH |
199 | |
200 | int mode; | |
201 | ||
e0c6ed95 AM |
202 | /* Any other register associated with the mode. */ |
203 | unsigned int x_reg; | |
204 | ||
205 | /* Any expression. */ | |
206 | expressionS exp; | |
19d63e5d | 207 | } op_type; |
252b5132 RH |
208 | |
209 | static expressionS *da_operand; | |
210 | static expressionS *imm_operand; | |
211 | ||
212 | int reg[16]; | |
213 | int the_cc; | |
214 | int the_ctrl; | |
215 | int the_flags; | |
216 | int the_interrupt; | |
217 | ||
218 | char * | |
c0fecd35 AM |
219 | whatreg (reg, src) |
220 | int *reg; | |
221 | char *src; | |
252b5132 | 222 | { |
3882b010 | 223 | if (ISDIGIT (src[1])) |
252b5132 RH |
224 | { |
225 | *reg = (src[0] - '0') * 10 + src[1] - '0'; | |
226 | return src + 2; | |
227 | } | |
228 | else | |
229 | { | |
230 | *reg = (src[0] - '0'); | |
231 | return src + 1; | |
232 | } | |
233 | } | |
234 | ||
e0c6ed95 | 235 | /* Parse operands |
252b5132 | 236 | |
e0c6ed95 AM |
237 | rh0-rh7, rl0-rl7 |
238 | r0-r15 | |
239 | rr0-rr14 | |
240 | rq0--rq12 | |
241 | WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp | |
242 | r0l,r0h,..r7l,r7h | |
243 | @WREG | |
244 | @WREG+ | |
245 | @-WREG | |
246 | #const | |
247 | */ | |
252b5132 | 248 | |
bc0d738a NC |
249 | /* Try to parse a reg name. Return a pointer to the first character |
250 | in SRC after the reg name. */ | |
251 | ||
252b5132 | 252 | char * |
c0fecd35 AM |
253 | parse_reg (src, mode, reg) |
254 | char *src; | |
255 | int *mode; | |
256 | unsigned int *reg; | |
252b5132 RH |
257 | { |
258 | char *res = 0; | |
259 | char regno; | |
260 | ||
28bab82b | 261 | if (src[0] == 's' && src[1] == 'p' && (src[2] == 0 || src[2] == ',')) |
252b5132 RH |
262 | { |
263 | if (segmented_mode) | |
e0c6ed95 AM |
264 | { |
265 | *mode = CLASS_REG_LONG; | |
266 | *reg = 14; | |
267 | } | |
252b5132 | 268 | else |
e0c6ed95 AM |
269 | { |
270 | *mode = CLASS_REG_WORD; | |
271 | *reg = 15; | |
272 | } | |
252b5132 RH |
273 | return src + 2; |
274 | } | |
275 | if (src[0] == 'r') | |
276 | { | |
277 | if (src[1] == 'r') | |
e0c6ed95 | 278 | { |
28bab82b NC |
279 | if (src[2] < '0' || src[2] > '9') |
280 | return res; /* Assume no register name but a label starting with 'rr'. */ | |
e0c6ed95 AM |
281 | *mode = CLASS_REG_LONG; |
282 | res = whatreg (reg, src + 2); | |
252b5132 RH |
283 | regno = *reg; |
284 | if (regno > 14) | |
e0c6ed95 AM |
285 | as_warn (_("register rr%d, out of range."), regno); |
286 | } | |
252b5132 | 287 | else if (src[1] == 'h') |
e0c6ed95 | 288 | { |
28bab82b NC |
289 | if (src[2] < '0' || src[2] > '9') |
290 | return res; /* Assume no register name but a label starting with 'rh'. */ | |
e0c6ed95 AM |
291 | *mode = CLASS_REG_BYTE; |
292 | res = whatreg (reg, src + 2); | |
252b5132 RH |
293 | regno = *reg; |
294 | if (regno > 7) | |
e0c6ed95 AM |
295 | as_warn (_("register rh%d, out of range."), regno); |
296 | } | |
252b5132 | 297 | else if (src[1] == 'l') |
e0c6ed95 | 298 | { |
28bab82b NC |
299 | if (src[2] < '0' || src[2] > '9') |
300 | return res; /* Assume no register name but a label starting with 'rl'. */ | |
e0c6ed95 AM |
301 | *mode = CLASS_REG_BYTE; |
302 | res = whatreg (reg, src + 2); | |
252b5132 RH |
303 | regno = *reg; |
304 | if (regno > 7) | |
e0c6ed95 AM |
305 | as_warn (_("register rl%d, out of range."), regno); |
306 | *reg += 8; | |
307 | } | |
252b5132 | 308 | else if (src[1] == 'q') |
e0c6ed95 | 309 | { |
28bab82b NC |
310 | if (src[2] < '0' || src[2] > '9') |
311 | return res; /* Assume no register name but a label starting with 'rq'. */ | |
e0c6ed95 AM |
312 | *mode = CLASS_REG_QUAD; |
313 | res = whatreg (reg, src + 2); | |
252b5132 RH |
314 | regno = *reg; |
315 | if (regno > 12) | |
e0c6ed95 AM |
316 | as_warn (_("register rq%d, out of range."), regno); |
317 | } | |
252b5132 | 318 | else |
e0c6ed95 | 319 | { |
28bab82b NC |
320 | if (src[1] < '0' || src[1] > '9') |
321 | return res; /* Assume no register name but a label starting with 'r'. */ | |
e0c6ed95 AM |
322 | *mode = CLASS_REG_WORD; |
323 | res = whatreg (reg, src + 1); | |
252b5132 RH |
324 | regno = *reg; |
325 | if (regno > 15) | |
e0c6ed95 AM |
326 | as_warn (_("register r%d, out of range."), regno); |
327 | } | |
252b5132 RH |
328 | } |
329 | return res; | |
252b5132 RH |
330 | } |
331 | ||
332 | char * | |
c0fecd35 AM |
333 | parse_exp (s, op) |
334 | char *s; | |
335 | expressionS *op; | |
252b5132 RH |
336 | { |
337 | char *save = input_line_pointer; | |
338 | char *new; | |
339 | ||
340 | input_line_pointer = s; | |
341 | expression (op); | |
342 | if (op->X_op == O_absent) | |
343 | as_bad (_("missing operand")); | |
344 | new = input_line_pointer; | |
345 | input_line_pointer = save; | |
346 | return new; | |
347 | } | |
348 | ||
349 | /* The many forms of operand: | |
350 | ||
351 | <rb> | |
352 | <r> | |
353 | <rr> | |
354 | <rq> | |
355 | @r | |
356 | #exp | |
357 | exp | |
358 | exp(r) | |
359 | r(#exp) | |
360 | r(r) | |
252b5132 RH |
361 | */ |
362 | ||
e0c6ed95 | 363 | static char * |
c0fecd35 AM |
364 | checkfor (ptr, what) |
365 | char *ptr; | |
366 | char what; | |
252b5132 RH |
367 | { |
368 | if (*ptr == what) | |
369 | ptr++; | |
370 | else | |
e0c6ed95 AM |
371 | as_bad (_("expected %c"), what); |
372 | ||
252b5132 RH |
373 | return ptr; |
374 | } | |
375 | ||
e0c6ed95 AM |
376 | /* Make sure the mode supplied is the size of a word. */ |
377 | ||
252b5132 | 378 | static void |
c0fecd35 AM |
379 | regword (mode, string) |
380 | int mode; | |
381 | char *string; | |
252b5132 RH |
382 | { |
383 | int ok; | |
384 | ||
385 | ok = CLASS_REG_WORD; | |
386 | if (ok != mode) | |
387 | { | |
388 | as_bad (_("register is wrong size for a word %s"), string); | |
389 | } | |
390 | } | |
391 | ||
e0c6ed95 AM |
392 | /* Make sure the mode supplied is the size of an address. */ |
393 | ||
252b5132 | 394 | static void |
c0fecd35 AM |
395 | regaddr (mode, string) |
396 | int mode; | |
397 | char *string; | |
252b5132 RH |
398 | { |
399 | int ok; | |
400 | ||
401 | ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD; | |
402 | if (ok != mode) | |
403 | { | |
404 | as_bad (_("register is wrong size for address %s"), string); | |
405 | } | |
406 | } | |
407 | ||
19d63e5d | 408 | struct ctrl_names { |
e0c6ed95 AM |
409 | int value; |
410 | char *name; | |
252b5132 RH |
411 | }; |
412 | ||
e0c6ed95 | 413 | struct ctrl_names ctrl_table[] = { |
879db8be NC |
414 | { 0x2, "fcw" }, |
415 | { 0x3, "refresh" }, | |
416 | { 0x4, "psapseg" }, | |
417 | { 0x5, "psapoff" }, | |
418 | { 0x5, "psap" }, | |
419 | { 0x6, "nspseg" }, | |
420 | { 0x7, "nspoff" }, | |
421 | { 0x7, "nsp" }, | |
422 | { 0 , 0 } | |
252b5132 | 423 | }; |
e0c6ed95 | 424 | |
252b5132 | 425 | static void |
c0fecd35 AM |
426 | get_ctrl_operand (ptr, mode, dst) |
427 | char **ptr; | |
428 | struct z8k_op *mode; | |
879db8be | 429 | unsigned int dst ATTRIBUTE_UNUSED; |
252b5132 RH |
430 | { |
431 | char *src = *ptr; | |
252b5132 RH |
432 | int i; |
433 | ||
434 | while (*src == ' ') | |
435 | src++; | |
436 | ||
437 | mode->mode = CLASS_CTRL; | |
438 | for (i = 0; ctrl_table[i].name; i++) | |
439 | { | |
440 | int j; | |
441 | ||
442 | for (j = 0; ctrl_table[i].name[j]; j++) | |
e0c6ed95 AM |
443 | { |
444 | if (ctrl_table[i].name[j] != src[j]) | |
445 | goto fail; | |
446 | } | |
252b5132 RH |
447 | the_ctrl = ctrl_table[i].value; |
448 | *ptr = src + j; | |
449 | return; | |
e0c6ed95 AM |
450 | fail: |
451 | ; | |
252b5132 RH |
452 | } |
453 | the_ctrl = 0; | |
454 | return; | |
455 | } | |
456 | ||
19d63e5d | 457 | struct flag_names { |
252b5132 RH |
458 | int value; |
459 | char *name; | |
460 | ||
461 | }; | |
462 | ||
e0c6ed95 | 463 | struct flag_names flag_table[] = { |
879db8be NC |
464 | { 0x1, "p" }, |
465 | { 0x1, "v" }, | |
466 | { 0x2, "s" }, | |
467 | { 0x4, "z" }, | |
468 | { 0x8, "c" }, | |
469 | { 0x0, "+" }, | |
470 | { 0, 0 } | |
252b5132 RH |
471 | }; |
472 | ||
473 | static void | |
c0fecd35 AM |
474 | get_flags_operand (ptr, mode, dst) |
475 | char **ptr; | |
476 | struct z8k_op *mode; | |
879db8be | 477 | unsigned int dst ATTRIBUTE_UNUSED; |
252b5132 RH |
478 | { |
479 | char *src = *ptr; | |
252b5132 RH |
480 | int i; |
481 | int j; | |
482 | ||
483 | while (*src == ' ') | |
484 | src++; | |
485 | ||
486 | mode->mode = CLASS_FLAGS; | |
487 | the_flags = 0; | |
488 | for (j = 0; j <= 9; j++) | |
489 | { | |
e0c6ed95 | 490 | if (!src[j]) |
252b5132 | 491 | goto done; |
e0c6ed95 AM |
492 | for (i = 0; flag_table[i].name; i++) |
493 | { | |
494 | if (flag_table[i].name[0] == src[j]) | |
495 | { | |
496 | the_flags = the_flags | flag_table[i].value; | |
497 | goto match; | |
498 | } | |
499 | } | |
252b5132 RH |
500 | goto done; |
501 | match: | |
e0c6ed95 | 502 | ; |
252b5132 | 503 | } |
e0c6ed95 | 504 | done: |
252b5132 RH |
505 | *ptr = src + j; |
506 | return; | |
507 | } | |
508 | ||
19d63e5d | 509 | struct interrupt_names { |
252b5132 RH |
510 | int value; |
511 | char *name; | |
512 | ||
513 | }; | |
514 | ||
19d63e5d | 515 | struct interrupt_names intr_table[] = { |
879db8be NC |
516 | { 0x1, "nvi" }, |
517 | { 0x2, "vi" }, | |
518 | { 0x3, "both" }, | |
519 | { 0x3, "all" }, | |
520 | { 0, 0 } | |
252b5132 RH |
521 | }; |
522 | ||
523 | static void | |
c0fecd35 AM |
524 | get_interrupt_operand (ptr, mode, dst) |
525 | char **ptr; | |
526 | struct z8k_op *mode; | |
879db8be | 527 | unsigned int dst ATTRIBUTE_UNUSED; |
252b5132 RH |
528 | { |
529 | char *src = *ptr; | |
252b5132 RH |
530 | int i; |
531 | ||
532 | while (*src == ' ') | |
533 | src++; | |
534 | ||
535 | mode->mode = CLASS_IMM; | |
536 | for (i = 0; intr_table[i].name; i++) | |
537 | { | |
538 | int j; | |
539 | ||
540 | for (j = 0; intr_table[i].name[j]; j++) | |
e0c6ed95 AM |
541 | { |
542 | if (intr_table[i].name[j] != src[j]) | |
543 | goto fail; | |
544 | } | |
252b5132 RH |
545 | the_interrupt = intr_table[i].value; |
546 | *ptr = src + j; | |
547 | return; | |
e0c6ed95 AM |
548 | fail: |
549 | ; | |
252b5132 RH |
550 | } |
551 | the_interrupt = 0x0; | |
552 | return; | |
553 | } | |
554 | ||
19d63e5d | 555 | struct cc_names { |
252b5132 RH |
556 | int value; |
557 | char *name; | |
558 | ||
559 | }; | |
560 | ||
e0c6ed95 | 561 | struct cc_names table[] = { |
879db8be NC |
562 | { 0x0, "f" }, |
563 | { 0x1, "lt" }, | |
564 | { 0x2, "le" }, | |
565 | { 0x3, "ule" }, | |
566 | { 0x4, "ov" }, | |
567 | { 0x4, "pe" }, | |
568 | { 0x5, "mi" }, | |
569 | { 0x6, "eq" }, | |
570 | { 0x6, "z" }, | |
571 | { 0x7, "c" }, | |
572 | { 0x7, "ult" }, | |
573 | { 0x8, "t" }, | |
574 | { 0x9, "ge" }, | |
575 | { 0xa, "gt" }, | |
576 | { 0xb, "ugt" }, | |
577 | { 0xc, "nov" }, | |
578 | { 0xc, "po" }, | |
579 | { 0xd, "pl" }, | |
580 | { 0xe, "ne" }, | |
581 | { 0xe, "nz" }, | |
582 | { 0xf, "nc" }, | |
583 | { 0xf, "uge" }, | |
584 | { 0 , 0 } | |
252b5132 RH |
585 | }; |
586 | ||
587 | static void | |
c0fecd35 AM |
588 | get_cc_operand (ptr, mode, dst) |
589 | char **ptr; | |
590 | struct z8k_op *mode; | |
879db8be | 591 | unsigned int dst ATTRIBUTE_UNUSED; |
252b5132 RH |
592 | { |
593 | char *src = *ptr; | |
252b5132 RH |
594 | int i; |
595 | ||
596 | while (*src == ' ') | |
597 | src++; | |
598 | ||
599 | mode->mode = CLASS_CC; | |
600 | for (i = 0; table[i].name; i++) | |
601 | { | |
602 | int j; | |
603 | ||
604 | for (j = 0; table[i].name[j]; j++) | |
605 | { | |
606 | if (table[i].name[j] != src[j]) | |
607 | goto fail; | |
608 | } | |
609 | the_cc = table[i].value; | |
610 | *ptr = src + j; | |
611 | return; | |
e0c6ed95 AM |
612 | fail: |
613 | ; | |
252b5132 RH |
614 | } |
615 | the_cc = 0x8; | |
616 | } | |
617 | ||
618 | static void | |
619 | get_operand (ptr, mode, dst) | |
620 | char **ptr; | |
621 | struct z8k_op *mode; | |
879db8be | 622 | unsigned int dst ATTRIBUTE_UNUSED; |
252b5132 RH |
623 | { |
624 | char *src = *ptr; | |
625 | char *end; | |
252b5132 RH |
626 | |
627 | mode->mode = 0; | |
628 | ||
629 | while (*src == ' ') | |
630 | src++; | |
631 | if (*src == '#') | |
632 | { | |
633 | mode->mode = CLASS_IMM; | |
634 | imm_operand = &(mode->exp); | |
635 | src = parse_exp (src + 1, &(mode->exp)); | |
636 | } | |
637 | else if (*src == '@') | |
638 | { | |
639 | int d; | |
640 | ||
641 | mode->mode = CLASS_IR; | |
642 | src = parse_reg (src + 1, &d, &mode->reg); | |
643 | } | |
644 | else | |
645 | { | |
646 | int regn; | |
647 | ||
648 | end = parse_reg (src, &mode->mode, ®n); | |
649 | ||
650 | if (end) | |
651 | { | |
652 | int nw, nr; | |
653 | ||
654 | src = end; | |
655 | if (*src == '(') | |
656 | { | |
657 | src++; | |
658 | end = parse_reg (src, &nw, &nr); | |
659 | if (end) | |
660 | { | |
e0c6ed95 | 661 | /* Got Ra(Rb). */ |
252b5132 RH |
662 | src = end; |
663 | ||
664 | if (*src != ')') | |
e0c6ed95 | 665 | as_bad (_("Missing ) in ra(rb)")); |
252b5132 | 666 | else |
e0c6ed95 | 667 | src++; |
252b5132 RH |
668 | |
669 | regaddr (mode->mode, "ra(rb) ra"); | |
e0c6ed95 AM |
670 | #if 0 |
671 | regword (mode->mode, "ra(rb) rb"); | |
672 | #endif | |
252b5132 RH |
673 | mode->mode = CLASS_BX; |
674 | mode->reg = regn; | |
675 | mode->x_reg = nr; | |
676 | reg[ARG_RX] = nr; | |
677 | } | |
678 | else | |
679 | { | |
e0c6ed95 | 680 | /* Got Ra(disp). */ |
252b5132 RH |
681 | if (*src == '#') |
682 | src++; | |
683 | src = parse_exp (src, &(mode->exp)); | |
684 | src = checkfor (src, ')'); | |
685 | mode->mode = CLASS_BA; | |
686 | mode->reg = regn; | |
687 | mode->x_reg = 0; | |
688 | imm_operand = &(mode->exp); | |
689 | } | |
690 | } | |
691 | else | |
692 | { | |
693 | mode->reg = regn; | |
694 | mode->x_reg = 0; | |
695 | } | |
696 | } | |
697 | else | |
698 | { | |
e0c6ed95 | 699 | /* No initial reg. */ |
252b5132 RH |
700 | src = parse_exp (src, &(mode->exp)); |
701 | if (*src == '(') | |
702 | { | |
703 | src++; | |
704 | end = parse_reg (src, &(mode->mode), ®n); | |
705 | regword (mode->mode, "addr(Ra) ra"); | |
706 | mode->mode = CLASS_X; | |
707 | mode->reg = regn; | |
708 | mode->x_reg = 0; | |
709 | da_operand = &(mode->exp); | |
710 | src = checkfor (end, ')'); | |
711 | } | |
712 | else | |
713 | { | |
e0c6ed95 | 714 | /* Just an address. */ |
252b5132 RH |
715 | mode->mode = CLASS_DA; |
716 | mode->reg = 0; | |
717 | mode->x_reg = 0; | |
718 | da_operand = &(mode->exp); | |
719 | } | |
720 | } | |
721 | } | |
722 | *ptr = src; | |
723 | } | |
724 | ||
e0c6ed95 | 725 | static char * |
252b5132 RH |
726 | get_operands (opcode, op_end, operand) |
727 | opcode_entry_type *opcode; | |
728 | char *op_end; | |
729 | op_type *operand; | |
730 | { | |
731 | char *ptr = op_end; | |
e0c6ed95 AM |
732 | char *savptr; |
733 | ||
14899840 | 734 | ptr++; |
252b5132 RH |
735 | switch (opcode->noperands) |
736 | { | |
737 | case 0: | |
738 | operand[0].mode = 0; | |
739 | operand[1].mode = 0; | |
740 | break; | |
741 | ||
742 | case 1: | |
252b5132 | 743 | if (opcode->arg_info[0] == CLASS_CC) |
14899840 NC |
744 | get_cc_operand (&ptr, operand + 0, 0); |
745 | ||
252b5132 | 746 | else if (opcode->arg_info[0] == CLASS_FLAGS) |
14899840 NC |
747 | get_flags_operand (&ptr, operand + 0, 0); |
748 | ||
e0c6ed95 | 749 | else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2))) |
14899840 NC |
750 | get_interrupt_operand (&ptr, operand + 0, 0); |
751 | ||
252b5132 | 752 | else |
14899840 NC |
753 | get_operand (&ptr, operand + 0, 0); |
754 | ||
252b5132 RH |
755 | operand[1].mode = 0; |
756 | break; | |
757 | ||
758 | case 2: | |
252b5132 RH |
759 | savptr = ptr; |
760 | if (opcode->arg_info[0] == CLASS_CC) | |
14899840 NC |
761 | get_cc_operand (&ptr, operand + 0, 0); |
762 | ||
252b5132 | 763 | else if (opcode->arg_info[0] == CLASS_CTRL) |
e0c6ed95 AM |
764 | { |
765 | get_ctrl_operand (&ptr, operand + 0, 0); | |
14899840 | 766 | |
e0c6ed95 AM |
767 | if (the_ctrl == 0) |
768 | { | |
769 | ptr = savptr; | |
770 | get_operand (&ptr, operand + 0, 0); | |
14899840 | 771 | |
e0c6ed95 | 772 | if (ptr == 0) |
879db8be | 773 | return NULL; |
e0c6ed95 AM |
774 | if (*ptr == ',') |
775 | ptr++; | |
776 | get_ctrl_operand (&ptr, operand + 1, 1); | |
777 | return ptr; | |
778 | } | |
779 | } | |
252b5132 | 780 | else |
14899840 NC |
781 | get_operand (&ptr, operand + 0, 0); |
782 | ||
252b5132 | 783 | if (ptr == 0) |
879db8be | 784 | return NULL; |
252b5132 | 785 | if (*ptr == ',') |
e0c6ed95 | 786 | ptr++; |
252b5132 RH |
787 | get_operand (&ptr, operand + 1, 1); |
788 | break; | |
789 | ||
790 | case 3: | |
252b5132 RH |
791 | get_operand (&ptr, operand + 0, 0); |
792 | if (*ptr == ',') | |
793 | ptr++; | |
794 | get_operand (&ptr, operand + 1, 1); | |
795 | if (*ptr == ',') | |
796 | ptr++; | |
797 | get_operand (&ptr, operand + 2, 2); | |
798 | break; | |
799 | ||
800 | case 4: | |
252b5132 RH |
801 | get_operand (&ptr, operand + 0, 0); |
802 | if (*ptr == ',') | |
803 | ptr++; | |
804 | get_operand (&ptr, operand + 1, 1); | |
805 | if (*ptr == ',') | |
806 | ptr++; | |
807 | get_operand (&ptr, operand + 2, 2); | |
808 | if (*ptr == ',') | |
809 | ptr++; | |
810 | get_cc_operand (&ptr, operand + 3, 3); | |
811 | break; | |
e0c6ed95 | 812 | |
252b5132 RH |
813 | default: |
814 | abort (); | |
815 | } | |
816 | ||
817 | return ptr; | |
818 | } | |
819 | ||
820 | /* Passed a pointer to a list of opcodes which use different | |
e0c6ed95 AM |
821 | addressing modes. Return the opcode which matches the opcodes |
822 | provided. */ | |
252b5132 | 823 | |
e0c6ed95 | 824 | static opcode_entry_type * |
c0fecd35 AM |
825 | get_specific (opcode, operands) |
826 | opcode_entry_type *opcode; | |
827 | op_type *operands; | |
252b5132 RH |
828 | |
829 | { | |
830 | opcode_entry_type *this_try = opcode; | |
831 | int found = 0; | |
832 | unsigned int noperands = opcode->noperands; | |
833 | ||
879db8be | 834 | int this_index = opcode->idx; |
252b5132 RH |
835 | |
836 | while (this_index == opcode->idx && !found) | |
837 | { | |
838 | unsigned int i; | |
839 | ||
840 | this_try = opcode++; | |
841 | for (i = 0; i < noperands; i++) | |
842 | { | |
879db8be | 843 | unsigned int mode = operands[i].mode; |
252b5132 RH |
844 | |
845 | if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK)) | |
846 | { | |
e0c6ed95 AM |
847 | /* It could be an pc rel operand, if this is a da mode |
848 | and we like disps, then insert it. */ | |
252b5132 RH |
849 | |
850 | if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP) | |
851 | { | |
e0c6ed95 | 852 | /* This is the case. */ |
252b5132 RH |
853 | operands[i].mode = CLASS_DISP; |
854 | } | |
855 | else if (mode == CLASS_BA && this_try->arg_info[i]) | |
856 | { | |
e0c6ed95 AM |
857 | /* Can't think of a way to turn what we've been |
858 | given into something that's OK. */ | |
252b5132 RH |
859 | goto fail; |
860 | } | |
861 | else if (this_try->arg_info[i] & CLASS_PR) | |
862 | { | |
863 | if (mode == CLASS_REG_LONG && segmented_mode) | |
864 | { | |
e0c6ed95 | 865 | /* OK. */ |
252b5132 RH |
866 | } |
867 | else if (mode == CLASS_REG_WORD && !segmented_mode) | |
868 | { | |
e0c6ed95 | 869 | /* OK. */ |
252b5132 RH |
870 | } |
871 | else | |
872 | goto fail; | |
873 | } | |
874 | else | |
875 | goto fail; | |
876 | } | |
877 | switch (mode & CLASS_MASK) | |
878 | { | |
879 | default: | |
880 | break; | |
881 | case CLASS_X: | |
882 | case CLASS_IR: | |
883 | case CLASS_BA: | |
884 | case CLASS_BX: | |
885 | case CLASS_DISP: | |
886 | case CLASS_REG: | |
887 | case CLASS_REG_WORD: | |
888 | case CLASS_REG_BYTE: | |
889 | case CLASS_REG_QUAD: | |
890 | case CLASS_REG_LONG: | |
891 | case CLASS_REGN0: | |
892 | reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg; | |
893 | break; | |
894 | } | |
895 | } | |
896 | ||
897 | found = 1; | |
e0c6ed95 AM |
898 | fail: |
899 | ; | |
252b5132 RH |
900 | } |
901 | if (found) | |
902 | return this_try; | |
903 | else | |
904 | return 0; | |
905 | } | |
906 | ||
879db8be | 907 | #if 0 /* Not used. */ |
252b5132 | 908 | static void |
c0fecd35 AM |
909 | check_operand (operand, width, string) |
910 | struct z8k_op *operand; | |
911 | unsigned int width; | |
912 | char *string; | |
252b5132 RH |
913 | { |
914 | if (operand->exp.X_add_symbol == 0 | |
915 | && operand->exp.X_op_symbol == 0) | |
916 | { | |
917 | ||
e0c6ed95 AM |
918 | /* No symbol involved, let's look at offset, it's dangerous if |
919 | any of the high bits are not 0 or ff's, find out by oring or | |
920 | anding with the width and seeing if the answer is 0 or all | |
921 | fs. */ | |
252b5132 RH |
922 | if ((operand->exp.X_add_number & ~width) != 0 && |
923 | (operand->exp.X_add_number | width) != (~0)) | |
924 | { | |
e0c6ed95 AM |
925 | as_warn (_("operand %s0x%x out of range."), |
926 | string, operand->exp.X_add_number); | |
252b5132 RH |
927 | } |
928 | } | |
929 | ||
930 | } | |
879db8be | 931 | #endif |
252b5132 RH |
932 | |
933 | static char buffer[20]; | |
934 | ||
935 | static void | |
c0fecd35 AM |
936 | newfix (ptr, type, operand) |
937 | int ptr; | |
938 | int type; | |
939 | expressionS *operand; | |
252b5132 RH |
940 | { |
941 | if (operand->X_add_symbol | |
942 | || operand->X_op_symbol | |
943 | || operand->X_add_number) | |
944 | { | |
945 | fix_new_exp (frag_now, | |
946 | ptr, | |
947 | 1, | |
948 | operand, | |
949 | 0, | |
950 | type); | |
951 | } | |
952 | } | |
953 | ||
954 | static char * | |
c0fecd35 AM |
955 | apply_fix (ptr, type, operand, size) |
956 | char *ptr; | |
957 | int type; | |
958 | expressionS *operand; | |
959 | int size; | |
252b5132 RH |
960 | { |
961 | int n = operand->X_add_number; | |
962 | ||
252b5132 | 963 | newfix ((ptr - buffer) / 2, type, operand); |
252b5132 RH |
964 | switch (size) |
965 | { | |
879db8be | 966 | case 8: /* 8 nibbles == 32 bits. */ |
252b5132 RH |
967 | *ptr++ = n >> 28; |
968 | *ptr++ = n >> 24; | |
969 | *ptr++ = n >> 20; | |
970 | *ptr++ = n >> 16; | |
879db8be | 971 | case 4: /* 4 nibbles == 16 bits. */ |
252b5132 RH |
972 | *ptr++ = n >> 12; |
973 | *ptr++ = n >> 8; | |
974 | case 2: | |
975 | *ptr++ = n >> 4; | |
976 | case 1: | |
977 | *ptr++ = n >> 0; | |
978 | break; | |
979 | } | |
252b5132 | 980 | return ptr; |
252b5132 RH |
981 | } |
982 | ||
e0c6ed95 AM |
983 | /* Now we know what sort of opcodes it is. Let's build the bytes. */ |
984 | ||
252b5132 | 985 | #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y; |
19d63e5d | 986 | |
252b5132 RH |
987 | static void |
988 | build_bytes (this_try, operand) | |
e0c6ed95 | 989 | opcode_entry_type *this_try; |
879db8be | 990 | struct z8k_op *operand ATTRIBUTE_UNUSED; |
252b5132 | 991 | { |
252b5132 | 992 | char *output_ptr = buffer; |
252b5132 | 993 | int c; |
252b5132 RH |
994 | int nib; |
995 | int nibble; | |
996 | unsigned int *class_ptr; | |
997 | ||
998 | frag_wane (frag_now); | |
999 | frag_new (0); | |
1000 | ||
25d3fb58 | 1001 | memset (buffer, 0, sizeof (buffer)); |
252b5132 | 1002 | class_ptr = this_try->byte_info; |
252b5132 | 1003 | |
879db8be | 1004 | for (nibble = 0; (c = *class_ptr++); nibble++) |
252b5132 RH |
1005 | { |
1006 | ||
1007 | switch (c & CLASS_MASK) | |
1008 | { | |
1009 | default: | |
252b5132 | 1010 | abort (); |
e0c6ed95 | 1011 | |
252b5132 | 1012 | case CLASS_ADDRESS: |
e0c6ed95 | 1013 | /* Direct address, we don't cope with the SS mode right now. */ |
252b5132 RH |
1014 | if (segmented_mode) |
1015 | { | |
879db8be | 1016 | /* da_operand->X_add_number |= 0x80000000; -- Now set at relocation time. */ |
252b5132 RH |
1017 | output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8); |
1018 | } | |
1019 | else | |
1020 | { | |
1021 | output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4); | |
1022 | } | |
1023 | da_operand = 0; | |
1024 | break; | |
1025 | case CLASS_DISP8: | |
e0c6ed95 | 1026 | /* pc rel 8 bit */ |
252b5132 RH |
1027 | output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2); |
1028 | da_operand = 0; | |
1029 | break; | |
1030 | ||
1031 | case CLASS_0DISP7: | |
e0c6ed95 | 1032 | /* pc rel 7 bit */ |
252b5132 RH |
1033 | *output_ptr = 0; |
1034 | output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2); | |
1035 | da_operand = 0; | |
1036 | break; | |
1037 | ||
1038 | case CLASS_1DISP7: | |
e0c6ed95 | 1039 | /* pc rel 7 bit */ |
252b5132 RH |
1040 | *output_ptr = 0x80; |
1041 | output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2); | |
e0c6ed95 | 1042 | output_ptr[-2] = 0x8; |
252b5132 RH |
1043 | da_operand = 0; |
1044 | break; | |
1045 | ||
1046 | case CLASS_BIT_1OR2: | |
1047 | *output_ptr = c & 0xf; | |
1048 | if (imm_operand) | |
1049 | { | |
1050 | if (imm_operand->X_add_number == 2) | |
e0c6ed95 | 1051 | *output_ptr |= 2; |
252b5132 | 1052 | else if (imm_operand->X_add_number != 1) |
e0c6ed95 | 1053 | as_bad (_("immediate must be 1 or 2")); |
252b5132 RH |
1054 | } |
1055 | else | |
e0c6ed95 | 1056 | as_bad (_("immediate 1 or 2 expected")); |
252b5132 RH |
1057 | output_ptr++; |
1058 | break; | |
1059 | case CLASS_CC: | |
1060 | *output_ptr++ = the_cc; | |
1061 | break; | |
e0c6ed95 AM |
1062 | case CLASS_0CCC: |
1063 | *output_ptr++ = the_ctrl; | |
1064 | break; | |
1065 | case CLASS_1CCC: | |
1066 | *output_ptr++ = the_ctrl | 0x8; | |
1067 | break; | |
1068 | case CLASS_00II: | |
1069 | *output_ptr++ = (~the_interrupt & 0x3); | |
1070 | break; | |
1071 | case CLASS_01II: | |
1072 | *output_ptr++ = (~the_interrupt & 0x3) | 0x4; | |
1073 | break; | |
1074 | case CLASS_FLAGS: | |
1075 | *output_ptr++ = the_flags; | |
1076 | break; | |
3c25c5f6 | 1077 | case CLASS_IGNORE: |
252b5132 RH |
1078 | case CLASS_BIT: |
1079 | *output_ptr++ = c & 0xf; | |
1080 | break; | |
1081 | case CLASS_REGN0: | |
1082 | if (reg[c & 0xf] == 0) | |
e0c6ed95 AM |
1083 | as_bad (_("can't use R0 here")); |
1084 | /* Fall through. */ | |
252b5132 RH |
1085 | case CLASS_REG: |
1086 | case CLASS_REG_BYTE: | |
1087 | case CLASS_REG_WORD: | |
1088 | case CLASS_REG_LONG: | |
1089 | case CLASS_REG_QUAD: | |
e0c6ed95 | 1090 | /* Insert bit mattern of right reg. */ |
252b5132 RH |
1091 | *output_ptr++ = reg[c & 0xf]; |
1092 | break; | |
1093 | case CLASS_DISP: | |
6840198f NC |
1094 | switch (c & ARG_MASK) |
1095 | { | |
1096 | case ARG_DISP12: | |
1097 | output_ptr = apply_fix (output_ptr, R_CALLR, da_operand, 4); | |
1098 | break; | |
1099 | case ARG_DISP16: | |
879db8be NC |
1100 | output_ptr = apply_fix (output_ptr, R_REL16, da_operand, 4); |
1101 | break; | |
1102 | default: | |
1103 | output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4); | |
1104 | } | |
252b5132 RH |
1105 | da_operand = 0; |
1106 | break; | |
1107 | ||
1108 | case CLASS_IMM: | |
1109 | { | |
1110 | nib = 0; | |
1111 | switch (c & ARG_MASK) | |
1112 | { | |
3c25c5f6 NC |
1113 | case ARG_NIM4: |
1114 | imm_operand->X_add_number = -imm_operand->X_add_number; | |
1115 | /* Drop through. */ | |
252b5132 RH |
1116 | case ARG_IMM4: |
1117 | output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1); | |
1118 | break; | |
1119 | case ARG_IMM4M1: | |
1120 | imm_operand->X_add_number--; | |
1121 | output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1); | |
1122 | break; | |
1123 | case ARG_IMMNMINUS1: | |
1124 | imm_operand->X_add_number--; | |
1125 | output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1); | |
1126 | break; | |
1127 | case ARG_NIM8: | |
1128 | imm_operand->X_add_number = -imm_operand->X_add_number; | |
1129 | case ARG_IMM8: | |
1130 | output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2); | |
1131 | break; | |
1132 | case ARG_IMM16: | |
1133 | output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4); | |
1134 | break; | |
1135 | ||
1136 | case ARG_IMM32: | |
1137 | output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8); | |
1138 | break; | |
1139 | ||
1140 | default: | |
1141 | abort (); | |
1142 | } | |
1143 | } | |
1144 | } | |
1145 | } | |
1146 | ||
e0c6ed95 | 1147 | /* Copy from the nibble buffer into the frag. */ |
252b5132 RH |
1148 | { |
1149 | int length = (output_ptr - buffer) / 2; | |
1150 | char *src = buffer; | |
1151 | char *fragp = frag_more (length); | |
1152 | ||
1153 | while (src < output_ptr) | |
1154 | { | |
1155 | *fragp = (src[0] << 4) | src[1]; | |
1156 | src += 2; | |
1157 | fragp++; | |
1158 | } | |
252b5132 | 1159 | } |
252b5132 RH |
1160 | } |
1161 | ||
1162 | /* This is the guts of the machine-dependent assembler. STR points to a | |
1994a7c7 NC |
1163 | machine dependent instruction. This function is supposed to emit |
1164 | the frags/bytes it assembles to. */ | |
252b5132 RH |
1165 | |
1166 | void | |
c0fecd35 AM |
1167 | md_assemble (str) |
1168 | char *str; | |
252b5132 | 1169 | { |
879db8be | 1170 | char c; |
252b5132 RH |
1171 | char *op_start; |
1172 | char *op_end; | |
252b5132 RH |
1173 | struct z8k_op operand[3]; |
1174 | opcode_entry_type *opcode; | |
1175 | opcode_entry_type *prev_opcode; | |
1176 | ||
e0c6ed95 | 1177 | /* Drop leading whitespace. */ |
252b5132 RH |
1178 | while (*str == ' ') |
1179 | str++; | |
1180 | ||
e0c6ed95 | 1181 | /* Find the op code end. */ |
252b5132 RH |
1182 | for (op_start = op_end = str; |
1183 | *op_end != 0 && *op_end != ' '; | |
1184 | op_end++) | |
e0c6ed95 | 1185 | ; |
252b5132 RH |
1186 | |
1187 | if (op_end == op_start) | |
1188 | { | |
1189 | as_bad (_("can't find opcode ")); | |
1190 | } | |
1191 | c = *op_end; | |
1192 | ||
1193 | *op_end = 0; | |
1194 | ||
e0c6ed95 | 1195 | opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start); |
252b5132 RH |
1196 | |
1197 | if (opcode == NULL) | |
1198 | { | |
1199 | as_bad (_("unknown opcode")); | |
1200 | return; | |
1201 | } | |
1202 | ||
1203 | if (opcode->opcode == 250) | |
1204 | { | |
252b5132 RH |
1205 | pseudo_typeS *p; |
1206 | char oc; | |
252b5132 RH |
1207 | char *old = input_line_pointer; |
1208 | *op_end = c; | |
1209 | ||
3c25c5f6 NC |
1210 | /* Was really a pseudo op. */ |
1211 | ||
252b5132 RH |
1212 | input_line_pointer = op_end; |
1213 | ||
1214 | oc = *old; | |
1215 | *old = '\n'; | |
1216 | while (*input_line_pointer == ' ') | |
1217 | input_line_pointer++; | |
1218 | p = (pseudo_typeS *) (opcode->func); | |
1219 | ||
1220 | (p->poc_handler) (p->poc_val); | |
1221 | input_line_pointer = old; | |
1222 | *old = oc; | |
1223 | } | |
1224 | else | |
1225 | { | |
3c25c5f6 NC |
1226 | char *new_input_line_pointer; |
1227 | ||
1228 | new_input_line_pointer = get_operands (opcode, op_end, operand); | |
1229 | if (new_input_line_pointer) | |
1230 | input_line_pointer = new_input_line_pointer; | |
252b5132 RH |
1231 | prev_opcode = opcode; |
1232 | ||
1233 | opcode = get_specific (opcode, operand); | |
1234 | ||
1235 | if (opcode == 0) | |
1236 | { | |
e0c6ed95 | 1237 | /* Couldn't find an opcode which matched the operands. */ |
252b5132 RH |
1238 | char *where = frag_more (2); |
1239 | ||
1240 | where[0] = 0x0; | |
1241 | where[1] = 0x0; | |
1242 | ||
1243 | as_bad (_("Can't find opcode to match operands")); | |
1244 | return; | |
1245 | } | |
1246 | ||
1247 | build_bytes (opcode, operand); | |
1248 | } | |
1249 | } | |
1250 | ||
1251 | void | |
c0fecd35 | 1252 | tc_crawl_symbol_chain (headers) |
879db8be | 1253 | object_headers *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
1254 | { |
1255 | printf (_("call to tc_crawl_symbol_chain \n")); | |
1256 | } | |
1257 | ||
1258 | symbolS * | |
c0fecd35 | 1259 | md_undefined_symbol (name) |
879db8be | 1260 | char *name ATTRIBUTE_UNUSED; |
252b5132 RH |
1261 | { |
1262 | return 0; | |
1263 | } | |
1264 | ||
1265 | void | |
c0fecd35 | 1266 | tc_headers_hook (headers) |
879db8be | 1267 | object_headers *headers ATTRIBUTE_UNUSED; |
252b5132 RH |
1268 | { |
1269 | printf (_("call to tc_headers_hook \n")); | |
1270 | } | |
1271 | ||
e0c6ed95 AM |
1272 | /* Various routines to kill one day. */ |
1273 | /* Equal to MAX_PRECISION in atof-ieee.c. */ | |
252b5132 RH |
1274 | #define MAX_LITTLENUMS 6 |
1275 | ||
e0c6ed95 AM |
1276 | /* Turn a string in input_line_pointer into a floating point constant |
1277 | of type TYPE, and store the appropriate bytes in *LITP. The number | |
1278 | of LITTLENUMS emitted is stored in *SIZEP. An error message is | |
1279 | returned, or NULL on OK. */ | |
1280 | ||
252b5132 RH |
1281 | char * |
1282 | md_atof (type, litP, sizeP) | |
1283 | char type; | |
1284 | char *litP; | |
1285 | int *sizeP; | |
1286 | { | |
1287 | int prec; | |
1288 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
1289 | LITTLENUM_TYPE *wordP; | |
1290 | char *t; | |
1291 | char *atof_ieee (); | |
1292 | ||
1293 | switch (type) | |
1294 | { | |
1295 | case 'f': | |
1296 | case 'F': | |
1297 | case 's': | |
1298 | case 'S': | |
1299 | prec = 2; | |
1300 | break; | |
1301 | ||
1302 | case 'd': | |
1303 | case 'D': | |
1304 | case 'r': | |
1305 | case 'R': | |
1306 | prec = 4; | |
1307 | break; | |
1308 | ||
1309 | case 'x': | |
1310 | case 'X': | |
1311 | prec = 6; | |
1312 | break; | |
1313 | ||
1314 | case 'p': | |
1315 | case 'P': | |
1316 | prec = 6; | |
1317 | break; | |
1318 | ||
1319 | default: | |
1320 | *sizeP = 0; | |
1321 | return _("Bad call to MD_ATOF()"); | |
1322 | } | |
1323 | t = atof_ieee (input_line_pointer, type, words); | |
1324 | if (t) | |
1325 | input_line_pointer = t; | |
1326 | ||
1327 | *sizeP = prec * sizeof (LITTLENUM_TYPE); | |
1328 | for (wordP = words; prec--;) | |
1329 | { | |
1330 | md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE)); | |
1331 | litP += sizeof (LITTLENUM_TYPE); | |
1332 | } | |
1333 | return 0; | |
1334 | } | |
1335 | \f | |
5a38dc70 | 1336 | const char *md_shortopts = "z:"; |
e0c6ed95 | 1337 | |
3c25c5f6 NC |
1338 | struct option md_longopts[] = |
1339 | { | |
1340 | {NULL, no_argument, NULL, 0} | |
1341 | }; | |
e0c6ed95 AM |
1342 | |
1343 | size_t md_longopts_size = sizeof (md_longopts); | |
252b5132 RH |
1344 | |
1345 | int | |
1346 | md_parse_option (c, arg) | |
1347 | int c; | |
1348 | char *arg; | |
1349 | { | |
1350 | switch (c) | |
1351 | { | |
1352 | case 'z': | |
1353 | if (!strcmp (arg, "8001")) | |
1354 | s_segm (); | |
1355 | else if (!strcmp (arg, "8002")) | |
1356 | s_unseg (); | |
1357 | else | |
1358 | { | |
1359 | as_bad (_("invalid architecture -z%s"), arg); | |
1360 | return 0; | |
1361 | } | |
1362 | break; | |
1363 | ||
1364 | default: | |
1365 | return 0; | |
1366 | } | |
1367 | ||
1368 | return 1; | |
1369 | } | |
1370 | ||
1371 | void | |
1372 | md_show_usage (stream) | |
1373 | FILE *stream; | |
1374 | { | |
e0c6ed95 | 1375 | fprintf (stream, _("\ |
252b5132 RH |
1376 | Z8K options:\n\ |
1377 | -z8001 generate segmented code\n\ | |
1378 | -z8002 generate unsegmented code\n")); | |
1379 | } | |
1380 | \f | |
1381 | void | |
1382 | tc_aout_fix_to_chars () | |
1383 | { | |
1384 | printf (_("call to tc_aout_fix_to_chars \n")); | |
1385 | abort (); | |
1386 | } | |
1387 | ||
1388 | void | |
1389 | md_convert_frag (headers, seg, fragP) | |
879db8be NC |
1390 | object_headers *headers ATTRIBUTE_UNUSED; |
1391 | segT seg ATTRIBUTE_UNUSED; | |
1392 | fragS *fragP ATTRIBUTE_UNUSED; | |
252b5132 RH |
1393 | { |
1394 | printf (_("call to md_convert_frag \n")); | |
1395 | abort (); | |
1396 | } | |
1397 | ||
1398 | valueT | |
c0fecd35 AM |
1399 | md_section_align (seg, size) |
1400 | segT seg; | |
1401 | valueT size; | |
252b5132 | 1402 | { |
e0c6ed95 AM |
1403 | return ((size + (1 << section_alignment[(int) seg]) - 1) |
1404 | & (-1 << section_alignment[(int) seg])); | |
252b5132 RH |
1405 | } |
1406 | ||
1407 | void | |
94f592af | 1408 | md_apply_fix3 (fixP, valP, segment) |
14899840 | 1409 | fixS * fixP; |
94f592af NC |
1410 | valueT * valP; |
1411 | segT segment ATTRIBUTE_UNUSED; | |
252b5132 | 1412 | { |
94f592af | 1413 | long val = * (long *) valP; |
252b5132 RH |
1414 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
1415 | ||
1416 | switch (fixP->fx_r_type) | |
1417 | { | |
1418 | case R_IMM4L: | |
1419 | buf[0] = (buf[0] & 0xf0) | ((buf[0] + val) & 0xf); | |
1420 | break; | |
1421 | ||
1422 | case R_JR: | |
1423 | ||
1424 | *buf++ = val; | |
e0c6ed95 AM |
1425 | #if 0 |
1426 | if (val != 0) | |
1427 | abort (); | |
1428 | #endif | |
252b5132 RH |
1429 | break; |
1430 | ||
1431 | case R_DISP7: | |
1432 | ||
1433 | *buf++ += val; | |
e0c6ed95 AM |
1434 | #if 0 |
1435 | if (val != 0) | |
1436 | abort (); | |
1437 | #endif | |
252b5132 RH |
1438 | break; |
1439 | ||
1440 | case R_IMM8: | |
1441 | buf[0] += val; | |
1442 | break; | |
1443 | case R_IMM16: | |
1444 | *buf++ = (val >> 8); | |
1445 | *buf++ = val; | |
1446 | break; | |
1447 | case R_IMM32: | |
1448 | *buf++ = (val >> 24); | |
1449 | *buf++ = (val >> 16); | |
1450 | *buf++ = (val >> 8); | |
1451 | *buf++ = val; | |
1452 | break; | |
1453 | #if 0 | |
1454 | case R_DA | R_SEG: | |
1455 | *buf++ = (val >> 16); | |
1456 | *buf++ = 0x00; | |
1457 | *buf++ = (val >> 8); | |
1458 | *buf++ = val; | |
1459 | break; | |
1460 | #endif | |
1461 | ||
1462 | case 0: | |
1463 | md_number_to_chars (buf, val, fixP->fx_size); | |
1464 | break; | |
1465 | ||
1466 | default: | |
1467 | abort (); | |
252b5132 | 1468 | } |
94f592af NC |
1469 | |
1470 | if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) | |
1471 | fixP->fx_done = 1; | |
252b5132 RH |
1472 | } |
1473 | ||
1474 | int | |
1475 | md_estimate_size_before_relax (fragP, segment_type) | |
879db8be NC |
1476 | register fragS *fragP ATTRIBUTE_UNUSED; |
1477 | register segT segment_type ATTRIBUTE_UNUSED; | |
252b5132 | 1478 | { |
14899840 | 1479 | printf (_("call tomd_estimate_size_before_relax\n")); |
252b5132 RH |
1480 | abort (); |
1481 | } | |
1482 | ||
e0c6ed95 | 1483 | /* Put number into target byte order. */ |
252b5132 RH |
1484 | |
1485 | void | |
c0fecd35 AM |
1486 | md_number_to_chars (ptr, use, nbytes) |
1487 | char *ptr; | |
1488 | valueT use; | |
1489 | int nbytes; | |
252b5132 RH |
1490 | { |
1491 | number_to_chars_bigendian (ptr, use, nbytes); | |
1492 | } | |
e0c6ed95 | 1493 | |
252b5132 RH |
1494 | long |
1495 | md_pcrel_from (fixP) | |
879db8be | 1496 | fixS *fixP ATTRIBUTE_UNUSED; |
252b5132 RH |
1497 | { |
1498 | abort (); | |
1499 | } | |
1500 | ||
1501 | void | |
1502 | tc_coff_symbol_emit_hook (s) | |
879db8be | 1503 | symbolS *s ATTRIBUTE_UNUSED; |
252b5132 RH |
1504 | { |
1505 | } | |
1506 | ||
1507 | void | |
1508 | tc_reloc_mangle (fix_ptr, intr, base) | |
1509 | fixS *fix_ptr; | |
1510 | struct internal_reloc *intr; | |
1511 | bfd_vma base; | |
1512 | ||
1513 | { | |
1514 | symbolS *symbol_ptr; | |
1515 | ||
e0c6ed95 AM |
1516 | if (fix_ptr->fx_addsy |
1517 | && fix_ptr->fx_subsy) | |
252b5132 RH |
1518 | { |
1519 | symbolS *add = fix_ptr->fx_addsy; | |
1520 | symbolS *sub = fix_ptr->fx_subsy; | |
e0c6ed95 AM |
1521 | |
1522 | if (S_GET_SEGMENT (add) != S_GET_SEGMENT (sub)) | |
1523 | as_bad (_("Can't subtract symbols in different sections %s %s"), | |
1524 | S_GET_NAME (add), S_GET_NAME (sub)); | |
1525 | else | |
252b5132 | 1526 | { |
e0c6ed95 AM |
1527 | int diff = S_GET_VALUE (add) - S_GET_VALUE (sub); |
1528 | ||
1529 | fix_ptr->fx_addsy = 0; | |
1530 | fix_ptr->fx_subsy = 0; | |
1531 | fix_ptr->fx_offset += diff; | |
252b5132 | 1532 | } |
252b5132 RH |
1533 | } |
1534 | symbol_ptr = fix_ptr->fx_addsy; | |
1535 | ||
1536 | /* If this relocation is attached to a symbol then it's ok | |
e0c6ed95 | 1537 | to output it. */ |
252b5132 RH |
1538 | if (fix_ptr->fx_r_type == 0) |
1539 | { | |
e0c6ed95 | 1540 | /* cons likes to create reloc32's whatever the size of the reloc. */ |
252b5132 RH |
1541 | switch (fix_ptr->fx_size) |
1542 | { | |
1543 | case 2: | |
1544 | intr->r_type = R_IMM16; | |
1545 | break; | |
1546 | case 1: | |
1547 | intr->r_type = R_IMM8; | |
1548 | break; | |
1549 | case 4: | |
1550 | intr->r_type = R_IMM32; | |
1551 | break; | |
1552 | default: | |
1553 | abort (); | |
1554 | } | |
252b5132 RH |
1555 | } |
1556 | else | |
e0c6ed95 | 1557 | intr->r_type = fix_ptr->fx_r_type; |
252b5132 RH |
1558 | |
1559 | intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base; | |
1560 | intr->r_offset = fix_ptr->fx_offset; | |
1561 | ||
1562 | if (symbol_ptr) | |
1563 | intr->r_symndx = symbol_ptr->sy_number; | |
1564 | else | |
1565 | intr->r_symndx = -1; | |
1566 | } |