Home | History | Annotate | Line # | Download | only in gas
frags.h revision 1.1.1.8
      1      1.1  christos /* frags.h - Header file for the frag concept.
      2  1.1.1.8  christos    Copyright (C) 1987-2025 Free Software Foundation, Inc.
      3      1.1  christos 
      4      1.1  christos    This file is part of GAS, the GNU Assembler.
      5      1.1  christos 
      6      1.1  christos    GAS is free software; you can redistribute it and/or modify
      7      1.1  christos    it under the terms of the GNU General Public License as published by
      8      1.1  christos    the Free Software Foundation; either version 3, or (at your option)
      9      1.1  christos    any later version.
     10      1.1  christos 
     11      1.1  christos    GAS is distributed in the hope that it will be useful,
     12      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14      1.1  christos    GNU General Public License for more details.
     15      1.1  christos 
     16      1.1  christos    You should have received a copy of the GNU General Public License
     17      1.1  christos    along with GAS; see the file COPYING.  If not, write to the Free
     18      1.1  christos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     19      1.1  christos    02110-1301, USA.  */
     20      1.1  christos 
     21      1.1  christos #ifndef FRAGS_H
     22      1.1  christos #define FRAGS_H
     23      1.1  christos 
     24      1.1  christos /* A code fragment (frag) is some known number of chars, followed by some
     25      1.1  christos    unknown number of chars. Typically the unknown number of chars is an
     26      1.1  christos    instruction address whose size is yet unknown. We always know the greatest
     27      1.1  christos    possible size the unknown number of chars may become, and reserve that
     28      1.1  christos    much room at the end of the frag.
     29      1.1  christos    Once created, frags do not change address during assembly.
     30      1.1  christos    We chain the frags in (a) forward-linked list(s). The object-file address
     31      1.1  christos    of the 1st char of a frag is generally not known until after relax().
     32      1.1  christos    Many things at assembly time describe an address by {object-file-address
     33      1.1  christos    of a particular frag}+offset.
     34      1.1  christos 
     35      1.1  christos    BUG: it may be smarter to have a single pointer off to various different
     36      1.1  christos    notes for different frag kinds.  See how code pans.  */
     37      1.1  christos 
     38      1.1  christos struct frag {
     39      1.1  christos   /* Object file address (as an octet offset).  */
     40      1.1  christos   addressT fr_address;
     41      1.1  christos   /* When relaxing multiple times, remember the address the frag had
     42      1.1  christos      in the last relax pass.  */
     43      1.1  christos   addressT last_fr_address;
     44      1.1  christos 
     45      1.1  christos   /* (Fixed) number of octets we know we have.  May be 0.  */
     46  1.1.1.5  christos   valueT fr_fix;
     47  1.1.1.8  christos   /* May be used for (Variable) number of octets after above.  */
     48      1.1  christos   offsetT fr_var;
     49      1.1  christos   /* For variable-length tail.  */
     50      1.1  christos   offsetT fr_offset;
     51      1.1  christos   /* For variable-length tail.  */
     52      1.1  christos   symbolS *fr_symbol;
     53      1.1  christos   /* Points to opcode low addr byte, for relaxation.  */
     54      1.1  christos   char *fr_opcode;
     55      1.1  christos 
     56      1.1  christos   /* Chain forward; ascending address order.  Rooted in frch_root.  */
     57      1.1  christos   struct frag *fr_next;
     58      1.1  christos 
     59      1.1  christos   /* Where the frag was created, or where it became a variant frag.  */
     60  1.1.1.3  christos   const char *fr_file;
     61      1.1  christos   unsigned int fr_line;
     62      1.1  christos 
     63      1.1  christos #ifndef NO_LISTING
     64      1.1  christos   struct list_info_struct *line;
     65      1.1  christos #endif
     66      1.1  christos 
     67      1.1  christos   /* A serial number for a sequence of frags having at most one alignment
     68      1.1  christos      or org frag, and that at the tail of the sequence.  */
     69      1.1  christos   unsigned int region:16;
     70      1.1  christos 
     71      1.1  christos   /* Flipped each relax pass so we can easily determine whether
     72      1.1  christos      fr_address has been adjusted.  */
     73      1.1  christos   unsigned int relax_marker:1;
     74      1.1  christos 
     75      1.1  christos   /* Used to ensure that all insns are emitted on proper address
     76      1.1  christos      boundaries.  */
     77      1.1  christos   unsigned int has_code:1;
     78      1.1  christos   unsigned int insn_addr:6;
     79      1.1  christos 
     80      1.1  christos   /* What state is my tail in? */
     81      1.1  christos   relax_stateT fr_type;
     82      1.1  christos   relax_substateT fr_subtype;
     83      1.1  christos 
     84      1.1  christos #ifdef USING_CGEN
     85      1.1  christos   /* Don't include this unless using CGEN to keep frag size down.  */
     86      1.1  christos   struct {
     87      1.1  christos     /* CGEN_INSN entry for this instruction.  */
     88      1.1  christos     const struct cgen_insn *insn;
     89      1.1  christos     /* Index into operand table.  */
     90      1.1  christos     int opindex;
     91      1.1  christos     /* Target specific data, usually reloc number.  */
     92      1.1  christos     int opinfo;
     93      1.1  christos   } fr_cgen;
     94      1.1  christos #endif
     95      1.1  christos 
     96      1.1  christos #ifdef TC_FRAG_TYPE
     97      1.1  christos   TC_FRAG_TYPE tc_frag_data;
     98      1.1  christos #endif
     99      1.1  christos #ifdef OBJ_FRAG_TYPE
    100      1.1  christos   OBJ_FRAG_TYPE obj_frag_data;
    101      1.1  christos #endif
    102      1.1  christos 
    103      1.1  christos   /* Data begins here.  */
    104      1.1  christos   char fr_literal[1];
    105      1.1  christos };
    106      1.1  christos 
    107      1.1  christos #define SIZEOF_STRUCT_FRAG \
    108      1.1  christos ((char *) zero_address_frag.fr_literal - (char *) &zero_address_frag)
    109      1.1  christos /* We want to say fr_literal[0] above.  */
    110      1.1  christos 
    111      1.1  christos /* Current frag we are building.  This frag is incomplete.  It is,
    112      1.1  christos    however, included in frchain_now.  The fr_fix field is bogus;
    113      1.1  christos    instead, use frag_now_fix ().  */
    114      1.1  christos COMMON fragS *frag_now;
    115      1.1  christos extern addressT frag_now_fix (void);
    116      1.1  christos extern addressT frag_now_fix_octets (void);
    117      1.1  christos 
    118      1.1  christos /* For foreign-segment symbol fixups.  */
    119      1.1  christos COMMON fragS zero_address_frag;
    120      1.1  christos COMMON fragS predefined_address_frag;
    121      1.1  christos 
    122      1.1  christos extern void frag_append_1_char (int);
    123      1.1  christos #define FRAG_APPEND_1_CHAR(X) frag_append_1_char (X)
    124      1.1  christos 
    125      1.1  christos void frag_init (void);
    126  1.1.1.8  christos fragS *frag_alloc (struct obstack *, size_t);
    127  1.1.1.2  christos void frag_grow (size_t nchars);
    128  1.1.1.2  christos char *frag_more (size_t nchars);
    129      1.1  christos void frag_align (int alignment, int fill_character, int max);
    130      1.1  christos void frag_align_pattern (int alignment, const char *fill_pattern,
    131  1.1.1.2  christos 			 size_t n_fill, int max);
    132      1.1  christos void frag_align_code (int alignment, int max);
    133  1.1.1.2  christos void frag_new (size_t old_frags_var_max_size);
    134      1.1  christos void frag_wane (fragS * fragP);
    135  1.1.1.2  christos size_t frag_room (void);
    136      1.1  christos 
    137      1.1  christos char *frag_variant (relax_stateT type,
    138  1.1.1.2  christos 		    size_t max_chars,
    139  1.1.1.2  christos 		    size_t var,
    140      1.1  christos 		    relax_substateT subtype,
    141      1.1  christos 		    symbolS * symbol,
    142      1.1  christos 		    offsetT offset,
    143      1.1  christos 		    char *opcode);
    144      1.1  christos 
    145      1.1  christos char *frag_var (relax_stateT type,
    146  1.1.1.2  christos 		size_t max_chars,
    147  1.1.1.2  christos 		size_t var,
    148      1.1  christos 		relax_substateT subtype,
    149      1.1  christos 		symbolS * symbol,
    150      1.1  christos 		offsetT offset,
    151      1.1  christos 		char *opcode);
    152      1.1  christos 
    153  1.1.1.6  christos bool frag_offset_fixed_p (const fragS *, const fragS *, offsetT *);
    154  1.1.1.6  christos bool frag_offset_ignore_align_p (const fragS *, const fragS *, offsetT *);
    155  1.1.1.6  christos bool frag_gtoffset_p (valueT, const fragS *, valueT, const fragS *, offsetT *);
    156      1.1  christos 
    157  1.1.1.8  christos unsigned int get_frag_count (void);
    158  1.1.1.2  christos void clear_frag_count (void);
    159  1.1.1.2  christos 
    160      1.1  christos #endif /* FRAGS_H */
    161