summaryrefslogtreecommitdiffstats
path: root/debug/risc-v-gsp-rm-vm/examples/scripts/dump_diff.py
blob: 11d1fbb70fd0e2b55c78da53e5bef2cdb79a32c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Snapshot-diff the uproc control block across a host-injected PING.

Run from the tool root:

    ./risc-v-gsp-rm-debugger.sh run examples/scripts/dump_diff.py

Demonstrates: symbol -> structure schema decoding, snapshot + diff, host
stimulus via memory writes, and symbol-annotated output.
"""
import json
from pathlib import Path

from greeneye import Memory
from greeneye.structs import render, schema_from_json

TOOL_ROOT = Path(__file__).resolve().parents[2]
schema = schema_from_json(json.loads((TOOL_ROOT / "firmware/uproc_demo/gsp_ctrl.schema.json").read_text()))
ctrl = symbols.lookup("gsp_ctrl")

# Let the firmware self-test settle.
s.run(duration=0.4)
before = s.snapshot(ctrl, schema.size, "ctrl-before-ping")

# Host stimulus: PING with argument 0x1234.
memory.write_u64(ctrl + 32, 1)   # mailbox
memory.write_u64(ctrl + 40, 0x1234)
s.run(duration=0.4)
after = s.snapshot(ctrl, schema.size, "ctrl-after-ping")

print("decoded control block:")
print(render(schema, schema.decode(after, base=ctrl)))
print("\nchanged bytes:")
print(Memory.render_diff(Memory.diff(before, after, base=ctrl), symbols))