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 |
No files matched your search
@@ -3,22 +3,42 @@
|
||||
A modern C toolchain for the DEC VT1200 / TI TMS34010, built as a small fork of
|
||||
upstream LLVM.
|
||||
|
||||
**Status: M4.** `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). M4 adds function pointers and `CALL Rs`, 32-bit
|
||||
multiply/divide, zero-extending narrow loads, module-unique private labels,
|
||||
`i8`/`i16` fixed arguments and the contiguous-stack varargs form, the X11R4
|
||||
`XImage`/`XEvent` layouts, the full image/event client, the corrected 30-entry
|
||||
ROM symbol table, and the pinned termtris full-game integration. It is still
|
||||
**assembly-only**: no object writer, no `clang -c`, and no native COFF;
|
||||
GSPA/GSPLNK under DOSBox produce the COFF. Floats, `long long`, general
|
||||
varargs, bitfields, structs by value, narrow returns and native COFF are 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.
|
||||
|
||||
Branch `m4` is the current milestone snapshot in both repositories; the
|
||||
default branch is `m3` until the controller/user updates it after the final
|
||||
review. Branch `m3` remains the previous snapshot, `m2` is the M2 tip and
|
||||
`m1` the reproducible M1 snapshot.
|
||||
> **`-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)
|
||||
@@ -26,32 +46,247 @@ review. Branch `m3` remains the previous snapshot, `m2` is the M2 tip and
|
||||
- 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 `m4`) — the full buildable LLVM 23.1.5 tree with the TMS34010
|
||||
target, clang bit-address changes and the M2/M3/M4 backend. Branch `m3`
|
||||
(the repository default) is the previous snapshot; branch `m2` is the M2
|
||||
tip and 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 `m4`) — plans/specs, VT1200 integration tooling, `tms-bitaddr`,
|
||||
`tms-clang`, symbols, the M2/M3/M4 harnesses and the spike. Branch `m3`
|
||||
(the repository default) is the previous snapshot; branch `m2` 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/M4 do not change it.
|
||||
M2–M6 do not change it.
|
||||
|
||||
## What M4 provides
|
||||
## What M6 provides
|
||||
|
||||
M4 closes the remaining Xlib path to a real image/event client and a full-game
|
||||
integration, still assembly-only:
|
||||
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`
|
||||
@@ -70,21 +305,35 @@ integration, still assembly-only:
|
||||
- **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`.
|
||||
- **`i8`/`i16` fixed arguments.** 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 remain rejected. `m4-arg8.ll`.
|
||||
`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. Static variadic definitions can lose `...` under
|
||||
`-O2` dead-argument elimination; external termtris `sprintf` is unaffected.
|
||||
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`.
|
||||
- **Driver policies.** `scripts/tms-clang` passes `-replexitval=never` (the
|
||||
i33 exit-value multiply is unselectable on this i64-less target) and
|
||||
`-switch-to-lookup=false` (a late byte-offset GEP after `--scale` would be
|
||||
read as a bit offset, an 8x address bug). Both are driver policies because
|
||||
`opt` has no target machine.
|
||||
`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
|
||||
@@ -93,10 +342,14 @@ integration, still assembly-only:
|
||||
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 columns, so the rightmost 12 source columns (the last
|
||||
visible cell's final 12 px) are not displayed; the last visible cell is
|
||||
20 px, not 32. It asserts the checker pixels, the real LK401 `q`
|
||||
(keycode 193 / keysym `0x71`), window focus and zero X errors in MAME.
|
||||
`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
|
||||
@@ -166,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
|
||||
@@ -191,29 +444,116 @@ 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/M4) |
|
||||
| | 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 M4 gates
|
||||
## Run the M6 gates
|
||||
|
||||
These are the documented commands on branch `m4`; all must pass. The MAME
|
||||
gates are slow and are run once.
|
||||
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
|
||||
@@ -478,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
|
||||
@@ -505,14 +847,15 @@ 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.
|
||||
|
||||
### M3 carry-forwards in M4
|
||||
@@ -521,44 +864,60 @@ 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. The M3 regression is deliberately unchanged:
|
||||
`m3-cmpi.ll` still uses `CHECK-DAG: MOVI 0`/`MOVI 1` (the 1/0 order is not
|
||||
pinned), and `scripts/m3/dis-roundtrip.sh` still hardcodes the nine
|
||||
`XCreateSimpleWindow` push registers. Those M3-strength fixes remain
|
||||
test-hardening follow-ups; the M3 gates pass as-is. See the M4 feature list
|
||||
above.
|
||||
`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.
|
||||
|
||||
## M4 non-goals and the M5 boundary
|
||||
## M5 non-goals and the M6 boundary
|
||||
|
||||
M4 deliberately stops before:
|
||||
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:
|
||||
|
||||
- **Native object output:** no `MCCodeEmitter`, object writer,
|
||||
`llc -filetype=obj`, `clang -c` or native COFF; GSPA/GSPLNK still produce
|
||||
the COFF. The `JR`/branch-relaxation code-size pass and MMTM/MMFM
|
||||
register-list saves are M5 (the current per-register system-stack pushes
|
||||
have the identical ABI layout).
|
||||
- **Floating point and `long long`:** no float/double or `i64` arguments,
|
||||
returns, arithmetic or branches.
|
||||
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`.
|
||||
- **Bitfields and aggregates by value:** no structs/unions by value, `sret`,
|
||||
`byval`, bitfields or aggregate returns. Struct fields through pointers are
|
||||
supported.
|
||||
- **Narrow returns:** `i8`/`i16` returns remain rejected; fixed i8/i16
|
||||
arguments are supported.
|
||||
- **Xlib beyond the tested calls:** the client uses 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.
|
||||
- **Deeper libc/runtime coverage:** M5 owns the broader `RTS.LIB` integration.
|
||||
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 termtris tree is test-only (GPLv3) and is not part of the compiler
|
||||
or project distribution.
|
||||
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/M4 (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
|
||||
@@ -567,6 +926,9 @@ scripts/m2/ M2 harness: C inputs, entry.asm, link.cmd, stubs, check
|
||||
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)
|
||||
@@ -574,6 +936,11 @@ scripts/tests/m3/diff/ TI branch/Xlib goldens, differential check + negative c
|
||||
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
|
||||
@@ -588,12 +955,14 @@ 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/M4
|
||||
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 differential golden check needs
|
||||
no DOSBox/MAME/SDK; it needs only the built `clang`, `opt`, `llc` and
|
||||
`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:
|
||||
|
||||
```sh
|
||||
@@ -611,14 +980,14 @@ Xlib call sequence, `as34`, `dis34`, SDKs, manuals). It is not vendored:
|
||||
|
||||
## Build the compiler
|
||||
|
||||
### Compiler fork (M4, the normal path)
|
||||
### Compiler fork (M6, the normal path)
|
||||
|
||||
The fork checkout already exists at `build/llvm-clean` on `m4`. 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=m4 ./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
|
||||
```
|
||||
|
||||
@@ -626,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=m4 ./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)
|
||||
|
||||
@@ -643,23 +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/M4 fork),
|
||||
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/M4.
|
||||
M1–M6.
|
||||
|
||||
## Build the M0 support tools
|
||||
|
||||
The M2/M3/M4 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/M4):
|
||||
M0 regression test (optional in M2–M6):
|
||||
|
||||
```sh
|
||||
TMS_CLANG=$PWD/build/llvm-clean-build/bin/clang \
|
||||
@@ -669,34 +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
|
||||
|
||||
M5 adds the native COFF path (`MCCodeEmitter`/object writer), floats,
|
||||
`long long`, general varargs (`va_list`), bitfields, structs by value and the
|
||||
`JR`/branch-relaxation code-size pass, plus MMTM/MMFM register-list saves and
|
||||
deeper libc/runtime coverage. 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.
|
||||
@@ -326,8 +326,8 @@ Compile `layout-ti.c` (the `Display`/`Screen`/`XImage`/`XEvent` offset functions
|
||||
- [ ] **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`, `XLoadFont 0x3FD4AE80`, `XCopyArea 0x3FD3E220`, `sleep 0x3FB33A20`.
|
||||
- Note: `XLoadFont`/`XCopyArea` are **not** in the pinned termtris `xlib.h`; they are ROM-validated by their request builders (OpenFont opcode 45 and CopyArea opcode 62), as `symbols/README.md` records.
|
||||
- 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.
|
||||
|
||||
@@ -545,4 +545,4 @@ Do not force-push, merge into `m0`, or change the default; the controller update
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M4 closes the remaining Xlib path to a real image/event client and a full-game integration. M5 owns the native COFF/MCCodeEmitter, floats, varargs, bitfields, `long long`, the `JR`/branch-relaxation code-size pass, MMTM/MMFM, 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.
|
||||
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
|
||||
|
||||
|
||||
+70
-56
@@ -12,7 +12,8 @@
|
||||
# _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
|
||||
#
|
||||
@@ -290,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
|
||||
@@ -354,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
|
||||
}
|
||||
@@ -363,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.
|
||||
@@ -377,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##*:}
|
||||
@@ -385,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%%:*}
|
||||
@@ -407,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"
|
||||
@@ -429,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 \
|
||||
@@ -439,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
|
||||
|
||||
@@ -257,7 +257,7 @@ awk '
|
||||
low ~ /^[[:space:]]*;/ { next }
|
||||
!on { next }
|
||||
expect == 1 {
|
||||
if ($0 ~ /SETF 16, 0, 0/) { expect = 2 }
|
||||
if ($0 ~ /SETF 16, 1, 0/) { expect = 2 }
|
||||
else { bad++; expect = 0 }
|
||||
next
|
||||
}
|
||||
@@ -273,7 +273,7 @@ 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,0,0 + SETF 32,0,1"
|
||||
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.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
+209
-34
@@ -15,6 +15,16 @@
|
||||
# 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
|
||||
@@ -50,6 +60,13 @@ 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
|
||||
@@ -67,13 +84,26 @@ 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
|
||||
src=$DIR/$name.c
|
||||
case $name in
|
||||
*/*) src=$name ;;
|
||||
*) src=$DIR/$name.c ;;
|
||||
esac
|
||||
base=$(basename "$src" .c)
|
||||
[ -f "$src" ] || fail "missing source: $src"
|
||||
"$ROOT/scripts/tms-clang" "$CLANG_OPT" -o "$ASM/$name.ll" "$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/$name.ll" -o "$ASM/$name.s" \
|
||||
|| fail "llc failed for $name.c"
|
||||
echo " $name.s: $(grep -c . "$ASM/$name.s") lines"
|
||||
"$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"
|
||||
@@ -96,49 +126,194 @@ echo "== assemble and link with GSPA/GSPLNK under DOSBox"
|
||||
# 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.
|
||||
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
|
||||
cat "$ENTRY" > "$SDK/M4.ASM"
|
||||
for name in $SOURCES; do
|
||||
cat "$ASM/$name.unique.s" >> "$SDK/M4.ASM"
|
||||
done
|
||||
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"
|
||||
cat "$extra" >> "$SDK/M4.ASM"
|
||||
EXTRAS="$EXTRAS $extra"
|
||||
done
|
||||
fi
|
||||
if [ -n "${M4_ROM_SYMBOLS:-}" ]; then
|
||||
"$ROOT/scripts/m2/gen-rom-imports.sh" "$SYMS" "$WORK/rom-imports.asm"
|
||||
cat "$WORK/rom-imports.asm" >> "$SDK/M4.ASM"
|
||||
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
|
||||
# The linker command file must keep CRLF line endings.
|
||||
sed 's/\r$//' "$DIR/link.cmd" | sed 's/$/\r/' > "$SDK/M4.CMD"
|
||||
rm -f "$SDK/M4.OBJ" "$SDK/M4.OUT" "$SDK/M4.MAP" "$SDK/M4.LST"
|
||||
rm -f "$SDK/M4EXT.OBJ" "$SDK/M4EXT.LST"
|
||||
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M4 M4.obj M4.lst -l" \
|
||||
-c "gsplnk M4.cmd" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
run_dosbox() {
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf "$@" > "$WORK/dosbox.log" 2>&1
|
||||
}
|
||||
|
||||
[ -f "$SDK/M4.LST" ] || fail "GSPA produced no listing (see $WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$SDK/M4.LST" > "$WORK/m4.lst"
|
||||
grep -q 'No Errors' "$WORK/m4.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/m4.lst" >&2 || true; fail "GSPA reported errors"; }
|
||||
grep -q 'No Warnings' "$WORK/m4.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$WORK/m4.lst" >&2 || true; fail "GSPA reported warnings"; }
|
||||
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"
|
||||
|
||||
+5
-5
@@ -3,11 +3,11 @@
|
||||
* driver's late-GEP policy.
|
||||
*
|
||||
* The optimizer's switch-to-lookup-table transform creates a new i8 GEP after
|
||||
* tms-bitaddr --scale; --normalize cannot tell that index apart from an
|
||||
* already-scaled bit offset, so the table would be indexed one bit per slot.
|
||||
* tms-clang passes -switch-to-lookup=false; this source makes the hazard
|
||||
* reachable at -O2 (termtris' init_game and runesc switches are the real
|
||||
* cases).
|
||||
* 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)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
.globl _start
|
||||
.globl _varargs_test
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -98,7 +98,9 @@ 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.
|
||||
if ! grep -Eq '^[[:space:]]*JA(LT|LE|GT|GE|LO|LS|HI|HS|EQ|NE)[[:space:]]' "$TMP/sumto.s"; then
|
||||
# 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
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
# 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)
|
||||
@@ -28,23 +31,28 @@ if git -C "$VENDOR" rev-parse --git-dir >/dev/null 2>&1; then
|
||||
fi
|
||||
|
||||
# The optimizer's switch-to-lookup-table transform creates a late byte-offset
|
||||
# GEP that --normalize cannot distinguish from an already-scaled bit offset.
|
||||
# tms-clang disables it; a dense char switch is the regression probe. The
|
||||
# termtris init_game/runesc switches are the real instances.
|
||||
# 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"
|
||||
if grep -q 'switch\.table' "$TMP/switch.ll"; then
|
||||
fail "switch-to-lookup table survived the driver pipeline (8x index bug)"
|
||||
fi
|
||||
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"
|
||||
"$DIR/build.sh" || fail "termtris build failed"
|
||||
BUILD=${TERMTRIS_BUILD:-$DIR/build.sh}
|
||||
"$BUILD" || fail "termtris build failed"
|
||||
|
||||
echo "== run board/move/panels/quit in MAME"
|
||||
TERMTRIS_NOBUILD=1 \
|
||||
|
||||
@@ -42,17 +42,27 @@ for fn in le ule sum_le ge uge gt ugt ne lt ult; do
|
||||
[ -s "$TMP/$fn.s" ] || fail "linked assembly has no _$fn body"
|
||||
done
|
||||
|
||||
check_branch() { # check_branch FUNC MNEMONIC WHAT
|
||||
if grep -Eq "^[[:space:]]*$2[[:space:]]" "$TMP/$1.s"; then
|
||||
echo " ok _$1 uses $2 ($3)"
|
||||
check_branch() { # check_branch FUNC JA<cc> WHAT
|
||||
# M5's JR relaxation selects the one-word relative form for an in-range
|
||||
# branch, keeping the condition code. Accept either spelling but require
|
||||
# exactly the same <cc> suffix.
|
||||
_cond=${2#JA}
|
||||
[ "$_cond" != "$2" ] \
|
||||
|| fail "check_branch expects a JA<cc> mnemonic, got $2"
|
||||
if grep -Eq "^[[:space:]]*J[AR]${_cond}[[:space:]]" "$TMP/$1.s"; then
|
||||
echo " ok _$1 uses JA/JR$_cond ($3)"
|
||||
return 0
|
||||
fi
|
||||
sed 's/^/ /' "$TMP/$1.s" >&2
|
||||
fail "_$1 does not use $2 ($3)"
|
||||
fail "_$1 does not use JA/JR$_cond ($3)"
|
||||
}
|
||||
|
||||
reject_branch() { # reject_branch FUNC ERE WHAT
|
||||
if grep -Eq "^[[:space:]]*$2[[:space:]]" "$TMP/$1.s"; then
|
||||
# The ERE names the absolute form; allow the relative prefix as well. The
|
||||
# condition itself is unchanged, so a wrong signed/unsigned form still
|
||||
# fails.
|
||||
_re=$(printf '%s\n' "$2" | sed 's/^JA/J[AR]/')
|
||||
if grep -Eq "^[[:space:]]*${_re}[[:space:]]" "$TMP/$1.s"; then
|
||||
sed 's/^/ /' "$TMP/$1.s" >&2
|
||||
fail "_$1 uses the wrong condition $2 ($3)"
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# M6 c-testsuite `single-exec` output subset.
|
||||
#
|
||||
# Curated list seeded by the M5 Task 12 list and expanded by M6 Task 8 with
|
||||
# the float/double, long long, bitfield, varargs and aggregate tests the M6
|
||||
# language/runtime work made runnable. One test name per line (no .c
|
||||
# suffix); the `.c`, `.c.expected` and `.tags` live under the pinned
|
||||
# vendor/conformance/c-testsuite/tests/single-exec tree. Every listed test is
|
||||
# portable C89/C99 using only language features and shim conversions the M6
|
||||
# path supports. Each test must return 0 and its captured output must equal
|
||||
# `<name>.c.expected` byte for byte, including the `%f` and `%lld` output.
|
||||
# Unsupported tests live in c-testsuite.skip, never here.
|
||||
#
|
||||
# Core language: integer arithmetic, control flow, pointers, arrays, structs,
|
||||
# strings (expected output is empty; the status is 0).
|
||||
00001
|
||||
00004
|
||||
00006
|
||||
00007
|
||||
00009
|
||||
00010
|
||||
00015
|
||||
00017
|
||||
00022
|
||||
00025
|
||||
00027
|
||||
00029
|
||||
00030
|
||||
00034
|
||||
00035
|
||||
00038
|
||||
00039
|
||||
#
|
||||
# Formatted output: %d/%i/%u/%c/%s/%ld through the conformance shim.
|
||||
00056
|
||||
00125
|
||||
00132
|
||||
00154
|
||||
00156
|
||||
00157
|
||||
00163
|
||||
00170
|
||||
00173
|
||||
00213
|
||||
00214
|
||||
00215
|
||||
#
|
||||
# M6 floats/doubles: float/double arithmetic, globals, struct members, %f and
|
||||
# double sizeof. 00175 and 00195 compare the exact printed output.
|
||||
00113
|
||||
00119
|
||||
00123
|
||||
00175
|
||||
00178
|
||||
00195
|
||||
#
|
||||
# M6 64-bit integers: long long arithmetic/constants/conversions, int64_t,
|
||||
# pointer-width interactions and the exact %lld/%llx-style output.
|
||||
00081
|
||||
00082
|
||||
00104
|
||||
00128
|
||||
00135
|
||||
00200
|
||||
00203
|
||||
00212
|
||||
00217
|
||||
00219
|
||||
#
|
||||
# M6 varargs, bitfields, aggregates, and sprintf output.
|
||||
00140
|
||||
00218
|
||||
00186
|
||||
Executable
+195
@@ -0,0 +1,195 @@
|
||||
#!/bin/sh
|
||||
# M5 c-testsuite `single-exec` output-subset gate.
|
||||
#
|
||||
# scripts/tests/m5/c-testsuite.sh [LIST] [SKIP]
|
||||
#
|
||||
# LIST (default scripts/tests/m5/c-testsuite.list) names the curated
|
||||
# vendor/conformance/c-testsuite/tests/single-exec tests. Every listed test
|
||||
# runs through the Task 9 single-exec entry point
|
||||
# (conformance/c-testsuite.sh -> run.sh --classify --expect-status 0
|
||||
# --expect-output-file <name>.c.expected). The captured stdout must equal
|
||||
# the .c.expected bytes exactly, main must return 0, the COFF loader readback
|
||||
# must be clean and the completion magic must be present. A mismatch fails.
|
||||
# A listed test that the classifier rejects is reported as a skip and fails
|
||||
# the gate: unsupported tests belong in SKIP, never in LIST.
|
||||
#
|
||||
# SKIP (default scripts/tests/m5/c-testsuite.skip) accounts for every other
|
||||
# single-exec test with a feature/reason. Rows are
|
||||
# <name><TAB><feature>: <reason>
|
||||
# Skips are reported separately and are never counted as passes. The gate
|
||||
# checks that every skip names an existing test, is not also listed, and has a
|
||||
# reason; a classifier-rejected test must carry the classifier's exact reason.
|
||||
# LIST + SKIP must cover the pinned suite, so no test is silently dropped.
|
||||
#
|
||||
# The MAME boot dominates the runtime. Task 11's proven 300/600 injection
|
||||
# frames are reused; the loader readback and completion magic checks remain.
|
||||
# The suite runs serially because M4_SDK is shared.
|
||||
#
|
||||
# Overridable: C_TESTSUITE_DIR C_TESTSUITE_LOADER_AT C_TESTSUITE_LOADER_END
|
||||
# M5_C_TESTSUITE_WORK M5_CONFORMANCE_DIR M5_CONFORMANCE_MODE
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$HERE/conformance}
|
||||
CONFORMANCE=$CONFORMANCE_DIR/c-testsuite.sh
|
||||
CLASSIFY=$CONFORMANCE_DIR/classify.sh
|
||||
SUITE_DIR=${C_TESTSUITE_DIR:-$ROOT/vendor/conformance/c-testsuite/tests/single-exec}
|
||||
WORK=${M5_C_TESTSUITE_WORK:-$ROOT/build/m5-c-testsuite}
|
||||
LOADER_AT=${C_TESTSUITE_LOADER_AT:-300}
|
||||
LOADER_END=${C_TESTSUITE_LOADER_END:-600}
|
||||
|
||||
fail() {
|
||||
echo "c-testsuite: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$CONFORMANCE" ] || fail "missing conformance entry point: $CONFORMANCE"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-testsuite tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
LIST=$HERE/c-testsuite.list
|
||||
SKIP=$HERE/c-testsuite.skip
|
||||
if [ $# -gt 0 ]; then
|
||||
LIST=$1
|
||||
shift
|
||||
fi
|
||||
if [ $# -gt 0 ]; then
|
||||
SKIP=$1
|
||||
shift
|
||||
fi
|
||||
[ $# -eq 0 ] || fail "unexpected trailing arguments: $*"
|
||||
[ -f "$LIST" ] || fail "no c-testsuite.list ($LIST); Task 12 seeds it"
|
||||
[ -f "$SKIP" ] || fail "no c-testsuite.skip ($SKIP); Task 12 seeds it"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
LOG=$WORK/c-testsuite.log
|
||||
: > "$LOG"
|
||||
|
||||
list_count() {
|
||||
awk '$0 !~ /^[[:space:]]*(#|$)/ { n++ } END { print n + 0 }' "$1"
|
||||
}
|
||||
|
||||
LIST_COUNT=$(list_count "$LIST")
|
||||
[ "$LIST_COUNT" -gt 0 ] || fail "c-testsuite.list is empty ($LIST)"
|
||||
|
||||
# One running log with the runner's per-test result rows, plus the individual
|
||||
# runner logs kept under the work dir.
|
||||
ONE_LIST=$WORK/one.list
|
||||
pass=0
|
||||
runner_skip=0
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
case $name in
|
||||
*/*|.*) fail "unsafe test name in $LIST: '$name'" ;;
|
||||
esac
|
||||
base=${name%.c}
|
||||
src=$SUITE_DIR/$base.c
|
||||
expected=$SUITE_DIR/$base.c.expected
|
||||
[ -f "$src" ] || fail "missing c-testsuite source: $src"
|
||||
[ -f "$expected" ] || fail "missing c-testsuite expected output: $expected"
|
||||
total=$((total + 1))
|
||||
|
||||
printf '%s\n' "$base" > "$ONE_LIST"
|
||||
one_log=$WORK/$base.log
|
||||
set +e
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$LOADER_END \
|
||||
"$CONFORMANCE" "$ONE_LIST" > "$one_log" 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
cat "$one_log" >> "$LOG"
|
||||
case $rc in
|
||||
0)
|
||||
pass=$((pass + 1))
|
||||
;;
|
||||
*)
|
||||
# The wrapper exits 1 when its only test was classified as a skip
|
||||
# (pass=0). Report the reason, but fail below: an unsupported test
|
||||
# must be in c-testsuite.skip, not the list.
|
||||
if grep -q '^CONFORMANCE: SKIP ' "$one_log"; then
|
||||
reason=$(sed -n 's/^CONFORMANCE: SKIP id=[^ ]* reason=//p' "$one_log")
|
||||
runner_skip=$((runner_skip + 1))
|
||||
echo "c-testsuite: SKIP $base (listed but classifier-rejected: $reason)" >&2
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "c-testsuite: FAIL $base (runner exit $rc; log $one_log)" >&2
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done < "$LIST"
|
||||
|
||||
# Validate the skip file and collect its coverage.
|
||||
: > "$WORK/skip-reasons.txt"
|
||||
skip=0
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
name=${line%% *}
|
||||
reason=${line#* }
|
||||
[ "$name" != "$line" ] || fail "malformed skip row (no tab): $line"
|
||||
case $name in
|
||||
*/*|.*) fail "unsafe test name in $SKIP: '$name'" ;;
|
||||
esac
|
||||
base=${name%.c}
|
||||
[ -f "$SUITE_DIR/$base.c" ] || fail "skip names a missing test: $base"
|
||||
if grep -Fxq "$base" "$LIST"; then
|
||||
fail "test $base is both listed and skipped"
|
||||
fi
|
||||
[ -n "$reason" ] || fail "skip for $base has no reason"
|
||||
case $reason in
|
||||
*:?*) ;;
|
||||
*) fail "skip for $base has no feature/reason: '$reason'" ;;
|
||||
esac
|
||||
|
||||
set +e
|
||||
classified=$("$CLASSIFY" "$SUITE_DIR/$base.c" 2>&1)
|
||||
crc=$?
|
||||
set -e
|
||||
case $crc in
|
||||
0)
|
||||
# A classifier-supported test is only skipped for an explicit shim
|
||||
# gap or because it is outside the curated subset.
|
||||
case $reason in
|
||||
libc:*|stderr:*|shim-format:*|runtime:*|unselected:*) ;;
|
||||
*) fail "skip for $base does not name a shim gap or an unselected test: '$reason'" ;;
|
||||
esac
|
||||
;;
|
||||
1)
|
||||
[ "$reason" = "$classified" ] \
|
||||
|| fail "skip reason for $base is stale: '$reason' != '$classified'"
|
||||
;;
|
||||
*)
|
||||
fail "classifier error (exit $crc) on $base: $classified"
|
||||
;;
|
||||
esac
|
||||
skip=$((skip + 1))
|
||||
printf '%s\t%s\n' "$base" "$reason" >> "$WORK/skip-reasons.txt"
|
||||
done < "$SKIP"
|
||||
|
||||
[ "$failed" -eq 0 ] || fail "$failed of $total listed tests failed"
|
||||
[ "$pass" -gt 0 ] \
|
||||
|| fail "no tests passed (pass=0 skip=$runner_skip total=$total); all-skip is not a pass"
|
||||
[ "$runner_skip" -eq 0 ] \
|
||||
|| fail "$runner_skip listed test(s) were classifier-rejected; move them to $SKIP"
|
||||
|
||||
suite_count=$(find "$SUITE_DIR" -maxdepth 1 -type f -name '*.c' | wc -l | tr -d ' ')
|
||||
[ "$((pass + skip))" -eq "$suite_count" ] \
|
||||
|| fail "list+skip cover $((pass + skip)) tests, suite has $suite_count; every test needs a pass or a skip"
|
||||
|
||||
if [ "$skip" -gt 0 ]; then
|
||||
awk -F '\t' '{ printf "c-testsuite: SKIP %s reason=%s\n", $1, $2 }' \
|
||||
"$WORK/skip-reasons.txt" >> "$LOG"
|
||||
echo "c-testsuite: skipped $skip test(s) by reason:"
|
||||
awk -F '\t' '{ split($2, a, ":"); print a[1] }' "$WORK/skip-reasons.txt" \
|
||||
| sort | uniq -c | sort -rn | sed 's/^/ /'
|
||||
fi
|
||||
|
||||
echo "c-testsuite: PASS pass=$pass skip=$skip total=$suite_count"
|
||||
echo "c-testsuite: logs $WORK"
|
||||
echo "c-testsuite: skip reasons $WORK/skip-reasons.txt"
|
||||
@@ -0,0 +1,182 @@
|
||||
# M6 c-testsuite `single-exec` skips.
|
||||
#
|
||||
# Every single-exec test that is not in c-testsuite.list is accounted for here
|
||||
# as `<name><TAB><feature>: <reason>`, so no pinned test is silently dropped.
|
||||
# A skipped test is never a pass. M6 Task 8 removed the float/long-long/
|
||||
# bitfield skip rows for the tests that moved into the list; the remainder are
|
||||
# either classifier-rejected (exact `feature: reason` text) or
|
||||
# classifier-supported tests outside the curated output subset
|
||||
# (`unselected:`) or an explicit shim gap
|
||||
# (`libc:`/`stderr:`/`shim-format:`/`runtime:`).
|
||||
00002 unselected: classifier-supported; outside the curated output subset
|
||||
00003 unselected: classifier-supported; outside the curated output subset
|
||||
00005 unselected: classifier-supported; outside the curated output subset
|
||||
00008 unselected: classifier-supported; outside the curated output subset
|
||||
00011 unselected: classifier-supported; outside the curated output subset
|
||||
00012 unselected: classifier-supported; outside the curated output subset
|
||||
00013 unselected: classifier-supported; outside the curated output subset
|
||||
00014 unselected: classifier-supported; outside the curated output subset
|
||||
00016 unselected: classifier-supported; outside the curated output subset
|
||||
00018 unselected: classifier-supported; outside the curated output subset
|
||||
00019 unselected: classifier-supported; outside the curated output subset
|
||||
00020 unselected: classifier-supported; outside the curated output subset
|
||||
00021 unselected: classifier-supported; outside the curated output subset
|
||||
00023 unselected: classifier-supported; outside the curated output subset
|
||||
00024 unselected: classifier-supported; outside the curated output subset
|
||||
00026 unselected: classifier-supported; outside the curated output subset
|
||||
00028 unselected: classifier-supported; outside the curated output subset
|
||||
00031 unselected: classifier-supported; outside the curated output subset
|
||||
00032 unselected: classifier-supported; outside the curated output subset
|
||||
00033 unselected: classifier-supported; outside the curated output subset
|
||||
00036 unselected: classifier-supported; outside the curated output subset
|
||||
00037 unselected: classifier-supported; outside the curated output subset
|
||||
00040 libc: calloc is not implemented by the conformance shim
|
||||
00041 unselected: classifier-supported; outside the curated output subset
|
||||
00042 unselected: classifier-supported; outside the curated output subset
|
||||
00043 unselected: classifier-supported; outside the curated output subset
|
||||
00044 unselected: classifier-supported; outside the curated output subset
|
||||
00045 unselected: classifier-supported; outside the curated output subset
|
||||
00046 unselected: classifier-supported; outside the curated output subset
|
||||
00047 unselected: classifier-supported; outside the curated output subset
|
||||
00048 unselected: classifier-supported; outside the curated output subset
|
||||
00049 unselected: classifier-supported; outside the curated output subset
|
||||
00050 unselected: classifier-supported; outside the curated output subset
|
||||
00051 unselected: classifier-supported; outside the curated output subset
|
||||
00052 unselected: classifier-supported; outside the curated output subset
|
||||
00053 unselected: classifier-supported; outside the curated output subset
|
||||
00054 unselected: classifier-supported; outside the curated output subset
|
||||
00055 unselected: classifier-supported; outside the curated output subset
|
||||
00057 unselected: classifier-supported; outside the curated output subset
|
||||
00058 unselected: classifier-supported; outside the curated output subset
|
||||
00059 unselected: classifier-supported; outside the curated output subset
|
||||
00060 unselected: classifier-supported; outside the curated output subset
|
||||
00061 unselected: classifier-supported; outside the curated output subset
|
||||
00062 unselected: classifier-supported; outside the curated output subset
|
||||
00063 unselected: classifier-supported; outside the curated output subset
|
||||
00064 unselected: classifier-supported; outside the curated output subset
|
||||
00065 unselected: classifier-supported; outside the curated output subset
|
||||
00066 unselected: classifier-supported; outside the curated output subset
|
||||
00067 unselected: classifier-supported; outside the curated output subset
|
||||
00068 unselected: classifier-supported; outside the curated output subset
|
||||
00069 unselected: classifier-supported; outside the curated output subset
|
||||
00070 unselected: classifier-supported; outside the curated output subset
|
||||
00071 unselected: classifier-supported; outside the curated output subset
|
||||
00072 unselected: classifier-supported; outside the curated output subset
|
||||
00073 unselected: classifier-supported; outside the curated output subset
|
||||
00074 unselected: classifier-supported; outside the curated output subset
|
||||
00075 unselected: classifier-supported; outside the curated output subset
|
||||
00076 unselected: classifier-supported; outside the curated output subset
|
||||
00077 unselected: classifier-supported; outside the curated output subset
|
||||
00078 unselected: classifier-supported; outside the curated output subset
|
||||
00079 unselected: classifier-supported; outside the curated output subset
|
||||
00080 unselected: classifier-supported; outside the curated output subset
|
||||
00083 unselected: classifier-supported; outside the curated output subset
|
||||
00084 unselected: classifier-supported; outside the curated output subset
|
||||
00085 unselected: classifier-supported; outside the curated output subset
|
||||
00086 unselected: classifier-supported; outside the curated output subset
|
||||
00087 unselected: classifier-supported; outside the curated output subset
|
||||
00088 unselected: classifier-supported; outside the curated output subset
|
||||
00089 unselected: classifier-supported; outside the curated output subset
|
||||
00090 unselected: classifier-supported; outside the curated output subset
|
||||
00091 unselected: classifier-supported; outside the curated output subset
|
||||
00092 unselected: classifier-supported; outside the curated output subset
|
||||
00093 unselected: classifier-supported; outside the curated output subset
|
||||
00094 unselected: classifier-supported; outside the curated output subset
|
||||
00095 unselected: classifier-supported; outside the curated output subset
|
||||
00096 unselected: classifier-supported; outside the curated output subset
|
||||
00097 unselected: classifier-supported; outside the curated output subset
|
||||
00098 wide-char: wide characters are unsupported
|
||||
00099 unselected: classifier-supported; outside the curated output subset
|
||||
00100 unselected: classifier-supported; outside the curated output subset
|
||||
00101 unselected: classifier-supported; outside the curated output subset
|
||||
00102 unselected: classifier-supported; outside the curated output subset
|
||||
00103 unselected: classifier-supported; outside the curated output subset
|
||||
00105 unselected: classifier-supported; outside the curated output subset
|
||||
00106 unselected: classifier-supported; outside the curated output subset
|
||||
00107 unselected: classifier-supported; outside the curated output subset
|
||||
00108 unselected: classifier-supported; outside the curated output subset
|
||||
00109 unselected: classifier-supported; outside the curated output subset
|
||||
00110 unselected: classifier-supported; outside the curated output subset
|
||||
00111 unselected: classifier-supported; outside the curated output subset
|
||||
00112 unselected: classifier-supported; outside the curated output subset
|
||||
00114 unselected: classifier-supported; outside the curated output subset
|
||||
00115 unselected: classifier-supported; outside the curated output subset
|
||||
00116 unselected: classifier-supported; outside the curated output subset
|
||||
00117 unselected: classifier-supported; outside the curated output subset
|
||||
00118 unselected: classifier-supported; outside the curated output subset
|
||||
00120 unselected: classifier-supported; outside the curated output subset
|
||||
00121 unselected: classifier-supported; outside the curated output subset
|
||||
00122 unselected: classifier-supported; outside the curated output subset
|
||||
00124 unselected: classifier-supported; outside the curated output subset
|
||||
00126 unselected: classifier-supported; outside the curated output subset
|
||||
00127 unselected: classifier-supported; outside the curated output subset
|
||||
00129 unselected: classifier-supported; outside the curated output subset
|
||||
00130 unselected: classifier-supported; outside the curated output subset
|
||||
00131 unselected: classifier-supported; outside the curated output subset
|
||||
00133 unselected: classifier-supported; outside the curated output subset
|
||||
00134 unselected: classifier-supported; outside the curated output subset
|
||||
00136 unselected: classifier-supported; outside the curated output subset
|
||||
00137 unselected: classifier-supported; outside the curated output subset
|
||||
00138 unselected: classifier-supported; outside the curated output subset
|
||||
00139 unselected: classifier-supported; outside the curated output subset
|
||||
00141 unselected: classifier-supported; outside the curated output subset
|
||||
00142 unselected: classifier-supported; outside the curated output subset
|
||||
00143 unselected: classifier-supported; outside the curated output subset
|
||||
00144 unselected: classifier-supported; outside the curated output subset
|
||||
00145 unselected: classifier-supported; outside the curated output subset
|
||||
00146 unselected: classifier-supported; outside the curated output subset
|
||||
00147 unselected: classifier-supported; outside the curated output subset
|
||||
00148 unselected: classifier-supported; outside the curated output subset
|
||||
00149 unselected: classifier-supported; outside the curated output subset
|
||||
00150 unselected: classifier-supported; outside the curated output subset
|
||||
00151 unselected: classifier-supported; outside the curated output subset
|
||||
00152 unselected: classifier-supported; outside the curated output subset
|
||||
00153 unselected: classifier-supported; outside the curated output subset
|
||||
00155 unselected: classifier-supported; outside the curated output subset
|
||||
00158 unselected: classifier-supported; outside the curated output subset
|
||||
00159 unselected: classifier-supported; outside the curated output subset
|
||||
00160 unselected: classifier-supported; outside the curated output subset
|
||||
00161 unselected: classifier-supported; outside the curated output subset
|
||||
00162 unselected: classifier-supported; outside the curated output subset
|
||||
00164 unselected: classifier-supported; outside the curated output subset
|
||||
00165 unselected: classifier-supported; outside the curated output subset
|
||||
00166 unselected: classifier-supported; outside the curated output subset
|
||||
00167 unselected: classifier-supported; outside the curated output subset
|
||||
00168 unselected: classifier-supported; outside the curated output subset
|
||||
00169 unselected: classifier-supported; outside the curated output subset
|
||||
00171 unselected: classifier-supported; outside the curated output subset
|
||||
00172 unselected: classifier-supported; outside the curated output subset
|
||||
00174 libc: sin() is not implemented by the conformance shim
|
||||
00176 unselected: classifier-supported; outside the curated output subset
|
||||
00177 unselected: classifier-supported; outside the curated output subset
|
||||
00179 wide-char: wide characters are unsupported
|
||||
00180 unselected: classifier-supported; outside the curated output subset
|
||||
00181 unselected: classifier-supported; outside the curated output subset
|
||||
00182 file-io: stdio/POSIX file I/O is unavailable under the bare loader
|
||||
00183 unselected: classifier-supported; outside the curated output subset
|
||||
00184 unselected: classifier-supported; outside the curated output subset
|
||||
00185 unselected: classifier-supported; outside the curated output subset
|
||||
00187 file-io: stdio/POSIX file I/O is unavailable under the bare loader
|
||||
00188 unselected: classifier-supported; outside the curated output subset
|
||||
00189 file-io: stdio/POSIX file I/O is unavailable under the bare loader
|
||||
00190 unselected: classifier-supported; outside the curated output subset
|
||||
00191 unselected: classifier-supported; outside the curated output subset
|
||||
00192 unselected: classifier-supported; outside the curated output subset
|
||||
00193 unselected: classifier-supported; outside the curated output subset
|
||||
00194 unselected: classifier-supported; outside the curated output subset
|
||||
00196 unselected: classifier-supported; outside the curated output subset
|
||||
00197 unselected: classifier-supported; outside the curated output subset
|
||||
00198 unselected: classifier-supported; outside the curated output subset
|
||||
00199 unselected: classifier-supported; outside the curated output subset
|
||||
00201 unselected: classifier-supported; outside the curated output subset
|
||||
00202 unselected: classifier-supported; outside the curated output subset
|
||||
00204 format-unsupported: printf %n, positional $, %e/%g/%a/%F, %j, long-double %L/%F and wide %ls/%lc are not implemented by the shim
|
||||
00205 runtime: M2 .data supports only integer, pointer and byte-array initializers (host compile fails)
|
||||
00206 unselected: classifier-supported; outside the curated output subset
|
||||
00207 unselected: classifier-supported; outside the curated output subset
|
||||
00208 wide-char: wide characters are unsupported
|
||||
00209 unselected: classifier-supported; outside the curated output subset
|
||||
00210 unselected: classifier-supported; outside the curated output subset
|
||||
00211 unselected: classifier-supported; outside the curated output subset
|
||||
00216 runtime: M2 .data supports only integer, pointer and byte-array initializers (host compile fails)
|
||||
00220 wide-char: wide characters are unsupported
|
||||
@@ -0,0 +1,118 @@
|
||||
# M6 c-torture `execute` subset.
|
||||
#
|
||||
# One test name per line (no .c suffix), selected from
|
||||
# vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute.
|
||||
# The M6 gate runs each name at -O0 and a bounded subset at -O2 through the
|
||||
# conformance harness and requires main to return 0 in MAME.
|
||||
#
|
||||
# M6 Task 8 removed the M5 "integer/control only" restriction: the list now
|
||||
# includes the float/double, long long, bitfield, general-varargs and
|
||||
# aggregate-by-value tests the M6 compiler/runtime made runnable. It is 79
|
||||
# tests (59 M5 legacy + 20 M6 additions); the 40-60 curated target is a soft
|
||||
# bound for this one-time expansion, and the 19 legacy tests that a first cut
|
||||
# dropped are restored so no previously gated shape loses coverage. The full
|
||||
# corpus classifier report (`c-torture.sh --scan`) is the selection report, not
|
||||
# this gate.
|
||||
#
|
||||
# Test selection is runtime-verified, not classifier-only: several
|
||||
# classifier-supported tests still hit the M2 `.data` initializer limit
|
||||
# (aggregate/bitfield globals) or the 300/600 frame budget and are not listed.
|
||||
#
|
||||
# Integer arithmetic, conversions, and bit operations
|
||||
20000313-1
|
||||
20000503-1
|
||||
20000519-2
|
||||
20000715-2
|
||||
20001009-1
|
||||
20021118-3
|
||||
20030128-1
|
||||
20030821-1
|
||||
20050410-1
|
||||
20070724-1
|
||||
20071205-1
|
||||
20081112-1
|
||||
920721-1
|
||||
941025-1
|
||||
950706-1
|
||||
960219-1
|
||||
961122-2
|
||||
990324-1
|
||||
991202-2
|
||||
#
|
||||
# Control flow: loops, conditionals, switch, recursion
|
||||
20000205-1
|
||||
20000412-2
|
||||
20000412-4
|
||||
20000511-1
|
||||
20000731-2
|
||||
20010206-1
|
||||
20010422-1
|
||||
20010723-1
|
||||
20040706-1
|
||||
20070212-2
|
||||
920506-1
|
||||
930123-1
|
||||
960419-1
|
||||
961017-1
|
||||
980602-1
|
||||
980929-1
|
||||
990604-1
|
||||
991202-1
|
||||
#
|
||||
# Arrays, pointers, and string literals
|
||||
20000112-1
|
||||
20000314-1
|
||||
20000314-3
|
||||
20000403-1
|
||||
20000412-1
|
||||
20000412-6
|
||||
20000422-1
|
||||
20000706-4
|
||||
20001027-1
|
||||
20010711-1
|
||||
20011109-2
|
||||
20011114-1
|
||||
20011128-1
|
||||
20020911-1
|
||||
20021119-1
|
||||
20050106-1
|
||||
20090207-1
|
||||
930429-1
|
||||
931110-2
|
||||
951115-1
|
||||
960419-2
|
||||
991227-1
|
||||
#
|
||||
# M6 floats/doubles: arithmetic, comparisons, struct/union members, globals,
|
||||
# floats passed by value, and a double function pointer.
|
||||
20000603-1
|
||||
20000605-1
|
||||
20020213-1
|
||||
920501-8
|
||||
930614-1
|
||||
930614-2
|
||||
#
|
||||
# M6 64-bit integers: constants, add/sub/mul, shifts, divide/remainder and
|
||||
# conversions through int.
|
||||
20000402-1
|
||||
20000523-1
|
||||
20001108-1
|
||||
20110418-1
|
||||
20141125-1
|
||||
#
|
||||
# M6 general varargs: va_list passes through a second function, mixed
|
||||
# int/double/long walks, many stack arguments and a va_list copy.
|
||||
20000519-1
|
||||
stdarg-4
|
||||
va-arg-1
|
||||
multi-ix
|
||||
#
|
||||
# M6 bitfields: packed struct fields, bitfield arithmetic and bitfield stores.
|
||||
20000113-1
|
||||
20001101
|
||||
20040629-1
|
||||
#
|
||||
# M6 aggregates: struct/union passed and returned by value, including a
|
||||
# float/char-array struct checked with memcmp.
|
||||
20081103-1
|
||||
921112-1
|
||||
Executable
+200
@@ -0,0 +1,200 @@
|
||||
#!/bin/sh
|
||||
# M5 GCC c-torture `execute` subset gate.
|
||||
#
|
||||
# scripts/tests/m5/c-torture.sh [LIST]
|
||||
# scripts/tests/m5/c-torture.sh --scan [CORPUS_DIR]
|
||||
#
|
||||
# LIST is the curated allowlist (default: scripts/tests/m5/c-torture.list).
|
||||
# Each non-comment line names a test under the pinned GCC 16.2.0
|
||||
# gcc.c-torture/execute tree. The gate compiles every test through the Task 9
|
||||
# conformance harness twice, once with tms-clang -O0 and once with -O2 (both
|
||||
# the IR pipeline and llc), links the shim/entry, runs the COFF in MAME, and
|
||||
# requires main to return 0 with the completion magic present. stdout is
|
||||
# ignored because c-torture tests may print diagnostics on success; the status
|
||||
# is the oracle. A test that cannot compile is not silently dropped: the
|
||||
# classifier reports it as a skip with a reason, and a run with no passing
|
||||
# test fails even when every test was skipped.
|
||||
#
|
||||
# --scan is the broader report mode: it runs the classifier over every .c in
|
||||
# the corpus, writes build/m5-c-torture/c-torture-scan.txt, and prints the
|
||||
# supported/skip counts by feature. It never compiles or runs a test, so it is
|
||||
# a selection report, not the gate.
|
||||
#
|
||||
# The default MAME injection/exit frames are lower than Task 9's 2500/2700.
|
||||
# The VT1200 OS is ready well before frame 300 (verified against the pinned
|
||||
# loader); 300 leaves a wide margin while keeping the serial suite practical.
|
||||
# The loader COFF readback and the completion magic are still required, so the
|
||||
# lower frame does not weaken the pass condition.
|
||||
#
|
||||
# Overridable: C_TORTURE_DIR C_TORTURE_LOADER_AT C_TORTURE_LOADER_END
|
||||
# M5_C_TORTURE_WORK M5_CONFORMANCE_DIR
|
||||
# M5_CONFORMANCE_CLANG_OPT M5_CONFORMANCE_LLC_OPT (per pass)
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$HERE/conformance}
|
||||
CONFORMANCE=$CONFORMANCE_DIR/c-torture.sh
|
||||
CLASSIFY=$CONFORMANCE_DIR/classify.sh
|
||||
SUITE_DIR=${C_TORTURE_DIR:-$ROOT/vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute}
|
||||
WORK=${M5_C_TORTURE_WORK:-$ROOT/build/m5-c-torture}
|
||||
LOADER_AT=${C_TORTURE_LOADER_AT:-300}
|
||||
LOADER_END=${C_TORTURE_LOADER_END:-600}
|
||||
|
||||
fail() {
|
||||
echo "c-torture: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$CONFORMANCE" ] || fail "missing conformance entry point: $CONFORMANCE"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-torture tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
SCAN=0
|
||||
LIST=$HERE/c-torture.list
|
||||
if [ $# -gt 0 ]; then
|
||||
case $1 in
|
||||
--scan)
|
||||
SCAN=1
|
||||
shift
|
||||
[ $# -eq 0 ] || { SUITE_DIR=$1; shift; }
|
||||
;;
|
||||
-*)
|
||||
fail "unknown option: $1"
|
||||
;;
|
||||
*)
|
||||
LIST=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
[ $# -eq 0 ] || fail "unexpected trailing arguments: $*"
|
||||
[ -d "$SUITE_DIR" ] || fail "missing corpus: $SUITE_DIR"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
if [ "$SCAN" -eq 1 ]; then
|
||||
REPORT=$WORK/c-torture-scan.txt
|
||||
find "$SUITE_DIR" -maxdepth 1 -type f -name '*.c' | sort \
|
||||
> "$WORK/c-torture-corpus.txt"
|
||||
total=0
|
||||
supported=0
|
||||
skipped=0
|
||||
{
|
||||
echo "# M5 c-torture execute classifier scan"
|
||||
echo "# corpus: $SUITE_DIR"
|
||||
echo "# rows: status<TAB>test<TAB>reason"
|
||||
} > "$REPORT"
|
||||
while IFS= read -r src; do
|
||||
name=$(basename "$src" .c)
|
||||
total=$((total + 1))
|
||||
set +e
|
||||
reason=$("$CLASSIFY" "$src" 2>&1)
|
||||
rc=$?
|
||||
set -e
|
||||
case $rc in
|
||||
0)
|
||||
supported=$((supported + 1))
|
||||
printf 'supported\t%s\t\n' "$name" >> "$REPORT"
|
||||
;;
|
||||
1)
|
||||
skipped=$((skipped + 1))
|
||||
printf 'skip\t%s\t%s\n' "$name" "$reason" >> "$REPORT"
|
||||
;;
|
||||
*)
|
||||
fail "classifier error (exit $rc) on $name: $reason"
|
||||
;;
|
||||
esac
|
||||
done < "$WORK/c-torture-corpus.txt"
|
||||
{
|
||||
echo "# total $total supported $supported skip $skipped"
|
||||
} >> "$REPORT"
|
||||
echo "c-torture scan: total=$total supported=$supported skip=$skipped"
|
||||
echo "c-torture scan: skipped tests by feature:"
|
||||
awk -F '\t' '$1 == "skip" { split($3, a, ":"); print a[1] }' "$REPORT" \
|
||||
| sort | uniq -c | sort -rn | sed 's/^/ /' || true
|
||||
echo "c-torture scan: report $REPORT"
|
||||
[ "$supported" -gt 0 ] || fail "no supported c-torture tests in $SUITE_DIR"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
[ -f "$LIST" ] || fail "no c-torture.list ($LIST); Task 11 seeds it"
|
||||
LIST_COUNT=$(awk '$0 !~ /^[[:space:]]*(#|$)/ { n++ } END { print n + 0 }' "$LIST")
|
||||
[ "$LIST_COUNT" -gt 0 ] || fail "c-torture.list is empty ($LIST)"
|
||||
|
||||
# Each pass writes its own conformance log. The Task 9 runner prints one
|
||||
# machine-readable result line per test, plus the suite summary.
|
||||
run_pass() {
|
||||
opt=$1
|
||||
log=$2
|
||||
set +e
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$LOADER_END \
|
||||
M5_CONFORMANCE_CLANG_OPT=$opt \
|
||||
M5_CONFORMANCE_LLC_OPT=$opt \
|
||||
"$CONFORMANCE" "$LIST" > "$log" 2>&1
|
||||
rc=$?
|
||||
set -e
|
||||
echo "$rc" > "$log.rc"
|
||||
}
|
||||
|
||||
count() {
|
||||
awk -v pat="$2" '$0 ~ pat { n++ } END { print n + 0 }' "$1"
|
||||
}
|
||||
|
||||
run_pass -O0 "$WORK/c-torture-O0.log"
|
||||
run_pass -O2 "$WORK/c-torture-O2.log"
|
||||
|
||||
bad=0
|
||||
for opt in -O0 -O2; do
|
||||
case $opt in
|
||||
-O0) log=$WORK/c-torture-O0.log ;;
|
||||
-O2) log=$WORK/c-torture-O2.log ;;
|
||||
esac
|
||||
rc=$(cat "$log.rc")
|
||||
pass=$(count "$log" '^CONFORMANCE: PASS ')
|
||||
skip=$(count "$log" '^CONFORMANCE: SKIP ')
|
||||
# A test can print both a CONFORMANCE: FAIL row and the runner's
|
||||
# "c-torture: FAIL <name>" line; a compile/link/MAME failure that exits
|
||||
# before run.sh prints a result row only prints the latter. Count the
|
||||
# union of test names so a failure is not counted twice.
|
||||
: > "$WORK/c-torture-fail-names.log"
|
||||
grep '^CONFORMANCE: FAIL id=c-torture/' "$log" 2>/dev/null \
|
||||
| sed 's/^CONFORMANCE: FAIL id=c-torture\///; s/[[:space:]].*$//' \
|
||||
>> "$WORK/c-torture-fail-names.log" || true
|
||||
grep '^c-torture: FAIL ' "$log" 2>/dev/null \
|
||||
| sed 's/^c-torture: FAIL //; s/[[:space:]].*$//' \
|
||||
>> "$WORK/c-torture-fail-names.log" || true
|
||||
failn=$(sort -u "$WORK/c-torture-fail-names.log" | wc -l | tr -d ' ')
|
||||
[ "$pass" -gt 0 ] || {
|
||||
echo "c-torture: $opt no tests passed (pass=0 skip=$skip); all-skip is not a pass" >&2
|
||||
bad=1
|
||||
}
|
||||
[ "$failn" -eq 0 ] || {
|
||||
echo "c-torture: $opt $failn test(s) failed" >&2
|
||||
bad=1
|
||||
}
|
||||
[ "$rc" -eq 0 ] || {
|
||||
echo "c-torture: $opt conformance runner exited $rc" >&2
|
||||
bad=1
|
||||
}
|
||||
TOTAL=$((pass + skip + failn))
|
||||
[ "$TOTAL" -eq "$LIST_COUNT" ] || {
|
||||
echo "c-torture: $opt produced $TOTAL result rows, list has $LIST_COUNT" >&2
|
||||
bad=1
|
||||
}
|
||||
if [ "$skip" -gt 0 ]; then
|
||||
echo "c-torture: $opt skipped $skip test(s):" >&2
|
||||
grep '^CONFORMANCE: SKIP ' "$log" | sed 's/^/ /' >&2 || true
|
||||
fi
|
||||
eval "PASS_${opt#-}=$pass"
|
||||
eval "SKIP_${opt#-}=$skip"
|
||||
eval "FAIL_${opt#-}=$failn"
|
||||
done
|
||||
|
||||
if [ "$bad" -ne 0 ]; then
|
||||
echo "c-torture: logs $WORK" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "c-torture: PASS O0 pass=$PASS_O0 skip=$SKIP_O0 total=$LIST_COUNT O2 pass=$PASS_O2 skip=$SKIP_O2 total=$LIST_COUNT"
|
||||
echo "c-torture: logs $WORK"
|
||||
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
# c-testsuite single-exec entry point (M5 Task 12 seeds the list).
|
||||
#
|
||||
# c-testsuite.sh [LIST]
|
||||
#
|
||||
# Each non-comment line of LIST names a test under the pinned
|
||||
# vendor/conformance/c-testsuite/tests/single-exec tree. The test is
|
||||
# classified first; unsupported tests are reported as skips (never passes).
|
||||
# A supported test must return 0 and its stdout must equal
|
||||
# <name>.c.expected. A run with no passing test is a failure, even if every
|
||||
# test was skipped. This tier requires the native TI-COFF link (--mode native);
|
||||
# an asm/GSPA fallback is a failure, so a native-object regression cannot hide
|
||||
# here. All compile, link, MAME and compare work lives in run.sh.
|
||||
#
|
||||
# Default list: scripts/tests/m5/c-testsuite.list
|
||||
# Overridable: C_TESTSUITE_DIR M5_CONFORMANCE_DIR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
RUN=$HERE/run.sh
|
||||
CLASSIFY=$HERE/classify.sh
|
||||
|
||||
LIST=${1:-$ROOT/scripts/tests/m5/c-testsuite.list}
|
||||
SUITE_DIR=${C_TESTSUITE_DIR:-$ROOT/vendor/conformance/c-testsuite/tests/single-exec}
|
||||
|
||||
fail() {
|
||||
echo "c-testsuite: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
if [ ! -f "$LIST" ]; then
|
||||
fail "no c-testsuite.list ($LIST); Task 12 seeds it"
|
||||
fi
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-testsuite tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
pass=0
|
||||
skip=0
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
total=$((total + 1))
|
||||
base=${name%.c}
|
||||
src=$SUITE_DIR/$base.c
|
||||
expected=$SUITE_DIR/$base.c.expected
|
||||
[ -f "$expected" ] || expected=$SUITE_DIR/$base.expected
|
||||
[ -f "$src" ] || fail "missing c-testsuite source: $src"
|
||||
[ -f "$expected" ] || fail "missing c-testsuite expected output: $expected"
|
||||
if "$RUN" --id "c-testsuite/$base" --classify --mode native \
|
||||
--expect-status 0 --expect-output-file "$expected" "$src"; then
|
||||
pass=$((pass + 1))
|
||||
else
|
||||
rc=$?
|
||||
if [ "$rc" -eq 2 ]; then
|
||||
skip=$((skip + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "c-testsuite: FAIL $base" >&2
|
||||
fi
|
||||
fi
|
||||
done < "$LIST"
|
||||
|
||||
[ "$total" -gt 0 ] || fail "c-testsuite.list is empty"
|
||||
[ "$failed" -eq 0 ] || fail "$failed of $total tests failed"
|
||||
[ "$pass" -gt 0 ] \
|
||||
|| fail "no tests passed (pass=0 skip=$skip total=$total); all-skip is not a pass"
|
||||
echo "c-testsuite: PASS pass=$pass skip=$skip total=$total"
|
||||
Executable
+67
@@ -0,0 +1,67 @@
|
||||
#!/bin/sh
|
||||
# c-torture conformance entry point (M5 Task 11 seeds the list).
|
||||
#
|
||||
# c-torture.sh [LIST]
|
||||
#
|
||||
# Each non-comment line of LIST names a test under the pinned
|
||||
# vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute tree.
|
||||
# The test is classified first; unsupported tests are reported as skips (never
|
||||
# passes), and supported tests must return 0 (stdout is ignored here). A run
|
||||
# with no passing test is a failure, even if every test was skipped. All
|
||||
# compile, link, MAME and compare work lives in run.sh.
|
||||
#
|
||||
# Default list: scripts/tests/m5/c-torture.list
|
||||
# Overridable: C_TORTURE_DIR M5_CONFORMANCE_DIR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
RUN=$HERE/run.sh
|
||||
CLASSIFY=$HERE/classify.sh
|
||||
|
||||
LIST=${1:-$ROOT/scripts/tests/m5/c-torture.list}
|
||||
SUITE_DIR=${C_TORTURE_DIR:-$ROOT/vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute}
|
||||
|
||||
fail() {
|
||||
echo "c-torture: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
if [ ! -f "$LIST" ]; then
|
||||
fail "no c-torture.list ($LIST); Task 11 seeds it"
|
||||
fi
|
||||
[ -d "$SUITE_DIR" ] || fail "missing pinned c-torture tree: $SUITE_DIR (run scripts/fetch-conformance.sh)"
|
||||
|
||||
pass=0
|
||||
skip=0
|
||||
failed=0
|
||||
total=0
|
||||
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
total=$((total + 1))
|
||||
src=$SUITE_DIR/$name.c
|
||||
[ -f "$src" ] || fail "missing c-torture source: $src"
|
||||
if "$RUN" --id "c-torture/$name" --classify \
|
||||
--expect-status 0 --ignore-output "$src"; then
|
||||
pass=$((pass + 1))
|
||||
else
|
||||
rc=$?
|
||||
if [ "$rc" -eq 2 ]; then
|
||||
skip=$((skip + 1))
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "c-torture: FAIL $name" >&2
|
||||
fi
|
||||
fi
|
||||
done < "$LIST"
|
||||
|
||||
[ "$total" -gt 0 ] || fail "c-torture.list is empty"
|
||||
[ "$failed" -eq 0 ] || fail "$failed of $total tests failed"
|
||||
[ "$pass" -gt 0 ] \
|
||||
|| fail "no tests passed (pass=0 skip=$skip total=$total); all-skip is not a pass"
|
||||
echo "c-torture: PASS pass=$pass skip=$skip total=$total"
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
#!/bin/sh
|
||||
# Classify a C source for features the M6 conformance path cannot run.
|
||||
#
|
||||
# classify.sh FILE
|
||||
#
|
||||
# Prints "feature: reason" and exits 1 when the source uses an unsupported
|
||||
# feature; prints nothing and exits 0 when it is acceptable. Exits 2 for
|
||||
# usage, unreadable-source, grep or skip-table errors, so callers can tell a
|
||||
# real skip apart from a classifier failure. The reasons come from skip.tsv
|
||||
# so the manifest, suite runners and reports agree.
|
||||
#
|
||||
# M6 implements floats/doubles, 64-bit integers, bitfields, general varargs
|
||||
# and aggregates, so those are no longer skipped. The remaining skips are
|
||||
# genuine M6 non-goals: 128-bit integers, non-local jumps, signals, wide
|
||||
# characters, stdio/POSIX file I/O and the printf conversions the shim does
|
||||
# not implement. This is deliberately conservative: a false positive skips a
|
||||
# test (and says why), while a false negative could turn an unsupported test
|
||||
# into a fake pass. Comments are scanned; printf conversions are checked
|
||||
# inside string literals only.
|
||||
set -eu
|
||||
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
SKIPS=$HERE/skip.tsv
|
||||
|
||||
[ $# -eq 1 ] || { echo "usage: $0 FILE.c" >&2; exit 2; }
|
||||
SRC=$1
|
||||
[ -f "$SRC" ] || { echo "classify: missing source: $SRC" >&2; exit 2; }
|
||||
[ -f "$SKIPS" ] || { echo "classify: missing $SKIPS" >&2; exit 2; }
|
||||
|
||||
feature=
|
||||
|
||||
match() {
|
||||
[ -z "$feature" ] || return 0
|
||||
if grep -Eqi -- "$2" "$SRC"; then
|
||||
feature=$1
|
||||
else
|
||||
st=$?
|
||||
[ "$st" -eq 1 ] || {
|
||||
echo "classify: grep failed (status $st) on $SRC" >&2
|
||||
exit 2
|
||||
}
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# A printf conversion is only meaningful inside a string literal. Scan the
|
||||
# double-quoted literals instead of the whole source so a C modulo expression
|
||||
# (`x % e`, `0 % a++`, `(c || b) % g`) is not mistaken for a conversion.
|
||||
# Escaped quotes are split so a conversion after \" is still seen.
|
||||
match_formats() {
|
||||
[ -z "$feature" ] || return 0
|
||||
set +e
|
||||
literals=$(sed 's/\\"/""/g' "$SRC" | grep -o '"[^"]*"')
|
||||
st=$?
|
||||
set -e
|
||||
[ "$st" -le 1 ] || {
|
||||
echo "classify: string-literal scan failed (status $st) on $SRC" >&2
|
||||
exit 2
|
||||
}
|
||||
if printf '%s\n' "$literals" | grep -Eq -- "$2"; then
|
||||
feature=$1
|
||||
else
|
||||
st=$?
|
||||
[ "$st" -eq 1 ] || {
|
||||
echo "classify: grep failed (status $st) on $SRC" >&2
|
||||
exit 2
|
||||
}
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Order is only cosmetic; the first match names the primary blocker. Most
|
||||
# matches are case-insensitive so macro spellings are not missed. The
|
||||
# format-unsupported scan is case-sensitive because %L/%e/%g/%a/%F are
|
||||
# distinct conversions and %ld/%lld/%lf are supported; the regex spells out
|
||||
# the uppercase forms it does match.
|
||||
match int128 '__int128|__uint128|__int128_t|__uint128_t'
|
||||
match setjmp '(^|[^A-Za-z0-9_])(setjmp|longjmp|sigsetjmp|siglongjmp)([^A-Za-z0-9_]|$)'
|
||||
match signal '(^|[^A-Za-z0-9_])(signal|sigaction|sigemptyset|sigaddset|sigprocmask)([^A-Za-z0-9_]|$)'
|
||||
match wide-char '(^|[^A-Za-z0-9_])(wchar|wchar_t|wint_t|wprintf|wscanf)([^A-Za-z0-9_]|$)|L"|L'"'"''
|
||||
# %n (also %hhn/%lln), positional arguments, the floating conversions without
|
||||
# shim support (%e/%g/%a/%F, including %lF), %j (intmax_t is 64-bit here while
|
||||
# the shim reads 32), long double and wide strings are genuinely unsupported.
|
||||
# %z/%t are supported: size_t is unsigned int and ptrdiff_t is int on this
|
||||
# target, so the shim's 32-bit read is correct. Field width, precision, * and
|
||||
# %lld/%llu/%f are implemented and must not be skipped.
|
||||
match_formats format-unsupported '%[-+ #0-9.*]*\$|%[-+ #0-9.*]*l?[eEgGaAF]|%[-+ #0-9.*]*j[diouxX]|%[-+ #0-9.*]*(hh|h|ll|l)?n|%[-+ #0-9.*]*L[diouxXeEfgGaAF]|%[-+ #0-9.*]*l[sc]'
|
||||
match file-io '(^|[^A-Za-z0-9_])(FILE|fopen|fclose|fread|fwrite|fprintf|freopen|fflush|fseek|ftell|fgetc|fputc|fgets|fputs|remove|rename|tmpfile|tmpnam)([^A-Za-z0-9_]|$)|(^|[^A-Za-z0-9_])(open|creat)[[:space:]]*\('
|
||||
|
||||
[ -n "$feature" ] || exit 0
|
||||
|
||||
reason=$(awk -F '\t' -v f="$feature" '$1 == f { print $2; exit }' "$SKIPS") \
|
||||
|| { echo "classify: cannot read $SKIPS" >&2; exit 2; }
|
||||
[ -n "$reason" ] || {
|
||||
echo "classify: no reason for feature '$feature' in $SKIPS" >&2
|
||||
exit 2
|
||||
}
|
||||
printf '%s: %s\n' "$feature" "$reason"
|
||||
exit 1
|
||||
@@ -0,0 +1,129 @@
|
||||
-- conformance-check.lua -- load the conformance COFF with the M4 loader and
|
||||
-- publish the shim's result block.
|
||||
--
|
||||
-- The loader is scripts/m4/run.sh's loader (vendor/vt1200/dwt/loader/loader.lua),
|
||||
-- loaded through M4_LOADER_LUA. The test's entry writes:
|
||||
-- 01B00000 status
|
||||
-- 01B00020 out_len
|
||||
-- 01B00040 magic 0x434F4E46
|
||||
-- 01B10000 output bytes (bit addresses, 8 bits apart)
|
||||
--
|
||||
-- The block is above the linker-managed .bss region (01A00000..01A80000), so
|
||||
-- test globals cannot overwrite it. The runner rejects len >= the 16 KiB cap
|
||||
-- because the shim truncates there.
|
||||
--
|
||||
-- The result is written to CONF_RESULT in a stable, shell-readable form:
|
||||
-- status=<8 hex>
|
||||
-- len=<decimal>
|
||||
-- magic=<8 hex>
|
||||
-- loader=<8 hex> (loader result block status at 01882D00)
|
||||
-- out=<uppercase hex bytes>
|
||||
--
|
||||
-- The runner compares this file against the manifest/expected result. A
|
||||
-- missing magic is a failure, never a pass.
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local machine = manager.machine
|
||||
local cpu = machine.devices[':maincpu']
|
||||
local prog = cpu.spaces['program']
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
||||
local RESULT = os.getenv("CONF_RESULT") or "conformance-result.txt"
|
||||
|
||||
local STATUS = 0x01B00000
|
||||
local LEN = 0x01B00020
|
||||
local MAGIC = 0x01B00040
|
||||
local OUT = 0x01B10000
|
||||
local CAP = 16384
|
||||
local MAGIC_VAL = 0x434F4E46
|
||||
local LOADER_STATUS = 0x01882D00
|
||||
|
||||
local frames = 0
|
||||
local done = false
|
||||
|
||||
local function rd32(a)
|
||||
local ok, v = pcall(function() return prog:read_u32(a) end)
|
||||
if ok then return v end
|
||||
return 0xDEADBEEF
|
||||
end
|
||||
|
||||
local function rd8(a)
|
||||
local ok, v = pcall(function() return prog:read_u8(a) end)
|
||||
if ok then return v end
|
||||
return 0
|
||||
end
|
||||
|
||||
local function dump(tag)
|
||||
local status = rd32(STATUS)
|
||||
local raw_len = rd32(LEN)
|
||||
local magic = rd32(MAGIC)
|
||||
local loader = rd32(LOADER_STATUS)
|
||||
local bytes = {}
|
||||
local shown = {}
|
||||
local n = 0
|
||||
local nread = raw_len
|
||||
|
||||
-- Keep the raw length for the runner (it rejects len >= CAP), but never
|
||||
-- loop over an implausible value.
|
||||
if nread < 0 or nread > CAP then
|
||||
nread = 0
|
||||
end
|
||||
for i = 0, nread - 1 do
|
||||
local b = rd8(OUT + i * 8)
|
||||
bytes[#bytes + 1] = string.format("%02X", b)
|
||||
if i < 128 then
|
||||
shown[#shown + 1] = string.format("%02X", b)
|
||||
end
|
||||
n = n + 1
|
||||
end
|
||||
local outhex = table.concat(bytes)
|
||||
local shownhex = table.concat(shown)
|
||||
if n > 128 then
|
||||
shownhex = shownhex .. "..."
|
||||
end
|
||||
|
||||
print(string.format(
|
||||
"CONF: %s status=%08X len=%d magic=%08X loader=%08X out=%s",
|
||||
tag, status, raw_len, magic, loader, shownhex))
|
||||
|
||||
local f, err = io.open(RESULT, "w")
|
||||
if not f then
|
||||
print("CONF: cannot write result " .. tostring(RESULT) ..
|
||||
": " .. tostring(err))
|
||||
machine:exit()
|
||||
return
|
||||
end
|
||||
f:write(string.format("status=%08X\n", status))
|
||||
f:write(string.format("len=%d\n", raw_len))
|
||||
f:write(string.format("magic=%08X\n", magic))
|
||||
f:write(string.format("loader=%08X\n", loader))
|
||||
f:write("out=" .. outhex .. "\n")
|
||||
f:close()
|
||||
|
||||
if magic == MAGIC_VAL and loader == 0 then
|
||||
print("CONF MAME: PASS")
|
||||
else
|
||||
print("CONF MAME: FAIL")
|
||||
end
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames <= AT or done then
|
||||
return
|
||||
end
|
||||
|
||||
local magic = rd32(MAGIC)
|
||||
local loader = rd32(LOADER_STATUS)
|
||||
|
||||
-- A successful run publishes the magic. A loader error after injection
|
||||
-- is final even if the app never starts. Otherwise wait for ENDF.
|
||||
if magic == MAGIC_VAL or (frames > AT + 60 and loader ~= 0)
|
||||
or frames >= ENDF then
|
||||
done = true
|
||||
dump(frames >= ENDF and "timeout" or "result")
|
||||
machine:exit()
|
||||
end
|
||||
end, "m5-conformance-check")
|
||||
@@ -0,0 +1,10 @@
|
||||
; data-pad.asm -- keep the linked .data section a whole number of 16-bit words.
|
||||
;
|
||||
; llc emits an odd-length byte array (for example a 7-byte string literal)
|
||||
; without a trailing word, so the concatenated .data section can end on an
|
||||
; odd byte. The VT1200 COFF loader rejects a section whose bit size is not a
|
||||
; whole number of words (status 4). This object is linked last in both the
|
||||
; native and asm paths. GSPA aligns a .word directive to a 16-bit boundary,
|
||||
; so this pads any preceding odd byte and then contributes exactly one word.
|
||||
.data
|
||||
.word 0
|
||||
@@ -0,0 +1,68 @@
|
||||
; entry.asm -- M5 conformance entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the test's main(1, argv) through the M4 TI ABI and publishes the
|
||||
; result for the MAME check:
|
||||
;
|
||||
; 01B00000 status main's return value
|
||||
; 01B00020 out_len maintained by shim.c
|
||||
; 01B00040 magic 0x434F4E46 after main returns
|
||||
; 01B10000 output shim.c's 16 KiB output buffer
|
||||
;
|
||||
; The result block is above the linker-managed RAM region
|
||||
; (01A00000..01A80000), so a test's .bss cannot overwrite it. That region is
|
||||
; 64 KiB and this file reserves 4 KiB for _cstack; Tasks 11/12 should keep the
|
||||
; sum of globals and stack under those limits.
|
||||
;
|
||||
; exit()/abort() in shim.c publish status and magic themselves and spin, so
|
||||
; an abnormal test still leaves an observable result. argv is a real
|
||||
; two-element vector: { "conformance", NULL }.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
|
||||
; Clear the result cells that live outside every loaded section.
|
||||
movi 01B00000h, a1
|
||||
sub a0, a0
|
||||
move a0, *a1, 1
|
||||
movi 01B00020h, a1
|
||||
move a0, *a1, 1
|
||||
movi 01B00040h, a1
|
||||
move a0, *a1, 1
|
||||
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
; argv[0] = "conformance", argv[1] = NULL.
|
||||
movi _conformance_argv, a0
|
||||
movi _conformance_name, a1
|
||||
move a1, *a0, 1
|
||||
sub a1, a1
|
||||
move a1, *a0(32), 1
|
||||
|
||||
; main(1, argv): arguments are pushed in reverse order on A14.
|
||||
move a14, -*sp, 1
|
||||
move a0, *a14+, 1
|
||||
movi 1, a1
|
||||
move a1, *a14+, 1
|
||||
calla _main
|
||||
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
|
||||
movi 01B00000h, a1
|
||||
move a8, *a1, 1
|
||||
movi 01B00040h, a1
|
||||
movi 434F4E46h, a0
|
||||
move a0, *a1, 1
|
||||
rets
|
||||
|
||||
.data
|
||||
_conformance_name:
|
||||
.byte 063h, 06Fh, 06Eh, 066h, 06Fh, 072h, 06Dh, 061h
|
||||
.byte 06Eh, 063h, 065h, 000h
|
||||
.even
|
||||
|
||||
.bss _conformance_argv, 64, 1
|
||||
.bss _cstack, 32768, 16
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef CONFORMANCE_LIMITS_H
|
||||
#define CONFORMANCE_LIMITS_H
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define SCHAR_MIN (-128)
|
||||
#define SCHAR_MAX 127
|
||||
#define UCHAR_MAX 255
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#define SHRT_MIN (-32768)
|
||||
#define SHRT_MAX 32767
|
||||
#define USHRT_MAX 65535
|
||||
#define INT_MIN (-2147483647 - 1)
|
||||
#define INT_MAX 2147483647
|
||||
#define UINT_MAX 4294967295U
|
||||
#define LONG_MIN INT_MIN
|
||||
#define LONG_MAX INT_MAX
|
||||
#define ULONG_MAX UINT_MAX
|
||||
#define LLONG_MIN (-9223372036854775807LL - 1)
|
||||
#define LLONG_MAX 9223372036854775807LL
|
||||
#define ULLONG_MAX 18446744073709551615ULL
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef CONFORMANCE_STDARG_H
|
||||
#define CONFORMANCE_STDARG_H
|
||||
|
||||
/* M6 general varargs: the target's va_list is the compiler's built-in
|
||||
* downward stack walk (see scripts/m6/varargs-main.c). Keep these macros
|
||||
* thin wrappers over the clang builtins so the va_arg type/ABI rules come
|
||||
* from the target lowering, not from a header layout guess. */
|
||||
|
||||
typedef __builtin_va_list va_list;
|
||||
|
||||
#define va_start(ap, last) __builtin_va_start(ap, last)
|
||||
#define va_arg(ap, type) __builtin_va_arg(ap, type)
|
||||
#define va_end(ap) __builtin_va_end(ap)
|
||||
#define va_copy(dst, src) __builtin_va_copy(dst, src)
|
||||
#define __va_copy(dst, src) __builtin_va_copy(dst, src)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,14 @@
|
||||
#ifndef CONFORMANCE_STDDEF_H
|
||||
#define CONFORMANCE_STDDEF_H
|
||||
|
||||
typedef unsigned int size_t;
|
||||
typedef int ptrdiff_t;
|
||||
typedef int wchar_t;
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef CONFORMANCE_STDINT_H
|
||||
#define CONFORMANCE_STDINT_H
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef int intptr_t;
|
||||
typedef unsigned int uintptr_t;
|
||||
typedef long long intmax_t;
|
||||
typedef unsigned long long uintmax_t;
|
||||
|
||||
#define INT8_MIN (-128)
|
||||
#define INT8_MAX 127
|
||||
#define UINT8_MAX 255U
|
||||
#define INT16_MIN (-32768)
|
||||
#define INT16_MAX 32767
|
||||
#define UINT16_MAX 65535U
|
||||
#define INT32_MIN (-2147483647 - 1)
|
||||
#define INT32_MAX 2147483647
|
||||
#define UINT32_MAX 4294967295U
|
||||
#define INT64_MIN (-9223372036854775807LL - 1)
|
||||
#define INT64_MAX 9223372036854775807LL
|
||||
#define UINT64_MAX 18446744073709551615ULL
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
#define INTMAX_MIN INT64_MIN
|
||||
#define INTMAX_MAX INT64_MAX
|
||||
#define UINTMAX_MAX UINT64_MAX
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,13 @@
|
||||
#ifndef CONFORMANCE_STDIO_H
|
||||
#define CONFORMANCE_STDIO_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
int printf(const char *fmt, ...);
|
||||
int sprintf(char *buf, const char *fmt, ...);
|
||||
int putchar(int c);
|
||||
int puts(const char *s);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef CONFORMANCE_STDLIB_H
|
||||
#define CONFORMANCE_STDLIB_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
#define RAND_MAX 32767
|
||||
|
||||
void exit(int status);
|
||||
void _exit(int status);
|
||||
void abort(void);
|
||||
int atoi(const char *s);
|
||||
int abs(int v);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef CONFORMANCE_STRING_H
|
||||
#define CONFORMANCE_STRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
unsigned int strlen(const char *s);
|
||||
int strcmp(const char *a, const char *b);
|
||||
int strncmp(const char *a, const char *b, unsigned int n);
|
||||
char *strcpy(char *d, const char *s);
|
||||
char *strncpy(char *d, const char *s, unsigned int n);
|
||||
char *strchr(const char *s, int c);
|
||||
char *strrchr(const char *s, int c);
|
||||
void *memcpy(void *dst, const void *src, unsigned int n);
|
||||
void *memmove(void *dst, const void *src, unsigned int n);
|
||||
void *memset(void *dst, int c, unsigned int n);
|
||||
int memcmp(const void *a, const void *b, unsigned int n);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
-a
|
||||
-o M4.OUT
|
||||
-m M4.MAP
|
||||
-e _start
|
||||
M4.obj
|
||||
-l m6flib.lib
|
||||
-l m6rts.lib
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 58000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# M5 conformance manifest
|
||||
#
|
||||
# test_id<TAB>suite<TAB>expected<TAB>features<TAB>skip_reason
|
||||
#
|
||||
# expected: status=<decimal> or status=<decimal>;stdout=<escaped text>
|
||||
# escapes: \n \t \r \\ (interpreted with printf %b)
|
||||
# features: space-separated classifier tags (int-control, print, ...)
|
||||
# skip_reason: empty for a runnable row; a non-empty reason is reported as a
|
||||
# SKIP and is never counted as a pass.
|
||||
#
|
||||
# Tasks 11 and 12 seed the c-torture and c-testsuite rows. This file defines
|
||||
# the row format and is read by scripts/tests/m5/conformance/run.sh
|
||||
# --manifest-row.
|
||||
#
|
||||
# Examples (kept commented so the gate does not try to fetch them here):
|
||||
# int-control/c0001 c-torture status=0;stdout= int-control
|
||||
# single-exec/0001 c-testsuite status=0;stdout=ok\n print #
|
||||
|
Executable
+496
@@ -0,0 +1,496 @@
|
||||
#!/bin/sh
|
||||
# M5 conformance runner: compile one C test with the shim and entry, link it
|
||||
# through the M4 pipeline (native TI-COFF when it works, asm/GSPA fallback),
|
||||
# load the COFF in MAME, and compare the observed status/stdout with the
|
||||
# expected result.
|
||||
#
|
||||
# run.sh [options] SOURCE.c
|
||||
#
|
||||
# --id ID label (default: source basename)
|
||||
# --expect SPEC expected result:
|
||||
# status=<decimal>[;stdout=<escaped text>]
|
||||
# escapes understood by printf %b: \n \t \r \\
|
||||
# default: status=0;stdout= (silent success)
|
||||
# --expect-status N override the expected status
|
||||
# --expect-output-file F expect stdout to be exactly the bytes in F
|
||||
# --ignore-output compare only the status (c-torture success is silent
|
||||
# or diagnostic output; c-testsuite keeps the compare)
|
||||
# --manifest-row ROW parse test_id<TAB>suite<TAB>expected<TAB>features<TAB>skip_reason
|
||||
# --classify skip (exit 2) when classify.sh rejects SOURCE
|
||||
# --mode auto|native|asm link mode (default auto: native, asm fallback)
|
||||
# --native same as --mode native
|
||||
# --asm same as --mode asm
|
||||
# --timeout SECONDS MAME timeout (default 900)
|
||||
#
|
||||
# Exit status: 0 pass, 1 failure (compile/link/MAME/classifier/compare),
|
||||
# 2 skip (a classified unsupported test or a manifest skip_reason).
|
||||
#
|
||||
# The linker-managed .bss region is 01A00000..01A80000 (64 KiB, including the
|
||||
# 4 KiB _cstack in entry.asm). The result block is above it at 01B00000, so a
|
||||
# test's globals cannot overwrite the status/output.
|
||||
#
|
||||
# The runner prints one machine-readable result line:
|
||||
# CONFORMANCE: PASS id=... status=... stdout_len=... link=...
|
||||
# CONFORMANCE: FAIL id=...
|
||||
# CONFORMANCE: SKIP id=... reason=...
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG M4_SDK M6_LIB_SDK LOADER_AT LOADER_END
|
||||
# MAME_TIMEOUT M5_CONFORMANCE_WORK M5_CONFORMANCE_CLANG_OPT
|
||||
# M5_CONFORMANCE_LLC_OPT M5_CONFORMANCE_MODE
|
||||
# M5_CONFORMANCE_CLASSIFY
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
CLASSIFY=${M5_CONFORMANCE_CLASSIFY:-$HERE/classify.sh}
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
M4_SDK=${M4_SDK:-$ROOT/build/m4-sdk}
|
||||
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=${LOADER_BIN:-$ROOT/vendor/vt1200/dwt/loader/build/loader.bin}
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
MAME_TIMEOUT=${MAME_TIMEOUT:-900}
|
||||
|
||||
WORK_BASE=${M5_CONFORMANCE_WORK:-$ROOT/build/m5-conformance}
|
||||
CLANG_OPT=${M5_CONFORMANCE_CLANG_OPT:--O0}
|
||||
LLC_OPT=${M5_CONFORMANCE_LLC_OPT:--O0}
|
||||
MODE=${M5_CONFORMANCE_MODE:-auto}
|
||||
|
||||
# Shim contract constants (keep in sync with shim.c and conformance-check.lua).
|
||||
OUT_CAP=16384
|
||||
PROG_ORIGIN=$((0x018A0000))
|
||||
PROG_END=$((0x018F8000))
|
||||
RAM_ORIGIN=$((0x01A00000))
|
||||
RAM_END=$((0x01A80000))
|
||||
RESULT_BASE=$((0x01B00000))
|
||||
|
||||
ID=
|
||||
SRC=
|
||||
EXPECT_SPEC=
|
||||
EXPECT_SPEC_SET=0
|
||||
EXPECT_STATUS=
|
||||
EXPECT_OUTPUT_FILE=
|
||||
MANIFEST_ROW=
|
||||
DO_CLASSIFY=0
|
||||
IGNORE_OUTPUT=0
|
||||
FEATURES=
|
||||
|
||||
fail() {
|
||||
echo "conformance: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
sed -n '2,/^set -eu/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//' >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--id)
|
||||
[ $# -ge 2 ] || usage
|
||||
ID=$2
|
||||
shift 2
|
||||
;;
|
||||
--expect)
|
||||
[ $# -ge 2 ] || usage
|
||||
EXPECT_SPEC=$2
|
||||
EXPECT_SPEC_SET=1
|
||||
shift 2
|
||||
;;
|
||||
--expect-status)
|
||||
[ $# -ge 2 ] || usage
|
||||
EXPECT_STATUS=$2
|
||||
shift 2
|
||||
;;
|
||||
--expect-output-file)
|
||||
[ $# -ge 2 ] || usage
|
||||
EXPECT_OUTPUT_FILE=$2
|
||||
shift 2
|
||||
;;
|
||||
--ignore-output)
|
||||
IGNORE_OUTPUT=1
|
||||
shift
|
||||
;;
|
||||
--manifest-row)
|
||||
[ $# -ge 2 ] || usage
|
||||
MANIFEST_ROW=$2
|
||||
shift 2
|
||||
;;
|
||||
--classify)
|
||||
DO_CLASSIFY=1
|
||||
shift
|
||||
;;
|
||||
--mode)
|
||||
[ $# -ge 2 ] || usage
|
||||
MODE=$2
|
||||
shift 2
|
||||
;;
|
||||
--native)
|
||||
MODE=native
|
||||
shift
|
||||
;;
|
||||
--asm)
|
||||
MODE=asm
|
||||
shift
|
||||
;;
|
||||
--timeout)
|
||||
[ $# -ge 2 ] || usage
|
||||
MAME_TIMEOUT=$2
|
||||
shift 2
|
||||
;;
|
||||
--)
|
||||
shift
|
||||
break
|
||||
;;
|
||||
-*)
|
||||
echo "conformance: unknown option: $1" >&2
|
||||
usage
|
||||
;;
|
||||
*)
|
||||
[ -z "$SRC" ] || fail "more than one source given: $SRC and $1"
|
||||
SRC=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
[ $# -eq 0 ] || fail "unexpected trailing arguments: $*"
|
||||
[ -n "$SRC" ] || usage
|
||||
[ -f "$SRC" ] || fail "missing source: $SRC"
|
||||
case $MODE in
|
||||
auto|native|asm) ;;
|
||||
*) fail "bad link mode '$MODE' (want auto, native or asm)" ;;
|
||||
esac
|
||||
|
||||
if [ -n "$MANIFEST_ROW" ]; then
|
||||
ROW_ID=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $1}')
|
||||
ROW_SUITE=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $2}')
|
||||
ROW_EXPECT=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $3}')
|
||||
ROW_FEATURES=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $4}')
|
||||
ROW_SKIP=$(printf '%s\n' "$MANIFEST_ROW" | awk -F '\t' '{print $5}')
|
||||
[ -n "$ID" ] || ID=$ROW_ID
|
||||
if [ -n "$ROW_EXPECT" ]; then
|
||||
EXPECT_SPEC=$ROW_EXPECT
|
||||
EXPECT_SPEC_SET=1
|
||||
fi
|
||||
FEATURES=$ROW_FEATURES
|
||||
if [ -n "$ROW_SKIP" ]; then
|
||||
echo "CONFORMANCE: SKIP id=${ID:-$SRC} reason=$ROW_SKIP"
|
||||
exit 2
|
||||
fi
|
||||
# The suite column is informational; keep it in logs when present.
|
||||
[ -z "$ROW_SUITE" ] || FEATURES="${FEATURES:+$FEATURES }suite=$ROW_SUITE"
|
||||
fi
|
||||
|
||||
[ -n "$ID" ] || ID=$(basename "$SRC" .c)
|
||||
case $ID in
|
||||
.|..) fail "unsafe id '$ID' (would escape the work directory)" ;;
|
||||
esac
|
||||
SAFE_ID=$(printf '%s' "$ID" | tr -c 'A-Za-z0-9._-' '_')
|
||||
case $SAFE_ID in
|
||||
''|.|..) fail "unsafe id '$ID' (would escape the work directory)" ;;
|
||||
esac
|
||||
WORK=$WORK_BASE/$SAFE_ID
|
||||
|
||||
if [ "$DO_CLASSIFY" -eq 1 ]; then
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
set +e
|
||||
REASON=$("$CLASSIFY" "$SRC" 2>&1)
|
||||
RC=$?
|
||||
set -e
|
||||
case $RC in
|
||||
0) ;;
|
||||
1) echo "CONFORMANCE: SKIP id=$ID reason=$REASON"; exit 2 ;;
|
||||
*) fail "classifier error (exit $RC): $REASON" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Parse the expected result after any manifest/option overrides.
|
||||
STATUS_EXPECT=0
|
||||
OUT_ESCAPED=
|
||||
if [ "$EXPECT_SPEC_SET" -eq 1 ]; then
|
||||
case $EXPECT_SPEC in
|
||||
status=*)
|
||||
REST=${EXPECT_SPEC#status=}
|
||||
case $REST in
|
||||
*';stdout='*)
|
||||
STATUS_EXPECT=${REST%%;stdout=*}
|
||||
OUT_ESCAPED=${REST#*;stdout=}
|
||||
;;
|
||||
*)
|
||||
STATUS_EXPECT=$REST
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
*)
|
||||
fail "bad expected result '$EXPECT_SPEC' (want status=N[;stdout=TEXT])"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
[ -z "$EXPECT_STATUS" ] || STATUS_EXPECT=$EXPECT_STATUS
|
||||
case $STATUS_EXPECT in
|
||||
''|*[!0-9]*) fail "expected status is not decimal: '$STATUS_EXPECT'" ;;
|
||||
esac
|
||||
EXPECT_STATUS_HEX=$(printf '%08X' "$STATUS_EXPECT")
|
||||
|
||||
if [ -n "$EXPECT_OUTPUT_FILE" ]; then
|
||||
[ -f "$EXPECT_OUTPUT_FILE" ] \
|
||||
|| fail "missing expected output file: $EXPECT_OUTPUT_FILE"
|
||||
EXPECT_HEX=$(od -An -v -tx1 "$EXPECT_OUTPUT_FILE" | tr -d ' \n')
|
||||
EXPECT_SOURCE=$EXPECT_OUTPUT_FILE
|
||||
else
|
||||
EXPECT_HEX=$(printf '%b' "$OUT_ESCAPED" | od -An -v -tx1 | tr -d ' \n')
|
||||
EXPECT_SOURCE="status=$STATUS_EXPECT;stdout=$OUT_ESCAPED"
|
||||
fi
|
||||
EXPECT_HEX=$(printf '%s' "$EXPECT_HEX" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$MAME" ] || fail "missing MAME: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK" "$WORK/run/nvram" "$WORK/run/cfg" "$WORK/evidence"
|
||||
rm -f "$WORK/result.txt"
|
||||
|
||||
# The shim's %f uses the compiler's GSP double arithmetic and fptosi/sitofp,
|
||||
# which reach the 1990 flib.lib FD$ entries; memcpy/memmove and the rest of the
|
||||
# shim stay ordinary C. Copy the 1990 libraries under M6* names so they cannot
|
||||
# collide with the 1987 SDK's own FLIB.LIB/RTS.LIB (a different, smaller GSP
|
||||
# library) in the shared M4 SDK directory.
|
||||
echo "== extract the 1990 flib.lib/rts.lib for the shim's %f"
|
||||
LIB_SDK=${M6_LIB_SDK:-$ROOT/build/m6-sdk}
|
||||
if [ ! -f "$LIB_SDK/flib.lib" ] || [ ! -f "$LIB_SDK/rts.lib" ]; then
|
||||
mkdir -p "$LIB_SDK"
|
||||
M6_SDK_OUT="$LIB_SDK" "$ROOT/scripts/m6/flib-extract.sh" \
|
||||
> "$WORK/flib-extract.log" 2>&1 \
|
||||
|| { cat "$WORK/flib-extract.log" >&2; fail "flib-extract.sh failed"; }
|
||||
fi
|
||||
mkdir -p "$M4_SDK"
|
||||
cp "$LIB_SDK/flib.lib" "$M4_SDK/M6FLIB.LIB"
|
||||
cp "$LIB_SDK/rts.lib" "$M4_SDK/M6RTS.LIB"
|
||||
|
||||
# GSPA/GSPLNK 2.00 use 8.3 object names, and GSPLNK misparses an object name
|
||||
# that starts with a digit (the c-testsuite files are 00001.c, ...). Compile a
|
||||
# short local copy so the native object path works for every test name; keep
|
||||
# the original directory on the include path for quoted headers.
|
||||
SRC_DIR=$(cd "$(dirname "$SRC")" && pwd)
|
||||
COMPILE_SRC=$WORK/test.c
|
||||
cp "$SRC" "$COMPILE_SRC"
|
||||
|
||||
link_once() {
|
||||
native=$1
|
||||
log=$2
|
||||
M4_SOURCES="$COMPILE_SRC $HERE/shim.c" \
|
||||
M4_ENTRY="$HERE/entry.asm" \
|
||||
M4_CLANG_OPT="$CLANG_OPT" \
|
||||
M4_LLC_OPT="$LLC_OPT" \
|
||||
M4_EXTRA_INCLUDES="-I $HERE/include -I $SRC_DIR" \
|
||||
M4_WORK="$WORK/m4" \
|
||||
M4_COFF="$WORK/m4/m4.coff" \
|
||||
M4_SDK="$M4_SDK" \
|
||||
M4_NATIVE_PROG_LEN=58000h \
|
||||
M4_NATIVE_RAM_LEN=80000h \
|
||||
M4_NATIVE_LIBS="m6flib.lib m6rts.lib" \
|
||||
M4_LINK_CMD="$HERE/link.cmd" \
|
||||
M4_EXTRA_ASM="$HERE/data-pad.asm" \
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_NATIVE="$native" \
|
||||
"$ROOT/scripts/m4/run.sh" > "$log" 2>&1
|
||||
}
|
||||
|
||||
check_map() {
|
||||
map=$WORK/m4/m4.map
|
||||
[ -f "$map" ] || fail "linker produced no map: $map"
|
||||
for sec in .text .data .bss; do
|
||||
origin=$(awk -v s="$sec" '$1 == s { print $3; exit }' "$map")
|
||||
length=$(awk -v s="$sec" '$1 == s { print $4; exit }' "$map")
|
||||
[ -n "$origin" ] || fail "linker map has no $sec section"
|
||||
[ -n "$length" ] || fail "linker map has no $sec length"
|
||||
case $origin$length in
|
||||
*[!0-9A-Fa-f]*) fail "linker map has a non-hex $sec origin/length" ;;
|
||||
esac
|
||||
case $sec in
|
||||
.bss)
|
||||
low=$RAM_ORIGIN
|
||||
limit=$RAM_END
|
||||
;;
|
||||
*)
|
||||
low=$PROG_ORIGIN
|
||||
limit=$PROG_END
|
||||
;;
|
||||
esac
|
||||
start=$((0x$origin))
|
||||
end=$((start + 0x$length))
|
||||
[ "$start" -ge "$low" ] \
|
||||
|| fail "$sec starts at $(printf '%08X' "$start"), below $(printf '%08X' "$low")"
|
||||
[ "$end" -le "$limit" ] \
|
||||
|| fail "$sec ends at $(printf '%08X' "$end"), beyond $(printf '%08X' "$limit")"
|
||||
done
|
||||
[ "$RAM_END" -lt "$RESULT_BASE" ] \
|
||||
|| fail "result block at $(printf '%08X' "$RESULT_BASE") overlaps linker RAM"
|
||||
}
|
||||
|
||||
check_link() {
|
||||
case $LINK_MODE in
|
||||
asm|asm-fallback) LINK_LOG=$WORK/link-asm.log ;;
|
||||
*) LINK_LOG=$WORK/link-native.log ;;
|
||||
esac
|
||||
grep -q '^M4 LINK: PASS' "$LINK_LOG" \
|
||||
|| fail "linked image has no M4 LINK: PASS"
|
||||
COFF=$WORK/m4/m4.coff
|
||||
[ -f "$COFF" ] || fail "linker produced no COFF: $COFF"
|
||||
check_map
|
||||
echo " linked $COFF ($LINK_MODE)"
|
||||
}
|
||||
|
||||
run_mame() {
|
||||
echo "== run the COFF in MAME ($LINK_MODE)"
|
||||
rm -f "$WORK/result.txt"
|
||||
set +e
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$COFF" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
CONF_RESULT="$WORK/result.txt" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$HERE/conformance-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1
|
||||
MAME_RC=$?
|
||||
set -e
|
||||
if [ "$MAME_RC" -ne 0 ]; then
|
||||
tail -40 "$WORK/mame.log" >&2 || true
|
||||
fail "MAME exited $MAME_RC"
|
||||
fi
|
||||
grep -q 'LOADER: COFF poked .* readback 0 bad' "$WORK/mame.log" \
|
||||
|| { tail -40 "$WORK/mame.log" >&2; \
|
||||
fail "loader did not verify the COFF buffer"; }
|
||||
grep -q 'CONF: .* status=' "$WORK/mame.log" \
|
||||
|| { tail -40 "$WORK/mame.log" >&2; fail "MAME produced no CONF result"; }
|
||||
|
||||
RESULT=$WORK/result.txt
|
||||
[ -f "$RESULT" ] || fail "MAME wrote no result file: $RESULT"
|
||||
STATUS_HEX=$(sed -n 's/^status=//p' "$RESULT" | tr -d '\r')
|
||||
LEN=$(sed -n 's/^len=//p' "$RESULT" | tr -d '\r')
|
||||
MAGIC_HEX=$(sed -n 's/^magic=//p' "$RESULT" | tr -d '\r')
|
||||
LOADER_HEX=$(sed -n 's/^loader=//p' "$RESULT" | tr -d '\r')
|
||||
ACTUAL_HEX=$(sed -n 's/^out=//p' "$RESULT" | tr -d '\r')
|
||||
[ -n "$STATUS_HEX" ] || fail "result file has no status"
|
||||
[ -n "$MAGIC_HEX" ] || fail "result file has no magic"
|
||||
[ -n "$LOADER_HEX" ] || fail "result file has no loader status"
|
||||
ACTUAL_HEX=$(printf '%s' "$ACTUAL_HEX" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
if [ "$LOADER_HEX" != "00000000" ]; then
|
||||
return 2
|
||||
fi
|
||||
|
||||
[ -n "$LEN" ] || fail "result file has no output length"
|
||||
case $LEN in
|
||||
*[!0-9]*) fail "result output length is not decimal: '$LEN'" ;;
|
||||
esac
|
||||
if [ "$LEN" -ge "$OUT_CAP" ]; then
|
||||
fail "output truncated: length $LEN reached the $OUT_CAP-byte shim cap"
|
||||
fi
|
||||
|
||||
if [ "$MAGIC_HEX" != "434F4E46" ]; then
|
||||
tail -40 "$WORK/mame.log" >&2 || true
|
||||
fail "no completion magic (got $MAGIC_HEX): test did not finish"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
echo "== compile and link ($ID, $CLANG_OPT, mode=$MODE)"
|
||||
case $MODE in
|
||||
asm)
|
||||
link_once "" "$WORK/link-asm.log" \
|
||||
|| { tail -40 "$WORK/link-asm.log" >&2; fail "asm compile/link failed"; }
|
||||
LINK_MODE=asm
|
||||
;;
|
||||
native)
|
||||
link_once 1 "$WORK/link-native.log" \
|
||||
|| { tail -40 "$WORK/link-native.log" >&2; fail "native compile/link failed"; }
|
||||
LINK_MODE=native
|
||||
;;
|
||||
auto)
|
||||
if link_once 1 "$WORK/link-native.log"; then
|
||||
LINK_MODE=native
|
||||
elif link_once "" "$WORK/link-asm.log"; then
|
||||
echo " native link failed; using the asm/GSPA fallback"
|
||||
LINK_MODE=asm-fallback
|
||||
else
|
||||
echo "== native link log" >&2
|
||||
tail -30 "$WORK/link-native.log" >&2 || true
|
||||
echo "== asm link log" >&2
|
||||
tail -30 "$WORK/link-asm.log" >&2 || true
|
||||
fail "compile/link failed in both native and asm paths"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
check_link
|
||||
|
||||
set +e
|
||||
run_mame
|
||||
MAME_RESULT=$?
|
||||
set -e
|
||||
if [ "$MAME_RESULT" -eq 2 ]; then
|
||||
tail -20 "$WORK/mame.log" >&2 || true
|
||||
if [ "$MODE" = auto ] && [ "$LINK_MODE" = native ]; then
|
||||
cp "$WORK/mame.log" "$WORK/mame-native.log" 2>/dev/null || true
|
||||
cp "$COFF" "$WORK/native.coff" 2>/dev/null || true
|
||||
echo " native COFF was loader-rejected (status $LOADER_HEX); retrying with asm/GSPA"
|
||||
link_once "" "$WORK/link-asm.log" \
|
||||
|| { tail -40 "$WORK/link-asm.log" >&2; fail "asm retry compile/link failed"; }
|
||||
LINK_MODE=asm-fallback
|
||||
check_link
|
||||
set +e
|
||||
run_mame
|
||||
MAME_RESULT=$?
|
||||
set -e
|
||||
[ "$MAME_RESULT" -eq 0 ] \
|
||||
|| fail "COFF loader rejected the asm fallback (status $LOADER_HEX)"
|
||||
else
|
||||
fail "COFF loader rejected the $LINK_MODE image (status $LOADER_HEX)"
|
||||
fi
|
||||
fi
|
||||
|
||||
OUTPUT_MISMATCH=0
|
||||
if [ "$IGNORE_OUTPUT" -eq 0 ] && [ "$ACTUAL_HEX" != "$EXPECT_HEX" ]; then
|
||||
OUTPUT_MISMATCH=1
|
||||
fi
|
||||
|
||||
if [ "$STATUS_HEX" != "$EXPECT_STATUS_HEX" ] || [ "$OUTPUT_MISMATCH" -eq 1 ]; then
|
||||
echo "CONFORMANCE: FAIL id=$ID status=$STATUS_HEX expected_status=$EXPECT_STATUS_HEX stdout_len=$LEN"
|
||||
if [ "$STATUS_HEX" != "$EXPECT_STATUS_HEX" ]; then
|
||||
echo " status mismatch: expected $EXPECT_STATUS_HEX, got $STATUS_HEX"
|
||||
fi
|
||||
if [ "$OUTPUT_MISMATCH" -eq 1 ]; then
|
||||
echo " output mismatch: expected '$EXPECT_HEX', got '$ACTUAL_HEX'"
|
||||
printf ' expected source: %s\n' "$EXPECT_SOURCE"
|
||||
fi
|
||||
echo " work dir: $WORK"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "CONFORMANCE: PASS id=$ID status=$STATUS_HEX stdout_len=$LEN link=$LINK_MODE"
|
||||
Executable
+320
@@ -0,0 +1,320 @@
|
||||
#!/bin/sh
|
||||
# M5/M6 conformance harness selftest.
|
||||
#
|
||||
# Three tiny C cases exercise the whole path:
|
||||
# pass int main(void) { return 0; }
|
||||
# fail int main(void) { return 7; }
|
||||
# print int main(void) { printf("ok\n"); return 0; }
|
||||
#
|
||||
# The pass and print cases must pass; the fail case must fail against the
|
||||
# default status 0 and then pass when status 7 is expected (proving the status
|
||||
# is captured, not guessed). A fourth run expects the wrong output and must
|
||||
# fail with an output-mismatch diagnostic, proving the compare is real.
|
||||
# Additional cases prove the shim's real va_list walk (format), the M6
|
||||
# %lld/%f/sprintf formats through the same shim (format-m6), entry's
|
||||
# main(1, argv) contract (argv), and that a large .bss cannot overwrite the
|
||||
# result block (bigbss). Classifier checks prove the M6 %lld/%f/varargs source
|
||||
# is accepted, a genuinely unsupported source (__int128) is a skip (not a
|
||||
# pass), an all-skip suite is a failure, a classifier error is a failure, and
|
||||
# an unsafe id is rejected before any rm -rf.
|
||||
#
|
||||
# scripts/tests/m5/conformance/selftest.sh
|
||||
#
|
||||
# Overridable: M5_CONFORMANCE_SELFTEST_WORK M5_CONFORMANCE_WORK
|
||||
# LOADER_AT LOADER_END M5_CONFORMANCE_MODE (auto|native|asm)
|
||||
# M5_CONFORMANCE_CLASSIFY
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
WORK=${M5_CONFORMANCE_SELFTEST_WORK:-$ROOT/build/m5-conformance-selftest}
|
||||
MODE=${M5_CONFORMANCE_MODE:-auto}
|
||||
|
||||
RUN=$HERE/run.sh
|
||||
CLASSIFY=$HERE/classify.sh
|
||||
|
||||
fail() {
|
||||
echo "conformance selftest: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -f "$RUN" ] || fail "missing runner: $RUN"
|
||||
[ -x "$RUN" ] || fail "runner is not executable: $RUN"
|
||||
[ -f "$HERE/shim.c" ] || fail "missing shim: $HERE/shim.c"
|
||||
[ -f "$HERE/entry.asm" ] || fail "missing entry: $HERE/entry.asm"
|
||||
[ -f "$CLASSIFY" ] || fail "missing classifier: $CLASSIFY"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
cat > "$WORK/pass.c" <<'EOF'
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
|
||||
cat > "$WORK/fail.c" <<'EOF'
|
||||
int main(void) { return 7; }
|
||||
EOF
|
||||
|
||||
cat > "$WORK/print.c" <<'EOF'
|
||||
int printf(const char *fmt, ...);
|
||||
int main(void) { printf("ok\n"); return 0; }
|
||||
EOF
|
||||
|
||||
cat > "$WORK/format.c" <<'EOF'
|
||||
int printf(const char *fmt, ...);
|
||||
int main(void)
|
||||
{
|
||||
printf("a=%d b=%s c=%c %% x=%x\n", 42, "hi", 'Z', 255);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/format-m6.c" <<'EOF'
|
||||
int printf(const char *fmt, ...);
|
||||
int sprintf(char *buf, const char *fmt, ...);
|
||||
int main(void)
|
||||
{
|
||||
char b[256]; /* >= the shim's SPRINTF_CAP */
|
||||
int n = sprintf(b, "%lld|%.2f|%s", -9000000000LL, 3.25, "ok");
|
||||
|
||||
printf("%d %f %s (%d)\n", -7, -1.5, b, n);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/argv.c" <<'EOF'
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 1)
|
||||
return 1;
|
||||
if (argv == 0 || argv[0] == 0 || argv[0][0] != 'c')
|
||||
return 2;
|
||||
if (argv[1] != 0)
|
||||
return 3;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/bigbss.c" <<'EOF'
|
||||
char big[50000];
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 50000; i++)
|
||||
big[i] = (char)(i * 7);
|
||||
for (i = 0; i < 50000; i++)
|
||||
if (big[i] != (char)(i * 7))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/truncate.c" <<'EOF'
|
||||
int putchar(int c);
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 16384; i++)
|
||||
putchar('x');
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
cat > "$WORK/skip.c" <<'EOF'
|
||||
__int128 unsupported_feature;
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
|
||||
run_case() {
|
||||
id=$1
|
||||
expect=$2
|
||||
src=$3
|
||||
log=$4
|
||||
if ! "$RUN" --id "$id" --mode "$MODE" --expect "$expect" "$src" \
|
||||
> "$log" 2>&1; then
|
||||
cat "$log" >&2
|
||||
fail "$id did not pass"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "== pass: main returns 0"
|
||||
run_case selftest-pass 'status=0;stdout=' "$WORK/pass.c" "$WORK/pass.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-pass' "$WORK/pass.log" \
|
||||
|| { cat "$WORK/pass.log" >&2; fail "pass case has no PASS line"; }
|
||||
|
||||
echo "== fail: main returns 7 must fail expected status 0"
|
||||
if "$RUN" --id selftest-fail --mode "$MODE" \
|
||||
--expect 'status=0;stdout=' "$WORK/fail.c" > "$WORK/fail.log" 2>&1; then
|
||||
cat "$WORK/fail.log" >&2
|
||||
fail "fail case (return 7) unexpectedly passed"
|
||||
fi
|
||||
grep -q '^CONFORMANCE: FAIL id=selftest-fail' "$WORK/fail.log" \
|
||||
|| { cat "$WORK/fail.log" >&2; fail "fail case has no FAIL line"; }
|
||||
grep -q 'status=00000007' "$WORK/fail.log" \
|
||||
|| { cat "$WORK/fail.log" >&2; fail "fail case did not capture status 7"; }
|
||||
|
||||
echo "== fail: the same source passes when status 7 is expected"
|
||||
run_case selftest-fail-expected 'status=7;stdout=' \
|
||||
"$WORK/fail.c" "$WORK/fail-expected.log"
|
||||
|
||||
echo "== print: writes ok and returns 0"
|
||||
run_case selftest-print 'status=0;stdout=ok\n' \
|
||||
"$WORK/print.c" "$WORK/print.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-print' "$WORK/print.log" \
|
||||
|| { cat "$WORK/print.log" >&2; fail "print case has no PASS line"; }
|
||||
|
||||
echo "== format: printf va_list walk and formatting"
|
||||
run_case selftest-format 'status=0;stdout=a=42 b=hi c=Z % x=ff\n' \
|
||||
"$WORK/format.c" "$WORK/format.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-format' "$WORK/format.log" \
|
||||
|| { cat "$WORK/format.log" >&2; fail "format case has no PASS line"; }
|
||||
|
||||
echo "== format-m6: %lld/%f/sprintf through the shared shim"
|
||||
run_case selftest-format-m6 'status=0;stdout=-7 -1.500000 -9000000000|3.25|ok (19)\n' \
|
||||
"$WORK/format-m6.c" "$WORK/format-m6.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-format-m6' "$WORK/format-m6.log" \
|
||||
|| { cat "$WORK/format-m6.log" >&2; \
|
||||
fail "format-m6 case has no PASS line"; }
|
||||
|
||||
echo "== argv: entry passes main(1, argv)"
|
||||
run_case selftest-argv 'status=0;stdout=' \
|
||||
"$WORK/argv.c" "$WORK/argv.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-argv' "$WORK/argv.log" \
|
||||
|| { cat "$WORK/argv.log" >&2; fail "argv case has no PASS line"; }
|
||||
|
||||
echo "== bigbss: globals cannot overwrite the result block"
|
||||
run_case selftest-bigbss 'status=0;stdout=' \
|
||||
"$WORK/bigbss.c" "$WORK/bigbss.log"
|
||||
grep -q '^CONFORMANCE: PASS id=selftest-bigbss' "$WORK/bigbss.log" \
|
||||
|| { cat "$WORK/bigbss.log" >&2; fail "bigbss case has no PASS line"; }
|
||||
|
||||
echo "== truncation: output at the 16 KiB cap must fail"
|
||||
set +e
|
||||
"$RUN" --id selftest-truncate --mode "$MODE" --expect-status 0 \
|
||||
--ignore-output "$WORK/truncate.c" > "$WORK/truncate.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/truncate.log" >&2; \
|
||||
fail "truncation case exited $RC, want 1"; }
|
||||
grep -q 'output truncated' "$WORK/truncate.log" \
|
||||
|| { cat "$WORK/truncate.log" >&2; \
|
||||
fail "truncation was not diagnosed"; }
|
||||
|
||||
echo "== print: a wrong expected output must fail"
|
||||
if "$RUN" --id selftest-mismatch --mode "$MODE" \
|
||||
--expect 'status=0;stdout=no\n' "$WORK/print.c" \
|
||||
> "$WORK/mismatch.log" 2>&1; then
|
||||
cat "$WORK/mismatch.log" >&2
|
||||
fail "wrong expected output unexpectedly passed"
|
||||
fi
|
||||
grep -q '^CONFORMANCE: FAIL id=selftest-mismatch' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch has no FAIL line"; }
|
||||
grep -q 'output mismatch' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch was not diagnosed as output"; }
|
||||
grep -q '6F6B0A' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch did not report actual 'ok\\n'"; }
|
||||
grep -q '6E6F0A' "$WORK/mismatch.log" \
|
||||
|| { cat "$WORK/mismatch.log" >&2; fail "mismatch did not report expected 'no\\n'"; }
|
||||
|
||||
echo "== classifier: M6 features are accepted"
|
||||
if ! "$CLASSIFY" "$WORK/format-m6.c" > "$WORK/classify-m6.log" 2>&1; then
|
||||
cat "$WORK/classify-m6.log" >&2
|
||||
fail "classifier still rejects the M6 %lld/%f/varargs source"
|
||||
fi
|
||||
[ ! -s "$WORK/classify-m6.log" ] \
|
||||
|| { cat "$WORK/classify-m6.log" >&2; \
|
||||
fail "classifier accepted the M6 source but printed a reason"; }
|
||||
|
||||
echo "== classifier: __int128 is skipped, not passed"
|
||||
if "$CLASSIFY" "$WORK/skip.c" > "$WORK/classify.log" 2>&1; then
|
||||
cat "$WORK/classify.log" >&2
|
||||
fail "classifier accepted an __int128 source"
|
||||
fi
|
||||
grep -q 'int128' "$WORK/classify.log" \
|
||||
|| { cat "$WORK/classify.log" >&2; \
|
||||
fail "classifier did not name the int128 feature"; }
|
||||
|
||||
set +e
|
||||
"$RUN" --id selftest-skip --mode "$MODE" --classify "$WORK/skip.c" \
|
||||
> "$WORK/skip.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 2 ] || { cat "$WORK/skip.log" >&2; \
|
||||
fail "classified source exited $RC, want 2 (skip)"; }
|
||||
grep -q '^CONFORMANCE: SKIP id=selftest-skip' "$WORK/skip.log" \
|
||||
|| { cat "$WORK/skip.log" >&2; fail "classified source has no SKIP line"; }
|
||||
|
||||
echo "== classifier: an I/O/usage error is a failure, not a skip"
|
||||
cat > "$WORK/bad-classifier.sh" <<'EOF'
|
||||
#!/bin/sh
|
||||
echo "fake classifier I/O error" >&2
|
||||
exit 2
|
||||
EOF
|
||||
chmod +x "$WORK/bad-classifier.sh"
|
||||
set +e
|
||||
M5_CONFORMANCE_CLASSIFY="$WORK/bad-classifier.sh" "$RUN" \
|
||||
--id selftest-classifier-error --mode "$MODE" --classify \
|
||||
--expect 'status=0;stdout=' "$WORK/pass.c" \
|
||||
> "$WORK/classifier-error.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/classifier-error.log" >&2; \
|
||||
fail "classifier error exited $RC, want 1 (failure)"; }
|
||||
grep -q 'classifier error' "$WORK/classifier-error.log" \
|
||||
|| { cat "$WORK/classifier-error.log" >&2; \
|
||||
fail "classifier error was not diagnosed"; }
|
||||
if grep -q '^CONFORMANCE: SKIP' "$WORK/classifier-error.log"; then
|
||||
cat "$WORK/classifier-error.log" >&2
|
||||
fail "classifier error was reported as a skip"
|
||||
fi
|
||||
|
||||
echo "== all-skip: a suite with no passing test must fail"
|
||||
mkdir -p "$WORK/skip-suite"
|
||||
cat > "$WORK/skip-suite/onlyskip.c" <<'EOF'
|
||||
__int128 unsupported_feature;
|
||||
int main(void) { return 0; }
|
||||
EOF
|
||||
: > "$WORK/skip-suite/onlyskip.c.expected"
|
||||
printf 'onlyskip\n' > "$WORK/allskip-torture.list"
|
||||
printf 'onlyskip\n' > "$WORK/allskip-testsuite.list"
|
||||
|
||||
set +e
|
||||
C_TORTURE_DIR="$WORK/skip-suite" "$HERE/c-torture.sh" \
|
||||
"$WORK/allskip-torture.list" > "$WORK/allskip-torture.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/allskip-torture.log" >&2; \
|
||||
fail "all-skip c-torture exited $RC, want 1"; }
|
||||
grep -q 'no tests passed' "$WORK/allskip-torture.log" \
|
||||
|| { cat "$WORK/allskip-torture.log" >&2; \
|
||||
fail "all-skip c-torture did not fail with 'no tests passed'"; }
|
||||
grep -q '^CONFORMANCE: SKIP' "$WORK/allskip-torture.log" \
|
||||
|| { cat "$WORK/allskip-torture.log" >&2; \
|
||||
fail "all-skip c-torture did not exercise a classifier skip"; }
|
||||
|
||||
set +e
|
||||
C_TESTSUITE_DIR="$WORK/skip-suite" "$HERE/c-testsuite.sh" \
|
||||
"$WORK/allskip-testsuite.list" > "$WORK/allskip-testsuite.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/allskip-testsuite.log" >&2; \
|
||||
fail "all-skip c-testsuite exited $RC, want 1"; }
|
||||
grep -q 'no tests passed' "$WORK/allskip-testsuite.log" \
|
||||
|| { cat "$WORK/allskip-testsuite.log" >&2; \
|
||||
fail "all-skip c-testsuite did not fail with 'no tests passed'"; }
|
||||
|
||||
echo "== id: '.' and '..' must not construct a deletable work path"
|
||||
set +e
|
||||
"$RUN" --id .. --mode "$MODE" --expect 'status=0;stdout=' \
|
||||
"$WORK/pass.c" > "$WORK/unsafe-id.log" 2>&1
|
||||
RC=$?
|
||||
set -e
|
||||
[ "$RC" -eq 1 ] || { cat "$WORK/unsafe-id.log" >&2; \
|
||||
fail "unsafe id exited $RC, want 1"; }
|
||||
grep -q 'unsafe id' "$WORK/unsafe-id.log" \
|
||||
|| { cat "$WORK/unsafe-id.log" >&2; fail "unsafe id was not rejected"; }
|
||||
|
||||
echo "conformance selftest: PASS"
|
||||
echo " pass, expected-fail status 7, print, format, format-m6, argv, bigbss,"
|
||||
echo " truncation, output mismatch, classifier accepts M6, classifier int128"
|
||||
echo " skip, classifier error, all-skip suite, unsafe id"
|
||||
@@ -0,0 +1,847 @@
|
||||
/*
|
||||
* shim.c -- freestanding conformance runtime for the M5/M6 harness.
|
||||
*
|
||||
* The harness links one conformance test, this shim, and entry.asm into a
|
||||
* TMS34010 COFF image. The shim provides the small libc surface the
|
||||
* conformance tests use: printf/sprintf/putchar/puts/string/memory functions,
|
||||
* and exit/abort publish a terminal status. There is no libc: the formatter
|
||||
* uses the compiler's real __builtin_va_list walk (the M6 `char *` va_list
|
||||
* over the downward-walking all-stack ABI). The M4 contiguous `&last_fixed`
|
||||
* pattern is still what scripts/m4/varargs.c uses; it is not needed here.
|
||||
*
|
||||
* printf and sprintf share one formatter (`conf_format`) over a small sink:
|
||||
* printf stores through the fixed CONF_OUT buffer at 01B10000h, sprintf into
|
||||
* the caller's buffer with the SPRINTF_CAP limit. The M5 conversions
|
||||
* (%d %i %u %o %x %X %p %c %s, flags - 0 + space #, width, h/hh) keep their
|
||||
* byte-identical output. M6 adds %ld/%lu, %lld/%llu (i64), %f (GSP double),
|
||||
* width/precision with `*`, %s width/precision, and space/left padding for a
|
||||
* %c width (the no-width %c form is unchanged). `%f` uses the compiler's
|
||||
* GSP double arithmetic, fptosi (FD$DTOI) and sitofp (FD$ITOD); flib has no
|
||||
* floor/fmod/libm entry, so the conversion is done here.
|
||||
*
|
||||
* Marker layout (32-bit cells at bit addresses):
|
||||
* 01B00000 status 0 = success, otherwise the main/exit/abort status
|
||||
* 01B00020 out_len number of bytes written to the output buffer
|
||||
* 01B00040 magic 0x434F4E46 once the result is complete ("CONF")
|
||||
* 01B10000 output text written by printf/putchar/puts (16 KiB)
|
||||
*
|
||||
* The result block is above the linker-managed RAM region
|
||||
* (01A00000..01A80000, 64 KiB of .bss including the 4 KiB _cstack), so a
|
||||
* test's globals cannot overwrite the status/output. entry.asm writes
|
||||
* status/magic when main returns. exit/abort write them directly and then
|
||||
* spin, so the result is observable even if the test does not return normally.
|
||||
* out_char() stops at CONF_CAP; the runner rejects out_len == CONF_CAP as a
|
||||
* truncation rather than accepting a partial output.
|
||||
*
|
||||
* sprintf has no size argument in C, so this freestanding shim gives it a
|
||||
* fixed destination cap (SPRINTF_CAP bytes, including the NUL). Callers must
|
||||
* supply a buffer of at least SPRINTF_CAP bytes; longer formatted output is
|
||||
* truncated, but the return value is still the full untruncated length.
|
||||
*/
|
||||
|
||||
#define CONF_STATUS ((volatile int *)0x01B00000UL)
|
||||
#define CONF_LEN ((volatile int *)0x01B00020UL)
|
||||
#define CONF_MAGIC ((volatile int *)0x01B00040UL)
|
||||
#define CONF_OUT ((char *)0x01B10000UL)
|
||||
#define CONF_CAP 16384
|
||||
#define CONF_MAGIC_VAL 0x434F4E46
|
||||
#define SPRINTF_CAP 256
|
||||
|
||||
/* The `%f` fraction is produced one decimal digit at a time with i32
|
||||
* conversions, so the precision is capped at 6. The integer part must fit
|
||||
* i32: magnitudes above FLOAT_MAX_I32 (2^31 - 128) are clamped before the
|
||||
* fptosi, so the band (2^31 - 128, 2^31) also clamps even though it would fit
|
||||
* i32. GSP has no NaN, and infinity clamps too. */
|
||||
#define FLOAT_PREC_MAX 6
|
||||
#define FLOAT_MAX_I32 2147483520.0 /* 2^31 - 128, safely inside i32 */
|
||||
|
||||
static int out_len;
|
||||
|
||||
/* Destination for the shared formatter. printf starts `used` at out_len so it
|
||||
* continues the fixed CONF_OUT stream; sprintf starts at 0 in the caller's
|
||||
* buffer. The formatter's own return value counts every formatted character,
|
||||
* including bytes dropped at the cap. */
|
||||
struct sink {
|
||||
char *buf;
|
||||
int cap;
|
||||
int used;
|
||||
int conf;
|
||||
};
|
||||
|
||||
static void sink_char(struct sink *s, int c)
|
||||
{
|
||||
if (s->used < s->cap)
|
||||
s->buf[s->used++] = (char)c;
|
||||
if (s->conf) {
|
||||
out_len = s->used;
|
||||
*CONF_LEN = out_len;
|
||||
}
|
||||
}
|
||||
|
||||
static void sink_pad(struct sink *s, int c, int n)
|
||||
{
|
||||
while (n-- > 0)
|
||||
sink_char(s, c);
|
||||
}
|
||||
|
||||
static void sink_str(struct sink *s, const char *p)
|
||||
{
|
||||
while (*p)
|
||||
sink_char(s, *p++);
|
||||
}
|
||||
|
||||
static int out_char(int c)
|
||||
{
|
||||
if (out_len < CONF_CAP) {
|
||||
CONF_OUT[out_len] = (char)c;
|
||||
out_len++;
|
||||
*CONF_LEN = out_len;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int out_str(const char *s)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
while (*s) {
|
||||
out_char(*s++);
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/* Integer conversion for 32-bit values. `prec` is -1 when no explicit
|
||||
* precision was given; when it is >= 0 it is the minimum digit count and the
|
||||
* `0` flag no longer zero-pads the field (C semantics). With prec < 0 the
|
||||
* output is byte-identical to the M5 shim. */
|
||||
static int emit_uint(struct sink *s, unsigned int v, int neg, int base,
|
||||
int upper, int width, int zero, int left, int plus,
|
||||
int space, int alt, int prec)
|
||||
{
|
||||
static const char lower[] = "0123456789abcdef";
|
||||
static const char upper_digits[] = "0123456789ABCDEF";
|
||||
const char *digits = upper ? upper_digits : lower;
|
||||
char tmp[32];
|
||||
int n = 0, min_digits, pad, prefix_len = 0, i;
|
||||
int sign = 0;
|
||||
char prefix[3];
|
||||
|
||||
if (v == 0) {
|
||||
/* C: converting zero with precision 0 yields no digits; the octal
|
||||
* alternative form still prints the single required 0. */
|
||||
if (prec != 0)
|
||||
tmp[n++] = '0';
|
||||
else if (alt && base == 8)
|
||||
tmp[n++] = '0';
|
||||
} else {
|
||||
while (v) {
|
||||
tmp[n++] = digits[v % (unsigned int)base];
|
||||
v /= (unsigned int)base;
|
||||
}
|
||||
}
|
||||
|
||||
if (neg)
|
||||
sign = '-';
|
||||
else if (plus)
|
||||
sign = '+';
|
||||
else if (space)
|
||||
sign = ' ';
|
||||
if (n == 0)
|
||||
sign = 0;
|
||||
|
||||
if (prec > n)
|
||||
min_digits = prec;
|
||||
else
|
||||
min_digits = n;
|
||||
|
||||
if (alt) {
|
||||
if (base == 16 && n > 0) {
|
||||
/* Known pre-existing M5 deviation: %#x of 0 prints
|
||||
* 0x0 (C says 0). Kept byte-identical here. With no
|
||||
* digits (%.0x of 0) no prefix is emitted. */
|
||||
prefix[0] = '0';
|
||||
prefix[1] = upper ? 'X' : 'x';
|
||||
prefix_len = 2;
|
||||
} else if (base == 8 && n > 0 && tmp[n - 1] != '0' &&
|
||||
min_digits == n) {
|
||||
/* If the precision padding already supplies the leading
|
||||
* zero, the octal alternative form must not add another. */
|
||||
prefix[0] = '0';
|
||||
prefix_len = 1;
|
||||
}
|
||||
}
|
||||
if (prefix_len)
|
||||
prefix[prefix_len] = 0;
|
||||
|
||||
pad = width - min_digits - prefix_len - (sign ? 1 : 0);
|
||||
if (pad < 0)
|
||||
pad = 0;
|
||||
|
||||
if (!left && !(zero && prec < 0))
|
||||
sink_pad(s, ' ', pad);
|
||||
if (sign)
|
||||
sink_char(s, sign);
|
||||
if (prefix_len)
|
||||
sink_str(s, prefix);
|
||||
if (!left && zero && prec < 0)
|
||||
sink_pad(s, '0', pad);
|
||||
for (i = n; i < min_digits; i++)
|
||||
sink_char(s, '0');
|
||||
while (n--)
|
||||
sink_char(s, tmp[n]);
|
||||
if (left)
|
||||
sink_pad(s, ' ', pad);
|
||||
return min_digits + prefix_len + (sign ? 1 : 0) + pad;
|
||||
}
|
||||
|
||||
/* 64-bit integer conversion (%lld/%llu). Same presentation rules as
|
||||
* emit_uint; the digit extraction uses the compiler's i64 divide/remainder
|
||||
* sequence (rts.lib has no 64-bit helper). */
|
||||
static int emit_uint64(struct sink *s, unsigned long long v, int neg, int base,
|
||||
int upper, int width, int zero, int left, int plus,
|
||||
int space, int alt, int prec)
|
||||
{
|
||||
static const char lower[] = "0123456789abcdef";
|
||||
static const char upper_digits[] = "0123456789ABCDEF";
|
||||
const char *digits = upper ? upper_digits : lower;
|
||||
char tmp[24];
|
||||
int n = 0, min_digits, pad, prefix_len = 0, i;
|
||||
int sign = 0;
|
||||
char prefix[3];
|
||||
|
||||
if (v == 0) {
|
||||
if (prec != 0)
|
||||
tmp[n++] = '0';
|
||||
else if (alt && base == 8)
|
||||
tmp[n++] = '0';
|
||||
} else {
|
||||
while (v) {
|
||||
tmp[n++] = digits[(unsigned int)(v % (unsigned int)base)];
|
||||
v /= (unsigned int)base;
|
||||
}
|
||||
}
|
||||
|
||||
if (neg)
|
||||
sign = '-';
|
||||
else if (plus)
|
||||
sign = '+';
|
||||
else if (space)
|
||||
sign = ' ';
|
||||
if (n == 0)
|
||||
sign = 0;
|
||||
|
||||
if (prec > n)
|
||||
min_digits = prec;
|
||||
else
|
||||
min_digits = n;
|
||||
|
||||
if (alt) {
|
||||
if (base == 16 && n > 0) {
|
||||
/* Known pre-existing M5 deviation: %#x of 0 prints
|
||||
* 0x0 (C says 0). Kept byte-identical here. With no
|
||||
* digits (%.0x of 0) no prefix is emitted. */
|
||||
prefix[0] = '0';
|
||||
prefix[1] = upper ? 'X' : 'x';
|
||||
prefix_len = 2;
|
||||
} else if (base == 8 && n > 0 && tmp[n - 1] != '0' &&
|
||||
min_digits == n) {
|
||||
prefix[0] = '0';
|
||||
prefix_len = 1;
|
||||
}
|
||||
}
|
||||
if (prefix_len)
|
||||
prefix[prefix_len] = 0;
|
||||
|
||||
pad = width - min_digits - prefix_len - (sign ? 1 : 0);
|
||||
if (pad < 0)
|
||||
pad = 0;
|
||||
|
||||
if (!left && !(zero && prec < 0))
|
||||
sink_pad(s, ' ', pad);
|
||||
if (sign)
|
||||
sink_char(s, sign);
|
||||
if (prefix_len)
|
||||
sink_str(s, prefix);
|
||||
if (!left && zero && prec < 0)
|
||||
sink_pad(s, '0', pad);
|
||||
for (i = n; i < min_digits; i++)
|
||||
sink_char(s, '0');
|
||||
while (n--)
|
||||
sink_char(s, tmp[n]);
|
||||
if (left)
|
||||
sink_pad(s, ' ', pad);
|
||||
return min_digits + prefix_len + (sign ? 1 : 0) + pad;
|
||||
}
|
||||
|
||||
/* %f for the GSP double. Formats the magnitude (the sign is extracted by a
|
||||
* compare against 0.0 and prepended), extracts `prec` decimal fraction digits
|
||||
* with GSP double multiply/subtract and fptosi, then rounds half-up from the
|
||||
* next digit (carrying through the fraction and into the integer part). The
|
||||
* caller has already normalised `prec` to 0..FLOAT_PREC_MAX. `alt` forces a
|
||||
* decimal point with precision 0 (the `#` flag). */
|
||||
static int emit_float(struct sink *s, double v, int width, int zero, int left,
|
||||
int plus, int space, int prec, int alt)
|
||||
{
|
||||
char ibuf[24];
|
||||
char fbuf[FLOAT_PREC_MAX];
|
||||
char sign = 0;
|
||||
int n = 0, i, pad, len, ip, dot;
|
||||
double f;
|
||||
|
||||
if (v < 0.0) {
|
||||
sign = '-';
|
||||
v = -v;
|
||||
} else if (plus) {
|
||||
sign = '+';
|
||||
} else if (space) {
|
||||
sign = ' ';
|
||||
}
|
||||
|
||||
/* The integer part and each fraction digit go through fptosi, which
|
||||
* flib only provides for i32. Clamp instead of taking FD$DTOI's
|
||||
* infinity error path. */
|
||||
if (v > FLOAT_MAX_I32)
|
||||
v = FLOAT_MAX_I32;
|
||||
|
||||
ip = (int)v;
|
||||
f = v - (double)ip;
|
||||
|
||||
for (i = 0; i < prec; i++) {
|
||||
int d;
|
||||
|
||||
f *= 10.0;
|
||||
d = (int)f;
|
||||
if (d < 0)
|
||||
d = 0;
|
||||
if (d > 9)
|
||||
d = 9;
|
||||
fbuf[i] = (char)('0' + d);
|
||||
f -= (double)d;
|
||||
}
|
||||
|
||||
f *= 10.0;
|
||||
if ((int)f >= 5) {
|
||||
int k = prec - 1;
|
||||
|
||||
while (k >= 0 && fbuf[k] == '9') {
|
||||
fbuf[k] = '0';
|
||||
k--;
|
||||
}
|
||||
if (k >= 0)
|
||||
fbuf[k]++;
|
||||
else
|
||||
ip++;
|
||||
}
|
||||
|
||||
if (ip == 0) {
|
||||
ibuf[n++] = '0';
|
||||
} else {
|
||||
while (ip > 0) {
|
||||
ibuf[n++] = (char)('0' + ip % 10);
|
||||
ip /= 10;
|
||||
}
|
||||
}
|
||||
|
||||
dot = prec > 0 || alt;
|
||||
len = n + (dot ? prec + 1 : 0);
|
||||
pad = width - len - (sign ? 1 : 0);
|
||||
if (pad < 0)
|
||||
pad = 0;
|
||||
|
||||
if (!left && !zero)
|
||||
sink_pad(s, ' ', pad);
|
||||
if (sign)
|
||||
sink_char(s, sign);
|
||||
if (!left && zero)
|
||||
sink_pad(s, '0', pad);
|
||||
while (n--)
|
||||
sink_char(s, ibuf[n]);
|
||||
if (dot) {
|
||||
sink_char(s, '.');
|
||||
for (i = 0; i < prec; i++)
|
||||
sink_char(s, fbuf[i]);
|
||||
}
|
||||
if (left)
|
||||
sink_pad(s, ' ', pad);
|
||||
return len + (sign ? 1 : 0) + pad;
|
||||
}
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
out_char(c);
|
||||
*CONF_LEN = out_len;
|
||||
return c;
|
||||
}
|
||||
|
||||
int puts(const char *s)
|
||||
{
|
||||
int n = out_str(s);
|
||||
|
||||
out_char('\n');
|
||||
*CONF_LEN = out_len;
|
||||
return n + 1;
|
||||
}
|
||||
|
||||
unsigned int strlen(const char *s)
|
||||
{
|
||||
const char *p = s;
|
||||
|
||||
while (*p)
|
||||
p++;
|
||||
return (unsigned int)(p - s);
|
||||
}
|
||||
|
||||
int strcmp(const char *a, const char *b)
|
||||
{
|
||||
while (*a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return (int)(unsigned char)*a - (int)(unsigned char)*b;
|
||||
}
|
||||
|
||||
int strncmp(const char *a, const char *b, unsigned int n)
|
||||
{
|
||||
while (n && *a && *a == *b) {
|
||||
a++;
|
||||
b++;
|
||||
n--;
|
||||
}
|
||||
if (n == 0)
|
||||
return 0;
|
||||
return (int)(unsigned char)*a - (int)(unsigned char)*b;
|
||||
}
|
||||
|
||||
char *strcpy(char *d, const char *s)
|
||||
{
|
||||
char *r = d;
|
||||
|
||||
while ((*d++ = *s++) != 0)
|
||||
;
|
||||
return r;
|
||||
}
|
||||
|
||||
char *strncpy(char *d, const char *s, unsigned int n)
|
||||
{
|
||||
char *r = d;
|
||||
|
||||
while (n && *s) {
|
||||
*d++ = *s++;
|
||||
n--;
|
||||
}
|
||||
while (n) {
|
||||
*d++ = 0;
|
||||
n--;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
char *strchr(const char *s, int c)
|
||||
{
|
||||
for (;; s++) {
|
||||
if (*s == (char)c)
|
||||
return (char *)s;
|
||||
if (!*s)
|
||||
return (char *)0;
|
||||
}
|
||||
}
|
||||
|
||||
char *strrchr(const char *s, int c)
|
||||
{
|
||||
const char *r = (const char *)0;
|
||||
|
||||
for (;; s++) {
|
||||
if (*s == (char)c)
|
||||
r = s;
|
||||
if (!*s)
|
||||
return (char *)r;
|
||||
}
|
||||
}
|
||||
|
||||
void *memcpy(void *dst, const void *src, unsigned int n)
|
||||
{
|
||||
char *d = (char *)dst;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memmove(void *dst, const void *src, unsigned int n)
|
||||
{
|
||||
char *d = (char *)dst;
|
||||
const char *s = (const char *)src;
|
||||
|
||||
if (d < s) {
|
||||
while (n--)
|
||||
*d++ = *s++;
|
||||
} else if (d > s) {
|
||||
char *de = d;
|
||||
const char *se = s;
|
||||
unsigned int k = n;
|
||||
|
||||
/* Advance end pointers with constant 8-bit steps instead of
|
||||
* `d += n`. At -O2 the optimizer canonicalises an
|
||||
* `inttoptr(add(ptrtoint p, n*8))` back into a byte-indexed
|
||||
* pointer GEP; tms-clang's post-opt `--scale` then scales that
|
||||
* GEP a second time (the late-GEP over-scaling risk recorded in
|
||||
* the Task 6 report). Constant steps are not rewritten. */
|
||||
while (k--) {
|
||||
de++;
|
||||
se++;
|
||||
}
|
||||
while (n--)
|
||||
*--de = *--se;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *memset(void *dst, int c, unsigned int n)
|
||||
{
|
||||
char *d = (char *)dst;
|
||||
|
||||
while (n--)
|
||||
*d++ = (char)c;
|
||||
return dst;
|
||||
}
|
||||
|
||||
int memcmp(const void *a, const void *b, unsigned int n)
|
||||
{
|
||||
const unsigned char *x = (const unsigned char *)a;
|
||||
const unsigned char *y = (const unsigned char *)b;
|
||||
|
||||
while (n--) {
|
||||
if (*x != *y)
|
||||
return (int)*x - (int)*y;
|
||||
x++;
|
||||
y++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int atoi(const char *s)
|
||||
{
|
||||
int sign = 1, v = 0;
|
||||
|
||||
while (*s == ' ' || *s == '\t' || *s == '\n' || *s == '\r')
|
||||
s++;
|
||||
if (*s == '-') {
|
||||
sign = -1;
|
||||
s++;
|
||||
} else if (*s == '+') {
|
||||
s++;
|
||||
}
|
||||
while (*s >= '0' && *s <= '9') {
|
||||
v = v * 10 + (*s - '0');
|
||||
s++;
|
||||
}
|
||||
return sign * v;
|
||||
}
|
||||
|
||||
int abs(int v)
|
||||
{
|
||||
return v < 0 ? -v : v;
|
||||
}
|
||||
|
||||
/* One formatter for printf and sprintf. `ap` is the caller's real va_list
|
||||
* (char * on this target); the sink decides where characters go and how many
|
||||
* the destination can store. Returns the number of characters formatted. */
|
||||
static int conf_format(const char *fmt, __builtin_va_list ap, struct sink *out)
|
||||
{
|
||||
const char *p = fmt;
|
||||
int total = 0;
|
||||
|
||||
while (*p) {
|
||||
int left = 0, zero = 0, plus = 0, space = 0, alt = 0;
|
||||
int width = 0, prec = -1;
|
||||
int is_short = 0, is_char = 0, is_long = 0, is_ll = 0;
|
||||
int conv;
|
||||
|
||||
if (*p != '%') {
|
||||
sink_char(out, *p++);
|
||||
total++;
|
||||
continue;
|
||||
}
|
||||
p++;
|
||||
if (*p == '%') {
|
||||
sink_char(out, *p++);
|
||||
total++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
if (*p == '-') {
|
||||
left = 1;
|
||||
p++;
|
||||
} else if (*p == '0') {
|
||||
zero = 1;
|
||||
p++;
|
||||
} else if (*p == '+') {
|
||||
plus = 1;
|
||||
p++;
|
||||
} else if (*p == ' ') {
|
||||
space = 1;
|
||||
p++;
|
||||
} else if (*p == '#') {
|
||||
alt = 1;
|
||||
p++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*p == '*') {
|
||||
int w = __builtin_va_arg(ap, int);
|
||||
|
||||
if (w < 0) {
|
||||
left = 1;
|
||||
/* Avoid the INT_MIN negation overflow; the huge
|
||||
* width is then bounded only by the output cap. */
|
||||
w = (w == (-2147483647 - 1)) ? 2147483647 : -w;
|
||||
}
|
||||
width = w;
|
||||
p++;
|
||||
} else {
|
||||
while (*p >= '0' && *p <= '9') {
|
||||
width = width * 10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
if (*p == '.') {
|
||||
p++;
|
||||
if (*p == '*') {
|
||||
int pr = __builtin_va_arg(ap, int);
|
||||
|
||||
prec = pr < 0 ? -1 : pr;
|
||||
p++;
|
||||
} else {
|
||||
prec = 0;
|
||||
while (*p >= '0' && *p <= '9') {
|
||||
prec = prec * 10 + (*p - '0');
|
||||
p++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (*p == 'l') {
|
||||
p++;
|
||||
if (*p == 'l') {
|
||||
p++;
|
||||
is_ll = 1;
|
||||
} else {
|
||||
is_long = 1;
|
||||
}
|
||||
} else if (*p == 'h') {
|
||||
p++;
|
||||
is_short = 1;
|
||||
if (*p == 'h') {
|
||||
p++;
|
||||
is_char = 1;
|
||||
}
|
||||
} else if (*p == 'z' || *p == 't' || *p == 'j') {
|
||||
p++;
|
||||
} else if (*p == 'L') {
|
||||
p++;
|
||||
}
|
||||
|
||||
conv = *p;
|
||||
if (!conv)
|
||||
break;
|
||||
p++;
|
||||
|
||||
switch (conv) {
|
||||
case 'd':
|
||||
case 'i': {
|
||||
int sv;
|
||||
unsigned int uv;
|
||||
|
||||
if (is_ll) {
|
||||
long long llv = __builtin_va_arg(ap, long long);
|
||||
unsigned long long lluv;
|
||||
int neg = llv < 0;
|
||||
|
||||
if (neg)
|
||||
lluv = (unsigned long long)(-(llv + 1)) +
|
||||
1ULL;
|
||||
else
|
||||
lluv = (unsigned long long)llv;
|
||||
total += emit_uint64(out, lluv, neg, 10, 0,
|
||||
width, zero, left, plus,
|
||||
space, alt, prec);
|
||||
break;
|
||||
}
|
||||
if (is_long)
|
||||
sv = (int)__builtin_va_arg(ap, long);
|
||||
else
|
||||
sv = __builtin_va_arg(ap, int);
|
||||
if (is_char)
|
||||
sv = (signed char)sv;
|
||||
else if (is_short)
|
||||
sv = (short)sv;
|
||||
if (sv < 0)
|
||||
uv = ~(unsigned int)sv + 1U;
|
||||
else
|
||||
uv = (unsigned int)sv;
|
||||
total += emit_uint(out, uv, sv < 0, 10, 0, width,
|
||||
zero, left, plus, space, alt, prec);
|
||||
break;
|
||||
}
|
||||
case 'u':
|
||||
case 'o':
|
||||
case 'x':
|
||||
case 'X': {
|
||||
unsigned int uv;
|
||||
|
||||
if (is_ll) {
|
||||
unsigned long long lluv =
|
||||
__builtin_va_arg(ap, unsigned long long);
|
||||
|
||||
total += emit_uint64(
|
||||
out, lluv, 0,
|
||||
conv == 'o' ? 8 :
|
||||
(conv == 'u' ? 10 : 16),
|
||||
conv == 'X', width, zero, left, plus,
|
||||
space, alt, prec);
|
||||
break;
|
||||
}
|
||||
if (is_long)
|
||||
uv = (unsigned int)__builtin_va_arg(ap,
|
||||
unsigned long);
|
||||
else
|
||||
uv = __builtin_va_arg(ap, unsigned int);
|
||||
if (is_char)
|
||||
uv = (unsigned char)uv;
|
||||
else if (is_short)
|
||||
uv = (unsigned short)uv;
|
||||
total += emit_uint(out, uv, 0,
|
||||
conv == 'o' ? 8 : (conv == 'u' ? 10 : 16),
|
||||
conv == 'X', width, zero, left,
|
||||
plus, space, alt, prec);
|
||||
break;
|
||||
}
|
||||
case 'p': {
|
||||
unsigned int uv;
|
||||
|
||||
uv = (unsigned int)__builtin_va_arg(ap, void *);
|
||||
if (width == 0)
|
||||
width = 8;
|
||||
total += emit_uint(out, uv, 0, 16, 0, width, 1, left,
|
||||
0, 0, 1, -1);
|
||||
break;
|
||||
}
|
||||
case 'c': {
|
||||
int cv, pad;
|
||||
|
||||
cv = __builtin_va_arg(ap, int);
|
||||
/* Width and '-' pad with spaces, like glibc; '0' is not
|
||||
* meaningful for %c and is ignored. */
|
||||
pad = width - 1;
|
||||
if (pad < 0)
|
||||
pad = 0;
|
||||
if (!left)
|
||||
sink_pad(out, ' ', pad);
|
||||
sink_char(out, (char)cv);
|
||||
if (left)
|
||||
sink_pad(out, ' ', pad);
|
||||
total += 1 + pad;
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
const char *sp;
|
||||
int slen = 0, shown, i, pad;
|
||||
|
||||
sp = __builtin_va_arg(ap, char *);
|
||||
if (!sp)
|
||||
sp = "(null)";
|
||||
while (sp[slen])
|
||||
slen++;
|
||||
shown = slen;
|
||||
if (prec >= 0 && prec < shown)
|
||||
shown = prec;
|
||||
pad = width - shown;
|
||||
if (pad < 0)
|
||||
pad = 0;
|
||||
if (!left)
|
||||
sink_pad(out, ' ', pad);
|
||||
for (i = 0; i < shown; i++)
|
||||
sink_char(out, sp[i]);
|
||||
if (left)
|
||||
sink_pad(out, ' ', pad);
|
||||
total += shown + pad;
|
||||
break;
|
||||
}
|
||||
case 'f': {
|
||||
double dv;
|
||||
|
||||
dv = __builtin_va_arg(ap, double);
|
||||
if (prec < 0)
|
||||
prec = FLOAT_PREC_MAX;
|
||||
if (prec > FLOAT_PREC_MAX)
|
||||
prec = FLOAT_PREC_MAX;
|
||||
total += emit_float(out, dv, width, zero, left, plus,
|
||||
space, prec, alt);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
sink_char(out, '%');
|
||||
sink_char(out, conv);
|
||||
total += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
int printf(const char *fmt, ...)
|
||||
{
|
||||
__builtin_va_list ap;
|
||||
struct sink s;
|
||||
int r;
|
||||
|
||||
__builtin_va_start(ap, fmt);
|
||||
s.buf = CONF_OUT;
|
||||
s.cap = CONF_CAP;
|
||||
s.used = out_len;
|
||||
s.conf = 1;
|
||||
r = conf_format(fmt, ap, &s);
|
||||
__builtin_va_end(ap);
|
||||
out_len = s.used;
|
||||
*CONF_LEN = out_len;
|
||||
return r;
|
||||
}
|
||||
|
||||
int sprintf(char *buf, const char *fmt, ...)
|
||||
{
|
||||
__builtin_va_list ap;
|
||||
struct sink s;
|
||||
int r;
|
||||
|
||||
__builtin_va_start(ap, fmt);
|
||||
s.buf = buf;
|
||||
s.cap = SPRINTF_CAP - 1;
|
||||
s.used = 0;
|
||||
s.conf = 0;
|
||||
r = conf_format(fmt, ap, &s);
|
||||
__builtin_va_end(ap);
|
||||
buf[s.used] = 0;
|
||||
return r;
|
||||
}
|
||||
|
||||
void exit(int status)
|
||||
{
|
||||
*CONF_LEN = out_len;
|
||||
*CONF_STATUS = status;
|
||||
*CONF_MAGIC = CONF_MAGIC_VAL;
|
||||
for (;;)
|
||||
;
|
||||
}
|
||||
|
||||
void _exit(int status)
|
||||
{
|
||||
exit(status);
|
||||
}
|
||||
|
||||
void abort(void)
|
||||
{
|
||||
exit(134); /* 128 + SIGABRT */
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
# conformance feature skips
|
||||
#
|
||||
# feature<TAB>reason
|
||||
#
|
||||
# classify.sh reports the first matching feature. A skipped test is never
|
||||
# counted as a pass; the suite runners count it separately and print the
|
||||
# reason. M6 implements floats/doubles, 64-bit integers, bitfields, general
|
||||
# varargs and aggregates, so those features are no longer listed here. The
|
||||
# remaining rows are the genuine M6/M7 non-goals (keep them in sync with the
|
||||
# M6 boundary: signals, wide characters, file I/O and non-local jumps are not
|
||||
# part of M6; 128-bit integers are not supported).
|
||||
int128 128-bit integers are unsupported
|
||||
setjmp setjmp/longjmp need non-local jumps, which are unsupported
|
||||
signal signals are unavailable under the bare loader
|
||||
wide-char wide characters are unsupported
|
||||
format-unsupported printf %n, positional $, %e/%g/%a/%F, %j, long-double %L/%F and wide %ls/%lc are not implemented by the shim
|
||||
file-io stdio/POSIX file I/O is unavailable under the bare loader
|
||||
|
@@ -0,0 +1,68 @@
|
||||
# M5 CodeGen/Generic allowlist.
|
||||
#
|
||||
# A small curated compile-only set, not the whole Generic corpus. Every entry
|
||||
# must compile with:
|
||||
# llc -march=tms34010 -filetype=asm -O0
|
||||
# to a non-empty .s. The set stays within the M5 subset: integer (<=32 bit),
|
||||
# pointer, control flow, load/store, calls and PHI. No floats, vectors,
|
||||
# atomics, 64-bit integer values, varargs, or aggregate values/arguments/
|
||||
# returns. The one aggregate-typed access is
|
||||
# 2006-06-13-ComputeMaskedBitsCrash.ll: it uses a struct-typed global and a
|
||||
# struct-field GEP for address computation but never loads, stores, passes or
|
||||
# returns an aggregate value.
|
||||
#
|
||||
# The broad sweep in generic.sh covers all Generic .ll files; this list is the
|
||||
# gate that must stay green for the supported feature shapes.
|
||||
|
||||
# Integer arithmetic and shifts (add/sub/mul/div/rem/and/or/xor/shl/lshr/ashr).
|
||||
BasicInstrs
|
||||
|
||||
# sdiv-by-constant (negative power of two).
|
||||
div-neg-power-2
|
||||
|
||||
# Return-only and global load/return.
|
||||
ret0
|
||||
ret42
|
||||
global-ret0
|
||||
|
||||
# Direct calls: one/two/void arguments, one/two-deep call chains.
|
||||
call-ret0
|
||||
call-ret42
|
||||
call-void
|
||||
call2-ret0
|
||||
fastcall
|
||||
|
||||
# Calls and PHI/control: a call argument defined by a later call, and a
|
||||
# pointer PHI feeding a call.
|
||||
badCallArgLRLLVM
|
||||
2003-05-30-BadPreselectPhi
|
||||
|
||||
# PHI carrying ptrtoint globals plus a call.
|
||||
2005-04-09-GlobalInPHI
|
||||
|
||||
# Load/select and load/store with narrow integer operations.
|
||||
2007-01-15-LoadSelectCycle
|
||||
2006-11-20-DAGCombineCrash
|
||||
fwdtwice
|
||||
|
||||
# i16 loads, icmp and a switch.
|
||||
2006-04-26-SetCCAnd
|
||||
|
||||
# GEP/load/store/shift/mask.
|
||||
2006-06-13-ComputeMaskedBitsCrash
|
||||
|
||||
# Branches and i1 boolean folding.
|
||||
2006-10-27-CondFolding
|
||||
2006-10-29-Crash
|
||||
|
||||
# PHI/icmp control flow.
|
||||
2006-01-12-BadSetCCFold
|
||||
|
||||
# Loop induction/PHI control flow.
|
||||
2007-04-17-lsr-crash
|
||||
|
||||
# Switch lowering with PHIs.
|
||||
2006-09-06-SwitchLowering
|
||||
|
||||
# A trivial intrinsic call.
|
||||
assume
|
||||
@@ -0,0 +1,65 @@
|
||||
# M5 CodeGen/Generic expected-fail manifest.
|
||||
#
|
||||
# Format: test<TAB>reason
|
||||
#
|
||||
# Every broad-sweep `unsupported` row is recorded here with the reason the
|
||||
# M5 target cannot compile it. generic.sh enforces both directions:
|
||||
# - each entry must be `unsupported`, not `pass` (stale) and never `crash`;
|
||||
# - every `unsupported` row in the sweep must have an entry here.
|
||||
#
|
||||
# A crash is a regression, never an expected failure. Reasons are the actual
|
||||
# diagnostic categories from the sweep; "M6" marks a feature deferred from
|
||||
# the M5 subset (float/double, i128 and wider integers, general varargs,
|
||||
# aggregates, GC). i64 is implemented by M6 Task 2; its former entries were
|
||||
# removed from this manifest when they started compiling.
|
||||
2004-05-09-LiveVarPartialRegister target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
2007-04-08-MultipleFrameIndices inline asm register constraint cannot be allocated
|
||||
2007-04-27-InlineAsm-X-Dest inline asm register constraint cannot be allocated
|
||||
2007-04-27-LargeMemObject inline asm memory constraint is not supported
|
||||
2007-12-17-InvokeAsm inline asm memory constraint is not supported
|
||||
2008-02-04-Ctlz target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
2008-02-20-MatchingMem inline asm memory constraint is not supported
|
||||
2008-08-07-PtrToInt-SmallerInt target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
2010-ZeroSizedArg target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
APIntParam target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
APIntSextParam target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
APIntZextParam target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
GlobalISel/irtranslator-byte-type target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
add-with-overflow-128 target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
addr-label blockaddress values are not supported
|
||||
annotate target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
bfloat target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
bfloat-op missing libcall lowering (floats/vectors are deferred to M6)
|
||||
cast-fp target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
dag-combine-ossfuzz-crash target rejection: TMS34010: integer multiply wider than 64 bits is not supported (M6 implements exactly 64-bit arithmetic)
|
||||
expand-experimental-reductions target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
extractelement-shuffle target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
fast-math-flags IR verifier rejects the input (fast-math flags on an integer call)
|
||||
fp128-exp10-libcall target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
fp128-math-libcalls target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
fp_to_int target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
fpoperations target rejection: TMS34010: flib.lib has no libm entry for intrinsic 'llvm.roundeven.f32'
|
||||
fpowi-promote target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
half target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
half-op missing libcall lowering (floats/vectors are deferred to M6)
|
||||
icmp-illegal target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
inline-asm-mem-clobber inline asm register constraint cannot be allocated
|
||||
inline-asm-special-strings inline asm syntax is not supported by the TMS34010 parser
|
||||
intrinsics target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
llvm-ct-intrinsics target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
nested-select target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
overloaded-intrinsic-name gc.statepoint calls are not supported
|
||||
pr12507 target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
pr24662 target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
pr49872 target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
print-arith-fp target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
ptr-annotate target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
replace-intrinsics-with-veclib target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
replace-intrinsics-with-veclib-darwin-libsystem-m target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
select target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
select-cc target rejection: M2 supports only void/integer(<=64)/pointer returns
|
||||
trap target rejection: M2 supports only direct calls to global functions and indirect calls through a function pointer
|
||||
vector missing libcall lowering (floats/vectors are deferred to M6)
|
||||
zero-sized-array target rejection: TMS34010 supports only integer (<=64 bit) and pointer arguments
|
||||
gc-lowering target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
shadow-stack-gc-lowering target rejection: M2 .data supports only integer, pointer and byte-array initializers
|
||||
Executable
+283
@@ -0,0 +1,283 @@
|
||||
#!/bin/sh
|
||||
# M5 CodeGen/Generic compile-only no-crash sweep.
|
||||
#
|
||||
# scripts/tests/m5/generic.sh
|
||||
#
|
||||
# Phase 1 (allowlist gate): compile each file in generic-allowlist.txt with
|
||||
# llc -march=tms34010 -filetype=asm -O0
|
||||
# and require exit 0 and a non-empty asm file. The allowlist is a small,
|
||||
# curated integer/control/load-store/call/PHI set; it is not a claim that every
|
||||
# Generic test is runnable, only that these compile cleanly.
|
||||
#
|
||||
# Phase 2 (broad sweep): compile every .ll file under the LLVM
|
||||
# test/CodeGen/Generic tree and classify each result:
|
||||
#
|
||||
# pass exit 0 and a non-empty .s
|
||||
# unsupported a clear LLVM/target diagnostic (Cannot select, an explicit
|
||||
# M2/TMS34010 rejection, a missing libcall, an inline-asm
|
||||
# constraint failure), even when LLVM exits through
|
||||
# report_fatal_error()
|
||||
# crash signal/abort/assertion/timeout, or any failure without a
|
||||
# recognized diagnostic
|
||||
#
|
||||
# Every `unsupported` row must be recorded with a reason in
|
||||
# generic-expected-fail.txt. A crash is a regression and is never a skip:
|
||||
# it fails this gate even if the manifest names the test. The report is
|
||||
# written to build/m5-generic/generic-report.txt.
|
||||
#
|
||||
# This is a compile-only sweep. Hand-written Generic IR GEPs are
|
||||
# byte-oriented and the target tms-clang bit-address scaling does not apply,
|
||||
# so executing the output is out of scope.
|
||||
#
|
||||
# Overridable: TMS_LLC LLVM_BIN GENERIC_SRC M5_WORK GENERIC_TIMEOUT
|
||||
# GENERIC_ALLOWLIST GENERIC_MANIFEST
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
GENERIC_SRC=${GENERIC_SRC:-$ROOT/build/llvm-clean/llvm/test/CodeGen/Generic}
|
||||
M5_WORK=${M5_WORK:-$ROOT/build/m5-generic}
|
||||
# M5_WORK is removed below; reject paths that could escape their intended
|
||||
# build directory or name the filesystem root.
|
||||
case $M5_WORK in
|
||||
'' | / | . | ..)
|
||||
echo "M5 generic: FAIL: unsafe M5_WORK '$M5_WORK'" >&2
|
||||
exit 1
|
||||
;;
|
||||
*/../* | */.. | ../* | */./* | */.)
|
||||
echo "M5 generic: FAIL: unsafe M5_WORK '$M5_WORK' (contains . or ..)" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
# 2010-11-04-BigByval is intentionally expensive upstream (a 128 KiB byval
|
||||
# copy; PR7170). It takes ~6 minutes here but does finish, so the timeout is
|
||||
# generous enough not to misclassify it while still catching a real hang.
|
||||
GENERIC_TIMEOUT=${GENERIC_TIMEOUT:-900}
|
||||
ALLOWLIST=${GENERIC_ALLOWLIST:-$HERE/generic-allowlist.txt}
|
||||
MANIFEST=${GENERIC_MANIFEST:-$HERE/generic-expected-fail.txt}
|
||||
REPORT=$M5_WORK/generic-report.txt
|
||||
|
||||
fail() {
|
||||
echo "M5 generic: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -d "$GENERIC_SRC" ] || fail "missing Generic test tree: $GENERIC_SRC"
|
||||
GENERIC_SRC=$(cd "$GENERIC_SRC" && pwd)
|
||||
command -v timeout >/dev/null 2>&1 || fail "timeout(1) is required"
|
||||
|
||||
rm -rf "$M5_WORK"
|
||||
mkdir -p "$M5_WORK/allowlist" "$M5_WORK/sweep"
|
||||
|
||||
# The first stderr line, with CRs stripped and long diagnostics truncated, is
|
||||
# enough for a report row.
|
||||
detail() {
|
||||
sed -n '1{s/\r$//;p;}' "$1" 2>/dev/null | cut -c1-200
|
||||
}
|
||||
|
||||
# Print the classification reason for a non-passing result, or nothing when
|
||||
# stderr has no recognized diagnostic.
|
||||
failure_reason() {
|
||||
err=$1
|
||||
line=$(detail "$err")
|
||||
if grep -Eq 'LLVM ERROR: Cannot select:' "$err"; then
|
||||
printf 'target cannot select IR node: %s\n' \
|
||||
"$(printf '%s\n' "$line" | sed 's/^LLVM ERROR: //')"
|
||||
elif grep -Eq 'LLVM ERROR: (TMS34010|M2)([: ]|$)' "$err"; then
|
||||
printf 'target rejection: %s\n' \
|
||||
"$(printf '%s\n' "$line" | sed 's/^LLVM ERROR: //')"
|
||||
elif grep -Fq 'LLVM ERROR: unsupported library call operation' "$err"; then
|
||||
printf 'missing libcall lowering (floats/vectors are deferred to M6)\n'
|
||||
elif grep -Fq 'LLVM ERROR: Could not match memory address' "$err"; then
|
||||
printf 'inline asm memory constraint is not supported\n'
|
||||
elif grep -Fq "error: could not allocate output register for constraint" "$err"; then
|
||||
printf 'inline asm register constraint cannot be allocated\n'
|
||||
elif grep -Fq 'error: unexpected token' "$err"; then
|
||||
printf 'inline asm syntax is not supported by the TMS34010 parser\n'
|
||||
elif grep -Fq 'fast-math-flags specified for call' "$err"; then
|
||||
printf 'IR verifier rejects the input (fast-math flags on an integer call)\n'
|
||||
fi
|
||||
}
|
||||
|
||||
# classify_one OUT ERR RC: print "pass|unsupported|crash<TAB>detail".
|
||||
classify_one() {
|
||||
out=$1
|
||||
err=$2
|
||||
rc=$3
|
||||
if [ "$rc" -eq 0 ]; then
|
||||
if [ -s "$out" ]; then
|
||||
printf 'pass\tasm %s bytes\n' "$(wc -c < "$out" | tr -d ' ')"
|
||||
else
|
||||
printf 'crash\tllc exited 0 but produced an empty asm file\n'
|
||||
fi
|
||||
return
|
||||
fi
|
||||
if grep -Eq 'Assertion .* failed' "$err"; then
|
||||
printf 'crash\tassertion: %s\n' "$(detail "$err" | cut -c1-160)"
|
||||
return
|
||||
fi
|
||||
# Timeout(1) uses 124 for SIGTERM and 137 for SIGKILL. Keep both as
|
||||
# crashes, but do not pretend SIGKILL is necessarily a timeout: it can be
|
||||
# the OOM killer. Only 134 (SIGABRT from report_fatal_error) is the
|
||||
# clear-diagnostic carve-out; any other signal is a crash even if a
|
||||
# diagnostic was printed before it.
|
||||
if [ "$rc" -eq 124 ]; then
|
||||
printf 'crash\ttimeout after %ss\n' "$GENERIC_TIMEOUT"
|
||||
return
|
||||
fi
|
||||
if [ "$rc" -eq 137 ]; then
|
||||
printf 'crash\tkilled by signal 9 (SIGKILL; possibly OOM)\n'
|
||||
return
|
||||
fi
|
||||
if [ "$rc" -ge 128 ] && [ "$rc" -ne 134 ]; then
|
||||
sig=$((rc - 128))
|
||||
if [ "$sig" -eq 0 ]; then
|
||||
printf 'crash\texit 128 (signal range, no signal number)\n'
|
||||
else
|
||||
printf 'crash\tkilled by signal %s\n' "$sig"
|
||||
fi
|
||||
return
|
||||
fi
|
||||
reason=$(failure_reason "$err")
|
||||
if [ -n "$reason" ]; then
|
||||
printf 'unsupported\t%s\n' "$reason"
|
||||
elif [ "$rc" -eq 134 ]; then
|
||||
printf 'crash\tabort (SIGABRT) with no recognized diagnostic: %s\n' \
|
||||
"$(detail "$err")"
|
||||
else
|
||||
printf 'crash\texit %s: %s\n' "$rc" "$(detail "$err")"
|
||||
fi
|
||||
}
|
||||
|
||||
# --- Phase 1: allowlist gate -------------------------------------------------
|
||||
[ -f "$ALLOWLIST" ] || fail "no allowlist: $ALLOWLIST"
|
||||
allow_total=0
|
||||
while IFS= read -r name; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
allow_total=$((allow_total + 1))
|
||||
src=$GENERIC_SRC/$name.ll
|
||||
[ -f "$src" ] || fail "allowlist entry has no source: $src"
|
||||
flat=$(printf '%s' "$name" | tr '/' '_')
|
||||
out=$M5_WORK/allowlist/$flat.s
|
||||
err=$M5_WORK/allowlist/$flat.err
|
||||
set +e
|
||||
timeout "$GENERIC_TIMEOUT" "$TMS_LLC" -march=tms34010 -filetype=asm -O0 \
|
||||
"$src" -o "$out" 2> "$err"
|
||||
rc=$?
|
||||
set -e
|
||||
[ "$rc" -eq 0 ] || fail "allowlist $name: llc exited $rc: $(detail "$err")"
|
||||
[ -s "$out" ] || fail "allowlist $name: empty asm"
|
||||
done < "$ALLOWLIST"
|
||||
[ "$allow_total" -gt 0 ] || fail "generic-allowlist.txt is empty"
|
||||
echo "M5 generic allowlist: PASS files=$allow_total"
|
||||
|
||||
# --- Phase 2: broad no-crash sweep ------------------------------------------
|
||||
total=0
|
||||
pass=0
|
||||
unsupported=0
|
||||
crash=0
|
||||
: > "$M5_WORK/unsupported.txt"
|
||||
|
||||
{
|
||||
echo "# M5 CodeGen/Generic compile-only sweep"
|
||||
echo "# llc: $TMS_LLC"
|
||||
echo "# flags: -march=tms34010 -filetype=asm -O0"
|
||||
echo "# timeout: ${GENERIC_TIMEOUT}s"
|
||||
echo "# rows: status<TAB>test<TAB>detail"
|
||||
} > "$REPORT"
|
||||
|
||||
find "$GENERIC_SRC" -type f -name '*.ll' | sort > "$M5_WORK/tests.txt"
|
||||
[ -s "$M5_WORK/tests.txt" ] || fail "no Generic .ll files under $GENERIC_SRC"
|
||||
|
||||
while IFS= read -r src; do
|
||||
rel=${src#"$GENERIC_SRC"/}
|
||||
name=${rel%.ll}
|
||||
total=$((total + 1))
|
||||
# Keep the report name relative to the Generic tree (subdirectories
|
||||
# included) but use a flat, unique work file per test.
|
||||
stem=$(basename "$src" .ll)
|
||||
out=$M5_WORK/sweep/$total-$stem.s
|
||||
err=$M5_WORK/sweep/$total-$stem.err
|
||||
set +e
|
||||
timeout "$GENERIC_TIMEOUT" "$TMS_LLC" -march=tms34010 -filetype=asm -O0 \
|
||||
"$src" -o "$out" 2> "$err"
|
||||
rc=$?
|
||||
set -e
|
||||
result=$(classify_one "$out" "$err" "$rc")
|
||||
status=${result%% *}
|
||||
why=${result#* }
|
||||
case $status in
|
||||
pass)
|
||||
pass=$((pass + 1))
|
||||
;;
|
||||
unsupported)
|
||||
unsupported=$((unsupported + 1))
|
||||
printf '%s\n' "$name" >> "$M5_WORK/unsupported.txt"
|
||||
;;
|
||||
crash)
|
||||
crash=$((crash + 1))
|
||||
echo "M5 generic: CRASH $name: $why" >&2
|
||||
;;
|
||||
*)
|
||||
fail "internal classification error for $name: $result"
|
||||
;;
|
||||
esac
|
||||
printf '%s\t%s\t%s\n' "$status" "$name" "$why" >> "$REPORT"
|
||||
done < "$M5_WORK/tests.txt"
|
||||
|
||||
{
|
||||
echo "# total $total pass $pass unsupported $unsupported crash $crash"
|
||||
} >> "$REPORT"
|
||||
|
||||
# --- Manifest check ----------------------------------------------------------
|
||||
# Every unsupported row needs a reason, and a manifest row may not name a
|
||||
# passing test (stale) or a crash (a crash is never a known failure).
|
||||
[ -f "$MANIFEST" ] || fail "no expected-fail manifest: $MANIFEST"
|
||||
: > "$M5_WORK/manifest.txt"
|
||||
while IFS=$(printf '\t') read -r name reason; do
|
||||
case $name in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
[ -n "${reason:-}" ] || fail "manifest entry '$name' has no reason"
|
||||
[ -f "$GENERIC_SRC/$name.ll" ] || fail "manifest entry has no source: $name.ll"
|
||||
if grep -Fxq "$name" "$M5_WORK/unsupported.txt"; then
|
||||
printf '%s\n' "$name" >> "$M5_WORK/manifest.txt"
|
||||
else
|
||||
row=$(awk -F '\t' -v n="$name" '$2 == n { print $1 }' "$REPORT")
|
||||
case $row in
|
||||
pass)
|
||||
fail "manifest entry '$name' now passes; remove it from the manifest"
|
||||
;;
|
||||
crash)
|
||||
fail "manifest entry '$name' crashes; a crash is not a known failure"
|
||||
;;
|
||||
*)
|
||||
fail "manifest entry '$name' is not in the sweep"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done < "$MANIFEST"
|
||||
|
||||
sort -o "$M5_WORK/unsupported.txt" "$M5_WORK/unsupported.txt"
|
||||
sort -o "$M5_WORK/manifest.txt" "$M5_WORK/manifest.txt"
|
||||
listed=$(comm -23 "$M5_WORK/manifest.txt" "$M5_WORK/unsupported.txt")
|
||||
[ -z "$listed" ] || fail "manifest names a non-unsupported test: $listed"
|
||||
missing=$(comm -13 "$M5_WORK/manifest.txt" "$M5_WORK/unsupported.txt")
|
||||
if [ -n "$missing" ]; then
|
||||
echo "M5 generic: unsupported tests with no manifest reason:" >&2
|
||||
echo "$missing" | sed 's/^/ /' >&2
|
||||
fail "record every unsupported test in generic-expected-fail.txt"
|
||||
fi
|
||||
|
||||
[ "$total" -gt 0 ] || fail "no Generic tests found"
|
||||
[ "$crash" -eq 0 ] || fail "$crash Generic test(s) crashed"
|
||||
[ "$pass" -gt 0 ] || fail "no Generic test passed"
|
||||
|
||||
echo "M5 generic sweep: PASS total=$total pass=$pass unsupported=$unsupported crash=$crash"
|
||||
echo "M5 generic: report $REPORT"
|
||||
Executable
+307
@@ -0,0 +1,307 @@
|
||||
#!/bin/sh
|
||||
# M5 JR / branch-relaxation gate.
|
||||
#
|
||||
# Proves that a local branch whose displacement fits the ISA's signed 8-bit
|
||||
# word range uses the one-word relative JR/JR<cc> form, that the absolute
|
||||
# JAUC/JA<cc> form is kept when it cannot reach (and for the zero displacement,
|
||||
# which the short form cannot encode), and that the native object path, the
|
||||
# assembler path and the 1987 GSPA/GSPLNK oracle agree:
|
||||
#
|
||||
# 1. compile the M3 branch.c loop and require the in-range loop branches in
|
||||
# _sumto to be JR forms (m5-jr.ll pins the far-branch side);
|
||||
# 2. re-assemble llc's asm output with llvm-mc and require its .text to equal
|
||||
# the llc -filetype=obj .text byte for byte;
|
||||
# 3. assemble a symbolic JR that is in range (two-byte encoding) and one that
|
||||
# is out of range (the MC backend must widen it to the three-word form);
|
||||
# 4. run the unchanged M3 branch.c loop in MAME through GSPA/GSPLNK and
|
||||
# require the M3 markers (sum=55 max=22 lt=1 screens=0x480 root_off=0x40);
|
||||
# 5. record the linked .text size and the all-JA baseline: every JR in the
|
||||
# linked image replaces a six-byte JA, so the relaxation saved 4 bytes
|
||||
# per JR. Every JR target must be within the ISA's +-2032-bit reach.
|
||||
#
|
||||
# scripts/tests/m5/jr.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TMS_LLVM_MC
|
||||
# DIS34 M5_JR_WORK DOSBOX MAME MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
WORK=${M5_JR_WORK:-$ROOT/build/m5-jr}
|
||||
SRC=$ROOT/scripts/m3
|
||||
export M3_WORK=${M3_WORK:-$WORK/m3}
|
||||
export M3_COFF=${M3_COFF:-$M3_WORK/m3.coff}
|
||||
|
||||
fail() {
|
||||
echo "M5 JR: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Extract a .text section. llvm-mc uses LLVM's generic ELF writer (sizes in
|
||||
# bytes); llc -filetype=obj and GSPLNK write TI-COFF (sizes in bits, optional
|
||||
# header size at offset 16).
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
|
||||
if d[:4] == b"\x7fELF":
|
||||
e_shoff, = struct.unpack_from("<I", d, 0x20)
|
||||
e_shentsize, = struct.unpack_from("<H", d, 0x2E)
|
||||
e_shnum, = struct.unpack_from("<H", d, 0x30)
|
||||
e_shstrndx, = struct.unpack_from("<H", d, 0x32)
|
||||
o = e_shoff + e_shstrndx * e_shentsize
|
||||
str_off, = struct.unpack_from("<I", d, o + 16)
|
||||
str_size, = struct.unpack_from("<I", d, o + 20)
|
||||
strtab = d[str_off:str_off + str_size]
|
||||
for i in range(e_shnum):
|
||||
o = e_shoff + i * e_shentsize
|
||||
name_off, = struct.unpack_from("<I", d, o)
|
||||
name = strtab[name_off:strtab.find(b"\0", name_off)].decode("latin1")
|
||||
if name != ".text":
|
||||
continue
|
||||
off, size = struct.unpack_from("<II", d, o + 16)
|
||||
text = d[off:off + size]
|
||||
with open(out, "wb") as g:
|
||||
g.write(text)
|
||||
print(f"{path}: ELF .text {len(text)} bytes")
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
|
||||
machine, nscns = struct.unpack_from("<HH", d, 0)
|
||||
opthdr, = struct.unpack_from("<H", d, 16)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want TI-COFF 0x0090")
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size, ptr = struct.unpack_from("<II", d, o + 16)
|
||||
if name != ".text":
|
||||
continue
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: .text {size} bits is not whole bytes")
|
||||
text = d[ptr:ptr + size // 8]
|
||||
with open(out, "wb") as g:
|
||||
g.write(text)
|
||||
print(f"{path}: TI-COFF .text {len(text)} bytes")
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
}
|
||||
|
||||
# The M3 gate keeps the loop in branch.c (IndVarSimplify would otherwise turn
|
||||
# sumto into an i33 multiply that this target cannot select).
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
echo "== compile the M3 branch.c loop"
|
||||
TMS_OPT=$OPT_NOREPLEXIT TMS_CLANG="$TMS_CLANG" TMS_BITADDR="$TMS_BITADDR" \
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$SRC" \
|
||||
-o "$WORK/branch.ll" "$SRC/branch.c" || fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/branch.ll" \
|
||||
-o "$WORK/branch.s" || fail "llc -filetype=asm failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj "$WORK/branch.ll" \
|
||||
-o "$WORK/branch.o" || fail "llc -filetype=obj failed"
|
||||
|
||||
# The short-loop body must use the relative form. m5-jr.ll checks the other
|
||||
# half of the contract (a far/zero-displacement branch stays absolute).
|
||||
awk '/^_sumto:/ { on = 1; next } on && /-- End function/ { exit } on' \
|
||||
"$WORK/branch.s" > "$WORK/sumto.s"
|
||||
grep -Eq '^[[:space:]]*JR(UC|EQ|NE|LT|LE|GT|GE|LO|LS|HI|HS|P|N|V|NV|NN)[[:space:]]' \
|
||||
"$WORK/sumto.s" || { sed 's/^/ /' "$WORK/sumto.s" >&2; fail "_sumto has no JR branch"; }
|
||||
JR_ASM=$(grep -Ec '^[[:space:]]*JR(UC|EQ|NE|LT|LE|GT|GE|LO|LS|HI|HS|P|N|V|NV|NN)[[:space:]]' "$WORK/sumto.s" || true)
|
||||
echo " _sumto: $JR_ASM relative branch(es)"
|
||||
|
||||
echo "== asm and object paths must encode the same branch stream"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$WORK/branch.s" \
|
||||
-o "$WORK/branch-mc.o" || fail "llvm-mc could not assemble llc's output"
|
||||
extract_text "$WORK/branch.o" "$WORK/branch-obj.text"
|
||||
extract_text "$WORK/branch-mc.o" "$WORK/branch-mc.text"
|
||||
if ! cmp -s "$WORK/branch-obj.text" "$WORK/branch-mc.text"; then
|
||||
{
|
||||
echo "M5 JR: FAIL: llc -filetype=obj and llvm-mc .text differ"
|
||||
echo " object: $(od -An -v -tx1 "$WORK/branch-obj.text")"
|
||||
echo " asm: $(od -An -v -tx1 "$WORK/branch-mc.text")"
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
echo " obj .text == llvm-mc .text ($(wc -c < "$WORK/branch-obj.text") bytes)"
|
||||
|
||||
echo "== MC relaxation: symbolic JR forms must widen when not encodable"
|
||||
cat > "$WORK/relax.s" <<'EOF'
|
||||
.text
|
||||
m5_relax:
|
||||
JRUC near
|
||||
RETS 0
|
||||
near:
|
||||
RETS 0
|
||||
JRUC zero
|
||||
zero:
|
||||
RETS 0
|
||||
JRUC far
|
||||
RETS 0
|
||||
EOF
|
||||
# `far` follows 200 NOPs (400 bytes). `zero` is the next instruction, so its
|
||||
# displacement would be 0 (the 16-bit relative form's marker), and disp -128
|
||||
# (low byte 0x80) is the absolute-JA marker: neither is encodable in one word.
|
||||
# The last two probes pin the boundaries: -127 must stay short, -128 must
|
||||
# widen. Each is placed 126/127 NOPs (252/254 bytes) after its label.
|
||||
awk 'BEGIN { for (i = 0; i < 200; i++) print "\tNOP" }' >> "$WORK/relax.s"
|
||||
printf 'far:\n\tRETS 0\nback127:\n' >> "$WORK/relax.s"
|
||||
awk 'BEGIN { for (i = 0; i < 126; i++) print "\tNOP" }' >> "$WORK/relax.s"
|
||||
printf '\tJRUC back127\nback128:\n' >> "$WORK/relax.s"
|
||||
awk 'BEGIN { for (i = 0; i < 127; i++) print "\tNOP" }' >> "$WORK/relax.s"
|
||||
printf '\tJRUC back128\n\tRETS 0\n' >> "$WORK/relax.s"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$WORK/relax.s" \
|
||||
-o "$WORK/relax.o" || fail "llvm-mc failed on the relaxation probe"
|
||||
extract_text "$WORK/relax.o" "$WORK/relax.text"
|
||||
# Layout with three widenings (zero, far, back128): JRUC near 2 + RETS 2 +
|
||||
# near RETS 2 + JRUC zero 6 + RETS 2 + JRUC far 6 + RETS 2 + 200 NOPs 400 +
|
||||
# far RETS 2 + 126 NOPs 252 + JRUC back127 2 + 127 NOPs 254 + JRUC back128 6 +
|
||||
# RETS 2 = 940 bytes. A missing widening would be 4 bytes smaller.
|
||||
RELAX_BYTES=$(wc -c < "$WORK/relax.text")
|
||||
[ "$RELAX_BYTES" -eq 940 ] \
|
||||
|| fail "relaxed .text is $RELAX_BYTES bytes, want 940 (three 6-byte JAs)"
|
||||
"$DIS34" -b 0 -l -o "$WORK/relax.text" > "$WORK/relax.dis" 2>/dev/null \
|
||||
|| fail "dis34 failed on the relaxation probe"
|
||||
# dis34 -l prints `<bit address>:\t<mnemonic> <target>\t; <encoded words>`.
|
||||
python3 - "$WORK/relax.dis" <<'PY' || fail "the MC relaxation probe is wrong"
|
||||
import re
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
branches = []
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = re.match(r"^[0-9a-f]+:\s+(j[a-z]*)\s+\S+\s*;\s*([0-9a-f ]+)$",
|
||||
line.strip())
|
||||
if m:
|
||||
words = m.group(2).replace(" ", "")
|
||||
branches.append((m.group(1), len(words) // 2, words[:4]))
|
||||
# near disp=1 (c001) stays 2 bytes; zero, far and back128 widen to 6 bytes;
|
||||
# back127 disp=-127 (c081) is the last encodable displacement and stays 2.
|
||||
want = [("jruc", 2, "c001"), ("jauc", 6, "c080"), ("jauc", 6, "c080"),
|
||||
("jruc", 2, "c081"), ("jauc", 6, "c080")]
|
||||
if branches != want:
|
||||
sys.exit(f"branch encodings {branches}, want {want}")
|
||||
print(" branch encodings:",
|
||||
" ".join(f"{m}/{n}B" for m, n, _w in branches))
|
||||
PY
|
||||
|
||||
echo "== run the M3 branch.c loop in MAME"
|
||||
"$ROOT/scripts/tests/m3/run.sh" > "$WORK/m3.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/m3.log" >&2; fail "M3 gate failed"; }
|
||||
grep -q '^M3 MAME: PASS' "$WORK/m3.log" \
|
||||
|| { grep -E '^M3:' "$WORK/m3.log" >&2 || true; fail "M3 MAME markers did not pass"; }
|
||||
MARKER=$(grep -E 'M3: display=' "$WORK/m3.log" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no M3 marker line"
|
||||
case "$MARKER" in
|
||||
*" sum=55 max=22 lt=1 screens=0x480 root_off=0x40"*) ;;
|
||||
*) fail "M3 marker values changed: $MARKER" ;;
|
||||
esac
|
||||
echo " $MARKER"
|
||||
|
||||
echo "== linked .text size"
|
||||
# Recorded baseline for the unchanged M3 sources (branch.c, layout.c, xhello.c).
|
||||
# Update these constants together if those sources, the relaxation, or the
|
||||
# frame save/restore change. MMTM/MMFM shortened xhello's 4-register save and
|
||||
# restore by 8 bytes (882 -> 874); functions saving one or two registers keep
|
||||
# the same or grow by up to 4 bytes, so re-measure after changing the ABI.
|
||||
EXPECTED_TEXT_BYTES=874
|
||||
EXPECTED_JR=14
|
||||
TEXT_BITS=$(awk '$1 == ".text" && $2 == "0" { print $4; exit }' "$M3_WORK/m3.map")
|
||||
[ -n "$TEXT_BITS" ] || fail "the linker map has no .text section"
|
||||
TEXT_BYTES=$((0x$TEXT_BITS / 8))
|
||||
extract_text "$M3_COFF" "$WORK/m3.text"
|
||||
"$DIS34" -b 018A0000 -l -o "$WORK/m3.text" > "$WORK/m3.dis" 2>/dev/null \
|
||||
|| fail "dis34 failed on the linked image"
|
||||
NJR=$(grep -Ec '^[0-9a-f]+:[[:space:]]+jr(uc|eq|ne|lt|le|gt|ge|lo|ls|hi|hs|p|n|v|nv|nn)([[:space:]]|;|$)' "$WORK/m3.dis" || true)
|
||||
[ "$NJR" -eq "$EXPECTED_JR" ] \
|
||||
|| fail "the linked image has $NJR JR branches, want $EXPECTED_JR"
|
||||
[ "$TEXT_BYTES" -eq "$EXPECTED_TEXT_BYTES" ] \
|
||||
|| fail "linked .text is $TEXT_BYTES bytes, want $EXPECTED_TEXT_BYTES"
|
||||
BASELINE=$((TEXT_BYTES + 4 * NJR))
|
||||
SAVED=$((4 * NJR))
|
||||
echo " linked .text: $TEXT_BYTES bytes; $NJR JR branch(es) save $SAVED bytes"
|
||||
echo " all-JA baseline: $BASELINE bytes"
|
||||
|
||||
# A branch to the following instruction cannot use the one-word form (disp 0
|
||||
# selects the 16-bit relative form), so it must stay absolute. A far branch is
|
||||
# absolute too, so require the specific shape: a JA whose target label is
|
||||
# defined on the next line. The M3 baseline has exactly two, both in xhello.
|
||||
ZERO_DISP_JA=$(python3 - "$M3_WORK/asm" <<'PY'
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
count = 0
|
||||
for path in sorted(glob.glob(os.path.join(sys.argv[1], "*.unique.s"))):
|
||||
lines = open(path, encoding="latin1").read().splitlines()
|
||||
for i, line in enumerate(lines):
|
||||
m = re.match(r"^\s*JA(?:UC|EQ|NE|LT|LE|GT|GE|LO|LS|HI|HS|P|N|V|NV|NN)"
|
||||
r"\s+(\S+)", line)
|
||||
if not m or i + 1 >= len(lines):
|
||||
continue
|
||||
label = re.match(r"^([A-Za-z_][A-Za-z0-9_]*):", lines[i + 1])
|
||||
if label and label.group(1) == m.group(1):
|
||||
count += 1
|
||||
print(count)
|
||||
PY
|
||||
)
|
||||
[ "$ZERO_DISP_JA" -eq 2 ] \
|
||||
|| fail "the compiled TUs have $ZERO_DISP_JA zero-displacement JA branches, want 2"
|
||||
echo " zero-displacement branches kept absolute: $ZERO_DISP_JA"
|
||||
|
||||
# Every JR must be one 16-bit word (dis34 -l prints the encoded words in the
|
||||
# trailing comment; a GSPA 16-bit relative form would print two words) and must
|
||||
# encode a nonzero displacement that fits the signed 8-bit word range.
|
||||
python3 - "$WORK/m3.dis" <<'PY' || fail "a JR encoding is not a one-word in-range JR"
|
||||
import re
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
pat = re.compile(r"^([0-9a-f]+):\s+jr[a-z]*\s+(\S+)\s*;\s*([0-9a-f ]+)$")
|
||||
count = 0
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = pat.match(line.strip())
|
||||
if not m:
|
||||
continue
|
||||
pc = int(m.group(1), 16)
|
||||
tgt_text = m.group(2).lstrip("L")
|
||||
try:
|
||||
tgt = int(tgt_text, 16)
|
||||
except ValueError:
|
||||
sys.exit(f"cannot parse JR target: {line.strip()}")
|
||||
words = m.group(3).replace(" ", "")
|
||||
if len(words) != 4:
|
||||
sys.exit(f"JR is not one word: {line.strip()}")
|
||||
delta = tgt - (pc + 16)
|
||||
if delta == 0 or delta % 16 or abs(delta) > 127 * 16:
|
||||
sys.exit(f"JR out of range: {line.strip()} (delta {delta} bits)")
|
||||
count += 1
|
||||
if count == 0:
|
||||
sys.exit("no JR instruction found")
|
||||
print(f" all {count} JR branches are one word and in range (±2032 bits)")
|
||||
PY
|
||||
|
||||
echo "M5 JR: PASS"
|
||||
Executable
+215
@@ -0,0 +1,215 @@
|
||||
#!/bin/sh
|
||||
# M5 MC round-trip gate.
|
||||
#
|
||||
# Assembles llvm/test/MC/TMS34010/roundtrip.s with `llvm-mc -filetype=obj`,
|
||||
# extracts the .text bytes, and requires the vendored smart34010 `dis34` to
|
||||
# reproduce the source mnemonics and operands. GSPA/`dis34` are the encoding
|
||||
# oracle; the expected bytes in encodings.s are GSPA listings, not this
|
||||
# encoder's output.
|
||||
#
|
||||
# scripts/tests/m5/mc-roundtrip.sh
|
||||
#
|
||||
# Overridable: TMS_LLVM_MC TMS_DIS34 M5_MC_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
TMS_DIS34=${TMS_DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
SRC=${TMS_MC_SRC:-$ROOT/build/llvm-clean/llvm/test/MC/TMS34010/roundtrip.s}
|
||||
M5_MC_WORK=${M5_MC_WORK:-$ROOT/build/m5-mc}
|
||||
|
||||
fail() {
|
||||
echo "M5 MC round-trip: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLVM_MC" ] || fail "missing llvm-mc: $TMS_LLVM_MC"
|
||||
[ -x "$TMS_DIS34" ] || fail "missing dis34: $TMS_DIS34"
|
||||
[ -f "$SRC" ] || fail "missing source: $SRC"
|
||||
|
||||
mkdir -p "$M5_MC_WORK"
|
||||
OBJ=$M5_MC_WORK/roundtrip.o
|
||||
rm -f "$OBJ"
|
||||
|
||||
echo "== assemble $SRC"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$SRC" -o "$OBJ" \
|
||||
|| fail "llvm-mc -filetype=obj failed"
|
||||
|
||||
# Extract .text. llvm-mc uses LLVM's generic ELF writer, whose section size is
|
||||
# in bytes; the target's own TI-COFF writer (llc -filetype=obj) stores section
|
||||
# sizes in bits. Prefer the ELF path, with a bits-first TI-COFF fallback.
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
|
||||
def elf_text():
|
||||
if len(d) < 52 or d[:4] != b"\x7fELF" or d[4] != 1 or d[5] != 1:
|
||||
return None
|
||||
e_shoff = struct.unpack_from("<I", d, 0x20)[0]
|
||||
e_shentsize = struct.unpack_from("<H", d, 0x2E)[0]
|
||||
e_shnum = struct.unpack_from("<H", d, 0x30)[0]
|
||||
e_shstrndx = struct.unpack_from("<H", d, 0x32)[0]
|
||||
if e_shentsize != 40 or e_shnum == 0 or e_shstrndx >= e_shnum:
|
||||
return None
|
||||
shstr = e_shoff + e_shstrndx * e_shentsize
|
||||
str_off = struct.unpack_from("<I", d, shstr + 16)[0]
|
||||
str_size = struct.unpack_from("<I", d, shstr + 20)[0]
|
||||
strtab = d[str_off:str_off + str_size]
|
||||
for i in range(e_shnum):
|
||||
o = e_shoff + i * e_shentsize
|
||||
name_off = struct.unpack_from("<I", d, o)[0]
|
||||
name = strtab[name_off:strtab.find(b"\0", name_off)].decode("latin1")
|
||||
if name == ".text":
|
||||
off = struct.unpack_from("<I", d, o + 16)[0]
|
||||
size = struct.unpack_from("<I", d, o + 20)[0]
|
||||
if off + size > len(d):
|
||||
sys.exit(f"{path}: .text runs past EOF")
|
||||
return d[off:off + size]
|
||||
return None
|
||||
|
||||
def coff_text():
|
||||
if len(d) < 20:
|
||||
return None
|
||||
machine, nscns, _time, _symptr, _nsyms, opthdr, _flags = \
|
||||
struct.unpack_from("<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
return None
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size = struct.unpack_from("<I", d, o + 16)[0]
|
||||
ptr = struct.unpack_from("<I", d, o + 20)[0]
|
||||
if name == ".text":
|
||||
# The native TI-COFF writer stores SizeOfRawData in bits.
|
||||
nbytes = size // 8
|
||||
if size and ptr + nbytes <= len(d):
|
||||
return d[ptr:ptr + nbytes]
|
||||
# Fallback for a COFF producer that uses byte sizes.
|
||||
if size and ptr + size <= len(d):
|
||||
return d[ptr:ptr + size]
|
||||
return None
|
||||
|
||||
text = elf_text()
|
||||
if text is None:
|
||||
text = coff_text()
|
||||
if text is None:
|
||||
sys.exit(f"{path}: no .text section")
|
||||
if not text:
|
||||
sys.exit(f"{path}: .text is empty")
|
||||
if len(text) % 2:
|
||||
sys.exit(f"{path}: .text has an odd byte count ({len(text)})")
|
||||
with open(out, "wb") as f:
|
||||
f.write(text)
|
||||
PY
|
||||
}
|
||||
|
||||
TEXT=$M5_MC_WORK/roundtrip.text
|
||||
extract_text "$OBJ" "$TEXT"
|
||||
|
||||
echo "== disassemble with dis34"
|
||||
"$TMS_DIS34" "$TEXT" > "$M5_MC_WORK/roundtrip.dis" 2> "$M5_MC_WORK/roundtrip.err" \
|
||||
|| { cat "$M5_MC_WORK/roundtrip.err" >&2; fail "dis34 failed"; }
|
||||
|
||||
python3 - "$SRC" "$M5_MC_WORK/roundtrip.dis" <<'PY'
|
||||
import re
|
||||
import sys
|
||||
|
||||
src_path, dis_path = sys.argv[1], sys.argv[2]
|
||||
|
||||
REG = re.compile(r"^(a|b)\d+$|^sp$|^b15$")
|
||||
|
||||
|
||||
def canon_num(s):
|
||||
s = s.strip()
|
||||
try:
|
||||
return "#%d" % int(s, 0)
|
||||
except ValueError:
|
||||
return s
|
||||
|
||||
|
||||
def split_ops(text):
|
||||
# The TMS34010 syntax has no commas inside parentheses; split naively.
|
||||
return [p.strip() for p in text.split(",") if p.strip() != ""]
|
||||
|
||||
|
||||
def canon_operand(op):
|
||||
op = op.strip().lower()
|
||||
m = re.match(r"^([-+])?\*([ab]\d+|sp|b15)(\+)?(?:\((.*)\))?$", op)
|
||||
if m:
|
||||
sign, reg, post, disp = m.groups()
|
||||
out = (sign or "") + "*" + reg
|
||||
if post:
|
||||
out += "+"
|
||||
if disp is not None:
|
||||
out += "(" + canon_num(disp) + ")"
|
||||
return out
|
||||
if op.startswith("@"):
|
||||
return "@" + canon_num(op[1:])
|
||||
if REG.match(op):
|
||||
return op
|
||||
return canon_num(op)
|
||||
|
||||
|
||||
ALIASES = {"jac": "jalo", "janc": "jahs", "jrc": "jrlo", "jrnc": "jrhs"}
|
||||
|
||||
|
||||
def canon_inst(mnem, ops):
|
||||
mnem = ALIASES.get(mnem.strip().lower(), mnem.strip().lower())
|
||||
ops = [canon_operand(o) for o in split_ops(ops)]
|
||||
if mnem == "rets" and not ops:
|
||||
ops = ["#0"]
|
||||
return mnem, ops
|
||||
|
||||
|
||||
def source_insts(path):
|
||||
insts = []
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.split("#", 1)[0].strip()
|
||||
if not line or line.startswith(".") or line.endswith(":"):
|
||||
continue
|
||||
parts = line.split(None, 1)
|
||||
mnem = parts[0]
|
||||
rest = parts[1] if len(parts) > 1 else ""
|
||||
insts.append(canon_inst(mnem, rest))
|
||||
return insts
|
||||
|
||||
|
||||
def dis_insts(path):
|
||||
insts = []
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
line = line.split(";", 1)[0].strip()
|
||||
if not line or line.startswith(".word"):
|
||||
continue
|
||||
parts = line.split(None, 1)
|
||||
mnem = parts[0]
|
||||
rest = parts[1] if len(parts) > 1 else ""
|
||||
insts.append(canon_inst(mnem, rest))
|
||||
return insts
|
||||
|
||||
|
||||
want = source_insts(src_path)
|
||||
got = dis_insts(dis_path)
|
||||
|
||||
if want != got:
|
||||
print("M5 MC round-trip: FAIL: dis34 did not reproduce the source", file=sys.stderr)
|
||||
for i in range(max(len(want), len(got))):
|
||||
w = want[i] if i < len(want) else None
|
||||
g = got[i] if i < len(got) else None
|
||||
mark = " " if w == g else "!!"
|
||||
print(f" {mark} src={w} dis34={g}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f" {len(want)} instructions round-tripped through dis34")
|
||||
PY
|
||||
|
||||
echo "M5 MC round-trip: PASS"
|
||||
Executable
+225
@@ -0,0 +1,225 @@
|
||||
#!/bin/sh
|
||||
# M5 MMTM/MMFM register-list frame-save gate.
|
||||
#
|
||||
# Proves that the frame lowering saves the callee-save set with one MMTM and
|
||||
# restores it with one MMFM, without changing the TI ABI:
|
||||
#
|
||||
# 1. compile m5-mmtm.ll to asm and to a TI-COFF object; the callee saves
|
||||
# A0/A1/A3/A5 with one `MMTM SP, A0, A1, A3, A5`, restores with one
|
||||
# `MMFM SP, ...`, and still reloads the old STK from *SP(192) and returns
|
||||
# with RETS 2;
|
||||
# 2. assemble llc's asm with llvm-mc and require its .text to equal the
|
||||
# llc -filetype=obj .text byte for byte, so the asm and object paths use
|
||||
# the same register-list encoding;
|
||||
# 3. dis34 the object: the MMTM/MMFM register lists and their encoded masks
|
||||
# (0xd400/0x002b) must be present, and no per-register save may precede
|
||||
# SETFP; record the code-size saving;
|
||||
# 4. run the unchanged M2 and M3 gates in MAME and require their markers and
|
||||
# old-STK/ABI values.
|
||||
#
|
||||
# scripts/tests/m5/mmtm.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_LLVM_MC DIS34 M5_MMTM_WORK M2_WORK M2_COFF
|
||||
# M2_SDK M3_WORK M3_COFF M3_SDK MAME DOSBOX MAME_TIMEOUT
|
||||
# DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_LLVM_MC=${TMS_LLVM_MC:-$LLVM_BIN/llvm-mc}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
|
||||
WORK=${M5_MMTM_WORK:-$ROOT/build/m5-mmtm}
|
||||
export M2_WORK=${M2_WORK:-$WORK/m2}
|
||||
export M2_COFF=${M2_COFF:-$M2_WORK/m2.coff}
|
||||
export M3_WORK=${M3_WORK:-$WORK/m3}
|
||||
export M3_COFF=${M3_COFF:-$M3_WORK/m3.coff}
|
||||
|
||||
fail() {
|
||||
echo "M5 MMTM: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_LLC" "$TMS_LLVM_MC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Extract a .text section. llvm-mc uses LLVM's generic ELF writer (sizes in
|
||||
# bytes); llc -filetype=obj and GSPLNK write TI-COFF (sizes in bits, optional
|
||||
# header size at offset 16).
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
|
||||
if d[:4] == b"\x7fELF":
|
||||
e_shoff, = struct.unpack_from("<I", d, 0x20)
|
||||
e_shentsize, = struct.unpack_from("<H", d, 0x2E)
|
||||
e_shnum, = struct.unpack_from("<H", d, 0x30)
|
||||
e_shstrndx, = struct.unpack_from("<H", d, 0x32)
|
||||
o = e_shoff + e_shstrndx * e_shentsize
|
||||
str_off, = struct.unpack_from("<I", d, o + 16)
|
||||
str_size, = struct.unpack_from("<I", d, o + 20)
|
||||
strtab = d[str_off:str_off + str_size]
|
||||
for i in range(e_shnum):
|
||||
o = e_shoff + i * e_shentsize
|
||||
name_off, = struct.unpack_from("<I", d, o)
|
||||
name = strtab[name_off:strtab.find(b"\0", name_off)].decode("latin1")
|
||||
if name != ".text":
|
||||
continue
|
||||
off, size = struct.unpack_from("<II", d, o + 16)
|
||||
text = d[off:off + size]
|
||||
with open(out, "wb") as g:
|
||||
g.write(text)
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
|
||||
machine, nscns = struct.unpack_from("<HH", d, 0)
|
||||
opthdr, = struct.unpack_from("<H", d, 16)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want TI-COFF 0x0090")
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size, ptr = struct.unpack_from("<II", d, o + 16)
|
||||
if name != ".text":
|
||||
continue
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: .text {size} bits is not whole bytes")
|
||||
with open(out, "wb") as g:
|
||||
g.write(d[ptr:ptr + size // 8])
|
||||
sys.exit(0)
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
}
|
||||
|
||||
echo "== compile m5-mmtm.ll (asm and object paths)"
|
||||
"$TMS_LLC" -march=tms34010 -O2 -filetype=asm \
|
||||
"$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-mmtm.ll" \
|
||||
-o "$WORK/mmtm.s" || fail "llc -filetype=asm failed"
|
||||
"$TMS_LLC" -march=tms34010 -O2 -filetype=obj \
|
||||
"$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m5-mmtm.ll" \
|
||||
-o "$WORK/mmtm.o" || fail "llc -filetype=obj failed"
|
||||
|
||||
grep -Eq '^[[:space:]]*MMTM SP, A0, A1, A3, A5[[:space:]]*$' "$WORK/mmtm.s" \
|
||||
|| { grep -n 'MMT\|MOVE A.*-\*SP' "$WORK/mmtm.s" >&2; \
|
||||
fail "the callee does not save A0/A1/A3/A5 with one MMTM"; }
|
||||
grep -Eq '^[[:space:]]*MMFM SP, A0, A1, A3, A5[[:space:]]*$' "$WORK/mmtm.s" \
|
||||
|| { grep -n 'MMF\|MOVE \*SP+' "$WORK/mmtm.s" >&2; \
|
||||
fail "the callee does not restore A0/A1/A3/A5 with one MMFM"; }
|
||||
# The callee prologue must be exactly FP push + one MMTM: no per-register push.
|
||||
CALLEE=$(awk '/^_mmtm_callee:/ { on = 1; next } on && /-- End function/ { exit } on' \
|
||||
"$WORK/mmtm.s")
|
||||
printf '%s\n' "$CALLEE" | grep -Eq '^[[:space:]]*MOVE A13, -\*SP, 1[[:space:]]*$' \
|
||||
|| fail "the callee does not save FP with one MOVE push"
|
||||
PROLOGUE=$(printf '%s\n' "$CALLEE" | awk '
|
||||
/^[[:space:]]*MOVE A14, A13[[:space:]]*$/ { exit }
|
||||
{ print }
|
||||
')
|
||||
if printf '%s\n' "$PROLOGUE" | grep -Eq '^[[:space:]]*MOVE A([0-9]|1[0-2]), -\*SP, 1[[:space:]]*$'; then
|
||||
fail "the callee still has per-register system-stack saves"
|
||||
fi
|
||||
printf '%s\n' "$PROLOGUE" | grep -Eq '^[[:space:]]*MMTM SP, A0, A1, A3, A5[[:space:]]*$' \
|
||||
|| fail "the callee prologue does not save the register list with MMTM"
|
||||
printf '%s\n' "$CALLEE" | grep -Eq '^[[:space:]]*MOVE \*SP\(192\), A14, 1[[:space:]]*$' \
|
||||
|| fail "the callee old-STK load is not *SP(192)"
|
||||
printf '%s\n' "$CALLEE" | grep -Eq '^[[:space:]]*RETS 2[[:space:]]*$' \
|
||||
|| fail "the callee does not return with RETS 2"
|
||||
echo " callee: MOVE A13,-*SP ; MMTM SP, A0, A1, A3, A5 ; *SP(192),A14 ; RETS 2"
|
||||
|
||||
echo "== asm and object paths must encode the same register lists"
|
||||
"$TMS_LLVM_MC" -triple=tms34010 -filetype=obj "$WORK/mmtm.s" \
|
||||
-o "$WORK/mmtm-mc.o" || fail "llvm-mc could not assemble llc's output"
|
||||
extract_text "$WORK/mmtm.o" "$WORK/mmtm-obj.text" \
|
||||
|| fail "could not extract the llc object .text"
|
||||
extract_text "$WORK/mmtm-mc.o" "$WORK/mmtm-mc.text" \
|
||||
|| fail "could not extract the llvm-mc object .text"
|
||||
cmp -s "$WORK/mmtm-obj.text" "$WORK/mmtm-mc.text" \
|
||||
|| fail "llc -filetype=obj and llvm-mc .text differ"
|
||||
echo " obj .text == llvm-mc .text ($(wc -c < "$WORK/mmtm-obj.text") bytes)"
|
||||
|
||||
echo "== dis34 register list"
|
||||
"$DIS34" -b 0 -l -o "$WORK/mmtm-obj.text" > "$WORK/mmtm.dis" 2>/dev/null \
|
||||
|| fail "dis34 failed on the m5-mmtm object"
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmtm[[:space:]]+sp,[[:space:]]*a0,[[:space:]]*a1,[[:space:]]*a3,[[:space:]]*a5[[:space:]]*;' \
|
||||
"$WORK/mmtm.dis" \
|
||||
|| { grep -i 'mm[ft]m' "$WORK/mmtm.dis" >&2; fail "dis34 has no MMTM SP, A0, A1, A3, A5"; }
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmfm[[:space:]]+sp,[[:space:]]*a0,[[:space:]]*a1,[[:space:]]*a3,[[:space:]]*a5[[:space:]]*;' \
|
||||
"$WORK/mmtm.dis" \
|
||||
|| { grep -i 'mm[ft]m' "$WORK/mmtm.dis" >&2; fail "dis34 has no MMFM SP, A0, A1, A3, A5"; }
|
||||
# Pin the masks: MMTM numbers A0 from bit 15, MMFM from bit 0.
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmtm[[:space:]]+sp,[^;]*;[[:space:]]*098f[[:space:]]+d400[[:space:]]*$' \
|
||||
"$WORK/mmtm.dis" || fail "MMTM encoding is not 098f d400"
|
||||
grep -Eiq '^[0-9a-f]+:[[:space:]]+mmfm[[:space:]]+sp,[^;]*;[[:space:]]*09af[[:space:]]*002b[[:space:]]*$' \
|
||||
"$WORK/mmtm.dis" || fail "MMFM encoding is not 09af 002b"
|
||||
echo " dis34: MMTM SP, a0,a1,a3,a5 ; 098f d400"
|
||||
echo " dis34: MMFM SP, a0,a1,a3,a5 ; 09af 002b"
|
||||
|
||||
# Code size: an MMTM/MMFM is two words (4 bytes) and replaces one two-byte
|
||||
# MOVE push/pop per saved register. Count the registers in the two lists of
|
||||
# the callee and report the saving for that function.
|
||||
CALLEE_REGS=$(awk '
|
||||
{ low = tolower($0) }
|
||||
low ~ /mm[tf]m[[:space:]]+sp,/ {
|
||||
line = low
|
||||
sub(/^.*mm[tf]m[[:space:]]+sp,[[:space:]]*/, "", line)
|
||||
sub(/[[:space:]]*;.*$/, "", line)
|
||||
n += split(line, regs, ",")
|
||||
}
|
||||
END { print n + 0 }
|
||||
' <<EOF
|
||||
$CALLEE
|
||||
EOF
|
||||
)
|
||||
[ "$CALLEE_REGS" -gt 0 ] || fail "no registers in the callee register lists"
|
||||
# The old sequence was one 2-byte push and one 2-byte pop per register (2n
|
||||
# each direction), so the total is 4n bytes.
|
||||
OLD_BYTES=$((CALLEE_REGS * 4))
|
||||
NEW_BYTES=8
|
||||
SAVED_BYTES=$((OLD_BYTES - NEW_BYTES))
|
||||
echo " code size: $CALLEE_REGS saved-register slots: $OLD_BYTES bytes of pushes+pops" \
|
||||
"-> MMTM+MMFM $NEW_BYTES bytes (saves $SAVED_BYTES bytes)"
|
||||
|
||||
echo "== M2 gate (caller/callee + the unchanged ABI markers)"
|
||||
"$ROOT/scripts/tests/m2/run.sh" > "$WORK/m2.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/m2.log" >&2; fail "M2 gate failed"; }
|
||||
grep -q '^M2 MAME: PASS' "$WORK/m2.log" \
|
||||
|| { grep -E 'M2:' "$WORK/m2.log" >&2 || true; fail "M2 MAME markers did not pass"; }
|
||||
grep -q 'M2: check=4 first=20 second=22 caller=42 locals=7 keep=16' "$WORK/m2.log" \
|
||||
|| { grep -E 'M2:' "$WORK/m2.log" >&2 || true; fail "M2 marker values changed"; }
|
||||
grep -q 'MMTM SP,' "$M2_WORK/asm/keep.s" \
|
||||
|| fail "M2 keep.s does not use MMTM"
|
||||
grep -q 'MMFM SP,' "$M2_WORK/asm/keep.s" \
|
||||
|| fail "M2 keep.s does not use MMFM"
|
||||
echo " $(grep -E 'M2:' "$WORK/m2.log" | tail -1)"
|
||||
echo " keep.s: $(grep -m1 'MMTM' "$M2_WORK/asm/keep.s" | sed 's/^[[:space:]]*//')"
|
||||
|
||||
echo "== M3 gate (xhello + the unchanged display/branch markers)"
|
||||
"$ROOT/scripts/tests/m3/run.sh" > "$WORK/m3.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/m3.log" >&2; fail "M3 gate failed"; }
|
||||
grep -q '^M3 MAME: PASS' "$WORK/m3.log" \
|
||||
|| { grep -E 'M3:' "$WORK/m3.log" >&2 || true; fail "M3 MAME markers did not pass"; }
|
||||
MARKER=$(grep -E 'M3: display=' "$WORK/m3.log" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no M3 marker line"
|
||||
case "$MARKER" in
|
||||
*" sum=55 max=22 lt=1 screens=0x480 root_off=0x40"*) ;;
|
||||
*) fail "M3 marker values changed: $MARKER" ;;
|
||||
esac
|
||||
grep -q 'MMTM SP,' "$M3_WORK/asm/xhello.s" \
|
||||
|| fail "M3 xhello.s does not use MMTM"
|
||||
grep -q 'MMFM SP,' "$M3_WORK/asm/xhello.s" \
|
||||
|| fail "M3 xhello.s does not use MMFM"
|
||||
echo " $MARKER"
|
||||
echo " xhello.s: $(grep -m1 'MMTM' "$M3_WORK/asm/xhello.s" | sed 's/^[[:space:]]*//')"
|
||||
|
||||
echo "M5 MMTM: PASS"
|
||||
Executable
+469
@@ -0,0 +1,469 @@
|
||||
#!/bin/sh
|
||||
# M5 native-link gate: link an llc-produced TI-COFF object with a GSPA entry
|
||||
# object and run the linked image in MAME.
|
||||
#
|
||||
# 1. tms-clang -O0 -> IR, llc -filetype=obj -> NATIVE.O
|
||||
# 2. GSPA 2.00 assembles scripts/m5/native-entry.asm -> ENTRY.O
|
||||
# 3. GSPLNK 2.00 links NATIVE.O + ENTRY.O (scripts/m5/native-link.cmd)
|
||||
# 4. MAME + dwt/loader/loader.lua places the linked image and the check script
|
||||
# requires 018A8000 == 42, 018A8020 == 152 (42 + 'n'), 018A8040 == 1,
|
||||
# 018A8060 == 2, 018A8080 == 10 and 018A80A0 == 77. These prove the
|
||||
# .data MOVI, the .bss read/write, the branch loop and the resolved
|
||||
# undefined-external call. Both CALLAs in native_combo() are same-section
|
||||
# .text references; the cross-section proof is the .data/.bss MOVI.
|
||||
# 5. dis34 decodes _native_value at its linked bit address.
|
||||
#
|
||||
# The object itself is inspected for the GSPA/GSPLNK conventions: three
|
||||
# sections, section symbols with aux records, C_EXT globals, and R-RELLONG
|
||||
# relocations whose field holds a bit-address addend.
|
||||
#
|
||||
# scripts/tests/m5/native-link.sh
|
||||
#
|
||||
# Overridable: TMS_LLC M5_WORK M5_SDK SDK_IMG DOSBOX DOSBOX_CONF
|
||||
# MAME MAME_TIMEOUT DIS34 LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m5
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/scripts/tms-clang}
|
||||
|
||||
WORK=${M5_WORK:-$ROOT/build/m5-native-link}
|
||||
SDK=${M5_SDK:-$WORK/sdk}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
MAME_TIMEOUT=${MAME_TIMEOUT:-900}
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
|
||||
fail() {
|
||||
echo "M5 native-link: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -x "$TMS_CLANG" ] || fail "missing tms-clang: $TMS_CLANG"
|
||||
[ -f "$DOSBOX_CONF" ] || fail "missing DOSBox config: $DOSBOX_CONF"
|
||||
command -v "$DOSBOX" >/dev/null 2>&1 || fail "missing DOSBox: $DOSBOX"
|
||||
[ -x "$MAME" ] || fail "missing MAME binary: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing COFF loader: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing COFF loader payload: $LOADER_BIN"
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
|
||||
mkdir -p "$WORK" "$WORK/dos" "$WORK/run/nvram" "$WORK/run/cfg" "$WORK/evidence"
|
||||
|
||||
echo "== compile and encode"
|
||||
"$TMS_CLANG" -O0 -o "$WORK/native-link.ll" "$DIR/native-link.c" \
|
||||
|| fail "tms-clang failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=obj \
|
||||
"$WORK/native-link.ll" -o "$WORK/native-link.o" \
|
||||
|| fail "llc -filetype=obj failed"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$WORK/native-link.ll" -o "$WORK/native-link.s" \
|
||||
|| fail "llc -filetype=asm failed"
|
||||
grep -q 'MOVI _msg' "$WORK/native-link.s" \
|
||||
|| fail "assembly has no cross-section MOVI _msg"
|
||||
grep -q 'CALLA _native_value' "$WORK/native-link.s" \
|
||||
|| fail "assembly has no CALLA _native_value"
|
||||
|
||||
echo "== inspect the native TI-COFF object"
|
||||
python3 - "$WORK/native-link.o" "$WORK/native.text" <<'PY' || fail "native object is not GSPA/GSPLNK TI-COFF"
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, text_out = sys.argv[1], sys.argv[2]
|
||||
d = open(path, "rb").read()
|
||||
if len(d) < 20:
|
||||
sys.exit(f"{path}: too short for a TI-COFF header")
|
||||
machine, nscns, _time, symptr, nsyms, opthdr, flags = struct.unpack_from(
|
||||
"<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if opthdr != 0:
|
||||
sys.exit(f"{path}: optional-header size {opthdr}, want 0")
|
||||
if flags != 0x0100:
|
||||
sys.exit(f"{path}: file flags {flags:#06x}, want 0x0100")
|
||||
if nscns != 3:
|
||||
sys.exit(f"{path}: {nscns} sections, want 3 (.text/.data/.bss)")
|
||||
|
||||
want_flags = {".text": 0x20, ".data": 0x40, ".bss": 0x80}
|
||||
sections = []
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size, ptr = struct.unpack_from("<II", d, o + 16)
|
||||
relptr, = struct.unpack_from("<I", d, o + 24)
|
||||
nreloc, = struct.unpack_from("<H", d, o + 32)
|
||||
sflags, = struct.unpack_from("<I", d, o + 36)
|
||||
if name not in want_flags:
|
||||
sys.exit(f"{path}: unexpected section {name!r}")
|
||||
if sflags != want_flags[name]:
|
||||
sys.exit(f"{path}: {name} flags {sflags:#06x}, want {want_flags[name]:#06x}")
|
||||
sections.append(dict(index=i + 1, name=name, size=size, ptr=ptr,
|
||||
relptr=relptr, nreloc=nreloc, raw=b""))
|
||||
if name != ".bss":
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: {name} size {size} bits is not whole bytes")
|
||||
sections[-1]["raw"] = d[ptr:ptr + size // 8]
|
||||
if len(sections[-1]["raw"]) != size // 8:
|
||||
sys.exit(f"{path}: {name} raw data runs past EOF")
|
||||
|
||||
by_name = {s["name"]: s for s in sections}
|
||||
if by_name[".text"]["size"] == 0:
|
||||
sys.exit(f"{path}: .text is empty")
|
||||
if by_name[".data"]["size"] == 0:
|
||||
sys.exit(f"{path}: .data is empty")
|
||||
if by_name[".bss"]["size"] == 0:
|
||||
sys.exit(f"{path}: .bss is empty")
|
||||
|
||||
# Symbol records, including long names in the string table.
|
||||
string_base = symptr + nsyms * 18
|
||||
syms = {}
|
||||
sym_class = {}
|
||||
sym_section = {}
|
||||
sym_index = {}
|
||||
i = 0
|
||||
while i < nsyms:
|
||||
o = symptr + i * 18
|
||||
if o + 18 > len(d):
|
||||
sys.exit(f"{path}: symbol {i} past EOF")
|
||||
name = d[o:o + 8]
|
||||
if name[:4] == b"\0\0\0\0":
|
||||
off, = struct.unpack_from("<I", d, o + 4)
|
||||
end = d.find(b"\0", string_base + off)
|
||||
nm = d[string_base + off:end].decode("latin1")
|
||||
else:
|
||||
nm = name.rstrip(b"\0").decode("latin1")
|
||||
value, secno, _typ, cls, naux = struct.unpack_from("<IhHBB", d, o + 8)
|
||||
if cls in (2, 3):
|
||||
syms[nm] = value
|
||||
sym_class[nm] = cls
|
||||
sym_section[nm] = secno
|
||||
sym_index[nm] = i
|
||||
if cls == 3 and naux != 1:
|
||||
sys.exit(f"{path}: section symbol {nm!r} has {naux} aux records, want 1")
|
||||
i += 1 + naux
|
||||
|
||||
if sym_class.get(".text") != 3 or sym_section.get(".text") != 1:
|
||||
sys.exit(f"{path}: missing .text section symbol")
|
||||
if sym_class.get(".data") != 3 or sym_section.get(".data") != 2:
|
||||
sys.exit(f"{path}: missing .data section symbol")
|
||||
if sym_class.get(".bss") != 3 or sym_section.get(".bss") != 3:
|
||||
sys.exit(f"{path}: missing .bss section symbol")
|
||||
for nm, sec in (("_native_value", 1), ("_native_first", 1),
|
||||
("_native_bump", 1), ("_native_combo", 1), ("_native_loop", 1),
|
||||
("_native_call_external", 1), ("_msg", 2),
|
||||
("_native_counter", 3), ("_native_external", 0)):
|
||||
if nm not in syms:
|
||||
sys.exit(f"{path}: missing symbol {nm}")
|
||||
if sym_class[nm] != 2:
|
||||
sys.exit(f"{path}: {nm} class {sym_class[nm]}, want 2 (C_EXT)")
|
||||
if sym_section[nm] != sec:
|
||||
sys.exit(f"{path}: {nm} section {sym_section[nm]}, want {sec}")
|
||||
if syms["_native_value"] != 0:
|
||||
sys.exit(f"{path}: _native_value value {syms['_native_value']}, want 0")
|
||||
if syms["_native_external"] != 0:
|
||||
sys.exit(f"{path}: _native_external value {syms['_native_external']}, want 0")
|
||||
|
||||
# Relocations are 10-byte {bit address, symbol index, type 0x11} records.
|
||||
def relocs(sec):
|
||||
out = []
|
||||
for r in range(sec["nreloc"]):
|
||||
o = sec["relptr"] + r * 10
|
||||
raddr, symidx, rtype = struct.unpack_from("<IIH", d, o)
|
||||
out.append((raddr, symidx, rtype))
|
||||
return out
|
||||
|
||||
text_relocs = relocs(by_name[".text"])
|
||||
data_relocs = relocs(by_name[".data"])
|
||||
if not text_relocs:
|
||||
sys.exit(f"{path}: .text has no relocations")
|
||||
if not data_relocs:
|
||||
sys.exit(f"{path}: .data has no relocations")
|
||||
for raddr, _symidx, rtype in text_relocs + data_relocs:
|
||||
if rtype != 0x11:
|
||||
sys.exit(f"{path}: relocation type {rtype:#06x}, want 0x11 R-RELLONG")
|
||||
if raddr % 8:
|
||||
sys.exit(f"{path}: relocation address {raddr:#x} is not byte-aligned")
|
||||
|
||||
# The cross-section MOVI _msg must use the .data section symbol (record index
|
||||
# 2: .text, .text-aux, .data) and its field must hold _msg's bit offset.
|
||||
data_sym = 2
|
||||
found_data_ref = False
|
||||
for raddr, symidx, _rtype in text_relocs:
|
||||
if symidx == data_sym:
|
||||
field, = struct.unpack_from("<I", by_name[".text"]["raw"], raddr // 8)
|
||||
if field == syms["_msg"]:
|
||||
found_data_ref = True
|
||||
if not found_data_ref:
|
||||
sys.exit(f"{path}: no cross-section .text relocation to _msg")
|
||||
|
||||
# The .bss read/write in native_bump() is a .text -> .bss reference. The .bss
|
||||
# section symbol is record index 4 (.text + aux, .data + aux, .bss).
|
||||
bss_sym = 4
|
||||
bss_addend = 32 # native_counter[1] is 4 bytes into the 8-byte array
|
||||
found_bss_ref = False
|
||||
for raddr, symidx, _rtype in text_relocs:
|
||||
if symidx == bss_sym:
|
||||
field, = struct.unpack_from("<I", by_name[".text"]["raw"], raddr // 8)
|
||||
if field == syms["_native_counter"] + bss_addend:
|
||||
found_bss_ref = True
|
||||
if not found_bss_ref:
|
||||
sys.exit(f"{path}: no cross-section .text relocation to "
|
||||
f"_native_counter+{bss_addend}")
|
||||
|
||||
# A branch reference is a same-section 0xFFFF relocation whose instruction
|
||||
# opcode is JAUC (0xC080) or JAcc (0xC?80). In-range branches are relaxed to
|
||||
# the one-word JR form and need no relocation, so native_far() supplies the
|
||||
# conditional JAcc relocation and the zero-displacement branch supplies the
|
||||
# unconditional one. Requiring both keeps a broken branch heuristic red.
|
||||
text_raw = by_name[".text"]["raw"]
|
||||
def opcode_before(raddr):
|
||||
return struct.unpack_from("<H", text_raw, raddr // 8 - 2)[0]
|
||||
|
||||
branch_relocs = []
|
||||
for raddr, symidx, _rtype in text_relocs:
|
||||
if symidx != 0xFFFF:
|
||||
continue
|
||||
word = opcode_before(raddr)
|
||||
if (word & 0xF0FF) == 0xC080:
|
||||
branch_relocs.append(word)
|
||||
if not branch_relocs:
|
||||
sys.exit(f"{path}: no same-section branch relocation (JAUC/JAcc)")
|
||||
if not any(word != 0xC080 for word in branch_relocs):
|
||||
sys.exit(f"{path}: branch relocations have no conditional JAcc")
|
||||
|
||||
# The undefined native_external must be a section-0 C_EXT and its relocation
|
||||
# must use that symbol-table record, not the 0xFFFF same-section escape.
|
||||
ext_idx = sym_index["_native_external"]
|
||||
if not any(symidx == ext_idx for _raddr, symidx, _rtype in text_relocs):
|
||||
sys.exit(f"{path}: no .text relocation to the undefined _native_external")
|
||||
|
||||
# The .long __str pointer in .data is a same-section reference: symbol index
|
||||
# 0xFFFF with the target's section-relative bit offset in the field.
|
||||
if not any(symidx == 0xFFFF for _raddr, symidx, _rtype in data_relocs):
|
||||
sys.exit(f"{path}: .data has no same-section R-RELLONG (symbol 0xFFFF)")
|
||||
if not any(symidx == 0xFFFF for _raddr, symidx, _rtype in text_relocs):
|
||||
sys.exit(f"{path}: .text has no same-section R-RELLONG (symbol 0xFFFF)")
|
||||
|
||||
# A .bss section record must never carry a relocation; the writer rejects one.
|
||||
if by_name[".bss"]["nreloc"] != 0:
|
||||
sys.exit(f"{path}: .bss has {by_name['.bss']['nreloc']} relocations")
|
||||
|
||||
open(text_out, "wb").write(text_raw)
|
||||
print(f" object: sections=3 symbols={len(syms)} "
|
||||
f"text-relocs={len(text_relocs)} data-relocs={len(data_relocs)} "
|
||||
f"branch-relocs={len(branch_relocs)}")
|
||||
print(f" _native_value={syms['_native_value']} _msg={syms['_msg']} "
|
||||
f"_native_counter+{bss_addend}={syms['_native_counter'] + bss_addend} "
|
||||
f"(.data/.bss bits)")
|
||||
PY
|
||||
|
||||
echo "== extract the GSPA/GSPLNK toolchain"
|
||||
if [ ! -f "$SDK/GSPA.EXE" ] || [ ! -f "$SDK/GSPLNK.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "SDK image not found: $SDK_IMG"
|
||||
mkdir -p "$SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE is not extracted in $SDK"
|
||||
[ -f "$SDK/GSPLNK.EXE" ] || fail "GSPLNK.EXE is not extracted in $SDK"
|
||||
|
||||
DOS_DIR=$WORK/dos
|
||||
rm -rf "$DOS_DIR"
|
||||
mkdir -p "$DOS_DIR"
|
||||
cp "$SDK/GSPA.EXE" "$SDK/GSPLNK.EXE" "$DOS_DIR/"
|
||||
cp "$WORK/native-link.o" "$DOS_DIR/NATIVE.O"
|
||||
sed 's/\r$//' "$DIR/native-entry.asm" | sed 's/$/\r/' > "$DOS_DIR/ENTRY.ASM"
|
||||
sed 's/\r$//' "$DIR/native-link.cmd" | sed 's/$/\r/' > "$DOS_DIR/NATIVE.CMD"
|
||||
|
||||
echo "== assemble ENTRY.ASM and link with GSPLNK 2.00"
|
||||
rm -f "$DOS_DIR/ENTRY.O" "$DOS_DIR/ENTRY.LST" \
|
||||
"$DOS_DIR/NATIVE.OUT" "$DOS_DIR/NATIVE.MAP"
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $DOS_DIR" -c "c:" \
|
||||
-c "gspa ENTRY ENTRY.O ENTRY.LST -l" \
|
||||
-c "gsplnk NATIVE.CMD" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
|
||||
[ -f "$DOS_DIR/ENTRY.LST" ] || fail "GSPA produced no ENTRY.LST"
|
||||
sed 's/\r$//' "$DOS_DIR/ENTRY.LST" > "$WORK/entry.lst"
|
||||
grep -q 'No Errors' "$WORK/entry.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/entry.lst" >&2 || true; fail "GSPA reported errors"; }
|
||||
grep -q 'No Warnings' "$WORK/entry.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$WORK/entry.lst" >&2 || true; fail "GSPA reported warnings"; }
|
||||
[ -f "$DOS_DIR/NATIVE.OUT" ] \
|
||||
|| { tail -30 "$WORK/dosbox.log" >&2; fail "GSPLNK produced no NATIVE.OUT"; }
|
||||
[ -f "$DOS_DIR/NATIVE.MAP" ] || fail "GSPLNK produced no NATIVE.MAP"
|
||||
cp "$DOS_DIR/NATIVE.OUT" "$WORK/native-link.coff"
|
||||
sed 's/\r$//' "$DOS_DIR/NATIVE.MAP" > "$WORK/native-link.map"
|
||||
|
||||
# The linker map has two symbol columns, so accept either position.
|
||||
map_addr() {
|
||||
awk -v want="$1" '
|
||||
{ for (i = 1; i <= NF; i++) if ($i == want) { print $(i - 1); exit } }
|
||||
' "$WORK/native-link.map"
|
||||
}
|
||||
VALUE_ADDR=$(map_addr _native_value)
|
||||
FIRST_ADDR=$(map_addr _native_first)
|
||||
MSG_ADDR=$(map_addr _msg)
|
||||
COUNTER_ADDR=$(map_addr _native_counter)
|
||||
LOOP_ADDR=$(map_addr _native_loop)
|
||||
EXT_ADDR=$(map_addr _native_external)
|
||||
[ -n "$VALUE_ADDR" ] || fail "linker map has no _native_value"
|
||||
[ -n "$FIRST_ADDR" ] || fail "linker map has no _native_first"
|
||||
[ -n "$MSG_ADDR" ] || fail "linker map has no _msg"
|
||||
[ -n "$COUNTER_ADDR" ] || fail "linker map has no _native_counter"
|
||||
[ -n "$LOOP_ADDR" ] || fail "linker map has no _native_loop"
|
||||
[ -n "$EXT_ADDR" ] || fail "linker map has no _native_external"
|
||||
grep -q 'ENTRY POINT SYMBOL: "_native_entry"' "$WORK/native-link.map" \
|
||||
|| fail "linker map has no _native_entry entry point"
|
||||
echo " linked _native_value=$VALUE_ADDR _native_first=$FIRST_ADDR _msg=$MSG_ADDR _native_counter=$COUNTER_ADDR _native_loop=$LOOP_ADDR _native_external=$EXT_ADDR"
|
||||
|
||||
# The linked image must be fully relocated: GSPLNK with -a writes no relocs.
|
||||
python3 - "$WORK/native-link.coff" <<'PY' || fail "linked COFF has relocations"
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path = sys.argv[1]
|
||||
d = open(path, "rb").read()
|
||||
machine, nscns, _time, _symptr, _nsyms, opthdr, flags = struct.unpack_from(
|
||||
"<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if not (flags & 0x0001):
|
||||
sys.exit(f"{path}: linked image is not executable (flags {flags:#06x})")
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
nreloc, = struct.unpack_from("<H", d, o + 32)
|
||||
if nreloc:
|
||||
sys.exit(f"{path}: linked {name} still has {nreloc} relocations")
|
||||
PY
|
||||
|
||||
# Re-extract the linked .text (the object extract above is the unlinked one).
|
||||
# Its linked base is the dis34 base; _native_value is checked by address.
|
||||
TEXT_ADDR=$(python3 - "$WORK/native-link.coff" "$WORK/native-linked.text" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
d = open(path, "rb").read()
|
||||
_nscns, = struct.unpack_from("<H", d, 2)
|
||||
_opthdr, = struct.unpack_from("<H", d, 16)
|
||||
base = 20 + _opthdr
|
||||
for i in range(_nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
if name == ".text":
|
||||
paddr, _vaddr, size, ptr = struct.unpack_from("<IIII", d, o + 8)
|
||||
open(out, "wb").write(d[ptr:ptr + size // 8])
|
||||
print(f"{paddr:08X}")
|
||||
break
|
||||
else:
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
) || fail "could not extract linked .text"
|
||||
|
||||
echo "== disassemble _native_value with dis34"
|
||||
"$DIS34" -b "$TEXT_ADDR" -l -o "$WORK/native-linked.text" \
|
||||
> "$WORK/dis34.txt" 2> "$WORK/dis34.err" \
|
||||
|| { cat "$WORK/dis34.err" >&2; fail "dis34 failed"; }
|
||||
[ -s "$WORK/dis34.txt" ] || fail "dis34 produced no output"
|
||||
python3 - "$WORK/dis34.txt" "$VALUE_ADDR" "$FIRST_ADDR" <<'PY' \
|
||||
|| fail "dis34 did not decode _native_value"
|
||||
import re
|
||||
import sys
|
||||
|
||||
path, value_addr, first_addr = sys.argv[1], int(sys.argv[2], 16), int(
|
||||
sys.argv[3], 16)
|
||||
rows = []
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = re.match(r"^([0-9a-fA-F]+):\s+(.*)$", line.strip())
|
||||
if m:
|
||||
rows.append((int(m.group(1), 16), m.group(2)))
|
||||
if not any(addr == value_addr and text.lower().startswith("setf")
|
||||
for addr, text in rows):
|
||||
sys.exit(f"dis34 has no SETF at _native_value {value_addr:#x}")
|
||||
if not any(value_addr <= addr < first_addr and
|
||||
re.match(r"movi\s+0x2a,\s*a0(\s*;.*)?$", text, re.I)
|
||||
for addr, text in rows):
|
||||
sys.exit(f"dis34 has no MOVI 42 in _native_value "
|
||||
f"[{value_addr:#x}, {first_addr:#x})")
|
||||
print(f" dis34 decoded _native_value at {value_addr:08x} .. {first_addr:08x}")
|
||||
PY
|
||||
|
||||
echo "== run the linked COFF in MAME"
|
||||
cat > "$WORK/native-check.lua" <<'LUA'
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local frames = 0
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == ENDF - 1 then
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local value = prog:read_u32(0x018A8000)
|
||||
local combo = prog:read_u32(0x018A8020)
|
||||
local bump1 = prog:read_u32(0x018A8040)
|
||||
local bump2 = prog:read_u32(0x018A8060)
|
||||
local loop = prog:read_u32(0x018A8080)
|
||||
local ext = prog:read_u32(0x018A80A0)
|
||||
print(string.format(
|
||||
"NATIVE: value=%d combo=%d bump1=%d bump2=%d loop=%d ext=%d",
|
||||
value, combo, bump1, bump2, loop, ext))
|
||||
if value == 42 and combo == 152 and bump1 == 1 and bump2 == 2 and
|
||||
loop == 10 and ext == 77 then
|
||||
print("NATIVE MAME: PASS")
|
||||
else
|
||||
print("NATIVE MAME: FAIL (want value=42 combo=152 " ..
|
||||
"bump1=1 bump2=2 loop=10 ext=77)")
|
||||
end
|
||||
end
|
||||
end, "native-check")
|
||||
LUA
|
||||
|
||||
rm -rf "$WORK/run/nvram"
|
||||
mkdir -p "$WORK/run/nvram"
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$WORK/native-link.coff" \
|
||||
LOADER_OUT="$WORK/evidence" \
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
timeout "$MAME_TIMEOUT" "$MAME" vt1200 \
|
||||
-rompath "$ROOT/vendor/vt1200/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-nvram_directory "$WORK/run/nvram" \
|
||||
-cfg_directory "$WORK/run/cfg" \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$WORK/native-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; fail "COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -q 'placed \.data .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .data bytes"
|
||||
grep -q '^NATIVE: value=42 combo=152 bump1=1 bump2=2 loop=10 ext=77$' \
|
||||
"$WORK/mame.log" \
|
||||
|| { grep '^NATIVE:' "$WORK/mame.log" >&2 || true; fail "markers are wrong"; }
|
||||
grep -q '^NATIVE MAME: PASS$' "$WORK/mame.log" \
|
||||
|| fail "MAME marker check failed"
|
||||
|
||||
echo "M5 native-link: PASS"
|
||||
Executable
+212
@@ -0,0 +1,212 @@
|
||||
#!/bin/sh
|
||||
# M5 native-pipeline gate: build the real M4 clients through the native TI-COFF
|
||||
# path and require the same markers as the GSPA-assembled (oracle) path.
|
||||
#
|
||||
# scripts/tests/m5/native.sh
|
||||
#
|
||||
# 1. xshow + xgfix: tms-clang -> llc -filetype=obj -> GSPLNK -> loader/MAME.
|
||||
# The M4 image/event gate markers must still hold: the checker pixels, the
|
||||
# injected `Q` (keycode 193 / keysym 0x71), the client window focus, and
|
||||
# xerrors=0.
|
||||
# 2. termtris (six TUs): the same native build feeds the existing M4 termtris
|
||||
# gate (scripts/tests/m4/termtris.sh) through TERMTRIS_BUILD, so the
|
||||
# board/move/panels/quit thresholds, focus, loader status and snapshots are
|
||||
# enforced by the unchanged gate.
|
||||
# 3. dis34 comparison: build the asm/GSPA oracle of xshow and termtris into
|
||||
# private work directories, extract both linked .text sections, and compare
|
||||
# the decoded instruction streams. Layouts are allowed to differ; a raw
|
||||
# byte compare is not used.
|
||||
#
|
||||
# Overridable: M5_NATIVE_WORK MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m5
|
||||
WORK=${M5_NATIVE_WORK:-$ROOT/build/m5-native}
|
||||
XWORK=$WORK/xshow-native
|
||||
AWORK=$WORK/xshow-asm
|
||||
TWORK=$WORK/termtris-native
|
||||
DIS34=${DIS34:-$ROOT/vendor/vt1200/tools/smart34010/dis34}
|
||||
|
||||
fail() {
|
||||
echo "M5 native: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$DIS34" ] || fail "missing dis34: $DIS34"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
echo "== xshow + xgfix through the native object path"
|
||||
M5_XSHOW_WORK=$XWORK "$ROOT/scripts/m5/native.sh" xshow \
|
||||
|| fail "native xshow build/run failed"
|
||||
|
||||
XLOG=$XWORK/mame.log
|
||||
[ -f "$XLOG" ] || fail "no native xshow MAME log: $XLOG"
|
||||
[ -f "$XWORK/asm/xshow.o" ] || fail "xshow.c was not compiled to an object"
|
||||
[ -f "$XWORK/asm/xgfix.o" ] || fail "xgfix.c was not compiled to an object"
|
||||
[ -f "$XWORK/m4.coff" ] || fail "no native linked image"
|
||||
|
||||
MARKER=$(grep -aE '^M4: display=' "$XLOG" | tail -1 || true)
|
||||
[ -n "$MARKER" ] || fail "no native xshow marker line"
|
||||
echo " $MARKER"
|
||||
case "$MARKER" in
|
||||
*" quit=1 events="*) ;;
|
||||
*) fail "native xshow quit marker is not 1" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" keycode=193 keysym=0x71 "*) ;;
|
||||
*) fail "native xshow: the injected Q did not produce keycode 193 / 0x71" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" xerrors=0 "*) ;;
|
||||
*) fail "native xshow xerrors is not 0" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" focus=0x400001 "*) ;;
|
||||
*) fail "native xshow input focus is not the client window 0x400001" ;;
|
||||
esac
|
||||
case "$MARKER" in
|
||||
*" last=2"*) ;;
|
||||
*) fail "native xshow: the last X event is not KeyPress (last=2)" ;;
|
||||
esac
|
||||
|
||||
grep -Fq 'M4: pixel screen(50,50) image(18,30) cell(0,0) bit=0x04019032 value=0 black' "$XLOG" \
|
||||
|| fail "native xshow: (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' "$XLOG" \
|
||||
|| fail "native xshow: (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' "$XLOG" \
|
||||
|| fail "native xshow: later-band checker cell is wrong"
|
||||
grep -Eq '^M4: pixel screen\(25,30\) image\(-7,10\) cell\(-1,0\) bit=0x[0-9A-F]+ value=1 white$' "$XLOG" \
|
||||
|| fail "native xshow: left prefix in band 0 is wrong"
|
||||
grep -Eq '^M4: pixel screen\(25,62\) image\(-7,42\) cell\(-1,1\) bit=0x[0-9A-F]+ value=0 black$' "$XLOG" \
|
||||
|| fail "native xshow: left prefix in band 1 is wrong"
|
||||
grep -q '^M4 MAME: PASS' "$XLOG" || fail "native xshow marker check did not pass"
|
||||
grep -q 'LOADER: result status=0 (OK)' "$XLOG" \
|
||||
|| fail "native xshow loader status is not OK"
|
||||
grep -q 'placed \.text .* 0 differing' "$XLOG" \
|
||||
|| fail "native xshow loader did not verify the placed .text bytes"
|
||||
|
||||
echo "== termtris (six TUs) through the native object path and the M4 gate"
|
||||
TERMTRIS_BUILD="$ROOT/scripts/m5/native.sh" \
|
||||
TERMTRIS_WORK="$TWORK" \
|
||||
"$ROOT/scripts/tests/m4/termtris.sh" \
|
||||
|| fail "native termtris gate failed"
|
||||
[ -f "$TWORK/asm/main.o" ] || fail "main.c was not compiled to an object"
|
||||
[ -f "$TWORK/asm/game.o" ] || fail "game.c was not compiled to an object"
|
||||
|
||||
echo "== dis34: compare the native and asm linked xshow .text"
|
||||
# Build the GSPA oracle into its own directory. M4_SKIP_MAME keeps this a
|
||||
# build/link comparison; the asm MAME gate is scripts/tests/m4/run.sh.
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_SOURCES="xshow xgfix" \
|
||||
M4_ENTRY="$ROOT/scripts/m4/xshow-entry.asm" \
|
||||
M4_CLANG_OPT=-O2 \
|
||||
M4_ROM_SYMBOLS=1 \
|
||||
LOADER_AT=2500 \
|
||||
LOADER_END=3400 \
|
||||
M4_WORK="$AWORK" \
|
||||
"$ROOT/scripts/m4/run.sh" > "$WORK/xshow-asm.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/xshow-asm.log" >&2; fail "asm xshow oracle build failed"; }
|
||||
|
||||
extract_text() {
|
||||
python3 - "$1" "$2" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out = sys.argv[1], sys.argv[2]
|
||||
d = open(path, "rb").read()
|
||||
nscns, = struct.unpack_from("<H", d, 2)
|
||||
opthdr, = struct.unpack_from("<H", d, 16)
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
if name != ".text":
|
||||
continue
|
||||
paddr, _vaddr, size, ptr = struct.unpack_from("<IIII", d, o + 8)
|
||||
open(out, "wb").write(d[ptr:ptr + size // 8])
|
||||
print(f"{paddr:08X}")
|
||||
break
|
||||
else:
|
||||
sys.exit(f"{path}: no .text section")
|
||||
PY
|
||||
}
|
||||
|
||||
# Compare decoded instruction text, not raw bytes: the native driver assembles
|
||||
# the entry/extras as separate objects, and layouts are allowed to differ.
|
||||
compare_text() {
|
||||
label=$1
|
||||
native_coff=$2
|
||||
asm_coff=$3
|
||||
stem=$4
|
||||
NATIVE_ADDR=$(extract_text "$native_coff" "$WORK/$stem-native.text") \
|
||||
|| fail "could not extract the native $label .text"
|
||||
ASM_ADDR=$(extract_text "$asm_coff" "$WORK/$stem-asm.text") \
|
||||
|| fail "could not extract the asm $label .text"
|
||||
[ "$NATIVE_ADDR" = "$ASM_ADDR" ] \
|
||||
|| fail "$label native .text base $NATIVE_ADDR != asm $ASM_ADDR"
|
||||
|
||||
"$DIS34" -b "$NATIVE_ADDR" -l -o "$WORK/$stem-native.text" \
|
||||
> "$WORK/$stem-native.dis" 2>&1 \
|
||||
|| { cat "$WORK/$stem-native.dis" >&2; fail "dis34 failed for native $label"; }
|
||||
"$DIS34" -b "$ASM_ADDR" -l -o "$WORK/$stem-asm.text" \
|
||||
> "$WORK/$stem-asm.dis" 2>&1 \
|
||||
|| { cat "$WORK/$stem-asm.dis" >&2; fail "dis34 failed for asm $label"; }
|
||||
|
||||
python3 - "$WORK/$stem-native.dis" "$WORK/$stem-asm.dis" "$NATIVE_ADDR" "$label" <<'PY' \
|
||||
|| fail "$label native and asm decoded instruction streams differ"
|
||||
import re
|
||||
import sys
|
||||
|
||||
native_path, asm_path, base, label = (
|
||||
sys.argv[1], sys.argv[2], int(sys.argv[3], 16), sys.argv[4])
|
||||
|
||||
|
||||
def decode(path):
|
||||
"""[(bit address, instruction text without the raw-bytes comment)]."""
|
||||
rows = []
|
||||
for line in open(path, encoding="latin1"):
|
||||
m = re.match(r"^([0-9a-fA-F]+):\s+(.*)$", line.strip())
|
||||
if not m:
|
||||
continue
|
||||
text = re.sub(r"\s*;.*$", "", m.group(2)).strip()
|
||||
rows.append((int(m.group(1), 16), text))
|
||||
return rows
|
||||
|
||||
|
||||
native = decode(native_path)
|
||||
asm = decode(asm_path)
|
||||
if not native:
|
||||
sys.exit("native disassembly is empty")
|
||||
if not asm:
|
||||
sys.exit("asm disassembly is empty")
|
||||
|
||||
# Compare the decoded instruction streams (mnemonic and operands). The
|
||||
# native driver assembles the entry/extras as separate objects in the same
|
||||
# order as the asm path, so the layouts match today; this comparison does not
|
||||
# require that or use raw byte equality.
|
||||
text = [text for _addr, text in native]
|
||||
asm_text = [text for _addr, text in asm]
|
||||
if len(text) != len(asm_text):
|
||||
sys.exit(f"decoded instruction count differs: {len(text)} != {len(asm_text)}")
|
||||
for i, (a, b) in enumerate(zip(text, asm_text)):
|
||||
if a != b:
|
||||
sys.exit(f"decoded instruction {i} differs:\n native: {a}\n asm: {b}")
|
||||
print(f" dis34 {label}: {len(text)} decoded instructions match "
|
||||
f"(base 0x{base:08x})")
|
||||
PY
|
||||
}
|
||||
|
||||
compare_text xshow "$XWORK/m4.coff" "$AWORK/m4.coff" xshow
|
||||
|
||||
echo "== dis34: compare the native and asm linked termtris .text"
|
||||
# scripts/m4/termtris/build.sh is the asm oracle builder; it takes
|
||||
# TERMTRIS_WORK/TERMTRIS_SDK and stops after the GSPLNK link.
|
||||
ATWORK=$WORK/termtris-asm
|
||||
TERMTRIS_WORK="$ATWORK" \
|
||||
TERMTRIS_SDK="$ATWORK/sdk" \
|
||||
"$ROOT/scripts/m4/termtris/build.sh" > "$WORK/termtris-asm.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/termtris-asm.log" >&2; fail "asm termtris oracle build failed"; }
|
||||
compare_text termtris "$TWORK/termtris.coff" "$ATWORK/termtris.coff" termtris
|
||||
|
||||
echo "M5 native: PASS (xshow markers + termtris gate + dis34 instruction streams)"
|
||||
Executable
+256
@@ -0,0 +1,256 @@
|
||||
#!/bin/sh
|
||||
# M5 native-object smoke gate.
|
||||
#
|
||||
# Proves that `llc -march=tms34010 -filetype=obj` emits a TI-COFF object whose
|
||||
# `.text` section is byte-for-byte identical to the GSPA-assembled `.text` of
|
||||
# the same functions. The GSPA/GSPLNK 2.00 toolchain under DOSBox is the format
|
||||
# and encoding oracle; this script never derives the expected bytes from the
|
||||
# LLVM encoder itself.
|
||||
#
|
||||
# The IR covers the ADDI/frame path, the short (16-bit) MOVI immediate form and
|
||||
# the long (32-bit) MOVI immediate form. The object also carries the three
|
||||
# TI-COFF section symbols; symbol operands and relocations are covered by the
|
||||
# native-link gate (scripts/tests/m5/native-link.sh).
|
||||
#
|
||||
# scripts/tests/m5/object-smoke.sh
|
||||
#
|
||||
# Overridable: TMS_LLC LLVM_BIN M5_WORK M5_SDK SDK_IMG DOSBOX DOSBOX_CONF
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
M5_WORK=${M5_WORK:-$ROOT/build/m5-smoke}
|
||||
M5_SDK=${M5_SDK:-$ROOT/build/m4-sdk}
|
||||
SDK_IMG=${SDK_IMG:-$ROOT/vendor/vt1200/tools/tms34010-sdk/1987-05 TMS34010 SDK/1987-11-06 TMS34010 Simulator-C Tools-ASM Tools.img}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
DOSBOX_CONF=${DOSBOX_CONF:-$ROOT/vendor/vt1200/harness/sdk-scratch/dosbox-bench.conf}
|
||||
|
||||
fail() {
|
||||
echo "M5 object smoke: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$TMS_LLC" ] || fail "missing llc: $TMS_LLC"
|
||||
[ -f "$DOSBOX_CONF" ] || fail "missing DOSBox config: $DOSBOX_CONF"
|
||||
command -v "$DOSBOX" >/dev/null 2>&1 || fail "missing DOSBox: $DOSBOX"
|
||||
|
||||
mkdir -p "$M5_WORK"
|
||||
|
||||
cat > "$M5_WORK/m5-smoke.ll" <<'EOF'
|
||||
define i32 @f(i32 %a) {
|
||||
%r = add i32 %a, 1
|
||||
ret i32 %r
|
||||
}
|
||||
; Long (32-bit) MOVI immediate form.
|
||||
define i32 @movi_long() {
|
||||
ret i32 305419896
|
||||
}
|
||||
; Short (16-bit) MOVI immediate form.
|
||||
define i32 @movi_short() {
|
||||
ret i32 42
|
||||
}
|
||||
; Long (32-bit) CMPI immediate form (the one's complement must be written).
|
||||
define i32 @cmpi_long(i32 %a) {
|
||||
%c = icmp eq i32 %a, 100000
|
||||
%r = select i1 %c, i32 1, i32 0
|
||||
ret i32 %r
|
||||
}
|
||||
; Long ANDI immediate form (also one's-complemented).
|
||||
define i32 @andi_long(i32 %a) {
|
||||
%r = and i32 %a, 100000
|
||||
ret i32 %r
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "== encode the smoke functions with llc -filetype=obj"
|
||||
rm -f "$M5_WORK/m5-smoke.o" "$M5_WORK/m5-smoke.s"
|
||||
"$TMS_LLC" -march=tms34010 -filetype=obj "$M5_WORK/m5-smoke.ll" \
|
||||
-o "$M5_WORK/m5-smoke.o" || fail "llc -filetype=obj exited nonzero"
|
||||
[ -s "$M5_WORK/m5-smoke.o" ] || fail "llc produced an empty object"
|
||||
"$TMS_LLC" -march=tms34010 -filetype=asm "$M5_WORK/m5-smoke.ll" \
|
||||
-o "$M5_WORK/m5-smoke.s" || fail "llc -filetype=asm exited nonzero"
|
||||
grep -q 'RETS 2' "$M5_WORK/m5-smoke.s" || fail "assembly has no RETS 2"
|
||||
grep -q 'MOVI 305419896' "$M5_WORK/m5-smoke.s" \
|
||||
|| fail "assembly has no long-form MOVI 305419896"
|
||||
grep -q 'MOVI 42' "$M5_WORK/m5-smoke.s" \
|
||||
|| fail "assembly has no short-form MOVI 42"
|
||||
grep -q 'CMPI 100000' "$M5_WORK/m5-smoke.s" \
|
||||
|| fail "assembly has no long-form CMPI 100000"
|
||||
grep -q 'ANDI 100000' "$M5_WORK/m5-smoke.s" \
|
||||
|| fail "assembly has no long-form ANDI 100000"
|
||||
|
||||
# Extract the 1987 SDK the same way scripts/m4/run.sh does, but assemble into
|
||||
# a private DOS directory so this gate cannot race the M4 runner.
|
||||
if [ ! -f "$M5_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 "$M5_SDK"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/A2/*" "$M5_SDK/"
|
||||
mcopy -s -n -i "$SDK_IMG" "::/C2/*" "$M5_SDK/"
|
||||
fi
|
||||
[ -f "$M5_SDK/GSPA.EXE" ] || fail "GSPA.EXE is not extracted in $M5_SDK"
|
||||
|
||||
GSPA_DIR=$M5_WORK/gspa
|
||||
rm -rf "$GSPA_DIR"
|
||||
mkdir -p "$GSPA_DIR"
|
||||
cp "$M5_SDK/GSPA.EXE" "$GSPA_DIR/GSPA.EXE"
|
||||
sed 's/\r$//' "$M5_WORK/m5-smoke.s" | sed 's/$/\r/' > "$GSPA_DIR/M5.ASM"
|
||||
|
||||
echo "== assemble the same functions with GSPA 2.00"
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $GSPA_DIR" -c "c:" \
|
||||
-c "gspa M5 M5.obj M5.lst -l" \
|
||||
-c "exit" -exit > "$M5_WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$M5_WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
|
||||
[ -f "$GSPA_DIR/M5.OBJ" ] || fail "GSPA produced no object (see $M5_WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$GSPA_DIR/M5.LST" > "$M5_WORK/m5-gspa.lst"
|
||||
grep -q 'No Errors' "$M5_WORK/m5-gspa.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$M5_WORK/m5-gspa.lst" >&2 || true; fail "GSPA reported errors"; }
|
||||
grep -q 'No Warnings' "$M5_WORK/m5-gspa.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$M5_WORK/m5-gspa.lst" >&2 || true; fail "GSPA reported warnings"; }
|
||||
|
||||
# TI-COFF parser: both the GSPA object and the LLVM object use the same
|
||||
# 20-byte file header and 40-byte section headers. The section size is in
|
||||
# bits; the raw data pointer is a byte file offset. The `native` mode also
|
||||
# asserts the minimal writer's header flags and one-symbol-per-function table.
|
||||
parse_coff() {
|
||||
if ! python3 - "$1" "$2" "$3" <<'PY'
|
||||
import struct
|
||||
import sys
|
||||
|
||||
path, out, mode = sys.argv[1], sys.argv[2], sys.argv[3]
|
||||
with open(path, "rb") as f:
|
||||
d = f.read()
|
||||
if len(d) < 20:
|
||||
sys.exit(f"{path}: too short for a TI-COFF header")
|
||||
|
||||
machine, nscns, _time, symptr, nsyms, opthdr, flags = struct.unpack_from("<HHIIIHH", d, 0)
|
||||
if machine != 0x0090:
|
||||
sys.exit(f"{path}: machine {machine:#06x}, want 0x0090")
|
||||
if opthdr != 0:
|
||||
sys.exit(f"{path}: optional-header size {opthdr}, want 0")
|
||||
if flags != 0x0100:
|
||||
sys.exit(f"{path}: file flags {flags:#06x}, want 0x0100 (F_AR32WR)")
|
||||
if nscns < 1:
|
||||
sys.exit(f"{path}: no sections")
|
||||
if mode == "native" and nscns != 3:
|
||||
sys.exit(f"{path}: {nscns} sections, want 3 (.text/.data/.bss)")
|
||||
|
||||
want_flags = {".text": 0x20, ".data": 0x40, ".bss": 0x80}
|
||||
base = 20 + opthdr
|
||||
text = None
|
||||
for i in range(nscns):
|
||||
o = base + i * 40
|
||||
name = d[o:o + 8].split(b"\0", 1)[0].decode("latin1")
|
||||
size = struct.unpack_from("<I", d, o + 16)[0]
|
||||
ptr = struct.unpack_from("<I", d, o + 20)[0]
|
||||
sflags = struct.unpack_from("<I", d, o + 36)[0]
|
||||
if mode == "native":
|
||||
if name not in want_flags:
|
||||
sys.exit(f"{path}: unexpected section {name!r}")
|
||||
if sflags != want_flags[name]:
|
||||
sys.exit(f"{path}: {name} flags {sflags:#06x}, "
|
||||
f"want {want_flags[name]:#06x}")
|
||||
if name == ".text":
|
||||
if size == 0:
|
||||
sys.exit(f"{path}: .text is empty")
|
||||
if size % 8:
|
||||
sys.exit(f"{path}: .text size {size} bits is not whole bytes")
|
||||
nbytes = size // 8
|
||||
if ptr + nbytes > len(d):
|
||||
sys.exit(f"{path}: .text raw data runs past EOF")
|
||||
text = d[ptr:ptr + nbytes]
|
||||
|
||||
if text is None:
|
||||
sys.exit(f"{path}: no .text section")
|
||||
|
||||
if mode == "native":
|
||||
# Three section symbols (each with one aux record) and five C_EXT
|
||||
# function symbols: nsyms counts aux records too.
|
||||
if nsyms != 11:
|
||||
sys.exit(f"{path}: {nsyms} symbol entries, want 11 "
|
||||
f"(3 section symbols + aux, 5 functions)")
|
||||
symtab = {}
|
||||
sectab = {}
|
||||
i = 0
|
||||
while i < nsyms:
|
||||
o = symptr + i * 18
|
||||
name = d[o:o + 8]
|
||||
if name[:4] == b"\0\0\0\0":
|
||||
soff = struct.unpack_from("<I", d, o + 4)[0]
|
||||
end = d.find(b"\0", symptr + nsyms * 18 + soff)
|
||||
nm = d[symptr + nsyms * 18 + soff:end].decode("latin1")
|
||||
else:
|
||||
nm = name.rstrip(b"\0").decode("latin1")
|
||||
value = struct.unpack_from("<I", d, o + 8)[0]
|
||||
sec = struct.unpack_from("<h", d, o + 12)[0]
|
||||
cls = d[o + 16]
|
||||
naux = d[o + 17]
|
||||
if cls == 3:
|
||||
if nm not in want_flags:
|
||||
sys.exit(f"{path}: section symbol {nm!r} has no TI-COFF section")
|
||||
if naux != 1:
|
||||
sys.exit(f"{path}: section symbol {nm!r} has {naux} aux, want 1")
|
||||
if sec != 1 + list(want_flags).index(nm):
|
||||
sys.exit(f"{path}: section symbol {nm!r} section {sec}")
|
||||
sectab[nm] = value
|
||||
elif cls == 2:
|
||||
if sec != 1:
|
||||
sys.exit(f"{path}: symbol {nm!r} section {sec}, want 1 (.text)")
|
||||
symtab[nm] = value
|
||||
else:
|
||||
sys.exit(f"{path}: symbol {nm!r} class {cls}, want 2 or 3")
|
||||
i += 1 + naux
|
||||
for want in (".text", ".data", ".bss"):
|
||||
if want not in sectab or sectab[want] != 0:
|
||||
sys.exit(f"{path}: missing section symbol {want}")
|
||||
for want in ("_f", "_movi_long", "_movi_short", "_cmpi_long",
|
||||
"_andi_long"):
|
||||
if want not in symtab:
|
||||
sys.exit(f"{path}: missing symbol {want}")
|
||||
if symtab["_f"] != 0:
|
||||
sys.exit(f"{path}: _f value {symtab['_f']}, want 0")
|
||||
if symtab["_movi_long"] <= 0:
|
||||
sys.exit(f"{path}: _movi_long value {symtab['_movi_long']}, want > 0")
|
||||
if symtab["_movi_short"] <= symtab["_movi_long"]:
|
||||
sys.exit(f"{path}: _movi_short value {symtab['_movi_short']} does not follow _movi_long {symtab['_movi_long']}")
|
||||
if symtab["_cmpi_long"] <= symtab["_movi_short"]:
|
||||
sys.exit(f"{path}: _cmpi_long value {symtab['_cmpi_long']} does not follow _movi_short {symtab['_movi_short']}")
|
||||
if symtab["_andi_long"] <= symtab["_cmpi_long"]:
|
||||
sys.exit(f"{path}: _andi_long value {symtab['_andi_long']} does not follow _cmpi_long {symtab['_cmpi_long']}")
|
||||
|
||||
with open(out, "wb") as f:
|
||||
f.write(text)
|
||||
print(f"{path}: machine=0x{machine:04x} sections={nscns} symbols={nsyms} flags=0x{flags:04x} .text={len(text)} bytes")
|
||||
PY
|
||||
then
|
||||
fail "could not parse TI-COFF object: $1"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "== extract .text from the native and GSPA objects"
|
||||
parse_coff "$M5_WORK/m5-smoke.o" "$M5_WORK/native.text" native
|
||||
parse_coff "$GSPA_DIR/M5.OBJ" "$M5_WORK/gspa.text" gspa
|
||||
|
||||
NATIVE_BYTES=$(wc -c < "$M5_WORK/native.text")
|
||||
GSPA_BYTES=$(wc -c < "$M5_WORK/gspa.text")
|
||||
[ "$NATIVE_BYTES" -gt 0 ] || fail "native .text is empty"
|
||||
[ "$NATIVE_BYTES" -eq "$GSPA_BYTES" ] \
|
||||
|| fail "native .text is $NATIVE_BYTES bytes, GSPA .text is $GSPA_BYTES bytes"
|
||||
|
||||
if ! cmp -s "$M5_WORK/native.text" "$M5_WORK/gspa.text"; then
|
||||
{
|
||||
echo "M5 object smoke: FAIL: .text bytes differ"
|
||||
echo " native: $(od -An -v -tx1 "$M5_WORK/native.text")"
|
||||
echo " GSPA: $(od -An -v -tx1 "$M5_WORK/gspa.text")"
|
||||
} >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo " native .text == GSPA .text ($NATIVE_BYTES bytes)"
|
||||
echo "M5 object smoke: PASS"
|
||||
Executable
+210
@@ -0,0 +1,210 @@
|
||||
#!/bin/sh
|
||||
# M5 policy gate: the default tms-clang -O2 pipeline must no longer need the
|
||||
# switch-to-lookup driver workaround, the raw opt+llc path must diagnose the
|
||||
# i33 closed-form multiply instead of failing in SelectionDAG, and a static
|
||||
# variadic definition without a va_list walk must be rejected at -O2 instead of
|
||||
# silently losing its `...` arguments.
|
||||
#
|
||||
# M5 -> M6 notes:
|
||||
# - case 3b used to pin the i64 reject diagnostic ("64-bit multiply ...
|
||||
# reserved for M6"). M6 Task 2 implements i64, so that case now pins the
|
||||
# other side of the same boundary: the 64-bit multiply must compile to an
|
||||
# inline target sequence (MPYS/MPYU) and must not call an invented 64-bit
|
||||
# runtime helper.
|
||||
# - case 4b used to stop at the pre-opt scan. M6 Task 4 implements the real
|
||||
# va_list lowering, so it now also runs llc at -O0 and -O2 on the same local
|
||||
# definition and requires a selected body (no "local variadic definition"
|
||||
# diagnostic). Case 4's no-va_list definition stays rejected.
|
||||
#
|
||||
# scripts/tests/m5/policy.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_OPT TMS_LLC TMS_BITADDR TMS_DRIVER
|
||||
# M5_POLICY_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
TMS_DRIVER=${TMS_DRIVER:-$ROOT/scripts/tms-clang}
|
||||
WORK=${M5_POLICY_WORK:-$ROOT/build/m5-policy}
|
||||
|
||||
fail() {
|
||||
echo "m5 policy: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_DRIVER"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
export TMS_CLANG TMS_OPT TMS_LLC TMS_BITADDR
|
||||
|
||||
# 1. The switch-to-lookup workaround is gone and the ordinary -O2 path still
|
||||
# produces a table that is indexed in bits. Trace the real opt invocation
|
||||
# rather than grepping the driver source.
|
||||
OPT_REAL=$TMS_OPT
|
||||
TRACE=$WORK/opt-switch.args
|
||||
cat > "$WORK/opt-trace" <<EOF
|
||||
#!/bin/sh
|
||||
printf '%s\n' "\$*" >> "$TRACE"
|
||||
exec "$OPT_REAL" "\$@"
|
||||
EOF
|
||||
chmod +x "$WORK/opt-trace"
|
||||
export TRACE
|
||||
: > "$TRACE"
|
||||
|
||||
TMS_OPT=$WORK/opt-trace "$TMS_DRIVER" -O2 -o "$WORK/switch.ll" \
|
||||
"$ROOT/scripts/m4/switch.c" \
|
||||
|| fail "default -O2 could not compile the M4 switch"
|
||||
grep -q -- '-replexitval=never' "$TRACE" \
|
||||
|| { sed 's/^/ /' "$TRACE" >&2; \
|
||||
fail "the opt invocation does not pass -replexitval=never"; }
|
||||
if grep -q -- '-switch-to-lookup' "$TRACE"; then
|
||||
sed 's/^/ /' "$TRACE" >&2
|
||||
fail "the opt invocation still passes -switch-to-lookup"
|
||||
fi
|
||||
grep -q 'switch.table' "$WORK/switch.ll" \
|
||||
|| fail "the M4 switch produced no lookup table (the test is not exercising the fix)"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/switch.ll" \
|
||||
-o "$WORK/switch.s" || fail "llc could not select the switch"
|
||||
|
||||
awk '/^_sw_tile:/ { on = 1; next } on && /-- End function/ { exit } on' \
|
||||
"$WORK/switch.s" > "$WORK/sw_tile.s"
|
||||
if ! grep -Eq '^[[:space:]]*SLL[[:space:]]+3' "$WORK/sw_tile.s"; then
|
||||
sed 's/^/ /' "$WORK/sw_tile.s" >&2
|
||||
fail "the switch-table index is not shifted into bits (8x table bug)"
|
||||
fi
|
||||
if ! grep -Eq '^[[:space:]]*MOVB[[:space:]]+\*A[0-9]+' "$WORK/sw_tile.s"; then
|
||||
sed 's/^/ /' "$WORK/sw_tile.s" >&2
|
||||
fail "the switch lookup has no byte load"
|
||||
fi
|
||||
echo " ok default -O2 switch table is indexed in bits"
|
||||
|
||||
# 2. The driver keeps its documented -replexitval policy (traced above) and the
|
||||
# loop is not rewritten into an unsupported closed form.
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/loop.ll" "$ROOT/scripts/m4/loop.c" \
|
||||
|| fail "default -O2 could not compile the M4 loop"
|
||||
if grep -Eq '\bmul i(33|64)\b' "$WORK/loop.ll"; then
|
||||
grep -E '\bmul i(33|64)\b' "$WORK/loop.ll" >&2
|
||||
fail "driver -O2 produced a wide multiply"
|
||||
fi
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/loop.ll" \
|
||||
-o "$WORK/loop.s" || fail "the driver -O2 loop does not select"
|
||||
echo " ok driver -O2 keeps the loop and passes -replexitval=never"
|
||||
|
||||
# 3. The raw opt+llc path (no -replexitval) reaches the closed-form i33
|
||||
# multiply. It must fail with the target's clear diagnostic, not a
|
||||
# SelectionDAG "Cannot select" or an assertion.
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
-S -emit-llvm -ffreestanding -fno-builtin -nostdinc \
|
||||
-o "$WORK/loop.step1.ll" "$ROOT/scripts/m4/loop.c" \
|
||||
|| fail "clang could not emit the raw loop IR"
|
||||
"$TMS_BITADDR" --scale "$WORK/loop.step1.ll" "$WORK/loop.scaled.ll" 2>/dev/null \
|
||||
|| fail "tms-bitaddr --scale failed"
|
||||
"$TMS_OPT" -passes='default<O2>' -S "$WORK/loop.scaled.ll" \
|
||||
-o "$WORK/loop.opt.ll" || fail "opt failed on the raw loop"
|
||||
grep -Eq '\bmul i(33|64)\b' "$WORK/loop.opt.ll" \
|
||||
|| fail "the raw opt pipeline did not produce the i33 multiply"
|
||||
|
||||
if "$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/loop.opt.ll" \
|
||||
-o "$WORK/raw-i33.s" 2> "$WORK/raw-i33.err"; then
|
||||
fail "raw opt+llc accepted the i33 multiply"
|
||||
fi
|
||||
grep -q 'i33 multiply' "$WORK/raw-i33.err" \
|
||||
|| { sed 's/^/ /' "$WORK/raw-i33.err" >&2; \
|
||||
fail "the raw i33 path has no clear target diagnostic"; }
|
||||
if grep -Eq 'Cannot select|Assertion|assertion' "$WORK/raw-i33.err"; then
|
||||
sed 's/^/ /' "$WORK/raw-i33.err" >&2
|
||||
fail "the raw i33 path still fails in SelectionDAG/an assertion"
|
||||
fi
|
||||
grep -q -- '-replexitval=never' "$WORK/raw-i33.err" \
|
||||
|| { sed 's/^/ /' "$WORK/raw-i33.err" >&2; \
|
||||
fail "the i33 diagnostic does not name the driver policy"; }
|
||||
echo " ok raw i33 path fails with the target diagnostic"
|
||||
|
||||
# 3b. M6 implements i64. The old i64/M6-boundary diagnostic is gone: the same
|
||||
# source must now select a real 64-bit multiply sequence, with no invented
|
||||
# library helper (rts.lib has no 64-bit entry).
|
||||
cat > "$WORK/u64mul.c" <<'EOF'
|
||||
unsigned long long u64mul(unsigned long long a, unsigned long long b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
EOF
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/u64mul.ll" "$WORK/u64mul.c" \
|
||||
|| fail "default -O2 failed to emit the i64 multiply source"
|
||||
grep -Eq '\bmul i64\b' "$WORK/u64mul.ll" \
|
||||
|| fail "the i64 source did not produce a mul i64"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm "$WORK/u64mul.ll" \
|
||||
-o "$WORK/u64mul.s" || fail "llc rejected a 64-bit multiply after M6"
|
||||
grep -q 'MPYS\|MPYU' "$WORK/u64mul.s" \
|
||||
|| fail "the i64 multiply has no target multiply sequence"
|
||||
if grep -Eq 'CALLA (__muldi3|__divdi3|__udivdi3)' "$WORK/u64mul.s"; then
|
||||
fail "the i64 multiply calls an invented 64-bit runtime helper"
|
||||
fi
|
||||
echo " ok i64 multiply selects an inline MPYS/MPYU sequence"
|
||||
|
||||
# 4. A static variadic definition loses `...` to dead-argument elimination at
|
||||
# -O2. The driver must reject it before opt; -O0 still supports it.
|
||||
if "$TMS_DRIVER" -O2 -o "$WORK/varargs.ll" "$ROOT/scripts/m4/varargs.c" \
|
||||
2> "$WORK/varargs.err"; then
|
||||
fail "default -O2 accepted a static variadic definition"
|
||||
fi
|
||||
grep -q 'static variadic definition' "$WORK/varargs.err" \
|
||||
|| { sed 's/^/ /' "$WORK/varargs.err" >&2; \
|
||||
fail "the static-variadics rejection has no clear message"; }
|
||||
grep -q "remove 'static' or compile with -O0" "$WORK/varargs.err" \
|
||||
|| { sed 's/^/ /' "$WORK/varargs.err" >&2; \
|
||||
fail "the static-variadics message gives no remedy"; }
|
||||
"$TMS_DRIVER" -O0 -o "$WORK/varargs-O0.ll" "$ROOT/scripts/m4/varargs.c" \
|
||||
|| fail "-O0 no longer supports the static contiguous-stack varargs probe"
|
||||
echo " ok static varargs is rejected at -O2 and kept at -O0"
|
||||
|
||||
# 4b. A local variadic definition that uses llvm.va_start/va_arg keeps its
|
||||
# `...` through DeadArgumentElimination, so neither the pre-opt scan nor
|
||||
# the M6 llc guard may reject it as the static contiguous-stack shape.
|
||||
# Both llc levels must select the walk (M6 general varargs).
|
||||
cat > "$WORK/vastart.c" <<'EOF'
|
||||
static int vsum(int a, ...)
|
||||
{
|
||||
__builtin_va_list ap;
|
||||
__builtin_va_start(ap, a);
|
||||
int x = __builtin_va_arg(ap, int);
|
||||
__builtin_va_end(ap);
|
||||
return a + x;
|
||||
}
|
||||
int call_vsum(void) { return vsum(1, 2); }
|
||||
EOF
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/vastart.ll" "$WORK/vastart.c" \
|
||||
|| fail "the static-variadic scan rejected a definition that calls llvm.va_start"
|
||||
grep -Eq '^define internal .*\.\.\.' "$WORK/vastart.ll" \
|
||||
|| fail "the va_start definition lost its '...'"
|
||||
grep -q 'llvm.va_start' "$WORK/vastart.ll" \
|
||||
|| fail "the va_start definition no longer calls llvm.va_start"
|
||||
for level in -O0 -O2; do
|
||||
"$TMS_LLC" -march=tms34010 "$level" -filetype=asm "$WORK/vastart.ll" \
|
||||
-o "$WORK/vastart$level.s" \
|
||||
|| fail "llc $level rejected the va_start local variadic definition"
|
||||
grep -q 'RETS 2' "$WORK/vastart$level.s" \
|
||||
|| fail "llc $level produced no va_start walk body"
|
||||
done
|
||||
echo " ok local va_start varargs select at -O0 and -O2"
|
||||
|
||||
# 5. External varargs (the sprintf ABI) must still compile through -O2.
|
||||
cat > "$WORK/extvar.c" <<'EOF'
|
||||
extern int sprintf(char *, const char *, ...);
|
||||
int fmt(char *buf) { return sprintf(buf, "%d", 42); }
|
||||
EOF
|
||||
"$TMS_DRIVER" -O2 -o "$WORK/extvar.ll" "$WORK/extvar.c" \
|
||||
|| fail "external sprintf varargs no longer compile at -O2"
|
||||
grep -q 'call.*@sprintf' "$WORK/extvar.ll" \
|
||||
|| fail "the external sprintf call was lost"
|
||||
echo " ok external sprintf varargs still compile at -O2"
|
||||
|
||||
echo "m5 policy: PASS"
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
#!/bin/sh
|
||||
# M5 long-private-name gate: two translation units both define the same long
|
||||
# private symbol. GSPA 2.00 keeps only 31 identifier characters; appending
|
||||
# the M4 `_XXXXXXXX` module token to a long name used to truncate the token
|
||||
# away, so both TUs emitted the same label and GSPA reported a duplicate
|
||||
# definition. The naming scheme must cap the base, fold the full name into a
|
||||
# hash, and keep the module token at the end of a <=31-character label.
|
||||
#
|
||||
# scripts/tests/m5/private-long.sh
|
||||
#
|
||||
# Overridable: M5_PRIVATE_LONG_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m5
|
||||
WORK=${M5_PRIVATE_LONG_WORK:-$ROOT/build/m5-private-long}
|
||||
|
||||
fail() {
|
||||
echo "m5 private-long: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
M4_SKIP_MAME=1 \
|
||||
M4_SOURCES="$DIR/private-long-a.c $DIR/private-long-b.c" \
|
||||
M4_ENTRY="$ROOT/scripts/m4/private-entry.asm" \
|
||||
M4_WORK="$WORK" \
|
||||
"$ROOT/scripts/m4/run.sh" || fail "two-TU long-private-name link failed"
|
||||
|
||||
ASM_A=$WORK/asm/private-long-a.s
|
||||
ASM_B=$WORK/asm/private-long-b.s
|
||||
for f in "$ASM_A" "$ASM_B"; do
|
||||
[ -f "$f" ] || fail "missing assembly: $f"
|
||||
done
|
||||
|
||||
# The C `static` symbol is internal (not private), so its sanitized base is
|
||||
# `_this_is_a_very_long_private_name`; the cap keeps the first 13 characters
|
||||
# (`_this_is_a_ve`) and adds `_` + an 8-hex name hash + `_` + the 8-hex
|
||||
# module token, for a 31-character label.
|
||||
PAT='_this_is_a_ve_[0-9A-F]{8}_[0-9A-F]{8}'
|
||||
A_SYM=$(grep -oE "${PAT}:" "$ASM_A" | head -1 | tr -d ':')
|
||||
B_SYM=$(grep -oE "${PAT}:" "$ASM_B" | head -1 | tr -d ':')
|
||||
[ -n "$A_SYM" ] || { sed 's/^/ /' "$ASM_A" >&2; fail "private-long-a has no capped private label"; }
|
||||
[ -n "$B_SYM" ] || { sed 's/^/ /' "$ASM_B" >&2; fail "private-long-b has no capped private label"; }
|
||||
echo " ok capped private labels: $A_SYM vs $B_SYM"
|
||||
|
||||
for sym in "$A_SYM" "$B_SYM"; do
|
||||
len=${#sym}
|
||||
[ "$len" -le 31 ] || fail "private label '$sym' is $len characters, GSPA keeps 31"
|
||||
done
|
||||
|
||||
[ "$A_SYM" != "$B_SYM" ] \
|
||||
|| fail "both TUs still share the long private label: $A_SYM"
|
||||
|
||||
# The last two underscore-separated fields are the full-name hash and the
|
||||
# module token. The name hash is a property of the private name and must be
|
||||
# identical in both TUs; only the module token may differ.
|
||||
A_REST=${A_SYM#_this_is_a_ve_}
|
||||
A_NAME=${A_REST%%_*}
|
||||
A_TOKEN=${A_REST##*_}
|
||||
B_REST=${B_SYM#_this_is_a_ve_}
|
||||
B_NAME=${B_REST%%_*}
|
||||
B_TOKEN=${B_REST##*_}
|
||||
[ "${#A_NAME}" -eq 8 ] || fail "name hash '$A_NAME' is not 8 hex digits"
|
||||
[ "${#B_NAME}" -eq 8 ] || fail "name hash '$B_NAME' is not 8 hex digits"
|
||||
[ "$A_NAME" = "$B_NAME" ] \
|
||||
|| fail "the full-name hash differs between TUs: $A_NAME vs $B_NAME"
|
||||
[ "${#A_TOKEN}" -eq 8 ] || fail "module token '$A_TOKEN' is not 8 hex digits"
|
||||
[ "${#B_TOKEN}" -eq 8 ] || fail "module token '$B_TOKEN' is not 8 hex digits"
|
||||
[ "$A_TOKEN" != "$B_TOKEN" ] \
|
||||
|| fail "the 8-hex module token did not survive: $A_TOKEN"
|
||||
echo " ok name hash is stable: $A_NAME; module tokens differ: $A_TOKEN vs $B_TOKEN"
|
||||
|
||||
# Public names stay exactly as the IR spells them.
|
||||
grep -Eq '^[[:space:]]*\.globl[[:space:]]+_a([[:space:]]|$)' "$ASM_A" \
|
||||
|| fail "private-long-a does not expose public _a"
|
||||
grep -Eq '^[[:space:]]*\.globl[[:space:]]+_b([[:space:]]|$)' "$ASM_B" \
|
||||
|| fail "private-long-b does not expose public _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"
|
||||
echo " ok public names unchanged: _a and _b"
|
||||
|
||||
echo "m5 private-long: PASS"
|
||||
@@ -0,0 +1,53 @@
|
||||
-- robust-check.lua -- read the M5 robustness marker words written by the
|
||||
-- compiled functions.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- M5_EXPECT_ALLOCA 408 alloca_sum(17)
|
||||
-- M5_EXPECT_BYVAL 64 robust_byval()
|
||||
-- M5_EXPECT_NARROW 1056 robust_narrow()
|
||||
-- M5_EXPECT_MEM 438 robust_mem()
|
||||
-- M5_EXPECT_ALLOCA_USE 1496 alloca_use(17)
|
||||
-- M5_EXPECT_BYVAL6 64 robust_byval6()
|
||||
-- M5_EXPECT_MEMMOVE 2148 robust_memmove()
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local EXPECT_ALLOCA = tonumber(os.getenv("M5_EXPECT_ALLOCA") or "408")
|
||||
local EXPECT_BYVAL = tonumber(os.getenv("M5_EXPECT_BYVAL") or "64")
|
||||
local EXPECT_NARROW = tonumber(os.getenv("M5_EXPECT_NARROW") or "1056")
|
||||
local EXPECT_MEM = tonumber(os.getenv("M5_EXPECT_MEM") or "438")
|
||||
local EXPECT_ALLOCA_USE = tonumber(os.getenv("M5_EXPECT_ALLOCA_USE") or "1496")
|
||||
local EXPECT_BYVAL6 = tonumber(os.getenv("M5_EXPECT_BYVAL6") or "64")
|
||||
local EXPECT_MEMMOVE = tonumber(os.getenv("M5_EXPECT_MEMMOVE") or "2148")
|
||||
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 alloca = prog:read_u32(0x018A8000)
|
||||
local byval = prog:read_u32(0x018A8020)
|
||||
local narrow = prog:read_u32(0x018A8040)
|
||||
local mem = prog:read_u32(0x018A8060)
|
||||
local alloca_use = prog:read_u32(0x018A8080)
|
||||
local byval6 = prog:read_u32(0x018A80A0)
|
||||
local memmove = prog:read_u32(0x018A80C0)
|
||||
print(string.format(
|
||||
"M5: alloca=%d byval=%d narrow=%d mem=%d alloca_use=%d byval6=%d memmove=%d",
|
||||
alloca, byval, narrow, mem, alloca_use, byval6, memmove))
|
||||
if alloca == EXPECT_ALLOCA and byval == EXPECT_BYVAL
|
||||
and narrow == EXPECT_NARROW and mem == EXPECT_MEM
|
||||
and alloca_use == EXPECT_ALLOCA_USE
|
||||
and byval6 == EXPECT_BYVAL6 and memmove == EXPECT_MEMMOVE then
|
||||
print("M5 MAME: PASS")
|
||||
else
|
||||
print(string.format(
|
||||
"M5 MAME: FAIL (want alloca=%d byval=%d narrow=%d mem=%d alloca_use=%d byval6=%d memmove=%d)",
|
||||
EXPECT_ALLOCA, EXPECT_BYVAL, EXPECT_NARROW, EXPECT_MEM,
|
||||
EXPECT_ALLOCA_USE, EXPECT_BYVAL6, EXPECT_MEMMOVE))
|
||||
end
|
||||
end
|
||||
end, "m5-robust-check")
|
||||
@@ -0,0 +1,57 @@
|
||||
; robust-entry.asm -- M5 robustness gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Markers (0x20 bits apart):
|
||||
; 018A8000 alloca_sum(17) == 408
|
||||
; 018A8020 robust_byval() == 64
|
||||
; 018A8040 robust_narrow() == 1056 (156 + -100 + 1000)
|
||||
; 018A8060 robust_mem() == 438 (1..12 + 4 * 0x5A)
|
||||
; 018A8080 alloca_use(17) == 1496 (2 * a_sum + b_sum)
|
||||
; 018A80A0 robust_byval6() == 64 (6-byte byval slot)
|
||||
; 018A80C0 robust_memmove() == 2148 (10/64-byte memmove)
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 32, 0, 1
|
||||
setf 16, 1, 0
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
|
||||
; alloca_sum(17): last argument first, on the program stack
|
||||
move a14, -*sp, 1
|
||||
movi 17, a0
|
||||
move a0, *a14+, 1
|
||||
calla _alloca_sum
|
||||
movi 018A8000h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
calla _robust_byval
|
||||
movi 018A8020h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
calla _robust_narrow
|
||||
movi 018A8040h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
calla _robust_mem
|
||||
movi 018A8060h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
; alloca_use(17): both VLAs must survive sum_vla(a, 17)
|
||||
move a14, -*sp, 1
|
||||
movi 17, a0
|
||||
move a0, *a14+, 1
|
||||
calla _alloca_use
|
||||
movi 018A8080h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
calla _robust_byval6
|
||||
movi 018A80A0h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
calla _robust_memmove
|
||||
movi 018A80C0h, a2
|
||||
move a8, *a2, 1
|
||||
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,176 @@
|
||||
/* M5 robustness gate payload: dynamic alloca, byval, narrow returns, and the
|
||||
* llvm.memcpy/llvm.memset intrinsics. The entry assembly calls each function
|
||||
* and stores the result at a marker word; robust.sh checks the values in MAME.
|
||||
*
|
||||
* The gate is built at -O0 so the narrow-return calls are not constant-folded
|
||||
* and the VLA keeps its runtime size. The lit tests pin the same features at
|
||||
* -O2.
|
||||
*/
|
||||
|
||||
struct pair {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
__attribute__((noinline))
|
||||
int alloca_sum(int n)
|
||||
{
|
||||
volatile int a[n];
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
a[i] = i * 3;
|
||||
for (i = 0; i < n; ++i)
|
||||
sum += a[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
/* A g(buf,n)-style callee used to check that the VLA reservation is real: the
|
||||
* call's argument pushes start at A14 and would overwrite the VLA if the
|
||||
* dynamic alloca advanced A14 by only size/8. */
|
||||
__attribute__((noinline))
|
||||
int sum_vla(const volatile int *p, int n)
|
||||
{
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
sum += p[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int alloca_use(int n)
|
||||
{
|
||||
volatile int a[n];
|
||||
volatile int b[n];
|
||||
int i;
|
||||
int s;
|
||||
int t = 0;
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
a[i] = i * 3;
|
||||
for (i = 0; i < n; ++i)
|
||||
b[i] = i * 5;
|
||||
|
||||
/* Both VLAs must survive this argumented call, and a second alloca. */
|
||||
s = sum_vla(a, n);
|
||||
for (i = 0; i < n; ++i)
|
||||
t += a[i] + b[i];
|
||||
return s + t;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int byval_sum(struct pair p)
|
||||
{
|
||||
return p.x * 3 + p.y;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int robust_byval(void)
|
||||
{
|
||||
struct pair p;
|
||||
|
||||
p.x = 11;
|
||||
p.y = 31;
|
||||
return byval_sum(p);
|
||||
}
|
||||
|
||||
/* Six bytes distinguishes the TI 16-bit byval slot rounding from a 32-bit
|
||||
* extension: the object occupies 6 bytes, not 8. */
|
||||
struct pair6 {
|
||||
int x;
|
||||
short y;
|
||||
};
|
||||
|
||||
__attribute__((noinline))
|
||||
int byval6_sum(struct pair6 p)
|
||||
{
|
||||
return p.x * 3 + p.y;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int robust_byval6(void)
|
||||
{
|
||||
struct pair6 p;
|
||||
|
||||
p.x = 11;
|
||||
p.y = 31;
|
||||
return byval6_sum(p);
|
||||
}
|
||||
|
||||
/* 0xFF9C makes the low byte 0x9C (156) and the low 16 bits -100. */
|
||||
volatile int narrow_seed = 0xFF9C;
|
||||
|
||||
__attribute__((noinline))
|
||||
unsigned char narrow8(void)
|
||||
{
|
||||
return (unsigned char)narrow_seed;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
signed short narrow16(void)
|
||||
{
|
||||
return (signed short)narrow_seed;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
int robust_narrow(void)
|
||||
{
|
||||
return (int)narrow8() + (int)narrow16() + 1000;
|
||||
}
|
||||
|
||||
__attribute__((noinline))
|
||||
void mem_ops(unsigned char *d, const unsigned char *s)
|
||||
{
|
||||
__builtin_memcpy(d, s, 12);
|
||||
__builtin_memset(d + 12, 0x5A, 4);
|
||||
}
|
||||
|
||||
/* A short public name: GSPA 2.00 truncates identifiers at 31 characters, and
|
||||
* a private constant would get the sanitized module-token suffix. */
|
||||
unsigned char robust_src[16] = {1, 2, 3, 4, 5, 6, 7, 8,
|
||||
9, 10, 11, 12, 0, 0, 0, 0};
|
||||
|
||||
__attribute__((noinline))
|
||||
int robust_mem(void)
|
||||
{
|
||||
unsigned char dst[16];
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
mem_ops(dst, robust_src);
|
||||
for (i = 0; i < 16; ++i)
|
||||
sum += dst[i];
|
||||
return sum;
|
||||
}
|
||||
|
||||
unsigned char robust_src64[64] = {
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
|
||||
49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64
|
||||
};
|
||||
|
||||
/* Constant memmove (10 and 64 bytes) must compile: PreISel does not expand
|
||||
* these sizes, so the target pass expands them into overlap-safe loops. The
|
||||
* overlapping 10-byte move checks the backward direction. */
|
||||
__attribute__((noinline))
|
||||
int robust_memmove(void)
|
||||
{
|
||||
unsigned char buf[64];
|
||||
unsigned char ov[12] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
|
||||
int i;
|
||||
int sum = 0;
|
||||
|
||||
__builtin_memmove(buf, robust_src64, 64);
|
||||
for (i = 0; i < 64; ++i)
|
||||
sum += buf[i]; /* 1..64 = 2080 */
|
||||
|
||||
__builtin_memmove(ov + 1, ov, 10);
|
||||
for (i = 0; i < 12; ++i)
|
||||
sum += ov[i]; /* 1,1..10,12 = 68 */
|
||||
|
||||
return sum; /* 2148 */
|
||||
}
|
||||
Executable
+158
@@ -0,0 +1,158 @@
|
||||
#!/bin/sh
|
||||
# M5 robustness gate: dynamic alloca, byval, i8/i16 returns, and
|
||||
# llvm.memcpy/llvm.memset in both the assembly and native object paths.
|
||||
#
|
||||
# The payload (robust.c) is compiled at -O0 so the VLA keeps a runtime size,
|
||||
# the byval struct stays a real by-value call, and the narrow-return calls are
|
||||
# not constant-folded. Each path is assembled/linked with GSPA/GSPLNK and run
|
||||
# in MAME; the marker words must match:
|
||||
#
|
||||
# alloca_sum(17) = 408 (sum of 3*i for i=0..16)
|
||||
# robust_byval() = 64 (11 * 3 + 31, read from the callee's copy)
|
||||
# robust_narrow() = 1056 (156 + -100 + 1000)
|
||||
# robust_mem() = 438 (1..12 plus four 0x5A bytes)
|
||||
# alloca_use(17) = 1496 (two VLAs survive sum_vla(a, 17))
|
||||
# robust_byval6() = 64 (6-byte byval slot, TI 16-bit rounding)
|
||||
# robust_memmove() = 2148 (10/64-byte constant memmove, overlap-safe)
|
||||
#
|
||||
# Both paths must produce the same markers, and the assembly must show the
|
||||
# feature-specific instructions (A14 dynamic adjustment, byval slot advance,
|
||||
# ANDI 255 for zeroext i8, FS0/word copies for the memory intrinsics).
|
||||
#
|
||||
# scripts/tests/m5/robust.sh
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_CLANG TMS_LLC MAME DOSBOX DOSBOX_CONF SDK_IMG
|
||||
# M5_ROBUST_WORK M5_ROBUST_ASM M5_ROBUST_NATIVE
|
||||
# MAME_TIMEOUT DOSBOX_TIMEOUT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
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=${M5_ROBUST_WORK:-$ROOT/build/m5-robust}
|
||||
ASM_WORK=${M5_ROBUST_ASM:-$WORK/asm-path}
|
||||
NATIVE_WORK=${M5_ROBUST_NATIVE:-$WORK/native-path}
|
||||
|
||||
LOADER_LUA=$ROOT/vendor/vt1200/dwt/loader/loader.lua
|
||||
LOADER_BIN=$ROOT/vendor/vt1200/dwt/loader/build/loader.bin
|
||||
LOADER_AT=${LOADER_AT:-2500}
|
||||
LOADER_END=${LOADER_END:-2700}
|
||||
|
||||
fail() {
|
||||
echo "M5 robust: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$MAME" ] || fail "missing MAME: $MAME"
|
||||
[ -f "$LOADER_LUA" ] || fail "missing loader.lua: $LOADER_LUA"
|
||||
[ -f "$LOADER_BIN" ] || fail "missing loader.bin: $LOADER_BIN"
|
||||
[ -f "$DOSBOX_CONF" ] || fail "missing DOSBox config: $DOSBOX_CONF"
|
||||
[ -f "$SDK_IMG" ] || fail "missing SDK image: $SDK_IMG"
|
||||
|
||||
mkdir -p "$WORK"
|
||||
|
||||
build_and_link() {
|
||||
label=$1
|
||||
work=$2
|
||||
native=$3
|
||||
mkdir -p "$work"
|
||||
echo "== $label path: compile with tms-clang -O0 / llc -O0 and link"
|
||||
M4_SOURCES="$HERE/robust.c" \
|
||||
M4_ENTRY="$HERE/robust-entry.asm" \
|
||||
M4_CLANG_OPT=-O0 \
|
||||
M4_LLC_OPT=-O0 \
|
||||
M4_WORK="$work" \
|
||||
M4_NATIVE="$native" \
|
||||
M4_SKIP_MAME=1 \
|
||||
"$ROOT/scripts/m4/run.sh" > "$work/run.log" 2>&1 \
|
||||
|| { tail -40 "$work/run.log" >&2; \
|
||||
fail "$label compile/link failed"; }
|
||||
grep -q '^M4 LINK: PASS' "$work/run.log" \
|
||||
|| { tail -20 "$work/run.log" >&2; fail "$label link did not pass"; }
|
||||
}
|
||||
|
||||
run_mame() {
|
||||
label=$1
|
||||
work=$2
|
||||
echo "== $label path: run the COFF in MAME"
|
||||
M4_LOADER_LUA="$LOADER_LUA" \
|
||||
VT1200_MONITOR=VR319 \
|
||||
VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT="$LOADER_AT" LOADER_END="$LOADER_END" \
|
||||
LOADER_BIN="$LOADER_BIN" LOADER_COFF="$work/m4.coff" \
|
||||
LOADER_OUT="$work/evidence" \
|
||||
M5_EXPECT_ALLOCA=408 M5_EXPECT_BYVAL=64 \
|
||||
M5_EXPECT_NARROW=1056 M5_EXPECT_MEM=438 \
|
||||
M5_EXPECT_ALLOCA_USE=1496 M5_EXPECT_BYVAL6=64 \
|
||||
M5_EXPECT_MEMMOVE=2148 \
|
||||
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 "$HERE/robust-check.lua" -autoboot_delay 0 \
|
||||
> "$work/mame.log" 2>&1 \
|
||||
|| { tail -30 "$work/mame.log" >&2; fail "$label MAME run failed"; }
|
||||
grep -q 'LOADER: result status=0 (OK)' "$work/mame.log" \
|
||||
|| { grep 'LOADER: result' "$work/mame.log" >&2 || true; \
|
||||
fail "$label loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$work/mame.log" \
|
||||
|| fail "$label loader could not verify the placed .text bytes"
|
||||
grep -q '^M5 MAME: PASS' "$work/mame.log" \
|
||||
|| { grep -E '^M5:' "$work/mame.log" >&2 || true; \
|
||||
fail "$label M5 marker check failed"; }
|
||||
MARKERS=$(grep -E '^M5: alloca=' "$work/mame.log" | tail -1)
|
||||
[ -n "$MARKERS" ] || fail "$label produced no M5 marker line"
|
||||
echo " $MARKERS"
|
||||
}
|
||||
|
||||
# 1. Assembly path (GSPA/GSPLNK text) and its feature checks.
|
||||
build_and_link asm "$ASM_WORK" ""
|
||||
grep -q '^_alloca_sum:' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "assembly path has no _alloca_sum"
|
||||
grep -Eq '^[[:space:]]*MOVE A14, A[0-9]+' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "dynamic alloca does not read A14"
|
||||
grep -Eq '^[[:space:]]*MOVE A[0-9]+, A14' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "dynamic alloca does not write the advanced A14"
|
||||
grep -Eq '^[[:space:]]*ADDI 64, A14' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "byval caller does not advance A14 by the 8-byte byval slot"
|
||||
grep -Eq '^[[:space:]]*ANDI 255, A[0-9]+' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "zeroext i8 return/caller does not mask to 8 bits"
|
||||
grep -Eq '^[[:space:]]*CALLA _sum_vla' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "alloca_use does not call the argumented VLA consumer"
|
||||
grep -Eq '^[[:space:]]*MOVI 1515870810, A[0-9]+' "$ASM_WORK/asm/robust.s" \
|
||||
|| fail "known-size memset did not replicate 0x5A into a word"
|
||||
if grep -q 'CALLA _memcpy' "$ASM_WORK/asm/robust.s"; then
|
||||
fail "assembly path still calls _memcpy instead of the inline expansion"
|
||||
fi
|
||||
if grep -q 'CALLA _memset' "$ASM_WORK/asm/robust.s"; then
|
||||
fail "assembly path still calls _memset instead of the inline expansion"
|
||||
fi
|
||||
if grep -q 'CALLA _memmove' "$ASM_WORK/asm/robust.s"; then
|
||||
fail "assembly path still calls _memmove instead of the inline expansion"
|
||||
fi
|
||||
run_mame asm "$ASM_WORK"
|
||||
|
||||
# 2. Native TI-COFF path: llc -filetype=obj -> GSPLNK. GSPLNK links the
|
||||
# object and the loader runs it; the markers must be identical.
|
||||
build_and_link native "$NATIVE_WORK" 1
|
||||
run_mame native "$NATIVE_WORK"
|
||||
|
||||
ASM_MARKERS=$(grep -E '^M5: alloca=' "$ASM_WORK/mame.log" | tail -1)
|
||||
NATIVE_MARKERS=$(grep -E '^M5: alloca=' "$NATIVE_WORK/mame.log" | tail -1)
|
||||
[ "$ASM_MARKERS" = "$NATIVE_MARKERS" ] \
|
||||
|| fail "asm and native marker lines differ: '$ASM_MARKERS' vs '$NATIVE_MARKERS'"
|
||||
echo " asm and native markers agree"
|
||||
echo "M5 robust: PASS"
|
||||
Executable
+239
@@ -0,0 +1,239 @@
|
||||
#!/bin/sh
|
||||
# M6 aggregate gate: structs/unions by value, aggregate returns, no sret.
|
||||
#
|
||||
# scripts/tests/m6/aggregate.sh
|
||||
#
|
||||
# Compiles llvm/test/CodeGen/TMS34010/m6-aggregate.ll and the C driver
|
||||
# scripts/m6/aggregate-main.c, assembles/links them with GSPA/GSPLNK 2.00 and
|
||||
# the 1990 flib.lib/rts.lib under DOSBox, loads the COFF with the existing dwt
|
||||
# loader and runs it in MAME. Both -O0 and -O2 run by default;
|
||||
# AGGREGATE_OPT=-O0 (or -O2) selects one level.
|
||||
#
|
||||
# What it proves at runtime:
|
||||
# - the caller-allocated return slot: reserve alignTo(size, 2) bytes before
|
||||
# saving STK, call, copy the object out, release the slot;
|
||||
# - the callee writes the object at saved_STK-size (the top of the rounded
|
||||
# slot) and ends with LOADSTK + RETS 2, including with no explicit args;
|
||||
# - no sret pointer argument and no A8 aggregate return: the driver IR has
|
||||
# direct record returns and no `sret`, and the C-side aggregates are
|
||||
# returned as `%struct.*`/`%union.*` values;
|
||||
# - the 6-byte struct (six), the 5-byte packed struct (five, 6-byte slot),
|
||||
# the 20-byte / five-word struct (big, the 1987 `_mkbig` case), the 2-word
|
||||
# struct (pair, the 1987 `_mkpair` case), a nested struct, and a union;
|
||||
# - a packed bitfield struct (bits, one 16-bit word) returned by value, with
|
||||
# its fields, signed sign-extension and raw packed word checked (the
|
||||
# Task 5 bitfield / Task 6 aggregate-return seam);
|
||||
# - struct/union by-value arguments keep the M5 byval copy-in-the-argument-
|
||||
# area behavior (both hand-written .ll callees and C callees);
|
||||
# - guards after a 5-byte and a 6-byte object prove the copy is exact and
|
||||
# does not write the rounded slot's pad byte into the caller's object;
|
||||
# - i64/double/float members of a returned aggregate keep the little-endian
|
||||
# i64 order and the GSP double/float word order.
|
||||
#
|
||||
# Overridable: LLVM_BIN TMS_LLC TMS_CLANG TMS_OPT TMS_BITADDR MAME DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG AGGREGATE_WORK AGGREGATE_COFF AGGREGATE_SDK
|
||||
# LOADER_AT LOADER_END MAME_TIMEOUT DOSBOX_TIMEOUT AGGREGATE_OPT
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
DIR=$ROOT/scripts/m6
|
||||
TEST=$ROOT/build/llvm-clean/llvm/test/CodeGen/TMS34010/m6-aggregate.ll
|
||||
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
TMS_LLC=${TMS_LLC:-$LLVM_BIN/llc}
|
||||
TMS_CLANG=${TMS_CLANG:-$LLVM_BIN/clang}
|
||||
TMS_OPT=${TMS_OPT:-$LLVM_BIN/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
|
||||
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}
|
||||
|
||||
BASE_WORK=${AGGREGATE_WORK:-$ROOT/build/m6-aggregate}
|
||||
SDK=${AGGREGATE_SDK:-$BASE_WORK/sdk}
|
||||
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:-3400}
|
||||
AGGREGATE_OPTS=${AGGREGATE_OPT:--O0 -O2}
|
||||
|
||||
fail() {
|
||||
echo "m6 aggregate: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_LLC" "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -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"
|
||||
|
||||
mkdir -p "$BASE_WORK" "$SDK"
|
||||
|
||||
echo "== extract the 1987 GSPA/GSPLNK tools"
|
||||
if [ ! -f "$SDK/GSPA.EXE" ] || [ ! -f "$SDK/GSPLNK.EXE" ]; then
|
||||
command -v mcopy >/dev/null 2>&1 || fail "mtools (mcopy) is required"
|
||||
[ -f "$SDK_IMG" ] || fail "1987 SDK image not found: $SDK_IMG"
|
||||
mcopy -n -i "$SDK_IMG" "::/A2/GSPA.EXE" "::/A2/GSPLNK.EXE" "$SDK/"
|
||||
fi
|
||||
[ -f "$SDK/GSPA.EXE" ] || fail "GSPA.EXE not extracted into $SDK"
|
||||
[ -f "$SDK/GSPLNK.EXE" ] || fail "GSPLNK.EXE not extracted into $SDK"
|
||||
|
||||
echo "== extract the 1990 flib.lib/rts.lib"
|
||||
LIB_SDK=${M6_LIB_SDK:-$ROOT/build/m6-sdk}
|
||||
M6_SDK_OUT="$LIB_SDK" "$DIR/flib-extract.sh" > "$BASE_WORK/flib-extract.log" 2>&1 \
|
||||
|| { cat "$BASE_WORK/flib-extract.log" >&2; fail "flib-extract.sh failed"; }
|
||||
cp "$LIB_SDK/flib.lib" "$LIB_SDK/rts.lib" "$SDK/"
|
||||
|
||||
run_one() {
|
||||
opt=$1
|
||||
tag=$(echo "$opt" | tr -d '-')
|
||||
WORK=$BASE_WORK/$tag
|
||||
COFF=${AGGREGATE_COFF:-$WORK/aggregate.coff}
|
||||
|
||||
mkdir -p "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
||||
|
||||
echo "== [$opt] compile m6-aggregate.ll (the hand-written callees)"
|
||||
"$TMS_LLC" -march=tms34010 "$opt" -filetype=asm "$TEST" \
|
||||
-o "$WORK/aggregate-funcs.s" \
|
||||
|| fail "$opt: llc -filetype=asm failed for m6-aggregate.ll"
|
||||
echo " aggregate-funcs.s: $(grep -c . "$WORK/aggregate-funcs.s") lines"
|
||||
|
||||
# The hand-written aggregate returns must be direct record returns; the
|
||||
# functions are named with the C linkage underscore by llc.
|
||||
grep -q '^_mk_six:' "$WORK/aggregate-funcs.s" \
|
||||
|| fail "$opt: aggregate-funcs.s has no _mk_six"
|
||||
grep -q '^_mk_big:' "$WORK/aggregate-funcs.s" \
|
||||
|| fail "$opt: aggregate-funcs.s has no _mk_big"
|
||||
# No sret: a hand-written sret form is rejected by the target, and the
|
||||
# generated code must not contain an sret-register dance.
|
||||
if grep -q 'sret' "$WORK/aggregate-funcs.s"; then
|
||||
fail "$opt: aggregate-funcs.s mentions sret"
|
||||
fi
|
||||
|
||||
echo "== [$opt] compile the C driver (caller and C callee side)"
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
"$ROOT/scripts/tms-clang" "$opt" -o "$WORK/aggregate-main.ll" \
|
||||
"$DIR/aggregate-main.c" \
|
||||
|| fail "$opt: tms-clang failed for aggregate-main.c"
|
||||
|
||||
# Clang must classify record returns as direct/by-value. An sret pointer
|
||||
# argument would appear here as `sret(%struct...)`; the target's aggregate
|
||||
# lowering is by value and the 1987 ABI has no such argument. At -O2 the
|
||||
# named record types may be printed structurally (`{ i32, i16 }`), so
|
||||
# check that each C callee returns a non-void value instead of spelling
|
||||
# the type.
|
||||
if grep -q 'sret' "$WORK/aggregate-main.ll"; then
|
||||
fail "$opt: Clang emitted an sret pointer for an aggregate return"
|
||||
fi
|
||||
for fn in c_mksix c_mkbig c_mkouter c_mkuni c_mkmixed; do
|
||||
line=$(grep -E "^define .*@$fn\\(" "$WORK/aggregate-main.ll" || true)
|
||||
[ -n "$line" ] || fail "$opt: aggregate-main.ll has no $fn definition"
|
||||
case "$line" in
|
||||
*" void @$fn(")
|
||||
fail "$opt: $fn returns void (an indirect/sret form)" ;;
|
||||
esac
|
||||
done
|
||||
|
||||
"$TMS_LLC" -march=tms34010 "$opt" -filetype=asm "$WORK/aggregate-main.ll" \
|
||||
-o "$WORK/aggregate-main.s" || fail "$opt: llc failed for aggregate-main.ll"
|
||||
echo " aggregate-main.s: $(grep -c . "$WORK/aggregate-main.s") lines"
|
||||
|
||||
# The six C-side aggregate callees must be linked; the A8-free return
|
||||
# shape is covered by the runtime markers and m6-aggregate.ll.
|
||||
for fn in _c_mksix _c_mkbig _c_mkouter _c_mkuni _c_mkmixed _c_mkbits; do
|
||||
# Internal linkage adds a hash suffix to the symbol (LLVM's internal
|
||||
# name mangling), e.g. _c_mksix_CC884A0A.
|
||||
grep -Eq "^${fn}(_[0-9A-Fa-f]+)?:" "$WORK/aggregate-main.s" \
|
||||
|| fail "$opt: aggregate-main.s has no $fn"
|
||||
done
|
||||
|
||||
echo "== [$opt] assemble/link with GSPA/GSPLNK under DOSBox"
|
||||
cat "$DIR/aggregate-entry.asm" "$WORK/aggregate-funcs.s" \
|
||||
"$WORK/aggregate-main.s" > "$SDK/M6.ASM"
|
||||
sed 's/\r$//' "$DIR/aggregate-link.cmd" | sed 's/$/\r/' > "$SDK/M6.CMD"
|
||||
rm -f "$SDK/M6.OBJ" "$SDK/M6.OUT" "$SDK/M6.MAP" "$SDK/M6.LST" "$SDK/M6.LNK"
|
||||
|
||||
SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy \
|
||||
timeout "${DOSBOX_TIMEOUT:-300}" "$DOSBOX" -conf "$DOSBOX_CONF" \
|
||||
-noprimaryconf -nolocalconf \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M6 M6.obj M6.lst -l" \
|
||||
-c "gsplnk M6.cmd > M6.LNK" \
|
||||
-c "exit" -exit > "$WORK/dosbox.log" 2>&1 \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "$opt: DOSBox failed"; }
|
||||
|
||||
[ -f "$SDK/M6.LST" ] || fail "$opt: GSPA produced no listing (see $WORK/dosbox.log)"
|
||||
sed 's/\r$//' "$SDK/M6.LST" > "$WORK/m6.lst"
|
||||
grep -q 'No Errors' "$WORK/m6.lst" \
|
||||
|| { grep -i -B2 -A2 'error' "$WORK/m6.lst" >&2 || true; \
|
||||
fail "$opt: GSPA reported errors"; }
|
||||
grep -q 'No Warnings' "$WORK/m6.lst" \
|
||||
|| { grep -i -B2 -A2 'warning' "$WORK/m6.lst" >&2 || true; \
|
||||
fail "$opt: GSPA reported warnings"; }
|
||||
[ -f "$SDK/M6.OUT" ] \
|
||||
|| { if [ -f "$SDK/M6.LNK" ]; then cat "$SDK/M6.LNK" >&2; fi; \
|
||||
fail "$opt: GSPLNK produced no M6.OUT"; }
|
||||
[ -f "$SDK/M6.MAP" ] || fail "$opt: GSPLNK produced no M6.MAP"
|
||||
sed 's/\r$//' "$SDK/M6.MAP" > "$WORK/m6.map"
|
||||
cp "$SDK/M6.OUT" "$COFF"
|
||||
cp "$SDK/M6.ASM" "$WORK/m6.asm"
|
||||
|
||||
entry=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m6.map")
|
||||
[ "$entry" = "018A0000" ] || fail "$opt: linked _start is '$entry', want 018A0000"
|
||||
markers=$(awk '$2 == "_aggregate_markers" { print $1; exit }' "$WORK/m6.map")
|
||||
[ -n "$markers" ] || fail "$opt: linker map has no _aggregate_markers symbol"
|
||||
echo " _start=$entry _aggregate_markers=$markers"
|
||||
|
||||
# Both the hand-written and C-side aggregate entry points are linked.
|
||||
for sym in _mk_six _mk_five _mk_big _mk_pair _mk_outer _mk_uni \
|
||||
_sum_six _sum_big _sum_uni; do
|
||||
grep -q " $sym\$" "$WORK/m6.map" || fail "$opt: linker map has no $sym"
|
||||
done
|
||||
# The sret-free IR/asm is checked above; a map has no sret symbol text.
|
||||
|
||||
echo "== [$opt] run the COFF in MAME"
|
||||
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" \
|
||||
M2_LOADER_LUA="$LOADER_LUA" \
|
||||
AGGREGATE_MARKERS="$markers" \
|
||||
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 "$DIR/aggregate-check.lua" -autoboot_delay 0 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "$opt: MAME run failed"; }
|
||||
|
||||
MARKERS=$(grep -E '^M6 aggregate:' "$WORK/mame.log" | tail -1 || true)
|
||||
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; \
|
||||
fail "$opt: MAME produced no aggregate markers"; }
|
||||
echo " $MARKERS"
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; \
|
||||
fail "$opt: COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "$opt: COFF loader could not verify the placed .text bytes"
|
||||
grep -q '^M6 AGGREGATE MAME: PASS' "$WORK/mame.log" \
|
||||
|| { grep 'M6 aggregate: marker\|M6 AGGREGATE MAME' "$WORK/mame.log" >&2 || true; \
|
||||
tail -30 "$WORK/mame.log" >&2; \
|
||||
fail "$opt: aggregate marker check failed"; }
|
||||
|
||||
echo "M6 AGGREGATE ($opt): PASS"
|
||||
}
|
||||
|
||||
for opt in $AGGREGATE_OPTS; do
|
||||
run_one "$opt"
|
||||
done
|
||||
|
||||
echo "M6 AGGREGATE: PASS"
|
||||
Loaded 100 of 114 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user