-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[otbn] Allow sim to compare result to dmem
Signed-off-by: Amin Abdulrahman <[email protected]>
- Loading branch information
Showing
8 changed files
with
164 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Copyright lowRISC contributors (OpenTitan project). | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import re | ||
import struct | ||
from typing import Dict | ||
|
||
from hw.ip.otbn.util.shared.mem_layout import get_memory_layout | ||
|
||
_DMEM_RE = re.compile( | ||
r'\s*(?P<label>[a-zA-Z0-9_]+)\s*:\s*(?P<val>(:?[0-9a-f]+))$') | ||
|
||
|
||
def parse_dmem_exp(dump: str) -> Dict[str, int]: | ||
'''Parse the expected dmem. | ||
Format: | ||
label: hex_data | ||
Returns a dictionary mapping labels to the expected bytes. | ||
''' | ||
|
||
out = {} | ||
for line in dump.split('\n'): | ||
# Remove comments and ignore blank lines. | ||
line = line.split('#', 1)[0].strip() | ||
if not line: | ||
continue | ||
m = _DMEM_RE.match(line) | ||
if not m: | ||
raise ValueError(f'Failed to parse dmem dump line ({line}).') | ||
label = m.group('label') | ||
value = bytes.fromhex(m.group('val')) | ||
|
||
if label in out: | ||
raise ValueError(f'DMEM dump contains multiple values ' | ||
f'for {label}.') | ||
out[label] = value | ||
|
||
return out | ||
|
||
|
||
def parse_actual_dmem(dump: bytes) -> bytes: | ||
'''Parse the dmem dump. | ||
Returns the dmem bytes except integrity info. | ||
''' | ||
dmem_bytes = [] | ||
# 8 32-bit data words + 1 byte integrity info per word = 40 bytes | ||
bytes_w_integrity = 8 * 4 + 8 | ||
for w in struct.iter_unpack(f"<{bytes_w_integrity}s", dump): | ||
tmp = [] | ||
# discard byte indicating integrity status | ||
for v in struct.iter_unpack("<BI", w[0]): | ||
tmp += [x for x in struct.unpack("4B", v[1].to_bytes(4, "big"))] | ||
dmem_bytes += tmp | ||
assert len(dmem_bytes) == get_memory_layout().dmem_size_bytes | ||
return bytes(dmem_bytes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
result: 6ff7b440e4486d8c1a343ef7de3f5755ff3b910ae028fecfda01f020f2a033736e328be51f4f5577051a9b76882e22e038083011956960faf5c89c3b5553facfad4cbd8311cf8bca78c79f34b479815005968c5d6f20fd62716dbfa334951f41436378bfb1669647382cf4af4eaeb12f7479d0a1dcfd33179d2bd863 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters