1 /* frags.c - manage frags -
3 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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)
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.
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
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 struct obstack frags
; /* All, and only, frags live here. */
27 extern fragS zero_address_frag
;
28 extern fragS bss_address_frag
;
30 /* Initialization for frag routines. */
34 zero_address_frag
.fr_type
= rs_fill
;
35 bss_address_frag
.fr_type
= rs_fill
;
36 obstack_begin (&frags
, 5000);
42 * Try to augment current frag by nchars chars.
43 * If there is no room, close of the current frag with a ".fill 0"
44 * and begin a new frag. Unless the new frag has nchars chars available
45 * do not return. Do not set up any fields of *now_frag.
51 if (obstack_room (&frags
) < nchars
)
59 oldc
= frags
.chunk_size
;
60 frags
.chunk_size
= 2 * nchars
;
61 while ((n
= obstack_room (&frags
)) < nchars
&& n
< oldn
)
67 frags
.chunk_size
= oldc
;
69 if (obstack_room (&frags
) < nchars
)
70 as_fatal ("Can't extend frag %d. chars", nchars
);
76 * Call this to close off a completed frag, and start up a new (empty)
77 * frag, in the same subsegment as the old frag.
78 * [frchain_now remains the same but frag_now is updated.]
79 * Because this calculates the correct value of fr_fix by
80 * looking at the obstack 'frags', it needs to know how many
81 * characters at the end of the old frag belong to (the maximal)
82 * fr_var: the rest must belong to fr_fix.
83 * It doesn't actually set up the old frag's fr_var: you may have
84 * set fr_var == 1, but allocated 10 chars to the end of the frag:
85 * in this case you pass old_frags_var_max_size == 10.
87 * Make a new frag, initialising some components. Link new frag at end
91 frag_new (old_frags_var_max_size
)
92 int old_frags_var_max_size
;/* Number of chars (already allocated on
94 /* in variable_length part of frag. */
96 register fragS
*former_last_fragP
;
97 register frchainS
*frchP
;
100 frag_now
->fr_fix
= frag_now_fix () - old_frags_var_max_size
;
101 /* Fix up old frag's fr_fix. */
103 obstack_finish (&frags
);
104 /* This will align the obstack so the next struct we allocate on it
105 will begin at a correct boundary. */
108 former_last_fragP
= frchP
->frch_last
;
109 know (former_last_fragP
);
110 know (former_last_fragP
== frag_now
);
111 obstack_blank (&frags
, SIZEOF_STRUCT_FRAG
);
112 /* We expect this will begin at a correct boundary for a struct. */
113 tmp
= obstack_alignment_mask (&frags
);
114 obstack_alignment_mask (&frags
) = 0; /* Turn off alignment */
115 /* If we ever hit a machine where strings must be aligned, we Lose
117 frag_now
= (fragS
*) obstack_finish (&frags
);
118 obstack_alignment_mask (&frags
) = tmp
; /* Restore alignment */
120 /* Just in case we don't get zero'd bytes */
121 memset (frag_now
, '\0', SIZEOF_STRUCT_FRAG
);
123 /* Generally, frag_now->points to an address rounded up to next
124 alignment. However, characters will add to obstack frags
125 IMMEDIATELY after the struct frag, even if they are not starting
126 at an alignment address. */
127 former_last_fragP
->fr_next
= frag_now
;
128 frchP
->frch_last
= frag_now
;
132 extern struct list_info_struct
*listing_tail
;
133 frag_now
->line
= listing_tail
;
137 frag_now
->fr_next
= NULL
;
143 * Start a new frag unless we have n more chars of room in the current frag.
144 * Close off the old frag with a .fill 0.
146 * Return the address of the 1st char to write into. Advance
147 * frag_now_growth past the new chars.
154 register char *retval
;
156 if (now_seg
== absolute_section
)
158 as_bad ("attempt to allocate data in absolute section");
159 subseg_set (text_section
, 0);
162 if (mri_common_symbol
!= NULL
)
164 as_bad ("attempt to allocate data in common section");
165 mri_common_symbol
= NULL
;
169 retval
= obstack_next_free (&frags
);
170 obstack_blank_fast (&frags
, nchars
);
177 * Start a new frag unless we have max_chars more chars of room in the current frag.
178 * Close off the old frag with a .fill 0.
180 * Set up a machine_dependent relaxable frag, then start a new frag.
181 * Return the address of the 1st char of the var part of the old frag
186 frag_var (type
, max_chars
, var
, subtype
, symbol
, offset
, opcode
)
190 relax_substateT subtype
;
195 register char *retval
;
197 frag_grow (max_chars
);
198 retval
= obstack_next_free (&frags
);
199 obstack_blank_fast (&frags
, max_chars
);
200 frag_now
->fr_var
= var
;
201 frag_now
->fr_type
= type
;
202 frag_now
->fr_subtype
= subtype
;
203 frag_now
->fr_symbol
= symbol
;
204 frag_now
->fr_offset
= offset
;
205 frag_now
->fr_opcode
= opcode
;
206 /* default these to zero. */
207 frag_now
->fr_pcrel_adjust
= 0;
208 frag_now
->fr_bsr
= 0;
209 frag_new (max_chars
);
216 * OVE: This variant of frag_var assumes that space for the tail has been
217 * allocated by caller.
218 * No call to frag_grow is done.
219 * Two new arguments have been added.
223 frag_variant (type
, max_chars
, var
, subtype
, symbol
, offset
, opcode
)
227 relax_substateT subtype
;
232 register char *retval
;
234 retval
= obstack_next_free (&frags
);
235 frag_now
->fr_var
= var
;
236 frag_now
->fr_type
= type
;
237 frag_now
->fr_subtype
= subtype
;
238 frag_now
->fr_symbol
= symbol
;
239 frag_now
->fr_offset
= offset
;
240 frag_now
->fr_opcode
= opcode
;
241 frag_now
->fr_pcrel_adjust
= 0;
242 frag_now
->fr_bsr
= 0;
243 frag_new (max_chars
);
245 } /* frag_variant() */
250 * Reduce the variable end of a frag to a harmless state.
254 register fragS
*fragP
;
256 fragP
->fr_type
= rs_fill
;
257 fragP
->fr_offset
= 0;
264 * Make a frag for ".align foo,bar". Call is "frag_align (foo,bar);".
265 * Foo & bar are absolute integers.
267 * Call to close off the current frag with a ".align", then start a new
268 * (so far empty) frag, in the same subsegment as the last frag.
272 frag_align (alignment
, fill_character
)
277 p
= frag_var (rs_align
, 1, 1, (relax_substateT
) 0,
278 (symbolS
*) 0, (long) alignment
, (char *) 0);
283 frag_align_pattern (alignment
, fill_pattern
, n_fill
)
285 const char *fill_pattern
;
289 p
= frag_var (rs_align
, n_fill
, n_fill
, (relax_substateT
) 0,
290 (symbolS
*) 0, (long) alignment
, (char *) 0);
291 memcpy (p
, fill_pattern
, n_fill
);
297 if (now_seg
== absolute_section
)
298 return abs_section_offset
;
299 return (char*)obstack_next_free (&frags
) - frag_now
->fr_literal
;
303 frag_append_1_char (datum
)
306 if (obstack_room (&frags
) <= 1)
308 frag_wane (frag_now
);
311 obstack_1grow (&frags
, datum
);
This page took 0.034846 seconds and 4 git commands to generate.