1 /* frags.c - manage frags -
2 Copyright (C) 1987, 1990, 1991 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 struct obstack frags; /* All, and only, frags live here. */
26 fragS zero_address_frag = {
34 rs_fill, /* fr_type */
36 0, /* fr_pcrel_adjust */
38 0 /* fr_literal [0] */
41 fragS bss_address_frag = {
42 0, /* fr_address. Gets filled in to make up
50 rs_fill, /* fr_type */
52 0, /* fr_pcrel_adjust */
54 0 /* fr_literal [0] */
61 * Try to augment current frag by nchars chars.
62 * If there is no room, close of the current frag with a ".fill 0"
63 * and begin a new frag. Unless the new frag has nchars chars available
64 * do not return. Do not set up any fields of *now_frag.
66 static void frag_grow(nchars)
69 if (obstack_room (&frags) < nchars) {
76 oldc=frags.chunk_size;
77 frags.chunk_size=2*nchars;
78 while((n=obstack_room(&frags))<nchars && n<oldn) {
83 frags.chunk_size=oldc;
85 if (obstack_room (&frags) < nchars)
86 as_fatal("Can't extend frag %d. chars", nchars);
92 * Call this to close off a completed frag, and start up a new (empty)
93 * frag, in the same subsegment as the old frag.
94 * [frchain_now remains the same but frag_now is updated.]
95 * Because this calculates the correct value of fr_fix by
96 * looking at the obstack 'frags', it needs to know how many
97 * characters at the end of the old frag belong to (the maximal)
98 * fr_var: the rest must belong to fr_fix.
99 * It doesn't actually set up the old frag's fr_var: you may have
100 * set fr_var == 1, but allocated 10 chars to the end of the frag:
101 * in this case you pass old_frags_var_max_size == 10.
103 * Make a new frag, initialising some components. Link new frag at end
106 void frag_new(old_frags_var_max_size)
107 int old_frags_var_max_size; /* Number of chars (already allocated on
109 /* in variable_length part of frag. */
111 register fragS * former_last_fragP;
112 /* char *throw_away_pointer; JF unused */
113 register frchainS * frchP;
116 frag_now->fr_fix = (char *) (obstack_next_free (&frags)) -
117 (frag_now->fr_literal) - old_frags_var_max_size;
118 /* Fix up old frag's fr_fix. */
120 obstack_finish (&frags);
121 /* This will align the obstack so the */
122 /* next struct we allocate on it will */
123 /* begin at a correct boundary. */
126 former_last_fragP = frchP->frch_last;
127 know (former_last_fragP);
128 know (former_last_fragP == frag_now);
129 obstack_blank (&frags, SIZEOF_STRUCT_FRAG);
130 /* We expect this will begin at a correct */
131 /* boundary for a struct. */
132 tmp=obstack_alignment_mask(&frags);
133 obstack_alignment_mask(&frags)=0; /* Turn off alignment */
134 /* If we ever hit a machine
135 where strings must be
136 aligned, we Lose Big */
137 frag_now=(fragS *)obstack_finish(&frags);
138 obstack_alignment_mask(&frags)=tmp; /* Restore alignment */
140 /* Just in case we don't get zero'd bytes */
141 bzero(frag_now, SIZEOF_STRUCT_FRAG);
143 /* obstack_unaligned_done (&frags, &frag_now); */
144 /* know (frags.obstack_c_next_free == frag_now->fr_literal); */
145 /* Generally, frag_now->points to an */
146 /* address rounded up to next alignment. */
147 /* However, characters will add to obstack */
148 /* frags IMMEDIATELY after the struct frag, */
149 /* even if they are not starting at an */
150 /* alignment address. */
151 former_last_fragP->fr_next = frag_now;
152 frchP->frch_last = frag_now;
156 extern struct list_info_struct *listing_tail;
157 frag_now->line = listing_tail;
161 frag_now->fr_next = NULL;
167 * Start a new frag unless we have n more chars of room in the current frag.
168 * Close off the old frag with a .fill 0.
170 * Return the address of the 1st char to write into. Advance
171 * frag_now_growth past the new chars.
174 char *frag_more (nchars)
177 register char *retval;
180 retval = obstack_next_free (&frags);
181 obstack_blank_fast (&frags, nchars);
188 * Start a new frag unless we have max_chars more chars of room in the current frag.
189 * Close off the old frag with a .fill 0.
191 * Set up a machine_dependent relaxable frag, then start a new frag.
192 * Return the address of the 1st char of the var part of the old frag
196 char *frag_var(type, max_chars, var, subtype, symbol, offset, opcode)
200 relax_substateT subtype;
205 register char *retval;
207 frag_grow (max_chars);
208 retval = obstack_next_free (&frags);
209 obstack_blank_fast (&frags, max_chars);
210 frag_now->fr_var = var;
211 frag_now->fr_type = type;
212 frag_now->fr_subtype = subtype;
213 frag_now->fr_symbol = symbol;
214 frag_now->fr_offset = offset;
215 frag_now->fr_opcode = opcode;
216 /* default these to zero. */
217 frag_now->fr_pcrel_adjust = 0;
218 frag_now->fr_bsr = 0;
219 frag_new (max_chars);
226 * OVE: This variant of frag_var assumes that space for the tail has been
227 * allocated by caller.
228 * No call to frag_grow is done.
229 * Two new arguments have been added.
232 char *frag_variant(type, max_chars, var, subtype, symbol, offset, opcode, pcrel_adjust,bsr)
236 relax_substateT subtype;
243 register char *retval;
245 /* frag_grow (max_chars); */
246 retval = obstack_next_free (&frags);
247 /* obstack_blank_fast (&frags, max_chars); */ /* OVE: so far the only diff */
248 frag_now->fr_var = var;
249 frag_now->fr_type = type;
250 frag_now->fr_subtype = subtype;
251 frag_now->fr_symbol = symbol;
252 frag_now->fr_offset = offset;
253 frag_now->fr_opcode = opcode;
254 frag_now->fr_pcrel_adjust = pcrel_adjust;
255 frag_now->fr_bsr = bsr;
256 frag_new (max_chars);
258 } /* frag_variant() */
263 * Reduce the variable end of a frag to a harmless state.
265 void frag_wane(fragP)
266 register fragS * fragP;
268 fragP->fr_type = rs_fill;
269 fragP->fr_offset = 0;
276 * Make a frag for ".align foo,bar". Call is "frag_align (foo,bar);".
277 * Foo & bar are absolute integers.
279 * Call to close off the current frag with a ".align", then start a new
280 * (so far empty) frag, in the same subsegment as the last frag.
283 void frag_align(alignment, fill_character)
287 *(frag_var (rs_align, 1, 1, (relax_substateT)0, (symbolS *)0,
288 (long)alignment, (char *)0)) = fill_character;