Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9dc8f28488 | ||
|
|
827d9315dd | ||
|
|
e0cf441118 | ||
|
|
8d18ab91b2 | ||
|
|
094d2543f7 | ||
|
|
2fec10b039 | ||
|
|
bc92886312 | ||
|
|
3226a84988 | ||
|
|
5760a35867 | ||
|
|
7aab6a6485 | ||
|
|
15201f31ba | ||
|
|
eb44a1aade | ||
|
|
5379cd4629 | ||
|
|
2fca960398 | ||
|
|
3005647f30 | ||
|
|
85c4a1778a | ||
|
|
8be4a978cc | ||
|
|
12cb023b3c | ||
|
|
ae73e6b054 | ||
|
|
ded91f2054 | ||
|
|
e997b3ff22 | ||
|
|
53f0b3c56b | ||
|
|
b973ccd250 | ||
|
|
1a62878e93 | ||
|
|
f18115314c | ||
|
|
581a264ab3 | ||
|
|
c1d0378212 | ||
|
|
dad0245d5e | ||
|
|
fa90562bb9 | ||
|
|
ea1222001f | ||
|
|
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,367 @@
|
||||
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: M6.** The TI language surface is complete for the M6 scope, with the
|
||||
documented `.data` initializer, sub-byte record-stride and GSP/`printf` limits
|
||||
remaining: `long long`, `float` and `double` arguments/returns/arithmetic,
|
||||
general `va_list` varargs, packed bitfields, aggregates by value and return,
|
||||
the linked 1990 `flib.lib`/`rts.lib` runtime with the `printf`/`sprintf` shim,
|
||||
and the expanded conformance tier. `llc -march=tms34010 -filetype=obj` 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: arguments are pushed
|
||||
on the program stack, scalar results are returned in `A8`, `float`/`double`/
|
||||
`i64`/aggregate results use the caller-allocated hidden slot with `RETS 2`,
|
||||
frames use `A13`/`A14`/`A15`, and functions end in `RETS 2` (`RETS 0` without
|
||||
arguments). M5 added 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 and the first pinned external
|
||||
conformance tier. M6 adds:
|
||||
`float`/`double` soft-float via GSP `flib` calls, `long long` with an inline
|
||||
divide/remainder loop, `va_list`/`va_start`/`va_arg`/`va_copy`, TI packed
|
||||
bitfields, aggregate returns through the hidden slot (explicit `sret` is
|
||||
rejected), the linked `flib`/`rts` runtime, and 79 c-torture / 48 c-testsuite
|
||||
curated tests. Debug info, a native linker, the wider Xlib surface, stderr and
|
||||
the full external suites beyond the curated supported subset are M7.
|
||||
|
||||
> **`-O2` warning (M6).** `scripts/tms-clang` defaults to `-O2`. Until the M7
|
||||
> bit-pointer barrier lands, an `-O2` C `p += n` whose derived pointer is used
|
||||
> (load/store or integer cast) can be over-scaled by 8×: `InstCombine`
|
||||
> canonicalizes a bit-offset `inttoptr(add)` back into a byte GEP and the
|
||||
> post-opt `--scale` multiplies it again. Pass `-O0` for pointer-increment
|
||||
> code; the gates run both levels and the conformance `-O2` subset avoids the
|
||||
> shape. Changing the default is an M7 policy decision.
|
||||
|
||||
Branch `m6` is the current milestone snapshot and the repository default
|
||||
in both repositories. Branch `m5` is the previous snapshot, `m4` the one
|
||||
before that, `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)
|
||||
- M6 plan: [`docs/superpowers/plans/2026-11-13-tms34010-m6-language-runtime-and-floats.md`](docs/superpowers/plans/2026-11-13-tms34010-m6-language-runtime-and-floats.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 `m6`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2/M3/M4/M5/M6 backend. Branch
|
||||
`m6` is the repository default; branch `m5` is the previous snapshot, `m4` is
|
||||
before that, 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
|
||||
snapshot, including the retired M1 harness.
|
||||
(branch `m6`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2/M3/M4/M5/M6 harnesses and the conformance tier.
|
||||
Branch `m6` is the repository default; `m5` is the previous snapshot, `m4` is
|
||||
before that, `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–M6 do not change it.
|
||||
|
||||
## What M3 provides
|
||||
## What M6 provides
|
||||
|
||||
M6 closes the TI C language surface on the M5 all-stack ABI, native TI-COFF
|
||||
path and asm oracle. Full target rules and evidence are in
|
||||
[`build/llvm-clean/TMS34010.md`](build/llvm-clean/TMS34010.md) ("M6 state").
|
||||
|
||||
- **`long long`.** Two 32-bit argument slots and an 8-byte caller-allocated
|
||||
hidden return slot (`RETS 2`, no `A8`). Add/sub use post-RA `ADDC`/`SUBB`;
|
||||
multiply uses the 32-bit `MUL`/`MPYS`/`MPYU` path; shifts use
|
||||
`SHL/SRL/SRA_PARTS`; unsigned/signed divide and remainder use a correct
|
||||
inline 64-iteration restoring loop because `rts.lib` has no 64-bit helper.
|
||||
**i64 objects in memory are little-endian (LSW at the lower address)** per
|
||||
the design spec and the `e` data layout; the **argument/hidden-return stack
|
||||
slot is MSW-first**, a separate M6 ABI choice pinned by the Task 1 probe.
|
||||
Variadic i64 returns, atomic i64 accesses and i64 `.data` initializers are
|
||||
rejected loudly.
|
||||
- **`float`/`double` soft-float.** GSP-format values and `flib.lib` stack
|
||||
entries: arithmetic pushes its result on `A14`, compares return in `A8`,
|
||||
conversions use `A8`/`A14`; every call saves/restores `A14` and `A8`. `f32`
|
||||
lives in `ARegs`, `f64` in an `ARegsPair` with pair spills. IEEE IR
|
||||
constants are converted to GSP words (exponent+1, half-up), with a GSP
|
||||
constant pool and the `TMS34010LowerFloatConstants` pass for
|
||||
store/return/argument literals. GSP has no NaN, denormals or signed zero:
|
||||
`-0.0` is canonicalised to `+0`, and NaN/denormal/overflow literals are
|
||||
rejected loudly. Only i32 float↔int conversions and no libm
|
||||
(`fsqrt`/`fma`/`frem`) are available.
|
||||
- **Hidden returns.** `float`, `double`, `i64` and aggregates share one
|
||||
caller-allocated slot rule: `ADDI 32`/`64`/`alignTo(size,2)` before saving
|
||||
STK, the callee writes at `saved_STK-size`, restores A14 and ends `RETS 2`
|
||||
(even with no arguments). Scalar `A8` returns are unchanged.
|
||||
- **General varargs.** `va_list` is a 32-bit `char *`; the caller saves STK
|
||||
for every variadic call, `va_start = FP-(fixed_argument_bytes+4)*8`, and
|
||||
`va_arg` walks downward with per-type word orders. `va_copy`/`va_end` and
|
||||
an `int f(...)` definition work; a variadic `i64`/float hidden return and a
|
||||
`va_arg` of a struct are rejected. The M4 contiguous `&last_fixed` pattern
|
||||
still works.
|
||||
- **Packed bitfields.** LSB-first, no padding between adjacent fields, an
|
||||
unnamed/leading `:0` is ignored, and fields may cross 32 bits. `SEXT1`
|
||||
handles `int s:1`; `TMS34010ExpandNarrowMem` splits i24/i40/i48/i56
|
||||
containers in IR so the byte offsets stay bit addresses. A 31-bit field at
|
||||
bit 33 and a 57-bit field use the little-endian i64 memory split. Remaining
|
||||
divergence: TI advances nested/array objects by the bit content (36 bits for
|
||||
`struct s`) while Clang uses the byte-rounded `sizeof` (5 bytes); field
|
||||
offsets, `sizeof` and standalone 16-bit-rounded allocation agree.
|
||||
- **Aggregates by value and return.** Clang's target ABI classifies a record
|
||||
return as direct, so the IR has no `sret` parameter; the callee writes
|
||||
flattened leaves directly at their object offsets in the rounded hidden slot
|
||||
and the caller copies them out. Struct/union arguments keep the M5 `byval`
|
||||
form. An explicit `sret` pointer is rejected with a clear diagnostic; a
|
||||
packed bitfield struct returned by value is covered end-to-end in the
|
||||
aggregate gate.
|
||||
`TMS34010ExpandAggMem` splits aggregate load/stores before `LowerI64` and
|
||||
`ExpandNarrowMem` so no byte offset is added to a bit address.
|
||||
- **Runtime and formats.** The 1990 SDK `flib.lib` (GSP soft-float) and
|
||||
`rts.lib` are linked with the 1987 GSPA/GSPLNK tools (the `$` symbols need
|
||||
no alias; the 1990 tools are OS/2-only). The shared conformance shim
|
||||
implements `printf`/`sprintf` with `%d %i %u %o %x %X %p %c %s %%`,
|
||||
`h`/`hh`/`l`/`ll`, `%ld`/`%lu`/`%lld`/`%llu`, `%f`, width/precision
|
||||
(including `*`) and `%s` precision. `%c` honours width and `-` (space
|
||||
padding; `0` is not meaningful and is ignored). `%f` precision is capped at
|
||||
6 and the integer part at `2^31-128`; `sprintf` has a 256-byte cap and
|
||||
returns the untruncated length; there is no `snprintf`. `%e/%g/%a/%F`, `%n`,
|
||||
positional `$`, `%j` and wide formats remain unsupported (no libm, 32-bit
|
||||
shim reads); `%z`/`%t` work. A linked-runtime gate checks 587 output bytes
|
||||
exactly and the `flib` entries plus the rts-backed `_isascii` in the GSPLNK
|
||||
map at `-O0` and `-O2`.
|
||||
- **Conformance.** The pins are GCC 16.2.0 (SHA-256
|
||||
`e6738e29597f733270731aa90600f37ffdc045079dfc27ec7e8192cc81085c3e`) and
|
||||
c-testsuite `5c7275656d751de0e68b2d340a95b5681858ed07`. The curated
|
||||
c-torture list is 79 tests (59 M5 + 20 M6). The M5 gate passes **79/79 at
|
||||
`-O0` and `-O2`**; the M6 wrapper runs all 79 at `-O0` and the committed
|
||||
**20-test bounded `-O2` subset**. c-testsuite is **48 pass / 172 skip /
|
||||
220** with exact stdout;
|
||||
every skip has a reason and there are no crashes. Generic is 197 files with
|
||||
146 pass / 51 unsupported / 0 crash.
|
||||
|
||||
Known M6 limitations: the general `-O2` `p += n` over-scale (an `InstCombine`
|
||||
canonicalization; M7 owns the bit-pointer barrier), the sub-byte record stride
|
||||
above, the GSP value/`%f` caps, the explicit-`sret` rejection, the M2 `.data`
|
||||
aggregate/bitfield-global initializer gap, and no native linker/`.cinit`.
|
||||
|
||||
**M6/M7 boundary.** M7 owns debug info, a native linker (including `.cinit`
|
||||
and public long names), the wider Xlib surface, real-hardware validation
|
||||
(M6 acceptance is MAME plus the existing dwt loader), stderr capture, the full
|
||||
external suites beyond the curated supported subset, the `-O2` bit-pointer
|
||||
semantic barrier, the sub-byte array/nested-record stride (TI advances by the
|
||||
bit content, e.g. 36 bits; Clang uses the byte-rounded `sizeof`), the `.data`
|
||||
aggregate-initializer extension and performance work (for example an i64
|
||||
divide fast path).
|
||||
|
||||
## What M5 provides
|
||||
|
||||
M5 added the native object path and the first external conformance tier while
|
||||
keeping the M4 assembly path as the oracle; M6 builds the language/runtime
|
||||
surface on top. The M5 state below is the baseline.
|
||||
|
||||
- **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-clang` scales GEPs
|
||||
to bit offsets **before** `opt` (the M0/M2 bit-address pointer model, so
|
||||
`(int)(p + n) - (int)p` stays `8n`) and runs `tms-bitaddr --scale` **again**
|
||||
on the optimized IR, so the byte-indexed GEPs that `opt` introduces are
|
||||
converted from byte to bit units: the M4 switch and termtris lookup tables, and the
|
||||
`.fca.N.gep` loads that SROA creates when a returned aggregate is taken apart
|
||||
(`+4` bytes must become `+32` bits). Known M6 limitation: `InstCombine` can
|
||||
canonicalize an already-bit `inttoptr(add(ptrtoint,...))` back into a GEP, and
|
||||
the post-opt scale then treats that bit offset as bytes (an 8x over-scale for
|
||||
an `-O2` C `p += n` whose derived pointer is used (load/store or integer
|
||||
cast)). The shared
|
||||
conformance shim's `memmove` avoids the shape with constant end-pointer steps;
|
||||
a proper fix needs a target bit-pointer semantic barrier (M7). `-replexitval=never`
|
||||
remains a documented `tms-clang` TMS34010 policy for the i33 IndVarSimplify
|
||||
closed-form shape even though i64 lowering exists: llc 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 at the M6 head are
|
||||
LLVM `CodeGen/Generic` (197 `.ll`: 146 pass / 51 unsupported / 0 crash, plus
|
||||
a 24-file curated allowlist), GCC c-torture `execute` (79/79 at `-O0` and
|
||||
`-O2`; M6 Task 8 expanded the shared list from 59 to 79 and the corpus
|
||||
classifier reports 1,636 supported / 56 skipped from 1,692 tests), and
|
||||
c-testsuite `single-exec` (48 pass / 172 skip / 220, with
|
||||
exact `.c.expected` output). The shim provides `printf`/`sprintf` with a
|
||||
real `va_list` walk and `%ld`/`%lld`/`%f` plus width/precision,
|
||||
`putchar`/`puts`, `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, the 79-test c-torture gate about 22–25 minutes and
|
||||
c-testsuite about 5–7 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 removed that flag for the switch-table GEP, and M6 Task 6
|
||||
generalizes it: `tms-clang` keeps the pre-opt `--scale` (bit-addressed pointer
|
||||
casts) and scales every late byte GEP after `opt`, which also fixes
|
||||
aggregate-split `.fca.N.gep` loads. The known `p += n` over-scale from
|
||||
`InstCombine` canonicalizing a bit-offset `inttoptr` back into a GEP is
|
||||
documented above and worked around in the conformance shim's `memmove`; M7
|
||||
owns the proper fix. All 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 +386,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 +407,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 +419,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,26 +444,197 @@ 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–M6) |
|
||||
|---|---|---|
|
||||
| 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)`, … |
|
||||
| Return value | `A0` | `A8` |
|
||||
| Return value | `A0` | `A8` for scalars; `float`/`double`/`i64`/aggregates use a caller-allocated hidden slot |
|
||||
| Frame | none; leaf functions only | `A13` FP, `A14` STK, `A15` system stack |
|
||||
| Locals | none | positive FP offsets |
|
||||
| Return instruction | `RETS 0` | `RETS 2` with arguments, `RETS 0` without |
|
||||
| Return instruction | `RETS 0` | `RETS 2` with arguments or a hidden return, `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 M6 gates
|
||||
|
||||
These are the documented commands on branch `m6`; 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: 103 passed
|
||||
# (34 m2-* + 8 m3-* + 18 m4-* + 15 m5-* + 28 m6-*)
|
||||
build/llvm-clean-build/bin/llvm-lit -v \
|
||||
build/llvm-clean/llvm/test/CodeGen/TMS34010 --filter='(m2|m3|m4|m5|m6)-'
|
||||
|
||||
# 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. M6 language/runtime gates (MAME; run serially)
|
||||
scripts/tests/m6/spike.sh # hand-written flib/rts ABI probe
|
||||
scripts/tests/m6/i64.sh # long long ABI/arithmetic/memory
|
||||
scripts/tests/m6/float.sh # float/double soft-float, -O0 and -O2
|
||||
scripts/tests/m6/varargs.sh # va_list/va_start/va_arg/va_copy
|
||||
scripts/tests/m6/bitfield.sh # TI packed layout and lowering
|
||||
scripts/tests/m6/aggregate.sh # aggregates by value and return
|
||||
scripts/tests/m6/runtime.sh # linked flib/rts + printf/sprintf, both -O levels
|
||||
# i64/varargs/bitfield default to -O0; run the -O2 level with
|
||||
# I64_OPT=-O2 / VARARGS_OPT=-O2 / BITFIELD_OPT=-O2.
|
||||
|
||||
# 5. 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
|
||||
|
||||
# 6. 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
|
||||
|
||||
# 7. 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
|
||||
|
||||
# 8. The conformance tiers
|
||||
scripts/tests/m5/generic.sh # Generic allowlist + no-crash sweep
|
||||
scripts/tests/m5/c-torture.sh # 79 tests at -O0 and -O2
|
||||
scripts/tests/m5/c-testsuite.sh # 48 output tests + 172 reported skips
|
||||
scripts/tests/m6/c-torture.sh # 79 at -O0 + the 20-test bounded -O2 subset
|
||||
scripts/tests/m6/c-testsuite.sh # 48 exact-output tests at -O0
|
||||
|
||||
# 9. 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).
|
||||
`scripts/tests/m6/runtime.sh` extracts the 1990 SDK `flib.lib`/`rts.lib` into
|
||||
`build/m6-sdk` on first use (the SDK is a prerequisite; nothing is vendored).
|
||||
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`/`m6`)
|
||||
|
||||
These are the documented commands on branch `m4`; all must pass. On branches
|
||||
`m5`/`m6`, use the M6 list above (it includes `llvm-mc` and the M5/M6 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 +715,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 +818,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,53 +847,100 @@ 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 closed the M4 gaps for the native object path, `JR`/relaxation,
|
||||
`MMTM`/`MMFM`, narrow returns, `byval` and the switch-table policy. It
|
||||
deliberately stopped before:
|
||||
|
||||
- **Floating point and `long long`:** no float/double or `i64` arguments,
|
||||
returns, arithmetic or branches; the i33/`-replexitval` policy stayed until
|
||||
the i64 lowering landed. M6 closes this.
|
||||
- **General varargs:** no `va_list`, `va_start` or `va_arg`; only the
|
||||
contiguous `&last_fixed` pattern used by termtris `sprintf`. M5 used that
|
||||
same pattern inside the conformance shim; true `va_list` tests were skipped.
|
||||
M6 closes this.
|
||||
- **Bitfields and aggregates by value:** bitfields, `sret`, aggregate returns
|
||||
and general aggregate arguments were unsupported; `byval` arguments and
|
||||
struct fields through pointers were supported. M6 adds packed bitfields and
|
||||
aggregate returns; an explicit `sret` pointer remains rejected because the
|
||||
TI ABI has no such argument.
|
||||
- **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. These remain M7.
|
||||
- **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 and the full suites
|
||||
remain M7.
|
||||
- **Deeper libc/runtime coverage:** M5's shim is freestanding and does not add
|
||||
`RTS.LIB` entries. M6 links the 1990 `flib.lib`/`rts.lib` and expands
|
||||
`printf`/`sprintf`; a broader libc surface remains M7.
|
||||
- **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). This is
|
||||
unchanged in M6; a native linker that could own `.cinit`/public names is
|
||||
M7.
|
||||
|
||||
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). The 1990 SDK `flib.lib`/`rts.lib` used by the M6 runtime
|
||||
gates are likewise test/runtime inputs, extracted from the SDK into
|
||||
`build/m6-sdk`; they are not vendored or distributed.
|
||||
|
||||
## Repository layout
|
||||
|
||||
```text
|
||||
build/llvm-clean/ compiler fork checkout used for M2/M3 (ignored)
|
||||
build/llvm-clean/ compiler fork checkout used for M2–M6 (ignored)
|
||||
build/llvm-clean-build/ its Ninja build tree (ignored)
|
||||
build/m6-sdk/ extracted 1990 flib.lib/rts.lib (ignored, not vendored)
|
||||
build/llvm-src/ M0 working fork (ignored)
|
||||
patches/llvm/ frozen M0 patch series against llvmorg-23.1.5
|
||||
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/m6/ M6 harness: ABI spike asm, i64/float/varargs/bitfield/
|
||||
aggregate/runtime drivers, GSP link command files, checkers
|
||||
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/tests/m6/ M6 gates (spike/i64/float/varargs/bitfield/aggregate/runtime
|
||||
and the c-torture/c-testsuite wrappers)
|
||||
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 +955,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–M6
|
||||
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 +980,14 @@ Xlib call sequence, `as34`, `dis34`, SDKs, manuals). It is not vendored:
|
||||
|
||||
## Build the compiler
|
||||
|
||||
### Compiler fork (M3, the normal path)
|
||||
### Compiler fork (M6, 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 `m6`. 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=m6 ./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 +995,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=m6 ./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 +1012,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–M6 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–M6.
|
||||
|
||||
## Build the M0 support tools
|
||||
|
||||
The M2/M3 pipeline uses `tms-bitaddr` and `tms-clang`:
|
||||
The M2–M6 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–M6):
|
||||
|
||||
```sh
|
||||
TMS_CLANG=$PWD/build/llvm-clean-build/bin/clang \
|
||||
@@ -487,33 +1038,119 @@ 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 \
|
||||
TMS_OPT=$PWD/build/llvm-clean-build/bin/opt \
|
||||
TMS_BITADDR=$PWD/tools/tms-bitaddr/tms-bitaddr \
|
||||
scripts/tms-clang -O2 -o /tmp/add2.ll scripts/tests/m2/diff/ti-add2.c
|
||||
# The driver defaults to the fork build (build/llvm-clean-build/bin); pass
|
||||
# TMS_CLANG/TMS_OPT/TMS_BITADDR to override.
|
||||
scripts/tms-clang -O2 -o /tmp/add2.ll scripts/tests/m2/diff/ti-add2.c
|
||||
|
||||
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
|
||||
in `A8`, and ends in `RETS 2`. Always produce the IR with `scripts/tms-clang`
|
||||
(or run `tms-bitaddr --scale`) before `llc`: raw clang IR carries byte GEP
|
||||
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
|
||||
addresses would be 8× too small. Run `llc -O0` on the bit-addressed IR that
|
||||
`tms-clang` already optimized and scaled. `tms-clang` scales once **before**
|
||||
`opt` (so integer pointer casts keep the bit-address model), then runs
|
||||
`--scale` again on the optimized IR: after the first `--scale` every
|
||||
pre-existing GEP is gone, so any GEP `opt` created indexes bytes (SROA's
|
||||
aggregate-split loads, switch tables) and must be shifted by 3. Known M6
|
||||
limitation: `InstCombine` can canonicalize a bit-offset
|
||||
`inttoptr(add(ptrtoint,...))` back into a GEP, and the post-opt `--scale` then
|
||||
multiplies that already-bit index by 8 again; an `-O2` C `p += n` whose
|
||||
derived pointer is used (load/store or integer cast) can be over-scaled. The conformance shim's
|
||||
`memmove` avoids the shape until a target bit-pointer semantic barrier lands
|
||||
(M7). `tms-bitaddr --normalize` remains for input
|
||||
that is already bit-addressed; it 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.
|
||||
|
||||
## M6 ABI foundation (Task 1)
|
||||
|
||||
The `m6` branch keeps the M5 all-stack TI ABI. Task 1 fixed and proved the
|
||||
language-runtime contract that tasks 2/3/6 consume (the lowering itself is in
|
||||
the M6 sections above):
|
||||
|
||||
- **1990 SDK libraries.** `flib.lib` is the GSP-format floating-point library;
|
||||
`flibc.lib`/`flibi.lib` are identified as the 34082/IEEE variants from
|
||||
member-code inspection (not from running the OS/2-only 1990 compiler) and
|
||||
are not the M6 link input. `rts.lib` is the C runtime and has no 64-bit
|
||||
helper (`_div`/`_ldiv` are the 32-bit wrappers); i64 multiply/divide use
|
||||
target sequences.
|
||||
- **Tools and symbols.** The 1990 r5.01 tools are OS/2 1.x NE binaries and do
|
||||
not run under DOSBox; the 1987 GSPA 2.00/GSPLNK 2.00 tools link the 1990
|
||||
TI-COFF libraries unchanged. The `$` symbols (`FS$ADD`, `FD$ADD`, ...) need
|
||||
no alias. The exact link line is `M6.OBJ` + `-l flib.lib` + `-l rts.lib`
|
||||
with `-e _start` (`scripts/m6/link.cmd`); the symbol snapshot is
|
||||
`scripts/m6/flib-symbols.txt`.
|
||||
- **`flib` result conventions.** There are three, not one:
|
||||
- arithmetic (`FS$ADD`/`SUB`/`MUL`/`DIV`/`NEG`/`INC`/`DEC` and `FD$...`)
|
||||
pushes its result on A14;
|
||||
- compares (`FS$EQ`/`NE`/`LT`/`LE`/`GT`/`GE` and `FD$...`) pop both
|
||||
operands and return the boolean in **A8**, with nothing pushed;
|
||||
- conversions use **A8** for the integer side: `FD$FTOI`/`FTOU`/
|
||||
`DTOI`/`DTOU` pop the float/double from A14 and return the integer in
|
||||
A8; `FD$ITOF`/`UTOF`/`ITOD`/`UTOD` take the integer in A8 and push one
|
||||
float or two double words on A14; `FD$FTOD`/`FD$DTOF` pop and push.
|
||||
`flib` ends in `RETS` (not `RETS 2`), so the caller pops any pushed result
|
||||
and then restores A14 from the old-STK word it saved on the system stack.
|
||||
`FS$SUB_R`/`FD$SUB_R` (and the `DIV_R` pair) are for the reversed operand
|
||||
order.
|
||||
- **GSP format.** `float` is one 32-bit word; `double` is two GSP words with
|
||||
the **least-significant word at the lower address**. 1.5 is `40600000h`
|
||||
(float) and `00000000h`/`400C0000h` (double LSW/MSW); 4.0 is `41400000h`
|
||||
and `00000000h`/`40280000h`. This is not IEEE; do not mix `flib.lib` with
|
||||
IEEE constants. The compiler converts IR IEEE bits to GSP words as described
|
||||
in the M6 float section.
|
||||
- **Hidden return.** A `float`/`double`/`i64`/aggregate return is written by
|
||||
the callee into a caller-allocated slot immediately below the STK value the
|
||||
caller saved: float 32 bits, double/i64 64 bits, aggregate rounded to 16
|
||||
bits. The caller does `ADDI 32/64,STK`, saves STK, pushes the arguments,
|
||||
and `CALLA`; the callee writes at `saved_STK-size`, restores A14 and
|
||||
`RETS 2`. A hidden-return call always saves STK, so it uses `RETS 2` even
|
||||
with no explicit arguments. The one-slot `float` argument rule is pinned by
|
||||
the M6 `float.sh` gate (the 1987 K&R oracle promotes float parameters to
|
||||
double and does not independently pin it).
|
||||
- **i64 word order.** `long long` arguments occupy two 32-bit slots, and the
|
||||
**argument and hidden-return stack slot is MSW-first** (the high word at
|
||||
the lower address). A `long long` **object in memory** is the opposite:
|
||||
little-endian, LSW at the lower address, per design spec §4.1 and the `e`
|
||||
data layout. The two rules are separate: the stack slot is the M6 ABI
|
||||
choice pinned by the probe, while memory matches the optimizer/Clang
|
||||
layout (Task 5 corrected the original "big-endian memory" ruling). The
|
||||
Task 1/2 wording that called i64 memory big-endian is superseded.
|
||||
- **Gate.** `scripts/tests/m6/spike.sh` assembles the hand-written
|
||||
`spike-entry.asm`/`spike-probe.asm`, links `flib.lib`/`rts.lib`, loads the
|
||||
COFF with the existing dwt loader and runs it in MAME. It checks 13 markers
|
||||
covering float/double arithmetic, double and float hidden returns, the i64
|
||||
two-slot return, `FS$SUB` push order, `FS$EQ` in A8,
|
||||
`FD$FTOI`/`FD$ITOF`, and a post-return marker after `_m6_probe` returns.
|
||||
It passes with
|
||||
`M6: fs_add=41400000 fd_add=40280000/00000000 dadd=40280000/00000000
|
||||
i64=2345678A/00000001 fsub=40400000 feq=1 ftoi=1 itof=40400000
|
||||
fadd=41400000 ret=5A5A5A5A`, loader status 0 and `.text` placed with 0
|
||||
differing bytes. The full rule is in `build/llvm-clean/TMS34010.md`,
|
||||
"M6 state".
|
||||
|
||||
## 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.
|
||||
M7 owns debug info, a native linker (including `.cinit` and public long
|
||||
names), the wider Xlib surface, real-hardware validation (M6 acceptance is
|
||||
MAME plus the existing dwt loader), stderr capture, the full external suites
|
||||
beyond the curated supported subset, the `-O2` bit-pointer semantic barrier,
|
||||
the sub-byte array/nested-record stride (TI's bit-content advance vs Clang's
|
||||
byte-rounded `sizeof`), the M2 `.data` aggregate/bitfield-global initializer
|
||||
extension, and performance work (for example an i64 divide fast path). 2ine
|
||||
r5.01 is a later speed-up for the GSPA/GSPLNK step. The compiler fork is
|
||||
canonical for target code; this project holds the plan, harness, pins and
|
||||
integration tests.
|
||||
@@ -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.
|
||||
@@ -0,0 +1,447 @@
|
||||
# TMS34010 M6 — Floats, 64-bit Integers, General Varargs, Bitfields, and Aggregates 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:** The compiler supports the TI C language surface that M5 deferred — `float`/`double`/`long double`, `long long`/i64, general `va_list`/`va_start`/`va_arg`, bitfields, and structs/unions by value with `sret`/aggregate returns — using the validated `flib.lib`/`rts.lib` runtime, with the conformance tier expanded to the newly supported features.
|
||||
|
||||
**Architecture:** M6 keeps the M5 native TI-COFF/GSPLNK path, the all-stack TI ABI, and the M5 asm oracle. The 64-bit and floating-point ABI follows the TI C guide: arguments are pushed on the program stack and widened to 32 bits; a `float`/`double`/`long long` return is written into a caller-allocated stack slot (the same hidden-return rule as struct returns); `long long` occupies two 32-bit slots. Float/double arithmetic and conversions lower to `FS$*`/`FD$*` calls in the TI `flib.lib`; the `rts.lib` supplies the remaining runtime. Bitfields use Clang's packed record layout (the target already sets `PackStruct=1`); aggregates use the M5 `byval`/hidden-return machinery. The conformance shim/classifier gain general varargs and drop the M6 feature skips.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m6`), C++17, CMake/Ninja, `llc`, `llvm-mc`, TI COFF, GSPA/GSPLNK 2.00 under DOSBox, the TI `flib.lib`/`flibc.lib`/`rts.lib` (1990 SDK), the dwt COFF loader, MAME, `dis34`, `llvm-lit`/FileCheck, the 1987 TI compiler as a differential oracle, pinned GCC 16.2.0 c-torture and c-testsuite.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (§4.2, §7.4–§7.5, §8; M6); the M5 plan `docs/superpowers/plans/2026-11-12-tms34010-m5-native-object-path-and-conformance.md` is the handoff.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Compiler work happens in **`llvm-tms34010`**, branch `m6`, created from `m5` at `f9c593ddd5bca0dc30cc2273c05a995100e576f3`. Project work happens in **`tms-c-compiler`**, branch `m6`, created from `m5` at `5ee3a6592c7d09e8c58635490077df0ef2d7fc99` plus the M6 plan commit. Do not merge into `m0`–`m5`; do not change the default (`m5`).
|
||||
- Use upstream LLVM `llvmorg-23.1.5`; keep the fork minimal. Use the existing `build/llvm-clean` and `build/llvm-clean-build`.
|
||||
- The M2–M5 TI ABI is unchanged: A8 scalar return, A13 FP, A14 STK, A15 system stack, `RETS 2/0`, `FS1 = 32`, `FS0 = 16` with the field-extension bit set (`SETF 16,1,0`).
|
||||
- **Stack ABI:** all arguments are pushed on the program stack and widened to 32 bits; structs by value are rounded to 16 bits. `float`/`double`/`long long` and aggregate returns use a **caller-allocated program-stack slot** (the callee copies the result there), so the call site uses the old-STK save and `RETS 2`.
|
||||
- **i64 ABI (to be confirmed by Task 1):** `long long` arguments occupy two 32-bit stack slots (low word first at the lower address, matching the TI endianness); the return is an 8-byte caller-allocated slot. If the 1990 C guide or `rts.lib` evidence shows a different TI 64-bit convention, Task 1 records the ruling and adjusts these rules before Tasks 2/6 use them.
|
||||
- **Float/double:** arguments are 32-bit-widened stack slots (`float` one, `double` two); the return is the caller-allocated stack slot; arithmetic/compare/conversion lowers to the validated `FS$*`/`FD$*` entries in `flib.lib` (or a target sequence for a missing entry). Use the exact TI library names; do not invent libcalls.
|
||||
- **General varargs:** the M4 contiguous `&last_fixed` pattern remains supported; M6 adds a real `va_list`/`va_start`/`va_arg` for the TI ABI. External variadic definitions (`sprintf`/`printf`) are supported at `-O2`; the M5 static-variadic restriction is lifted once the optimizer no longer drops `...`.
|
||||
- **Bitfields:** the TI packed structure rules (fully packed; only the first object in an array is 16-bit aligned); Clang's target already sets `PackStruct=1`; verify/adjust the target record layout against the M4 `_Static_assert` offsets and the TI C guide.
|
||||
- **Aggregates:** structs/unions by value use the 16-bit-rounded stack slots and the hidden return slot; `sret`/`byval`/aggregate returns are M6 (the M5 `byval` slot rule is 16-bit). Keep the M5 `alloca`/memcpy/memmove behavior.
|
||||
- **Native object path:** TI COFF linked by GSPLNK; the existing loader. The asm path (`-filetype=asm` → GSPA/GSPLNK) remains the oracle; do not delete it.
|
||||
- Every M2–M5 gate stays green; add `m6-*` lit tests and `scripts/tests/m6/*`. The M5 conformance harness/classifier/lists are the base; the M6 features remove their skips.
|
||||
- **M6 non-goals (M7):** debug info, a native linker, the wider Xlib surface, real-hardware-only validation, and the full GCC/LLVM suites beyond the supported subset. Document the boundary. Ruling: the spec's M5 re-scope lists debug info as M6, but this plan splits it into M7 as an independent object/debug subsystem; the M6 language/runtime surface is already a complete milestone. Cost if wrong: debug info arrives one milestone later.
|
||||
- No force-push, no merge into `m0`–`m5`, no default change. Push `m6` after the final gate run and review.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Float/double/i64 ABI.** A wrong stack/hidden-return layout corrupts every call and return. The tests are Task 1's ABI probe, Task 2's two-slot i64 call/return, and Task 3's float/double call/return in MAME.
|
||||
2. **Bitfield packed layout.** A wrong bitfield offset or signedness silently reads/writes the wrong bits. The tests are Task 5's TI-offset static asserts and MAME bitfield checks.
|
||||
3. **General varargs.** A wrong `va_list`/`va_arg` walk corrupts `printf`/`sprintf` output. The tests are Task 4's multi-format output and the expanded c-torture/c-testsuite output.
|
||||
4. **Aggregates/sret.** A wrong hidden-return pointer or copy size corrupts struct returns. The tests are Task 6's by-value/sret MAME cases.
|
||||
5. **Soft-float libcalls/constants.** A wrong `FS$`/`FD$` name, argument order, or constant pool entry produces wrong values. The tests are Task 3's `fadd`/`fmul`/`fcmp`/conversion MAME cases and Task 7's runtime.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: M6 branches, ABI rules, and the soft-float/i64 probe
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/m6/spike-probe.asm` (hand-written `FS$ADD`/`FD$ADD` and i64 stack probes), `scripts/m6/spike-entry.asm`, `scripts/m6/spike-check.lua`, `scripts/tests/m6/spike.sh`
|
||||
- Create: `scripts/m6/flib-extract.sh` (or the equivalent extraction into `build/m6-sdk`)
|
||||
- Modify: `build/llvm-clean/TMS34010.md` (the M6 ABI note), `README.md` (the M6 section)
|
||||
- Test: `scripts/tests/m6/spike.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M5 native TI-COFF/GSPLNK harness, the 1990 SDK `flib.lib`/`rts.lib`, the TI C guide.
|
||||
- Produces: a written/committed ABI rule for i64/float/double args and hidden returns; a linked `flib.lib` probe proving the `FS$`/`FD$` ABI; the exact library symbol list and link line.
|
||||
|
||||
- [ ] **Step 1: Write the failing ABI probe**
|
||||
|
||||
`spike-probe.asm` pushes the `FS$ADD` float operands (1.5, 2.5) and the i64 two-slot operands on A14, calls the library entries, and stores the results at the M4 markers; `spike-entry.asm` sets FS0/FS1, A14/A13 and calls the probe. The C target does not support float/i64 yet (Tasks 2/3), so this probe is hand-written asm, not a C float call. `scripts/tests/m6/spike.sh` assembles/links with the 1990 `flib.lib`/`rts.lib` and runs the COFF in MAME. The first run must fail because the float/i64 ABI and the `flib` link are not wired.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m6/spike.sh`
|
||||
Expected: a link/ABI failure (missing `FS$ADD`/`FD$ADD`, wrong hidden-return slot, or the `$` symbol rejected by GSPA).
|
||||
|
||||
- [ ] **Step 3: Extract and validate the library/ABI**
|
||||
|
||||
`flib-extract.sh` extracts `flib.lib`/`flibc.lib`/`rts.lib` from the 1990 SDK into `build/m6-sdk` and records the exact symbols (`FS$ADD`, `FS$SUB`, `FS$MUL`, `FS$DIV`, `FS$NEG`, `FS$EQ`…, `FD$ADD`, …, the conversion entries) and the `flib` stack ABI (operands on A14, result pushed); verify the `$` symbol handling with GSPA/GSPLNK and record the link line. Confirm the i64 two-slot/hidden-return and float/double hidden-return rules from the C guide/`flib` source.
|
||||
|
||||
- [ ] **Step 4: Write the ABI note and run the probe green**
|
||||
|
||||
Add the i64/float/double ABI rule to `TMS34010.md`/README (the exact stack order, hidden-return slot, `RETS 2`, library names). Run:
|
||||
|
||||
```sh
|
||||
scripts/tests/m6/spike.sh
|
||||
```
|
||||
|
||||
Expected: the `FS$ADD` result (e.g. 1.5+2.5 == 4.0) and the i64 sum are correct in MAME; the link line and symbol list are recorded.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "tms34010: M6 64-bit/float ABI notes"
|
||||
git add scripts/m6 scripts/tests/m6/spike.sh README.md
|
||||
git commit -m "tests: M6 float/i64 ABI probe"
|
||||
```
|
||||
|
||||
### Task 2: `long long` / i64 arguments, returns, and arithmetic
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010ISelLowering.cpp/.h`, `TMS34010CallingConv.td`, `TMS34010InstrInfo.td`, `TMS34010FrameLowering.cpp`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m6-i64.ll`, `scripts/tests/m6/i64.sh`
|
||||
- Reuse: the M5 `byval`/hidden-return stack machinery.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1's i64 ABI rule; the M5 stack/frame.
|
||||
- Produces: i64 formal/call arguments as two 32-bit slots; an 8-byte caller-allocated return slot; add/sub/and/or/xor/shift/compare and mul/div/rem (sequences or `flib`/`rts` helpers) with correct endianness; `RETS 2`.
|
||||
|
||||
- [ ] **Step 1: Write the failing i64 test**
|
||||
|
||||
`m6-i64.ll` defines `long long addll(long long, long long)`, `subll`, `mull`, `divll`, `remll`, shifts, and compares; checks the two-slot argument/return shape and the library/sequence. `i64.sh` runs `addll(0x12345678, 0x9ABCDEF0)`, `mull`, `divll`, `remll`, and signed shifts in MAME.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m6-i64.ll`
|
||||
Expected: the M5 `only i32/pointer returns`/argument rejection.
|
||||
|
||||
- [ ] **Step 3: Implement i64**
|
||||
|
||||
Extend `CanLowerReturn`/`LowerReturn`/`LowerFormalArguments`/`LowerCall` for i64 with the Task 1 ABI (two slots, hidden 8-byte return, `RETS 2`). Implement the i64 arithmetic with the 32-bit halves (`ADD`/`ADDC`/`SUBB`, shifts, compares) and the validated helpers/sequences for mul/div/rem. Keep the endianness fixed and documented.
|
||||
|
||||
- [ ] **Step 4: Run the i64 gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v .../m6-i64.ll
|
||||
scripts/tests/m6/i64.sh
|
||||
scripts/tests/m2/run.sh
|
||||
scripts/tests/m3/run.sh
|
||||
scripts/tests/m4/run.sh
|
||||
```
|
||||
|
||||
Expected: PASS; the MAME values are correct; the M2–M4 gates are unchanged.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m6-i64.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: i64 arguments, returns and arithmetic"
|
||||
git add scripts/tests/m6/i64.sh
|
||||
git commit -m "tests: M6 i64 gate"
|
||||
```
|
||||
|
||||
### Task 3: `float`/`double` soft-float via `flib.lib`
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010ISelLowering.cpp/.h`, `TMS34010TargetMachine.cpp` (libcall names), `TMS34010InstrInfo.td` (constant pool/loads), `TMS34010AsmPrinter.cpp` (float constants), `TMS34010Subtarget`/TTI as needed
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m6-float.ll`, `scripts/tests/m6/float.sh`
|
||||
- Reuse: Task 1's `flib` ABI/link.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1's `FS$`/`FD$` list and stack ABI; Task 2's hidden-return/stack slots.
|
||||
- Produces: `f32`/`f64` arguments/returns, `FADD`/`FSUB`/`FMUL`/`FDIV`/`FNEG`, comparisons, and int↔float conversions via the exact `FS$`/`FD$` libcalls; constant-pool emission for float/double literals.
|
||||
|
||||
- [ ] **Step 1: Write the failing float test**
|
||||
|
||||
`m6-float.ll` defines `float fadd(float,float)`, `double dadd(double,double)`, `fmul`, `fdiv`, `fcmp`, and conversions; checks the libcall names, the stack/hidden-return shape, and the constant pool. `float.sh` runs `fadd(1.5,2.5)=4.0`, `fmul`, `fdiv`, `fcmp`, and conversions in MAME, linking `flib.lib`.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m6-float.ll`
|
||||
Expected: float/double rejection or a missing libcall/constant pool.
|
||||
|
||||
- [ ] **Step 3: Implement the soft-float lowering**
|
||||
|
||||
Set the float/double operation actions to `LibCall` and the exact `FS$*`/`FD$*` names; lower float/double args/returns via the Task 1/A2 stack rules; add the constant pool for `f32`/`f64` literals (bit-exact `.long` pairs, 16-bit-aligned); implement the comparisons/conversions through the `flib` entries. Do not hardcode a library address or guess a symbol name.
|
||||
|
||||
- [ ] **Step 4: Run the float gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v .../m6-float.ll
|
||||
scripts/tests/m6/float.sh
|
||||
scripts/tests/m6/spike.sh
|
||||
```
|
||||
|
||||
Expected: PASS; the MAME float/double values are correct; the constant pool is bit-exact.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m6-float.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: float/double soft-float lowering"
|
||||
git add scripts/tests/m6/float.sh
|
||||
git commit -m "tests: M6 float/double gate"
|
||||
```
|
||||
|
||||
### Task 4: General varargs (`va_list`, `va_start`, `va_arg`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010ISelLowering.cpp/.h`, `TMS34010CallingConv.td`, `TMS34010FrameLowering.cpp`
|
||||
- Modify: `scripts/tests/m5/conformance/shim.c` (a real `va_list`-based `printf`/`sprintf` path)
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m6-varargs.ll`, `scripts/tests/m6/varargs.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M5 contiguous `&last_fixed` pattern; the M4 `sprintf`/shim; the all-stack ABI.
|
||||
- Produces: a `va_list` type and `va_start`/`va_arg` lowering for the TI stack layout; external variadic definitions/calls at `-O2`; the M4 contiguous pattern remains.
|
||||
|
||||
- [ ] **Step 1: Write the failing varargs test**
|
||||
|
||||
`m6-varargs.ll` defines an external variadic `printf`-shaped function and a `va_start`/`va_arg` walk over `int`, `long`, `char *`, `double`; C `varargs.sh` prints `%d %s %f` and compares the output. The first run must fail on the `va_start`/local variadic restriction.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m6-varargs.ll`
|
||||
Expected: `Cannot select: va_start`/`vastart` or the M5 local-variadic rejection.
|
||||
|
||||
- [ ] **Step 3: Implement the varargs lowering**
|
||||
|
||||
Add the `va_list` representation, `va_start`/`va_arg`/`va_end`/`va_copy` lowering, and the external variadic call/definition ABI; keep the contiguous M4 pattern working. Let the static-variadic `-O2` path through once `va_start` keeps `...`; update the M5 diagnostic/tests accordingly. Extend the shim to use the real `va_list` where supported.
|
||||
|
||||
- [ ] **Step 4: Run the varargs gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v .../m6-varargs.ll
|
||||
scripts/tests/m6/varargs.sh
|
||||
scripts/tests/m4/varargs.sh
|
||||
```
|
||||
|
||||
Expected: the `%d %s %f` output is exact; the M4 contiguous pattern still passes.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m6-varargs.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: general varargs"
|
||||
git add scripts/tests/m6/varargs.sh scripts/tests/m5/conformance/shim.c
|
||||
git commit -m "tests: M6 varargs gate and shim"
|
||||
```
|
||||
|
||||
### Task 5: Bitfields
|
||||
|
||||
**Files:**
|
||||
- Modify: `build/llvm-clean/clang/lib/Basic/Targets/TMS34010.cpp/.h` (record/bitfield layout as needed)
|
||||
- Modify: `TMS34010ISelLowering.cpp` (bitfield load/store masks) if the DAG needs target help
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m6-bitfield.ll`, `scripts/tests/m6/bitfield.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the Clang `PackStruct=1` target, the M4 packed-struct `_Static_assert` offsets, the TI C guide.
|
||||
- Produces: TI-compatible packed bitfield offsets/signedness and correct masked loads/stores for `unsigned`/`signed` fields of 1..32 bits, including cross-byte/cross-word fields.
|
||||
|
||||
- [ ] **Step 1: Write the failing bitfield test**
|
||||
|
||||
`m6-bitfield.ll`/C defines packed structs with adjacent/signed/unsigned/cross-word bitfields and static asserts the TI offsets; `bitfield.sh` reads/writes every field and checks the observed bits in MAME against the TI layout. The first run must fail on a layout/shift/mask mismatch.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m6-bitfield.ll` / `scripts/tests/m6/bitfield.sh`
|
||||
Expected: wrong offsets/masks or an unsupported bitfield shape.
|
||||
|
||||
- [ ] **Step 3: Implement the layout/adjustments**
|
||||
|
||||
Make the Clang record layout match the TI packed rules and the M4 offsets; adjust the target load/store lowering for the signed/unsigned field extraction and insertion if the generic DAG is wrong. Keep ordinary packed structs/arrays unchanged.
|
||||
|
||||
- [ ] **Step 4: Run the bitfield gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v .../m6-bitfield.ll
|
||||
scripts/tests/m6/bitfield.sh
|
||||
scripts/tests/m4/layout.sh
|
||||
```
|
||||
|
||||
Expected: the TI offsets and every MAME field value match; the M4 layout is unchanged.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add clang/lib/Basic/Targets/TMS34010.cpp clang/lib/Basic/Targets/TMS34010.h llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m6-bitfield.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: TI packed bitfields"
|
||||
git add scripts/tests/m6/bitfield.sh
|
||||
git commit -m "tests: M6 bitfield gate"
|
||||
```
|
||||
|
||||
### Task 6: Aggregates by value, `sret`, and aggregate returns
|
||||
|
||||
**Files:**
|
||||
- Modify: `TMS34010ISelLowering.cpp/.h`, `TMS34010CallingConv.td`, `TMS34010FrameLowering.cpp`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m6-aggregate.ll`, `scripts/tests/m6/aggregate.sh`
|
||||
- Reuse: the M5 `byval`/hidden-return/`memcpy` machinery.
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1/2's hidden-return slot; the M5 `byval` 16-bit slots; the memcpy/`alloca`.
|
||||
- Produces: structs/unions by value with 16-bit-rounded slots, `sret`/aggregate returns via the caller-allocated slot, and correct copies; `byval` remains supported.
|
||||
|
||||
- [ ] **Step 1: Write the failing aggregate test**
|
||||
|
||||
`m6-aggregate.ll`/C defines a 6-byte struct by value, a larger struct by value, a struct return, a union by value, and an `sret` call; static-asserts the offsets/sizes and checks the fields in MAME. The first run must fail on the current sret/aggregate rejection or a copy/size mismatch.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v .../m6-aggregate.ll` / `scripts/tests/m6/aggregate.sh`
|
||||
Expected: `sret`/aggregate return rejection or a wrong slot/copy.
|
||||
|
||||
- [ ] **Step 3: Implement the aggregate lowering**
|
||||
|
||||
Extend `LowerCall`/`LowerFormalArguments`/`CanLowerReturn`/`LowerReturn` for `sret`, structs/unions by value, and aggregate returns using the 16-bit-rounded stack slots and the hidden return pointer; use `memcpy`/the exact object size. Keep the M5 `byval` and scalar ABI.
|
||||
|
||||
- [ ] **Step 4: Run the aggregate gate green**
|
||||
|
||||
```sh
|
||||
build/llvm-clean-build/bin/llvm-lit -v .../m6-aggregate.ll
|
||||
scripts/tests/m6/aggregate.sh
|
||||
scripts/tests/m5/robust.sh
|
||||
scripts/tests/m2/run.sh
|
||||
```
|
||||
|
||||
Expected: the MAME fields/sizes match; the M5 byval/robust gate is unchanged.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/CodeGen/TMS34010/m6-aggregate.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: aggregates by value and sret"
|
||||
git add scripts/tests/m6/aggregate.sh
|
||||
git commit -m "tests: M6 aggregate gate"
|
||||
```
|
||||
|
||||
### Task 7: Runtime/libc breadth (`flib`/`rts`, `printf`/`sprintf`)
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/m6/link.cmd` / the M6 harness to link `flib.lib`/`rts.lib`; `scripts/tests/m5/conformance/shim.c`
|
||||
- Test: `scripts/tests/m6/runtime.sh`, `llvm/test/CodeGen/TMS34010/m6-runtime.ll` if needed
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Tasks 3/4's float/varargs; the M5 sandbox.
|
||||
- Produces: a linked runtime with `flib`/`rts` and a `printf`/`sprintf` that handles the M6 formats; the M6 conformance tests reuse it.
|
||||
|
||||
- [ ] **Step 1: Write the failing runtime test**
|
||||
|
||||
`runtime.sh` builds a C program using `printf("%d %s %f %lld")`, `sprintf`, `memcpy`/`memmove`, and the `flib` arithmetic; the first run must fail on the missing libcall/format.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m6/runtime.sh`
|
||||
Expected: a missing `FS$`/`FD$` link or a format/output failure.
|
||||
|
||||
- [ ] **Step 3: Implement the runtime link/shim**
|
||||
|
||||
Wire `flib.lib`/`rts.lib` in the M6 link command; extend the shim/`printf` to the M6 formats (`%f`, `%lld`, `%llu`, width/precision) using the real `va_list`; keep the M5 `printf`/`sprintf` behavior. Do not bypass the `flib`/`rts` where the ABI requires it.
|
||||
|
||||
- [ ] **Step 4: Run the runtime gate green**
|
||||
|
||||
```sh
|
||||
scripts/tests/m6/runtime.sh
|
||||
scripts/tests/m5/robust.sh
|
||||
scripts/tests/m5/native.sh
|
||||
```
|
||||
|
||||
Expected: the output/values match; the M5 native path stays green.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git add scripts/m6/link.cmd scripts/tests/m6/runtime.sh scripts/tests/m5/conformance/shim.c
|
||||
git commit -m "tests: M6 runtime and printf/sprintf"
|
||||
```
|
||||
|
||||
### Task 8: Conformance expansion
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tests/m5/conformance/classify.sh`, `skip.tsv`, `scripts/tests/m5/c-torture.list`, `c-testsuite.list`
|
||||
- Create: `scripts/tests/m6/c-torture.sh`, `scripts/tests/m6/c-testsuite.sh` (the M6 wrappers over the M5 runner/expanded lists)
|
||||
- Test: the expanded gates and reports
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Tasks 1–7; the pinned GCC 16.2/c-testsuite corpora.
|
||||
- Produces: the M6 classifier/allowlists that no longer skip the supported float/i64/varargs/bitfield/aggregate tests; the full supported-suite report and the curated M6 gate; the `printf` output comparison.
|
||||
|
||||
- [ ] **Step 1: Write the failing conformance test**
|
||||
|
||||
Extend the c-torture/c-testsuite lists with the newly supported tests and remove the corresponding skip rows. The first run must fail because the classifier still skips them or the output/float libcall is missing.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m6/c-torture.sh` / `c-testsuite.sh` (or the expanded M5 scripts)
|
||||
Expected: skips for now-supported features or a missing `flib` link.
|
||||
|
||||
- [ ] **Step 3: Expand the classifier/lists**
|
||||
|
||||
Remove the M6 feature skips; keep the genuinely unsupported (debug info, wider Xlib, etc.); add the `printf` output tests; record the full supported-suite counts and reasons. Keep the curated gate runtime bounded (target 40–60 per suite) and the full `--scan` as a report.
|
||||
|
||||
- [ ] **Step 4: Run the expanded gates green**
|
||||
|
||||
```sh
|
||||
scripts/tests/m6/c-torture.sh
|
||||
scripts/tests/m6/c-testsuite.sh
|
||||
scripts/tests/m5/generic.sh
|
||||
scripts/tests/m5/conformance/selftest.sh
|
||||
```
|
||||
|
||||
Expected: the expanded lists pass; skipped tests have reasons; the Generic no-crash report still has no crashes.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```sh
|
||||
git add scripts/tests/m5/conformance/classify.sh scripts/tests/m5/conformance/skip.tsv scripts/tests/m5/c-torture.list scripts/tests/m5/c-testsuite.list scripts/tests/m6/c-torture.sh scripts/tests/m6/c-testsuite.sh
|
||||
git commit -m "tests: expand M6 conformance coverage"
|
||||
```
|
||||
|
||||
### Task 9: Docs, full gates, and push
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, `symbols/README.md` (if runtime symbols are added)
|
||||
- Test: the full M6/M5/M4/M3/M2 gate list
|
||||
|
||||
- [ ] **Step 1: Update the docs**
|
||||
|
||||
Document the M6 i64/float/double ABI, the `flib`/`rts` runtime, general varargs/`printf`, packed bitfields, aggregates/sret, the expanded conformance counts/pins, and the M6/M7 boundary (debug info, native linker, wider Xlib, real hardware). Correct the M5 stale notes.
|
||||
|
||||
- [ ] **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|m6)-'
|
||||
build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010
|
||||
scripts/tests/m6/spike.sh
|
||||
scripts/tests/m6/i64.sh
|
||||
scripts/tests/m6/float.sh
|
||||
scripts/tests/m6/varargs.sh
|
||||
scripts/tests/m6/bitfield.sh
|
||||
scripts/tests/m6/aggregate.sh
|
||||
scripts/tests/m6/runtime.sh
|
||||
scripts/tests/m6/c-torture.sh
|
||||
scripts/tests/m6/c-testsuite.sh
|
||||
scripts/tests/m5/object-smoke.sh
|
||||
scripts/tests/m5/native-link.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/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; skips 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 clang/lib/Basic/Targets/TMS34010.cpp clang/lib/Basic/Targets/TMS34010.h TMS34010.md
|
||||
git -C build/llvm-clean commit -m "tms34010: M6 floats, i64, varargs, bitfields and aggregates"
|
||||
git -C build/llvm-clean push origin m6
|
||||
git add README.md symbols scripts/m6 scripts/tests/m6 scripts/tests/m5 scripts/m3
|
||||
git commit -m "tests/docs: M6 language/runtime coverage"
|
||||
git push origin m6
|
||||
```
|
||||
|
||||
Do not force-push, merge into `m0`–`m5`, or change the default. The controller updates the default to `m6` after the final review only if the user asks.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M6 closes the TI language surface: float/double/i64 ABI, soft-float `flib`, general varargs, packed bitfields, aggregates/sret, and the expanded conformance tier. M7 owns debug info, the native linker, the wider Xlib surface, real-hardware validation, and the full external suites beyond the curated supported subset. 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.
|
||||
@@ -71,21 +71,28 @@ early GEP-scaling pass.
|
||||
|
||||
- Registers: A0–A12 general, A8 return value, A13 FP, A14 STK (program stack),
|
||||
A15 system stack. B0–B14 are unused by TI's C compiler.
|
||||
- Caller: if arguments are passed or a float/double is returned, push the old
|
||||
STK on the system stack (`MOVE STK,-*SP`); push arguments on the program
|
||||
stack in reverse order, widened to 32 bits; structs by value rounded to
|
||||
16 bits; struct return address pushed on the program stack; call with
|
||||
`CALLA` (direct) or `CALL Rs` (indirect).
|
||||
- Caller: if arguments are passed or a float/double/`i64`/aggregate is
|
||||
returned, push the old STK on the system stack (`MOVE STK,-*SP`); reserve
|
||||
the hidden return slot (if any) at the top of the program stack **before**
|
||||
saving STK; push arguments on the program stack in reverse order, widened
|
||||
to 32 bits; structs by value rounded to 16 bits; call with `CALLA` (direct)
|
||||
or `CALL Rs` (indirect). There is no `sret` pointer argument in the TI
|
||||
ABI.
|
||||
- Callee: save used A registers except A8 on the system stack (`MMTM SP,…`);
|
||||
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.
|
||||
- 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.)
|
||||
- `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.
|
||||
- Hidden returns: the caller reserves `alignTo(size,2)` bytes at the top of
|
||||
the program stack (before saving STK) for a struct/union, `float`/`double`
|
||||
or `i64` result; the callee copies the object bytes to `saved_STK-size`
|
||||
(the top of the slot) and ends `RETS 2`; the caller copies the bytes out
|
||||
and releases the slot. The caller does not push a return address. Float/
|
||||
double and `i64` use the same rule with a 4/8-byte object. (The 1987
|
||||
`_mkbig`/`_callbig` oracle in the plan and `TMS34010.md` binds this form;
|
||||
it supersedes the earlier sret wording in this document.)
|
||||
- Symbols use a leading underscore (`_main`); sections are `.text`, `.data`,
|
||||
`.bss`; code is position-dependent and linked at fixed bit addresses.
|
||||
|
||||
@@ -263,16 +270,22 @@ non-constant pointer expression by 8×.
|
||||
|
||||
- Custom calling convention `CC_TMS34010`.
|
||||
- `LowerFormalArguments` / `LowerCall` / `LowerReturn` implement the caller and
|
||||
callee rules in §4.2 exactly; `sret` and `byval` follow the TI layout.
|
||||
callee rules in §4.2 exactly; `byval` follows the TI layout. An explicit
|
||||
`sret` pointer is rejected: aggregate returns use the hidden slot above.
|
||||
- **Explicit arguments**: pushed on the program stack (A14) in reverse order,
|
||||
each widened to 32 bits. The first explicit argument is at `FP(-32)`, the
|
||||
second at `FP(-64)`, etc.
|
||||
- **Struct return**: the caller pushes the return-space address **after** the
|
||||
explicit arguments, so it is the top program-stack slot: the callee reads it
|
||||
at `FP(-32)` and the first explicit argument is at `FP(-64)`.
|
||||
- **Hidden return slot**: for a struct/union, `float`/`double` or `i64`
|
||||
result, the caller reserves `alignTo(size,2)` bytes at the top of its own
|
||||
frame **before** saving STK and passes no return pointer. The callee
|
||||
writes the object at `saved_STK-size` (= `FP-(argbytes+size)`) and ends
|
||||
`RETS 2`; the caller copies the bytes out and releases the slot with
|
||||
`ADDI -size,STK`. This is the 1987 `_mkbig`/`_callbig` form and supersedes
|
||||
the earlier sret wording; an explicit `sret` argument is rejected.
|
||||
- **Old STK**: the caller saves A14 on the system stack only when it passes
|
||||
arguments or the callee returns a float/double. A no-argument function with
|
||||
locals has no saved old STK; the callee restores STK from FP before `RETS 0`.
|
||||
arguments or the callee returns a `float`/`double`/`i64`/aggregate through
|
||||
the hidden slot. A no-argument function with locals has no saved old STK;
|
||||
the callee restores STK from FP before `RETS 0`.
|
||||
- **System stack layout** (grows down), after the callee's `MMTM` of `n`
|
||||
registers:
|
||||
|
||||
@@ -324,7 +337,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.
|
||||
@@ -434,7 +447,16 @@ appears in MAME (real unit when available).
|
||||
no X errors.
|
||||
|
||||
**M5 — robustness and native path.** `memcpy`, `alloca`, `byval`, varargs
|
||||
(`sprintf`), floats, bitfields, `long long`; native COFF and debug info.
|
||||
(`sprintf`), floats, bitfields, `long long`; native COFF and debug info
|
||||
(debug info was re-scoped to M6 below, then moved to **M7** by the M6
|
||||
plan/ledger ruling).
|
||||
|
||||
> **M5 re-scoped (2026-11-13):** floats/double, bitfields, `long long`/i64 and
|
||||
> general varargs (`va_list`/`va_start`/`va_arg` beyond the contiguous
|
||||
> `sprintf` form) are **M6**. M5 delivers the integer/pointer native object
|
||||
> path, `alloca`/`byval`/narrow returns, `memcpy`/`memset`/`memmove`,
|
||||
> `JR`/`MMTM`, and the curated conformance tier. **Debug info is M7** per
|
||||
> the M6 plan and ledger ruling (`progress.md`), not M6.
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
|
||||
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
+365
@@ -0,0 +1,365 @@
|
||||
#!/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_LIBS="a b" add `-l a -l b` to the native link (library
|
||||
# files must already be in the SDK directory; the
|
||||
# conformance shim uses flib.lib/rts.lib for %f)
|
||||
# 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_LIBS=${M4_NATIVE_LIBS:-}
|
||||
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"
|
||||
NATIVE_LIBS="$NATIVE_LIBS rts.lib"
|
||||
fi
|
||||
for lib in $NATIVE_LIBS; do
|
||||
dos=$(printf '%s' "$lib" | tr '[:lower:]' '[:upper:]')
|
||||
[ -f "$SDK/$dos" ] || [ -f "$SDK/$lib" ] \
|
||||
|| fail "$lib not extracted into $SDK"
|
||||
done
|
||||
{
|
||||
printf '%s\n' '-a' '-o M4.OUT' '-m M4.MAP' '-e _start'
|
||||
printf '%s\n' "$NATIVE_OBJS"
|
||||
for lib in $NATIVE_LIBS; do
|
||||
printf '%s\n' "-l $lib"
|
||||
done
|
||||
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. tms-clang's post-opt --scale converts that byte/element
|
||||
* index to bits (M6 Task 6 generalized this beyond the old switch.table-only
|
||||
* normalize rule). This source makes the hazard reachable at -O2 (termtris'
|
||||
* init_game and runesc switches are the real cases): a missed scale would
|
||||
* index the table one bit per slot.
|
||||
*/
|
||||
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; }
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* abi-oracle.c -- the 1987 TI C compiler ABI oracle for M6 task 1.
|
||||
*
|
||||
* The 1987 GSP C compiler is on the 1987-11-06 "Simulator-C Tools-ASM Tools"
|
||||
* image (::/C2). Run it under DOSBox with the module name (no extension):
|
||||
*
|
||||
* gspcpp oracle.c
|
||||
* gspcc oracle.c
|
||||
* gspcg oracle.c
|
||||
*
|
||||
* ORACLE.ASM then shows the exact stack sequences reproduced in
|
||||
* build/llvm-clean/TMS34010.md ("M6 state"):
|
||||
* - _dadd/_dcall: GSP double argument order and the caller-allocated
|
||||
* hidden return slot (the callee writes saved_STK-64/saved_STK-32);
|
||||
* - _fadd: a float return uses the single word at saved_STK-32 (the K&R
|
||||
* compiler promotes the parameters, so it calls FD$ADD + FD$DTOF);
|
||||
* - _mkpair/_callpair: a 64-bit struct return uses the same hidden slot
|
||||
* and the caller releases it with ADDI -64,STK;
|
||||
* - _d2i/_i2d: the FD$DTOI/FD$ITOD conversion entries.
|
||||
*
|
||||
* The 1987 compiler is K&R-only; long long did not exist, so i64 has no
|
||||
* external oracle. M6 i64 memory is little-endian (LSW at the lower
|
||||
* address, per spec §4.1); the argument/hidden-slot order is MSW-first and
|
||||
* is documented
|
||||
* in TMS34010.md and pinned by scripts/m6/spike-probe.asm.
|
||||
*/
|
||||
|
||||
double dadd(a, b)
|
||||
double a;
|
||||
double b;
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
double dcall(a, b)
|
||||
double a;
|
||||
double b;
|
||||
{
|
||||
double r;
|
||||
r = dadd(a, b);
|
||||
return r;
|
||||
}
|
||||
|
||||
long d2i(a)
|
||||
double a;
|
||||
{
|
||||
return (long)a;
|
||||
}
|
||||
|
||||
double i2d(a)
|
||||
long a;
|
||||
{
|
||||
return (double)a;
|
||||
}
|
||||
|
||||
float fadd(a, b)
|
||||
float a;
|
||||
float b;
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
struct pair {
|
||||
long a;
|
||||
long b;
|
||||
};
|
||||
|
||||
struct pair mkpair(a, b)
|
||||
long a;
|
||||
long b;
|
||||
{
|
||||
struct pair p;
|
||||
p.a = a;
|
||||
p.b = b;
|
||||
return p;
|
||||
}
|
||||
|
||||
long callpair(a, b)
|
||||
long a;
|
||||
long b;
|
||||
{
|
||||
struct pair p;
|
||||
p = mkpair(a, b);
|
||||
return p.a + p.b;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
-- aggregate-check.lua -- read the M6 aggregate marker words and compare them
|
||||
-- with the expected ABI/layout values.
|
||||
--
|
||||
-- AGGREGATE_MARKERS is the bit address of _aggregate_markers from the linker
|
||||
-- map. Each marker is one 32-bit word at base + n*0x20 bits. The raw-object
|
||||
-- markers pin the byte layout (little-endian, fields in ascending order) and
|
||||
-- the guards prove an aggregate copy does not overrun the object.
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
|
||||
dofile(os.getenv("M2_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2900")
|
||||
local BASE = tonumber(os.getenv("AGGREGATE_MARKERS"), 16)
|
||||
local N = 49
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local expect = {
|
||||
[0] = 0x11223344, [1] = 0x00005566, -- mk_six fields
|
||||
[2] = 0x11223344, [3] = 0x00005566, -- raw six object word/half
|
||||
[4] = 0x600D600D, -- guard after a 6-byte copy
|
||||
[5] = 0xAABBCCDD, [6] = 0x0000005A, -- mk_five fields (5-byte object)
|
||||
[7] = 0xAABBCCDD, [8] = 0x0000005A, -- raw five object word/byte
|
||||
[9] = 0x000000A5, -- guard after a 5-byte copy
|
||||
[10] = 0x00000010, [11] = 0x00000011, -- mk_big fields
|
||||
[12] = 0x00000012, [13] = 0x00000013,
|
||||
[14] = 0x00000014,
|
||||
[15] = 0x00000010, [16] = 0x00000011, -- raw big object words
|
||||
[17] = 0x00000012, [18] = 0x00000013,
|
||||
[19] = 0x00000014,
|
||||
[20] = 0xAAAA5555, [21] = 0x12345678, -- mk_pair (the 1987 _mkpair)
|
||||
[22] = 0x00000100, [23] = 0x00000009, -- mk_outer nested fields
|
||||
[24] = 0x00000003,
|
||||
[25] = 0xDEADBEEF, [26] = 0xDEADBEEF, -- mk_uni field and raw word
|
||||
[27] = 0x3366EF96, -- sum_six(six, 100)
|
||||
[28] = 0x00000024, -- sum_big(big)
|
||||
[29] = 0x12345678, -- sum_uni(uni)
|
||||
[30] = 0x000000CF, -- c_usesix(50)
|
||||
[31] = 0x00000018, -- c_usebig(10)
|
||||
[32] = 0x00000405, -- c_useouter(0x200)
|
||||
[33] = 0x0BADF00D, -- c_useuni(...)
|
||||
[34] = 0x0000000B, -- c_sumpair({5,6})
|
||||
[35] = 0x00000030, -- c_sumsix({0x10,0x20})
|
||||
[36] = 0x112233C2, -- c_sumuni(l + c[5])
|
||||
[37] = 0x000000D2, -- c_usemixed(100)
|
||||
[38] = 0x00000064, -- mixed raw a
|
||||
[39] = 0x00000064, -- mixed raw i64 LSW (little-endian)
|
||||
[40] = 0x00000000, -- mixed raw i64 MSW
|
||||
[41] = 0x00000000, -- mixed raw double LSW (GSP 1.5)
|
||||
[42] = 0x400C0000, -- mixed raw double MSW
|
||||
[43] = 0x40D00000, -- mixed raw float (GSP 2.5)
|
||||
[44] = 0x00000007, -- mixed raw char
|
||||
[45] = 0x000B1405, -- c_mkbits fields a=5 b=20 c=-5
|
||||
[46] = 0xFFFFFFFB, -- signed int c:4 sign-extends
|
||||
[47] = 0x00000BA5, -- raw packed bitfield word
|
||||
[48] = 0x5A5A5A5A, -- marker after aggregate_run returns
|
||||
}
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
local bad = 0
|
||||
for i = 0, N - 1 do
|
||||
got[i] = prog:read_u32(BASE + i * 0x20)
|
||||
if got[i] ~= expect[i] then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
io.write(string.format("M6 aggregate:"))
|
||||
for i = 0, N - 1 do
|
||||
io.write(string.format(" %08X", got[i]))
|
||||
end
|
||||
io.write("\n")
|
||||
if bad == 0 then
|
||||
print("M6 AGGREGATE MAME: PASS")
|
||||
else
|
||||
for i = 0, N - 1 do
|
||||
if got[i] ~= expect[i] then
|
||||
print(string.format(
|
||||
"M6 aggregate: marker %d got %08X want %08X",
|
||||
i, got[i], expect[i]))
|
||||
end
|
||||
end
|
||||
print("M6 AGGREGATE MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "aggregate-check")
|
||||
@@ -0,0 +1,28 @@
|
||||
; aggregate-entry.asm -- M6 aggregate gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack, calls the C
|
||||
; driver aggregate_run() and writes a post-return marker. aggregate.sh
|
||||
; concatenates the llc output for m6-aggregate.ll and the compiled driver
|
||||
; after this file, so _aggregate_run and the aggregate functions are in the
|
||||
; same assembly.
|
||||
;
|
||||
; The marker array is in .bss (linked at the ram origin); aggregate-check.lua
|
||||
; reads its address from the linker map and checks 49 words (markers 0..48,
|
||||
; the last one written after aggregate_run returns). Marker n is 0x20 bits
|
||||
; above marker n-1, matching one 32-bit value per marker slot.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _aggregate_run
|
||||
movi 5A5A5A5Ah, a0
|
||||
movi _aggregate_markers+1536, a2 ; marker 48, the post-return word
|
||||
move a0, *a2, 1
|
||||
rets
|
||||
|
||||
.globl _aggregate_markers
|
||||
.bss _aggregate_markers, 1568, 16 ; 49 marker words (0x20 bits each)
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
/* M6 aggregate gate driver.
|
||||
*
|
||||
* Calls the hand-written ABI functions in m6-aggregate.ll through the TI
|
||||
* aggregate rules and writes result words to the marker array defined by the
|
||||
* entry assembly. The .ll callees are *not* compiled by Clang, so the driver
|
||||
* pins the caller side against independently written lowering; the C
|
||||
* functions below then exercise the compiler's own callee side (and its
|
||||
* caller side calling itself).
|
||||
*
|
||||
* The ABI under test (1987 `_mkbig`/`_callbig`):
|
||||
* - the caller reserves an alignTo(size, 2)-byte slot at the top of its
|
||||
* frame before saving STK, pushes the arguments, calls;
|
||||
* - the callee copies the object bytes to saved_STK-size (the object sits
|
||||
* at the top of the rounded slot) and ends with LOADSTK + RETS 2;
|
||||
* - the caller copies the bytes out and releases the slot;
|
||||
* - struct/union arguments are still byval copies in the argument area;
|
||||
* - no sret pointer argument and no A8 aggregate return.
|
||||
*
|
||||
* Marker word n lives at aggregate_markers[n], i.e. 0x20 bits above the
|
||||
* previous one; scripts/m6/aggregate-check.lua reads them by bit address from
|
||||
* the linker map.
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned long long u64;
|
||||
|
||||
struct six {
|
||||
int a;
|
||||
short b;
|
||||
};
|
||||
|
||||
struct five {
|
||||
int a;
|
||||
char b;
|
||||
};
|
||||
|
||||
/* A packed bitfield struct returned by value: the Task 5 (bitfields) / Task 6
|
||||
* (aggregate return) seam. The 12 field bits fit one 16-bit word, so the
|
||||
* hidden slot is 2 bytes and the callee stores the packed bits directly. */
|
||||
struct bits {
|
||||
unsigned int a : 3;
|
||||
unsigned int b : 5;
|
||||
int c : 4;
|
||||
};
|
||||
|
||||
struct big {
|
||||
long a, b, c, d, e;
|
||||
};
|
||||
|
||||
struct pair {
|
||||
long a, b;
|
||||
};
|
||||
|
||||
struct inner {
|
||||
long a;
|
||||
short b;
|
||||
};
|
||||
|
||||
struct outer {
|
||||
struct inner i;
|
||||
long c;
|
||||
};
|
||||
|
||||
union uni {
|
||||
long l;
|
||||
char c[6];
|
||||
};
|
||||
|
||||
struct mixed {
|
||||
long a;
|
||||
long long b;
|
||||
double d;
|
||||
float f;
|
||||
char c;
|
||||
};
|
||||
|
||||
struct six_guard {
|
||||
struct six s;
|
||||
unsigned int guard;
|
||||
};
|
||||
|
||||
struct five_guard {
|
||||
struct five f;
|
||||
unsigned char guard;
|
||||
};
|
||||
|
||||
/* Layout contract: TI packs records, so a 5-byte object is possible and the
|
||||
* 6-byte slot rounds it up by one byte. */
|
||||
_Static_assert(sizeof(struct six) == 6, "six");
|
||||
_Static_assert(__builtin_offsetof(struct six, b) == 4, "six.b");
|
||||
_Static_assert(sizeof(struct bits) == 2, "bits");
|
||||
_Static_assert(sizeof(struct five) == 5, "five");
|
||||
_Static_assert(__builtin_offsetof(struct five, b) == 4, "five.b");
|
||||
_Static_assert(sizeof(struct big) == 20, "big");
|
||||
_Static_assert(sizeof(struct pair) == 8, "pair");
|
||||
_Static_assert(sizeof(struct inner) == 6, "inner");
|
||||
_Static_assert(sizeof(struct outer) == 10, "outer");
|
||||
_Static_assert(__builtin_offsetof(struct outer, c) == 6, "outer.c");
|
||||
_Static_assert(sizeof(union uni) == 6, "uni");
|
||||
_Static_assert(sizeof(struct mixed) == 25, "mixed");
|
||||
_Static_assert(__builtin_offsetof(struct mixed, b) == 4, "mixed.b");
|
||||
_Static_assert(__builtin_offsetof(struct mixed, d) == 12, "mixed.d");
|
||||
_Static_assert(__builtin_offsetof(struct mixed, f) == 20, "mixed.f");
|
||||
_Static_assert(__builtin_offsetof(struct mixed, c) == 24, "mixed.c");
|
||||
|
||||
extern volatile u32 aggregate_markers[];
|
||||
|
||||
/* Callees defined in m6-aggregate.ll. */
|
||||
extern struct six mk_six(int, int);
|
||||
extern struct five mk_five(int, int);
|
||||
extern struct big mk_big(int);
|
||||
extern struct pair mk_pair(int, int);
|
||||
extern struct outer mk_outer(int);
|
||||
extern union uni mk_uni(int);
|
||||
extern int sum_six(struct six, int);
|
||||
extern int sum_big(struct big);
|
||||
extern int sum_uni(union uni);
|
||||
|
||||
/* Keep raw object copies in .bss so the exact bytes can be inspected. */
|
||||
static volatile struct six six_raw;
|
||||
static volatile struct five five_raw;
|
||||
static volatile struct big big_raw;
|
||||
static volatile union uni uni_raw;
|
||||
static volatile struct mixed mixed_raw;
|
||||
static volatile struct six_guard six_guard_slot;
|
||||
static volatile struct five_guard five_guard_slot;
|
||||
static volatile struct bits bits_raw;
|
||||
|
||||
static void mark(u32 n, u32 v) { aggregate_markers[n] = v; }
|
||||
|
||||
/* --- C-side aggregate callees (the compiler's callee lowering) ----------- */
|
||||
|
||||
static __attribute__((noinline)) struct six c_mksix(int a, int b)
|
||||
{
|
||||
struct six s;
|
||||
s.a = a;
|
||||
s.b = (short)b;
|
||||
return s;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) int c_usesix(int x)
|
||||
{
|
||||
struct six s = c_mksix(x, 7);
|
||||
return s.a * 3 + s.b + x;
|
||||
}
|
||||
|
||||
/* The bitfield-struct return: fields come from x so the callee cannot fold
|
||||
* the result, and the caller reads them back through the returned object.
|
||||
* c uses the low bits only: a (x >> 8) & mask source would exercise an
|
||||
* unrelated generic load-narrowing path on this bit-addressed target. */
|
||||
static __attribute__((noinline)) struct bits c_mkbits(int x)
|
||||
{
|
||||
struct bits v;
|
||||
|
||||
v.a = x & 7;
|
||||
v.b = (x >> 3) & 31;
|
||||
v.c = -(x & 7);
|
||||
return v;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) struct big c_mkbig(int x)
|
||||
{
|
||||
struct big b;
|
||||
b.a = x;
|
||||
b.b = x + 1;
|
||||
b.c = x + 2;
|
||||
b.d = x + 3;
|
||||
b.e = x + 4;
|
||||
return b;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) int c_usebig(int x)
|
||||
{
|
||||
struct big b = c_mkbig(x);
|
||||
return b.a + b.e;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) struct outer c_mkouter(int x)
|
||||
{
|
||||
struct outer o;
|
||||
o.i.a = x;
|
||||
o.i.b = 2;
|
||||
o.c = x + 3;
|
||||
return o;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) int c_useouter(int x)
|
||||
{
|
||||
struct outer o = c_mkouter(x);
|
||||
return o.i.a + o.i.b + o.c;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) union uni c_mkuni(int x)
|
||||
{
|
||||
union uni u;
|
||||
u.l = x;
|
||||
return u;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) int c_useuni(int x)
|
||||
{
|
||||
union uni u = c_mkuni(x);
|
||||
return u.l;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) struct mixed c_mkmixed(int x)
|
||||
{
|
||||
struct mixed m;
|
||||
m.a = x;
|
||||
m.b = x;
|
||||
m.d = 1.5;
|
||||
m.f = 2.5f;
|
||||
m.c = 7;
|
||||
return m;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) int c_usemixed(int x)
|
||||
{
|
||||
struct mixed m = c_mkmixed(x);
|
||||
return (long)m.a + (long)m.b + (long)m.d + (long)m.f + (long)m.c;
|
||||
}
|
||||
|
||||
static __attribute__((noinline)) int c_sumpair(struct pair p) { return p.a + p.b; }
|
||||
static __attribute__((noinline)) int c_sumsix(struct six s) { return s.a + s.b; }
|
||||
static __attribute__((noinline)) int c_sumuni(union uni u) { return u.l + u.c[5]; }
|
||||
|
||||
void aggregate_run(void)
|
||||
{
|
||||
struct six s6;
|
||||
struct five f5;
|
||||
struct big b5;
|
||||
struct pair p2;
|
||||
struct outer o;
|
||||
union uni u;
|
||||
volatile u32 *w;
|
||||
volatile u8 *pb;
|
||||
|
||||
/* The .ll 6-byte struct return and its raw memory image. */
|
||||
s6 = mk_six(0x11223344, 0x5566);
|
||||
mark(0, (u32)s6.a);
|
||||
mark(1, (u16)s6.b);
|
||||
six_raw = s6;
|
||||
w = (volatile u32 *)&six_raw;
|
||||
mark(2, w[0]);
|
||||
pb = (volatile u8 *)&six_raw;
|
||||
mark(3, pb[4] | ((u32)pb[5] << 8));
|
||||
|
||||
/* A 6-byte object must not overwrite the next object. */
|
||||
six_guard_slot.guard = 0x600D600D;
|
||||
six_guard_slot.s = mk_six(0x11223344, 0x5566);
|
||||
mark(4, six_guard_slot.guard);
|
||||
|
||||
/* The 5-byte object in a 6-byte slot; the guard proves the copy is exact
|
||||
* (the slot's pad byte is not written into the caller's object). */
|
||||
f5 = mk_five(0xAABBCCDD, 0x5A);
|
||||
mark(5, (u32)f5.a);
|
||||
mark(6, (u8)f5.b);
|
||||
five_raw = f5;
|
||||
w = (volatile u32 *)&five_raw;
|
||||
mark(7, w[0]);
|
||||
pb = (volatile u8 *)&five_raw;
|
||||
mark(8, pb[4]);
|
||||
five_guard_slot.guard = 0xA5;
|
||||
five_guard_slot.f = mk_five(0x01020304, 0x7E);
|
||||
mark(9, five_guard_slot.guard);
|
||||
|
||||
/* The 5-word / 160-bit case. */
|
||||
b5 = mk_big(0x10);
|
||||
mark(10, (u32)b5.a);
|
||||
mark(11, (u32)b5.b);
|
||||
mark(12, (u32)b5.c);
|
||||
mark(13, (u32)b5.d);
|
||||
mark(14, (u32)b5.e);
|
||||
big_raw = b5;
|
||||
w = (volatile u32 *)&big_raw;
|
||||
mark(15, w[0]);
|
||||
mark(16, w[1]);
|
||||
mark(17, w[2]);
|
||||
mark(18, w[3]);
|
||||
mark(19, w[4]);
|
||||
|
||||
/* The 2-word case (1987 `_mkpair`). */
|
||||
p2 = mk_pair(0xAAAA5555, 0x12345678);
|
||||
mark(20, (u32)p2.a);
|
||||
mark(21, (u32)p2.b);
|
||||
|
||||
/* Nested struct: flattened fields at 0, 4 and 6. */
|
||||
o = mk_outer(0x100);
|
||||
mark(22, (u32)o.i.a);
|
||||
mark(23, (u32)o.i.b);
|
||||
mark(24, (u32)o.c);
|
||||
|
||||
/* Union return and its raw low word. */
|
||||
u = mk_uni(0xDEADBEEF);
|
||||
mark(25, (u32)u.l);
|
||||
uni_raw = u;
|
||||
w = (volatile u32 *)&uni_raw;
|
||||
mark(26, w[0]);
|
||||
|
||||
/* Struct/union by value as arguments: the callee receives a private copy
|
||||
* in the argument area (the driver is the caller here). */
|
||||
mark(27, (u32)sum_six(s6, 100));
|
||||
mark(28, (u32)sum_big(b5));
|
||||
mark(29, (u32)sum_uni(mk_uni(0x12345678)));
|
||||
|
||||
/* C-defined callees (the compiler's own callee lowering), called from C. */
|
||||
mark(30, (u32)c_usesix(50));
|
||||
mark(31, (u32)c_usebig(10));
|
||||
mark(32, (u32)c_useouter(0x200));
|
||||
mark(33, (u32)c_useuni(0x0BADF00D));
|
||||
|
||||
p2.a = 5;
|
||||
p2.b = 6;
|
||||
mark(34, (u32)c_sumpair(p2));
|
||||
s6.a = 0x10;
|
||||
s6.b = 0x20;
|
||||
mark(35, (u32)c_sumsix(s6));
|
||||
u.l = 0x11223344;
|
||||
u.c[5] = 0x7E;
|
||||
mark(36, (u32)c_sumuni(u));
|
||||
|
||||
/* The aggregate can mix i64, double and float members. */
|
||||
mark(37, (u32)c_usemixed(100));
|
||||
mixed_raw = c_mkmixed(100);
|
||||
w = (volatile u32 *)&mixed_raw;
|
||||
mark(38, w[0]);
|
||||
mark(39, w[1]);
|
||||
mark(40, w[2]);
|
||||
mark(41, w[3]);
|
||||
mark(42, w[4]);
|
||||
mark(43, w[5]);
|
||||
pb = (volatile u8 *)&mixed_raw;
|
||||
mark(44, pb[24]);
|
||||
|
||||
/* Packed bitfield struct returned by value (Task 5/6 seam): fields, the
|
||||
* signed field and the raw packed word. c_mkbits(0x1A5) is a=5, b=20,
|
||||
* c=-5 in one 16-bit word. */
|
||||
{
|
||||
struct bits v = c_mkbits(0x1A5);
|
||||
volatile u8 *bb;
|
||||
|
||||
mark(45, (u32)v.a | ((u32)v.b << 8) |
|
||||
((u32)(v.c & 0xF) << 16));
|
||||
mark(46, (u32)v.c);
|
||||
bits_raw = v;
|
||||
bb = (volatile u8 *)&bits_raw;
|
||||
mark(47, (u32)bb[0] | ((u32)bb[1] << 8));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
-- bitfield-check.lua -- read the M6 bitfield marker words and compare them
|
||||
-- with the oracle's expected values.
|
||||
--
|
||||
-- BITFIELD_MARKERS is the bit address of _bitfield_markers from the linker
|
||||
-- map; each marker is one 32-bit word at base + n*0x20 bits. The struct
|
||||
-- case is the Task 5 oracle: a:3@0, b:5@3, c:4@8 (signed), d:20@12, e:4@32,
|
||||
-- and the raw word0/byte4 markers pin the actual storage bytes, not just the
|
||||
-- compiled read-back.
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
|
||||
dofile(os.getenv("M2_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2900")
|
||||
local BASE = tonumber(os.getenv("BITFIELD_MARKERS"), 16)
|
||||
local N = 62
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local expect = {
|
||||
[0] = 5, -- struct s.a (bits 0..2)
|
||||
[1] = 21, -- struct s.b (bits 3..7)
|
||||
[2] = 0xFFFFFFFD, -- struct s.c = -3, signed 4-bit
|
||||
[3] = 0x000ABCDE, -- struct s.d (bits 12..31)
|
||||
[4] = 9, -- struct s.e (bits 32..35)
|
||||
[5] = 0xABCDEDAD, -- raw word0 = a|b<<3|c<<8|d<<12
|
||||
[6] = 0x09, -- raw byte4 low nibble = e
|
||||
[7] = 7, -- c = +7
|
||||
[8] = 0xFFFFFFF8, -- c = -8 (the 4-bit minimum)
|
||||
[9] = 0x000FEDCB, -- cross.x
|
||||
[10] = 0x00012345, -- cross.y at bit 20, crossing bit 32
|
||||
[11] = 0x345FEDCB, -- raw word0: x | (y low 12) << 20
|
||||
[12] = 0x12, -- raw byte4: y high 8 bits
|
||||
[13] = 3, -- zw.a
|
||||
[14] = 17, -- zw.b after the ignored :0 (bit 3)
|
||||
[15] = 0x8B, -- raw byte = 3 | 17 << 3
|
||||
[16] = 0xFFFFFFFF, -- one.s = -1 (signed 1-bit)
|
||||
[17] = 1, -- one.u
|
||||
[18] = 0x03, -- raw byte: s in bit 0, u in bit 1
|
||||
[19] = 0, -- one.s = 0
|
||||
[20] = 1, -- one.u = 1
|
||||
[21] = 0x02, -- raw byte
|
||||
[22] = 0xFFFFFFFF, -- one.s = -1
|
||||
[23] = 0, -- one.u = 0
|
||||
[24] = 0x01, -- raw byte
|
||||
[25] = 0xDEADBEEF, -- word.w (full 32-bit field)
|
||||
[26] = 1, -- word.v at bit 32
|
||||
[27] = 0xDEADBEEF, -- raw word0
|
||||
[28] = 0x01, -- raw byte4
|
||||
[29] = 0x01234567, -- edge.p (28 bits)
|
||||
[30] = 0xA5, -- edge.q at bit 28, crossing bit 32
|
||||
[31] = 0x0C, -- edge.r at bit 36
|
||||
[32] = 0x51234567, -- raw word0: p | (q low nibble) << 28
|
||||
[33] = 0xCA, -- raw byte4: q high nibble | r << 4
|
||||
[34] = 0xFFFFFFFD, -- sx.a = -3 (signed 3-bit)
|
||||
[35] = 2, -- sx.b
|
||||
[36] = 0xFFFFFF38, -- sx.c = -200 (signed 9-bit)
|
||||
[37] = 0xFFFE0000, -- sx.d = -131072 (signed 18-bit)
|
||||
[38] = 0x80002715, -- raw word0 of the packed signed fields
|
||||
[39] = 0xFA0A1F00, -- sy.e = -100000000 (signed 30-bit)
|
||||
[40] = 0xFFFFFFEC, -- sy.f = -20 (signed 6-bit, crosses bit 32)
|
||||
[41] = 0x3A0A1F00, -- raw word0
|
||||
[42] = 0x0B, -- raw byte4: f high nibble
|
||||
[43] = 1, -- g2.a through a pointer
|
||||
[44] = 30, -- g2.b
|
||||
[45] = 0xFFFFFFFE, -- g2.c = -2
|
||||
[46] = 0x00054321, -- g2.d
|
||||
[47] = 15, -- g2.e
|
||||
[48] = 0x54321EF1, -- g2 raw word0
|
||||
[49] = 0x0F, -- g2 raw byte4
|
||||
[50] = 6, -- lz.a (leading :0 ignored)
|
||||
[51] = 9, -- lz.b at bit 3
|
||||
[52] = 0x4E, -- raw byte = 6 | 9 << 3
|
||||
[53] = 0x12345678, -- l64.f = 0x12345678 (bit 33)
|
||||
[54] = 0x00000000, -- l64 raw word0 (pad)
|
||||
[55] = 0x2468ACF0, -- l64 raw word1 (pad[32] | f<<1)
|
||||
[56] = 0x89ABCDEF, -- q64.q low word
|
||||
[57] = 0x89ABCDEF, -- q64 raw word0 (LSW)
|
||||
[58] = 0x01234567, -- q64 raw word1 (MSW)
|
||||
[59] = 0x12345678, -- copy_l64 read-back after an aggregate copy
|
||||
[60] = 0x2468ACF0, -- copied l64 raw MSW
|
||||
[61] = 0x5A5A5A5A, -- marker after bitfield_run returns
|
||||
}
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
local bad = 0
|
||||
for i = 0, N - 1 do
|
||||
got[i] = prog:read_u32(BASE + i * 0x20)
|
||||
if got[i] ~= expect[i] then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
io.write(string.format("M6 bitfield:"))
|
||||
for i = 0, N - 1 do
|
||||
io.write(string.format(" %08X", got[i]))
|
||||
end
|
||||
io.write("\n")
|
||||
if bad == 0 then
|
||||
print("M6 BITFIELD MAME: PASS")
|
||||
else
|
||||
for i = 0, N - 1 do
|
||||
if got[i] ~= expect[i] then
|
||||
print(string.format(
|
||||
"M6 bitfield: marker %d got %08X want %08X",
|
||||
i, got[i], expect[i]))
|
||||
end
|
||||
end
|
||||
print("M6 BITFIELD MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "bitfield-check")
|
||||
@@ -0,0 +1,27 @@
|
||||
; bitfield-entry.asm -- M6 bitfield gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack, calls the C
|
||||
; driver bitfield_run() and writes a post-return marker. bitfield.sh
|
||||
; concatenates the compiled driver after this file, so _bitfield_run and its
|
||||
; helpers are in the same assembly.
|
||||
;
|
||||
; The marker array is in .bss (linked at the ram origin); bitfield-check.lua
|
||||
; reads its address from the linker map and checks 62 words (markers 0..61,
|
||||
; the last one written after bitfield_run returns). Marker n is 0x20 bits
|
||||
; above marker n-1, matching one 32-bit value per marker slot.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _bitfield_run
|
||||
movi 5A5A5A5Ah, a0
|
||||
movi _bitfield_markers+1952, a2 ; marker 61, the post-return word
|
||||
move a0, *a2, 1
|
||||
rets
|
||||
|
||||
.globl _bitfield_markers
|
||||
.bss _bitfield_markers, 2048, 16 ; 62 marker words (0x20 bits each)
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
/* M6 bitfield gate driver.
|
||||
*
|
||||
* Every struct below is the 1987 GSP C compiler's packed bitfield layout:
|
||||
* bitfields are allocated LSB-first at the next free bit, with no padding
|
||||
* between adjacent fields and across the 32-bit word boundary; an unnamed
|
||||
* `:0` bitfield is ignored (the oracle's `b` after `a:3; :0` is at bit 3).
|
||||
* Clang's record layout for the target must agree; the _Static_asserts check
|
||||
* the byte-expressible part (sizeof/alignof) and the runtime markers check
|
||||
* the bit offsets by setting each field to a known value, reading it back and
|
||||
* checking the raw storage bytes.
|
||||
*
|
||||
* The structs are volatile so the accesses survive -O2; the marker array is
|
||||
* volatile too. Marker word n lives at bitfield_markers[n], i.e. 0x20 bits
|
||||
* above the previous one; scripts/m6/bitfield-check.lua reads them from the
|
||||
* linker map.
|
||||
*
|
||||
* Raw storage is read little-endian (the target's data layout is `e`): byte 0
|
||||
* holds struct bits 0..7. The 1987 oracle's `g` is `.bss _g,36,16`, and the
|
||||
* object allocator rounds that to 48 bits; the M6 .bss emitter rounds every
|
||||
* object to a 16-bit unit, so a standalone object matches. Arrays, nested
|
||||
* members and pointer arithmetic on a struct whose content is not a whole
|
||||
* byte are the documented divergence:
|
||||
* TI strides by the 36-bit content, Clang by the byte-rounded 5-byte sizeof.
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
|
||||
/* The oracle struct from the Task 5 notes (BITS.C). */
|
||||
struct s {
|
||||
unsigned a:3;
|
||||
unsigned b:5;
|
||||
int c:4;
|
||||
unsigned d:20;
|
||||
unsigned e:4;
|
||||
};
|
||||
|
||||
struct cross { unsigned x:20; unsigned y:20; };
|
||||
struct zw { unsigned a:3; unsigned :0; unsigned b:5; };
|
||||
struct one { int s:1; unsigned u:1; };
|
||||
struct word { unsigned w:32; unsigned v:1; };
|
||||
struct edge { unsigned p:28; unsigned q:8; unsigned r:4; };
|
||||
struct sx { int a:3; unsigned b:2; int c:9; int d:18; };
|
||||
struct sy { int e:30; int f:6; };
|
||||
struct lz { unsigned :0; unsigned a:3; unsigned b:5; };
|
||||
/* A 31-bit field at bit 33 needs an i64 container (LSB-first). */
|
||||
struct l64 { unsigned long long pad:33; unsigned f:31; };
|
||||
struct q64 { unsigned long long q:57; };
|
||||
|
||||
volatile struct s g;
|
||||
volatile struct s g2;
|
||||
volatile struct cross cg;
|
||||
volatile struct zw zg;
|
||||
volatile struct one og;
|
||||
volatile struct word wg;
|
||||
volatile struct edge eg;
|
||||
volatile struct sx sx;
|
||||
volatile struct sy sy;
|
||||
volatile struct lz lz;
|
||||
volatile struct l64 l64g;
|
||||
volatile struct l64 l64h;
|
||||
volatile struct q64 q64g;
|
||||
|
||||
extern volatile u32 bitfield_markers[];
|
||||
|
||||
/* The oracle's sizeof values: 36 bits -> 5 bytes, 40 -> 5, 8 -> 1, 2 -> 1,
|
||||
* 33 -> 5. TI reports the byte-rounded size; Clang must agree. */
|
||||
_Static_assert(sizeof(struct s) == 5, "oracle sizeof(struct s)");
|
||||
_Static_assert(sizeof(struct cross) == 5, "cross is a whole 40-bit word pair");
|
||||
_Static_assert(sizeof(struct zw) == 1, "the :0 is ignored; a+b is 8 bits");
|
||||
_Static_assert(sizeof(struct one) == 1, "two 1-bit fields fit one byte");
|
||||
_Static_assert(sizeof(struct word) == 5, "32+1 bits round to 5 bytes");
|
||||
_Static_assert(sizeof(struct edge) == 5, "28+8+4 bits = 40");
|
||||
_Static_assert(sizeof(struct sx) == 4, "3+2+9+18 bits = 32");
|
||||
_Static_assert(sizeof(struct sy) == 5, "30+6 bits = 36, rounded to 5 bytes");
|
||||
_Static_assert(sizeof(struct lz) == 1, "leading :0 is ignored");
|
||||
_Static_assert(sizeof(struct l64) == 8, "33+31 bits = 64");
|
||||
_Static_assert(sizeof(struct q64) == 8, "57 bits round to 8 bytes");
|
||||
_Static_assert(_Alignof(struct s) == 1, "packed record alignment is 1 byte");
|
||||
|
||||
static u32 raw_byte(volatile void *p, int i)
|
||||
{
|
||||
return ((volatile unsigned char *)p)[i];
|
||||
}
|
||||
|
||||
static u32 raw_word0(volatile void *p)
|
||||
{
|
||||
volatile unsigned char *b = (volatile unsigned char *)p;
|
||||
return (u32)b[0] | ((u32)b[1] << 8) | ((u32)b[2] << 16) |
|
||||
((u32)b[3] << 24);
|
||||
}
|
||||
|
||||
static u32 raw_word1(volatile void *p)
|
||||
{
|
||||
volatile unsigned char *b = (volatile unsigned char *)p;
|
||||
return (u32)b[4] | ((u32)b[5] << 8) | ((u32)b[6] << 16) |
|
||||
((u32)b[7] << 24);
|
||||
}
|
||||
|
||||
static void set_l64(unsigned f) { l64g.f = f; }
|
||||
static unsigned get_l64(void) { return l64g.f; }
|
||||
static void set_q64(unsigned long long q) { q64g.q = q; }
|
||||
static unsigned long long get_q64(void) { return q64g.q; }
|
||||
/* An aggregate copy: at -O2 the optimizer may forward the i64 copy
|
||||
* into the field read, so the memory order must match the IR. */
|
||||
static unsigned copy_l64(struct l64 *dst, struct l64 *src)
|
||||
{
|
||||
*dst = *src;
|
||||
return dst->f;
|
||||
}
|
||||
|
||||
void bitfield_run(void)
|
||||
{
|
||||
volatile struct s *gp = &g2;
|
||||
|
||||
/* The oracle struct: a:3@0, b:5@3, c:4@8 (signed), d:20@12, e:4@32.
|
||||
* Expected bytes: AD ED CD AB 09 (word0 ABCDEDADh, then e in byte 4). */
|
||||
g.a = 5;
|
||||
g.b = 21;
|
||||
g.c = -3;
|
||||
g.d = 0xABCDE;
|
||||
g.e = 9;
|
||||
bitfield_markers[0] = g.a;
|
||||
bitfield_markers[1] = g.b;
|
||||
bitfield_markers[2] = (u32)g.c;
|
||||
bitfield_markers[3] = g.d;
|
||||
bitfield_markers[4] = g.e;
|
||||
bitfield_markers[5] = raw_word0((volatile void *)&g);
|
||||
bitfield_markers[6] = raw_byte((volatile void *)&g, 4);
|
||||
|
||||
/* Signed nibble boundaries: +7 and the minimum -8 must sign-extend. */
|
||||
g.c = 7;
|
||||
bitfield_markers[7] = (u32)g.c;
|
||||
g.c = -8;
|
||||
bitfield_markers[8] = (u32)g.c;
|
||||
|
||||
/* struct cross: y:20 at bit 20 crosses bit 32.
|
||||
* word0 345FEDCBh, byte4 12h. */
|
||||
cg.x = 0xFEDCB;
|
||||
cg.y = 0x12345;
|
||||
bitfield_markers[9] = cg.x;
|
||||
bitfield_markers[10] = cg.y;
|
||||
bitfield_markers[11] = raw_word0((volatile void *)&cg);
|
||||
bitfield_markers[12] = raw_byte((volatile void *)&cg, 4);
|
||||
|
||||
/* struct zw: a:3, unnamed :0 ignored, b:5 at bit 3.
|
||||
* byte 8Bh (a=3 in bits 0..2, b=17 in bits 3..7). */
|
||||
zg.a = 3;
|
||||
zg.b = 17;
|
||||
bitfield_markers[13] = zg.a;
|
||||
bitfield_markers[14] = zg.b;
|
||||
bitfield_markers[15] = raw_byte((volatile void *)&zg, 0);
|
||||
|
||||
/* struct one: the signed 1-bit field is the SEXT1 case (SLL 31/SRA 31).
|
||||
* A 1-bit signed field holds 0 or -1: s=-1,u=1 -> byte 3; s=0,u=1 ->
|
||||
* byte 2; s=-1,u=0 -> byte 1. */
|
||||
og.s = -1;
|
||||
og.u = 1;
|
||||
bitfield_markers[16] = (u32)og.s;
|
||||
bitfield_markers[17] = og.u;
|
||||
bitfield_markers[18] = raw_byte((volatile void *)&og, 0);
|
||||
og.s = 0;
|
||||
og.u = 1;
|
||||
bitfield_markers[19] = (u32)og.s;
|
||||
bitfield_markers[20] = og.u;
|
||||
bitfield_markers[21] = raw_byte((volatile void *)&og, 0);
|
||||
og.s = -1;
|
||||
og.u = 0;
|
||||
bitfield_markers[22] = (u32)og.s;
|
||||
bitfield_markers[23] = og.u;
|
||||
bitfield_markers[24] = raw_byte((volatile void *)&og, 0);
|
||||
|
||||
/* struct word: w:32 at bit 0 (a full-word field) and v:1 at bit 32. */
|
||||
wg.w = 0xDEADBEEF;
|
||||
wg.v = 1;
|
||||
bitfield_markers[25] = wg.w;
|
||||
bitfield_markers[26] = wg.v;
|
||||
bitfield_markers[27] = raw_word0((volatile void *)&wg);
|
||||
bitfield_markers[28] = raw_byte((volatile void *)&wg, 4);
|
||||
|
||||
/* struct edge: q:8 at bit 28 crosses bit 32 (low nibble in word0 bits
|
||||
* 28..31, high nibble in byte4 bits 0..3); r:4 at bit 36.
|
||||
* word0 51234567h, byte4 CAh. */
|
||||
eg.p = 0x1234567;
|
||||
eg.q = 0xA5;
|
||||
eg.r = 0xC;
|
||||
bitfield_markers[29] = eg.p;
|
||||
bitfield_markers[30] = eg.q;
|
||||
bitfield_markers[31] = eg.r;
|
||||
bitfield_markers[32] = raw_word0((volatile void *)&eg);
|
||||
bitfield_markers[33] = raw_byte((volatile void *)&eg, 4);
|
||||
|
||||
/* Signed fields at odd offsets inside one 32-bit word:
|
||||
* a:3@0, b:2@3, c:9@5, d:18@14; word0 80002715h. */
|
||||
sx.a = -3;
|
||||
sx.b = 2;
|
||||
sx.c = -200;
|
||||
sx.d = -131072;
|
||||
bitfield_markers[34] = (u32)sx.a;
|
||||
bitfield_markers[35] = sx.b;
|
||||
bitfield_markers[36] = (u32)sx.c;
|
||||
bitfield_markers[37] = (u32)sx.d;
|
||||
bitfield_markers[38] = raw_word0((volatile void *)&sx);
|
||||
|
||||
/* A signed field crossing the word boundary: e:30@0, f:6@30.
|
||||
* e=-100000000 (-100000000 & 3FFFFFFF = 3A0A1F00h), f=-20 (2Ch: low
|
||||
* two bits 0 in word0 bits 30..31, high nibble Bh in byte4 bits 0..3). */
|
||||
sy.e = -100000000;
|
||||
sy.f = -20;
|
||||
bitfield_markers[39] = (u32)sy.e;
|
||||
bitfield_markers[40] = (u32)sy.f;
|
||||
bitfield_markers[41] = raw_word0((volatile void *)&sy);
|
||||
bitfield_markers[42] = raw_byte((volatile void *)&sy, 4);
|
||||
|
||||
/* The same oracle struct through a pointer, so the access path is a
|
||||
* GEP/load/store rather than a fixed global address.
|
||||
* word0 54321EF1h, byte4 0Fh. */
|
||||
gp->a = 1;
|
||||
gp->b = 30;
|
||||
gp->c = -2;
|
||||
gp->d = 0x54321;
|
||||
gp->e = 15;
|
||||
bitfield_markers[43] = gp->a;
|
||||
bitfield_markers[44] = gp->b;
|
||||
bitfield_markers[45] = (u32)gp->c;
|
||||
bitfield_markers[46] = gp->d;
|
||||
bitfield_markers[47] = gp->e;
|
||||
bitfield_markers[48] = raw_word0((volatile void *)&g2);
|
||||
bitfield_markers[49] = raw_byte((volatile void *)&g2, 4);
|
||||
|
||||
/* A leading unnamed :0 is ignored too: a:3@0, b:5@3, byte 4Eh. */
|
||||
lz.a = 6;
|
||||
lz.b = 9;
|
||||
bitfield_markers[50] = lz.a;
|
||||
bitfield_markers[51] = lz.b;
|
||||
bitfield_markers[52] = raw_byte((volatile void *)&lz, 0);
|
||||
|
||||
/* 64-bit containers: LSW at the lower address. f@33, 31 bits;
|
||||
* raw word0 = pad[0..31], raw word1 = pad[32] | f << 1. */
|
||||
set_l64(0x12345678u);
|
||||
bitfield_markers[53] = get_l64();
|
||||
bitfield_markers[54] = raw_word0((volatile void *)&l64g);
|
||||
bitfield_markers[55] = raw_word1((volatile void *)&l64g);
|
||||
|
||||
/* 57-bit field: LSW = q[0..31], MSW = q[32..56]. */
|
||||
set_q64(0x0123456789ABCDEFull);
|
||||
bitfield_markers[56] = (u32)get_q64();
|
||||
bitfield_markers[57] = raw_word0((volatile void *)&q64g);
|
||||
bitfield_markers[58] = raw_word1((volatile void *)&q64g);
|
||||
|
||||
/* Aggregate copy: GVN may forward the i64 copy into the field read at
|
||||
* -O2, so the memory order must match the IR. (A constant-initialized
|
||||
* i64 aggregate still hits the pre-existing M2 .data limitation at -O0.) */
|
||||
bitfield_markers[59] = copy_l64(&l64h, &l64g);
|
||||
bitfield_markers[60] = raw_word1((volatile void *)&l64h);
|
||||
}
|
||||
Executable
+183
@@ -0,0 +1,183 @@
|
||||
#!/bin/sh
|
||||
# Extract and validate the 1990-11 TMS340 Family SDK floating-point/runtime
|
||||
# libraries for the M6 ABI work.
|
||||
#
|
||||
# scripts/m6/flib-extract.sh
|
||||
#
|
||||
# The 1990 r5.01 Code Generation Tools are OS/2 1.x NE binaries and do not run
|
||||
# under DOSBox, but their TI-COFF libraries are ordinary ar archives. The 1987
|
||||
# GSPA 2.00/GSPLNK 2.00 tools assemble and link them unchanged, `$` symbols
|
||||
# included.
|
||||
#
|
||||
# Outputs (all under build/m6-sdk, which is git-ignored):
|
||||
# flib.lib flibc.lib flibi.lib rts.lib flib.src rts.src
|
||||
# flib-members/ rts-members/ extracted archive members
|
||||
# flib-symbols.txt exact external definitions
|
||||
#
|
||||
# Overridable: M6_SDK_OUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
OUT=${M6_SDK_OUT:-$ROOT/build/m6-sdk}
|
||||
ZIPDIR="$ROOT/vendor/vt1200/tools/tms34010-sdk/1990-11 TMS340 Family SDK"
|
||||
ZIP1="$ZIPDIR/1990-11-19 TMS340 Family Code Generation Tools (1 of 2) r5.01 rev2564062-1641.zip"
|
||||
ZIP2="$ZIPDIR/1990-11-19 TMS340 Family Code Generation Tools (2 of 2) r5.01 rev2564062-1641.zip"
|
||||
|
||||
fail() {
|
||||
echo "m6 flib-extract: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
command -v unzip >/dev/null 2>&1 || fail "unzip is required"
|
||||
command -v ar >/dev/null 2>&1 || fail "ar is required"
|
||||
|
||||
mkdir -p "$OUT"
|
||||
if [ ! -f "$OUT/flib.lib" ] || [ ! -f "$OUT/rts.lib" ]; then
|
||||
[ -f "$ZIP2" ] || fail "1990 SDK archive not found: $ZIP2"
|
||||
unzip -o -q "$ZIP2" -d "$OUT"
|
||||
# The tool archives are not needed to link (the 1987 tools are used), but
|
||||
# extracting them records the exact 1990 release the libraries came from.
|
||||
if [ -f "$ZIP1" ]; then
|
||||
unzip -o -q "$ZIP1" -d "$OUT"
|
||||
fi
|
||||
fi
|
||||
for f in flib.lib flibc.lib flibi.lib rts.lib flib.src rts.src; do
|
||||
[ -f "$OUT/$f" ] || fail "missing $OUT/$f after extraction"
|
||||
done
|
||||
|
||||
extract_members() {
|
||||
lib=$1
|
||||
dir=$OUT/$2
|
||||
rm -rf "$dir"
|
||||
mkdir -p "$dir"
|
||||
(cd "$dir" && ar x "$OUT/$lib")
|
||||
chmod -R u+rw "$dir"
|
||||
}
|
||||
|
||||
extract_members flib.lib flib-members
|
||||
extract_members flibc.lib flibc-members
|
||||
extract_members flibi.lib flibi-members
|
||||
extract_members rts.lib rts-members
|
||||
|
||||
python3 - "$ROOT" "$OUT" <<'PY'
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
root, out = sys.argv[1], sys.argv[2]
|
||||
sys.path.insert(0, os.path.join(root, "vendor", "vt1200", "dwt", "loader"))
|
||||
import coff
|
||||
|
||||
|
||||
def symname(c, sym):
|
||||
"""Return a TI-COFF symbol name, resolving the long-name string table."""
|
||||
d = c["data"]
|
||||
raw = d[c["symptr"] + sym["index"] * 18:][:8]
|
||||
if raw[:4] == b"\0\0\0\0":
|
||||
off = struct.unpack_from("<I", raw, 4)[0]
|
||||
base = c["symptr"] + c["nsyms"] * 18
|
||||
end = d.index(b"\0", base + off)
|
||||
return d[base + off:end].decode("latin1")
|
||||
return raw.rstrip(b"\0").decode("latin1")
|
||||
|
||||
|
||||
lines = [
|
||||
"# 1990-11 TMS340 Family SDK r5.01 external symbol definitions",
|
||||
"# generated by scripts/m6/flib-extract.sh; do not edit",
|
||||
"#",
|
||||
"# flib.lib is the GSP-format floating-point library used by the TI C",
|
||||
"# compiler by default. flibc.lib/flibi.lib are identified as the",
|
||||
"# 34082/IEEE variants from member-code inspection (see the variant",
|
||||
"# section at the end); the 1990 compiler was not run. M6 links flib.lib.",
|
||||
"",
|
||||
]
|
||||
|
||||
for lib, members in (("flib.lib", "flib-members"), ("rts.lib", "rts-members")):
|
||||
lines.append("== %s" % lib)
|
||||
d = os.path.join(out, members)
|
||||
for fn in sorted(os.listdir(d)):
|
||||
c = coff.parse(os.path.join(d, fn))
|
||||
ext = [symname(c, s) for s in c["symbols"]
|
||||
if s["sclass"] == 2 and s["secno"] > 0]
|
||||
if ext:
|
||||
lines.append("%-14s %s" % (fn, " ".join(ext)))
|
||||
lines.append("")
|
||||
|
||||
|
||||
def text_bits(c):
|
||||
for s in c["sections"]:
|
||||
if s["name"] == ".text":
|
||||
return s["size"]
|
||||
return 0
|
||||
|
||||
|
||||
lines.append("== variant inspection (not linked by M6)")
|
||||
for lib, members in (("flib.lib", "flib-members"),
|
||||
("flibc.lib", "flibc-members"),
|
||||
("flibi.lib", "flibi-members")):
|
||||
parts = []
|
||||
for fn in ("fs_add.obj", "fd_add.obj"):
|
||||
c = coff.parse(os.path.join(out, members, fn))
|
||||
parts.append("%s .text %d bits" % (fn, text_bits(c)))
|
||||
lines.append("%-11s %s" % (lib, "; ".join(parts)))
|
||||
lines.extend([
|
||||
"# flibc/flibi are identified as the 34082/IEEE variants from member-code",
|
||||
"# inspection (their members begin with the 34082 path and are larger) and",
|
||||
"# release naming, not by running the OS/2-only 1990 compiler. M6 links",
|
||||
"# flib.lib only.",
|
||||
"",
|
||||
])
|
||||
|
||||
text = "\n".join(lines) + "\n"
|
||||
with open(os.path.join(out, "flib-symbols.txt"), "w") as f:
|
||||
f.write(text)
|
||||
sys.stdout.write(text)
|
||||
PY
|
||||
|
||||
# The exact entries M6 tasks 2/3/6 depend on. If a name is missing the ABI
|
||||
# contract in TMS34010.md/README.md is stale, so fail loudly.
|
||||
for sym in \
|
||||
'FS$ADD' 'FS$SUB' 'FS$SUB_R' 'FS$MUL' 'FS$DIV' 'FS$DIV_R' 'FS$NEG' \
|
||||
'FS$EQ' 'FS$NE' 'FS$LT' 'FS$LE' 'FS$GT' 'FS$GE' 'FS$ZERO' 'FS$INC' \
|
||||
'FS$INCR' 'FS$DEC' 'FS$DECR' \
|
||||
'FD$ADD' 'FD$SUB' 'FD$SUB_R' 'FD$MUL' 'FD$DIV' 'FD$DIV_R' 'FD$NEG' \
|
||||
'FD$EQ' 'FD$NE' 'FD$LT' 'FD$LE' 'FD$GT' 'FD$GE' 'FD$ZERO' 'FD$INC' \
|
||||
'FD$INCR' 'FD$DEC' 'FD$DECR' \
|
||||
'FD$DTOF' 'FD$FTOD' 'FD$FTOI' 'FD$FTOU' 'FD$DTOI' 'FD$DTOU' \
|
||||
'FD$ITOF' 'FD$ITOD' 'FD$UTOF' 'FD$UTOD'
|
||||
do
|
||||
grep -Fq " $sym" "$OUT/flib-symbols.txt" \
|
||||
|| fail "expected flib symbol $sym is missing"
|
||||
done
|
||||
|
||||
# rts.lib is the C runtime, not a 64-bit arithmetic source: M6 task 2 must use
|
||||
# target sequences, not invented helpers. Record that fact as a checked one.
|
||||
if grep -Eiq '(^| )(__ll|_ll|llmul|lldiv|lladd|llsub|\$ll|\$i64|__i64)' "$OUT/flib-symbols.txt"; then
|
||||
fail "unexpected 64-bit helper in flib/rts symbol list; re-check the ABI note"
|
||||
fi
|
||||
|
||||
cat > "$OUT/m6-abi.txt" <<EOF
|
||||
flib ABI (from flib.src and the 1987 C compiler output):
|
||||
* arithmetic: operands are pushed on A14, first operand first, second last;
|
||||
the result is pushed on A14 (one word for FS\$, two for FD\$);
|
||||
* compares: both operands are popped from A14; the boolean is in A8
|
||||
(1 true, 0 false); nothing is pushed;
|
||||
* conversions: FD\$FTOI/FTOU and FD\$DTOI/DTOU pop the float/double from A14
|
||||
and return the integer in A8; FD\$ITOF/UTOF and FD\$ITOD/UTOD take the
|
||||
integer in A8 and push one float / two double words on A14;
|
||||
FD\$FTOD pops a float and pushes two double words, FD\$DTOF pops a double
|
||||
and pushes one float word;
|
||||
* flib routines end in RETS (not RETS 2): pop the pushed result (if any),
|
||||
then restore the caller A14 from the old-STK word saved on the system
|
||||
stack;
|
||||
* flib.lib uses the GSP floating format: 1.5 = 40600000h (float) and
|
||||
00000000h/400C0000h (double, LSW at the lower address);
|
||||
* float arguments are one 32-bit slot (ANSI/FS\$ rule; the 1987 K&R oracle
|
||||
promotes float parameters to double, so it does not pin this slot).
|
||||
|
||||
link line:
|
||||
GSPLNK -l flib.lib -l rts.lib (scripts/m6/link.cmd)
|
||||
|
||||
symbol list: $OUT/flib-symbols.txt
|
||||
EOF
|
||||
cat "$OUT/m6-abi.txt"
|
||||
@@ -0,0 +1,139 @@
|
||||
# 1990-11 TMS340 Family SDK r5.01 external symbol definitions
|
||||
# generated by scripts/m6/flib-extract.sh; do not edit
|
||||
#
|
||||
# flib.lib is the GSP-format floating-point library used by the TI C
|
||||
# compiler by default. flibc.lib/flibi.lib are identified as the
|
||||
# 34082/IEEE variants from member-code inspection (see the variant
|
||||
# section at the end); the 1990 compiler was not run. M6 links flib.lib.
|
||||
|
||||
== flib.lib
|
||||
fc_dtof.obj FD$DTOF
|
||||
fc_dtoi.obj FD$DTOI
|
||||
fc_dtou.obj FD$DTOU
|
||||
fc_ftod.obj FD$FTOD
|
||||
fc_ftoi.obj FD$FTOI
|
||||
fc_ftou.obj FD$FTOU
|
||||
fc_itod.obj FD$ITOD
|
||||
fc_itof.obj FD$ITOF
|
||||
fc_utod.obj FD$UTOD
|
||||
fc_utof.obj FD$UTOF
|
||||
fd_add.obj FD$ADD FD$SUB_R FD$SUB
|
||||
fd_cmp.obj FD$GE FD$LE FD$GT FD$LT
|
||||
fd_decr.obj FD$DECR FD$DEC
|
||||
fd_div.obj FD$DIV_R FD$DIV
|
||||
fd_eq.obj FD$EQ
|
||||
fd_error.obj _fp_error
|
||||
fd_incr.obj FD$INCR FD$INC
|
||||
fd_mul.obj FD$MUL
|
||||
fd_ne.obj FD$NE
|
||||
fd_neg.obj FD$NEG
|
||||
fd_zero.obj FD$ZERO
|
||||
fs_add.obj FS$SUB_R FS$ADD FS$SUB
|
||||
fs_decr.obj FS$DECR FS$DEC
|
||||
fs_div.obj FS$DIV FS$DIV_R
|
||||
fs_eq.obj FS$EQ
|
||||
fs_ge.obj FS$GE
|
||||
fs_gt.obj FS$GT
|
||||
fs_incr.obj FS$INC FS$INCR
|
||||
fs_le.obj FS$LE
|
||||
fs_lt.obj FS$LT
|
||||
fs_mul.obj FS$MUL
|
||||
fs_ne.obj FS$NE
|
||||
fs_neg.obj FS$NEG
|
||||
fs_zero.obj FS$ZERO
|
||||
|
||||
== rts.lib
|
||||
abs.obj _labs _abs
|
||||
asctime.obj _asctime
|
||||
asin.obj _acos _asin
|
||||
atan.obj _atan2 _atan
|
||||
atof.obj _atof
|
||||
atoi.obj _atoi _atol
|
||||
boot.obj _c_int00 __present82
|
||||
bsearch.obj _bsearch
|
||||
check82.obj _check82
|
||||
clock.obj _clock
|
||||
ctime.obj _ctime
|
||||
ctype.obj __ctypes_
|
||||
difftime.obj _difftime
|
||||
div.obj _div _ldiv
|
||||
dtos.obj _dtos
|
||||
ecvt.obj _ecvt
|
||||
errno.obj _errno
|
||||
exit.obj _abort _exit _atexit
|
||||
exp.obj _exp
|
||||
fabs.obj _fabs
|
||||
fconvert.obj _fconvert
|
||||
fcvt.obj _fcvt
|
||||
floor.obj _ceil _floor
|
||||
fmod.obj _fmod
|
||||
frexp.obj _frexp
|
||||
gmtime.obj _gmtime
|
||||
isalnum.obj _isalnum
|
||||
isalpha.obj _isalpha
|
||||
isascii.obj _isascii
|
||||
iscntrl.obj _iscntrl
|
||||
isdigit.obj _isdigit
|
||||
isgraph.obj _isgraph
|
||||
islower.obj _islower
|
||||
isprint.obj _isprint
|
||||
ispunct.obj _ispunct
|
||||
isspace.obj _isspace
|
||||
isupper.obj _isupper
|
||||
isxdigit.obj _isxdigit
|
||||
ldexp.obj _ldexp
|
||||
localtim.obj _localtime
|
||||
log.obj _log _log10
|
||||
ltoa.obj _ltoa
|
||||
memchr.obj _memchr
|
||||
memcmp.obj _memcmp
|
||||
memmov.obj _memmove _memcpy
|
||||
memory.obj _minit _malloc _realloc _free _calloc
|
||||
memset.obj _memset
|
||||
mktime.obj _mktime
|
||||
modf.obj _modf
|
||||
pow.obj _pow
|
||||
qsort.obj _qsort
|
||||
rand.obj _srand _rand
|
||||
scheck.obj s$check
|
||||
setjmp.obj _longjmp __setjmp _setjmp
|
||||
sin.obj _cos _sin
|
||||
sinh.obj _sinh _cosh
|
||||
sqrt.obj _sqrt
|
||||
strcat.obj _strcat
|
||||
strchr.obj _strchr
|
||||
strcmp.obj _strcmp
|
||||
strcoll.obj _strcoll
|
||||
strcpy.obj _strcpy
|
||||
strcspn.obj _strcspn
|
||||
strerror.obj _strerror
|
||||
strftime.obj _strftime
|
||||
strlen.obj _strlen
|
||||
strncat.obj _strncat
|
||||
strncmp.obj _strncmp
|
||||
strncpy.obj _strncpy
|
||||
strpbrk.obj _strpbrk
|
||||
strrchr.obj _strrchr
|
||||
strspn.obj _strspn
|
||||
strstr.obj _strstr
|
||||
strtod.obj _strtod
|
||||
strtok.obj _strtok
|
||||
strtol.obj _strtol
|
||||
strtoul.obj _strtoul
|
||||
strxfrm.obj _strxfrm
|
||||
tan.obj _tan
|
||||
tanh.obj _tanh
|
||||
time.obj _time
|
||||
toascii.obj _toascii
|
||||
tolower.obj _tolower
|
||||
toupper.obj _toupper
|
||||
|
||||
== variant inspection (not linked by M6)
|
||||
flib.lib fs_add.obj .text 2384 bits; fd_add.obj .text 3728 bits
|
||||
flibc.lib fs_add.obj .text 3328 bits; fd_add.obj .text 4864 bits
|
||||
flibi.lib fs_add.obj .text 3328 bits; fd_add.obj .text 4864 bits
|
||||
# flibc/flibi are identified as the 34082/IEEE variants from member-code
|
||||
# inspection (their members begin with the 34082 path and are larger) and
|
||||
# release naming, not by running the OS/2-only 1990 compiler. M6 links
|
||||
# flib.lib only.
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
-- float-check.lua -- read the M6 float/double marker words and compare them
|
||||
-- with the expected GSP bit patterns.
|
||||
--
|
||||
-- FLOAT_MARKERS is the bit address of _float_markers from the linker map. Each
|
||||
-- marker is one 32-bit word at base + n*0x20 bits. Doubles are pairs: LSW
|
||||
-- first (the lower address), MSW second, which is also the GSP memory order.
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
|
||||
dofile(os.getenv("M2_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2900")
|
||||
local BASE = tonumber(os.getenv("FLOAT_MARKERS"), 16)
|
||||
local N = 80
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local expect = {
|
||||
[0] = 0x41400000, -- fadd(1.5,2.5) = 4.0
|
||||
[1] = 0x40400000, -- fsub(2.5,1.5) = 1.0
|
||||
[2] = 0xC0400000, -- fsub(1.5,2.5) = -1.0
|
||||
[3] = 0x41C00000, -- fmul(4.0,2.0) = 8.0
|
||||
[4] = 0x40C00000, -- fdiv(4.0,2.0) = 2.0
|
||||
[5] = 0xC0600000, -- fneg(1.5) = -1.5
|
||||
[6] = 0x41400000, -- C body float_add(1.5,2.5)
|
||||
[7] = 0x40600000, -- C float_ret() = 1.5
|
||||
[8] = 0x00000000, [9] = 0x40280000, -- dadd(1.5,2.5) = 4.0
|
||||
[10] = 0x00000000, [11] = 0x40080000, -- dsub(2.5,1.5) = 1.0
|
||||
[12] = 0x00000000, [13] = 0xC0080000, -- dsub(1.5,2.5) = -1.0
|
||||
[14] = 0x00000000, [15] = 0x40380000, -- dmul(4.0,2.0) = 8.0
|
||||
[16] = 0x00000000, [17] = 0x40180000, -- ddiv(4.0,2.0) = 2.0
|
||||
[18] = 0x00000000, [19] = 0xC00C0000, -- dneg(1.5) = -1.5
|
||||
[20] = 0x00000000, [21] = 0x40280000, -- C double_add(1.5,2.5) = 4.0
|
||||
[22] = 0x00000000, [23] = 0x401A0000, -- C double_ret() = 2.5
|
||||
[24] = 1, -- fcmpeq(1.5,1.5)
|
||||
[25] = 0, -- fcmpeq(1.5,2.5)
|
||||
[26] = 1, -- fcmplt(1.5,2.5)
|
||||
[27] = 0, -- fcmplt(2.5,1.5)
|
||||
[28] = 1, -- fcmple(2.5,2.5)
|
||||
[29] = 1, -- fcmpgt(2.5,1.5)
|
||||
[30] = 0, -- fcmpge(1.5,2.5)
|
||||
[31] = 1, -- fcmpne(1.5,2.5)
|
||||
[32] = 0, -- fcmpne(1.5,1.5)
|
||||
[33] = 1, -- dcmplt(1.5,2.5)
|
||||
[34] = 0, -- dcmplt(2.5,1.5)
|
||||
[35] = 1, -- dcmpeq(2.5,2.5)
|
||||
[36] = 2, -- ftoi(2.5)
|
||||
[37] = 0xFFFFFFFF, -- ftoi(-1.5) = -1
|
||||
[38] = 3, -- ftou(3.9)
|
||||
[39] = 2, -- dtoi(2.5)
|
||||
[40] = 3, -- dtou(3.9)
|
||||
[41] = 0x41700000, -- itof(7) = 7.0
|
||||
[42] = 0x41700000, -- utof(7) = 7.0
|
||||
[43] = 0xC0E00000, -- itof(-3) = -3.0
|
||||
[44] = 0x00000000, [45] = 0x402E0000, -- itod(7) = 7.0
|
||||
[46] = 0x00000000, [47] = 0x402E0000, -- utod(7) = 7.0
|
||||
[48] = 0x00000000, [49] = 0x400C0000, -- ftod(1.5f) = 1.5
|
||||
[50] = 0x40D00000, -- dtof(2.5) = 2.5
|
||||
[51] = 0x41700000, -- constant 7.0f
|
||||
[52] = 0xC0E00000, -- constant -3.0f
|
||||
[53] = 0x00000000, [54] = 0x402E0000, -- constant 7.0
|
||||
[55] = 0x00000000, [56] = 0xC01C0000, -- constant -3.0
|
||||
[57] = 1, -- fcmpge(2.5,2.5)
|
||||
[58] = 0, -- fcmpgt(1.5,1.5)
|
||||
[59] = 0xFFFFFFFF, -- dtoi(-1.5) = -1
|
||||
[60] = 0, -- fcmple(2.5,1.5)
|
||||
[61] = 0, -- dcmpeq(1.5,2.5)
|
||||
[62] = 11, -- fb_lt(1.5,2.5) true path
|
||||
[63] = 22, -- fb_lt(2.5,1.5) false path
|
||||
[64] = 33, -- db_lt(1.5,2.5) true path
|
||||
[65] = 44, -- db_lt(2.5,1.5) false path
|
||||
[66] = 3, -- fcount_lt(1.5,4.0): 1.5,2.5,3.5
|
||||
[67] = 0x00000000, [68] = 0x400C0000, -- dsel_i(1,1.5,2.5) = 1.5
|
||||
[69] = 0x00000000, [70] = 0x401A0000, -- dsel_i(0,1.5,2.5) = 2.5
|
||||
[71] = 0x00000000, [72] = 0x40280000, -- dsel_f(<,4.0,8.0) = 4.0
|
||||
[73] = 0x00000000, [74] = 0x40380000, -- dsel_f(>,4.0,8.0) = 8.0
|
||||
[75] = 0x00000000, -- fnegzero(): GSP canonicalises -0.0
|
||||
[76] = 0x00000000, -- fposzero()
|
||||
[77] = 0x00000000, [78] = 0x00000000, -- dnegzero(): two zero words
|
||||
[79] = 0x5A5A5A5A, -- marker after float_run returns
|
||||
}
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
local bad = 0
|
||||
for i = 0, N - 1 do
|
||||
got[i] = prog:read_u32(BASE + i * 0x20)
|
||||
if got[i] ~= expect[i] then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
io.write(string.format("M6 float:"))
|
||||
for i = 0, N - 1 do
|
||||
io.write(string.format(" %08X", got[i]))
|
||||
end
|
||||
io.write("\n")
|
||||
if bad == 0 then
|
||||
print("M6 FLOAT MAME: PASS")
|
||||
else
|
||||
for i = 0, N - 1 do
|
||||
if got[i] ~= expect[i] then
|
||||
print(string.format(
|
||||
"M6 float: marker %d got %08X want %08X",
|
||||
i, got[i], expect[i]))
|
||||
end
|
||||
end
|
||||
print("M6 FLOAT MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "float-check")
|
||||
@@ -0,0 +1,27 @@
|
||||
; float-entry.asm -- M6 float/double gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack, calls the C
|
||||
; driver float_run() and writes a post-return marker. float.sh concatenates
|
||||
; the llc output for m6-float.ll and the compiled driver after this file, so
|
||||
; _float_run and the float/double functions are in the same assembly.
|
||||
;
|
||||
; The marker array is in .bss (linked at the ram origin); float-check.lua reads
|
||||
; its address from the linker map and checks 80 words (markers 0..79, the last
|
||||
; one written after float_run returns). Marker n is 0x20 bits above marker
|
||||
; n-1, matching one 32-bit value per marker slot.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _float_run
|
||||
movi 5A5A5A5Ah, a0
|
||||
movi _float_markers+2528, a2 ; marker 79, the post-return word
|
||||
move a0, *a2, 1
|
||||
rets
|
||||
|
||||
.globl _float_markers
|
||||
.bss _float_markers, 2560, 16 ; 80 marker words (0x20 bits each)
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
/* M6 float/double gate driver.
|
||||
*
|
||||
* Calls the compiled float/double functions in m6-float.ll through the M6
|
||||
* flib ABI and writes the expected GSP result words to the marker array
|
||||
* defined by the entry assembly. Compiling this driver also exercises the
|
||||
* compiler's caller side (hidden float/double return slot, stack argument
|
||||
* pushes, LSW-first doubles) and the callee side of its own C functions
|
||||
* (float_add, double_add, float_ret, double_ret).
|
||||
*
|
||||
* Values are written as raw GSP words, not converted: a float union member
|
||||
* and an array of two 32-bit words for a GSP double (u[0] = LSW, u[1] = MSW).
|
||||
*
|
||||
* Marker word n lives at float_markers[n], i.e. 0x20 bits above the previous
|
||||
* one; scripts/m6/float-check.lua reads them by bit address from the linker
|
||||
* map.
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
|
||||
typedef union {
|
||||
float f;
|
||||
u32 u;
|
||||
} fu;
|
||||
|
||||
typedef union {
|
||||
double d;
|
||||
u32 u[2];
|
||||
} du;
|
||||
|
||||
extern volatile u32 float_markers[];
|
||||
|
||||
/* Callees defined in m6-float.ll. */
|
||||
extern float fadd(float, float);
|
||||
extern float fsub(float, float);
|
||||
extern float fmul(float, float);
|
||||
extern float fdiv(float, float);
|
||||
extern float fneg(float);
|
||||
extern double dadd(double, double);
|
||||
extern double dsub(double, double);
|
||||
extern double dmul(double, double);
|
||||
extern double ddiv(double, double);
|
||||
extern double dneg(double);
|
||||
extern int fcmpeq(float, float);
|
||||
extern int fcmplt(float, float);
|
||||
extern int fcmple(float, float);
|
||||
extern int fcmpgt(float, float);
|
||||
extern int fcmpge(float, float);
|
||||
extern int fcmpne(float, float);
|
||||
extern int dcmplt(double, double);
|
||||
extern int dcmpeq(double, double);
|
||||
extern int ftoi(float);
|
||||
extern int ftou(float);
|
||||
extern int dtoi(double);
|
||||
extern int dtou(double);
|
||||
extern float itof(int);
|
||||
extern float utof(u32);
|
||||
extern double itod(int);
|
||||
extern double utod(u32);
|
||||
extern double ftod(float);
|
||||
extern float dtof(double);
|
||||
|
||||
/* Control flow on floating-point comparisons. These are the shapes that were
|
||||
* missing: `if (a < b)` on float/double and `?:` on a double. */
|
||||
static int fb_lt(float a, float b)
|
||||
{
|
||||
if (a < b)
|
||||
return 11;
|
||||
return 22;
|
||||
}
|
||||
|
||||
static int db_lt(double a, double b)
|
||||
{
|
||||
if (a < b)
|
||||
return 33;
|
||||
return 44;
|
||||
}
|
||||
|
||||
/* A while loop whose condition is a float compare and whose body is float
|
||||
* arithmetic: a(float) = 1.5, b(float) = 4.0 iterates 1.5, 2.5, 3.5 and stops
|
||||
* at 4.5, so it counts 3. */
|
||||
static int fcount_lt(float a, float b)
|
||||
{
|
||||
int n = 0;
|
||||
while (a < b) {
|
||||
a = a + 1.0f;
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* An f64 select with an integer condition. */
|
||||
static double dsel_i(int c, double x, double y)
|
||||
{
|
||||
return c ? x : y;
|
||||
}
|
||||
|
||||
/* An f64 select with a floating-point condition. */
|
||||
static double dsel_f(double a, double b, double x, double y)
|
||||
{
|
||||
return (a < b) ? x : y;
|
||||
}
|
||||
|
||||
/* GSP has no signed zero: -0.0 must lower to the same all-zero words as +0.0,
|
||||
* exactly as GSPA prints `.float -0.0`. These markers pin that. */
|
||||
static float fnegzero(void)
|
||||
{
|
||||
return -0.0f;
|
||||
}
|
||||
|
||||
static float fposzero(void)
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
static double dnegzero(void)
|
||||
{
|
||||
return -0.0;
|
||||
}
|
||||
|
||||
static void mark_f(u32 n, float v)
|
||||
{
|
||||
fu x;
|
||||
x.f = v;
|
||||
float_markers[n] = x.u;
|
||||
}
|
||||
|
||||
static void mark_d(u32 n, double v)
|
||||
{
|
||||
du x;
|
||||
x.d = v;
|
||||
float_markers[n] = x.u[0]; /* LSW: the lower address in GSP order */
|
||||
float_markers[n + 1] = x.u[1]; /* MSW */
|
||||
}
|
||||
|
||||
/* C-side callees: the compiler must emit the flib calls for these bodies. */
|
||||
float float_add(float a, float b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
double double_add(double a, double b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
float float_ret(void)
|
||||
{
|
||||
return 1.5f;
|
||||
}
|
||||
|
||||
double double_ret(void)
|
||||
{
|
||||
return 2.5;
|
||||
}
|
||||
|
||||
void float_run(void)
|
||||
{
|
||||
/* Single-precision arithmetic, including the reversed subtraction order
|
||||
* and a negative result. */
|
||||
mark_f(0, fadd(1.5f, 2.5f)); /* 4.0 */
|
||||
mark_f(1, fsub(2.5f, 1.5f)); /* 1.0 */
|
||||
mark_f(2, fsub(1.5f, 2.5f)); /* -1.0 */
|
||||
mark_f(3, fmul(4.0f, 2.0f)); /* 8.0 */
|
||||
mark_f(4, fdiv(4.0f, 2.0f)); /* 2.0 */
|
||||
mark_f(5, fneg(1.5f)); /* -1.5 */
|
||||
mark_f(6, float_add(1.5f, 2.5f)); /* C body */
|
||||
mark_f(7, float_ret()); /* C no-argument hidden return */
|
||||
|
||||
/* Double-precision arithmetic, LSW then MSW. */
|
||||
mark_d(8, dadd(1.5, 2.5)); /* 4.0 */
|
||||
mark_d(10, dsub(2.5, 1.5)); /* 1.0 */
|
||||
mark_d(12, dsub(1.5, 2.5)); /* -1.0 */
|
||||
mark_d(14, dmul(4.0, 2.0)); /* 8.0 */
|
||||
mark_d(16, ddiv(4.0, 2.0)); /* 2.0 */
|
||||
mark_d(18, dneg(1.5)); /* -1.5 */
|
||||
mark_d(20, double_add(1.5, 2.5)); /* C body */
|
||||
mark_d(22, double_ret()); /* C no-argument hidden return */
|
||||
|
||||
/* Float compares: true and false cases. */
|
||||
float_markers[24] = (u32)fcmpeq(1.5f, 1.5f);
|
||||
float_markers[25] = (u32)fcmpeq(1.5f, 2.5f);
|
||||
float_markers[26] = (u32)fcmplt(1.5f, 2.5f);
|
||||
float_markers[27] = (u32)fcmplt(2.5f, 1.5f);
|
||||
float_markers[28] = (u32)fcmple(2.5f, 2.5f);
|
||||
float_markers[29] = (u32)fcmpgt(2.5f, 1.5f);
|
||||
float_markers[30] = (u32)fcmpge(1.5f, 2.5f);
|
||||
float_markers[31] = (u32)fcmpne(1.5f, 2.5f);
|
||||
float_markers[32] = (u32)fcmpne(1.5f, 1.5f);
|
||||
|
||||
/* Double compares. */
|
||||
float_markers[33] = (u32)dcmplt(1.5, 2.5);
|
||||
float_markers[34] = (u32)dcmplt(2.5, 1.5);
|
||||
float_markers[35] = (u32)dcmpeq(2.5, 2.5);
|
||||
|
||||
/* float/double -> integer: truncation toward zero. */
|
||||
float_markers[36] = (u32)ftoi(2.5f); /* 2 */
|
||||
float_markers[37] = (u32)ftoi(-1.5f); /* -1 */
|
||||
float_markers[38] = (u32)ftou(3.9f); /* 3 */
|
||||
float_markers[39] = (u32)dtoi(2.5); /* 2 */
|
||||
float_markers[40] = (u32)dtou(3.9); /* 3 */
|
||||
|
||||
/* integer -> float/double. */
|
||||
mark_f(41, itof(7)); /* 7.0 */
|
||||
mark_f(42, utof(7)); /* 7.0 */
|
||||
mark_f(43, itof(-3)); /* -3.0 */
|
||||
mark_d(44, itod(7)); /* 7.0 */
|
||||
mark_d(46, utod(7)); /* 7.0 */
|
||||
mark_d(48, ftod(1.5f)); /* 1.5 */
|
||||
mark_f(50, dtof(2.5)); /* 2.5 */
|
||||
|
||||
/* Constants materialised from the GSP pool, including a negative one. */
|
||||
mark_f(51, 7.0f);
|
||||
mark_f(52, -3.0f);
|
||||
mark_d(53, 7.0);
|
||||
mark_d(55, -3.0);
|
||||
|
||||
float_markers[57] = (u32)fcmpge(2.5f, 2.5f); /* 1 */
|
||||
float_markers[58] = (u32)fcmpgt(1.5f, 1.5f); /* 0 */
|
||||
float_markers[59] = (u32)dtoi(-1.5); /* -1 */
|
||||
float_markers[60] = (u32)fcmple(2.5f, 1.5f); /* 0 */
|
||||
float_markers[61] = (u32)dcmpeq(1.5, 2.5); /* 0 */
|
||||
|
||||
/* Control flow on float/double comparisons: the true and false path of a
|
||||
* float and a double branch, and a float-compared while loop. */
|
||||
float_markers[62] = (u32)fb_lt(1.5f, 2.5f); /* true: 11 */
|
||||
float_markers[63] = (u32)fb_lt(2.5f, 1.5f); /* false: 22 */
|
||||
float_markers[64] = (u32)db_lt(1.5, 2.5); /* true: 33 */
|
||||
float_markers[65] = (u32)db_lt(2.5, 1.5); /* false: 44 */
|
||||
float_markers[66] = (u32)fcount_lt(1.5f, 4.0f); /* 3 iterations */
|
||||
|
||||
/* ?: on a double, with an integer and a floating-point condition. */
|
||||
mark_d(67, dsel_i(1, 1.5, 2.5)); /* 1.5 */
|
||||
mark_d(69, dsel_i(0, 1.5, 2.5)); /* 2.5 */
|
||||
mark_d(71, dsel_f(1.5, 2.5, 4.0, 8.0)); /* 4.0 */
|
||||
mark_d(73, dsel_f(2.5, 1.5, 4.0, 8.0)); /* 8.0 */
|
||||
|
||||
/* Signed zero: both spellings lower to all-zero GSP words. */
|
||||
mark_f(75, fnegzero()); /* 0 */
|
||||
mark_f(76, fposzero()); /* 0 */
|
||||
mark_d(77, dnegzero()); /* 0 / 0 */
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
-- i64-check.lua -- read the M6 i64 marker words and compare them with the
|
||||
-- expected ABI/arithmetic values.
|
||||
--
|
||||
-- I64_MARKERS is the bit address of _i64_markers from the linker map. Each
|
||||
-- marker is one 32-bit word at base + n*0x20 bits. The values are pairs:
|
||||
-- MSW first, LSW second, so the word order is checked as well as the result.
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
|
||||
dofile(os.getenv("M2_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2900")
|
||||
local BASE = tonumber(os.getenv("I64_MARKERS"), 16)
|
||||
local N = 57
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local expect = {
|
||||
[0] = 0x2345678A, [1] = 0x00000001, -- addll(carry)
|
||||
[2] = 0x00000000, [3] = 0xACF13568, -- addll(12345678h,9ABCDEF0h)
|
||||
[4] = 0xFEDCBA98, [5] = 0x00000005, -- subll borrow
|
||||
[6] = 0x0000000A, [7] = 0x00000008, -- mull cross terms
|
||||
[8] = 0xFFFFFFFF, [9] = 0xFFFFFFF1, -- (-3)*5
|
||||
[10] = 0x00010004, [11] = 0xC016906B, -- divll / 1234h
|
||||
[12] = 0x00000000, [13] = 0x00000334, -- remll / 1234h
|
||||
[14] = 0x00000000, [15] = 0x10000000, -- divll by a >32-bit divisor
|
||||
[16] = 0x00000000, [17] = 0x0ABCDEF0, -- remll by a >32-bit divisor
|
||||
[18] = 0xFFFFFFDE, [19] = 0xBD0CFDB7, -- sdivll(-1e12, 7)
|
||||
[20] = 0xFFFFFFFF, [21] = 0xFFFFFFFF, -- sremll(-1e12, 7) == -1
|
||||
[22] = 0xFFFFFFFF, [23] = 0xFFFFFFEF, -- sdivll(123, -7) == -17
|
||||
[24] = 0x00000000, [25] = 0x00000004, -- sremll(123, -7) == 4
|
||||
[26] = 0x00000100, [27] = 0x00000000, -- 1 << 40
|
||||
[28] = 0x00000000, [29] = 0x00000001, -- 8000000000000000h >> 63
|
||||
[30] = 0xFFFFFFFF, [31] = 0xFFFFFFFC, -- -16 >> 2
|
||||
[32] = 1, [33] = 0, -- cmplt(-1,1), cmplt(1,-1)
|
||||
[34] = 1, [35] = 0, -- cmpeq both halves
|
||||
[36] = 0x00000006, [37] = 0x00000004, -- i64_slot LSW/MSW word order
|
||||
[38] = 0x00000004, [39] = 0x00000006, -- i64 load round-trip
|
||||
[40] = 0x0F0F0000, [41] = 0x0F0F0000, -- and
|
||||
[42] = 0xFFFF0F0F, [43] = 0xFFFF0F0F, -- or
|
||||
[44] = 0xF0F00F0F, [45] = 0xF0F00F0F, -- xor
|
||||
[46] = 0x11223344, [47] = 0x55667788, -- zero-argument i64 return
|
||||
[48] = 0x11223344, [49] = 0x55667788, -- shll(x, 0)
|
||||
[50] = 0x55667788, [51] = 0x00000000, -- shll(x, 32)
|
||||
[52] = 0x00000000, [53] = 0x11223344, -- srl(x, 32)
|
||||
[54] = 0xFFFFFFFF, [55] = 0x80000000, -- sra(8000..., 32)
|
||||
[56] = 0x5A5A5A5A, -- marker after i64_run returns
|
||||
}
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
local bad = 0
|
||||
for i = 0, N - 1 do
|
||||
got[i] = prog:read_u32(BASE + i * 0x20)
|
||||
if got[i] ~= expect[i] then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
io.write(string.format("M6 i64:"))
|
||||
for i = 0, N - 1 do
|
||||
io.write(string.format(" %08X", got[i]))
|
||||
end
|
||||
io.write("\n")
|
||||
if bad == 0 then
|
||||
print("M6 I64 MAME: PASS")
|
||||
else
|
||||
for i = 0, N - 1 do
|
||||
if got[i] ~= expect[i] then
|
||||
print(string.format(
|
||||
"M6 i64: marker %d got %08X want %08X",
|
||||
i, got[i], expect[i]))
|
||||
end
|
||||
end
|
||||
print("M6 I64 MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "i64-check")
|
||||
@@ -0,0 +1,27 @@
|
||||
; i64-entry.asm -- M6 i64 gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack, calls the C
|
||||
; driver i64_run() and writes a post-return marker. i64.sh concatenates the
|
||||
; llc output for m6-i64.ll and the compiled driver after this file, so
|
||||
; _i64_run and the i64 functions are in the same assembly.
|
||||
;
|
||||
; The marker array is in .bss (linked at the ram origin); i64-check.lua reads
|
||||
; its address from the linker map and checks 57 words (markers 0..56, the last
|
||||
; one written after i64_run returns). Marker n is 0x20 bits above marker n-1,
|
||||
; matching one 32-bit value per marker slot.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _i64_run
|
||||
movi 5A5A5A5Ah, a0
|
||||
movi _i64_markers+1792, a2 ; marker 56, the post-return word
|
||||
move a0, *a2, 1
|
||||
rets
|
||||
|
||||
.globl _i64_markers
|
||||
.bss _i64_markers, 2048, 16 ; 57 marker words (0x20 bits each)
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/* M6 i64 gate driver.
|
||||
*
|
||||
* Calls the compiled `long long` functions in m6-i64.ll through the M6 ABI and
|
||||
* writes the expected result words to the marker array defined by the entry
|
||||
* assembly. Compiling this driver also exercises the compiler's *caller*
|
||||
* side of the hidden-return slot and the two-slot i64 argument pushes; the
|
||||
* callee side (argument reads, ADD/ADDC, MPYS/MPYU, the division loop, RETS 2)
|
||||
* comes from the same llc output the lit test checks.
|
||||
*
|
||||
* Marker word n lives at i64_markers[n], i.e. 0x20 bits above the previous
|
||||
* one; scripts/m6/i64-check.lua reads them by bit address from the linker map.
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef long long s64;
|
||||
|
||||
extern u64 addll(u64, u64);
|
||||
extern u64 subll(u64, u64);
|
||||
extern u64 mull(u64, u64);
|
||||
extern u64 divll(u64, u64);
|
||||
extern u64 remll(u64, u64);
|
||||
extern s64 sdivll(s64, s64);
|
||||
extern s64 sremll(s64, s64);
|
||||
extern u64 andll(u64, u64);
|
||||
extern u64 orll(u64, u64);
|
||||
extern u64 xorll(u64, u64);
|
||||
extern u64 shll(u64, u32);
|
||||
extern u64 srl(u64, u32);
|
||||
extern s64 sra(s64, u32);
|
||||
extern u32 cmplt(s64, s64);
|
||||
extern u32 cmpeq(u64, u64);
|
||||
extern u64 ret64(void);
|
||||
|
||||
extern volatile u32 i64_markers[];
|
||||
|
||||
/* Every value is written as MSW first, LSW second, so the marker pair pins
|
||||
* the word order as well as the numeric result. */
|
||||
static void mark64(u32 n, u64 v)
|
||||
{
|
||||
i64_markers[n] = (u32)(v >> 32);
|
||||
i64_markers[n + 1] = (u32)v;
|
||||
}
|
||||
|
||||
/* i64 memory order: little-endian, LSW at the lower address. */
|
||||
volatile u64 i64_slot;
|
||||
|
||||
void i64_run(void)
|
||||
{
|
||||
u64 r;
|
||||
|
||||
/* addll(12345678FFFFFFFEh, 1111111100000003h) = 2345678A00000001h.
|
||||
* This is the Task 1 probe value; the low-word carry must reach the
|
||||
* high word. */
|
||||
mark64(0, addll(0x12345678FFFFFFFEull, 0x1111111100000003ull));
|
||||
|
||||
/* The literal brief case addll(12345678h, 9ABCDEF0h) = ACF13568h. */
|
||||
mark64(2, addll(0x12345678ull, 0x9ABCDEF0ull));
|
||||
|
||||
/* subll(1111111100000003h, 12345678FFFFFFFEh) = FEDCBA9800000005h:
|
||||
* the borrow crosses from the low into the high word. */
|
||||
mark64(4, subll(0x1111111100000003ull, 0x12345678FFFFFFFEull));
|
||||
|
||||
/* mull(0000000100000002h, 0000000300000004h) = 0000000A00000008h:
|
||||
* both cross terms are needed. */
|
||||
mark64(6, mull(0x0000000100000002ull, 0x0000000300000004ull));
|
||||
|
||||
/* (-3) * 5 = -15 = FFFFFFFFFFFFFFF1h. */
|
||||
mark64(8, mull(0xFFFFFFFFFFFFFFFDull, 5ull));
|
||||
|
||||
/* 123456789ABCDEF0h / 1234h = 10004C016906Bh, remainder 334h. */
|
||||
mark64(10, divll(0x123456789ABCDEF0ull, 0x1234ull));
|
||||
mark64(12, remll(0x123456789ABCDEF0ull, 0x1234ull));
|
||||
|
||||
/* A divisor above 32 bits forces the full 64x64 path:
|
||||
* 123456789ABCDEF0h / 123456789h = 100000000h, remainder ABCDEF0h. */
|
||||
mark64(14, divll(0x123456789ABCDEF0ull, 0x123456789ull));
|
||||
mark64(16, remll(0x123456789ABCDEF0ull, 0x123456789ull));
|
||||
|
||||
/* Signed division truncates toward zero: -1000000000000 / 7 =
|
||||
* -142857142857 = FFFFFFDEBD0CFDB7h, remainder -1. */
|
||||
mark64(18, (u64)sdivll(-1000000000000ll, 7ll));
|
||||
mark64(20, (u64)sremll(-1000000000000ll, 7ll));
|
||||
|
||||
/* 123 / -7 = -17 = FFFFFFFFh/FFFFFFEFh, remainder 4. */
|
||||
mark64(22, (u64)sdivll(123ll, -7ll));
|
||||
mark64(24, (u64)sremll(123ll, -7ll));
|
||||
|
||||
/* Variable-amount shifts: 1 << 40 = 10000000000h. */
|
||||
mark64(26, shll(1ull, 40));
|
||||
/* 8000000000000000h >> 63 = 1. */
|
||||
mark64(28, srl(0x8000000000000000ull, 63));
|
||||
/* -16 >> 2 = -4 = FFFFFFFFFFFFFFFCh (arithmetic). */
|
||||
mark64(30, (u64)sra(-16ll, 2));
|
||||
|
||||
/* Compares: signed high-half ordering and equality across both halves. */
|
||||
i64_markers[32] = cmplt(-1ll, 1ll);
|
||||
i64_markers[33] = cmplt(1ll, -1ll);
|
||||
i64_markers[34] = cmpeq(0x123456789ABCDEF0ull, 0x123456789ABCDEF0ull);
|
||||
i64_markers[35] = cmpeq(0x123456789ABCDEF1ull, 0x123456789ABCDEF0ull);
|
||||
|
||||
/* i64 store then load through a volatile object, plus a direct word
|
||||
* read: little-endian memory puts the LSW at the lower address. */
|
||||
i64_slot = addll(0x0000000100000002ull, 0x0000000300000004ull);
|
||||
{
|
||||
volatile u32 *w = (volatile u32 *)&i64_slot;
|
||||
i64_markers[36] = w[0];
|
||||
i64_markers[37] = w[1];
|
||||
}
|
||||
r = i64_slot;
|
||||
mark64(38, r);
|
||||
|
||||
/* Word-wise logic: and/or/xor of both halves. */
|
||||
mark64(40, andll(0xFFFF0000FFFF0000ull, 0x0F0F0F0F0F0F0F0Full));
|
||||
mark64(42, orll(0xFFFF0000FFFF0000ull, 0x0F0F0F0F0F0F0F0Full));
|
||||
mark64(44, xorll(0xFFFF0000FFFF0000ull, 0x0F0F0F0F0F0F0F0Full));
|
||||
|
||||
/* A zero-argument i64 return: the caller still saves STK for the hidden
|
||||
* slot and the callee must LOADSTK + RETS 2 with no argument area. */
|
||||
mark64(46, ret64());
|
||||
|
||||
/* Variable-shift edges: 0, 32, and the arithmetic sign fill. */
|
||||
mark64(48, shll(0x1122334455667788ull, 0));
|
||||
mark64(50, shll(0x1122334455667788ull, 32));
|
||||
mark64(52, srl(0x1122334455667788ull, 32));
|
||||
mark64(54, (u64)sra(0x8000000000000000ull, 32));
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 8000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
-- runtime-check.lua -- read the M6 runtime gate marker words and the shim's
|
||||
-- printf output block, and compare them with the expected values.
|
||||
--
|
||||
-- RUNTIME_MARKERS is the bit address of _runtime_markers from the linker map;
|
||||
-- each marker is one 32-bit word at base + n*0x20 bits. The shim's CONF
|
||||
-- output block is fixed: length at 01B00020h, bytes at 01B10000h (one byte per
|
||||
-- 8 bits). The checker compares the whole output byte-for-byte, including the
|
||||
-- newlines, so the format implementation is the runtime oracle.
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
|
||||
dofile(os.getenv("M2_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "3400")
|
||||
local BASE = tonumber(os.getenv("RUNTIME_MARKERS"), 16)
|
||||
local LEN_ADDR = 0x01B00020
|
||||
local OUT = 0x01B10000
|
||||
local CAP = 16384
|
||||
local N = 13 -- markers 0..12 are written by the driver
|
||||
local SENT = 15 -- marker 15 is written after runtime_run returns
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local expect = {
|
||||
[0] = 31, -- printf("%d %s %f %lld\n", ...) length
|
||||
[1] = 9, -- sprintf("%d|%s|%.1f", 7, "abc", 2.5) length
|
||||
[2] = 19, -- sprintf("%lld", 1234567890123456789) length
|
||||
[3] = 300, -- sprintf truncation: full length, not the stored one
|
||||
[4] = 255, -- strlen after truncation (SPRINTF_CAP-1)
|
||||
[5] = 1, -- the truncated buffer is NUL-terminated
|
||||
[6] = 4, -- (int)(1.5 + 2.5), flib FD$ADD + FD$DTOI
|
||||
[7] = 3, -- (int)(1.5 * 2.5), flib FD$MUL + FD$DTOI
|
||||
[8] = 1, -- memcpy result equals the source
|
||||
[9] = 1, -- overlapping memmove forward ("aabcdef")
|
||||
[10] = 1, -- overlapping memmove backward ("3456567")
|
||||
[11] = 17, -- printf("S[%s] (%d)\n", ...) length
|
||||
[12] = 1, -- rts.lib _isascii('A') nonzero, (0xC8) zero
|
||||
}
|
||||
|
||||
local lines = {
|
||||
"-42 hi 3.250000 -1234567890123",
|
||||
"[ 42][-0042][7 ][+5][ 5][ff][0xff][10][010][ abc]",
|
||||
"c=[ A][B ][C]",
|
||||
"9223372036854775807 -9223372036854775808 " ..
|
||||
"18446744073709551615 0 -1 4294967295 " ..
|
||||
"[-0000000000000000005]",
|
||||
"int=[-123456789][123456789abcdef0][110642547423257157360][00042][42 ]",
|
||||
"-3.250000 -3.25 3 1.3 3.25 3.25 +3.250000",
|
||||
"0.000000|00003.25|0.00| 3.25| 3.250000|3.|3.250000",
|
||||
"cap=2147483520.000000",
|
||||
"prec=[010][][][][][][0][0][ ]",
|
||||
"round=10.000000 ncap=-2147483520.000000",
|
||||
"S[7|abc|2.5] (9)",
|
||||
"T(300,255,1)",
|
||||
"mem=abcdefg abcdefg",
|
||||
"mov=aabcdef",
|
||||
"mov2=3456567",
|
||||
"rts=1",
|
||||
"flib 4.000000 3.750000",
|
||||
}
|
||||
local want_out = table.concat(lines, "\n") .. "\n"
|
||||
|
||||
local function read_string(space, addr, len)
|
||||
local s = {}
|
||||
for i = 0, len - 1 do
|
||||
s[#s + 1] = string.char(space:read_u8(addr + i * 8))
|
||||
end
|
||||
return table.concat(s)
|
||||
end
|
||||
|
||||
local function escape(s)
|
||||
return (s:gsub("\n", "\\n"))
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
local bad = 0
|
||||
for i = 0, N - 1 do
|
||||
got[i] = prog:read_u32(BASE + i * 0x20)
|
||||
if got[i] ~= expect[i] then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
got[SENT] = prog:read_u32(BASE + SENT * 0x20)
|
||||
if got[SENT] ~= 0x5A5A5A5A then
|
||||
bad = bad + 1
|
||||
end
|
||||
|
||||
io.write(string.format("M6 runtime:"))
|
||||
for i = 0, N - 1 do
|
||||
io.write(string.format(" %08X", got[i]))
|
||||
end
|
||||
io.write(string.format(" %08X\n", got[SENT]))
|
||||
|
||||
local len = prog:read_u32(LEN_ADDR)
|
||||
if len > CAP then
|
||||
print(string.format("M6 runtime: output length %d > cap %d",
|
||||
len, CAP))
|
||||
bad = bad + 1
|
||||
len = 0
|
||||
end
|
||||
local out = read_string(prog, OUT, len)
|
||||
print(string.format("M6 runtime out(%d): '%s'", len, escape(out)))
|
||||
if out ~= want_out then
|
||||
local diff = 1
|
||||
while diff <= #out and diff <= #want_out and
|
||||
out:sub(diff, diff) == want_out:sub(diff, diff) do
|
||||
diff = diff + 1
|
||||
end
|
||||
print(string.format(
|
||||
"M6 runtime: output differs at byte %d: got '%s' want '%s'",
|
||||
diff, escape(out:sub(diff, diff + 20)),
|
||||
escape(want_out:sub(diff, diff + 20))))
|
||||
bad = bad + 1
|
||||
end
|
||||
|
||||
if bad == 0 then
|
||||
print("M6 RUNTIME MAME: PASS")
|
||||
else
|
||||
for i = 0, N - 1 do
|
||||
if got[i] ~= expect[i] then
|
||||
print(string.format(
|
||||
"M6 runtime: marker %d got %08X want %08X",
|
||||
i, got[i], expect[i]))
|
||||
end
|
||||
end
|
||||
if got[SENT] ~= 0x5A5A5A5A then
|
||||
print(string.format(
|
||||
"M6 runtime: sentinel got %08X want 5A5A5A5A",
|
||||
got[SENT]))
|
||||
end
|
||||
print("M6 RUNTIME MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "runtime-check")
|
||||
@@ -0,0 +1,37 @@
|
||||
; runtime-entry.asm -- M6 runtime gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack, calls the C
|
||||
; driver runtime_run() and writes a post-return marker. runtime.sh
|
||||
; concatenates the compiled driver and the shared conformance shim after this
|
||||
; file, so _runtime_run, printf/sprintf and the string/memory functions share
|
||||
; one assembly.
|
||||
;
|
||||
; The marker array is in .bss (linked at the ram origin); runtime-check.lua
|
||||
; reads its address from the linker map and checks 13 words (0..12 written by
|
||||
; the driver), 15 after runtime_run returns, and leaves 13..14 zero/unchecked.
|
||||
; Marker n is 0x20 bits above marker n-1.
|
||||
;
|
||||
; The shim's printf output goes to its own CONF_* block above the linked RAM
|
||||
; region (length at 01B00020h, bytes at 01B10000h); the checker compares those
|
||||
; bytes with the expected text.
|
||||
;
|
||||
; GSPA requires `.ref` for an external symbol used by CALLA. The AsmPrinter
|
||||
; emits it for the flib `$` ExternalSymbols but not for an ordinary C
|
||||
; declaration (a GlobalAddress), so declare the rts.lib entry here.
|
||||
.ref _isascii
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _runtime_run
|
||||
movi 5A5A5A5Ah, a0
|
||||
movi _runtime_markers+480, a2 ; marker 15, the post-return word
|
||||
move a0, *a2, 1
|
||||
rets
|
||||
|
||||
.globl _runtime_markers
|
||||
.bss _runtime_markers, 512, 16 ; 16 marker words (0x20 bits each)
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
/* M6 runtime gate driver.
|
||||
*
|
||||
* Exercises the linked M6 runtime surface through the shared shim:
|
||||
* - printf("%d %s %f %lld", ...) with a negative int, a string, a GSP double
|
||||
* with a fraction, and a negative 64-bit value;
|
||||
* - the M5 integer formats/flags/width/alternate forms;
|
||||
* - i64/unsigned-i64 boundaries, %ld/%lu and a zero-padded %lld;
|
||||
* - %f sign/space/plus/zero/width/precision, star width/precision, and the
|
||||
* documented half-up rounding of %.0f / %.1f;
|
||||
* - sprintf return values (C: the full untruncated length), NUL
|
||||
* termination, and safe truncation at the shim's SPRINTF_CAP;
|
||||
* - memcpy and memmove, including an overlapping backward copy;
|
||||
* - a double add and multiply that must call flib.lib (FD$ADD/FD$MUL) and be
|
||||
* converted back to an int by the compiler's fptosi path (FD$DTOI).
|
||||
*
|
||||
* The shim writes printf output to the CONF_* block (0x01B00020 length,
|
||||
* 0x01B10000 bytes); runtime-check.lua compares those bytes exactly with the
|
||||
* expected text. Marker word n is runtime_markers[n], 0x20 bits apart, in the
|
||||
* .bss array defined by runtime-entry.asm.
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
|
||||
extern volatile u32 runtime_markers[];
|
||||
|
||||
extern int printf(const char *fmt, ...);
|
||||
extern int sprintf(char *buf, const char *fmt, ...);
|
||||
extern void *memcpy(void *dst, const void *src, unsigned int n);
|
||||
extern void *memmove(void *dst, const void *src, unsigned int n);
|
||||
extern int memcmp(const void *a, const void *b, unsigned int n);
|
||||
extern unsigned int strlen(const char *s);
|
||||
/* A real rts.lib scalar entry (isascii.obj; no data/.cinit dependency). The
|
||||
* 1990 `_div`/`_ldiv` wrappers also live in rts.lib but return div_t/ldiv_t
|
||||
* with the 1990 sret form, not M6's 1987 hidden slot, so calling them would
|
||||
* not be valid M6 ABI evidence. */
|
||||
extern int rts_isascii(int c) __asm__("isascii");
|
||||
|
||||
void runtime_run(void)
|
||||
{
|
||||
char sbuf[256]; /* the shim's sprintf cap (SPRINTF_CAP) */
|
||||
char lng[301];
|
||||
char m1[8] = "abcdefg";
|
||||
char m2[8];
|
||||
char m3[8] = "1234567";
|
||||
volatile double a = 1.5; /* volatile: keep FD$ADD/FD$MUL at -O2 */
|
||||
volatile double b = 2.5;
|
||||
double d, e;
|
||||
int i, n;
|
||||
|
||||
/* 1. The required mixed conversion: int, string, GSP double, i64. */
|
||||
runtime_markers[0] = (u32)printf("%d %s %f %lld\n",
|
||||
-42, "hi", 3.25,
|
||||
-1234567890123LL);
|
||||
|
||||
/* 2. M5 flags/width/alternate plus the new %s precision and width. */
|
||||
printf("[%5d][%05d][%-5d][%+d][% d][%x][%#x][%o][%#o][%8.3s]\n",
|
||||
42, -42, 7, 5, 5, 255, 255, 8, 8, "abcdef");
|
||||
|
||||
/* 2b. %c honours width/left; a bare %c is unchanged. */
|
||||
printf("c=[%3c][%-3c][%c]\n", 'A', 'B', 'C');
|
||||
|
||||
/* 3. i64/unsigned-i64 boundaries, 32-bit long, zero-padded i64. */
|
||||
printf("%lld %lld %llu %llu %lld %lu [%020lld]\n",
|
||||
9223372036854775807LL, (-9223372036854775807LL - 1),
|
||||
0xFFFFFFFFFFFFFFFFULL, 0ULL, -1LL, 0xFFFFFFFFUL, -5LL);
|
||||
|
||||
/* 3b. %ld, 64-bit hex/octal, integer precision and a negative `*`
|
||||
* width (left-justify with the magnitude of the width). */
|
||||
printf("int=[%ld][%llx][%llo][%.5d][%*d]\n",
|
||||
-123456789L, 0x123456789ABCDEF0ULL,
|
||||
0x123456789ABCDEF0ULL, 42, -6, 42);
|
||||
|
||||
/* 4. %f sign/flags/width/precision; %.0f and %.1f round half-up. */
|
||||
printf("%f %.2f %.0f %.1f %10.2f %-10.2f %+f\n",
|
||||
-3.25, -3.25, 2.5, 1.25, 3.25, 3.25, 3.25);
|
||||
|
||||
/* 5. Zero, zero-padded, star width/precision, space and '#' flags;
|
||||
* %.9f proves the documented 6-digit precision cap. */
|
||||
printf("%f|%08.2f|%.2f|%*.*f|% f|%#.0f|%.9f\n",
|
||||
0.0, 3.25, -0.0, 7, 2, 3.25, 3.25, 2.5, 3.25);
|
||||
|
||||
/* 5b. The documented i32-range cap: an out-of-range magnitude is clamped
|
||||
* instead of taking FD$DTOI's error path. */
|
||||
printf("cap=%f\n", 3000000000.0);
|
||||
|
||||
/* 5c. C precision edge cases: the octal '#' must not add a second
|
||||
* leading zero when precision already supplies one, and zero with
|
||||
* precision 0 produces no digits (except `%#.0o`/`%#o`, which keep
|
||||
* one). */
|
||||
printf("prec=[%#.3o][%.0d][%.0i][%.0u][%.0x][%.0X][%#.0o][%#o][%5.0d]\n",
|
||||
8, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
/* 5d. Rounding carry through the fraction into the integer part
|
||||
* (9.9999999 -> 10.000000) and the negative magnitude clamp. */
|
||||
printf("round=%f ncap=%f\n", 9.9999999, -3000000000.0);
|
||||
|
||||
/* sprintf into the caller buffer and print it; the return is the
|
||||
* C number of characters written (no NUL). */
|
||||
n = sprintf(sbuf, "%d|%s|%.1f", 7, "abc", 2.5);
|
||||
runtime_markers[1] = (u32)n;
|
||||
runtime_markers[11] = (u32)printf("S[%s] (%d)\n", sbuf, n);
|
||||
|
||||
/* sprintf return value at the 64-bit boundary (19 digits). */
|
||||
runtime_markers[2] = (u32)sprintf(sbuf, "%lld",
|
||||
1234567890123456789LL);
|
||||
|
||||
/* sprintf truncation: 300 characters into the 256-byte shim cap. */
|
||||
for (i = 0; i < 300; i++)
|
||||
lng[i] = 'a';
|
||||
lng[300] = 0;
|
||||
n = sprintf(sbuf, "%s", lng);
|
||||
runtime_markers[3] = (u32)n;
|
||||
runtime_markers[4] = strlen(sbuf);
|
||||
runtime_markers[5] = (u32)(sbuf[255] == 0);
|
||||
printf("T(%d,%u,%d)\n", n, strlen(sbuf), sbuf[255] == 0);
|
||||
|
||||
/* memcpy; then memmove in both directions (overlapping ranges). */
|
||||
memcpy(m2, m1, 8);
|
||||
runtime_markers[8] = (u32)(memcmp(m2, m1, 8) == 0);
|
||||
printf("mem=%s %s\n", m2, m1);
|
||||
memmove(m1 + 1, m1, 6);
|
||||
runtime_markers[9] = (u32)(memcmp(m1, "aabcdef", 8) == 0);
|
||||
printf("mov=%s\n", m1);
|
||||
memmove(m3, m3 + 2, 4);
|
||||
runtime_markers[10] = (u32)(memcmp(m3, "3456567", 8) == 0);
|
||||
printf("mov2=%s\n", m3);
|
||||
|
||||
/* rts.lib is linked for real: _isascii is a scalar entry with the TI ABI
|
||||
* (the 1990 _div/_ldiv wrappers are sret-form and are not called). */
|
||||
i = (rts_isascii('A') != 0) && (rts_isascii(0xC8) == 0);
|
||||
runtime_markers[12] = (u32)i;
|
||||
printf("rts=%d\n", i);
|
||||
|
||||
/* flib.lib double arithmetic, formatted back through %f. The volatile
|
||||
* operands keep the add/multiply from folding at -O2, so both levels
|
||||
* link and call the real FD$ entries. */
|
||||
d = a + b;
|
||||
e = a * b;
|
||||
runtime_markers[6] = (u32)(int)d;
|
||||
runtime_markers[7] = (u32)(int)e;
|
||||
printf("flib %f %f\n", d, e);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
-- spike-check.lua -- load the M6 ABI-spike COFF with dwt/loader/loader.lua and
|
||||
-- read the marker words written by scripts/m6/spike-probe.asm and
|
||||
-- spike-entry.asm.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_END loader inspection/exit frame
|
||||
--
|
||||
-- Markers (0x20 bits apart) are the M4 marker convention:
|
||||
-- 018A8000 FS$ADD float 4.0 (GSP) == 41400000h
|
||||
-- 018A8020 FD$ADD double 4.0 MSW (GSP) == 40280000h
|
||||
-- 018A8040 FD$ADD double 4.0 LSW == 00000000h
|
||||
-- 018A8060 _m6_dadd hidden-return MSW == 40280000h
|
||||
-- 018A8080 _m6_dadd hidden-return LSW == 00000000h
|
||||
-- 018A80A0 i64 sum high word == 2345678Ah
|
||||
-- 018A80C0 i64 sum low word == 00000001h
|
||||
-- 018A80E0 FS$SUB(2.5,1.5) float 1.0 == 40400000h
|
||||
-- 018A8100 FS$EQ(1.5,1.5) boolean in A8 == 00000001h
|
||||
-- 018A8120 FD$FTOI(1.5) integer in A8 == 00000001h
|
||||
-- 018A8140 FD$ITOF(1) float 1.0 pushed on A14 == 40400000h
|
||||
-- 018A8160 _m6_fadd hidden-return float 4.0 == 41400000h
|
||||
-- 018A8180 _start marker after _m6_probe returns == 5A5A5A5Ah
|
||||
|
||||
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, 12 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format(
|
||||
"M6: fs_add=%08X fd_add=%08X/%08X dadd=%08X/%08X i64=%08X/%08X fsub=%08X feq=%d ftoi=%d itof=%08X fadd=%08X ret=%08X",
|
||||
m[0], m[1], m[2], m[3], m[4], m[5], m[6],
|
||||
m[7], m[8], m[9], m[10], m[11], m[12]))
|
||||
local want = {
|
||||
0x41400000, -- FS$ADD 1.5 + 2.5
|
||||
0x40280000, -- FD$ADD 4.0 MSW
|
||||
0x00000000, -- FD$ADD 4.0 LSW
|
||||
0x40280000, -- hidden-return 4.0 MSW
|
||||
0x00000000, -- hidden-return 4.0 LSW
|
||||
0x2345678A, -- i64 sum high
|
||||
0x00000001, -- i64 sum low
|
||||
0x40400000, -- FS$SUB(2.5,1.5) = 1.0
|
||||
0x00000001, -- FS$EQ(1.5,1.5) = true in A8
|
||||
0x00000001, -- FD$FTOI(1.5) = 1 in A8
|
||||
0x40400000, -- FD$ITOF(1) = float 1.0 pushed on A14
|
||||
0x41400000, -- _m6_fadd hidden-return 4.0
|
||||
0x5A5A5A5A, -- _start after _m6_probe returns
|
||||
}
|
||||
local ok = true
|
||||
for i = 0, 12 do
|
||||
if m[i] ~= want[i + 1] then
|
||||
ok = false
|
||||
end
|
||||
end
|
||||
if ok then
|
||||
print("M6 MAME: PASS")
|
||||
else
|
||||
print("M6 MAME: FAIL (want fs_add=41400000 fd_add=40280000/00000000 dadd=40280000/00000000 i64=2345678A/00000001 fsub=40400000 feq=1 ftoi=1 itof=40400000 fadd=41400000 ret=5A5A5A5A)")
|
||||
end
|
||||
end
|
||||
end, "m6-check")
|
||||
@@ -0,0 +1,25 @@
|
||||
; spike-entry.asm -- M6 ABI spike entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the spike stack and calls the
|
||||
; hand-written probe. The probe is assembly because the compiler does not
|
||||
; support float/i64 calls until tasks 2/3.
|
||||
;
|
||||
; scripts/m6/spike-probe.asm the FS$/FD$ and i64 stack probes
|
||||
; scripts/m6/spike-check.lua the MAME marker check
|
||||
; scripts/tests/m6/spike.sh assemble, link with flib.lib/rts.lib, run
|
||||
;
|
||||
; FS0 is 16 and FS1 is 32 with the field-extension bit set, exactly as the M2
|
||||
; ABI requires. A13 is FP and A14 is STK. spike.sh concatenates
|
||||
; spike-probe.asm after this file, so _m6_probe is defined in the same assembly.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _m6_probe
|
||||
move a8, @018A8180h, 1 ; marker after the probe returns
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,274 @@
|
||||
; spike-probe.asm -- M6 float/double/i64 stack-ABI probe.
|
||||
;
|
||||
; The M6 compiler does not lower float/double or i64 calls yet (tasks 2/3), so
|
||||
; this probe is hand-written assembly that exercises the TI C stack ABI and
|
||||
; the 1990 SDK flib.lib entry points directly:
|
||||
;
|
||||
; 1. FS$ADD(1.5, 2.5) single-precision float, GSP format
|
||||
; 2. FD$ADD(1.5, 2.5) double precision, GSP format
|
||||
; 3. _m6_dadd(1.5, 2.5) a C-ABI double function with a caller-allocated
|
||||
; hidden 8-byte return slot; it calls FD$ADD
|
||||
; 4. _m6_i64_add two 32-bit argument words per i64 argument and a
|
||||
; caller-allocated hidden 8-byte return slot
|
||||
; 5. FS$SUB(2.5, 1.5) pins the arithmetic push order (2.5 first)
|
||||
; 6. FS$EQ(1.5, 1.5) compare result in A8, not on A14
|
||||
; 7. FD$FTOI/FD$ITOF integer conversion in A8 / float push on A14
|
||||
; 8. _m6_fadd(1.5,2.5) a C-ABI float function with a one-word hidden slot
|
||||
; 9. a marker after _m6_probe returns, so a broken A14 restore/RETS fails
|
||||
;
|
||||
; Results are written at the M4 marker addresses (0x20 bits apart) for
|
||||
; scripts/m6/spike-check.lua:
|
||||
;
|
||||
; 018A8000 FS$ADD float 4.0 == 41400000h (GSP)
|
||||
; 018A8020 FD$ADD double 4.0 most-significant word == 40280000h (GSP)
|
||||
; 018A8040 FD$ADD double 4.0 least-significant word == 00000000h
|
||||
; 018A8060 _m6_dadd hidden-return MSW == 40280000h
|
||||
; 018A8080 _m6_dadd hidden-return LSW == 00000000h
|
||||
; 018A80A0 i64 sum high word == 2345678Ah
|
||||
; 018A80C0 i64 sum low word == 00000001h
|
||||
; 018A80E0 FS$SUB(2.5,1.5) float 1.0 == 40400000h
|
||||
; 018A8100 FS$EQ(1.5,1.5) boolean in A8 == 00000001h
|
||||
; 018A8120 FD$FTOI(1.5) integer in A8 == 00000001h
|
||||
; 018A8140 FD$ITOF(1) float 1.0 pushed on A14 == 40400000h
|
||||
; 018A8160 _m6_fadd hidden-return float 4.0 == 41400000h
|
||||
; 018A8180 _start marker after _m6_probe returns == 5A5A5A5Ah
|
||||
;
|
||||
; 1990 flib.lib is the GSP-format library (flibc.lib/flibi.lib are the
|
||||
; 34082/IEEE variants by member inspection, not linked here). A GSP double is
|
||||
; stored least-significant word first:
|
||||
; the lower stack address holds the mantissa word, the higher address holds the
|
||||
; sign/exponent word. The M6 i64 stack-slot order is MSW-first, so its
|
||||
; most-significant word is at the lower address.
|
||||
FP .set A13
|
||||
STK .set A14
|
||||
|
||||
.ref FS$ADD
|
||||
.ref FS$SUB
|
||||
.ref FS$EQ
|
||||
.ref FD$ADD
|
||||
.ref FD$FTOI
|
||||
.ref FD$ITOF
|
||||
.text
|
||||
.globl _m6_probe
|
||||
_m6_probe:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
move a14, -*sp, 1 ; preserve the probe's entry STK
|
||||
move a13, -*sp, 1 ; preserve the probe's entry FP
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 1. FS$ADD: 1.5 + 2.5 == 4.0 (one 32-bit slot per float, GSP format)
|
||||
; ---------------------------------------------------------------------------
|
||||
move a14, -*sp, 1 ; flib uses RETS, not RETS 2
|
||||
movi 040600000h, a0 ; 1.5
|
||||
move a0, *a14+, 1
|
||||
movi 040D00000h, a0 ; 2.5
|
||||
move a0, *a14+, 1
|
||||
calla FS$ADD
|
||||
move -*a14, a8, 1 ; result 4.0
|
||||
move *sp+, a14, 1 ; restore STK
|
||||
move a8, @018A8000h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 2. FD$ADD: 1.5 + 2.5 == 4.0 (two 32-bit slots per double, GSP format).
|
||||
; GSP puts the least-significant (mantissa) word at the lower address, so
|
||||
; push it first; the sign/exponent word is the top of the operand.
|
||||
; ---------------------------------------------------------------------------
|
||||
move a14, -*sp, 1
|
||||
clr a0 ; 1.5 LSW
|
||||
move a0, *a14+, 1
|
||||
movi 0400C0000h, a0 ; 1.5 MSW
|
||||
move a0, *a14+, 1
|
||||
clr a0 ; 2.5 LSW
|
||||
move a0, *a14+, 1
|
||||
movi 0401A0000h, a0 ; 2.5 MSW
|
||||
move a0, *a14+, 1
|
||||
calla FD$ADD
|
||||
move -*a14, a0, 1 ; result MSW (top)
|
||||
move -*a14, a1, 1 ; result LSW
|
||||
move *sp+, a14, 1
|
||||
move a0, @018A8020h, 1
|
||||
move a1, @018A8040h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 3. _m6_dadd(1.5, 2.5): the caller reserves the 8-byte return slot at the top
|
||||
; of its frame, then saves STK, then pushes the arguments. The callee
|
||||
; writes the result at saved_STK-64 (LSW) and saved_STK-32 (MSW).
|
||||
; ---------------------------------------------------------------------------
|
||||
addi 64, a14 ; caller-allocated return slot
|
||||
move a14, -*sp, 1 ; save STK for the callee
|
||||
clr a0 ; b=2.5 LSW
|
||||
move a0, *a14+, 1
|
||||
movi 0401A0000h, a0 ; b=2.5 MSW
|
||||
move a0, *a14+, 1
|
||||
clr a0 ; a=1.5 LSW
|
||||
move a0, *a14+, 1
|
||||
movi 0400C0000h, a0 ; a=1.5 MSW
|
||||
move a0, *a14+, 1
|
||||
calla _m6_dadd
|
||||
move -*a14, a0, 1 ; result MSW (saved_STK-32)
|
||||
move -*a14, a1, 1 ; result LSW (saved_STK-64)
|
||||
move a0, @018A8060h, 1
|
||||
move a1, @018A8080h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 4. _m6_i64_add(12345678FFFFFFFEh, 1111111100000003h) == 2345678A00000001h.
|
||||
; Each i64 argument is two 32-bit slots, most-significant word first; the
|
||||
; return is the 8-byte caller-allocated slot (MSW at saved_STK-64, LSW at
|
||||
; saved_STK-32).
|
||||
; ---------------------------------------------------------------------------
|
||||
addi 64, a14 ; caller-allocated i64 return slot
|
||||
move a14, -*sp, 1
|
||||
movi 011111111h, a0 ; b high
|
||||
move a0, *a14+, 1
|
||||
movi 3, a0 ; b low
|
||||
move a0, *a14+, 1
|
||||
movi 012345678h, a0 ; a high
|
||||
move a0, *a14+, 1
|
||||
movi 0FFFFFFFEh, a0 ; a low
|
||||
move a0, *a14+, 1
|
||||
calla _m6_i64_add
|
||||
move -*a14, a0, 1 ; result low (saved_STK-32)
|
||||
move -*a14, a1, 1 ; result high (saved_STK-64)
|
||||
move a1, @018A80A0h, 1
|
||||
move a0, @018A80C0h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 5. FS$SUB(2.5, 1.5) == 1.0. The first operand is pushed first; the library
|
||||
; pops the second (top) and subtracts it from the first. Reversing the
|
||||
; push order would yield -1.0 (C0400000h), so this pins the order.
|
||||
; ---------------------------------------------------------------------------
|
||||
move a14, -*sp, 1
|
||||
movi 040D00000h, a0 ; 2.5 (first)
|
||||
move a0, *a14+, 1
|
||||
movi 040600000h, a0 ; 1.5 (second)
|
||||
move a0, *a14+, 1
|
||||
calla FS$SUB
|
||||
move -*a14, a0, 1 ; result 1.0
|
||||
move *sp+, a14, 1
|
||||
move a0, @018A80E0h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 6. FS$EQ(1.5, 1.5) -> A8=1. A compare pops both operands and does not push
|
||||
; a result; the boolean is in A8.
|
||||
; ---------------------------------------------------------------------------
|
||||
move a14, -*sp, 1
|
||||
movi 040600000h, a0 ; 1.5
|
||||
move a0, *a14+, 1
|
||||
move a0, *a14+, 1
|
||||
calla FS$EQ
|
||||
move *sp+, a14, 1 ; compare popped both; no result push
|
||||
move a8, @018A8100h, 1 ; boolean true
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 7. FD$FTOI(1.5) -> A8=1 (float input on A14, integer result in A8), then
|
||||
; FD$ITOF(1) -> float 1.0 pushed on A14 (integer input in A8).
|
||||
; ---------------------------------------------------------------------------
|
||||
move a14, -*sp, 1
|
||||
movi 040600000h, a0 ; 1.5
|
||||
move a0, *a14+, 1
|
||||
calla FD$FTOI
|
||||
move *sp+, a14, 1 ; input popped; no result push
|
||||
move a8, @018A8120h, 1 ; integer 1
|
||||
move a14, -*sp, 1 ; A8 still holds 1
|
||||
calla FD$ITOF
|
||||
move -*a14, a0, 1 ; result float 1.0 = 40400000h
|
||||
move *sp+, a14, 1
|
||||
move a0, @018A8140h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 8. _m6_fadd(1.5, 2.5): the caller reserves a one-word return slot
|
||||
; (ADDI 32,STK), the callee writes it at saved_STK-32 and RETS 2.
|
||||
; ---------------------------------------------------------------------------
|
||||
addi 32, a14 ; caller-allocated float return slot
|
||||
move a14, -*sp, 1
|
||||
movi 040D00000h, a0 ; b=2.5
|
||||
move a0, *a14+, 1
|
||||
movi 040600000h, a0 ; a=1.5
|
||||
move a0, *a14+, 1
|
||||
calla _m6_fadd
|
||||
move -*a14, a0, 1 ; result 4.0 (saved_STK-32)
|
||||
move a0, @018A8160h, 1
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; 9. Return a known A8 after all A14 save/restore pairs. spike-entry.asm
|
||||
; stores it after CALLA _m6_probe, so a broken restore or RETS cannot pass.
|
||||
; ---------------------------------------------------------------------------
|
||||
movi 05A5A5A5Ah, a8
|
||||
move *sp+, a13, 1 ; restore entry FP
|
||||
move *sp+, a14, 1 ; restore entry STK
|
||||
rets
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; _m6_dadd: double dadd(double a, double b) with the TI C hidden-return rule.
|
||||
; a at FP(-64)=LSW, FP(-32)=MSW; b at FP(-128)=LSW, FP(-96)=MSW
|
||||
; result at saved_STK-64=LSW, saved_STK-32=MSW
|
||||
; ---------------------------------------------------------------------------
|
||||
.globl _m6_dadd
|
||||
_m6_dadd:
|
||||
mmtm sp, a0, a1, a2
|
||||
move a13, -*sp, 1
|
||||
move a14, a13
|
||||
move *a13(-64), *a14+, 1 ; a LSW
|
||||
move *a13(-32), *a14+, 1 ; a MSW
|
||||
move *a13(-128), *a14+, 1 ; b LSW
|
||||
move *a13(-96), *a14+, 1 ; b MSW
|
||||
calla FD$ADD
|
||||
move -*a14, a2, 1 ; result MSW
|
||||
move -*a14, a1, 1 ; result LSW
|
||||
move *sp(160), a14, 1 ; caller's saved STK (3 regs+FP+PC)
|
||||
move a14, a0
|
||||
subi 64, a0
|
||||
move a1, *a0+, 1 ; LSW at saved_STK-64
|
||||
move a2, *a0, 1 ; MSW at saved_STK-32
|
||||
move *sp+, a13, 1
|
||||
mmfm sp, a0, a1, a2
|
||||
rets 2
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; _m6_fadd: float fadd(float a, float b) with the TI C hidden-return rule.
|
||||
; One 32-bit slot per float: a at FP(-32), b at FP(-64).
|
||||
; result at saved_STK-32.
|
||||
; ---------------------------------------------------------------------------
|
||||
.globl _m6_fadd
|
||||
_m6_fadd:
|
||||
mmtm sp, a0, a1
|
||||
move a13, -*sp, 1
|
||||
move a14, a13
|
||||
move *a13(-32), *a14+, 1 ; a
|
||||
move *a13(-64), *a14+, 1 ; b
|
||||
calla FS$ADD
|
||||
move -*a14, a1, 1 ; result
|
||||
move *sp(128), a14, 1 ; caller's saved STK (2 regs+FP+PC)
|
||||
move a14, a0
|
||||
subi 32, a0
|
||||
move a1, *a0, 1 ; result at saved_STK-32
|
||||
move *sp+, a13, 1
|
||||
mmfm sp, a0, a1
|
||||
rets 2
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; _m6_i64_add: long long add(long long a, long long b), hidden 8-byte return.
|
||||
; a high at FP(-64), a low at FP(-32); b high at FP(-128), b low at FP(-96).
|
||||
; The caller pushes b high, b low, a high, a low, so the pop order is
|
||||
; a low, a high, b low, b high.
|
||||
; ---------------------------------------------------------------------------
|
||||
.globl _m6_i64_add
|
||||
_m6_i64_add:
|
||||
mmtm sp, a0, a1, a2, a3
|
||||
move a13, -*sp, 1
|
||||
move a14, a13
|
||||
move -*a14, a2, 1 ; a low
|
||||
move -*a14, a1, 1 ; a high
|
||||
move -*a14, a0, 1 ; b low
|
||||
move -*a14, a3, 1 ; b high
|
||||
add a0, a2 ; low = a low + b low, sets carry
|
||||
addc a3, a1 ; high = a high + b high + carry
|
||||
move *sp(192), a14, 1 ; caller's saved STK (4 regs+FP+PC)
|
||||
move a14, a0
|
||||
subi 64, a0
|
||||
move a1, *a0+, 1 ; high at saved_STK-64
|
||||
move a2, *a0, 1 ; low at saved_STK-32
|
||||
move *sp+, a13, 1
|
||||
mmfm sp, a0, a1, a2, a3
|
||||
rets 2
|
||||
@@ -0,0 +1,87 @@
|
||||
-- varargs-check.lua -- read the M6 varargs marker words and the formatted
|
||||
-- output buffer, and compare them with the expected values.
|
||||
--
|
||||
-- VARARGS_MARKERS is the bit address of _varargs_markers from the linker map;
|
||||
-- each marker is one 32-bit word at base + n*0x20 bits. VARARGS_OUT is the
|
||||
-- bit address of the C driver's `char varargs_out[64]`; the checker reads the
|
||||
-- bytes of the expected string (TMS34010 memory is byte-addressed at the low
|
||||
-- end of a bit address, one byte per 8 bits).
|
||||
--
|
||||
-- The marker read runs one frame before loader.lua's inspection/exit frame.
|
||||
|
||||
dofile(os.getenv("M2_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2900")
|
||||
local BASE = tonumber(os.getenv("VARARGS_MARKERS"), 16)
|
||||
local OUT = tonumber(os.getenv("VARARGS_OUT"), 16)
|
||||
local N = 15
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local expect = {
|
||||
[0] = 100, -- vsum(4, 10, 20, 30, 40): int walk
|
||||
[1] = 42, -- vlong(0, 42): long is one slot
|
||||
[2] = 1, -- vptr(0, 0x12345678): char * is one slot
|
||||
[3] = 2, -- vdbl(0, 2.5): GSP double, MSW at the top
|
||||
[4] = 0x9ABCDEF0, -- vll(0, 123456789ABCDEF0h): i64 LSW at the top
|
||||
[5] = 257, -- mixed_di(0, 2.5, 7): double then int
|
||||
[6] = 0x5566BD76, -- mixed_llp(0, 1122334455667788h, CAFEh)
|
||||
[7] = 13, -- vcopy(0, 4, 5, 6): va_copy independence
|
||||
[8] = 24, -- vforward(3, 7, 8, 9): forwarded va_list
|
||||
[9] = 11, -- vnoargs(11): no fixed argument
|
||||
[10] = 77, -- vlastd(1.5, 77): double last fixed argument
|
||||
[11] = 4, -- myfmt("n=%d", -7) length
|
||||
[12] = 19, -- myfmt("v=%d s=%s d=%f", ...) length
|
||||
[13] = 2, -- call_vf32(): one-slot f32 va_arg
|
||||
[14] = 0x5A5A5A5A, -- marker after varargs_run returns
|
||||
}
|
||||
|
||||
local want_out = "v=42 s=hello d=3.25"
|
||||
|
||||
local function read_string(space, addr, len)
|
||||
local s = {}
|
||||
for i = 0, len - 1 do
|
||||
s[#s + 1] = string.char(space:read_u8(addr + i * 8))
|
||||
end
|
||||
return table.concat(s)
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local got = {}
|
||||
local bad = 0
|
||||
for i = 0, N - 1 do
|
||||
got[i] = prog:read_u32(BASE + i * 0x20)
|
||||
if got[i] ~= expect[i] then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
io.write(string.format("M6 varargs:"))
|
||||
for i = 0, N - 1 do
|
||||
io.write(string.format(" %08X", got[i]))
|
||||
end
|
||||
io.write("\n")
|
||||
local out = read_string(prog, OUT, #want_out)
|
||||
print(string.format("M6 varargs out: '%s'", out))
|
||||
if out ~= want_out then
|
||||
print(string.format("M6 varargs: output got '%s' want '%s'",
|
||||
out, want_out))
|
||||
bad = bad + 1
|
||||
end
|
||||
if bad == 0 then
|
||||
print("M6 VARARGS MAME: PASS")
|
||||
else
|
||||
for i = 0, N - 1 do
|
||||
if got[i] ~= expect[i] then
|
||||
print(string.format(
|
||||
"M6 varargs: marker %d got %08X want %08X",
|
||||
i, got[i], expect[i]))
|
||||
end
|
||||
end
|
||||
print("M6 VARARGS MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "varargs-check")
|
||||
@@ -0,0 +1,28 @@
|
||||
; varargs-entry.asm -- M6 varargs gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack, calls the C
|
||||
; driver varargs_run() and writes a post-return marker. varargs.sh
|
||||
; concatenates the llc output for m6-varargs.ll and the compiled driver after
|
||||
; this file, so _varargs_run and the variadic functions share one assembly.
|
||||
;
|
||||
; The marker array is in .bss (linked at the ram origin); varargs-check.lua
|
||||
; reads its address from the linker map and checks 15 words (markers 0..14, the
|
||||
; last one written after varargs_run returns). Marker n is 0x20 bits above
|
||||
; marker n-1. varargs_out is the formatted-output buffer defined by the C
|
||||
; driver (zero-initialized .bss); the checker also reads its bytes.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _varargs_run
|
||||
movi 5A5A5A5Ah, a0
|
||||
movi _varargs_markers+448, a2 ; marker 14, the post-return word
|
||||
move a0, *a2, 1
|
||||
rets
|
||||
|
||||
.globl _varargs_markers
|
||||
.bss _varargs_markers, 512, 16 ; 15 marker words (0x20 bits each)
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M6.OUT
|
||||
-m M6.MAP
|
||||
-e _start
|
||||
M6.OBJ
|
||||
-l flib.lib
|
||||
-l rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/* M6 varargs gate driver.
|
||||
*
|
||||
* Calls the compiled variadic functions in m6-varargs.ll through the TI
|
||||
* all-stack ABI and writes the expected result words to the marker array
|
||||
* defined by the entry assembly. Compiling this driver exercises the
|
||||
* compiler's own caller side (variadic call pushes) and callee side (a real
|
||||
* __builtin_va_list walk in myfmt, including a GSP double read).
|
||||
*
|
||||
* myfmt is the `%d %s %f` style output: it walks its va_list downward and
|
||||
* writes "v=42 s=hello d=3.25" into varargs_out. The MAME checker compares
|
||||
* those bytes exactly, so the formatted text is the runtime oracle for the
|
||||
* int, pointer (string) and double va_arg paths in one call.
|
||||
*
|
||||
* Marker word n lives at varargs_markers[n], i.e. 0x20 bits above the
|
||||
* previous one; scripts/m6/varargs-check.lua reads them by bit address from
|
||||
* the linker map.
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef long long s64;
|
||||
|
||||
extern volatile u32 varargs_markers[];
|
||||
|
||||
/* Callees defined in m6-varargs.ll. The driver and the .ll must agree on the
|
||||
* argument sequence; the IR signatures are the authoritative side.
|
||||
*
|
||||
* `vnoargs` is really `int vnoargs(...)`. ISO C cannot declare a variadic
|
||||
* function with no named parameter, so the driver declares a variadic
|
||||
* prototype with one int. The call site is variadic (so the caller saves STK,
|
||||
* which is what a variadic callee needs), and the callee treats that pushed
|
||||
* word as its first variadic argument. The declaration must not be used for
|
||||
* any other callee. */
|
||||
extern int vsum(int, ...);
|
||||
extern int vlong(int, ...);
|
||||
extern char *vptr(int, ...);
|
||||
extern int vdbl(int, ...);
|
||||
extern int vll(int, ...);
|
||||
extern int mixed_di(int, ...);
|
||||
extern int mixed_llp(int, ...);
|
||||
extern int vcopy(int, ...);
|
||||
extern int vforward(int, ...);
|
||||
extern int vnoargs(int, ...);
|
||||
extern int vlastd(double, ...);
|
||||
extern int call_vf32(void);
|
||||
|
||||
char varargs_out[64];
|
||||
|
||||
static int outn;
|
||||
|
||||
static void out_char(char c)
|
||||
{
|
||||
if (outn < 64)
|
||||
varargs_out[outn++] = c;
|
||||
}
|
||||
|
||||
static void out_str(const char *s)
|
||||
{
|
||||
while (*s)
|
||||
out_char(*s++);
|
||||
}
|
||||
|
||||
static void out_num(int v)
|
||||
{
|
||||
char tmp[12];
|
||||
int n = 0;
|
||||
unsigned int uv;
|
||||
|
||||
if (v < 0) {
|
||||
out_char('-');
|
||||
uv = ~(unsigned int)v + 1U;
|
||||
} else {
|
||||
uv = (unsigned int)v;
|
||||
}
|
||||
if (uv == 0)
|
||||
tmp[n++] = '0';
|
||||
while (uv) {
|
||||
tmp[n++] = (char)('0' + uv % 10);
|
||||
uv /= 10;
|
||||
}
|
||||
while (n--)
|
||||
out_char(tmp[n]);
|
||||
}
|
||||
|
||||
/* printf-shaped variadic callee using the real va_list: %d, %s and %f with
|
||||
* two fraction digits. The double is converted through the flib ftoi path, so
|
||||
* this also exercises a float-to-int conversion on a variadic value. */
|
||||
int myfmt(const char *fmt, ...)
|
||||
{
|
||||
__builtin_va_list ap;
|
||||
const char *p;
|
||||
|
||||
__builtin_va_start(ap, fmt);
|
||||
outn = 0;
|
||||
for (p = fmt; *p; p++) {
|
||||
if (*p != '%') {
|
||||
out_char(*p);
|
||||
continue;
|
||||
}
|
||||
p++;
|
||||
switch (*p) {
|
||||
case 'd': {
|
||||
int v = __builtin_va_arg(ap, int);
|
||||
out_num(v);
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
char *s = __builtin_va_arg(ap, char *);
|
||||
out_str(s);
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
double d = __builtin_va_arg(ap, double);
|
||||
int scaled = (int)(d * 100.0);
|
||||
int frac = scaled % 100;
|
||||
|
||||
out_num(scaled / 100);
|
||||
out_char('.');
|
||||
if (frac < 10)
|
||||
out_char('0');
|
||||
out_num(frac);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
out_char('%');
|
||||
out_char(*p);
|
||||
break;
|
||||
}
|
||||
}
|
||||
__builtin_va_end(ap);
|
||||
return outn;
|
||||
}
|
||||
|
||||
void varargs_run(void)
|
||||
{
|
||||
/* int walk over a fixed argument plus four variadic ints. */
|
||||
varargs_markers[0] = (u32)vsum(4, 10, 20, 30, 40);
|
||||
|
||||
/* long (one slot). */
|
||||
varargs_markers[1] = (u32)vlong(0, 42);
|
||||
|
||||
/* char * (one slot): compare the returned bit address. */
|
||||
varargs_markers[2] = (u32)(vptr(0, (char *)0x12345678UL) ==
|
||||
(char *)0x12345678UL);
|
||||
|
||||
/* double (two slots, MSW at the higher address): 2.5 -> 2. */
|
||||
varargs_markers[3] = (u32)vdbl(0, 2.5);
|
||||
|
||||
/* long long (two slots, LSW at the higher address): low word. */
|
||||
varargs_markers[4] = (u32)vll(0, 0x123456789ABCDEF0LL);
|
||||
|
||||
/* Mixed sequences: double then int, and i64 then pointer. */
|
||||
varargs_markers[5] = (u32)mixed_di(0, 2.5, 7);
|
||||
varargs_markers[6] = (u32)mixed_llp(0, 0x1122334455667788LL,
|
||||
(char *)0xCAFEUL);
|
||||
|
||||
/* va_copy: ap reads 4 then 5; aq still reads 4 independently. */
|
||||
varargs_markers[7] = (u32)vcopy(0, 4, 5, 6);
|
||||
|
||||
/* A callee forwarding its va_list to vsum_walk. */
|
||||
varargs_markers[8] = (u32)vforward(3, 7, 8, 9);
|
||||
|
||||
/* No fixed argument: the first pushed word is the first va_arg. */
|
||||
varargs_markers[9] = (u32)vnoargs(11);
|
||||
|
||||
/* A double last fixed argument (two slots) before the variadic area. */
|
||||
varargs_markers[10] = (u32)vlastd(1.5, 77);
|
||||
|
||||
/* An f32 va_arg: one GSP word (the C caller cannot pass a promoted
|
||||
* float, so call_vf32 is the hand-written IR caller). */
|
||||
varargs_markers[13] = (u32)call_vf32();
|
||||
|
||||
/* The %d path with a negative value, then the %d %s %f output. */
|
||||
varargs_markers[11] = (u32)myfmt("n=%d", -7);
|
||||
varargs_markers[12] = (u32)myfmt("v=%d s=%s d=%f", 42, "hello", 3.25);
|
||||
}
|
||||
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 --scale 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)"
|
||||
Loaded 100 of 157 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user