Skip to content

Commit

Permalink
Fix alignment of data segments
Browse files Browse the repository at this point in the history
  • Loading branch information
tilk committed Nov 3, 2023
1 parent 65832ed commit e36cd38
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions test/regression/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,21 @@ def load_segment(segment: Segment, *, disable_write_protection: bool = False) ->
if flags_raw & P_FLAGS.PF_X:
flags |= SegmentFlags.EXECUTABLE

config = CoreConfiguration()
if flags_raw & P_FLAGS.PF_X:
# align only instruction section to full icache lines
align_bits = CoreConfiguration().icache_block_size_bits
# align instruction section to full icache lines
align_bits = config.icache_block_size_bits
else:
# align to memory words
align_bits = config.xlen // 8

align_data_front = seg_start - align_down_to_power_of_two(seg_start, align_bits)
align_data_back = align_to_power_of_two(seg_end, align_bits) - seg_end
align_data_front = seg_start - align_down_to_power_of_two(seg_start, align_bits)
align_data_back = align_to_power_of_two(seg_end, align_bits) - seg_end

data = b"\x00" * align_data_front + data + b"\x00" * align_data_back
data = b"\x00" * align_data_front + data + b"\x00" * align_data_back

seg_start = align_down_to_power_of_two(seg_start, align_bits)
seg_end = align_to_power_of_two(seg_end, align_bits)
seg_start = align_down_to_power_of_two(seg_start, align_bits)
seg_end = align_to_power_of_two(seg_end, align_bits)

return RandomAccessMemory(range(seg_start, seg_end), flags, data)

Expand Down

0 comments on commit e36cd38

Please sign in to comment.