Skip to content

Commit

Permalink
Align instruction sections to ICache lane size
Browse files Browse the repository at this point in the history
  • Loading branch information
piotro888 committed Oct 28, 2023
1 parent 14aa970 commit 2dd30d5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions test/regression/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dataclasses import dataclass, replace
from elftools.elf.constants import P_FLAGS
from elftools.elf.elffile import ELFFile, Segment
from coreblocks.params.configurations import CoreConfiguration

all = [
"ReplyStatus",
Expand Down Expand Up @@ -155,9 +156,20 @@ def load_segment(segment: Segment, *, disable_write_protection: bool = False) ->
if flags_raw & P_FLAGS.PF_X:
flags |= SegmentFlags.EXECUTABLE

# append safe memory region for instruction fetch prediction
seg_end += 0x10
data += b"\0" * 0x10
if flags_raw & P_FLAGS.PF_X:
# align only instruction section to full icache lines
alignment = 2 ** CoreConfiguration().icache_block_size_bits

def align_down(n: int) -> int:
return (n // alignment) * alignment

align_front = seg_start - align_down(seg_start)
align_back = align_down(seg_end + alignment - 1) - seg_end

data = b"\x00" * align_front + data + b"\x00" * align_back

seg_start -= align_front
seg_end += align_back

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

Expand Down

0 comments on commit 2dd30d5

Please sign in to comment.