-- data-check.lua -- read the M7.1 `.data` initializer gate markers and the raw -- object bytes, and compare them with the exact expected values. -- -- M4_LOADER_LUA is the dwt loader script. Marker n is at 018A8000 + n*0x20 -- bits; marker 60 is the post-return sentinel. The raw image is at -- 018A9000: x@0, s@8, p@13, arr@26, u@44, pt@64, y@80 (the pt pointer bytes -- are compared with the linked address of x from marker 25). In the native -- run only, markers 26..29 and the 5-byte packed odd-offset pointer record at -- byte 96 are checked too; the raw GSPA path rejects that shape. -- -- The marker read runs one frame before loader.lua's inspection/exit frame. dofile(os.getenv("M4_LOADER_LUA")) local ENDF = tonumber(os.getenv("LOADER_END") or "2700") local BASE = 0x018A8000 local OUT = 0x018A9000 local N = 34 local SENT_IDX = 60 local SENT = 0x5A5A5A5A local NATIVE = os.getenv("M7_DATA_NATIVE") == "1" local frames = 0 local checked = false local expect = { 0x55667788, -- 0: low word of x 0x11223344, -- 1: high word of x 5, -- 2: s.a 17, -- 3: s.b 0xFFFFFFFD, -- 4: s.c (signed -3) 0x000ABCDE, -- 5: s.d 9, -- 6: s.e 0x11, -- 7: p.a 0x22334455, -- 8: p.b 0xAABBCCDD, -- 9: low word of p.c 0x66778899, -- 10: high word of p.c 0x11223344, -- 11: arr[0].a 0x778899AA, -- 12: arr[1].a 0xDDEEFF00, -- 13: arr[2].a 0x5566, -- 14: arr[0].b 0x12345678, -- 15: union active struct i 0x9ABC, -- 16: union active struct h 1, -- 17: pp == &x and *pp == x 3, -- 18: cp - &x in bytes 0x1234, -- 19: pt.tag 1, -- 20: pt.p == &x and pt.c == 0x5A 0x12345678, -- 21: union low word 0x00009ABC, -- 22: union high word 0x1122, -- 23: arr[2].b 0xBBCC, -- 24: arr[1].b nil, -- 25: linked address of x (runtime) nil, -- 26: odd.c (native only) nil, -- 27: odd.p == &x (native only) nil, -- 28: low word of *odd.p (native only) nil, -- 29: high word of *odd.p (native only) 0x55667788, -- 30: low word of y[0] 0x11223344, -- 31: high word of y[0] 0xDDEEFF00, -- 32: low word of y[1] 0x99AABBCC, -- 33: high word of y[1] } local raw = { { 0, "8877665544332211", "x" }, { 8, "8DEDCDAB09", "s" }, { 13, "1155443322DDCCBBAA99887766", "p" }, { 26, "443322116655AA998877CCBB00FFEEDD2211", "arr" }, { 44, "78563412BC9A0000", "u" }, { 80, "887766554433221100FFEEDDCCBBAA99", "y" }, } local function read_bytes(prog, off, len) local out = {} for i = 0, len - 1 do out[#out + 1] = string.char(prog:read_u8(OUT + (off + i) * 8)) end return table.concat(out) end local function hex(s) return (s:gsub(".", function(c) return string.format("%02X", string.byte(c)) end)) 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 expect[i + 1] ~= nil and got[i] ~= expect[i + 1] then bad = bad + 1 end end local sent = prog:read_u32(BASE + SENT_IDX * 0x20) if sent ~= SENT then bad = bad + 1 end for _, r in ipairs(raw) do local got_bytes = read_bytes(prog, r[1], #r[2] / 2) if hex(got_bytes) ~= r[2] then bad = bad + 1 print(string.format( "M7 data: %s bytes got %s want %s", r[3], hex(got_bytes), r[2])) end end -- pt: tag, linked pointer, char. The pointer bytes are the -- little-endian linked address of x from marker 25. local pt = read_bytes(prog, 64, 9) local pt_tag = string.unpack("