1#ifndef _FRAGS_H_ 2#define _FRAGS_H_ 3/* frags.h - Header file for the frag concept. 4 Copyright (C) 1987 Free Software Foundation, Inc. 5 6This file is part of GAS, the GNU Assembler. 7 8GAS is free software; you can redistribute it and/or modify 9it under the terms of the GNU General Public License as published by 10the Free Software Foundation; either version 1, or (at your option) 11any later version. 12 13GAS is distributed in the hope that it will be useful, 14but WITHOUT ANY WARRANTY; without even the implied warranty of 15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16GNU General Public License for more details. 17 18You should have received a copy of the GNU General Public License 19along with GAS; see the file COPYING. If not, write to 20the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 21 22#import "as.h" 23#import "relax.h" 24#import "struc-symbol.h" 25 26/* 27 * A code fragment (frag) is some known number of chars, followed by some 28 * unknown number of chars. Typically the unknown number of chars is an 29 * instruction address whose size is yet unknown. We always know the greatest 30 * possible size the unknown number of chars may become, and reserve that 31 * much room at the end of the frag. 32 * Once created, frags do not change address during assembly. 33 * We chain the frags in (a) forward-linked list(s). The object-file address 34 * of the 1st char of a frag is generally not known until after relax(). 35 * Many things at assembly time describe an address by {object-file-address 36 * of a particular frag}+offset. 37 38 BUG: it may be smarter to have a single pointer off to various different 39notes for different frag kinds. See how code pans out. 40 41 */ 42struct frag /* a code fragment */ 43{ 44 uint64_t fr_address; /* Object file address. */ 45 uint64_t last_fr_address; /* When relaxing multiple times, remember the */ 46 /* address the frag had in the last relax pass*/ 47 struct frag *fr_next; /* Chain forward; ascending address order. */ 48 /* Rooted in frch_root. */ 49 50 int32_t fr_fix; /* (Fixed) number of chars we know we have. */ 51 /* May be 0. */ 52 int32_t fr_var; /* (Variable) number of chars after above. */ 53 /* May be 0. */ 54 struct symbol *fr_symbol; /* For variable-length tail. */ 55 int32_t fr_offset; /* For variable-length tail. */ 56 char *fr_opcode; /* ->opcode low addr byte,for relax()ation*/ 57 relax_stateT fr_type; /* What state is my tail in? */ 58 relax_substateT fr_subtype; /* Used to index in to md_relax_table for */ 59 /* fr_type == rs_machine_dependent frags. */ 60#ifdef ARM 61 /* Where the frag was created, or where it became a variant frag. */ 62 char *fr_file; 63 unsigned int fr_line; 64 /* Flipped each relax pass so we can easily determine whether 65 fr_address has been adjusted. */ 66 unsigned int relax_marker:1, 67 pad:31; 68#endif /* ARM */ 69 char fr_literal[1]; /* Chars begin here. */ 70 /* One day we will compile fr_literal[0]. */ 71}; 72 73/* We want to say fr_literal[0] below */ 74#define SIZEOF_STRUCT_FRAG \ 75 ((uintptr_t)zero_address_frag.fr_literal - (uintptr_t)&zero_address_frag) 76 77/* 78 * frag_now points at the current frag we are building. This frag is incomplete. 79 * It is, however, included in frchain_now. Frag_now->fr_fix is not the total 80 * bytes in use for the frag. For that use: 81 * frag_now->fr_fix + obstack_next_free(&frags) - frag_now->fr_literal. 82 */ 83extern fragS *frag_now; 84extern addressT frag_now_fix (void); 85extern addressT frag_now_fix_octets (void); 86 87/* 88 * Frags ONLY live in this obstack. We use obstack_next_free() macro 89 * so please don't put any other objects on this stack! 90 */ 91extern struct obstack frags; 92 93/* For foreign-segment symbol fixups. */ 94extern fragS zero_address_frag; 95 96void frag_grow (unsigned int nchars); 97extern void frag_new( 98 int old_frags_var_max_size); 99extern char * frag_more( 100 int nchars); 101extern char *frag_var( 102 relax_stateT type, 103 int max_chars, 104 int var, 105 relax_substateT subtype, 106 symbolS *symbol, 107 int32_t offset, 108 char *opcode); 109extern void frag_wane( 110 fragS *fragP); 111extern void frag_align( 112 int power_of_2_alignment, 113 char *fill, 114 int fill_size, 115 int max_bytes_to_fill); 116 117/* 118 * A macro to speed up appending exactly 1 char 119 * to current frag. 120 */ 121/* JF changed < 1 to <= 1 to avoid a race conditon */ 122#define FRAG_APPEND_1_CHAR(datum) \ 123{ \ 124 if (obstack_room( &frags ) <= 1) {\ 125 frag_wane (frag_now); \ 126 frag_new (0); \ 127 } \ 128 (void)obstack_1grow( &frags, datum ); \ 129} 130#endif /* _FRAGS_H_ */ 131