Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ee3a6592c | ||
|
|
1d97b1c5cd | ||
|
|
480f4de4a4 | ||
|
|
3d9e6162bf | ||
|
|
cb1032a751 | ||
|
|
9baa05963c | ||
|
|
e5ee1686d8 | ||
|
|
1869a1f015 | ||
|
|
1d95b99029 | ||
|
|
a3d8070be6 | ||
|
|
97345c8b46 | ||
|
|
0b245867ab | ||
|
|
cfff7ad14e | ||
|
|
cdaaee62f3 | ||
|
|
556df985b9 | ||
|
|
8c2c784a41 | ||
|
|
9b5ee500fc | ||
|
|
1a6833045c | ||
|
|
d5740974cc | ||
|
|
8bbd536717 | ||
|
|
73ee5bf308 | ||
|
|
795515fe3f | ||
|
|
f098bdc613 | ||
|
|
2636412c0e | ||
|
|
719711ea3f | ||
|
|
74d42cdad6 | ||
|
|
5d980dc6e3 | ||
|
|
1511919437 | ||
|
|
2d5ed90fb2 | ||
|
|
1a91329864 | ||
|
|
fb0159620e | ||
|
|
26697b9585 | ||
|
|
7946519828 | ||
|
|
8cb060cdb4 | ||
|
|
7a89a1fe4c | ||
|
|
d8efad2479 | ||
|
|
00522b56fc | ||
|
|
7cd9a48ee3 | ||
|
|
cfe751ccab | ||
|
|
57ea80a5c0 | ||
|
|
28c9ee7e3c | ||
|
|
dbf71bdc5f |
No files matched your search
@@ -3,43 +3,242 @@
|
||||
A modern C toolchain for the DEC VT1200 / TI TMS34010, built as a small fork of
|
||||
upstream LLVM.
|
||||
|
||||
**Status: M3.** `llc -march=tms34010` emits GSPA-compatible assembly using the
|
||||
TI ABI: integer/pointer arguments are pushed on the program stack, the result is
|
||||
returned in `A8`, frames use `A13`/`A14`/`A15`, and functions end in `RETS 2`
|
||||
(`RETS 0` without arguments). M3 adds conditional/unconditional branches,
|
||||
ordinary `while`/`for` loops, integer ALU/shift operations, and the first
|
||||
compiled C Xlib client: a four-call window opened with `XOpenDisplay`, created with
|
||||
`XCreateSimpleWindow`, mapped with `XMapWindow` and synchronized with `XSync`.
|
||||
It is still **assembly-only**: no object writer, no `clang -c`, and no native
|
||||
COFF; GSPA/GSPLNK under DOSBox produce the COFF. XImage/XEvent, the real client,
|
||||
structs by value, function pointers, floats and `i64` remain M4/M5.
|
||||
**Status: M5.** `llc -march=tms34010 -filetype=obj` now emits TI-COFF objects
|
||||
that GSPLNK 2.00 links and the existing VT1200 loader runs; the M4
|
||||
`-filetype=asm` → GSPA/GSPLNK path remains the oracle and fallback. The TI ABI
|
||||
is unchanged: integer/pointer arguments are pushed on the program stack, the
|
||||
result is returned in `A8`, frames use `A13`/`A14`/`A15`, and functions end in
|
||||
`RETS 2` (`RETS 0` without arguments). M5 adds the native object path, the full
|
||||
MC encoder/assembler/disassembler, `JR`/branch relaxation, `MMTM`/`MMFM`
|
||||
register-list saves, dynamic `alloca`, `byval`, narrow returns, target
|
||||
`memcpy`/`memset`, the switch-table GEP fix that removes the
|
||||
`-switch-to-lookup=false` driver workaround, long private-name capping, and the
|
||||
first pinned external conformance tier (LLVM `CodeGen/Generic`, GCC 16.2
|
||||
c-torture and c-testsuite). Floats/double, `long long`, general `va_list`
|
||||
varargs, bitfields, aggregate returns/`sret`, debug info and the full external
|
||||
suites are M6.
|
||||
|
||||
Branch `m5` is the current milestone snapshot in both repositories; the
|
||||
default branch is `m4` until the controller/user updates it after the final
|
||||
review. Branch `m4` remains the previous snapshot, `m3` the M3 snapshot, `m2`
|
||||
the M2 tip and `m1` the reproducible M1 snapshot.
|
||||
|
||||
- Design: [`docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md`](docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md)
|
||||
- M0 plan: [`docs/superpowers/plans/2026-11-10-tms34010-m0-fork-and-bit-address-semantics.md`](docs/superpowers/plans/2026-11-10-tms34010-m0-fork-and-bit-address-semantics.md)
|
||||
- M1 plan: [`docs/superpowers/plans/2026-11-11-tms34010-m1-minimal-backend.md`](docs/superpowers/plans/2026-11-11-tms34010-m1-minimal-backend.md)
|
||||
- M2 plan: [`docs/superpowers/plans/2026-11-11-tms34010-m2-ti-abi-and-rom-calls.md`](docs/superpowers/plans/2026-11-11-tms34010-m2-ti-abi-and-rom-calls.md)
|
||||
- M3 plan: [`docs/superpowers/plans/2026-11-11-tms34010-m3-control-flow-and-xlib-window.md`](docs/superpowers/plans/2026-11-11-tms34010-m3-control-flow-and-xlib-window.md)
|
||||
- M4 plan: [`docs/superpowers/plans/2026-11-12-tms34010-m4-xlib-image-events-and-termtris.md`](docs/superpowers/plans/2026-11-12-tms34010-m4-xlib-image-events-and-termtris.md)
|
||||
- M5 plan: [`docs/superpowers/plans/2026-11-12-tms34010-m5-native-object-path-and-conformance.md`](docs/superpowers/plans/2026-11-12-tms34010-m5-native-object-path-and-conformance.md)
|
||||
- Spike: [`spike/REPORT-23.md`](spike/REPORT-23.md) (current, LLVM 23.1.5);
|
||||
[`spike/REPORT.md`](spike/REPORT.md) (historical, 19.1.7)
|
||||
|
||||
## Repositories
|
||||
|
||||
- **Compiler fork:** <https://git.wut.ee/opencode.siil.arti.ee/llvm-tms34010>
|
||||
(branch `m3`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2/M3 backend. Branch `m2` (the
|
||||
repository default) is the M2 snapshot; branch `tms34010` is the M1 tip and
|
||||
keeps the original M1 backend and suite.
|
||||
(branch `m5`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2/M3/M4/M5 backend. Branch `m4`
|
||||
(the repository default) is the previous snapshot; branch `m3` is before
|
||||
that, branch `m2` is the M2 tip and branch `tms34010` is the M1 tip and keeps
|
||||
the original M1 backend and suite.
|
||||
- **This project:** <https://git.wut.ee/opencode.siil.arti.ee/tms-c-compiler>
|
||||
(branch `m3`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2/M3 harnesses and the spike. Branch `m2` (the
|
||||
repository default) is the M2 snapshot and branch `m1` is the reproducible M1
|
||||
(branch `m5`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2/M3/M4/M5 harnesses and the conformance tier.
|
||||
Branch `m4` (the repository default) is the previous snapshot; branch `m3`
|
||||
is before that, `m2` is the M2 snapshot and `m1` is the reproducible M1
|
||||
snapshot, including the retired M1 harness.
|
||||
|
||||
The compiler fork is the canonical source for all target code. `patches/llvm`
|
||||
here is a **frozen M0 mirror** used by the default upstream+patches build; M2/M3
|
||||
do not change it.
|
||||
here is a **frozen M0 mirror** used by the default upstream+patches build;
|
||||
M2–M5 do not change it.
|
||||
|
||||
## What M3 provides
|
||||
## What M5 provides
|
||||
|
||||
M5 adds the native object path and the first external conformance tier while
|
||||
keeping the M4 assembly path as the oracle:
|
||||
|
||||
- **Native TI-COFF objects.** `llc -march=tms34010 -filetype=obj` writes a
|
||||
relocatable TI-COFF object with `.text`/`.data`/`.bss`, three section symbols
|
||||
with GSPA's 18-byte aux records, `C_EXT` globals and undefined externals, and
|
||||
10-byte `R-RELLONG` (`0x11`) relocations whose addends are **bit** addresses.
|
||||
GSPLNK 2.00 links the object (same-section `0xFFFF`, cross-section section
|
||||
symbols, and section-0 externals), and the existing dwt loader runs the
|
||||
linked image. Sizes in the object are bits, as in GSPA; `.data` and `.bss`
|
||||
are word-granular because the loader requires whole 16-bit words. There is
|
||||
no new linker and no new object format: the M4 asm path is unchanged and is
|
||||
still the default in `scripts/m4/run.sh`. `scripts/m5/native.sh` and
|
||||
`scripts/tests/m5/native.sh` build xshow and the six-TU termtris through the
|
||||
object path; the native and asm linked `.text` decode to the same
|
||||
instruction streams (753 xshow and 6,356 termtris instructions), and the
|
||||
native termtris links `.text` 166,608 bits (20,826 bytes), `.data` 9,536
|
||||
bits (1,192 bytes) and `.bss` 121,808 bits with loader status 0.
|
||||
- **Full MC layer.** `TMS34010MCCodeEmitter`, `MCAsmBackend`, the TI-COFF
|
||||
`MCObjectWriter`/`MCStreamer`, an `MCAsmParser` and an `MCDisassembler`
|
||||
cover the supported instruction table. `llvm-mc -triple=tms34010`
|
||||
assembles/disassembles it; `encodings.s` pins 126 `-show-encoding` cases,
|
||||
`disassembler.s` 77 inverse checks, and `roundtrip.s` 88 instructions
|
||||
round-trip through the 1987 `dis34`. The expected bytes come from GSPA
|
||||
listings, not from the new encoder. `llvm-mc -filetype=obj` uses LLVM's
|
||||
generic ELF writer; only `llc -filetype=obj` produces TI-COFF. The 10-byte
|
||||
`MOVE @a,@b`/`MOVB @a,@b` forms are not modeled and fail loudly.
|
||||
- **`JR` and branch relaxation.** Selection still builds the three-word
|
||||
absolute `JAUC`/`JA<cc>` branches; a pre-emit `TMS34010BranchRelaxation`
|
||||
pass then assumes the one-word relative `JR`/`JR<cc>` form and grows a branch
|
||||
back to `JA*` when its signed 8-bit word displacement is out of range
|
||||
(`±127` words = `±2032` bits), zero, odd, or its target is unknown. The MC
|
||||
backend independently relaxes a symbolic `JR` with the `FK_JR8` fixup, so
|
||||
`llvm-mc` input relaxes too. Relative to the M4 938-byte M3 image, 14 `JR`
|
||||
branches save 56 bytes and the MMTM/MMFM change saves another 8, giving 874
|
||||
(the current all-`JA` baseline is 930).
|
||||
- **`MMTM`/`MMFM` register-list saves.** The prologue saves the callee-saved
|
||||
set with one `MMTM SP, ...` and the epilogue restores it with one
|
||||
`MMFM SP, ...` (ascending register list; `MMTM` mask `0xd400` / `MMFM` mask
|
||||
`0x002b` for `A0,A1,A3,A5`). The old-STK slot, `A13` save, `A8` return and
|
||||
`RETS 2` arithmetic are unchanged. For a list of n saved registers the old
|
||||
per-register sequence cost 4n bytes and the new pair costs 8: n=1 grows by
|
||||
4 bytes, n=2 breaks even, n=3 saves 4 and n=4 saves 8.
|
||||
- **`alloca`, `byval`, narrow returns and `memcpy`/`memset`.** Dynamic
|
||||
`alloca` adjusts A14 in **bits** (`size << 3`), honors the requested
|
||||
alignment in bits, and supports `stacksave`/`stackrestore`; a no-argument
|
||||
function with a VLA rebuilds A14 from FP in the epilogue. `byval` copies the
|
||||
object to the program stack and advances A14 by `alignTo(size,2)` bytes
|
||||
(×8 bits). `i8`/`i16` returns leave `A8` with the declared
|
||||
`zeroext`/`signext` and the caller truncates/extends. Constant-size
|
||||
`memcpy`/`memset` become word/byte copies and runtime sizes become inline
|
||||
loops with bit-scaled GEPs. A constant `memmove` (including sizes <= 64
|
||||
bytes, which PreISel leaves alone) is expanded by a target pass into the
|
||||
same overlap-safe forward/backward loops; no `_memcpy`/`_memset`/`_memmove`
|
||||
libcall is emitted.
|
||||
`robust.sh` checks `alloca=408 byval=64 narrow=1056 mem=438 alloca_use=1496 byval6=64 memmove=2148`
|
||||
in both the asm and native paths.
|
||||
- **Driver policies.** `-switch-to-lookup=false` is gone. `tms-bitaddr`
|
||||
recognizes SimplifyCFG's `switch.table.*` GEP and shifts its byte/element
|
||||
index by 3, so the M4 switch and termtris lookups use bit-indexed tables
|
||||
under a plain `tms-clang -O2`. `-replexitval=never` remains a documented
|
||||
`tms-clang` TMS34010 policy until i64/M6: llc now rejects a raw-pipeline i33
|
||||
multiply with an actionable diagnostic (and keeps the 64-bit multiply
|
||||
diagnostic separate), and `tms-clang -O2` rejects a **static** variadic
|
||||
definition before dead-argument elimination can drop its `...`. `-O0` and
|
||||
the external `sprintf` still work.
|
||||
- **Private-label cap.** GSPA keeps only 31 identifier characters. M5 keeps
|
||||
the `_<8 hex>` module token, caps the base at 22 characters, and folds a
|
||||
longer base into a second 8-hex token before appending the module token, so
|
||||
two TUs with the same long static name still link. Public names longer than
|
||||
31 characters are still GSPA-truncated.
|
||||
- **Conformance fixes.** The tier exposed and fixed several real defects:
|
||||
`SETF16` must be sign-extending (`SETF 16, 1, 0`, `0x0570`; `fe=0` would
|
||||
zero-extend), a PHI copy can land between `CMP` and `Jcc` (`MOVE` writes the
|
||||
flags), so selection now emits a fused `CMPBR`/`CMPIBR` that is split after
|
||||
register allocation, and `gc.statepoint` calls get a target diagnostic
|
||||
instead of a `StatepointLowering` assertion. Object-mode `.bss` word
|
||||
granularity and the object `SRAK`/`SRLK` encoding were fixed as well.
|
||||
- **M3 tightening.** `m3-cmpi.ll` pins the `-O0`/`-O2` MOVI order with
|
||||
`CHECK`/`CHECK-NEXT`, and `scripts/m3/dis-roundtrip.sh` parses the
|
||||
nine-argument `XCreateSimpleWindow` pushes by value/register instead of
|
||||
hardcoding the registers.
|
||||
- **Conformance tier.** `scripts/tests/m5/conformance/run.sh` compiles a test
|
||||
with `tms-clang`, links the `shim.c` + `entry.asm` harness (native TI-COFF
|
||||
first, asm/GSPA fallback for the exploratory runner), runs it in MAME
|
||||
through the pinned loader, and compares a status/output block
|
||||
(`01B00000`/`01B10000`). The c-testsuite tier forces `--mode native`, so an
|
||||
asm fallback is a gate failure. `classify.sh` rejects
|
||||
unsupported features with a reason; a skip is never a pass. The corpus is
|
||||
pinned to GCC 16.2.0 (`gcc-16.2.0.tar.xz`, SHA-256
|
||||
`e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e`) and
|
||||
c-testsuite commit `5c7275656d751de0e68b2d340a95b5681858ed07`, materialized
|
||||
under the ignored `vendor/conformance` (test-only; GCC is GPL and
|
||||
c-testsuite keeps its own per-test licenses; neither is distributed). The
|
||||
GCC version is only the c-torture corpus source; the compiler under test is
|
||||
`tms-clang`. The three gates are
|
||||
LLVM `CodeGen/Generic` (197 `.ll`: 107 pass / 90 unsupported / 0 crash, plus
|
||||
a 24-file curated allowlist), GCC c-torture `execute` (59/59 at `-O0` and
|
||||
`-O2`; the corpus classifier reports 1,112 supported / 580 skipped from
|
||||
1,692 tests), and c-testsuite `single-exec` (29 pass / 191 skip / 220, with
|
||||
exact `.c.expected` output). The shim provides `printf`/`putchar`/`puts`
|
||||
through the M4 contiguous `&fmt` walk (no `va_list`), `exit`/`abort`, a
|
||||
16 KiB stdout buffer and a small string/integer surface. stderr is not
|
||||
captured, so stderr-writing tests are skipped rather than passed. On the
|
||||
reference machine the Generic gate takes about 6–7 minutes, c-torture about
|
||||
16–17 minutes and c-testsuite about 4–5 minutes; the serial MAME boot
|
||||
dominates.
|
||||
|
||||
## What M4 provides (branch `m4`, the previous snapshot)
|
||||
|
||||
M4 closed the remaining Xlib path to a real image/event client and a full-game
|
||||
integration, still assembly-only on that branch. M5 keeps this as the
|
||||
regression baseline and adds the native object path beside it.
|
||||
|
||||
- **Function pointers and `CALL Rs`.** A function pointer is a 32-bit bit
|
||||
address; an indirect call lowers to the one-word register call `CALL Rs`
|
||||
(GSPA `0x0920`, `dis34` `call aN`), with the same old-STK save, argument
|
||||
pushes, `SETF` fixup and `RETS 2` as a direct call. Direct calls remain
|
||||
`CALLA _sym`. `m4-fnptr.ll` + `scripts/tests/m4/fnptr.sh`.
|
||||
- **32-bit multiply/divide.** `MPYS`/`MPYU`/`DIVS`/`DIVU` with an odd
|
||||
destination (the even form is the `Rd:Rd+1` pair and would clobber the next
|
||||
register); remainder is quotient + `MPYS` + `SUB`. There is no compiler
|
||||
multiply/divide helper in `RTS.LIB`; `_div` is only the C `div()` wrapper.
|
||||
`m4-mul.ll` + `scripts/tests/m4/mul.sh`.
|
||||
- **Zero-extending and extending narrow loads.** `ZEXTLOAD`/`EXTLOAD` i8/i16
|
||||
lower to the sign-extending load plus `ANDI 255`/`ANDI 65535`; an i1 load is
|
||||
a byte load masked to one bit. `m4-zext.ll`, `m4-anyext.ll`,
|
||||
`m4-i1load.ll`.
|
||||
- **Module-unique private labels.** Every local symbol gets a custom 64-bit
|
||||
string-hash token (FNV-style, not canonical FNV-1a), so two TUs with literals
|
||||
no longer collide in GSPA's flat table; public names are unchanged.
|
||||
`m4-private.ll` and the two-TU `scripts/tests/m4/private.sh`. M5 caps a long
|
||||
private base so the module token survives GSPA's 31-character limit; see
|
||||
"What M5 provides".
|
||||
- **`i8`/`i16` fixed arguments (M4; M5 adds narrow returns).** Promoted to a
|
||||
4-byte stack slot; the caller sign/zero-extends per the parameter attribute
|
||||
and the callee truncates. `i8`/`i16`/`i64`/float/aggregate returns are
|
||||
rejected on `m4`; M5 adds `i8`/`i16` returns in `A8`. `m4-arg8.ll`,
|
||||
`m5-narrow-ret.ll`.
|
||||
- **Contiguous-stack varargs.** Only the `&last_fixed` walk used by termtris'
|
||||
`sprintf`; no `va_list`/`va_start`/`va_arg`. Zero-fixed and i8/i16-anchor
|
||||
definitions are rejected. On `m4`, static variadic definitions can lose `...`
|
||||
under `-O2` dead-argument elimination; M5 adds the `tms-clang` diagnostic and
|
||||
the llc check, while the external termtris `sprintf` remains supported.
|
||||
`m4-varargs.ll`, `m4-reject-vararg0.ll`,
|
||||
`m4-reject-vararg-narrow{,16}.ll`, `scripts/tests/m4/varargs.sh`,
|
||||
`m5-reject-static-vararg.ll`.
|
||||
- **Driver policies (M4 branch).** `scripts/tms-clang` passes
|
||||
`-replexitval=never` (the i33 exit-value multiply is unselectable on this
|
||||
i64-less target); M5 keeps it as a documented policy and adds the llc
|
||||
diagnostic for the raw pipeline. M4 also passed `-switch-to-lookup=false`
|
||||
(a late byte-offset GEP after `--scale` would be read as a bit offset, an 8x
|
||||
address bug); M5 removes that flag by fixing the switch-table GEP in
|
||||
`tms-bitaddr`. Both policies are driver-side because `opt` has no target
|
||||
machine.
|
||||
- **X11R4 `XImage`/`XEvent`/`XErrorEvent` layouts and the image client.** The
|
||||
real 32-bit packed offsets: `XImage` data 16, byte_order 20, bytes_per_line
|
||||
40, bits_per_pixel 44, f 64, `sizeof` 88; `XEvent` 96; `XErrorEvent` 20
|
||||
(with the explicit X11R4 object-size compatibility pad); `Display.screens`
|
||||
byte 0x90 / bit 0x480, `Screen.root` byte 0x8 / bit 0x40. The client draws a
|
||||
1-bit LSBFirst checker through an aligned pixmap + `XCopyArea` (12-pixel
|
||||
phase) and 15 bands of 32 rows (the ROM request buffer is 16 KiB), with
|
||||
`.bss` at `0x01A00000` and `prog` at `0x018A0000`. `XCopyArea` copies
|
||||
`IMG_W - 12` = 628 source columns (0–627) to window x = 12–639, so the
|
||||
image's rightmost 12 source columns (628–639, the final 12 px of the last
|
||||
32-px cell) are never displayed; that last cell is visible only as its left
|
||||
20 px. The 12-pixel prefix at window x = 0–11 is filled with the preceding
|
||||
cell's colour, so the checker phase is shifted by 12 px inside the (20,20)
|
||||
window while the cells remain 32 px. It asserts the checker pixels, the real
|
||||
LK401 `q` (keycode 193 / keysym `0x71`), window focus and zero X errors in
|
||||
MAME.
|
||||
- **Corrected 30-entry v2.2 symbol table.** `XMapWindow` is `0x3FD64F60`
|
||||
(MapWindow opcode 8); `0x3FD645B0` is `XRaiseWindow` (ConfigureWindow
|
||||
opcode 12, `CWStackMode=Above`). The XG block and the image/error-handler
|
||||
entries are validated by `scripts/m4/validate-syms.sh` and
|
||||
`scripts/tests/m4/symbols.sh`.
|
||||
- **Pinned termtris.** The full game builds with this compiler and the 1987
|
||||
GSPA/GSPLNK + `rts.lib`, at the pinned `vt1200-termtris` commit, and runs
|
||||
board/move/panels/quit in MAME with real key injection, the `0x40000`-bit
|
||||
`prog` region and the required thresholds. The tree is test-only (GPLv3).
|
||||
- **Differential goldens.** The 1987 TI compiler's function-pointer and
|
||||
image/struct-offset assembly is stored under `scripts/tests/m4/diff/`; the
|
||||
check compares ABI shape without running DOSBox.
|
||||
|
||||
## What M3 provides (branch `m3`)
|
||||
|
||||
M3 adds integer control flow and the first compiled C Xlib client, still
|
||||
assembly-only:
|
||||
@@ -62,8 +261,11 @@ assembly-only:
|
||||
- Misaligned accesses: `MOVE`/`MOVB` and the FS0/FS1 field-size forms have no
|
||||
alignment requirement on the TMS34010, so packed and bit-addressed struct
|
||||
fields select directly instead of being split into byte-wide accesses.
|
||||
- Nine `m3-*.ll` lit tests, for a total of 46 with the M2 suite; the M3
|
||||
end-to-end, dis34, layout and differential gates (below).
|
||||
- Nine `m3-*.ll` lit tests on the `m3` branch (46 with the M2 suite); M4
|
||||
removes five obsolete M2 refusal tests (`m2-reject-arg8`,
|
||||
`m2-reject-call-arg8`, `m2-reject-call-indirect`, `m2-reject-call-vararg`,
|
||||
`m2-reject-vararg`) and `m3-reject-zext.ll`, and adds 18 `m4-*` tests:
|
||||
46 - 5 - 1 + 18 = 58 total with the M2 suite.
|
||||
|
||||
M3 remains an `i32`/pointer milestone. `setcc` is supported, but narrow
|
||||
(`i8`/`i16`) parameters and returns are still rejected. Branches on `i64`,
|
||||
@@ -80,9 +282,9 @@ still emits assembly only.
|
||||
- **`-O2` loop exit-value rewriting is not lowered.** IndVarSimplify can turn
|
||||
`sumto`'s loop into a closed-form `i33` multiply, which M3 cannot select. The
|
||||
M3 harness therefore builds `branch.c` with `-replexitval=never`. Ordinary
|
||||
`while`/`for` loops that keep a real back-edge and phi work. M4/M5 must add
|
||||
multiply/`i64` lowering, a target-level pass policy, or a target diagnostic
|
||||
instead of a raw abort.
|
||||
`while`/`for` loops that keep a real back-edge and phi work. M4 adds
|
||||
multiply/divide and moves the `-replexitval=never` policy into
|
||||
`scripts/tms-clang`; see "What M4 provides".
|
||||
|
||||
## What M2 provides (branch `m2`)
|
||||
|
||||
@@ -92,8 +294,8 @@ M2 replaces the M1 test convention with the TI ABI and stops at assembly:
|
||||
functions with calls, frames and locals.
|
||||
- A caller saves `A14` (STK) on the system stack, pushes arguments on the
|
||||
program stack **in reverse order** (each a 32-bit slot), emits `CALLA`,
|
||||
then re-establishes both field sizes (`SETF 16,0,0`, `SETF 32,0,1`).
|
||||
- A callee starts with `SETF 16,0,0`/`SETF 32,0,1`, saves the used
|
||||
then re-establishes both field sizes (`SETF 16,1,0`, `SETF 32,0,1`).
|
||||
- A callee starts with `SETF 16,1,0`/`SETF 32,0,1`, saves the used
|
||||
A0–A7/A9–A12 registers and the old FP on the system stack, sets `FP = STK`,
|
||||
allocates the frame with `ADDI`, and restores both stacks in the epilogue.
|
||||
The first explicit argument is at `FP(-32)`, the second at `FP(-64)`, and
|
||||
@@ -117,7 +319,7 @@ M2 replaces the M1 test convention with the TI ABI and stops at assembly:
|
||||
|
||||
## The TI ABI
|
||||
|
||||
| | M1 test convention (branch `m1`) | TI ABI (M2/M3) |
|
||||
| | M1 test convention (branch `m1`) | TI ABI (M2–M5) |
|
||||
|---|---|---|
|
||||
| Integer/pointer arguments | `A0`–`A3`, four maximum | program stack via `A14` (STK), pushed in reverse |
|
||||
| Argument slots | registers | first at `FP(-32)`, second at `FP(-64)`, … |
|
||||
@@ -126,17 +328,172 @@ M2 replaces the M1 test convention with the TI ABI and stops at assembly:
|
||||
| Locals | none | positive FP offsets |
|
||||
| Return instruction | `RETS 0` | `RETS 2` with arguments, `RETS 0` without |
|
||||
| Calls, callee-saves, stack args | rejected | required |
|
||||
| Field size | harness sets FS1/FS0 before entry | `FS0 = 16` and `FS1 = 32`, set in the prologue and after every call |
|
||||
| Field size | harness sets FS1/FS0 before entry | `FS0 = 16, fe = 1` (sign-extending) and `FS1 = 32`, set in the prologue and after every call |
|
||||
|
||||
The callee-saved set is `A0`–`A7` and `A9`–`A12`; `A8` is the return register
|
||||
and `A13`–`A15` are reserved. After `n` system-stack pushes the saved old STK
|
||||
is at `SP + (n+1)*32`, and `RETS N` pops the return PC and advances `SP` by
|
||||
`32 + 16N`. `FS0` must be 16 and `FS1` must be 32 at function entry and
|
||||
immediately after every `CALLA` (`SETF 16,0,0` then `SETF 32,0,1`), because
|
||||
ROM code may change either field size. FS0 drives `short` loads/stores and FS1
|
||||
drives 32-bit words.
|
||||
`32 + 16N`. `FS0` must be 16 with the field-extension bit set (`SETF 16,1,0`,
|
||||
sign-extending) and `FS1` must be 32 at function entry and immediately after
|
||||
every `CALLA` (`SETF 16,1,0` then `SETF 32,0,1`), because ROM code may change
|
||||
either field size. FS0 drives `short` loads/stores and FS1 drives 32-bit words.
|
||||
|
||||
## Run the M3 gates
|
||||
## Run the M5 gates
|
||||
|
||||
These are the documented commands on branch `m5`; all must pass. The MAME and
|
||||
conformance gates are slow, share the M4 SDK image, and must run **serially**
|
||||
(no two gates at once).
|
||||
|
||||
```sh
|
||||
# 1. Build llc and the assembler/disassembler driver
|
||||
ninja -C build/llvm-clean-build llc llvm-mc
|
||||
|
||||
# 2. LLVM codegen tests: 76 passed (35 m2-* + 8 m3-* + 18 m4-* + 15 m5-*)
|
||||
build/llvm-clean-build/bin/llvm-lit -v \
|
||||
build/llvm-clean/llvm/test/CodeGen/TMS34010 --filter='(m2|m3|m4|m5)-'
|
||||
|
||||
# 3. MC tests: 4 passed (encodings, disassembler, round-trip, JR range)
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010
|
||||
|
||||
# 4. Native object, link and MC round-trip
|
||||
scripts/tests/m5/object-smoke.sh # native .text == GSPA .text
|
||||
scripts/tests/m5/native-link.sh # GSPLNK link + loader/MAME markers
|
||||
scripts/tests/m5/mc-roundtrip.sh # 88 instructions through dis34
|
||||
|
||||
# 5. The real M4 clients through the native object path
|
||||
scripts/tests/m5/native.sh
|
||||
# -> native xshow markers + termtris board/move/panels/quit + dis34 compare
|
||||
scripts/tests/m5/jr.sh # JR/relaxation + M3 MAME
|
||||
scripts/tests/m5/mmtm.sh # MMTM/MMFM + M2/M3 MAME
|
||||
scripts/tests/m5/robust.sh # alloca/byval/narrow/mem, both paths
|
||||
|
||||
# 6. Driver policy, private names and the conformance harness
|
||||
scripts/tests/m5/policy.sh
|
||||
scripts/tests/m5/private-long.sh
|
||||
scripts/tests/m5/conformance/selftest.sh
|
||||
|
||||
# 7. The conformance tiers
|
||||
scripts/tests/m5/generic.sh # Generic allowlist + no-crash sweep
|
||||
scripts/tests/m5/c-torture.sh # 59 tests at -O0 and -O2
|
||||
scripts/tests/m5/c-testsuite.sh # 29 output tests + 191 reported skips
|
||||
|
||||
# 8. M4, M3 and M2 regressions and the GEP tool
|
||||
scripts/tests/m4/run.sh
|
||||
scripts/tests/m4/dis-roundtrip.sh
|
||||
scripts/tests/m4/layout.sh
|
||||
scripts/tests/m4/symbols.sh
|
||||
scripts/tests/m4/termtris.sh
|
||||
scripts/tests/m4/diff/check.sh
|
||||
scripts/tests/m4/unsigned.sh
|
||||
scripts/tests/m4/private.sh
|
||||
scripts/tests/m4/mul.sh
|
||||
scripts/tests/m4/fnptr.sh
|
||||
scripts/tests/m4/varargs.sh
|
||||
scripts/tests/m3/run.sh
|
||||
scripts/tests/m3/dis-roundtrip.sh
|
||||
scripts/tests/m3/layout.sh
|
||||
scripts/tests/m3/diff/check.sh
|
||||
scripts/tests/m3/diff/negative-control.sh
|
||||
scripts/tests/m2/run.sh
|
||||
scripts/tests/m2/dis-roundtrip.sh
|
||||
scripts/tests/m2/diff/check.sh
|
||||
tools/tms-bitaddr/tests/run.sh
|
||||
```
|
||||
|
||||
`scripts/fetch-conformance.sh` materializes the pinned corpora under the
|
||||
ignored `vendor/conformance` (GCC 16.2.0 `gcc.c-torture/execute` and
|
||||
c-testsuite `single-exec`; `vendor/conformance/PINS` records the pins). The
|
||||
gate log prints each tier's counts; skipped tests carry a feature reason and
|
||||
are never counted as passes. The conformance tiers run serially because
|
||||
`M4_SDK` is shared; the MAME boot dominates the runtime.
|
||||
|
||||
## Run the M4 gates (branch `m4`; also green on `m5`)
|
||||
|
||||
These are the documented commands on branch `m4`; all must pass. On branch
|
||||
`m5`, use the M5 list above (it includes `llvm-mc` and the M5 gates); the M4
|
||||
commands below remain the historical regression set and use the `m4` test
|
||||
counts. The MAME gates are slow and are run once.
|
||||
|
||||
```sh
|
||||
# 1. Build llc, opt, clang and the test tools
|
||||
ninja -C build/llvm-clean-build llc opt clang llvm-config FileCheck count not
|
||||
|
||||
# 2. LLVM codegen tests: 58 passed (32 m2-* + 8 m3-* + 18 m4-*)
|
||||
build/llvm-clean-build/bin/llvm-lit -v \
|
||||
build/llvm-clean/llvm/test/CodeGen/TMS34010 --filter='(m2|m3|m4)-'
|
||||
|
||||
# 3. M4 image/event client in MAME (also runs layout.sh + validate-syms.sh)
|
||||
scripts/tests/m4/run.sh
|
||||
# -> m4 xshow: PASS (1-bit image + real q key + window focus + 0 X errors)
|
||||
|
||||
# 4. Linked .text decoded with dis34 (ROM stubs, CALL A?, SETF, RETS, checker)
|
||||
scripts/tests/m4/dis-roundtrip.sh
|
||||
# -> M4 dis34 round-trip: PASS
|
||||
|
||||
# 5. Layouts, the 30-entry symbol table, and the correction negative control
|
||||
scripts/tests/m4/layout.sh
|
||||
scripts/tests/m4/symbols.sh
|
||||
|
||||
# 6. The pinned termtris full-game integration
|
||||
scripts/tests/m4/termtris.sh
|
||||
# -> m4 termtris: PASS (board/move/panels/quit; .../termtris_*_3200.png)
|
||||
|
||||
# 7. Differential TI-compiler function-pointer/image ABI check (no DOSBox)
|
||||
scripts/tests/m4/diff/check.sh
|
||||
# -> M4 diff: PASS (goldens + negative controls)
|
||||
|
||||
# 8. The smaller M4 runtime gates
|
||||
scripts/tests/m4/unsigned.sh
|
||||
scripts/tests/m4/private.sh
|
||||
scripts/tests/m4/mul.sh
|
||||
scripts/tests/m4/fnptr.sh
|
||||
scripts/tests/m4/varargs.sh
|
||||
|
||||
# 9. M2/M3 regressions and the GEP tool tests
|
||||
scripts/tests/m3/run.sh
|
||||
scripts/tests/m3/dis-roundtrip.sh
|
||||
scripts/tests/m3/layout.sh
|
||||
scripts/tests/m2/run.sh
|
||||
scripts/tests/m2/dis-roundtrip.sh
|
||||
scripts/tests/m2/diff/check.sh
|
||||
tools/tms-bitaddr/tests/run.sh
|
||||
# -> tms-bitaddr: PASS
|
||||
```
|
||||
|
||||
`scripts/tests/m4/run.sh` first runs `layout.sh` and
|
||||
`scripts/m4/validate-syms.sh`, then compiles `scripts/m4/xshow.c` and
|
||||
`scripts/m4/xgfix.c` with `scripts/tms-clang -O2`, runs
|
||||
`llc -march=tms34010 -O0 -filetype=asm`, generates the ROM import stubs,
|
||||
concatenates `scripts/m4/xshow-entry.asm`, assembles/links with GSPA/GSPLNK
|
||||
2.00 under DOSBox, loads the COFF in MAME, injects the real LK401 `Q`, and
|
||||
requires the checker pixels, `quit=1`, keycode 193 / keysym `0x71`,
|
||||
`xerrors=0`, focus `0x400001` and the last event KeyPress. The 12-pixel
|
||||
prefix is checked as the preceding checker cell in bands 0 and 1.
|
||||
|
||||
`scripts/tests/m4/termtris.sh` runs the pinned tree through
|
||||
`scripts/m4/termtris/build.sh` and `play_keys.sh`; it enforces `loops >= 100`
|
||||
for all four modes, `events >= 6` for move/panels/quit (`>= 2` for board),
|
||||
`quit = 1` only for quit, focus = the created termtris window,
|
||||
`status=0 (OK)` and a non-empty screenshot each time. The vendored tree is
|
||||
test-only (GPLv3).
|
||||
|
||||
`scripts/tests/m4/diff/check.sh` is the new CI golden check. It compiles our
|
||||
function-pointer and image equivalents with `scripts/tms-clang` + `llc` and
|
||||
compares ABI shape with `scripts/tests/m4/diff/ti-fnptr.s` and
|
||||
`ti-image.s`: an indirect `CALL A?`, the old-STK save, argument/return/`RETS
|
||||
2`, ten `XCreateImage` and ten `XPutImage` pushes (the plan's 10/9 is a typo;
|
||||
`XPutImage` takes display, drawable, gc, image, src_x, src_y, dest_x, dest_y,
|
||||
width, height), nine `XCreateSimpleWindow` pushes, the leading
|
||||
constant/Display-last order, and the Display/Screen/XImage bit displacements.
|
||||
It then mutates copies of the goldens (removing the indirect call and
|
||||
reversing the `XPutImage` argument pushes) and requires the check to fail;
|
||||
the stored goldens are not modified. The goldens were generated once with
|
||||
GSP C Compiler 2.01 under DOSBox; CI never runs DOSBox.
|
||||
|
||||
Paths are overridable with `TMS_CLANG`, `TMS_OPT`, `TMS_BITADDR`, `TMS_LLC`,
|
||||
`MAME`, `DOSBOX`, `SDK_IMG`, the per-gate work/COFF variables and `M4_SYMS`.
|
||||
|
||||
## Run the M3 gates (branch `m3`)
|
||||
|
||||
These are the documented commands on branch `m3`; all must pass.
|
||||
|
||||
@@ -217,7 +574,7 @@ DOSBox, it greps the stored files. As in the MAME gate, `branch.c` must be
|
||||
built with `-replexitval=never`; the default exit-value rewrite turns
|
||||
`sumto`'s loop into an unselectable `i33` multiply.
|
||||
|
||||
## Run the M2 gates (default branch)
|
||||
## Run the M2 gates (branch `m2`)
|
||||
|
||||
These are the M2 commands; they also pass on `m3` (verified on branch `m3` on
|
||||
2026-11-11: `M2 MAME: PASS`, `M2 dis34 round-trip: PASS`, `M2 diff: PASS`). The
|
||||
@@ -320,9 +677,11 @@ M2 deliberately rejects or omits:
|
||||
- **Branches/control flow:** conditional and unconditional branches, loops,
|
||||
and spill/fixup paths that need them. A branch that reaches ISel fails
|
||||
loudly; M3 owns control flow.
|
||||
- **Floating point:** float/double arguments, returns and arithmetic (M5).
|
||||
- **Aggregates:** structs/unions by value, `sret`, `byval`, bitfields (M4/M5).
|
||||
- **Varargs:** `...` functions and calls (M5).
|
||||
- **Floating point:** float/double arguments, returns and arithmetic (M6).
|
||||
- **Aggregates:** structs/unions by value, `sret`, `byval`, bitfields (M5 adds
|
||||
`byval`; the rest are M6).
|
||||
- **Varargs:** `...` functions and calls (M4 adds the contiguous form; general
|
||||
`va_list` is M6).
|
||||
- **Function pointers and indirect calls** (M4).
|
||||
- **Tail calls:** ordinary `tail` markers are demoted to ordinary calls;
|
||||
`musttail` is not implemented (M2 C does not emit it). Real tail calls remain
|
||||
@@ -347,42 +706,66 @@ M3 deliberately stops at the first window and ordinary integer control flow:
|
||||
full X11R4 headers or real VT1200 client (M4). M3 uses exactly the four Xlib
|
||||
calls above and no other Xlib entry.
|
||||
- **Aggregates by value:** structs/unions passed or returned by value, `sret`,
|
||||
`byval`, bitfields (M4/M5). Struct *fields* through pointers are supported.
|
||||
bitfields (M5 adds `byval`; the rest are M6). Struct *fields* through
|
||||
pointers are supported.
|
||||
- **Function pointers and indirect calls:** the callee must be a direct global
|
||||
symbol (M4).
|
||||
- **Floating point and `i64`:** no float/double or 64-bit integer arguments,
|
||||
returns, arithmetic or branches (M5).
|
||||
returns, arithmetic or branches (M6).
|
||||
- **Object output:** still no `MCCodeEmitter`, object writer,
|
||||
`llc -filetype=obj`, `clang -c` or native COFF; GSPA/GSPLNK produce the COFF.
|
||||
The `JR`/branch-relaxation code-size pass is M5 as well.
|
||||
M5 adds the native path and the `JR`/branch-relaxation pass.
|
||||
- **Varargs, `musttail`, narrow ABI parameters/returns:** unchanged from M2.
|
||||
|
||||
## M4 prerequisites (carry-forwards)
|
||||
### M3 carry-forwards in M4
|
||||
|
||||
The final M3 review left these concrete prerequisites for M4:
|
||||
M4 closes three of the five final-M3 prerequisites: zero-extending loads
|
||||
replaced the reject test, private labels are module-unique, and unsigned/`<=`
|
||||
runtime coverage exists. The new M4 harness and
|
||||
`scripts/tests/m4/dis-roundtrip.sh` are operand/register-independent, and
|
||||
`layout.sh` was tightened. M5 completes the remaining M3 test-hardening
|
||||
carry-forwards: `m3-cmpi.ll` now pins the `-O0`/`-O2` MOVI order with
|
||||
`CHECK`/`CHECK-NEXT`, and `scripts/m3/dis-roundtrip.sh` parses the nine
|
||||
`XCreateSimpleWindow` push values/registers instead of hardcoding them. The
|
||||
M3 MAME values are unchanged.
|
||||
|
||||
- **Add zero-extending narrow loads.** M3 rejects `unsigned char`,
|
||||
`unsigned short` and `_Bool` loads (pinned by `m3-reject-zext.ll`); M4 must
|
||||
add the `ZEXTLOAD i8`/`i16` patterns and replace the reject test.
|
||||
- **Namespace every private label.** `scripts/tests/m3/run.sh` prefixes
|
||||
`LBB<n>_<m>` per translation unit, but deterministic private string labels
|
||||
are not renamed. Two TUs with literals therefore collide in GSPA's flat
|
||||
symbol table. M4 must namespace all private labels or make compiler private
|
||||
names module-unique.
|
||||
- **Add unsigned/`<=` runtime coverage.** `JALE`, `JALO`, `JAHI` and `JALS`,
|
||||
`JAHS`, `JANE`, `JAGE` are covered by lit tests only and do not appear in the
|
||||
compiled M3 image. M4 should add an unsigned/`<=` runtime marker.
|
||||
- **Replace fragile test plumbing.** The `always_inline` root helper and the
|
||||
register-hardcoded nine-argument dis34 check are test-strength aids that will
|
||||
not survive real M4 code; make them operand- and register-independent.
|
||||
- **Tighten test strength.** `m3-cmpi`'s `CHECK-DAG` for 0/1 does not pin their
|
||||
order, and `layout.sh` pairs the root probe with fixed constants; neither
|
||||
weakens the current pass, but both should be tightened.
|
||||
## M5 non-goals and the M6 boundary
|
||||
|
||||
M5 closes the M4 gaps for the native object path, `JR`/relaxation,
|
||||
`MMTM`/`MMFM`, narrow returns, `byval` and the switch-table policy. It
|
||||
deliberately stops before:
|
||||
|
||||
- **Floating point and `long long`:** no float/double or `i64` arguments,
|
||||
returns, arithmetic or branches; the i33/`-replexitval` policy stays until
|
||||
the i64 lowering lands.
|
||||
- **General varargs:** no `va_list`, `va_start` or `va_arg`; only the
|
||||
contiguous `&last_fixed` pattern used by termtris `sprintf`. M5 uses that
|
||||
same pattern inside the conformance shim; true `va_list` tests are skipped.
|
||||
- **Bitfields and aggregates by value:** bitfields, `sret`, aggregate returns
|
||||
and general aggregate arguments remain unsupported; `byval` arguments and
|
||||
struct fields through pointers are supported.
|
||||
- **Debug info and the wider Xlib surface:** no debug info, and the client uses
|
||||
only the validated image, event, GC, window and error-handler entries. It
|
||||
does not implement the whole Xlib surface, `XGetImage`, or `XDestroyImage` on
|
||||
a non-heap image.
|
||||
- **Full external suites and stderr:** the three tiers are curated subsets, not
|
||||
the full GCC/LLVM suites. The conformance shim captures stdout only, so
|
||||
tests that write stderr are skipped; stderr capture is M6.
|
||||
- **Deeper libc/runtime coverage:** the conformance shim is freestanding and
|
||||
does not add `RTS.LIB` entries. Broader libc/runtime integration is M6.
|
||||
- **Native `.cinit` and public long names:** the object writer accepts only
|
||||
`.text`/`.data`/`.bss` (termtris's `.cinit` is GSPA assembly and fails loudly
|
||||
if a C TU tries to emit it), and public identifiers longer than GSPA's 31
|
||||
characters are still truncated (only private names are capped).
|
||||
|
||||
The pinned GCC and c-testsuite trees are **test-only** and are not part of the
|
||||
compiler or project distribution (GCC is GPL; c-testsuite keeps its own
|
||||
per-test licenses).
|
||||
|
||||
## Repository layout
|
||||
|
||||
```text
|
||||
build/llvm-clean/ compiler fork checkout used for M2/M3 (ignored)
|
||||
build/llvm-clean/ compiler fork checkout used for M2–M5 (ignored)
|
||||
build/llvm-clean-build/ its Ninja build tree (ignored)
|
||||
build/llvm-src/ M0 working fork (ignored)
|
||||
patches/llvm/ frozen M0 patch series against llvmorg-23.1.5
|
||||
@@ -390,10 +773,19 @@ tools/tms-bitaddr/ GEP scale/normalize tool
|
||||
scripts/tms-clang IR pipeline wrapper (clang + tms-bitaddr + opt)
|
||||
scripts/m2/ M2 harness: C inputs, entry.asm, link.cmd, stubs, checks
|
||||
scripts/m3/ M3 harness: branch/xhello/layout inputs, Xlib header, entry/link
|
||||
scripts/m4/ M4 harness: unsigned/private/mul/fnptr/varargs, XImage client,
|
||||
XG fix, termtris build, symbols validator
|
||||
scripts/m5/ M5 harness: native entry/link files and long-private-name inputs
|
||||
scripts/tests/m2/ M2 gates (run.sh, dis-roundtrip.sh)
|
||||
scripts/tests/m2/diff/ TI golden asm and the differential ABI check
|
||||
scripts/tests/m3/ M3 gates (run.sh, dis-roundtrip.sh, layout.sh)
|
||||
scripts/tests/m3/diff/ TI branch/Xlib goldens, differential check + negative controls
|
||||
scripts/tests/m4/ M4 gates (run/dis-roundtrip/layout/symbols/termtris and the
|
||||
unsigned/private/mul/fnptr/varargs gates)
|
||||
scripts/tests/m4/diff/ TI function-pointer/image goldens + the differential check
|
||||
scripts/tests/m5/ M5 gates (object/link/MC/native/JR/MMTM/robust/policy/private)
|
||||
scripts/tests/m5/conformance/
|
||||
conformance runner, shim, entry, classifier, pins, manifests
|
||||
scripts/m1/ M1 harness (historical; also on branch `m1`, not an M2 gate)
|
||||
scripts/tests/m1/ M1 gates (historical; also on branch `m1`, not an M2 gate)
|
||||
scripts/tests/m0/ M0 integration tests
|
||||
@@ -408,10 +800,13 @@ docs/ design and plans
|
||||
## Prerequisites
|
||||
|
||||
`cmake`, `ninja-build`, `ccache`, a C++17 host compiler (GCC 14 is used here),
|
||||
Python 3, and about 20 GB of disk for the LLVM source and build. The M2/M3 MAME
|
||||
and dis34 gates additionally need `dosbox`, `mtools` (`mcopy`), the VT1200 SDK
|
||||
image, the `dwt` COFF loader, `dis34`, and a built MAME `vt1200` binary
|
||||
(`build/mame-src/vt1200`). The differential golden check needs no
|
||||
Python 3, and about 20 GB of disk for the LLVM source and build. The M2–M5
|
||||
MAME and dis34 gates additionally need `dosbox`, `mtools` (`mcopy`), the
|
||||
VT1200 SDK image, the `dwt` COFF loader, `dis34`, and a built MAME `vt1200`
|
||||
binary (`build/mame-src/vt1200`). The termtris gate also needs the pinned
|
||||
`vendor/vt1200-termtris` tree (test-only). The conformance tiers need the
|
||||
pinned `vendor/conformance` corpora (test-only; see
|
||||
`scripts/fetch-conformance.sh`). The differential golden check needs no
|
||||
DOSBox/MAME/SDK; it needs only the built `clang`, `opt`, `llc` and
|
||||
`tools/tms-bitaddr/tms-bitaddr`. On Debian:
|
||||
|
||||
@@ -430,14 +825,14 @@ Xlib call sequence, `as34`, `dis34`, SDKs, manuals). It is not vendored:
|
||||
|
||||
## Build the compiler
|
||||
|
||||
### Compiler fork (M3, the normal path)
|
||||
### Compiler fork (M5, the normal path)
|
||||
|
||||
The fork checkout already exists at `build/llvm-clean` on `m3`. Build it in
|
||||
The fork checkout already exists at `build/llvm-clean` on `m5`. Build it in
|
||||
place:
|
||||
|
||||
```sh
|
||||
LLVM_SRC=$PWD/build/llvm-clean LLVM_BRANCH=m3 ./scripts/build-llvm.sh
|
||||
# binaries: build/llvm-clean-build/bin/{llc,clang,opt,llvm-config,FileCheck}
|
||||
LLVM_SRC=$PWD/build/llvm-clean LLVM_BRANCH=m5 ./scripts/build-llvm.sh
|
||||
# binaries: build/llvm-clean-build/bin/{llc,llvm-mc,clang,opt,llvm-config,FileCheck}
|
||||
# lit driver: build/llvm-clean-build/bin/llvm-lit
|
||||
```
|
||||
|
||||
@@ -445,14 +840,14 @@ To clone the fork first instead of using an existing checkout:
|
||||
|
||||
```sh
|
||||
LLVM_REPO=gitea@git.wut.ee:opencode.siil.arti.ee/llvm-tms34010.git \
|
||||
LLVM_BRANCH=m3 ./scripts/build-llvm.sh
|
||||
LLVM_BRANCH=m5 ./scripts/build-llvm.sh
|
||||
```
|
||||
|
||||
Fork mode **never** checks out, resets, cleans or patches the source tree; it
|
||||
only runs CMake and Ninja. Local commits on the branch are safe. Use
|
||||
`LLVM_BUILD=...` to keep a separate build directory. It builds `llc`, clang,
|
||||
opt, `llvm-config`, FileCheck and the test helpers with X86 (host) and
|
||||
TMS34010; a first build takes roughly 20–40 minutes.
|
||||
`LLVM_BUILD=...` to keep a separate build directory. It builds `llc`,
|
||||
`llvm-mc`, clang, opt, `llvm-config`, FileCheck and the test helpers with X86
|
||||
(host) and TMS34010; a first build takes roughly 20–40 minutes.
|
||||
|
||||
### Upstream + patches (frozen M0 path)
|
||||
|
||||
@@ -462,22 +857,23 @@ TMS34010; a first build takes roughly 20–40 minutes.
|
||||
|
||||
This mode clones `llvmorg-23.1.5`, applies `patches/llvm/*.patch`, and builds
|
||||
`build/llvm-clean-build`. It owns and resets only a plain `llvm-project` clone:
|
||||
if `build/llvm-clean` has some other origin (for example the M2/M3 fork), it
|
||||
refuses rather than destroying it. Use fork mode for that checkout.
|
||||
if `build/llvm-clean` has some other origin (for example the M2–M5 fork),
|
||||
it refuses rather than destroying it. Use fork mode for that checkout.
|
||||
|
||||
`scripts/export-patches.sh` regenerates the committed M0 patch series with
|
||||
`git diff` (including new files via `git add -N`); it is not used for M1/M2/M3.
|
||||
`git diff` (including new files via `git add -N`); it is not used for
|
||||
M1–M5.
|
||||
|
||||
## Build the M0 support tools
|
||||
|
||||
The M2/M3 pipeline uses `tms-bitaddr` and `tms-clang`:
|
||||
The M2–M5 pipeline uses `tms-bitaddr` and `tms-clang`:
|
||||
|
||||
```sh
|
||||
LLVM_CONFIG=$PWD/build/llvm-clean-build/bin/llvm-config \
|
||||
tools/tms-bitaddr/build.sh
|
||||
```
|
||||
|
||||
M0 regression test (optional in M2/M3):
|
||||
M0 regression test (optional in M2–M5):
|
||||
|
||||
```sh
|
||||
TMS_CLANG=$PWD/build/llvm-clean-build/bin/clang \
|
||||
@@ -487,7 +883,7 @@ TMS_BITADDR=$PWD/tools/tms-bitaddr/tms-bitaddr \
|
||||
# -> M0 pipeline: PASS
|
||||
```
|
||||
|
||||
## Emit assembly by hand
|
||||
## Emit assembly or a native object by hand
|
||||
|
||||
```sh
|
||||
TMS_CLANG=$PWD/build/llvm-clean-build/bin/clang \
|
||||
@@ -497,6 +893,8 @@ TMS_BITADDR=$PWD/tools/tms-bitaddr/tms-bitaddr \
|
||||
|
||||
build/llvm-clean-build/bin/llc -march=tms34010 -O0 -filetype=asm \
|
||||
/tmp/add2.ll -o /tmp/add2.s
|
||||
build/llvm-clean-build/bin/llc -march=tms34010 -O0 -filetype=obj \
|
||||
/tmp/add2.ll -o /tmp/add2.o # TI-COFF, link with GSPLNK
|
||||
```
|
||||
|
||||
The resulting function loads its arguments at `FP(-32)` and `FP(-64)`, returns
|
||||
@@ -505,15 +903,17 @@ in `A8`, and ends in `RETS 2`. Always produce the IR with `scripts/tms-clang`
|
||||
offsets, but `llc` treats every surviving GEP offset as a *bit* offset, so
|
||||
addresses would be 8× too small. Run `llc -O0` on the normalized IR that
|
||||
`tms-clang` already optimized and scaled. `tms-bitaddr --normalize` consumes
|
||||
that scaled IR and rejects a typed (non-`i8`) or vector GEP instead of emitting
|
||||
its byte offset as bits. The lit tests use
|
||||
that scaled IR and rejects a typed (non-`i8` or `switch.table.*`) or vector GEP
|
||||
instead of emitting its byte offset as bits. The lit tests use
|
||||
`llc -march=tms34010 -O2 -filetype=asm` on hand-written IR to exercise the
|
||||
selector pipeline directly. Output is assembly only: `llc` cannot emit an
|
||||
object file or a usable COFF for this target.
|
||||
selector pipeline directly. `-filetype=obj` writes a TI-COFF object that
|
||||
GSPLNK 2.00 links; the existing loader runs the linked image. `llvm-mc
|
||||
-triple=tms34010` assembles and disassembles the same instruction table.
|
||||
|
||||
## Later milestones
|
||||
|
||||
M4 adds the real Xlib client (`XImage`/`XEvent`, the full X11R4 headers),
|
||||
structs by value and function pointers. M5 adds the native COFF path, floats,
|
||||
varargs, bitfields, `long long` and the `JR`/branch-relaxation code-size pass;
|
||||
2ine r5.01 is a later speed-up for the GSPA/GSPLNK step.
|
||||
M6 adds floats/double, `long long`/`i64` (and removes the i33
|
||||
`-replexitval=never` workaround), general varargs (`va_list`), bitfields,
|
||||
structs by value, `sret`, aggregate returns, debug info, the wider Xlib
|
||||
surface, stderr capture in the conformance harness, and the full external
|
||||
suites. 2ine r5.01 is a later speed-up for the GSPA/GSPLNK step.
|
||||
@@ -21,7 +21,7 @@
|
||||
- **Flags are modeled with a reserved `ST` pseudo-register:** `CMP`/`CMPI` define it, conditional branches and `SETCC` sequences use it. Do not silently drop the compare-to-branch dependency.
|
||||
- **CMP operand order:** for `icmp <pred> a, b` the compare must compute `a - b` (the branch condition reads the flags for `a <pred> b`). The signed/unsigned conditions map to the TMS34010 condition codes in `dis34`: `uc/p/ls/hi/lt/ge/le/gt/c/nc/eq/ne/v/nv/n/nn` (0–15).
|
||||
- M3 scalar control flow: i32/pointer values, signed and unsigned integer compares, `and`/`or`/`xor`/`shl`/`lshr`/`ashr`/`sub`/`neg`/`not`; no switch tables, indirect branches, floats, i64, or function pointers in M3.
|
||||
- **Xlib is ROM-v2.2 only.** Use the four known-good entries from `symbols/vt1200-v22.syms`: `XOpenDisplay 0x3F9C2570`, `XCreateSimpleWindow 0x3FD41B90`, `XMapWindow 0x3FD645B0`, `XSync 0x3FD9F6B0`. The stubs are `JAUC <address>h`; `CALLA _XOpenDisplay` reaches the ROM function.
|
||||
- **Xlib is ROM-v2.2 only.** Use the four known-good entries from `symbols/vt1200-v22.syms`: `XOpenDisplay 0x3F9C2570`, `XCreateSimpleWindow 0x3FD41B90`, `XMapWindow 0x3FD64F60`, `XSync 0x3FD9F6B0`. (`0x3FD645B0` is `XRaiseWindow`, not `XMapWindow`; the M4 correction verified it.) The stubs are `JAUC <address>h`; `CALLA _XOpenDisplay` reaches the ROM function.
|
||||
- **Display/Screen layout is ROM-specific:** xhello's `*a11(0480h)`/`*a10(040h)` are **bit displacements**, so `Display.screens` is the 32-bit pointer at **byte 0x90** (bit `0x480`) and `Screen.root` is the 32-bit root id at **byte 0x8** (bit `0x40`). M3 uses a minimal `scripts/m3/vt1200_xlib.h` with byte pads 0x90/0x8 and `_Static_assert`s, returning the ROM's bit offsets `0x480`/`0x40`; do not assume the host X11R7 `_XDisplay` layout matches the ROM. The full X11R4 `XImage`/`XEvent` headers are M4.
|
||||
- `XOpenDisplay("0::0")` must run in the loader-created `create_process` child, not the rdebug dispatcher; the M2 `_start`/loader path satisfies this.
|
||||
- `XCreateSimpleWindow` takes 9 arguments: `display, parent, x, y, width, height, border_width, border, background`; the first argument is at `FP(-32)`, the ninth at `FP(-288)`; `RETS 2`.
|
||||
@@ -588,7 +588,7 @@ Then read the VRAM pixel inside the window: the window is at `(100,100)`, 400×2
|
||||
|
||||
`scripts/m3/dis-roundtrip.sh` adapts the M2 COFF parser and symbol lookup. It must require:
|
||||
|
||||
- the `_XOpenDisplay`/`_XCreateSimpleWindow`/`_XMapWindow`/`_XSync` `JAUC` stubs at `3F9C2570`/`3FD41B90`/`3FD645B0`/`3FD9F6B0`;
|
||||
- the `_XOpenDisplay`/`_XCreateSimpleWindow`/`_XMapWindow`/`_XSync` `JAUC` stubs at `3F9C2570`/`3FD41B90`/`3FD64F60`/`3FD9F6B0`;
|
||||
- a `CALLA _XOpenDisplay` with one argument push; `CALLA _XCreateSimpleWindow` with **nine** `MOVE ...,*A14+,1` pushes in order (the first argument at the top of the program stack); `CALLA _XMapWindow` with two; `CALLA _XSync` with two;
|
||||
- the `SETF 16,0,0` + `SETF 32,0,1` after each call; `RETS 2` for the nine-argument function;
|
||||
- the branch code: `CMP`, `JALT`/`JAGT`/`JALE`/`JALO`/`JAHI`, `JAUC`, and the `LBB…` labels (no dot);
|
||||
|
||||
@@ -0,0 +1,548 @@
|
||||
# TMS34010 M4 — Xlib Images, Events, and the termtris Integration Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** A compiled C program displays a 1-bit `XImage` through the ROM Xlib, handles real X events and keyboard input, and exits cleanly; the project also builds the WIP `termtris` VT1200 client with this compiler and runs its move/panels/quit acceptance in MAME.
|
||||
|
||||
**Architecture:** M4 keeps the M3 asm-only path and TI ABI. It fills the scalar gaps real clients need (zero-extending narrow loads, module-unique private labels, unsigned/`<=` runtime coverage, 32-bit multiply/divide through `rts.lib`), adds function pointers/indirect `CALL`, adds the X11R4-compatible `XImage`/`XEvent`/`XErrorEvent` layouts, corrects the ROM symbol table, and implements the mandatory per-process XG block so a loader child can receive events. Two small clients prove the image and event paths; the pinned `termtris` branch is a third, full-game integration test.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m4`), C++17, CMake/Ninja, `llc`, GSPA/GSPLNK 2.00 under DOSBox, COFF loader, MAME, `dis34`, `llvm-lit`/FileCheck, 1987 TI compiler, the pinned `termtris` branch.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (§4.2, §7.3.1, §7.4–§7.7, §7.9, M4, M5)
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Compiler work happens in **`llvm-tms34010`**, branch `m4`, created from `m3` at `73c85350a401`. Use `build/llvm-clean` and `build/llvm-clean-build`; do not clone another LLVM tree.
|
||||
- Project plans/tests live in **`tms-c-compiler`**, branch `m4`, created from `m3` at `24f8773` plus the M4 plan commit. `m3` stays the default snapshot until M4 is reviewed; do not merge M2/M3 into `m0`.
|
||||
- The M3 TI ABI, `.data`, branch/loop, FS0/FS1 and old-STK rules are unchanged. M4 adds: function pointers/indirect calls, zero-extending narrow loads, module-unique private labels, 32-bit multiply/divide, XImage/XEvent/error-handler layouts, the XG block, and the wider Xlib.
|
||||
- Output remains **assembly only**: `llc -march=tms34010 -filetype=asm`; GSPA/GSPLNK 2.00 under DOSBox; the existing COFF loader. No LLVM object writer/MCCodeEmitter (M5).
|
||||
- **ROM v2.2 only.** Use the termtris `xlib.h` table and the ROM disassembly. Correct the table: **`XMapWindow = 0x3FD64F60`** (request opcode 8); **`0x3FD645B0` is `XRaiseWindow`** (ConfigureWindow, opcode 12, value-mask `0x40`/`CWStackMode`, value 0/`Above`), not a mapping entry. The M3 table/`xhello` used `0x3FD645B0` under the `XMapWindow` name; its MAME gate still saw a solid-white client area, so re-run that gate with `0x3FD64F60` and record whether the old pass depended on server-side create/configure behavior. The M3 harness/docs/dis34 expectations are updated.
|
||||
- **Per-process XG block is mandatory before `XOpenDisplay` in a loader child.** The termtris fix: `proc = *(u32*)0x001B3900; pp = *(u32*)(proc+0x100); *(u32*)pp = (u32)zeroed_1KiB;`. Without it `_XEnq` sees `XG == NULL` and `XNextEvent` delivers garbage/nothing. The ROM is untouched.
|
||||
- Known text/event/GC entries (termtris `xlib.h`): `XOpenDisplay 0x3F9C2570`, `XCreateSimpleWindow 0x3FD41B90`, `XSelectInput 0x3FD97D50`, `XSync 0x3FD9F6B0`, `XFlush 0x3F9B1030`, `XNextEvent 0x3F9C1CF0`, `XLookupString 0x3F9A9C30`, `XCreateGC 0x3F997000`, `XSetForeground 0x3FD99A60`, `XFillRectangle 0x3F99E8F0`, `XDrawString 0x3FDA0000`, `XPending 0x3FD67620`, `XGetInputFocus 0x3FD55210`, `XLoadFont 0x3FD4AE80`, `XCopyArea 0x3FD3E220`, `sleep 0x3FB33A20`. The `XImage` entries (`XCreateImage`, `XPutImage`, `XDestroyImage`, optional `XGetImage`) and `XSetErrorHandler`/`XSetIOErrorHandler` must be extracted/validated before use; do not guess.
|
||||
- `XMapWindow` is the mapping API for new clients; the M4 image/event clients use the true entry. The termtris client uses `XMapWindow 0x3FD64F60`.
|
||||
- The **termtris additional integration** is pinned at branch `termtris`, commit `be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf`. Its `apps/termtris` tree is GPLv3; vendor/read it with `COPYING` intact and test only. Build it with **this compiler**, not its TI r5.01/2ine path. Its acceptance is the proven `play_keys` run: `move`/`panels`/`quit`, `loops >= 100`, `events >= 6`, `focus` = the window, `quit = 1` for `q`, and the captured frames.
|
||||
- The **primary M4 acceptance** is the image/event client: a 1-bit `XImage` (LSBFirst) appears in MAME, no X errors are reported by the handler, and a real key press is delivered and processed. The termtris run is the additional, full-game integration test.
|
||||
- `XImage` data is `unsigned char`; zero-extending `unsigned char`/`unsigned short` loads must work. The program stack is A14 (grows up); the system stack A15; `RETS 2/0` and FS0/FS1 apply to indirect calls too.
|
||||
- X11 headers: use an X11R4-compatible subset (system Xlib/Xutil or a vendored minimal header). `Display.screens` remains byte `0x90` (bit `0x480`); `Screen.root` byte `0x8` (bit `0x40`). Verify the `XImage`/`XEvent`/`XErrorEvent` field offsets with `_Static_assert`s and a TI/host golden before relying on them.
|
||||
- The M2/M3 tests must stay green. Add `m4-*` lit tests and `scripts/tests/m4/*` gates.
|
||||
- No XImage/XEvent/the full Xlib beyond the listed calls; no floats/i64/varargs/bitfields/structs by value/native COFF in M4. The termtris compile may expose a gap; fix it or rule it out explicitly in the report.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Function pointer/indirect call ABI:** `CALL Rs`; the call-site old-STK save iff args; argument order; A8 return; FS0/FS1; the callee `RETS`. A wrong `CALL` target or stack leaves the caller corrupted. Tests in Task 3 (`m4-fnptr`, a C callback) and Task 7 (termtris callbacks).
|
||||
2. **XImage/XEvent/GC/XErrorEvent layout and semantics:** `XImage.byte_order`/`bitmap_bit_order` LSBFirst, `data`, `bytes_per_line`; `XEvent.type`/`xkey` fields; `XErrorEvent` fields. A wrong field or offset yields a black/garbled image or no key. Tests in Task 4 (static offsets) and Task 6 (image pixel/no-X-errors/key).
|
||||
3. **The XG block/event loop:** without `vt_install_xg()` before `XOpenDisplay` the loader child receives no events; the termtris tree documents the exact failure. Tests in Task 5 (XG gate) and Tasks 6/7 (keys/focus/quit).
|
||||
4. **`XMapWindow` vs `XRaiseWindow`:** the M3 table's `XMapWindow` (`0x3FD645B0`) is actually `XRaiseWindow` (ConfigureWindow opcode 12); the real `XMapWindow` is `0x3FD64F60` (opcode 8). Use it for new clients and correct the M3 harness/docs. Tests in Task 5 and the M3 re-run.
|
||||
5. **Narrow loads/unsigned/multiply/loop prerequisites:** `unsigned char` XImage data, `unsigned short`, `<=`/unsigned branches, and the `-O2` closed-form loop/multiply. A missing feature aborts a real client. Tests in Tasks 1/2 and the termtris run.
|
||||
6. **The termtris integration:** the pinned branch, the function-pointer callbacks, the event loop, the keys/panels/quit, the screenshots, the `loops/events/focus/quit` markers. Test in Task 7.
|
||||
7. **X11R4 layout vs the ROM:** the byte/bit `Display`/`Screen` and the `XImage`/`XEvent` fields; a header mismatch produces plausible but wrong data. Tests in Task 4 (static asserts) and Task 6.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: M4 branches, zero-extending narrow loads, private labels, and unsigned runtime
|
||||
|
||||
**Files:**
|
||||
- Modify: `build/llvm-clean/llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp`, `TMS34010InstrInfo.td`
|
||||
- Modify: `TMS34010TargetMachine.cpp` / `TMS34010AsmPrinter.cpp` (private symbol naming)
|
||||
- Test: `build/llvm-clean/llvm/test/CodeGen/TMS34010/m4-zext.ll`, `m4-private.ll` (or a two-TU shell test)
|
||||
- Create: `scripts/m4/unsigned.c`, `scripts/m4/private-a.c`, `private-b.c`, `scripts/tests/m4/{unsigned,private}.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: M3 target and tests.
|
||||
- Produces: `ZEXTLOAD i8/i16` selection; module-unique private symbols; runtime `JALS`/`JAHS`/`JANE`/`JAGE`/`JALE`/`JALO`/`JAHI` coverage.
|
||||
|
||||
- [ ] **Step 1: Write the failing tests**
|
||||
|
||||
`m4-zext.ll`:
|
||||
|
||||
```llvm
|
||||
; RUN: llc -march=tms34010 -O2 -filetype=asm < %s | FileCheck %s
|
||||
define i32 @zext8(ptr %p) {
|
||||
%v = load i8, ptr %p, align 1
|
||||
%r = zext i8 %v to i32
|
||||
ret i32 %r
|
||||
}
|
||||
define i32 @zext16(ptr %p) {
|
||||
%v = load i16, ptr %p, align 1
|
||||
%r = zext i16 %v to i32
|
||||
ret i32 %r
|
||||
}
|
||||
; CHECK-LABEL: _zext8:
|
||||
; CHECK: MOVB *A{{[0-9]+}}, A{{[0-9]+}}
|
||||
; CHECK: ANDI 255
|
||||
; CHECK-LABEL: _zext16:
|
||||
; CHECK: MOVE *A{{[0-9]+}}, A{{[0-9]+}}, 0
|
||||
; CHECK: ANDI 65535
|
||||
```
|
||||
|
||||
The `ANDI` forms are the 1's-complement immediates; the masks must be exact. `m4-private` compiles two TUs with the same private string literal and requires the GSPA link to succeed (no duplicate private label).
|
||||
|
||||
`scripts/m4/unsigned.c`:
|
||||
|
||||
```c
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n)*0x20u))
|
||||
int le(int a, int b) { return a <= b; }
|
||||
unsigned ule(unsigned a, unsigned b) { return a <= b; }
|
||||
int sum_le(int n) { int s = 0, i; for (i = 0; i <= n; i++) s += i; return s; }
|
||||
int unsigned_test(void) {
|
||||
MARK(0) = (unsigned)le(5, 7);
|
||||
MARK(1) = (unsigned)ule(7u, 5u);
|
||||
MARK(2) = (unsigned)sum_le(10);
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
`scripts/m4/private-a.c` and `private-b.c` each define a string literal and a function returning it, e.g. `char *a(void) { return "same"; }`; the linker must resolve both without a duplicate label.
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean-build/test/CodeGen/TMS34010 --filter='m4-(zext|private)'
|
||||
```
|
||||
|
||||
Expected: FAIL — `Cannot select: ... zext from i8/i16`, and the two-TU private link collides.
|
||||
|
||||
- [ ] **Step 3: Implement the zext loads and private naming**
|
||||
|
||||
- Set `ZEXTLOAD i8/i16` legal and add patterns: `MOVB` (which sign-extends) + `ANDI 255`, and FS0 `MOVE16` + `ANDI 65535`; reuse `ANDI` (the M4 `.td` fix already complements the immediate). Add the `ANDI` immediate 1's complement if needed.
|
||||
- Make private/string-literal symbols module-unique so two TUs with the same `.str`/private name do not collide in GSPA's flat symbol table. Keep public names unchanged; the sanitizer remains GSPA-valid. The two-TU test must assemble and link with `No Errors, No Warnings`.
|
||||
|
||||
- [ ] **Step 4: Run the MAME unsigned test**
|
||||
|
||||
Build `unsigned.c` with `tms-clang -O2` + `llc -O0`, link with the M3 `scripts/m4` harness/entry (a minimal entry calling `_unsigned_test`), and check `le(5,7)=1`, `ule(7,5)=0`, `sum_le(10)=55`. The assembly must contain `JALE`/`JALS` (or the correct unsigned `<=` form) and `JAHS`/`JAHI`.
|
||||
|
||||
- [ ] **Step 5: Run the suite and commit**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean-build/test/CodeGen/TMS34010 --filter='(m2|m3|m4)-'
|
||||
```
|
||||
|
||||
Expected: all green (the M3 suite plus the new tests). Commit the compiler changes and the project harness/tests; the report.
|
||||
|
||||
### Task 2: 32-bit multiply/divide and the `-O2` loop pipeline
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010InstrInfo.td`, `TMS34010ISelLowering.cpp/.h`, `TMS34010TargetMachine.cpp` (TTI/pass policy)
|
||||
- Create: `scripts/m4/mul.c`, `scripts/m4/loop.c`, `scripts/tests/m4/mul.sh`
|
||||
- Link: the 1987 `RTS.LIB` (the `_mul`/`_div`/`_mod` entries) or a target sequence
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1 and M3's `JAcc`/`ST`.
|
||||
- Produces: `MPYS`/`MPYU` 16×16; 32×32 multiply/divide via `rts.lib` libcalls or a sequence; an `-O2` loop policy that does not produce an unsupported i33 multiply.
|
||||
|
||||
- [ ] **Step 1: Write the failing tests**
|
||||
|
||||
`m4-mul.ll` (or C through `tms-clang`):
|
||||
|
||||
```llvm
|
||||
; RUN: llc -march=tms34010 -O2 -filetype=asm < %s | FileCheck %s
|
||||
define i32 @mul(i32 %a, i32 %b) {
|
||||
%r = mul i32 %a, %b
|
||||
ret i32 %r
|
||||
}
|
||||
; CHECK: MPYS
|
||||
; CHECK: MPYU
|
||||
```
|
||||
|
||||
`scripts/m4/loop.c`:
|
||||
|
||||
```c
|
||||
int sumto(int n) { int s = 0, i; for (i = 1; i <= n; i++) s += i; return s; }
|
||||
int squares(int n) { int s = 0, i; for (i = 0; i < n; i++) s += i * i; return s; }
|
||||
```
|
||||
|
||||
Compile with the **default** `tms-clang -O2` (no `-replexitval=never`) and require success + correct MAME results (`sumto(10)=55`, `squares(5)=30`).
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
```sh
|
||||
scripts/tms-clang -O2 -o /tmp/opencode/m4-mul.ll scripts/m4/mul.c
|
||||
build/llvm-clean-build/bin/llc -march=tms34010 -O0 -filetype=asm ...
|
||||
```
|
||||
|
||||
Expected: `Cannot select: mul` / `umul_lohi` / the i33 multiply / missing `_mul`.
|
||||
|
||||
- [ ] **Step 3: Implement the arithmetic and loop policy**
|
||||
|
||||
- Add `MPYS`/`MPYU` 16×16 and the 32×32 multiply/divide/remainder libcalls. Prefer linking the 1987 `RTS.LIB` `_mul`/`_div`/`_mod` entries (reuse the TI runtime; no new libc); wire the `TargetLowering` libcall names and the M4 `link.cmd` (`-l RTS.LIB`). If the runtime entry names differ, extract them from the SDK `RTS.LIB`/map and record them.
|
||||
- Address the `IndVarSimplify` exit-value i33 multiply: add a target `TargetTransformInfo`/pass policy that makes the closed-form replacement unprofitable for this target, or lower the i33/i64 multiply through the runtime. The M3 `m3` harness may keep `-replexitval=never`, but M4's ordinary `-O2` loop must compile.
|
||||
- Keep the M3 `shouldFoldConstantShiftPairToMask` behavior; the multiply/divide tests.
|
||||
|
||||
- [ ] **Step 4: Run the MAME multiply/loop tests**
|
||||
|
||||
`mul(6,7)=42`, `sumto(10)=55`, `squares(5)=30`; the `-O2` pipeline without the exit-value wrapper. Record the `RTS.LIB` link line and the symbols.
|
||||
|
||||
- [ ] **Step 5: Run the suite and commit**
|
||||
|
||||
Commit the compiler arithmetic/policy and the M4 tests; the report.
|
||||
|
||||
### Task 3: Function pointers and indirect calls
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010InstrInfo.td` (`CALL Rs`), `TMS34010ISelLowering.cpp/.h` (`LowerCall` indirect), `TMS34010MCInstLower.cpp` if needed
|
||||
- Test: `m4-fnptr.ll`, `scripts/m4/fnptr.c`, `scripts/tests/m4/fnptr.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: M3 `LowerCall`/`CALLA`/frames; Task 1/2.
|
||||
- Produces: `CALL Rs` (1-word indirect call; GSPA `CALL $rs`), function addresses as bit addresses, function-pointer parameters/returns, callback ABI.
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
`m4-fnptr.ll`:
|
||||
|
||||
```llvm
|
||||
; RUN: llc -march=tms34010 -O2 -filetype=asm < %s | FileCheck %s
|
||||
define i32 @inc(i32 %x) {
|
||||
%r = add i32 %x, 1
|
||||
ret i32 %r
|
||||
}
|
||||
define i32 @apply(ptr %f, i32 %x) {
|
||||
%r = call i32 %f(i32 %x)
|
||||
ret i32 %r
|
||||
}
|
||||
; CHECK-LABEL: _apply:
|
||||
; CHECK: CALL A{{[0-9]+}}
|
||||
; CHECK: RETS 2
|
||||
```
|
||||
|
||||
`scripts/m4/fnptr.c`:
|
||||
|
||||
```c
|
||||
typedef int (*fn)(int);
|
||||
int inc(int x) { return x + 1; }
|
||||
int apply(fn f, int x) { return f(x); }
|
||||
int fnptr_test(void) { return apply(inc, 41); } /* 42 */
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Expected: `M2/M3 supports only direct calls` fatal for the indirect call.
|
||||
|
||||
- [ ] **Step 3: Implement indirect calls**
|
||||
|
||||
- Define `CALL` (`CALL $rs`, 1 word, `isCall`, `Uses=[A14]`, `Defs=[A8,A14]`, 2 bytes) and the asm printer.
|
||||
- Extend `LowerCall`: accept a `RegisterSDNode`/`CopyFromReg` callee; emit the same old-STK/argument/`CALL Rs`/FS0-FS1/`A8` sequence as `CALLA`; reject only unsupported callee shapes. A function pointer is a 32-bit bit address; `MOVI _inc, A?` or `MOVI 0xADDR, A?` materializes it.
|
||||
- Keep the direct `CALLA` path and the `getCallPreservedMask`.
|
||||
- Test a function pointer from a global symbol and from an absolute address (`((fn)0x3F...)`), the latter used by the Xlib header.
|
||||
|
||||
- [ ] **Step 4: Run the MAME callback test**
|
||||
|
||||
`fnptr_test()=42`; the termtris function-pointer callbacks (`term_reset` etc.) are the integration case. Record the `CALL` encoding/`dis34`.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
Commit the compiler/test changes; the report.
|
||||
|
||||
### Task 4: X11R4-compatible headers and XImage/XEvent/error-event layouts
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/m4/x11m4.h` (or vendor an X11R4 subset), `scripts/m4/layout.c`, `scripts/m4/layout-ti.c`
|
||||
- Create: `scripts/tests/m4/layout.sh`
|
||||
- Reuse: the Task 3 `vt1200_xlib.h` byte/bit layout
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M3 `Display`/`Screen` layout (byte 0x90/0x8).
|
||||
- Produces: `XImage`, `XEvent`/`XKeyEvent`/`XExposeEvent`/`XFocusChangeEvent`/`XButtonEvent`, `XErrorEvent`, `GC`/`Visual`, the function prototypes/constants, and verified field offsets.
|
||||
|
||||
- [ ] **Step 1: Write the failing layout test**
|
||||
|
||||
`scripts/m4/x11m4.h` contains at least:
|
||||
|
||||
```c
|
||||
typedef struct _XImage {
|
||||
int width, height;
|
||||
int xoffset;
|
||||
int format;
|
||||
char *data;
|
||||
int byte_order;
|
||||
int bitmap_unit;
|
||||
int bitmap_bit_order;
|
||||
int bitmap_pad;
|
||||
int depth;
|
||||
int bytes_per_line;
|
||||
int bits_per_pixel;
|
||||
unsigned long red_mask, green_mask, blue_mask;
|
||||
void *obdata;
|
||||
struct funcs *f;
|
||||
} XImage;
|
||||
|
||||
typedef union _XEvent {
|
||||
int type;
|
||||
struct { int type; unsigned long serial; int send_event; void *display;
|
||||
unsigned long window, root, subwindow; unsigned long time;
|
||||
int x, y, x_root, y_root; unsigned state; unsigned keycode;
|
||||
int same_screen; } xkey;
|
||||
struct { int type; unsigned long serial; int send_event; void *display;
|
||||
unsigned long window; int x, y, width, height, count; } xexpose;
|
||||
/* xfocus/xbutton/... as needed */
|
||||
} XEvent;
|
||||
|
||||
typedef struct _XErrorEvent {
|
||||
int type;
|
||||
void *display;
|
||||
unsigned long resourceid, serial;
|
||||
unsigned char error_code, request_code, minor_code;
|
||||
} XErrorEvent;
|
||||
```
|
||||
|
||||
`scripts/m4/layout.c`:
|
||||
|
||||
```c
|
||||
#include "x11m4.h"
|
||||
_Static_assert(__builtin_offsetof(Display, screens) == 0x90, "...");
|
||||
_Static_assert(__builtin_offsetof(Screen, root) == 0x8, "...");
|
||||
_Static_assert(__builtin_offsetof(XImage, data) == 20, "...");
|
||||
_Static_assert(__builtin_offsetof(XImage, byte_order) == 24, "...");
|
||||
_Static_assert(__builtin_offsetof(XImage, bytes_per_line) == 40, "...");
|
||||
_Static_assert(__builtin_offsetof(XEvent, type) == 0, "...");
|
||||
_Static_assert(sizeof(XEvent) >= 96, "...");
|
||||
```
|
||||
|
||||
Use the actual 32-bit X11R4/system header field offsets; if the system header's `XImage`/`XEvent` match the ROM, assert them; otherwise document the ROM-verified subset. The `XImage` size must cover what `XCreateImage` returns; the `XEvent` buffer is the termtris `vt_u32 evbuf[24]` (96 bytes).
|
||||
|
||||
- [ ] **Step 2: Run it red/verify**
|
||||
|
||||
Compile with `scripts/tms-clang -O0` + `llc`; the static asserts must pass. If a field offset differs, fix the header (or the target if the packed struct is wrong) and report it. Do not use the host 64-bit layout without the 32-bit type mapping.
|
||||
|
||||
- [ ] **Step 3: Build the TI/host golden**
|
||||
|
||||
Compile `layout-ti.c` (the `Display`/`Screen`/`XImage`/`XEvent` offset functions) with the 1987 compiler; store the asm; require the same constants. The 1987 compiler's `&` is bit-addressed; convert to byte offsets consistently.
|
||||
|
||||
- [ ] **Step 4: Run the layout gate and commit**
|
||||
|
||||
`scripts/tests/m4/layout.sh` compiles the static asserts, checks the target and TI golden constants, and fails loudly. Commit the header/layout test.
|
||||
|
||||
### Task 5: ROM symbols, `XMapWindow` correction, and the XG block
|
||||
|
||||
**Files:**
|
||||
- Modify: `symbols/vt1200-v22.syms`, `symbols/README.md`
|
||||
- Modify: `scripts/m3/xhello.c`/`scripts/m3/dis-roundtrip.sh`/M3 docs (the `XMapWindow`/`XRaiseWindow` correction)
|
||||
- Create: `scripts/m4/xgfix.c`, `scripts/m4/validate-syms.sh`, `scripts/tests/m4/symbols.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the termtris `xlib.h` table and the M3 loader.
|
||||
- Produces: the corrected/extended v2.2 symbol table; `vt_install_xg()`; a symbol-validation gate.
|
||||
|
||||
- [ ] **Step 1: Correct and extend the symbol table**
|
||||
|
||||
- `XMapWindow = 0x3FD64F60`; add `XRaiseWindow = 0x3FD645B0` (not `XMapRaised`; the ROM entry sends ConfigureWindow with `CWStackMode=Above`). If a client wants map-and-raise, call `XMapWindow` then `XRaiseWindow`.
|
||||
- Add the termtris-proven entries: `XSelectInput 0x3FD97D50`, `XCreateGC 0x3F997000`, `XSetForeground 0x3FD99A60`, `XFillRectangle 0x3F99E8F0`, `XDrawString 0x3FDA0000`, `XNextEvent 0x3F9C1CF0`, `XLookupString 0x3F9A9C30`, `XFlush 0x3F9B1030`, `XPending 0x3FD67620`, `XGetInputFocus 0x3FD55210`, `sleep 0x3FB33A20` (all in the pinned termtris `xlib.h`).
|
||||
- Note: `XLoadFont 0x3FD4AE80` and `XCopyArea 0x3FD3E220` are **not** termtris-proven and are **not** in the pinned termtris `xlib.h`; add them only because they are ROM-validated by their request builders (OpenFont opcode 45 and CopyArea opcode 62), as `symbols/README.md` records.
|
||||
- Extract/validate the `XImage` entries (`XCreateImage`, `XPutImage`, `XDestroyImage`, optional `XGetImage`) and `XSetErrorHandler`/`XSetIOErrorHandler` from the ROM (Ghidra/`ptr_constants.py`, the `XPutImage`/`XGetImage` strings at `0x3F9D0E80`/`0x3FD567A0`). Do not guess an address; if an entry cannot be validated, report it and use the fallback (the termtris text client) for that part.
|
||||
- Update `scripts/m3/xhello.c`/the comments to call the true `XMapWindow` (`0x3FD64F60`), the M3 `dis-roundtrip.sh` stub expectation, and the M3 docs. Do not use `0x3FD645B0` as a mapping call. Re-run the M3 MAME/dis34 gates; the window must still appear, and record whether the old `0x3FD645B0` pass depended on server-side create/configure behavior.
|
||||
|
||||
- [ ] **Step 2: Implement the XG fix**
|
||||
|
||||
`scripts/m4/xgfix.c` (the termtris fix):
|
||||
|
||||
```c
|
||||
int vt_install_xg(void) {
|
||||
unsigned int proc = *(volatile unsigned int *)0x001B3900u;
|
||||
if (proc < 0x100u || proc > 0x01FFFFFFu) return 0;
|
||||
unsigned int pp = *(volatile unsigned int *)(proc + 0x100u);
|
||||
if (pp < 0x100u || pp > 0x01FFFFFFu) return 0;
|
||||
static unsigned int xg[256]; /* 1 KiB zeroed .bss */
|
||||
*(volatile unsigned int *)pp = (unsigned int)xg;
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
Call it **before** `XOpenDisplay` in the event/image clients and the termtris build.
|
||||
|
||||
- [ ] **Step 3: Validate the symbols**
|
||||
|
||||
`scripts/m4/validate-syms.sh` checks the v2.2 entries are in ROM range, 16-bit aligned, and start with a plausible function prologue (`dis34`); the termtris `xlib.h` is the evidence. Add a test that `0x3FD645B0` is reported as `XRaiseWindow` (ConfigureWindow opcode 12), so the correction is pinned.
|
||||
|
||||
- [ ] **Step 4: Run the M3 correction and the symbol gate**
|
||||
|
||||
Re-run `scripts/tests/m3/run.sh`/`dis-roundtrip.sh`; the M3 window still appears with the true `XMapWindow 0x3FD64F60`. Run `scripts/tests/m4/symbols.sh`; all entries validated. Commit.
|
||||
|
||||
### Task 6: The M4 image/event client and the MAME image/key gate
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/m4/xshow.c`, `scripts/m4/entry.asm`, `scripts/m4/link.cmd`, `scripts/m4/run.sh`, `scripts/m4/m4-check.lua`, `scripts/m4/dis-roundtrip.sh`
|
||||
- Create: `scripts/tests/m4/run.sh`, `scripts/tests/m4/dis-roundtrip.sh`
|
||||
- Reuse: `scripts/m4/x11m4.h`, `xgfix.c`, `validate-syms.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Tasks 1–5.
|
||||
- Produces: `M4 MAME: PASS` — a 1-bit `XImage` displayed, no X errors, a real key press processed, focus/window markers, and the window/image pixel evidence.
|
||||
|
||||
- [ ] **Step 1: Write the image/event client**
|
||||
|
||||
`scripts/m4/xshow.c` (the `xshow` shape, VT1200 Xlib):
|
||||
|
||||
```c
|
||||
#include "x11m4.h"
|
||||
static volatile unsigned int *MARK(unsigned n) { return (volatile unsigned int *)(0x018A8000u + n*0x20u); }
|
||||
static int xerrors;
|
||||
static int on_error(void *d, XErrorEvent *e) { xerrors++; return 0; }
|
||||
int xshow(void) {
|
||||
if (!vt_install_xg()) return -1;
|
||||
Display *d = XOpenDisplay("0::0");
|
||||
MARK(0)[0] = (unsigned)d; if (!d) return -1;
|
||||
Window w = XCreateSimpleWindow(d, vt_root(d), 20, 20, 640, 480, 0, 0, 0);
|
||||
MARK(1)[0] = (unsigned)w;
|
||||
XSelectInput(d, w, ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask);
|
||||
GC gc = XCreateGC(d, w, 0, 0);
|
||||
XSetForeground(d, gc, 1);
|
||||
/* 1-bit checker image, LSBFirst */
|
||||
int bpl = ((640 + 31) / 32) * 4;
|
||||
static unsigned char data[480 * 80]; /* 640/8 = 80 bytes/row */
|
||||
for (int y = 0; y < 480; y++) for (int x = 0; x < 640; x++)
|
||||
if (((x/32) ^ (y/32)) & 1) data[y*80 + (x>>3)] |= 1u << (x & 7);
|
||||
XImage *img = XCreateImage(d, 0, 1, XYBitmap, 0, (char *)data, 640, 480, 32, bpl);
|
||||
MARK(2)[0] = (unsigned)img; if (!img) return -1;
|
||||
img->byte_order = LSBFirst; img->bitmap_bit_order = LSBFirst;
|
||||
XSetErrorHandler(on_error);
|
||||
XMapWindow(d, w);
|
||||
XPutImage(d, w, gc, img, 0, 0, 0, 0, 640, 480);
|
||||
XSync(d, 0);
|
||||
for (;;) {
|
||||
XEvent ev;
|
||||
while (XPending(d)) {
|
||||
XNextEvent(d, &ev);
|
||||
MARK(4)[0]++;
|
||||
if (ev.type == KeyPress) {
|
||||
char buf[8]; unsigned long ks = 0;
|
||||
int n = XLookupString(&ev.xkey, buf, 8, &ks, 0);
|
||||
MARK(5)[0] = (unsigned)ev.xkey.keycode;
|
||||
MARK(6)[0] = (unsigned)ks;
|
||||
if (buf[0] == 'q') { MARK(3)[0] = 1; return 0; }
|
||||
} else if (ev.type == Expose) {
|
||||
XPutImage(d, w, gc, img, 0, 0, 0, 0, 640, 480);
|
||||
}
|
||||
}
|
||||
MARK(7)[0] = (unsigned)xerrors;
|
||||
XFlush(d);
|
||||
sleep(5); /* the ROM sleep; keep the process alive */
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Use the exact Task 4 field names/offsets; `XCreateImage`'s `visual` may be 0 for a 1-bit default; if the ROM requires the default visual, use `DefaultVisual` or the display's default; verify. The window is at (20,20), 640×480; the image checker is LSB-first; the key `q` quits. The `XSetErrorHandler` is a function pointer (Task 3); the `on_error` increments.
|
||||
|
||||
- [ ] **Step 2: Entry/link/runner**
|
||||
|
||||
`scripts/m4/entry.asm` sets FS0/FS1, STK/FP, calls `_xshow`, `rets`; `_cstack` `.bss` 32768 bits. `link.cmd` places `.text`/`.data` > prog at `018A0000h`, `.bss` > ram at `018A9000h`; link `RTS.LIB` if the compiler/libcall path needs it. `scripts/m4/run.sh` compiles `xshow.c`/`layout.c`/`xgfix.c` with `tms-clang -O2` + `llc -O0`, generates the ROM stubs/function-pointer addresses, GSPA/GSPLNK under DOSBox, loads in MAME with `VT1200_SKIP_LEVEL1=1`, the loader, `LOADER_AT=2500`, `LOADER_END=3400` (adjust), the `VT1200_MONITOR=VR319` pin, and `m4-check.lua`.
|
||||
|
||||
`scripts/m4/m4-check.lua` reads the markers: display/window/image nonzero, `xerrors==0`, `events>0`, the keycode/keysym for a `q` injected key, the quit marker, and the image checker at several window pixels (e.g. (30,30) and (50,50) alternate; the checker pattern at 32-pixel cells). Use the VRAM base bit `0x04000000`, VR319 2048-bit pitch, LSB-first; the window is at (20,20). Require `M4 MAME: PASS`; markers alone are not enough.
|
||||
|
||||
- [ ] **Step 3: Write the `dis34` round-trip**
|
||||
|
||||
`scripts/m4/dis-roundtrip.sh` checks the linked bytes for `CALL`/`CALLA` (the indirect call), the `XOpenDisplay`/`XCreateSimpleWindow`/`XSelectInput`/`XCreateGC`/`XSetForeground`/`XCreateImage`/`XSetErrorHandler`/`XMapWindow`/`XPutImage`/`XSync`/`XNextEvent`/`XLookupString` calls, the 9-argument `XCreateSimpleWindow` order, the `XSetErrorHandler` callback pointer, the `SETF`/`RETS`/old-STK rules, and the checker data in `.data`/`.bss`. The image client's `CALL` encoding is the Task 3 contract.
|
||||
|
||||
- [ ] **Step 4: Run the gates**
|
||||
|
||||
```sh
|
||||
scripts/tests/m4/run.sh
|
||||
scripts/tests/m4/dis-roundtrip.sh
|
||||
```
|
||||
|
||||
Expected: `M4 MAME: PASS` with the image checker, `xerrors=0`, a real key event, and the window; `M4 dis34 round-trip: PASS`.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
Commit the client/harness/tests; the report.
|
||||
|
||||
### Task 7: The pinned `termtris` additional integration test
|
||||
|
||||
**Files:**
|
||||
- Fetch: `https://git.wut.ee/opencode.energia.arti.ee/vt1200.git`, branch `termtris`, commit `be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf`, into `vendor/vt1200-termtris` (test-only, GPLv3 `COPYING` intact)
|
||||
- Create: `scripts/m4/termtris/build.sh`, `scripts/m4/termtris/play_keys.lua` (adapted from the vendored `apps/termtris/tests/play_keys.lua`), `scripts/m4/termtris/play_keys.sh`
|
||||
- Create: `scripts/tests/m4/termtris.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Tasks 1–6; the termtris `apps/termtris/src/vt1200/{xlib.h,xgfix.c,main.c,x11.c,compat.c}`, `src/game.c`, `src/pieces.h`, `src/game.h`, `src/term.h`, `src/vt1200/scoredb.c`, `src/vt1200/stdio.h`, `src/vt1200/inttypes.h`.
|
||||
- Produces: the termtris board, panels, move, and quit in MAME, with the proven `play_keys` marker acceptance.
|
||||
|
||||
- [ ] **Step 1: Fetch and pin**
|
||||
|
||||
```sh
|
||||
git clone --depth 1 --branch termtris \
|
||||
https://git.wut.ee/opencode.energia.arti.ee/vt1200.git \
|
||||
vendor/vt1200-termtris
|
||||
git -C vendor/vt1200-termtris rev-parse HEAD # be5b323...
|
||||
```
|
||||
|
||||
Keep `vendor/` ignored; the project test references the pinned checkout. The termtris `VT1200.md`/spec/plan and `apps/termtris/tests/play_keys.{sh,lua}` are the reference.
|
||||
|
||||
- [ ] **Step 2: Build termtris with this compiler**
|
||||
|
||||
`scripts/m4/termtris/build.sh` compiles the termtris sources with `tms-clang -O2 -I vendor/vt1200-termtris/apps/termtris/src -I .../src/vt1200` + `llc -O0`, concatenates the M4 entry (`_start` calls `_main`; `.data` is copied by the loader; `_cstack`) with the termtris `.s` and the function-pointer Xlib header, links with GSPA/GSPLNK (RTS.LIB for multiply/divide), and emits `build/termtris.coff`/`.map`.
|
||||
|
||||
- [ ] **Step 3: Run the play_keys acceptance**
|
||||
|
||||
Adapt the termtris `play_keys.lua`/`play_keys.sh`: the `move`/`panels`/`quit` modes, the tablet click + `A/D/S/W/0/P/R/H/Q` injection, the `DIAG_LOOPS/EVENTS/FOCUS/REV/QUIT/TICK` addresses from the M4 `.map`, `LOADER_AT=2500`, `LOADER_END=3200`, `LOADER_SNAP=1`, `VT1200_SKIP_LEVEL1=1`, the loader, and the M4 COFF. Require:
|
||||
- `loops >= 100` and `events >= 6` for `move`/`panels`;
|
||||
- `quit = 0` for `move`/`panels`, `quit = 1` for `quit`;
|
||||
- `focus` = the termtris window (nonzero);
|
||||
- the board/panels/move/quit screenshots.
|
||||
|
||||
The termtris's proven values were `move loops=333 events=18`, `panels loops=323 events=12`, `quit loops=277 events=10 quit=1`; the M4 run may differ in counts, but the thresholds and quit/focus must hold.
|
||||
|
||||
- [ ] **Step 4: Record and commit**
|
||||
|
||||
The termtris build proves: function pointers (`term_*` callbacks/absolute Xlib pointers), indirect calls, `XSelectInput`/`XNextEvent`/`XLookupString`, the XG block, `XCreateGC`/`XSetForeground`/`XFillRectangle`/`XDrawString`, the timer/sleep, multiply/divide, `sprintf`/compat, and the loader/child. If a termtris feature is genuinely outside M4, report it with a ruling and a specific follow-up; do not weaken the thresholds or fake the run.
|
||||
|
||||
Commit the M4 termtris scripts/tests and a short report; keep the vendored tree ignored.
|
||||
|
||||
### Task 8: Differential/dis34, docs, and push
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m4/diff/{ti-fnptr.c,ti-fnptr.s,ti-image.c,ti-image.s,check.sh}`
|
||||
- Modify: `README.md` (project), `build/llvm-clean/TMS34010.md` (compiler), `symbols/README.md`
|
||||
- Push: compiler `m4`, project `m4`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: all previous tasks.
|
||||
- Produces: stored TI goldens for function-pointer/call/image/struct-offset shape, M4 docs, and pushed `m4` branches.
|
||||
|
||||
- [ ] **Step 1: Produce the TI goldens**
|
||||
|
||||
Compile K&R/ANSI C for a function-pointer apply/callback and the Xlib image-call shape with the 1987 compiler; store `ti-fnptr.s`/`ti-image.s`; no DOSBox in CI. The check compares ABI shape: `CALL Rs`/indirect call, the old-STK push, the argument/return/`RETS 2`, the `XCreateImage`/`XPutImage` 10/9 argument pushes, the `Display`/`Screen`/`XImage` offsets (byte 0x90/0x8; the XImage fields).
|
||||
|
||||
- [ ] **Step 2: Write the diff check**
|
||||
|
||||
`scripts/tests/m4/diff/check.sh` generates our asm with `tms-clang` + `llc` and greps the stored goldens; accept TI spelling variants; fail loudly. Add negative controls for the `CALL`/the image argument order.
|
||||
|
||||
- [ ] **Step 3: Update the docs**
|
||||
|
||||
README M4: function pointers/indirect calls; zext narrow loads; multiply/divide/`rts.lib`; the image/event clients; the XG fix; the corrected `XMapWindow`/`XRaiseWindow`; the `XImage`/`XEvent` layouts; the termtris additional integration and its pinned branch; commands; M4 non-goals (XImage/XEvent beyond the tested calls, native COFF, floats/i64/varargs/structs by value; the M4/M5 boundary). TMS34010.md: the `CALL Rs` ABI, function pointers, zext patterns, multiply/divide libcalls, the TTI/loop policy, the XImage/XEvent lowering, the XG/ROM notes. symbols README: the corrected/extended v2.2 entries and the evidence.
|
||||
|
||||
- [ ] **Step 4: Run every M4 gate**
|
||||
|
||||
```sh
|
||||
ninja -C build/llvm-clean-build llc opt clang llvm-config FileCheck count not
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean-build/test/CodeGen/TMS34010 --filter='(m2|m3|m4)-'
|
||||
scripts/tests/m4/run.sh
|
||||
scripts/tests/m4/dis-roundtrip.sh
|
||||
scripts/tests/m4/layout.sh
|
||||
scripts/tests/m4/symbols.sh
|
||||
scripts/tests/m4/termtris.sh
|
||||
scripts/tests/m4/diff/check.sh
|
||||
tools/tms-bitaddr/tests/run.sh
|
||||
scripts/tests/m3/run.sh
|
||||
scripts/tests/m3/dis-roundtrip.sh
|
||||
```
|
||||
|
||||
All green; the M3 gates still pass with the corrected `XMapWindow`/`XRaiseWindow`.
|
||||
|
||||
- [ ] **Step 5: Commit and push**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010 TMS34010.md
|
||||
git -C build/llvm-clean commit -m "tms34010: M4 function pointers, XImage/events and termtris support"
|
||||
git -C build/llvm-clean push origin m4
|
||||
git add README.md symbols scripts/m4 scripts/tests/m4 scripts/m3
|
||||
git commit -m "tests: M4 Xlib images, events and the termtris integration"
|
||||
git push origin m4
|
||||
```
|
||||
|
||||
Do not force-push, merge into `m0`, or change the default; the controller updates the git.wut.ee default to `m4` after the final review if the user asks.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M4 closes the remaining Xlib path to a real image/event client and a full-game integration. M5 owns the native TI-COFF/MCCodeEmitter path, `JR`/branch relaxation, MMTM/MMFM, `alloca`/`byval`/narrow returns/mem intrinsics, and the first conformance tier; M6 owns floats, `long long`, general varargs, bitfields, aggregates by value, debug info, the wider Xlib surface and deeper libc/runtime coverage. The compiler repo is canonical for target code; this project repo holds the plans, wrappers, symbols and integration tests. The pinned `termtris` tree is test-only (GPLv3), not part of the compiler or project distribution.
|
||||
@@ -0,0 +1,641 @@
|
||||
# TMS34010 M5 — Native COFF Object Path, Code-Size/ABI Robustness, and Conformance Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
>
|
||||
> **Status note (2026-11-13):** the SDD ledger
|
||||
> `.superpowers/sdd/2026-11-12-tms34010-m5-native-object-path-and-conformance/progress.md`
|
||||
> is authoritative. All M5 tasks are complete; the checkboxes below are kept
|
||||
> as the original plan record. M5 re-scoped floats/bitfields/`long long`/
|
||||
> general varargs/debug info to M6; `byval` is an M5 form.
|
||||
|
||||
**Goal:** `llc -march=tms34010 -filetype=obj` produces TI-COFF objects that GSPLNK links and the existing loader runs, with `JR`/relaxation, `MMTM`/`MMFM`, `alloca`/`byval`/narrow returns, `memcpy`/`memset`, the `-switch-to-lookup=false` policy removed (and the remaining `-replexitval=never` policy documented and verified until i64 arrives), and a pinned conformance tier (LLVM `CodeGen/Generic`, GCC c-torture, c-testsuite) proving integer/control-flow behavior in MAME.
|
||||
|
||||
**Architecture:** M5 keeps the M4 assembly path as the oracle and adds the native MC path beside it. The MC layer (`MCCodeEmitter`, `MCAsmBackend`, a TI-COFF `MCObjectWriter`, `MCAsmParser`/`MCDisassembler`) feeds `llc -filetype=obj`; GSPLNK still links, and the existing COFF loader still runs. Code-size/ABI work is layered on the native path: `JR` relaxation, `MMTM`/`MMFM` register-list saves, dynamic `alloca`, `byval`, narrow returns, and `memcpy`/`memset`. A conformance harness compiles pinned external test suites with the M5 pipeline, runs them in MAME through a small entry/`printf`/`exit`/`abort` shim, and classifies unsupported-feature tests explicitly. The `-switch-to-lookup=false` policy is removed by fixing the switch-table GEP normalization; `-replexitval=never` stays as a documented `tms-clang` TMS34010 policy until i64/M6, with an `llc` diagnostic for the unsupported i33 multiply.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m5`), C++17, CMake/Ninja, `llc`, `llvm-mc`, TI COFF, GSPA/GSPLNK 2.00 under DOSBox (oracle/fallback), the dwt COFF loader, MAME, `dis34`, `llvm-lit`/FileCheck, the 1987 TI compiler as a differential oracle, pinned GCC 16.2 c-torture and c-testsuite.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (§7, §8, M5); the M4 plan `docs/superpowers/plans/2026-11-12-tms34010-m4-xlib-image-events-and-termtris.md` is the handoff.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Compiler work happens in **`llvm-tms34010`**, branch `m5`, created from `m4` at `de5a365596c819a1902e58b989e18be85865219a`. Project work happens in **`tms-c-compiler`**, branch `m5`, created from `m4` at `5d980dc6e3317dd60a725e1188657e9d6a9d1d3e` plus the M5 plan commit. Do not merge `m0`/`m1`/`m2`/`m3`/`m4`; do not change either default branch.
|
||||
- Use upstream LLVM `llvmorg-23.1.5`; keep the fork minimal against upstream. Use the existing `build/llvm-clean` and `build/llvm-clean-build`.
|
||||
- The M2–M4 TI ABI is unchanged: A8 return, A13 frame pointer, A14 stack pointer, A15 system stack, `RETS 2/0`, `FS1 = 32`, `FS0 = 16`.
|
||||
- **Native object path:** `llc -march=tms34010 -filetype=obj` emits TI-COFF objects that GSPLNK 2.00 links; the existing loader runs the linked image. No new linker is added in M5. The M4 asm path (`-filetype=asm` → GSPA/GSPLNK) remains the oracle and fallback until the native path passes the full M4 gates; do not delete GSPA/GSPLNK.
|
||||
- Every M2/M3/M4 gate must stay green. Add `m5-*` lit tests and `scripts/tests/m5/*` gates. The M4 tests are the acceptance for the native path, not just the hand-written unit tests.
|
||||
- **M5 scope:** native COFF, `JR`/relaxation, `MMTM`/`MMFM`, `alloca`, `byval`, narrow `i8`/`i16` returns, `memcpy`/`memset`, removal of the `-switch-to-lookup=false` driver policy, a documented `tms-clang` `-replexitval=never` policy plus an `llc` diagnostic (until i64/M6), and the conformance tier.
|
||||
- **M5 non-goals (M6):** floats/double, `long long`/i64 (and therefore removal of the i33/`-replexitval` workaround), general varargs (`va_list`/`va_start`/`va_arg`; the M4 contiguous `&last_fixed` pattern remains), bitfields, structs/unions by value, `sret`, aggregate returns, debug info, the wider Xlib surface, and real-hardware-only validation.
|
||||
- **Conformance is test-only:** pin GCC 16.2.0 `gcc.c-torture/execute` (`https://ftp.gnu.org/gnu/gcc/gcc-16.2.0/gcc-16.2.0.tar.xz`, SHA-256 recorded by the fetch script) and c-testsuite commit `5c7275656d751de0e68b2d340a95b5681858ed07`. The GCC version is only the corpus source; the compiler under test is `tms-clang`, and the feature classifier skips tests outside the M5 language subset. Keep their licenses/COPYING; `vendor/conformance` is ignored and never distributed. A feature classifier must skip unsupported features with a recorded reason; no gate may silently pass a skipped test as a pass.
|
||||
- The native object/relocation model uses **bit addresses** (the TMS34010 program space); every relocation addend is a bit offset. GSPLNK's linked COFF and `dis34` are the format/encoding oracles.
|
||||
- Do not force-push, merge into `m0`, or change the default. Push `m5` in both repos only after the final gate run and review.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **TI-COFF relocation/symbol/bit-addend correctness.** A wrong section index, symbol value, or bit addend links plausible but wrong code. The tests are the GSPLNK link plus the loader/MAME run for a cross-section `MOVI`/`CALLA` (Task 2) and the full M4 programs through the native path (Task 4).
|
||||
2. **MC encoding exactness.** A wrong `.td` encoding or operand order is silent in the object. The tests are `llvm-mc -show-encoding` and a `dis34` round-trip over the full supported instruction table, compared with the GSPA encodings (Task 3).
|
||||
3. **`JR`/branch relaxation.** Relaxing a branch can change reach or direction. The tests are short/long branch cases, the M3 loop in MAME, and a code-size measurement (Task 5).
|
||||
4. **`MMTM`/`MMFM` frame save/restore.** A wrong register list corrupts the callee's A14/A15 or a saved A register. The tests are callee-save/args/nested-call cases and the M2/M3 MAME gates (Task 6).
|
||||
5. **Conformance classifier, shim, and expected results.** A skip for the wrong reason, a `printf` bug, or a vacuous output compare hides real failures. The tests are known-pass/known-fail/skip controls and an output-mismatch control (Tasks 9–12).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: M5 branches and the native-object smoke
|
||||
|
||||
**Files:**
|
||||
- Create: `build/llvm-clean/llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCCodeEmitter.cpp`, `TMS34010MCCodeEmitter.h`, `TMS34010MCAsmBackend.cpp`, `TMS34010MCAsmBackend.h`, `TMS34010MCObjectWriter.cpp`, `TMS34010MCObjectWriter.h`
|
||||
- Modify: `build/llvm-clean/llvm/lib/Target/TMS34010/MCTargetDesc/CMakeLists.txt`, `MCTargetDesc/TMS34010MCTargetDesc.cpp`
|
||||
- Test: `build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-object-smoke.ll`, `scripts/tests/m5/object-smoke.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `TMS34010MCInstLower`, `TMS34010MCAsmInfo`, the M4 `.td` encodings.
|
||||
- Produces: `MCCodeEmitter *createTMS34010MCCodeEmitter(const MCInstrInfo &MII, const MCRegisterInfo &MRI)`, `MCAsmBackend *createTMS34010MCAsmBackend(const Target &T)`, and `TMS34010MCAsmBackend::createObjectWriter(raw_pwrite_stream &OS)` returning a TI-COFF writer.
|
||||
|
||||
- [ ] **Step 1: Write the failing smoke test**
|
||||
|
||||
`m5-object-smoke.ll`:
|
||||
|
||||
```llvm
|
||||
; RUN: llc -march=tms34010 -filetype=obj < %s -o %t.o
|
||||
; RUN: test -s %t.o
|
||||
; RUN: llc -march=tms34010 -filetype=asm < %s -o %t.s
|
||||
; RUN: grep -q 'RETS 2' %t.s
|
||||
define i32 @f(i32 %a) {
|
||||
%r = add i32 %a, 1
|
||||
ret i32 %r
|
||||
}
|
||||
```
|
||||
|
||||
`scripts/tests/m5/object-smoke.sh` builds the same IR with `llc -filetype=obj`, extracts the `.text` bytes using the COFF header the implementer writes, and compares them with the GSPA-assembled `.text` from `scripts/m4/run.sh`-style assembly. The script must fail if the object is empty, if the `.text` bytes differ, or if `llc` exits nonzero.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llc -march=tms34010 -filetype=obj /tmp/m5-smoke.ll -o /tmp/m5-smoke.o`
|
||||
Expected: `llc: error: createMCCodeEmitter failed`.
|
||||
|
||||
- [ ] **Step 3: Implement the minimal MC layer**
|
||||
|
||||
Add a `TMS34010MCCodeEmitter` using the TableGen `getBinaryCodeForInstr` for `RETS`, `MOVI`, `MOVE`, `ADDI`, and `SETF`; a `TMS34010MCAsmBackend` with `getFixupKindInfo`, `applyFixup`, `writeNopData`, and `createObjectWriter`; and a `TMS34010COFFObjectWriter` that writes a minimal TI-COFF header, a `.text` section, one symbol, and no relocations. Register the emitter and backend in `LLVMInitializeTMS34010TargetMC`.
|
||||
|
||||
The TI-COFF header/section fields must match the GSPA object for this smoke function (machine, section count, optional-header size 0, section flags, raw-data size); the object writer is the only new format code. Do not invent a new object format.
|
||||
|
||||
- [ ] **Step 4: Run the smoke test green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-object-smoke.ll
|
||||
scripts/tests/m5/object-smoke.sh
|
||||
```
|
||||
|
||||
Expected: both PASS; the object is non-empty and the `.text` bytes match GSPA.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/MCTargetDesc llvm/test/CodeGen/TMS34010/m5-object-smoke.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: add the minimal MC object path"
|
||||
git add scripts/tests/m5/object-smoke.sh
|
||||
git commit -m "tests: M5 native-object smoke gate"
|
||||
```
|
||||
|
||||
### Task 2: TI-COFF sections, symbols, relocations, and GSPLNK link
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010MCObjectWriter.cpp/.h`, `TMS34010MCAsmBackend.cpp`
|
||||
- Create: `scripts/m5/native-link.c`, `scripts/m5/native-entry.asm`, `scripts/m5/native-link.cmd`, `scripts/tests/m5/native-link.sh`
|
||||
- Test: `scripts/tests/m5/native-link.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1's writer/encoder.
|
||||
- Produces: a TI-COFF object with `.text`/`.data`/`.bss` sections, a symbol table, and absolute/bit-addend relocations that GSPLNK 2.00 links into the existing loader image.
|
||||
|
||||
- [ ] **Step 1: Write the failing native-link test**
|
||||
|
||||
`native-link.c`:
|
||||
|
||||
```c
|
||||
int native_value(void) { return 42; }
|
||||
```
|
||||
|
||||
`native-entry.asm` sets FS0/FS1, A14/A13, calls `_native_value`, stores A8 at `0x018A8000`, and `rets`. The test runs:
|
||||
|
||||
```sh
|
||||
scripts/tms-clang -O0 -o build/m5-native/native-link.ll scripts/m5/native-link.c
|
||||
build/llvm-clean-build/bin/llc -march=tms34010 -O0 -filetype=obj build/m5-native/native-link.ll -o build/m5-native/native-link.o
|
||||
# assemble the entry with GSPA, then GSPLNK native-link.o + entry.o
|
||||
# load the linked COFF in MAME and require 0x018A8000 == 42
|
||||
```
|
||||
|
||||
The first run must fail at GSPLNK (unknown/malformed object) or at the loader (wrong relocation).
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/native-link.sh`
|
||||
Expected: GSPLNK/loader failure on the object, not a `llc` encoding failure.
|
||||
|
||||
- [ ] **Step 3: Implement sections, symbols, and relocations**
|
||||
|
||||
Write the TI-COFF section headers and raw data for `.text`/`.data`/`.bss`; emit the symbol table entries for `_native_value`, `_native_entry`, and the section symbols; record relocations for `CALLA`/`MOVI` symbol operands as **bit-address** addends. Match the GSPA/GSPLNK COFF conventions (machine, flags, relocation types, symbol value/section fields). The existing `build/m3/m3.coff`/`m4` COFFs and the loader parser are the format oracle.
|
||||
|
||||
- [ ] **Step 4: Run the native-link test green**
|
||||
|
||||
Run: `scripts/tests/m5/native-link.sh`
|
||||
Expected: GSPLNK links; the loader reports `status=0`; MAME reads `0x018A8000 == 42`; `dis34` decodes the linked `_native_value`.
|
||||
|
||||
- [ ] **Step 5: Add the cross-section relocation case**
|
||||
|
||||
Extend `native-link.c` with a `const char *msg = "native";` and a function that returns `msg[0]`/calls a second function, so the object needs a `.data` symbol relocation and a cross-section `CALLA`. Require the MAME marker / `dis34` to prove the linked bit addresses, then commit.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/MCTargetDesc
|
||||
git -C build/llvm-clean commit -m "tms34010: linkable TI-COFF objects"
|
||||
git add scripts/m5/native-link.c scripts/m5/native-entry.asm scripts/m5/native-link.cmd scripts/tests/m5/native-link.sh
|
||||
git commit -m "tests: M5 native COFF link gate"
|
||||
```
|
||||
|
||||
### Task 3: Full MC emitter, assembler, disassembler, and `llvm-mc` round-trip
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010MCCodeEmitter.cpp/.h`, `TMS34010InstrInfo.td`, `TMS34010.td`, `MCTargetDesc/CMakeLists.txt`, `MCTargetDesc/TMS34010MCTargetDesc.cpp`
|
||||
- Create: `MCTargetDesc/TMS34010AsmParser.cpp/.h`, `MCTargetDesc/TMS34010Disassembler.cpp/.h`, `llvm/test/MC/TMS34010/*.s`, `scripts/tests/m5/mc-roundtrip.sh`
|
||||
- Test: `llvm/test/MC/TMS34010/encodings.s`, `scripts/tests/m5/mc-roundtrip.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1/2's emitter/backend; the M4 instruction set.
|
||||
- Produces: `llvm-mc -triple=tms34010` encoding/decoding for every supported instruction, with `-show-encoding` matching GSPA/`dis34`.
|
||||
|
||||
- [ ] **Step 1: Write the failing encoding test**
|
||||
|
||||
`encodings.s` contains one instruction per supported mnemonic/operand shape with the expected GSPA/`dis34` encoding:
|
||||
|
||||
```asm
|
||||
; RUN: llvm-mc -triple=tms34010 -show-encoding %s | FileCheck %s
|
||||
; CHECK: add a0, a1
|
||||
; CHECK-NEXT: encoding: [0x00,0x00]
|
||||
; ... RETS, MOVI, MOVE, MOVB, ADDI, CMPI, JAUC, CALL, CALLA, SETF, MMTM, MMFM, JR
|
||||
```
|
||||
|
||||
`mc-roundtrip.sh` also assembles with `llvm-mc -filetype=obj`, extracts the `.text`, and requires `dis34` to reproduce the source mnemonics/operands.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-mc -triple=tms34010 -show-encoding build/llvm-clean/llvm/test/MC/TMS34010/encodings.s`
|
||||
Expected: `llvm-mc` missing or `unable to create target`.
|
||||
|
||||
- [ ] **Step 3: Implement the full emitter and parser/disassembler**
|
||||
|
||||
Add the TableGen `-gen-asm-matcher`/`-gen-disassembler` outputs to `MCTargetDesc/CMakeLists.txt`; implement `TMS34010AsmParser` (operand parsing for A/B registers, immediates, symbol/bit-address expressions), `TMS34010Disassembler` (the inverse of the `.td` encodings), and the full `TMS34010MCCodeEmitter`. Build `llvm-mc` in `build/llvm-clean-build`.
|
||||
|
||||
The M4 asm text/GSPA listing and `dis34` are the encodings oracle. Do not change an existing M2–M4 instruction encoding to make the parser easier; fix the parser or the `.td` operand shape.
|
||||
|
||||
- [ ] **Step 4: Run the MC gate green**
|
||||
|
||||
```sh
|
||||
ninja -C build/llvm-clean-build llvm-mc
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010
|
||||
scripts/tests/m5/mc-roundtrip.sh
|
||||
```
|
||||
|
||||
Expected: PASS for the full supported table; `dis34` round-trip for the object bytes.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/MCTargetDesc llvm/lib/Target/TMS34010/TMS34010.td llvm/lib/Target/TMS34010/TMS34010InstrInfo.td llvm/test/MC/TMS34010
|
||||
git -C build/llvm-clean commit -m "tms34010: full MC assembler/encoder/disassembler"
|
||||
git add scripts/tests/m5/mc-roundtrip.sh
|
||||
git commit -m "tests: M5 MC round-trip gate"
|
||||
```
|
||||
|
||||
### Task 4: Native object pipeline and the M4 regressions
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/m5/native.sh`, `scripts/tests/m5/native.sh`
|
||||
- Modify: `scripts/m4/run.sh` (add `M4_NATIVE=1`, default unchanged)
|
||||
- Test: `scripts/tests/m5/native.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Tasks 1–3; the M4 `run.sh` harness.
|
||||
- Produces: the M4 xshow and termtris programs built with `llc -filetype=obj` + GSPLNK, linked by the existing loader, passing the same MAME markers. The asm path remains the default.
|
||||
|
||||
- [ ] **Step 1: Write the failing native-pipeline test**
|
||||
|
||||
`scripts/tests/m5/native.sh` builds `scripts/m4/xshow.c` + `xgfix.c` and the termtris six TUs with `M4_NATIVE=1` (object path), links with GSPLNK, runs the M4 MAME checks, and requires the same markers (`xerrors=0`, key, focus; termtris loops/events/quit/focus). The first run must fail because the object path cannot yet link the full programs.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/native.sh`
|
||||
Expected: the object/link step fails on an unsupported relocation/section (not on an asm encoding).
|
||||
|
||||
- [ ] **Step 3: Extend the object path for the full programs**
|
||||
|
||||
Add the `.cinit` section, common/weak symbols if needed, the `MOVI`/`CALLA`/`CALL`/`MMTM`/`MMFM`/`.bss` relocations, and the `scripts/m5/native.sh` compile/link driver. Keep the GSPA/GSPLNK asm path byte-identical; add a `dis34` comparison of the native and asm linked `.text` where feasible.
|
||||
|
||||
- [ ] **Step 4: Run the native M4 gates green**
|
||||
|
||||
```sh
|
||||
scripts/tests/m5/native.sh
|
||||
scripts/tests/m4/run.sh
|
||||
scripts/tests/m4/termtris.sh
|
||||
```
|
||||
|
||||
Expected: the native xshow/termtris markers match the asm path; the M4 default gates still pass.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010
|
||||
git -C build/llvm-clean commit -m "tms34010: native object path for M4 programs"
|
||||
git add scripts/m5/native.sh scripts/tests/m5/native.sh scripts/m4/run.sh
|
||||
git commit -m "tests: M5 native pipeline and M4 regressions"
|
||||
```
|
||||
|
||||
### Task 5: `JR` and branch relaxation
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010InstrInfo.td` (`JR`), `TMS34010InstrInfo.cpp/.h`, `TMS34010MCAsmBackend.cpp`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m5-jr.ll`, `scripts/tests/m5/jr.sh`
|
||||
- Reuse: the M3 branch/loop MAME gate.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 4's native path.
|
||||
- Produces: relative `JR` for in-range local branches and `JAUC`/`JA<cc>` for out-of-range/absolute branches; the MC backend relaxes iteratively.
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
`m5-jr.ll` has a short loop whose body fits the `JR` range and a function with a far branch. Check `JR` in the short body and `JAUC` in the far body; `scripts/tests/m5/jr.sh` runs the M3 `branch.c` loop in MAME and records the linked `.text` size.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m5-jr.ll`
|
||||
Expected: no `JR` selection / relaxation failure.
|
||||
|
||||
- [ ] **Step 3: Implement `JR` and relaxation**
|
||||
|
||||
Add the `JR` encoding/operand (signed bit displacement), select it for local conditional/unconditional branches, and implement `TMS34010MCAsmBackend::mayNeedRelaxation`/`relaxInstruction` to widen to `JA*` when the displacement is out of range. Update `getInstSizeInBytes`. Keep the M3 `JAcc` labels/branch behavior; the `LBB` labels remain GSPA-safe.
|
||||
|
||||
- [ ] **Step 4: Run the JR gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-jr.ll
|
||||
scripts/tests/m5/jr.sh
|
||||
scripts/tests/m3/run.sh
|
||||
```
|
||||
|
||||
Expected: PASS; the short loop uses `JR`; the far branch uses `JA`; the M3 MAME values are unchanged; the code size is recorded.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m5-jr.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: JR branches and relaxation"
|
||||
git add scripts/tests/m5/jr.sh
|
||||
git commit -m "tests: M5 JR relaxation gate"
|
||||
```
|
||||
|
||||
### Task 6: `MMTM`/`MMFM` register-list saves
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010FrameLowering.cpp`, `TMS34010InstrInfo.td`, `TMS34010RegisterInfo.cpp/.h`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m5-mmtm.ll`, `scripts/tests/m5/mmtm.sh`
|
||||
- Reuse: `m2-callee-save.ll`, the M2/M3 MAME calls.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 4's native path.
|
||||
- Produces: prologue/epilogue `MMTM SP, ...`/`MMFM SP, ...` for callee-saved A registers, with the same A14/A15 old-STK and `RETS 2` ABI as the per-register pushes.
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
`m5-mmtm.ll` has a callee that uses A0/A1/A3/A5 and is called from a function that keeps values live across it. Require `MMTM SP, ...`/`MMFM SP, ...` and the ABI's old-STK/`RETS 2`; `mmtm.sh` runs the M2 `caller`/`callee` and M3 `xhello` in MAME.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m5-mmtm.ll`
|
||||
Expected: per-register pushes, no `MMTM`/`MMFM`.
|
||||
|
||||
- [ ] **Step 3: Implement the register-list saves**
|
||||
|
||||
Emit the callee-save set as one `MMTM SP, ...` in the prologue and `MMFM SP, ...` in the epilogue, keeping the old-STK layout and the A8 return. The register list must be ascending/valid for the `.td` encoding; use the existing `.td` `MMTM`/`MMFM` definitions or add them. Do not change the ABI-visible order of the old-STK/FP slots.
|
||||
|
||||
- [ ] **Step 4: Run the MMTM gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-mmtm.ll
|
||||
scripts/tests/m5/mmtm.sh
|
||||
scripts/tests/m2/run.sh
|
||||
scripts/tests/m3/run.sh
|
||||
```
|
||||
|
||||
Expected: PASS; the M2/M3 returned values and ABI markers are unchanged; `dis34` shows the register list.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m5-mmtm.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: MMTM/MMFM register-list saves"
|
||||
git add scripts/tests/m5/mmtm.sh
|
||||
git commit -m "tests: M5 MMTM/MMFM gate"
|
||||
```
|
||||
|
||||
### Task 7: `alloca`, `byval`, narrow returns, and `memcpy`/`memset`
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010ISelLowering.cpp/.h`, `TMS34010FrameLowering.cpp`, `TMS34010InstrInfo.td`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m5-alloca.ll`, `m5-byval.ll`, `m5-narrow-ret.ll`, `m5-memintrin.ll`, `scripts/tests/m5/robust.sh`
|
||||
- Reuse: the M2/M3 MAME harness.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 4's native path; the M4 `i8`/`i16` argument support.
|
||||
- Produces: dynamic `alloca` (A14 adjustment/restore), `byval` argument copies, `i8`/`i16` returns in A8 with the correct extension, and `memcpy`/`memset` lowered to the ROM/`rts.lib` entries or a byte/word loop.
|
||||
|
||||
- [ ] **Step 1: Write the failing tests**
|
||||
|
||||
- `m5-alloca.ll`: `alloca i32, i32 %n` in a loop, store/load, return a checksum.
|
||||
- `m5-byval.ll`: `byval` struct argument, callee reads the fields.
|
||||
- `m5-narrow-ret.ll`: `define zeroext i8 @f()` / `signext i16`, caller compares the value.
|
||||
- `m5-memintrin.ll`: `llvm.memcpy`/`llvm.memset` of known sizes.
|
||||
Run the focused lit tests red; the expected failures are the current `Cannot select`/rejection diagnostics.
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m5-(alloca|byval|narrow-ret|memintrin).ll`
|
||||
Expected: the current limitations (dynamic alloca, byval, narrow returns, memintrin) fail.
|
||||
|
||||
- [ ] **Step 3: Implement the lowering**
|
||||
|
||||
Add dynamic stack allocation/restore (A14 and the frame), `byval` stack copies, narrow return extension/truncation in A8, and `memcpy`/`memset` selection (the validated ROM `blit_copy`/`memset` entries or an inline loop). Keep the M4 argument/locals ABI and the M2/M3 frames. Add MAME markers for the checksums/bytes.
|
||||
|
||||
- [ ] **Step 4: Run the robustness gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010 --filter='m5-(alloca|byval|narrow-ret|memintrin)'
|
||||
scripts/tests/m5/robust.sh
|
||||
scripts/tests/m2/run.sh
|
||||
scripts/tests/m3/run.sh
|
||||
```
|
||||
|
||||
Expected: PASS; the alloca/byval/narrow-return/memintrin markers are correct; the M2/M3 gates are unchanged.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010
|
||||
git -C build/llvm-clean commit -m "tms34010: alloca, byval, narrow returns and mem intrinsics"
|
||||
git add scripts/tests/m5/robust.sh
|
||||
git commit -m "tests: M5 robustness gate"
|
||||
```
|
||||
|
||||
### Task 8: Remove `-switch-to-lookup`, pin `-replexitval`, and harden the deferred edges
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tms-clang`, `TMS34010ISelLowering.cpp/.h`, `TMS34010TargetMachine.cpp`, `tools/tms-bitaddr` (the switch-table GEP)
|
||||
- Modify: `build/llvm-clean/llvm/test/CodeGen/TMS34010/m3-cmpi.ll`, `scripts/m3/dis-roundtrip.sh` (tighten the M3 carry-forward tests)
|
||||
- Test: `scripts/tests/m5/policy.sh`, `llvm/test/CodeGen/TMS34010/m5-policy.ll`, `m5-reject-static-vararg.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M4 `-replexitval=never`/`-switch-to-lookup=false` policies; the static-variadic gap; the private-label token.
|
||||
- Produces: an ordinary `tms-clang -O2` that compiles the M4 **switch** without the driver flag; a documented `tms-clang` TMS34010 `-replexitval=never` policy with an `llc` diagnostic for an i33 multiply reached through the raw pipeline; a diagnostic for static variadic definitions at `-O2`; a long-private-name two-TU link test; the tightened `m3-cmpi` MOVI order and the M3 push-register check.
|
||||
|
||||
- [ ] **Step 1: Write the failing policy test**
|
||||
|
||||
`policy.sh` compiles the M4 `switch.c` and a static variadic function with the **default** `tms-clang -O2` after removing `-switch-to-lookup=false` from the wrapper (temporarily or via a copy), and separately runs the raw `opt -passes='default<O2>'` + `llc` path on an i33 loop without `-replexitval=never`. Require the switch to compile without a byte-indexed table, the static variadic definition to be rejected/kept correctly, and the raw i33 path to fail with a clear target diagnostic (not `Cannot select`/an assertion).
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/policy.sh`
|
||||
Expected: the byte-indexed switch-table miscompile, the static variadic miscompile, or the raw i33 `Cannot select`.
|
||||
|
||||
- [ ] **Step 3: Implement the target/verifier fixes**
|
||||
|
||||
Fix the switch-table GEP in `tms-bitaddr`/the target's GEP normalization so a `getelementptr i8, ptr @switch.table, i32 %idx` after `--scale` is not treated as a bit offset; remove `-switch-to-lookup=false` from `scripts/tms-clang` and prove the M4 `switch.c`/termtris board still pass. Keep `-replexitval=never` in `tms-clang` as a documented TMS34010 policy (i64/M6 will remove it); add an `llc`/target diagnostic for the i33/`umul_lohi` shape reached through the raw pipeline. Add the static-variadic `-O2` diagnostic (reject `static` variadic definitions or keep `...` through the optimizer). Tighten `m3-cmpi.ll` with `CHECK`/`CHECK-NEXT` MOVI order and replace the M3 nine-argument push-register check with the M4-style operand parsing. Add the long-private-name two-TU link test.
|
||||
|
||||
- [ ] **Step 4: Run the policy/hardening gate green**
|
||||
|
||||
```sh
|
||||
scripts/tests/m5/policy.sh
|
||||
scripts/tests/m3/run.sh
|
||||
scripts/tests/m3/dis-roundtrip.sh
|
||||
scripts/tests/m4/run.sh
|
||||
```
|
||||
|
||||
Expected: the switch compiles without the flag; the raw i33 path fails with a clear diagnostic; the M3/M4 gates remain green.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m3-cmpi.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: remove switch-to-lookup; pin replexitval edges"
|
||||
git add scripts/tms-clang tools/tms-bitaddr scripts/tests/m5/policy.sh scripts/m3/dis-roundtrip.sh
|
||||
git commit -m "tests: M5 policy and hardening gate"
|
||||
```
|
||||
|
||||
### Task 9: Conformance harness, shim, manifest, and feature classifier
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/fetch-conformance.sh`, `scripts/tests/m5/conformance/run.sh`, `shim.c`, `entry.asm`, `classify.sh`, `manifest.tsv`, `skip.tsv`, `c-torture.sh`, `c-testsuite.sh`
|
||||
- Create: `vendor/conformance` (ignored; pinned GCC 16.2.0 c-torture and c-testsuite `5c7275656d751de0e68b2d340a95b5681858ed07`)
|
||||
- Test: `scripts/tests/m5/conformance/selftest.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Tasks 4–8's native/asm pipeline; the M4 contiguous varargs; the ROM `blit_copy`/`rts.lib`.
|
||||
- Produces: a runner that compiles one test, links the shim/entry, runs it in MAME, captures a status/output buffer, and compares the expected result. The manifest row format is `test_id<TAB>suite<TAB>expected<TAB>features<TAB>skip_reason`.
|
||||
|
||||
- [ ] **Step 1: Write the failing selftest**
|
||||
|
||||
`selftest.sh` contains three tiny C cases:
|
||||
|
||||
```c
|
||||
/* pass */ int main(void) { return 0; }
|
||||
/* fail */ int main(void) { return 7; }
|
||||
/* print */ int main(void) { printf("ok\n"); return 0; }
|
||||
```
|
||||
|
||||
The first run must fail because the runner/shim/log capture does not exist.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/conformance/selftest.sh`
|
||||
Expected: missing runner/shim or an unreadable result.
|
||||
|
||||
- [ ] **Step 3: Implement the shim and runner**
|
||||
|
||||
`shim.c` defines `printf`/`putchar`/`puts` with the M4 contiguous `&fmt` walk, writing to a fixed output buffer; `exit`/`abort` set the status/marker; `entry.asm` calls `main(1, argv)`, stores the output buffer/status at the M4 marker addresses, and returns. `run.sh` compiles the test + shim + entry, links (native if available, asm fallback), runs MAME, reads the status/output, and compares the manifest/expected. `classify.sh` scans a source for unsupported features (`float`, `double`, `long long`, `int64`, `bitfield`, `va_list`, `va_start`, `va_arg`, `alloca`, `setjmp`, `signal`, `wchar`, `%f`, `%e`, `%g`, `%ll`, `%L`, files) and emits a skip reason.
|
||||
|
||||
`fetch-conformance.sh` pins GCC 16.2.0 (`gcc-16.2.0.tar.xz`, SHA-256 checked) and the c-testsuite commit; it preserves `COPYING`, uses `vendor/conformance`, and never writes into the repo.
|
||||
|
||||
- [ ] **Step 4: Run the selftest green**
|
||||
|
||||
Run: `scripts/tests/m5/conformance/selftest.sh`
|
||||
Expected: PASS for the pass/print cases, FAIL (expected) for the fail case, and the output compare catches a mismatch.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git add scripts/fetch-conformance.sh scripts/tests/m5/conformance
|
||||
git commit -m "tests: M5 conformance harness and shim"
|
||||
```
|
||||
|
||||
### Task 10: `CodeGen/Generic` no-crash sweep
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m5/generic.sh`, `generic-allowlist.txt`, `generic-expected-fail.txt`
|
||||
- Test: `scripts/tests/m5/generic.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 9's manifest/classifier; the LLVM `test/CodeGen/Generic` 200 files.
|
||||
- Produces: a curated allowlist gate and a broad no-crash report; every failure is classified as unsupported/known/unexpected.
|
||||
|
||||
- [ ] **Step 1: Write the failing generic gate**
|
||||
|
||||
`generic.sh` runs `llc -march=tms34010 -filetype=asm -O0` on the allowlist (integer/control/load-store/call/PHI; no floats/vectors/atomics/i64/varargs/aggregates) and requires exit 0 and a non-empty asm; the broad sweep runs all 200 and writes `generic-report.txt` with `pass`/`unsupported`/`crash`. The first run must fail because the allowlist is empty/nonexistent.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/generic.sh`
|
||||
Expected: `no allowlist` or a known crash.
|
||||
|
||||
- [ ] **Step 3: Seed the allowlist and expected-fail manifest**
|
||||
|
||||
Start with a small allowlist (the stress/PHI/load-store/bitcast tests that the M5 target can select) and record each broad-sweep failure with a reason. Do not put a crash in the expected-fail list; crashes are regressions.
|
||||
|
||||
- [ ] **Step 4: Run the generic gate green**
|
||||
|
||||
Run: `scripts/tests/m5/generic.sh`
|
||||
Expected: allowlist PASS; broad sweep has no `crash` rows; `unsupported` rows have diagnostics.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git add scripts/tests/m5/generic.sh scripts/tests/m5/generic-allowlist.txt scripts/tests/m5/generic-expected-fail.txt
|
||||
git commit -m "tests: M5 CodeGen/Generic no-crash sweep"
|
||||
```
|
||||
|
||||
### Task 11: GCC 16.2 c-torture `execute` subset
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m5/c-torture.sh`, `c-torture.list`
|
||||
- Test: `scripts/tests/m5/c-torture.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 9's runner/shim/classifier; the pinned GCC c-torture `execute`.
|
||||
- Produces: a curated allowlist of integer/control/array/pointer tests that return 0 or `abort`; the runner requires `main` 0 and no abort, in MAME.
|
||||
|
||||
- [ ] **Step 1: Write the failing c-torture gate**
|
||||
|
||||
`c-torture.sh` compiles each name in `c-torture.list` with `tms-clang -O0` (and a second `-O2` pass where supported), links the shim/entry, runs MAME, and requires `main` 0/no abort. The first run must fail because the list is empty.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/c-torture.sh`
|
||||
Expected: `no c-torture.list` or the first test fails.
|
||||
|
||||
- [ ] **Step 3: Seed the list**
|
||||
|
||||
Select tests with the classifier (`int-control` only; no floats/i64/bitfields/varargs/aggregates/alloca/setjmp/signals/files), verify they compile on the host, and commit the list. Keep the list small enough to run in the M5 gate (target 40–60 tests); put the broader scan in a report mode.
|
||||
|
||||
- [ ] **Step 4: Run the c-torture gate green**
|
||||
|
||||
Run: `scripts/tests/m5/c-torture.sh`
|
||||
Expected: PASS for the list; the report records skipped tests and reasons.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git add scripts/tests/m5/c-torture.sh scripts/tests/m5/c-torture.list
|
||||
git commit -m "tests: M5 c-torture integer subset"
|
||||
```
|
||||
|
||||
### Task 12: c-testsuite `single-exec` subset
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m5/c-testsuite.sh`, `c-testsuite.list`, `c-testsuite.skip`
|
||||
- Test: `scripts/tests/m5/c-testsuite.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 9's runner/shim/classifier; the pinned c-testsuite `single-exec` `.c`/`.expected`/`.tags`.
|
||||
- Produces: a curated set whose stdout/stderr equals the `.expected` file; the official `tests/single-exec/*.c` interface; a skip list for unsupported features.
|
||||
|
||||
- [ ] **Step 1: Write the failing c-testsuite gate**
|
||||
|
||||
`c-testsuite.sh` runs each name in `c-testsuite.list` through the `single-exec` runner interface and compares the captured output with `.expected`. The first run must fail because the list is empty.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m5/c-testsuite.sh`
|
||||
Expected: `no c-testsuite.list` or the first output mismatch.
|
||||
|
||||
- [ ] **Step 3: Seed the list and skip file**
|
||||
|
||||
Select `single-exec` tests tagged portable/integer/control/string that the classifier accepts; add the rest to `c-testsuite.skip` with a reason. The `printf` shim must handle the formats these tests use; a `%f`/`%ll`/wide test is skipped, not silently passed.
|
||||
|
||||
- [ ] **Step 4: Run the c-testsuite gate green**
|
||||
|
||||
Run: `scripts/tests/m5/c-testsuite.sh`
|
||||
Expected: PASS for the list; skipped tests are reported with reasons; an output mismatch fails.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git add scripts/tests/m5/c-testsuite.sh scripts/tests/m5/c-testsuite.list scripts/tests/m5/c-testsuite.skip
|
||||
git commit -m "tests: M5 c-testsuite output subset"
|
||||
```
|
||||
|
||||
### Task 13: Docs, full gates, and push
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, `symbols/README.md` (if the native path adds symbols)
|
||||
- Test: the full M5/M4/M3/M2 gate list
|
||||
|
||||
- [ ] **Step 1: Update the docs**
|
||||
|
||||
Document the native TI-COFF path (`llc -filetype=obj` → GSPLNK → loader), the MC/assembler/disassembler, `JR`/relaxation, `MMTM`/`MMFM`, `alloca`/`byval`/narrow returns/mem intrinsics, the removed driver policies, the conformance tiers (Generic/c-torture/c-testsuite, the classifier, the shim), the pinned test versions, and the M5/M6 boundary. Correct the plan's `XLoadFont`/`XCopyArea` note, the `xshow` right-edge wording, and the private-label GSPA 31-character caveat in the project docs.
|
||||
|
||||
- [ ] **Step 2: Run every gate**
|
||||
|
||||
```sh
|
||||
ninja -C build/llvm-clean-build llc llvm-mc
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010 --filter='(m2|m3|m4|m5)-'
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010
|
||||
scripts/tests/m5/object-smoke.sh
|
||||
scripts/tests/m5/native-link.sh
|
||||
scripts/tests/m5/mc-roundtrip.sh
|
||||
scripts/tests/m5/native.sh
|
||||
scripts/tests/m5/jr.sh
|
||||
scripts/tests/m5/mmtm.sh
|
||||
scripts/tests/m5/robust.sh
|
||||
scripts/tests/m5/policy.sh
|
||||
scripts/tests/m5/conformance/selftest.sh
|
||||
scripts/tests/m5/generic.sh
|
||||
scripts/tests/m5/c-torture.sh
|
||||
scripts/tests/m5/c-testsuite.sh
|
||||
scripts/tests/m4/run.sh
|
||||
scripts/tests/m4/dis-roundtrip.sh
|
||||
scripts/tests/m4/layout.sh
|
||||
scripts/tests/m4/symbols.sh
|
||||
scripts/tests/m4/termtris.sh
|
||||
scripts/tests/m3/run.sh
|
||||
scripts/tests/m3/dis-roundtrip.sh
|
||||
scripts/tests/m2/run.sh
|
||||
tools/tms-bitaddr/tests/run.sh
|
||||
```
|
||||
|
||||
All green; the conformance report has no unexpected crashes; skipped tests have reasons.
|
||||
|
||||
- [ ] **Step 3: Commit and push**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010 llvm/test/MC/TMS34010 TMS34010.md
|
||||
git -C build/llvm-clean commit -m "tms34010: M5 native object path, code-size and conformance"
|
||||
git -C build/llvm-clean push origin m5
|
||||
git add README.md symbols scripts/m5 scripts/tests/m5 scripts/tms-clang scripts/m3
|
||||
git commit -m "tests/docs: M5 native object path and conformance"
|
||||
git push origin m5
|
||||
```
|
||||
|
||||
Do not force-push, merge into `m0`–`m4`, or change the default. The controller updates the default to `m5` after the final review only if the user asks.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M5 delivers the native object path and the first external conformance tier while keeping the M4 asm path as the oracle. M6 owns floats/double, `long long`, general varargs (`va_list`), bitfields, structs by value, aggregate returns, debug info, the wider Xlib surface, and the full external suites. The compiler repo is canonical for target code; this project repo holds the plan, harness, pins, and integration tests. The pinned GCC/c-testsuite trees are test-only (GPL) and are not part of the compiler or project distribution.
|
||||
@@ -80,9 +80,9 @@ early GEP-scaling pass.
|
||||
set `FP = STK`; `ADDI frame_size,STK`; locals at positive FP offsets, first
|
||||
argument at `FP(-32)`; restore STK from `*SP(offset)`; `MMFM`; `RETS 2` if
|
||||
arguments or stack return, `RETS 0` otherwise.
|
||||
- `FS1` must be 32 inside C code and `FE0` must be 0; `FS0` may be changed
|
||||
without restoring. Xlib clobbers the field-size state, so FS1 must be
|
||||
re-established after every call.
|
||||
- `FS1` must be 32 inside C code and `FS0` must be 16 with its field-extension
|
||||
bit set (`SETF 16,1,0`, sign-extending); both must be re-established after
|
||||
every call because Xlib may change the field-size state.
|
||||
- Struct return: caller allocates, pushes the address; callee copies. Float/
|
||||
double return: caller allocates space on the program stack, callee copies.
|
||||
(C guide §5.3.)
|
||||
@@ -324,7 +324,7 @@ non-constant pointer expression by 8×.
|
||||
MAME, and the byte-exact ROM round-trip.
|
||||
- Loads/stores: misaligned accesses allowed; `MOVB` for i8, `MOVE` with FS0 for
|
||||
i16, `MOVE` with FS1 for i32/pointers; i64 as two 32-bit accesses. Ensure
|
||||
FS1 is 32; use FS0 for 16-bit.
|
||||
FS1 is 32 and FS0 is 16 sign-extending; use FS0 for 16-bit.
|
||||
- `memcpy`/`memmove`/`memset`: lower to byte/word loops; lengths are bytes,
|
||||
addresses bits; overlap semantics for `memmove`.
|
||||
- `alloca`/VLA: size ×8; 16-bit alignment for standalone objects.
|
||||
@@ -436,6 +436,12 @@ no X errors.
|
||||
**M5 — robustness and native path.** `memcpy`, `alloca`, `byval`, varargs
|
||||
(`sprintf`), floats, bitfields, `long long`; native COFF and debug info.
|
||||
|
||||
> **M5 re-scoped (2026-11-13):** floats/double, bitfields, `long long`/i64,
|
||||
> general varargs (`va_list`/`va_start`/`va_arg` beyond the contiguous
|
||||
> `sprintf` form) and debug info are **M6**. M5 delivers the integer/pointer
|
||||
> native object path, `alloca`/`byval`/narrow returns, `memcpy`/`memset`/
|
||||
> `memmove`, `JR`/`MMTM`, and the curated conformance tier.
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
| risk | mitigation |
|
||||
|
||||
Executable
+134
@@ -0,0 +1,134 @@
|
||||
#!/bin/sh
|
||||
# Fetch the pinned external conformance corpora into vendor/conformance.
|
||||
#
|
||||
# scripts/fetch-conformance.sh [DEST]
|
||||
# scripts/fetch-conformance.sh --gcc-only [DEST]
|
||||
# scripts/fetch-conformance.sh --c-testsuite-only [DEST]
|
||||
#
|
||||
# DEST defaults to vendor/conformance (ignored by git). Nothing in the
|
||||
# tracked tree is written.
|
||||
#
|
||||
# Pins:
|
||||
# GCC 16.2.0 https://ftp.gnu.org/gnu/gcc/gcc-16.2.0/gcc-16.2.0.tar.xz
|
||||
# SHA-256 e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e
|
||||
# (only gcc/testsuite/gcc.c-torture and COPYING* are extracted)
|
||||
# c-testsuite 5c7275656d751de0e68b2d340a95b5681858ed07
|
||||
# https://github.com/c-testsuite/c-testsuite
|
||||
#
|
||||
# The corpus licences are preserved in each extracted tree (COPYING*). The
|
||||
# tests are test-only and are not part of the compiler or project
|
||||
# distribution.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
|
||||
GCC_VERSION=16.2.0
|
||||
GCC_TOP=gcc-$GCC_VERSION
|
||||
GCC_URL=https://ftp.gnu.org/gnu/gcc/$GCC_TOP/$GCC_TOP.tar.xz
|
||||
GCC_SHA256=e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e
|
||||
|
||||
CTEST_REPO=https://github.com/c-testsuite/c-testsuite
|
||||
CTEST_COMMIT=5c7275656d751de0e68b2d340a95b5681858ed07
|
||||
|
||||
DO_GCC=1
|
||||
DO_CTEST=1
|
||||
DEST=
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--gcc-only) DO_CTEST=0; shift ;;
|
||||
--c-testsuite-only) DO_GCC=0; shift ;;
|
||||
-h|--help)
|
||||
sed -n '2,/^set -eu/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
-*) echo "fetch-conformance: unknown option: $1" >&2; exit 2 ;;
|
||||
*)
|
||||
[ -z "$DEST" ] || { echo "fetch-conformance: more than one DEST" >&2; exit 2; }
|
||||
DEST=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
DEST=${DEST:-$ROOT/vendor/conformance}
|
||||
mkdir -p "$DEST"
|
||||
DEST=$(cd "$DEST" && pwd)
|
||||
|
||||
fail() {
|
||||
echo "fetch-conformance: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
download() {
|
||||
url=$1
|
||||
out=$2
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fL --retry 3 --connect-timeout 30 -o "$out.part" "$url"
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -O "$out.part" "$url"
|
||||
else
|
||||
fail "need curl or wget to download $url"
|
||||
fi
|
||||
mv "$out.part" "$out"
|
||||
}
|
||||
|
||||
if [ "$DO_GCC" -eq 1 ]; then
|
||||
TAR=$DEST/downloads/$GCC_TOP.tar.xz
|
||||
mkdir -p "$DEST/downloads"
|
||||
if [ ! -f "$TAR" ]; then
|
||||
echo "== download $GCC_URL"
|
||||
download "$GCC_URL" "$TAR"
|
||||
fi
|
||||
echo "== verify $GCC_TOP.tar.xz"
|
||||
printf '%s %s\n' "$GCC_SHA256" "$TAR" | sha256sum -c - \
|
||||
|| fail "SHA-256 mismatch for $TAR"
|
||||
|
||||
if [ ! -d "$DEST/$GCC_TOP/gcc/testsuite/gcc.c-torture/execute" ]; then
|
||||
echo "== extract gcc.c-torture and COPYING*"
|
||||
tar -xJf "$TAR" -C "$DEST" --wildcards \
|
||||
"$GCC_TOP/gcc/testsuite/gcc.c-torture/*" \
|
||||
"$GCC_TOP/COPYING*"
|
||||
else
|
||||
echo "== gcc.c-torture already extracted"
|
||||
fi
|
||||
[ -d "$DEST/$GCC_TOP/gcc/testsuite/gcc.c-torture/execute" ] \
|
||||
|| fail "extraction produced no gcc.c-torture/execute"
|
||||
ls "$DEST/$GCC_TOP"/COPYING* >/dev/null 2>&1 \
|
||||
|| fail "extraction preserved no COPYING file"
|
||||
fi
|
||||
|
||||
if [ "$DO_CTEST" -eq 1 ]; then
|
||||
CTEST=$DEST/c-testsuite
|
||||
if [ ! -d "$CTEST/.git" ]; then
|
||||
echo "== clone $CTEST_REPO"
|
||||
mkdir -p "$(dirname "$CTEST")"
|
||||
git clone --filter=blob:none --no-checkout "$CTEST_REPO" "$CTEST"
|
||||
fi
|
||||
echo "== checkout c-testsuite $CTEST_COMMIT"
|
||||
git -C "$CTEST" fetch --depth 1 origin "$CTEST_COMMIT" 2>/dev/null || true
|
||||
git -C "$CTEST" checkout --detach "$CTEST_COMMIT"
|
||||
REV=$(git -C "$CTEST" rev-parse HEAD)
|
||||
[ "$REV" = "$CTEST_COMMIT" ] \
|
||||
|| fail "c-testsuite is at $REV, want $CTEST_COMMIT"
|
||||
[ -d "$CTEST/tests/single-exec" ] \
|
||||
|| fail "c-testsuite checkout has no tests/single-exec"
|
||||
if [ -f "$CTEST/COPYING" ]; then
|
||||
:
|
||||
elif [ -f "$CTEST/LICENSE" ]; then
|
||||
:
|
||||
else
|
||||
fail "c-testsuite checkout preserved no COPYING/LICENSE"
|
||||
fi
|
||||
fi
|
||||
|
||||
{
|
||||
printf 'gcc_version\t%s\n' "$GCC_VERSION"
|
||||
printf 'gcc_url\t%s\n' "$GCC_URL"
|
||||
printf 'gcc_sha256\t%s\n' "$GCC_SHA256"
|
||||
printf 'c_testsuite_repo\t%s\n' "$CTEST_REPO"
|
||||
printf 'c_testsuite_commit\t%s\n' "$CTEST_COMMIT"
|
||||
} > "$DEST/PINS"
|
||||
|
||||
echo "== pinned conformance corpora at $DEST"
|
||||
du -sh "$DEST" 2>/dev/null || true
|
||||
@@ -21,7 +21,7 @@
|
||||
.globl _start
|
||||
_start:
|
||||
setf 32, 0, 1 ; FS1 = 32 for 32-bit MOVE
|
||||
setf 16, 0, 0 ; FS0 = 16, for any i16 code
|
||||
setf 16, 1, 0 ; FS0 = 16, for any i16 code
|
||||
movi 20, a0
|
||||
movi 22, a1
|
||||
calla _add
|
||||
|
||||
@@ -268,7 +268,7 @@ expect_seq "$TMP/keep.txt" \
|
||||
'move[[:space:]]+a14,[[:space:]]*-\*sp,[[:space:]]*1' \
|
||||
'move[[:space:]]+[^,]+,[[:space:]]*\*a14\+,[[:space:]]*1' \
|
||||
'calla' \
|
||||
'setf[[:space:]]+16,[[:space:]]*0,[[:space:]]*0' \
|
||||
'setf[[:space:]]+16,[[:space:]]*1,[[:space:]]*0' \
|
||||
'setf[[:space:]]+32,[[:space:]]*0,[[:space:]]*1' \
|
||||
'move[[:space:]]+\*sp\(0x[0-9a-f]+\),[[:space:]]*a14,[[:space:]]*1' \
|
||||
'rets[[:space:]]+2([[:space:]]*(;|$))'
|
||||
@@ -291,8 +291,15 @@ check_stk() {
|
||||
_addr=$2
|
||||
func_body "$_addr" > "$TMP/func.txt"
|
||||
_pushes=$(awk '
|
||||
tolower($0) ~ /move[[:space:]]+[a-z0-9]+,[[:space:]]*-\*sp,[[:space:]]*1/ { n++ }
|
||||
tolower($0) ~ /move[[:space:]]+a14,[[:space:]]*a13/ { print n; exit }
|
||||
{ low = tolower($0) }
|
||||
low ~ /move[[:space:]]+[a-z0-9]+,[[:space:]]*-\*sp,[[:space:]]*1/ { n++ }
|
||||
low ~ /mmtm[[:space:]]+sp,/ {
|
||||
line = low
|
||||
sub(/^.*mmtm[[:space:]]+sp,[[:space:]]*/, "", line)
|
||||
sub(/[[:space:]]*;.*$/, "", line)
|
||||
n += split(line, regs, ",")
|
||||
}
|
||||
low ~ /move[[:space:]]+a14,[[:space:]]*a13/ { print n; exit }
|
||||
' "$TMP/func.txt")
|
||||
[ -n "$_pushes" ] || fail "$_label has no SETFP (MOVE A14,A13)"
|
||||
_operand=$(grep -Eio '\*sp\(0x[0-9a-f]+\)' "$TMP/func.txt" | head -1 \
|
||||
@@ -301,8 +308,8 @@ check_stk() {
|
||||
_want=$(( (_pushes + 1) * 32 ))
|
||||
_got=$((0x$_operand))
|
||||
[ "$_got" -eq "$_want" ] \
|
||||
|| fail "$_label restores A14 from *SP(0x$_operand) ($_got bits) but $_pushes pushes need $_want bits"
|
||||
echo " ok $_label: $_pushes pushes -> *SP($(printf '0x%x' "$_want")), A14, 1"
|
||||
|| fail "$_label restores A14 from *SP(0x$_operand) ($_got bits) but $_pushes saved slots need $_want bits"
|
||||
echo " ok $_label: $_pushes saved slots -> *SP($(printf '0x%x' "$_want")), A14, 1"
|
||||
}
|
||||
check_stk "_add2" "$ADD2"
|
||||
check_stk "_first" "$FIRST"
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
.globl _start
|
||||
_start:
|
||||
setf 32, 0, 1
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
|
||||
+73
-58
@@ -7,11 +7,13 @@
|
||||
# VT1200 tree's dis34, and checks that GSPA encoded the compiler output:
|
||||
#
|
||||
# _XOpenDisplay/_XCreateSimpleWindow/_XMapWindow/_XSync JAUC <ROM bit addr>
|
||||
# (XMapWindow is 3FD64F60, MapWindow opcode 8; 3FD645B0 is XRaiseWindow)
|
||||
# _xhello: 1 push -> CALLA _XOpenDisplay, 9 pushes -> CALLA
|
||||
# _XCreateSimpleWindow (arguments 1,0,2,200,400,100,100,root,
|
||||
# display in that order, display pushed last), 2 -> _XMapWindow,
|
||||
# 2 -> _XSync, each followed by the ABI's SETF 16/32 pair
|
||||
# branch code: CMP, JALT, JAGT, JAEQ, JAUC and LBB… labels (never .LBB)
|
||||
# branch code: CMP plus relative JR/JR<cc> branches (absolute JA* only for a
|
||||
# zero-displacement or out-of-range target) and LBB… labels (never .LBB)
|
||||
# .data: 30 3A 3A 30 00 ("0::0")
|
||||
# old-STK restore offsets: *SP((pushes+1)*32),A14
|
||||
#
|
||||
@@ -256,8 +258,8 @@ expect_at "_XOpenDisplay" "$XOPEN" "JAUC 3F9C2570" \
|
||||
'jauc[[:space:]]+0x3f9c2570'
|
||||
expect_at "_XCreateSimpleWindow" "$XCREATE" "JAUC 3FD41B90" \
|
||||
'jauc[[:space:]]+0x3fd41b90'
|
||||
expect_at "_XMapWindow" "$XMAP" "JAUC 3FD645B0" \
|
||||
'jauc[[:space:]]+0x3fd645b0'
|
||||
expect_at "_XMapWindow" "$XMAP" "JAUC 3FD64F60" \
|
||||
'jauc[[:space:]]+0x3fd64f60'
|
||||
expect_at "_XSync" "$XSYNC" "JAUC 3FD9F6B0" \
|
||||
'jauc[[:space:]]+0x3fd9f6b0'
|
||||
|
||||
@@ -289,59 +291,44 @@ P4=$(count_between "$TMP/xhello.txt" "calla[[:space:]]+l${XMAP_L}" \
|
||||
echo " ok argument pushes: XOpenDisplay=1 XCreateSimpleWindow=9 XMapWindow=2 XSync=2"
|
||||
|
||||
# Counting pushes is not enough: the nine words must reach the callee in the
|
||||
# ABI order. build/m3/m3.lst records background 1, border 0, border width 2,
|
||||
# height 200, width 400, y 100, then x 100 (x reuses y's register, so there are
|
||||
# six MOVIs for the seven constants), followed by the root (A2) and display
|
||||
# (A0) pushes. Assert the immediates and push registers as one sequence, so a
|
||||
# swapped pair fails even though the count stays nine, and require the final
|
||||
# push before CALLA to be the display register.
|
||||
# ABI order. Parse the linked assembly the way the M4 dis34 gate does: record
|
||||
# each MOVI's register/value pair, then map every push register to the last
|
||||
# value loaded into it. The root (A2) and display (A0) are named explicitly.
|
||||
# x reuses y's register, so there are six MOVIs for the seven constants. This
|
||||
# fails a swapped immediate or register while keeping the exact nine-argument
|
||||
# order 1,0,2,200,400,100,100,root,display and the display pushed last.
|
||||
awk '
|
||||
tolower($0) ~ /calla[[:space:]]+l'"$XOPEN_L"'/ { on = 1; next }
|
||||
tolower($0) ~ /calla[[:space:]]+l'"$XCREATE_L"'/ { exit }
|
||||
/^[[:space:]]*CALLA[[:space:]]+_XOpenDisplay/ { on = 1; next }
|
||||
/^[[:space:]]*CALLA[[:space:]]+_XCreateSimpleWindow/ { exit }
|
||||
!on { next }
|
||||
tolower($0) ~ /move[[:space:]]+a14,[[:space:]]*-\*sp,[[:space:]]*1/ { started = 1; next }
|
||||
!started { next }
|
||||
tolower($0) ~ /movi[[:space:]]+/ {
|
||||
/^[[:space:]]*MOVI[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[^:]*:[[:space:]]+movi[[:space:]]+/, "", line)
|
||||
sub(/.*MOVI[[:space:]]+/, "", line)
|
||||
sub(/[[:space:]]*;.*/, "", line)
|
||||
sub(/[[:space:]]+/, " ", line)
|
||||
split(line, p, /,[[:space:]]*/)
|
||||
printf "IMM %s %s\n", tolower(p[1]), tolower(p[2])
|
||||
gsub(/[[:space:]]/, "", p[1])
|
||||
gsub(/[[:space:]]/, "", p[2])
|
||||
val[p[2]] = p[1]
|
||||
next
|
||||
}
|
||||
tolower($0) ~ /move[[:space:]]+a[0-9]+,[[:space:]]*\*a14\+,[[:space:]]*1/ {
|
||||
/^[[:space:]]*MOVE[[:space:]]+A[0-9]+,[[:space:]]*\*A14\+,/ {
|
||||
line = $0
|
||||
sub(/^[^:]*:[[:space:]]+move[[:space:]]+/, "", line)
|
||||
sub(/.*MOVE[[:space:]]+/, "", line)
|
||||
sub(/,.*/, "", line)
|
||||
printf "PUSH %s\n", tolower(line)
|
||||
next
|
||||
v = val[line]
|
||||
if (line == "A2") v = "root"
|
||||
if (line == "A0") v = "display"
|
||||
print v
|
||||
}
|
||||
' "$TMP/xhello.txt" > "$TMP/xcreate.seq"
|
||||
cat > "$TMP/xcreate.want" <<'EOF'
|
||||
IMM 0x1 a1
|
||||
PUSH a1
|
||||
IMM 0x0 a1
|
||||
PUSH a1
|
||||
IMM 0x2 a3
|
||||
PUSH a3
|
||||
IMM 0xc8 a3
|
||||
PUSH a3
|
||||
IMM 0x190 a3
|
||||
PUSH a3
|
||||
IMM 0x64 a3
|
||||
PUSH a3
|
||||
PUSH a3
|
||||
PUSH a2
|
||||
PUSH a0
|
||||
EOF
|
||||
if ! cmp -s "$TMP/xcreate.want" "$TMP/xcreate.seq"; then
|
||||
' "$ASM" > "$TMP/xcreate.vals"
|
||||
printf '%s\n' 1 0 2 200 400 100 100 root display > "$TMP/xcreate.want"
|
||||
if ! cmp -s "$TMP/xcreate.want" "$TMP/xcreate.vals"; then
|
||||
{
|
||||
echo "M3 dis34 round-trip: FAIL: XCreateSimpleWindow argument order"
|
||||
echo " expected (background,border,border_width,height,width,y,x,root,display):"
|
||||
sed 's/^/ /' "$TMP/xcreate.want"
|
||||
echo " got:"
|
||||
sed 's/^/ /' "$TMP/xcreate.seq"
|
||||
sed 's/^/ /' "$TMP/xcreate.vals"
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
@@ -353,7 +340,7 @@ awk '
|
||||
/^_xhello:/ { on = 1; next }
|
||||
on && /-- End function/ { exit }
|
||||
on && /^[[:space:]]*CALLA/ { pending = 1; next }
|
||||
on && pending && /SETF[[:space:]]+16,[[:space:]]*0,[[:space:]]*0/ { saw16 = 1; next }
|
||||
on && pending && /SETF[[:space:]]+16,[[:space:]]*1,[[:space:]]*0/ { saw16 = 1; next }
|
||||
on && pending && saw16 && /SETF[[:space:]]+32,[[:space:]]*0,[[:space:]]*1/ {
|
||||
n++; pending = 0; saw16 = 0; next
|
||||
}
|
||||
@@ -362,7 +349,7 @@ awk '
|
||||
SETF_COUNT=$(cat "$TMP/setf_count")
|
||||
[ "$SETF_COUNT" -eq 4 ] \
|
||||
|| fail "found $SETF_COUNT post-call SETF 16/32 pairs in _xhello, want 4"
|
||||
echo " ok four post-call SETF 16,0,0 + SETF 32,0,1 pairs"
|
||||
echo " ok four post-call SETF 16,1,0 + SETF 32,0,1 pairs"
|
||||
|
||||
# _xhello takes no arguments of its own (the nine-argument call is inside it),
|
||||
# so it returns with RETS 0; the argument-taking branch functions use RETS 2.
|
||||
@@ -376,6 +363,9 @@ for pair in "$SUMTO:_sumto" "$MAX2:_max2" "$LT:_lt"; do
|
||||
done
|
||||
|
||||
echo "== check the branch code"
|
||||
# A compiled local branch uses the one-word relative JR/JR<cc> form when the
|
||||
# displacement fits; far or zero-displacement branches keep JAUC/JA<cc>. The
|
||||
# condition code must survive either encoding.
|
||||
for pair in "$SUMTO:_sumto" "$MAX2:_max2" "$LT:_lt"; do
|
||||
addr=${pair%%:*}
|
||||
label=${pair##*:}
|
||||
@@ -384,11 +374,11 @@ for pair in "$SUMTO:_sumto" "$MAX2:_max2" "$LT:_lt"; do
|
||||
sed 's/^/ /' "$TMP/fn.txt" >&2
|
||||
fail "$label has no CMP"
|
||||
fi
|
||||
if ! grep -Eiq '\bjauc\b' "$TMP/fn.txt"; then
|
||||
if ! grep -Eiq '\bj[ra](uc|eq|ne|lt|le|gt|ge|lo|ls|hi|hs|p|n|v|nv|nn)\b' "$TMP/fn.txt"; then
|
||||
sed 's/^/ /' "$TMP/fn.txt" >&2
|
||||
fail "$label has no JAUC"
|
||||
fail "$label has no branch"
|
||||
fi
|
||||
echo " ok $label: CMP + JAUC"
|
||||
echo " ok $label: CMP + branch"
|
||||
done
|
||||
for pair in "$XHELLO:_xhello"; do
|
||||
addr=${pair%%:*}
|
||||
@@ -406,14 +396,32 @@ for callee in _sumto _max2 _lt _layout_screens _layout_root; do
|
||||
|| fail "_branch_test does not call $callee"
|
||||
done
|
||||
echo " ok _branch_test calls sumto, max2, lt, layout_screens, layout_root"
|
||||
# Conditional branch opcodes emitted by this compiled image. JALE/JALO/JAHI
|
||||
# coverage lives in the m3-loop/m3-unsigned/m3-cmpi lit tests; this image has
|
||||
# the signed compare, loop-exit and smax branches.
|
||||
for op in jalt jagt jaeq; do
|
||||
grep -Eiq "^[0-9a-f]+:[[:space:]]+$op([[:space:]]|;|$)" "$TMP/dis34.txt" \
|
||||
|| fail "no $op instruction in the linked .text"
|
||||
echo " ok $op present"
|
||||
done
|
||||
# Conditional branch conditions, pinned per function: _sumto has the loop exit
|
||||
# (signed LT) and the result check (EQ), _max2 is smax (GT) and _lt is signed
|
||||
# LT. JALE/JALO/JAHI coverage lives in the m3-loop/m3-unsigned/m3-cmpi lit
|
||||
# tests. The condition code must survive whichever encoding the relaxation
|
||||
# selected.
|
||||
pin_cond() {
|
||||
_addr=$1
|
||||
_label=$2
|
||||
_cc=$3
|
||||
func_body "$_addr" > "$TMP/fn.txt"
|
||||
if ! grep -Eiq "^[0-9a-f]+:[[:space:]]+j[ra]${_cc}([[:space:]]|;|$)" \
|
||||
"$TMP/fn.txt"; then
|
||||
sed 's/^/ /' "$TMP/fn.txt" >&2
|
||||
fail "$_label has no J*${_cc} branch"
|
||||
fi
|
||||
echo " ok $_label: J*${_cc} branch"
|
||||
}
|
||||
pin_cond "$SUMTO" _sumto lt
|
||||
pin_cond "$SUMTO" _sumto eq
|
||||
pin_cond "$MAX2" _max2 gt
|
||||
pin_cond "$LT" _lt lt
|
||||
# At least one branch must have taken the one-word relative form; otherwise the
|
||||
# relaxation silently did nothing and the code-size claim is meaningless.
|
||||
grep -Eqio "^[0-9a-f]+:[[:space:]]+jr(uc|eq|ne|lt|le|gt|ge|lo|ls|hi|hs|p|n|v|nv|nn)([[:space:]]|;|$)" \
|
||||
"$TMP/dis34.txt" || fail "no JR branch in the linked .text"
|
||||
echo " ok JR relative branches present"
|
||||
|
||||
# GSPA rejects dotted .L labels; the harness gives each TU an LBB prefix.
|
||||
grep -q 'LBB' "$ASM" || fail "linked assembly has no LBB block labels"
|
||||
@@ -428,8 +436,15 @@ check_stk() {
|
||||
_addr=$2
|
||||
func_body "$_addr" > "$TMP/func.txt"
|
||||
_pushes=$(awk '
|
||||
tolower($0) ~ /move[[:space:]]+[a-z0-9]+,[[:space:]]*-\*sp,[[:space:]]*1/ { n++ }
|
||||
tolower($0) ~ /move[[:space:]]+a14,[[:space:]]*a13/ { print n; exit }
|
||||
{ low = tolower($0) }
|
||||
low ~ /move[[:space:]]+[a-z0-9]+,[[:space:]]*-\*sp,[[:space:]]*1/ { n++ }
|
||||
low ~ /mmtm[[:space:]]+sp,/ {
|
||||
line = low
|
||||
sub(/^.*mmtm[[:space:]]+sp,[[:space:]]*/, "", line)
|
||||
sub(/[[:space:]]*;.*$/, "", line)
|
||||
n += split(line, regs, ",")
|
||||
}
|
||||
low ~ /move[[:space:]]+a14,[[:space:]]*a13/ { print n; exit }
|
||||
' "$TMP/func.txt")
|
||||
[ -n "$_pushes" ] || fail "$_label has no SETFP (MOVE A14,A13)"
|
||||
_operand=$(grep -Eio '\*sp\(0x[0-9a-f]+\)' "$TMP/func.txt" | head -1 \
|
||||
@@ -438,8 +453,8 @@ check_stk() {
|
||||
_want=$(( (_pushes + 1) * 32 ))
|
||||
_got=$((0x$_operand))
|
||||
[ "$_got" -eq "$_want" ] \
|
||||
|| fail "$_label restores A14 from *SP(0x$_operand) ($_got bits) but $_pushes pushes need $_want bits"
|
||||
echo " ok $_label: $_pushes pushes -> *SP($(printf '0x%x' "$_want")), A14, 1"
|
||||
|| fail "$_label restores A14 from *SP(0x$_operand) ($_got bits) but $_pushes saved slots need $_want bits"
|
||||
echo " ok $_label: $_pushes saved slots -> *SP($(printf '0x%x' "$_want")), A14, 1"
|
||||
}
|
||||
check_stk "_sumto" "$SUMTO"
|
||||
check_stk "_max2" "$MAX2"
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
# 018A80E0 layout_screens() == 0x480
|
||||
# 018A8100 layout_root() == 0x40
|
||||
#
|
||||
# XMapWindow is the true MapWindow entry 3FD64F60 (request opcode 8);
|
||||
# 3FD645B0 is XRaiseWindow (ConfigureWindow opcode 12), not a mapping call.
|
||||
#
|
||||
# and, decisively, the full all-white VRAM word at (150,150) and another at
|
||||
# (250,200) inside the mapped window. A markers-only or root-window bit is a
|
||||
# failure.
|
||||
|
||||
@@ -3,8 +3,12 @@
|
||||
# client must exist in the v2.2 table, sit in the ROM's bit range, be 16-bit
|
||||
# aligned, and disassemble to a plausible function prologue.
|
||||
#
|
||||
# This is a regression check, not a re-extraction: dwt/gui/xhello.asm is the
|
||||
# evidence that these entries work. M4 extends the table for XImage/XEvent.
|
||||
# This is a regression check, not a re-extraction: dwt/gui/xhello.asm and the
|
||||
# termtris xlib.h are the evidence that these entries work. XMapWindow is the
|
||||
# true map entry (MapWindow request opcode 8); 0x3FD645B0 is XRaiseWindow
|
||||
# (ConfigureWindow opcode 12), never a mapping call. M4 extends the table for
|
||||
# XImage/XEvent and validates every entry independently in
|
||||
# scripts/m4/validate-syms.sh.
|
||||
#
|
||||
# scripts/m3/validate-syms.sh [symbols/vt1200-v22.syms]
|
||||
#
|
||||
@@ -55,7 +59,7 @@ check_sym() { # check_sym NAME EXPECTED_HEX
|
||||
|
||||
check_sym XOpenDisplay 0x3F9C2570
|
||||
check_sym XCreateSimpleWindow 0x3FD41B90
|
||||
check_sym XMapWindow 0x3FD645B0
|
||||
check_sym XMapWindow 0x3FD64F60
|
||||
check_sym XSync 0x3FD9F6B0
|
||||
|
||||
echo "m3 validate-syms: PASS (four v2.2 Xlib entries in ROM, aligned, prologues valid)"
|
||||
@@ -1,5 +1,10 @@
|
||||
#include "vt1200_xlib.h"
|
||||
|
||||
/*
|
||||
* XMapWindow maps with the true MapWindow entry (0x3FD64F60, request opcode
|
||||
* 8), not 0x3FD645B0: that address is XRaiseWindow (ConfigureWindow opcode
|
||||
* 12, CWStackMode=Above).
|
||||
*/
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n) * 0x20u))
|
||||
|
||||
int xhello(void) {
|
||||
|
||||
Executable
+312
@@ -0,0 +1,312 @@
|
||||
#!/bin/sh
|
||||
# M4 dis34 round-trip for the image/event client.
|
||||
#
|
||||
# scripts/m4/dis-roundtrip.sh
|
||||
#
|
||||
# Parses build/m4-xshow/m4.coff, disassembles its linked .text at 018A0000
|
||||
# with dis34, and checks that GSPA encoded:
|
||||
#
|
||||
# - every ROM Xlib import as JAUC <bit address> (the v2.2 table);
|
||||
# - the image client's direct calls: XOpenDisplay, XCreateSimpleWindow,
|
||||
# XSelectInput, XCreateGC, XSetForeground, XCreatePixmap, XCreateImage,
|
||||
# XSetErrorHandler, XMapWindow, XRaiseWindow, XSetInputFocus, XPutImage,
|
||||
# XCopyArea, XFillRectangle, XSync, XPending, XNextEvent, XLookupString,
|
||||
# XFlush, XGetInputFocus;
|
||||
# - the ROM sleep through a function pointer (CALL Rs, encoded 0x0920), the
|
||||
# Task 3 indirect-call contract;
|
||||
# - the nine-argument XCreateSimpleWindow order 0,0,0,480,640,20,20,root,
|
||||
# display (display pushed last);
|
||||
# - the XSetErrorHandler callback pointer (MOVI _on_error);
|
||||
# - SETF 16/32 after every call and the RETS/old-STK rules;
|
||||
# - the 480x80-byte checker .bss and its word-fill loop.
|
||||
#
|
||||
# Overridable: M4_COFF M4_ASM DIS34
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
WORK=${M4_WORK:-$ROOT/build/m4-xshow}
|
||||
COFF=${M4_COFF:-$WORK/m4.coff}
|
||||
ASM=${M4_ASM:-$WORK/m4.asm}
|
||||
LST=${M4_LST:-$WORK/m4.lst}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
|
||||
fail() {
|
||||
echo "M4 dis34 round-trip: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$COFF" ] || fail "linked COFF not found: $COFF (run scripts/m4/run.sh)"
|
||||
[ -f "$ASM" ] || fail "linked assembly not found: $ASM"
|
||||
[ -f "$LST" ] || fail "GSPA listing not found: $LST"
|
||||
[ -x "$DIS34" ] || fail "dis34 not found or not executable: $DIS34"
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-dis34.XXXXXX")
|
||||
FAIL_LOG=${M4_DIS_FAIL_LOG:-${TMPDIR:-/tmp}/m4-dis34-failure.txt}
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
read_u8s() { od -An -v -tu1 -j "$1" -N "$2" "$COFF"; }
|
||||
u16() { read_u8s "$1" 2 | awk '{ print $1 + 256 * $2 }'; }
|
||||
u32() { read_u8s "$1" 4 | awk '{ print $1 + 256 * $2 + 65536 * $3 + 16777216 * $4 }'; }
|
||||
|
||||
echo "== parse the COFF section table ($COFF)"
|
||||
nscns=$(u16 2)
|
||||
opthdr=$(u16 16)
|
||||
[ "$nscns" -gt 0 ] 2>/dev/null || fail "COFF has no sections"
|
||||
[ "$opthdr" -gt 0 ] 2>/dev/null || fail "COFF has no optional header"
|
||||
|
||||
TEXT_ADDR=; TEXT_BITS=; TEXT_PTR=
|
||||
DATA_ADDR=; DATA_BITS=; DATA_PTR=
|
||||
BSS_ADDR=; BSS_BITS=
|
||||
sh_base=$((20 + opthdr))
|
||||
i=0
|
||||
while [ "$i" -lt "$nscns" ]; do
|
||||
o=$((sh_base + i * 40))
|
||||
name=$(dd if="$COFF" bs=1 skip="$o" count=8 2>/dev/null | tr -d '\000')
|
||||
case "$name" in
|
||||
.text) TEXT_ADDR=$(u32 $((o + 8))); TEXT_BITS=$(u32 $((o + 16))); TEXT_PTR=$(u32 $((o + 20))) ;;
|
||||
.data) DATA_ADDR=$(u32 $((o + 8))); DATA_BITS=$(u32 $((o + 16))); DATA_PTR=$(u32 $((o + 20))) ;;
|
||||
.bss) BSS_ADDR=$(u32 $((o + 8))); BSS_BITS=$(u32 $((o + 16))) ;;
|
||||
esac
|
||||
i=$((i + 1))
|
||||
done
|
||||
[ -n "$TEXT_ADDR" ] || fail "COFF has no .text section"
|
||||
[ "$TEXT_BITS" -gt 0 ] 2>/dev/null || fail ".text is empty"
|
||||
[ $((TEXT_BITS % 8)) -eq 0 ] || fail ".text size $TEXT_BITS bits is not whole bytes"
|
||||
[ -n "$DATA_ADDR" ] || fail "COFF has no .data section"
|
||||
[ -n "$BSS_ADDR" ] || fail "COFF has no .bss section"
|
||||
[ "$BSS_BITS" -ge $((0x4B000)) ] 2>/dev/null \
|
||||
|| fail ".bss is $BSS_BITS bits, too small for the 640x480 image (0x4B000 bits)"
|
||||
|
||||
TEXT_HEX=$(printf '%08X' "$TEXT_ADDR")
|
||||
ENTRY=$(u32 $((20 + 16)))
|
||||
ENTRY_HEX=$(printf '%08X' "$ENTRY")
|
||||
TEXT_BYTES=$((TEXT_BITS / 8))
|
||||
[ "$TEXT_HEX" = "018A0000" ] || fail ".text is linked at $TEXT_HEX, want 018A0000"
|
||||
[ "$ENTRY_HEX" = "018A0000" ] || fail "COFF entry point is $ENTRY_HEX, want 018A0000"
|
||||
BSS_HEX=$(printf '%08X' "$BSS_ADDR")
|
||||
[ "$BSS_HEX" = "01A00000" ] || fail ".bss is at $BSS_HEX, want 01A00000"
|
||||
echo " .text at $TEXT_HEX: $TEXT_BITS bits ($TEXT_BYTES bytes)"
|
||||
echo " .data at $(printf '%08X' "$DATA_ADDR"): $DATA_BITS bits"
|
||||
echo " .bss at $BSS_HEX: $BSS_BITS bits"
|
||||
echo " entry point $ENTRY_HEX"
|
||||
|
||||
dd if="$COFF" of="$TMP/text.bin" bs=1 skip="$TEXT_PTR" count="$TEXT_BYTES" 2>/dev/null
|
||||
[ "$(wc -c < "$TMP/text.bin")" -eq "$TEXT_BYTES" ] || fail "could not extract .text"
|
||||
|
||||
echo "== resolve linked symbols"
|
||||
symptr=$(u32 8)
|
||||
nsyms=$(u32 12)
|
||||
[ "$nsyms" -gt 0 ] 2>/dev/null || fail "COFF has no symbol table"
|
||||
sym_addr() {
|
||||
_want=$1
|
||||
_strtab=$((symptr + nsyms * 18))
|
||||
_i=0
|
||||
while [ "$_i" -lt "$nsyms" ]; do
|
||||
_o=$((symptr + _i * 18))
|
||||
if [ "$(u32 "$_o")" -eq 0 ]; then
|
||||
_soff=$(u32 $((_o + 4)))
|
||||
_n=$(dd if="$COFF" bs=1 skip=$((_strtab + _soff)) count=64 2>/dev/null |
|
||||
tr '\000' '\n' | head -1)
|
||||
else
|
||||
_n=$(dd if="$COFF" bs=1 skip="$_o" count=8 2>/dev/null | tr -d '\000')
|
||||
fi
|
||||
if [ "$_n" = "$_want" ]; then
|
||||
u32 $((_o + 8))
|
||||
return 0
|
||||
fi
|
||||
_aux=$(od -An -v -tu1 -j $((_o + 17)) -N 1 "$COFF" | awk '{ print $1 }')
|
||||
_i=$((_i + 1 + _aux))
|
||||
done
|
||||
return 1
|
||||
}
|
||||
get_sym() {
|
||||
_a=$(sym_addr "$1") || fail "COFF symbol table has no $1"
|
||||
printf '%s' "$_a"
|
||||
}
|
||||
|
||||
XOPEN=$(get_sym _XOpenDisplay)
|
||||
XCREATE=$(get_sym _XCreateSimpleWindow)
|
||||
XSELECT=$(get_sym _XSelectInput)
|
||||
XGC=$(get_sym _XCreateGC)
|
||||
XSETFG=$(get_sym _XSetForeground)
|
||||
XCPM=$(get_sym _XCreatePixmap)
|
||||
XCI=$(get_sym _XCreateImage)
|
||||
XERR=$(get_sym _XSetErrorHandler)
|
||||
XMAP=$(get_sym _XMapWindow)
|
||||
XRAISE=$(get_sym _XRaiseWindow)
|
||||
XSETFOCUS=$(get_sym _XSetInputFocus)
|
||||
XPUT=$(get_sym _XPutImage)
|
||||
XCOPY=$(get_sym _XCopyArea)
|
||||
XFILL=$(get_sym _XFillRectangle)
|
||||
XSYNC=$(get_sym _XSync)
|
||||
XPEND=$(get_sym _XPending)
|
||||
XNEXT=$(get_sym _XNextEvent)
|
||||
XLOOKUP=$(get_sym _XLookupString)
|
||||
XFLUSH=$(get_sym _XFlush)
|
||||
XGETFOCUS=$(get_sym _XGetInputFocus)
|
||||
XSLEEP=$(get_sym _sleep)
|
||||
XBLIT=$(get_sym _blit_copy)
|
||||
XSHOW=$(get_sym _xshow)
|
||||
|
||||
echo "== disassemble the emitted .text with dis34"
|
||||
"$DIS34" -b "$TEXT_HEX" -l -o "$TMP/text.bin" > "$TMP/dis34.txt" 2> "$TMP/dis34.err" \
|
||||
|| { cat "$TMP/dis34.err" >&2; fail "dis34 failed"; }
|
||||
[ -s "$TMP/dis34.txt" ] || fail "dis34 produced no output"
|
||||
|
||||
match_at() {
|
||||
_file=$1; _addr=$2; _pat=$3
|
||||
_laddr=$(printf '%08x' "$_addr")
|
||||
grep -Eiq "^${_laddr}:[[:space:]]+${_pat}([[:space:]]*(;|$))" "$_file"
|
||||
}
|
||||
expect_at() {
|
||||
_label=$1; _addr=$2; _want=$3; _pat=$4
|
||||
_laddr=$(printf '%08x' "$_addr")
|
||||
if match_at "$TMP/dis34.txt" "$_addr" "$_pat"; then
|
||||
echo " ok $_label @ 0x$_laddr: $_want"
|
||||
return 0
|
||||
fi
|
||||
{
|
||||
echo "M4 dis34 round-trip: FAIL"
|
||||
echo " $_label at bit 0x$_laddr: expected $_want"
|
||||
awk -v a="$_laddr" '{ low=tolower($0) } low ~ ("^" a ":") { seen=1 } seen { print " " $0; n++ } seen && n>=4 { exit }' "$TMP/dis34.txt"
|
||||
cp "$TMP/dis34.txt" "$FAIL_LOG" 2>/dev/null || true
|
||||
} >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
echo "== check the ROM import stubs"
|
||||
expect_at _XOpenDisplay "$XOPEN" "JAUC 3F9C2570" 'jauc[[:space:]]+0x3f9c2570'
|
||||
expect_at _XCreateSimpleWindow "$XCREATE" "JAUC 3FD41B90" 'jauc[[:space:]]+0x3fd41b90'
|
||||
expect_at _XSelectInput "$XSELECT" "JAUC 3FD97D50" 'jauc[[:space:]]+0x3fd97d50'
|
||||
expect_at _XCreateGC "$XGC" "JAUC 3F997000" 'jauc[[:space:]]+0x3f997000'
|
||||
expect_at _XSetForeground "$XSETFG" "JAUC 3FD99A60" 'jauc[[:space:]]+0x3fd99a60'
|
||||
expect_at _XCreatePixmap "$XCPM" "JAUC 3FD416E0" 'jauc[[:space:]]+0x3fd416e0'
|
||||
expect_at _XCreateImage "$XCI" "JAUC 3F9A0490" 'jauc[[:space:]]+0x3f9a0490'
|
||||
expect_at _XSetErrorHandler "$XERR" "JAUC 3FD45700" 'jauc[[:space:]]+0x3fd45700'
|
||||
expect_at _XMapWindow "$XMAP" "JAUC 3FD64F60" 'jauc[[:space:]]+0x3fd64f60'
|
||||
expect_at _XRaiseWindow "$XRAISE" "JAUC 3FD645B0" 'jauc[[:space:]]+0x3fd645b0'
|
||||
expect_at _XSetInputFocus "$XSETFOCUS" "JAUC 3FD536B0" 'jauc[[:space:]]+0x3fd536b0'
|
||||
expect_at _XPutImage "$XPUT" "JAUC 3F9CEC70" 'jauc[[:space:]]+0x3f9cec70'
|
||||
expect_at _XCopyArea "$XCOPY" "JAUC 3FD3E220" 'jauc[[:space:]]+0x3fd3e220'
|
||||
expect_at _XFillRectangle "$XFILL" "JAUC 3F99E8F0" 'jauc[[:space:]]+0x3f99e8f0'
|
||||
expect_at _XSync "$XSYNC" "JAUC 3FD9F6B0" 'jauc[[:space:]]+0x3fd9f6b0'
|
||||
expect_at _XPending "$XPEND" "JAUC 3FD67620" 'jauc[[:space:]]+0x3fd67620'
|
||||
expect_at _XNextEvent "$XNEXT" "JAUC 3F9C1CF0" 'jauc[[:space:]]+0x3f9c1cf0'
|
||||
expect_at _XLookupString "$XLOOKUP" "JAUC 3F9A9C30" 'jauc[[:space:]]+0x3f9a9c30'
|
||||
expect_at _XFlush "$XFLUSH" "JAUC 3F9B1030" 'jauc[[:space:]]+0x3f9b1030'
|
||||
expect_at _XGetInputFocus "$XGETFOCUS" "JAUC 3FD55210" 'jauc[[:space:]]+0x3fd55210'
|
||||
expect_at _sleep "$XSLEEP" "JAUC 3FB33A20" 'jauc[[:space:]]+0x3fb33a20'
|
||||
expect_at _blit_copy "$XBLIT" "JAUC 3FB44400" 'jauc[[:space:]]+0x3fb44400'
|
||||
|
||||
echo "== check the compiled client calls (linked assembly keeps the names)"
|
||||
for sym in XOpenDisplay XCreateSimpleWindow XSelectInput XCreateGC XSetForeground \
|
||||
XCreatePixmap XCreateImage XSetErrorHandler XMapWindow XRaiseWindow \
|
||||
XSetInputFocus XPutImage XCopyArea XFillRectangle XSync XPending \
|
||||
XNextEvent XLookupString XFlush XGetInputFocus; do
|
||||
grep -q "CALLA _${sym}" "$ASM" || fail "linked assembly has no CALLA _$sym"
|
||||
done
|
||||
echo " ok direct CALLA imports: 20 Xlib entries"
|
||||
grep -Eq '^[[:space:]]*MOVI _on_error_[A-Za-z0-9_]+, A[0-9]+' "$ASM" \
|
||||
|| fail "no MOVI _on_error before XSetErrorHandler"
|
||||
echo " ok XSetErrorHandler callback pointer: MOVI _on_error…"
|
||||
grep -Eq '^[[:space:]]*CALL A[0-9]+' "$ASM" \
|
||||
|| fail "no indirect CALL (Task 3 CALL Rs) in the client"
|
||||
echo " ok indirect sleep call: CALL A?"
|
||||
grep -q 'CALLA _blit_copy' "$ASM" \
|
||||
|| fail "linked assembly has no CALLA _blit_copy (ROM copy entry)"
|
||||
echo " ok ROM blit_copy entry: CALLA _blit_copy (JAUC 3FB44400)"
|
||||
|
||||
# XCreateSimpleWindow argument order: push 0,0,0,480,640,20,20,root,display.
|
||||
LN=$(grep -n 'CALLA _XCreateSimpleWindow' "$ASM" | head -1 | cut -d: -f1)
|
||||
[ -n "$LN" ] || fail "linked assembly has no CALLA _XCreateSimpleWindow"
|
||||
sed -n "$((LN - 24)),$((LN))p" "$ASM" > "$TMP/create.block"
|
||||
awk '
|
||||
/^[[:space:]]*MOVI[[:space:]]/ {
|
||||
line=$0; sub(/.*MOVI[[:space:]]+/, "", line); sub(/[[:space:]]*;.*/, "", line);
|
||||
split(line, p, /,[[:space:]]*/); gsub(/[[:space:]]/, "", p[1]); gsub(/[[:space:]]/, "", p[2]);
|
||||
val[p[2]] = p[1]; next
|
||||
}
|
||||
/^[[:space:]]*MOVE[[:space:]]+A[0-9]+,[[:space:]]*\*A14\+,/ {
|
||||
line=$0; sub(/.*MOVE[[:space:]]+/, "", line); sub(/,.*/, "", line);
|
||||
v = val[line]; if (line == "A1") v = "root"; if (line == "A0") v = "display";
|
||||
print v
|
||||
}
|
||||
' "$TMP/create.block" > "$TMP/create.vals"
|
||||
printf '%s\n' 0 0 0 480 640 20 20 root display > "$TMP/create.want"
|
||||
if ! cmp -s "$TMP/create.want" "$TMP/create.vals"; then
|
||||
{
|
||||
echo "M4 dis34 round-trip: FAIL: XCreateSimpleWindow argument order"
|
||||
echo " expected (background,border,border_width,height,width,y,x,root,display):"
|
||||
sed 's/^/ /' "$TMP/create.want"
|
||||
echo " got:"
|
||||
sed 's/^/ /' "$TMP/create.vals"
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " ok XCreateSimpleWindow order: 0,0,0,480,640,20,20,root,display (display last)"
|
||||
|
||||
# Every call must be followed by the SETF 16/32 pair. The hand-written
|
||||
# _start trampoline (`calla _xshow` + rets) is not a compiler call and is
|
||||
# checked separately; the scan starts at _xshow: so lower-case call spellings
|
||||
# inside the compiler output are still matched.
|
||||
grep -Eq '^[[:space:]]*calla[[:space:]]+_xshow' "$ASM" \
|
||||
|| fail "entry.asm does not call _xshow"
|
||||
awk '
|
||||
{ low = tolower($0) }
|
||||
/^_xshow:/ { on = 1 }
|
||||
low ~ /^[[:space:]]*;/ { next }
|
||||
!on { next }
|
||||
expect == 1 {
|
||||
if ($0 ~ /SETF 16, 1, 0/) { expect = 2 }
|
||||
else { bad++; expect = 0 }
|
||||
next
|
||||
}
|
||||
expect == 2 {
|
||||
if ($0 ~ /SETF 32, 0, 1/) { ok++; expect = 0 }
|
||||
else { bad++; expect = 0 }
|
||||
next
|
||||
}
|
||||
low ~ /^[[:space:]]*(calla|call)[[:space:]]/ { calls++; expect = 1 }
|
||||
END { printf "%d %d %d\n", calls + 0, ok + 0, bad + 0 }
|
||||
' "$ASM" > "$TMP/setf.count"
|
||||
read CALLS SETF_OK SETF_BAD < "$TMP/setf.count"
|
||||
[ "$CALLS" -gt 0 ] || fail "linked assembly has no calls"
|
||||
[ "$SETF_BAD" -eq 0 ] || fail "$SETF_BAD calls lack the SETF 16/32 pair"
|
||||
[ "$SETF_OK" -eq "$CALLS" ] || fail "$CALLS calls but $SETF_OK post-call SETF 16/32 pairs"
|
||||
echo " ok $CALLS calls each followed by SETF 16,1,0 + SETF 32,0,1"
|
||||
|
||||
# Old-STK: on_error saves 3 registers; its epilogue restores A14 from
|
||||
# *SP((3+1)*32) = *SP(0x80). The prologue pushes A13, A0 and A1.
|
||||
awk '/^_on_error_/ { on=1 } on { print } on && /rets[[:space:]]+2/ { exit }' "$ASM" > "$TMP/onerr.s"
|
||||
grep -Eq 'MOVE \*SP\((0x80|128)\), A14, 1' "$TMP/onerr.s" \
|
||||
|| { sed 's/^/ /' "$TMP/onerr.s" >&2; fail "on_error does not restore A14 from *SP(0x80/128)"; }
|
||||
grep -Eq '^[[:space:]]*RETS 2' "$TMP/onerr.s" || fail "on_error has no RETS 2"
|
||||
echo " ok on_error: 3 pushes -> *SP(0x80),A14 and RETS 2"
|
||||
|
||||
# Task 3 CALL encoding in the GSPA listing.
|
||||
grep -Eq '^[[:space:]]*[0-9]+[[:space:]]+[0-9A-F]+[[:space:]]+0920[[:space:]]+CALL[[:space:]]+A[0-9]+' "$LST" \
|
||||
|| fail "GSPA listing has no 0x0920 CALL A?"
|
||||
echo " ok GSPA encoded the indirect call as 0x0920"
|
||||
|
||||
# dis34 must decode the indirect call as `call aN`.
|
||||
grep -Eq '^[0-9a-f]+:[[:space:]]+call[[:space:]]+a[0-9]+' "$TMP/dis34.txt" \
|
||||
|| fail "dis34 did not decode any CALL Rs as 'call aN'"
|
||||
echo " ok dis34 decodes CALL Rs as 'call aN'"
|
||||
|
||||
# The checker data lives in .bss: 480*80 bytes, built as 32-bit words.
|
||||
grep -Eq '\.bss[[:space:]]+_data_[A-Za-z0-9_]+,307200,32' "$ASM" \
|
||||
|| fail "linked assembly has no .bss _data…,307200,32 (480*80 bytes)"
|
||||
grep -Eq '^[[:space:]]*MOVI -1, A[0-9]+' "$ASM" \
|
||||
|| fail "checker fill loop has no MOVI -1 (all-ones cell)"
|
||||
grep -Eq '^[[:space:]]*NOT A[0-9]+' "$ASM" \
|
||||
|| fail "checker fill loop has no NOT (all-zero cell)"
|
||||
echo " ok checker .bss: 480*80 bytes, MOVI -1 / NOT cell fill"
|
||||
|
||||
# The client must actually set the XImage byte/bit order to LSBFirst. The
|
||||
# layout gate pins data=16 (0x80), byte_order=20 (0xA0) and
|
||||
# bitmap_bit_order=28 (0xE0); here the linked code stores zero at 0xA0/0xE0.
|
||||
grep -Eq 'ADDI 160, A[0-9]+' "$ASM" || fail "no XImage.byte_order (bit 0xA0) store"
|
||||
grep -Eq 'ADDI 224, A[0-9]+' "$ASM" || fail "no XImage.bitmap_bit_order (bit 0xE0) store"
|
||||
echo " ok XImage byte_order/bitmap_bit_order stores (LSBFirst at 0xA0/0xE0)"
|
||||
|
||||
echo "M4 dis34 round-trip: PASS"
|
||||
@@ -0,0 +1,17 @@
|
||||
; entry.asm -- M4 entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the compiled unsigned runtime test. Markers (0x20 bits apart):
|
||||
; 018A8000 le(5,7) == 1
|
||||
; 018A8020 ule(7,5) == 0 (unsigned <=)
|
||||
; 018A8040 sum_le(10) == 55
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _unsigned_test
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,43 @@
|
||||
-- fnptr-check.lua -- M4 function-pointer/indirect-call markers.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_END loader inspection/exit frame
|
||||
--
|
||||
-- Markers (0x20 bits apart):
|
||||
-- 018A8000 apply(inc, 41) == 42
|
||||
-- 018A8020 apply(vf, 41) == 42 (volatile local function pointer)
|
||||
-- 018A8040 apply(g_fn, 43) == 42 (global function pointer = dec)
|
||||
-- 018A8060 fnptr_test() == 42 (return value, stored by the entry)
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
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 m = {}
|
||||
for i = 0, 3 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format("M4: fnptr=%d fnptr_volatile=%d fnptr_global=%d fnptr_ret=%d",
|
||||
m[0], m[1], m[2], m[3]))
|
||||
local want = {42, 42, 42, 42}
|
||||
local ok = true
|
||||
for i = 0, 3 do
|
||||
if m[i] ~= want[i + 1] then
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
if ok then
|
||||
print("M4 MAME: PASS")
|
||||
else
|
||||
print("M4 MAME: FAIL (want fnptr=42 fnptr_volatile=42 fnptr_global=42 fnptr_ret=42)")
|
||||
end
|
||||
end
|
||||
end, "fnptr-check")
|
||||
@@ -0,0 +1,17 @@
|
||||
; fnptr-entry.asm -- M4 function-pointer/indirect-call test entry.
|
||||
;
|
||||
; Calls the function-pointer translation unit and stores its return value in
|
||||
; marker 3. Markers live at 0x018A8000 + n*0x20 (bit addresses).
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _fnptr_test
|
||||
movi 018A8060h, a0
|
||||
move a8, *a0, 1
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,29 @@
|
||||
/* fnptr.c -- M4 function-pointer/indirect-call runtime test.
|
||||
*
|
||||
* Markers live at 0x018A8000 + n*0x20 (bit addresses):
|
||||
* 0 apply(inc, 41) == 42 direct symbol passed as a pointer
|
||||
* 1 apply(vf, 41) == 42 volatile local function pointer
|
||||
* 2 apply(g_fn, 43) == 42 global function pointer holding dec
|
||||
* 3 fnptr_test() == 42 return value, stored by fnptr-entry.asm
|
||||
*
|
||||
* apply/inc/dec are noinline so -O2 cannot inline the helper and devirtualise
|
||||
* the callback into a direct call; the call inside apply is a real `call i32
|
||||
* %f` and lowers to CALL Rs.
|
||||
*/
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n) * 0x20u))
|
||||
|
||||
typedef int (*fn)(int);
|
||||
|
||||
__attribute__((noinline)) int inc(int x) { return x + 1; }
|
||||
__attribute__((noinline)) int dec(int x) { return x - 1; }
|
||||
__attribute__((noinline)) int apply(fn f, int x) { return f(x); }
|
||||
|
||||
static fn volatile g_fn = dec;
|
||||
|
||||
int fnptr_test(void) {
|
||||
volatile fn vf = inc;
|
||||
MARK(0) = (unsigned)apply(inc, 41);
|
||||
MARK(1) = (unsigned)apply(vf, 41);
|
||||
MARK(2) = (unsigned)apply(g_fn, 43);
|
||||
return apply(vf, 41);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Offset-only equivalent of scripts/m4/x11m4.h for the 1987 TI GSP C
|
||||
* compiler (GSPCC/GSPCG 2.01). The VT1200 C ABI packs struct members, so
|
||||
* these structs have the same byte layout as the target's x11m4.h. The
|
||||
* XImage function table is modelled as six 32-bit void* slots: only its
|
||||
* size and the offset of f are needed here, and that is layout-equivalent
|
||||
* to the target's six function pointers.
|
||||
*
|
||||
* The 1987 compiler's &-of-member is a bit address, so these functions
|
||||
* return the ROM's bit displacements directly.
|
||||
*/
|
||||
struct display {
|
||||
char pad[0x90];
|
||||
void *screens;
|
||||
};
|
||||
|
||||
struct screen {
|
||||
char pad[0x8];
|
||||
unsigned int root;
|
||||
};
|
||||
|
||||
struct ximage_funcs {
|
||||
void *create_image;
|
||||
void *destroy_image;
|
||||
void *get_pixel;
|
||||
void *put_pixel;
|
||||
void *sub_image;
|
||||
void *add_pixel;
|
||||
};
|
||||
|
||||
struct ximage {
|
||||
int width, height;
|
||||
int xoffset;
|
||||
int format;
|
||||
char *data;
|
||||
int byte_order;
|
||||
int bitmap_unit;
|
||||
int bitmap_bit_order;
|
||||
int bitmap_pad;
|
||||
int depth;
|
||||
int bytes_per_line;
|
||||
int bits_per_pixel;
|
||||
unsigned long red_mask, green_mask, blue_mask;
|
||||
void *obdata;
|
||||
struct ximage_funcs f;
|
||||
};
|
||||
|
||||
struct xerror {
|
||||
int type;
|
||||
void *display;
|
||||
unsigned long resourceid;
|
||||
unsigned long serial;
|
||||
unsigned char error_code;
|
||||
unsigned char request_code;
|
||||
unsigned char minor_code;
|
||||
unsigned char abi_pad;
|
||||
};
|
||||
|
||||
struct xkey {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
int send_event;
|
||||
void *display;
|
||||
unsigned long window;
|
||||
unsigned long root;
|
||||
unsigned long subwindow;
|
||||
unsigned long time;
|
||||
int x, y;
|
||||
int x_root, y_root;
|
||||
unsigned int state;
|
||||
unsigned int keycode;
|
||||
int same_screen;
|
||||
};
|
||||
|
||||
struct xexpose {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
int send_event;
|
||||
void *display;
|
||||
unsigned long window;
|
||||
int x, y;
|
||||
int width, height;
|
||||
int count;
|
||||
};
|
||||
|
||||
union xevent {
|
||||
int type;
|
||||
struct xkey xkey;
|
||||
struct xexpose xexpose;
|
||||
long pad[24];
|
||||
};
|
||||
|
||||
int layout_display_screens() { return (int)&((struct display *)0)->screens; }
|
||||
int layout_screen_root() { return (int)&((struct screen *)0)->root; }
|
||||
int layout_image_data() { return (int)&((struct ximage *)0)->data; }
|
||||
int layout_image_byte_order() { return (int)&((struct ximage *)0)->byte_order; }
|
||||
int layout_image_bytes_per_line() { return (int)&((struct ximage *)0)->bytes_per_line; }
|
||||
int layout_image_bits_per_pixel() { return (int)&((struct ximage *)0)->bits_per_pixel; }
|
||||
int layout_image_f() { return (int)&((struct ximage *)0)->f; }
|
||||
int layout_error_error_code() { return (int)&((struct xerror *)0)->error_code; }
|
||||
int layout_event_xkey_keycode() { return (int)&((struct xevent *)0)->xkey.keycode; }
|
||||
int layout_event_size() { return (int)sizeof(union xevent); }
|
||||
@@ -0,0 +1,114 @@
|
||||
*******************************************************
|
||||
* GSP C COMPILER, Version 2.01, 87.300 *
|
||||
*******************************************************
|
||||
FP .set A13
|
||||
STK .set A14
|
||||
.globl _layout_display_screens
|
||||
.file "LAYOUT.c"
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_display_screens
|
||||
******************************************************
|
||||
_layout_display_screens:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 1152,A7
|
||||
MOVE A7,A8
|
||||
EPI0_1:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_screen_root
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_screen_root
|
||||
******************************************************
|
||||
_layout_screen_root:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 64,A7
|
||||
MOVE A7,A8
|
||||
EPI0_2:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_image_data
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_image_data
|
||||
******************************************************
|
||||
_layout_image_data:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 128,A7
|
||||
MOVE A7,A8
|
||||
EPI0_3:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_image_byte_order
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_image_byte_order
|
||||
******************************************************
|
||||
_layout_image_byte_order:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 160,A7
|
||||
MOVE A7,A8
|
||||
EPI0_4:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_image_bytes_per_line
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_image_bytes_per_line
|
||||
******************************************************
|
||||
_layout_image_bytes_per_line:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 320,A7
|
||||
MOVE A7,A8
|
||||
EPI0_5:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_image_bits_per_pixel
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_image_bits_per_pixel
|
||||
******************************************************
|
||||
_layout_image_bits_per_pixel:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 352,A7
|
||||
MOVE A7,A8
|
||||
EPI0_6:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_image_f
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_image_f
|
||||
******************************************************
|
||||
_layout_image_f:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 512,A7
|
||||
MOVE A7,A8
|
||||
EPI0_7:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_error_error_code
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_error_error_code
|
||||
******************************************************
|
||||
_layout_error_error_code:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 128,A7
|
||||
MOVE A7,A8
|
||||
EPI0_8:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_event_xkey_keycode
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_event_xkey_keycode
|
||||
******************************************************
|
||||
_layout_event_xkey_keycode:
|
||||
MOVE A7,-*SP,1
|
||||
MOVI 416,A7
|
||||
MOVE A7,A8
|
||||
EPI0_9:
|
||||
MOVE *SP+,A7,1
|
||||
RETS 0
|
||||
.globl _layout_event_size
|
||||
******************************************************
|
||||
* FUNCTION DEF : _layout_event_size
|
||||
******************************************************
|
||||
_layout_event_size:
|
||||
MOVI 96,A8
|
||||
EPI0_10:
|
||||
RETS 0
|
||||
.end
|
||||
@@ -0,0 +1,120 @@
|
||||
#include "x11m4.h"
|
||||
|
||||
/*
|
||||
* Byte offsets are C offsets; the TMS34010 ROM's indirect displacements are
|
||||
* bit offsets, so every layout_* function below returns offset * 8. The one
|
||||
* exception is layout_event_size(), which reports sizeof(XEvent) in bytes
|
||||
* because the termtris buffer is sized in bytes (vt_u32 evbuf[24]).
|
||||
*/
|
||||
_Static_assert(sizeof(void *) == 4, "the VT1200 X11 ABI is 32-bit");
|
||||
_Static_assert(sizeof(long) == 4, "the VT1200 X11 ABI is 32-bit");
|
||||
_Static_assert(sizeof(XID) == 4, "XID must be 32-bit");
|
||||
_Static_assert(sizeof(Time) == 4, "Time must be 32-bit");
|
||||
|
||||
_Static_assert(__builtin_offsetof(Display, screens) == 0x90,
|
||||
"Display.screens must be at byte 0x90 (bit 0x480)");
|
||||
_Static_assert(__builtin_offsetof(Screen, root) == 0x8,
|
||||
"Screen.root must be at byte 0x8 (bit 0x40)");
|
||||
|
||||
/* 32-bit X11R4 XImage: data 16, byte_order 20, bytes_per_line 40. */
|
||||
_Static_assert(__builtin_offsetof(XImage, width) == 0, "XImage.width");
|
||||
_Static_assert(__builtin_offsetof(XImage, height) == 4, "XImage.height");
|
||||
_Static_assert(__builtin_offsetof(XImage, xoffset) == 8, "XImage.xoffset");
|
||||
_Static_assert(__builtin_offsetof(XImage, format) == 12, "XImage.format");
|
||||
_Static_assert(__builtin_offsetof(XImage, data) == 16,
|
||||
"XImage.data must be at byte 16 (bit 0x80)");
|
||||
_Static_assert(__builtin_offsetof(XImage, byte_order) == 20,
|
||||
"XImage.byte_order must be at byte 20 (bit 0xA0)");
|
||||
_Static_assert(__builtin_offsetof(XImage, bitmap_unit) == 24, "XImage.bitmap_unit");
|
||||
_Static_assert(__builtin_offsetof(XImage, bitmap_bit_order) == 28,
|
||||
"XImage.bitmap_bit_order");
|
||||
_Static_assert(__builtin_offsetof(XImage, bitmap_pad) == 32, "XImage.bitmap_pad");
|
||||
_Static_assert(__builtin_offsetof(XImage, depth) == 36, "XImage.depth");
|
||||
_Static_assert(__builtin_offsetof(XImage, bytes_per_line) == 40,
|
||||
"XImage.bytes_per_line must be at byte 40 (bit 0x140)");
|
||||
_Static_assert(__builtin_offsetof(XImage, bits_per_pixel) == 44,
|
||||
"XImage.bits_per_pixel must be at byte 44 (bit 0x160)");
|
||||
_Static_assert(__builtin_offsetof(XImage, red_mask) == 48, "XImage.red_mask");
|
||||
_Static_assert(__builtin_offsetof(XImage, green_mask) == 52, "XImage.green_mask");
|
||||
_Static_assert(__builtin_offsetof(XImage, blue_mask) == 56, "XImage.blue_mask");
|
||||
_Static_assert(__builtin_offsetof(XImage, obdata) == 60, "XImage.obdata");
|
||||
_Static_assert(__builtin_offsetof(XImage, f) == 64,
|
||||
"XImage.f must be at byte 64 (bit 0x200)");
|
||||
_Static_assert(__builtin_offsetof(struct funcs, destroy_image) == 4,
|
||||
"XImage.f.destroy_image must be 4 bytes into the inline funcs");
|
||||
_Static_assert(__builtin_offsetof(XImage, f.destroy_image) == 68,
|
||||
"XImage.f.destroy_image must be at byte 68 (bit 0x220)");
|
||||
_Static_assert(sizeof(struct funcs) == 24, "the X11R4 funcs tail is six pointers");
|
||||
_Static_assert(sizeof(XImage) == 88,
|
||||
"sizeof(XImage) must cover the ROM's full inline-funcs object");
|
||||
|
||||
/* 32-bit X11R4 XErrorEvent: error_code 16, request_code 17, minor_code 18. */
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, type) == 0, "XErrorEvent.type");
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, display) == 4, "XErrorEvent.display");
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, resourceid) == 8,
|
||||
"XErrorEvent.resourceid");
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, serial) == 12, "XErrorEvent.serial");
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, error_code) == 16,
|
||||
"XErrorEvent.error_code must be at byte 16 (bit 0x80)");
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, request_code) == 17,
|
||||
"XErrorEvent.request_code");
|
||||
_Static_assert(__builtin_offsetof(XErrorEvent, minor_code) == 18,
|
||||
"XErrorEvent.minor_code");
|
||||
/* The packed object would be 19 bytes; one X11R4 object-size compatibility
|
||||
* pad byte keeps the 32-bit object at 20. The client reads only the
|
||||
* handler-passed fields. */
|
||||
_Static_assert(sizeof(XErrorEvent) == 20, "sizeof(XErrorEvent) must be 20");
|
||||
|
||||
/* XEvent: type 0, xkey.window 16, xkey.keycode 52, xexpose.window 16, x 20. */
|
||||
_Static_assert(__builtin_offsetof(XEvent, type) == 0, "XEvent.type");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xkey.window) == 16, "XEvent.xkey.window");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xkey.keycode) == 52,
|
||||
"XEvent.xkey.keycode must be at byte 52 (bit 0x1A0)");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xexpose.window) == 16,
|
||||
"XEvent.xexpose.window");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xexpose.x) == 20, "XEvent.xexpose.x");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xfocus.window) == 16,
|
||||
"XEvent.xfocus.window");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xbutton.window) == 16,
|
||||
"XEvent.xbutton.window");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xconfigure.window) == 20,
|
||||
"XEvent.xconfigure.window");
|
||||
_Static_assert(__builtin_offsetof(XEvent, xclient.window) == 16,
|
||||
"XEvent.xclient.window");
|
||||
_Static_assert(sizeof(XEvent) >= 96,
|
||||
"XEvent must cover the termtris 96-byte vt_u32 evbuf[24]");
|
||||
_Static_assert(sizeof(XEvent) == 96, "the X11R4 XEvent union is 96 bytes");
|
||||
|
||||
int layout_display_screens(void) {
|
||||
return (int)__builtin_offsetof(Display, screens) * 8;
|
||||
}
|
||||
int layout_screen_root(void) {
|
||||
return (int)__builtin_offsetof(Screen, root) * 8;
|
||||
}
|
||||
int layout_image_data(void) {
|
||||
return (int)__builtin_offsetof(XImage, data) * 8;
|
||||
}
|
||||
int layout_image_byte_order(void) {
|
||||
return (int)__builtin_offsetof(XImage, byte_order) * 8;
|
||||
}
|
||||
int layout_image_bytes_per_line(void) {
|
||||
return (int)__builtin_offsetof(XImage, bytes_per_line) * 8;
|
||||
}
|
||||
int layout_image_bits_per_pixel(void) {
|
||||
return (int)__builtin_offsetof(XImage, bits_per_pixel) * 8;
|
||||
}
|
||||
int layout_image_f(void) {
|
||||
return (int)__builtin_offsetof(XImage, f) * 8;
|
||||
}
|
||||
int layout_error_error_code(void) {
|
||||
return (int)__builtin_offsetof(XErrorEvent, error_code) * 8;
|
||||
}
|
||||
int layout_event_xkey_keycode(void) {
|
||||
return (int)__builtin_offsetof(XEvent, xkey.keycode) * 8;
|
||||
}
|
||||
int layout_event_size(void) {
|
||||
return (int)sizeof(XEvent);
|
||||
}
|
||||
|
||||
/* Exercise the real access path: follows Display.screens and reads Screen.root. */
|
||||
unsigned int root_probe(Display *d) { return vt_root(d); }
|
||||
@@ -0,0 +1,16 @@
|
||||
-a
|
||||
-o M4.OUT
|
||||
-m M4.MAP
|
||||
-e _start
|
||||
M4.obj
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 8000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/* m4 loop.c -- an ordinary -O2 loop test. The driver wrapper disables
|
||||
* IndVarSimplify's exit-value replacement (-replexitval=never): this target has
|
||||
* no i64, and the closed form of sumto turns into an i33 multiply that llc
|
||||
* cannot select. The loops themselves must survive and run.
|
||||
*
|
||||
* Markers (0x20 bits apart, written by loop_test):
|
||||
* 018A8100 sumto(10) == 55
|
||||
* 018A8120 squares(5) == 30
|
||||
*/
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n)*0x20u))
|
||||
|
||||
int sumto(int n) {
|
||||
int s = 0, i;
|
||||
for (i = 1; i <= n; i++)
|
||||
s += i;
|
||||
return s;
|
||||
}
|
||||
|
||||
int squares(int n) {
|
||||
int s = 0, i;
|
||||
for (i = 0; i < n; i++)
|
||||
s += i * i;
|
||||
return s;
|
||||
}
|
||||
|
||||
int loop_test(void) {
|
||||
MARK(8) = (unsigned)sumto(10);
|
||||
MARK(9) = (unsigned)squares(5);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
-- m4-check.lua -- load the M4 COFF with dwt/loader/loader.lua and read the
|
||||
-- marker words written by unsigned.c.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_END loader inspection/exit frame
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
-- Markers (0x20 bits apart):
|
||||
-- 018A8000 le(5,7) == 1
|
||||
-- 018A8020 ule(7,5) == 0 (unsigned <=)
|
||||
-- 018A8040 sum_le(10) == 55
|
||||
-- 018A8060 ge(7,5) == 1 (signed >=)
|
||||
-- 018A8080 uge(5,7) == 0 (unsigned >=)
|
||||
-- 018A80A0 gt(5,7) == 0 (signed >)
|
||||
-- 018A80C0 ugt(7,5) == 1 (unsigned >)
|
||||
-- 018A80E0 ne(7,5) == 1
|
||||
-- 018A8100 lt(7,5) == 0 (signed <)
|
||||
-- 018A8120 ult(5,7) == 1 (unsigned <)
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
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 m = {}
|
||||
for i = 0, 9 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format(
|
||||
"M4: le=%d ule=%d sum_le=%d ge=%d uge=%d gt=%d ugt=%d ne=%d lt=%d ult=%d",
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9]))
|
||||
local want = {1, 0, 55, 1, 0, 0, 1, 1, 0, 1}
|
||||
local ok = true
|
||||
for i = 0, 9 do
|
||||
if m[i] ~= want[i + 1] then
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
if ok then
|
||||
print("M4 MAME: PASS")
|
||||
else
|
||||
print("M4 MAME: FAIL (want le=1 ule=0 sum_le=55 ge=1 uge=0 gt=0 ugt=1 ne=1 lt=0 ult=1)")
|
||||
end
|
||||
end
|
||||
end, "m4-check")
|
||||
@@ -0,0 +1,54 @@
|
||||
-- mul-check.lua -- M4 multiply/divide and -O2 loop markers.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_END loader inspection/exit frame
|
||||
--
|
||||
-- Markers (0x20 bits apart):
|
||||
-- 018A8000 mul(6,7) == 42
|
||||
-- 018A8020 umul16(0xffff,0xffff) == 0xfffe0001
|
||||
-- 018A8040 sdiv(100,7) == 14
|
||||
-- 018A8060 udiv(0xfffffffe,7) == 613566756
|
||||
-- 018A8080 srem(100,7) == 2
|
||||
-- 018A80A0 urem(100,7) == 2
|
||||
-- 018A80C0 sdiv(-100,7) == -14
|
||||
-- 018A80E0 srem(-100,7) == -2
|
||||
-- 018A8100 sumto(10) == 55
|
||||
-- 018A8120 squares(5) == 30
|
||||
-- 018A8140 mul(0x12345678,0x9abcdef0) == 0x242d2080
|
||||
-- 018A8160 urem(0xfffffffe,7) == 2
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
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 m = {}
|
||||
for i = 0, 11 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format(
|
||||
"M4: mul=%d umul16=%d sdiv=%d udiv=%d srem=%d urem=%d sdivneg=%d sremneg=%d sumto=%d squares=%d widemul=%d widerem=%d",
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9],
|
||||
m[10], m[11]))
|
||||
local want = {42, 0xfffe0001, 14, 613566756, 2, 2,
|
||||
0xfffffff2, 0xfffffffe, 55, 30, 0x242d2080, 2}
|
||||
local ok = true
|
||||
for i = 0, 11 do
|
||||
if m[i] ~= want[i + 1] then
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
if ok then
|
||||
print("M4 MAME: PASS")
|
||||
else
|
||||
print("M4 MAME: FAIL (want mul=42 umul16=4294836225 sdiv=14 udiv=613566756 srem=2 urem=2 sdivneg=-14 sremneg=-2 sumto=55 squares=30 widemul=606937216 widerem=2)")
|
||||
end
|
||||
end
|
||||
end, "mul-check")
|
||||
@@ -0,0 +1,16 @@
|
||||
; mul-entry.asm -- M4 multiply/divide and -O2 loop test entry.
|
||||
;
|
||||
; Calls the multiply/divide and loop translation units. Markers written by
|
||||
; mul.c and loop.c live at 0x018A8000 + n*0x20.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _mul_test
|
||||
calla _loop_test
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,49 @@
|
||||
/* m4 mul.c -- 32-bit multiply/divide marker test.
|
||||
*
|
||||
* Markers (0x20 bits apart, written by mul_test):
|
||||
* 018A8000 mul(6,7) == 42
|
||||
* 018A8020 umul16(0xffff,0xffff) == 0xfffe0001 (16x16 MPYU path)
|
||||
* 018A8040 sdiv(100,7) == 14
|
||||
* 018A8060 udiv(0xfffffffe,7) == 613566756
|
||||
* 018A8080 srem(100,7) == 2
|
||||
* 018A80A0 urem(100,7) == 2
|
||||
* 018A80C0 sdiv(-100,7) == -14
|
||||
* 018A80E0 srem(-100,7) == -2
|
||||
* 018A8140 mulu(0x12345678,0x9ABCDEF0) == 0x242D2080 (wide 32x32 product)
|
||||
* 018A8160 urem(0xfffffffe,7) == 2 (wide quotient in the remainder)
|
||||
*/
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n)*0x20u))
|
||||
|
||||
int mul(int a, int b) { return a * b; }
|
||||
|
||||
/* A full-width unsigned product. The 32x32 low bits are identical for signed
|
||||
* and unsigned values, so the target selects the same MPYS; using unsigned
|
||||
* operands keeps a wide marker from being signed-overflow UB. */
|
||||
unsigned mulu(unsigned a, unsigned b) { return a * b; }
|
||||
|
||||
/* A 16x16 unsigned product: both operands are masked to 16 bits, which is the
|
||||
* form the target selects to MPYU. The product must be computed in unsigned
|
||||
* arithmetic: 0xffff * 0xffff does not fit in signed int, so `int * int` would
|
||||
* be signed overflow and the optimizer could narrow or rename the result. */
|
||||
int umul16(int a, int b) {
|
||||
return (int)((unsigned)(a & 0xffff) * (unsigned)(b & 0xffff));
|
||||
}
|
||||
|
||||
int sdiv(int a, int b) { return a / b; }
|
||||
unsigned udiv(unsigned a, unsigned b) { return a / b; }
|
||||
int srem(int a, int b) { return a % b; }
|
||||
unsigned urem(unsigned a, unsigned b) { return a % b; }
|
||||
|
||||
int mul_test(void) {
|
||||
MARK(0) = (unsigned)mul(6, 7);
|
||||
MARK(1) = (unsigned)umul16(0xffff, 0xffff);
|
||||
MARK(2) = (unsigned)sdiv(100, 7);
|
||||
MARK(3) = udiv(0xfffffffeu, 7u);
|
||||
MARK(4) = (unsigned)srem(100, 7);
|
||||
MARK(5) = urem(100u, 7u);
|
||||
MARK(6) = (unsigned)sdiv(-100, 7);
|
||||
MARK(7) = (unsigned)srem(-100, 7);
|
||||
MARK(10) = mulu(0x12345678u, 0x9ABCDEF0u);
|
||||
MARK(11) = urem(0xfffffffeu, 7u);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
char *a(void) { return "same"; }
|
||||
@@ -0,0 +1 @@
|
||||
char *b(void) { return "same"; }
|
||||
@@ -0,0 +1,16 @@
|
||||
; private-entry.asm -- M4 two-TU private-symbol link test entry.
|
||||
;
|
||||
; Calls both translation units so the linker keeps their functions and the
|
||||
; string literals that those functions reference.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _a
|
||||
calla _b
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
Executable
+355
@@ -0,0 +1,355 @@
|
||||
#!/bin/sh
|
||||
# M4 end-to-end runner: compile translation units, assemble/link with the 1987
|
||||
# GSPA/GSPLNK toolchain under DOSBox, load the COFF in MAME, and evaluate the
|
||||
# marker Lua script.
|
||||
#
|
||||
# scripts/m4/run.sh
|
||||
#
|
||||
# The default is unsigned.c at -O0, linked with entry.asm and checked by
|
||||
# m4-check.lua. Other M4 tasks can reuse this runner:
|
||||
#
|
||||
# M4_SOURCES="foo bar" C basenames under scripts/m4 (default: unsigned)
|
||||
# M4_ENTRY=/path/entry.asm assembly entry file (default: scripts/m4/entry.asm)
|
||||
# M4_CHECK_LUA=/path.lua MAME marker script (default: scripts/m4/m4-check.lua)
|
||||
# M4_CLANG_OPT=-O2 tms-clang optimization level (default: -O0)
|
||||
# M4_LLC_OPT=-O0 llc optimization level (default: -O0)
|
||||
# M4_ROM_SYMBOLS=1 append the per-ROM import stubs from symbols
|
||||
# M4_EXTRA_ASM="/a.asm /b.asm" extra assembly to concatenate
|
||||
# M4_EXTRA_INCLUDES="-I dir" extra tms-clang include flags
|
||||
# M4_NATIVE=1 compile with llc -filetype=obj and link the
|
||||
# objects with GSPLNK (the default is GSPA text)
|
||||
# M4_NATIVE_RTS=1 add `-l rts.lib` to the native link
|
||||
# M4_NATIVE_PROG_LEN=8000h native program region length (bits)
|
||||
# M4_NATIVE_RAM_LEN=80000h native RAM region length (bits)
|
||||
# M4_LINK_CMD=/path/link.cmd asm-path GSPLNK command file (default link.cmd)
|
||||
# M4_SKIP_MAME=1 stop after a clean GSPA/GSPLNK link
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# SDK_IMG M4_WORK M4_COFF M4_SDK M4_SYMS LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
|
||||
WORK=${M4_WORK:-$ROOT/build/m4}
|
||||
COFF=${M4_COFF:-$WORK/m4.coff}
|
||||
SDK=${M4_SDK:-$ROOT/build/m4-sdk}
|
||||
ASM=$WORK/asm
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
SYMS=${M4_SYMS:-$ROOT/symbols/vt1200-v22.syms}
|
||||
|
||||
SOURCES=${M4_SOURCES:-unsigned}
|
||||
ENTRY=${M4_ENTRY:-$DIR/entry.asm}
|
||||
CHECK_LUA=${M4_CHECK_LUA:-$DIR/m4-check.lua}
|
||||
CLANG_OPT=${M4_CLANG_OPT:--O0}
|
||||
LLC_OPT=${M4_LLC_OPT:--O0}
|
||||
EXTRA_INCLUDES=${M4_EXTRA_INCLUDES:-}
|
||||
NATIVE=${M4_NATIVE:-0}
|
||||
NATIVE_RTS=${M4_NATIVE_RTS:-0}
|
||||
NATIVE_PROG_LEN=${M4_NATIVE_PROG_LEN:-8000h}
|
||||
NATIVE_RAM_LEN=${M4_NATIVE_RAM_LEN:-80000h}
|
||||
LINK_CMD=${M4_LINK_CMD:-$DIR/link.cmd}
|
||||
|
||||
fail() {
|
||||
echo "m4: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$ENTRY" ] || fail "missing entry: $ENTRY"
|
||||
|
||||
mkdir -p "$ASM" "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
||||
mkdir -p "$(dirname "$COFF")"
|
||||
|
||||
echo "== compile and select ($CLANG_OPT / llc $LLC_OPT)"
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
for name in $SOURCES; do
|
||||
case $name in
|
||||
*/*) src=$name ;;
|
||||
*) src=$DIR/$name.c ;;
|
||||
esac
|
||||
base=$(basename "$src" .c)
|
||||
[ -f "$src" ] || fail "missing source: $src"
|
||||
# shellcheck disable=SC2086
|
||||
"$ROOT/scripts/tms-clang" "$CLANG_OPT" $EXTRA_INCLUDES \
|
||||
-o "$ASM/$base.ll" "$src"
|
||||
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
||||
"$ASM/$base.ll" -o "$ASM/$base.s" \
|
||||
|| fail "llc -filetype=asm failed for $name"
|
||||
if [ "$NATIVE" = 1 ]; then
|
||||
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=obj \
|
||||
"$ASM/$base.ll" -o "$ASM/$base.o" \
|
||||
|| fail "llc -filetype=obj failed for $name"
|
||||
echo " $base.o: $(wc -c < "$ASM/$base.o") bytes"
|
||||
else
|
||||
echo " $base.s: $(grep -c . "$ASM/$base.s") lines"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "== extract the 1987 SDK"
|
||||
if [ ! -f "$SDK/GSPA.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "SDK image not found: $SDK_IMG"
|
||||
mkdir -p "$SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE not extracted into $SDK"
|
||||
|
||||
# .bss is placed at 0x01A00000 (link.cmd). The 640x480 1-bit image is
|
||||
# 38400 bytes; with the 4 KiB C stack and 1 KiB XG block it cannot fit the old
|
||||
# 32 KiB region at 0x018A9000. 0x01A00000 is the region the termtris loader
|
||||
# uses for its 125984-bit .bss (termtris.map 0x01A00000..0x01A1EC20), while the
|
||||
# X server's request buffer lives in low RAM (0x00988FD0..0x0098CFD0).
|
||||
echo "== assemble and link with GSPA/GSPLNK under DOSBox"
|
||||
# GSPA 2.00 has one flat symbol table per assembly, and llc names basic blocks
|
||||
# LBB0_1, LBB1_2, ... restarting in every translation unit. Give each TU its
|
||||
# own LBB prefix, as the M3 runner does, so a multi-TU client (xshow + xgfix)
|
||||
# cannot collide. The per-TU .s files keep their original labels.
|
||||
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
||||
"$ROOT/scripts/m2/gen-rom-imports.sh" "$SYMS" "$WORK/rom-imports.asm"
|
||||
fi
|
||||
|
||||
# A separately assembled entry must declare the symbols another object
|
||||
# defines; GSPA otherwise treats an undefined reference as an assembly error.
|
||||
# (In the asm path the definitions are in the same concatenated assembly.)
|
||||
entry_externs() {
|
||||
awk '
|
||||
{
|
||||
line = $0
|
||||
sub(/;.*/, "", line)
|
||||
if (line ~ /^[[:space:]]*\.(globl|ref|bss)[[:space:]]/) {
|
||||
n = split(line, a, /[[:space:],]+/)
|
||||
for (i = 1; i <= n; i++)
|
||||
if (a[i] ~ /^_[A-Za-z0-9_]+$/) known[a[i]] = 1
|
||||
}
|
||||
if (line ~ /^[[:space:]]*_[A-Za-z0-9_]+:/) {
|
||||
s = line
|
||||
sub(/^[[:space:]]*/, "", s)
|
||||
sub(/:.*/, "", s)
|
||||
known[s] = 1
|
||||
}
|
||||
n = split(line, a, /[^A-Za-z0-9_]+/)
|
||||
for (i = 1; i <= n; i++)
|
||||
if (a[i] ~ /^_[A-Za-z0-9_]+$/) ref[a[i]] = 1
|
||||
}
|
||||
END { for (s in ref) if (!known[s]) print s }
|
||||
' "$@" | sort
|
||||
}
|
||||
|
||||
strip_end() {
|
||||
sed '/^[[:space:]]*\.end[[:space:]]*$/d' "$1"
|
||||
}
|
||||
|
||||
EXTRAS=
|
||||
if [ -n "${M4_EXTRA_ASM:-}" ]; then
|
||||
for extra in $M4_EXTRA_ASM; do
|
||||
[ -f "$extra" ] || fail "missing extra assembly: $extra"
|
||||
EXTRAS="$EXTRAS $extra"
|
||||
done
|
||||
fi
|
||||
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
||||
EXTRAS="$EXTRAS $WORK/rom-imports.asm"
|
||||
fi
|
||||
|
||||
if [ "$NATIVE" = 1 ]; then
|
||||
# Assemble the entry and the extras (cinit, ROM import stubs) as their own
|
||||
# objects, with the extras last. That keeps the linked layout equal to the
|
||||
# default asm path (entry, C code, extras), so the dis34 stream comparison
|
||||
# sees the same function addresses.
|
||||
{
|
||||
entry_externs "$ENTRY" | sed 's/^/\t.globl\t/'
|
||||
strip_end "$ENTRY"
|
||||
printf '\t.end\n'
|
||||
} > "$SDK/M4.ASM"
|
||||
if [ -n "$EXTRAS" ]; then
|
||||
{
|
||||
# shellcheck disable=SC2086
|
||||
entry_externs $EXTRAS | sed 's/^/\t.globl\t/'
|
||||
for extra in $EXTRAS; do
|
||||
strip_end "$extra"
|
||||
done
|
||||
printf '\t.end\n'
|
||||
} > "$SDK/M4EXT.ASM"
|
||||
fi
|
||||
|
||||
NATIVE_OBJS="M4.OBJ"
|
||||
for name in $SOURCES; do
|
||||
case $name in
|
||||
*/*) src=$name ;;
|
||||
*) src=$DIR/$name.c ;;
|
||||
esac
|
||||
base=$(basename "$src" .c)
|
||||
dos=$(printf '%s' "$base" | tr '[:lower:]' '[:upper:]')
|
||||
[ "${#dos}" -le 8 ] \
|
||||
|| fail "native object name '$dos.OBJ' does not fit 8.3"
|
||||
cp "$ASM/$base.o" "$SDK/$dos.OBJ"
|
||||
NATIVE_OBJS="$NATIVE_OBJS $dos.OBJ"
|
||||
done
|
||||
if [ -n "$EXTRAS" ]; then
|
||||
NATIVE_OBJS="$NATIVE_OBJS M4EXT.OBJ"
|
||||
fi
|
||||
if [ "$NATIVE_RTS" = 1 ]; then
|
||||
[ -f "$SDK/RTS.LIB" ] || fail "RTS.LIB not extracted into $SDK"
|
||||
fi
|
||||
{
|
||||
printf '%s\n' '-a' '-o M4.OUT' '-m M4.MAP' '-e _start'
|
||||
printf '%s\n' "$NATIVE_OBJS"
|
||||
if [ "$NATIVE_RTS" = 1 ]; then
|
||||
printf '%s\n' '-l rts.lib'
|
||||
fi
|
||||
printf '%s\n' 'MEMORY' '{'
|
||||
printf ' prog: origin = 018A0000h, length = %s\n' "$NATIVE_PROG_LEN"
|
||||
printf ' ram: origin = 01A00000h, length = %s\n' "$NATIVE_RAM_LEN"
|
||||
printf '%s\n' '}'
|
||||
printf '%s\n' 'SECTIONS' '{'
|
||||
printf '%s\n' ' .text: {} > prog'
|
||||
printf '%s\n' ' .data: {} > prog'
|
||||
printf '%s\n' ' .cinit: {} > prog'
|
||||
printf '%s\n' ' .bss: {} > ram'
|
||||
printf '%s\n' '}'
|
||||
} > "$WORK/m4.cmd"
|
||||
sed 's/$/\r/' "$WORK/m4.cmd" > "$SDK/M4.CMD"
|
||||
else
|
||||
tag=0
|
||||
for name in $SOURCES; do
|
||||
case $name in
|
||||
*/*) src=$name ;;
|
||||
*) src=$DIR/$name.c ;;
|
||||
esac
|
||||
base=$(basename "$src" .c)
|
||||
tag=$((tag + 1))
|
||||
sed "s/LBB\([0-9][0-9]*_[0-9][0-9]*\)/LBB$tag\1/g" \
|
||||
"$ASM/$base.s" > "$ASM/$base.unique.s"
|
||||
done
|
||||
cat "$ENTRY" > "$SDK/M4.ASM"
|
||||
for name in $SOURCES; do
|
||||
case $name in
|
||||
*/*) src=$name ;;
|
||||
*) src=$DIR/$name.c ;;
|
||||
esac
|
||||
base=$(basename "$src" .c)
|
||||
cat "$ASM/$base.unique.s" >> "$SDK/M4.ASM"
|
||||
done
|
||||
if [ -n "${M4_EXTRA_ASM:-}" ]; then
|
||||
for extra in $M4_EXTRA_ASM; do
|
||||
cat "$extra" >> "$SDK/M4.ASM"
|
||||
done
|
||||
fi
|
||||
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
||||
cat "$WORK/rom-imports.asm" >> "$SDK/M4.ASM"
|
||||
fi
|
||||
# The linker command file must keep CRLF line endings.
|
||||
sed 's/\r$//' "$LINK_CMD" | sed 's/$/\r/' > "$SDK/M4.CMD"
|
||||
fi
|
||||
rm -f "$SDK/M4.OBJ" "$SDK/M4.OUT" "$SDK/M4.MAP" "$SDK/M4.LST"
|
||||
rm -f "$SDK/M4EXT.OBJ" "$SDK/M4EXT.LST"
|
||||
|
||||
run_dosbox() {
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf "$@" > "$WORK/dosbox.log" 2>&1
|
||||
}
|
||||
|
||||
if [ "$NATIVE" = 1 ] && [ -n "$EXTRAS" ]; then
|
||||
run_dosbox \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M4 M4.obj M4.lst -l" \
|
||||
-c "gspa M4EXT M4EXT.obj M4EXT.lst -l" \
|
||||
-c "gsplnk M4.cmd" \
|
||||
-c "exit" -exit \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
else
|
||||
run_dosbox \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M4 M4.obj M4.lst -l" \
|
||||
-c "gsplnk M4.cmd" \
|
||||
-c "exit" -exit \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
fi
|
||||
|
||||
check_lst() {
|
||||
lst=$1
|
||||
[ -f "$SDK/$lst.LST" ] \
|
||||
|| fail "GSPA produced no $lst.LST (see $WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$SDK/$lst.LST" > "$WORK/$lst.lst"
|
||||
grep -q 'No Errors' "$WORK/$lst.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/$lst.lst" >&2 || true; \
|
||||
fail "GSPA reported errors in $lst"; }
|
||||
grep -q 'No Warnings' "$WORK/$lst.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$WORK/$lst.lst" >&2 || true; \
|
||||
fail "GSPA reported warnings in $lst"; }
|
||||
}
|
||||
|
||||
check_lst M4
|
||||
[ -z "$EXTRAS" ] || [ "$NATIVE" != 1 ] || check_lst M4EXT
|
||||
[ -f "$SDK/M4.OUT" ] || fail "GSPLNK produced no M4.OUT"
|
||||
sed 's/\r$//' "$SDK/M4.MAP" > "$WORK/m4.map"
|
||||
cp "$SDK/M4.OUT" "$COFF"
|
||||
cp "$SDK/M4.ASM" "$WORK/m4.asm"
|
||||
[ ! -f "$SDK/M4EXT.ASM" ] || cp "$SDK/M4EXT.ASM" "$WORK/m4ext.asm"
|
||||
|
||||
ENTRY_ADDR=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m4.map")
|
||||
[ "$ENTRY_ADDR" = "018A0000" ] || fail "linker entry _start is '$ENTRY_ADDR', want 018A0000"
|
||||
grep -q 'ENTRY POINT SYMBOL: "_start"' "$WORK/m4.map" \
|
||||
|| fail "linker map has no _start entry point"
|
||||
echo " linked .text at 018A0000, M4.OUT -> $COFF"
|
||||
|
||||
if [ -n "${M4_SKIP_MAME:-}" ]; then
|
||||
echo "M4 LINK: PASS"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "== run the COFF in MAME"
|
||||
[ -x "$MAME" ] || fail "MAME binary not built: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "COFF loader missing: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "COFF loader payload missing: $LOADER_BIN"
|
||||
[ -f "$CHECK_LUA" ] || fail "marker Lua missing: $CHECK_LUA"
|
||||
|
||||
rm -rf "$WORK/run/nvram"
|
||||
mkdir -p "$WORK/run/nvram"
|
||||
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$COFF" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
timeout "${MAME_TIMEOUT:-900}" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$CHECK_LUA" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
MARKERS=$(grep -E '^M4: ' "$WORK/mame.log" | tail -1 || true)
|
||||
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; fail "MAME produced no M4 markers"; }
|
||||
echo " $MARKERS"
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; fail "COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -q '^M4 MAME: PASS' "$WORK/mame.log" \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "M4 marker check failed"; }
|
||||
|
||||
echo "M4 MAME: PASS"
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* switch.c -- a dense char switch, used by tests/m4/termtris.sh to pin the
|
||||
* driver's late-GEP policy.
|
||||
*
|
||||
* The optimizer's switch-to-lookup-table transform creates a new i8 GEP after
|
||||
* tms-bitaddr --scale; --normalize cannot tell that index apart from an
|
||||
* already-scaled bit offset, so the table would be indexed one bit per slot.
|
||||
* tms-clang passes -switch-to-lookup=false; this source makes the hazard
|
||||
* reachable at -O2 (termtris' init_game and runesc switches are the real
|
||||
* cases).
|
||||
*/
|
||||
int sw_tile(int c)
|
||||
{
|
||||
switch(c) {
|
||||
case '#': return 2;
|
||||
case '.': return 1;
|
||||
case '{': return 11;
|
||||
case '}': return 12;
|
||||
case '[': return 13;
|
||||
case ']': return 14;
|
||||
case '>': return 15;
|
||||
case '<': return 16;
|
||||
case '-': return 17;
|
||||
case '(': return 18;
|
||||
case ')': return 19;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int sw_sum(const char *s)
|
||||
{
|
||||
int r = 0;
|
||||
while(*s) {
|
||||
r += sw_tile(*s++);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
Executable
+226
@@ -0,0 +1,226 @@
|
||||
#!/bin/sh
|
||||
# build.sh -- build the pinned termtris COFF with this compiler (tms-clang +
|
||||
# llc), then assemble/link with the TI GSPA/GSPLNK toolchain.
|
||||
#
|
||||
# scripts/m4/termtris/build.sh
|
||||
#
|
||||
# Inputs: the test-only pinned checkout vendor/vt1200-termtris (branch
|
||||
# `termtris`, commit be5b323...). Output: build/m4-termtris/termtris.coff and
|
||||
# termtris.map, plus the generated TERMTRIS.ASM/LST for the dis34-style checks.
|
||||
#
|
||||
# Overridable: VT1200_TERMTRIS TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC
|
||||
# TERMTRIS_WORK TERMTRIS_SDK DOSBOX DOSBOX_CONF SDK_IMG
|
||||
# TERMTRIS_CC_OPT TERMTRIS_LLC_OPT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4/termtris
|
||||
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
||||
SRC=$VENDOR/apps/termtris/src
|
||||
ENTRY_SRC=$SRC/vt1200
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
|
||||
WORK=${TERMTRIS_WORK:-$ROOT/build/m4-termtris}
|
||||
SDK=${TERMTRIS_SDK:-$ROOT/build/m4-termtris-sdk}
|
||||
ASM=$WORK/asm
|
||||
CC_OPT=${TERMTRIS_CC_OPT:--O2}
|
||||
LLC_OPT=${TERMTRIS_LLC_OPT:--O0}
|
||||
|
||||
SOURCES="main game scoredb x11 compat xgfix"
|
||||
|
||||
fail() {
|
||||
echo "termtris build: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -d "$SRC" ] || fail "missing pinned termtris source: $SRC"
|
||||
|
||||
# The pinned commit matters: a newer branch may have moved the DIAG markers or
|
||||
# changed the game loop. Fail loudly rather than silently test another tree.
|
||||
if git -C "$VENDOR" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
rev=$(git -C "$VENDOR" rev-parse HEAD)
|
||||
[ "$rev" = "be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf" ] \
|
||||
|| fail "vendor tree is $rev, want the pinned be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf"
|
||||
fi
|
||||
|
||||
mkdir -p "$ASM" "$WORK"
|
||||
|
||||
echo "== compile the pinned sources with this compiler ($CC_OPT) and llc ($LLC_OPT)"
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
# -I order: quoted game headers, then the vt1200 shims (stdio.h/inttypes.h),
|
||||
# then the small local shims for stdlib/string/time. tms-clang passes
|
||||
# -nostdinc, so every angle-bracket header must resolve here.
|
||||
INCLUDES="-I $SRC -I $SRC/vt1200 -I $DIR/include"
|
||||
for name in $SOURCES; do
|
||||
case $name in
|
||||
game) src=$SRC/game.c ;;
|
||||
main|x11|compat|xgfix) src=$SRC/vt1200/$name.c ;;
|
||||
scoredb) src=$SRC/vt1200/scoredb.c ;;
|
||||
*) fail "unknown source $name" ;;
|
||||
esac
|
||||
[ -f "$src" ] || fail "missing source: $src"
|
||||
# shellcheck disable=SC2086
|
||||
"$ROOT/scripts/tms-clang" "$CC_OPT" $INCLUDES -o "$ASM/$name.ll" "$src" \
|
||||
|| fail "tms-clang failed for $src"
|
||||
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
||||
"$ASM/$name.ll" -o "$ASM/$name.s" \
|
||||
|| fail "llc failed for $src"
|
||||
echo " $name.s: $(grep -c . "$ASM/$name.s") lines"
|
||||
done
|
||||
|
||||
echo "== extract the TI 1987 SDK"
|
||||
if [ ! -f "$SDK/GSPA.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "SDK image not found: $SDK_IMG"
|
||||
mkdir -p "$SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE not extracted into $SDK"
|
||||
[ -f "$SDK/RTS.LIB" ] || fail "RTS.LIB not extracted into $SDK"
|
||||
|
||||
# GSPA has one flat symbol table per assembly, and llc restarts LBB0_1 in every
|
||||
# translation unit. Give each TU its own LBB prefix (the M4 run.sh pattern).
|
||||
tag=0
|
||||
for name in $SOURCES; do
|
||||
tag=$((tag + 1))
|
||||
sed "s/LBB\([0-9][0-9]*_[0-9][0-9]*\)/LBB$tag\1/g" \
|
||||
"$ASM/$name.s" > "$ASM/$name.unique.s"
|
||||
done
|
||||
|
||||
# The body (entry, code, libc) without the .cinit member: the linker takes the
|
||||
# empty CINIT.asm first, and the caller relinks with CINITZ.asm when the map
|
||||
# says .cinit is empty.
|
||||
# The vendored entry/cinit files end with `.end`, which stops GSPA at that
|
||||
# point when the pieces are concatenated into one assembly (the vendored
|
||||
# build assembles each file separately). Drop the terminator; GSPA's own
|
||||
# `.end` is appended by the cinit member.
|
||||
strip_end() {
|
||||
sed '/^[[:space:]]*\.end[[:space:]]*$/d' "$1"
|
||||
}
|
||||
: > "$WORK/code.asm"
|
||||
strip_end "$ENTRY_SRC/entry.asm" >> "$WORK/code.asm"
|
||||
for name in $SOURCES; do
|
||||
cat "$ASM/$name.unique.s" >> "$WORK/code.asm"
|
||||
done
|
||||
|
||||
# GSPA needs an explicit `.globl` declaration for a symbol the linker will
|
||||
# resolve from another object (rts.lib); llc prints the call/reference but no
|
||||
# declaration. Collect the CALLA/MOVI references and declare the ones this
|
||||
# assembly does not define itself.
|
||||
sed -n \
|
||||
-e 's/.*CALLA[[:space:]]*\(_[A-Za-z0-9_][A-Za-z0-9_]*\).*/\1/p' \
|
||||
-e 's/.*MOVI[[:space:]]*\(_[A-Za-z0-9_][A-Za-z0-9_]*\).*/\1/p' \
|
||||
"$WORK/code.asm" | sort -u > "$WORK/refs.txt"
|
||||
sed -n 's/^\(_[A-Za-z0-9_][A-Za-z0-9_]*\):.*/\1/p' "$WORK/code.asm" \
|
||||
| sort -u > "$WORK/defs.txt"
|
||||
: > "$WORK/externs.asm"
|
||||
while read -r sym; do
|
||||
[ -n "$sym" ] || continue
|
||||
grep -qxF "$sym" "$WORK/defs.txt" || printf '\t.globl\t%s\n' "$sym" >> "$WORK/externs.asm"
|
||||
done < "$WORK/refs.txt"
|
||||
: > "$WORK/body.asm"
|
||||
cat "$WORK/externs.asm" "$WORK/code.asm" > "$WORK/body.asm"
|
||||
strip_end "$ENTRY_SRC/cinit.asm" > "$WORK/cinit.asm"
|
||||
strip_end "$ENTRY_SRC/cinitz.asm" > "$WORK/cinitz.asm"
|
||||
|
||||
# The link command file must keep CRLF line endings for the DOS tool.
|
||||
write_cmd() {
|
||||
{
|
||||
printf '%s\n' '-a'
|
||||
printf '%s\n' '-o TERMTRIS.OUT'
|
||||
printf '%s\n' '-m TERMTRIS.MAP'
|
||||
printf '%s\n' '-e _start'
|
||||
printf '%s\n' 'TERMTRIS.obj'
|
||||
printf '%s\n' '-l rts.lib'
|
||||
printf '%s\n' 'MEMORY'
|
||||
printf '%s\n' '{'
|
||||
# The vintage r5.01 build's text+data is 10.6+0.6 KiB and fits the
|
||||
# 20000h-bit program region. This compiler's -O2/llc -O0 output is
|
||||
# about twice as large (see the report), so the program region is
|
||||
# widened to 40000h bits (32 KiB). It ends at 018E0000, below the
|
||||
# loader's COFF buffer at 01900000 and the .bss region at 01A00000.
|
||||
printf '%s\n' ' prog: origin = 018A0000h, length = 40000h'
|
||||
printf '%s\n' ' ram: origin = 01A00000h, length = 40000h'
|
||||
printf '%s\n' '}'
|
||||
printf '%s\n' 'SECTIONS'
|
||||
printf '%s\n' '{'
|
||||
printf '%s\n' ' .text: {} > prog'
|
||||
printf '%s\n' ' .data: {} > prog'
|
||||
printf '%s\n' ' .cinit: {} > prog'
|
||||
printf '%s\n' ' .bss: {} > ram'
|
||||
printf '%s\n' '}'
|
||||
} > "$WORK/termtris.cmd"
|
||||
sed 's/$/\r/' "$WORK/termtris.cmd" > "$SDK/TERMTRIS.CMD"
|
||||
}
|
||||
|
||||
assemble_link() {
|
||||
cinit=$1
|
||||
cat "$WORK/body.asm" "$WORK/$cinit" > "$SDK/TERMTRIS.ASM"
|
||||
rm -f "$SDK/TERMTRIS.OBJ" "$SDK/TERMTRIS.LST" \
|
||||
"$SDK/TERMTRIS.OUT" "$SDK/TERMTRIS.MAP"
|
||||
write_cmd
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa TERMTRIS TERMTRIS.obj TERMTRIS.lst -l" \
|
||||
-c "gsplnk TERMTRIS.cmd" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/dosbox.log" >&2; fail "DOSBox failed ($cinit)"; }
|
||||
|
||||
[ -f "$SDK/TERMTRIS.LST" ] || fail "GSPA produced no listing (see $WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$SDK/TERMTRIS.LST" > "$WORK/termtris.lst"
|
||||
grep -q 'No Errors' "$WORK/termtris.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/termtris.lst" >&2 || true; \
|
||||
fail "GSPA reported an error"; }
|
||||
# GSPA's symbol table caps names at 31 characters. llc's path-hashed
|
||||
# static/switch-table names can exceed that; the truncation is consistent
|
||||
# between definition and reference and the map below is checked for
|
||||
# duplicates. Any other warning is fatal.
|
||||
nwarn=$(grep -c 'WARNING' "$WORK/termtris.lst" || true)
|
||||
ntrunc=$(grep -c 'WARNING - SYMBOL TRUNCATED' "$WORK/termtris.lst" || true)
|
||||
if [ "$nwarn" -ne "$ntrunc" ]; then
|
||||
grep -i -B2 -A2 'warning' "$WORK/termtris.lst" >&2 || true
|
||||
fail "GSPA reported a non-truncation warning"
|
||||
fi
|
||||
[ "$nwarn" -eq 0 ] || echo " GSPA: $nwarn long symbol name(s) truncated to 31 chars"
|
||||
[ -f "$SDK/TERMTRIS.OUT" ] || fail "GSPLNK produced no TERMTRIS.OUT"
|
||||
sed 's/\r$//' "$SDK/TERMTRIS.MAP" > "$WORK/termtris.map"
|
||||
}
|
||||
|
||||
echo "== assemble and link with GSPA/GSPLNK under DOSBox"
|
||||
assemble_link cinit.asm
|
||||
CSIZE=$(awk '$1 == ".cinit" {print $4; exit}' "$WORK/termtris.map")
|
||||
if [ "$CSIZE" = "00000000" ]; then
|
||||
# An empty .cinit makes the linker point `cinit` at .text; the entry's
|
||||
# walker would read an instruction as a record count. Relink with the
|
||||
# one-word terminator, exactly as the vendored build.sh does.
|
||||
echo " .cinit is empty; relinking with the CINITZ terminator"
|
||||
assemble_link cinitz.asm
|
||||
fi
|
||||
|
||||
ENTRY_ADDR=$(awk '$2 == "_start" { print $1; exit }' "$WORK/termtris.map")
|
||||
[ -n "$ENTRY_ADDR" ] || fail "link map has no _start"
|
||||
[ "$ENTRY_ADDR" = "018a0000" ] || [ "$ENTRY_ADDR" = "018A0000" ] \
|
||||
|| fail "linker _start is '$ENTRY_ADDR', want 018a0000"
|
||||
|
||||
cp "$SDK/TERMTRIS.OUT" "$WORK/termtris.coff"
|
||||
cp "$SDK/TERMTRIS.ASM" "$WORK/termtris.asm"
|
||||
|
||||
echo " linked .text at $ENTRY_ADDR, TERMTRIS.OUT -> $WORK/termtris.coff"
|
||||
awk '/^\.text|^\.data|^\.cinit|^\.bss/ || /_dbg_loops|_dbg_events|_dbg_last|_dbg_focus|_dbg_rev|_quit|_tick_interval/ {print}' \
|
||||
"$WORK/termtris.map" | sed -n '1,40p'
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* stdlib.h -- the subset of <stdlib.h> termtris' game.c uses, for the
|
||||
* freestanding tms-clang build. The implementations come from the TI 1987
|
||||
* RTS.LIB (rand/srand); there is no heap allocator in the game.
|
||||
*/
|
||||
#ifndef VT_TERMTRIS_STDLIB_H_
|
||||
#define VT_TERMTRIS_STDLIB_H_
|
||||
|
||||
int rand(void);
|
||||
void srand(unsigned seed);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* string.h -- the subset of <string.h> termtris uses, for the freestanding
|
||||
* tms-clang build. The implementations come from the TI 1987 RTS.LIB.
|
||||
*/
|
||||
#ifndef VT_TERMTRIS_STRING_H_
|
||||
#define VT_TERMTRIS_STRING_H_
|
||||
|
||||
void *memcpy(void *dst, const void *src, unsigned n);
|
||||
void *memset(void *dst, int c, unsigned n);
|
||||
unsigned strlen(const char *s);
|
||||
char *strcpy(char *dst, const char *src);
|
||||
char *strncpy(char *dst, const char *src, unsigned n);
|
||||
int strcmp(const char *a, const char *b);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* time.h -- game.c includes <time.h>, but the VT1200 port replaces time(0)
|
||||
* with the ROM's free-running tick (vt_rand_seed); no time function is used.
|
||||
*/
|
||||
#ifndef VT_TERMTRIS_TIME_H_
|
||||
#define VT_TERMTRIS_TIME_H_
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,393 @@
|
||||
-- play_keys.lua -- M4 termtris acceptance harness (adapted from the pinned
|
||||
-- apps/termtris/tests/play_keys.lua).
|
||||
--
|
||||
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
|
||||
-- the OS, then at frame LOADER_AT pokes:
|
||||
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
|
||||
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
|
||||
-- * the loader descriptor at 0x01882C00
|
||||
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
|
||||
-- or any firmware transport: this is the debugger-assisted milestone.
|
||||
--
|
||||
-- The loader itself copies the COFF sections to their linked bit addresses and
|
||||
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
|
||||
-- the input and reads the result; it never writes the app's code or markers.
|
||||
--
|
||||
-- Env:
|
||||
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
|
||||
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
|
||||
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
|
||||
-- LOADER_AT injection frame (default 2500)
|
||||
-- LOADER_END inspection/exit frame (default 2700)
|
||||
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
|
||||
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
|
||||
-- LOADER_VERBOSE 1 = print the result block every 25 frames
|
||||
|
||||
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
|
||||
|
||||
local machine = manager.machine
|
||||
local PLAY_MODE = os.getenv("PLAY_MODE") or "move"
|
||||
print("PLAYKEYS: mode="..PLAY_MODE)
|
||||
local DL = tonumber(os.getenv("DIAG_LOOPS") or "0")
|
||||
local DE = tonumber(os.getenv("DIAG_EVENTS") or "0")
|
||||
local DT = tonumber(os.getenv("DIAG_LAST") or "0")
|
||||
local DF = tonumber(os.getenv("DIAG_FOCUS") or "0")
|
||||
local DR = tonumber(os.getenv("DIAG_REV") or "0")
|
||||
local DQ = tonumber(os.getenv("DIAG_QUIT") or "0")
|
||||
local DTICK = tonumber(os.getenv("DIAG_TICK") or "0")
|
||||
local DW = tonumber(os.getenv("DIAG_WIN") or "0")
|
||||
|
||||
local ports = machine.ioport.ports
|
||||
local key_a = ports[":lk401:K26"].fields["A"]
|
||||
local key_d = ports[":lk401:K28"].fields["D"]
|
||||
local key_s = ports[":lk401:K27"].fields["S"]
|
||||
local key_w = ports[":lk401:K14"].fields["W"]
|
||||
local key_0 = ports[":lk401:K10"].fields["0 )"]
|
||||
local key_p = ports[":lk401:K22"].fields["P"]
|
||||
local key_r = ports[":lk401:K16"].fields["R"]
|
||||
local key_h = ports[":lk401:K31"].fields["H"]
|
||||
local key_q = ports[":lk401:K13"].fields["Q"]
|
||||
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
|
||||
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
|
||||
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
|
||||
local cpu = machine.devices[':maincpu']
|
||||
local dbg = machine.debugger
|
||||
local prog = cpu.spaces['program']
|
||||
|
||||
if not dbg then
|
||||
print("LOADER: debugger not enabled; pass -debug")
|
||||
machine:exit()
|
||||
return
|
||||
end
|
||||
|
||||
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
|
||||
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
|
||||
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
|
||||
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
|
||||
local SNAP = os.getenv("LOADER_SNAP") == "1"
|
||||
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
|
||||
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
|
||||
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
|
||||
|
||||
local LOADER_BASE = 0x01880000
|
||||
local DESC = 0x01882C00
|
||||
local RESULT = 0x01882D00
|
||||
local RETURN_STUB = 0x01883100
|
||||
local RETURN_SP = 0x01883110
|
||||
|
||||
local function rd(p) return io.open(p, "rb") end
|
||||
local function slurp(p)
|
||||
local f, err = rd(p)
|
||||
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local function u16(s, o)
|
||||
return s:byte(o + 1) + s:byte(o + 2) * 256
|
||||
end
|
||||
|
||||
local function u32(s, o)
|
||||
return s:byte(o + 1) + s:byte(o + 2) * 256
|
||||
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
|
||||
end
|
||||
|
||||
local function parse_coff(d)
|
||||
local c = { data = d }
|
||||
c.magic = u16(d, 0)
|
||||
c.nscns = u16(d, 2)
|
||||
c.opthdr = u16(d, 16)
|
||||
c.sections = {}
|
||||
if c.opthdr > 0 then
|
||||
c.optmagic = u16(d, 20)
|
||||
c.entry = u32(d, 20 + 16)
|
||||
c.textstart = u32(d, 20 + 20)
|
||||
c.datastart = u32(d, 20 + 24)
|
||||
end
|
||||
local base = 20 + c.opthdr
|
||||
for i = 0, c.nscns - 1 do
|
||||
local o = base + i * 40
|
||||
local name = d:sub(o + 1, o + 8):gsub("%z", "")
|
||||
c.sections[#c.sections + 1] = {
|
||||
name = name,
|
||||
paddr = u32(d, o + 8),
|
||||
size = u32(d, o + 16), -- bits
|
||||
scnptr = u32(d, o + 20),
|
||||
flags = u32(d, o + 36),
|
||||
}
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local function poke_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local function verify_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
local bad = 0
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
return n, bad
|
||||
end
|
||||
|
||||
local function w32(a, v) prog:write_u32(a, v) end
|
||||
local function r32(a)
|
||||
local ok, v = pcall(function() return prog:read_u32(a) end)
|
||||
if ok then return v end
|
||||
return 0xDEADBEEF
|
||||
end
|
||||
|
||||
local loader = slurp(BIN)
|
||||
local coff = slurp(COFF)
|
||||
local app = parse_coff(coff)
|
||||
|
||||
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
|
||||
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
|
||||
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
|
||||
app.magic, app.nscns, app.opthdr,
|
||||
app.optmagic and string.format("%04X", app.optmagic) or "none",
|
||||
hex(app.entry or 0), hex(app.textstart or 0)))
|
||||
for _, s in ipairs(app.sections) do
|
||||
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
|
||||
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
|
||||
end
|
||||
|
||||
local TRACE = os.getenv("LOADER_TRACE") == "1"
|
||||
|
||||
local frames = 0
|
||||
local injected = false
|
||||
local done = false
|
||||
local last_count = -1
|
||||
|
||||
local function status_name(v)
|
||||
local t = {
|
||||
[0] = "OK",
|
||||
[1] = "bad descriptor",
|
||||
[2] = "truncated COFF / section headers",
|
||||
[3] = "bad COFF magic",
|
||||
[4] = "section size not whole words",
|
||||
[5] = "target outside RAM",
|
||||
[6] = "target overlaps loader page or COFF buffer",
|
||||
[7] = "relocation records present (unsupported)",
|
||||
[8] = "target not in a free-list block",
|
||||
[9] = "no entry point",
|
||||
}
|
||||
return t[v] or ("error " .. tostring(v))
|
||||
end
|
||||
|
||||
local function result_dump()
|
||||
local st = r32(RESULT + 0x000)
|
||||
print(string.format(
|
||||
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
|
||||
st, status_name(st), hex(r32(RESULT + 0x020)),
|
||||
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
|
||||
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
|
||||
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
|
||||
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
|
||||
r32(RESULT + 0x140), r32(RESULT + 0x160)))
|
||||
end
|
||||
|
||||
local function inject()
|
||||
-- 1. loader itself
|
||||
local n, bad = 0, 0
|
||||
poke_bytes(LOADER_BASE, loader)
|
||||
n, bad = verify_bytes(LOADER_BASE, loader)
|
||||
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
|
||||
n, bad, hex(LOADER_BASE)))
|
||||
|
||||
-- 2. COFF image
|
||||
poke_bytes(BUF, coff)
|
||||
n, bad = verify_bytes(BUF, coff)
|
||||
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
|
||||
n, bad, hex(BUF)))
|
||||
|
||||
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
|
||||
for _, s in ipairs(app.sections) do
|
||||
if s.flags & 0x80 ~= 0 then
|
||||
for i = 0, math.floor(s.size / 16) - 1 do
|
||||
prog:write_u16(s.paddr + i * 16, 0xA5A5)
|
||||
end
|
||||
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
|
||||
hex(s.paddr), hex(s.paddr + s.size)))
|
||||
end
|
||||
end
|
||||
|
||||
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
|
||||
w32(DESC + 0x00, 0)
|
||||
prog:write_u16(DESC + 0x00, 0x4C44)
|
||||
prog:write_u16(DESC + 0x10, 0x5231)
|
||||
w32(DESC + 0x20, BUF)
|
||||
w32(DESC + 0x40, #coff)
|
||||
w32(DESC + 0x60, MODE)
|
||||
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
|
||||
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
|
||||
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
|
||||
|
||||
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
|
||||
-- itself); mode 1 returns here, and the stub resumes the interrupted
|
||||
-- PC so the caller yields and the scheduler can run the child.
|
||||
local orig_pc = cpu.state['PC'].value
|
||||
if MODE == 1 then
|
||||
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
|
||||
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
|
||||
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
|
||||
else
|
||||
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
|
||||
end
|
||||
|
||||
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
|
||||
-- the return slot so mode=1 would return to the spin stub.
|
||||
-- Leave SP alone for mode 0: the loader pushes onto the current
|
||||
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
|
||||
-- would use the return stub.)
|
||||
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
|
||||
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
|
||||
cpu.state['A8'].value = A8DESC and DESC or 0
|
||||
if MODE == 1 then
|
||||
-- Simulate a CALLA from the current process: push the return
|
||||
-- address on the *firmware* stack (a real transport would do this).
|
||||
local sp = cpu.state['SP'].value - 0x20
|
||||
w32(sp, RETURN_STUB)
|
||||
cpu.state['SP'].value = sp
|
||||
end
|
||||
cpu.state['PC'].value = LOADER_BASE
|
||||
injected = true
|
||||
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
|
||||
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
|
||||
end
|
||||
|
||||
local function inspect()
|
||||
result_dump()
|
||||
|
||||
-- Verify the placement from RAM: .text/.data must equal the file bytes.
|
||||
for _, s in ipairs(app.sections) do
|
||||
if s.scnptr ~= 0 and s.size > 0 then
|
||||
local nb = math.floor(s.size / 8)
|
||||
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
|
||||
local _, bad = verify_bytes(s.paddr, bytes)
|
||||
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
|
||||
s.name, hex(s.paddr), nb, bad))
|
||||
end
|
||||
end
|
||||
|
||||
local base = COFF:match("([^/]+)$") or COFF
|
||||
if base:find("marker") then
|
||||
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
|
||||
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
|
||||
hex(r32(0x018E0060)), r32(0x018E0080)))
|
||||
elseif base:find("xhello") then
|
||||
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
|
||||
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
|
||||
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
|
||||
end
|
||||
if DL ~= 0 then
|
||||
print(string.format("DIAG: loops=%d events=%d last=%d focus=%08X rev=%d quit=%d window=%08X", r32(DL), r32(DE), r32(DT), DF ~= 0 and r32(DF) or 0, DR ~= 0 and r32(DR) or 0, DQ ~= 0 and r32(DQ) or 0, DW ~= 0 and r32(DW) or 0))
|
||||
if DTICK ~= 0 then
|
||||
print(string.format("DIAG: tick=%d", r32(DTICK)))
|
||||
end
|
||||
end
|
||||
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == 2900 then tabx:set_value(700); taby:set_value(500); print("PLAYKEYS: move") end
|
||||
if frames == 3000 then tabb:set_value(1); print("PLAYKEYS: click down") end
|
||||
if frames == 3020 then tabb:set_value(0); print("PLAYKEYS: click up") end
|
||||
if PLAY_MODE == "move" then
|
||||
if frames == 3100 then key_a:set_value(1) end
|
||||
if frames == 3110 then key_a:set_value(0) end
|
||||
if frames == 3120 then key_d:set_value(1) end
|
||||
if frames == 3130 then key_d:set_value(0) end
|
||||
if frames == 3140 then key_s:set_value(1) end
|
||||
if frames == 3150 then key_s:set_value(0) end
|
||||
if frames == 3160 then key_w:set_value(1) end
|
||||
if frames == 3170 then key_w:set_value(0) end
|
||||
if frames == 3180 then key_0:set_value(1) end
|
||||
if frames == 3190 then key_0:set_value(0) end
|
||||
elseif PLAY_MODE == "panels" then
|
||||
if frames == 3100 then key_h:set_value(1) end
|
||||
if frames == 3110 then key_h:set_value(0) end
|
||||
if frames == 3120 then key_r:set_value(1) end
|
||||
if frames == 3130 then key_r:set_value(0) end
|
||||
elseif PLAY_MODE == "quit" then
|
||||
if frames == 3095 then print("PLAYKEYS: quit arm") end
|
||||
if frames == 3100 then print("PLAYKEYS: Q down"); key_q:set_value(1) end
|
||||
if frames == 3110 then print("PLAYKEYS: Q up"); key_q:set_value(0) end
|
||||
end
|
||||
if frames == AT and not injected then
|
||||
inject()
|
||||
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
|
||||
end
|
||||
if injected and TRACE and frames == AT + 1 then
|
||||
dbg:command("trace off")
|
||||
print("LOADER: trace written to /tmp/opencode/ld.tr")
|
||||
end
|
||||
if injected and not done then
|
||||
if TRACE and frames <= AT + 40 then
|
||||
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
|
||||
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
|
||||
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
|
||||
hex(r32(RESULT + 0x020))))
|
||||
end
|
||||
local st = r32(RESULT + 0x000)
|
||||
-- status 0 means OK; nonzero is final too once parsing has begun
|
||||
if st ~= 0xFFFFFFFF and not done then
|
||||
-- The loader writes 0 on success. A nonzero status is final
|
||||
-- only after it has been written once (it is 0 from power-on,
|
||||
-- so require the loader to have run: PC no longer at entry or
|
||||
-- the app counter moved).
|
||||
end
|
||||
if VERBOSE and frames % 25 == 0 then
|
||||
result_dump()
|
||||
end
|
||||
if base_contains_marker then
|
||||
local c = r32(0x018E0080)
|
||||
if c ~= last_count then
|
||||
if last_count ~= -1 then
|
||||
print(string.format("LOADER: marker counter %d -> %d (child running)",
|
||||
last_count, c))
|
||||
end
|
||||
last_count = c
|
||||
end
|
||||
end
|
||||
end
|
||||
if frames >= ENDF then
|
||||
if injected then
|
||||
done = true
|
||||
inspect()
|
||||
if SNAP then
|
||||
local screen = nil
|
||||
for _, s in pairs(machine.screens) do screen = s break end
|
||||
if screen then
|
||||
local out = OUT .. "/loader_frame" .. frames .. ".png"
|
||||
local ok, err = pcall(function() return screen:snapshot(out) end)
|
||||
print(string.format("LOADER: snapshot %s ok=%s %s",
|
||||
out, tostring(ok), tostring(err or "")))
|
||||
end
|
||||
end
|
||||
end
|
||||
machine:exit()
|
||||
end
|
||||
end, "vt1200-loader")
|
||||
|
||||
-- (Lua has no forward use of a name defined later; set a small flag here.)
|
||||
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
|
||||
|
||||
dbg.visible_cpu = cpu
|
||||
dbg.execution_state = 'run'
|
||||
Executable
+104
@@ -0,0 +1,104 @@
|
||||
#!/bin/sh
|
||||
# play_keys.sh -- run the M4-built termtris COFF in MAME through the proven
|
||||
# play_keys paths (board, move, panels, quit), capture a snapshot per mode,
|
||||
# and print the DIAG line. Threshold enforcement lives in
|
||||
# scripts/tests/m4/termtris.sh.
|
||||
#
|
||||
# scripts/m4/termtris/play_keys.sh
|
||||
#
|
||||
# Env: MODES (default "board move panels quit"), TERMTRIS_NOBUILD=1,
|
||||
# MAME, TERMTRIS_WORK, LOADER_AT/LOADER_END.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4/termtris
|
||||
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
||||
WORK=${TERMTRIS_WORK:-$ROOT/build/m4-termtris}
|
||||
M=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
COFF=$WORK/termtris.coff
|
||||
MAP=$WORK/termtris.map
|
||||
EV=$WORK/evidence
|
||||
LOADER=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
|
||||
fail() {
|
||||
echo "termtris play_keys: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ "${TERMTRIS_NOBUILD:-}" != 1 ]; then
|
||||
"$DIR/build.sh" > "$WORK/build.log" 2>&1 \
|
||||
|| { tail -40 "$WORK/build.log" >&2; fail "build failed"; }
|
||||
fi
|
||||
[ -f "$COFF" ] || fail "missing COFF: $COFF"
|
||||
[ -f "$MAP" ] || fail "missing link map: $MAP"
|
||||
[ -x "$M" ] || fail "MAME binary not built: $M"
|
||||
[ -f "$LOADER" ] || fail "COFF loader missing: $LOADER"
|
||||
|
||||
mkdir -p "$EV" "$WORK/run/nvram" "$WORK/run/cfg"
|
||||
|
||||
# The link map prints two address/name pairs per line, so the symbol address
|
||||
# is the field before the name (the vendored play_keys.sh does the same).
|
||||
addr() {
|
||||
awk -v sym="$1" '{for (i = 2; i <= NF; i++) if ($i == sym) print $(i - 1)}' \
|
||||
"$MAP" | head -1
|
||||
}
|
||||
DIAG_LOOPS=$(addr _dbg_loops)
|
||||
DIAG_EVENTS=$(addr _dbg_events)
|
||||
DIAG_LAST=$(addr _dbg_last)
|
||||
DIAG_FOCUS=$(addr _dbg_focus)
|
||||
DIAG_REV=$(addr _dbg_rev)
|
||||
DIAG_QUIT=$(addr _quit)
|
||||
DIAG_TICK=$(addr _tick_interval)
|
||||
DIAG_WIN=$(addr _vt_win)
|
||||
for sym in "$DIAG_LOOPS" "$DIAG_EVENTS" "$DIAG_LAST" "$DIAG_FOCUS" \
|
||||
"$DIAG_REV" "$DIAG_QUIT" "$DIAG_TICK" "$DIAG_WIN"; do
|
||||
[ -n "$sym" ] || fail "a termtris DIAG symbol is missing from $MAP"
|
||||
done
|
||||
|
||||
echo "== termtris markers: loops=$DIAG_LOOPS events=$DIAG_EVENTS last=$DIAG_LAST"
|
||||
echo " focus=$DIAG_FOCUS rev=$DIAG_REV quit=$DIAG_QUIT tick=$DIAG_TICK win=$DIAG_WIN"
|
||||
|
||||
for mode in ${MODES:-board move panels quit}; do
|
||||
LOG=$WORK/play_$mode.log
|
||||
rm -f "$EV/loader_frame3200.png" "$EV/loader_frame"*.png
|
||||
echo "== play_keys: $mode"
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
VT1200_MONITOR=VR319 \
|
||||
LOADER_SNAP=1 \
|
||||
PLAY_MODE=$mode \
|
||||
DIAG_LOOPS="0x$DIAG_LOOPS" \
|
||||
DIAG_EVENTS="0x$DIAG_EVENTS" \
|
||||
DIAG_LAST="0x$DIAG_LAST" \
|
||||
DIAG_FOCUS="0x$DIAG_FOCUS" \
|
||||
DIAG_REV="0x$DIAG_REV" \
|
||||
DIAG_QUIT="0x$DIAG_QUIT" \
|
||||
DIAG_TICK="0x$DIAG_TICK" \
|
||||
DIAG_WIN="0x$DIAG_WIN" \
|
||||
LOADER_AT="${LOADER_AT:-2500}" \
|
||||
LOADER_END="${LOADER_END:-3200}" \
|
||||
LOADER_BIN="$LOADER" \
|
||||
LOADER_COFF="$COFF" \
|
||||
LOADER_OUT="$EV" \
|
||||
timeout "${MAME_TIMEOUT:-900}" "$M" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/play_keys.lua" -autoboot_delay 0 \
|
||||
> "$LOG" 2>&1 \
|
||||
|| { tail -40 "$LOG" >&2; fail "MAME run failed for $mode"; }
|
||||
|
||||
grep -E 'PLAYKEYS:|LOADER: result|LOADER: snapshot' "$LOG" | tail -5 \
|
||||
|| true
|
||||
DIAG=$(grep -a 'DIAG: loops' "$LOG" | tail -1 || true)
|
||||
[ -n "$DIAG" ] || { tail -40 "$LOG" >&2; \
|
||||
fail "no DIAG line for $mode (see $LOG)"; }
|
||||
echo " $DIAG"
|
||||
echo "$DIAG" > "$WORK/diag_$mode.txt"
|
||||
[ -s "$EV/loader_frame${LOADER_END:-3200}.png" ] \
|
||||
|| fail "no $mode snapshot in $EV"
|
||||
cp "$EV/loader_frame${LOADER_END:-3200}.png" \
|
||||
"$EV/termtris_${mode}_${LOADER_END:-3200}.png"
|
||||
echo " $EV/termtris_${mode}_${LOADER_END:-3200}.png"
|
||||
done
|
||||
@@ -0,0 +1,24 @@
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n)*0x20u))
|
||||
int le(int a, int b) { return a <= b; }
|
||||
unsigned ule(unsigned a, unsigned b) { return a <= b; }
|
||||
int sum_le(int n) { int s = 0, i; for (i = 0; i <= n; i++) s += i; return s; }
|
||||
int ge(int a, int b) { return a >= b; }
|
||||
unsigned uge(unsigned a, unsigned b) { return a >= b; }
|
||||
int gt(int a, int b) { return a > b; }
|
||||
unsigned ugt(unsigned a, unsigned b) { return a > b; }
|
||||
int ne(int a, int b) { return a != b; }
|
||||
int lt(int a, int b) { return a < b; }
|
||||
unsigned ult(unsigned a, unsigned b) { return a < b; }
|
||||
int unsigned_test(void) {
|
||||
MARK(0) = (unsigned)le(5, 7);
|
||||
MARK(1) = (unsigned)ule(7u, 5u);
|
||||
MARK(2) = (unsigned)sum_le(10);
|
||||
MARK(3) = (unsigned)ge(7, 5);
|
||||
MARK(4) = (unsigned)uge(5u, 7u);
|
||||
MARK(5) = (unsigned)gt(5, 7);
|
||||
MARK(6) = (unsigned)ugt(7u, 5u);
|
||||
MARK(7) = (unsigned)ne(7, 5);
|
||||
MARK(8) = (unsigned)lt(7, 5);
|
||||
MARK(9) = (unsigned)ult(5u, 7u);
|
||||
return 0;
|
||||
}
|
||||
Executable
+278
@@ -0,0 +1,278 @@
|
||||
#!/bin/sh
|
||||
# M4 ROM symbol validation.
|
||||
#
|
||||
# Every entry in the v2.2 table must:
|
||||
# - sit in the ROM bit range 3F200000h..3FFFFFFFh,
|
||||
# - be 16-bit aligned (TMS34010 instructions are 16-bit words), and
|
||||
# - start with a plausible function prologue (MMTM/MOVE/SETF/CMP/ADDI).
|
||||
#
|
||||
# The correction-sensitive entries are also checked semantically with dis34:
|
||||
# - XMapWindow must be 0x3FD64F60 and build MapWindow request opcode 8;
|
||||
# - XRaiseWindow must be 0x3FD645B0 and build ConfigureWindow opcode 12 with
|
||||
# CWStackMode=Above (value mask 0x40, value 0);
|
||||
# - XPutImage builds request opcode 0x48 and XGetImage opcode 0x49;
|
||||
# - XLoadFont builds OpenFont opcode 45 (0x2d) and XCopyArea CopyArea
|
||||
# opcode 62 (0x3e) — both from the ROM request builders, not termtris;
|
||||
# - XCreatePixmap builds CreatePixmap opcode 0x35 and XSetInputFocus builds
|
||||
# SetInputFocus opcode 0x2a;
|
||||
# - XCreateImage allocates 0x58 bytes (sizeof(XImage) == 88);
|
||||
# - XSetErrorHandler / XSetIOErrorHandler install the ROM defaults into the
|
||||
# per-process XG block at +0x60 / +0x40.
|
||||
#
|
||||
# This is a separate gate from scripts/m3/validate-syms.sh: M3 is a four-entry
|
||||
# regression, M4 walks the whole table. Both use the same range/alignment/
|
||||
# prologue rules and the same corrected XMapWindow address.
|
||||
#
|
||||
# scripts/m4/validate-syms.sh [symbols/vt1200-v22.syms]
|
||||
#
|
||||
# Overridable: M4_SYMS DIS34 ROM
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
SYMS=${1:-${M4_SYMS:-$ROOT/symbols/vt1200-v22.syms}}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
ROM=${ROM:-$ROOT/vendor/vt1200/vt1200_v22.bin}
|
||||
|
||||
ROM_LO=$((0x3F200000))
|
||||
ROM_HI=$((0x3FFFFFFF))
|
||||
|
||||
MAPWINDOW=$((0x3FD64F60))
|
||||
RAISEWINDOW=$((0x3FD645B0))
|
||||
|
||||
fail() {
|
||||
echo "m4 validate-syms: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$SYMS" ] || fail "symbol file not found: $SYMS"
|
||||
[ -x "$DIS34" ] || fail "dis34 not found or not executable: $DIS34"
|
||||
[ -f "$ROM" ] || fail "ROM image not found: $ROM"
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-syms.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
sym_addr() { # sym_addr NAME
|
||||
awk -v n="$1" '$1 == n { print $2; exit }' "$SYMS"
|
||||
}
|
||||
|
||||
dis_at() { # dis_at BIT_ADDR BYTE_COUNT OUT
|
||||
_daddr=$1
|
||||
_dcount=$2
|
||||
_dout=$3
|
||||
_doff=$(( (_daddr - ROM_LO) / 8 ))
|
||||
dd if="$ROM" of="$_dout.bin" bs=1 skip="$_doff" count="$_dcount" 2>/dev/null
|
||||
# dis34 reports "unexpected end of input" when the last instruction is
|
||||
# truncated; the leading instructions are still valid, so ignore its exit
|
||||
# status and parse the output.
|
||||
"$DIS34" -b "$(printf '%08X' "$_daddr")" -o "$_dout.bin" \
|
||||
> "$_dout" 2>/dev/null || true
|
||||
}
|
||||
|
||||
first_insn() { # first_insn DIS_TEXT
|
||||
awk 'NF && $1 !~ /^L[0-9A-Fa-f]+:$/ { print tolower($1); exit }' "$1"
|
||||
}
|
||||
|
||||
require_match() { # require_match DIS_TEXT ERE WHAT
|
||||
grep -Eiq "$2" "$1" || {
|
||||
sed 's/^/ /' "$1" >&2
|
||||
fail "$3"
|
||||
}
|
||||
}
|
||||
|
||||
check_prologue() { # check_prologue NAME ADDR
|
||||
_name=$1
|
||||
_addr=$2
|
||||
|
||||
case "$_addr" in
|
||||
0x* | 0X*) ;;
|
||||
*) fail "$_name has malformed address '$_addr' (want 0x...)" ;;
|
||||
esac
|
||||
_dec=$((_addr))
|
||||
|
||||
[ "$_dec" -ge "$ROM_LO" ] && [ "$_dec" -le "$ROM_HI" ] \
|
||||
|| fail "$_name $_addr is outside the ROM bit range 3F200000h..3FFFFFFFh"
|
||||
[ $((_dec % 16)) -eq 0 ] \
|
||||
|| fail "$_name $_addr is not 16-bit aligned"
|
||||
|
||||
dis_at "$_dec" 64 "$TMP/insn"
|
||||
_first=$(first_insn "$TMP/insn")
|
||||
[ -n "$_first" ] || fail "$_name $_addr disassembled to nothing"
|
||||
case " move mmtm setf cmp addi " in
|
||||
*" $_first "*) ;;
|
||||
*) fail "$_name $_addr starts with '$_first', not a plausible function prologue" ;;
|
||||
esac
|
||||
echo " ok $_name $_addr: $_first ..."
|
||||
}
|
||||
|
||||
# XMapWindow must be the MapWindow entry, not the ConfigureWindow entry.
|
||||
check_mapwindow() {
|
||||
_addr=$(sym_addr XMapWindow)
|
||||
[ -n "$_addr" ] || fail "table has no XMapWindow entry"
|
||||
_dec=$((_addr))
|
||||
if [ "$_dec" -eq "$RAISEWINDOW" ]; then
|
||||
fail "XMapWindow is $_addr, which is XRaiseWindow (ConfigureWindow opcode 12), not the MapWindow entry (0x3FD64F60): wrong address"
|
||||
fi
|
||||
[ "$_dec" -eq "$MAPWINDOW" ] \
|
||||
|| fail "XMapWindow is $_addr, expected 0x3FD64F60 (MapWindow request opcode 8); wrong address"
|
||||
|
||||
dis_at "$_dec" 512 "$TMP/mapwindow"
|
||||
require_match "$TMP/mapwindow" 'movk[[:space:]]+8,[[:space:]]+a11' \
|
||||
"XMapWindow does not build MapWindow request opcode 8"
|
||||
require_match "$TMP/mapwindow" 'movb[[:space:]]+a11,[[:space:]]+\*a10' \
|
||||
"XMapWindow does not write the request opcode to the display buffer"
|
||||
echo " ok XMapWindow builds MapWindow opcode 8 (XRaiseWindow is 0x3FD645B0)"
|
||||
}
|
||||
|
||||
# XRaiseWindow must be the ConfigureWindow/Above entry.
|
||||
check_raisewindow() {
|
||||
_addr=$(sym_addr XRaiseWindow)
|
||||
[ -n "$_addr" ] || fail "table has no XRaiseWindow entry"
|
||||
_dec=$((_addr))
|
||||
if [ "$_dec" -eq "$MAPWINDOW" ]; then
|
||||
fail "XRaiseWindow is $_addr, which is XMapWindow (MapWindow opcode 8), not ConfigureWindow: wrong address"
|
||||
fi
|
||||
[ "$_dec" -eq "$RAISEWINDOW" ] \
|
||||
|| fail "XRaiseWindow is $_addr, expected 0x3FD645B0 (ConfigureWindow opcode 12)"
|
||||
|
||||
dis_at "$_dec" 512 "$TMP/raisewindow"
|
||||
require_match "$TMP/raisewindow" 'movk[[:space:]]+12,[[:space:]]+a[0-9]+' \
|
||||
"XRaiseWindow does not build ConfigureWindow request opcode 12"
|
||||
require_match "$TMP/raisewindow" 'movi[[:space:]]+0x40,[[:space:]]+a[0-9]+' \
|
||||
"XRaiseWindow does not set the CWStackMode value mask 0x40"
|
||||
require_match "$TMP/raisewindow" '\*a10\(0x40\)' \
|
||||
"XRaiseWindow does not write the CWStackMode value-mask field"
|
||||
require_match "$TMP/raisewindow" '\*a10\(0x60\)' \
|
||||
"XRaiseWindow does not write the CWStackMode=Above value"
|
||||
echo " ok XRaiseWindow builds ConfigureWindow opcode 12, CWStackMode=Above"
|
||||
}
|
||||
|
||||
# XPutImage/XGetImage request opcodes, per the ROM strings they reference.
|
||||
check_image_requests() {
|
||||
_addr=$(sym_addr XPutImage)
|
||||
[ -n "$_addr" ] || fail "table has no XPutImage entry"
|
||||
dis_at "$((_addr))" 544 "$TMP/putimage"
|
||||
require_match "$TMP/putimage" 'movi[[:space:]]+0x48,[[:space:]]+a[0-9]+' \
|
||||
"XPutImage does not build PutImage request opcode 0x48"
|
||||
require_match "$TMP/putimage" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XPutImage does not write its request opcode to the buffer"
|
||||
echo " ok XPutImage builds PutImage opcode 0x48"
|
||||
|
||||
_addr=$(sym_addr XGetImage)
|
||||
[ -n "$_addr" ] || fail "table has no XGetImage entry"
|
||||
dis_at "$((_addr))" 512 "$TMP/getimage"
|
||||
require_match "$TMP/getimage" 'movi[[:space:]]+0x49,[[:space:]]+a[0-9]+' \
|
||||
"XGetImage does not build GetImage request opcode 0x49"
|
||||
require_match "$TMP/getimage" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XGetImage does not write its request opcode to the buffer"
|
||||
echo " ok XGetImage builds GetImage opcode 0x49"
|
||||
}
|
||||
|
||||
# XLoadFont/XCopyArea are inherited from the M4 plan, not the termtris xlib.h.
|
||||
# Their ROM bodies build OpenFont opcode 45 (0x2d) and CopyArea opcode 62
|
||||
# (0x3e); both write the opcode to the request buffer.
|
||||
check_font_copy() {
|
||||
_addr=$(sym_addr XLoadFont)
|
||||
[ -n "$_addr" ] || fail "table has no XLoadFont entry"
|
||||
dis_at "$((_addr))" 512 "$TMP/loadfont"
|
||||
require_match "$TMP/loadfont" 'movi[[:space:]]+0x2d,[[:space:]]+a[0-9]+' \
|
||||
"XLoadFont does not build OpenFont request opcode 45 (0x2d)"
|
||||
require_match "$TMP/loadfont" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XLoadFont does not write its request opcode to the buffer"
|
||||
echo " ok XLoadFont builds OpenFont opcode 45 (not termtris xlib.h)"
|
||||
|
||||
_addr=$(sym_addr XCopyArea)
|
||||
[ -n "$_addr" ] || fail "table has no XCopyArea entry"
|
||||
dis_at "$((_addr))" 512 "$TMP/copyarea"
|
||||
require_match "$TMP/copyarea" 'movi[[:space:]]+0x3e,[[:space:]]+a[0-9]+' \
|
||||
"XCopyArea does not build CopyArea request opcode 62 (0x3e)"
|
||||
require_match "$TMP/copyarea" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XCopyArea does not write its request opcode to the buffer"
|
||||
echo " ok XCopyArea builds CopyArea opcode 62 (not termtris xlib.h)"
|
||||
}
|
||||
|
||||
# XCreatePixmap/XSetInputFocus are used by the image client. Their request
|
||||
# builders are CreatePixmap opcode 0x35 and SetInputFocus opcode 0x2a.
|
||||
check_pixmap_focus() {
|
||||
_addr=$(sym_addr XCreatePixmap)
|
||||
[ -n "$_addr" ] || fail "table has no XCreatePixmap entry"
|
||||
dis_at "$((_addr))" 512 "$TMP/createpixmap"
|
||||
require_match "$TMP/createpixmap" 'movi[[:space:]]+0x35,[[:space:]]+a[0-9]+' \
|
||||
"XCreatePixmap does not build CreatePixmap request opcode 0x35"
|
||||
require_match "$TMP/createpixmap" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XCreatePixmap does not write its request opcode to the buffer"
|
||||
echo " ok XCreatePixmap builds CreatePixmap opcode 0x35"
|
||||
|
||||
_addr=$(sym_addr XSetInputFocus)
|
||||
[ -n "$_addr" ] || fail "table has no XSetInputFocus entry"
|
||||
dis_at "$((_addr))" 256 "$TMP/setinputfocus"
|
||||
require_match "$TMP/setinputfocus" 'movi[[:space:]]+0x2a,[[:space:]]+a[0-9]+' \
|
||||
"XSetInputFocus does not build SetInputFocus request opcode 0x2a"
|
||||
require_match "$TMP/setinputfocus" 'calla[[:space:]]+0x3fd526e0' \
|
||||
"XSetInputFocus does not call the SetInputFocus request builder"
|
||||
require_match "$TMP/setinputfocus" '\*a13\(0xffa0\)' \
|
||||
"XSetInputFocus does not read the revert_to argument"
|
||||
require_match "$TMP/setinputfocus" '\*a13\(0xffc0\)' \
|
||||
"XSetInputFocus does not read the focus argument"
|
||||
require_match "$TMP/setinputfocus" '\*a13\(0xffe0\)' \
|
||||
"XSetInputFocus does not read the display argument"
|
||||
echo " ok XSetInputFocus builds SetInputFocus opcode 0x2a"
|
||||
}
|
||||
|
||||
check_xcreateimage() {
|
||||
_addr=$(sym_addr XCreateImage)
|
||||
[ -n "$_addr" ] || fail "table has no XCreateImage entry"
|
||||
dis_at "$((_addr))" 256 "$TMP/createimage"
|
||||
require_match "$TMP/createimage" 'movi[[:space:]]+0x58,[[:space:]]+a[0-9]+' \
|
||||
"XCreateImage does not allocate 0x58 bytes (sizeof(XImage) == 88)"
|
||||
require_match "$TMP/createimage" 'calla[[:space:]]+0x3f703d90' \
|
||||
"XCreateImage does not call the ROM zeroing allocator (0x3F703D90)"
|
||||
echo " ok XCreateImage allocates an 88-byte XImage"
|
||||
}
|
||||
|
||||
# The error-handler setters write the per-process XG block: IO at +0x40,
|
||||
# protocol error at +0x60. The defaults are the ROM's _XDefaultIOError and
|
||||
# _XDefaultError.
|
||||
check_error_handlers() {
|
||||
_addr=$(sym_addr XSetErrorHandler)
|
||||
[ -n "$_addr" ] || fail "table has no XSetErrorHandler entry"
|
||||
dis_at "$((_addr))" 448 "$TMP/seterror"
|
||||
require_match "$TMP/seterror" 'movi[[:space:]]+0x3f9bd9f0,[[:space:]]+a[0-9]+' \
|
||||
"XSetErrorHandler does not install _XDefaultError (0x3F9BD9F0) when the handler is null"
|
||||
require_match "$TMP/seterror" '\*a11\(0x60\)' \
|
||||
"XSetErrorHandler does not store into the XG block at +0x60"
|
||||
echo " ok XSetErrorHandler stores XG+0x60, default _XDefaultError"
|
||||
|
||||
_addr=$(sym_addr XSetIOErrorHandler)
|
||||
[ -n "$_addr" ] || fail "table has no XSetIOErrorHandler entry"
|
||||
dis_at "$((_addr))" 448 "$TMP/setioerror"
|
||||
require_match "$TMP/setioerror" 'movi[[:space:]]+0x3f9bcd40,[[:space:]]+a[0-9]+' \
|
||||
"XSetIOErrorHandler does not install _XDefaultIOError (0x3F9BCD40) when the handler is null"
|
||||
require_match "$TMP/setioerror" '\*a11\(0x40\)' \
|
||||
"XSetIOErrorHandler does not store into the XG block at +0x40"
|
||||
echo " ok XSetIOErrorHandler stores XG+0x40, default _XDefaultIOError"
|
||||
}
|
||||
|
||||
# Walk every symbol line. Keep this generic so a newly added entry cannot
|
||||
# silently bypass the range/alignment/prologue gate.
|
||||
echo "== validate every v2.2 table entry"
|
||||
count=0
|
||||
while read -r name addr rest; do
|
||||
case "$name" in
|
||||
'' | '#'*) continue ;;
|
||||
esac
|
||||
[ -n "$addr" ] || fail "malformed symbol line for '$name' (no address)"
|
||||
check_prologue "$name" "$addr"
|
||||
count=$((count + 1))
|
||||
done < "$SYMS"
|
||||
[ "$count" -gt 0 ] || fail "no entries found in $SYMS"
|
||||
|
||||
echo "== validate the correction-sensitive entries"
|
||||
check_mapwindow
|
||||
check_raisewindow
|
||||
check_image_requests
|
||||
check_font_copy
|
||||
check_pixmap_focus
|
||||
check_xcreateimage
|
||||
check_error_handlers
|
||||
|
||||
echo "m4 validate-syms: PASS ($count v2.2 entries in ROM, aligned, prologues valid; XMapWindow/XRaiseWindow pinned)"
|
||||
@@ -0,0 +1,31 @@
|
||||
-- varargs-check.lua -- load the varargs ABI probe with the M4 COFF loader and
|
||||
-- check the three sums. The callee walks the contiguous program stack below
|
||||
-- its last fixed argument; these values prove the variadic slots are real.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_END loader inspection/exit frame
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
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 m = {}
|
||||
for i = 0, 2 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format("M4: varargs sum1=%d sum2=%d sum3=%d",
|
||||
m[0], m[1], m[2]))
|
||||
if m[0] == 15 and m[1] == 150 and m[2] == 1500 then
|
||||
print("M4 MAME: PASS")
|
||||
else
|
||||
print("M4 MAME: FAIL (want 15, 150, 1500)")
|
||||
end
|
||||
end
|
||||
end, "varargs-check")
|
||||
@@ -0,0 +1,13 @@
|
||||
; varargs-entry.asm -- M4 entry for the varargs ABI probe.
|
||||
.text
|
||||
.globl _start
|
||||
.globl _varargs_test
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _varargs_test
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* varargs.c -- the contiguous-stack varargs ABI probe.
|
||||
*
|
||||
* M4 supports only the TI ABI's stack layout: a variadic callee takes the
|
||||
* address of its last fixed argument and walks down one 32-bit slot per extra
|
||||
* argument. There is no va_start/va_arg/va_list. The termtris compat.c
|
||||
* sprintf uses exactly this pattern; this probe proves the values arrive.
|
||||
*
|
||||
* Markers (0x20 bits apart, written by the test):
|
||||
* 018A8000 sumvar(1,2,3,4,5) == 15
|
||||
* 018A8020 sumvar(10,20,30,40,50) == 150
|
||||
* 018A8040 sumvar(100,200,300,400,500) == 1500
|
||||
*/
|
||||
#define MARK(n) (*(volatile int *)(0x018A8000UL + (n) * 0x20UL))
|
||||
|
||||
static int sumvar(int a, int b, ...)
|
||||
{
|
||||
int *p = &b;
|
||||
int s = a + b;
|
||||
|
||||
p--;
|
||||
s += *p; /* first variadic argument */
|
||||
p--;
|
||||
s += *p; /* second */
|
||||
p--;
|
||||
s += *p; /* third */
|
||||
return s;
|
||||
}
|
||||
|
||||
void varargs_test(void)
|
||||
{
|
||||
MARK(0) = sumvar(1, 2, 3, 4, 5);
|
||||
MARK(1) = sumvar(10, 20, 30, 40, 50);
|
||||
MARK(2) = sumvar(100, 200, 300, 400, 500);
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* Minimal X11R4-compatible declarations for the M4 VT1200 clients.
|
||||
*
|
||||
* The VT1200 X server is X11R4 on a 32-bit TMS34010, so this header models
|
||||
* that ABI: XID/Window/KeySym/Time are 32-bit unsigned long, GC is a 32-bit
|
||||
* pointer, and XImage carries the inline six-entry struct funcs tail.
|
||||
*
|
||||
* Display/Screen deliberately do NOT include the host X11R4 header. The
|
||||
* VT1200 ROM's Display is the M3-verified layout: Display.screens at byte
|
||||
* 0x90 (bit 0x480) and Screen.root at byte 0x8 (bit 0x40). Do not include
|
||||
* scripts/m3/vt1200_xlib.h here; its XOpenDisplay/XCreateSimpleWindow
|
||||
* prototypes conflict with the wider M4 ones below.
|
||||
*
|
||||
* Offset assertions live in scripts/m4/layout.c; the TI golden in
|
||||
* scripts/m4/layout-ti.s carries the same bit displacements.
|
||||
*/
|
||||
#ifndef X11M4_H
|
||||
#define X11M4_H
|
||||
|
||||
typedef unsigned long XID;
|
||||
typedef XID Window;
|
||||
typedef XID Drawable;
|
||||
typedef XID Pixmap;
|
||||
typedef XID Atom;
|
||||
typedef XID Colormap;
|
||||
typedef XID Cursor;
|
||||
typedef XID Font;
|
||||
typedef XID GContext;
|
||||
typedef XID KeySym;
|
||||
typedef unsigned long Mask;
|
||||
typedef unsigned long Time;
|
||||
typedef int Bool;
|
||||
typedef unsigned char KeyCode;
|
||||
typedef char *XPointer;
|
||||
|
||||
typedef struct _XGC *GC;
|
||||
typedef struct _Visual Visual; /* opaque: clients only pass a Visual * */
|
||||
typedef struct _XImage XImage;
|
||||
|
||||
/*
|
||||
* The VT1200 ROM layout, reused from scripts/m3/vt1200_xlib.h. TMS34010
|
||||
* indirect displacements are bit offsets, so screens is at byte 0x90 and
|
||||
* root at byte 0x8.
|
||||
*/
|
||||
typedef struct _Display {
|
||||
unsigned char pad[0x90];
|
||||
void *screens;
|
||||
} Display;
|
||||
|
||||
typedef struct _Screen {
|
||||
unsigned char pad[0x8];
|
||||
unsigned int root;
|
||||
} Screen;
|
||||
|
||||
/* X11R4 xlib.h: the image function table is inline in XImage, not a pointer. */
|
||||
struct funcs {
|
||||
XImage *(*create_image)(Display *, Visual *, unsigned int, int, int, char *,
|
||||
unsigned int, unsigned int, int, int);
|
||||
int (*destroy_image)(XImage *);
|
||||
unsigned long (*get_pixel)(XImage *, int, int);
|
||||
int (*put_pixel)(XImage *, int, int, unsigned long);
|
||||
XImage *(*sub_image)(XImage *, int, int, unsigned int, unsigned int);
|
||||
int (*add_pixel)(XImage *, long);
|
||||
};
|
||||
|
||||
typedef struct _XImage {
|
||||
int width, height;
|
||||
int xoffset;
|
||||
int format;
|
||||
char *data;
|
||||
int byte_order;
|
||||
int bitmap_unit;
|
||||
int bitmap_bit_order;
|
||||
int bitmap_pad;
|
||||
int depth;
|
||||
int bytes_per_line;
|
||||
int bits_per_pixel;
|
||||
unsigned long red_mask, green_mask, blue_mask;
|
||||
void *obdata;
|
||||
struct funcs f;
|
||||
} XImage;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window window;
|
||||
} XAnyEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window window;
|
||||
Window root;
|
||||
Window subwindow;
|
||||
Time time;
|
||||
int x, y;
|
||||
int x_root, y_root;
|
||||
unsigned int state;
|
||||
unsigned int keycode;
|
||||
Bool same_screen;
|
||||
} XKeyEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window window;
|
||||
Window root;
|
||||
Window subwindow;
|
||||
Time time;
|
||||
int x, y;
|
||||
int x_root, y_root;
|
||||
unsigned int state;
|
||||
unsigned int button;
|
||||
Bool same_screen;
|
||||
} XButtonEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window window;
|
||||
int mode;
|
||||
int detail;
|
||||
} XFocusChangeEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window window;
|
||||
int x, y;
|
||||
int width, height;
|
||||
int count;
|
||||
} XExposeEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window event;
|
||||
Window window;
|
||||
int x, y;
|
||||
int width, height;
|
||||
int border_width;
|
||||
Window above;
|
||||
Bool override_redirect;
|
||||
} XConfigureEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
unsigned long serial;
|
||||
Bool send_event;
|
||||
Display *display;
|
||||
Window window;
|
||||
Atom message_type;
|
||||
int format;
|
||||
union {
|
||||
char b[20];
|
||||
short s[10];
|
||||
long l[5];
|
||||
} data;
|
||||
} XClientMessageEvent;
|
||||
|
||||
typedef struct {
|
||||
int type;
|
||||
Display *display;
|
||||
XID resourceid;
|
||||
unsigned long serial;
|
||||
unsigned char error_code;
|
||||
unsigned char request_code;
|
||||
unsigned char minor_code;
|
||||
/*
|
||||
* X11R4's 32-bit XErrorEvent is 20 bytes. The TMS34010 C ABI packs
|
||||
* structs (and TI C does too), so the three trailing chars would make the
|
||||
* packed object 19 bytes. This byte is an X11R4 object-size compatibility
|
||||
* pad; the client reads only the handler-passed fields.
|
||||
*/
|
||||
unsigned char abi_pad;
|
||||
} XErrorEvent;
|
||||
|
||||
/*
|
||||
* X11R4's XEvent is 96 bytes: the largest member is pad[24] (the protocol
|
||||
* xEvent is 24 longs). The termtris event buffer is vt_u32 evbuf[24].
|
||||
*/
|
||||
typedef union _XEvent {
|
||||
int type;
|
||||
XAnyEvent xany;
|
||||
XKeyEvent xkey;
|
||||
XButtonEvent xbutton;
|
||||
XFocusChangeEvent xfocus;
|
||||
XExposeEvent xexpose;
|
||||
XConfigureEvent xconfigure;
|
||||
XClientMessageEvent xclient;
|
||||
XErrorEvent xerror;
|
||||
long pad[24];
|
||||
} XEvent;
|
||||
|
||||
/* Event codes (X11R4). */
|
||||
#define KeyPress 2
|
||||
#define KeyRelease 3
|
||||
#define ButtonPress 4
|
||||
#define ButtonRelease 5
|
||||
#define FocusIn 9
|
||||
#define FocusOut 10
|
||||
#define Expose 12
|
||||
|
||||
/* Event masks (X11R4). */
|
||||
#define NoEventMask 0L
|
||||
#define KeyPressMask (1L << 0)
|
||||
#define KeyReleaseMask (1L << 1)
|
||||
#define ButtonPressMask (1L << 2)
|
||||
#define ButtonReleaseMask (1L << 3)
|
||||
#define ExposureMask (1L << 15)
|
||||
#define StructureNotifyMask (1L << 17)
|
||||
#define FocusChangeMask (1L << 21)
|
||||
|
||||
/* Image byte/bit order and format. */
|
||||
#define LSBFirst 0
|
||||
#define MSBFirst 1
|
||||
#define XYBitmap 0
|
||||
#define XYPixmap 1
|
||||
#define ZPixmap 2
|
||||
|
||||
#define True 1
|
||||
#define False 0
|
||||
#define None 0L
|
||||
|
||||
typedef int (*XErrorHandler)(Display *, XErrorEvent *);
|
||||
typedef int (*XIOErrorHandler)(Display *);
|
||||
|
||||
/*
|
||||
* Real Xlib entry points. The VT1200 ROM exports these names; Task 5
|
||||
* validates their bit addresses in symbols/vt1200-v22.syms.
|
||||
*
|
||||
* XCreateGC's XGCValues* and XLookupString's XComposeStatus* are modelled as
|
||||
* void*: the layout is not needed by the M4 clients and the 32-bit pointer
|
||||
* ABI is unchanged.
|
||||
*/
|
||||
extern Display *XOpenDisplay(const char *name);
|
||||
extern Window XCreateSimpleWindow(Display *display, Window parent, int x, int y,
|
||||
unsigned int width, unsigned int height,
|
||||
unsigned int border_width,
|
||||
unsigned long border,
|
||||
unsigned long background);
|
||||
extern int XMapWindow(Display *display, Window window);
|
||||
/* CreatePixmap opcode 0x35; depth 1 for the image client's 1-bit pixmap. */
|
||||
extern Pixmap XCreatePixmap(Display *display, Drawable drawable,
|
||||
unsigned int width, unsigned int height,
|
||||
unsigned int depth);
|
||||
/* ConfigureWindow(CWStackMode=Above): map-and-raise for a client that must be
|
||||
* above the Terminal Manager (XMapWindow alone does not raise). */
|
||||
extern int XRaiseWindow(Display *display, Window window);
|
||||
extern int XSync(Display *display, Bool discard);
|
||||
extern int XFlush(Display *display);
|
||||
extern int XSelectInput(Display *display, Window window, long event_mask);
|
||||
extern GC XCreateGC(Display *display, Drawable drawable,
|
||||
unsigned long valuemask, void *values);
|
||||
extern int XSetForeground(Display *display, GC gc, unsigned long foreground);
|
||||
extern int XFillRectangle(Display *display, Drawable drawable, GC gc, int x,
|
||||
int y, unsigned int width, unsigned int height);
|
||||
extern int XDrawString(Display *display, Drawable drawable, GC gc, int x, int y,
|
||||
const char *string, int length);
|
||||
extern int XNextEvent(Display *display, XEvent *event);
|
||||
extern int XLookupString(XKeyEvent *event, char *buffer, int bytes,
|
||||
KeySym *keysym, void *compose_status);
|
||||
extern int XPending(Display *display);
|
||||
/* The ROM's ms sleep (symbols/vt1200-v22.syms: 0x3FB33A20); yields so the
|
||||
* X server and the other firmware processes keep running. */
|
||||
extern int sleep(int ms);
|
||||
extern int XGetInputFocus(Display *display, Window *focus, int *revert_to);
|
||||
/*
|
||||
* The ROM's XSetInputFocus reads three arguments (display, focus, revert_to)
|
||||
* and supplies CurrentTime inside the request builder; the disassembly at
|
||||
* 0x3FD536B0 reads 0xffe0/0xffc0/0xffa0 and builds SetInputFocus opcode 0x2a.
|
||||
*/
|
||||
#define RevertToParent 2
|
||||
extern int XSetInputFocus(Display *display, Window focus, int revert_to);
|
||||
/* ROM blitter memcpy used by _XPutImage; the ROM order is (src, dst, bytes). */
|
||||
extern int blit_copy(void *src, void *dst, int nbytes);
|
||||
extern Font XLoadFont(Display *display, const char *name);
|
||||
extern int XCopyArea(Display *display, Drawable src, Drawable dest, GC gc,
|
||||
int src_x, int src_y, unsigned int width,
|
||||
unsigned int height, int dest_x, int dest_y);
|
||||
extern XImage *XCreateImage(Display *display, Visual *visual,
|
||||
unsigned int depth, int format, int offset,
|
||||
char *data, unsigned int width,
|
||||
unsigned int height, int bitmap_pad,
|
||||
int bytes_per_line);
|
||||
extern int XPutImage(Display *display, Drawable drawable, GC gc, XImage *image,
|
||||
int src_x, int src_y, int dest_x, int dest_y,
|
||||
unsigned int width, unsigned int height);
|
||||
extern int XDestroyImage(XImage *image);
|
||||
extern XErrorHandler XSetErrorHandler(XErrorHandler handler);
|
||||
extern XIOErrorHandler XSetIOErrorHandler(XIOErrorHandler handler);
|
||||
|
||||
/* Install the per-process XG block before XOpenDisplay (scripts/m4/xgfix.c). */
|
||||
extern int vt_install_xg(void);
|
||||
|
||||
/* Follow Display.screens (bit 0x480) and read Screen.root (bit 0x40). */
|
||||
static inline __attribute__((always_inline)) unsigned int
|
||||
vt_root(Display *display) {
|
||||
return ((Screen *)((Display *)display)->screens)->root;
|
||||
}
|
||||
|
||||
#endif /* X11M4_H */
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Per-process Xlib context (XG) installer for the VT1200 loader child.
|
||||
*
|
||||
* The ROM Xlib keeps its per-process state in the user word at
|
||||
* *(current_process + 0x100). A process created by the loader inherits a
|
||||
* zeroed cell there, so the ROM's _XEnq sees XG == NULL and XNextEvent reads
|
||||
* garbage or never reports events. Points that word at a zeroed 1 KiB block
|
||||
* before XOpenDisplay.
|
||||
*
|
||||
* This is a RAM write only; the ROM image is untouched. Must be called before
|
||||
* XOpenDisplay, once per process.
|
||||
*/
|
||||
int vt_install_xg(void) {
|
||||
unsigned int proc = *(volatile unsigned int *)0x001B3900u;
|
||||
if (proc < 0x100u || proc > 0x01FFFFFFu) return 0;
|
||||
unsigned int pp = *(volatile unsigned int *)(proc + 0x100u);
|
||||
if (pp < 0x100u || pp > 0x01FFFFFFu) return 0;
|
||||
static unsigned int xg[256]; /* 1 KiB zeroed .bss */
|
||||
*(volatile unsigned int *)pp = (unsigned int)xg;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
-- xshow-check.lua -- load the M4 image/event COFF with dwt/loader/loader.lua,
|
||||
-- inject a real LK401 `Q` key, and prove the mapped 1-bit XImage in VRAM.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_AT injection frame (default 2500)
|
||||
-- LOADER_END loader inspection/exit frame (default 3400)
|
||||
--
|
||||
-- Markers (0x20 bits apart):
|
||||
-- 018A8000 display nonzero
|
||||
-- 018A8020 window nonzero
|
||||
-- 018A8040 image nonzero
|
||||
-- 018A8060 quit 1 after the `q` KeyPress
|
||||
-- 018A8080 events count of XNextEvent calls (> 0)
|
||||
-- 018A80A0 keycode ev.xkey.keycode (193 for the LK401 Q)
|
||||
-- 018A80C0 keysym XLookupString keysym (XK_q = 0x71)
|
||||
-- 018A80E0 xerrors 0
|
||||
-- 018A8100 focus XGetInputFocus after XSetInputFocus
|
||||
-- 018A8120 last last X event type (2 = KeyPress)
|
||||
--
|
||||
-- The client window is XCreateSimpleWindow(..., 20, 20, 640, 480, ...) with
|
||||
-- no border. The VT1200 server copies a 1-bit bitmap correctly only when the
|
||||
-- destination x is 32-bit aligned, so the client draws the aligned pixmap at
|
||||
-- window x = 12 (screen x = 32) and fills the 12-pixel prefix with the
|
||||
-- preceding cell's colour. The checker cells are 32 pixels wide with a
|
||||
-- 12-pixel phase: image data x = sx - 20 - 12. The window-relative points
|
||||
-- (30,30) and (50,30) are adjacent cells (0,0) and (1,0), as are (30,62) and
|
||||
-- (50,62). The samples at data (368,280), (468,380) and (568,430) prove the
|
||||
-- banded PutImage assembled the whole 640x480 image, not just its first band.
|
||||
-- The prefix samples at screen (25,30)/(25,62) prove the preceding-cell fill.
|
||||
-- The pixel is read from the exact VRAM bit address (VR319: 2048-bit rows,
|
||||
-- LSB-first), not from a whole unaligned word that would cross a cell.
|
||||
--
|
||||
-- The focus path is the tablet click: XSetInputFocus alone leaves the DWT WM
|
||||
-- at PointerRoot (verified: focus=0x1 and no key), so the gate moves the
|
||||
-- absolute tablet (0..2199) to (700,500), the termtris-proven in-window point,
|
||||
-- and clicks. That point maps inside termtris' (80..560,80..392) rectangle,
|
||||
-- which is contained in this client's (20..660,20..500) window. The focus
|
||||
-- marker must become the client's own window; the ButtonRelease handler
|
||||
-- samples it after the click.
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "3400")
|
||||
local ports = manager.machine.ioport.ports
|
||||
local key_q = ports[":lk401:K13"].fields["Q"]
|
||||
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
|
||||
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
|
||||
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
|
||||
|
||||
local MOVE_AT = 2900
|
||||
local CLICK_DOWN = 2920
|
||||
local CLICK_UP = 2930
|
||||
local Q_DOWN = 3000
|
||||
local Q_UP = 3010
|
||||
|
||||
local VRAM_BASE = 0x04000000
|
||||
local VRAM_PITCH = 2048 -- VR319: 2048 bits per row
|
||||
local WIN_X, WIN_Y = 20, 20
|
||||
local IMG_PHASE = 12 -- pixmap is copied to window x=12 (screen x=32)
|
||||
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local function read_bit(prog, sx, sy)
|
||||
local bit = VRAM_BASE + sy * VRAM_PITCH + sx
|
||||
return prog:read_u16(bit) % 2, bit
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
|
||||
if frames == MOVE_AT then
|
||||
tabx:set_value(700)
|
||||
taby:set_value(500)
|
||||
print(string.format("M4: inject frame %d tablet (700,500)", frames))
|
||||
elseif frames == CLICK_DOWN then
|
||||
tabb:set_value(1)
|
||||
print(string.format("M4: inject frame %d button down", frames))
|
||||
elseif frames == CLICK_UP then
|
||||
tabb:set_value(0)
|
||||
print(string.format("M4: inject frame %d button up", frames))
|
||||
elseif frames == Q_DOWN then
|
||||
key_q:set_value(1)
|
||||
print(string.format("M4: inject frame %d Q down", frames))
|
||||
elseif frames == Q_UP then
|
||||
key_q:set_value(0)
|
||||
print(string.format("M4: inject frame %d Q up", frames))
|
||||
end
|
||||
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local m = {}
|
||||
for i = 0, 9 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
|
||||
print(string.format(
|
||||
"M4: display=%u window=%u image=%u quit=%d events=%d keycode=%d keysym=0x%X xerrors=%d focus=0x%X last=%d",
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9]))
|
||||
|
||||
-- screen -> image (window-relative) -> 32-pixel cell
|
||||
local function sample(sx, sy)
|
||||
local b, bit = read_bit(prog, sx, sy)
|
||||
local rx, ry = sx - WIN_X - IMG_PHASE, sy - WIN_Y
|
||||
local cx, cy = math.floor(rx / 32), math.floor(ry / 32)
|
||||
print(string.format(
|
||||
"M4: pixel screen(%d,%d) image(%d,%d) cell(%d,%d) bit=0x%08X value=%d %s",
|
||||
sx, sy, rx, ry, cx, cy, bit, b,
|
||||
b == 1 and "white" or "black"))
|
||||
return b
|
||||
end
|
||||
|
||||
-- The task's exact pair plus the orthogonal pair, at cell centres and
|
||||
-- at points well inside the cells (away from a 32-pixel boundary).
|
||||
local b00 = sample(50, 50) -- data (18,30) cell (0,0) -> black
|
||||
local b10 = sample(70, 50) -- data (38,30) cell (1,0) -> white
|
||||
local b01 = sample(50, 82) -- data (18,62) cell (0,1) -> white
|
||||
local b11 = sample(70, 82) -- data (38,62) cell (1,1) -> black
|
||||
local c00 = sample(36, 36) -- data (4,16) cell (0,0) -> black
|
||||
local c10 = sample(68, 36) -- data (36,16) cell (1,0) -> white
|
||||
local c01 = sample(36, 68) -- data (4,48) cell (0,1) -> white
|
||||
local c11 = sample(68, 68) -- data (36,48) cell (1,1) -> black
|
||||
-- later bands, so a repeated first-band bug cannot pass
|
||||
local d1 = sample(400, 300) -- data (368,280) cell (11,8) -> white
|
||||
local d2 = sample(500, 400) -- data (468,380) cell (14,11) -> white
|
||||
local d3 = sample(600, 450) -- data (568,430) cell (17,13) -> black
|
||||
-- the 12-pixel prefix is the preceding cell: white in band 0, black
|
||||
-- in band 1, so it cannot be a constant left stripe.
|
||||
local p0 = sample(25, 30) -- data (-7,10) cell (-1,0) -> white
|
||||
local p1 = sample(25, 62) -- data (-7,42) cell (-1,1) -> black
|
||||
|
||||
local keysym_ok = (m[6] == 0x71)
|
||||
local image_ok = b00 == 0 and b10 == 1 and b01 == 1 and b11 == 0
|
||||
and c00 == 0 and c10 == 1 and c01 == 1 and c11 == 0
|
||||
and d1 == 1 and d2 == 1 and d3 == 0
|
||||
and p0 == 1 and p1 == 0
|
||||
local ok = m[0] ~= 0 and m[1] ~= 0 and m[2] ~= 0
|
||||
and m[3] == 1 and m[4] > 0 and m[7] == 0
|
||||
and m[5] == 193 and keysym_ok
|
||||
and m[8] == m[1] and m[8] ~= 0 and m[9] == 2
|
||||
and image_ok
|
||||
|
||||
if ok then
|
||||
print("M4 MAME: PASS")
|
||||
else
|
||||
print(string.format(
|
||||
"M4 MAME: FAIL (markers display/window/image=%u/%u/%u quit=%d events=%d keycode=%d keysym=0x%X xerrors=%d focus=0x%X last=%d; image %s)",
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8], m[9],
|
||||
image_ok and "checker-ok" or "checker-mismatch"))
|
||||
end
|
||||
end
|
||||
end, "xshow-check")
|
||||
@@ -0,0 +1,22 @@
|
||||
; xshow-entry.asm -- M4 image/event client entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the compiled xshow() client. Markers (0x20 bits apart):
|
||||
; 018A8000 display nonzero
|
||||
; 018A8020 window nonzero
|
||||
; 018A8040 image nonzero
|
||||
; 018A8060 quit 1 after the real `q` KeyPress
|
||||
; 018A8080 events count of XNextEvent calls
|
||||
; 018A80A0 keycode ev.xkey.keycode
|
||||
; 018A80C0 keysym XLookupString keysym
|
||||
; 018A80E0 xerrors 0
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _xshow
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,280 @@
|
||||
/*
|
||||
* xshow.c -- the M4 1-bit XImage + real-key-event client.
|
||||
*
|
||||
* The client installs the per-process XG block (Task 5), opens the VT1200 X
|
||||
* display, creates a 640x480 window at (20,20), draws a 32-pixel checkerboard
|
||||
* through a 1-bit LSBFirst XYBitmap XImage, then drains X events and quits on
|
||||
* the real keyboard's `q`.
|
||||
*
|
||||
* Markers live at 0x018A8000 + n*0x20 (bit addresses):
|
||||
* 0 Display * nonzero
|
||||
* 1 Window nonzero
|
||||
* 2 XImage * nonzero
|
||||
* 3 quit 1 after the `q` KeyPress
|
||||
* 4 events count of every XNextEvent
|
||||
* 5 keycode ev.xkey.keycode of the last KeyPress
|
||||
* 6 keysym XLookupString keysym of the last KeyPress
|
||||
* 7 xerrors count of X protocol errors seen by on_error
|
||||
* 8 focus XGetInputFocus window (0x400001 after the click)
|
||||
* 9 last last X event type (2 = KeyPress)
|
||||
*
|
||||
* The static image is 480 * 80 bytes in .bss (640 pixels / 8 = 80 bytes per
|
||||
* row). It is intentionally never passed to XDestroyImage: the ROM destructor
|
||||
* frees the data pointer, which is .bss here, not heap memory.
|
||||
*
|
||||
* Two VT1200 server/Xlib constraints shape the drawing path. A single 38 KiB
|
||||
* PutImage request does not complete (the ROM request buffer is 16 KiB), so the
|
||||
* image is emitted in 32-row bands and each band selects its rows by moving
|
||||
* XImage.data (the server ignores src_y). The server also copies a 1-bit
|
||||
* bitmap correctly only when the destination x is 32-bit aligned, so the bands
|
||||
* go into an aligned depth-1 pixmap and XCopyArea places the image at window
|
||||
* x=12 (screen x=32); the 12-pixel prefix is filled with the first cell's
|
||||
* colour. The checker cells are still 32 pixels, with a 12-pixel phase inside
|
||||
* the (20,20) window.
|
||||
*/
|
||||
#include "x11m4.h"
|
||||
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n) * 0x20u))
|
||||
|
||||
#define IMG_W 640
|
||||
#define IMG_H 480
|
||||
#define IMG_BPL 80 /* ((640 + 31) / 32) * 4 */
|
||||
|
||||
static int xerrors;
|
||||
/*
|
||||
* The image bytes: 480 rows * 80 bytes. It is built as 32-bit words because
|
||||
* each word spans exactly one 32-pixel cell and LSBFirst makes word bit i
|
||||
* pixel x = 32*cell + i. (The brief's per-bit byte OR loop compiles to an
|
||||
* i8 load with `anyext`, which this target cannot select at -O2; the word
|
||||
* form writes the identical bytes.) The 4-byte alignment lets the compiler
|
||||
* use whole-word stores.
|
||||
*/
|
||||
static unsigned char data[IMG_H * IMG_BPL] __attribute__((aligned(4)));
|
||||
|
||||
/*
|
||||
* The ROM calls this through the pointer installed by XSetErrorHandler. The
|
||||
* Task 4 header's XErrorHandler is authoritative: int (Display*, XErrorEvent*).
|
||||
*/
|
||||
static int on_error(Display *d, XErrorEvent *e) {
|
||||
(void)d;
|
||||
(void)e;
|
||||
xerrors++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call the ROM sleep through a function pointer: the image then exercises the
|
||||
* Task 3 indirect-call contract (CALL Rs) as well as the direct CALLA imports.
|
||||
* It is volatile so the optimizer cannot devirtualise the load into a direct
|
||||
* CALLA and erase that coverage. The pointer lives in .data as `.long _sleep`.
|
||||
*/
|
||||
static int (*volatile vt_sleep)(int) = sleep;
|
||||
|
||||
/*
|
||||
* The ROM Xlib copies an XImage into its request buffer with the TMS34010
|
||||
* blitter. `blit_copy` is the validated ROM entry _XPutImage calls
|
||||
* (0x3F9CBFE0 -> 0x3FB44400): (source, destination, byte count). A process
|
||||
* created by the loader inherits a zeroed blitter window/pitch context, so the
|
||||
* first copy writes nothing; prime it once with a four-byte self-copy.
|
||||
*/
|
||||
static void prime_blitter(void) {
|
||||
blit_copy(data, data, 4);
|
||||
}
|
||||
|
||||
/*
|
||||
* A single 640x480 1-bit PutImage is 0xC0 + 480*80 = 38592 bytes, but the ROM
|
||||
* Xlib's request buffer is only 16384 bytes. XPutImage's direct-send path for
|
||||
* an image larger than the buffer does not make progress in the harness, so
|
||||
* emit the image in 32-row bands: each band's request fits the buffer, and the
|
||||
* explicit flush/yield lets the X server drain it. The assembled drawable is
|
||||
* still the whole 640x480 image.
|
||||
*/
|
||||
static void present(Display *d, Drawable target, Window w, GC gc) {
|
||||
int y;
|
||||
|
||||
/*
|
||||
* The server copies 1-bit bitmaps correctly only when the destination x is
|
||||
* 32-bit aligned. Draw the aligned pixmap starting at window x = 12
|
||||
* (screen x = 32) and fill the 12-pixel prefix with the preceding cell's
|
||||
* colour, band by band, so the visible 32-pixel phase is preserved. The
|
||||
* checker cells are still 32 pixels wide; the phase is offset by 12 pixels
|
||||
* inside the (20,20) window. Only IMG_W - 12 = 628 columns are copied, so
|
||||
* the rightmost 12 source columns (the final 12 px of the last cell) are
|
||||
* not displayed and the last visible cell is 20 px, not 32.
|
||||
*/
|
||||
XCopyArea(d, target, w, gc, 0, 0, IMG_W - 12, IMG_H, 12, 0);
|
||||
for (y = 0; y < IMG_H; y += 32) {
|
||||
XSetForeground(d, gc, ((y / 32) & 1) == 0 ? 1 : 0);
|
||||
XFillRectangle(d, w, gc, 0, y, 12, 32);
|
||||
}
|
||||
XSetForeground(d, gc, 1);
|
||||
XFlush(d);
|
||||
}
|
||||
|
||||
static void draw_image(Display *d, Drawable target, Window w, GC gc,
|
||||
XImage *img) {
|
||||
char *base = (char *)data;
|
||||
int y;
|
||||
|
||||
prime_blitter();
|
||||
for (y = 0; y < IMG_H; y += 32) {
|
||||
/*
|
||||
* src_y is ignored by the bitmap path, so select the band by moving
|
||||
* the image data pointer.
|
||||
*/
|
||||
img->data = base + y * IMG_BPL;
|
||||
XPutImage(d, target, gc, img, 0, 0, 0, y, IMG_W, 32);
|
||||
XFlush(d);
|
||||
vt_sleep(1);
|
||||
}
|
||||
img->data = base;
|
||||
present(d, target, w, gc);
|
||||
}
|
||||
|
||||
int xshow(void) {
|
||||
Display *d;
|
||||
Window w;
|
||||
Pixmap pm;
|
||||
GC gc;
|
||||
XImage *img;
|
||||
int tries;
|
||||
int x, y;
|
||||
|
||||
if (!vt_install_xg())
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* The display server may still be starting when the loader creates this
|
||||
* process; retry as the termtris client does. XOpenDisplay allocates the
|
||||
* connection, so one success ends the loop.
|
||||
*/
|
||||
d = 0;
|
||||
for (tries = 0; tries < 40; tries++) {
|
||||
d = XOpenDisplay("0::0");
|
||||
if (d)
|
||||
break;
|
||||
vt_sleep(50);
|
||||
}
|
||||
MARK(0) = (unsigned)d;
|
||||
if (!d)
|
||||
return -1;
|
||||
|
||||
w = XCreateSimpleWindow(d, vt_root(d), 20, 20, IMG_W, IMG_H, 0, 0, 0);
|
||||
MARK(1) = (unsigned)w;
|
||||
|
||||
/* These are counters/state, not loader-zeroed .bss: clear them first. */
|
||||
MARK(3) = 0;
|
||||
MARK(4) = 0;
|
||||
MARK(5) = 0;
|
||||
MARK(6) = 0;
|
||||
MARK(7) = 0;
|
||||
|
||||
XSelectInput(d, w, ExposureMask | KeyPressMask | KeyReleaseMask |
|
||||
ButtonPressMask | ButtonReleaseMask |
|
||||
StructureNotifyMask | FocusChangeMask);
|
||||
gc = XCreateGC(d, w, 0, 0);
|
||||
XSetForeground(d, gc, 1);
|
||||
pm = XCreatePixmap(d, w, IMG_W, IMG_H, 1);
|
||||
|
||||
/*
|
||||
* 32-pixel checkerboard, LSB-first in each byte/word. Build whole 32-bit
|
||||
* words (each word is exactly one 32-pixel cell) and toggle the row fill
|
||||
* every 32 rows; this avoids the i8 anyext load and the i1
|
||||
* sign_extend_inreg that the brief's per-bit loop creates at -O2.
|
||||
*/
|
||||
{
|
||||
unsigned int fill = 0xFFFFFFFFu;
|
||||
unsigned int band = 0;
|
||||
|
||||
for (y = 0; y < IMG_H; y++) {
|
||||
unsigned int *row = (unsigned int *)(data + y * IMG_BPL);
|
||||
unsigned int v = fill;
|
||||
|
||||
for (x = 0; x < IMG_BPL / 4; x++) {
|
||||
row[x] = v;
|
||||
v = ~v;
|
||||
}
|
||||
if (++band == 32) {
|
||||
band = 0;
|
||||
fill = ~fill;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* visual 0 is safe for the ROM XCreateImage: it only dereferences the
|
||||
* visual when the pointer is nonzero, and a depth-1 XYBitmap takes its
|
||||
* byte/bit order from the Display. We set both orders explicitly below.
|
||||
*/
|
||||
img = XCreateImage(d, 0, 1, XYBitmap, 0, (char *)data, IMG_W, IMG_H, 32,
|
||||
IMG_BPL);
|
||||
MARK(2) = (unsigned)img;
|
||||
if (!img)
|
||||
return -1;
|
||||
img->byte_order = LSBFirst;
|
||||
img->bitmap_bit_order = LSBFirst;
|
||||
|
||||
XSetErrorHandler(on_error);
|
||||
XMapWindow(d, w);
|
||||
XRaiseWindow(d, w);
|
||||
XSetInputFocus(d, w, RevertToParent);
|
||||
draw_image(d, pm, w, gc, img);
|
||||
XSync(d, 0);
|
||||
{
|
||||
Window fw = 0;
|
||||
int rv = 0;
|
||||
|
||||
XGetInputFocus(d, &fw, &rv);
|
||||
MARK(8) = (unsigned)fw;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
XEvent ev;
|
||||
|
||||
while (XPending(d)) {
|
||||
XNextEvent(d, &ev);
|
||||
MARK(4) = MARK(4) + 1;
|
||||
MARK(9) = (unsigned)ev.type;
|
||||
if (ev.type == KeyPress) {
|
||||
char buf[8];
|
||||
unsigned long ks = 0;
|
||||
int n;
|
||||
|
||||
buf[0] = 0;
|
||||
n = XLookupString(&ev.xkey, buf, 8, &ks, 0);
|
||||
MARK(5) = (unsigned)ev.xkey.keycode;
|
||||
MARK(6) = (unsigned)ks;
|
||||
/* The server may hand back the shifted form. */
|
||||
if (n > 0 && (buf[0] == 'q' || buf[0] == 'Q')) {
|
||||
MARK(3) = 1;
|
||||
break;
|
||||
}
|
||||
} else if (ev.type == ButtonRelease) {
|
||||
Window fw = 0;
|
||||
int rv = 0;
|
||||
|
||||
XGetInputFocus(d, &fw, &rv);
|
||||
MARK(8) = (unsigned)fw;
|
||||
} else if (ev.type == Expose) {
|
||||
present(d, pm, w, gc);
|
||||
}
|
||||
}
|
||||
|
||||
MARK(7) = (unsigned)xerrors;
|
||||
if (MARK(3))
|
||||
break;
|
||||
XFlush(d);
|
||||
vt_sleep(5);
|
||||
}
|
||||
|
||||
/*
|
||||
* Quit: stop serving events, but keep the process alive so the harness can
|
||||
* read the mapped image out of VRAM at LOADER_END. Returning here would
|
||||
* let the firmware tear the process (and its window) down before the read.
|
||||
*/
|
||||
for (;;) {
|
||||
MARK(7) = (unsigned)xerrors;
|
||||
XFlush(d);
|
||||
vt_sleep(5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
; native-entry.asm -- M5 native-object entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the object produced by llc -filetype=obj and writes six markers:
|
||||
; 018A8000 native_value() == 42
|
||||
; 018A8020 native_combo() == 152 (42 + 'n')
|
||||
; 018A8040 native_bump() == 1
|
||||
; 018A8060 native_bump() == 2
|
||||
; 018A8080 native_loop(5) == 10
|
||||
; 018A80A0 native_call_external() == 77
|
||||
;
|
||||
; native_combo() calls native_value() and native_first(); both are .text
|
||||
; symbols, so the CALLAs are same-section 0xFFFF relocations. The
|
||||
; cross-section section-symbol relocation path is exercised by native_first()'s
|
||||
; MOVI to the .data object msg and native_bump()'s MOVI to the .bss object
|
||||
; native_counter. native_loop() carries the conditional/unconditional branch
|
||||
; relocations. native_external() is defined here and is an undefined C_EXT
|
||||
; reference in the llc object. The object is assembled separately with GSPA
|
||||
; 2.00 and the two objects are linked by GSPLNK 2.00.
|
||||
.ref _native_value
|
||||
.ref _native_combo
|
||||
.ref _native_bump
|
||||
.ref _native_loop
|
||||
.ref _native_call_external
|
||||
.text
|
||||
.globl _native_entry
|
||||
_native_entry:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _native_value
|
||||
move a8, @018A8000h, 1
|
||||
calla _native_combo
|
||||
move a8, @018A8020h, 1
|
||||
calla _native_bump
|
||||
move a8, @018A8040h, 1
|
||||
calla _native_bump
|
||||
move a8, @018A8060h, 1
|
||||
move a14, -*sp, 1
|
||||
movi 5, a0
|
||||
move a0, *a14+, 1
|
||||
calla _native_loop
|
||||
move a8, @018A8080h, 1
|
||||
calla _native_call_external
|
||||
move a8, @018A80A0h, 1
|
||||
rets
|
||||
|
||||
.globl _native_external
|
||||
_native_external:
|
||||
; Same prologue/epilogue as an llc-compiled leaf so native_call_external
|
||||
; gets the A14 frame it expects on return.
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
move a13, -*sp, 1
|
||||
move a0, -*sp, 1
|
||||
move a14, a13
|
||||
addi 32, a14
|
||||
move a13, a0
|
||||
addi -32, a0
|
||||
move *a0, a0, 1
|
||||
movi 77, a0
|
||||
move a0, a8
|
||||
move *sp(96), a14, 1
|
||||
move *sp+, a0, 1
|
||||
move *sp+, a13, 1
|
||||
rets 2
|
||||
|
||||
.bss _cstack, 32768, 16
|
||||
.end
|
||||
@@ -0,0 +1,124 @@
|
||||
/* M5 native-link: one translation unit that the native TI-COFF object path
|
||||
* must link with a GSPA entry object.
|
||||
*
|
||||
* native_value() lives in .text and is called from native-entry.asm.
|
||||
* msg is a .data pointer to the "native" string; native_first() loads it with
|
||||
* a cross-section MOVI, so the object needs a .data symbol relocation.
|
||||
* native_combo() calls native_value() and native_first(): both target .text
|
||||
* symbols, so those CALLAs are same-section relocations resolved through the
|
||||
* 0xFFFF section-relative path. A cross-section CALL would need a second code
|
||||
* section, which this writer does not represent; the shared section-symbol
|
||||
* relocation path is exercised by the .data and .bss MOVIs instead.
|
||||
*/
|
||||
|
||||
int native_value(void) { return 42; }
|
||||
|
||||
const char *msg = "native";
|
||||
|
||||
int native_first(void) { return msg[0]; }
|
||||
|
||||
/* Element 1 is at a non-zero .bss offset, so the MOVI relocation field is a
|
||||
* meaningful bit addend rather than an ambiguous zero. */
|
||||
int native_counter[2];
|
||||
|
||||
int native_bump(void) {
|
||||
native_counter[1] = native_counter[1] + 1;
|
||||
return native_counter[1];
|
||||
}
|
||||
|
||||
int native_combo(void) { return native_value() + native_first(); }
|
||||
|
||||
/* A conditional branch and a back edge, so the object carries JAcc/JAUC
|
||||
* relocations that GSPLNK must resolve. The in-range branches here are
|
||||
* relaxed to the one-word JR form; native_far() below keeps the conditional
|
||||
* absolute form covered. */
|
||||
int native_loop(int n) {
|
||||
int s = 0;
|
||||
for (int i = 0; i < n; ++i)
|
||||
s += i;
|
||||
return s;
|
||||
}
|
||||
|
||||
/* A conditional branch whose target is far outside the 127-word one-word
|
||||
* range (about 280 words with 64 volatile reads, so a small codegen change
|
||||
* cannot flip it back): the relaxation cannot use JR, so the object still
|
||||
* carries a conditional JA<cc> relocation. The volatile loads keep the body
|
||||
* from being folded away. */
|
||||
volatile int native_probe;
|
||||
|
||||
int native_far(int a) {
|
||||
int s = 0;
|
||||
if (a) {
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
s += native_probe;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/* Defined by native-entry.asm: an undefined C_EXT section-0 symbol plus the
|
||||
* text relocation that GSPLNK resolves against the entry object. */
|
||||
extern int native_external(int);
|
||||
|
||||
int native_call_external(void) { return native_external(37); }
|
||||
@@ -0,0 +1,16 @@
|
||||
-a
|
||||
-o NATIVE.OUT
|
||||
-m NATIVE.MAP
|
||||
-e _native_entry
|
||||
NATIVE.O ENTRY.O
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 8000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh
|
||||
# M5 native-object compile/link driver.
|
||||
#
|
||||
# scripts/m5/native.sh [xshow|termtris]
|
||||
#
|
||||
# The default mode is `termtris`, so scripts/tests/m4/termtris.sh can use this
|
||||
# script as its TERMTRIS_BUILD hook: it produces $TERMTRIS_WORK/termtris.coff
|
||||
# and termtris.map from the six pinned C TUs compiled with
|
||||
# `llc -filetype=obj` and linked by GSPLNK. The gate then runs the unchanged
|
||||
# play_keys/MAME checks.
|
||||
#
|
||||
# `xshow` builds scripts/m4/xshow.c + xgfix.c through scripts/m4/run.sh with
|
||||
# M4_NATIVE=1, links them with GSPLNK and runs the M4 image/event MAME check.
|
||||
# The asm/GSPA path remains the default of run.sh.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC LLVM_BIN
|
||||
# M5_XSHOW_WORK TERMTRIS_WORK TERMTRIS_SDK VT1200_TERMTRIS
|
||||
# M4_SDK DOSBOX DOSBOX_CONF SDK_IMG MAME LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
MODE=${1:-termtris}
|
||||
DIR=$ROOT/scripts/m4
|
||||
TERMTRIS_DIR=$DIR/termtris
|
||||
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
||||
|
||||
fail() {
|
||||
echo "M5 native driver: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
case $MODE in
|
||||
xshow)
|
||||
WORK=${M5_XSHOW_WORK:-$ROOT/build/m5-native-xshow}
|
||||
M4_NATIVE=1 \
|
||||
M4_SOURCES="xshow xgfix" \
|
||||
M4_ENTRY="$DIR/xshow-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/xshow-check.lua" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_LLC_OPT=-O0 \
|
||||
M4_ROM_SYMBOLS=1 \
|
||||
LOADER_AT=2500 \
|
||||
LOADER_END=3400 \
|
||||
M4_WORK="$WORK" \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
VT1200_MONITOR=VR319 \
|
||||
"$DIR/run.sh"
|
||||
;;
|
||||
termtris)
|
||||
WORK=${TERMTRIS_WORK:-$ROOT/build/m5-native-termtris}
|
||||
SRC=$VENDOR/apps/termtris/src
|
||||
[ -d "$SRC" ] || fail "missing pinned termtris source: $SRC"
|
||||
if git -C "$VENDOR" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
rev=$(git -C "$VENDOR" rev-parse HEAD)
|
||||
[ "$rev" = "be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf" ] \
|
||||
|| fail "vendor tree is $rev, want be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf"
|
||||
fi
|
||||
mkdir -p "$WORK"
|
||||
# cinit.asm is a GSPA entry piece (`.sect ".cinit"`); it is assembled into
|
||||
# the extras object, not compiled by llc. The rts.lib .cinit data makes the
|
||||
# section non-empty, so the empty cinit.asm is sufficient (the asm gate's
|
||||
# CINITZ fallback is only needed when no library contributes .cinit).
|
||||
M4_NATIVE=1 \
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_SOURCES="$SRC/vt1200/main.c $SRC/game.c $SRC/vt1200/scoredb.c $SRC/vt1200/x11.c $SRC/vt1200/compat.c $SRC/vt1200/xgfix.c" \
|
||||
M4_EXTRA_INCLUDES="-I $SRC -I $SRC/vt1200 -I $TERMTRIS_DIR/include" \
|
||||
M4_ENTRY="$SRC/vt1200/entry.asm" \
|
||||
M4_EXTRA_ASM="$SRC/vt1200/cinit.asm" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_LLC_OPT=-O0 \
|
||||
M4_NATIVE_RTS=1 \
|
||||
M4_NATIVE_PROG_LEN=40000h \
|
||||
M4_NATIVE_RAM_LEN=40000h \
|
||||
M4_WORK="$WORK" \
|
||||
M4_COFF="$WORK/termtris.coff" \
|
||||
M4_SDK="${TERMTRIS_SDK:-$WORK/sdk}" \
|
||||
"$DIR/run.sh"
|
||||
# play_keys.sh reads the linker map by name; run.sh writes m4.map.
|
||||
cp "$WORK/m4.map" "$WORK/termtris.map"
|
||||
;;
|
||||
*)
|
||||
fail "unknown mode '$MODE' (want xshow or termtris)"
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,6 @@
|
||||
/* Long private name, TU a: identical in private-long-b.c so the old naming
|
||||
* scheme would truncate the 8-hex module token at GSPA's 31-character limit
|
||||
* and emit the same label in both translation units. */
|
||||
static const char this_is_a_very_long_private_name[] = "same";
|
||||
|
||||
char *a(void) { return (char *)this_is_a_very_long_private_name; }
|
||||
@@ -0,0 +1,6 @@
|
||||
/* Long private name, TU b: deliberately identical to private-long-a.c. The
|
||||
* capped base plus the name hash and module token must keep the two labels
|
||||
* distinct within GSPA's 31-character identifier limit. */
|
||||
static const char this_is_a_very_long_private_name[] = "same";
|
||||
|
||||
char *b(void) { return (char *)this_is_a_very_long_private_name; }
|
||||
Executable
+568
@@ -0,0 +1,568 @@
|
||||
#!/bin/sh
|
||||
# M4 differential TI-compiler check: function pointers and the Xlib image ABI.
|
||||
#
|
||||
# scripts/tests/m4/diff/check.sh
|
||||
#
|
||||
# The stored ti-fnptr.s/ti-image.s are one-time outputs of the 1987 TI
|
||||
# compiler (GSP C Compiler 2.01) under DOSBox. CI never runs DOSBox: this
|
||||
# script greps the stored golden files and compares their ABI shape with the
|
||||
# assembly our compiler emits for the equivalent C.
|
||||
#
|
||||
# The oracle is the ABI shape, not instruction selection:
|
||||
#
|
||||
# apply the old-STK save, one program-stack argument push, a call through
|
||||
# an A register (TI CALL, ours CALL; CALLR is accepted too), and a
|
||||
# last RETS of RETS 2. A direct CALLA in apply is a failure.
|
||||
# test the direct CALLA _apply calls (at least three; TI has three,
|
||||
# ours has four because the fixture calls apply again in the return).
|
||||
# image XCreateImage and XPutImage take ten argument pushes, XCreatePixmap
|
||||
# five, and XCreateSimpleWindow nine. Every call saves old STK.
|
||||
# The first pushes are the last arguments, so the leading constants
|
||||
# are XCreateImage 80,32,480,640; XPutImage 32,640; XCreatePixmap
|
||||
# 1,480,640; XCreateSimpleWindow 0,0,0,480,640. The final push is
|
||||
# the Display pointer, not a constant. This is what makes the
|
||||
# reversed-argument negative control fail.
|
||||
# offsets Display.screens (bit 0x480, byte 0x90), Screen.root (bit 0x40,
|
||||
# byte 0x8), and XImage data/byte_order/bytes_per_line/bits_per_pixel/
|
||||
# f (bits 0x80/0xA0/0x140/0x160/0x200). TI uses the packed direct
|
||||
# displacements; ours materialises an ADDI and the matching load or
|
||||
# store through the same register.
|
||||
#
|
||||
# The plan's "XCreateImage/XPutImage 10/9" is a typo for 10/10: XPutImage is
|
||||
# (display, drawable, gc, image, src_x, src_y, dest_x, dest_y, width, height),
|
||||
# ten arguments. Nine is XCreateSimpleWindow.
|
||||
#
|
||||
# Negative controls run at the end: the check is re-run on a copy of the
|
||||
# fnptr golden with the indirect call removed, on a copy of the image golden
|
||||
# with the XPutImage argument pushes fully reversed, and on a copy with only
|
||||
# the Display and drawable pushes swapped. All must fail. The stored goldens
|
||||
# are never modified.
|
||||
#
|
||||
# Our fnptr source is scripts/m4/fnptr.c (the runtime gate fixture). The image
|
||||
# equivalent is generated here because it needs only the layout declarations.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TI_FNPTR TI_IMAGE
|
||||
# OUR_FNPTR; M4_DIFF_POSITIVE_ONLY=1 skips the negative controls.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
DIR=$ROOT/scripts/tests/m4/diff
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TI_FNPTR=${TI_FNPTR:-$DIR/ti-fnptr.s}
|
||||
TI_IMAGE=${TI_IMAGE:-$DIR/ti-image.s}
|
||||
OUR_FNPTR=${OUR_FNPTR:-$ROOT/scripts/m4/fnptr.c}
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
|
||||
fail() {
|
||||
echo "M4 diff: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$TI_FNPTR" ] || fail "stored TI golden missing: $TI_FNPTR"
|
||||
[ -f "$TI_IMAGE" ] || fail "stored TI golden missing: $TI_IMAGE"
|
||||
[ -f "$OUR_FNPTR" ] || fail "our fnptr source missing: $OUR_FNPTR"
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-diff.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
echo "== compile our fnptr.s and image.s"
|
||||
TMS_CLANG="$TMS_CLANG" TMS_OPT="$TMS_OPT" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -o "$TMP/fnptr.ll" "$OUR_FNPTR"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$TMP/fnptr.ll" -o "$TMP/fnptr.s"
|
||||
|
||||
cat > "$TMP/image.c" <<'EOF'
|
||||
struct display { unsigned char pad[0x90]; void *screens; };
|
||||
struct screen { unsigned char pad[0x8]; unsigned int root; };
|
||||
struct ximage_funcs {
|
||||
void *create_image; void *destroy_image; void *get_pixel;
|
||||
void *put_pixel; void *sub_image; void *add_pixel;
|
||||
};
|
||||
struct ximage {
|
||||
int width, height; int xoffset; int format; char *data; int byte_order;
|
||||
int bitmap_unit; int bitmap_bit_order; int bitmap_pad; int depth;
|
||||
int bytes_per_line; int bits_per_pixel;
|
||||
unsigned long red_mask, green_mask, blue_mask;
|
||||
void *obdata;
|
||||
struct ximage_funcs f;
|
||||
};
|
||||
extern struct display *XOpenDisplay(const char *);
|
||||
extern int XCreateSimpleWindow(struct display *, unsigned int, int, int,
|
||||
unsigned int, unsigned int, unsigned int,
|
||||
unsigned long, unsigned long);
|
||||
extern unsigned int XCreatePixmap(struct display *, unsigned int, unsigned int,
|
||||
unsigned int, unsigned int);
|
||||
extern struct ximage *XCreateImage(struct display *, void *, unsigned int, int,
|
||||
int, char *, unsigned int, unsigned int,
|
||||
int, int);
|
||||
extern int XPutImage(struct display *, unsigned int, void *, struct ximage *,
|
||||
int, int, int, int, unsigned int, unsigned int);
|
||||
extern int XMapWindow(struct display *, unsigned int);
|
||||
extern int XSync(struct display *, int);
|
||||
|
||||
__attribute__((noinline))
|
||||
unsigned int image(struct display *d, unsigned int w, void *gc, char *data) {
|
||||
struct ximage *img;
|
||||
unsigned int root;
|
||||
unsigned int pm;
|
||||
|
||||
root = ((struct screen *)d->screens)->root;
|
||||
img = XCreateImage(d, 0, 1, 0, 0, data, 640, 480, 32, 80);
|
||||
img->byte_order = 0;
|
||||
img->bytes_per_line = 80;
|
||||
img->bits_per_pixel = 1;
|
||||
img->f.create_image = 0;
|
||||
pm = XCreatePixmap(d, w, 640, 480, 1);
|
||||
XPutImage(d, pm, gc, img, 0, 0, 0, 0, 640, 32);
|
||||
img->data = data;
|
||||
XMapWindow(d, w);
|
||||
XSync(d, 0);
|
||||
return root + pm;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
unsigned int window(struct display *d) {
|
||||
unsigned int root = ((struct screen *)d->screens)->root;
|
||||
return XCreateSimpleWindow(d, root, 20, 20, 640, 480, 0, 0, 0);
|
||||
}
|
||||
EOF
|
||||
|
||||
TMS_CLANG="$TMS_CLANG" TMS_OPT="$TMS_OPT" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -o "$TMP/image.ll" "$TMP/image.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$TMP/image.ll" -o "$TMP/image.s"
|
||||
echo " fnptr.s: $(grep -c . "$TMP/fnptr.s") lines, image.s: $(grep -c . "$TMP/image.s") lines"
|
||||
|
||||
# Our llc output has `;` end-of-line comments. Strip them so a comment cannot
|
||||
# satisfy a check; TI asm has none.
|
||||
for f in "$TMP/fnptr.s" "$TMP/image.s"; do
|
||||
sed 's/;.*//' "$f" > "$f.code"
|
||||
done
|
||||
|
||||
# body FILE FUNC: from `_func:` to the next function label or section directive.
|
||||
body() {
|
||||
awk -v want="_$2:" '
|
||||
$1 == want { infn = 1; next }
|
||||
infn {
|
||||
if ($0 ~ /^[[:space:]]*\.(globl|sect|text|bss|data|end|file)/) exit
|
||||
print
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
require() {
|
||||
_file=$1
|
||||
_pat=$2
|
||||
_what=$3
|
||||
if grep -Eiq "$_pat" "$_file"; then
|
||||
echo " ok $_what"
|
||||
return 0
|
||||
fi
|
||||
echo "M4 diff: FAIL: missing $_what" >&2
|
||||
echo " pattern: $_pat" >&2
|
||||
sed 's/^/ /' "$_file" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
require_last_rets2() {
|
||||
if awk '
|
||||
/^[[:space:]]*RETS([[:space:]]|$)/ { last = $0; seen = 1 }
|
||||
END {
|
||||
if (!seen)
|
||||
exit 1
|
||||
exit (last ~ /^[[:space:]]*RETS[[:space:]]+2[[:space:]]*$/) ? 0 : 1
|
||||
}
|
||||
' "$1"; then
|
||||
echo " ok $2"
|
||||
return 0
|
||||
fi
|
||||
echo "M4 diff: FAIL: $2 (last RETS is not RETS 2)" >&2
|
||||
sed 's/^/ /' "$1" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# call_info FILE FUNC CALLEE: one line
|
||||
# "N PUSHES OLDSTK LASTDISP TOKENS..." for the first call to CALLEE in the
|
||||
# function body. Each TOKENS element is a resolved decimal constant for a
|
||||
# push whose source register last held a constant, or X for anything else.
|
||||
# LASTDISP is 1 when the final push's source is the first-argument slot: the
|
||||
# TI golden's `*FP(-32)`, or our register loaded from the ADDI -32 slot.
|
||||
call_info() {
|
||||
body "$1" "$2" | awk -v want="$3" '
|
||||
function isreg(x) { return x ~ /^A([0-9]|1[0-5])$/ }
|
||||
function trim(x) { gsub(/^[[:space:]]+|[[:space:]]+$/, "", x); return x }
|
||||
function unknown(r) { has[r] = 0 }
|
||||
function operands(line, a, n, i) {
|
||||
n = split(line, a, ",")
|
||||
for (i = 1; i <= n; i++)
|
||||
a[i] = trim(a[i])
|
||||
return n
|
||||
}
|
||||
/^[[:space:]]*MOVE[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[[:space:]]*MOVE[[:space:]]+/, "", line)
|
||||
n = operands(line, a)
|
||||
if (n >= 3 && a[2] ~ /^\*(STK|A14)\+$/ && a[3] == "1") {
|
||||
npush++
|
||||
if (isreg(a[1]) && has[a[1]])
|
||||
consts = consts " " val[a[1]]
|
||||
else
|
||||
consts = consts " X"
|
||||
if (a[1] == "*FP(-32)" ||
|
||||
(isreg(a[1]) && hasdisp[a[1]]))
|
||||
lastdisp = 1
|
||||
else
|
||||
lastdisp = 0
|
||||
next
|
||||
}
|
||||
if (n >= 3 && a[2] ~ /^-\*SP$/ && (a[1] == "STK" || a[1] == "A14")) {
|
||||
oldstk = 1
|
||||
next
|
||||
}
|
||||
if (n >= 2 && isreg(a[2])) {
|
||||
dsrc = 0
|
||||
if (a[1] == "*FP(-32)")
|
||||
dsrc = 1
|
||||
else if (a[1] ~ /^\*A[0-9]+$/ && firstaddr[substr(a[1], 2)])
|
||||
dsrc = 1
|
||||
else if (isreg(a[1]) && hasdisp[a[1]])
|
||||
dsrc = 1
|
||||
if (a[1] ~ /^-?[0-9]+$/) {
|
||||
val[a[2]] = a[1]; has[a[2]] = 1; hasdisp[a[2]] = 0
|
||||
} else if (isreg(a[1]) && has[a[1]]) {
|
||||
val[a[2]] = val[a[1]]; has[a[2]] = 1; hasdisp[a[2]] = dsrc
|
||||
} else {
|
||||
has[a[2]] = 0; hasdisp[a[2]] = dsrc
|
||||
}
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*(MOVI|MOVK)[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[[:space:]]*(MOVI|MOVK)[[:space:]]+/, "", line)
|
||||
n = operands(line, a)
|
||||
if (n >= 2 && isreg(a[2]) && a[1] ~ /^-?[0-9]+$/) {
|
||||
val[a[2]] = a[1]; has[a[2]] = 1; hasdisp[a[2]] = 0
|
||||
} else if (n >= 2 && isreg(a[2])) {
|
||||
unknown(a[2])
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CLR[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[[:space:]]*CLR[[:space:]]+/, "", line)
|
||||
if (isreg(trim(line))) {
|
||||
val[trim(line)] = 0; has[trim(line)] = 1
|
||||
hasdisp[trim(line)] = 0
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*SUB[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[[:space:]]*SUB[[:space:]]+/, "", line)
|
||||
n = operands(line, a)
|
||||
if (n >= 2 && isreg(a[2]) && a[1] == a[2]) {
|
||||
val[a[2]] = 0; has[a[2]] = 1; hasdisp[a[2]] = 0
|
||||
} else if (n >= 2 && isreg(a[2])) {
|
||||
unknown(a[2])
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*(ADDK|SUBK)[[:space:]]/ {
|
||||
op = $1
|
||||
line = $0
|
||||
sub(/^[[:space:]]*(ADDK|SUBK)[[:space:]]+/, "", line)
|
||||
n = operands(line, a)
|
||||
if (n >= 2 && isreg(a[2]) && a[1] ~ /^-?[0-9]+$/ && has[a[2]]) {
|
||||
val[a[2]] = val[a[2]] + (op == "ADDK" ? a[1] : -a[1])
|
||||
hasdisp[a[2]] = 0
|
||||
} else if (n >= 2 && isreg(a[2])) {
|
||||
unknown(a[2])
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*ADDI[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[[:space:]]*ADDI[[:space:]]+/, "", line)
|
||||
n = operands(line, a)
|
||||
if (n >= 2 && isreg(a[2])) {
|
||||
unknown(a[2])
|
||||
if (a[1] == "-32")
|
||||
firstaddr[a[2]] = 1
|
||||
else
|
||||
firstaddr[a[2]] = 0
|
||||
}
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CALLA[[:space:]]/ {
|
||||
callee = $2
|
||||
sub(/^_/, "", callee)
|
||||
if (callee == want) {
|
||||
print npush, oldstk, lastdisp, consts
|
||||
exit
|
||||
}
|
||||
npush = 0; oldstk = 0; lastdisp = 0; consts = ""
|
||||
next
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
# check_call FILE FUNC CALLEE NPUSH "CONST PREFIX"
|
||||
check_call() {
|
||||
_file=$1
|
||||
_func=$2
|
||||
_callee=$3
|
||||
_wantn=$4
|
||||
_wantc=$5
|
||||
_info=$(call_info "$_file" "$_func" "$_callee")
|
||||
[ -n "$_info" ] || fail "$_func has no CALLA $_callee"
|
||||
set -- $_info
|
||||
_n=$1
|
||||
_stk=$2
|
||||
_disp=$3
|
||||
shift 3
|
||||
_tokens="$*"
|
||||
[ "$_n" = "$_wantn" ] \
|
||||
|| fail "$_func/$_callee has $_n argument pushes, want $_wantn"
|
||||
[ "$_stk" = 1 ] || fail "$_func/$_callee does not save old STK"
|
||||
case "$_tokens" in
|
||||
"$_wantc "*) ;;
|
||||
*)
|
||||
echo "M4 diff: FAIL: $_func/$_callee leading constants are '$_tokens', want '$_wantc ...'" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
_last=${_tokens##* }
|
||||
[ "$_last" = X ] \
|
||||
|| fail "$_func/$_callee last push looks like a constant, not the Display argument"
|
||||
[ "$_disp" = 1 ] \
|
||||
|| fail "$_func/$_callee last push is not the Display argument (first-argument slot)"
|
||||
echo " ok $_func/$_callee: $_n pushes, old STK, leading [$_wantc], Display last"
|
||||
}
|
||||
|
||||
# check_fnptr FILE WHO TESTFUNC
|
||||
check_fnptr() {
|
||||
_f=$1
|
||||
_who=$2
|
||||
_test=$3
|
||||
body "$_f" apply > "$TMP/apply.body"
|
||||
require "$TMP/apply.body" '^[[:space:]]*CALL(R)?[[:space:]]+A[0-9]+' \
|
||||
"$_who: apply calls through an A register"
|
||||
if grep -Eq '^[[:space:]]*CALLA[[:space:]]' "$TMP/apply.body"; then
|
||||
sed 's/^/ /' "$TMP/apply.body" >&2
|
||||
fail "$_who: apply still contains a direct CALLA"
|
||||
fi
|
||||
require "$TMP/apply.body" '^[[:space:]]*MOVE[[:space:]]+(STK|A14),[[:space:]]*-\*SP' \
|
||||
"$_who: apply saves the old STK"
|
||||
require "$TMP/apply.body" \
|
||||
'^[[:space:]]*MOVE[[:space:]]+[^,]+,[[:space:]]*\*(STK|A14)\+,[[:space:]]*1' \
|
||||
"$_who: apply pushes the callback argument"
|
||||
require_last_rets2 "$TMP/apply.body" "$_who: apply ends with RETS 2"
|
||||
|
||||
body "$_f" "$_test" > "$TMP/$_test.body"
|
||||
_calls=$(grep -Ec '^[[:space:]]*CALLA[[:space:]]+_apply' "$TMP/$_test.body" || true)
|
||||
[ "$_calls" -ge 3 ] \
|
||||
|| { sed 's/^/ /' "$TMP/$_test.body" >&2; fail "$_who: $_test makes $_calls direct CALLA _apply calls, want at least 3"; }
|
||||
echo " ok $_who: $_test makes $_calls direct CALLA _apply calls (want >= 3)"
|
||||
}
|
||||
|
||||
# has_addi_access FILE KIND DISP: an ADDI DISP,REG immediately followed by a
|
||||
# MOVE that uses *REG as a load (KIND=load) or store destination (KIND=store).
|
||||
has_addi_access() {
|
||||
awk -v kind="$2" -v disp="$3" '
|
||||
function disp_ok(d) {
|
||||
if (d == disp) return 1
|
||||
if (disp == "1152" && (d == "0x480" || d == "480h")) return 1
|
||||
if (disp == "64" && (d == "0x40" || d == "40h")) return 1
|
||||
if (disp == "128" && (d == "0x80" || d == "80h")) return 1
|
||||
if (disp == "160" && (d == "0xA0" || d == "0a0h")) return 1
|
||||
if (disp == "320" && (d == "0x140" || d == "140h")) return 1
|
||||
if (disp == "352" && (d == "0x160" || d == "160h")) return 1
|
||||
if (disp == "512" && (d == "0x200" || d == "200h")) return 1
|
||||
return 0
|
||||
}
|
||||
/^[[:space:]]*ADDI[[:space:]]/ {
|
||||
line = $0
|
||||
sub(/^[[:space:]]*ADDI[[:space:]]+/, "", line)
|
||||
split(line, f, /[[:space:]]*,[[:space:]]*/)
|
||||
d = f[1]
|
||||
reg = f[2]
|
||||
if (!disp_ok(d))
|
||||
next
|
||||
if (getline nxt <= 0)
|
||||
next
|
||||
while (nxt ~ /^[[:space:]]*$/) {
|
||||
if (getline nxt <= 0)
|
||||
next
|
||||
}
|
||||
if (kind == "load" &&
|
||||
nxt ~ ("^[[:space:]]*MOVE[[:space:]]+\\*" reg "([,\\(]|[[:space:]]|$)"))
|
||||
found = 1
|
||||
if (kind == "store" &&
|
||||
nxt ~ ("^[[:space:]]*MOVE[[:space:]]+[^,]+, ?\\*" reg "([,\\(]|[[:space:]]|$)"))
|
||||
found = 1
|
||||
}
|
||||
END { exit found ? 0 : 1 }
|
||||
' "$1"
|
||||
}
|
||||
|
||||
check_offsets() {
|
||||
_f=$1
|
||||
_who=$2
|
||||
_side=$3
|
||||
body "$_f" image > "$TMP/image.body"
|
||||
if [ "$_side" = ti ]; then
|
||||
require "$TMP/image.body" \
|
||||
'^[[:space:]]*MOVE[[:space:]]+\*(A[0-9]+|FP|SP)\((1152|0x480|480h)\),' \
|
||||
"$_who: Display.screens is loaded at bit 0x480 (byte 0x90)"
|
||||
require "$TMP/image.body" \
|
||||
'^[[:space:]]*MOVE[[:space:]]+\*(A[0-9]+|FP|SP)\((64|0x40|40h)\),[[:space:]]*\*(A[0-9]+|FP|SP)\([0-9]+\)' \
|
||||
"$_who: Screen.root is loaded at bit 0x40 (byte 0x8)"
|
||||
for pair in 128:data 160:byte_order 320:bytes_per_line 352:bits_per_pixel 512:f; do
|
||||
d=${pair%%:*}
|
||||
name=${pair##*:}
|
||||
case "$d" in
|
||||
128) pat='(128|0x80|80h)' ;;
|
||||
160) pat='(160|0xA0|0a0h)' ;;
|
||||
320) pat='(320|0x140|140h)' ;;
|
||||
352) pat='(352|0x160|160h)' ;;
|
||||
512) pat='(512|0x200|200h)' ;;
|
||||
esac
|
||||
require "$TMP/image.body" \
|
||||
"^[[:space:]]*MOVE[[:space:]]+.*\\*A[0-9]+\\($pat\\)," \
|
||||
"$_who: XImage.$name is at bit $d"
|
||||
done
|
||||
return 0
|
||||
fi
|
||||
for pair in load:1152:screens load:64:root store:128:data store:160:byte_order \
|
||||
store:320:bytes_per_line store:352:bits_per_pixel store:512:f; do
|
||||
kind=${pair%%:*}
|
||||
rest=${pair#*:}
|
||||
d=${rest%%:*}
|
||||
name=${rest##*:}
|
||||
if has_addi_access "$TMP/image.body" "$kind" "$d"; then
|
||||
echo " ok $_who: XImage/Display/Screen $name access at bit $d (ADDI + $kind)"
|
||||
else
|
||||
sed 's/^/ /' "$TMP/image.body" >&2
|
||||
fail "$_who: no $kind through bit displacement $d for $name"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# check_image FILE WHO TI|ours
|
||||
check_image() {
|
||||
_f=$1
|
||||
_who=$2
|
||||
_side=$3
|
||||
check_call "$_f" image XCreateImage 10 "80 32 480 640"
|
||||
check_call "$_f" image XCreatePixmap 5 "1 480 640"
|
||||
check_call "$_f" image XPutImage 10 "32 640"
|
||||
check_call "$_f" window XCreateSimpleWindow 9 "0 0 0 480 640"
|
||||
body "$_f" image > "$TMP/rets.body"
|
||||
require_last_rets2 "$TMP/rets.body" "$_who: image ends with RETS 2"
|
||||
body "$_f" window > "$TMP/rets2.body"
|
||||
require_last_rets2 "$TMP/rets2.body" "$_who: window ends with RETS 2"
|
||||
check_offsets "$_f" "$_who" "$_side"
|
||||
}
|
||||
|
||||
echo "== ABI shape: TI fnptr golden"
|
||||
check_fnptr "$TI_FNPTR" "TI" test
|
||||
echo "== ABI shape: our fnptr"
|
||||
check_fnptr "$TMP/fnptr.s.code" "ours" fnptr_test
|
||||
|
||||
echo "== ABI shape: TI image golden"
|
||||
check_image "$TI_IMAGE" "TI" ti
|
||||
echo "== ABI shape: our image"
|
||||
check_image "$TMP/image.s.code" "ours" ours
|
||||
|
||||
if [ "${M4_DIFF_POSITIVE_ONLY:-0}" = 1 ]; then
|
||||
echo "M4 diff: PASS"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "== negative controls"
|
||||
# 1. Remove the indirect call from the fnptr golden: apply must then fail.
|
||||
sed 's/^[[:space:]]*CALL[[:space:]].*/ CALLA _dec/' "$TI_FNPTR" \
|
||||
> "$TMP/fnptr-no-indirect.s"
|
||||
grep -q 'CALLA _dec' "$TMP/fnptr-no-indirect.s" \
|
||||
|| fail "could not construct the no-indirect-call fnptr golden"
|
||||
if M4_DIFF_POSITIVE_ONLY=1 TI_FNPTR="$TMP/fnptr-no-indirect.s" \
|
||||
"$0" > "$TMP/neg-fnptr.out" 2>&1; then
|
||||
sed 's/^/ /' "$TMP/neg-fnptr.out" >&2
|
||||
fail "check accepted a fnptr golden without the indirect call"
|
||||
fi
|
||||
echo " ok negative control: fnptr without the indirect call rejected"
|
||||
grep 'M4 diff: FAIL' "$TMP/neg-fnptr.out" | head -1 | sed 's/^/ /'
|
||||
|
||||
# 2. Reverse the ten XPutImage argument pushes: Display must no longer be the
|
||||
# last push and the leading constants must change.
|
||||
awk '
|
||||
{ lines[NR] = $0 }
|
||||
/^[[:space:]]*MOVE[[:space:]]+[^,]+,[[:space:]]*\*STK\+,[[:space:]]*1[[:space:]]*$/ {
|
||||
npush++
|
||||
pos[npush] = NR
|
||||
push[npush] = $0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CALLA[[:space:]]+_XPutImage/ {
|
||||
for (i = 1; i <= npush; i++)
|
||||
lines[pos[i]] = push[npush - i + 1]
|
||||
npush = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CALLA[[:space:]]/ { npush = 0; next }
|
||||
END { for (i = 1; i <= NR; i++) print lines[i] }
|
||||
' "$TI_IMAGE" > "$TMP/image-reversed.s"
|
||||
if cmp -s "$TI_IMAGE" "$TMP/image-reversed.s"; then
|
||||
fail "reversed-argument mutation did not change the image golden"
|
||||
fi
|
||||
if M4_DIFF_POSITIVE_ONLY=1 TI_IMAGE="$TMP/image-reversed.s" \
|
||||
"$0" > "$TMP/neg-image.out" 2>&1; then
|
||||
sed 's/^/ /' "$TMP/neg-image.out" >&2
|
||||
fail "check accepted the reversed XPutImage argument order"
|
||||
fi
|
||||
echo " ok negative control: reversed XPutImage arguments rejected"
|
||||
grep 'M4 diff: FAIL' "$TMP/neg-image.out" | head -1 | sed 's/^/ /'
|
||||
|
||||
# 3. Swap only the last two XPutImage pushes (Display and drawable). The
|
||||
# leading constants and the non-constant last-token rule still hold, so
|
||||
# only the first-argument (Display) check can reject this.
|
||||
awk '
|
||||
{ lines[NR] = $0 }
|
||||
/^[[:space:]]*MOVE[[:space:]]+[^,]+,[[:space:]]*\*STK\+,[[:space:]]*1[[:space:]]*$/ {
|
||||
npush++
|
||||
pos[npush] = NR
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CALLA[[:space:]]+_XPutImage/ {
|
||||
if (npush >= 2) {
|
||||
tmp = lines[pos[npush]]
|
||||
lines[pos[npush]] = lines[pos[npush - 1]]
|
||||
lines[pos[npush - 1]] = tmp
|
||||
}
|
||||
npush = 0
|
||||
next
|
||||
}
|
||||
/^[[:space:]]*CALLA[[:space:]]/ { npush = 0; next }
|
||||
END { for (i = 1; i <= NR; i++) print lines[i] }
|
||||
' "$TI_IMAGE" > "$TMP/image-swapped.s"
|
||||
if cmp -s "$TI_IMAGE" "$TMP/image-swapped.s"; then
|
||||
fail "Display/drawable swap mutation did not change the image golden"
|
||||
fi
|
||||
if M4_DIFF_POSITIVE_ONLY=1 TI_IMAGE="$TMP/image-swapped.s" \
|
||||
"$0" > "$TMP/neg-swap.out" 2>&1; then
|
||||
sed 's/^/ /' "$TMP/neg-swap.out" >&2
|
||||
fail "check accepted the Display/drawable push swap"
|
||||
fi
|
||||
echo " ok negative control: Display swapped with the drawable rejected"
|
||||
grep 'M4 diff: FAIL' "$TMP/neg-swap.out" | head -1 | sed 's/^/ /'
|
||||
|
||||
echo "M4 diff: PASS"
|
||||
@@ -0,0 +1,33 @@
|
||||
/* K&R source for the M4 differential function-pointer golden.
|
||||
*
|
||||
* The 1987 TI compiler (GSP C Compiler 2.01) does not accept a typedef for a
|
||||
* function pointer, nor the volatile qualifier on the local, so the callback
|
||||
* is spelled as a plain `int (*f)()` parameter and the local pointer is
|
||||
* unqualified. `apply` is the call-through-pointer proof: the caller pushes
|
||||
* `x` and the callback, saves STK, and calls through the loaded pointer (TI
|
||||
* `CALL A7`, ours `CALL A?`). The direct calls to `apply` from `test()` stay
|
||||
* `CALLA _apply`.
|
||||
*/
|
||||
int inc(x) int x; { return x + 1; }
|
||||
int dec(x) int x; { return x - 1; }
|
||||
|
||||
int apply(f, x)
|
||||
int (*f)();
|
||||
int x;
|
||||
{
|
||||
return (*f)(x);
|
||||
}
|
||||
|
||||
int (*g_dec)() = dec;
|
||||
|
||||
int test()
|
||||
{
|
||||
int (*vf)();
|
||||
int a;
|
||||
int b;
|
||||
|
||||
vf = inc;
|
||||
a = apply(inc, 41);
|
||||
b = apply(vf, 41);
|
||||
return apply(g_dec, 43) + a + b;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
*******************************************************
|
||||
* GSP C COMPILER, Version 2.01, 87.300 *
|
||||
*******************************************************
|
||||
FP .set A13
|
||||
STK .set A14
|
||||
.globl _inc
|
||||
.file "TI-FNPTR.c"
|
||||
******************************************************
|
||||
* FUNCTION DEF : _inc
|
||||
******************************************************
|
||||
_inc:
|
||||
MMTM SP,A7,FP
|
||||
MOVE STK,FP
|
||||
MOVE *FP(-32),A7,1
|
||||
ADDK 1,A7
|
||||
MOVE A7,A8
|
||||
EPI0_1:
|
||||
MOVE *SP(96),STK,1
|
||||
MMFM SP,A7,FP
|
||||
RETS 2
|
||||
.globl _dec
|
||||
******************************************************
|
||||
* FUNCTION DEF : _dec
|
||||
******************************************************
|
||||
_dec:
|
||||
MMTM SP,A7,FP
|
||||
MOVE STK,FP
|
||||
MOVE *FP(-32),A7,1
|
||||
SUBK 1,A7
|
||||
MOVE A7,A8
|
||||
EPI0_2:
|
||||
MOVE *SP(96),STK,1
|
||||
MMFM SP,A7,FP
|
||||
RETS 2
|
||||
.globl _apply
|
||||
******************************************************
|
||||
* FUNCTION DEF : _apply
|
||||
******************************************************
|
||||
_apply:
|
||||
MMTM SP,A7,FP
|
||||
MOVE STK,FP
|
||||
MOVE STK,-*SP,1
|
||||
MOVE *FP(-64),*STK+,1
|
||||
MOVE *FP(-32),A7,1
|
||||
CALL A7
|
||||
EPI0_3:
|
||||
MOVE *SP(96),STK,1
|
||||
MMFM SP,A7,FP
|
||||
RETS 2
|
||||
|
||||
.sect ".cinit"
|
||||
.word IS1
|
||||
.long _g_dec+0
|
||||
.field _dec+0,32
|
||||
IS1 .set 2
|
||||
.text
|
||||
.globl _g_dec
|
||||
.bss _g_dec,32,16
|
||||
.globl _test
|
||||
******************************************************
|
||||
* FUNCTION DEF : _test
|
||||
******************************************************
|
||||
_test:
|
||||
MMTM SP,A0,A5,A7,A12,FP
|
||||
MOVE STK,FP
|
||||
ADDI 96,STK
|
||||
MOVI _inc,A0
|
||||
MOVE A0,*FP,1
|
||||
MOVE STK,-*SP,1
|
||||
MOVI 41,A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVE A0,*STK+,1
|
||||
CALLA _apply
|
||||
MOVE A8,*FP(32),1
|
||||
MOVE STK,-*SP,1
|
||||
MOVE A12,*STK+,1
|
||||
MOVE *FP(0),*STK+,1
|
||||
CALLA _apply
|
||||
MOVE A8,*FP(64),1
|
||||
MOVE STK,-*SP,1
|
||||
ADDK 2,A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVE @_g_dec,*STK+,1
|
||||
CALLA _apply
|
||||
MOVE A8,A7
|
||||
MOVE *FP(32),A5,1
|
||||
ADD A5,A7
|
||||
MOVE *FP(64),A5,1
|
||||
ADD A5,A7
|
||||
MOVE A7,A8
|
||||
EPI0_4:
|
||||
ADDI -96,STK
|
||||
MMFM SP,A0,A5,A7,A12,FP
|
||||
RETS 0
|
||||
.end
|
||||
@@ -0,0 +1,86 @@
|
||||
/* K&R source for the M4 differential Xlib-image golden.
|
||||
*
|
||||
* It models the X11R4 32-bit XImage/Display/Screen layout and the ten-argument
|
||||
* XCreateImage/XPutImage, five-argument XCreatePixmap and nine-argument
|
||||
* XCreateSimpleWindow calls. The 1987 TI compiler packs struct members and
|
||||
* its &-of-member is already a bit address, so the golden carries the ROM
|
||||
* bit displacements directly: Display.screens 1152 (byte 0x90), Screen.root
|
||||
* 64 (byte 0x8), and XImage data/byte_order/bytes_per_line/bits_per_pixel/f
|
||||
* 128/160/320/352/512 (bytes 16/20/40/44/64).
|
||||
*/
|
||||
struct display {
|
||||
char pad[0x90];
|
||||
void *screens;
|
||||
};
|
||||
|
||||
struct screen {
|
||||
char pad[0x8];
|
||||
unsigned int root;
|
||||
};
|
||||
|
||||
struct ximage_funcs {
|
||||
void *create_image;
|
||||
void *destroy_image;
|
||||
void *get_pixel;
|
||||
void *put_pixel;
|
||||
void *sub_image;
|
||||
void *add_pixel;
|
||||
};
|
||||
|
||||
struct ximage {
|
||||
int width, height;
|
||||
int xoffset;
|
||||
int format;
|
||||
char *data;
|
||||
int byte_order;
|
||||
int bitmap_unit;
|
||||
int bitmap_bit_order;
|
||||
int bitmap_pad;
|
||||
int depth;
|
||||
int bytes_per_line;
|
||||
int bits_per_pixel;
|
||||
unsigned long red_mask, green_mask, blue_mask;
|
||||
void *obdata;
|
||||
struct ximage_funcs f;
|
||||
};
|
||||
|
||||
extern struct display *XOpenDisplay();
|
||||
extern int XCreateSimpleWindow();
|
||||
extern unsigned int XCreatePixmap();
|
||||
extern struct ximage *XCreateImage();
|
||||
extern int XPutImage();
|
||||
extern int XMapWindow();
|
||||
extern int XSync();
|
||||
|
||||
int image(d, w, gc, data)
|
||||
struct display *d;
|
||||
unsigned int w;
|
||||
void *gc;
|
||||
char *data;
|
||||
{
|
||||
struct ximage *img;
|
||||
unsigned int root;
|
||||
unsigned int pm;
|
||||
|
||||
root = ((struct screen *)d->screens)->root;
|
||||
img = XCreateImage(d, 0, 1, 0, 0, data, 640, 480, 32, 80);
|
||||
img->byte_order = 0;
|
||||
img->bytes_per_line = 80;
|
||||
img->bits_per_pixel = 1;
|
||||
img->f.create_image = 0;
|
||||
pm = XCreatePixmap(d, w, 640, 480, 1);
|
||||
XPutImage(d, pm, gc, img, 0, 0, 0, 0, 640, 32);
|
||||
img->data = data;
|
||||
XMapWindow(d, w);
|
||||
XSync(d, 0);
|
||||
return root + pm;
|
||||
}
|
||||
|
||||
int window(d)
|
||||
struct display *d;
|
||||
{
|
||||
unsigned int root;
|
||||
|
||||
root = ((struct screen *)d->screens)->root;
|
||||
return XCreateSimpleWindow(d, root, 20, 20, 640, 480, 0, 0, 0);
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
*******************************************************
|
||||
* GSP C COMPILER, Version 2.01, 87.300 *
|
||||
*******************************************************
|
||||
FP .set A13
|
||||
STK .set A14
|
||||
.globl _XOpenDisplay
|
||||
.globl _XCreateSimpleWindow
|
||||
.globl _XCreatePixmap
|
||||
.globl _XCreateImage
|
||||
.globl _XPutImage
|
||||
.globl _XMapWindow
|
||||
.globl _XSync
|
||||
.globl _image
|
||||
.file "TI-IMAGE.c"
|
||||
******************************************************
|
||||
* FUNCTION DEF : _image
|
||||
******************************************************
|
||||
_image:
|
||||
MMTM SP,A5,A7,A12,FP
|
||||
MOVE STK,FP
|
||||
ADDI 96,STK
|
||||
MOVE *FP(-32),A7,1
|
||||
MOVE *A7(1152),A7,1
|
||||
MOVE *A7(64),*FP(32),1
|
||||
MOVE STK,-*SP,1
|
||||
MOVI 80,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVK 32,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVI 480,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVI 640,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVE *FP(-128),*STK+,1
|
||||
CLR A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVE A7,*STK+,1
|
||||
ADDK 1,A7
|
||||
MOVE A7,*STK+,1
|
||||
SUB A7,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVE *FP(-32),*STK+,1
|
||||
CALLA _XCreateImage
|
||||
MOVE A8,*FP,1
|
||||
MOVE *FP,A7,1
|
||||
CLR A12
|
||||
MOVE A12,*A7(160),1
|
||||
MOVI 80,A12
|
||||
MOVE A12,*A7(320),1
|
||||
MOVK 1,A12
|
||||
MOVE A12,*A7(352),1
|
||||
SUB A12,A12
|
||||
MOVE A12,*A7(512),1
|
||||
MOVE STK,-*SP,1
|
||||
ADDK 1,A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVI 480,A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVI 640,A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVE *FP(-64),*STK+,1
|
||||
MOVE *FP(-32),*STK+,1
|
||||
CALLA _XCreatePixmap
|
||||
MOVE A8,*FP(64),1
|
||||
MOVE STK,-*SP,1
|
||||
MOVK 32,A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVI 640,A12
|
||||
MOVE A12,*STK+,1
|
||||
CLR A12
|
||||
MOVE A12,*STK+,1
|
||||
MOVE A12,*STK+,1
|
||||
MOVE A12,*STK+,1
|
||||
MOVE A12,*STK+,1
|
||||
MOVE A7,*STK+,1
|
||||
MOVE *FP(-96),*STK+,1
|
||||
MOVE *FP(64),*STK+,1
|
||||
MOVE *FP(-32),*STK+,1
|
||||
CALLA _XPutImage
|
||||
MOVE *FP(-128),*A7(128),1
|
||||
MOVE STK,-*SP,1
|
||||
MOVE *FP(-64),*STK+,1
|
||||
MOVE *FP(-32),*STK+,1
|
||||
CALLA _XMapWindow
|
||||
MOVE STK,-*SP,1
|
||||
MOVE A12,*STK+,1
|
||||
MOVE *FP(-32),*STK+,1
|
||||
CALLA _XSync
|
||||
MOVE *FP(32),A7,1
|
||||
MOVE *FP(64),A5,1
|
||||
ADD A5,A7
|
||||
MOVE A7,A8
|
||||
EPI0_1:
|
||||
MOVE *SP(160),STK,1
|
||||
MMFM SP,A5,A7,A12,FP
|
||||
RETS 2
|
||||
.globl _window
|
||||
******************************************************
|
||||
* FUNCTION DEF : _window
|
||||
******************************************************
|
||||
_window:
|
||||
MMTM SP,A7,FP
|
||||
MOVE STK,FP
|
||||
ADDK 32,STK
|
||||
MOVE *FP(-32),A7,1
|
||||
MOVE *A7(1152),A7,1
|
||||
MOVE *A7(64),*FP(0),1
|
||||
MOVE STK,-*SP,1
|
||||
CLR A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVE A7,*STK+,1
|
||||
MOVE A7,*STK+,1
|
||||
MOVI 480,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVI 640,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVK 20,A7
|
||||
MOVE A7,*STK+,1
|
||||
MOVE A7,*STK+,1
|
||||
MOVE *FP(0),*STK+,1
|
||||
MOVE *FP(-32),*STK+,1
|
||||
CALLA _XCreateSimpleWindow
|
||||
EPI0_2:
|
||||
MOVE *SP(96),STK,1
|
||||
MMFM SP,A7,FP
|
||||
RETS 2
|
||||
.end
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# M4 dis34 gate: rebuild the image client through the normal GSPA/GSPLNK path,
|
||||
# then verify the ROM import stubs, the direct/indirect call encodings,
|
||||
# XCreateSimpleWindow's nine-argument order, the XSetErrorHandler callback,
|
||||
# SETF/RETS/old-STK, and the checker .bss.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_XSHOW_WORK:-$ROOT/build/m4-xshow}
|
||||
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_SOURCES="xshow xgfix" \
|
||||
M4_ENTRY="$DIR/xshow-entry.asm" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_ROM_SYMBOLS=1 \
|
||||
M4_WORK="$WORK" \
|
||||
"$ROOT/scripts/m4/run.sh"
|
||||
|
||||
M4_WORK="$WORK" exec "$ROOT/scripts/m4/dis-roundtrip.sh"
|
||||
Executable
+159
@@ -0,0 +1,159 @@
|
||||
#!/bin/sh
|
||||
# M4 function-pointer/indirect-call gate: compile fnptr.c with the default
|
||||
# tms-clang -O2 pipeline, link with GSPA/GSPLNK, run in MAME and check that all
|
||||
# four markers are 42. The linked assembly must call through an A register in
|
||||
# _apply (CALL, not CALLA) while _fnptr_test still makes the direct CALLA to
|
||||
# apply and materialises inc's address with MOVI. dis34 must decode the
|
||||
# indirect call as `call aN` at the linked address.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_FNPTR_WORK:-$ROOT/build/m4-fnptr}
|
||||
COFF=$WORK/m4.coff
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
|
||||
fail() {
|
||||
echo "m4 fnptr: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
M4_SOURCES=fnptr \
|
||||
M4_ENTRY="$DIR/fnptr-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/fnptr-check.lua" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_WORK="$WORK" \
|
||||
M4_COFF="$COFF" \
|
||||
"$ROOT/scripts/m4/run.sh" || fail "M4 function-pointer run failed"
|
||||
|
||||
ASM=$WORK/m4.asm
|
||||
MAP=$WORK/m4.map
|
||||
[ -f "$ASM" ] || fail "linked assembly not found: $ASM"
|
||||
[ -f "$MAP" ] || fail "linker map not found: $MAP"
|
||||
|
||||
EXPECTED="M4: fnptr=42 fnptr_volatile=42 fnptr_global=42 fnptr_ret=42"
|
||||
grep -Fqx "$EXPECTED" "$WORK/mame.log" \
|
||||
|| { grep -E '^M4: ' "$WORK/mame.log" >&2 || true; fail "runtime markers did not match: $EXPECTED"; }
|
||||
echo " ok runtime markers: $EXPECTED"
|
||||
|
||||
# Stop at the next function label (a column-0 label that is not an LBB block
|
||||
# label), so a following local function cannot leak into this slice.
|
||||
body() { # body FILE FUNC
|
||||
awk -v want="_$2:" '
|
||||
$1 == want { infn = 1; next }
|
||||
infn {
|
||||
if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]*:/ && $0 !~ /^LBB/) exit
|
||||
print
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-fnptr.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
for fn in inc dec apply fnptr_test; do
|
||||
body "$ASM" "$fn" > "$TMP/$fn.s"
|
||||
[ -s "$TMP/$fn.s" ] || fail "linked assembly has no _$fn body"
|
||||
done
|
||||
|
||||
check_seq() { # check_seq FILE ERE... : each pattern in order
|
||||
_file=$1
|
||||
shift
|
||||
_last=0
|
||||
for _pat in "$@"; do
|
||||
_line=$(awk -v start="$_last" -v pat="$_pat" '
|
||||
NR > start && $0 ~ pat { print NR; exit }
|
||||
' "$_file")
|
||||
[ -n "$_line" ] || {
|
||||
sed 's/^/ /' "$_file" >&2
|
||||
fail "_${_file##*/} is missing sequence /$_pat/"
|
||||
}
|
||||
_last=$_line
|
||||
done
|
||||
}
|
||||
|
||||
# apply receives the callback in a stack slot: the target is loaded/copied into
|
||||
# an allocatable A register after the argument push, then called with the
|
||||
# one-word register call. It must not become a direct CALLA.
|
||||
if grep -Eq '^[[:space:]]*CALLA[[:space:]]' "$TMP/apply.s"; then
|
||||
sed 's/^/ /' "$TMP/apply.s" >&2
|
||||
fail "_apply still contains a direct CALLA"
|
||||
fi
|
||||
check_seq "$TMP/apply.s" \
|
||||
'MOVE A14, -\*SP, 1' \
|
||||
'MOVE .*\*A14\+, 1' \
|
||||
'^[[:space:]]*CALL A[0-9]+' \
|
||||
'SETF 32, 0, 1' \
|
||||
'MOVE \*SP\(.*\), A14, 1' \
|
||||
'RETS 2'
|
||||
echo " ok _apply: old-STK, argument push, CALL A?, SETF, old-STK reload, RETS 2"
|
||||
|
||||
# Passing inc as an argument is a MOVI of the global symbol; the calls to the
|
||||
# helper itself remain the direct CALLA path. The global function pointer is
|
||||
# a .data word holding dec's bit address and is loaded at runtime.
|
||||
check_seq "$TMP/fnptr_test.s" 'MOVI _inc, A[0-9]+' 'CALLA _apply'
|
||||
if [ "$(grep -Ec '^[[:space:]]*CALLA _apply' "$TMP/fnptr_test.s")" -lt 3 ]; then
|
||||
sed 's/^/ /' "$TMP/fnptr_test.s" >&2
|
||||
fail "_fnptr_test does not make all three direct CALLA _apply calls"
|
||||
fi
|
||||
grep -Eq '^[[:space:]]*MOVI _g_fn[A-Za-z0-9_]*, A[0-9]+' "$TMP/fnptr_test.s" \
|
||||
|| { sed 's/^/ /' "$TMP/fnptr_test.s" >&2; fail "_fnptr_test does not load the global function pointer"; }
|
||||
grep -Fq '.long _dec' "$ASM" \
|
||||
|| { grep -n '\.long' "$ASM" >&2 || true; fail "the .data function pointer does not hold _dec"; }
|
||||
echo " ok _fnptr_test: MOVI _inc + three direct CALLA _apply, loads _g_fn, .long _dec"
|
||||
|
||||
# Reassemble-time evidence: GSPA 2.00 accepted the uppercase CALL A? spelling
|
||||
# (it rejects CALL $A?) and encoded it as the one-word 0x0920 form. The
|
||||
# listing shows the opcode word next to the instruction.
|
||||
grep -Eq '^[[:space:]]*[0-9]+[[:space:]]+[0-9A-F]+[[:space:]]+0920[[:space:]]+CALL[[:space:]]+A[0-9]+' "$WORK/m4.lst" \
|
||||
|| { grep -i 'call' "$WORK/m4.lst" >&2 || true; fail "GSPA listing has no 0x0920 CALL A?"; }
|
||||
echo " ok GSPA listing encoded CALL A? as 0x0920"
|
||||
|
||||
# dis34 evidence at the linked address: _apply's indirect call decodes as
|
||||
# `call aN` (the disassembler's spelling for CALL Rs).
|
||||
[ -x "$DIS34" ] || fail "dis34 not executable: $DIS34"
|
||||
APPLY_ADDR=$(awk '$1 == "_apply" { print $2; exit } $2 == "_apply" { print $1; exit }' "$MAP")
|
||||
[ -n "$APPLY_ADDR" ] || fail "linker map has no _apply symbol"
|
||||
|
||||
read_u8s() { od -An -v -tu1 -j "$1" -N "$2" "$COFF"; }
|
||||
u16() { read_u8s "$1" 2 | awk '{ print $1 + 256 * $2 }'; }
|
||||
u32() { read_u8s "$1" 4 | awk '{ print $1 + 256 * $2 + 65536 * $3 + 16777216 * $4 }'; }
|
||||
|
||||
nscns=$(u16 2)
|
||||
opthdr=$(u16 16)
|
||||
TEXT_ADDR=
|
||||
TEXT_BITS=
|
||||
TEXT_PTR=
|
||||
sh_base=$((20 + opthdr))
|
||||
i=0
|
||||
while [ "$i" -lt "$nscns" ]; do
|
||||
o=$((sh_base + i * 40))
|
||||
name=$(dd if="$COFF" bs=1 skip="$o" count=8 2>/dev/null | tr -d '\000')
|
||||
if [ "$name" = ".text" ]; then
|
||||
TEXT_ADDR=$(u32 $((o + 8)))
|
||||
TEXT_BITS=$(u32 $((o + 16)))
|
||||
TEXT_PTR=$(u32 $((o + 20)))
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
[ -n "$TEXT_ADDR" ] || fail "COFF has no .text section"
|
||||
[ $((TEXT_BITS % 8)) -eq 0 ] || fail ".text size $TEXT_BITS bits is not whole bytes"
|
||||
TEXT_HEX=$(printf '%08X' "$TEXT_ADDR")
|
||||
TEXT_BYTES=$((TEXT_BITS / 8))
|
||||
dd if="$COFF" of="$TMP/text.bin" bs=1 skip="$TEXT_PTR" count="$TEXT_BYTES" 2>/dev/null
|
||||
[ "$(wc -c < "$TMP/text.bin")" -eq "$TEXT_BYTES" ] || fail "could not extract .text"
|
||||
|
||||
"$DIS34" -b "$TEXT_HEX" -l -o "$TMP/text.bin" > "$TMP/dis34.txt" 2> "$TMP/dis34.err" \
|
||||
|| { cat "$TMP/dis34.err" >&2; fail "dis34 failed"; }
|
||||
APPLY_L=$(printf '%s' "$APPLY_ADDR" | tr 'A-F' 'a-f')
|
||||
awk -v a="$APPLY_L" '
|
||||
{ low = tolower($0) }
|
||||
low ~ ("^" a ":") { on = 1 }
|
||||
on { print }
|
||||
on && low ~ /^[0-9a-f]+:[[:space:]]+rets([[:space:]]|;|$)/ { exit }
|
||||
' "$TMP/dis34.txt" > "$TMP/apply.dis"
|
||||
grep -Eq '^[0-9a-f]+:[[:space:]]+call[[:space:]]+a[0-9]+' "$TMP/apply.dis" \
|
||||
|| { sed 's/^/ /' "$TMP/apply.dis" >&2; fail "dis34 does not decode _apply's CALL Rs as 'call aN'"; }
|
||||
echo " ok dis34 _apply @ 0x$APPLY_L: $(grep -E '^[0-9a-f]+:[[:space:]]+call[[:space:]]+a[0-9]+' "$TMP/apply.dis" | head -1 | sed 's/^[[:space:]]*//')"
|
||||
|
||||
echo "m4 fnptr: PASS"
|
||||
Executable
+148
@@ -0,0 +1,148 @@
|
||||
#!/bin/sh
|
||||
# M4 layout gate: the X11R4-compatible XImage/XEvent/XErrorEvent and the ROM's
|
||||
# Display/Screen layouts must match the 32-bit VT1200 ABI.
|
||||
#
|
||||
# layout.c asserts the byte offsets with _Static_assert and returns the ROM's
|
||||
# bit displacements (byte offset * 8). layout-ti.c is the same layout compiled
|
||||
# by the 1987 TI compiler once; its &-of-member is already a bit address.
|
||||
# Both asm files must carry the same constants.
|
||||
#
|
||||
# No host X11 headers are used: layout.c includes only scripts/m4/x11m4.h and
|
||||
# tms-clang runs with -nostdinc.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
WORK=${M4_LAYOUT_WORK:-$ROOT/build/m4-layout}
|
||||
GOLDEN=$ROOT/scripts/m4/layout-ti.s
|
||||
|
||||
fail() {
|
||||
echo "layout.sh: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_LLC" "$TMS_BITADDR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$GOLDEN" ] || fail "missing TI golden: $GOLDEN"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Exit 0 here means every _Static_assert in layout.c held on the target.
|
||||
TMS_CLANG="$TMS_CLANG" TMS_OPT="$TMS_OPT" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O0 -o "$WORK/layout.ll" \
|
||||
"$ROOT/scripts/m4/layout.c" \
|
||||
|| fail "target compile failed (XImage/XEvent/XErrorEvent/Display static asserts?)"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$WORK/layout.ll" -o "$WORK/layout.s" \
|
||||
|| fail "llc failed for layout.ll"
|
||||
|
||||
# Print one function body, stopping at the next function label. TI's
|
||||
# EPI0_n labels are inside the function and come after the constant we check.
|
||||
body() { # body FILE FUNC
|
||||
awk -v want="_$2:" '
|
||||
$1 == want { infn = 1; next }
|
||||
infn {
|
||||
if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]*:/ && $0 !~ /^LBB/) exit
|
||||
print
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
# Allowed spellings for a constant: C hex, assembler hex with `h`, decimal.
|
||||
has_const() { # has_const FILE FUNC ERE
|
||||
body "$1" "$2" | tr 'A-Z' 'a-z' | grep -Eq "$3"
|
||||
}
|
||||
|
||||
check() { # check FILE FUNC ERE WHAT
|
||||
if ! has_const "$1" "$2" "$3"; then
|
||||
echo "layout.sh: $1: _$2 body:" >&2
|
||||
body "$1" "$2" >&2
|
||||
fail "_$2 in $1 does not contain $4"
|
||||
fi
|
||||
}
|
||||
|
||||
# First MOVI immediate in a function body, in decimal.
|
||||
const_value() { # const_value FILE FUNC
|
||||
body "$1" "$2" | awk '
|
||||
/MOVI/ {
|
||||
for (i = 1; i <= NF; i++)
|
||||
if ($i == "MOVI") {
|
||||
v = $(i + 1)
|
||||
sub(/,.*/, "", v)
|
||||
print v
|
||||
exit
|
||||
}
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
to_dec() { # to_dec TOKEN
|
||||
case "$1" in
|
||||
0x* | 0X*) printf '%d' "$1" ;;
|
||||
*h | *H) printf '%d' "0x${1%?}" ;;
|
||||
*) printf '%d' "$1" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
HEX480='(0x480|480h|[^0-9a-f]1152[^0-9a-f])'
|
||||
HEX40='(0x40|40h|[^0-9a-f]64[^0-9a-f])'
|
||||
HEX80='(0x80|80h|[^0-9a-f]128[^0-9a-f])'
|
||||
HEXA0='(0xa0|0a0h|[^0-9a-f]160[^0-9a-f])'
|
||||
HEX140='(0x140|140h|[^0-9a-f]320[^0-9a-f])'
|
||||
HEX160='(0x160|160h|[^0-9a-f]352[^0-9a-f])'
|
||||
HEX200='(0x200|200h|[^0-9a-f]512[^0-9a-f])'
|
||||
HEX1A0='(0x1a0|1a0h|[^0-9a-f]416[^0-9a-f])'
|
||||
|
||||
for asm in "$WORK/layout.s" "$GOLDEN"; do
|
||||
check "$asm" layout_display_screens "$HEX480" "0x480 (Display.screens)"
|
||||
check "$asm" layout_screen_root "$HEX40" "0x40 (Screen.root)"
|
||||
check "$asm" layout_image_data "$HEX80" "0x80 (XImage.data at byte 16)"
|
||||
check "$asm" layout_image_byte_order "$HEXA0" "0xA0 (XImage.byte_order at byte 20)"
|
||||
check "$asm" layout_image_bytes_per_line "$HEX140" "0x140 (XImage.bytes_per_line at byte 40)"
|
||||
check "$asm" layout_image_bits_per_pixel "$HEX160" "0x160 (XImage.bits_per_pixel at byte 44)"
|
||||
check "$asm" layout_image_f "$HEX200" "0x200 (XImage.f at byte 64)"
|
||||
check "$asm" layout_error_error_code "$HEX80" "0x80 (XErrorEvent.error_code at byte 16)"
|
||||
check "$asm" layout_event_xkey_keycode "$HEX1A0" "0x1A0 (XEvent.xkey.keycode at byte 52)"
|
||||
done
|
||||
|
||||
# sizeof(XEvent) is in bytes. It must cover the termtris vt_u32 evbuf[24].
|
||||
TARGET_TOKEN=$(const_value "$WORK/layout.s" layout_event_size) \
|
||||
|| fail "could not read layout_event_size from layout.s"
|
||||
GOLDEN_TOKEN=$(const_value "$GOLDEN" layout_event_size) \
|
||||
|| fail "could not read layout_event_size from the TI golden"
|
||||
[ -n "$TARGET_TOKEN" ] || fail "layout.s layout_event_size has no MOVI constant"
|
||||
[ -n "$GOLDEN_TOKEN" ] || fail "TI golden layout_event_size has no MOVI constant"
|
||||
TARGET_SIZE=$(to_dec "$TARGET_TOKEN") \
|
||||
|| fail "could not parse layout_event_size '$TARGET_TOKEN' from layout.s"
|
||||
GOLDEN_SIZE=$(to_dec "$GOLDEN_TOKEN") \
|
||||
|| fail "could not parse layout_event_size '$GOLDEN_TOKEN' from the TI golden"
|
||||
[ "$TARGET_SIZE" -ge 96 ] \
|
||||
|| fail "target sizeof(XEvent) = $TARGET_SIZE bytes, want >= 96"
|
||||
[ "$GOLDEN_SIZE" -ge 96 ] \
|
||||
|| fail "TI sizeof(XEvent) = $GOLDEN_SIZE bytes, want >= 96"
|
||||
[ "$TARGET_SIZE" -eq "$GOLDEN_SIZE" ] \
|
||||
|| fail "target sizeof(XEvent)=$TARGET_SIZE but TI golden=$GOLDEN_SIZE"
|
||||
|
||||
# root_probe exercises the real access path: vt_root() follows Display.screens
|
||||
# (bit 0x480) and reads Screen.root (bit 0x40). The helper is always_inline.
|
||||
check "$WORK/layout.s" root_probe "$HEX480" "0x480 (Display.screens)"
|
||||
check "$WORK/layout.s" root_probe "$HEX40" "0x40 (Screen.root)"
|
||||
if body "$WORK/layout.s" root_probe | grep -q 'MOVB'; then
|
||||
fail "root_probe contains MOVB: align-1 field loads did not select MOVE"
|
||||
fi
|
||||
|
||||
# Guard against the old byte/bit-confusion mistake: Display.screens must not
|
||||
# be 0x480*8 (9216) and Screen.root must not be 0x40*8 (512).
|
||||
if body "$WORK/layout.s" layout_display_screens | tr 'A-Z' 'a-z' |
|
||||
grep -Eq '(^|[^0-9])(9216|2400h)([^0-9a-f]|$)' ||
|
||||
body "$WORK/layout.s" layout_screen_root | tr 'A-Z' 'a-z' |
|
||||
grep -Eq '(^|[^0-9])(512|200h)([^0-9a-f]|$)'; then
|
||||
fail "target carries byte-pad offsets (9216/512); ROM displacements are bits 0x480/0x40"
|
||||
fi
|
||||
|
||||
echo "layout.sh: PASS (XImage data/byte_order/bpl/bpp/f = 0x80/0xA0/0x140/0x160/0x200; XErrorEvent.error_code=0x80; XEvent.xkey.keycode=0x1A0; sizeof(XEvent)=$TARGET_SIZE; Display.screens=0x480, Screen.root=0x40; target + TI golden)"
|
||||
Executable
+109
@@ -0,0 +1,109 @@
|
||||
#!/bin/sh
|
||||
# M4 multiply/divide and -O2 loop gate: compile mul.c and loop.c with the
|
||||
# default tms-clang -O2 (the driver wrapper, not a local opt wrapper), link with
|
||||
# GSPA/GSPLNK, run in MAME and check every arithmetic marker. The linked
|
||||
# assembly must use MPYS/MPYU/DIVS/DIVU for the operations mul.c names.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_MUL_WORK:-$ROOT/build/m4-mul}
|
||||
|
||||
fail() {
|
||||
echo "m4 mul: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
M4_SOURCES="mul loop" \
|
||||
M4_ENTRY="$DIR/mul-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/mul-check.lua" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_WORK="$WORK" \
|
||||
"$ROOT/scripts/m4/run.sh" || fail "M4 multiply/loop run failed"
|
||||
|
||||
ASM=$WORK/m4.asm
|
||||
[ -f "$ASM" ] || fail "linked assembly not found: $ASM"
|
||||
|
||||
# The loop source must compile with the ordinary driver -O2 pipeline: no local
|
||||
# -replexitval flag and no i33/i64 multiply in the emitted IR.
|
||||
grep -q -- '-replexitval=never' "$ROOT/scripts/tms-clang" \
|
||||
|| fail "scripts/tms-clang does not disable IndVarSimplify exit-value replacement"
|
||||
if grep -Eq '\bmul i(33|64)\b' "$WORK/asm/loop.ll"; then
|
||||
sed 's/^/ /' "$WORK/asm/loop.ll" >&2
|
||||
fail "loop.ll still contains an i33/i64 multiply"
|
||||
fi
|
||||
echo " ok driver -O2 loop IR has no i33/i64 multiply"
|
||||
|
||||
# The 16x16 unsigned product must not carry the old signed-overflow
|
||||
# annotation. With the multiply done in unsigned arithmetic the IR is
|
||||
# `mul nuw`, not `mul nuw nsw`; the latter contradicts the 0xfffe0001 result.
|
||||
if awk '/^define .*@umul16\(/{infn=1} infn{print} infn && /^}/{exit}' \
|
||||
"$WORK/asm/mul.ll" | grep -q 'mul nuw nsw'; then
|
||||
fail "umul16 still has a signed no-wrap multiply (the product is unsigned)"
|
||||
fi
|
||||
echo " ok umul16 multiplies without signed no-wrap"
|
||||
|
||||
# The wide product must likewise be an unsigned multiply: signed `nsw` on
|
||||
# values whose product exceeds 32 bits would make the marker UB/poison.
|
||||
if awk '/^define .*@mulu\(/{infn=1} infn{print} infn && /^}/{exit}' \
|
||||
"$WORK/asm/mul.ll" | grep -Eq 'mul (nuw )?nsw'; then
|
||||
fail "mulu has a signed no-wrap multiply (the wide product is unsigned)"
|
||||
fi
|
||||
echo " ok mulu multiplies without signed no-wrap"
|
||||
|
||||
# Stop at the next function label (a column-0 label that is not an LBB block
|
||||
# label), so a following local function cannot leak into this slice.
|
||||
body() { # body FILE FUNC
|
||||
awk -v want="_$2:" '
|
||||
$1 == want { infn = 1; next }
|
||||
infn {
|
||||
if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]*:/ && $0 !~ /^LBB/) exit
|
||||
print
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-mul.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
EXPECTED="M4: mul=42 umul16=4294836225 sdiv=14 udiv=613566756 srem=2 urem=2 sdivneg=4294967282 sremneg=4294967294 sumto=55 squares=30 widemul=606937216 widerem=2"
|
||||
grep -Fqx "$EXPECTED" "$WORK/mame.log" \
|
||||
|| { grep -E '^M4: ' "$WORK/mame.log" >&2 || true; fail "runtime markers did not match: $EXPECTED"; }
|
||||
echo " ok runtime markers: $EXPECTED"
|
||||
|
||||
for fn in mul mulu umul16 sdiv udiv srem urem sumto squares; do
|
||||
body "$ASM" "$fn" > "$TMP/$fn.s"
|
||||
[ -s "$TMP/$fn.s" ] || fail "linked assembly has no _$fn body"
|
||||
done
|
||||
|
||||
check_insn() { # check_insn FUNC MNEMONIC WHAT
|
||||
if grep -Eq "^[[:space:]]*$2([[:space:]]|$)" "$TMP/$1.s"; then
|
||||
echo " ok _$1 uses $2 ($3)"
|
||||
return 0
|
||||
fi
|
||||
sed 's/^/ /' "$TMP/$1.s" >&2
|
||||
fail "_$1 does not use $2 ($3)"
|
||||
}
|
||||
|
||||
check_insn mul MPYS "signed 32x32 low product"
|
||||
check_insn mulu MPYS "wide unsigned 32x32 low product"
|
||||
check_insn umul16 MPYU "16x16 unsigned product"
|
||||
check_insn sdiv DIVS "signed 32/32 divide"
|
||||
check_insn udiv DIVU "unsigned 32/32 divide"
|
||||
check_insn srem DIVS "signed remainder divide"
|
||||
check_insn srem MPYS "signed remainder multiply"
|
||||
check_insn srem SUB "signed remainder subtract"
|
||||
check_insn urem DIVU "unsigned remainder divide"
|
||||
check_insn urem SUB "unsigned remainder subtract"
|
||||
check_insn squares MPYS "loop multiply"
|
||||
|
||||
# The driven loop must remain a loop (a backward branch), not a closed form.
|
||||
# M5's JR relaxation may use the one-word relative form; both JA<cc> and JR<cc>
|
||||
# keep the loop condition unchanged.
|
||||
if ! grep -Eq '^[[:space:]]*J[AR](LT|LE|GT|GE|LO|LS|HI|HS|EQ|NE)[[:space:]]' "$TMP/sumto.s"; then
|
||||
sed 's/^/ /' "$TMP/sumto.s" >&2
|
||||
fail "_sumto has no conditional branch (loop was not kept)"
|
||||
fi
|
||||
echo " ok _sumto keeps a conditional loop branch"
|
||||
|
||||
echo "m4 mul: PASS"
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
# M4 private-symbol gate: compile two translation units that both contain the
|
||||
# string literal "same", assemble/link them with GSPA/GSPLNK, and require a
|
||||
# clean link. Before M4 both TUs emitted the same ``__2EL_2Estr`` label and
|
||||
# GSPA's flat symbol table reported a duplicate definition.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_PRIVATE_WORK:-$ROOT/build/m4-private}
|
||||
|
||||
fail() {
|
||||
echo "m4 private: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_SOURCES="private-a private-b" \
|
||||
M4_ENTRY="$DIR/private-entry.asm" \
|
||||
M4_WORK="$WORK" \
|
||||
"$ROOT/scripts/m4/run.sh" || fail "two-TU GSPA link failed"
|
||||
|
||||
ASM_A=$WORK/asm/private-a.s
|
||||
ASM_B=$WORK/asm/private-b.s
|
||||
for f in "$ASM_A" "$ASM_B"; do
|
||||
[ -f "$f" ] || fail "missing assembly: $f"
|
||||
done
|
||||
|
||||
# Each TU's string label must be GSPA-safe and module-unique.
|
||||
A_SYM=$(grep -oE '__2EL_2Estr_[0-9A-F]+:' "$ASM_A" | head -1 | tr -d ':')
|
||||
B_SYM=$(grep -oE '__2EL_2Estr_[0-9A-F]+:' "$ASM_B" | head -1 | tr -d ':')
|
||||
[ -n "$A_SYM" ] || { sed 's/^/ /' "$ASM_A" >&2; fail "private-a has no module-unique string label"; }
|
||||
[ -n "$B_SYM" ] || { sed 's/^/ /' "$ASM_B" >&2; fail "private-b has no module-unique string label"; }
|
||||
[ "$A_SYM" != "$B_SYM" ] \
|
||||
|| fail "both TUs use the same private label: $A_SYM"
|
||||
echo " ok private labels differ: $A_SYM vs $B_SYM"
|
||||
|
||||
if grep -qx '__2EL_2Estr:' "$ASM_A" || grep -qx '__2EL_2Estr:' "$ASM_B"; then
|
||||
fail "a TU still emits the colliding bare __2EL_2Estr label"
|
||||
fi
|
||||
|
||||
# Public names must not be rewritten.
|
||||
grep -Eq '^[[:space:]]*\.globl[[:space:]]+_a([[:space:]]|$)' "$ASM_A" \
|
||||
|| fail "private-a does not expose public _a"
|
||||
grep -Eq '^[[:space:]]*\.globl[[:space:]]+_b([[:space:]]|$)' "$ASM_B" \
|
||||
|| fail "private-b does not expose public _b"
|
||||
echo " ok public names unchanged: _a and _b"
|
||||
|
||||
grep -q '^_a:' "$WORK/m4.asm" || fail "linked assembly has no _a"
|
||||
grep -q '^_b:' "$WORK/m4.asm" || fail "linked assembly has no _b"
|
||||
awk '$2 == "_a" || $2 == "_b" { found++ } END { exit found == 2 ? 0 : 1 }' \
|
||||
"$WORK/m4.map" || fail "linker map does not define both _a and _b"
|
||||
|
||||
echo "m4 private: PASS"
|
||||
Executable
+75
@@ -0,0 +1,75 @@
|
||||
#!/bin/sh
|
||||
# M4 image/event gate: compile the 1-bit XImage client and xgfix, assemble and
|
||||
# link with GSPA/GSPLNK, run in MAME, inject the real LK401 `Q`, and require the
|
||||
# image pixels, the key, the focus (the client's own window), and zero X errors.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_XSHOW_WORK:-$ROOT/build/m4-xshow}
|
||||
|
||||
fail() {
|
||||
echo "m4 xshow: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# The client uses the Task 4 XImage/XEvent layout and the Task 5 ROM table.
|
||||
"$ROOT/scripts/tests/m4/layout.sh" || fail "XImage/XEvent layout gate failed"
|
||||
"$ROOT/scripts/m4/validate-syms.sh" || fail "ROM symbol validation failed"
|
||||
|
||||
M4_SOURCES="xshow xgfix" \
|
||||
M4_ENTRY="$DIR/xshow-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/xshow-check.lua" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_ROM_SYMBOLS=1 \
|
||||
LOADER_AT=2500 \
|
||||
LOADER_END=3400 \
|
||||
M4_WORK="$WORK" \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
VT1200_MONITOR=VR319 \
|
||||
"$ROOT/scripts/m4/run.sh" || fail "M4 image/event run failed"
|
||||
|
||||
LOG=$WORK/mame.log
|
||||
[ -f "$LOG" ] || fail "no MAME log: $LOG"
|
||||
|
||||
MARKER=$(grep -aE '^M4: display=' "$LOG" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no M4 marker line"
|
||||
echo " $MARKER"
|
||||
case "$MARKER" in
|
||||
*" quit=1 events="*) ;;
|
||||
*) fail "quit marker is not 1" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" keycode=193 keysym=0x71 "*) ;;
|
||||
*) fail "the injected Q did not produce keycode 193 / keysym 0x71" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" xerrors=0 "*) ;;
|
||||
*) fail "xerrors is not 0" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" focus=0x400001 "*) ;;
|
||||
*) fail "input focus is not the client window 0x400001" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" last=2"*) ;;
|
||||
*) fail "the last X event is not KeyPress (last=2)" ;;
|
||||
esac
|
||||
|
||||
# The image evidence: the two required cells plus a later band.
|
||||
grep -Fq 'M4: pixel screen(50,50) image(18,30) cell(0,0) bit=0x04019032 value=0 black' "$LOG" \
|
||||
|| fail "window-relative (30,30) is not the black checker cell"
|
||||
grep -Fq 'M4: pixel screen(70,50) image(38,30) cell(1,0) bit=0x04019046 value=1 white' "$LOG" \
|
||||
|| fail "window-relative (50,30) is not the white checker cell"
|
||||
grep -Fq 'M4: pixel screen(500,400) image(468,380) cell(14,11) bit=0x040C81F4 value=1 white' "$LOG" \
|
||||
|| fail "later-band checker cell is wrong"
|
||||
# The 12-pixel prefix is the preceding cell: white in band 0, black in band 1.
|
||||
grep -Eq '^M4: pixel screen\(25,30\) image\(-7,10\) cell\(-1,0\) bit=0x[0-9A-F]+ value=1 white$' "$LOG" \
|
||||
|| fail "left prefix in band 0 is not the preceding (white) cell"
|
||||
grep -Eq '^M4: pixel screen\(25,62\) image\(-7,42\) cell\(-1,1\) bit=0x[0-9A-F]+ value=0 black$' "$LOG" \
|
||||
|| fail "left prefix in band 1 is not the preceding (black) cell"
|
||||
|
||||
grep -q '^M4 MAME: PASS' "$LOG" || fail "image/key check did not pass"
|
||||
grep -q 'LOADER: result status=0 (OK)' "$LOG" || fail "loader status is not OK"
|
||||
|
||||
echo "m4 xshow: PASS (1-bit image + real q key + window focus + 0 X errors)"
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
# M4 symbol gate.
|
||||
#
|
||||
# Runs scripts/m4/validate-syms.sh on the real v2.2 table and pins the
|
||||
# XMapWindow/XRaiseWindow correction: a table that maps XMapWindow to
|
||||
# 0x3FD645B0 (ConfigureWindow/XRaiseWindow) must be rejected and named.
|
||||
# Also proves the generic alignment gate is live.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
VALIDATE=$ROOT/scripts/m4/validate-syms.sh
|
||||
SYMS=${M4_SYMS:-$ROOT/symbols/vt1200-v22.syms}
|
||||
|
||||
fail() {
|
||||
echo "symbols.sh: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$VALIDATE" ] || fail "validator not executable: $VALIDATE"
|
||||
[ -f "$SYMS" ] || fail "symbol file not found: $SYMS"
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-symbols.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
echo "== the real v2.2 table"
|
||||
"$VALIDATE" "$SYMS" || fail "the committed v2.2 table did not validate"
|
||||
|
||||
echo "== negative control: XMapWindow 0x3FD645B0"
|
||||
sed 's/^XMapWindow[[:space:]].*/XMapWindow 0x3FD645B0/' \
|
||||
"$SYMS" > "$TMP/wrong-mapwindow.syms"
|
||||
grep -q '^XMapWindow[[:space:]]*0x3FD645B0' "$TMP/wrong-mapwindow.syms" \
|
||||
|| fail "could not construct the wrong-XMapWindow table"
|
||||
if "$VALIDATE" "$TMP/wrong-mapwindow.syms" > "$TMP/wrong.out" 2>&1; then
|
||||
sed 's/^/ /' "$TMP/wrong.out" >&2
|
||||
fail "validator accepted XMapWindow 0x3FD645B0"
|
||||
fi
|
||||
grep -q 'XRaiseWindow' "$TMP/wrong.out" \
|
||||
|| { sed 's/^/ /' "$TMP/wrong.out" >&2; fail "rejection did not name XRaiseWindow"; }
|
||||
grep -qi 'wrong' "$TMP/wrong.out" \
|
||||
|| { sed 's/^/ /' "$TMP/wrong.out" >&2; fail "rejection did not report the wrong address"; }
|
||||
echo " ok XMapWindow 0x3FD645B0 rejected as XRaiseWindow/wrong"
|
||||
|
||||
echo "== negative control: unaligned entry"
|
||||
sed 's/^XPutImage[[:space:]].*/XPutImage 0x3F9CEC71/' \
|
||||
"$SYMS" > "$TMP/unaligned.syms"
|
||||
if "$VALIDATE" "$TMP/unaligned.syms" > "$TMP/unaligned.out" 2>&1; then
|
||||
sed 's/^/ /' "$TMP/unaligned.out" >&2
|
||||
fail "validator accepted an unaligned XPutImage address"
|
||||
fi
|
||||
grep -qi 'aligned' "$TMP/unaligned.out" \
|
||||
|| { sed 's/^/ /' "$TMP/unaligned.out" >&2; fail "alignment failure not reported"; }
|
||||
echo " ok unaligned XPutImage rejected"
|
||||
|
||||
echo "symbols.sh: PASS (v2.2 table validates; XMapWindow correction and alignment are pinned)"
|
||||
Executable
+112
@@ -0,0 +1,112 @@
|
||||
#!/bin/sh
|
||||
# M4 termtris gate: build the pinned termtris with this compiler, run the
|
||||
# proven play_keys paths in MAME (board, move, panels, quit), and enforce the
|
||||
# loop/event/quit/focus thresholds and the four snapshots.
|
||||
#
|
||||
# TERMTRIS_BUILD overrides the builder (default scripts/m4/termtris/build.sh);
|
||||
# the M5 native gate points it at scripts/m5/native.sh.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4/termtris
|
||||
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
||||
WORK=${TERMTRIS_WORK:-$ROOT/build/m4-termtris}
|
||||
EV=$WORK/evidence
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
PIN=be5b323f5d2cc4f7a7d25e7143c67bd9828ccbdf
|
||||
|
||||
fail() {
|
||||
echo "m4 termtris: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -d "$VENDOR" ] || fail "missing pinned termtris tree: $VENDOR"
|
||||
if git -C "$VENDOR" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
rev=$(git -C "$VENDOR" rev-parse HEAD)
|
||||
[ "$rev" = "$PIN" ] || fail "vendor tree is $rev, want $PIN"
|
||||
fi
|
||||
|
||||
# The optimizer's switch-to-lookup-table transform creates a late byte-offset
|
||||
# GEP. tms-bitaddr --normalize recognizes the `switch.table.*` base and
|
||||
# shifts its index into bits; a dense char switch is the regression probe.
|
||||
# The termtris init_game/runesc switches are the real instances.
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/tt-switch.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
"$ROOT/scripts/tms-clang" -O2 -o "$TMP/switch.ll" "$ROOT/scripts/m4/switch.c" \
|
||||
|| fail "tms-clang failed for the switch probe"
|
||||
grep -q 'switch\.table' "$TMP/switch.ll" \
|
||||
|| fail "the switch probe no longer exercises a lookup table"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$TMP/switch.ll" \
|
||||
-o "$TMP/switch.s" || fail "llc failed for the switch probe"
|
||||
awk '/^_sw_tile:/ { on = 1; next } on && /-- End function/ { exit } on' \
|
||||
"$TMP/switch.s" > "$TMP/sw_tile.s"
|
||||
grep -Eq '^[[:space:]]*SLL[[:space:]]+3' "$TMP/sw_tile.s" \
|
||||
|| { sed 's/^/ /' "$TMP/sw_tile.s" >&2; \
|
||||
fail "switch-table index is not shifted into bits (8x index bug)"; }
|
||||
grep -q 'CMPI' "$TMP/switch.s" || fail "the switch probe has no compare/branch"
|
||||
|
||||
echo "== build the pinned termtris with this compiler"
|
||||
BUILD=${TERMTRIS_BUILD:-$DIR/build.sh}
|
||||
"$BUILD" || fail "termtris build failed"
|
||||
|
||||
echo "== run board/move/panels/quit in MAME"
|
||||
TERMTRIS_NOBUILD=1 \
|
||||
MODES="board move panels quit" \
|
||||
LOADER_AT=2500 LOADER_END=3200 \
|
||||
"$DIR/play_keys.sh" || fail "play_keys run failed"
|
||||
|
||||
field() {
|
||||
# field FILE NAME -> the decimal/hex value after NAME=
|
||||
sed -n "s/.*[[:space:]]$2=\\([0-9A-Fa-f]*\\).*/\\1/p" "$1" | head -1
|
||||
}
|
||||
|
||||
for mode in board move panels quit; do
|
||||
DIAG=$WORK/diag_$mode.txt
|
||||
LOG=$WORK/play_$mode.log
|
||||
[ -f "$DIAG" ] || fail "no DIAG for $mode"
|
||||
[ -f "$LOG" ] || fail "no MAME log for $mode"
|
||||
|
||||
LOOPS=$(field "$DIAG" loops)
|
||||
EVENTS=$(field "$DIAG" events)
|
||||
QUIT=$(field "$DIAG" quit)
|
||||
FOCUS=$(field "$DIAG" focus)
|
||||
WINDOW=$(field "$DIAG" window)
|
||||
[ -n "$LOOPS" ] && [ -n "$EVENTS" ] && [ -n "$QUIT" ] \
|
||||
&& [ -n "$FOCUS" ] && [ -n "$WINDOW" ] \
|
||||
|| fail "$mode DIAG line is incomplete: $(cat "$DIAG")"
|
||||
|
||||
[ "$LOOPS" -ge 100 ] || fail "$mode main loop barely ran (loops=$LOOPS)"
|
||||
[ "$FOCUS" != 00000000 ] && [ "$FOCUS" != 00000001 ] \
|
||||
|| fail "$mode focus is not a created window (focus=$FOCUS)"
|
||||
[ "$FOCUS" = "$WINDOW" ] \
|
||||
|| fail "$mode focus $FOCUS is not the termtris window $WINDOW"
|
||||
case $mode in
|
||||
move|panels)
|
||||
[ "$EVENTS" -ge 6 ] || fail "$mode got $EVENTS events, expected the click and keys"
|
||||
[ "$QUIT" = 0 ] || fail "$mode quit unexpectedly"
|
||||
;;
|
||||
quit)
|
||||
[ "$EVENTS" -ge 6 ] || fail "$mode got $EVENTS events, expected the click and q"
|
||||
[ "$QUIT" = 1 ] || fail "q did not reach the game (quit=$QUIT)"
|
||||
;;
|
||||
board)
|
||||
[ "$EVENTS" -ge 2 ] || fail "$mode got $EVENTS events, expected the click"
|
||||
[ "$QUIT" = 0 ] || fail "$mode quit unexpectedly"
|
||||
;;
|
||||
esac
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$LOG" \
|
||||
|| fail "$mode loader status is not OK"
|
||||
grep -q 'placed \.text .* 0 differing' "$LOG" \
|
||||
|| fail "$mode loader did not verify the placed .text bytes"
|
||||
[ -s "$EV/termtris_${mode}_3200.png" ] \
|
||||
|| fail "$mode snapshot is missing"
|
||||
echo " $mode loops=$LOOPS events=$EVENTS quit=$QUIT focus=$FOCUS"
|
||||
done
|
||||
|
||||
echo "m4 termtris: PASS (board/move/panels/quit; ${EV}/termtris_*_3200.png)"
|
||||
Executable
+89
@@ -0,0 +1,89 @@
|
||||
#!/bin/sh
|
||||
# M4 unsigned runtime gate: compile unsigned.c at -O0, link with GSPA/GSPLNK,
|
||||
# run in MAME, and check every signed/unsigned predicate marker. The linked
|
||||
# assembly must use the real condition mnemonics for each function.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
WORK=${M4_UNSIGNED_WORK:-$ROOT/build/m4-unsigned}
|
||||
|
||||
fail() {
|
||||
echo "m4 unsigned: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
M4_WORK="$WORK" "$ROOT/scripts/m4/run.sh" || fail "M4 unsigned run failed"
|
||||
|
||||
ASM=$WORK/m4.asm
|
||||
[ -f "$ASM" ] || fail "linked assembly not found: $ASM"
|
||||
|
||||
# Stop at the next function label (a column-0 label that is not an LBB block
|
||||
# label), so a following local function cannot leak into this slice.
|
||||
body() { # body FILE FUNC
|
||||
awk -v want="_$2:" '
|
||||
$1 == want { infn = 1; next }
|
||||
infn {
|
||||
if ($0 ~ /^[A-Za-z_][A-Za-z0-9_]*:/ && $0 !~ /^LBB/) exit
|
||||
print
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/m4-unsigned.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
EXPECTED="M4: le=1 ule=0 sum_le=55 ge=1 uge=0 gt=0 ugt=1 ne=1 lt=0 ult=1"
|
||||
grep -Fqx "$EXPECTED" "$WORK/mame.log" \
|
||||
|| { grep -E '^M4: ' "$WORK/mame.log" >&2 || true; fail "runtime markers did not match: $EXPECTED"; }
|
||||
echo " ok runtime markers: $EXPECTED"
|
||||
|
||||
for fn in le ule sum_le ge uge gt ugt ne lt ult; do
|
||||
body "$ASM" "$fn" > "$TMP/$fn.s"
|
||||
[ -s "$TMP/$fn.s" ] || fail "linked assembly has no _$fn body"
|
||||
done
|
||||
|
||||
check_branch() { # check_branch FUNC JA<cc> WHAT
|
||||
# M5's JR relaxation selects the one-word relative form for an in-range
|
||||
# branch, keeping the condition code. Accept either spelling but require
|
||||
# exactly the same <cc> suffix.
|
||||
_cond=${2#JA}
|
||||
[ "$_cond" != "$2" ] \
|
||||
|| fail "check_branch expects a JA<cc> mnemonic, got $2"
|
||||
if grep -Eq "^[[:space:]]*J[AR]${_cond}[[:space:]]" "$TMP/$1.s"; then
|
||||
echo " ok _$1 uses JA/JR$_cond ($3)"
|
||||
return 0
|
||||
fi
|
||||
sed 's/^/ /' "$TMP/$1.s" >&2
|
||||
fail "_$1 does not use JA/JR$_cond ($3)"
|
||||
}
|
||||
|
||||
reject_branch() { # reject_branch FUNC ERE WHAT
|
||||
# The ERE names the absolute form; allow the relative prefix as well. The
|
||||
# condition itself is unchanged, so a wrong signed/unsigned form still
|
||||
# fails.
|
||||
_re=$(printf '%s\n' "$2" | sed 's/^JA/J[AR]/')
|
||||
if grep -Eq "^[[:space:]]*${_re}[[:space:]]" "$TMP/$1.s"; then
|
||||
sed 's/^/ /' "$TMP/$1.s" >&2
|
||||
fail "_$1 uses the wrong condition $2 ($3)"
|
||||
fi
|
||||
}
|
||||
|
||||
check_branch le JALE "signed <="
|
||||
check_branch ule JALS "unsigned <="
|
||||
check_branch sum_le JAGT "signed i > n loop exit"
|
||||
check_branch ge JAGE "signed >="
|
||||
check_branch uge JAHS "unsigned >="
|
||||
check_branch gt JAGT "signed >"
|
||||
check_branch ugt JAHI "unsigned >"
|
||||
check_branch ne JANE "!="
|
||||
check_branch lt JALT "signed <"
|
||||
check_branch ult JALO "unsigned <"
|
||||
|
||||
# The unsigned predicates must not silently select a signed branch form.
|
||||
reject_branch ule 'JA(LT|LE|GT|GE)' "unsigned <="
|
||||
reject_branch uge 'JA(LT|LE|GT|GE)' "unsigned >="
|
||||
reject_branch ugt 'JA(LT|LE|GT|GE)' "unsigned >"
|
||||
reject_branch ult 'JA(LT|LE|GT|GE)' "unsigned <"
|
||||
reject_branch ne 'JAEQ' "!="
|
||||
|
||||
echo "m4 unsigned: PASS"
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
# M4 varargs ABI gate: compile the contiguous-stack probe with this compiler,
|
||||
# link it with the M4 runner, and require the three sums in MAME.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m4
|
||||
WORK=${M4_VARARGS_WORK:-$ROOT/build/m4-varargs}
|
||||
|
||||
fail() {
|
||||
echo "m4 varargs: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
M4_SOURCES=varargs \
|
||||
M4_ENTRY="$DIR/varargs-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/varargs-check.lua" \
|
||||
M4_CLANG_OPT=-O0 \
|
||||
M4_WORK="$WORK" \
|
||||
LOADER_AT=2500 \
|
||||
LOADER_END=2700 \
|
||||
"$DIR/run.sh" || fail "M4 varargs run failed"
|
||||
|
||||
LOG=$WORK/mame.log
|
||||
[ -f "$LOG" ] || fail "no MAME log: $LOG"
|
||||
MARKER=$(grep -aE '^M4: varargs ' "$LOG" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no varargs marker line"
|
||||
echo " $MARKER"
|
||||
grep -q '^M4 MAME: PASS' "$LOG" || fail "varargs marker values are wrong"
|
||||
grep -q 'LOADER: result status=0 (OK)' "$LOG" || fail "loader status is not OK"
|
||||
|
||||
echo "m4 varargs: PASS (three contiguous stack args per call)"
|
||||
@@ -0,0 +1,43 @@
|
||||
# M5 c-testsuite `single-exec` output subset.
|
||||
#
|
||||
# Curated list seeded by Task 12. One test name per line (no .c suffix); the
|
||||
# `.c`, `.c.expected` and `.tags` live under the pinned
|
||||
# vendor/conformance/c-testsuite/tests/single-exec tree. Every listed test is
|
||||
# portable C89/C99 using only integer/pointer/struct/array/string language
|
||||
# features and, where it prints, the shim's printf conversions. Each test
|
||||
# must return 0 and its captured output must equal `<name>.c.expected` byte
|
||||
# for byte. Unsupported tests live in c-testsuite.skip, never here.
|
||||
#
|
||||
# Core language: integer arithmetic, control flow, pointers, arrays, structs,
|
||||
# strings (expected output is empty; the status is 0).
|
||||
00001
|
||||
00004
|
||||
00006
|
||||
00007
|
||||
00009
|
||||
00010
|
||||
00015
|
||||
00017
|
||||
00022
|
||||
00025
|
||||
00027
|
||||
00029
|
||||
00030
|
||||
00034
|
||||
00035
|
||||
00038
|
||||
00039
|
||||
#
|
||||
# Formatted output: %d/%i/%u/%c/%s/%ld through the conformance shim.
|
||||
00056
|
||||
00125
|
||||
00132
|
||||
00154
|
||||
00156
|
||||
00157
|
||||
00163
|
||||
00170
|
||||
00173
|
||||
00213
|
||||
00214
|
||||
00215
|
||||
Executable
+195
@@ -0,0 +1,195 @@
|
||||
#!/bin/sh
|
||||
# M5 c-testsuite `single-exec` output-subset gate.
|
||||
#
|
||||
# scripts/tests/m5/c-testsuite.sh [LIST] [SKIP]
|
||||
#
|
||||
# LIST (default scripts/tests/m5/c-testsuite.list) names the curated
|
||||
# vendor/conformance/c-testsuite/tests/single-exec tests. Every listed test
|
||||
# runs through the Task 9 single-exec entry point
|
||||
# (conformance/c-testsuite.sh -> run.sh --classify --expect-status 0
|
||||
# --expect-output-file <name>.c.expected). The captured stdout must equal
|
||||
# the .c.expected bytes exactly, main must return 0, the COFF loader readback
|
||||
# must be clean and the completion magic must be present. A mismatch fails.
|
||||
# A listed test that the classifier rejects is reported as a skip and fails
|
||||
# the gate: unsupported tests belong in SKIP, never in LIST.
|
||||
#
|
||||
# SKIP (default scripts/tests/m5/c-testsuite.skip) accounts for every other
|
||||
# single-exec test with a feature/reason. Rows are
|
||||
# <name><TAB><feature>: <reason>
|
||||
# Skips are reported separately and are never counted as passes. The gate
|
||||
# checks that every skip names an existing test, is not also listed, and has a
|
||||
# reason; a classifier-rejected test must carry the classifier's exact reason.
|
||||
# LIST + SKIP must cover the pinned suite, so no test is silently dropped.
|
||||
#
|
||||
# The MAME boot dominates the runtime. Task 11's proven 300/600 injection
|
||||
# frames are reused; the loader readback and completion magic checks remain.
|
||||
# The suite runs serially because M4_SDK is shared.
|
||||
#
|
||||
# Overridable: C_TESTSUITE_DIR C_TESTSUITE_LOADER_AT C_TESTSUITE_LOADER_END
|
||||
# M5_C_TESTSUITE_WORK M5_CONFORMANCE_DIR M5_CONFORMANCE_MODE
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$HERE/conformance}
|
||||
CONFORMANCE=$CONFORMANCE_DIR/c-testsuite.sh
|
||||
CLASSIFY=$CONFORMANCE_DIR/classify.sh
|
||||
SUITE_DIR=${C_TESTSUITE_DIR:-$ROOT/vendor/conformance/c-testsuite/tests/single-exec}
|
||||
WORK=${M5_C_TESTSUITE_WORK:-$ROOT/build/m5-c-testsuite}
|
||||
LOADER_AT=${C_TESTSUITE_LOADER_AT:-300}
|
||||
LOADER_END=${C_TESTSUITE_LOADER_END:-600}
|
||||
|
||||
fail() {
|
||||
echo "c-testsuite: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$CONFORMANCE" ] || fail "missing conformance entry point: $CONFORMANCE"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-testsuite tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
LIST=$HERE/c-testsuite.list
|
||||
SKIP=$HERE/c-testsuite.skip
|
||||
if [ $# -gt 0 ]; then
|
||||
LIST=$1
|
||||
shift
|
||||
fi
|
||||
if [ $# -gt 0 ]; then
|
||||
SKIP=$1
|
||||
shift
|
||||
fi
|
||||
[ $# -eq 0 ] || fail "unexpected trailing arguments: $*"
|
||||
[ -f "$LIST" ] || fail "no c-testsuite.list ($LIST); Task 12 seeds it"
|
||||
[ -f "$SKIP" ] || fail "no c-testsuite.skip ($SKIP); Task 12 seeds it"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
LOG=$WORK/c-testsuite.log
|
||||
: > "$LOG"
|
||||
|
||||
list_count() {
|
||||
awk '$0 !~ /^[[:space:]]*(#|$)/ { n++ } END { print n + 0 }' "$1"
|
||||
}
|
||||
|
||||
LIST_COUNT=$(list_count "$LIST")
|
||||
[ "$LIST_COUNT" -gt 0 ] || fail "c-testsuite.list is empty ($LIST)"
|
||||
|
||||
# One running log with the runner's per-test result rows, plus the individual
|
||||
# runner logs kept under the work dir.
|
||||
ONE_LIST=$WORK/one.list
|
||||
pass=0
|
||||
runner_skip=0
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
case $name in
|
||||
*/*|.*) fail "unsafe test name in $LIST: '$name'" ;;
|
||||
esac
|
||||
base=${name%.c}
|
||||
src=$SUITE_DIR/$base.c
|
||||
expected=$SUITE_DIR/$base.c.expected
|
||||
[ -f "$src" ] || fail "missing c-testsuite source: $src"
|
||||
[ -f "$expected" ] || fail "missing c-testsuite expected output: $expected"
|
||||
total=$((total + 1))
|
||||
|
||||
printf '%s\n' "$base" > "$ONE_LIST"
|
||||
one_log=$WORK/$base.log
|
||||
set +e
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$LOADER_END \
|
||||
"$CONFORMANCE" "$ONE_LIST" > "$one_log" 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
cat "$one_log" >> "$LOG"
|
||||
case $rc in
|
||||
0)
|
||||
pass=$((pass + 1))
|
||||
;;
|
||||
*)
|
||||
# The wrapper exits 1 when its only test was classified as a skip
|
||||
# (pass=0). Report the reason, but fail below: an unsupported test
|
||||
# must be in c-testsuite.skip, not the list.
|
||||
if grep -q '^CONFORMANCE: SKIP ' "$one_log"; then
|
||||
reason=$(sed -n 's/^CONFORMANCE: SKIP id=[^ ]* reason=//p' "$one_log")
|
||||
runner_skip=$((runner_skip + 1))
|
||||
echo "c-testsuite: SKIP $base (listed but classifier-rejected: $reason)" >&2
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "c-testsuite: FAIL $base (runner exit $rc; log $one_log)" >&2
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done < "$LIST"
|
||||
|
||||
# Validate the skip file and collect its coverage.
|
||||
: > "$WORK/skip-reasons.txt"
|
||||
skip=0
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
name=${line%% *}
|
||||
reason=${line#* }
|
||||
[ "$name" != "$line" ] || fail "malformed skip row (no tab): $line"
|
||||
case $name in
|
||||
*/*|.*) fail "unsafe test name in $SKIP: '$name'" ;;
|
||||
esac
|
||||
base=${name%.c}
|
||||
[ -f "$SUITE_DIR/$base.c" ] || fail "skip names a missing test: $base"
|
||||
if grep -Fxq "$base" "$LIST"; then
|
||||
fail "test $base is both listed and skipped"
|
||||
fi
|
||||
[ -n "$reason" ] || fail "skip for $base has no reason"
|
||||
case $reason in
|
||||
*:?*) ;;
|
||||
*) fail "skip for $base has no feature/reason: '$reason'" ;;
|
||||
esac
|
||||
|
||||
set +e
|
||||
classified=$("$CLASSIFY" "$SUITE_DIR/$base.c" 2>&1)
|
||||
crc=$?
|
||||
set -e
|
||||
case $crc in
|
||||
0)
|
||||
# A classifier-supported test is only skipped for an explicit shim
|
||||
# gap or because it is outside the curated subset.
|
||||
case $reason in
|
||||
libc:*|stderr:*|shim-format:*|runtime:*|unselected:*) ;;
|
||||
*) fail "skip for $base does not name a shim gap or an unselected test: '$reason'" ;;
|
||||
esac
|
||||
;;
|
||||
1)
|
||||
[ "$reason" = "$classified" ] \
|
||||
|| fail "skip reason for $base is stale: '$reason' != '$classified'"
|
||||
;;
|
||||
*)
|
||||
fail "classifier error (exit $crc) on $base: $classified"
|
||||
;;
|
||||
esac
|
||||
skip=$((skip + 1))
|
||||
printf '%s\t%s\n' "$base" "$reason" >> "$WORK/skip-reasons.txt"
|
||||
done < "$SKIP"
|
||||
|
||||
[ "$failed" -eq 0 ] || fail "$failed of $total listed tests failed"
|
||||
[ "$pass" -gt 0 ] \
|
||||
|| fail "no tests passed (pass=0 skip=$runner_skip total=$total); all-skip is not a pass"
|
||||
[ "$runner_skip" -eq 0 ] \
|
||||
|| fail "$runner_skip listed test(s) were classifier-rejected; move them to $SKIP"
|
||||
|
||||
suite_count=$(find "$SUITE_DIR" -maxdepth 1 -type f -name '*.c' | wc -l | tr -d ' ')
|
||||
[ "$((pass + skip))" -eq "$suite_count" ] \
|
||||
|| fail "list+skip cover $((pass + skip)) tests, suite has $suite_count; every test needs a pass or a skip"
|
||||
|
||||
if [ "$skip" -gt 0 ]; then
|
||||
awk -F '\t' '{ printf "c-testsuite: SKIP %s reason=%s\n", $1, $2 }' \
|
||||
"$WORK/skip-reasons.txt" >> "$LOG"
|
||||
echo "c-testsuite: skipped $skip test(s) by reason:"
|
||||
awk -F '\t' '{ split($2, a, ":"); print a[1] }' "$WORK/skip-reasons.txt" \
|
||||
| sort | uniq -c | sort -rn | sed 's/^/ /'
|
||||
fi
|
||||
|
||||
echo "c-testsuite: PASS pass=$pass skip=$skip total=$suite_count"
|
||||
echo "c-testsuite: logs $WORK"
|
||||
echo "c-testsuite: skip reasons $WORK/skip-reasons.txt"
|
||||
@@ -0,0 +1,199 @@
|
||||
# M5 c-testsuite `single-exec` skips.
|
||||
#
|
||||
# Every single-exec test that is not in c-testsuite.list is accounted for here
|
||||
# as `<name><TAB><feature>: <reason>`, so no pinned test is silently dropped.
|
||||
# A skipped test is never a pass. Classifier-rejected tests carry the
|
||||
# classifier's exact `feature: reason` text; classifier-supported tests that
|
||||
# are outside this subset are marked `unselected:` or an explicit shim gap
|
||||
# (`libc:`/`stderr:`/`shim-format:`/`runtime:`).
|
||||
00002 unselected: classifier-supported; outside the curated output subset
|
||||
00003 unselected: classifier-supported; outside the curated output subset
|
||||
00005 unselected: classifier-supported; outside the curated output subset
|
||||
00008 unselected: classifier-supported; outside the curated output subset
|
||||
00011 unselected: classifier-supported; outside the curated output subset
|
||||
00012 unselected: classifier-supported; outside the curated output subset
|
||||
00013 unselected: classifier-supported; outside the curated output subset
|
||||
00014 unselected: classifier-supported; outside the curated output subset
|
||||
00016 unselected: classifier-supported; outside the curated output subset
|
||||
00018 unselected: classifier-supported; outside the curated output subset
|
||||
00019 unselected: classifier-supported; outside the curated output subset
|
||||
00020 unselected: classifier-supported; outside the curated output subset
|
||||
00021 unselected: classifier-supported; outside the curated output subset
|
||||
00023 unselected: classifier-supported; outside the curated output subset
|
||||
00024 unselected: classifier-supported; outside the curated output subset
|
||||
00026 unselected: classifier-supported; outside the curated output subset
|
||||
00028 unselected: classifier-supported; outside the curated output subset
|
||||
00031 unselected: classifier-supported; outside the curated output subset
|
||||
00032 unselected: classifier-supported; outside the curated output subset
|
||||
00033 unselected: classifier-supported; outside the curated output subset
|
||||
00036 unselected: classifier-supported; outside the curated output subset
|
||||
00037 unselected: classifier-supported; outside the curated output subset
|
||||
00040 libc: calloc is not implemented by the conformance shim
|
||||
00041 unselected: classifier-supported; outside the curated output subset
|
||||
00042 unselected: classifier-supported; outside the curated output subset
|
||||
00043 unselected: classifier-supported; outside the curated output subset
|
||||
00044 unselected: classifier-supported; outside the curated output subset
|
||||
00045 unselected: classifier-supported; outside the curated output subset
|
||||
00046 unselected: classifier-supported; outside the curated output subset
|
||||
00047 unselected: classifier-supported; outside the curated output subset
|
||||
00048 unselected: classifier-supported; outside the curated output subset
|
||||
00049 unselected: classifier-supported; outside the curated output subset
|
||||
00050 unselected: classifier-supported; outside the curated output subset
|
||||
00051 unselected: classifier-supported; outside the curated output subset
|
||||
00052 unselected: classifier-supported; outside the curated output subset
|
||||
00053 unselected: classifier-supported; outside the curated output subset
|
||||
00054 unselected: classifier-supported; outside the curated output subset
|
||||
00055 unselected: classifier-supported; outside the curated output subset
|
||||
00057 unselected: classifier-supported; outside the curated output subset
|
||||
00058 unselected: classifier-supported; outside the curated output subset
|
||||
00059 unselected: classifier-supported; outside the curated output subset
|
||||
00060 unselected: classifier-supported; outside the curated output subset
|
||||
00061 unselected: classifier-supported; outside the curated output subset
|
||||
00062 unselected: classifier-supported; outside the curated output subset
|
||||
00063 unselected: classifier-supported; outside the curated output subset
|
||||
00064 unselected: classifier-supported; outside the curated output subset
|
||||
00065 unselected: classifier-supported; outside the curated output subset
|
||||
00066 unselected: classifier-supported; outside the curated output subset
|
||||
00067 unselected: classifier-supported; outside the curated output subset
|
||||
00068 unselected: classifier-supported; outside the curated output subset
|
||||
00069 unselected: classifier-supported; outside the curated output subset
|
||||
00070 unselected: classifier-supported; outside the curated output subset
|
||||
00071 unselected: classifier-supported; outside the curated output subset
|
||||
00072 unselected: classifier-supported; outside the curated output subset
|
||||
00073 unselected: classifier-supported; outside the curated output subset
|
||||
00074 unselected: classifier-supported; outside the curated output subset
|
||||
00075 unselected: classifier-supported; outside the curated output subset
|
||||
00076 unselected: classifier-supported; outside the curated output subset
|
||||
00077 unselected: classifier-supported; outside the curated output subset
|
||||
00078 unselected: classifier-supported; outside the curated output subset
|
||||
00079 unselected: classifier-supported; outside the curated output subset
|
||||
00080 unselected: classifier-supported; outside the curated output subset
|
||||
00081 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00082 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00083 unselected: classifier-supported; outside the curated output subset
|
||||
00084 unselected: classifier-supported; outside the curated output subset
|
||||
00085 unselected: classifier-supported; outside the curated output subset
|
||||
00086 unselected: classifier-supported; outside the curated output subset
|
||||
00087 unselected: classifier-supported; outside the curated output subset
|
||||
00088 unselected: classifier-supported; outside the curated output subset
|
||||
00089 unselected: classifier-supported; outside the curated output subset
|
||||
00090 unselected: classifier-supported; outside the curated output subset
|
||||
00091 unselected: classifier-supported; outside the curated output subset
|
||||
00092 unselected: classifier-supported; outside the curated output subset
|
||||
00093 unselected: classifier-supported; outside the curated output subset
|
||||
00094 unselected: classifier-supported; outside the curated output subset
|
||||
00095 unselected: classifier-supported; outside the curated output subset
|
||||
00096 unselected: classifier-supported; outside the curated output subset
|
||||
00097 unselected: classifier-supported; outside the curated output subset
|
||||
00098 wide-char: wide characters are deferred to M6
|
||||
00099 unselected: classifier-supported; outside the curated output subset
|
||||
00100 unselected: classifier-supported; outside the curated output subset
|
||||
00101 unselected: classifier-supported; outside the curated output subset
|
||||
00102 unselected: classifier-supported; outside the curated output subset
|
||||
00103 unselected: classifier-supported; outside the curated output subset
|
||||
00104 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00105 unselected: classifier-supported; outside the curated output subset
|
||||
00106 unselected: classifier-supported; outside the curated output subset
|
||||
00107 unselected: classifier-supported; outside the curated output subset
|
||||
00108 unselected: classifier-supported; outside the curated output subset
|
||||
00109 unselected: classifier-supported; outside the curated output subset
|
||||
00110 unselected: classifier-supported; outside the curated output subset
|
||||
00111 unselected: classifier-supported; outside the curated output subset
|
||||
00112 unselected: classifier-supported; outside the curated output subset
|
||||
00113 float: floats and doubles are deferred to M6
|
||||
00114 unselected: classifier-supported; outside the curated output subset
|
||||
00115 unselected: classifier-supported; outside the curated output subset
|
||||
00116 unselected: classifier-supported; outside the curated output subset
|
||||
00117 unselected: classifier-supported; outside the curated output subset
|
||||
00118 unselected: classifier-supported; outside the curated output subset
|
||||
00119 float: floats and doubles are deferred to M6
|
||||
00120 unselected: classifier-supported; outside the curated output subset
|
||||
00121 unselected: classifier-supported; outside the curated output subset
|
||||
00122 unselected: classifier-supported; outside the curated output subset
|
||||
00123 float: floats and doubles are deferred to M6
|
||||
00124 unselected: classifier-supported; outside the curated output subset
|
||||
00126 unselected: classifier-supported; outside the curated output subset
|
||||
00127 unselected: classifier-supported; outside the curated output subset
|
||||
00128 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00129 unselected: classifier-supported; outside the curated output subset
|
||||
00130 unselected: classifier-supported; outside the curated output subset
|
||||
00131 unselected: classifier-supported; outside the curated output subset
|
||||
00133 unselected: classifier-supported; outside the curated output subset
|
||||
00134 unselected: classifier-supported; outside the curated output subset
|
||||
00135 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00136 unselected: classifier-supported; outside the curated output subset
|
||||
00137 unselected: classifier-supported; outside the curated output subset
|
||||
00138 unselected: classifier-supported; outside the curated output subset
|
||||
00139 unselected: classifier-supported; outside the curated output subset
|
||||
00140 float: floats and doubles are deferred to M6
|
||||
00141 unselected: classifier-supported; outside the curated output subset
|
||||
00142 unselected: classifier-supported; outside the curated output subset
|
||||
00143 unselected: classifier-supported; outside the curated output subset
|
||||
00144 bitfield: bitfields are deferred to M6
|
||||
00145 unselected: classifier-supported; outside the curated output subset
|
||||
00146 unselected: classifier-supported; outside the curated output subset
|
||||
00147 unselected: classifier-supported; outside the curated output subset
|
||||
00148 unselected: classifier-supported; outside the curated output subset
|
||||
00149 unselected: classifier-supported; outside the curated output subset
|
||||
00150 unselected: classifier-supported; outside the curated output subset
|
||||
00151 unselected: classifier-supported; outside the curated output subset
|
||||
00152 unselected: classifier-supported; outside the curated output subset
|
||||
00153 unselected: classifier-supported; outside the curated output subset
|
||||
00155 unselected: classifier-supported; outside the curated output subset
|
||||
00158 unselected: classifier-supported; outside the curated output subset
|
||||
00159 unselected: classifier-supported; outside the curated output subset
|
||||
00160 unselected: classifier-supported; outside the curated output subset
|
||||
00161 unselected: classifier-supported; outside the curated output subset
|
||||
00162 unselected: classifier-supported; outside the curated output subset
|
||||
00164 unselected: classifier-supported; outside the curated output subset
|
||||
00165 unselected: classifier-supported; outside the curated output subset
|
||||
00166 unselected: classifier-supported; outside the curated output subset
|
||||
00167 unselected: classifier-supported; outside the curated output subset
|
||||
00168 unselected: classifier-supported; outside the curated output subset
|
||||
00169 unselected: classifier-supported; outside the curated output subset
|
||||
00171 unselected: classifier-supported; outside the curated output subset
|
||||
00172 unselected: classifier-supported; outside the curated output subset
|
||||
00174 float: floats and doubles are deferred to M6
|
||||
00175 float: floats and doubles are deferred to M6
|
||||
00176 unselected: classifier-supported; outside the curated output subset
|
||||
00177 unselected: classifier-supported; outside the curated output subset
|
||||
00178 float: floats and doubles are deferred to M6
|
||||
00179 wide-char: wide characters are deferred to M6
|
||||
00180 unselected: classifier-supported; outside the curated output subset
|
||||
00181 unselected: classifier-supported; outside the curated output subset
|
||||
00182 long-long-format: %ll/%L need 64-bit formatting
|
||||
00183 unselected: classifier-supported; outside the curated output subset
|
||||
00184 unselected: classifier-supported; outside the curated output subset
|
||||
00185 unselected: classifier-supported; outside the curated output subset
|
||||
00186 libc: sprintf is not implemented by the conformance shim
|
||||
00187 file-io: stdio/POSIX file I/O is unavailable under the bare loader
|
||||
00188 unselected: classifier-supported; outside the curated output subset
|
||||
00189 file-io: stdio/POSIX file I/O is unavailable under the bare loader
|
||||
00190 unselected: classifier-supported; outside the curated output subset
|
||||
00191 unselected: classifier-supported; outside the curated output subset
|
||||
00192 unselected: classifier-supported; outside the curated output subset
|
||||
00193 unselected: classifier-supported; outside the curated output subset
|
||||
00194 unselected: classifier-supported; outside the curated output subset
|
||||
00195 float: floats and doubles are deferred to M6
|
||||
00196 unselected: classifier-supported; outside the curated output subset
|
||||
00197 unselected: classifier-supported; outside the curated output subset
|
||||
00198 unselected: classifier-supported; outside the curated output subset
|
||||
00199 unselected: classifier-supported; outside the curated output subset
|
||||
00200 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00201 unselected: classifier-supported; outside the curated output subset
|
||||
00202 unselected: classifier-supported; outside the curated output subset
|
||||
00203 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00204 float: floats and doubles are deferred to M6
|
||||
00205 runtime: M2 .data supports only integer, pointer and byte-array initializers (host compile fails)
|
||||
00206 unselected: classifier-supported; outside the curated output subset
|
||||
00207 unselected: classifier-supported; outside the curated output subset
|
||||
00208 wide-char: wide characters are deferred to M6
|
||||
00209 unselected: classifier-supported; outside the curated output subset
|
||||
00210 unselected: classifier-supported; outside the curated output subset
|
||||
00211 unselected: classifier-supported; outside the curated output subset
|
||||
00212 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00216 runtime: M2 .data supports only integer, pointer and byte-array initializers (host compile fails)
|
||||
00217 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00218 bitfield: bitfields are deferred to M6
|
||||
00219 long-long: 64-bit integers (long long/int64) are deferred to M6
|
||||
00220 wide-char: wide characters are deferred to M6
|
||||
@@ -0,0 +1,74 @@
|
||||
# M5 c-torture `execute` subset.
|
||||
#
|
||||
# One test name per line (no .c suffix), selected from
|
||||
# vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute.
|
||||
# The gate runs each name at -O0 and -O2 through the Task 9 conformance
|
||||
# harness and requires main to return 0 in MAME. Keep this list to the
|
||||
# integer/control/array/pointer subset: no floats, 64-bit integers, bitfields,
|
||||
# general varargs, aggregates by value, setjmp, signals, wide
|
||||
# characters, or file I/O. Seeded by Task 11.
|
||||
#
|
||||
# Integer arithmetic, conversions, and bit operations
|
||||
20000313-1
|
||||
20000503-1
|
||||
20000519-2
|
||||
20000715-2
|
||||
20001009-1
|
||||
20021118-3
|
||||
20030128-1
|
||||
20030821-1
|
||||
20050410-1
|
||||
20070724-1
|
||||
20071205-1
|
||||
20081112-1
|
||||
920721-1
|
||||
941025-1
|
||||
950706-1
|
||||
960219-1
|
||||
961122-2
|
||||
990324-1
|
||||
991202-2
|
||||
#
|
||||
# Control flow: loops, conditionals, switch, recursion
|
||||
20000205-1
|
||||
20000412-2
|
||||
20000412-4
|
||||
20000511-1
|
||||
20000731-2
|
||||
20010206-1
|
||||
20010422-1
|
||||
20010723-1
|
||||
20040706-1
|
||||
20070212-2
|
||||
920506-1
|
||||
930123-1
|
||||
960419-1
|
||||
961017-1
|
||||
980602-1
|
||||
980929-1
|
||||
990604-1
|
||||
991202-1
|
||||
#
|
||||
# Arrays, pointers, and string literals
|
||||
20000112-1
|
||||
20000314-1
|
||||
20000314-3
|
||||
20000403-1
|
||||
20000412-1
|
||||
20000412-6
|
||||
20000422-1
|
||||
20000706-4
|
||||
20001027-1
|
||||
20010711-1
|
||||
20011109-2
|
||||
20011114-1
|
||||
20011128-1
|
||||
20020911-1
|
||||
20021119-1
|
||||
20050106-1
|
||||
20090207-1
|
||||
930429-1
|
||||
931110-2
|
||||
951115-1
|
||||
960419-2
|
||||
991227-1
|
||||
Executable
+200
@@ -0,0 +1,200 @@
|
||||
#!/bin/sh
|
||||
# M5 GCC c-torture `execute` subset gate.
|
||||
#
|
||||
# scripts/tests/m5/c-torture.sh [LIST]
|
||||
# scripts/tests/m5/c-torture.sh --scan [CORPUS_DIR]
|
||||
#
|
||||
# LIST is the curated allowlist (default: scripts/tests/m5/c-torture.list).
|
||||
# Each non-comment line names a test under the pinned GCC 16.2.0
|
||||
# gcc.c-torture/execute tree. The gate compiles every test through the Task 9
|
||||
# conformance harness twice, once with tms-clang -O0 and once with -O2 (both
|
||||
# the IR pipeline and llc), links the shim/entry, runs the COFF in MAME, and
|
||||
# requires main to return 0 with the completion magic present. stdout is
|
||||
# ignored because c-torture tests may print diagnostics on success; the status
|
||||
# is the oracle. A test that cannot compile is not silently dropped: the
|
||||
# classifier reports it as a skip with a reason, and a run with no passing
|
||||
# test fails even when every test was skipped.
|
||||
#
|
||||
# --scan is the broader report mode: it runs the classifier over every .c in
|
||||
# the corpus, writes build/m5-c-torture/c-torture-scan.txt, and prints the
|
||||
# supported/skip counts by feature. It never compiles or runs a test, so it is
|
||||
# a selection report, not the gate.
|
||||
#
|
||||
# The default MAME injection/exit frames are lower than Task 9's 2500/2700.
|
||||
# The VT1200 OS is ready well before frame 300 (verified against the pinned
|
||||
# loader); 300 leaves a wide margin while keeping the serial suite practical.
|
||||
# The loader COFF readback and the completion magic are still required, so the
|
||||
# lower frame does not weaken the pass condition.
|
||||
#
|
||||
# Overridable: C_TORTURE_DIR C_TORTURE_LOADER_AT C_TORTURE_LOADER_END
|
||||
# M5_C_TORTURE_WORK M5_CONFORMANCE_DIR
|
||||
# M5_CONFORMANCE_CLANG_OPT M5_CONFORMANCE_LLC_OPT (per pass)
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$HERE/conformance}
|
||||
CONFORMANCE=$CONFORMANCE_DIR/c-torture.sh
|
||||
CLASSIFY=$CONFORMANCE_DIR/classify.sh
|
||||
SUITE_DIR=${C_TORTURE_DIR:-$ROOT/vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute}
|
||||
WORK=${M5_C_TORTURE_WORK:-$ROOT/build/m5-c-torture}
|
||||
LOADER_AT=${C_TORTURE_LOADER_AT:-300}
|
||||
LOADER_END=${C_TORTURE_LOADER_END:-600}
|
||||
|
||||
fail() {
|
||||
echo "c-torture: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$CONFORMANCE" ] || fail "missing conformance entry point: $CONFORMANCE"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-torture tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
SCAN=0
|
||||
LIST=$HERE/c-torture.list
|
||||
if [ $# -gt 0 ]; then
|
||||
case $1 in
|
||||
--scan)
|
||||
SCAN=1
|
||||
shift
|
||||
[ $# -eq 0 ] || { SUITE_DIR=$1; shift; }
|
||||
;;
|
||||
-*)
|
||||
fail "unknown option: $1"
|
||||
;;
|
||||
*)
|
||||
LIST=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
[ $# -eq 0 ] || fail "unexpected trailing arguments: $*"
|
||||
[ -d "$SUITE_DIR" ] || fail "missing corpus: $SUITE_DIR"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
if [ "$SCAN" -eq 1 ]; then
|
||||
REPORT=$WORK/c-torture-scan.txt
|
||||
find "$SUITE_DIR" -maxdepth 1 -type f -name '*.c' | sort \
|
||||
> "$WORK/c-torture-corpus.txt"
|
||||
total=0
|
||||
supported=0
|
||||
skipped=0
|
||||
{
|
||||
echo "# M5 c-torture execute classifier scan"
|
||||
echo "# corpus: $SUITE_DIR"
|
||||
echo "# rows: status<TAB>test<TAB>reason"
|
||||
} > "$REPORT"
|
||||
while IFS= read -r src; do
|
||||
name=$(basename "$src" .c)
|
||||
total=$((total + 1))
|
||||
set +e
|
||||
reason=$("$CLASSIFY" "$src" 2>&1)
|
||||
rc=$?
|
||||
set -e
|
||||
case $rc in
|
||||
0)
|
||||
supported=$((supported + 1))
|
||||
printf 'supported\t%s\t\n' "$name" >> "$REPORT"
|
||||
;;
|
||||
1)
|
||||
skipped=$((skipped + 1))
|
||||
printf 'skip\t%s\t%s\n' "$name" "$reason" >> "$REPORT"
|
||||
;;
|
||||
*)
|
||||
fail "classifier error (exit $rc) on $name: $reason"
|
||||
;;
|
||||
esac
|
||||
done < "$WORK/c-torture-corpus.txt"
|
||||
{
|
||||
echo "# total $total supported $supported skip $skipped"
|
||||
} >> "$REPORT"
|
||||
echo "c-torture scan: total=$total supported=$supported skip=$skipped"
|
||||
echo "c-torture scan: skipped tests by feature:"
|
||||
awk -F '\t' '$1 == "skip" { split($3, a, ":"); print a[1] }' "$REPORT" \
|
||||
| sort | uniq -c | sort -rn | sed 's/^/ /' || true
|
||||
echo "c-torture scan: report $REPORT"
|
||||
[ "$supported" -gt 0 ] || fail "no supported c-torture tests in $SUITE_DIR"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
[ -f "$LIST" ] || fail "no c-torture.list ($LIST); Task 11 seeds it"
|
||||
LIST_COUNT=$(awk '$0 !~ /^[[:space:]]*(#|$)/ { n++ } END { print n + 0 }' "$LIST")
|
||||
[ "$LIST_COUNT" -gt 0 ] || fail "c-torture.list is empty ($LIST)"
|
||||
|
||||
# Each pass writes its own conformance log. The Task 9 runner prints one
|
||||
# machine-readable result line per test, plus the suite summary.
|
||||
run_pass() {
|
||||
opt=$1
|
||||
log=$2
|
||||
set +e
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$LOADER_END \
|
||||
M5_CONFORMANCE_CLANG_OPT=$opt \
|
||||
M5_CONFORMANCE_LLC_OPT=$opt \
|
||||
"$CONFORMANCE" "$LIST" > "$log" 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
echo "$rc" > "$log.rc"
|
||||
}
|
||||
|
||||
count() {
|
||||
awk -v pat="$2" '$0 ~ pat { n++ } END { print n + 0 }' "$1"
|
||||
}
|
||||
|
||||
run_pass -O0 "$WORK/c-torture-O0.log"
|
||||
run_pass -O2 "$WORK/c-torture-O2.log"
|
||||
|
||||
bad=0
|
||||
for opt in -O0 -O2; do
|
||||
case $opt in
|
||||
-O0) log=$WORK/c-torture-O0.log ;;
|
||||
-O2) log=$WORK/c-torture-O2.log ;;
|
||||
esac
|
||||
rc=$(cat "$log.rc")
|
||||
pass=$(count "$log" '^CONFORMANCE: PASS ')
|
||||
skip=$(count "$log" '^CONFORMANCE: SKIP ')
|
||||
# A test can print both a CONFORMANCE: FAIL row and the runner's
|
||||
# "c-torture: FAIL <name>" line; a compile/link/MAME failure that exits
|
||||
# before run.sh prints a result row only prints the latter. Count the
|
||||
# union of test names so a failure is not counted twice.
|
||||
: > "$WORK/c-torture-fail-names.log"
|
||||
grep '^CONFORMANCE: FAIL id=c-torture/' "$log" 2>/dev/null \
|
||||
| sed 's/^CONFORMANCE: FAIL id=c-torture\///; s/[[:space:]].*$//' \
|
||||
>> "$WORK/c-torture-fail-names.log" || true
|
||||
grep '^c-torture: FAIL ' "$log" 2>/dev/null \
|
||||
| sed 's/^c-torture: FAIL //; s/[[:space:]].*$//' \
|
||||
>> "$WORK/c-torture-fail-names.log" || true
|
||||
failn=$(sort -u "$WORK/c-torture-fail-names.log" | wc -l | tr -d ' ')
|
||||
[ "$pass" -gt 0 ] || {
|
||||
echo "c-torture: $opt no tests passed (pass=0 skip=$skip); all-skip is not a pass" >&2
|
||||
bad=1
|
||||
}
|
||||
[ "$failn" -eq 0 ] || {
|
||||
echo "c-torture: $opt $failn test(s) failed" >&2
|
||||
bad=1
|
||||
}
|
||||
[ "$rc" -eq 0 ] || {
|
||||
echo "c-torture: $opt conformance runner exited $rc" >&2
|
||||
bad=1
|
||||
}
|
||||
TOTAL=$((pass + skip + failn))
|
||||
[ "$TOTAL" -eq "$LIST_COUNT" ] || {
|
||||
echo "c-torture: $opt produced $TOTAL result rows, list has $LIST_COUNT" >&2
|
||||
bad=1
|
||||
}
|
||||
if [ "$skip" -gt 0 ]; then
|
||||
echo "c-torture: $opt skipped $skip test(s):" >&2
|
||||
grep '^CONFORMANCE: SKIP ' "$log" | sed 's/^/ /' >&2 || true
|
||||
fi
|
||||
eval "PASS_${opt#-}=$pass"
|
||||
eval "SKIP_${opt#-}=$skip"
|
||||
eval "FAIL_${opt#-}=$failn"
|
||||
done
|
||||
|
||||
if [ "$bad" -ne 0 ]; then
|
||||
echo "c-torture: logs $WORK" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "c-torture: PASS O0 pass=$PASS_O0 skip=$SKIP_O0 total=$LIST_COUNT O2 pass=$PASS_O2 skip=$SKIP_O2 total=$LIST_COUNT"
|
||||
echo "c-torture: logs $WORK"
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
# c-testsuite single-exec entry point (M5 Task 12 seeds the list).
|
||||
#
|
||||
# c-testsuite.sh [LIST]
|
||||
#
|
||||
# Each non-comment line of LIST names a test under the pinned
|
||||
# vendor/conformance/c-testsuite/tests/single-exec tree. The test is
|
||||
# classified first; unsupported tests are reported as skips (never passes).
|
||||
# A supported test must return 0 and its stdout must equal
|
||||
# <name>.c.expected. A run with no passing test is a failure, even if every
|
||||
# test was skipped. This tier requires the native TI-COFF link (--mode native);
|
||||
# an asm/GSPA fallback is a failure, so a native-object regression cannot hide
|
||||
# here. All compile, link, MAME and compare work lives in run.sh.
|
||||
#
|
||||
# Default list: scripts/tests/m5/c-testsuite.list
|
||||
# Overridable: C_TESTSUITE_DIR M5_CONFORMANCE_DIR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
RUN=$HERE/run.sh
|
||||
CLASSIFY=$HERE/classify.sh
|
||||
|
||||
LIST=${1:-$ROOT/scripts/tests/m5/c-testsuite.list}
|
||||
SUITE_DIR=${C_TESTSUITE_DIR:-$ROOT/vendor/conformance/c-testsuite/tests/single-exec}
|
||||
|
||||
fail() {
|
||||
echo "c-testsuite: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
if [ ! -f "$LIST" ]; then
|
||||
fail "no c-testsuite.list ($LIST); Task 12 seeds it"
|
||||
fi
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-testsuite tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
pass=0
|
||||
skip=0
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
total=$((total + 1))
|
||||
base=${name%.c}
|
||||
src=$SUITE_DIR/$base.c
|
||||
expected=$SUITE_DIR/$base.c.expected
|
||||
[ -f "$expected" ] || expected=$SUITE_DIR/$base.expected
|
||||
[ -f "$src" ] || fail "missing c-testsuite source: $src"
|
||||
[ -f "$expected" ] || fail "missing c-testsuite expected output: $expected"
|
||||
if "$RUN" --id "c-testsuite/$base" --classify --mode native \
|
||||
--expect-status 0 --expect-output-file "$expected" "$src"; then
|
||||
pass=$((pass + 1))
|
||||
else
|
||||
rc=$?
|
||||
if [ "$rc" -eq 2 ]; then
|
||||
skip=$((skip + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "c-testsuite: FAIL $base" >&2
|
||||
fi
|
||||
fi
|
||||
done < "$LIST"
|
||||
|
||||
[ "$total" -gt 0 ] || fail "c-testsuite.list is empty"
|
||||
[ "$failed" -eq 0 ] || fail "$failed of $total tests failed"
|
||||
[ "$pass" -gt 0 ] \
|
||||
|| fail "no tests passed (pass=0 skip=$skip total=$total); all-skip is not a pass"
|
||||
echo "c-testsuite: PASS pass=$pass skip=$skip total=$total"
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/bin/sh
|
||||
# c-torture conformance entry point (M5 Task 11 seeds the list).
|
||||
#
|
||||
# c-torture.sh [LIST]
|
||||
#
|
||||
# Each non-comment line of LIST names a test under the pinned
|
||||
# vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute tree.
|
||||
# The test is classified first; unsupported tests are reported as skips (never
|
||||
# passes), and supported tests must return 0 (stdout is ignored here). A run
|
||||
# with no passing test is a failure, even if every test was skipped. All
|
||||
# compile, link, MAME and compare work lives in run.sh.
|
||||
#
|
||||
# Default list: scripts/tests/m5/c-torture.list
|
||||
# Overridable: C_TORTURE_DIR M5_CONFORMANCE_DIR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
RUN=$HERE/run.sh
|
||||
CLASSIFY=$HERE/classify.sh
|
||||
|
||||
LIST=${1:-$ROOT/scripts/tests/m5/c-torture.list}
|
||||
SUITE_DIR=${C_TORTURE_DIR:-$ROOT/vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute}
|
||||
|
||||
fail() {
|
||||
echo "c-torture: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
if [ ! -f "$LIST" ]; then
|
||||
fail "no c-torture.list ($LIST); Task 11 seeds it"
|
||||
fi
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-torture tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
pass=0
|
||||
skip=0
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
total=$((total + 1))
|
||||
src=$SUITE_DIR/$name.c
|
||||
[ -f "$src" ] || fail "missing c-torture source: $src"
|
||||
if "$RUN" --id "c-torture/$name" --classify \
|
||||
--expect-status 0 --ignore-output "$src"; then
|
||||
pass=$((pass + 1))
|
||||
else
|
||||
rc=$?
|
||||
if [ "$rc" -eq 2 ]; then
|
||||
skip=$((skip + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "c-torture: FAIL $name" >&2
|
||||
fi
|
||||
fi
|
||||
done < "$LIST"
|
||||
|
||||
[ "$total" -gt 0 ] || fail "c-torture.list is empty"
|
||||
[ "$failed" -eq 0 ] || fail "$failed of $total tests failed"
|
||||
[ "$pass" -gt 0 ] \
|
||||
|| fail "no tests passed (pass=0 skip=$skip total=$total); all-skip is not a pass"
|
||||
echo "c-torture: PASS pass=$pass skip=$skip total=$total"
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
# Classify a C source for features the M5 conformance path cannot run.
|
||||
#
|
||||
# classify.sh FILE
|
||||
#
|
||||
# Prints "feature: reason" and exits 1 when the source uses an unsupported
|
||||
# feature; prints nothing and exits 0 when it is acceptable. Exits 2 for
|
||||
# usage, unreadable-source, grep or skip-table errors, so callers can tell a
|
||||
# real skip apart from a classifier failure. The reasons come from skip.tsv
|
||||
# so the manifest, suite runners and reports agree.
|
||||
#
|
||||
# This is deliberately conservative: a false positive skips a test (and says
|
||||
# why), while a false negative could turn an unsupported test into a fake
|
||||
# pass. Comments and string literals are scanned too.
|
||||
set -eu
|
||||
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
SKIPS=$HERE/skip.tsv
|
||||
|
||||
[ $# -eq 1 ] || { echo "usage: $0 FILE.c" >&2; exit 2; }
|
||||
SRC=$1
|
||||
[ -f "$SRC" ] || { echo "classify: missing source: $SRC" >&2; exit 2; }
|
||||
[ -f "$SKIPS" ] || { echo "classify: missing $SKIPS" >&2; exit 2; }
|
||||
|
||||
feature=
|
||||
|
||||
match() {
|
||||
[ -z "$feature" ] || return 0
|
||||
if grep -Eqi -- "$2" "$SRC"; then
|
||||
feature=$1
|
||||
else
|
||||
st=$?
|
||||
[ "$st" -eq 1 ] || {
|
||||
echo "classify: grep failed (status $st) on $SRC" >&2
|
||||
exit 2
|
||||
}
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
match_cs() {
|
||||
[ -z "$feature" ] || return 0
|
||||
if grep -Eq -- "$2" "$SRC"; then
|
||||
feature=$1
|
||||
else
|
||||
st=$?
|
||||
[ "$st" -eq 1 ] || {
|
||||
echo "classify: grep failed (status $st) on $SRC" >&2
|
||||
exit 2
|
||||
}
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Order is only cosmetic; the first match names the primary blocker. Most
|
||||
# matches are case-insensitive so macro spellings (INT64_MAX, UINT64_C,
|
||||
# intmax_t) are not missed. The %ll/%L length check stays case-sensitive
|
||||
# because %ld is supported while %Ld is a long-double format.
|
||||
match float '(^|[^A-Za-z0-9_])(float|double)([^A-Za-z0-9_]|$)'
|
||||
match long-long 'long[[:space:]]+long|(^|[^A-Za-z0-9_])(u?int64(_t)?|intmax_t|uintmax_t|__int64(_t)?|int64_max|int64_c|uint64_max|uint64_c)([^A-Za-z0-9_]|$)'
|
||||
match int128 '__int128|__uint128|__int128_t|__uint128_t'
|
||||
match bitfield '[A-Za-z_][A-Za-z0-9_]*[[:space:]]*:[[:space:]]*[0-9]+[[:space:]]*;'
|
||||
match varargs '(^|[^A-Za-z0-9_])(va_list|va_start|va_arg|va_end|va_copy)([^A-Za-z0-9_]|$)'
|
||||
match setjmp '(^|[^A-Za-z0-9_])(setjmp|longjmp|sigsetjmp|siglongjmp)([^A-Za-z0-9_]|$)'
|
||||
match signal '(^|[^A-Za-z0-9_])(signal|sigaction|sigemptyset|sigaddset|sigprocmask)([^A-Za-z0-9_]|$)'
|
||||
match wide-char '(^|[^A-Za-z0-9_])(wchar|wchar_t|wint_t|wprintf|wscanf)([^A-Za-z0-9_]|$)|L"|L'"'"''
|
||||
match float-format '%[-+ #0-9.*]*[fFeEgGaA]'
|
||||
match_cs long-long-format '%[-+ #0-9.*]*ll|%[-+ #0-9.*]*LL|%[-+ #0-9.*]*L'
|
||||
match format-unsupported '%[-+ #0-9.*]*n|%[-+ #0-9.]*\*|%[-+ #0-9]*\.[0-9*]*[diouxXcspn]'
|
||||
match file-io '(^|[^A-Za-z0-9_])(FILE|fopen|fclose|fread|fwrite|fprintf|freopen|fflush|fseek|ftell|fgetc|fputc|fgets|fputs|remove|rename|tmpfile|tmpnam)([^A-Za-z0-9_]|$)|(^|[^A-Za-z0-9_])(open|creat)[[:space:]]*\('
|
||||
|
||||
[ -n "$feature" ] || exit 0
|
||||
|
||||
reason=$(awk -F '\t' -v f="$feature" '$1 == f { print $2; exit }' "$SKIPS") \
|
||||
|| { echo "classify: cannot read $SKIPS" >&2; exit 2; }
|
||||
[ -n "$reason" ] || {
|
||||
echo "classify: no reason for feature '$feature' in $SKIPS" >&2
|
||||
exit 2
|
||||
}
|
||||
printf '%s: %s\n' "$feature" "$reason"
|
||||
exit 1
|
||||
@@ -0,0 +1,129 @@
|
||||
-- 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")
|
||||
@@ -0,0 +1,10 @@
|
||||
; data-pad.asm -- keep the linked .data section a whole number of 16-bit words.
|
||||
;
|
||||
; llc emits an odd-length byte array (for example a 7-byte string literal)
|
||||
; without a trailing word, so the concatenated .data section can end on an
|
||||
; odd byte. The VT1200 COFF loader rejects a section whose bit size is not a
|
||||
; whole number of words (status 4). This object is linked last in both the
|
||||
; native and asm paths. GSPA aligns a .word directive to a 16-bit boundary,
|
||||
; so this pads any preceding odd byte and then contributes exactly one word.
|
||||
.data
|
||||
.word 0
|
||||
@@ -0,0 +1,68 @@
|
||||
; entry.asm -- M5 conformance entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the test's main(1, argv) through the M4 TI ABI and publishes the
|
||||
; result for the MAME check:
|
||||
;
|
||||
; 01B00000 status main's return value
|
||||
; 01B00020 out_len maintained by shim.c
|
||||
; 01B00040 magic 0x434F4E46 after main returns
|
||||
; 01B10000 output shim.c's 16 KiB output buffer
|
||||
;
|
||||
; The result block is above the linker-managed RAM region
|
||||
; (01A00000..01A80000), so a test's .bss cannot overwrite it. That region is
|
||||
; 64 KiB and this file reserves 4 KiB for _cstack; Tasks 11/12 should keep the
|
||||
; sum of globals and stack under those limits.
|
||||
;
|
||||
; exit()/abort() in shim.c publish status and magic themselves and spin, so
|
||||
; an abnormal test still leaves an observable result. argv is a real
|
||||
; two-element vector: { "conformance", NULL }.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
|
||||
; Clear the result cells that live outside every loaded section.
|
||||
movi 01B00000h, a1
|
||||
sub a0, a0
|
||||
move a0, *a1, 1
|
||||
movi 01B00020h, a1
|
||||
move a0, *a1, 1
|
||||
movi 01B00040h, a1
|
||||
move a0, *a1, 1
|
||||
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
; argv[0] = "conformance", argv[1] = NULL.
|
||||
movi _conformance_argv, a0
|
||||
movi _conformance_name, a1
|
||||
move a1, *a0, 1
|
||||
sub a1, a1
|
||||
move a1, *a0(32), 1
|
||||
|
||||
; main(1, argv): arguments are pushed in reverse order on A14.
|
||||
move a14, -*sp, 1
|
||||
move a0, *a14+, 1
|
||||
movi 1, a1
|
||||
move a1, *a14+, 1
|
||||
calla _main
|
||||
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
|
||||
movi 01B00000h, a1
|
||||
move a8, *a1, 1
|
||||
movi 01B00040h, a1
|
||||
movi 434F4E46h, a0
|
||||
move a0, *a1, 1
|
||||
rets
|
||||
|
||||
.data
|
||||
_conformance_name:
|
||||
.byte 063h, 06Fh, 06Eh, 066h, 06Fh, 072h, 06Dh, 061h
|
||||
.byte 06Eh, 063h, 065h, 000h
|
||||
.even
|
||||
|
||||
.bss _conformance_argv, 64, 1
|
||||
.bss _cstack, 32768, 16
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef CONFORMANCE_LIMITS_H
|
||||
#define CONFORMANCE_LIMITS_H
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define SCHAR_MIN (-128)
|
||||
#define SCHAR_MAX 127
|
||||
#define UCHAR_MAX 255
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#define SHRT_MIN (-32768)
|
||||
#define SHRT_MAX 32767
|
||||
#define USHRT_MAX 65535
|
||||
#define INT_MIN (-2147483647 - 1)
|
||||
#define INT_MAX 2147483647
|
||||
#define UINT_MAX 4294967295U
|
||||
#define LONG_MIN INT_MIN
|
||||
#define LONG_MAX INT_MAX
|
||||
#define ULONG_MAX UINT_MAX
|
||||
#define LLONG_MIN (-9223372036854775807LL - 1)
|
||||
#define LLONG_MAX 9223372036854775807LL
|
||||
#define ULLONG_MAX 18446744073709551615ULL
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef CONFORMANCE_STDDEF_H
|
||||
#define CONFORMANCE_STDDEF_H
|
||||
|
||||
typedef unsigned int size_t;
|
||||
typedef int ptrdiff_t;
|
||||
typedef int wchar_t;
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef CONFORMANCE_STDINT_H
|
||||
#define CONFORMANCE_STDINT_H
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef int intptr_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
|
||||
#define INT8_MIN (-128)
|
||||
#define INT8_MAX 127
|
||||
#define UINT8_MAX 255U
|
||||
#define INT16_MIN (-32768)
|
||||
#define INT16_MAX 32767
|
||||
#define UINT16_MAX 65535U
|
||||
#define INT32_MIN (-2147483647 - 1)
|
||||
#define INT32_MAX 2147483647
|
||||
#define UINT32_MAX 4294967295U
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef CONFORMANCE_STDIO_H
|
||||
#define CONFORMANCE_STDIO_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
int printf(const char *fmt, ...);
|
||||
int putchar(int c);
|
||||
int puts(const char *s);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef CONFORMANCE_STDLIB_H
|
||||
#define CONFORMANCE_STDLIB_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
#define RAND_MAX 32767
|
||||
|
||||
void exit(int status);
|
||||
void _exit(int status);
|
||||
void abort(void);
|
||||
int atoi(const char *s);
|
||||
int abs(int v);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef CONFORMANCE_STRING_H
|
||||
#define CONFORMANCE_STRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
unsigned int strlen(const char *s);
|
||||
int strcmp(const char *a, const char *b);
|
||||
int strncmp(const char *a, const char *b, unsigned int n);
|
||||
char *strcpy(char *d, const char *s);
|
||||
char *strncpy(char *d, const char *s, unsigned int n);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strrchr(const char *s, int c);
|
||||
void *memcpy(void *dst, const void *src, unsigned int n);
|
||||
void *memmove(void *dst, const void *src, unsigned int n);
|
||||
void *memset(void *dst, int c, unsigned int n);
|
||||
int memcmp(const void *a, const void *b, unsigned int n);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
-a
|
||||
-o M4.OUT
|
||||
-m M4.MAP
|
||||
-e _start
|
||||
M4.obj
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 58000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# M5 conformance manifest
|
||||
#
|
||||
# test_id<TAB>suite<TAB>expected<TAB>features<TAB>skip_reason
|
||||
#
|
||||
# expected: status=<decimal> or status=<decimal>;stdout=<escaped text>
|
||||
# escapes: \n \t \r \\ (interpreted with printf %b)
|
||||
# features: space-separated classifier tags (int-control, print, ...)
|
||||
# skip_reason: empty for a runnable row; a non-empty reason is reported as a
|
||||
# SKIP and is never counted as a pass.
|
||||
#
|
||||
# Tasks 11 and 12 seed the c-torture and c-testsuite rows. This file defines
|
||||
# the row format and is read by scripts/tests/m5/conformance/run.sh
|
||||
# --manifest-row.
|
||||
#
|
||||
# Examples (kept commented so the gate does not try to fetch them here):
|
||||
# int-control/c0001 c-torture status=0;stdout= int-control
|
||||
# single-exec/0001 c-testsuite status=0;stdout=ok\n print #
|
||||
|
Executable
+478
@@ -0,0 +1,478 @@
|
||||
#!/bin/sh
|
||||
# M5 conformance runner: compile one C test with the shim and entry, link it
|
||||
# through the M4 pipeline (native TI-COFF when it works, asm/GSPA fallback),
|
||||
# load the COFF in MAME, and compare the observed status/stdout with the
|
||||
# expected result.
|
||||
#
|
||||
# run.sh [options] SOURCE.c
|
||||
#
|
||||
# --id ID label (default: source basename)
|
||||
# --expect SPEC expected result:
|
||||
# status=<decimal>[;stdout=<escaped text>]
|
||||
# escapes understood by printf %b: \n \t \r \\
|
||||
# default: status=0;stdout= (silent success)
|
||||
# --expect-status N override the expected status
|
||||
# --expect-output-file F expect stdout to be exactly the bytes in F
|
||||
# --ignore-output compare only the status (c-torture success is silent
|
||||
# or diagnostic output; c-testsuite keeps the compare)
|
||||
# --manifest-row ROW parse test_id<TAB>suite<TAB>expected<TAB>features<TAB>skip_reason
|
||||
# --classify skip (exit 2) when classify.sh rejects SOURCE
|
||||
# --mode auto|native|asm link mode (default auto: native, asm fallback)
|
||||
# --native same as --mode native
|
||||
# --asm same as --mode asm
|
||||
# --timeout SECONDS MAME timeout (default 900)
|
||||
#
|
||||
# Exit status: 0 pass, 1 failure (compile/link/MAME/classifier/compare),
|
||||
# 2 skip (a classified unsupported test or a manifest skip_reason).
|
||||
#
|
||||
# The linker-managed .bss region is 01A00000..01A80000 (64 KiB, including the
|
||||
# 4 KiB _cstack in entry.asm). The result block is above it at 01B00000, so a
|
||||
# test's globals cannot overwrite the status/output.
|
||||
#
|
||||
# The runner prints one machine-readable result line:
|
||||
# CONFORMANCE: PASS id=... status=... stdout_len=... link=...
|
||||
# CONFORMANCE: FAIL id=...
|
||||
# CONFORMANCE: SKIP id=... reason=...
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG M4_SDK LOADER_AT LOADER_END MAME_TIMEOUT
|
||||
# M5_CONFORMANCE_WORK M5_CONFORMANCE_CLANG_OPT
|
||||
# M5_CONFORMANCE_LLC_OPT M5_CONFORMANCE_MODE
|
||||
# M5_CONFORMANCE_CLASSIFY
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CLASSIFY=${M5_CONFORMANCE_CLASSIFY:-$HERE/classify.sh}
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
M4_SDK=${M4_SDK:-$ROOT/build/m4-sdk}
|
||||
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=${LOADER_BIN:-$ROOT/vendor/vt1200/dwt/loader/build/loader.bin}
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
MAME_TIMEOUT=${MAME_TIMEOUT:-900}
|
||||
|
||||
WORK_BASE=${M5_CONFORMANCE_WORK:-$ROOT/build/m5-conformance}
|
||||
CLANG_OPT=${M5_CONFORMANCE_CLANG_OPT:--O0}
|
||||
LLC_OPT=${M5_CONFORMANCE_LLC_OPT:--O0}
|
||||
MODE=${M5_CONFORMANCE_MODE:-auto}
|
||||
|
||||
# Shim contract constants (keep in sync with shim.c and conformance-check.lua).
|
||||
OUT_CAP=16384
|
||||
PROG_ORIGIN=$((0x018A0000))
|
||||
PROG_END=$((0x018F8000))
|
||||
RAM_ORIGIN=$((0x01A00000))
|
||||
RAM_END=$((0x01A80000))
|
||||
RESULT_BASE=$((0x01B00000))
|
||||
|
||||
ID=
|
||||
SRC=
|
||||
EXPECT_SPEC=
|
||||
EXPECT_SPEC_SET=0
|
||||
EXPECT_STATUS=
|
||||
EXPECT_OUTPUT_FILE=
|
||||
MANIFEST_ROW=
|
||||
DO_CLASSIFY=0
|
||||
IGNORE_OUTPUT=0
|
||||
FEATURES=
|
||||
|
||||
fail() {
|
||||
echo "conformance: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
sed -n '2,/^set -eu/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--id)
|
||||
[ $# -ge 2 ] || usage
|
||||
ID=$2
|
||||
shift 2
|
||||
;;
|
||||
--expect)
|
||||
[ $# -ge 2 ] || usage
|
||||
EXPECT_SPEC=$2
|
||||
EXPECT_SPEC_SET=1
|
||||
shift 2
|
||||
;;
|
||||
--expect-status)
|
||||
[ $# -ge 2 ] || usage
|
||||
EXPECT_STATUS=$2
|
||||
shift 2
|
||||
;;
|
||||
--expect-output-file)
|
||||
[ $# -ge 2 ] || usage
|
||||
EXPECT_OUTPUT_FILE=$2
|
||||
shift 2
|
||||
;;
|
||||
--ignore-output)
|
||||
IGNORE_OUTPUT=1
|
||||
shift
|
||||
;;
|
||||
--manifest-row)
|
||||
[ $# -ge 2 ] || usage
|
||||
MANIFEST_ROW=$2
|
||||
shift 2
|
||||
;;
|
||||
--classify)
|
||||
DO_CLASSIFY=1
|
||||
shift
|
||||
;;
|
||||
--mode)
|
||||
[ $# -ge 2 ] || usage
|
||||
MODE=$2
|
||||
shift 2
|
||||
;;
|
||||
--native)
|
||||
MODE=native
|
||||
shift
|
||||
;;
|
||||
--asm)
|
||||
MODE=asm
|
||||
shift
|
||||
;;
|
||||
--timeout)
|
||||
[ $# -ge 2 ] || usage
|
||||
MAME_TIMEOUT=$2
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
echo "conformance: unknown option: $1" >&2
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
[ -z "$SRC" ] || fail "more than one source given: $SRC and $1"
|
||||
SRC=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
[ $# -eq 0 ] || fail "unexpected trailing arguments: $*"
|
||||
[ -n "$SRC" ] || usage
|
||||
[ -f "$SRC" ] || fail "missing source: $SRC"
|
||||
case $MODE in
|
||||
auto|native|asm) ;;
|
||||
*) fail "bad link mode '$MODE' (want auto, native or asm)" ;;
|
||||
esac
|
||||
|
||||
if [ -n "$MANIFEST_ROW" ]; then
|
||||
ROW_ID=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $1}')
|
||||
ROW_SUITE=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $2}')
|
||||
ROW_EXPECT=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $3}')
|
||||
ROW_FEATURES=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $4}')
|
||||
ROW_SKIP=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $5}')
|
||||
[ -n "$ID" ] || ID=$ROW_ID
|
||||
if [ -n "$ROW_EXPECT" ]; then
|
||||
EXPECT_SPEC=$ROW_EXPECT
|
||||
EXPECT_SPEC_SET=1
|
||||
fi
|
||||
FEATURES=$ROW_FEATURES
|
||||
if [ -n "$ROW_SKIP" ]; then
|
||||
echo "CONFORMANCE: SKIP id=${ID:-$SRC} reason=$ROW_SKIP"
|
||||
exit 2
|
||||
fi
|
||||
# The suite column is informational; keep it in logs when present.
|
||||
[ -z "$ROW_SUITE" ] || FEATURES="${FEATURES:+$FEATURES }suite=$ROW_SUITE"
|
||||
fi
|
||||
|
||||
[ -n "$ID" ] || ID=$(basename "$SRC" .c)
|
||||
case $ID in
|
||||
.|..) fail "unsafe id '$ID' (would escape the work directory)" ;;
|
||||
esac
|
||||
SAFE_ID=$(printf '%s' "$ID" | tr -c 'A-Za-z0-9._-' '_')
|
||||
case $SAFE_ID in
|
||||
''|.|..) fail "unsafe id '$ID' (would escape the work directory)" ;;
|
||||
esac
|
||||
WORK=$WORK_BASE/$SAFE_ID
|
||||
|
||||
if [ "$DO_CLASSIFY" -eq 1 ]; then
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
set +e
|
||||
REASON=$("$CLASSIFY" "$SRC" 2>&1)
|
||||
RC=$?
|
||||
set -e
|
||||
case $RC in
|
||||
0) ;;
|
||||
1) echo "CONFORMANCE: SKIP id=$ID reason=$REASON"; exit 2 ;;
|
||||
*) fail "classifier error (exit $RC): $REASON" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Parse the expected result after any manifest/option overrides.
|
||||
STATUS_EXPECT=0
|
||||
OUT_ESCAPED=
|
||||
if [ "$EXPECT_SPEC_SET" -eq 1 ]; then
|
||||
case $EXPECT_SPEC in
|
||||
status=*)
|
||||
REST=${EXPECT_SPEC#status=}
|
||||
case $REST in
|
||||
*';stdout='*)
|
||||
STATUS_EXPECT=${REST%%;stdout=*}
|
||||
OUT_ESCAPED=${REST#*;stdout=}
|
||||
;;
|
||||
*)
|
||||
STATUS_EXPECT=$REST
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
fail "bad expected result '$EXPECT_SPEC' (want status=N[;stdout=TEXT])"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
[ -z "$EXPECT_STATUS" ] || STATUS_EXPECT=$EXPECT_STATUS
|
||||
case $STATUS_EXPECT in
|
||||
''|*[!0-9]*) fail "expected status is not decimal: '$STATUS_EXPECT'" ;;
|
||||
esac
|
||||
EXPECT_STATUS_HEX=$(printf '%08X' "$STATUS_EXPECT")
|
||||
|
||||
if [ -n "$EXPECT_OUTPUT_FILE" ]; then
|
||||
[ -f "$EXPECT_OUTPUT_FILE" ] \
|
||||
|| fail "missing expected output file: $EXPECT_OUTPUT_FILE"
|
||||
EXPECT_HEX=$(od -An -v -tx1 "$EXPECT_OUTPUT_FILE" | tr -d ' \n')
|
||||
EXPECT_SOURCE=$EXPECT_OUTPUT_FILE
|
||||
else
|
||||
EXPECT_HEX=$(printf '%b' "$OUT_ESCAPED" | od -An -v -tx1 | tr -d ' \n')
|
||||
EXPECT_SOURCE="status=$STATUS_EXPECT;stdout=$OUT_ESCAPED"
|
||||
fi
|
||||
EXPECT_HEX=$(printf '%s' "$EXPECT_HEX" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$MAME" ] || fail "missing MAME: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK" "$WORK/run/nvram" "$WORK/run/cfg" "$WORK/evidence"
|
||||
rm -f "$WORK/result.txt"
|
||||
|
||||
# GSPA/GSPLNK 2.00 use 8.3 object names, and GSPLNK misparses an object name
|
||||
# that starts with a digit (the c-testsuite files are 00001.c, ...). Compile a
|
||||
# short local copy so the native object path works for every test name; keep
|
||||
# the original directory on the include path for quoted headers.
|
||||
SRC_DIR=$(cd "$(dirname "$SRC")" && pwd)
|
||||
COMPILE_SRC=$WORK/test.c
|
||||
cp "$SRC" "$COMPILE_SRC"
|
||||
|
||||
link_once() {
|
||||
native=$1
|
||||
log=$2
|
||||
M4_SOURCES="$COMPILE_SRC $HERE/shim.c" \
|
||||
M4_ENTRY="$HERE/entry.asm" \
|
||||
M4_CLANG_OPT="$CLANG_OPT" \
|
||||
M4_LLC_OPT="$LLC_OPT" \
|
||||
M4_EXTRA_INCLUDES="-I $HERE/include -I $SRC_DIR" \
|
||||
M4_WORK="$WORK/m4" \
|
||||
M4_COFF="$WORK/m4/m4.coff" \
|
||||
M4_SDK="$M4_SDK" \
|
||||
M4_NATIVE_PROG_LEN=58000h \
|
||||
M4_NATIVE_RAM_LEN=80000h \
|
||||
M4_LINK_CMD="$HERE/link.cmd" \
|
||||
M4_EXTRA_ASM="$HERE/data-pad.asm" \
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_NATIVE="$native" \
|
||||
"$ROOT/scripts/m4/run.sh" > "$log" 2>&1
|
||||
}
|
||||
|
||||
check_map() {
|
||||
map=$WORK/m4/m4.map
|
||||
[ -f "$map" ] || fail "linker produced no map: $map"
|
||||
for sec in .text .data .bss; do
|
||||
origin=$(awk -v s="$sec" '$1 == s { print $3; exit }' "$map")
|
||||
length=$(awk -v s="$sec" '$1 == s { print $4; exit }' "$map")
|
||||
[ -n "$origin" ] || fail "linker map has no $sec section"
|
||||
[ -n "$length" ] || fail "linker map has no $sec length"
|
||||
case $origin$length in
|
||||
*[!0-9A-Fa-f]*) fail "linker map has a non-hex $sec origin/length" ;;
|
||||
esac
|
||||
case $sec in
|
||||
.bss)
|
||||
low=$RAM_ORIGIN
|
||||
limit=$RAM_END
|
||||
;;
|
||||
*)
|
||||
low=$PROG_ORIGIN
|
||||
limit=$PROG_END
|
||||
;;
|
||||
esac
|
||||
start=$((0x$origin))
|
||||
end=$((start + 0x$length))
|
||||
[ "$start" -ge "$low" ] \
|
||||
|| fail "$sec starts at $(printf '%08X' "$start"), below $(printf '%08X' "$low")"
|
||||
[ "$end" -le "$limit" ] \
|
||||
|| fail "$sec ends at $(printf '%08X' "$end"), beyond $(printf '%08X' "$limit")"
|
||||
done
|
||||
[ "$RAM_END" -lt "$RESULT_BASE" ] \
|
||||
|| fail "result block at $(printf '%08X' "$RESULT_BASE") overlaps linker RAM"
|
||||
}
|
||||
|
||||
check_link() {
|
||||
case $LINK_MODE in
|
||||
asm|asm-fallback) LINK_LOG=$WORK/link-asm.log ;;
|
||||
*) LINK_LOG=$WORK/link-native.log ;;
|
||||
esac
|
||||
grep -q '^M4 LINK: PASS' "$LINK_LOG" \
|
||||
|| fail "linked image has no M4 LINK: PASS"
|
||||
COFF=$WORK/m4/m4.coff
|
||||
[ -f "$COFF" ] || fail "linker produced no COFF: $COFF"
|
||||
check_map
|
||||
echo " linked $COFF ($LINK_MODE)"
|
||||
}
|
||||
|
||||
run_mame() {
|
||||
echo "== run the COFF in MAME ($LINK_MODE)"
|
||||
rm -f "$WORK/result.txt"
|
||||
set +e
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$COFF" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
CONF_RESULT="$WORK/result.txt" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$HERE/conformance-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1
|
||||
MAME_RC=$?
|
||||
set -e
|
||||
if [ "$MAME_RC" -ne 0 ]; then
|
||||
tail -40 "$WORK/mame.log" >&2 || true
|
||||
fail "MAME exited $MAME_RC"
|
||||
fi
|
||||
grep -q 'LOADER: COFF poked .* readback 0 bad' "$WORK/mame.log" \
|
||||
|| { tail -40 "$WORK/mame.log" >&2; \
|
||||
fail "loader did not verify the COFF buffer"; }
|
||||
grep -q 'CONF: .* status=' "$WORK/mame.log" \
|
||||
|| { tail -40 "$WORK/mame.log" >&2; fail "MAME produced no CONF result"; }
|
||||
|
||||
RESULT=$WORK/result.txt
|
||||
[ -f "$RESULT" ] || fail "MAME wrote no result file: $RESULT"
|
||||
STATUS_HEX=$(sed -n 's/^status=//p' "$RESULT" | tr -d '\r')
|
||||
LEN=$(sed -n 's/^len=//p' "$RESULT" | tr -d '\r')
|
||||
MAGIC_HEX=$(sed -n 's/^magic=//p' "$RESULT" | tr -d '\r')
|
||||
LOADER_HEX=$(sed -n 's/^loader=//p' "$RESULT" | tr -d '\r')
|
||||
ACTUAL_HEX=$(sed -n 's/^out=//p' "$RESULT" | tr -d '\r')
|
||||
[ -n "$STATUS_HEX" ] || fail "result file has no status"
|
||||
[ -n "$MAGIC_HEX" ] || fail "result file has no magic"
|
||||
[ -n "$LOADER_HEX" ] || fail "result file has no loader status"
|
||||
ACTUAL_HEX=$(printf '%s' "$ACTUAL_HEX" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
if [ "$LOADER_HEX" != "00000000" ]; then
|
||||
return 2
|
||||
fi
|
||||
|
||||
[ -n "$LEN" ] || fail "result file has no output length"
|
||||
case $LEN in
|
||||
*[!0-9]*) fail "result output length is not decimal: '$LEN'" ;;
|
||||
esac
|
||||
if [ "$LEN" -ge "$OUT_CAP" ]; then
|
||||
fail "output truncated: length $LEN reached the $OUT_CAP-byte shim cap"
|
||||
fi
|
||||
|
||||
if [ "$MAGIC_HEX" != "434F4E46" ]; then
|
||||
tail -40 "$WORK/mame.log" >&2 || true
|
||||
fail "no completion magic (got $MAGIC_HEX): test did not finish"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
echo "== compile and link ($ID, $CLANG_OPT, mode=$MODE)"
|
||||
case $MODE in
|
||||
asm)
|
||||
link_once "" "$WORK/link-asm.log" \
|
||||
|| { tail -40 "$WORK/link-asm.log" >&2; fail "asm compile/link failed"; }
|
||||
LINK_MODE=asm
|
||||
;;
|
||||
native)
|
||||
link_once 1 "$WORK/link-native.log" \
|
||||
|| { tail -40 "$WORK/link-native.log" >&2; fail "native compile/link failed"; }
|
||||
LINK_MODE=native
|
||||
;;
|
||||
auto)
|
||||
if link_once 1 "$WORK/link-native.log"; then
|
||||
LINK_MODE=native
|
||||
elif link_once "" "$WORK/link-asm.log"; then
|
||||
echo " native link failed; using the asm/GSPA fallback"
|
||||
LINK_MODE=asm-fallback
|
||||
else
|
||||
echo "== native link log" >&2
|
||||
tail -30 "$WORK/link-native.log" >&2 || true
|
||||
echo "== asm link log" >&2
|
||||
tail -30 "$WORK/link-asm.log" >&2 || true
|
||||
fail "compile/link failed in both native and asm paths"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
check_link
|
||||
|
||||
set +e
|
||||
run_mame
|
||||
MAME_RESULT=$?
|
||||
set -e
|
||||
if [ "$MAME_RESULT" -eq 2 ]; then
|
||||
tail -20 "$WORK/mame.log" >&2 || true
|
||||
if [ "$MODE" = auto ] && [ "$LINK_MODE" = native ]; then
|
||||
cp "$WORK/mame.log" "$WORK/mame-native.log" 2>/dev/null || true
|
||||
cp "$COFF" "$WORK/native.coff" 2>/dev/null || true
|
||||
echo " native COFF was loader-rejected (status $LOADER_HEX); retrying with asm/GSPA"
|
||||
link_once "" "$WORK/link-asm.log" \
|
||||
|| { tail -40 "$WORK/link-asm.log" >&2; fail "asm retry compile/link failed"; }
|
||||
LINK_MODE=asm-fallback
|
||||
check_link
|
||||
set +e
|
||||
run_mame
|
||||
MAME_RESULT=$?
|
||||
set -e
|
||||
[ "$MAME_RESULT" -eq 0 ] \
|
||||
|| fail "COFF loader rejected the asm fallback (status $LOADER_HEX)"
|
||||
else
|
||||
fail "COFF loader rejected the $LINK_MODE image (status $LOADER_HEX)"
|
||||
fi
|
||||
fi
|
||||
|
||||
OUTPUT_MISMATCH=0
|
||||
if [ "$IGNORE_OUTPUT" -eq 0 ] && [ "$ACTUAL_HEX" != "$EXPECT_HEX" ]; then
|
||||
OUTPUT_MISMATCH=1
|
||||
fi
|
||||
|
||||
if [ "$STATUS_HEX" != "$EXPECT_STATUS_HEX" ] || [ "$OUTPUT_MISMATCH" -eq 1 ]; then
|
||||
echo "CONFORMANCE: FAIL id=$ID status=$STATUS_HEX expected_status=$EXPECT_STATUS_HEX stdout_len=$LEN"
|
||||
if [ "$STATUS_HEX" != "$EXPECT_STATUS_HEX" ]; then
|
||||
echo " status mismatch: expected $EXPECT_STATUS_HEX, got $STATUS_HEX"
|
||||
fi
|
||||
if [ "$OUTPUT_MISMATCH" -eq 1 ]; then
|
||||
echo " output mismatch: expected '$EXPECT_HEX', got '$ACTUAL_HEX'"
|
||||
printf ' expected source: %s\n' "$EXPECT_SOURCE"
|
||||
fi
|
||||
echo " work dir: $WORK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "CONFORMANCE: PASS id=$ID status=$STATUS_HEX stdout_len=$LEN link=$LINK_MODE"
|
||||
Executable
+287
@@ -0,0 +1,287 @@
|
||||
#!/bin/sh
|
||||
# M5 conformance harness selftest.
|
||||
#
|
||||
# Three tiny C cases exercise the whole path:
|
||||
# pass int main(void) { return 0; }
|
||||
# fail int main(void) { return 7; }
|
||||
# print int main(void) { printf("ok\n"); return 0; }
|
||||
#
|
||||
# The pass and print cases must pass; the fail case must fail against the
|
||||
# default status 0 and then pass when status 7 is expected (proving the status
|
||||
# is captured, not guessed). A fourth run expects the wrong output and must
|
||||
# fail with an output-mismatch diagnostic, proving the compare is real.
|
||||
# Additional cases prove the contiguous varargs walk (format), entry's
|
||||
# main(1, argv) contract (argv), and that a large .bss cannot overwrite the
|
||||
# result block (bigbss). Classifier checks prove an unsupported source is a
|
||||
# skip (not a pass), an all-skip suite is a failure, a classifier error is a
|
||||
# failure, and an unsafe id is rejected before any rm -rf.
|
||||
#
|
||||
# scripts/tests/m5/conformance/selftest.sh
|
||||
#
|
||||
# Overridable: M5_CONFORMANCE_SELFTEST_WORK M5_CONFORMANCE_WORK
|
||||
# LOADER_AT LOADER_END M5_CONFORMANCE_MODE (auto|native|asm)
|
||||
# M5_CONFORMANCE_CLASSIFY
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
WORK=${M5_CONFORMANCE_SELFTEST_WORK:-$ROOT/build/m5-conformance-selftest}
|
||||
MODE=${M5_CONFORMANCE_MODE:-auto}
|
||||
|
||||
RUN=$HERE/run.sh
|
||||
CLASSIFY=$HERE/classify.sh
|
||||
|
||||
fail() {
|
||||
echo "conformance selftest: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -x "$RUN" ] || fail "runner is not executable: $RUN"
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
cat > "$WORK/pass.c" <<'EOF'
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
|
||||
cat > "$WORK/fail.c" <<'EOF'
|
||||
int main(void) { return 7; }
|
||||
EOF
|
||||
|
||||
cat > "$WORK/print.c" <<'EOF'
|
||||
int printf(const char *fmt, ...);
|
||||
int main(void) { printf("ok\n"); return 0; }
|
||||
EOF
|
||||
|
||||
cat > "$WORK/format.c" <<'EOF'
|
||||
int printf(const char *fmt, ...);
|
||||
int main(void)
|
||||
{
|
||||
printf("a=%d b=%s c=%c %% x=%x\n", 42, "hi", 'Z', 255);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/argv.c" <<'EOF'
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 1)
|
||||
return 1;
|
||||
if (argv == 0 || argv[0] == 0 || argv[0][0] != 'c')
|
||||
return 2;
|
||||
if (argv[1] != 0)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/bigbss.c" <<'EOF'
|
||||
char big[50000];
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 50000; i++)
|
||||
big[i] = (char)(i * 7);
|
||||
for (i = 0; i < 50000; i++)
|
||||
if (big[i] != (char)(i * 7))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/truncate.c" <<'EOF'
|
||||
int putchar(int c);
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 16384; i++)
|
||||
putchar('x');
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/skip.c" <<'EOF'
|
||||
double deferred_feature;
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
|
||||
run_case() {
|
||||
id=$1
|
||||
expect=$2
|
||||
src=$3
|
||||
log=$4
|
||||
if ! "$RUN" --id "$id" --mode "$MODE" --expect "$expect" "$src" \
|
||||
> "$log" 2>&1; then
|
||||
cat "$log" >&2
|
||||
fail "$id did not pass"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "== pass: main returns 0"
|
||||
run_case selftest-pass 'status=0;stdout=' "$WORK/pass.c" "$WORK/pass.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-pass' "$WORK/pass.log" \
|
||||
|| { cat "$WORK/pass.log" >&2; fail "pass case has no PASS line"; }
|
||||
|
||||
echo "== fail: main returns 7 must fail expected status 0"
|
||||
if "$RUN" --id selftest-fail --mode "$MODE" \
|
||||
--expect 'status=0;stdout=' "$WORK/fail.c" > "$WORK/fail.log" 2>&1; then
|
||||
cat "$WORK/fail.log" >&2
|
||||
fail "fail case (return 7) unexpectedly passed"
|
||||
fi
|
||||
grep -q '^CONFORMANCE: FAIL id=selftest-fail' "$WORK/fail.log" \
|
||||
|| { cat "$WORK/fail.log" >&2; fail "fail case has no FAIL line"; }
|
||||
grep -q 'status=00000007' "$WORK/fail.log" \
|
||||
|| { cat "$WORK/fail.log" >&2; fail "fail case did not capture status 7"; }
|
||||
|
||||
echo "== fail: the same source passes when status 7 is expected"
|
||||
run_case selftest-fail-expected 'status=7;stdout=' \
|
||||
"$WORK/fail.c" "$WORK/fail-expected.log"
|
||||
|
||||
echo "== print: writes ok and returns 0"
|
||||
run_case selftest-print 'status=0;stdout=ok\n' \
|
||||
"$WORK/print.c" "$WORK/print.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-print' "$WORK/print.log" \
|
||||
|| { cat "$WORK/print.log" >&2; fail "print case has no PASS line"; }
|
||||
|
||||
echo "== format: contiguous varargs and formatting"
|
||||
run_case selftest-format 'status=0;stdout=a=42 b=hi c=Z % x=ff\n' \
|
||||
"$WORK/format.c" "$WORK/format.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-format' "$WORK/format.log" \
|
||||
|| { cat "$WORK/format.log" >&2; fail "format case has no PASS line"; }
|
||||
|
||||
echo "== argv: entry passes main(1, argv)"
|
||||
run_case selftest-argv 'status=0;stdout=' \
|
||||
"$WORK/argv.c" "$WORK/argv.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-argv' "$WORK/argv.log" \
|
||||
|| { cat "$WORK/argv.log" >&2; fail "argv case has no PASS line"; }
|
||||
|
||||
echo "== bigbss: globals cannot overwrite the result block"
|
||||
run_case selftest-bigbss 'status=0;stdout=' \
|
||||
"$WORK/bigbss.c" "$WORK/bigbss.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-bigbss' "$WORK/bigbss.log" \
|
||||
|| { cat "$WORK/bigbss.log" >&2; fail "bigbss case has no PASS line"; }
|
||||
|
||||
echo "== truncation: output at the 16 KiB cap must fail"
|
||||
set +e
|
||||
"$RUN" --id selftest-truncate --mode "$MODE" --expect-status 0 \
|
||||
--ignore-output "$WORK/truncate.c" > "$WORK/truncate.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/truncate.log" >&2; \
|
||||
fail "truncation case exited $RC, want 1"; }
|
||||
grep -q 'output truncated' "$WORK/truncate.log" \
|
||||
|| { cat "$WORK/truncate.log" >&2; \
|
||||
fail "truncation was not diagnosed"; }
|
||||
|
||||
echo "== print: a wrong expected output must fail"
|
||||
if "$RUN" --id selftest-mismatch --mode "$MODE" \
|
||||
--expect 'status=0;stdout=no\n' "$WORK/print.c" \
|
||||
> "$WORK/mismatch.log" 2>&1; then
|
||||
cat "$WORK/mismatch.log" >&2
|
||||
fail "wrong expected output unexpectedly passed"
|
||||
fi
|
||||
grep -q '^CONFORMANCE: FAIL id=selftest-mismatch' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch has no FAIL line"; }
|
||||
grep -q 'output mismatch' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch was not diagnosed as output"; }
|
||||
grep -q '6F6B0A' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch did not report actual 'ok\\n'"; }
|
||||
grep -q '6E6F0A' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch did not report expected 'no\\n'"; }
|
||||
|
||||
echo "== classifier: double is skipped, not passed"
|
||||
if "$CLASSIFY" "$WORK/skip.c" > "$WORK/classify.log" 2>&1; then
|
||||
cat "$WORK/classify.log" >&2
|
||||
fail "classifier accepted a double source"
|
||||
fi
|
||||
grep -q 'float' "$WORK/classify.log" \
|
||||
|| { cat "$WORK/classify.log" >&2; fail "classifier did not name the float feature"; }
|
||||
|
||||
set +e
|
||||
"$RUN" --id selftest-skip --mode "$MODE" --classify "$WORK/skip.c" \
|
||||
> "$WORK/skip.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 2 ] || { cat "$WORK/skip.log" >&2; \
|
||||
fail "classified source exited $RC, want 2 (skip)"; }
|
||||
grep -q '^CONFORMANCE: SKIP id=selftest-skip' "$WORK/skip.log" \
|
||||
|| { cat "$WORK/skip.log" >&2; fail "classified source has no SKIP line"; }
|
||||
|
||||
echo "== classifier: an I/O/usage error is a failure, not a skip"
|
||||
cat > "$WORK/bad-classifier.sh" <<'EOF'
|
||||
#!/bin/sh
|
||||
echo "fake classifier I/O error" >&2
|
||||
exit 2
|
||||
EOF
|
||||
chmod +x "$WORK/bad-classifier.sh"
|
||||
set +e
|
||||
M5_CONFORMANCE_CLASSIFY="$WORK/bad-classifier.sh" "$RUN" \
|
||||
--id selftest-classifier-error --mode "$MODE" --classify \
|
||||
--expect 'status=0;stdout=' "$WORK/pass.c" \
|
||||
> "$WORK/classifier-error.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/classifier-error.log" >&2; \
|
||||
fail "classifier error exited $RC, want 1 (failure)"; }
|
||||
grep -q 'classifier error' "$WORK/classifier-error.log" \
|
||||
|| { cat "$WORK/classifier-error.log" >&2; \
|
||||
fail "classifier error was not diagnosed"; }
|
||||
if grep -q '^CONFORMANCE: SKIP' "$WORK/classifier-error.log"; then
|
||||
cat "$WORK/classifier-error.log" >&2
|
||||
fail "classifier error was reported as a skip"
|
||||
fi
|
||||
|
||||
echo "== all-skip: a suite with no passing test must fail"
|
||||
mkdir -p "$WORK/skip-suite"
|
||||
cat > "$WORK/skip-suite/onlyskip.c" <<'EOF'
|
||||
double deferred_feature;
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
: > "$WORK/skip-suite/onlyskip.c.expected"
|
||||
printf 'onlyskip\n' > "$WORK/allskip-torture.list"
|
||||
printf 'onlyskip\n' > "$WORK/allskip-testsuite.list"
|
||||
|
||||
set +e
|
||||
C_TORTURE_DIR="$WORK/skip-suite" "$HERE/c-torture.sh" \
|
||||
"$WORK/allskip-torture.list" > "$WORK/allskip-torture.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/allskip-torture.log" >&2; \
|
||||
fail "all-skip c-torture exited $RC, want 1"; }
|
||||
grep -q 'no tests passed' "$WORK/allskip-torture.log" \
|
||||
|| { cat "$WORK/allskip-torture.log" >&2; \
|
||||
fail "all-skip c-torture did not fail with 'no tests passed'"; }
|
||||
grep -q '^CONFORMANCE: SKIP' "$WORK/allskip-torture.log" \
|
||||
|| { cat "$WORK/allskip-torture.log" >&2; \
|
||||
fail "all-skip c-torture did not exercise a classifier skip"; }
|
||||
|
||||
set +e
|
||||
C_TESTSUITE_DIR="$WORK/skip-suite" "$HERE/c-testsuite.sh" \
|
||||
"$WORK/allskip-testsuite.list" > "$WORK/allskip-testsuite.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/allskip-testsuite.log" >&2; \
|
||||
fail "all-skip c-testsuite exited $RC, want 1"; }
|
||||
grep -q 'no tests passed' "$WORK/allskip-testsuite.log" \
|
||||
|| { cat "$WORK/allskip-testsuite.log" >&2; \
|
||||
fail "all-skip c-testsuite did not fail with 'no tests passed'"; }
|
||||
|
||||
echo "== id: '.' and '..' must not construct a deletable work path"
|
||||
set +e
|
||||
"$RUN" --id .. --mode "$MODE" --expect 'status=0;stdout=' \
|
||||
"$WORK/pass.c" > "$WORK/unsafe-id.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/unsafe-id.log" >&2; \
|
||||
fail "unsafe id exited $RC, want 1"; }
|
||||
grep -q 'unsafe id' "$WORK/unsafe-id.log" \
|
||||
|| { cat "$WORK/unsafe-id.log" >&2; fail "unsafe id was not rejected"; }
|
||||
|
||||
echo "conformance selftest: PASS"
|
||||
echo " pass, expected-fail status 7, print, format, argv, bigbss, truncation"
|
||||
echo " output mismatch, classifier skip, classifier error, all-skip suite, unsafe id"
|
||||
@@ -0,0 +1,451 @@
|
||||
/*
|
||||
* shim.c -- freestanding conformance runtime for the M5 harness.
|
||||
*
|
||||
* The harness links one conformance test, this shim, and entry.asm into a
|
||||
* TMS34010 COFF image. The shim provides the small libc surface the integer
|
||||
* conformance tests use: printf/putchar/puts write to a fixed output buffer,
|
||||
* and exit/abort publish a terminal status. There is no libc and no
|
||||
* va_list: printf walks the M4 contiguous program-stack arguments from the
|
||||
* address of its last fixed parameter (&fmt), exactly like scripts/m4/varargs.c.
|
||||
*
|
||||
* Marker layout (32-bit cells at bit addresses):
|
||||
* 01B00000 status 0 = success, otherwise the main/exit/abort status
|
||||
* 01B00020 out_len number of bytes written to the output buffer
|
||||
* 01B00040 magic 0x434F4E46 once the result is complete ("CONF")
|
||||
* 01B10000 output text written by printf/putchar/puts (16 KiB)
|
||||
*
|
||||
* The result block is above the linker-managed RAM region
|
||||
* (01A00000..01A80000, 64 KiB of .bss including the 4 KiB _cstack), so a
|
||||
* test's globals cannot overwrite the status/output. entry.asm writes
|
||||
* status/magic when main returns. exit/abort write them directly and then
|
||||
* spin, so the result is observable even if the test does not return normally.
|
||||
* out_char() stops at CONF_CAP; the runner rejects out_len == CONF_CAP as a
|
||||
* truncation rather than accepting a partial output.
|
||||
*/
|
||||
|
||||
#define CONF_STATUS ((volatile int *)0x01B00000UL)
|
||||
#define CONF_LEN ((volatile int *)0x01B00020UL)
|
||||
#define CONF_MAGIC ((volatile int *)0x01B00040UL)
|
||||
#define CONF_OUT ((char *)0x01B10000UL)
|
||||
#define CONF_CAP 16384
|
||||
#define CONF_MAGIC_VAL 0x434F4E46
|
||||
|
||||
static int out_len;
|
||||
|
||||
static int out_char(int c)
|
||||
{
|
||||
if (out_len < CONF_CAP) {
|
||||
CONF_OUT[out_len] = (char)c;
|
||||
out_len++;
|
||||
*CONF_LEN = out_len;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int out_str(const char *s)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
while (*s) {
|
||||
out_char(*s++);
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static int emit_pad(int c, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
out_char(c);
|
||||
return n;
|
||||
}
|
||||
|
||||
static int emit_uint(unsigned int v, int neg, int base, int upper,
|
||||
int width, int zero, int left, int plus, int space,
|
||||
int alt)
|
||||
{
|
||||
static const char lower[] = "0123456789abcdef";
|
||||
static const char upper_digits[] = "0123456789ABCDEF";
|
||||
const char *digits = upper ? upper_digits : lower;
|
||||
char tmp[32];
|
||||
int n = 0, total = 0, pad, prefix_len = 0;
|
||||
int sign = 0;
|
||||
char prefix[3];
|
||||
|
||||
if (v == 0) {
|
||||
tmp[n++] = '0';
|
||||
} else {
|
||||
while (v) {
|
||||
tmp[n++] = digits[v % (unsigned int)base];
|
||||
v /= (unsigned int)base;
|
||||
}
|
||||
}
|
||||
|
||||
if (neg)
|
||||
sign = '-';
|
||||
else if (plus)
|
||||
sign = '+';
|
||||
else if (space)
|
||||
sign = ' ';
|
||||
|
||||
if (alt) {
|
||||
if (base == 16) {
|
||||
prefix[0] = '0';
|
||||
prefix[1] = upper ? 'X' : 'x';
|
||||
prefix_len = 2;
|
||||
} else if (base == 8 && tmp[n - 1] != '0') {
|
||||
prefix[0] = '0';
|
||||
prefix_len = 1;
|
||||
}
|
||||
}
|
||||
if (prefix_len)
|
||||
prefix[prefix_len] = 0;
|
||||
|
||||
pad = width - n - prefix_len - (sign ? 1 : 0);
|
||||
if (pad < 0)
|
||||
pad = 0;
|
||||
|
||||
if (!left && !zero)
|
||||
total += emit_pad(' ', pad);
|
||||
if (sign)
|
||||
total += out_char(sign);
|
||||
if (prefix_len)
|
||||
total += out_str(prefix);
|
||||
if (!left && zero)
|
||||
total += emit_pad('0', pad);
|
||||
while (n--)
|
||||
total += out_char(tmp[n]);
|
||||
if (left)
|
||||
total += emit_pad(' ', pad);
|
||||
return total;
|
||||
}
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
out_char(c);
|
||||
*CONF_LEN = out_len;
|
||||
return c;
|
||||
}
|
||||
|
||||
int puts(const char *s)
|
||||
{
|
||||
int n = out_str(s);
|
||||
|
||||
out_char('\n');
|
||||
*CONF_LEN = out_len;
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
unsigned int strlen(const char *s)
|
||||
{
|
||||
const char *p = s;
|
||||
|
||||
while (*p)
|
||||
p++;
|
||||
return (unsigned int)(p - s);
|
||||
}
|
||||
|
||||
int strcmp(const char *a, const char *b)
|
||||
{
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return (int)(unsigned char)*a - (int)(unsigned char)*b;
|
||||
}
|
||||
|
||||
int strncmp(const char *a, const char *b, unsigned int n)
|
||||
{
|
||||
while (n && *a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
n--;
|
||||
}
|
||||
if (n == 0)
|
||||
return 0;
|
||||
return (int)(unsigned char)*a - (int)(unsigned char)*b;
|
||||
}
|
||||
|
||||
char *strcpy(char *d, const char *s)
|
||||
{
|
||||
char *r = d;
|
||||
|
||||
while ((*d++ = *s++) != 0)
|
||||
;
|
||||
return r;
|
||||
}
|
||||
|
||||
char *strncpy(char *d, const char *s, unsigned int n)
|
||||
{
|
||||
char *r = d;
|
||||
|
||||
while (n && *s) {
|
||||
*d++ = *s++;
|
||||
n--;
|
||||
}
|
||||
while (n) {
|
||||
*d++ = 0;
|
||||
n--;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
char *strchr(const char *s, int c)
|
||||
{
|
||||
for (;; s++) {
|
||||
if (*s == (char)c)
|
||||
return (char *)s;
|
||||
if (!*s)
|
||||
return (char *)0;
|
||||
}
|
||||
}
|
||||
|
||||
char *strrchr(const char *s, int c)
|
||||
{
|
||||
const char *r = (const char *)0;
|
||||
|
||||
for (;; s++) {
|
||||
if (*s == (char)c)
|
||||
r = s;
|
||||
if (!*s)
|
||||
return (char *)r;
|
||||
}
|
||||
}
|
||||
|
||||
void *memcpy(void *dst, const void *src, unsigned int n)
|
||||
{
|
||||
char *d = (char *)dst;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memmove(void *dst, const void *src, unsigned int n)
|
||||
{
|
||||
char *d = (char *)dst;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if (d < s) {
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
} else if (d > s) {
|
||||
d += n;
|
||||
s += n;
|
||||
while (n--)
|
||||
*--d = *--s;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memset(void *dst, int c, unsigned int n)
|
||||
{
|
||||
char *d = (char *)dst;
|
||||
|
||||
while (n--)
|
||||
*d++ = (char)c;
|
||||
return dst;
|
||||
}
|
||||
|
||||
int memcmp(const void *a, const void *b, unsigned int n)
|
||||
{
|
||||
const unsigned char *x = (const unsigned char *)a;
|
||||
const unsigned char *y = (const unsigned char *)b;
|
||||
|
||||
while (n--) {
|
||||
if (*x != *y)
|
||||
return (int)*x - (int)*y;
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int atoi(const char *s)
|
||||
{
|
||||
int sign = 1, v = 0;
|
||||
|
||||
while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r')
|
||||
s++;
|
||||
if (*s == '-') {
|
||||
sign = -1;
|
||||
s++;
|
||||
} else if (*s == '+') {
|
||||
s++;
|
||||
}
|
||||
while (*s >= '0' && *s <= '9') {
|
||||
v = v * 10 + (*s - '0');
|
||||
s++;
|
||||
}
|
||||
return sign * v;
|
||||
}
|
||||
|
||||
int abs(int v)
|
||||
{
|
||||
return v < 0 ? -v : v;
|
||||
}
|
||||
|
||||
int printf(const char *fmt, ...)
|
||||
{
|
||||
const char *p = fmt;
|
||||
int **ap = (int **)&fmt;
|
||||
int total = 0;
|
||||
|
||||
while (*p) {
|
||||
int left = 0, zero = 0, plus = 0, space = 0, alt = 0;
|
||||
int width = 0, is_short = 0, is_char = 0;
|
||||
int conv;
|
||||
|
||||
if (*p != '%') {
|
||||
total += out_char(*p++);
|
||||
continue;
|
||||
}
|
||||
p++;
|
||||
if (*p == '%') {
|
||||
total += out_char(*p++);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (*p == '-') {
|
||||
left = 1;
|
||||
p++;
|
||||
} else if (*p == '0') {
|
||||
zero = 1;
|
||||
p++;
|
||||
} else if (*p == '+') {
|
||||
plus = 1;
|
||||
p++;
|
||||
} else if (*p == ' ') {
|
||||
space = 1;
|
||||
p++;
|
||||
} else if (*p == '#') {
|
||||
alt = 1;
|
||||
p++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (*p >= '0' && *p <= '9') {
|
||||
width = width * 10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
if (*p == 'l') {
|
||||
p++;
|
||||
if (*p == 'l')
|
||||
p++;
|
||||
} else if (*p == 'h') {
|
||||
p++;
|
||||
is_short = 1;
|
||||
if (*p == 'h') {
|
||||
p++;
|
||||
is_char = 1;
|
||||
}
|
||||
} else if (*p == 'z' || *p == 't' || *p == 'j') {
|
||||
p++;
|
||||
} else if (*p == 'L') {
|
||||
p++;
|
||||
}
|
||||
|
||||
conv = *p;
|
||||
if (!conv)
|
||||
break;
|
||||
p++;
|
||||
|
||||
switch (conv) {
|
||||
case 'd':
|
||||
case 'i': {
|
||||
int sv;
|
||||
unsigned int uv;
|
||||
|
||||
ap--;
|
||||
sv = (int)*ap;
|
||||
if (is_char)
|
||||
sv = (signed char)sv;
|
||||
else if (is_short)
|
||||
sv = (short)sv;
|
||||
if (sv < 0)
|
||||
uv = ~(unsigned int)sv + 1U;
|
||||
else
|
||||
uv = (unsigned int)sv;
|
||||
total += emit_uint(uv, sv < 0, 10, 0, width, zero,
|
||||
left, plus, space, alt);
|
||||
break;
|
||||
}
|
||||
case 'u':
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'X': {
|
||||
unsigned int uv;
|
||||
|
||||
ap--;
|
||||
uv = (unsigned int)*ap;
|
||||
if (is_char)
|
||||
uv = (unsigned char)uv;
|
||||
else if (is_short)
|
||||
uv = (unsigned short)uv;
|
||||
total += emit_uint(uv, 0,
|
||||
conv == 'o' ? 8 : (conv == 'u' ? 10 : 16),
|
||||
conv == 'X', width, zero, left,
|
||||
plus, space, alt);
|
||||
break;
|
||||
}
|
||||
case 'p': {
|
||||
unsigned int uv;
|
||||
|
||||
ap--;
|
||||
uv = (unsigned int)*ap;
|
||||
if (width == 0)
|
||||
width = 8;
|
||||
total += emit_uint(uv, 0, 16, 0, width, 1, left, 0, 0, 1);
|
||||
break;
|
||||
}
|
||||
case 'c': {
|
||||
int cv;
|
||||
|
||||
ap--;
|
||||
cv = (int)*ap;
|
||||
total += out_char((char)cv);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
const char *s;
|
||||
|
||||
ap--;
|
||||
s = (const char *)*ap;
|
||||
if (!s)
|
||||
s = "(null)";
|
||||
total += out_str(s);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
total += out_char('%');
|
||||
total += out_char(conv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*CONF_LEN = out_len;
|
||||
return total;
|
||||
}
|
||||
|
||||
void exit(int status)
|
||||
{
|
||||
*CONF_LEN = out_len;
|
||||
*CONF_STATUS = status;
|
||||
*CONF_MAGIC = CONF_MAGIC_VAL;
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
void _exit(int status)
|
||||
{
|
||||
exit(status);
|
||||
}
|
||||
|
||||
void abort(void)
|
||||
{
|
||||
exit(134); /* 128 + SIGABRT */
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# conformance feature skips
|
||||
#
|
||||
# feature<TAB>reason
|
||||
#
|
||||
# classify.sh reports the first matching feature. A skipped test is never
|
||||
# counted as a pass; the suite runners count it separately and print the
|
||||
# reason. Keep these reasons in sync with the M5 non-goals (M6 owns floats,
|
||||
# 64-bit integers, bitfields, general varargs, signals and wide characters).
|
||||
float floats and doubles are deferred to M6
|
||||
long-long 64-bit integers (long long/int64) are deferred to M6
|
||||
int128 128-bit integers are unsupported
|
||||
bitfield bitfields are deferred to M6
|
||||
varargs va_list/va_start/va_arg are deferred to M6 (only the contiguous &last_fixed walk is supported)
|
||||
setjmp setjmp/longjmp need non-local jumps, deferred to M6
|
||||
signal signals are unavailable under the bare loader
|
||||
wide-char wide characters are deferred to M6
|
||||
float-format %f/%e/%g/%a need floating-point formatting
|
||||
long-long-format %ll/%L need 64-bit formatting
|
||||
format-unsupported printf %n, * width/precision and explicit precision are not implemented by the shim
|
||||
file-io stdio/POSIX file I/O is unavailable under the bare loader
|
||||
|
@@ -0,0 +1,68 @@
|
||||
# M5 CodeGen/Generic allowlist.
|
||||
#
|
||||
# A small curated compile-only set, not the whole Generic corpus. Every entry
|
||||
# must compile with:
|
||||
# llc -march=tms34010 -filetype=asm -O0
|
||||
# to a non-empty .s. The set stays within the M5 subset: integer (<=32 bit),
|
||||
# pointer, control flow, load/store, calls and PHI. No floats, vectors,
|
||||
# atomics, 64-bit integer values, varargs, or aggregate values/arguments/
|
||||
# returns. The one aggregate-typed access is
|
||||
# 2006-06-13-ComputeMaskedBitsCrash.ll: it uses a struct-typed global and a
|
||||
# struct-field GEP for address computation but never loads, stores, passes or
|
||||
# returns an aggregate value.
|
||||
#
|
||||
# The broad sweep in generic.sh covers all Generic .ll files; this list is the
|
||||
# gate that must stay green for the supported feature shapes.
|
||||
|
||||
# Integer arithmetic and shifts (add/sub/mul/div/rem/and/or/xor/shl/lshr/ashr).
|
||||
BasicInstrs
|
||||
|
||||
# sdiv-by-constant (negative power of two).
|
||||
div-neg-power-2
|
||||
|
||||
# Return-only and global load/return.
|
||||
ret0
|
||||
ret42
|
||||
global-ret0
|
||||
|
||||
# Direct calls: one/two/void arguments, one/two-deep call chains.
|
||||
call-ret0
|
||||
call-ret42
|
||||
call-void
|
||||
call2-ret0
|
||||
fastcall
|
||||
|
||||
# Calls and PHI/control: a call argument defined by a later call, and a
|
||||
# pointer PHI feeding a call.
|
||||
badCallArgLRLLVM
|
||||
2003-05-30-BadPreselectPhi
|
||||
|
||||
# PHI carrying ptrtoint globals plus a call.
|
||||
2005-04-09-GlobalInPHI
|
||||
|
||||
# Load/select and load/store with narrow integer operations.
|
||||
2007-01-15-LoadSelectCycle
|
||||
2006-11-20-DAGCombineCrash
|
||||
fwdtwice
|
||||
|
||||
# i16 loads, icmp and a switch.
|
||||
2006-04-26-SetCCAnd
|
||||
|
||||
# GEP/load/store/shift/mask.
|
||||
2006-06-13-ComputeMaskedBitsCrash
|
||||
|
||||
# Branches and i1 boolean folding.
|
||||
2006-10-27-CondFolding
|
||||
2006-10-29-Crash
|
||||
|
||||
# PHI/icmp control flow.
|
||||
2006-01-12-BadSetCCFold
|
||||
|
||||
# Loop induction/PHI control flow.
|
||||
2007-04-17-lsr-crash
|
||||
|
||||
# Switch lowering with PHIs.
|
||||
2006-09-06-SwitchLowering
|
||||
|
||||
# A trivial intrinsic call.
|
||||
assume
|
||||
@@ -0,0 +1,102 @@
|
||||
# M5 CodeGen/Generic expected-fail manifest.
|
||||
#
|
||||
# Format: test<TAB>reason
|
||||
#
|
||||
# Every broad-sweep `unsupported` row is recorded here with the reason the
|
||||
# M5 target cannot compile it. generic.sh enforces both directions:
|
||||
# - each entry must be `unsupported`, not `pass` (stale) and never `crash`;
|
||||
# - every `unsupported` row in the sweep must have an entry here.
|
||||
#
|
||||
# A crash is a regression, never an expected failure. Reasons are the actual
|
||||
# diagnostic categories from the sweep; "M6" marks a feature deferred from
|
||||
# the M5 subset (floats, 64-bit integers, general varargs, aggregates, GC).
|
||||
2003-05-27-phifcmpd target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2003-05-27-useboolinotherbb target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2003-05-27-usefsubasbool target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2003-05-28-ManyArgs target rejection: TMS34010 supports only integer (<=32 bit) and pointer call arguments
|
||||
2003-07-07-BadLongConst target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2003-07-29-BadConstSbyte target rejection: TMS34010 supports only integer (<=32 bit) and pointer call arguments
|
||||
2004-05-09-LiveVarPartialRegister target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
2005-10-21-longlonggtu target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2005-12-01-Crash target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2005-12-12-ExpandSextInreg target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2006-02-12-InsertLibcall target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2006-04-28-Sign-extend-bool sign_extend_inreg on i1 is not selectable
|
||||
2006-06-12-LowerSwitchCrash target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2006-07-03-schedulers target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2006-09-02-LocalAllocCrash 64-bit shift (srl_parts) reached selection; i64 is deferred to M6
|
||||
2007-04-08-MultipleFrameIndices inline asm register constraint cannot be allocated
|
||||
2007-04-27-InlineAsm-X-Dest inline asm register constraint cannot be allocated
|
||||
2007-04-27-LargeMemObject inline asm memory constraint is not supported
|
||||
2007-05-15-InfiniteRecursion target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2007-12-17-InvokeAsm inline asm memory constraint is not supported
|
||||
2008-01-25-dag-combine-mul target rejection: TMS34010: 64-bit multiply reached code generation; the i64 path is reserved for M6. M5 supports 32-bit multiplication only.
|
||||
2008-01-30-LoadCrash target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2008-02-04-Ctlz target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2008-02-20-MatchingMem inline asm memory constraint is not supported
|
||||
2008-02-25-NegateZero target rejection: TMS34010 supports only integer (<=32 bit) and pointer call arguments
|
||||
2008-02-26-NegatableCrash target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2008-08-07-PtrToInt-SmallerInt target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
2009-03-17-LSR-APInt target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2009-03-29-SoftFloatVectorExtract target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2009-04-10-SinkCrash target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2010-07-27-DAGCombineCrash target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
2010-ZeroSizedArg target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
2013-03-20-APFloatCrash target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
APIntParam target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
APIntSextParam target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
APIntZextParam target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
ForceStackAlign target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
GlobalISel/irtranslator-byte-type target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
add-with-overflow-128 target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
addr-label blockaddress values are not supported
|
||||
annotate target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
badarg6 target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
bfloat target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
bfloat-op missing libcall lowering (floats/vectors are deferred to M6)
|
||||
bool-to-double target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
bswap target rejection: TMS34010 supports only integer (<=32 bit) and pointer call arguments
|
||||
cast-fp target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
constindices target rejection: TMS34010 supports only integer (<=32 bit) and pointer call arguments
|
||||
dag-combine-ossfuzz-crash target rejection: TMS34010: 64-bit multiply reached code generation; the i64 path is reserved for M6. M5 supports 32-bit multiplication only.
|
||||
denormal-fp-math-cl-opt target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
expand-experimental-reductions target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
extractelement-shuffle target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
fast-math-flags IR verifier rejects the input (fast-math flags on an integer call)
|
||||
fneg-fabs target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
fp-to-int-invalid missing libcall lowering (floats/vectors are deferred to M6)
|
||||
fp128-exp10-libcall target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
fp128-math-libcalls target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
fp_to_int target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
fpoperations target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
fpowi-promote target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
half target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
half-op missing libcall lowering (floats/vectors are deferred to M6)
|
||||
i128-addsub target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
i128-arith target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
icmp-illegal target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
inline-asm-mem-clobber inline asm register constraint cannot be allocated
|
||||
inline-asm-special-strings inline asm syntax is not supported by the TMS34010 parser
|
||||
intrinsics target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
isunord target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
llvm-ct-intrinsics target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
multiple-return-values-cross-block-with-invoke target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
nested-select target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
overloaded-intrinsic-name gc.statepoint calls are not supported
|
||||
pr12507 target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
pr24662 target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
pr33094 target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
pr49872 target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
print-arith-fp target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
ptr-annotate target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
replace-intrinsics-with-veclib target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
replace-intrinsics-with-veclib-darwin-libsystem-m target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
select target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
select-cc target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
shift-int64 target rejection: M2 supports only void/integer(<=32)/pointer returns
|
||||
storetrunc-fp target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
trap target rejection: M2 supports only direct calls to global functions and indirect calls through a function pointer
|
||||
v-split missing libcall lowering (floats/vectors are deferred to M6)
|
||||
vector missing libcall lowering (floats/vectors are deferred to M6)
|
||||
vector-casts missing libcall lowering (floats/vectors are deferred to M6)
|
||||
zero-sized-array target rejection: TMS34010 supports only integer (<=32 bit) and pointer arguments
|
||||
Executable
+283
@@ -0,0 +1,283 @@
|
||||
#!/bin/sh
|
||||
# M5 CodeGen/Generic compile-only no-crash sweep.
|
||||
#
|
||||
# scripts/tests/m5/generic.sh
|
||||
#
|
||||
# Phase 1 (allowlist gate): compile each file in generic-allowlist.txt with
|
||||
# llc -march=tms34010 -filetype=asm -O0
|
||||
# and require exit 0 and a non-empty asm file. The allowlist is a small,
|
||||
# curated integer/control/load-store/call/PHI set; it is not a claim that every
|
||||
# Generic test is runnable, only that these compile cleanly.
|
||||
#
|
||||
# Phase 2 (broad sweep): compile every .ll file under the LLVM
|
||||
# test/CodeGen/Generic tree and classify each result:
|
||||
#
|
||||
# pass exit 0 and a non-empty .s
|
||||
# unsupported a clear LLVM/target diagnostic (Cannot select, an explicit
|
||||
# M2/TMS34010 rejection, a missing libcall, an inline-asm
|
||||
# constraint failure), even when LLVM exits through
|
||||
# report_fatal_error()
|
||||
# crash signal/abort/assertion/timeout, or any failure without a
|
||||
# recognized diagnostic
|
||||
#
|
||||
# Every `unsupported` row must be recorded with a reason in
|
||||
# generic-expected-fail.txt. A crash is a regression and is never a skip:
|
||||
# it fails this gate even if the manifest names the test. The report is
|
||||
# written to build/m5-generic/generic-report.txt.
|
||||
#
|
||||
# This is a compile-only sweep. Hand-written Generic IR GEPs are
|
||||
# byte-oriented and the target tms-clang bit-address scaling does not apply,
|
||||
# so executing the output is out of scope.
|
||||
#
|
||||
# Overridable: TMS_LLC LLVM_BIN GENERIC_SRC M5_WORK GENERIC_TIMEOUT
|
||||
# GENERIC_ALLOWLIST GENERIC_MANIFEST
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
GENERIC_SRC=${GENERIC_SRC:-$ROOT/build/llvm-clean/llvm/test/CodeGen/Generic}
|
||||
M5_WORK=${M5_WORK:-$ROOT/build/m5-generic}
|
||||
# M5_WORK is removed below; reject paths that could escape their intended
|
||||
# build directory or name the filesystem root.
|
||||
case $M5_WORK in
|
||||
'' | / | . | ..)
|
||||
echo "M5 generic: FAIL: unsafe M5_WORK '$M5_WORK'" >&2
|
||||
exit 1
|
||||
;;
|
||||
*/../* | */.. | ../* | */./* | */.)
|
||||
echo "M5 generic: FAIL: unsafe M5_WORK '$M5_WORK' (contains . or ..)" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
# 2010-11-04-BigByval is intentionally expensive upstream (a 128 KiB byval
|
||||
# copy; PR7170). It takes ~6 minutes here but does finish, so the timeout is
|
||||
# generous enough not to misclassify it while still catching a real hang.
|
||||
GENERIC_TIMEOUT=${GENERIC_TIMEOUT:-900}
|
||||
ALLOWLIST=${GENERIC_ALLOWLIST:-$HERE/generic-allowlist.txt}
|
||||
MANIFEST=${GENERIC_MANIFEST:-$HERE/generic-expected-fail.txt}
|
||||
REPORT=$M5_WORK/generic-report.txt
|
||||
|
||||
fail() {
|
||||
echo "M5 generic: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -d "$GENERIC_SRC" ] || fail "missing Generic test tree: $GENERIC_SRC"
|
||||
GENERIC_SRC=$(cd "$GENERIC_SRC" && pwd)
|
||||
command -v timeout >/dev/null 2>&1 || fail "timeout(1) is required"
|
||||
|
||||
rm -rf "$M5_WORK"
|
||||
mkdir -p "$M5_WORK/allowlist" "$M5_WORK/sweep"
|
||||
|
||||
# The first stderr line, with CRs stripped and long diagnostics truncated, is
|
||||
# enough for a report row.
|
||||
detail() {
|
||||
sed -n '1{s/\r$//;p;}' "$1" 2>/dev/null | cut -c1-200
|
||||
}
|
||||
|
||||
# Print the classification reason for a non-passing result, or nothing when
|
||||
# stderr has no recognized diagnostic.
|
||||
failure_reason() {
|
||||
err=$1
|
||||
line=$(detail "$err")
|
||||
if grep -Eq 'LLVM ERROR: Cannot select:' "$err"; then
|
||||
printf 'target cannot select IR node: %s\n' \
|
||||
"$(printf '%s\n' "$line" | sed 's/^LLVM ERROR: //')"
|
||||
elif grep -Eq 'LLVM ERROR: (TMS34010|M2)([: ]|$)' "$err"; then
|
||||
printf 'target rejection: %s\n' \
|
||||
"$(printf '%s\n' "$line" | sed 's/^LLVM ERROR: //')"
|
||||
elif grep -Fq 'LLVM ERROR: unsupported library call operation' "$err"; then
|
||||
printf 'missing libcall lowering (floats/vectors are deferred to M6)\n'
|
||||
elif grep -Fq 'LLVM ERROR: Could not match memory address' "$err"; then
|
||||
printf 'inline asm memory constraint is not supported\n'
|
||||
elif grep -Fq "error: could not allocate output register for constraint" "$err"; then
|
||||
printf 'inline asm register constraint cannot be allocated\n'
|
||||
elif grep -Fq 'error: unexpected token' "$err"; then
|
||||
printf 'inline asm syntax is not supported by the TMS34010 parser\n'
|
||||
elif grep -Fq 'fast-math-flags specified for call' "$err"; then
|
||||
printf 'IR verifier rejects the input (fast-math flags on an integer call)\n'
|
||||
fi
|
||||
}
|
||||
|
||||
# classify_one OUT ERR RC: print "pass|unsupported|crash<TAB>detail".
|
||||
classify_one() {
|
||||
out=$1
|
||||
err=$2
|
||||
rc=$3
|
||||
if [ "$rc" -eq 0 ]; then
|
||||
if [ -s "$out" ]; then
|
||||
printf 'pass\tasm %s bytes\n' "$(wc -c < "$out" | tr -d ' ')"
|
||||
else
|
||||
printf 'crash\tllc exited 0 but produced an empty asm file\n'
|
||||
fi
|
||||
return
|
||||
fi
|
||||
if grep -Eq 'Assertion .* failed' "$err"; then
|
||||
printf 'crash\tassertion: %s\n' "$(detail "$err" | cut -c1-160)"
|
||||
return
|
||||
fi
|
||||
# Timeout(1) uses 124 for SIGTERM and 137 for SIGKILL. Keep both as
|
||||
# crashes, but do not pretend SIGKILL is necessarily a timeout: it can be
|
||||
# the OOM killer. Only 134 (SIGABRT from report_fatal_error) is the
|
||||
# clear-diagnostic carve-out; any other signal is a crash even if a
|
||||
# diagnostic was printed before it.
|
||||
if [ "$rc" -eq 124 ]; then
|
||||
printf 'crash\ttimeout after %ss\n' "$GENERIC_TIMEOUT"
|
||||
return
|
||||
fi
|
||||
if [ "$rc" -eq 137 ]; then
|
||||
printf 'crash\tkilled by signal 9 (SIGKILL; possibly OOM)\n'
|
||||
return
|
||||
fi
|
||||
if [ "$rc" -ge 128 ] && [ "$rc" -ne 134 ]; then
|
||||
sig=$((rc - 128))
|
||||
if [ "$sig" -eq 0 ]; then
|
||||
printf 'crash\texit 128 (signal range, no signal number)\n'
|
||||
else
|
||||
printf 'crash\tkilled by signal %s\n' "$sig"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
reason=$(failure_reason "$err")
|
||||
if [ -n "$reason" ]; then
|
||||
printf 'unsupported\t%s\n' "$reason"
|
||||
elif [ "$rc" -eq 134 ]; then
|
||||
printf 'crash\tabort (SIGABRT) with no recognized diagnostic: %s\n' \
|
||||
"$(detail "$err")"
|
||||
else
|
||||
printf 'crash\texit %s: %s\n' "$rc" "$(detail "$err")"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Phase 1: allowlist gate -------------------------------------------------
|
||||
[ -f "$ALLOWLIST" ] || fail "no allowlist: $ALLOWLIST"
|
||||
allow_total=0
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
allow_total=$((allow_total + 1))
|
||||
src=$GENERIC_SRC/$name.ll
|
||||
[ -f "$src" ] || fail "allowlist entry has no source: $src"
|
||||
flat=$(printf '%s' "$name" | tr '/' '_')
|
||||
out=$M5_WORK/allowlist/$flat.s
|
||||
err=$M5_WORK/allowlist/$flat.err
|
||||
set +e
|
||||
timeout "$GENERIC_TIMEOUT" "$TMS_LLC" -march=tms34010 -filetype=asm -O0 \
|
||||
"$src" -o "$out" 2> "$err"
|
||||
rc=$?
|
||||
set -e
|
||||
[ "$rc" -eq 0 ] || fail "allowlist $name: llc exited $rc: $(detail "$err")"
|
||||
[ -s "$out" ] || fail "allowlist $name: empty asm"
|
||||
done < "$ALLOWLIST"
|
||||
[ "$allow_total" -gt 0 ] || fail "generic-allowlist.txt is empty"
|
||||
echo "M5 generic allowlist: PASS files=$allow_total"
|
||||
|
||||
# --- Phase 2: broad no-crash sweep ------------------------------------------
|
||||
total=0
|
||||
pass=0
|
||||
unsupported=0
|
||||
crash=0
|
||||
: > "$M5_WORK/unsupported.txt"
|
||||
|
||||
{
|
||||
echo "# M5 CodeGen/Generic compile-only sweep"
|
||||
echo "# llc: $TMS_LLC"
|
||||
echo "# flags: -march=tms34010 -filetype=asm -O0"
|
||||
echo "# timeout: ${GENERIC_TIMEOUT}s"
|
||||
echo "# rows: status<TAB>test<TAB>detail"
|
||||
} > "$REPORT"
|
||||
|
||||
find "$GENERIC_SRC" -type f -name '*.ll' | sort > "$M5_WORK/tests.txt"
|
||||
[ -s "$M5_WORK/tests.txt" ] || fail "no Generic .ll files under $GENERIC_SRC"
|
||||
|
||||
while IFS= read -r src; do
|
||||
rel=${src#"$GENERIC_SRC"/}
|
||||
name=${rel%.ll}
|
||||
total=$((total + 1))
|
||||
# Keep the report name relative to the Generic tree (subdirectories
|
||||
# included) but use a flat, unique work file per test.
|
||||
stem=$(basename "$src" .ll)
|
||||
out=$M5_WORK/sweep/$total-$stem.s
|
||||
err=$M5_WORK/sweep/$total-$stem.err
|
||||
set +e
|
||||
timeout "$GENERIC_TIMEOUT" "$TMS_LLC" -march=tms34010 -filetype=asm -O0 \
|
||||
"$src" -o "$out" 2> "$err"
|
||||
rc=$?
|
||||
set -e
|
||||
result=$(classify_one "$out" "$err" "$rc")
|
||||
status=${result%% *}
|
||||
why=${result#* }
|
||||
case $status in
|
||||
pass)
|
||||
pass=$((pass + 1))
|
||||
;;
|
||||
unsupported)
|
||||
unsupported=$((unsupported + 1))
|
||||
printf '%s\n' "$name" >> "$M5_WORK/unsupported.txt"
|
||||
;;
|
||||
crash)
|
||||
crash=$((crash + 1))
|
||||
echo "M5 generic: CRASH $name: $why" >&2
|
||||
;;
|
||||
*)
|
||||
fail "internal classification error for $name: $result"
|
||||
;;
|
||||
esac
|
||||
printf '%s\t%s\t%s\n' "$status" "$name" "$why" >> "$REPORT"
|
||||
done < "$M5_WORK/tests.txt"
|
||||
|
||||
{
|
||||
echo "# total $total pass $pass unsupported $unsupported crash $crash"
|
||||
} >> "$REPORT"
|
||||
|
||||
# --- Manifest check ----------------------------------------------------------
|
||||
# Every unsupported row needs a reason, and a manifest row may not name a
|
||||
# passing test (stale) or a crash (a crash is never a known failure).
|
||||
[ -f "$MANIFEST" ] || fail "no expected-fail manifest: $MANIFEST"
|
||||
: > "$M5_WORK/manifest.txt"
|
||||
while IFS=$(printf '\t') read -r name reason; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
[ -n "${reason:-}" ] || fail "manifest entry '$name' has no reason"
|
||||
[ -f "$GENERIC_SRC/$name.ll" ] || fail "manifest entry has no source: $name.ll"
|
||||
if grep -Fxq "$name" "$M5_WORK/unsupported.txt"; then
|
||||
printf '%s\n' "$name" >> "$M5_WORK/manifest.txt"
|
||||
else
|
||||
row=$(awk -F '\t' -v n="$name" '$2 == n { print $1 }' "$REPORT")
|
||||
case $row in
|
||||
pass)
|
||||
fail "manifest entry '$name' now passes; remove it from the manifest"
|
||||
;;
|
||||
crash)
|
||||
fail "manifest entry '$name' crashes; a crash is not a known failure"
|
||||
;;
|
||||
*)
|
||||
fail "manifest entry '$name' is not in the sweep"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done < "$MANIFEST"
|
||||
|
||||
sort -o "$M5_WORK/unsupported.txt" "$M5_WORK/unsupported.txt"
|
||||
sort -o "$M5_WORK/manifest.txt" "$M5_WORK/manifest.txt"
|
||||
listed=$(comm -23 "$M5_WORK/manifest.txt" "$M5_WORK/unsupported.txt")
|
||||
[ -z "$listed" ] || fail "manifest names a non-unsupported test: $listed"
|
||||
missing=$(comm -13 "$M5_WORK/manifest.txt" "$M5_WORK/unsupported.txt")
|
||||
if [ -n "$missing" ]; then
|
||||
echo "M5 generic: unsupported tests with no manifest reason:" >&2
|
||||
echo "$missing" | sed 's/^/ /' >&2
|
||||
fail "record every unsupported test in generic-expected-fail.txt"
|
||||
fi
|
||||
|
||||
[ "$total" -gt 0 ] || fail "no Generic tests found"
|
||||
[ "$crash" -eq 0 ] || fail "$crash Generic test(s) crashed"
|
||||
[ "$pass" -gt 0 ] || fail "no Generic test passed"
|
||||
|
||||
echo "M5 generic sweep: PASS total=$total pass=$pass unsupported=$unsupported crash=$crash"
|
||||
echo "M5 generic: report $REPORT"
|
||||
Executable
+307
@@ -0,0 +1,307 @@
|
||||
#!/bin/sh
|
||||
# M5 JR / branch-relaxation gate.
|
||||
#
|
||||
# Proves that a local branch whose displacement fits the ISA's signed 8-bit
|
||||
# word range uses the one-word relative JR/JR<cc> form, that the absolute
|
||||
# JAUC/JA<cc> form is kept when it cannot reach (and for the zero displacement,
|
||||
# which the short form cannot encode), and that the native object path, the
|
||||
# assembler path and the 1987 GSPA/GSPLNK oracle agree:
|
||||
#
|
||||
# 1. compile the M3 branch.c loop and require the in-range loop branches in
|
||||
# _sumto to be JR forms (m5-jr.ll pins the far-branch side);
|
||||
# 2. re-assemble llc's asm output with llvm-mc and require its .text to equal
|
||||
# the llc -filetype=obj .text byte for byte;
|
||||
# 3. assemble a symbolic JR that is in range (two-byte encoding) and one that
|
||||
# is out of range (the MC backend must widen it to the three-word form);
|
||||
# 4. run the unchanged M3 branch.c loop in MAME through GSPA/GSPLNK and
|
||||
# require the M3 markers (sum=55 max=22 lt=1 screens=0x480 root_off=0x40);
|
||||
# 5. record the linked .text size and the all-JA baseline: every JR in the
|
||||
# linked image replaces a six-byte JA, so the relaxation saved 4 bytes
|
||||
# per JR. Every JR target must be within the ISA's +-2032-bit reach.
|
||||
#
|
||||
# scripts/tests/m5/jr.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TMS_LLVM_MC
|
||||
# DIS34 M5_JR_WORK DOSBOX MAME MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
WORK=${M5_JR_WORK:-$ROOT/build/m5-jr}
|
||||
SRC=$ROOT/scripts/m3
|
||||
export M3_WORK=${M3_WORK:-$WORK/m3}
|
||||
export M3_COFF=${M3_COFF:-$M3_WORK/m3.coff}
|
||||
|
||||
fail() {
|
||||
echo "M5 JR: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Extract a .text section. llvm-mc uses LLVM's generic ELF writer (sizes in
|
||||
# bytes); llc -filetype=obj and GSPLNK write TI-COFF (sizes in bits, optional
|
||||
# header size at offset 16).
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
|
||||
if d[:4] == b"\x7fELF":
|
||||
e_shoff, = struct.unpack_from("<I", d, 0x20)
|
||||
e_shentsize, = struct.unpack_from("<H", d, 0x2E)
|
||||
e_shnum, = struct.unpack_from("<H", d, 0x30)
|
||||
e_shstrndx, = struct.unpack_from("<H", d, 0x32)
|
||||
o = e_shoff + e_shstrndx * e_shentsize
|
||||
str_off, = struct.unpack_from("<I", d, o + 16)
|
||||
str_size, = struct.unpack_from("<I", d, o + 20)
|
||||
strtab = d[str_off:str_off + str_size]
|
||||
for i in range(e_shnum):
|
||||
o = e_shoff + i * e_shentsize
|
||||
name_off, = struct.unpack_from("<I", d, o)
|
||||
name = strtab[name_off:strtab.find(b"\0", name_off)].decode("latin1")
|
||||
if name != ".text":
|
||||
continue
|
||||
off, size = struct.unpack_from("<II", d, o + 16)
|
||||
text = d[off:off + size]
|
||||
with open(out, "wb") as g:
|
||||
g.write(text)
|
||||
print(f"{path}: ELF .text {len(text)} bytes")
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
|
||||
machine, nscns = struct.unpack_from("<HH", d, 0)
|
||||
opthdr, = struct.unpack_from("<H", d, 16)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want TI-COFF 0x0090")
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size, ptr = struct.unpack_from("<II", d, o + 16)
|
||||
if name != ".text":
|
||||
continue
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: .text {size} bits is not whole bytes")
|
||||
text = d[ptr:ptr + size // 8]
|
||||
with open(out, "wb") as g:
|
||||
g.write(text)
|
||||
print(f"{path}: TI-COFF .text {len(text)} bytes")
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
}
|
||||
|
||||
# The M3 gate keeps the loop in branch.c (IndVarSimplify would otherwise turn
|
||||
# sumto into an i33 multiply that this target cannot select).
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
echo "== compile the M3 branch.c loop"
|
||||
TMS_OPT=$OPT_NOREPLEXIT TMS_CLANG="$TMS_CLANG" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
-o "$WORK/branch.ll" "$SRC/branch.c" || fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/branch.ll" \
|
||||
-o "$WORK/branch.s" || fail "llc -filetype=asm failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj "$WORK/branch.ll" \
|
||||
-o "$WORK/branch.o" || fail "llc -filetype=obj failed"
|
||||
|
||||
# The short-loop body must use the relative form. m5-jr.ll checks the other
|
||||
# half of the contract (a far/zero-displacement branch stays absolute).
|
||||
awk '/^_sumto:/ { on = 1; next } on && /-- End function/ { exit } on' \
|
||||
"$WORK/branch.s" > "$WORK/sumto.s"
|
||||
grep -Eq '^[[:space:]]*JR(UC|EQ|NE|LT|LE|GT|GE|LO|LS|HI|HS|P|N|V|NV|NN)[[:space:]]' \
|
||||
"$WORK/sumto.s" || { sed 's/^/ /' "$WORK/sumto.s" >&2; fail "_sumto has no JR branch"; }
|
||||
JR_ASM=$(grep -Ec '^[[:space:]]*JR(UC|EQ|NE|LT|LE|GT|GE|LO|LS|HI|HS|P|N|V|NV|NN)[[:space:]]' "$WORK/sumto.s" || true)
|
||||
echo " _sumto: $JR_ASM relative branch(es)"
|
||||
|
||||
echo "== asm and object paths must encode the same branch stream"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$WORK/branch.s" \
|
||||
-o "$WORK/branch-mc.o" || fail "llvm-mc could not assemble llc's output"
|
||||
extract_text "$WORK/branch.o" "$WORK/branch-obj.text"
|
||||
extract_text "$WORK/branch-mc.o" "$WORK/branch-mc.text"
|
||||
if ! cmp -s "$WORK/branch-obj.text" "$WORK/branch-mc.text"; then
|
||||
{
|
||||
echo "M5 JR: FAIL: llc -filetype=obj and llvm-mc .text differ"
|
||||
echo " object: $(od -An -v -tx1 "$WORK/branch-obj.text")"
|
||||
echo " asm: $(od -An -v -tx1 "$WORK/branch-mc.text")"
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " obj .text == llvm-mc .text ($(wc -c < "$WORK/branch-obj.text") bytes)"
|
||||
|
||||
echo "== MC relaxation: symbolic JR forms must widen when not encodable"
|
||||
cat > "$WORK/relax.s" <<'EOF'
|
||||
.text
|
||||
m5_relax:
|
||||
JRUC near
|
||||
RETS 0
|
||||
near:
|
||||
RETS 0
|
||||
JRUC zero
|
||||
zero:
|
||||
RETS 0
|
||||
JRUC far
|
||||
RETS 0
|
||||
EOF
|
||||
# `far` follows 200 NOPs (400 bytes). `zero` is the next instruction, so its
|
||||
# displacement would be 0 (the 16-bit relative form's marker), and disp -128
|
||||
# (low byte 0x80) is the absolute-JA marker: neither is encodable in one word.
|
||||
# The last two probes pin the boundaries: -127 must stay short, -128 must
|
||||
# widen. Each is placed 126/127 NOPs (252/254 bytes) after its label.
|
||||
awk 'BEGIN { for (i = 0; i < 200; i++) print "\tNOP" }' >> "$WORK/relax.s"
|
||||
printf 'far:\n\tRETS 0\nback127:\n' >> "$WORK/relax.s"
|
||||
awk 'BEGIN { for (i = 0; i < 126; i++) print "\tNOP" }' >> "$WORK/relax.s"
|
||||
printf '\tJRUC back127\nback128:\n' >> "$WORK/relax.s"
|
||||
awk 'BEGIN { for (i = 0; i < 127; i++) print "\tNOP" }' >> "$WORK/relax.s"
|
||||
printf '\tJRUC back128\n\tRETS 0\n' >> "$WORK/relax.s"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$WORK/relax.s" \
|
||||
-o "$WORK/relax.o" || fail "llvm-mc failed on the relaxation probe"
|
||||
extract_text "$WORK/relax.o" "$WORK/relax.text"
|
||||
# Layout with three widenings (zero, far, back128): JRUC near 2 + RETS 2 +
|
||||
# near RETS 2 + JRUC zero 6 + RETS 2 + JRUC far 6 + RETS 2 + 200 NOPs 400 +
|
||||
# far RETS 2 + 126 NOPs 252 + JRUC back127 2 + 127 NOPs 254 + JRUC back128 6 +
|
||||
# RETS 2 = 940 bytes. A missing widening would be 4 bytes smaller.
|
||||
RELAX_BYTES=$(wc -c < "$WORK/relax.text")
|
||||
[ "$RELAX_BYTES" -eq 940 ] \
|
||||
|| fail "relaxed .text is $RELAX_BYTES bytes, want 940 (three 6-byte JAs)"
|
||||
"$DIS34" -b 0 -l -o "$WORK/relax.text" > "$WORK/relax.dis" 2>/dev/null \
|
||||
|| fail "dis34 failed on the relaxation probe"
|
||||
# dis34 -l prints `<bit address>:\t<mnemonic> <target>\t; <encoded words>`.
|
||||
python3 - "$WORK/relax.dis" <<'PY' || fail "the MC relaxation probe is wrong"
|
||||
import re
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
branches = []
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = re.match(r"^[0-9a-f]+:\s+(j[a-z]*)\s+\S+\s*;\s*([0-9a-f ]+)$",
|
||||
line.strip())
|
||||
if m:
|
||||
words = m.group(2).replace(" ", "")
|
||||
branches.append((m.group(1), len(words) // 2, words[:4]))
|
||||
# near disp=1 (c001) stays 2 bytes; zero, far and back128 widen to 6 bytes;
|
||||
# back127 disp=-127 (c081) is the last encodable displacement and stays 2.
|
||||
want = [("jruc", 2, "c001"), ("jauc", 6, "c080"), ("jauc", 6, "c080"),
|
||||
("jruc", 2, "c081"), ("jauc", 6, "c080")]
|
||||
if branches != want:
|
||||
sys.exit(f"branch encodings {branches}, want {want}")
|
||||
print(" branch encodings:",
|
||||
" ".join(f"{m}/{n}B" for m, n, _w in branches))
|
||||
PY
|
||||
|
||||
echo "== run the M3 branch.c loop in MAME"
|
||||
"$ROOT/scripts/tests/m3/run.sh" > "$WORK/m3.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/m3.log" >&2; fail "M3 gate failed"; }
|
||||
grep -q '^M3 MAME: PASS' "$WORK/m3.log" \
|
||||
|| { grep -E '^M3:' "$WORK/m3.log" >&2 || true; fail "M3 MAME markers did not pass"; }
|
||||
MARKER=$(grep -E 'M3: display=' "$WORK/m3.log" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no M3 marker line"
|
||||
case "$MARKER" in
|
||||
*" sum=55 max=22 lt=1 screens=0x480 root_off=0x40"*) ;;
|
||||
*) fail "M3 marker values changed: $MARKER" ;;
|
||||
esac
|
||||
echo " $MARKER"
|
||||
|
||||
echo "== linked .text size"
|
||||
# Recorded baseline for the unchanged M3 sources (branch.c, layout.c, xhello.c).
|
||||
# Update these constants together if those sources, the relaxation, or the
|
||||
# frame save/restore change. MMTM/MMFM shortened xhello's 4-register save and
|
||||
# restore by 8 bytes (882 -> 874); functions saving one or two registers keep
|
||||
# the same or grow by up to 4 bytes, so re-measure after changing the ABI.
|
||||
EXPECTED_TEXT_BYTES=874
|
||||
EXPECTED_JR=14
|
||||
TEXT_BITS=$(awk '$1 == ".text" && $2 == "0" { print $4; exit }' "$M3_WORK/m3.map")
|
||||
[ -n "$TEXT_BITS" ] || fail "the linker map has no .text section"
|
||||
TEXT_BYTES=$((0x$TEXT_BITS / 8))
|
||||
extract_text "$M3_COFF" "$WORK/m3.text"
|
||||
"$DIS34" -b 018A0000 -l -o "$WORK/m3.text" > "$WORK/m3.dis" 2>/dev/null \
|
||||
|| fail "dis34 failed on the linked image"
|
||||
NJR=$(grep -Ec '^[0-9a-f]+:[[:space:]]+jr(uc|eq|ne|lt|le|gt|ge|lo|ls|hi|hs|p|n|v|nv|nn)([[:space:]]|;|$)' "$WORK/m3.dis" || true)
|
||||
[ "$NJR" -eq "$EXPECTED_JR" ] \
|
||||
|| fail "the linked image has $NJR JR branches, want $EXPECTED_JR"
|
||||
[ "$TEXT_BYTES" -eq "$EXPECTED_TEXT_BYTES" ] \
|
||||
|| fail "linked .text is $TEXT_BYTES bytes, want $EXPECTED_TEXT_BYTES"
|
||||
BASELINE=$((TEXT_BYTES + 4 * NJR))
|
||||
SAVED=$((4 * NJR))
|
||||
echo " linked .text: $TEXT_BYTES bytes; $NJR JR branch(es) save $SAVED bytes"
|
||||
echo " all-JA baseline: $BASELINE bytes"
|
||||
|
||||
# A branch to the following instruction cannot use the one-word form (disp 0
|
||||
# selects the 16-bit relative form), so it must stay absolute. A far branch is
|
||||
# absolute too, so require the specific shape: a JA whose target label is
|
||||
# defined on the next line. The M3 baseline has exactly two, both in xhello.
|
||||
ZERO_DISP_JA=$(python3 - "$M3_WORK/asm" <<'PY'
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
count = 0
|
||||
for path in sorted(glob.glob(os.path.join(sys.argv[1], "*.unique.s"))):
|
||||
lines = open(path, encoding="latin1").read().splitlines()
|
||||
for i, line in enumerate(lines):
|
||||
m = re.match(r"^\s*JA(?:UC|EQ|NE|LT|LE|GT|GE|LO|LS|HI|HS|P|N|V|NV|NN)"
|
||||
r"\s+(\S+)", line)
|
||||
if not m or i + 1 >= len(lines):
|
||||
continue
|
||||
label = re.match(r"^([A-Za-z_][A-Za-z0-9_]*):", lines[i + 1])
|
||||
if label and label.group(1) == m.group(1):
|
||||
count += 1
|
||||
print(count)
|
||||
PY
|
||||
)
|
||||
[ "$ZERO_DISP_JA" -eq 2 ] \
|
||||
|| fail "the compiled TUs have $ZERO_DISP_JA zero-displacement JA branches, want 2"
|
||||
echo " zero-displacement branches kept absolute: $ZERO_DISP_JA"
|
||||
|
||||
# Every JR must be one 16-bit word (dis34 -l prints the encoded words in the
|
||||
# trailing comment; a GSPA 16-bit relative form would print two words) and must
|
||||
# encode a nonzero displacement that fits the signed 8-bit word range.
|
||||
python3 - "$WORK/m3.dis" <<'PY' || fail "a JR encoding is not a one-word in-range JR"
|
||||
import re
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
pat = re.compile(r"^([0-9a-f]+):\s+jr[a-z]*\s+(\S+)\s*;\s*([0-9a-f ]+)$")
|
||||
count = 0
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = pat.match(line.strip())
|
||||
if not m:
|
||||
continue
|
||||
pc = int(m.group(1), 16)
|
||||
tgt_text = m.group(2).lstrip("L")
|
||||
try:
|
||||
tgt = int(tgt_text, 16)
|
||||
except ValueError:
|
||||
sys.exit(f"cannot parse JR target: {line.strip()}")
|
||||
words = m.group(3).replace(" ", "")
|
||||
if len(words) != 4:
|
||||
sys.exit(f"JR is not one word: {line.strip()}")
|
||||
delta = tgt - (pc + 16)
|
||||
if delta == 0 or delta % 16 or abs(delta) > 127 * 16:
|
||||
sys.exit(f"JR out of range: {line.strip()} (delta {delta} bits)")
|
||||
count += 1
|
||||
if count == 0:
|
||||
sys.exit("no JR instruction found")
|
||||
print(f" all {count} JR branches are one word and in range (±2032 bits)")
|
||||
PY
|
||||
|
||||
echo "M5 JR: PASS"
|
||||
Executable
+215
@@ -0,0 +1,215 @@
|
||||
#!/bin/sh
|
||||
# M5 MC round-trip gate.
|
||||
#
|
||||
# Assembles llvm/test/MC/TMS34010/roundtrip.s with `llvm-mc -filetype=obj`,
|
||||
# extracts the .text bytes, and requires the vendored smart34010 `dis34` to
|
||||
# reproduce the source mnemonics and operands. GSPA/`dis34` are the encoding
|
||||
# oracle; the expected bytes in encodings.s are GSPA listings, not this
|
||||
# encoder's output.
|
||||
#
|
||||
# scripts/tests/m5/mc-roundtrip.sh
|
||||
#
|
||||
# Overridable: TMS_LLVM_MC TMS_DIS34 M5_MC_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
TMS_DIS34=${TMS_DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
SRC=${TMS_MC_SRC:-$ROOT/build/llvm-clean/llvm/test/MC/TMS34010/roundtrip.s}
|
||||
M5_MC_WORK=${M5_MC_WORK:-$ROOT/build/m5-mc}
|
||||
|
||||
fail() {
|
||||
echo "M5 MC round-trip: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLVM_MC" ] || fail "missing llvm-mc: $TMS_LLVM_MC"
|
||||
[ -x "$TMS_DIS34" ] || fail "missing dis34: $TMS_DIS34"
|
||||
[ -f "$SRC" ] || fail "missing source: $SRC"
|
||||
|
||||
mkdir -p "$M5_MC_WORK"
|
||||
OBJ=$M5_MC_WORK/roundtrip.o
|
||||
rm -f "$OBJ"
|
||||
|
||||
echo "== assemble $SRC"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$SRC" -o "$OBJ" \
|
||||
|| fail "llvm-mc -filetype=obj failed"
|
||||
|
||||
# Extract .text. llvm-mc uses LLVM's generic ELF writer, whose section size is
|
||||
# in bytes; the target's own TI-COFF writer (llc -filetype=obj) stores section
|
||||
# sizes in bits. Prefer the ELF path, with a bits-first TI-COFF fallback.
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
|
||||
def elf_text():
|
||||
if len(d) < 52 or d[:4] != b"\x7fELF" or d[4] != 1 or d[5] != 1:
|
||||
return None
|
||||
e_shoff = struct.unpack_from("<I", d, 0x20)[0]
|
||||
e_shentsize = struct.unpack_from("<H", d, 0x2E)[0]
|
||||
e_shnum = struct.unpack_from("<H", d, 0x30)[0]
|
||||
e_shstrndx = struct.unpack_from("<H", d, 0x32)[0]
|
||||
if e_shentsize != 40 or e_shnum == 0 or e_shstrndx >= e_shnum:
|
||||
return None
|
||||
shstr = e_shoff + e_shstrndx * e_shentsize
|
||||
str_off = struct.unpack_from("<I", d, shstr + 16)[0]
|
||||
str_size = struct.unpack_from("<I", d, shstr + 20)[0]
|
||||
strtab = d[str_off:str_off + str_size]
|
||||
for i in range(e_shnum):
|
||||
o = e_shoff + i * e_shentsize
|
||||
name_off = struct.unpack_from("<I", d, o)[0]
|
||||
name = strtab[name_off:strtab.find(b"\0", name_off)].decode("latin1")
|
||||
if name == ".text":
|
||||
off = struct.unpack_from("<I", d, o + 16)[0]
|
||||
size = struct.unpack_from("<I", d, o + 20)[0]
|
||||
if off + size > len(d):
|
||||
sys.exit(f"{path}: .text runs past EOF")
|
||||
return d[off:off + size]
|
||||
return None
|
||||
|
||||
def coff_text():
|
||||
if len(d) < 20:
|
||||
return None
|
||||
machine, nscns, _time, _symptr, _nsyms, opthdr, _flags = \
|
||||
struct.unpack_from("<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
return None
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size = struct.unpack_from("<I", d, o + 16)[0]
|
||||
ptr = struct.unpack_from("<I", d, o + 20)[0]
|
||||
if name == ".text":
|
||||
# The native TI-COFF writer stores SizeOfRawData in bits.
|
||||
nbytes = size // 8
|
||||
if size and ptr + nbytes <= len(d):
|
||||
return d[ptr:ptr + nbytes]
|
||||
# Fallback for a COFF producer that uses byte sizes.
|
||||
if size and ptr + size <= len(d):
|
||||
return d[ptr:ptr + size]
|
||||
return None
|
||||
|
||||
text = elf_text()
|
||||
if text is None:
|
||||
text = coff_text()
|
||||
if text is None:
|
||||
sys.exit(f"{path}: no .text section")
|
||||
if not text:
|
||||
sys.exit(f"{path}: .text is empty")
|
||||
if len(text) % 2:
|
||||
sys.exit(f"{path}: .text has an odd byte count ({len(text)})")
|
||||
with open(out, "wb") as f:
|
||||
f.write(text)
|
||||
PY
|
||||
}
|
||||
|
||||
TEXT=$M5_MC_WORK/roundtrip.text
|
||||
extract_text "$OBJ" "$TEXT"
|
||||
|
||||
echo "== disassemble with dis34"
|
||||
"$TMS_DIS34" "$TEXT" > "$M5_MC_WORK/roundtrip.dis" 2> "$M5_MC_WORK/roundtrip.err" \
|
||||
|| { cat "$M5_MC_WORK/roundtrip.err" >&2; fail "dis34 failed"; }
|
||||
|
||||
python3 - "$SRC" "$M5_MC_WORK/roundtrip.dis" <<'PY'
|
||||
import re
|
||||
import sys
|
||||
|
||||
src_path, dis_path = sys.argv[1], sys.argv[2]
|
||||
|
||||
REG = re.compile(r"^(a|b)\d+$|^sp$|^b15$")
|
||||
|
||||
|
||||
def canon_num(s):
|
||||
s = s.strip()
|
||||
try:
|
||||
return "#%d" % int(s, 0)
|
||||
except ValueError:
|
||||
return s
|
||||
|
||||
|
||||
def split_ops(text):
|
||||
# The TMS34010 syntax has no commas inside parentheses; split naively.
|
||||
return [p.strip() for p in text.split(",") if p.strip() != ""]
|
||||
|
||||
|
||||
def canon_operand(op):
|
||||
op = op.strip().lower()
|
||||
m = re.match(r"^([-+])?\*([ab]\d+|sp|b15)(\+)?(?:\((.*)\))?$", op)
|
||||
if m:
|
||||
sign, reg, post, disp = m.groups()
|
||||
out = (sign or "") + "*" + reg
|
||||
if post:
|
||||
out += "+"
|
||||
if disp is not None:
|
||||
out += "(" + canon_num(disp) + ")"
|
||||
return out
|
||||
if op.startswith("@"):
|
||||
return "@" + canon_num(op[1:])
|
||||
if REG.match(op):
|
||||
return op
|
||||
return canon_num(op)
|
||||
|
||||
|
||||
ALIASES = {"jac": "jalo", "janc": "jahs", "jrc": "jrlo", "jrnc": "jrhs"}
|
||||
|
||||
|
||||
def canon_inst(mnem, ops):
|
||||
mnem = ALIASES.get(mnem.strip().lower(), mnem.strip().lower())
|
||||
ops = [canon_operand(o) for o in split_ops(ops)]
|
||||
if mnem == "rets" and not ops:
|
||||
ops = ["#0"]
|
||||
return mnem, ops
|
||||
|
||||
|
||||
def source_insts(path):
|
||||
insts = []
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.split("#", 1)[0].strip()
|
||||
if not line or line.startswith(".") or line.endswith(":"):
|
||||
continue
|
||||
parts = line.split(None, 1)
|
||||
mnem = parts[0]
|
||||
rest = parts[1] if len(parts) > 1 else ""
|
||||
insts.append(canon_inst(mnem, rest))
|
||||
return insts
|
||||
|
||||
|
||||
def dis_insts(path):
|
||||
insts = []
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.split(";", 1)[0].strip()
|
||||
if not line or line.startswith(".word"):
|
||||
continue
|
||||
parts = line.split(None, 1)
|
||||
mnem = parts[0]
|
||||
rest = parts[1] if len(parts) > 1 else ""
|
||||
insts.append(canon_inst(mnem, rest))
|
||||
return insts
|
||||
|
||||
|
||||
want = source_insts(src_path)
|
||||
got = dis_insts(dis_path)
|
||||
|
||||
if want != got:
|
||||
print("M5 MC round-trip: FAIL: dis34 did not reproduce the source", file=sys.stderr)
|
||||
for i in range(max(len(want), len(got))):
|
||||
w = want[i] if i < len(want) else None
|
||||
g = got[i] if i < len(got) else None
|
||||
mark = " " if w == g else "!!"
|
||||
print(f" {mark} src={w} dis34={g}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f" {len(want)} instructions round-tripped through dis34")
|
||||
PY
|
||||
|
||||
echo "M5 MC round-trip: PASS"
|
||||
Executable
+225
@@ -0,0 +1,225 @@
|
||||
#!/bin/sh
|
||||
# M5 MMTM/MMFM register-list frame-save gate.
|
||||
#
|
||||
# Proves that the frame lowering saves the callee-save set with one MMTM and
|
||||
# restores it with one MMFM, without changing the TI ABI:
|
||||
#
|
||||
# 1. compile m5-mmtm.ll to asm and to a TI-COFF object; the callee saves
|
||||
# A0/A1/A3/A5 with one `MMTM SP, A0, A1, A3, A5`, restores with one
|
||||
# `MMFM SP, ...`, and still reloads the old STK from *SP(192) and returns
|
||||
# with RETS 2;
|
||||
# 2. assemble llc's asm with llvm-mc and require its .text to equal the
|
||||
# llc -filetype=obj .text byte for byte, so the asm and object paths use
|
||||
# the same register-list encoding;
|
||||
# 3. dis34 the object: the MMTM/MMFM register lists and their encoded masks
|
||||
# (0xd400/0x002b) must be present, and no per-register save may precede
|
||||
# SETFP; record the code-size saving;
|
||||
# 4. run the unchanged M2 and M3 gates in MAME and require their markers and
|
||||
# old-STK/ABI values.
|
||||
#
|
||||
# scripts/tests/m5/mmtm.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_LLVM_MC DIS34 M5_MMTM_WORK M2_WORK M2_COFF
|
||||
# M2_SDK M3_WORK M3_COFF M3_SDK MAME DOSBOX MAME_TIMEOUT
|
||||
# DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
|
||||
WORK=${M5_MMTM_WORK:-$ROOT/build/m5-mmtm}
|
||||
export M2_WORK=${M2_WORK:-$WORK/m2}
|
||||
export M2_COFF=${M2_COFF:-$M2_WORK/m2.coff}
|
||||
export M3_WORK=${M3_WORK:-$WORK/m3}
|
||||
export M3_COFF=${M3_COFF:-$M3_WORK/m3.coff}
|
||||
|
||||
fail() {
|
||||
echo "M5 MMTM: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Extract a .text section. llvm-mc uses LLVM's generic ELF writer (sizes in
|
||||
# bytes); llc -filetype=obj and GSPLNK write TI-COFF (sizes in bits, optional
|
||||
# header size at offset 16).
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
|
||||
if d[:4] == b"\x7fELF":
|
||||
e_shoff, = struct.unpack_from("<I", d, 0x20)
|
||||
e_shentsize, = struct.unpack_from("<H", d, 0x2E)
|
||||
e_shnum, = struct.unpack_from("<H", d, 0x30)
|
||||
e_shstrndx, = struct.unpack_from("<H", d, 0x32)
|
||||
o = e_shoff + e_shstrndx * e_shentsize
|
||||
str_off, = struct.unpack_from("<I", d, o + 16)
|
||||
str_size, = struct.unpack_from("<I", d, o + 20)
|
||||
strtab = d[str_off:str_off + str_size]
|
||||
for i in range(e_shnum):
|
||||
o = e_shoff + i * e_shentsize
|
||||
name_off, = struct.unpack_from("<I", d, o)
|
||||
name = strtab[name_off:strtab.find(b"\0", name_off)].decode("latin1")
|
||||
if name != ".text":
|
||||
continue
|
||||
off, size = struct.unpack_from("<II", d, o + 16)
|
||||
text = d[off:off + size]
|
||||
with open(out, "wb") as g:
|
||||
g.write(text)
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
|
||||
machine, nscns = struct.unpack_from("<HH", d, 0)
|
||||
opthdr, = struct.unpack_from("<H", d, 16)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want TI-COFF 0x0090")
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size, ptr = struct.unpack_from("<II", d, o + 16)
|
||||
if name != ".text":
|
||||
continue
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: .text {size} bits is not whole bytes")
|
||||
with open(out, "wb") as g:
|
||||
g.write(d[ptr:ptr + size // 8])
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
}
|
||||
|
||||
echo "== compile m5-mmtm.ll (asm and object paths)"
|
||||
"$TMS_LLC" -march=tms34010 -O2 -filetype=asm \
|
||||
"$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-mmtm.ll" \
|
||||
-o "$WORK/mmtm.s" || fail "llc -filetype=asm failed"
|
||||
"$TMS_LLC" -march=tms34010 -O2 -filetype=obj \
|
||||
"$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-mmtm.ll" \
|
||||
-o "$WORK/mmtm.o" || fail "llc -filetype=obj failed"
|
||||
|
||||
grep -Eq '^[[:space:]]*MMTM SP, A0, A1, A3, A5[[:space:]]*$' "$WORK/mmtm.s" \
|
||||
|| { grep -n 'MMT\|MOVE A.*-\*SP' "$WORK/mmtm.s" >&2; \
|
||||
fail "the callee does not save A0/A1/A3/A5 with one MMTM"; }
|
||||
grep -Eq '^[[:space:]]*MMFM SP, A0, A1, A3, A5[[:space:]]*$' "$WORK/mmtm.s" \
|
||||
|| { grep -n 'MMF\|MOVE \*SP+' "$WORK/mmtm.s" >&2; \
|
||||
fail "the callee does not restore A0/A1/A3/A5 with one MMFM"; }
|
||||
# The callee prologue must be exactly FP push + one MMTM: no per-register push.
|
||||
CALLEE=$(awk '/^_mmtm_callee:/ { on = 1; next } on && /-- End function/ { exit } on' \
|
||||
"$WORK/mmtm.s")
|
||||
printf '%s\n' "$CALLEE" | grep -Eq '^[[:space:]]*MOVE A13, -\*SP, 1[[:space:]]*$' \
|
||||
|| fail "the callee does not save FP with one MOVE push"
|
||||
PROLOGUE=$(printf '%s\n' "$CALLEE" | awk '
|
||||
/^[[:space:]]*MOVE A14, A13[[:space:]]*$/ { exit }
|
||||
{ print }
|
||||
')
|
||||
if printf '%s\n' "$PROLOGUE" | grep -Eq '^[[:space:]]*MOVE A([0-9]|1[0-2]), -\*SP, 1[[:space:]]*$'; then
|
||||
fail "the callee still has per-register system-stack saves"
|
||||
fi
|
||||
printf '%s\n' "$PROLOGUE" | grep -Eq '^[[:space:]]*MMTM SP, A0, A1, A3, A5[[:space:]]*$' \
|
||||
|| fail "the callee prologue does not save the register list with MMTM"
|
||||
printf '%s\n' "$CALLEE" | grep -Eq '^[[:space:]]*MOVE \*SP\(192\), A14, 1[[:space:]]*$' \
|
||||
|| fail "the callee old-STK load is not *SP(192)"
|
||||
printf '%s\n' "$CALLEE" | grep -Eq '^[[:space:]]*RETS 2[[:space:]]*$' \
|
||||
|| fail "the callee does not return with RETS 2"
|
||||
echo " callee: MOVE A13,-*SP ; MMTM SP, A0, A1, A3, A5 ; *SP(192),A14 ; RETS 2"
|
||||
|
||||
echo "== asm and object paths must encode the same register lists"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$WORK/mmtm.s" \
|
||||
-o "$WORK/mmtm-mc.o" || fail "llvm-mc could not assemble llc's output"
|
||||
extract_text "$WORK/mmtm.o" "$WORK/mmtm-obj.text" \
|
||||
|| fail "could not extract the llc object .text"
|
||||
extract_text "$WORK/mmtm-mc.o" "$WORK/mmtm-mc.text" \
|
||||
|| fail "could not extract the llvm-mc object .text"
|
||||
cmp -s "$WORK/mmtm-obj.text" "$WORK/mmtm-mc.text" \
|
||||
|| fail "llc -filetype=obj and llvm-mc .text differ"
|
||||
echo " obj .text == llvm-mc .text ($(wc -c < "$WORK/mmtm-obj.text") bytes)"
|
||||
|
||||
echo "== dis34 register list"
|
||||
"$DIS34" -b 0 -l -o "$WORK/mmtm-obj.text" > "$WORK/mmtm.dis" 2>/dev/null \
|
||||
|| fail "dis34 failed on the m5-mmtm object"
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmtm[[:space:]]+sp,[[:space:]]*a0,[[:space:]]*a1,[[:space:]]*a3,[[:space:]]*a5[[:space:]]*;' \
|
||||
"$WORK/mmtm.dis" \
|
||||
|| { grep -i 'mm[ft]m' "$WORK/mmtm.dis" >&2; fail "dis34 has no MMTM SP, A0, A1, A3, A5"; }
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmfm[[:space:]]+sp,[[:space:]]*a0,[[:space:]]*a1,[[:space:]]*a3,[[:space:]]*a5[[:space:]]*;' \
|
||||
"$WORK/mmtm.dis" \
|
||||
|| { grep -i 'mm[ft]m' "$WORK/mmtm.dis" >&2; fail "dis34 has no MMFM SP, A0, A1, A3, A5"; }
|
||||
# Pin the masks: MMTM numbers A0 from bit 15, MMFM from bit 0.
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmtm[[:space:]]+sp,[^;]*;[[:space:]]*098f[[:space:]]+d400[[:space:]]*$' \
|
||||
"$WORK/mmtm.dis" || fail "MMTM encoding is not 098f d400"
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmfm[[:space:]]+sp,[^;]*;[[:space:]]*09af[[:space:]]*002b[[:space:]]*$' \
|
||||
"$WORK/mmtm.dis" || fail "MMFM encoding is not 09af 002b"
|
||||
echo " dis34: MMTM SP, a0,a1,a3,a5 ; 098f d400"
|
||||
echo " dis34: MMFM SP, a0,a1,a3,a5 ; 09af 002b"
|
||||
|
||||
# Code size: an MMTM/MMFM is two words (4 bytes) and replaces one two-byte
|
||||
# MOVE push/pop per saved register. Count the registers in the two lists of
|
||||
# the callee and report the saving for that function.
|
||||
CALLEE_REGS=$(awk '
|
||||
{ low = tolower($0) }
|
||||
low ~ /mm[tf]m[[:space:]]+sp,/ {
|
||||
line = low
|
||||
sub(/^.*mm[tf]m[[:space:]]+sp,[[:space:]]*/, "", line)
|
||||
sub(/[[:space:]]*;.*$/, "", line)
|
||||
n += split(line, regs, ",")
|
||||
}
|
||||
END { print n + 0 }
|
||||
' <<EOF
|
||||
$CALLEE
|
||||
EOF
|
||||
)
|
||||
[ "$CALLEE_REGS" -gt 0 ] || fail "no registers in the callee register lists"
|
||||
# The old sequence was one 2-byte push and one 2-byte pop per register (2n
|
||||
# each direction), so the total is 4n bytes.
|
||||
OLD_BYTES=$((CALLEE_REGS * 4))
|
||||
NEW_BYTES=8
|
||||
SAVED_BYTES=$((OLD_BYTES - NEW_BYTES))
|
||||
echo " code size: $CALLEE_REGS saved-register slots: $OLD_BYTES bytes of pushes+pops" \
|
||||
"-> MMTM+MMFM $NEW_BYTES bytes (saves $SAVED_BYTES bytes)"
|
||||
|
||||
echo "== M2 gate (caller/callee + the unchanged ABI markers)"
|
||||
"$ROOT/scripts/tests/m2/run.sh" > "$WORK/m2.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/m2.log" >&2; fail "M2 gate failed"; }
|
||||
grep -q '^M2 MAME: PASS' "$WORK/m2.log" \
|
||||
|| { grep -E 'M2:' "$WORK/m2.log" >&2 || true; fail "M2 MAME markers did not pass"; }
|
||||
grep -q 'M2: check=4 first=20 second=22 caller=42 locals=7 keep=16' "$WORK/m2.log" \
|
||||
|| { grep -E 'M2:' "$WORK/m2.log" >&2 || true; fail "M2 marker values changed"; }
|
||||
grep -q 'MMTM SP,' "$M2_WORK/asm/keep.s" \
|
||||
|| fail "M2 keep.s does not use MMTM"
|
||||
grep -q 'MMFM SP,' "$M2_WORK/asm/keep.s" \
|
||||
|| fail "M2 keep.s does not use MMFM"
|
||||
echo " $(grep -E 'M2:' "$WORK/m2.log" | tail -1)"
|
||||
echo " keep.s: $(grep -m1 'MMTM' "$M2_WORK/asm/keep.s" | sed 's/^[[:space:]]*//')"
|
||||
|
||||
echo "== M3 gate (xhello + the unchanged display/branch markers)"
|
||||
"$ROOT/scripts/tests/m3/run.sh" > "$WORK/m3.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/m3.log" >&2; fail "M3 gate failed"; }
|
||||
grep -q '^M3 MAME: PASS' "$WORK/m3.log" \
|
||||
|| { grep -E 'M3:' "$WORK/m3.log" >&2 || true; fail "M3 MAME markers did not pass"; }
|
||||
MARKER=$(grep -E 'M3: display=' "$WORK/m3.log" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no M3 marker line"
|
||||
case "$MARKER" in
|
||||
*" sum=55 max=22 lt=1 screens=0x480 root_off=0x40"*) ;;
|
||||
*) fail "M3 marker values changed: $MARKER" ;;
|
||||
esac
|
||||
grep -q 'MMTM SP,' "$M3_WORK/asm/xhello.s" \
|
||||
|| fail "M3 xhello.s does not use MMTM"
|
||||
grep -q 'MMFM SP,' "$M3_WORK/asm/xhello.s" \
|
||||
|| fail "M3 xhello.s does not use MMFM"
|
||||
echo " $MARKER"
|
||||
echo " xhello.s: $(grep -m1 'MMTM' "$M3_WORK/asm/xhello.s" | sed 's/^[[:space:]]*//')"
|
||||
|
||||
echo "M5 MMTM: PASS"
|
||||
Executable
+469
@@ -0,0 +1,469 @@
|
||||
#!/bin/sh
|
||||
# M5 native-link gate: link an llc-produced TI-COFF object with a GSPA entry
|
||||
# object and run the linked image in MAME.
|
||||
#
|
||||
# 1. tms-clang -O0 -> IR, llc -filetype=obj -> NATIVE.O
|
||||
# 2. GSPA 2.00 assembles scripts/m5/native-entry.asm -> ENTRY.O
|
||||
# 3. GSPLNK 2.00 links NATIVE.O + ENTRY.O (scripts/m5/native-link.cmd)
|
||||
# 4. MAME + dwt/loader/loader.lua places the linked image and the check script
|
||||
# requires 018A8000 == 42, 018A8020 == 152 (42 + 'n'), 018A8040 == 1,
|
||||
# 018A8060 == 2, 018A8080 == 10 and 018A80A0 == 77. These prove the
|
||||
# .data MOVI, the .bss read/write, the branch loop and the resolved
|
||||
# undefined-external call. Both CALLAs in native_combo() are same-section
|
||||
# .text references; the cross-section proof is the .data/.bss MOVI.
|
||||
# 5. dis34 decodes _native_value at its linked bit address.
|
||||
#
|
||||
# The object itself is inspected for the GSPA/GSPLNK conventions: three
|
||||
# sections, section symbols with aux records, C_EXT globals, and R-RELLONG
|
||||
# relocations whose field holds a bit-address addend.
|
||||
#
|
||||
# scripts/tests/m5/native-link.sh
|
||||
#
|
||||
# Overridable: TMS_LLC M5_WORK M5_SDK SDK_IMG DOSBOX DOSBOX_CONF
|
||||
# MAME MAME_TIMEOUT DIS34 LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m5
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/scripts/tms-clang}
|
||||
|
||||
WORK=${M5_WORK:-$ROOT/build/m5-native-link}
|
||||
SDK=${M5_SDK:-$WORK/sdk}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
MAME_TIMEOUT=${MAME_TIMEOUT:-900}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
|
||||
fail() {
|
||||
echo "M5 native-link: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -x "$TMS_CLANG" ] || fail "missing tms-clang: $TMS_CLANG"
|
||||
[ -f "$DOSBOX_CONF" ] || fail "missing DOSBox config: $DOSBOX_CONF"
|
||||
command -v "$DOSBOX" >/dev/null 2>&1 || fail "missing DOSBox: $DOSBOX"
|
||||
[ -x "$MAME" ] || fail "missing MAME binary: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
|
||||
mkdir -p "$WORK" "$WORK/dos" "$WORK/run/nvram" "$WORK/run/cfg" "$WORK/evidence"
|
||||
|
||||
echo "== compile and encode"
|
||||
"$TMS_CLANG" -O0 -o "$WORK/native-link.ll" "$DIR/native-link.c" \
|
||||
|| fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$WORK/native-link.ll" -o "$WORK/native-link.o" \
|
||||
|| fail "llc -filetype=obj failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$WORK/native-link.ll" -o "$WORK/native-link.s" \
|
||||
|| fail "llc -filetype=asm failed"
|
||||
grep -q 'MOVI _msg' "$WORK/native-link.s" \
|
||||
|| fail "assembly has no cross-section MOVI _msg"
|
||||
grep -q 'CALLA _native_value' "$WORK/native-link.s" \
|
||||
|| fail "assembly has no CALLA _native_value"
|
||||
|
||||
echo "== inspect the native TI-COFF object"
|
||||
python3 - "$WORK/native-link.o" "$WORK/native.text" <<'PY' || fail "native object is not GSPA/GSPLNK TI-COFF"
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, text_out = sys.argv[1], sys.argv[2]
|
||||
d = open(path, "rb").read()
|
||||
if len(d) < 20:
|
||||
sys.exit(f"{path}: too short for a TI-COFF header")
|
||||
machine, nscns, _time, symptr, nsyms, opthdr, flags = struct.unpack_from(
|
||||
"<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if opthdr != 0:
|
||||
sys.exit(f"{path}: optional-header size {opthdr}, want 0")
|
||||
if flags != 0x0100:
|
||||
sys.exit(f"{path}: file flags {flags:#06x}, want 0x0100")
|
||||
if nscns != 3:
|
||||
sys.exit(f"{path}: {nscns} sections, want 3 (.text/.data/.bss)")
|
||||
|
||||
want_flags = {".text": 0x20, ".data": 0x40, ".bss": 0x80}
|
||||
sections = []
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size, ptr = struct.unpack_from("<II", d, o + 16)
|
||||
relptr, = struct.unpack_from("<I", d, o + 24)
|
||||
nreloc, = struct.unpack_from("<H", d, o + 32)
|
||||
sflags, = struct.unpack_from("<I", d, o + 36)
|
||||
if name not in want_flags:
|
||||
sys.exit(f"{path}: unexpected section {name!r}")
|
||||
if sflags != want_flags[name]:
|
||||
sys.exit(f"{path}: {name} flags {sflags:#06x}, want {want_flags[name]:#06x}")
|
||||
sections.append(dict(index=i + 1, name=name, size=size, ptr=ptr,
|
||||
relptr=relptr, nreloc=nreloc, raw=b""))
|
||||
if name != ".bss":
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: {name} size {size} bits is not whole bytes")
|
||||
sections[-1]["raw"] = d[ptr:ptr + size // 8]
|
||||
if len(sections[-1]["raw"]) != size // 8:
|
||||
sys.exit(f"{path}: {name} raw data runs past EOF")
|
||||
|
||||
by_name = {s["name"]: s for s in sections}
|
||||
if by_name[".text"]["size"] == 0:
|
||||
sys.exit(f"{path}: .text is empty")
|
||||
if by_name[".data"]["size"] == 0:
|
||||
sys.exit(f"{path}: .data is empty")
|
||||
if by_name[".bss"]["size"] == 0:
|
||||
sys.exit(f"{path}: .bss is empty")
|
||||
|
||||
# Symbol records, including long names in the string table.
|
||||
string_base = symptr + nsyms * 18
|
||||
syms = {}
|
||||
sym_class = {}
|
||||
sym_section = {}
|
||||
sym_index = {}
|
||||
i = 0
|
||||
while i < nsyms:
|
||||
o = symptr + i * 18
|
||||
if o + 18 > len(d):
|
||||
sys.exit(f"{path}: symbol {i} past EOF")
|
||||
name = d[o:o + 8]
|
||||
if name[:4] == b"\0\0\0\0":
|
||||
off, = struct.unpack_from("<I", d, o + 4)
|
||||
end = d.find(b"\0", string_base + off)
|
||||
nm = d[string_base + off:end].decode("latin1")
|
||||
else:
|
||||
nm = name.rstrip(b"\0").decode("latin1")
|
||||
value, secno, _typ, cls, naux = struct.unpack_from("<IhHBB", d, o + 8)
|
||||
if cls in (2, 3):
|
||||
syms[nm] = value
|
||||
sym_class[nm] = cls
|
||||
sym_section[nm] = secno
|
||||
sym_index[nm] = i
|
||||
if cls == 3 and naux != 1:
|
||||
sys.exit(f"{path}: section symbol {nm!r} has {naux} aux records, want 1")
|
||||
i += 1 + naux
|
||||
|
||||
if sym_class.get(".text") != 3 or sym_section.get(".text") != 1:
|
||||
sys.exit(f"{path}: missing .text section symbol")
|
||||
if sym_class.get(".data") != 3 or sym_section.get(".data") != 2:
|
||||
sys.exit(f"{path}: missing .data section symbol")
|
||||
if sym_class.get(".bss") != 3 or sym_section.get(".bss") != 3:
|
||||
sys.exit(f"{path}: missing .bss section symbol")
|
||||
for nm, sec in (("_native_value", 1), ("_native_first", 1),
|
||||
("_native_bump", 1), ("_native_combo", 1), ("_native_loop", 1),
|
||||
("_native_call_external", 1), ("_msg", 2),
|
||||
("_native_counter", 3), ("_native_external", 0)):
|
||||
if nm not in syms:
|
||||
sys.exit(f"{path}: missing symbol {nm}")
|
||||
if sym_class[nm] != 2:
|
||||
sys.exit(f"{path}: {nm} class {sym_class[nm]}, want 2 (C_EXT)")
|
||||
if sym_section[nm] != sec:
|
||||
sys.exit(f"{path}: {nm} section {sym_section[nm]}, want {sec}")
|
||||
if syms["_native_value"] != 0:
|
||||
sys.exit(f"{path}: _native_value value {syms['_native_value']}, want 0")
|
||||
if syms["_native_external"] != 0:
|
||||
sys.exit(f"{path}: _native_external value {syms['_native_external']}, want 0")
|
||||
|
||||
# Relocations are 10-byte {bit address, symbol index, type 0x11} records.
|
||||
def relocs(sec):
|
||||
out = []
|
||||
for r in range(sec["nreloc"]):
|
||||
o = sec["relptr"] + r * 10
|
||||
raddr, symidx, rtype = struct.unpack_from("<IIH", d, o)
|
||||
out.append((raddr, symidx, rtype))
|
||||
return out
|
||||
|
||||
text_relocs = relocs(by_name[".text"])
|
||||
data_relocs = relocs(by_name[".data"])
|
||||
if not text_relocs:
|
||||
sys.exit(f"{path}: .text has no relocations")
|
||||
if not data_relocs:
|
||||
sys.exit(f"{path}: .data has no relocations")
|
||||
for raddr, _symidx, rtype in text_relocs + data_relocs:
|
||||
if rtype != 0x11:
|
||||
sys.exit(f"{path}: relocation type {rtype:#06x}, want 0x11 R-RELLONG")
|
||||
if raddr % 8:
|
||||
sys.exit(f"{path}: relocation address {raddr:#x} is not byte-aligned")
|
||||
|
||||
# The cross-section MOVI _msg must use the .data section symbol (record index
|
||||
# 2: .text, .text-aux, .data) and its field must hold _msg's bit offset.
|
||||
data_sym = 2
|
||||
found_data_ref = False
|
||||
for raddr, symidx, _rtype in text_relocs:
|
||||
if symidx == data_sym:
|
||||
field, = struct.unpack_from("<I", by_name[".text"]["raw"], raddr // 8)
|
||||
if field == syms["_msg"]:
|
||||
found_data_ref = True
|
||||
if not found_data_ref:
|
||||
sys.exit(f"{path}: no cross-section .text relocation to _msg")
|
||||
|
||||
# The .bss read/write in native_bump() is a .text -> .bss reference. The .bss
|
||||
# section symbol is record index 4 (.text + aux, .data + aux, .bss).
|
||||
bss_sym = 4
|
||||
bss_addend = 32 # native_counter[1] is 4 bytes into the 8-byte array
|
||||
found_bss_ref = False
|
||||
for raddr, symidx, _rtype in text_relocs:
|
||||
if symidx == bss_sym:
|
||||
field, = struct.unpack_from("<I", by_name[".text"]["raw"], raddr // 8)
|
||||
if field == syms["_native_counter"] + bss_addend:
|
||||
found_bss_ref = True
|
||||
if not found_bss_ref:
|
||||
sys.exit(f"{path}: no cross-section .text relocation to "
|
||||
f"_native_counter+{bss_addend}")
|
||||
|
||||
# A branch reference is a same-section 0xFFFF relocation whose instruction
|
||||
# opcode is JAUC (0xC080) or JAcc (0xC?80). In-range branches are relaxed to
|
||||
# the one-word JR form and need no relocation, so native_far() supplies the
|
||||
# conditional JAcc relocation and the zero-displacement branch supplies the
|
||||
# unconditional one. Requiring both keeps a broken branch heuristic red.
|
||||
text_raw = by_name[".text"]["raw"]
|
||||
def opcode_before(raddr):
|
||||
return struct.unpack_from("<H", text_raw, raddr // 8 - 2)[0]
|
||||
|
||||
branch_relocs = []
|
||||
for raddr, symidx, _rtype in text_relocs:
|
||||
if symidx != 0xFFFF:
|
||||
continue
|
||||
word = opcode_before(raddr)
|
||||
if (word & 0xF0FF) == 0xC080:
|
||||
branch_relocs.append(word)
|
||||
if not branch_relocs:
|
||||
sys.exit(f"{path}: no same-section branch relocation (JAUC/JAcc)")
|
||||
if not any(word != 0xC080 for word in branch_relocs):
|
||||
sys.exit(f"{path}: branch relocations have no conditional JAcc")
|
||||
|
||||
# The undefined native_external must be a section-0 C_EXT and its relocation
|
||||
# must use that symbol-table record, not the 0xFFFF same-section escape.
|
||||
ext_idx = sym_index["_native_external"]
|
||||
if not any(symidx == ext_idx for _raddr, symidx, _rtype in text_relocs):
|
||||
sys.exit(f"{path}: no .text relocation to the undefined _native_external")
|
||||
|
||||
# The .long __str pointer in .data is a same-section reference: symbol index
|
||||
# 0xFFFF with the target's section-relative bit offset in the field.
|
||||
if not any(symidx == 0xFFFF for _raddr, symidx, _rtype in data_relocs):
|
||||
sys.exit(f"{path}: .data has no same-section R-RELLONG (symbol 0xFFFF)")
|
||||
if not any(symidx == 0xFFFF for _raddr, symidx, _rtype in text_relocs):
|
||||
sys.exit(f"{path}: .text has no same-section R-RELLONG (symbol 0xFFFF)")
|
||||
|
||||
# A .bss section record must never carry a relocation; the writer rejects one.
|
||||
if by_name[".bss"]["nreloc"] != 0:
|
||||
sys.exit(f"{path}: .bss has {by_name['.bss']['nreloc']} relocations")
|
||||
|
||||
open(text_out, "wb").write(text_raw)
|
||||
print(f" object: sections=3 symbols={len(syms)} "
|
||||
f"text-relocs={len(text_relocs)} data-relocs={len(data_relocs)} "
|
||||
f"branch-relocs={len(branch_relocs)}")
|
||||
print(f" _native_value={syms['_native_value']} _msg={syms['_msg']} "
|
||||
f"_native_counter+{bss_addend}={syms['_native_counter'] + bss_addend} "
|
||||
f"(.data/.bss bits)")
|
||||
PY
|
||||
|
||||
echo "== extract the GSPA/GSPLNK toolchain"
|
||||
if [ ! -f "$SDK/GSPA.EXE" ] || [ ! -f "$SDK/GSPLNK.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "SDK image not found: $SDK_IMG"
|
||||
mkdir -p "$SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE is not extracted in $SDK"
|
||||
[ -f "$SDK/GSPLNK.EXE" ] || fail "GSPLNK.EXE is not extracted in $SDK"
|
||||
|
||||
DOS_DIR=$WORK/dos
|
||||
rm -rf "$DOS_DIR"
|
||||
mkdir -p "$DOS_DIR"
|
||||
cp "$SDK/GSPA.EXE" "$SDK/GSPLNK.EXE" "$DOS_DIR/"
|
||||
cp "$WORK/native-link.o" "$DOS_DIR/NATIVE.O"
|
||||
sed 's/\r$//' "$DIR/native-entry.asm" | sed 's/$/\r/' > "$DOS_DIR/ENTRY.ASM"
|
||||
sed 's/\r$//' "$DIR/native-link.cmd" | sed 's/$/\r/' > "$DOS_DIR/NATIVE.CMD"
|
||||
|
||||
echo "== assemble ENTRY.ASM and link with GSPLNK 2.00"
|
||||
rm -f "$DOS_DIR/ENTRY.O" "$DOS_DIR/ENTRY.LST" \
|
||||
"$DOS_DIR/NATIVE.OUT" "$DOS_DIR/NATIVE.MAP"
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $DOS_DIR" -c "c:" \
|
||||
-c "gspa ENTRY ENTRY.O ENTRY.LST -l" \
|
||||
-c "gsplnk NATIVE.CMD" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
|
||||
[ -f "$DOS_DIR/ENTRY.LST" ] || fail "GSPA produced no ENTRY.LST"
|
||||
sed 's/\r$//' "$DOS_DIR/ENTRY.LST" > "$WORK/entry.lst"
|
||||
grep -q 'No Errors' "$WORK/entry.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/entry.lst" >&2 || true; fail "GSPA reported errors"; }
|
||||
grep -q 'No Warnings' "$WORK/entry.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$WORK/entry.lst" >&2 || true; fail "GSPA reported warnings"; }
|
||||
[ -f "$DOS_DIR/NATIVE.OUT" ] \
|
||||
|| { tail -30 "$WORK/dosbox.log" >&2; fail "GSPLNK produced no NATIVE.OUT"; }
|
||||
[ -f "$DOS_DIR/NATIVE.MAP" ] || fail "GSPLNK produced no NATIVE.MAP"
|
||||
cp "$DOS_DIR/NATIVE.OUT" "$WORK/native-link.coff"
|
||||
sed 's/\r$//' "$DOS_DIR/NATIVE.MAP" > "$WORK/native-link.map"
|
||||
|
||||
# The linker map has two symbol columns, so accept either position.
|
||||
map_addr() {
|
||||
awk -v want="$1" '
|
||||
{ for (i = 1; i <= NF; i++) if ($i == want) { print $(i - 1); exit } }
|
||||
' "$WORK/native-link.map"
|
||||
}
|
||||
VALUE_ADDR=$(map_addr _native_value)
|
||||
FIRST_ADDR=$(map_addr _native_first)
|
||||
MSG_ADDR=$(map_addr _msg)
|
||||
COUNTER_ADDR=$(map_addr _native_counter)
|
||||
LOOP_ADDR=$(map_addr _native_loop)
|
||||
EXT_ADDR=$(map_addr _native_external)
|
||||
[ -n "$VALUE_ADDR" ] || fail "linker map has no _native_value"
|
||||
[ -n "$FIRST_ADDR" ] || fail "linker map has no _native_first"
|
||||
[ -n "$MSG_ADDR" ] || fail "linker map has no _msg"
|
||||
[ -n "$COUNTER_ADDR" ] || fail "linker map has no _native_counter"
|
||||
[ -n "$LOOP_ADDR" ] || fail "linker map has no _native_loop"
|
||||
[ -n "$EXT_ADDR" ] || fail "linker map has no _native_external"
|
||||
grep -q 'ENTRY POINT SYMBOL: "_native_entry"' "$WORK/native-link.map" \
|
||||
|| fail "linker map has no _native_entry entry point"
|
||||
echo " linked _native_value=$VALUE_ADDR _native_first=$FIRST_ADDR _msg=$MSG_ADDR _native_counter=$COUNTER_ADDR _native_loop=$LOOP_ADDR _native_external=$EXT_ADDR"
|
||||
|
||||
# The linked image must be fully relocated: GSPLNK with -a writes no relocs.
|
||||
python3 - "$WORK/native-link.coff" <<'PY' || fail "linked COFF has relocations"
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
d = open(path, "rb").read()
|
||||
machine, nscns, _time, _symptr, _nsyms, opthdr, flags = struct.unpack_from(
|
||||
"<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if not (flags & 0x0001):
|
||||
sys.exit(f"{path}: linked image is not executable (flags {flags:#06x})")
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
nreloc, = struct.unpack_from("<H", d, o + 32)
|
||||
if nreloc:
|
||||
sys.exit(f"{path}: linked {name} still has {nreloc} relocations")
|
||||
PY
|
||||
|
||||
# Re-extract the linked .text (the object extract above is the unlinked one).
|
||||
# Its linked base is the dis34 base; _native_value is checked by address.
|
||||
TEXT_ADDR=$(python3 - "$WORK/native-link.coff" "$WORK/native-linked.text" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
d = open(path, "rb").read()
|
||||
_nscns, = struct.unpack_from("<H", d, 2)
|
||||
_opthdr, = struct.unpack_from("<H", d, 16)
|
||||
base = 20 + _opthdr
|
||||
for i in range(_nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
if name == ".text":
|
||||
paddr, _vaddr, size, ptr = struct.unpack_from("<IIII", d, o + 8)
|
||||
open(out, "wb").write(d[ptr:ptr + size // 8])
|
||||
print(f"{paddr:08X}")
|
||||
break
|
||||
else:
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
) || fail "could not extract linked .text"
|
||||
|
||||
echo "== disassemble _native_value with dis34"
|
||||
"$DIS34" -b "$TEXT_ADDR" -l -o "$WORK/native-linked.text" \
|
||||
> "$WORK/dis34.txt" 2> "$WORK/dis34.err" \
|
||||
|| { cat "$WORK/dis34.err" >&2; fail "dis34 failed"; }
|
||||
[ -s "$WORK/dis34.txt" ] || fail "dis34 produced no output"
|
||||
python3 - "$WORK/dis34.txt" "$VALUE_ADDR" "$FIRST_ADDR" <<'PY' \
|
||||
|| fail "dis34 did not decode _native_value"
|
||||
import re
|
||||
import sys
|
||||
|
||||
path, value_addr, first_addr = sys.argv[1], int(sys.argv[2], 16), int(
|
||||
sys.argv[3], 16)
|
||||
rows = []
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = re.match(r"^([0-9a-fA-F]+):\s+(.*)$", line.strip())
|
||||
if m:
|
||||
rows.append((int(m.group(1), 16), m.group(2)))
|
||||
if not any(addr == value_addr and text.lower().startswith("setf")
|
||||
for addr, text in rows):
|
||||
sys.exit(f"dis34 has no SETF at _native_value {value_addr:#x}")
|
||||
if not any(value_addr <= addr < first_addr and
|
||||
re.match(r"movi\s+0x2a,\s*a0(\s*;.*)?$", text, re.I)
|
||||
for addr, text in rows):
|
||||
sys.exit(f"dis34 has no MOVI 42 in _native_value "
|
||||
f"[{value_addr:#x}, {first_addr:#x})")
|
||||
print(f" dis34 decoded _native_value at {value_addr:08x} .. {first_addr:08x}")
|
||||
PY
|
||||
|
||||
echo "== run the linked COFF in MAME"
|
||||
cat > "$WORK/native-check.lua" <<'LUA'
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local frames = 0
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 then
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local value = prog:read_u32(0x018A8000)
|
||||
local combo = prog:read_u32(0x018A8020)
|
||||
local bump1 = prog:read_u32(0x018A8040)
|
||||
local bump2 = prog:read_u32(0x018A8060)
|
||||
local loop = prog:read_u32(0x018A8080)
|
||||
local ext = prog:read_u32(0x018A80A0)
|
||||
print(string.format(
|
||||
"NATIVE: value=%d combo=%d bump1=%d bump2=%d loop=%d ext=%d",
|
||||
value, combo, bump1, bump2, loop, ext))
|
||||
if value == 42 and combo == 152 and bump1 == 1 and bump2 == 2 and
|
||||
loop == 10 and ext == 77 then
|
||||
print("NATIVE MAME: PASS")
|
||||
else
|
||||
print("NATIVE MAME: FAIL (want value=42 combo=152 " ..
|
||||
"bump1=1 bump2=2 loop=10 ext=77)")
|
||||
end
|
||||
end
|
||||
end, "native-check")
|
||||
LUA
|
||||
|
||||
rm -rf "$WORK/run/nvram"
|
||||
mkdir -p "$WORK/run/nvram"
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$WORK/native-link.coff" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$WORK/native-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; fail "COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -q 'placed \.data .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .data bytes"
|
||||
grep -q '^NATIVE: value=42 combo=152 bump1=1 bump2=2 loop=10 ext=77$' \
|
||||
"$WORK/mame.log" \
|
||||
|| { grep '^NATIVE:' "$WORK/mame.log" >&2 || true; fail "markers are wrong"; }
|
||||
grep -q '^NATIVE MAME: PASS$' "$WORK/mame.log" \
|
||||
|| fail "MAME marker check failed"
|
||||
|
||||
echo "M5 native-link: PASS"
|
||||
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user