Skip to content

Commit 1180a2f

Browse files
have sections aligned at / end at 32bit boundaries
1 parent f25da34 commit 1180a2f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

demo.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ textend:
5454
data0: .skip 4, 0x23
5555
data1: .space 4, 0x42
5656
data2: .skip 4
57-
datab: .byte 1, 2, 3, 4
5857
dataw: .word 1, 2, 3, 4
5958
datal: .long 1, 2, 3, 4
59+
datab: .byte 1, 2, 3 # test alignment / fill up of section
6060
dataend:
6161

6262
.bss
6363
bss0: .skip 4
64-
bss1: .skip 2
64+
bss1: .skip 2 # test alignment / fill up of section
6565
bssend:

esp32_ulp/assemble.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ def append_section(self, value, expected_section=None):
6565
self.sections[s].append(value)
6666
self.offsets[s] += len(value)
6767

68+
def finalize_sections(self):
69+
# make sure all sections have a bytelength dividable by 4,
70+
# thus having all sections aligned at 32bit-word boundaries.
71+
for s in list(self.sections.keys()) + [BSS, ]:
72+
offs = self.offsets[s]
73+
mod = offs % 4
74+
if mod:
75+
fill = int(0).to_bytes(4 - mod, 'little')
76+
self.offsets[s] += len(fill)
77+
if s is not BSS:
78+
self.sections[s].append(fill)
79+
6880
def dump(self):
6981
print("Symbols:")
7082
for label, section_offset in sorted(self.symbols.items()):
@@ -144,4 +156,5 @@ def assemble(self, lines):
144156
self.append_section(instruction.to_bytes(4, 'little'), TEXT)
145157
continue
146158
raise Exception('Unknown opcode or directive: %s' % opcode)
159+
self.finalize_sections()
147160

0 commit comments

Comments
 (0)