Extend --bitptr's raw inttoptr barrier through the zext/trunc clang emits for a 64-bit pointer-int expression, so `inttoptr(add(zext(ptrtoint p), i64 24))` becomes `@__tms_bitptr(i32 24, ptr p)` instead of a post-scale `getelementptr i8, p, 192`. The pointer is 32-bit, so the addend is zext/truncated to the low word. The matcher also covers the reversed add operand order and the sub form (negated addend). Harden getBitPtrFn/lower_bitptr_calls: an existing @__tms_bitptr with a mismatched signature or body, or a non-CallInst/mismatched use, now fails loudly instead of leaving an undefined external. Add @late64 (and sub/reversed/trunc) to bitptr.ll, assert the nounwind readnone declaration, add a late64 M0 shape check (24, never 192) and a late64 runtime marker to the M7 gate. Tighten the gate's one-scale check to reject a second shl i32 in copy_back and to match SLL 3/SLL 6 exactly (not SLL 31). Update the stale M6 comments in bitscale.cpp and the c-torture -O2 comment.
98 lines
2.6 KiB
Lua
98 lines
2.6 KiB
Lua
-- pointer-check.lua -- read the M7.1 `-O2` pointer gate markers and the exact
|
|
-- copy bytes, and compare them with the expected values.
|
|
--
|
|
-- M4_LOADER_LUA is the dwt loader script. Marker n is at 018A8000 + n*0x20
|
|
-- bits (0..9 from the driver, 10 the post-return sentinel); the copy bytes are
|
|
-- at 018A9000 + n*8 bits.
|
|
--
|
|
-- 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 = 10
|
|
local SENT = 0x5A5A5A5A
|
|
local frames = 0
|
|
local checked = false
|
|
|
|
local expect = {
|
|
1, -- a[0..7] == "aabcdefg" after the overlapping backward copy
|
|
1, -- a[8] == 'h', a[9] and a[65] untouched
|
|
81, -- b[3] == 'Q' after `p += 3; *p = 'Q'`
|
|
0, -- b[0] untouched
|
|
0, -- b[24] untouched (the old double-scaled byte)
|
|
0, -- b[127] untouched
|
|
5, -- (q - b) in bytes
|
|
40, -- (u32)q - (u32)b in bits
|
|
1, -- the forward byte checks
|
|
1, -- late64: c + 24 bits == c + 3 bytes (not 192 bits)
|
|
}
|
|
local want_bytes = "aabcdefgh"
|
|
|
|
local function escape(s)
|
|
return (s:gsub("\n", "\\n"))
|
|
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 + 1] then
|
|
bad = bad + 1
|
|
end
|
|
end
|
|
local sent = prog:read_u32(BASE + 10 * 0x20)
|
|
if sent ~= SENT then
|
|
bad = bad + 1
|
|
end
|
|
|
|
local bytes = {}
|
|
for i = 0, #want_bytes - 1 do
|
|
bytes[#bytes + 1] =
|
|
string.char(prog:read_u8(OUT + i * 8))
|
|
end
|
|
local got_bytes = table.concat(bytes)
|
|
|
|
io.write("M7 pointer:")
|
|
for i = 0, N - 1 do
|
|
io.write(string.format(" %08X", got[i]))
|
|
end
|
|
io.write(string.format(" %08X\n", sent))
|
|
print(string.format("M7 pointer bytes(%d): '%s' want '%s'",
|
|
#got_bytes, escape(got_bytes), escape(want_bytes)))
|
|
|
|
if got_bytes ~= want_bytes then
|
|
bad = bad + 1
|
|
end
|
|
|
|
if bad == 0 then
|
|
print("M4: pointer gate markers and bytes match")
|
|
print("M4 MAME: PASS")
|
|
print("M7 POINTER MAME: PASS")
|
|
else
|
|
for i = 0, N - 1 do
|
|
if got[i] ~= expect[i + 1] then
|
|
print(string.format(
|
|
"M7 pointer: marker %d got %08X want %08X",
|
|
i, got[i], expect[i + 1]))
|
|
end
|
|
end
|
|
if sent ~= SENT then
|
|
print(string.format(
|
|
"M7 pointer: sentinel got %08X want %08X",
|
|
sent, SENT))
|
|
end
|
|
print("M4: pointer gate marker/byte mismatch")
|
|
print("M4 MAME: FAIL")
|
|
print("M7 POINTER MAME: FAIL")
|
|
end
|
|
end
|
|
end, "m7-pointer-check")
|