-- varargs-check.lua -- read the M6 varargs marker words and the formatted -- output buffer, and compare them with the expected values. -- -- VARARGS_MARKERS is the bit address of _varargs_markers from the linker map; -- each marker is one 32-bit word at base + n*0x20 bits. VARARGS_OUT is the -- bit address of the C driver's `char varargs_out[64]`; the checker reads the -- bytes of the expected string (TMS34010 memory is byte-addressed at the low -- end of a bit address, one byte per 8 bits). -- -- The marker read runs one frame before loader.lua's inspection/exit frame. dofile(os.getenv("M2_LOADER_LUA")) local ENDF = tonumber(os.getenv("LOADER_END") or "2900") local BASE = tonumber(os.getenv("VARARGS_MARKERS"), 16) local OUT = tonumber(os.getenv("VARARGS_OUT"), 16) local N = 15 local frames = 0 local checked = false local expect = { [0] = 100, -- vsum(4, 10, 20, 30, 40): int walk [1] = 42, -- vlong(0, 42): long is one slot [2] = 1, -- vptr(0, 0x12345678): char * is one slot [3] = 2, -- vdbl(0, 2.5): GSP double, MSW at the top [4] = 0x9ABCDEF0, -- vll(0, 123456789ABCDEF0h): i64 LSW at the top [5] = 257, -- mixed_di(0, 2.5, 7): double then int [6] = 0x5566BD76, -- mixed_llp(0, 1122334455667788h, CAFEh) [7] = 13, -- vcopy(0, 4, 5, 6): va_copy independence [8] = 24, -- vforward(3, 7, 8, 9): forwarded va_list [9] = 11, -- vnoargs(11): no fixed argument [10] = 77, -- vlastd(1.5, 77): double last fixed argument [11] = 4, -- myfmt("n=%d", -7) length [12] = 19, -- myfmt("v=%d s=%s d=%f", ...) length [13] = 2, -- call_vf32(): one-slot f32 va_arg [14] = 0x5A5A5A5A, -- marker after varargs_run returns } local want_out = "v=42 s=hello d=3.25" local function read_string(space, addr, len) local s = {} for i = 0, len - 1 do s[#s + 1] = string.char(space:read_u8(addr + i * 8)) end return table.concat(s) end emu.register_frame_done(function() frames = frames + 1 if frames == ENDF - 1 and not checked then checked = true local prog = manager.machine.devices[':maincpu'].spaces['program'] local got = {} local bad = 0 for i = 0, N - 1 do got[i] = prog:read_u32(BASE + i * 0x20) if got[i] ~= expect[i] then bad = bad + 1 end end io.write(string.format("M6 varargs:")) for i = 0, N - 1 do io.write(string.format(" %08X", got[i])) end io.write("\n") local out = read_string(prog, OUT, #want_out) print(string.format("M6 varargs out: '%s'", out)) if out ~= want_out then print(string.format("M6 varargs: output got '%s' want '%s'", out, want_out)) bad = bad + 1 end if bad == 0 then print("M6 VARARGS MAME: PASS") else for i = 0, N - 1 do if got[i] ~= expect[i] then print(string.format( "M6 varargs: marker %d got %08X want %08X", i, got[i], expect[i])) end end print("M6 VARARGS MAME: FAIL") end end end, "varargs-check")