serial reconstruction
This commit is contained in:
@@ -25,6 +25,11 @@ from .sci_protocol import (
|
||||
sci_protocol_json_payload,
|
||||
sci_protocol_metadata_for_instruction,
|
||||
)
|
||||
from .serial_reconstruction import (
|
||||
serial_reconstruction_comment_for_instruction,
|
||||
serial_reconstruction_json_payload,
|
||||
serial_reconstruction_metadata_for_instruction,
|
||||
)
|
||||
from .symbols import symbol_for_address
|
||||
from .tables import IO_REGISTERS
|
||||
from .timing import format_timing_summary
|
||||
@@ -248,6 +253,42 @@ def _board_profile_lines(board_profile: dict[str, object] | None) -> list[str]:
|
||||
return lines
|
||||
|
||||
|
||||
def _serial_reconstruction_lines(serial_reconstruction: dict[str, object] | None) -> list[str]:
|
||||
if not serial_reconstruction:
|
||||
return []
|
||||
candidates = serial_reconstruction.get("candidates", [])
|
||||
if not isinstance(candidates, list) or not candidates:
|
||||
return []
|
||||
|
||||
lines = ["; Serial Protocol Reconstruction"]
|
||||
for candidate in candidates:
|
||||
if not isinstance(candidate, dict):
|
||||
continue
|
||||
kind = str(candidate.get("kind", "candidate"))
|
||||
confidence = candidate.get("confidence")
|
||||
score = candidate.get("confidence_score")
|
||||
if kind == "candidate_sci1_tx_frame":
|
||||
lines.append(
|
||||
f"; TX candidate: {candidate['frame_length']} bytes "
|
||||
f"{candidate['buffer_start_hex']}-{candidate['buffer_end_hex']}, "
|
||||
f"checksum {candidate['checksum_address_hex']} seeded by {candidate['checksum_seed_hex']} "
|
||||
f"(confidence {confidence} {score})",
|
||||
)
|
||||
elif kind == "candidate_sci1_rx_frame":
|
||||
lines.append(
|
||||
f"; RX candidate: {candidate['frame_length']} bytes "
|
||||
f"capture {candidate['capture_buffer_start_hex']}-{candidate['capture_buffer_end_hex']}, "
|
||||
f"validate {candidate['validation_buffer_start_hex']}-{candidate['validation_buffer_end_hex']} "
|
||||
f"checksum {candidate['checksum_address_hex']} seeded by {candidate['checksum_seed_hex']} "
|
||||
f"(confidence {confidence} {score})",
|
||||
)
|
||||
caveat = candidate.get("caveat")
|
||||
if caveat:
|
||||
lines.append(f"; caveat: {caveat}")
|
||||
lines.append("")
|
||||
return lines
|
||||
|
||||
|
||||
def format_listing(
|
||||
rom_path: Path,
|
||||
rom: Rom,
|
||||
@@ -262,6 +303,7 @@ def format_listing(
|
||||
show_cycles: bool = False,
|
||||
sci_analysis: dict[str, object] | None = None,
|
||||
sci_protocol: dict[str, object] | None = None,
|
||||
serial_reconstruction: dict[str, object] | None = None,
|
||||
board_profile: dict[str, object] | None = None,
|
||||
peripheral_access: dict[str, object] | None = None,
|
||||
indirect_flow: dict[str, object] | None = None,
|
||||
@@ -328,6 +370,7 @@ def format_listing(
|
||||
|
||||
lines.extend(_symbol_lines(symbols))
|
||||
lines.extend(_board_profile_lines(board_profile))
|
||||
lines.extend(_serial_reconstruction_lines(serial_reconstruction))
|
||||
lines.extend(_lcd_text_lines(lcd_text))
|
||||
lines.extend(_lcd_driver_lines(lcd_driver))
|
||||
|
||||
@@ -347,6 +390,7 @@ def format_listing(
|
||||
ins.comment,
|
||||
sci_comment_for_instruction(sci_analysis, address),
|
||||
sci_protocol_comment_for_instruction(sci_protocol, address),
|
||||
serial_reconstruction_comment_for_instruction(serial_reconstruction, address),
|
||||
board_comment_for_instruction(board_profile, address),
|
||||
peripheral_comment_for_instruction(peripheral_access, address),
|
||||
indirect_comment_for_instruction(indirect_flow, address),
|
||||
@@ -375,6 +419,7 @@ def write_json(
|
||||
timing_summary: dict[str, list[dict[str, object]]] | None = None,
|
||||
sci_analysis: dict[str, object] | None = None,
|
||||
sci_protocol: dict[str, object] | None = None,
|
||||
serial_reconstruction: dict[str, object] | None = None,
|
||||
board_profile: dict[str, object] | None = None,
|
||||
peripheral_access: dict[str, object] | None = None,
|
||||
indirect_flow: dict[str, object] | None = None,
|
||||
@@ -404,6 +449,7 @@ def write_json(
|
||||
"timing_summary": timing_summary or {"blocks": [], "loops": []},
|
||||
"sci": sci_json_payload(sci_analysis),
|
||||
"sci_protocol": sci_protocol_json_payload(sci_protocol),
|
||||
"serial_reconstruction": serial_reconstruction_json_payload(serial_reconstruction),
|
||||
"board_profile": board_json_payload(board_profile),
|
||||
"peripheral_access": peripheral_json_payload(peripheral_access),
|
||||
"indirect_flow": indirect_flow or {"sites": []},
|
||||
@@ -416,6 +462,7 @@ def write_json(
|
||||
ins,
|
||||
sci_analysis,
|
||||
sci_protocol,
|
||||
serial_reconstruction,
|
||||
board_profile,
|
||||
peripheral_access,
|
||||
indirect_flow,
|
||||
@@ -477,6 +524,7 @@ def _instruction_payload(
|
||||
ins: Instruction,
|
||||
sci_analysis: dict[str, object] | None = None,
|
||||
sci_protocol: dict[str, object] | None = None,
|
||||
serial_reconstruction: dict[str, object] | None = None,
|
||||
board_profile: dict[str, object] | None = None,
|
||||
peripheral_access: dict[str, object] | None = None,
|
||||
indirect_flow: dict[str, object] | None = None,
|
||||
@@ -514,6 +562,9 @@ def _instruction_payload(
|
||||
sci_protocol_metadata = sci_protocol_metadata_for_instruction(sci_protocol, ins.address)
|
||||
if sci_protocol_metadata:
|
||||
payload["sci_protocol"] = sci_protocol_metadata
|
||||
serial_reconstruction_metadata = serial_reconstruction_metadata_for_instruction(serial_reconstruction, ins.address)
|
||||
if serial_reconstruction_metadata:
|
||||
payload["serial_reconstruction"] = serial_reconstruction_metadata
|
||||
board_metadata = board_metadata_for_instruction(board_profile, ins.address)
|
||||
if board_metadata:
|
||||
payload["board_profile"] = board_metadata
|
||||
|
||||
Reference in New Issue
Block a user