130 lines
3.5 KiB
Lua
130 lines
3.5 KiB
Lua
-- conformance-check.lua -- load the conformance COFF with the M4 loader and
|
|
-- publish the shim's result block.
|
|
--
|
|
-- The loader is scripts/m4/run.sh's loader (vendor/vt1200/dwt/loader/loader.lua),
|
|
-- loaded through M4_LOADER_LUA. The test's entry writes:
|
|
-- 01B00000 status
|
|
-- 01B00020 out_len
|
|
-- 01B00040 magic 0x434F4E46
|
|
-- 01B10000 output bytes (bit addresses, 8 bits apart)
|
|
--
|
|
-- The block is above the linker-managed .bss region (01A00000..01A80000), so
|
|
-- test globals cannot overwrite it. The runner rejects len >= the 16 KiB cap
|
|
-- because the shim truncates there.
|
|
--
|
|
-- The result is written to CONF_RESULT in a stable, shell-readable form:
|
|
-- status=<8 hex>
|
|
-- len=<decimal>
|
|
-- magic=<8 hex>
|
|
-- loader=<8 hex> (loader result block status at 01882D00)
|
|
-- out=<uppercase hex bytes>
|
|
--
|
|
-- The runner compares this file against the manifest/expected result. A
|
|
-- missing magic is a failure, never a pass.
|
|
|
|
dofile(os.getenv("M4_LOADER_LUA"))
|
|
|
|
local machine = manager.machine
|
|
local cpu = machine.devices[':maincpu']
|
|
local prog = cpu.spaces['program']
|
|
|
|
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
|
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
|
local RESULT = os.getenv("CONF_RESULT") or "conformance-result.txt"
|
|
|
|
local STATUS = 0x01B00000
|
|
local LEN = 0x01B00020
|
|
local MAGIC = 0x01B00040
|
|
local OUT = 0x01B10000
|
|
local CAP = 16384
|
|
local MAGIC_VAL = 0x434F4E46
|
|
local LOADER_STATUS = 0x01882D00
|
|
|
|
local frames = 0
|
|
local done = false
|
|
|
|
local function rd32(a)
|
|
local ok, v = pcall(function() return prog:read_u32(a) end)
|
|
if ok then return v end
|
|
return 0xDEADBEEF
|
|
end
|
|
|
|
local function rd8(a)
|
|
local ok, v = pcall(function() return prog:read_u8(a) end)
|
|
if ok then return v end
|
|
return 0
|
|
end
|
|
|
|
local function dump(tag)
|
|
local status = rd32(STATUS)
|
|
local raw_len = rd32(LEN)
|
|
local magic = rd32(MAGIC)
|
|
local loader = rd32(LOADER_STATUS)
|
|
local bytes = {}
|
|
local shown = {}
|
|
local n = 0
|
|
local nread = raw_len
|
|
|
|
-- Keep the raw length for the runner (it rejects len >= CAP), but never
|
|
-- loop over an implausible value.
|
|
if nread < 0 or nread > CAP then
|
|
nread = 0
|
|
end
|
|
for i = 0, nread - 1 do
|
|
local b = rd8(OUT + i * 8)
|
|
bytes[#bytes + 1] = string.format("%02X", b)
|
|
if i < 128 then
|
|
shown[#shown + 1] = string.format("%02X", b)
|
|
end
|
|
n = n + 1
|
|
end
|
|
local outhex = table.concat(bytes)
|
|
local shownhex = table.concat(shown)
|
|
if n > 128 then
|
|
shownhex = shownhex .. "..."
|
|
end
|
|
|
|
print(string.format(
|
|
"CONF: %s status=%08X len=%d magic=%08X loader=%08X out=%s",
|
|
tag, status, raw_len, magic, loader, shownhex))
|
|
|
|
local f, err = io.open(RESULT, "w")
|
|
if not f then
|
|
print("CONF: cannot write result " .. tostring(RESULT) ..
|
|
": " .. tostring(err))
|
|
machine:exit()
|
|
return
|
|
end
|
|
f:write(string.format("status=%08X\n", status))
|
|
f:write(string.format("len=%d\n", raw_len))
|
|
f:write(string.format("magic=%08X\n", magic))
|
|
f:write(string.format("loader=%08X\n", loader))
|
|
f:write("out=" .. outhex .. "\n")
|
|
f:close()
|
|
|
|
if magic == MAGIC_VAL and loader == 0 then
|
|
print("CONF MAME: PASS")
|
|
else
|
|
print("CONF MAME: FAIL")
|
|
end
|
|
end
|
|
|
|
emu.register_frame_done(function()
|
|
frames = frames + 1
|
|
if frames <= AT or done then
|
|
return
|
|
end
|
|
|
|
local magic = rd32(MAGIC)
|
|
local loader = rd32(LOADER_STATUS)
|
|
|
|
-- A successful run publishes the magic. A loader error after injection
|
|
-- is final even if the app never starts. Otherwise wait for ENDF.
|
|
if magic == MAGIC_VAL or (frames > AT + 60 and loader ~= 0)
|
|
or frames >= ENDF then
|
|
done = true
|
|
dump(frames >= ENDF and "timeout" or "result")
|
|
machine:exit()
|
|
end
|
|
end, "m5-conformance-check")
|