@@ -202,19 +202,30 @@ def d_data(self):
202202 def d_bss (self ):
203203 self .section = BSS
204204
205+ def fill (self , section , amount , fill_byte ):
206+ if fill_byte is not None and section is BSS :
207+ raise ValueError ('fill in bss section not allowed' )
208+ if section is TEXT : # TODO: text section should be filled with NOPs
209+ raise ValueError ('fill/skip/align in text section not supported' )
210+ fill = int (fill_byte or 0 ).to_bytes (1 , 'little' ) * amount
211+ self .offsets [section ] += len (fill )
212+ if section is not BSS :
213+ self .sections [section ].append (fill )
214+
205215 def d_skip (self , amount , fill = None ):
206- s = self .section
207216 amount = int (amount )
208- if fill is not None and s is BSS :
209- raise ValueError ('fill not allowed in section %s' % s )
210- if s is BSS :
211- self .append_section (amount )
212- else :
213- fill = int (fill or 0 ).to_bytes (1 , 'little' ) * amount
214- self .append_section (fill )
217+ self .fill (self .section , amount , fill )
215218
216219 d_space = d_skip
217220
221+ def d_align (self , align = 4 , fill = None ):
222+ align = int (align )
223+ offs = self .offsets [self .section ]
224+ mod = offs % align
225+ if mod :
226+ amount = align - mod
227+ self .fill (self .section , amount , fill )
228+
218229 def d_set (self , symbol , expr ):
219230 value = int (expr ) # TODO: support more than just integers
220231 self .symbols .set_sym (symbol , ABS , None , value )
0 commit comments