This repository is a machine, not a toolchain. R8Forge keeps the language, the ISA specification and the tools that assemble, pack and run tapes; this one keeps what it takes to build the thing: the RTL and its testbench, the requirements note, the 34 chip board wiring, the panel design and its mockups, the mechanics analysis, the bill of materials, the buying guide and the order sheet, the bring up plan, and the microcode directory that is still empty. The equivalence test came with the RTL, since it needs both halves: it assembles a tape with r8forge, packs it with tape_pack, runs it with tape_run --loop-stack --retest, then compiles rtl/rot8.v with iverilog and requires the same OUT stream and the same step count. It takes those three binaries as parameters and its header says they must be built for eight bit cells and sixty four cells, because an eleven bit packer feeding an eight bit machine produces different output and looks like an RTL bug. Verified here: hello 577 instructions 417 steps, calc 51378 instructions 166741 steps with "12 34 + ." fed in, both agreeing with the interpreter.
109 lines
4.5 KiB
CMake
109 lines
4.5 KiB
CMake
# Compare the RTL against the R8Forge interpreter, on a real tape.
|
|
#
|
|
# The one standard this machine answers to: same OUT stream, same step count as
|
|
# `r8forge_tape_run --loop-stack --retest` (the bracket discipline the board
|
|
# implements: jump back *onto* the [, so ] pops the loop stack on the jump).
|
|
#
|
|
# cmake -DRTL=rtl
|
|
# -DPACK=<R8Forge>/build/Release/r8forge_tape_pack
|
|
# -DRUN=<R8Forge>/build/Release/r8forge_tape_run
|
|
# -DR8FORGE=<R8Forge>/build/Release/r8forge
|
|
# -DSOURCE=../R8Forge/examples/hello.r8asm
|
|
# -DWORK=build [-DINPUT="12 34 + ."] [-DTAPE_ARGS=""]
|
|
# -P tests/rtl_sim.cmake
|
|
#
|
|
# It assembles SOURCE, packs it, runs the interpreter, compiles rtl/rot8.v with
|
|
# iverilog, runs the testbench, and compares both the OUT stream and the step
|
|
# count. The RTL is the 8 bit / 64 cell machine, so SOURCE has to be a tape that
|
|
# fits in 64 cells (all the shipped examples do; the flagship peaks at 155 and
|
|
# therefore wraps, which still matches the interpreter but is not a good test).
|
|
foreach(var RTL PACK RUN R8FORGE SOURCE WORK)
|
|
if(NOT DEFINED ${var})
|
|
message(FATAL_ERROR "rtl_sim.cmake needs -D${var}=...")
|
|
endif()
|
|
endforeach()
|
|
if(NOT DEFINED INPUT)
|
|
set(INPUT "")
|
|
endif()
|
|
|
|
get_filename_component(rtl_dir "${RTL}" ABSOLUTE)
|
|
get_filename_component(work_dir "${WORK}" ABSOLUTE)
|
|
get_filename_component(source_dir "${SOURCE}" DIRECTORY)
|
|
file(MAKE_DIRECTORY "${work_dir}")
|
|
|
|
find_program(IVERILOG iverilog)
|
|
find_program(VVP vvp)
|
|
if(NOT IVERILOG OR NOT VVP)
|
|
message(FATAL_ERROR "rtl_sim needs iverilog and vvp on PATH")
|
|
endif()
|
|
|
|
# The assembler resolves `%include "lib/..."` against the *working directory*, not
|
|
# against the source file, so it has to run from the R8Forge root (the parent of
|
|
# examples/). -DASSEMBLE_DIR overrides that when the source lives elsewhere.
|
|
if(NOT DEFINED ASSEMBLE_DIR)
|
|
get_filename_component(ASSEMBLE_DIR "${source_dir}/.." ABSOLUTE)
|
|
endif()
|
|
execute_process(COMMAND ${R8FORGE} ${SOURCE} OUTPUT_VARIABLE text RESULT_VARIABLE rc
|
|
WORKING_DIRECTORY ${ASSEMBLE_DIR})
|
|
if(NOT rc EQUAL 0)
|
|
message(FATAL_ERROR "assembling ${SOURCE} in ${ASSEMBLE_DIR} failed: ${rc}")
|
|
endif()
|
|
string(LENGTH "${text}" length)
|
|
file(WRITE ${work_dir}/rtl_sim.rot8 "${text}")
|
|
execute_process(COMMAND ${PACK} ${work_dir}/rtl_sim.rot8 -o ${work_dir}/rtl_sim.r8t
|
|
--hex ${work_dir}/rtl_sim.hex
|
|
OUTPUT_VARIABLE packed RESULT_VARIABLE rc)
|
|
if(NOT rc EQUAL 0)
|
|
message(FATAL_ERROR "packing failed: ${rc} ${packed}")
|
|
endif()
|
|
message(STATUS "${packed}")
|
|
file(WRITE ${work_dir}/rtl_sim_in.txt "${INPUT}")
|
|
|
|
if(INPUT STREQUAL "")
|
|
execute_process(COMMAND ${RUN} ${work_dir}/rtl_sim.r8t --loop-stack --retest
|
|
OUTPUT_VARIABLE sw RESULT_VARIABLE rc)
|
|
else()
|
|
execute_process(COMMAND ${RUN} ${work_dir}/rtl_sim.r8t --loop-stack --retest
|
|
-i "${INPUT}"
|
|
OUTPUT_VARIABLE sw RESULT_VARIABLE rc)
|
|
endif()
|
|
if(NOT rc EQUAL 0)
|
|
message(FATAL_ERROR "software run failed: ${rc} ${sw}")
|
|
endif()
|
|
|
|
execute_process(COMMAND ${IVERILOG} -g2012 -o rot8_tb.vvp
|
|
${rtl_dir}/rot8.v ${rtl_dir}/tb_rot8.v
|
|
WORKING_DIRECTORY ${work_dir}
|
|
OUTPUT_VARIABLE build_log RESULT_VARIABLE rc)
|
|
if(NOT rc EQUAL 0)
|
|
message(FATAL_ERROR "iverilog failed: ${build_log}")
|
|
endif()
|
|
|
|
# Run vvp *from the work directory* with relative file names. Icarus passes
|
|
# plusargs through as raw bytes, so an absolute path containing non-ASCII (this
|
|
# checkout lives under a Chinese directory name) arrives at $readmemh mangled and
|
|
# the memory silently stays empty -- the machine then runs a tape of opcode 0.
|
|
execute_process(COMMAND ${VVP} rot8_tb.vvp +HEX=rtl_sim.hex
|
|
+LEN=${length} +INFILE=rtl_sim_in.txt
|
|
WORKING_DIRECTORY ${work_dir}
|
|
OUTPUT_VARIABLE rtl RESULT_VARIABLE rc)
|
|
if(NOT rc EQUAL 0)
|
|
message(FATAL_ERROR "vvp failed: ${rc} ${rtl}")
|
|
endif()
|
|
string(REGEX MATCH "out[^\n]*" rtl_out "${rtl}")
|
|
|
|
string(REGEX MATCH "^out([^()]*) *\\(([0-9]+) steps" _ "${sw}")
|
|
set(sw_values "${CMAKE_MATCH_1}")
|
|
set(sw_steps "${CMAKE_MATCH_2}")
|
|
string(REGEX MATCH "^out([^()]*) *\\(([0-9]+) steps" _ "${rtl_out}")
|
|
set(rtl_values "${CMAKE_MATCH_1}")
|
|
set(rtl_steps "${CMAKE_MATCH_2}")
|
|
|
|
if(NOT sw_values STREQUAL rtl_values)
|
|
message(FATAL_ERROR "OUT streams differ\n sw : ${sw_values}\n rtl: ${rtl_values}")
|
|
endif()
|
|
if(NOT sw_steps STREQUAL rtl_steps)
|
|
message(FATAL_ERROR "step counts differ: sw ${sw_steps}, rtl ${rtl_steps}")
|
|
endif()
|
|
message(STATUS "${length} instructions, ${sw_steps} steps: RTL and interpreter agree")
|