-
Notifications
You must be signed in to change notification settings - Fork 19
[sw,dv] Add SW-DV logging #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martin-velay
wants to merge
4
commits into
lowRISC:main
Choose a base branch
from
martin-velay:sw_dv_log
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b185b8d
[utils] Add rv64 + CHERI ELF support
martin-velay cf6eed5
[sw] Add DV_LOG_* macros for SW-to-DV logging
martin-velay 2a4c3e2
[dv] Add SW logger support and smoketest sequence
martin-velay d54086c
[dv,doc] Update README.md files for logging
martin-velay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
hw/top_chip/dv/env/seq_lib/top_chip_dv_dv_log_smoketest_vseq.sv
This file contains hidden or 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,58 @@ | ||
| // Copyright lowRISC contributors (COSMIC project). | ||
| // Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| class top_chip_dv_dv_log_smoketest_vseq extends top_chip_dv_base_vseq; | ||
| `uvm_object_utils(top_chip_dv_dv_log_smoketest_vseq) | ||
|
|
||
| string exp_messages[] = '{ | ||
| "SW-DV log smoketest starting...", | ||
| "a = 10, b = 20, c = 12", | ||
| "a + b + c = 42", | ||
| "Smoke test for the SW-DV log interface, completed successfully!" | ||
| }; | ||
|
|
||
| typedef bit [1024*8-1:0] arg_t; | ||
|
|
||
| extern function new(string name = ""); | ||
| extern task body(); | ||
| // Per SV LRM 6.16, a string shorter than the packed type is left-padded with zeros: the last | ||
| // character sits at byte[0] (LSB) and the first at byte[N-1]. Collect the bytes upward from | ||
| // byte[0] until the null terminator, then reverse them with the streaming operator to restore | ||
| // left-to-right order. | ||
| extern function string arg_t_to_string(arg_t val); | ||
| endclass : top_chip_dv_dv_log_smoketest_vseq | ||
|
|
||
|
|
||
| function top_chip_dv_dv_log_smoketest_vseq::new(string name = ""); | ||
| super.new(name); | ||
| endfunction : new | ||
|
|
||
| function string top_chip_dv_dv_log_smoketest_vseq::arg_t_to_string(arg_t val); | ||
| byte unsigned bytes[$]; | ||
| for (int i = 0; i < ($bits(val) / 8); i++) begin | ||
| logic [7:0] c = val[i*8 +: 8]; | ||
| if (c == 8'h00) break; | ||
| bytes.push_back(c); | ||
| end | ||
| return string'({<<8{bytes}}); | ||
| endfunction : arg_t_to_string | ||
|
|
||
| task top_chip_dv_dv_log_smoketest_vseq::body(); | ||
| if (cfg == null) begin | ||
| set_handles(); | ||
| end | ||
|
|
||
| // Check each expected message inline as the event fires. This ensures we sample printed_log | ||
| // in the same delta as the event. | ||
| for (int i = 0; i < exp_messages.size(); i++) begin | ||
| string actual; | ||
| @(cfg.sw_logger_vif.printed_log_event); | ||
| actual = arg_t_to_string(arg_t'(cfg.sw_logger_vif.printed_log)); | ||
| if (actual != exp_messages[i]) begin | ||
| `uvm_error(get_full_name(), | ||
| $sformatf("Log message mismatch at index %0d. Expected '%0s' but saw '%0s'.", | ||
| i, exp_messages[i], actual)) | ||
| end | ||
| end | ||
| endtask : body | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
87 changes: 87 additions & 0 deletions
87
hw/vendor/patches/lowrisc_ip/util_device_sw_utils/0001-rv64-elf-support.patch
This file contains hidden or 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,87 @@ | ||
| diff --git a/extract_sw_logs.py b/extract_sw_logs.py | ||
| --- a/extract_sw_logs.py | ||
| +++ b/extract_sw_logs.py | ||
| @@ -173,6 +173,33 @@ | ||
| raise KeyError(f"string at addr {str_addr:x} not found") | ||
|
|
||
|
|
||
| +# CHERI __cap_relocs entry: five little-endian uint64 words. | ||
| +_CAP_RELOC_FMT = '<QQQQQ' | ||
| +_CAP_RELOC_SIZE = struct.calcsize(_CAP_RELOC_FMT) | ||
| + | ||
| + | ||
| +def get_cap_relocs(elf): | ||
| + '''Build a {capability_location: target_addr} map from __cap_relocs. | ||
| + | ||
| + On CHERI targets, pointer fields in initialised data (such as the file and | ||
| + format pointers of the log_fields_t entries in .logs.fields) are stored as | ||
| + capabilities whose address is materialised at runtime. The static ELF only | ||
| + holds a placeholder, while the real target is recorded in __cap_relocs. Each | ||
| + entry is five uint64 words: (location, object, offset, size, perms); the | ||
| + resolved target address is object + offset. Returns an empty dict on | ||
| + non-CHERI ELFs, where the section is absent or empty.''' | ||
| + section = elf.get_section_by_name('__cap_relocs') | ||
| + relocs = {} | ||
| + if section is None: | ||
| + return relocs | ||
| + data = section.data() | ||
| + for off in range(0, len(data), _CAP_RELOC_SIZE): | ||
| + location, obj, offset, _size, _perms = struct.unpack( | ||
| + _CAP_RELOC_FMT, data[off:off + _CAP_RELOC_SIZE]) | ||
| + relocs[location] = obj + offset | ||
| + return relocs | ||
| + | ||
| + | ||
| def extract_sw_logs(elf_file, logs_fields_section): | ||
| '''This function extracts contents from the logs fields section, and the | ||
| read only sections, processes them and generates a tuple of (results) - | ||
| @@ -222,17 +249,42 @@ | ||
| logs_fields_section, elf_file)) | ||
| sys.exit(1) | ||
|
|
||
| - header_size = 4 | ||
| - logs_offset, = struct.unpack('I', logs_data[0:header_size]) | ||
| + # Determine the log_fields_t binary layout, which depends on the target. | ||
| + # - rv32: 20-byte entries (all uint32) behind a 4-byte header. | ||
| + # - rv64: 32-byte entries with 8-byte pointer fields, 8-byte header. | ||
| + # - CHERI: file/format pointers are 16-byte capabilities, which forces | ||
| + # 16-byte section alignment and 64-byte entries behind a | ||
| + # 16-byte header. The capabilities hold placeholders in the | ||
| + # static image; their target addresses come from __cap_relocs | ||
| + # (see get_cap_relocs), keyed by the in-image slot location. | ||
| + cap_relocs = get_cap_relocs(elf) | ||
| + is_cheri = int(section.header['sh_addralign']) >= 16 | ||
| + if is_cheri: | ||
| + sec_addr = int(section.header['sh_addr']) | ||
| + header_size, entry_size = 16, 64 | ||
| + file_off, format_off = 0x10, 0x30 | ||
| + logs_offset = sec_addr | ||
| + elif elf.elfclass == 64: | ||
| + header_size, entry_size, entry_fmt = 8, 32, '<I4xQIIQ' | ||
| + logs_offset, = struct.unpack('<Q', logs_data[0:header_size]) | ||
| + else: | ||
| + header_size, entry_size, entry_fmt = 4, LOGS_FIELDS_SIZE, '<IIIII' | ||
| + logs_offset, = struct.unpack('<I', logs_data[0:header_size]) | ||
|
|
||
| # Dump the logs with fields. | ||
| result = "" | ||
| - num_logs = (logs_size - header_size) // LOGS_FIELDS_SIZE | ||
| + num_logs = (logs_size - header_size) // entry_size | ||
| for i in range(num_logs): | ||
| - start = header_size + i * LOGS_FIELDS_SIZE | ||
| - end = start + LOGS_FIELDS_SIZE | ||
| - severity, file_addr, line, nargs, format_addr = struct.unpack( | ||
| - 'IIIII', logs_data[start:end]) | ||
| + start = header_size + i * entry_size | ||
| + if is_cheri: | ||
| + severity, = struct.unpack('<I', logs_data[start:start + 4]) | ||
| + line, nargs = struct.unpack( | ||
| + '<II', logs_data[start + 0x20:start + 0x28]) | ||
| + file_addr = cap_relocs[sec_addr + start + file_off] | ||
| + format_addr = cap_relocs[sec_addr + start + format_off] | ||
| + else: | ||
| + severity, file_addr, line, nargs, format_addr = struct.unpack( | ||
| + entry_fmt, logs_data[start:start + entry_size]) | ||
| result += "addr: {}\n".format(hex(logs_offset + start)[2:]) | ||
| result += "severity: {}\n".format(severity) | ||
| result += "file: {}\n".format( |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.