1 /* This file is tc-tahoe.c
3 Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1995, 2000
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 /* This bit glommed from tahoe-inst.h. */
27 typedef unsigned char byte;
28 typedef byte tahoe_opcodeT;
30 /* This is part of tahoe-ins-parse.c & friends.
31 We want to parse a tahoe instruction text into a tree defined here. */
33 #define TIT_MAX_OPERANDS (4) /* maximum number of operands in one
34 single tahoe instruction */
36 struct top /* tahoe instruction operand */
38 int top_ndx; /* -1, or index register. eg 7=[R7] */
39 int top_reg; /* -1, or register number. eg 7 = R7 or (R7) */
40 byte top_mode; /* Addressing mode byte. This byte, defines
41 which of the 11 modes opcode is. */
43 char top_access; /* Access type wanted for this opperand
44 'b'branch ' 'no-instruction 'amrvw' */
45 char top_width; /* Operand width expected, one of "bwlq?-:!" */
47 char * top_error; /* Say if operand is inappropriate */
49 segT seg_of_operand; /* segment as returned by expression()*/
51 expressionS exp_of_operand; /* The expression as parsed by expression()*/
53 byte top_dispsize; /* Number of bytes in the displacement if we
57 /* The addressing modes for an operand. These numbers are the acutal values
58 for certain modes, so be carefull if you screw with them. */
59 #define TAHOE_DIRECT_REG (0x50)
60 #define TAHOE_REG_DEFERRED (0x60)
62 #define TAHOE_REG_DISP (0xE0)
63 #define TAHOE_REG_DISP_DEFERRED (0xF0)
65 #define TAHOE_IMMEDIATE (0x8F)
66 #define TAHOE_IMMEDIATE_BYTE (0x88)
67 #define TAHOE_IMMEDIATE_WORD (0x89)
68 #define TAHOE_IMMEDIATE_LONGWORD (0x8F)
69 #define TAHOE_ABSOLUTE_ADDR (0x9F)
71 #define TAHOE_DISPLACED_RELATIVE (0xEF)
72 #define TAHOE_DISP_REL_DEFERRED (0xFF)
74 #define TAHOE_AUTO_DEC (0x7E)
75 #define TAHOE_AUTO_INC (0x8E)
76 #define TAHOE_AUTO_INC_DEFERRED (0x9E)
77 /* INDEXED_REG is decided by the existance or lack of a [reg]. */
79 /* These are encoded into top_width when top_access=='b'
80 and it's a psuedo op. */
81 #define TAHOE_WIDTH_ALWAYS_JUMP '-'
82 #define TAHOE_WIDTH_CONDITIONAL_JUMP '?'
83 #define TAHOE_WIDTH_BIG_REV_JUMP '!'
84 #define TAHOE_WIDTH_BIG_NON_REV_JUMP ':'
86 /* The hex code for certain tahoe commands and modes.
87 This is just for readability. */
88 #define TAHOE_JMP (0x71)
89 #define TAHOE_PC_REL_LONG (0xEF)
90 #define TAHOE_BRB (0x11)
91 #define TAHOE_BRW (0x13)
92 /* These, when 'ored' with, or added to, a register number,
93 set up the number for the displacement mode. */
94 #define TAHOE_PC_OR_BYTE (0xA0)
95 #define TAHOE_PC_OR_WORD (0xC0)
96 #define TAHOE_PC_OR_LONG (0xE0)
98 struct tit /* Get it out of the sewer, it stands for
99 tahoe instruction tree (Geeze!). */
101 tahoe_opcodeT tit_opcode; /* The opcode. */
102 byte tit_operands; /* How many operands are here. */
103 struct top tit_operand[TIT_MAX_OPERANDS]; /* Operands */
104 char *tit_error; /* "" or fatal error text */
107 /* end: tahoe-inst.h */
109 /* tahoe.c - tahoe-specific -
113 #include "opcode/tahoe.h"
115 /* This is the number to put at the beginning of the a.out file */
116 long omagic = OMAGIC;
118 /* These chars start a comment anywhere in a source file (except inside
119 another comment or a quoted string. */
120 const char comment_chars[] = "#;";
122 /* These chars only start a comment at the beginning of a line. */
123 const char line_comment_chars[] = "#";
125 /* Chars that can be used to separate mant from exp in floating point nums */
126 const char EXP_CHARS[] = "eE";
128 /* Chars that mean this number is a floating point constant
130 or 0d1.234E-12 (see exp chars above)
131 Note: The Tahoe port doesn't support floating point constants. This is
132 consistant with 'as' If it's needed, I can always add it later. */
133 const char FLT_CHARS[] = "df";
135 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
136 changed in read.c . Ideally it shouldn't have to know about it at all,
137 but nothing is ideal around here.
138 (The tahoe has plenty of room, so the change currently isn't needed.)
141 static struct tit t; /* A tahoe instruction after decoding. */
144 /* A table of pseudo ops (sans .), the function called, and an integer op
145 that the function is called with. */
147 const pseudo_typeS md_pseudo_table[] =
149 {"dfloat", float_cons, 'd'},
150 {"ffloat", float_cons, 'f'},
155 * For Tahoe, relative addresses of "just the right length" are pretty easy.
156 * The branch displacement is always the last operand, even in
157 * synthetic instructions.
158 * For Tahoe, we encode the relax_substateTs (in e.g. fr_substate) as:
160 * 4 3 2 1 0 bit number
161 * ---/ /--+-------+-------+-------+-------+-------+
162 * | what state ? | how long ? |
163 * ---/ /--+-------+-------+-------+-------+-------+
165 * The "how long" bits are 00=byte, 01=word, 10=long.
166 * This is a Un*x convention.
167 * Not all lengths are legit for a given value of (what state).
168 * The four states are listed below.
169 * The "how long" refers merely to the displacement length.
170 * The address usually has some constant bytes in it as well.
173 States for Tahoe address relaxing.
174 1. TAHOE_WIDTH_ALWAYS_JUMP (-)
176 Tahoe opcodes are: (Hex)
180 Always, 1 byte opcode, then displacement/absolute.
181 If word or longword, change opcode to brw or jmp.
183 2. TAHOE_WIDTH_CONDITIONAL_JUMP (?)
184 J<cond> where <cond> is a simple flag test.
186 Tahoe opcodes are: (Hex)
199 Always, you complement 4th bit to reverse the condition.
200 Always, 1-byte opcode, then 1-byte displacement.
202 3. TAHOE_WIDTH_BIG_REV_JUMP (!)
203 Jbc/Jbs where cond tests a memory bit.
205 Tahoe opcodes are: (Hex)
208 Always, you complement 4th bit to reverse the condition.
209 Always, 1-byte opcde, longword, longword-address, 1-word-displacement
211 4. TAHOE_WIDTH_BIG_NON_REV_JUMP (:)
214 Tahoe opcodes are: (Hex)
220 Always, we cannot reverse the sense of the branch; we have a word
223 We need to modify the opcode is for class 1, 2 and 3 instructions.
224 After relax() we may complement the 4th bit of 2 or 3 to reverse sense of
227 We sometimes store context in the operand literal. This way we can figure out
228 after relax() what the original addressing mode was. (Was is pc_rel, or
229 pc_rel_disp? That sort of thing.) */
231 /* These displacements are relative to the START address of the
232 displacement which is at the start of the displacement, not the end of
233 the instruction. The hardware pc_rel is at the end of the instructions.
234 That's why all the displacements have the length of the displacement added
235 to them. (WF + length(word))
237 The first letter is Byte, Word.
238 2nd letter is Forward, Backward. */
241 #define WF (2+ 32767)
242 #define WB (2+-32768)
243 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
245 #define C(a,b) ENCODE_RELAX(a,b)
246 /* This macro has no side-effects. */
247 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
248 #define RELAX_STATE(what) ((what) >> 2)
249 #define RELAX_LENGTH(length) ((length) && 3)
251 #define STATE_ALWAYS_BRANCH (1)
252 #define STATE_CONDITIONAL_BRANCH (2)
253 #define STATE_BIG_REV_BRANCH (3)
254 #define STATE_BIG_NON_REV_BRANCH (4)
255 #define STATE_PC_RELATIVE (5)
257 #define STATE_BYTE (0)
258 #define STATE_WORD (1)
259 #define STATE_LONG (2)
260 #define STATE_UNDF (3) /* Symbol undefined in pass1 */
262 /* This is the table used by gas to figure out relaxing modes. The fields are
263 forward_branch reach, backward_branch reach, number of bytes it would take,
264 where the next biggest branch is. */
265 const relax_typeS md_relax_table[] =
269 }, /* error sentinel 0,0 */
279 /* Unconditional branch cases "jrb"
280 The relax part is the actual displacement */
283 }, /* brb B`foo 1,0 */
286 }, /* brw W`foo 1,1 */
289 }, /* Jmp L`foo 1,2 */
293 /* Reversible Conditional Branch. If the branch won't reach, reverse
294 it, and jump over a brw or a jmp that will reach. The relax part is the
298 }, /* b<cond> B`foo 2,0 */
300 WF + 2, WB + 2, 4, C (2, 2)
301 }, /* brev over, brw W`foo, over: 2,1 */
304 }, /* brev over, jmp L`foo, over: 2,2 */
308 /* Another type of reversable branch. But this only has a word
315 }, /* jbX W`foo 3,1 */
318 }, /* jrevX over, jmp L`foo, over: 3,2 */
322 /* These are the non reversable branches, all of which have a word
323 displacement. If I can't reach, branch over a byte branch, to a
324 jump that will reach. The jumped branch jumps over the reaching
325 branch, to continue with the flow of the program. It's like playing
332 }, /* aobl_ W`foo 4,1 */
335 }, /*aobl_ W`hop,br over,hop: jmp L^foo,over 4,2*/
339 /* Normal displacement mode, no jumping or anything like that.
340 The relax points to one byte before the address, thats why all
341 the numbers are up by one. */
343 BF + 1, BB + 1, 2, C (5, 1)
346 WF + 1, WB + 1, 3, C (5, 2)
361 /* End relax stuff */
363 /* Handle of the OPCODE hash table. NULL means any use before
364 md_begin() will crash. */
365 static struct hash_control *op_hash;
367 /* Init function. Build the hash table. */
373 int synthetic_too = 1; /* If 0, just use real opcodes. */
375 op_hash = hash_new ();
377 for (tP = totstrs; *tP->name && !errorval; tP++)
378 errorval = hash_insert (op_hash, tP->name, &tP->detail);
381 for (tP = synthetic_totstrs; *tP->name && !errorval; tP++)
382 errorval = hash_insert (op_hash, tP->name, &tP->detail);
388 CONST char *md_shortopts = "ad:STt:V";
389 struct option md_longopts[] = {
390 {NULL, no_argument, NULL, 0}
392 size_t md_longopts_size = sizeof (md_longopts);
395 md_parse_option (c, arg)
402 as_warn (_("The -a option doesn't exist. (Despite what the man page says!"));
406 as_warn (_("Displacement length %s ignored!"), arg);
410 as_warn (_("SYMBOL TABLE not implemented"));
414 as_warn (_("TOKEN TRACE not implemented"));
418 as_warn (_("I don't need or use temp. file \"%s\"."), arg);
422 as_warn (_("I don't use an interpass file! -V ignored"));
433 md_show_usage (stream)
436 fprintf (stream, _("\
447 /* The functions in this section take numbers in the machine format, and
448 munges them into Tahoe byte order.
449 They exist primarily for cross assembly purpose. */
450 void /* Knows about order of bytes in address. */
451 md_number_to_chars (con, value, nbytes)
452 char con[]; /* Return 'nbytes' of chars here. */
453 valueT value; /* The value of the bits. */
454 int nbytes; /* Number of bytes in the output. */
456 number_to_chars_bigendian (con, value, nbytes);
460 void /* Knows about order of bytes in address. */
461 md_number_to_imm (con, value, nbytes)
462 char con[]; /* Return 'nbytes' of chars here. */
463 long int value; /* The value of the bits. */
464 int nbytes; /* Number of bytes in the output. */
466 md_number_to_chars (con, value, nbytes);
472 tc_apply_fix (fixP, val)
476 /* should never be called */
480 void /* Knows about order of bytes in address. */
481 md_number_to_disp (con, value, nbytes)
482 char con[]; /* Return 'nbytes' of chars here. */
483 long int value; /* The value of the bits. */
484 int nbytes; /* Number of bytes in the output. */
486 md_number_to_chars (con, value, nbytes);
489 void /* Knows about order of bytes in address. */
490 md_number_to_field (con, value, nbytes)
491 char con[]; /* Return 'nbytes' of chars here. */
492 long int value; /* The value of the bits. */
493 int nbytes; /* Number of bytes in the output. */
495 md_number_to_chars (con, value, nbytes);
498 /* Put the bits in an order that a tahoe will understand, despite the ordering
499 of the native machine.
500 On Tahoe: first 4 bytes are normal unsigned big endian long,
501 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
502 The last byte is broken up with bit 7 as pcrel,
503 bits 6 & 5 as length,
504 bit 4 as extern and the last nibble as 'undefined'. */
508 md_ri_to_chars (ri_p, ri)
509 struct relocation_info *ri_p, ri;
511 byte the_bytes[sizeof (struct relocation_info)];
512 /* The reason I can't just encode these directly into ri_p is that
513 ri_p may point to ri. */
516 md_number_to_chars (the_bytes, ri.r_address, sizeof (ri.r_address));
518 /* now the fun stuff */
519 the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
520 the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
521 the_bytes[6] = ri.r_symbolnum & 0x0ff;
522 the_bytes[7] = (((ri.r_extern << 4) & 0x10) | ((ri.r_length << 5) & 0x60) |
523 ((ri.r_pcrel << 7) & 0x80)) & 0xf0;
525 bcopy (the_bytes, (char *) ri_p, sizeof (struct relocation_info));
530 /* Put the bits in an order that a tahoe will understand, despite the ordering
531 of the native machine.
532 On Tahoe: first 4 bytes are normal unsigned big endian long,
533 next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
534 The last byte is broken up with bit 7 as pcrel,
535 bits 6 & 5 as length,
536 bit 4 as extern and the last nibble as 'undefined'. */
539 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
542 relax_addressT segment_address_in_file;
546 know (fixP->fx_addsy != NULL);
548 md_number_to_chars (where,
549 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
552 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
553 ? S_GET_TYPE (fixP->fx_addsy)
554 : fixP->fx_addsy->sy_number);
556 where[4] = (r_symbolnum >> 16) & 0x0ff;
557 where[5] = (r_symbolnum >> 8) & 0x0ff;
558 where[6] = r_symbolnum & 0x0ff;
559 where[7] = (((is_pcrel (fixP) << 7) & 0x80)
560 | ((((fixP->fx_type == FX_8 || fixP->fx_type == FX_PCREL8
562 : (fixP->fx_type == FX_16 || fixP->fx_type == FX_PCREL16
564 : (fixP->fx_type == FX_32 || fixP->fx_type == FX_PCREL32
566 : 42)))) << 5) & 0x60)
567 | ((!S_IS_DEFINED (fixP->fx_addsy) << 4) & 0x10));
570 /* Relocate byte stuff */
572 /* This is for broken word. */
573 const int md_short_jump_size = 3;
576 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
578 addressT from_addr, to_addr;
584 offset = to_addr - (from_addr + 1);
586 md_number_to_chars (ptr, offset, 2);
589 const int md_long_jump_size = 6;
590 const int md_reloc_size = 8; /* Size of relocation record */
593 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
595 addressT from_addr, to_addr;
601 offset = to_addr - (from_addr + 4);
603 *ptr++ = TAHOE_PC_REL_LONG;
604 md_number_to_chars (ptr, offset, 4);
608 * md_estimate_size_before_relax()
610 * Called just before relax().
611 * Any symbol that is now undefined will not become defined, so we assumed
612 * that it will be resolved by the linker.
613 * Return the correct fr_subtype in the frag, for relax()
614 * Return the initial "guess for fr_var" to caller. (How big I think this
616 * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
617 * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
618 * Although it may not be explicit in the frag, pretend fr_var starts with a
622 md_estimate_size_before_relax (fragP, segment_type)
623 register fragS *fragP;
624 segT segment_type; /* N_DATA or N_TEXT. */
627 register int old_fr_fix;
628 /* int pc_rel; FIXME: remove this */
630 old_fr_fix = fragP->fr_fix;
631 switch (fragP->fr_subtype)
633 case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF):
634 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
636 /* The symbol was in the same segment as the opcode, and it's
637 a real pc_rel case so it's a relaxable case. */
638 fragP->fr_subtype = ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE);
642 /* This case is still undefined, so asume it's a long word for the
644 p = fragP->fr_literal + old_fr_fix;
645 *p |= TAHOE_PC_OR_LONG;
646 /* We now know how big it will be, one long word. */
647 fragP->fr_fix += 1 + 4;
648 fix_new (fragP, old_fr_fix + 1, fragP->fr_symbol,
649 fragP->fr_offset, FX_PCREL32, NULL);
654 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_UNDF):
655 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
657 fragP->fr_subtype = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
661 p = fragP->fr_literal + old_fr_fix;
662 *fragP->fr_opcode ^= 0x10; /* Reverse sense of branch. */
665 *p++ = TAHOE_PC_REL_LONG;
666 fragP->fr_fix += 1 + 1 + 1 + 4;
667 fix_new (fragP, old_fr_fix + 3, fragP->fr_symbol,
668 fragP->fr_offset, FX_PCREL32, NULL);
673 case ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_UNDF):
674 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
677 ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_WORD);
681 p = fragP->fr_literal + old_fr_fix;
682 *fragP->fr_opcode ^= 0x10; /* Reverse sense of branch. */
686 *p++ = TAHOE_PC_REL_LONG;
687 fragP->fr_fix += 2 + 2 + 4;
688 fix_new (fragP, old_fr_fix + 4, fragP->fr_symbol,
689 fragP->fr_offset, FX_PCREL32, NULL);
694 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_UNDF):
695 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
697 fragP->fr_subtype = ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_WORD);
701 p = fragP->fr_literal + old_fr_fix;
707 *p++ = TAHOE_PC_REL_LONG;
708 fragP->fr_fix += 2 + 2 + 2 + 4;
709 fix_new (fragP, old_fr_fix + 6, fragP->fr_symbol,
710 fragP->fr_offset, FX_PCREL32, NULL);
715 case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_UNDF):
716 if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
718 fragP->fr_subtype = ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE);
722 p = fragP->fr_literal + old_fr_fix;
723 *fragP->fr_opcode = TAHOE_JMP;
724 *p++ = TAHOE_PC_REL_LONG;
725 fragP->fr_fix += 1 + 4;
726 fix_new (fragP, old_fr_fix + 1, fragP->fr_symbol,
727 fragP->fr_offset, FX_PCREL32, NULL);
735 return (fragP->fr_var + fragP->fr_fix - old_fr_fix);
736 } /* md_estimate_size_before_relax() */
741 * Called after relax() is finished.
742 * In: Address of frag.
743 * fr_type == rs_machine_dependent.
744 * fr_subtype is what the address relaxed to.
746 * Out: Any fixSs and constants are set up.
747 * Caller will turn frag into a ".space 0".
750 md_convert_frag (headers, seg, fragP)
751 object_headers *headers;
753 register fragS *fragP;
755 register char *addressP; /* -> _var to change. */
756 register char *opcodeP; /* -> opcode char(s) to change. */
757 register short int length_code; /* 2=long 1=word 0=byte */
758 register short int extension = 0; /* Size of relaxed address.
759 Added to fr_fix: incl. ALL var chars. */
760 register symbolS *symbolP;
761 register long int where;
762 register long int address_of_var;
763 /* Where, in file space, is _var of *fragP? */
764 register long int target_address;
765 /* Where, in file space, does addr point? */
767 know (fragP->fr_type == rs_machine_dependent);
768 length_code = RELAX_LENGTH (fragP->fr_subtype);
769 know (length_code >= 0 && length_code < 3);
770 where = fragP->fr_fix;
771 addressP = fragP->fr_literal + where;
772 opcodeP = fragP->fr_opcode;
773 symbolP = fragP->fr_symbol;
775 target_address = S_GET_VALUE (symbolP) + fragP->fr_offset;
776 address_of_var = fragP->fr_address + where;
777 switch (fragP->fr_subtype)
779 case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE):
780 /* *addressP holds the registers number, plus 0x10, if it's deferred
781 mode. To set up the right mode, just OR the size of this displacement */
782 /* Byte displacement. */
783 *addressP++ |= TAHOE_PC_OR_BYTE;
784 *addressP = target_address - (address_of_var + 2);
788 case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_WORD):
789 /* Word displacement. */
790 *addressP++ |= TAHOE_PC_OR_WORD;
791 md_number_to_chars (addressP, target_address - (address_of_var + 3), 2);
795 case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_LONG):
796 /* Long word displacement. */
797 *addressP++ |= TAHOE_PC_OR_LONG;
798 md_number_to_chars (addressP, target_address - (address_of_var + 5), 4);
802 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
803 *addressP = target_address - (address_of_var + 1);
807 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
808 *opcodeP ^= 0x10; /* Reverse sense of test. */
809 *addressP++ = 3; /* Jump over word branch */
810 *addressP++ = TAHOE_BRW;
811 md_number_to_chars (addressP, target_address - (address_of_var + 4), 2);
815 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_LONG):
816 *opcodeP ^= 0x10; /* Reverse sense of test. */
818 *addressP++ = TAHOE_JMP;
819 *addressP++ = TAHOE_PC_REL_LONG;
820 md_number_to_chars (addressP, target_address, 4);
824 case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE):
825 *addressP = target_address - (address_of_var + 1);
829 case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_WORD):
830 *opcodeP = TAHOE_BRW;
831 md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
835 case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_LONG):
836 *opcodeP = TAHOE_JMP;
837 *addressP++ = TAHOE_PC_REL_LONG;
838 md_number_to_chars (addressP, target_address - (address_of_var + 5), 4);
842 case ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_WORD):
843 md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
847 case ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_LONG):
851 *addressP++ = TAHOE_JMP;
852 *addressP++ = TAHOE_PC_REL_LONG;
853 md_number_to_chars (addressP, target_address, 4);
857 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_WORD):
858 md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
862 case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_LONG):
865 *addressP++ = TAHOE_BRB;
867 *addressP++ = TAHOE_JMP;
868 *addressP++ = TAHOE_PC_REL_LONG;
869 md_number_to_chars (addressP, target_address, 4);
874 BAD_CASE (fragP->fr_subtype);
877 fragP->fr_fix += extension;
878 } /* md_convert_frag */
881 /* This is the stuff for md_assemble. */
885 #define BIGGESTREG PC_REG
888 * Parse the string pointed to by START
889 * If it represents a valid register, point START to the character after
890 * the last valid register char, and return the register number (0-15).
891 * If invalid, leave START alone, return -1.
892 * The format has to be exact. I don't do things like eat leading zeros
894 * Note: This doesn't check for the next character in the string making
895 * this invalid. Ex: R123 would return 12, it's the callers job to check
896 * what start is point to apon return.
898 * Valid registers are R1-R15, %1-%15, FP (13), SP (14), PC (15)
899 * Case doesn't matter.
902 tahoe_reg_parse (start)
903 char **start; /* A pointer to the string to parse. */
905 register char *regpoint = *start;
906 register int regnum = -1;
910 case '%': /* Registers can start with a %,
911 R or r, and then a number. */
914 if (isdigit (*regpoint))
916 /* Got the first digit. */
917 regnum = *regpoint++ - '0';
918 if ((regnum == 1) && isdigit (*regpoint))
920 /* Its a two digit number. */
921 regnum = 10 + (*regpoint++ - '0');
922 if (regnum > BIGGESTREG)
923 { /* Number too big? */
929 case 'F': /* Is it the FP */
938 case 's': /* How about the SP */
947 case 'p': /* OR the PC even */
959 { /* No error, so move string pointer */
962 return regnum; /* Return results */
963 } /* tahoe_reg_parse */
966 * This chops up an operand and figures out its modes and stuff.
967 * It's a little touchy about extra characters.
968 * Optex to start with one extra character so it can be overwritten for
969 * the backward part of the parsing.
970 * You can't put a bunch of extra characters in side to
971 * make the command look cute. ie: * foo ( r1 ) [ r0 ]
972 * If you like doing a lot of typing, try COBOL!
973 * Actually, this parser is a little weak all around. It's designed to be
974 * used with compliers, so I emphisise correct decoding of valid code quickly
975 * rather that catching every possable error.
976 * Note: This uses the expression function, so save input_line_pointer before
979 * Sperry defines the semantics of address modes (and values)
980 * by a two-letter code, explained here.
982 * letter 1: access type
984 * a address calculation - no data access, registers forbidden
985 * b branch displacement
986 * m read - let go of bus - write back "modify"
989 * v bit field address: like 'a' but registers are OK
991 * letter 2: data type (i.e. width, alignment)
996 * q quadword (Even regs < 14 allowed) (if 12, you get a warning)
997 * - unconditional synthetic jbr operand
998 * ? simple synthetic reversable branch operand
999 * ! complex synthetic reversable branch operand
1000 * : complex synthetic non-reversable branch operand
1002 * The '-?!:' letter 2's are not for external consumption. They are used
1003 * by GAS for psuedo ops relaxing code.
1005 * After parsing topP has:
1007 * top_ndx: -1, or the index register. eg 7=[R7]
1008 * top_reg: -1, or register number. eg 7 = R7 or (R7)
1009 * top_mode: The addressing mode byte. This byte, defines which of
1010 * the 11 modes opcode is.
1011 * top_access: Access type wanted for this opperand 'b'branch ' '
1012 * no-instruction 'amrvw'
1013 * top_width: Operand width expected, one of "bwlq?-:!"
1014 * exp_of_operand: The expression as parsed by expression()
1015 * top_dispsize: Number of bytes in the displacement if we can figure it
1016 * out and it's relavent.
1018 * Need syntax checks built.
1022 tip_op (optex, topP)
1023 char *optex; /* The users text input, with one leading character */
1024 struct top *topP; /* The tahoe instruction with some fields already set:
1026 out: ndx, reg, mode, error, dispsize */
1029 int mode = 0; /* This operand's mode. */
1030 char segfault = *optex; /* To keep the back parsing from freaking. */
1031 char *point = optex + 1; /* Parsing from front to back. */
1032 char *end; /* Parsing from back to front. */
1033 int reg = -1; /* major register, -1 means absent */
1034 int imreg = -1; /* Major register in immediate mode */
1035 int ndx = -1; /* index register number, -1 means absent */
1036 char dec_inc = ' '; /* Is the SP auto-incremented '+' or
1037 auto-decremented '-' or neither ' '. */
1038 int immediate = 0; /* 1 if '$' immediate mode */
1039 int call_width = 0; /* If the caller casts the displacement */
1040 int abs_width = 0; /* The width of the absolute displacment */
1041 int com_width = 0; /* Displacement width required by branch */
1042 int deferred = 0; /* 1 if '*' deferral is used */
1043 byte disp_size = 0; /* How big is this operand. 0 == don't know */
1044 char *op_bad = ""; /* Bad operand error */
1046 char *tp, *temp, c; /* Temporary holders */
1048 char access = topP->top_access; /* Save on a deref. */
1049 char width = topP->top_width;
1051 int really_none = 0; /* Empty expressions evaluate to 0
1052 but I need to know if it's there or not */
1053 expressionS *expP; /* -> expression values for this operand */
1055 /* Does this command restrict the displacement size. */
1057 com_width = (width == 'b' ? 1 :
1059 (width == 'l' ? 4 : 0)));
1061 *optex = '\0'; /* This is kind of a back stop for all
1062 the searches to fail on if needed.*/
1064 { /* A dereference? */
1069 /* Force words into a certain mode */
1070 /* Bitch, Bitch, Bitch! */
1072 * Using the ^ operator is ambigous. If I have an absolute label
1073 * called 'w' set to, say 2, and I have the expression 'w^1', do I get
1074 * 1, forced to be in word displacement mode, or do I get the value of
1075 * 'w' or'ed with 1 (3 in this case).
1076 * The default is 'w' as an offset, so that's what I use.
1077 * Stick with `, it does the same, and isn't ambig.
1080 if (*point != '\0' && ((point[1] == '^') || (point[1] == '`')))
1090 as_warn (_("Casting a branch displacement is bad form, and is ignored."));
1093 c = (isupper (*point) ? tolower (*point) : *point);
1094 call_width = ((c == 'b') ? 1 :
1095 ((c == 'w') ? 2 : 4));
1101 /* Setting immediate mode */
1109 * I've pulled off all the easy stuff off the front, move to the end and
1113 for (end = point; *end != '\0'; end++) /* Move to the end. */
1116 if (end != point) /* Null string? */
1119 if (end > point && *end == ' ' && end[-1] != '\'')
1120 end--; /* Hop white space */
1122 /* Is this an index reg. */
1123 if ((*end == ']') && (end[-1] != '\''))
1127 /* Find opening brace. */
1128 for (--end; (*end != '[' && end != point); end--)
1131 /* If I found the opening brace, get the index register number. */
1134 tp = end + 1; /* tp should point to the start of a reg. */
1135 ndx = tahoe_reg_parse (&tp);
1137 { /* Reg. parse error. */
1142 end--; /* Found it, move past brace. */
1146 op_bad = _("Couldn't parse the [index] in this operand.");
1147 end = point; /* Force all the rest of the tests to fail. */
1152 op_bad = _("Couldn't find the opening '[' for the index of this operand.");
1153 end = point; /* Force all the rest of the tests to fail. */
1157 /* Post increment? */
1165 /* register in parens? */
1166 if ((*end == ')') && (end[-1] != '\''))
1170 /* Find opening paren. */
1171 for (--end; (*end != '(' && end != point); end--)
1174 /* If I found the opening paren, get the register number. */
1178 reg = tahoe_reg_parse (&tp);
1181 /* Not a register, but could be part of the expression. */
1183 end = temp; /* Rest the pointer back */
1187 end--; /* Found the reg. move before opening paren. */
1192 op_bad = _("Couldn't find the opening '(' for the deref of this operand.");
1193 end = point; /* Force all the rest of the tests to fail. */
1197 /* Pre decrement? */
1202 op_bad = _("Operand can't be both pre-inc and post-dec.");
1214 * Everything between point and end is the 'expression', unless it's
1222 imreg = tahoe_reg_parse (&point); /* Get the immediate register
1226 /* If there is junk after point, then the it's not immediate reg. */
1231 if (imreg != -1 && reg != -1)
1232 op_bad = _("I parsed 2 registers in this operand.");
1235 * Evaluate whats left of the expression to see if it's valid.
1236 * Note again: This assumes that the calling expression has saved
1237 * input_line_pointer. (Nag, nag, nag!)
1240 if (*op_bad == '\0')
1242 /* Statement has no syntax goofs yet: let's sniff the expression. */
1243 input_line_pointer = point;
1244 expP = &(topP->exp_of_operand);
1245 topP->seg_of_operand = expression (expP);
1249 /* No expression. For BSD4.2 compatibility, missing expression is
1251 expP->X_op = O_constant;
1252 expP->X_add_number = 0;
1255 /* for SEG_ABSOLUTE, we shouldnt need to set X_op_symbol,
1256 X_add_symbol to any particular value. */
1257 /* But, we will program defensively. Since this situation occurs
1258 rarely so it costs us little to do so. */
1259 expP->X_add_symbol = NULL;
1260 expP->X_op_symbol = NULL;
1261 /* How many bytes are needed to express this abs value? */
1263 ((((expP->X_add_number & 0xFFFFFF80) == 0) ||
1264 ((expP->X_add_number & 0xFFFFFF80) == 0xFFFFFF80)) ? 1 :
1265 (((expP->X_add_number & 0xFFFF8000) == 0) ||
1266 ((expP->X_add_number & 0xFFFF8000) == 0xFFFF8000)) ? 2 : 4);
1273 * Major bug. We can't handle the case of a operator
1274 * expression in a synthetic opcode variable-length
1275 * instruction. We don't have a frag type that is smart
1276 * enough to relax a operator, and so we just force all
1277 * operators to behave like SEG_PASS1s. Clearly, if there is
1278 * a demand we can invent a new or modified frag type and
1279 * then coding up a frag for this case will be easy.
1282 op_bad = _("Can't relocate expression error.");
1286 /* This is an error. Tahoe doesn't allow any expressions
1287 bigger that a 32 bit long word. Any bigger has to be referenced
1289 op_bad = _("Expression is too large for a 32 bits.");
1292 if (*input_line_pointer != '\0')
1294 op_bad = _("Junk at end of expression.");
1300 /* I'm done, so restore optex */
1304 * At this point in the game, we (in theory) have all the components of
1305 * the operand at least parsed. Now it's time to check for syntax/semantic
1306 * errors, and build the mode.
1307 * This is what I have:
1308 * deferred = 1 if '*'
1309 * call_width = 0,1,2,4
1310 * abs_width = 0,1,2,4
1311 * com_width = 0,1,2,4
1312 * immediate = 1 if '$'
1313 * ndx = -1 or reg num
1314 * dec_inc = '-' or '+' or ' '
1315 * reg = -1 or reg num
1316 * imreg = -1 or reg num
1317 * topP->exp_of_operand
1320 /* Is there a displacement size? */
1321 disp_size = (call_width ? call_width :
1322 (com_width ? com_width :
1323 abs_width ? abs_width : 0));
1325 if (*op_bad == '\0')
1330 mode = TAHOE_DIRECT_REG;
1331 if (deferred || immediate || (dec_inc != ' ') ||
1332 (reg != -1) || !really_none)
1333 op_bad = _("Syntax error in direct register mode.");
1335 op_bad = _("You can't index a register in direct register mode.");
1336 else if (imreg == SP_REG && access == 'r')
1338 _("SP can't be the source operand with direct register addressing.");
1339 else if (access == 'a')
1340 op_bad = _("Can't take the address of a register.");
1341 else if (access == 'b')
1342 op_bad = _("Direct Register can't be used in a branch.");
1343 else if (width == 'q' && ((imreg % 2) || (imreg > 13)))
1344 op_bad = _("For quad access, the register must be even and < 14.");
1345 else if (call_width)
1346 op_bad = _("You can't cast a direct register.");
1348 if (*op_bad == '\0')
1350 /* No errors, check for warnings */
1351 if (width == 'q' && imreg == 12)
1352 as_warn (_("Using reg 14 for quadwords can tromp the FP register."));
1357 /* We know: imm = -1 */
1359 else if (dec_inc == '-')
1362 mode = TAHOE_AUTO_DEC;
1363 if (deferred || immediate || !really_none)
1364 op_bad = _("Syntax error in auto-dec mode.");
1366 op_bad = _("You can't have an index auto dec mode.");
1367 else if (access == 'r')
1368 op_bad = _("Auto dec mode cant be used for reading.");
1369 else if (reg != SP_REG)
1370 op_bad = _("Auto dec only works of the SP register.");
1371 else if (access == 'b')
1372 op_bad = _("Auto dec can't be used in a branch.");
1373 else if (width == 'q')
1374 op_bad = _("Auto dec won't work with quadwords.");
1376 /* We know: imm = -1, dec_inc != '-' */
1378 else if (dec_inc == '+')
1380 if (immediate || !really_none)
1381 op_bad = _("Syntax error in one of the auto-inc modes.");
1385 mode = TAHOE_AUTO_INC_DEFERRED;
1387 op_bad = _("Auto inc deferred only works of the SP register.");
1389 op_bad = _("You can't have an index auto inc deferred mode.");
1390 else if (access == 'b')
1391 op_bad = _("Auto inc can't be used in a branch.");
1396 mode = TAHOE_AUTO_INC;
1397 if (access == 'm' || access == 'w')
1398 op_bad = _("You can't write to an auto inc register.");
1399 else if (reg != SP_REG)
1400 op_bad = _("Auto inc only works of the SP register.");
1401 else if (access == 'b')
1402 op_bad = _("Auto inc can't be used in a branch.");
1403 else if (width == 'q')
1404 op_bad = _("Auto inc won't work with quadwords.");
1406 op_bad = _("You can't have an index in auto inc mode.");
1409 /* We know: imm = -1, dec_inc == ' ' */
1413 if ((ndx != -1) && (reg == SP_REG))
1414 op_bad = _("You can't index the sp register.");
1418 mode = TAHOE_REG_DISP_DEFERRED;
1420 op_bad = _("Syntax error in register displaced mode.");
1422 else if (really_none)
1425 mode = TAHOE_REG_DEFERRED;
1426 /* if reg = SP then cant be indexed */
1431 mode = TAHOE_REG_DISP;
1434 /* We know: imm = -1, dec_inc == ' ', Reg = -1 */
1439 op_bad = _("An offest is needed for this operand.");
1440 if (deferred && immediate)
1443 mode = TAHOE_ABSOLUTE_ADDR;
1449 mode = TAHOE_IMMEDIATE;
1451 op_bad = _("You can't index a register in immediate mode.");
1453 op_bad = _("Immediate access can't be used as an address.");
1454 /* ponder the wisdom of a cast because it doesn't do any good. */
1459 mode = TAHOE_DISP_REL_DEFERRED;
1464 mode = TAHOE_DISPLACED_RELATIVE;
1470 * At this point, all the errors we can do have be checked for.
1471 * We can build the 'top'. */
1473 topP->top_ndx = ndx;
1474 topP->top_reg = reg;
1475 topP->top_mode = mode;
1476 topP->top_error = op_bad;
1477 topP->top_dispsize = disp_size;
1483 * This converts a string into a tahoe instruction.
1484 * The string must be a bare single instruction in tahoe (with BSD4 frobs)
1486 * It provides at most one fatal error message (which stops the scan)
1487 * some warning messages as it finds them.
1488 * The tahoe instruction is returned in exploded form.
1490 * The exploded instruction is returned to a struct tit of your choice.
1491 * #include "tahoe-inst.h" to know what a struct tit is.
1496 tip (titP, instring)
1497 struct tit *titP; /* We build an exploded instruction here. */
1498 char *instring; /* Text of a vax instruction: we modify. */
1500 register struct tot_wot *twP = NULL; /* How to bit-encode this opcode. */
1501 register char *p; /* 1/skip whitespace.2/scan vot_how */
1502 register char *q; /* */
1503 register unsigned char count; /* counts number of operands seen */
1504 register struct top *operandp;/* scan operands in struct tit */
1505 register char *alloperr = ""; /* error over all operands */
1506 register char c; /* Remember char, (we clobber it
1507 with '\0' temporarily). */
1508 char *save_input_line_pointer;
1510 if (*instring == ' ')
1511 ++instring; /* Skip leading whitespace. */
1512 for (p = instring; *p && *p != ' '; p++)
1513 ; /* MUST end in end-of-string or
1515 /* Scanned up to end of operation-code. */
1516 /* Operation-code is ended with whitespace. */
1519 titP->tit_error = _("No operator");
1521 titP->tit_opcode = 0;
1528 * Here with instring pointing to what better be an op-name, and p
1529 * pointing to character just past that.
1530 * We trust instring points to an op-name, with no whitespace.
1532 twP = (struct tot_wot *) hash_find (op_hash, instring);
1533 *p = c; /* Restore char after op-code. */
1536 titP->tit_error = _("Unknown operator");
1538 titP->tit_opcode = 0;
1543 * We found a match! So let's pick up as many operands as the
1544 * instruction wants, and even gripe if there are too many.
1545 * We expect comma to seperate each operand.
1546 * We let instring track the text, while p tracks a part of the
1550 count = 0; /* no operands seen yet */
1551 instring = p + (*p != '\0'); /* point past the operation code */
1552 /* tip_op() screws with the input_line_pointer, so save it before
1554 save_input_line_pointer = input_line_pointer;
1555 for (p = twP->args, operandp = titP->tit_operand;
1560 * Here to parse one operand. Leave instring pointing just
1561 * past any one ',' that marks the end of this operand.
1564 as_fatal (_("Compiler bug: ODD number of bytes in arg structure %s."),
1568 for (q = instring; (*q != ',' && *q != '\0'); q++)
1570 if (*q == '\'' && q[1] != '\0') /* Jump quoted characters */
1575 * Q points to ',' or '\0' that ends argument. C is that
1579 operandp->top_access = p[0];
1580 operandp->top_width = p[1];
1581 tip_op (instring - 1, operandp);
1582 *q = c; /* Restore input text. */
1583 if (*(operandp->top_error))
1585 alloperr = operandp->top_error;
1587 instring = q + (c ? 1 : 0); /* next operand (if any) */
1588 count++; /* won another argument, may have an operr */
1591 alloperr = _("Not enough operands");
1593 /* Restore the pointer. */
1594 input_line_pointer = save_input_line_pointer;
1598 if (*instring == ' ')
1599 instring++; /* Skip whitespace. */
1601 alloperr = _("Too many operands");
1603 titP->tit_error = alloperr;
1607 titP->tit_opcode = twP->code; /* The op-code. */
1608 titP->tit_operands = count;
1611 /* md_assemble() emit frags for 1 instruction */
1613 md_assemble (instruction_string)
1614 char *instruction_string; /* A string: assemble 1 instruction. */
1617 register struct top *operandP;/* An operand. Scans all operands. */
1618 /* char c_save; fixme: remove this line *//* What used to live after an expression. */
1619 /* struct frag *fragP; fixme: remove this line *//* Fragment of code we just made. */
1620 /* register struct top *end_operandP; fixme: remove this line *//* -> slot just after last operand
1621 Limit of the for (each operand). */
1622 register expressionS *expP; /* -> expression values for this operand */
1624 /* These refer to an instruction operand expression. */
1625 segT to_seg; /* Target segment of the address. */
1627 register valueT this_add_number;
1628 register symbolS *this_add_symbol; /* +ve (minuend) symbol. */
1630 /* tahoe_opcodeT opcode_as_number; fixme: remove this line *//* The opcode as a number. */
1631 char *opcodeP; /* Where it is in a frag. */
1632 /* char *opmodeP; fixme: remove this line *//* Where opcode type is, in a frag. */
1634 int dispsize; /* From top_dispsize: tahoe_operand_width
1636 int is_undefined; /* 1 if operand expression's
1637 segment not known yet. */
1638 int pc_rel; /* Is this operand pc relative? */
1640 /* Decode the operand. */
1641 tip (&t, instruction_string);
1644 * Check to see if this operand decode properly.
1645 * Notice that we haven't made any frags yet.
1646 * If it goofed, then this instruction will wedge in any pass,
1647 * and we can safely flush it, without causing interpass symbol phase
1648 * errors. That is, without changing label values in different passes.
1652 as_warn (_("Ignoring statement due to \"%s\""), t.tit_error);
1656 /* We saw no errors in any operands - try to make frag(s) */
1658 /* Remember where it is, in case we want to modify the op-code later. */
1659 opcodeP = frag_more (1);
1660 *opcodeP = t.tit_opcode;
1661 /* Now do each operand. */
1662 for (operandP = t.tit_operand;
1663 operandP < t.tit_operand + t.tit_operands;
1665 { /* for each operand */
1666 expP = &(operandP->exp_of_operand);
1667 if (operandP->top_ndx >= 0)
1669 /* Indexed addressing byte
1670 Legality of indexed mode already checked: it is OK */
1671 FRAG_APPEND_1_CHAR (0x40 + operandP->top_ndx);
1672 } /* if(top_ndx>=0) */
1674 /* Here to make main operand frag(s). */
1675 this_add_number = expP->X_add_number;
1676 this_add_symbol = expP->X_add_symbol;
1677 to_seg = operandP->seg_of_operand;
1678 know (to_seg == SEG_UNKNOWN || \
1679 to_seg == SEG_ABSOLUTE || \
1680 to_seg == SEG_DATA || \
1681 to_seg == SEG_TEXT || \
1683 is_undefined = (to_seg == SEG_UNKNOWN);
1684 /* Do we know how big this opperand is? */
1685 dispsize = operandP->top_dispsize;
1687 /* Deal with the branch possabilities. (Note, this doesn't include
1689 if (operandP->top_access == 'b')
1691 /* Branches must be expressions. A psuedo branch can also jump to
1692 an absolute address. */
1693 if (to_seg == now_seg || is_undefined)
1695 /* If is_undefined, then it might BECOME now_seg by relax time. */
1698 /* I know how big the branch is supposed to be (it's a normal
1699 branch), so I set up the frag, and let GAS do the rest. */
1700 p = frag_more (dispsize);
1701 fix_new (frag_now, p - frag_now->fr_literal,
1702 this_add_symbol, this_add_number,
1703 size_to_fx (dispsize, 1),
1708 /* (to_seg==now_seg || to_seg == SEG_UNKNOWN) && dispsize==0 */
1709 /* If we don't know how big it is, then its a synthetic branch,
1710 so we set up a simple relax state. */
1711 switch (operandP->top_width)
1713 case TAHOE_WIDTH_CONDITIONAL_JUMP:
1714 /* Simple (conditional) jump. I may have to reverse the
1715 condition of opcodeP, and then jump to my destination.
1716 I set 1 byte aside for the branch off set, and could need 6
1717 more bytes for the pc_rel jump */
1718 frag_var (rs_machine_dependent, 7, 1,
1719 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH,
1720 is_undefined ? STATE_UNDF : STATE_BYTE),
1721 this_add_symbol, this_add_number, opcodeP);
1723 case TAHOE_WIDTH_ALWAYS_JUMP:
1724 /* Simple (unconditional) jump. I may have to convert this to
1725 a word branch, or an absolute jump. */
1726 frag_var (rs_machine_dependent, 5, 1,
1727 ENCODE_RELAX (STATE_ALWAYS_BRANCH,
1728 is_undefined ? STATE_UNDF : STATE_BYTE),
1729 this_add_symbol, this_add_number, opcodeP);
1731 /* The smallest size for the next 2 cases is word. */
1732 case TAHOE_WIDTH_BIG_REV_JUMP:
1733 frag_var (rs_machine_dependent, 8, 2,
1734 ENCODE_RELAX (STATE_BIG_REV_BRANCH,
1735 is_undefined ? STATE_UNDF : STATE_WORD),
1736 this_add_symbol, this_add_number,
1739 case TAHOE_WIDTH_BIG_NON_REV_JUMP:
1740 frag_var (rs_machine_dependent, 10, 2,
1741 ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH,
1742 is_undefined ? STATE_UNDF : STATE_WORD),
1743 this_add_symbol, this_add_number,
1747 as_fatal (_("Compliler bug: Got a case (%d) I wasn't expecting."),
1748 operandP->top_width);
1754 /* to_seg != now_seg && to_seg != seg_unknown (still in branch)
1755 In other words, I'm jumping out of my segment so extend the
1756 branches to jumps, and let GAS fix them. */
1758 /* These are "branches" what will always be branches around a jump
1759 to the correct addresss in real life.
1760 If to_seg is SEG_ABSOLUTE, just encode the branch in,
1761 else let GAS fix the address. */
1763 switch (operandP->top_width)
1766 For SEG_ABSOLUTE, then mode is ABSOLUTE_ADDR, jump
1767 to that addresss (not pc_rel).
1768 For other segs, address is a long word PC rel jump. */
1769 case TAHOE_WIDTH_CONDITIONAL_JUMP:
1771 /* To reverse the condition in a TAHOE branch,
1777 *p++ = (operandP->top_mode ==
1778 TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1780 fix_new (frag_now, p - frag_now->fr_literal,
1781 this_add_symbol, this_add_number,
1782 (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1789 case TAHOE_WIDTH_ALWAYS_JUMP:
1790 /* br, just turn it into a jump */
1791 *opcodeP = TAHOE_JMP;
1793 *p++ = (operandP->top_mode ==
1794 TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1796 fix_new (frag_now, p - frag_now->fr_literal,
1797 this_add_symbol, this_add_number,
1798 (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1799 /* Now (eg) JMP foo */
1801 case TAHOE_WIDTH_BIG_REV_JUMP:
1807 *p++ = (operandP->top_mode ==
1808 TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1810 fix_new (frag_now, p - frag_now->fr_literal,
1811 this_add_symbol, this_add_number,
1812 (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1819 case TAHOE_WIDTH_BIG_NON_REV_JUMP:
1826 *p++ = (operandP->top_mode ==
1827 TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1829 fix_new (frag_now, p - frag_now->fr_literal,
1830 this_add_symbol, this_add_number,
1831 (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1833 * Now (eg) xOBxxx 1f
1841 as_warn (_("Real branch displacements must be expressions."));
1844 as_fatal (_("Complier error: I got an unknown synthetic branch :%c"),
1845 operandP->top_width);
1852 /* It ain't a branch operand. */
1853 switch (operandP->top_mode)
1855 /* Auto-foo access, only works for one reg (SP)
1856 so the only thing needed is the mode. */
1857 case TAHOE_AUTO_DEC:
1858 case TAHOE_AUTO_INC:
1859 case TAHOE_AUTO_INC_DEFERRED:
1860 FRAG_APPEND_1_CHAR (operandP->top_mode);
1863 /* Numbered Register only access. Only thing needed is the
1864 mode + Register number */
1865 case TAHOE_DIRECT_REG:
1866 case TAHOE_REG_DEFERRED:
1867 FRAG_APPEND_1_CHAR (operandP->top_mode + operandP->top_reg);
1870 /* An absolute address. It's size is always 5 bytes.
1871 (mode_type + 4 byte address). */
1872 case TAHOE_ABSOLUTE_ADDR:
1873 know ((this_add_symbol == NULL));
1875 *p = TAHOE_ABSOLUTE_ADDR;
1876 md_number_to_chars (p + 1, this_add_number, 4);
1879 /* Immediate data. If the size isn't known, then it's an address
1880 + and offset, which is 4 bytes big. */
1881 case TAHOE_IMMEDIATE:
1882 if (this_add_symbol != NULL)
1885 *p++ = TAHOE_IMMEDIATE_LONGWORD;
1886 fix_new (frag_now, p - frag_now->fr_literal,
1887 this_add_symbol, this_add_number,
1892 /* It's a integer, and I know it's size. */
1893 if ((unsigned) this_add_number < 0x40)
1895 /* Will it fit in a literal? */
1896 FRAG_APPEND_1_CHAR ((byte) this_add_number);
1900 p = frag_more (dispsize + 1);
1904 *p++ = TAHOE_IMMEDIATE_BYTE;
1905 *p = (byte) this_add_number;
1908 *p++ = TAHOE_IMMEDIATE_WORD;
1909 md_number_to_chars (p, this_add_number, 2);
1912 *p++ = TAHOE_IMMEDIATE_LONGWORD;
1913 md_number_to_chars (p, this_add_number, 4);
1920 /* Distance from the PC. If the size isn't known, we have to relax
1921 into it. The difference between this and disp(sp) is that
1922 this offset is pc_rel, and disp(sp) isn't.
1923 Note the drop through code. */
1925 case TAHOE_DISPLACED_RELATIVE:
1926 case TAHOE_DISP_REL_DEFERRED:
1927 operandP->top_reg = PC_REG;
1930 /* Register, plus a displacement mode. Save the register number,
1931 and weather its deffered or not, and relax the size if it isn't
1933 case TAHOE_REG_DISP:
1934 case TAHOE_REG_DISP_DEFERRED:
1935 if (operandP->top_mode == TAHOE_DISP_REL_DEFERRED ||
1936 operandP->top_mode == TAHOE_REG_DISP_DEFERRED)
1937 operandP->top_reg += 0x10; /* deffered mode is always 0x10 higher
1938 than it's non-deffered sibling. */
1940 /* Is this a value out of this segment?
1941 The first part of this conditional is a cludge to make gas
1942 produce the same output as 'as' when there is a lable, in
1943 the current segment, displaceing a register. It's strange,
1944 and no one in their right mind would do it, but it's easy
1946 if ((dispsize == 0 && !pc_rel) ||
1947 (to_seg != now_seg && !is_undefined && to_seg != SEG_ABSOLUTE))
1953 * We have a SEG_UNKNOWN symbol, or the size isn't cast.
1954 * It might turn out to be in the same segment as
1955 * the instruction, permitting relaxation.
1957 p = frag_var (rs_machine_dependent, 5, 2,
1958 ENCODE_RELAX (STATE_PC_RELATIVE,
1959 is_undefined ? STATE_UNDF : STATE_BYTE),
1960 this_add_symbol, this_add_number, 0);
1961 *p = operandP->top_reg;
1965 /* Either this is an abs, or a cast. */
1966 p = frag_more (dispsize + 1);
1970 *p = TAHOE_PC_OR_BYTE + operandP->top_reg;
1973 *p = TAHOE_PC_OR_WORD + operandP->top_reg;
1976 *p = TAHOE_PC_OR_LONG + operandP->top_reg;
1979 fix_new (frag_now, p + 1 - frag_now->fr_literal,
1980 this_add_symbol, this_add_number,
1981 size_to_fx (dispsize, pc_rel), NULL);
1985 as_fatal (_("Barf, bad mode %x\n"), operandP->top_mode);
1988 } /* for(operandP) */
1989 } /* if(!need_pass_2 && !goofed) */
1990 } /* tahoe_assemble() */
1992 /* We have no need to default values of symbols. */
1995 md_undefined_symbol (name)
1999 } /* md_undefined_symbol() */
2001 /* Round up a section size to the appropriate boundary. */
2003 md_section_align (segment, size)
2007 return ((size + 7) & ~7); /* Round all sects to multiple of 8 */
2008 } /* md_section_align() */
2010 /* Exactly what point is a PC-relative offset relative TO?
2011 On the sparc, they're relative to the address of the offset, plus
2012 its size. This gets us to the following instruction.
2013 (??? Is this right? FIXME-SOON) */
2015 md_pcrel_from (fixP)
2018 return (((fixP->fx_type == FX_8
2019 || fixP->fx_type == FX_PCREL8)
2021 : ((fixP->fx_type == FX_16
2022 || fixP->fx_type == FX_PCREL16)
2024 : ((fixP->fx_type == FX_32
2025 || fixP->fx_type == FX_PCREL32)
2027 : 0))) + fixP->fx_where + fixP->fx_frag->fr_address);
2028 } /* md_pcrel_from() */
2034 /* should never be called */
2037 } /* tc_is_pcrel() */