Files
ROT-8-Machine/tests/rtl_probe.sh
T
hermes 4307899a18 rtl: 修 in_ready 的单步漏洞,加 EPROM 取指模型,量出扫描占比
三件事,都有测试或数字兜着:

1. in_ready 少算 run/step。原来只有 `state==S_FETCH && op_now==OP_INP`,
   单步模式(run=0)停着时照样拉高,生产者按契约交出的字节被丢掉,机器从此
   卡在 ',' 上(steps 一直是 0)。补 `(run || step) && !halted`。
   回归:tests/tb_in_ready.v(自带纸带,不需要 R8Forge 构建)。

2. 新增 EPROM 参数(1 = 一字节一指令,prog_data0[2:0] 即操作码、ip 直接当地址),
   就是 docs/ttl-schematic.md 焊的 27C512 方案;tb_rot8.v 用 -DEPROM_MODE 打开。
   两种格式在 hello / calc / asm/test 上步数、拍数、OUT 流全部相同
   (417 / 166741 / 100142)—— 之前 RTL 只对得上打包镜像,和板子焊的格式不是一回事。

3. 栈满改成停机(原来是 sp 静默回绕);新增 tests/tb_state_mix.v + tests/rtl_probe.sh,
   量出拍数分布:calc 698075 拍里 531332 拍是括号前向扫描(76%),hello 27%、
   asm/test 53%;最大栈深 calc 7、test 4、hello 0。分析见 docs/bracket-skip.md。

文档同步:ttl-schematic 取消两片 74LS670 的栈方案(4 深不够,实测要 7),片数改 31+晶振;
微码字段数到 18 根,一片 28C64 装不下 → 定 16 位两片;NEXT.md/AGENTS.md/rtl/README.md
记录新状态与两条探针。
2026-11-25 16:53:18 +00:00

47 lines
1.7 KiB
Bash

#!/bin/sh
# tests/rtl_probe.sh -- 不依赖 R8Forge 的两条探针。
#
# ./tests/rtl_probe.sh in-ready
# 只跑 in_ready 的定向测试(自带纸带,不需要镜像)
#
# ./tests/rtl_probe.sh states <image.hex> <LEN> [input.txt] [eprom]
# 跑一张镜像,打印步数/拍数/扫描占比/最大栈深
#
# 镜像来源(R8Forge,8 位 / 64 格的构建):
# r8forge examples/calc.r8asm > calc.rot8
# r8forge_tape_pack calc.rot8 -o calc.r8t --hex calc.hex --verify
# r8forge_tape_pack calc.rot8 -o calc_e.r8t --eprom --hex calc_e.hex # 一字节一指令
#
# 注意:Icarus 把 plusarg 原样传给 $readmemh,路径里有非 ASCII 字符时内存会**静默留空**
# (见 rtl/README.md 的坑 1)——所以这里一律先 cd 到镜像目录再用相对路径。
set -e
cd "$(dirname "$0")/.."
mode=${1:-in-ready}
build=$(mktemp -d)
trap 'rm -rf "$build"' EXIT
case "$mode" in
in-ready)
iverilog -g2012 -o "$build/tb.vvp" rtl/rot8.v tests/tb_in_ready.v
exec vvp "$build/tb.vvp"
;;
states)
hex=$2; len=$3; infile=$4; eprom=$5
[ -n "$hex" ] && [ -n "$len" ] || { echo "usage: $0 states <image.hex> <LEN> [input.txt] [eprom]"; exit 2; }
dir=$(cd "$(dirname "$hex")" && pwd); base=$(basename "$hex")
extra=""
[ -n "$infile" ] && extra="+INFILE=$(cd "$(dirname "$infile")" && pwd)/$(basename "$infile")"
if [ "$eprom" = "eprom" ]; then
iverilog -g2012 -DEPROM_MODE -o "$build/tb.vvp" rtl/rot8.v tests/tb_state_mix.v
else
iverilog -g2012 -o "$build/tb.vvp" rtl/rot8.v tests/tb_state_mix.v
fi
cd "$dir"
exec vvp "$build/tb.vvp" "+HEX=$base" "+LEN=$len" $extra
;;
*)
echo "usage: $0 in-ready | states <image.hex> <LEN> [input.txt] [eprom]"; exit 2
;;
esac