Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
314ad047f4 | ||
|
|
429ac96405 | ||
|
|
73506844a8 | ||
|
|
9a99acb01e | ||
|
|
eb9ca73950 | ||
|
|
320e0117c1 | ||
|
|
7f1fc06bd8 | ||
|
|
c7e9e3a58b | ||
|
|
507dd6c615 | ||
|
|
2601c8485f | ||
|
|
cbe617e2c0 | ||
|
|
1fbf2a2598 | ||
|
|
f5facf7d28 | ||
|
|
1f6ac7820c | ||
|
|
61ed4ef070 | ||
|
|
817b6a03ec | ||
|
|
c779c7a725 | ||
|
|
4bb6ce7e4c | ||
|
|
ef8a8545ac | ||
|
|
536c80a797 | ||
|
|
8c1468978a | ||
|
|
537ed27d26 | ||
|
|
dfd13ab1c1 | ||
|
|
7fcae6e520 | ||
|
|
7fada4d9d7 | ||
|
|
d705e43d41 | ||
|
|
9916bbce92 | ||
|
|
12fa71d394 | ||
|
|
c6b437b738 | ||
|
|
28779e1800 | ||
|
|
20789d07f3 | ||
|
|
41c30eee99 | ||
|
|
e17c28a5d5 | ||
|
|
a7bbefad47 | ||
|
|
48091850e1 | ||
|
|
9694497548 | ||
|
|
e609a4b84e | ||
|
|
abbee9f42f | ||
|
|
d73dc9c020 | ||
|
|
5daf528128 | ||
|
|
48eb9bd248 | ||
|
|
f4442e8f6f | ||
|
|
848a570b4f | ||
|
|
16a7244bf6 | ||
|
|
2a95b71509 | ||
|
|
98eea9feb0 | ||
|
|
41ff4f68d2 | ||
|
|
55a0991529 | ||
|
|
d91785457f | ||
|
|
4a9636690f | ||
|
|
95b55dec97 | ||
|
|
739e48d8dd | ||
|
|
24eca1c080 | ||
|
|
b2dd323e71 | ||
|
|
8711dee37b | ||
|
|
8b6eed2510 | ||
|
|
b005cd13c4 | ||
|
|
30f0dd688e | ||
|
|
9700b5c44f | ||
|
|
8f28483868 | ||
|
|
4d2c2dce5c | ||
|
|
dd8c5ea3ce | ||
|
|
f340d74472 | ||
|
|
2a2efd61d7 | ||
|
|
66d21ebc35 | ||
|
|
1315df5548 | ||
|
|
af0c5cb617 | ||
|
|
bb78a97313 | ||
|
|
e55287f218 | ||
|
|
f9b51667c4 | ||
|
|
5214938b6b | ||
|
|
dc7de6f3a7 | ||
|
|
29c30ddcc6 | ||
|
|
dc94931eca | ||
|
|
0f7353c21c | ||
|
|
2157c24ef8 | ||
|
|
1eaabaa6a0 | ||
|
|
f471ab8c11 | ||
|
|
2835990a00 | ||
|
|
3c024b93b9 | ||
|
|
6e7d5bbe92 | ||
|
|
f8651fcb2f | ||
|
|
65e6a6e6b8 | ||
|
|
1e3977132d | ||
|
|
e540db3ca9 | ||
|
|
5f35a75a0a | ||
|
|
54608c0e32 | ||
|
|
11693186bc | ||
|
|
ff4cf94176 | ||
|
|
c756b568ae | ||
|
|
7d07fb787b | ||
|
|
98561252ad | ||
|
|
fe78805872 | ||
|
|
cdf137f64b | ||
|
|
38fdeb2e28 | ||
|
|
5757f056b0 | ||
|
|
9586ed21d1 | ||
|
|
a6379b206b | ||
|
|
5716e3ca35 | ||
|
|
0cab36a2b0 | ||
|
|
e7f8252470 | ||
|
|
3dccc4d188 | ||
|
|
e35cb154ce | ||
|
|
8b0b0bcd11 | ||
|
|
fefb1daba4 | ||
|
|
46417f53ec | ||
|
|
0075e57c0d | ||
|
|
38ab394c8b | ||
|
|
b21e762058 | ||
|
|
d7209392f2 | ||
|
|
e09d85c99f | ||
|
|
ad6b39738a | ||
|
|
4110a24c23 | ||
|
|
f79eadfda1 | ||
|
|
b0048b8151 | ||
|
|
773dd7597e | ||
|
|
e1436ba112 | ||
|
|
b313de480b | ||
|
|
9cf31b9b9b | ||
|
|
d3f411864d | ||
|
|
91d42be168 |
No files matched your search
@@ -0,0 +1,103 @@
|
||||
# TMS34010 M7.1 — Correctness and ABI Residuals Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Remove the remaining M6 correctness residuals: the `-O2` pointer over-scale, the sub-byte array/nested stride divergence, and the `.data` i64/aggregate/bitfield initializer gap, while keeping every M2–M6 gate green.
|
||||
|
||||
**Architecture:** The IR pipeline keeps the proven pre-opt bit scale, but replaces the scaled GEPs with opaque `@__tms_bitptr` calls so the optimizer cannot re-canonicalize them into already-bit GEPs. The post-opt pass scales only optimizer-created byte GEPs; a lowering pass then replaces the calls with `inttoptr(add(ptrtoint,...))` and a final instcombine restores the M0 folding. The sub-byte stride is diagnosed at compile time rather than silently byte-rounded. `.data` emission becomes recursive (i64, structs, unions, arrays, bitfields) in both raw and object modes.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m7`), C++17, Ninja, `llc`, `clang`, `tms-bitaddr`, `tms-clang`, TI COFF, GSPA/GSPLNK 2.00 under DOSBox, the dwt loader, MAME, `dis34`, `llvm-lit`/FileCheck.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §4.1–§4.2, §8 (M7.1), and the M6 plan/README boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Compiler work in `build/llvm-clean`, branch `m7` (from m6 `bdc16ab8d4b6`); project work in `tms-c-compiler`, branch `m7` (from m6 `9dc8f28`). No force-push, no merge into `m0`–`m6`, no default change.
|
||||
- Keep the TI all-stack ABI, the native TI-COFF/GSPLNK path, the asm oracle, the `dwt` loader, and every M2–M6 gate green.
|
||||
- MAME + the loader are the acceptance environment; real hardware is M7.3 and deferred.
|
||||
- Red/green TDD for every task; commit per task; no push until the M7.1 final review is clean, then push `m7`.
|
||||
- i64 `.data` words are little-endian (LSW first); the i64 argument/hidden-slot order stays MSW-first.
|
||||
- Do not silently byte-round a sub-byte record stride: the diagnostic must be loud (default-on warning/error).
|
||||
- Keep the narrow-load/store nonzero-offset guard from `bdc16ab8d4b6`.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **The bitptr barrier.** Does the optimizer see opaque calls (no folding through them), does the post-opt pass scale only byte GEPs, does the lowering restore the M0 `int_diff = 8/32` shape, and is `p += n` correct at the default `-O2` with one scale?
|
||||
2. **Sub-byte stride.** Does the diagnostic fire for the 1987 oracle `struct s arr[2]`/`struct nest`, not for byte-multiple records, and is the message actionable?
|
||||
3. **`.data` exactness.** i64 word order, packed struct/bitfield bytes, unions/arrays, relocations, raw and object modes; no over-read/write; unsupported shapes stay loud.
|
||||
4. **No M2–M6 regression** and the shim `memmove` workaround removed with the runtime gate proving the natural `d += n`.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: The `-O2` bit-pointer semantic barrier
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-bitaddr/bitscale.cpp` (`--bitptr`, `--lower-bitptr`, tests)
|
||||
- Modify: `tools/tms-bitaddr/tests/run.sh`, add `tests/bitptr.ll`
|
||||
- Modify: `scripts/tms-clang` (pipeline)
|
||||
- Modify: `scripts/tests/m5/conformance/shim.c` (remove the `memmove` workaround)
|
||||
- Create: `scripts/tests/m7/pointer-o2.sh` (C gate)
|
||||
- Test: `scripts/tests/m0/run.sh`, `scripts/tests/m6/runtime.sh`, the full M2–M6 gates
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M6 pre-opt `--scale` + post-opt `--scale` pipeline and the known `p += n` over-scale.
|
||||
- Produces: `@__tms_bitptr(i32 bitoff, ptr base)` (nounwind/readnone), `--bitptr`/`--lower-bitptr`, a pipeline that keeps opaque calls through `opt`, scales only post-opt byte GEPs, lowers the calls, and restores the M0 folding.
|
||||
|
||||
- [x] **Step 1: Write the failing tests.** Add `tests/bitptr.ll` to the `tms-bitaddr` suite: `--bitptr` turns `getelementptr i8, p, n` into a `@__tms_bitptr` call with the bit offset; `--lower-bitptr` turns it back into `inttoptr(add(ptrtoint p, n*8))`. Add `scripts/tests/m7/pointer-o2.sh`: a C driver with `char *p; p += n; *p = ...;` and the `memmove` overlap shape, compiled at `-O2`, linked with GSPA/GSPLNK, run in MAME, checking the correct bytes.
|
||||
- [x] **Step 2: Run it red.** The current pipeline double-scales (`%bit.off = shl n,3` twice / `p + n*64` bits) and/or the shim workaround is required; the new gate fails.
|
||||
- [x] **Step 3: Implement the barrier.** Add the `--bitptr`/`--lower-bitptr` modes; update `tms-clang` to clang → `--bitptr` → `opt` → `--scale` (post-opt byte GEPs) → `--lower-bitptr` → `opt -passes=instcombine` → output (at `-O0`: clang → `--bitptr` → `--lower-bitptr`); remove the shim `memmove` workaround (natural `d += n`).
|
||||
- [x] **Step 4: Run green.** `scripts/tests/m7/pointer-o2.sh`, `scripts/tests/m0/run.sh` (`int_diff` 8/32, `late` 24), `scripts/tests/m6/runtime.sh` both levels, the full TMS34010 lit suite, and the M2–M6 gates.
|
||||
- [x] **Step 5: Commit.** `tms-bitaddr` + `tms-clang` + shim + the gate.
|
||||
|
||||
### Task 2: Sub-byte array/nested stride diagnostic
|
||||
|
||||
**Files:**
|
||||
- Modify: `clang/lib/Basic/Targets/TMS34010.cpp/.h` (target hook/flag if needed)
|
||||
- Modify: `clang/lib/Sema/SemaType.cpp` / `SemaDecl.cpp` and `clang/include/clang/Basic/DiagnosticSemaKinds.td`
|
||||
- Create: `clang/test/Sema/tms34010-subbyte-stride.c` (or the target test location)
|
||||
- Create: `scripts/tests/m7/stride.sh`
|
||||
- Test: the oracle `struct s { unsigned a:3; unsigned b:5; int c:4; unsigned d:20; unsigned e:4; }` and `struct nest { struct s a; int b; }`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M4/M6 packed record layout (36-bit content, 5-byte `sizeof`).
|
||||
- Produces: a default-on diagnostic for arrays/nested members of records whose bit content is not a byte multiple, naming the byte-rounded and TI bit strides; no warning for byte-multiple records.
|
||||
|
||||
- [x] **Step 1: Write the failing test.** `stride.c` with `struct s arr[2];`, `struct nest n;`, and a byte-multiple control (e.g. `struct cross`); compile with `-Werror=tms34010-subbyte-stride`; the first run has no diagnostic (red).
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.** Compute the record bit content (last field bit offset + width, recursively for nested fields) and diagnose an array element/nested field whose content is not a byte multiple. A warning is the acceptance; an implementation of the bit-content stride is optional only if sound.
|
||||
- [x] **Step 4: Run green.** `stride.sh`; the Sema test; M4/M5/M6 layout/bitfield/aggregate gates.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 3: `.data` i64/aggregate/bitfield initializers
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010AsmPrinter.cpp` (raw and object initializers)
|
||||
- Create: `llvm/test/CodeGen/TMS34010/m7-data-initializers.ll`
|
||||
- Create: `scripts/tests/m7/data.sh` (C + MAME, raw bytes)
|
||||
- Test: the M5 object/native gates and the M6 runtime/conformance subset
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M5 `.data` emitter (integers ≤32, f32/f64, pointers, byte arrays, zero).
|
||||
- Produces: recursive struct/union/array/aggregate-zero emission and i64 two-word LSW-first emission in raw and object modes, with relocations; the existing unsupported-type diagnostics stay.
|
||||
|
||||
- [x] **Step 1: Write the failing test.** `m7-data-initializers.ll` and `data.sh` with `long long x = 0x1122334455667788;`, a packed struct, a bitfield struct, a union, an array of structs, and a pointer field; the current emitter rejects them (`M2 .data ...`).
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.** Extend `emitDataInitializer` and `emitDataInitializerObject` recursively; i64 LSW-first; exact packed sizes; relocations; keep vectors/i128/unsupported loud.
|
||||
- [x] **Step 4: Run green.** `data.sh` (raw bytes/MAME), the object path, `m5/native.sh`, `m5/object-smoke.sh`, the M6 runtime/conformance gates.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Docs, full gates, final review, push M7.1
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`
|
||||
- Test: the full M2–M7.1 gate list
|
||||
|
||||
- [x] **Step 1: Update the docs** for the bitptr barrier, the stride diagnostic, `.data` coverage and the new gate counts; keep the M7.2–M7.4 boundary.
|
||||
- [x] **Step 2: Run every gate** (M2–M6 full list + `scripts/tests/m7/*`; lit; conformance; generic).
|
||||
- [x] **Step 3: Commit, final whole-branch review, then push `m7`.** No default change.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M7.1 removes the default-`-O2` correctness risk and the M6 `.data`/stride gaps. M7.2 owns debug info and the native linker; M7.3 the wider Xlib/stderr/hardware; M7.4 the full external suites and performance. The compiler repo is canonical; the project holds the harness, plans and gates.
|
||||
@@ -0,0 +1,119 @@
|
||||
# TMS34010 M7.2 — Object/Debug (Native Linker and TI-COFF Debug Info) Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Close the M7.2 object/debug residuals: emit real debug information in the native TI-COFF object, and replace the GSPLNK dependency for the native path with `tools/tms-link`, including `.cinit` and public names longer than GSPA's 31-character limit, while keeping the GSPLNK output as the oracle.
|
||||
|
||||
**Architecture:** The MC object writer becomes a small TI-COFF **linker input** producer: optional `.cinit`, optional non-allocated `.debug_*` sections with long names, and the existing `.text`/`.data`/`.bss`. `llc` gains DWARF emission by setting `SupportsDebugInformation`; the asm path is unchanged because the compiler only emits debug for object output and existing IR has no `!dbg`. A new Python linker (`tools/tms-link`) reads those objects, lays out the four sections, resolves symbols and R-RELLONG fixups, and writes a position-dependent linked image the existing dwt loader accepts. Debug sections are stripped from the load image by default and kept with `--keep-debug` for `llvm-dwarfdump`.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m7`), C++17, Ninja, `llc`, `llvm-dwarfdump`, TI COFF, GSPA/GSPLNK 2.00 under DOSBox, the dwt loader, MAME, `dis34`, Python 3, `llvm-lit`/FileCheck.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M7.2), §4.1–§4.2 (ABI) and §7.8 (tooling); the M7.1 plan/README boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Compiler work in `build/llvm-clean` (branch `m7`, base the M7.1 push `065998da6f3c`); project work in `tms-c-compiler` (branch `m7`, base `e09d85c`). No force-push, no merge into `m0`–`m6`, no default change.
|
||||
- Keep the TI all-stack ABI, the asm oracle (GSPA/GSPLNK), the dwt loader, and every M2–M7.1 gate green.
|
||||
- The default native gate must keep linking the M5/M6 objects with GSPLNK until the `tms-link` oracle gate proves byte equality; then the gates may link with `tms-link` where they exercise it, while at least one gate keeps GSPLNK as the oracle each run.
|
||||
- `.cinit` is the TI init-record table (`u16 word count`, `u32 destination`, data words), not a raw image. Do not invent a second format.
|
||||
- Debug info is object-path only. `-filetype=asm` must not gain `.loc`/`.debug_*` output that GSPA cannot assemble.
|
||||
- Public names are not truncated on the object path; GSPA's 31-character truncation stays an asm-path limitation.
|
||||
- MAME + the loader are the acceptance environment; real hardware is M7.3 and deferred.
|
||||
- Red/green TDD; commit per task; no push until the M7.2 final review is clean.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **TI-COFF exactness.** Section order, bit sizes, long names (`/offset`), `.cinit` flags, `.debug_*` flags 0, relocations in debug sections, optional header fields. Existing three-section objects must be byte-identical when no `.cinit`/debug is present.
|
||||
2. **Debug validity.** `llvm-dwarfdump` reads the kept `.debug_*` sections after linking; line tables name the source and lines; low-PC values equal the linked addresses; the default image is stripped.
|
||||
3. **Linker correctness.** Relocation addends (same-section `0xFFFF`, section-symbol and undefined-external forms), alignment/placement, duplicate/undefined symbols, long names, `.cinit` placement, map, and loader acceptance.
|
||||
4. **Oracle equality.** `tms-link` vs GSPLNK: allocated section bytes and symbol addresses identical for the M5/M6 objects; no gate silently drops one side.
|
||||
5. **No M2–M7.1 regression** and no asm-output change.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: TI-COFF writer: `.cinit`, debug sections, long names
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCObjectWriter.{h,cpp}`
|
||||
- Modify: `llvm/lib/Target/TMS34010/MCTargetDesc/TMS34010MCAsmInfo.cpp` (`SupportsDebugInformation`)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (explicit `.cinit` section lowering if needed)
|
||||
- Create: `llvm/test/CodeGen/TMS34010/m7-cinit-section.ll`, `m7-debug-info.ll`
|
||||
- Test: the full TMS34010 lit suite; the M5 object/native gates unchanged
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M7.1 writer (three sections, `/`-less names, bit sizes, R-RELLONG).
|
||||
- Produces: optional `.cinit` (data flags `0x40`, after `.data`, only when non-empty), optional `.debug_*` sections (flags `0`, long names via the COFF string table), long section names in headers, and DWARF emission from `llc -filetype=obj` when the module has `!dbg`.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** `m7-cinit-section.ll`: a global in `section ".cinit"` plus a normal function; `llc -filetype=obj` must produce a fourth section named `.cinit` with the correct bytes/relocation. `m7-debug-info.ll`: a function with `!dbg` locations; `llc -filetype=obj` must produce `.debug_line`/`.debug_info` (long names). A small parser (the project `coff.py` or a new `tools/tms-link/tmscoff.py`) asserts the sections; the current writer fails (`.cinit` has no representation; debug unknown).
|
||||
- [x] **Step 2: Run red.** Both objects fail as expected; the three-section objects stay unchanged.
|
||||
- [x] **Step 3: Implement.**
|
||||
- Make the section list dynamic: `.text`, `.data`, `.cinit` (if present), `.bss`; emit section symbols/aux for each used section; keep `.text` required only when the module has code.
|
||||
- Section headers: names >8 bytes become `/` + decimal string-table offset; build the string table before writing headers (symbols already share it). The string table starts with its own 4-byte size.
|
||||
- Debug: set `SupportsDebugInformation = true`; accept non-empty sections whose names start with `.debug_` (and `.debug_*` from the DwarfDebug path), flags 0, with R-RELLONG relocations; keep unknown non-debug sections loud. Omit empty debug sections so existing objects stay three sections.
|
||||
- Keep `-filetype=asm` free of DWARF: the asm path has no `!dbg` in every existing gate; document that debug is object-only. If AsmPrinter emits `.loc` with debug IR in asm mode, gate it off (target AsmPrinter check) rather than weakening GSPA acceptance.
|
||||
- `.cinit` explicit section: ensure `__attribute__((section(".cinit")))` and `section ".cinit"` IR lower to an MC section named `.cinit`.
|
||||
- [x] **Step 4: Run green.** New lit tests; full lit (107 + new); `m5/object-smoke.sh`, `m5/native.sh`, `m5/native-link.sh`; `m7/data.sh` (byte-identical objects); the three-section assertion in `m5/native-link.sh` stays.
|
||||
- [x] **Step 5: Commit** (compiler + any project test parser).
|
||||
|
||||
### Task 2: `tools/tms-link` native linker
|
||||
|
||||
**Files:**
|
||||
- Create: `tools/tms-link/tms-link` (Python 3 CLI), `tools/tms-link/tmscoff.py` (reader/writer)
|
||||
- Create: `tools/tms-link/tests/run.sh` (+ fixtures)
|
||||
- Create: `scripts/tests/m7/link.sh` (linker unit/self-test gate)
|
||||
- Modify: `scripts/m4/run.sh` (`M4_LINKER=tms-link` opt-in path; default GSPLNK)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: one or more relocatable TI-COFF objects (Task 1), the entry object, and the M4/M5 defaults (`.text` `018A0000`, `.bss` `01A00000`, `prog`/`ram`).
|
||||
- Produces: `tms-link -o OUT [--map MAP] [--entry SYM] [--text ADDR] [--data ADDR] [--cinit ADDR] [--bss ADDR] [--keep-debug|--strip-debug] OBJ...`; a linked position-dependent COFF (`nreloc=0`, optional header populated), a map (`%08x %s` lines + `ENTRY POINT SYMBOL: "..."`), symbol resolution for long public names, `.cinit` placement after `.data`, and loud duplicate/undefined/unsupported-relocation errors.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** Feed it two tiny relocatable objects produced by `llc` (one defining a global/function, one referencing it) plus a `.cinit` object; assert the linked section addresses, resolved fields, map lines, and `nreloc=0`. Feed it a duplicate definition, an undefined external and an R-RELWORD and require loud failures.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Reader: mirror `vendor/vt1200/dwt/loader/coff.py` (header, sections, long names, symbols with aux, relocations).
|
||||
- Layout: `.text` at the text origin; `.data` immediately after (`align 16` bits); `.cinit` after `.data`; `.bss` at the bss origin. Sections are word-aligned; sizes stay in bits; `.bss` is virtual.
|
||||
- Symbols: section symbols get the output paddr; defined globals get paddr + section-relative value; undefined externals resolve to the unique definition; locals are resolved from their section. Public long names are preserved byte-for-byte.
|
||||
- Relocations: for each R-RELLONG, read the 32-bit field (the bit addend), resolve `S` from the symbol index (`0xFFFF` = the section base), write `S + addend`. Leave no relocations in the output.
|
||||
- Optional header: magic `0x0108`, vstamp `199`, text/data/bss sizes and starts, entry symbol; match GSPLNK's shape.
|
||||
- Debug: strip `.debug_*` by default; `--keep-debug` copies them with their relocations resolved against the linked addresses. Refuse more than one debug-bearing object in M7.2 with a clear message.
|
||||
- Map: section allocation and global symbol addresses in a stable,
|
||||
greppable form. Source-line ranges are the kept `.debug_*` data (`.debug_line`)
|
||||
validated with `llvm-dwarfdump` in Task 3; the linker does not parse DWARF
|
||||
for the text map.
|
||||
- [x] **Step 4: Run green.** `tools/tms-link/tests/run.sh`, `scripts/tests/m7/link.sh`; link `scripts/m5/native-link.c` + the GSPA entry object and compare allocated bytes/symbol addresses with GSPLNK.
|
||||
- [x] **Step 5: Commit** (project; plus the `M4_LINKER` hook).
|
||||
|
||||
### Task 3: End-to-end object tests and the GSPLNK oracle
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m7/oracle.sh` (both linkers, byte/symbol comparison, MAME)
|
||||
- Create: `scripts/tests/m7/cinit.sh`, `scripts/m7/cinit-entry.asm`, `scripts/m7/cinit.c`
|
||||
- Create: `scripts/tests/m7/longname.sh`, `scripts/m7/longname-a.c`, `scripts/m7/longname-b.c`
|
||||
- Create: `scripts/tests/m7/debug.sh`, `scripts/m7/debug.c`, `scripts/m7/elf-debug-wrap.py` (test-only ELF wrapper for `llvm-dwarfdump`)
|
||||
- Modify: `scripts/tms-clang` (`-g` pass-through) if needed
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1's debug objects, Task 2's linker and `M4_LINKER` hook.
|
||||
- Produces: gates that prove (a) `tms-link` == GSPLNK on the allocated image, (b) `.cinit` records are placed/relocated and the entry copies them in MAME, (c) a 40-character public function links and runs across two TUs, (d) the kept debug image validates with `llvm-dwarfdump` and the default image is stripped.
|
||||
|
||||
- [x] **Step 1: Write the failing gates.** `oracle.sh` links the M5 native objects both ways and requires identical `.text`/`.data`/`.bss` bytes and symbol values, plus the existing MAME markers. `cinit.sh` builds a C `.cinit` table, links with `tms-link`, and requires the entry's copy loop to write the expected words in MAME. `longname.sh` defines/calls a >31-character public symbol across two TUs. `debug.sh` compiles with `-g`, links `--keep-debug`, wraps the `.debug_*` sections in a minimal ELF container, and runs `llvm-dwarfdump` for the filename/line/address; it also asserts the default link has no debug sections and the image runs.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement the gates and any missing plumbing** (`tms-clang -g`, `M4_LINKER`, the ELF wrapper, the entry/cinit fixture). Keep each gate runnable alone and serial with MAME.
|
||||
- [x] **Step 4: Run green.** All four gates, the M5 object/native gates and the M7.1 gates.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Docs, full gates, final review, push M7.2
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`
|
||||
- Test: the full M0/M2–M7.2 list
|
||||
|
||||
- [x] **Step 1: Update the docs** for the debug format and validation path, the native linker (CLI, layout, map, `.cinit`, long names, strip/keep debug), the oracle comparison, the single-debug-TU limit, and the new counts. Correct the M6/M7.1 `.cinit`/debug/native-linker limitation text.
|
||||
- [x] **Step 2: Run every gate** (M0, M2–M7.2; lit CodeGen + MC + clang Sema/CodeGen; GSPLNK oracle). Record exact counts.
|
||||
- [x] **Step 3: Commit, final whole-branch review, then push `m7`.** No default change.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M7.2 makes the native path self-contained: `llc` objects carry `.cinit` and debug data, `tms-link` replaces GSPLNK for linking, and the GSPLNK image is the permanent oracle. M7.3 owns the wider Xlib surface, stderr capture and hardware; M7.4 the full external suites, performance and the final boundary. The compiler repo is canonical; the project holds the linker, harness, plans and gates.
|
||||
@@ -0,0 +1,113 @@
|
||||
# TMS34010 M7.3 — Runtime and Hardware (Wider Xlib, stderr, Hardware Harness) Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Widen the validated VT1200 Xlib surface and exercise it in MAME, add real stderr capture to the conformance harness, and deliver the real-hardware marker harness with its MAME-equivalent acceptance while the unit is unavailable.
|
||||
|
||||
**Architecture:** The Xlib surface stays ROM-import based: each new entry is validated against the v2.2 image with `validate-syms.sh`, declared in `scripts/m4/x11m4.h`, and used by a new client (`xmore`) that MAME runs through the existing loader. The conformance shim gains a second sink and length cell for `stderr`, with the runner/check-lua comparing it exactly. The hardware harness is a thin wrapper around the already-proven `dwt/loader/hostload.py --marker` path: it links the marker client at the real-unit origins, validates the same marker cells in MAME, and invokes hostload only when `VT1200_HOST` is set.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m7`), `tms-clang`, `llc`, GSPA/GSPLNK 2.00 under DOSBox, `tms-link`, TI COFF, the dwt loader, MAME, `dis34`, Python 3, `llvm-lit`.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M7.3), §7.7 (Xlib/ROM imports), §7.9; the M7.2 plan/README boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Project work in `tms-c-compiler` (branch `m7`, base the M7.2 push `3dccc4d`); compiler unchanged (`3c39d1d82190`) unless a real target bug appears.
|
||||
- Keep every M2–M7.2 gate green, the TI all-stack ABI, the asm oracle, the native path, and the default `m6` branch.
|
||||
- New Xlib addresses must pass `scripts/m4/validate-syms.sh` (ROM range, 16-bit aligned, real prologue) and come from the Ghidra/dis34 table; never guess.
|
||||
- stderr is a second stream: stdout bytes/markers stay byte-identical for existing tests; an empty stderr is the default.
|
||||
- The hardware run is **DEFERRED**: the gate must pass without a unit (MAME-equivalent acceptance) and must not mark the milestone blocked. `VT1200_HOST` enables the real run.
|
||||
- MAME + the loader are the acceptance environment. Run MAME gates serially.
|
||||
- Red/green TDD; commit per task; no push until the M7.3 final review is clean.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Xlib correctness:** each new symbol address is justified and validated; the client uses the correct X11R4 argument shapes; markers prove the calls actually ran (not just returned); no X errors; existing xshow/termtris unchanged.
|
||||
2. **stderr exactness:** separate buffer/length/magic, no aliasing with stdout, truncation semantics, runner comparison (`--expect-stderr` and `;stderr=`), empty default, and the selftest red cases.
|
||||
3. **Hardware harness honesty:** the COFF uses the proven hardware origins, the marker cells match `hostload.py`, the MAME check reads the same cells, and the deferred path is explicit and non-blocking.
|
||||
4. **No M2–M7.2 regression** and no change to the default linker/ABI.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Wider Xlib surface
|
||||
|
||||
**Files:**
|
||||
- Modify: `symbols/vt1200-v22.syms` (new validated entries)
|
||||
- Modify: `scripts/m4/x11m4.h` (prototypes/structs)
|
||||
- Create: `scripts/m7/xmore.c`, `scripts/m7/xmore-check.lua`
|
||||
- Create: `scripts/tests/m7/xlib.sh`
|
||||
- Test: `scripts/m4/validate-syms.sh`, the existing xshow/termtris gates
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the v2.2 ROM import table and the M4 Xlib ABI (`Display`, `XImage`, events).
|
||||
- Produces: validated `XMapSubwindows`, `XChangeWindowAttributes`, `XConfigureWindow`, `XInternAtom`, `XChangeProperty`, `XChangeGC` entries (addresses from `vendor/vt1200/dwt/notes/GUI_APPS.md`), prototypes, and an `xmore` client whose markers prove subwindow mapping, configure, atom/property changes, GC change, text (`XLoadFont`/`XDrawString`), drawing, and a heap `XCreateImage`/`XGetImage`/`XPutImage`/`XDestroyImage` round trip with no X errors.
|
||||
|
||||
- [x] **Step 1: Write the failing gate.** `xlib.sh` compiles `xmore.c` with `tms-clang`/`llc`, links via the M4 harness, loads it in MAME, and requires markers (window, child, GC, atom, property, configure, image, errors=0) plus a screenshot pixel check; `validate-syms.sh` currently rejects the new symbols.
|
||||
- [x] **Step 2: Run red.** `validate-syms.sh` fails on the missing entries; `xmore` does not link.
|
||||
- [x] **Step 3: Implement.**
|
||||
- Add the six addresses with the GUI_APPS evidence; run `validate-syms.sh`.
|
||||
- Declare the prototypes (`XWindowChanges`/`CW*` bits, `XInternAtom`, `XChangeProperty`, `XChangeGC` values) in `x11m4.h` without disturbing the existing ABI assertions.
|
||||
- Write `xmore.c`: one parent + child, `XMapSubwindows`, `XConfigureWindow` (move/resize), `XInternAtom("WM_NAME")`, `XChangeProperty`, `XChangeWindowAttributes` (background), `XChangeGC` (foreground), `XLoadFont`/`XDrawString`, draw a rectangle/image, `XCreateImage` on the heap, `XGetImage` a small region, `XPutImage`, `XDestroyImage`, `XSync`; markers at `0x018A8000 + n*0x20`; error handler counts X errors.
|
||||
- If a call is genuinely unusable (e.g. `XGetImage` blocks on the emulated server), keep it in the surface/test with a documented skip marker rather than silently dropping it.
|
||||
- [x] **Step 4: Run green.** `xlib.sh`, `validate-syms.sh`, the M4 xshow/termtris/symbols gates, and the M7.2/M6/M5 gates touched by the harness.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 2: stderr capture
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tests/m5/conformance/shim.c` (stderr stream, fprintf/fputs/fputc/fwrite)
|
||||
- Modify: `scripts/tests/m5/conformance/conformance-check.lua` (err_len/err buffer)
|
||||
- Modify: `scripts/tests/m5/conformance/run.sh` (`--expect-stderr`, `;stderr=` parsing/comparison)
|
||||
- Modify: `scripts/tests/m5/conformance/selftest.sh` (empty/formatted/truncated stderr cases)
|
||||
- Test: the conformance selftest, c-testsuite/c-torture smoke, the M6 runtime gate
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the shim's `CONF_OUT`/`CONF_LEN`/`CONF_MAGIC` result block.
|
||||
- Produces: `stderr` as a real `FILE *` target with `fprintf`/`vfprintf`/`fputs`/`fputc`/`fwrite`, a second buffer (`01B30000`, 16 KiB) and length (`01B00060`), runner expectation support, and selftests proving exact comparison and truncation rejection.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** Add selftest sources that write `fprintf(stderr, ...)`; the runner rejects `--expect-stderr` (unknown option) and the shim has no stderr.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Represent `stdout`/`stderr` as distinct sink descriptors; `printf` continues the stdout stream; stderr has its own buffer/length and the same 16 KiB cap.
|
||||
- Implement the write surface (return value = untruncated length, bytes capped) and `fprintf` via the existing formatter; declare `stderr` in the shim and any headers.
|
||||
- Extend the check lua to read `ERRLEN`/`ERR` and write `errlen=`/`err=`; extend the runner's spec parser and comparison, preserving `stdout` defaults.
|
||||
- Selftests: empty stderr passes; expected formatted stderr passes/fails correctly; `errlen >= CAP` is rejected as truncation.
|
||||
- [x] **Step 4: Run green.** conformance selftest, the c-testsuite/c-torture gates (no changed stdout), the M6 runtime gate.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 3: Real-hardware harness with MAME-equivalent acceptance
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/m7/hwmark.c` (or `.s`), `scripts/m7/hw-entry.asm`
|
||||
- Create: `scripts/tests/m7/hardware.sh`, `scripts/m7/hw-check.lua`
|
||||
- Test: the M4/M5 loader path; `dwt/loader/hostload.py` dry contract; no real unit required
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the proven hardware origins (`.text 018C0000`, `.data 018D0000`, `.bss 018D8000`) and `hostload.py`'s `MARKER_CELLS` (`018E0000` start, `018E0020` data=0xDEADBEEF, `018E0040` data2=0x12345678, `018E0060` bss=0, `018E0080` live counter).
|
||||
- Produces: a marker COFF (linked with `tms-link` or GSPLNK), a MAME run that checks the same cells through the loader, and a guarded real-hardware invocation: `VT1200_HOST=... scripts/tests/m7/hardware.sh` runs `hostload.py --marker --coff ...`; without it the gate prints `HARDWARE: DEFERRED` and passes on the MAME evidence.
|
||||
|
||||
- [x] **Step 1: Write the failing gate.** `hardware.sh` requires the marker cells in MAME and prints the deferred marker; no marker client exists yet.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Build the marker client at the hardware origins (entry sets STK/FP, calls `_main`, writes the sentinels and a live counter; `.data` holds the sentinels).
|
||||
- MAME: link/load/run the same COFF (loader.lua + `hw-check.lua`), assert the five cells and loader status 0.
|
||||
- Real path: invoke `dwt/loader/hostload.py` with `--coff`, `--marker`, `--host "$VT1200_HOST"`, and an evidence directory; propagate its failures. Do not fake a hardware pass; without the host, `HARDWARE: DEFERRED`.
|
||||
- Document the unit's MAC/IP/host assumptions and the deferred status.
|
||||
- [x] **Step 4: Run green.** `hardware.sh` (MAME + deferred), the M4/M5 native gates.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Docs, full gates, final review, push M7.3
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`
|
||||
- Test: the full M0/M2–M7.3 list
|
||||
|
||||
- [x] **Step 1: Update the docs** for the wider Xlib table and client, the stderr protocol (`01B00060`/`01B30000`), the hardware harness/origins/deferred status, and the new gate counts.
|
||||
- [x] **Step 2: Run every gate** (M0, M2–M7.3; lit; clang; conformance; generic; validate-syms; xshow/termtris). Record exact counts.
|
||||
- [x] **Step 3: Commit, final whole-branch review, then push `m7`.** No default change.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M7.3 completes the runtime surface and makes the hardware campaign reproducible while the unit is away. M7.4 owns the full external suites, performance and the final M7 boundary. The compiler repo is canonical for target code; this project repo holds the Xlib table, harness, plans and gates.
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
# TMS34010 M7.4 — Conformance, Performance and the M7 Boundary Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Close M7 with the full pinned external corpora, an i64 divide/remainder fast path with measured evidence, and the final M7 docs/counts/limitations/M8 boundary.
|
||||
|
||||
**Architecture:** A full-suite driver runs every file in the two pinned corpora through the existing conformance classifier and runner with the fast native loader settings, records per-test pass/skip/failure-category, and proves no unclassified crashes. The i64 division outliner gains a branch: when both operands' high words are zero it uses one 32-bit `DIVU`/`DIVS` (via i32 div/rem in IR) instead of the 64-step restoring loop; signed forms reuse the absolute-value normalization. A frame/cycle-based gate measures the small-divisor workload against the loop path.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m7`), `tms-clang`, `llc`, `tms-link`, TI COFF, the dwt loader, MAME, `dis34`, Python 3, `llvm-lit`/FileCheck, the conformance harness, GCC 16.2.0/c-testsuite pins.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M7.4), §7.9; the M7.3 plan/README boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Project work in `tms-c-compiler` (branch `m7`, base the M7.3 push `54608c0`); compiler work in `build/llvm-clean` (branch `m7`, `bbec928ba807`).
|
||||
- Keep every M2–M7.3 gate green, the TI all-stack ABI, the native path, the asm oracle, and the default `m6` branch.
|
||||
- Full-suite runs use the pinned corpora under `vendor/conformance` and the fast loader settings (`LOADER_AT=200`, `LOADER_END=1000`) in `native` mode; the default conformance gates keep their existing settings.
|
||||
- A test that is classifier-supported but fails must get an honest per-test skip reason or a recorded failure category; never count a skip as a pass. No MAME/loader crash.
|
||||
- The i64 fast path must preserve every M6 i64 semantic (signed truncation, remainder sign, divide-by-zero undefined) and the existing `m6-i64.ll` checks.
|
||||
- No push until the M7.4 final review is clean; default stays `m6`.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Full-suite honesty:** all 1,692 + 220 files accounted for; classifier-supported pass/skip/failure categories exact; no crash counted as pass; the report/log retained.
|
||||
2. **Fast path correctness:** the high-word check, zero divisor, signed normalization, 64-bit results, and the slow path unchanged; `m6-i64` and the runtime gate green.
|
||||
3. **Measurement:** the perf gate compares the fast path against a genuine slow-path workload, not a compile-time constant fold; the metric is reproducible.
|
||||
4. **No regression** and the final docs/boundary are accurate.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Full-suite harness and baseline run
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m7/full-suite.sh` (driver + report)
|
||||
- Create: `scripts/tests/m7/full-suite.skip` (generated/triaged skip reasons; Task 3 fills failures)
|
||||
- Test: the existing conformance runner/classifier; c-testsuite/c-torture smoke
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute/*.c` (1,692) and `vendor/conformance/c-testsuite/tests/single-exec/*.c` (220), `scripts/tests/m5/conformance/{run.sh,classify.sh}`.
|
||||
- Produces: `full-suite.sh [--corpus c-torture|c-testsuite|all] [--jobs 1]` with `LOADER_AT=200 LOADER_END=1000`, `--mode native`, per-test `pass/skip/fail:<category>` rows, a summary (`total/pass/skip/fail/crash`), and a retained log/report; a nonzero exit only on a crash or an unclassified failure.
|
||||
|
||||
- [x] **Step 1: Write the failing driver.** It builds sorted full lists, runs the runner with `--classify --mode native --expect-status 0 --ignore-output` (c-torture) and the `.expected` comparison (c-testsuite), and prints a summary. The first run has no triage file and fails on the known failing tests.
|
||||
- [x] **Step 2: Run a bounded sample red.** Pick 20 c-torture files and show pass/skip/fail; the failing ones are the red evidence.
|
||||
- [x] **Step 3: Implement.** Run tests serially (MAME); classify skips; categorize failures (compile/diagnostic, loader status, mismatch, timeout) into a stable `fail:<category>` form; write `full-suite-results.tsv`, `full-suite-report.txt`, and the per-test logs under a work directory; never treat a skip as a pass. Keep the default conformance gates untouched.
|
||||
- [x] **Step 4: Run the full c-testsuite (220) and start/complete the full c-torture (1,692).** Record exact counts; the run may take hours, so retain the log and resume from completed rows if interrupted (idempotent per id).
|
||||
- [x] **Step 5: Commit** the driver (and the initial results summary).
|
||||
|
||||
### Task 2: i64 divide/remainder fast path
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (`TMS34010LowerI64::lowerDivRem`)
|
||||
- Modify: `llvm/test/CodeGen/TMS34010/m6-i64.ll` (fast-path checks) or create `m7-i64div-fast.ll`
|
||||
- Create: `scripts/m7/i64div-perf.c`, `scripts/m7/i64div-perf-check.lua`, `scripts/tests/m7/i64div.sh`
|
||||
- Test: `scripts/tests/m6/i64.sh`, the M6 runtime gate, `m6-i64.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the inline restoring-division outliner (`lowerDivRem`, 64 iterations) and the target `DIVU`/`DIVS`.
|
||||
- Produces: a pre-check `(N >> 32) == 0 && (D >> 32) == 0`; on that path, `zext(udiv/urem (trunc N), (trunc D))` (32-bit `DIVU`) for unsigned, and for signed after the absolute-value normalization, with the same sign correction; the loop otherwise unchanged. A perf gate that measures a small-divisor workload (fast path) against a high-word-divisor workload (loop) using MAME frames/cycles or an equivalent instrumented counter.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** `m7-i64div-fast.ll` requires the 32-bit `DIVU`/`DIVS` fast path (and the loop label still present); the perf gate requires the small-divisor workload to complete in materially fewer frames/iterations than the slow path. Current output has only the loop.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement** the fast path in `lowerDivRem`, keeping the zero-divisor undefined behavior, signed truncation and remainder sign; verify the IR/asm.
|
||||
- [x] **Step 4: Run green.** The new lit test, the perf gate, `m6/i64.sh`, `m6/runtime.sh`, the M7.2/M7.3 gates.
|
||||
- [x] **Step 5: Commit** (compiler + project).
|
||||
|
||||
### Task 3: Full-suite triage, skip curation and exact counts
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tests/m7/full-suite.skip` (per-test honest reasons)
|
||||
- Modify: `scripts/tests/m7/full-suite.sh` (summaries/categories)
|
||||
- Create: `scripts/tests/m7/full-suite-report.txt` (retained)
|
||||
- Test: the full-suite driver (idempotent resume), no crashes
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: Task 1's per-test results.
|
||||
- Produces: every failing test either fixed or skipped with a feature/curation reason; exact total/pass/skip/fail-category counts for both corpora; a retained report reproducible from the pins.
|
||||
|
||||
- [x] **Step 1: Triage** the failures by root cause; fix cheap target/driver issues; otherwise add a per-test `full-suite.skip` reason (one line each) and re-run only those.
|
||||
- [x] **Step 2: Verify** the full results: no crash, no unclassified failure, every skip has a reason and is classifier-consistent.
|
||||
- [x] **Step 3: Record the exact counts** and anomalies in the report.
|
||||
- [x] **Step 4: Commit.**
|
||||
|
||||
### Task 4: Final M7 docs, full gates, final review, push M7.4/M7
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (M7 status)
|
||||
- Test: the full M0/M2–M7.4 list
|
||||
|
||||
- [x] **Step 1: Update the docs** for the full-suite method/counts/skips, the i64 fast path and measurement, the complete M7 counts/limitations, and the M7/M8 boundary. Mark M7 complete (M8 owns multi-TU DWARF merging, `.lib` linking, hardware completion, remaining performance).
|
||||
- [x] **Step 2: Run every gate** (M0, M2–M7.4; lit; clang; conformance; full suites; perf; generic). Record exact counts.
|
||||
- [x] **Step 3: Commit, final whole-branch review, then push `m7`.** No default change.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M7.4 closes the conformance and performance surface and freezes the M7 boundary. M8 owns the remaining object/debug depth (multi-TU DWARF), `.lib` linking, the hardware run once the unit returns, and any further performance work.
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
# TMS34010 M8 — Native Archives, Multi-TU DWARF, Conformance Depth and Hardware Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Close the M7/M8 boundary: make `tms-link` read the 1990 TI-COFF archives so the native path no longer needs GSPLNK for `flib`/`rts`, merge debug information from multiple translation units, deepen the conformance pass rate and performance evidence, and close out M8 with the hardware status and boundary.
|
||||
|
||||
**Architecture:** `tms-link` gains an `ar` reader with iterative selective extraction over its existing TI-COFF object model, then a DWARF merge stage that rehomes section-relative offsets and relocations across objects. The conformance/perf work uses the existing full-suite driver and the i64 measurement harness. The hardware harness already exists; M8.4 only runs it if the unit is available and records the result.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m8`), `tms-clang`, `llc`, `tms-link`, TI COFF and `ar` archives, the dwt loader, MAME, `dis34`, `llvm-dwarfdump`, Python 3, the conformance harness, GCC 16.2.0/c-testsuite pins.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M8.1–M8.4); the M7 README/ledger boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- M8 baseline: compiler `llvm-tms34010` `m7` at `e924e0c86343`, project `tms-c-compiler` `m7` at `0f7353c`; work on `m8` in both repos. `m7` remains the repository default unless the user asks; no force-push and no merge into `m0`–`m7`.
|
||||
- Keep every M2–M7.4 gate green, the TI all-stack ABI, the asm/GSPLNK oracle, and the native loader contract (`nreloc=0` linked image).
|
||||
- `.lib` archives are test/runtime inputs; do not vendor them. The 1990 `flib.lib`/`rts.lib` are System V `ar` (`!<arch>`) with TI-COFF members.
|
||||
- Debug merging must keep section-relative DWARF offsets correct; the default load image stays debug-stripped and `--keep-debug` is the tool image.
|
||||
- Full-suite accounting remains one row per file; no crash/unclassified result; skips always carry a reason.
|
||||
- No push until the M8 final review is clean; then push `m8`.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Archive correctness:** `ar` header/member parsing, long names, symbol resolution, iterative extraction, duplicate/undefined behavior, determinism, GSPLNK parity.
|
||||
2. **DWARF merge correctness:** CU/abbrev/str/line/addr offset rehoming, relocations, section-relative values, dwarfdump validation, single-TU compatibility, stripped load image unchanged.
|
||||
3. **Conformance honesty:** full accounting, flipped classes recorded, no hidden passes, performance measurement causal.
|
||||
4. **No regression** and the final boundary accurate.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Native `.lib` linking in `tms-link`
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tms-link`, `tools/tms-link/tmscoff.py`
|
||||
- Create: `tools/tms-link/tests/` archive fixtures/cases
|
||||
- Modify: `scripts/m4/run.sh` (`M4_LINKER=tms-link` accepts `M4_NATIVE_LIBS`/`M4_NATIVE_RTS`)
|
||||
- Test: `tools/tms-link/tests/run.sh`, `scripts/tests/m7/link.sh`, `scripts/tests/m5/native.sh`, `scripts/tests/m6/runtime.sh`, `scripts/tests/m6/i64.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `ar` archives with TI-COFF members (`build/m4-sdk/FLIB.LIB`, `RTS.LIB`), the existing object reader/linker, and the M4 hook.
|
||||
- Produces: archive detection/reader; selective extraction of members that define currently-undefined symbols (iterated to a fixpoint); `-l`/path CLI support; duplicate definitions/undefined symbols/unsupported members loud; a linked image with the same section/loader contract.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** A tiny archive fixture (2–3 members, one symbol each) linked by `tms-link`; a missing-symbol and a duplicate-definition negative; a `flib`-only program (e.g. `FD$ADD`) linked without GSPLNK; the current CLI does not read archives.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Parse `!<arch>\n`, 60-byte member headers, decimal sizes, even-byte padding, `/` and `//` special members, and `/N`/name forms; reject malformed archives loudly.
|
||||
- Add archive members to the link as candidate objects; extract only members that define an undefined symbol, iterating (archive semantics), never re-extracting a member; duplicate/undefined symbols fail with names.
|
||||
- CLI: accept `-l LIB` and archive paths; preserve object inputs, `--entry`, layout, map, debug strip/keep.
|
||||
- `scripts/m4/run.sh`: allow `M4_LINKER=tms-link` with `M4_NATIVE_LIBS`/`M4_NATIVE_RTS`; pass library paths; keep GSPLNK the default and the oracle.
|
||||
- [x] **Step 4: Run green.** Unit/archive tests; the M5 native and M6 runtime/i64 links with `tms-link` + libs; GSPLNK byte/symbol parity; MAME markers; one full native run. Do not regress non-library links.
|
||||
- [x] **Step 5: Commit** (project; compiler unchanged unless a target bug appears).
|
||||
|
||||
### Task 2: Multi-TU DWARF merging
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tms-link`, `tools/tms-link/tmscoff.py`
|
||||
- Create: `scripts/tests/m8/dwarf-multi.sh`, fixtures (`scripts/m8/debug-a.c`, `debug-b.c`, entry)
|
||||
- Test: `scripts/tests/m7/debug.sh` (single-TU compatibility), `llvm-dwarfdump`, MAME
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: multiple `--keep-debug`-capable debug-bearing objects from Task 1's linker and the M7 debug sections.
|
||||
- Produces: merged `.debug_info`/`.debug_abbrev`/`.debug_str`/`.debug_str_offsets`/`.debug_line`/`.debug_addr` (and related) sections with rehomed section-relative offsets/relocations across CUs; single-TU output unchanged; loud failure on unsupported shapes.
|
||||
|
||||
- [x] **Step 1: Write failing tests.** Two TUs with functions/lines, linked `--keep-debug`; the current linker refuses >1 debug object. Wrap the sections in the test ELF container and require `llvm-dwarfdump` to show both TUs' files/functions/lines/addresses.
|
||||
- [x] **Step 2: Run red.**
|
||||
- [x] **Step 3: Implement.**
|
||||
- Concatenate `.debug_info`/`.debug_line`/etc. while relocating each object's section-relative contributions: `.debug_abbrev` offsets in CU headers, `.debug_str_offsets` bases, `.debug_addr` bases, `.debug_line`/`.debug_line_str` offsets, and cross-section relocations to allocated sections.
|
||||
- Resolve relocations against the linked section layout; keep debug sections section-relative (paddr 0), `nreloc=0`.
|
||||
- Preserve the single-debug-TU output; refuse unsupported DWARF shapes loudly.
|
||||
- [x] **Step 4: Run green.** Multi-TU dwarfdump, single-TU `m7/debug.sh`, the stripped image in MAME, the M7.2 gates.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 3: Conformance depth and performance
|
||||
|
||||
**Files:**
|
||||
- Modify: the relevant target lowering/tests for fixed classes; the full-suite skip file; the perf driver if extending it
|
||||
- Test: `scripts/tests/m7/full-suite.sh` (accounting), `scripts/tests/m7/c-torture.sh`/`c-testsuite.sh`, `scripts/tests/m7/i64div.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M7.4 full-suite baseline (1,576 pass / 336 skip / 0 fail / 0 crash).
|
||||
- Produces: additional fixed classes with flipped counts, an updated honest skip list, and at least one new measured performance path (e.g. 64/32 i64 division when the divisor fits 32 bits).
|
||||
|
||||
- [x] **Step 1: Pick the highest-value classes** from the retained skip classes (rotates/`cttz`/`bswap`/`blockaddress`; inline-asm constraints; one ABI return shape; one timeout/image-size case) and write failing lit/runtime tests.
|
||||
- [x] **Step 2: Implement** the fixes, update the skip curation only where the class remains a genuine M8/M9 boundary, and re-run the affected full-suite rows.
|
||||
- [x] **Step 3: Performance:** implement and measure the 64/32 fast path (or an equally justified path) against the existing slow path; record frames/checksums.
|
||||
- [x] **Step 4: Run green** and record the new exact counts/flips.
|
||||
- [x] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Hardware status, final M8 docs, full gates, final review, push
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, the spec (M8 status)
|
||||
- Test: the full M0–M8 list
|
||||
|
||||
- [x] **Step 1: Hardware.** If the VT1200 is available, run `VT1200_HOST=… scripts/tests/m7/hardware.sh` and record the real-unit evidence; otherwise keep `HARDWARE: DEFERRED` explicit. Do not fake a pass.
|
||||
- [x] **Step 2: Docs.** Record M8.1/M8.2/M8.3 results, the final full-suite/perf counts, the remaining limitations, and the M8/M9 boundary.
|
||||
- [x] **Step 3: Gates and review.** Run the full serial list, commit, final whole-branch review, then push `m8` (default stays `m7` unless asked).
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M8.1 makes the native path library-complete; M8.2 makes debug info multi-TU; M8.3 raises the conformance/performance surface; M8.4 closes the milestone with the hardware status and boundary. The compiler repo remains canonical for target code; the project holds the linker, harness, plans and gates.
|
||||
@@ -0,0 +1,515 @@
|
||||
# TMS34010 M10 (Phase 2) — Native clang Pipeline 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:** Make `clang --target=tms34010 -c` semantically correct for pointer code at `-O0` and `-O2` with no extra flags, by moving the bit-address barrier, the post-optimizer scaling and the barrier lowering into the TMS34010 target's own pass pipeline.
|
||||
|
||||
**Architecture:** A minimal clang `ToolChain` supplies this target's compile defaults (freestanding, no builtins, no system includes, `-replexitval=never`). The transform logic from `tools/tms-bitaddr/bitscale.cpp` is ported to new-PM module passes in `llvm/lib/Target/TMS34010/` and registered from `TMS34010TargetMachine::registerPassBuilderCallbacks`: the barrier on the pipeline-start extension point (which also lowers immediately at `-O0`), scale/lower/final-InstCombine on optimizer-last. A `"tms.bitaddr"` module flag makes repeated application impossible, and a legacy pass in `addISelPrepare` lowers any barrier calls that still reach codegen. `llc`'s IR contract is untouched because `llc` builds no new-PM pipeline.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`), `llvm/lib/Target/TMS34010`, clang driver `ToolChains`, new pass manager (`PassBuilder` EP callbacks), module flags, lit/FileCheck, shell gates, MAME for runtime gates.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md` (§7 and §7.8 are this milestone; §8 is M11, which gets its own plan after M10 is promoted because it extends the same `ToolChain` file).
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Baseline: project `m9`/`55a0991`, compiler `m9`/`4e7d48d2717e`. Cut `m10` in both repos before Task 1; never force-push.
|
||||
- LLVM/Clang stay pinned at 23.1.5. Export the driver change as `patches/llvm/0005-*.patch`.
|
||||
- No new user-visible flag may be required for correctness: `clang --target=tms34010 -O2 -c` works with no extra arguments.
|
||||
- `llc`'s IR contract is unchanged: for `i8` GEPs the byte offset is the bit offset (`m2-late-gep.ll` → `ADDI 24`).
|
||||
- `opt` behaviour is unchanged: it builds no `TargetMachine`, so no target hook fires there.
|
||||
- `clang -O0 -c` objects must be **byte-identical** to the M9 path (`scripts/tms-clang` + `llc -O0`) across the corpus. `-O2` is gated on behaviour, not bytes.
|
||||
- Existing gates stay green: lit **129/129**, clang **5/5**, the M2–M9 gate list, the two-tier full suite **1,618 pass / 294 skip / 0 fail / 0 crash**, i64div **88/3302/221/120** with checksums `000000011E6F9AB4` / `00000000007512AE` / `F56810CFEDA9D656` / `00002C61C63842EE`.
|
||||
- TI ABI, the all-stack convention, GSPLNK as the byte/symbol oracle and the two-tier harness are unchanged.
|
||||
- `-O0` and `-O2` are both first-class. A change that only holds at one level is incomplete.
|
||||
- Debug locations survive every new pass: the M9.2 gates (`scripts/tests/m9/dwarf-ranges.sh`, `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`) must pass unchanged.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **`clang -emit-llvm` output fed to `llc`** — a user's normal two-step flow must not double-transform; llc must accept the emitted IR and produce the same code as `-c` (Task 3).
|
||||
2. **Hand-written IR through `llc`** — `getelementptr i8, ptr %p, i32 24` must still be `ADDI 24`; a barrier inside llc would silently redefine every existing fixture (Task 2).
|
||||
3. **`-O0` parity with the legacy path** — byte drift here means a hidden semantic change (optnone, always-inline, an extra InstCombine) rather than a benign optimization difference (Task 4).
|
||||
4. **Ordinary loop code at `-O2`** — `IndVarSimplify`'s i33 exit-value rewrite must not resurface as a compile failure once the shell wrapper stops passing `-replexitval=never` (Task 1, Task 5).
|
||||
5. **Debug info through the port** — barrier/lower must copy `!dbg`, or `-g -c` objects lose their line table and the DWARF gates go red (Task 2, Task 6).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: TMS34010 `ToolChain` with the target's compile defaults
|
||||
|
||||
**Files:**
|
||||
- Create: `clang/lib/Driver/ToolChains/TMS34010.h`
|
||||
- Create: `clang/lib/Driver/ToolChains/TMS34010.cpp`
|
||||
- Modify: `clang/lib/Driver/ToolChains/CMakeLists.txt`
|
||||
- Modify: `clang/lib/Driver/Driver.cpp` (arch switch in `Driver::getToolChain`, after the `msp430` case at ~line 7286)
|
||||
- Test: `clang/test/Driver/tms34010-defaults.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `toolchains::BareMetal` (`clang/lib/Driver/ToolChains/BareMetal.h`), whose ctor is `BareMetal(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)`.
|
||||
- Produces: `class TMS34010ToolChain : public BareMetal` with the same ctor, overriding `void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, BoundArch BA, Action::OffloadKind DeviceOffloadKind) const`, which appends `-ffreestanding`, `-fno-builtin`, `-mllvm`, `-replexitval=never` and then calls `BareMetal::addClangTargetOptions`.
|
||||
|
||||
- [ ] **Step 1: Write the failing driver test**
|
||||
|
||||
```c
|
||||
// clang/test/Driver/tms34010-defaults.c
|
||||
// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=FLAGS
|
||||
// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=NOSYS
|
||||
// FLAGS: "-cc1" {{.*}}-ffreestanding
|
||||
// FLAGS-SAME: -fno-builtin
|
||||
// FLAGS-SAME: "-mllvm" "-replexitval=never"
|
||||
// NOSYS-NOT: "-internal-isystem"
|
||||
int f(int n) { return n + 1; }
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: FAIL — the `-###` line has no `-ffreestanding` / `-mllvm -replexitval=never`.
|
||||
|
||||
- [ ] **Step 3: Implement the ToolChain**
|
||||
|
||||
`TMS34010.h` subclasses `BareMetal` with the forwarding ctor and the `addClangTargetOptions` override. `TMS34010.cpp` pushes the four default arguments in this order (`-ffreestanding`, `-fno-builtin`, `-mllvm`, `-replexitval=never`) before delegating to the base. In `Driver.cpp`, insert after the `msp430` case:
|
||||
|
||||
```cpp
|
||||
case llvm::Triple::tms34010:
|
||||
TC = std::make_unique<toolchains::TMS34010ToolChain>(*this, Target, Args);
|
||||
break;
|
||||
```
|
||||
|
||||
Add the header to `Driver.cpp`'s include block and `TMS34010.cpp` to `ToolChains/CMakeLists.txt` (`add_clang_library(clangDriver ...)`).
|
||||
|
||||
- [ ] **Step 4: Run it green, plus the loop case**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: PASS.
|
||||
|
||||
Then compile the shape that fails today, with no extra flags:
|
||||
|
||||
```sh
|
||||
printf 'int sumto(int n){int s=0;for(int i=0;i<=n;i++)s+=i;return s;}\n' > /tmp/opencode/m10-loop.c
|
||||
build/llvm-clean-build/bin/clang --target=tms34010 -O2 -c /tmp/opencode/m10-loop.c -o /tmp/opencode/m10-loop.o
|
||||
```
|
||||
Expected: exit 0, object written (before this task: `fatal error: TMS34010: i33 multiply (umul_lohi shape) reached code generation`).
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add clang/lib/Driver/ToolChains/TMS34010.h \
|
||||
clang/lib/Driver/ToolChains/TMS34010.cpp \
|
||||
clang/lib/Driver/ToolChains/CMakeLists.txt \
|
||||
clang/lib/Driver/Driver.cpp clang/test/Driver/tms34010-defaults.c
|
||||
git -C build/llvm-clean commit -m "tms34010: add the driver ToolChain with the target compile defaults"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: Bit-address passes and pipeline hooks (`-O0` and `-O2` correct)
|
||||
|
||||
**Files:**
|
||||
- Create: `llvm/lib/Target/TMS34010/TMS34010BitAddr.h`
|
||||
- Create: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp`
|
||||
- Modify: `llvm/lib/Target/TMS34010/CMakeLists.txt`
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.h`
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp`
|
||||
- Test: `clang/test/CodeGen/TMS34010/bitaddr-o0.c`, `clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `tools/tms-bitaddr/bitscale.cpp` as the behavioural reference (modes `--bitptr`, `--scale`, `--lower-bitptr`); `OptimizationLevel` from the pipeline-start callback.
|
||||
- Produces: free functions `bool tms34010BitPtr(Module &M, OptimizationLevel Level)`, `bool tms34010ScaleGEP(Module &M)`, `bool tms34010LowerBitPtr(Module &M)`; new-PM passes `TMS34010BitPtrPass(OptimizationLevel)`, `TMS34010ScaleGEPPass`, `TMS34010LowerBitPtrPass`, each `PassInfoMixin` with `PreservedAnalyses run(Module &M, ModuleAnalysisManager &)`; `void TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) override`.
|
||||
|
||||
- [ ] **Step 1: Write the failing asm tests**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
struct S { char c; int i; };
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int load_s(struct S *p) { return p[1].i; }
|
||||
int load_b(char *p) { return p[4]; }
|
||||
// CHECK-LABEL: _load_i:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
// CHECK-NOT: ADDI 4, A
|
||||
// CHECK-LABEL: _load_s:
|
||||
// CHECK: ADDI 40, A{{[0-9]+}}
|
||||
// CHECK-LABEL: _load_b:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
```
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -S -o - %s | FileCheck %s
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int sumto(int n) { int s = 0; for (int i = 0; i <= n; i++) s += i; return s; }
|
||||
// CHECK-LABEL: _load_i:
|
||||
// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
// CHECK-NOT: ADDI 4, A
|
||||
// CHECK-LABEL: _sumto:
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o0.c build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
Expected: FAIL — `ADDI 4` instead of `ADDI 32` (`_load_s` likewise off by the scale factor).
|
||||
|
||||
- [ ] **Step 3: Port the barrier pass**
|
||||
|
||||
In `TMS34010BitAddr.cpp`, implement `tms34010BitPtr` and `TMS34010BitPtrPass` by porting the `--bitptr` mode of `tools/tms-bitaddr/bitscale.cpp` **verbatim in behaviour**: the same `@__tms_bitptr(i32 bitoff, ptr base)` declaration with `nounwind readnone`, the same constant-expression-GEP rewrite to `inttoptr(add(ptrtoint, 8*off))`, the same declaration/body validation error, and every replaced instruction copies its `!dbg` location. Keep the `--normalize` mode out (nothing calls it).
|
||||
|
||||
- [ ] **Step 4: Port the lowering pass**
|
||||
|
||||
Implement `tms34010LowerBitPtr` and `TMS34010LowerBitPtrPass` from the `--lower-bitptr` mode: replace each call with `inttoptr(add(ptrtoint base, bitoff))` and drop the declaration; copy `!dbg` from the call. Then confirm the port compiles and is reachable (registration comes in Step 6):
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang llc FileCheck`
|
||||
Expected: clean build, no new warnings in the target.
|
||||
|
||||
- [ ] **Step 5: Port the scaling pass**
|
||||
|
||||
Implement `tms34010ScaleGEP`: multiply only the indices of GEPs that reach it (optimizer-created byte GEPs), keep the `switch.table.` special case (`isSwitchTableBase` → shift 3 even when `GepShift == 0`), and keep the `0 + x` / `x * 1` folding.
|
||||
|
||||
- [ ] **Step 6: Register the pipeline hooks**
|
||||
|
||||
In `TMS34010TargetMachine.cpp`:
|
||||
|
||||
```cpp
|
||||
void TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
|
||||
PB.registerPipelineStartEPCallback(
|
||||
[](ModulePassManager &MPM, OptimizationLevel Level) {
|
||||
MPM.addPass(TMS34010BitPtrPass(Level));
|
||||
if (Level == OptimizationLevel::O0) {
|
||||
MPM.addPass(TMS34010LowerBitPtrPass());
|
||||
}
|
||||
});
|
||||
PB.registerOptimizerLastEPCallback(
|
||||
[](ModulePassManager &MPM, OptimizationLevel,
|
||||
ThinOrFullLTOPhase) {
|
||||
MPM.addPass(TMS34010ScaleGEPPass());
|
||||
MPM.addPass(TMS34010LowerBitPtrPass());
|
||||
MPM.addPass(InstCombinePass(InstCombineOptions()
|
||||
.setVerifyFixpoint(false)));
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
`-O0` deliberately adds no `scale` (no optimizer runs, so no optimizer-created GEPs) and no `InstCombine` — that is what keeps `-O0` byte-identical to the legacy path (Task 4). Declare the override in `TMS34010TargetMachine.h` and add `TMS34010BitAddr.cpp` to the target's `CMakeLists.txt`.
|
||||
|
||||
- [ ] **Step 7: Run both asm tests green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang llc FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o0.c build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-o2.c`
|
||||
Expected: PASS at both levels.
|
||||
|
||||
- [ ] **Step 8: Prove `llc`'s contract is unchanged**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m2-late-gep.ll`
|
||||
Expected: PASS — still `ADDI 24`, not `ADDI 192`.
|
||||
|
||||
- [ ] **Step 9: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
llvm/lib/Target/TMS34010/CMakeLists.txt \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-o0.c \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
git -C build/llvm-clean commit -m "tms34010: move the bit-address barrier into the clang pipeline"
|
||||
```
|
||||
|
||||
End-to-end native proof (compile → link → MAME) lands in Task 5, when
|
||||
`tms-clang` routes every harness through native clang; at this point only the
|
||||
asm-level tests can observe the pipeline directly.
|
||||
|
||||
---
|
||||
|
||||
### Task 3: State machine, idempotency and the codegen safety net
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp` (module-flag transitions)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (`addISelPrepare` legacy pass)
|
||||
- Create: `scripts/tests/m10/bitaddr-idempotent.sh`
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the passes from Task 2.
|
||||
- Produces: module flag `"tms.bitaddr"` with values `1` (barriered, not lowered) and `2` (lowered/final); `class TMS34010LowerBitPtrLegacyPass : public ModulePass` in `TMS34010BitAddr.h` for the legacy codegen pipeline; `TMS34010PassConfig::addISelPrepare()` override that adds it before `TargetPassConfig::addISelPrepare()`.
|
||||
|
||||
- [ ] **Step 1: Write the failing state-1 test**
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m10-state1-lower.ll
|
||||
; RUN: llc -march=tms34010 -O0 -filetype=asm < %s | FileCheck %s
|
||||
@__tms_bitptr = external nounwind readnone
|
||||
!llvm.module.flags = !{!0}
|
||||
!0 = !{i32 4, !"tms.bitaddr", i32 1}
|
||||
define ptr @advance(ptr %p) {
|
||||
%q = call ptr @__tms_bitptr(i32 32, ptr %p)
|
||||
ret ptr %q
|
||||
}
|
||||
; CHECK-LABEL: _advance:
|
||||
; CHECK: ADDI 32, A{{[0-9]+}}
|
||||
; CHECK-NOT: CALLA
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
Expected: FAIL — the call is not lowered, so the asm contains `CALLA __tms_bitptr`.
|
||||
|
||||
- [ ] **Step 3: Implement the flag transitions**
|
||||
|
||||
`TMS34010BitPtrPass` sets `"tms.bitaddr"` to `1` when absent and does nothing when the value is `1` or `2` (module-level check first, before touching any instruction). `TMS34010LowerBitPtrPass` lowers only when the value is `1`, then sets it to `2`; with no flag it is a no-op. Write the value with `M.addModuleFlag(ModFlagBehavior::Override, "tms.bitaddr", ConstantInt::get(Type::getInt32Ty(M.getContext()), 1))` — `Override` so a second write replaces the value instead of erroring.
|
||||
|
||||
- [ ] **Step 4: Implement the codegen safety net**
|
||||
|
||||
Add `class TMS34010LowerBitPtrLegacyPass : public ModulePass` (in `TMS34010BitAddr.h`, defined in the `.cpp`) whose `runOnModule` calls `tms34010LowerBitPtr`. In `TMS34010PassConfig`, override:
|
||||
|
||||
```cpp
|
||||
void addISelPrepare() override {
|
||||
addPass(new TMS34010LowerBitPtrLegacyPass());
|
||||
TargetPassConfig::addISelPrepare();
|
||||
}
|
||||
```
|
||||
|
||||
- [ ] **Step 5: Run the state-1 test green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build llc clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m10-state1-lower.ll`
|
||||
Expected: PASS.
|
||||
|
||||
- [ ] **Step 6: Write the end-to-end idempotency gate**
|
||||
|
||||
`scripts/tests/m10/bitaddr-idempotent.sh` (shell, `set -eu`, `ROOT=$(cd "$(dirname "$0")/../../.." && pwd)`):
|
||||
|
||||
1. Compile a pointer file at `-O0` to IR: `clang --target=tms34010 -O0 -S -emit-llvm -o run1.ll src.c`.
|
||||
2. Assert `run1.ll` contains `"tms.bitaddr", i32 2` and no `__tms_bitptr`.
|
||||
3. Re-run the same command to `run2.ll` and `cmp` — identical.
|
||||
4. `llc -march=tms34010 -O0 -filetype=asm run1.ll` and assert `ADDI 32` for `p[1]`.
|
||||
5. Compile the same source with `clang --target=tms34010 -O0 -c` and validate the object: `python3 scripts/m4/coff-check.py native.o` must exit 0 (magic and section table valid).
|
||||
|
||||
- [ ] **Step 7: Run the idempotency gate**
|
||||
|
||||
Run: `scripts/tests/m10/bitaddr-idempotent.sh`
|
||||
Expected: `m10 bitaddr idempotent: PASS`.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.h \
|
||||
llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp \
|
||||
llvm/test/CodeGen/TMS34010/m10-state1-lower.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: make the bit-address pipeline idempotent"
|
||||
git add scripts/tests/m10/bitaddr-idempotent.sh
|
||||
git commit -m "m10: gate bit-address pipeline idempotency"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: Static-variadic guard and the `-O0` equivalence gate
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp` (guard inside the barrier pass)
|
||||
- Create: `scripts/tests/m10/legacy-tms-clang` (exact copy of the M9 script, `git show m9:scripts/tms-clang`)
|
||||
- Create: `scripts/tests/m10/equivalence.sh`
|
||||
- Test: `clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `TMS34010BitPtrPass(OptimizationLevel Level)` from Task 2.
|
||||
- Produces: the diagnostic `error: static variadic definition '<name>' loses its '...' arguments at -O2 (dead argument elimination); remove 'static' or compile with -O0` emitted at `-O2` only; `scripts/tests/m10/equivalence.sh` returning non-zero with a per-file diff list.
|
||||
|
||||
- [ ] **Step 1: Write the failing guard test**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
// RUN: not %clang_cc1 -triple tms34010-unknown-none -O2 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -emit-obj %s -o /dev/null
|
||||
// CHECK: static variadic definition 'sum' loses its '...' arguments
|
||||
static int sum(int n, ...) { int *p = &n; return p[0] + p[1]; }
|
||||
int call(void) { return sum(1, 2); }
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
Expected: FAIL — compiles silently (the guard still lives in the shell script).
|
||||
|
||||
- [ ] **Step 3: Move the guard into the barrier pass**
|
||||
|
||||
Port the `awk` guard's condition exactly: at `Level != O0`, scan each function definition; if it has `internal`/`private` linkage AND a variadic signature AND no `llvm.va_start`/`va_arg` use, report that diagnostic with the function's name and fail compilation (`report_fatal_error` or a diagnostic the driver prints as `error:`). Keep the `-O0` exemption.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c`
|
||||
Expected: PASS (both RUN lines).
|
||||
|
||||
- [ ] **Step 5: Create the legacy reference copy**
|
||||
|
||||
Run: `git show m9:scripts/tms-clang > scripts/tests/m10/legacy-tms-clang && chmod +x scripts/tests/m10/legacy-tms-clang`
|
||||
Expected: byte-identical to the M9 script; it is the oracle for the rest of the milestone.
|
||||
|
||||
- [ ] **Step 6: Write the equivalence gate**
|
||||
|
||||
`scripts/tests/m10/equivalence.sh` compiles each corpus file twice and compares objects:
|
||||
|
||||
- native: `clang --target=tms34010 -O0 -c "$f" -o native.o`
|
||||
- legacy: `scripts/tests/m10/legacy-tms-clang -O0 -o legacy.ll "$f"` then `llc -march=tms34010 -O0 -filetype=obj legacy.ll -o legacy.o`
|
||||
- require `cmp native.o legacy.o`.
|
||||
|
||||
Corpus: every `*.c` in `scripts/m4`, `scripts/m5`, `scripts/m6` plus `scripts/tests/m5/conformance/shim.c` and `heap.c`. Run the whole set at `-O0`, then at `-O0 -g`, and report per-file pass/fail with a summary line `m10 equivalence: pass=<n> fail=<n>`.
|
||||
|
||||
Then a second phase in the same script covers `-O2`, where byte identity is not
|
||||
expected: compile a heredoc fixture at `-O2` and FileCheck its asm shapes —
|
||||
`p[1]` for `int*` (`ADDI 32`), a struct-array stride, a `switch` table load and
|
||||
an aggregate return — so the scaling pass is pinned on optimizer-created GEPs.
|
||||
|
||||
- [ ] **Step 7: Run the gate, then prove it discriminates**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh`
|
||||
Expected: `fail=0`.
|
||||
|
||||
Then temporarily run the native side at `-O2` (edit a copy, not the gate) and confirm the comparison reports failures — proving the gate is not vacuous. Revert the copy.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010BitAddr.cpp \
|
||||
clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
git -C build/llvm-clean commit -m "tms34010: reject static variadics in the pre-optimizer barrier"
|
||||
git add scripts/tests/m10/legacy-tms-clang scripts/tests/m10/equivalence.sh
|
||||
git commit -m "m10: gate native/legacy object equivalence at -O0"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: `tms-clang` becomes a wrapper; gates move to the new seam
|
||||
|
||||
**Files:**
|
||||
- Modify: `scripts/tms-clang` (replace the body with the flag mapper)
|
||||
- Modify: `scripts/tests/m4/mul.sh:29`
|
||||
- Modify: `scripts/tests/m5/jr.sh:114-120`
|
||||
- Modify: `scripts/tests/m5/policy.sh:51-70`
|
||||
- Modify: `scripts/tests/m3/run.sh` (the `TMS_OPT` wrapper it installs)
|
||||
- Test: those four gates plus `scripts/tests/m10/equivalence.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the `ToolChain` defaults (Task 1) and the pipeline hooks (Task 2, Task 3).
|
||||
- Produces: `scripts/tms-clang` with the unchanged CLI (`-O0|-O2|-g|-I dir -o OUT.ll IN.c`) that maps to `clang --target=tms34010 [-O0|-O2] [-g] [-I dir] -S -emit-llvm -o OUT.ll IN.c` and no longer invokes `$TMS_OPT` or `$TMS_BITADDR`.
|
||||
|
||||
- [ ] **Step 1: Record the current gate behaviour as the baseline**
|
||||
|
||||
Run: `scripts/tests/m4/mul.sh && scripts/tests/m5/jr.sh && scripts/tests/m5/policy.sh && scripts/tests/m3/run.sh`
|
||||
Expected: all PASS on the pre-rewrite script (this is the behaviour that must survive).
|
||||
|
||||
- [ ] **Step 2: Rewrite `scripts/tms-clang`**
|
||||
|
||||
Keep the argument parser, `set -eu`, and the `TMS_CLANG`/`TMS_CLANG_EXTRA_FLAGS` overrides; delete the temp-dir pipeline, the awk guard (now in the pass), the `run_bitaddr` calls and both `opt` invocations. The whole script becomes the argument parse plus one `exec` of clang with `-S -emit-llvm`.
|
||||
|
||||
- [ ] **Step 3: Repoint the four gates**
|
||||
|
||||
- `m4/mul.sh`: replace the `grep -q -- '-replexitval=never' scripts/tms-clang` check with an assertion on the driver seam, e.g. `"$TMS_CLANG" -### --target=tms34010 -O2 -c ... 2>&1 | grep -q -- '-replexitval=never'`.
|
||||
- `m5/jr.sh`: drop the `OPT_NOREPLEXIT` wrapper and call `tms-clang -O2` directly; keep the same final assertion on the emitted IR/asm.
|
||||
- `m5/policy.sh`: replace the `opt-trace` harness with the `-###` check plus the existing final-IR/asm assertions for the switch-table and loop shapes.
|
||||
- `m3/run.sh`: same treatment for whatever `TMS_OPT` wrapper it installs.
|
||||
|
||||
Each edit must assert the same invariant, just observed at the driver seam instead of inside the script.
|
||||
|
||||
- [ ] **Step 4: Run the four gates green**
|
||||
|
||||
Run: `scripts/tests/m4/mul.sh && scripts/tests/m5/jr.sh && scripts/tests/m5/policy.sh && scripts/tests/m3/run.sh`
|
||||
Expected: all PASS, with the `-replexitval=never` policy still asserted.
|
||||
|
||||
- [ ] **Step 5: Prove native end-to-end**
|
||||
|
||||
With `tms-clang` now mapping to clang, the conformance harness compiles with
|
||||
native clang. Write a small pointer program and run it through the harness:
|
||||
|
||||
```sh
|
||||
cat > /tmp/opencode/m10-ptr.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int main(void) {
|
||||
int a[3] = {10, 20, 30};
|
||||
int *p = a;
|
||||
printf("%d %d\n", p[2], (int)(p + 2 - p));
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
scripts/tests/m5/conformance/run.sh --id m10-ptr --mode native \
|
||||
--expect 'status=0;stdout=30 2\n' /tmp/opencode/m10-ptr.c
|
||||
```
|
||||
|
||||
Expected: `PASS m10-ptr` (status 0, stdout `30 2`). The full breadth proof is the
|
||||
suite in Task 6, which now also compiles through native clang.
|
||||
|
||||
- [ ] **Step 6: Re-run the equivalence gate against the new wrapper**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh`
|
||||
Expected: `fail=0` — the oracle copy is unchanged, so this proves the wrapper
|
||||
produces the same IR the old script did.
|
||||
|
||||
- [ ] **Step 7: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/tms-clang scripts/tests/m4/mul.sh scripts/tests/m5/jr.sh \
|
||||
scripts/tests/m5/policy.sh scripts/tests/m3/run.sh
|
||||
git commit -m "m10: tms-clang maps to clang; gates assert the driver seam"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Full gate sweep, docs, patch export, promote `m10`
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md` (M10 status, `tms-clang` description, gate list)
|
||||
- Modify: `build/llvm-clean/TMS34010.md` (M10 section, pipeline description)
|
||||
- Modify: `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` (M10 acceptance met)
|
||||
- Create: `patches/llvm/0005-tms34010-toolchain.patch`
|
||||
- Test: the full M0–M10 gate list
|
||||
|
||||
- [ ] **Step 1: Export the driver patch**
|
||||
|
||||
Run: `git -C build/llvm-clean diff m9..m10 -- clang/ > patches/llvm/0005-tms34010-toolchain.patch`
|
||||
Expected: the patch contains only `ToolChains/TMS34010.{h,cpp}`, `ToolChains/CMakeLists.txt`, `Driver.cpp` and the driver test.
|
||||
|
||||
- [ ] **Step 2: Run the compiler tests**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010 build/llvm-clean/llvm/test/MC/TMS34010 build/llvm-clean/clang/test/CodeGen/TMS34010 build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: 129 TMS34010 lit tests plus the new ones, and 5 clang tests plus the new ones, all PASS.
|
||||
|
||||
- [ ] **Step 3: Run the M9/M10 behaviour gates**
|
||||
|
||||
Run: `scripts/tests/m10/equivalence.sh && scripts/tests/m10/bitaddr-idempotent.sh && tools/tms-bitaddr/tests/run.sh && scripts/tests/m9/dwarf-ranges.sh && scripts/tests/m8/dwarf-multi.sh && scripts/tests/m7/debug.sh`
|
||||
Expected: all PASS; DWARF output unchanged.
|
||||
|
||||
- [ ] **Step 4: Run the full suite and the divide measurement**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus all --work build/m10-bare`
|
||||
Expected: `all total=1912 pass=1618 skip=294 fail=0 crash=0`.
|
||||
Every row now compiles through native clang, because `tms-clang` is the thin
|
||||
wrapper — so this run is the breadth proof for the new pipeline, not just a
|
||||
regression check.
|
||||
Run: `scripts/tests/m7/i64div.sh`
|
||||
Expected: `fast=88 slow=3302 wide=221 div32=120`, ratios 37.5/14.9/1.8, all four checksums exact.
|
||||
|
||||
- [ ] **Step 5: Run the remaining M0–M8 gates**
|
||||
|
||||
Run the serial list from `README.md`'s gate section (M0, M2–M8 native/object/JR/MMTM/policy/robust/spike/i64/float/varargs/bitfield/aggregate/runtime, the curated c-torture and c-testsuite tiers, `hardware.sh` → `HARDWARE: DEFERRED`).
|
||||
Expected: every gate PASS; hardware DEFERRED.
|
||||
|
||||
- [ ] **Step 6: Update the docs**
|
||||
|
||||
Record in `README.md`, `TMS34010.md` and the spec: M10 complete, `clang --target=tms34010 -c` now correct with no flags, the ToolChain defaults, the pipeline hooks and state flag, the `-O0` byte-identity result, the new gates, and the M10/M11 boundary (M11 = CRT/headers/`libtms.a`/sysroot/link job).
|
||||
|
||||
- [ ] **Step 7: Commit, review, push, promote**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "docs: record the M10 native pipeline"
|
||||
git add README.md docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md \
|
||||
patches/llvm/0005-tms34010-toolchain.patch
|
||||
git commit -m "m10: document the native clang pipeline"
|
||||
```
|
||||
|
||||
Then run the M10 whole-branch review. Only after it is clean: push `m10` in both repositories, set it as the default branch on both remotes, and update the README's default-branch language. `m9` stays as the previous snapshot.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M10 ends with `clang --target=tms34010 -O2 -c` correct for pointer code and for ordinary loops, `-O0` objects byte-identical to the M9 path, and every existing gate green. M11 (Phase 3: CRT, headers, `libtms.a`, sysroot, `tms-link` link job) is planned separately once M10 is promoted, because it extends the `ToolChain` file created in Task 1.
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
# TMS34010 M9 — Conformance Classes, Debug Depth and Performance Implementation Plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax.
|
||||
|
||||
**Goal:** Raise the full-suite pass rate with the highest-value remaining classes, close the M8 DWARF/linker caveats, add a measured 64/32 divide fast path, and close M9 with the hardware status and boundary.
|
||||
|
||||
**Architecture:** Vector `.data` becomes another recursive aggregate in both the raw and object emitters; the target supplies an inline-asm register resolver for the A-register classes. The linker gains a form-aware DWARF input check (or walker) plus `.debug_rnglists` merging. The i64 outliner adds a single-DIVU 64/32 path when the quotient fits. The bare conformance tier and the full-loader list remain the two-tier harness.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`, branch `m9`), `tms-clang`, `llc`, `tms-link`, TI COFF, the dwt loader, MAME, `llvm-dwarfdump`, Python 3, the M8 two-tier harness and pins.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md` §8 (M9.1–M9.4); the M8 README/ledger boundary.
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- M9 baseline: compiler `m8`/`e3ad91edd130`, project `m8`/`f340d74`; work on `m9`. The default is promoted to `m9` only after the final review.
|
||||
- Keep every M2–M8.4 gate green, the TI all-stack ABI, the asm/GSPLNK oracle, the native loader contract, and the two-tier harness.
|
||||
- `M5_CONFORMANCE_BARE=1` remains the conformance default; full-loader exceptions need a reason in `full-suite.full-loader`.
|
||||
- Vector and inline-asm changes must be tested at `-O0` and `-O2`; unsupported shapes stay loud.
|
||||
- DWARF merging must stay section-relative and stripped-image compatible; single-TU output remains byte-compatible with M8.
|
||||
- Full-suite accounting remains one row per file; no crash/unclassified result; skips always carry a reason.
|
||||
- No push until the M9 final review is clean; then push `m9`, promote it, and update the README.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Vector bytes:** exact element order/padding for integer/fp vectors, packed widths, aggregate zero, raw and object paths; no over-read/write; existing scalar/record output unchanged.
|
||||
2. **Inline asm:** constraint mapping for i16/i32, clobbers, output/input ties, unsupported constraints loud; `-O0`/`-O2`.
|
||||
3. **DWARF:** form walker completeness, rnglists merging, offset rehoming, single-TU compatibility, dwarfdump and stripped MAME.
|
||||
4. **Divide:** 64/32 condition and quotient-fit, magnitudes/sign, `INT64_MIN`, divide-by-zero, measured frames/checksums, no M8 path regression.
|
||||
5. **No M2–M8.4 regression**, two-tier counts, and the final boundary.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Vector `.data` and inline-asm `r` constraints
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010AsmPrinter.cpp` (raw/object vector initializers)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelLowering.{h,cpp}` (inline-asm register resolver)
|
||||
- Create/modify: `llvm/test/CodeGen/TMS34010/m9-vector-data.ll`, `m9-inline-asm.ll`
|
||||
- Test: `scripts/tests/m7/data.sh`, the full-suite vector/inline-asm rows, M6/M5 gates
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the recursive `.data` emitter and the A-register classes (`ARegs`, `ARegsEven`, …).
|
||||
- Produces: exact vector initializer bytes (integer/fp element vectors, aggregate zero, byte-multiple only) in raw and object modes; `getRegForInlineAsmConstraint` mapping `r`/`=r` (and documented accepted subsets) to the target register classes; unsupported vectors/constraints loud.
|
||||
|
||||
- [ ] **Step 1: Write failing tests.** `m9-vector-data.ll` with `<2 x i32>`, `<4 x i16>`, an fp vector if supported, and a vector zero; `data.sh` raw/object bytes. `m9-inline-asm.ll` with `r` input/output at `-O0`/`-O2`. Current emitter rejects vectors; inline asm fails to allocate.
|
||||
- [ ] **Step 2: Run red.**
|
||||
- [ ] **Step 3: Implement.** Vector constants as ordered element bytes with exact alloc size; `ConstantAggregateZero` vector zero; keep unsupported widths/types loud. Implement the inline-asm resolver and clobber handling; reject unsupported constraints with a named error.
|
||||
- [ ] **Step 4: Run green.** Lit, data.sh, and the affected full-suite rows (bare/full-loader as appropriate); record flips.
|
||||
- [ ] **Step 5: Commit** (compiler + project gates/tests).
|
||||
|
||||
### Task 2: DWARF form walker and `.debug_rnglists`
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tms-link`, `tools/tms-link/tmscoff.py`
|
||||
- Create: `scripts/tests/m9/dwarf-ranges.sh`, fixtures
|
||||
- Test: `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`, `llvm-dwarfdump`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: M8's multi-TU debug merge and the current CU-abbrev-only raw patch.
|
||||
- Produces: a form-aware check/walker that rejects (or correctly patches) unrelocated section-relative fields, and `.debug_rnglists` concatenation/rehoming with a fixture; single-TU bytes unchanged.
|
||||
|
||||
- [ ] **Step 1: Write failing tests.** A synthetic object with an unrelocated `DW_AT_stmt_list`/`strp` (or a documented rejection), and a multi-TU `.debug_rnglists` fixture; current code silently assumes relocations.
|
||||
- [ ] **Step 2: Run red.**
|
||||
- [ ] **Step 3: Implement** the form walk (or input gate) and rnglists merge; keep the loud paths.
|
||||
- [ ] **Step 4: Run green.** `dwarf-ranges.sh`, `dwarf-multi.sh`, `m7/debug.sh`, stripped MAME.
|
||||
- [ ] **Step 5: Commit.**
|
||||
|
||||
### Task 3: 64/32 single-DIVU fast path
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010TargetMachine.cpp` (`lowerDivRem`)
|
||||
- Create/modify: `llvm/test/CodeGen/TMS34010/m9-i64div-64-32.ll`
|
||||
- Modify: `scripts/m7/i64div-perf.c`, `scripts/tests/m7/i64div.sh`
|
||||
- Test: `scripts/tests/m6/i64.sh`, `m6/runtime.sh`, `i64div.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the M8 fast/wide/loop CFG and the target `DIVU` 64-bit pair.
|
||||
- Produces: when the divisor's high word is zero and the quotient fits 32 bits (e.g. `hi(N) < D`), a single even-destination `DIVU` fast path; otherwise the M8 two-DIVU/loop path. Signed normalization and fixups unchanged.
|
||||
|
||||
- [ ] **Step 1: Write failing tests.** A 64/32 case with `hi(N) < D` requiring one `DIVU`; the M8 wide cases still two; perf phase measured.
|
||||
- [ ] **Step 2: Run red.**
|
||||
- [ ] **Step 3: Implement** the single-DIVU branch; preserve `INT64_MIN`, divide-by-zero UB and signs.
|
||||
- [ ] **Step 4: Run green.** Lit, M6 i64/runtime, i64div measurements; record frames/checksums.
|
||||
- [ ] **Step 5: Commit.**
|
||||
|
||||
### Task 4: Hardware status, final M9 docs, full gates, review, promote
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, spec (M9 status)
|
||||
- Test: the full M0–M9 list
|
||||
|
||||
- [ ] **Step 1: Hardware.** Run `VT1200_HOST=… scripts/tests/m7/hardware.sh` if a unit is available; otherwise keep `HARDWARE: DEFERRED`.
|
||||
- [ ] **Step 2: Docs.** Record M9.1/M9.2/M9.3 results, flips, perf, the final two-tier counts and the M9/M10 boundary; update the gate commands.
|
||||
- [ ] **Step 3: Gates and review.** Run the full serial list, commit, final whole-branch review, then push `m9`.
|
||||
- [ ] **Step 4: Promote.** Set `m9` as the repository default on both remotes (per the standing policy), update the README/docs default language, and verify `refs/heads/m9` is HEAD.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M9 closes the highest-value conformance classes, the DWARF future-producer and rnglists caveats, and adds a measured 64/32 divide fast path. The remaining classes (`blockaddress`, nested functions, VLAs, sret/aggregate/variadic/float returns, libm), broader hardware/link depth and any further performance work are M10. The compiler repo is canonical; the project holds the linker, harness, plans and gates.
|
||||
@@ -0,0 +1,311 @@
|
||||
# TMS34010 M11 (Phase 3) — Conventional Toolchain 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:** Make `clang --target=tms34010 hello.c -o hello` build a loader-valid image that `tms-run` can execute — CRT, headers and `libtms` found through a resource-directory sysroot, linked by `tms-link` through a real driver link job, with no wrapper and no project variables.
|
||||
|
||||
**Architecture:** `sdk/` holds the sources (CRT IR, shim, heap, headers, committed vendor archives); `scripts/tms-sdk` builds `crt0.o` with `llc` and `libtms.a` with `llvm-ar`, then installs everything plus the `tms-link`/`tmscoff.py` pair into `<resource-dir>/tms34010-unknown-none/{include,lib,bin}`. `TMS34010ToolChain` grows sysroot discovery and a `TMS34010Linker` Tool that maps driver flags onto `tms-link`. `tms-link` must emit loader-valid COFF on its own, because the production path no longer runs `coff-check.py --repair`.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`), clang driver `ToolChains/TMS34010.*`, `llc`, `llvm-ar`, `tools/tms-link` (Python + `tmscoff.py`), TMS34010 GSPA assembly, TI-COFF, MAME + the dwt loader, shell gates.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-18-tms34010-m11-conventional-toolchain-design.md` (§8 is this milestone; §11 is the roadmap, not this plan).
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Baseline: project `m10`/`a7bbefa`, compiler `m10`/`7fc2ac37b5ad`. Cut `m11` in both repos before Task 1; never force-push.
|
||||
- LLVM/Clang stay pinned at 23.1.5. All driver work stays inside `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` plus its two registration lines; patch `0005` grows, nothing else.
|
||||
- The driver must never bake in a checkout path: discovery is `--tms-sysroot=`, then `--sysroot`/`-isysroot`, then `<resource-dir>/tms34010-unknown-none`.
|
||||
- M10's contract must not regress: `clang --target=tms34010 -c` stays correct at `-O0`/`-O2`, and `-O0` objects stay byte-identical to the M9 path (`scripts/tests/m10/equivalence.sh` is the gate).
|
||||
- The CRT/runtime contract is fixed: status `01B00000`, out-len `01B00020`, magic `01B00040` = `0x434F4E46`, err-len `01B00060`, output `01B10000`, error `01B30000` (16 KiB each), `_cstack` 32768 bits (4096 bytes) at 16-bit alignment, `_conformance_argv` 64 bits, `_start` entry; `libtms`'s `exit`/`abort` publish and spin.
|
||||
- Link defaults: `--entry _start --text 018A0000 --bss 01A00000 --prog-len 40000h --ram-len 80000h`.
|
||||
- `coff-check.py --repair` leaves the production path; `tms-link` emits valid images unaided.
|
||||
- Vendor `flib.lib`/`rts.lib` are committed and gated against freshly extracted copies.
|
||||
- Existing gates stay green: lit suites, the serial M0–M10 list, the two-tier suite **1,618 pass / 294 skip / 0 fail / 0 crash**, i64div `88/3302/221/120` with the same four checksums, `HARDWARE: DEFERRED`.
|
||||
- No force-push, no default-branch change before the whole-branch review.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **A fresh shell after one setup command** — `clang --target=tms34010 hello.c -o hello` must work with no `M4_*`, `TMS_*`, `PATH` or include entries, from a directory outside the repo (Task 5).
|
||||
2. **Link-reduction knobs** — `-nostdlib`, `-nostartfiles`, `-nodefaultlibs` must each drop exactly their part and still link (Task 4).
|
||||
3. **Missing pieces are diagnosed, not guessed** — no sysroot, no installed `tms-link`, no `python3` must each name the cause and `scripts/tms-sdk`, never a raw linker error (Task 4).
|
||||
4. **CRT contract** — argv vector, 4 KiB stack, result-block addresses, `_start`, and `exit`/`abort` publishing must survive the assembly rewrite, because `tms-run` and the harness read them (Task 2).
|
||||
5. **M10 is untouched** — `clang -c` at `-O0`/`-O2` and the `-O0` byte-identity gate stay exactly as they were; the link work must not perturb codegen (Task 6).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: `tms-link` emits loader-valid images unaided
|
||||
|
||||
**Files:**
|
||||
- Modify: `tools/tms-link/tmscoff.py` (`write_coff`, only if the header is defective)
|
||||
- Modify: `tools/tms-link/tms-link` (only if the writer needs input)
|
||||
- Modify: `tools/tms-link/tests/{run.sh,linktest.py}`
|
||||
- Test: a new case in `tools/tms-link/tests/`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `tmscoff.write_coff(path, sections, symbols, *, entry, text_size, data_size, …)` and the existing `scripts/m4/coff-check.py [--repair] [--entry HEX] FILE` validator.
|
||||
- Produces: whatever the linker emits today must pass `coff-check.py` **without** `--repair`, including an odd-length `.bss`.
|
||||
|
||||
- [ ] **Step 1: Write the failing gate case**
|
||||
|
||||
Add to `tools/tms-link/tests/run.sh` a case that links a small object (reuse an existing fixture) and then runs
|
||||
`python3 scripts/m4/coff-check.py OUT.coff` expecting exit 0, plus a fixture whose `.bss` length is odd (e.g. one 8-bit symbol) checked the same way.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `tools/tms-link/tests/run.sh`
|
||||
Expected: FAIL on the new case with the validator's magic/size complaint (or on the odd-`.bss` case).
|
||||
|
||||
- [ ] **Step 3: Fix the writer**
|
||||
|
||||
If the file/optional header or section table is defective, fix `write_coff`. If an odd `.bss` is emitted unrounded, round only `.bss` to a whole 16-bit word, as `coff-check.py --repair` does. Do not change `.text`/`.data` contents, relocation handling, or the entry point.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `tools/tms-link/tests/run.sh`
|
||||
Expected: PASS, including the two new cases.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add tools/tms-link/tmscoff.py tools/tms-link/tms-link tools/tms-link/tests/
|
||||
git commit -m "m11: tms-link emits loader-valid COFF without repair"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: `sdk/crt0.ll` — the CRT as IR with a naked `_start`
|
||||
|
||||
**Files:**
|
||||
- Create: `sdk/crt0.ll`
|
||||
- Create: `scripts/tests/m11/crt.sh`
|
||||
- Test: `scripts/tests/m11/crt.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `llc -march=tms34010 -filetype=obj`, `tools/tms-link/tms-link`, `scripts/tms-run`, and the result-block contract in Global Constraints.
|
||||
- Produces: `sdk/crt0.ll`, a `naked` `_start` built by `llc`, defining `_start`, `_conformance_name` (12 bytes, `"conformance\0"`), `_conformance_argv` (64 bits), `_cstack` (32768 bits, 16-bit alignment), and preserving the register/stack setup of `scripts/tests/m5/conformance/entry.asm`.
|
||||
|
||||
- [ ] **Step 1: Write the failing contract test**
|
||||
|
||||
`scripts/tests/m11/crt.sh` builds `sdk/crt0.ll` with `llc`, compiles a heredoc `main.c` (`int main(int argc, char **argv) { printf("%d %s\n", argc, argv[0]); return 7; }`), links them with `tms-link` (`--entry _start --text 018A0000 --bss 01A00000 --prog-len 40000h --ram-len 80000h`) plus the existing conformance `shim.o`, and runs `scripts/tms-run`. Expected: status 7, stdout `1 conformance`.
|
||||
|
||||
- [ ] **Step 2: Record the red state**
|
||||
|
||||
Run: `scripts/tests/m11/crt.sh`
|
||||
Expected: FAIL — `sdk/crt0.ll` does not exist. Also record the known fact that `llvm-mc` emits ELF for this triple (and rejects `scripts/tests/m5/conformance/entry.asm`'s `.bss` operands, `h`-suffixed hex, `.even`), so this is an IR rewrite built with `llc`, not a copy.
|
||||
|
||||
- [ ] **Step 3: Write `sdk/crt0.ll`**
|
||||
|
||||
Express the CRT as IR (`sdk/crt0.ll`) with a `naked` `@start` whose single inline-asm block carries the instruction sequence, plus module globals for `_conformance_name`, `_conformance_argv` and `_cstack`. Keep the contract: `setf 16,1,0`/`setf 32,0,1`, clear the four result cells, point `A14` at `_cstack` and `A13` at it, build `argv = { _conformance_name, NULL }`, push `argv` then `1`, `calla _main`, store `A8` as the status and `0x434F4E46` as the magic, `rets`. Build it with `llc -march=tms34010 -filetype=obj`: `llvm-mc` emits ELF for this triple, so only CodeGen reaches the TI-COFF writer.
|
||||
|
||||
- [ ] **Step 4: Run the contract test**
|
||||
|
||||
Run: `scripts/tests/m11/crt.sh`
|
||||
Expected: `m11 crt: PASS` (status 7, stdout `1 conformance`).
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git add sdk/crt0.ll scripts/tests/m11/crt.sh
|
||||
git commit -m "m11: add the llc CRT with the conformance runtime contract"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: `sdk/` sources and `scripts/tms-sdk`
|
||||
|
||||
**Files:**
|
||||
- Create: `sdk/include/` (moved from `scripts/tests/m5/conformance/include`, 10 headers)
|
||||
- Create: `sdk/shim.c`, `sdk/heap.c` (moved from `scripts/tests/m5/conformance/`)
|
||||
- Create: `sdk/lib/flib.lib`, `sdk/lib/rts.lib` (committed copies of `build/m6-sdk/{flib,rts}.lib`)
|
||||
- Create: `scripts/tms-sdk`
|
||||
- Create: `scripts/tests/m11/sdk.sh`
|
||||
- Modify: `scripts/tests/m5/conformance/run.sh` (point at `sdk/include`)
|
||||
- Test: `scripts/tests/m11/sdk.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `sdk/crt0.ll` (Task 2), `llc`, `clang --target=tms34010 -c`, `llvm-ar`, `tools/tms-link/{tms-link,tmscoff.py}`.
|
||||
- Produces: `scripts/tms-sdk [--sysroot DIR]`, which installs `<sysroot>/{include,lib,bin}` with `include/*.h`, `lib/{crt0.o,libtms.a,flib.lib,rts.lib}`, `bin/{tms-link,tmscoff.py}`. Default sysroot: `$(clang -print-resource-dir)/tms34010-unknown-none`.
|
||||
|
||||
- [ ] **Step 1: Write the failing gate**
|
||||
|
||||
`scripts/tests/m11/sdk.sh` runs `scripts/tms-sdk --sysroot "$TMP/sysroot"` and asserts: the seven expected layout entries exist; `llvm-ar t libtms.a` lists `shim.o` and `heap.o`; a second run is idempotent; `cmp` of `crt0.o` against a fresh `llc` build is identical; `cmp` of `libtms.a` against a fresh `llvm-ar rcsD` build is identical; `sdk/lib/{flib,rts}.lib` match `build/m6-sdk/{flib,rts}.lib` when those exist.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m11/sdk.sh`
|
||||
Expected: FAIL — `scripts/tms-sdk` does not exist.
|
||||
|
||||
- [ ] **Step 3: Move the sources and commit the archives**
|
||||
|
||||
Move the headers, `shim.c` and `heap.c` into `sdk/`; copy `build/m6-sdk/{flib,rts}.lib` to `sdk/lib/`; update the conformance runner and any harness path that referenced `scripts/tests/m5/conformance/include` so exactly one copy exists.
|
||||
|
||||
- [ ] **Step 4: Implement `scripts/tms-sdk`**
|
||||
|
||||
Build `crt0.o` with `llc`, `shim.o`/`heap.o` with `clang --target=tms34010 -O2 -c`, `libtms.a` with `llvm-ar rcsD`, then install the layout above (copying the linker pair and marking `tms-link` executable). Rebuild `llvm-ar` if missing: `ninja -C build/llvm-clean-build llvm-ar`.
|
||||
|
||||
- [ ] **Step 5: Run it green**
|
||||
|
||||
Run: `scripts/tests/m11/sdk.sh`
|
||||
Expected: `m11 sdk: PASS`.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git add sdk scripts/tms-sdk scripts/tests/m11/sdk.sh scripts/tests/m5/conformance/run.sh
|
||||
git commit -m "m11: add the sdk sources and the sysroot installer"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: ToolChain sysroot discovery and the link job
|
||||
|
||||
**Files:**
|
||||
- Modify: `clang/lib/Driver/ToolChains/TMS34010.h`, `TMS34010.cpp`
|
||||
- Create: `clang/test/Driver/TMS34010-link.c`
|
||||
- Test: that driver test plus `clang/test/Driver/tms34010-defaults.c` (unchanged)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the installed sysroot from Task 3 and `tms-link`'s CLI (`--entry --text --bss --prog-len --ram-len --map --keep-debug -L -l`).
|
||||
- Produces: `class TMS34010Linker final : public Tool` with `ConstructJob`; `TMS34010ToolChain::buildLinker()`; sysroot-derived include/lib paths; `--tms-linker=PATH`; `-nostartfiles`/`-nodefaultlibs`/`-nostdlib`; `-g` → `--keep-debug`; `-Wl,` passthrough.
|
||||
|
||||
- [ ] **Step 1: Write the failing driver tests**
|
||||
|
||||
`clang/test/Driver/TMS34010-link.c` (model on `avr-link-nostdlib-nodefaultlibs.c`), using `-###`:
|
||||
- default link: `tms-link`, `--entry _start`, `--text 018A0000`, `--bss 01A00000`, the objects, `libtms.a`, `flib.lib`, `rts.lib`;
|
||||
- `-nostdlib`: none of `crt0.o`, `libtms.a`, `flib.lib`, `rts.lib`;
|
||||
- `-nostartfiles`: no `crt0.o`, libraries still present;
|
||||
- `-nodefaultlibs`: `crt0.o` present, no libraries;
|
||||
- `-g`: `--keep-debug`;
|
||||
- `-Wl,--prog-len=80000h`: appears verbatim;
|
||||
- `--tms-linker=/tmp/x`: that path replaces the sysroot linker;
|
||||
- `-l tms`: accepted, and `libtms.a` appears once;
|
||||
- a nonexistent `--tms-sysroot=/nope` and a sysroot without `bin/tms-link`: each produces the named "run scripts/tms-sdk" diagnostic, not a linker error;
|
||||
- `-c`: no link job at all.
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/TMS34010-link.c`
|
||||
Expected: FAIL — clang emits no link job for this target.
|
||||
|
||||
- [ ] **Step 3: Implement discovery and the linker Tool**
|
||||
|
||||
Search order `--tms-sysroot=`, `--sysroot`/`-isysroot`, `<resource-dir>/tms34010-unknown-none`. Add `<sysroot>/include` as a system include and `<sysroot>/lib` as a library path, without touching the M10 freestanding defaults. Implement `ConstructJob` with the argument order in the spec §8.2, and make a missing sysroot, missing `tms-link` or missing `python3` a `Diag` naming `scripts/tms-sdk` (check `python3` with `llvm::sys::findProgramByName`).
|
||||
|
||||
- [ ] **Step 4: Run them green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build clang FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/Driver/TMS34010-link.c build/llvm-clean/clang/test/Driver/tms34010-defaults.c`
|
||||
Expected: PASS for both files.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add clang/lib/Driver/ToolChains/TMS34010.h \
|
||||
clang/lib/Driver/ToolChains/TMS34010.cpp clang/test/Driver/TMS34010-link.c
|
||||
git -C build/llvm-clean commit -m "tms34010: add sysroot discovery and the tms-link job"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: Single-command build end to end
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m11/e2e.sh`
|
||||
- Test: `scripts/tests/m11/e2e.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `scripts/tms-sdk` (Task 3), the link job (Task 4), `scripts/tms-run`.
|
||||
- Produces: the acceptance gate for the milestone's headline command.
|
||||
|
||||
- [ ] **Step 1: Write the failing gate**
|
||||
|
||||
`scripts/tests/m11/e2e.sh` (run from a temp directory outside the repo, with `env -u M4_WORK -u TMS_CLANG …`): install the sysroot into a temp dir with `scripts/tms-sdk --sysroot`, export `CLANG` and pass `--tms-sysroot` once, then:
|
||||
- `clang --target=tms34010 hello.c -o hello` (a heredoc `hello.c` printing one line) and `tms-run hello` → status 0, stdout matches, and `hello.map` exists;
|
||||
- a two-TU build (`add.c` + `main.c`) → `add=42`;
|
||||
- `-c`, `-S`, `-E` produce an object, assembly and preprocessed source respectively;
|
||||
- `-O0` and `-O2` both run correctly;
|
||||
- `-g` links and the image keeps `.debug_*` while a default link is stripped;
|
||||
- `-nostdlib` with a user `_start` links;
|
||||
- `clang -### --target=tms34010 hello.c -o hello` contains no checkout path.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `scripts/tests/m11/e2e.sh`
|
||||
Expected: FAIL at the first link with the missing-sysroot/link-job diagnostic.
|
||||
|
||||
- [ ] **Step 3: Fix what the gate exposes**
|
||||
|
||||
Only driver/ToolToolchain or `tms-sdk` changes belong here; if a defect is in `tms-link`, note it and fix it with its own test.
|
||||
|
||||
- [ ] **Step 4: Run it green**
|
||||
|
||||
Run: `scripts/tests/m11/e2e.sh`
|
||||
Expected: `m11 e2e: PASS`.
|
||||
|
||||
- [ ] **Step 5: Verify one existing harness program and the compatibility alias**
|
||||
|
||||
Run the M4 harness with `M4_NATIVE=1 M4_LINKER=tms-link` on one program (e.g. `scripts/m4/unsigned.c`) and confirm its MAME markers still pass. Then run `scripts/tms-cc hello.c -o hello` and `scripts/tms-run hello` to confirm the Phase 1 alias still works after the sysroot change.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/tests/m11/e2e.sh
|
||||
git commit -m "m11: gate the single-command build end to end"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Docs, full sweep, patch export, promote `m11`
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md`
|
||||
- Modify: `patches/llvm/0005-*.patch`
|
||||
- Test: the full M0–M11 gate list
|
||||
|
||||
- [ ] **Step 1: Re-export the driver patch**
|
||||
|
||||
Run: `git -C build/llvm-clean diff m9..m11 -- clang/ > patches/llvm/0005-tms34010-toolchain.patch`
|
||||
Expected: only `ToolChains/TMS34010.{h,cpp}`, the two registration edits and the M10/M11 clang tests.
|
||||
|
||||
- [ ] **Step 2: Run the compiler and toolchain tests**
|
||||
|
||||
Run: lit for `llvm/test/CodeGen/TMS34010`, `llvm/test/MC/TMS34010`, `clang/test/CodeGen/TMS34010`, `clang/test/Driver/TMS34010*`; `tools/tms-link/tests/run.sh`; `tools/tms-bitaddr/tests/run.sh`.
|
||||
Expected: all PASS.
|
||||
|
||||
- [ ] **Step 3: Run the M11 gates and the M10 regressions**
|
||||
|
||||
Run: `scripts/tests/m11/{sdk,crt,e2e}.sh`, `scripts/tests/m10/equivalence.sh` (`pass=46 fail=0`), `scripts/tests/m10/bitaddr-idempotent.sh`, `scripts/tests/m9/dwarf-ranges.sh`, `scripts/tests/m8/dwarf-multi.sh`, `scripts/tests/m7/debug.sh`.
|
||||
Expected: all PASS.
|
||||
|
||||
- [ ] **Step 4: Run the suite and the divide measurement**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus all --work build/m11-final`
|
||||
Expected: `all total=1912 pass=1618 skip=294 fail=0 crash=0`.
|
||||
Run: `scripts/tests/m7/i64div.sh`
|
||||
Expected: `88/3302/221/120`, ratios 37.5/14.9/1.8, the same four checksums.
|
||||
|
||||
- [ ] **Step 5: Run the remaining M0–M10 gate list**
|
||||
|
||||
The serial list from `README.md`'s gate section, including `hardware.sh` → `HARDWARE: DEFERRED`.
|
||||
Expected: every gate PASS.
|
||||
|
||||
- [ ] **Step 6: Update the docs**
|
||||
|
||||
Record M11 complete: the single command, the sysroot layout and `scripts/tms-sdk`, `python3` as a link-time dependency, the link-reduction knobs, the CRT dialect rewrite and its preserved contract, the `tms-link` validity fix, `tms-cc` as a compatibility alias, and the M11/M12 boundary with a pointer to the roadmap (§11 of the design).
|
||||
|
||||
- [ ] **Step 7: Commit, review, push, promote**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "docs: record the M11 toolchain"
|
||||
git add README.md docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md \
|
||||
patches/llvm/0005-tms34010-toolchain.patch
|
||||
git commit -m "m11: document the conventional toolchain"
|
||||
```
|
||||
|
||||
Then run the whole-branch review, and only when it is clean: push `m11` in both repositories, set it as the default on both remotes, and update the README's default-branch wording. `m10` stays as the previous snapshot.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M11 ends with `clang --target=tms34010 hello.c -o hello` working from a clean shell after one `scripts/tms-sdk`, every M0–M10 gate still green, and the suite unchanged at 1,618 passes. M12 (conformance classes) is the next milestone per the roadmap; it gets its own design and plan.
|
||||
@@ -0,0 +1,383 @@
|
||||
# TMS34010 M12 — Tractable Conformance Gaps 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:** Close the backend gaps that account for 17 curated full-suite skips — inline-asm memory operands, the `ST` clobber, computed `goto`, return/frame address at level 0, and dynamic-alloca scaling — and produce a costed triage of the runtime-abort skips for M13.
|
||||
|
||||
**Architecture:** All compiler work stays in `llvm/lib/Target/TMS34010/` (plus `"st"` in clang's target register list). Inline-asm memory operands get a real selector in `TMS34010ISelDAGToDAG::SelectInlineAsmMemoryOperand`; computed goto needs the ISA's `jump Rd` instruction end to end plus `ISD::BlockAddress`/`ISD::BRIND` lowering; the frame intrinsics lower against the existing system-stack layout; the alloca fix keeps bit units throughout. The abort triage is a harness plus a research document, not a fix pass.
|
||||
|
||||
**Tech Stack:** LLVM/Clang 23.1.5 fork (`llvm-tms34010`), SelectionDAG/ISel, MC (encoding, parser, printer, disassembler), lit/FileCheck, the TMS34010 MAME harness, shell gates.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-19-tms34010-m12-tractable-gaps-design.md` (§7 per workstream, §8 acceptance).
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Baseline: project `m11`/`ef8a854`, compiler `m11`/`18b7fc9cd6df`. Cut `m12` in both repos before Task 1; never force-push.
|
||||
- LLVM/Clang stay pinned at 23.1.5. No generic-LLVM behaviour changes: `InlineAsm::ConstraintCode` is not extended, so `V` stays loud.
|
||||
- No TI ABI change: the all-stack convention, argument slots, the bit pointer model and the frame layout are unchanged.
|
||||
- `clang --target=tms34010 -c` and the M11 `hello.c -o hello` flow must keep working, including `-O0` byte identity (`scripts/tests/m10/equivalence.sh` `pass=46 fail=0`).
|
||||
- Build with `-j4` on this host (unbounded ninja has been OOM-killed).
|
||||
- Every gate stays green; the suite stays `0 fail / 0 crash`. A curated row is removed only in the task that makes it pass, with the flip recorded.
|
||||
- No gate expectation, checksum or recorded count moves beyond those recorded flips.
|
||||
- Out of scope, permanently: nested functions and VLA-in-struct (clang frontend refusals), dialect strictness, timeouts and region limits.
|
||||
|
||||
## Review Focus
|
||||
|
||||
1. **Inline-asm memory operands that are not a plain `*An`** — a user writing `"m"(*p)` where `p` is an argument, an sp-relative local, or a post-increment form must get a valid address, or a named error — never a silent register copy (Task 1).
|
||||
2. **Computed `goto` and the new instruction's encoding round-trip** — the block address must be section-relative, and `jump Rd` must assemble, disassemble and select consistently (Task 2).
|
||||
3. **`__builtin_return_address(0)` after a dynamic alloca or in a variadic callee** — the frame may not hold a fixed offset; the level-0 value must still be the caller's return address (Task 3).
|
||||
4. **A dynamic alloca whose size is not a multiple of 32 bits** — the stack adjust and the pointer arithmetic must agree (Task 4).
|
||||
5. **The triage's own honesty** — a row that aborts must be recorded with its actual status and cause, and the harness must not turn a curated skip into a fail row (Task 5).
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Inline-asm memory operands and the `ST` clobber
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelDAGToDAG.cpp:35-45` (`SelectInlineAsmMemoryOperand`)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp:650` (`getConstraintType`) if `o`/`V` need distinguishing
|
||||
- Modify: `clang/lib/Basic/Targets/TMS34010.cpp:73` (`getGCCRegNames`)
|
||||
- Test: `clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c`, `llvm/test/CodeGen/TMS34010/m12-inline-asm-st.ll`, `llvm/test/CodeGen/TMS34010/m12-inline-asm-mem-reject.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the target's existing addressing-mode selection (the matcher used by `LD`/`ST` in `TMS34010ISelDAGToDAG.cpp`) and the M9 constraint plumbing (`getRegForInlineAsmConstraint`, `getConstraintType`).
|
||||
- Produces: `bool TMS34010DAGToDAGISel::SelectInlineAsmMemoryOperand(const SDValue &Op, InlineAsm::ConstraintCode ConstraintID, SmallVectorImpl<SDValue> &OutOps)` that selects the five ISA memory forms (`*An`, `*An(disp)`, `*An+`, `*-An`, `*An(disp),N`) for `m`/`g`, and a named error for anything else; `"st"` present in clang's GCC register list.
|
||||
|
||||
- [ ] **Step 1: Write the failing tests**
|
||||
|
||||
```c
|
||||
// clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -S -o - %s | FileCheck %s
|
||||
int load_via_asm(int *p) {
|
||||
int x;
|
||||
__asm__ volatile("" : "=r"(x) : "m"(*p) : "memory");
|
||||
return x;
|
||||
}
|
||||
int store_via_asm(int *p, int v) {
|
||||
__asm__ volatile("" : : "m"(*p), "r"(v) : "memory");
|
||||
return v;
|
||||
}
|
||||
// CHECK-LABEL: _load_via_asm:
|
||||
// CHECK-NOT: error:
|
||||
// CHECK-LABEL: _store_via_asm:
|
||||
```
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m12-inline-asm-st.ll
|
||||
; RUN: llc -march=tms34010 -O0 -filetype=asm < %s | FileCheck %s
|
||||
define i32 @clobber_st(i32 %x) {
|
||||
%r = call i32 asm sideeffect "", "=r,0,~{st}"(i32 %x)
|
||||
ret i32 %r
|
||||
}
|
||||
; CHECK-LABEL: _clobber_st:
|
||||
; CHECK-NOT: error:
|
||||
```
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m12-inline-asm-mem-reject.ll
|
||||
; RUN: not llc -march=tms34010 -O0 -filetype=asm < %s 2>&1 | FileCheck %s
|
||||
define i32 @bad(i32 %x) {
|
||||
%r = call i32 asm sideeffect "", "=r,0,~{memory}"(i32 %x)
|
||||
ret i32 %r
|
||||
}
|
||||
; CHECK: TMS34010: unsupported inline asm
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run them red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c build/llvm-clean/llvm/test/CodeGen/TMS34010/m12-inline-asm-st.ll`
|
||||
Expected: FAIL — the first with `TMS34010: inline asm memory constraints ('m'/'o'/'V') are not supported`, the second with `unknown register name 'st' in asm`.
|
||||
|
||||
- [ ] **Step 3: Implement the selector and the clobber name**
|
||||
|
||||
In `SelectInlineAsmMemoryOperand`, match the operand to a memory form using the same `SelectAddr`-style helper the loads/stores use; push the base register and the displacement (if any) as `OutOps`. For `m`/`g` accept any matched form; for `o` accept only forms without a post-increment and with a non-negative displacement; for `V` keep the existing named error, extended to say that `V` needs core LLVM support. Add `"st"` to `getGCCRegNames()`; leave the register class and operand constraints untouched so `ST` is clobber-only.
|
||||
|
||||
- [ ] **Step 4: Run them green**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build -j4 clang llc FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c build/llvm-clean/llvm/test/CodeGen/TMS34010/m12-inline-asm-st.ll build/llvm-clean/llvm/test/CodeGen/TMS34010/m12-inline-asm-mem-reject.ll`
|
||||
Expected: PASS for all three.
|
||||
|
||||
- [ ] **Step 5: Flip the eleven corpus rows**
|
||||
|
||||
```sh
|
||||
awk -F'\t' '$2 ~ /^inline-asm: TMS34010 memory constraints/ {print $1}' \
|
||||
scripts/tests/m7/full-suite.skip > /tmp/opencode/m12-inline.txt
|
||||
scripts/tests/m7/full-suite.sh --corpus c-torture --list /tmp/opencode/m12-inline.txt \
|
||||
--redo --work build/m12-inline
|
||||
```
|
||||
Expected: all pass. Remove exactly those rows from `scripts/tests/m7/full-suite.skip` and record the count.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010ISelDAGToDAG.cpp \
|
||||
llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp clang/lib/Basic/Targets/TMS34010.cpp \
|
||||
llvm/test/CodeGen/TMS34010/m12-inline-asm-*.ll clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c
|
||||
git -C build/llvm-clean commit -m "tms34010: select inline-asm memory operands and name the st clobber"
|
||||
git add scripts/tests/m7/full-suite.skip
|
||||
git commit -m "m12: flip the inline-asm memory-constraint rows"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 2: `jump Rd`, `BRIND` and computed `goto`
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010InstrInfo.td` (new `JumpReg` definition, opcode `0x0160`)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010InstrInfo.cpp` if the instruction needs custom sizing
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp` (`LowerOperation`: `ISD::BlockAddress`, `ISD::BRIND`; `setOperationAction`)
|
||||
- Modify: `llvm/lib/Target/TMS34010/MCTargetDesc/{TMS34010AsmParser,TMS34010InstPrinter,TMS34010MCCodeEmitter,TMS34010Disassembler}.cpp` as the generated tables require
|
||||
- Test: `llvm/test/MC/TMS34010/m12-jump-reg.s`, `llvm/test/CodeGen/TMS34010/m12-computed-goto.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the existing branch machinery (`JUncond`, `JR`, `TMS34010Jrc`) and `TMS34010TargetLowering::LowerOperation`'s switch.
|
||||
- Produces: instruction `TMS34010::JumpReg` (`"jump $src"`), `ISD::BRIND` lowered to it, and `ISD::BlockAddress` lowered to a section-relative bit address (`TMS34010ISD::BITADDR`-style constant material, with the existing relocation path).
|
||||
|
||||
- [ ] **Step 1: Write the failing MC test**
|
||||
|
||||
```asm
|
||||
# llvm/test/MC/TMS34010/m12-jump-reg.s
|
||||
# RUN: llvm-mc -triple=tms34010 -show-encoding %s | FileCheck %s
|
||||
# RUN: llvm-mc -triple=tms34010 -filetype=obj %s -o %t.o
|
||||
# RUN: llvm-mc -triple=tms34010 -disassemble %t.o | FileCheck %s --check-prefix=DIS
|
||||
# CHECK: jump a0 # encoding: [0x60,0x01,0x00,0x00]
|
||||
# DIS: jump a0
|
||||
jump a0
|
||||
```
|
||||
|
||||
Confirm the expected encoding against `vendor/vt1200/tools/smart34010/README.md` (opcode `0x0160`) and the ISA's word order before pinning the bytes.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010/m12-jump-reg.s`
|
||||
Expected: FAIL — `invalid instruction mnemonic 'jump'`.
|
||||
|
||||
- [ ] **Step 3: Define the instruction and its MC surface**
|
||||
|
||||
Add `def JumpReg : TMS34010Inst<(outs), (ins ARegs:$src), "jump $src", …>` with the opcode and encoding the ISA specifies; update the assembler match table, printer and disassembler as generated. The disassembly assertion in the test is what proves the round-trip; keep `JUncond`/`JR` untouched.
|
||||
|
||||
- [ ] **Step 4: Run the MC test green and the MC suite**
|
||||
|
||||
Run: `ninja -C build/llvm-clean-build -j4 llvm-mc llc FileCheck && build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/MC/TMS34010`
|
||||
Expected: the new test plus the four existing MC tests pass.
|
||||
|
||||
- [ ] **Step 5: Write the failing computed-goto test**
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m12-computed-goto.ll
|
||||
; RUN: llc -march=tms34010 -O0 -filetype=asm < %s | FileCheck %s
|
||||
define i32 @cg(i32 %x) {
|
||||
entry:
|
||||
indirectbr ptr blockaddress(@cg, %a), [label %a, label %b]
|
||||
a:
|
||||
ret i32 1
|
||||
b:
|
||||
ret i32 2
|
||||
}
|
||||
; CHECK-LABEL: _cg:
|
||||
; CHECK: jump
|
||||
; CHECK-LABEL: .Lcg$a:
|
||||
```
|
||||
|
||||
- [ ] **Step 6: Run it red, then implement the lowerings**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m12-computed-goto.ll`
|
||||
Expected: FAIL — `Cannot select: … BlockAddress`.
|
||||
|
||||
Implement `ISD::BlockAddress` (section-relative bit address with the existing relocation path) and `ISD::BRIND` (jump through the selected register) in `LowerOperation`, and mark both `Custom` in the constructor. Then rerun the test.
|
||||
|
||||
- [ ] **Step 7: Flip the two corpus rows**
|
||||
|
||||
Run the two rows (`c-torture/920501-3`, `c-torture/990208-1`) through the suite in isolation; both must pass at `-O0` and `-O2`. Remove them from `full-suite.skip`.
|
||||
|
||||
- [ ] **Step 8: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010 llvm/test/MC/TMS34010/m12-jump-reg.s \
|
||||
llvm/test/CodeGen/TMS34010/m12-computed-goto.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: add jump Rd, BRIND and blockaddress lowering"
|
||||
git add scripts/tests/m7/full-suite.skip
|
||||
git commit -m "m12: flip the computed-goto rows"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 3: Return and frame address at level 0
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp` (`LowerOperation`, `setOperationAction` for `ISD::RETURNADDR`/`ISD::FRAMEADDR`)
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010FrameLowering.cpp` only if the level-0 value needs a slot recorded
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m12-frameaddr.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the system-stack layout documented in `TMS34010FrameLowering.cpp:120-145` — the callee saves the caller's state below the return address, and `LOADSTK`/`ADDSTK` already encode `(NumSaved + 1) * 32`.
|
||||
- Produces: `ISD::RETURNADDR` at level 0 → the caller's return address (a slot computed from the saved-register count or an `SP`-relative load emitted after PEI); `ISD::FRAMEADDR` at level 0 → `A13`; levels above 0 → a named error that says which intrinsic and level.
|
||||
|
||||
- [ ] **Step 1: Write the failing test**
|
||||
|
||||
```llvm
|
||||
; llvm/test/CodeGen/TMS34010/m12-frameaddr.ll
|
||||
; RUN: llc -march=tms34010 -O0 -filetype=asm < %s | FileCheck %s
|
||||
declare ptr @llvm.returnaddress(i32)
|
||||
declare ptr @llvm.frameaddress(i32)
|
||||
define ptr @ra0() {
|
||||
%p = call ptr @llvm.returnaddress(i32 0)
|
||||
ret ptr %p
|
||||
}
|
||||
define ptr @fa0() {
|
||||
%p = call ptr @llvm.frameaddress(i32 0)
|
||||
ret ptr %p
|
||||
}
|
||||
; CHECK-LABEL: _ra0:
|
||||
; CHECK-NOT: error
|
||||
; CHECK-LABEL: _fa0:
|
||||
; CHECK-NOT: error
|
||||
```
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m12-frameaddr.ll`
|
||||
Expected: FAIL with `unexpected TMS34010 custom lowering operation`.
|
||||
|
||||
- [ ] **Step 3: Implement the two lowerings**
|
||||
|
||||
Read `TMS34010FrameLowering.cpp` to derive the level-0 return-address offset from the saved-register count (the same expression the prologue/epilogue use), and lower `RETURNADDR(0)` to a load from it; `FRAMEADDR(0)` is `A13`. For a level above 0, fail with `TMS34010: <intrinsic> level <n> is unsupported (only level 0)`.
|
||||
|
||||
- [ ] **Step 4: Run the test green, then probe the frame cases**
|
||||
|
||||
Add a case with a dynamic alloca and a variadic callee to the same test and confirm the emitted offset changes with the frame instead of being hard-coded. Run the test.
|
||||
|
||||
- [ ] **Step 5: Flip the three corpus rows**
|
||||
|
||||
Run `c-torture/20030811-1`, `c-torture/frame-address`, `c-torture/pr17377` through the suite; remove those three from `full-suite.skip`. `20010122-1` and `20030323-1` stay curated; update their reasons to `level > 0 unsupported` if they do not already say so.
|
||||
|
||||
- [ ] **Step 6: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp \
|
||||
llvm/test/CodeGen/TMS34010/m12-frameaddr.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: lower returnaddress/frameaddress at level 0"
|
||||
git add scripts/tests/m7/full-suite.skip
|
||||
git commit -m "m12: flip the level-0 frame rows and restate the level>0 skips"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 4: Dynamic alloca scaling
|
||||
|
||||
**Files:**
|
||||
- Modify: `llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp:1894` (`ISD::DYNAMIC_STACKALLOC` case) and whatever size scaling feeds it
|
||||
- Test: `llvm/test/CodeGen/TMS34010/m12-dynalloca.ll`
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: the bit-unit pointer model and the `MOVE A14, A13` / `ADDSTK FrameBits` epilogue path for `hasVarSizedObjects()` (`TMS34010FrameLowering.cpp:133-143`).
|
||||
- Produces: a dynamic alloca whose stack adjustment and returned pointer agree in bits for non-multiple-of-32 sizes.
|
||||
|
||||
- [ ] **Step 1: Reproduce and write the failing test**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus c-torture --list <(echo c-torture/20070824-1) --redo --work build/m12-dyn` and capture the failure.
|
||||
|
||||
Then write `m12-dynalloca.ll` with a `dynamic alloca i8, i32 %n` and a store/load through the returned pointer, asserting the stack adjust is `8*n` bits (not `n`), at `-O0` and `-O2`.
|
||||
|
||||
- [ ] **Step 2: Run it red**
|
||||
|
||||
Run: `build/llvm-clean-build/bin/llvm-lit -v build/llvm-clean/llvm/test/CodeGen/TMS34010/m12-dynalloca.ll`
|
||||
Expected: FAIL — the assertion from the corpus run, or the wrong stack-adjust constant.
|
||||
|
||||
- [ ] **Step 3: Fix the scaling**
|
||||
|
||||
Make the alloca size arrive in bits (multiply the byte size by 8 where the DAG builds it, or scale in the `DYNAMIC_STACKALLOC` lowering), and keep alignment rounding in bits.
|
||||
|
||||
- [ ] **Step 4: Run the test and the corpus row green**
|
||||
|
||||
Run the lit test, then the corpus row alone. Then remove `c-torture/20070824-1` from `full-suite.skip`.
|
||||
|
||||
- [ ] **Step 5: Commit**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add llvm/lib/Target/TMS34010/TMS34010ISelLowering.cpp \
|
||||
llvm/test/CodeGen/TMS34010/m12-dynalloca.ll
|
||||
git -C build/llvm-clean commit -m "tms34010: scale dynamic alloca sizes in bit units"
|
||||
git add scripts/tests/m7/full-suite.skip
|
||||
git commit -m "m12: flip the dynamic-alloca row"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 5: Abort triage
|
||||
|
||||
**Files:**
|
||||
- Create: `scripts/tests/m12/abort-triage.sh`
|
||||
- Create: `docs/superpowers/research/2026-11-19-tms34010-abort-triage.md`
|
||||
- Test: the harness itself (run it; it must produce the document)
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: `scripts/tests/m7/full-suite.sh` (for corpus discovery and the classifier), `scripts/tests/m5/conformance/run.sh --classify --mode native --expect-status 0`, and the manifest's status/marker contract.
|
||||
- Produces: a document with one row per abort-skipped file: `corpus/name`, `-O0` result, `-O2` result, status word, first wrong marker or abort PC, cause class, evidence pointer, estimated cost; plus a summary grouped by cause and a proposed M13 scope. The harness discovers its set by re-running every curated `runtime-abort*`/wrong-result row, and must not edit `full-suite.skip`.
|
||||
|
||||
- [ ] **Step 1: Write the harness**
|
||||
|
||||
`scripts/tests/m12/abort-triage.sh`: enumerate the curated abort rows from `full-suite.skip`, run each at `-O0` and `-O2`, capture the runner's status and the first differing marker (reuse the runner's own output format), and emit the Markdown table. It must be hermetic apart from MAME, and serial.
|
||||
|
||||
- [ ] **Step 2: Run it and record the raw output**
|
||||
|
||||
Run: `scripts/tests/m12/abort-triage.sh`
|
||||
Expected: a table covering the discovered set (49–51 rows at the time of writing) with no `fail` rows added to the suite file.
|
||||
|
||||
- [ ] **Step 3: Group and write the research document**
|
||||
|
||||
Fill `2026-11-19-tms34010-abort-triage.md` from the harness output: one row per file, cause classes with the evidence, and an M13 proposal ordering the causes by files affected and estimated cost. Apply the plan's ruling: at most three fixes may be proposed as one-line fixes inside M12.
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/tests/m12/abort-triage.sh docs/superpowers/research/2026-11-19-tms34010-abort-triage.md
|
||||
git commit -m "m12: triage the runtime-abort skips for M13"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Task 6: Accounting, docs, full sweep, promote `m12`
|
||||
|
||||
**Files:**
|
||||
- Modify: `README.md`, `build/llvm-clean/TMS34010.md`, `docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md`
|
||||
- Modify: `patches/llvm/0005-*.patch` (the compiler delta for M12)
|
||||
- Test: the full M0–M12 gate list
|
||||
|
||||
- [ ] **Step 1: Re-record the suite accounting**
|
||||
|
||||
Run: `scripts/tests/m7/full-suite.sh --corpus all --work build/m12-final`
|
||||
Expected: `0 fail / 0 crash`, pass = 1,618 + 17 (plus any abort fixes taken), skip = 294 − the same number, and every removed row named in the commit history.
|
||||
|
||||
- [ ] **Step 2: Run the compiler and toolchain tests**
|
||||
|
||||
Run: lit for `llvm/test/CodeGen/TMS34010`, `llvm/test/MC/TMS34010`, `clang/test/CodeGen/TMS34010`, `clang/test/Driver/TMS34010*`; `tools/tms-link/tests/run.sh`; `tools/tms-bitaddr/tests/run.sh`; `scripts/tests/m11/{sdk,crt,e2e}.sh`; `scripts/tests/m10/equivalence.sh` (`pass=46 fail=0`).
|
||||
Expected: all PASS.
|
||||
|
||||
- [ ] **Step 3: Run the M0–M11 gate list and the divide measurement**
|
||||
|
||||
The serial list from `README.md`'s gate section, plus `scripts/tests/m7/i64div.sh` (expect `88/3302/221/120` and the four checksums) and `hardware.sh` (`HARDWARE: DEFERRED`).
|
||||
Expected: every gate PASS.
|
||||
|
||||
- [ ] **Step 4: Export the patch and update the docs**
|
||||
|
||||
Re-export `patches/llvm/0005-*.patch`; record M12 complete in the three documents: the 17 flips with their rows, the `ST`/`o`/`V` decisions, `jump Rd`, the level-0 frame intrinsics, the alloca fix, the triage report's path and headline (what M13 inherits), the permanently-out classes, and `m12` as the milestone branch pending promotion.
|
||||
|
||||
- [ ] **Step 5: Commit and hand off for review**
|
||||
|
||||
```bash
|
||||
git -C build/llvm-clean add TMS34010.md
|
||||
git -C build/llvm-clean commit -m "docs: record the M12 state"
|
||||
git add README.md docs/superpowers/specs/2026-11-10-tms34010-llvm-design.md \
|
||||
patches/llvm/0005-tms34010-toolchain.patch
|
||||
git commit -m "m12: document the conformance fixes and the abort triage"
|
||||
```
|
||||
|
||||
Then run the whole-branch review. Only when it is clean: push `m12` in both repositories, set it as the default on both remotes, and update the README's default-branch wording.
|
||||
|
||||
---
|
||||
|
||||
## Execution Handoff
|
||||
|
||||
M12 ends with 17 more files passing, a triaged abort list that makes M13 plannable, and every M0–M11 gate plus the M11 end-to-end build still green. M13 (ABI shapes + the triaged abort causes) is planned after this milestone is promoted.
|
||||
@@ -0,0 +1,93 @@
|
||||
# Multi-model review observations (M12)
|
||||
|
||||
Started 2026-11-19. The partner asked for two reviewers per task (DeepSeek Flash always, plus a free
|
||||
OpenCode model) and for anything noteworthy this surfaces to be written down.
|
||||
|
||||
## Protocol
|
||||
|
||||
| seat | model | role |
|
||||
|---|---|---|
|
||||
| A | `deepseek/deepseek-flash` | always present, first reader |
|
||||
| B | `opencode/tidepool-alpha-free` | second opinion on every task review |
|
||||
| C | `opencode/nemotron-3.5-super-vl-free` | third seat for the whole-branch review and risky tasks |
|
||||
|
||||
Both seats get the same brief, report and diff file, and neither sees the other's verdict. Findings
|
||||
are compared by the controller; disagreements are adjudicated in the normal fix loop.
|
||||
|
||||
## Findings caught by a second seat that seat A missed
|
||||
|
||||
| task | seat | finding | outcome |
|
||||
|---|---|---|---|
|
||||
| 3 | A (flash) | **Critical**: the level-0 return-address load was chained only to the entry node, so at `-O1+` it sank into the caller's saved-STK push window and read the saved frame pointer. Reproduced from C. Seat B had approved after checking only `-O0`. | Fix round 1: capture the RA in the prologue into an A13-relative slot; test now uses the RA after an argument-bearing call. **This is the first genuine severity divergence between the seats.** |
|
||||
| 1 | B (tidepool) | `ConstraintCode::X` is also accepted by the new memory selector (an unspecified superset, not in the rulings) | parked as Minor; harmless, `X` is an "any value" code |
|
||||
| 1 | B (tidepool) | `stkalign`'s new skip reason is report-attested only — the test source is not in the pinned repo | parked; the assert status (0x86) is recorded |
|
||||
|
||||
## Findings caught by seat A that a second seat missed
|
||||
|
||||
| task | seat A finding | outcome |
|
||||
|---|---|---|
|
||||
| (none yet) | | |
|
||||
|
||||
## Notes on the free seats
|
||||
|
||||
- Task 1: both seats independently verified the same core contracts (no register-copy fallback,
|
||||
`ST` outside every register class, skip accounting). Seat B added the `X`-superset observation and
|
||||
the "report-attested reason" caveat; seat A added the release-build `llvm_unreachable` safety nit
|
||||
and three test-strength nits. Neither found a defect the other's verdict would have missed at
|
||||
Critical/Important level.
|
||||
|
||||
## Task 2
|
||||
|
||||
- Both seats independently reproduced the same escalation: `990208-1`'s `-O2` abort comes from
|
||||
generic LLVM refusing to inline a function whose address is taken (`InlineCost.cpp:3320`), and the
|
||||
test's own `__OPTIMIZE__` guard then aborts on x86-64 too. Neither seat treated it as a TMS34010
|
||||
defect; the controller ruled to keep the row and record the caveat.
|
||||
- Distinct contributions: seat A found the constant-integer `BRIND` path has no lit coverage and that
|
||||
`920501-3` only ever adds a zero offset (so bit-unit scaling of a nonzero block-address offset is
|
||||
untested); seat B checked the object-smoke direction and the `MO_BlockAddress` symbol path in
|
||||
detail. Neither found a defect at Critical/Important that the other missed.
|
||||
|
||||
## Task 3 follow-ups
|
||||
|
||||
- The severity divergence was real and the fix loop needed two rounds: round 1 fixed the scheduling
|
||||
bug but introduced illegal `A8` operands (caught by seat A via `-verify-machineinstrs`); round 2
|
||||
used `A0`/`A1` and added the verifier to both tests.
|
||||
- Seat B, whose original review had approved, caught a **stale diff** in the re-review: the diff file
|
||||
described the A8 variant while the tree already carried the A0/A1 fix. It resolved the discrepancy
|
||||
by verifying the head tree and flagging it explicitly — a failure mode worth remembering when
|
||||
reviews and implementers overlap.
|
||||
|
||||
## Task 4
|
||||
|
||||
- Both seats converged on the same judgment: the dropped assertion only fired on constant-folded input,
|
||||
so it guarded nothing real, and both paths now scale by value. No divergence.
|
||||
- Seat A caught an evidence-hygiene problem nobody else would have looked for: the corpus RED log had
|
||||
been overwritten by the post-fix run, so the claimed reproduction is no longer inspectable. Keep
|
||||
pre-fix logs in their own work directory next time.
|
||||
|
||||
## Task 5
|
||||
|
||||
- Both seats approved and both independently re-derived the 54-row set from the skip file (52 aborts +
|
||||
2 wrong results) and reconciled all three count tables.
|
||||
- Seat A caught the evidence-durability problem: the load-bearing probe results lived only in an
|
||||
untracked `build/` directory, which would leave an M13 engineer unable to re-inspect the claims that
|
||||
killed the endianness "fix". Ruled: commit the probe sources.
|
||||
- Seat B added the note that the report's "one-line" candidate is really one-flag/one-condition, and
|
||||
that the stale 49-51/58 bounds should be read as history.
|
||||
|
||||
## Milestone summary
|
||||
|
||||
- Seats used: A = `deepseek/deepseek-flash` (every review), B = `opencode/tidepool-alpha-free` (every
|
||||
task review), C = `opencode/nemotron-3.5-super-vl-free` (whole-branch review).
|
||||
- **One genuine severity divergence:** Task 3, where seat B approved a return-address load that seat A
|
||||
reproduced as a miscompile at `-O1+`. The reproducer decided it; the fix needed two rounds because
|
||||
round 1 introduced illegal `A8` operands.
|
||||
- **Second-seat value:** seat B caught a stale diff (round-1 text vs round-2 tree) and reasoned about
|
||||
the tree; seat A caught an evidence-durability gap (probes only in `build/`); seat C contributed the
|
||||
pointer↔int "invalid for the target model" analysis and the `OpNo > 0` printer guard.
|
||||
- **Where the process was weakest:** two controller-supplied test/premise errors (a reject case using
|
||||
a supported clobber; the `-O2` requirement for a test that only makes sense at `-O0`), and one
|
||||
controller wording instruction that was simply wrong (`V` vs `v`). Each was caught by a review, but
|
||||
the controller was the source.
|
||||
- **Where the extra seats cost:** doubled review latency per task and several near-duplicate verdicts
|
||||
on mechanical tasks (1, 4). The divergence on 3 alone justified the protocol for this milestone.
|
||||
@@ -0,0 +1,451 @@
|
||||
# TMS34010 runtime-abort triage (M12)
|
||||
|
||||
Date: 2026-11-19. Milestone: M12 (Task 5). Status: **evidence only — no
|
||||
curated row was flipped and `full-suite.skip` was not modified.**
|
||||
|
||||
The M12 plan turns the largest remaining skip bucket into a costed list for
|
||||
M13. This document is that list. Every row below was discovered from the
|
||||
curated table, re-run uncurated at `-O0` and `-O2`, and assigned a cause with
|
||||
runtime and source evidence. The harness is
|
||||
`scripts/tests/m12/abort-triage.sh`.
|
||||
|
||||
## 1. Method
|
||||
|
||||
Discovery is mechanical, not a hardcoded list:
|
||||
|
||||
1. Read `scripts/tests/m7/full-suite.skip` and select every row whose reason
|
||||
starts with `runtime-abort` plus every wrong-result row (reason contains
|
||||
`wrong` and `result`).
|
||||
2. Re-run each selected row through the standard M5 runner with the M7
|
||||
driver's settings: `--classify --mode native --expect-status 0`, bare
|
||||
tier, `LOADER_AT=200`, `LOADER_END=1000` (per-test overrides honored), the
|
||||
driver's `-std`/`-fgnu89-inline`/`-fwrapv` dialect rules, and a 120 s MAME
|
||||
timeout.
|
||||
3. Run at `-O0` and `-O2`, serially, and capture the runner result, the status
|
||||
word, the completion magic, and the last non-empty stdout marker.
|
||||
|
||||
The shipped bare checker does not expose the abort PC, and every discovered
|
||||
test is silent (`stdout_len=0`). There is therefore no output marker to
|
||||
compare; the table's marker column is **status-derived**: `0x86` is `abort()`
|
||||
(the shim writes 134), and the two wrong-result rows return their wrong value
|
||||
as the status. Where a group needed a sharper cause, a small probe was run
|
||||
through the same runner; the probe sources, their run logs and the cause map
|
||||
are committed under `scripts/tests/m12/probes/` (see its `README.md`).
|
||||
|
||||
Command and cost:
|
||||
|
||||
```
|
||||
scripts/tests/m12/abort-triage.sh --work build/m12-abort-triage
|
||||
```
|
||||
|
||||
108 serial MAME runs (54 rows × 2 opt levels) in **133 s**. All 108 runs
|
||||
completed with magic `CONF` (`0x434F4E46`); there were no timeouts, no missing
|
||||
completions, and no crash/unclassified runner rows in the baseline.
|
||||
|
||||
## 2. Discovered set
|
||||
|
||||
**54 rows**, all `c-torture`. The plan estimated 49–51 and the spec's §7.6
|
||||
says 58; those numbers are stale. The 54-row table below is the Task 5
|
||||
snapshot; Task 6 then removed the one flipped row (`eeprof-1`), so a re-run
|
||||
of the harness now discovers 53. `m11` had 53 rows matching this rule; M12
|
||||
re-reasoned `stkalign` from `inline-asm` to `runtime-abort-alignment`, adding
|
||||
the 54th. The breakdown is 52 aborts plus 2 wrong results (`bitfld-6`,
|
||||
`bitfld-7`).
|
||||
|
||||
| curated class | rows |
|
||||
|---|---:|
|
||||
| `runtime-abort` | 14 |
|
||||
| `runtime-abort-alignment` | 3 |
|
||||
| `runtime-abort-bitfield` | 9 |
|
||||
| `runtime-abort-float` | 5 |
|
||||
| `runtime-abort-i64` | 10 |
|
||||
| `runtime-abort-varargs` | 6 |
|
||||
| `runtime-abort-vector` | 5 |
|
||||
| `runtime-bitfield` | 2 |
|
||||
|
||||
Seven rows pass at `-O2` and fail at `-O0`: `20031003-1`, `20050607-1`,
|
||||
`pr123625`, `pr65427`, `pr79737-2`, `pr94412`, `scal-to-vec3`. No row passes
|
||||
at `-O0`; no row fails only at `-O2`. The suite gate is `-O0`, so the `-O2`
|
||||
passes do not flip any row, but they are a useful hint that generic
|
||||
optimization folds away some of the `-O0` lowering bugs.
|
||||
|
||||
## 3. Per-file results
|
||||
|
||||
Status words are the runner's 8-digit hex; magic is `CONF` for every row.
|
||||
The status column is the `-O0` status; the seven rows that pass at `-O2`
|
||||
return `0x0` there (the raw table in `build/m12-abort-triage/abort-triage.md`
|
||||
shows both opt levels explicitly). Evidence pointers are relative to
|
||||
`build/m12-abort-triage/`:
|
||||
`O0/O2: NAME` means `logs/-O0/c-torture/NAME.log` and
|
||||
`logs/-O2/c-torture/NAME.log` (the `.rc` files sit beside them, and the
|
||||
per-opt `result.txt` is under `run-O0/` or `run-O2/`). Costs are group costs
|
||||
from §4 (`S` small, `M` medium, `L` large, `out` permanently out of scope).
|
||||
A `probes/NAME` citation in §4–§5 means `scripts/tests/m12/probes/NAME`, where
|
||||
the sources and their historical logs are committed.
|
||||
|
||||
| corpus/name | curated class | -O0 | -O2 | status | magic | status-derived marker | cause | cost | evidence |
|
||||
|---|---|---|---|---|---|---|---|---|---|
|
||||
| c-torture/20010904-1 | runtime-abort-alignment | fail:status | fail:status | 00000086 | CONF | abort (0x86) | align-packed-abi | L | O0/O2: 20010904-1 |
|
||||
| c-torture/20010904-2 | runtime-abort-alignment | fail:status | fail:status | 00000086 | CONF | abort (0x86) | align-packed-abi | L | O0/O2: 20010904-2 |
|
||||
| c-torture/20021127-1 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | freestanding-builtin | out | O0/O2: 20021127-1 |
|
||||
| c-torture/20031003-1 | runtime-abort-float | fail:status | pass | 00000086 | CONF | abort (0x86) | float-conv | M | O0/O2: 20031003-1 |
|
||||
| c-torture/20050604-1 | runtime-abort-float | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: 20050604-1 |
|
||||
| c-torture/20050607-1 | runtime-abort-i64 | fail:status | pass | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: 20050607-1 |
|
||||
| c-torture/20060420-1 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: 20060420-1 |
|
||||
| c-torture/20080502-1 | runtime-abort-float | fail:status | fail:status | 00000086 | CONF | abort (0x86) | signed-zero | M | O0/O2: 20080502-1 |
|
||||
| c-torture/20230630-1 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | endian-macro+sso | M | O0/O2: 20230630-1 |
|
||||
| c-torture/20230630-3 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | endian-macro+sso | M | O0/O2: 20230630-3 |
|
||||
| c-torture/920428-1 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | ptr-int-model | out | O0/O2: 920428-1 |
|
||||
| c-torture/920625-1 | runtime-abort-varargs | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 920625-1 |
|
||||
| c-torture/931004-10 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-10 |
|
||||
| c-torture/931004-12 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-12 |
|
||||
| c-torture/931004-14 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-14 |
|
||||
| c-torture/931004-2 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-2 |
|
||||
| c-torture/931004-4 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-4 |
|
||||
| c-torture/931004-6 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-6 |
|
||||
| c-torture/931004-8 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: 931004-8 |
|
||||
| c-torture/991112-1 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | rts-shim | S | O0/O2: 991112-1 |
|
||||
| c-torture/bitfld-3 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: bitfld-3 |
|
||||
| c-torture/bitfld-5 | runtime-abort-bitfield | fail:status | fail:status | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: bitfld-5 |
|
||||
| c-torture/bitfld-6 | runtime-bitfield | fail:status | fail:status | 00033333 | CONF | wrong result (0x33333) | endian-macro+sso | M | O0/O2: bitfld-6 |
|
||||
| c-torture/bitfld-7 | runtime-bitfield | fail:status | fail:status | 00222222 | CONF | wrong result (0x222222) | endian-macro+sso | M | O0/O2: bitfld-7 |
|
||||
| c-torture/eeprof-1 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | instr-flag | S | O0/O2: eeprof-1 |
|
||||
| c-torture/floatunsisf-1 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | float-conv | M | O0/O2: floatunsisf-1 |
|
||||
| c-torture/pr103255 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | ptr-int-model | out | O0/O2: pr103255 |
|
||||
| c-torture/pr123625 | runtime-abort | fail:status | pass | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: pr123625 |
|
||||
| c-torture/pr32244-1 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: pr32244-1 |
|
||||
| c-torture/pr34971 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: pr34971 |
|
||||
| c-torture/pr35456 | runtime-abort-float | fail:status | fail:status | 00000086 | CONF | abort (0x86) | signed-zero | M | O0/O2: pr35456 |
|
||||
| c-torture/pr38051 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | ptr-int-model | out | O0/O2: pr38051 |
|
||||
| c-torture/pr38151 | runtime-abort-varargs | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: pr38151 |
|
||||
| c-torture/pr44575 | runtime-abort-varargs | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: pr44575 |
|
||||
| c-torture/pr44683 | runtime-abort-float | fail:status | fail:status | 00000086 | CONF | abort (0x86) | signed-zero | M | O0/O2: pr44683 |
|
||||
| c-torture/pr57344-3 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: pr57344-3 |
|
||||
| c-torture/pr57344-4 | runtime-abort-i64 | fail:status | fail:status | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: pr57344-4 |
|
||||
| c-torture/pr58209 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | ptr-int-model | out | O0/O2: pr58209 |
|
||||
| c-torture/pr65401 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | endian-macro+sso | M | O0/O2: pr65401 |
|
||||
| c-torture/pr65427 | runtime-abort | fail:status | pass | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: pr65427 |
|
||||
| c-torture/pr79327 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | rts-shim | S | O0/O2: pr79327 |
|
||||
| c-torture/pr79737-2 | runtime-abort | fail:status | pass | 00000086 | CONF | abort (0x86) | bitfield-64 | M | O0/O2: pr79737-2 |
|
||||
| c-torture/pr85169 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: pr85169 |
|
||||
| c-torture/pr94412 | runtime-abort | fail:status | pass | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: pr94412 |
|
||||
| c-torture/scal-to-vec1 | runtime-abort-vector | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: scal-to-vec1 |
|
||||
| c-torture/scal-to-vec2 | runtime-abort-vector | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: scal-to-vec2 |
|
||||
| c-torture/scal-to-vec3 | runtime-abort-vector | fail:status | pass | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: scal-to-vec3 |
|
||||
| c-torture/simd-1 | runtime-abort-vector | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: simd-1 |
|
||||
| c-torture/simd-2 | runtime-abort-vector | fail:status | fail:status | 00000086 | CONF | abort (0x86) | vector-ops | L | O0/O2: simd-2 |
|
||||
| c-torture/stdarg-3 | runtime-abort-varargs | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: stdarg-3 |
|
||||
| c-torture/stkalign | runtime-abort-alignment | fail:status | fail:status | 00000086 | CONF | abort (0x86) | align-packed-abi | L | O0/O2: stkalign |
|
||||
| c-torture/strct-stdarg-1 | runtime-abort-varargs | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: strct-stdarg-1 |
|
||||
| c-torture/strct-varg-1 | runtime-abort-varargs | fail:status | fail:status | 00000086 | CONF | abort (0x86) | aggregate-varargs | L | O0/O2: strct-varg-1 |
|
||||
| c-torture/zerolen-2 | runtime-abort | fail:status | fail:status | 00000086 | CONF | abort (0x86) | align-packed-abi | L | O0/O2: zerolen-2 |
|
||||
|
||||
## 4. Causes, grouped
|
||||
|
||||
| cause | rows | cost | one-flag/one-condition? |
|
||||
|---|---:|---|---|
|
||||
| aggregate varargs | 13 | L | no |
|
||||
| vector arithmetic | 12 | L | no |
|
||||
| 64-bit / packed bitfields | 7 | M | no |
|
||||
| endianness macro + SSO | 5 | M | no (see §5) |
|
||||
| packed/over-alignment ABI | 4 | L | no |
|
||||
| pointer↔int model | 4 | out | no — not a compiler gap |
|
||||
| signed zero / signbit | 3 | M | no |
|
||||
| float↔int conversion | 2 | M | no |
|
||||
| RTS / shim runtime | 2 | S–out | no |
|
||||
| function-instrumentation flag | 1 | S | **yes** |
|
||||
| freestanding builtins | 1 | out | no |
|
||||
|
||||
### 4.1 Aggregate varargs — 13 rows, L
|
||||
|
||||
`920625-1`, `931004-2/4/6/8/10/12/14`, `pr38151`, `pr44575`, `stdarg-3`,
|
||||
`strct-stdarg-1`, `strct-varg-1`.
|
||||
|
||||
Every row takes an aggregate through `va_arg` (`struct tiny`, `point`,
|
||||
`struct S`, `struct S1/S2`, or `__builtin_va_arg`). Seven are curated as
|
||||
`runtime-abort-bitfield` but contain **no bitfields**; they are the same
|
||||
`931004` aggregate-vararg family with different struct sizes. A representative
|
||||
probe (`probes/va931004probe.c`) returns status 1: the very first
|
||||
`va_arg(ap, struct tiny)` is wrong (`x.c != 10`); the trailing `long` is never
|
||||
reached. Status is `0x86` at both opt levels.
|
||||
|
||||
This is the aggregate/variadic-argument ABI shape that M13 already owns, and
|
||||
the largest single bucket. Cost L: one varargs/aggregate-call path, but it has
|
||||
to be consistent between the caller, callee, and `va_arg` layout.
|
||||
|
||||
### 4.2 Vector arithmetic — 12 rows, L
|
||||
|
||||
`scal-to-vec1/2/3`, `simd-1/2`, `20050604-1`, `20050607-1`, `20060420-1`,
|
||||
`pr123625`, `pr65427`, `pr85169`, `pr94412`.
|
||||
|
||||
The simplest operation is already wrong: a probe derived from `simd-1`
|
||||
(`probes/simd1probe.c`) returns status `0x0A`, the line of the first
|
||||
`k = i + j` check — vector **add** fails at `-O0`. Five rows pass at `-O2`
|
||||
(`20050607-1`, `pr123625`, `pr65427`, `pr94412`, `scal-to-vec3`), so the gap
|
||||
is in the `-O0` vector lowering/scalarization, not in vector loads/stores or
|
||||
`.data` (which already pass). The remaining rows mix integer, float, `i64`,
|
||||
and over-sized vector shapes and fail at both levels. Cost L: a vector
|
||||
lowering family, not a single combine.
|
||||
|
||||
### 4.3 64-bit / packed bitfields — 7 rows, M
|
||||
|
||||
`bitfld-3`, `bitfld-5`, `pr32244-1`, `pr34971`, `pr57344-3`, `pr57344-4`,
|
||||
`pr79737-2`.
|
||||
|
||||
These are fields wider than a word (33/40/41, 40, 40), packed 64-bit fields
|
||||
(43/59), and a packed 18/24/15/14/1 layout. `pr79737-2` passes at `-O2`; the
|
||||
others fail at both levels with `0x86`. This is extraction/insertion and
|
||||
arithmetic on >32-bit (and packed) bitfields, distinct from the endianness
|
||||
group. Cost M: a bounded set of wide-bitfield lowering cases, but each needs
|
||||
an oracle check.
|
||||
|
||||
### 4.4 Endianness macro + `scalar_storage_order` — 5 rows, M
|
||||
|
||||
`20230630-1`, `20230630-3`, `bitfld-6`, `bitfld-7`, `pr65401`.
|
||||
|
||||
All five branch on `__BYTE_ORDER__`. The target's `TargetInfo` defines
|
||||
`__BIG_ENDIAN__` (`__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__`) because the
|
||||
unknown triple makes `TargetInfo::BigEndian` true, while the DataLayout is
|
||||
`e` (little-endian) and the emitted bitfield loads/stores are little-endian.
|
||||
`bitfld-6`/`bitfld-7` return wrong results (`0x33333`, `0x222222`): the
|
||||
source takes the big-endian branch, but the IR extracts the **low** 20/24 bits
|
||||
(`and 0xFFFFF` / `and 0xFFFFFF`), which is the little-endian extraction.
|
||||
|
||||
The evidence for the macro half is a frontend-only override
|
||||
(`probes/` runs with `-U__BIG_ENDIAN__ -D__BYTE_ORDER__=1234`):
|
||||
|
||||
- `bitfld-6`, `bitfld-7`, `20230630-3`, `pr65401` pass at both `-O0` and
|
||||
`-O2` with the override.
|
||||
- `20230630-1` passes at `-O2` and through the full-loader tier at `-O0`,
|
||||
but the bare tier **host-segfaults** at `-O0`; that is the same class of
|
||||
bare-MAME instability already listed in `full-suite.full-loader`.
|
||||
- The same override **regresses two currently passing rows**:
|
||||
`20230630-2` (full-loader) and `20230630-4` (native) fail because they
|
||||
select `scalar_storage_order("big-endian")` once the macro flips, and this
|
||||
target does not honor the reversed storage order. They only pass today
|
||||
because the macro is wrong in the matching direction.
|
||||
|
||||
So this is not a clean one-flag/one-condition fix: the macro and
|
||||
`scalar_storage_order` must be corrected together. That is why the apparent
|
||||
`BigEndian = false` single change is rejected in §5. Cost M, with a regression
|
||||
guard on the two `20230630-*` passers.
|
||||
|
||||
### 4.5 Packed / over-alignment ABI — 4 rows, L
|
||||
|
||||
`20010904-1`, `20010904-2`, `stkalign`, `zerolen-2`.
|
||||
|
||||
Probes:
|
||||
|
||||
- `probes/astkalign.c` returns `1` for `__alignof__(struct { char c
|
||||
__attribute__((aligned(64))); })`: the requested 64-byte member alignment
|
||||
is clamped.
|
||||
- `probes/azerolen.c` returns `2`: `sizeof(word) == sizeof(struct foo)` but
|
||||
`__alignof__(word) != __alignof(struct foo)`.
|
||||
- `20010904-*`: the linked `.bss` gives `Y` a stride of 1028 bytes (two `Y`
|
||||
objects are 2056 bytes), not the 32-byte-aligned 1056; the test's
|
||||
`(char *)&y[1] - (char *)&y[0]` is therefore `4 mod 32`, and the check is
|
||||
legitimately true. The `if (expr & 31)` form folds to `true` while the
|
||||
`return expr & 31` form folds to `0`; that fold disagreement is a second
|
||||
symptom of the same layout confusion.
|
||||
|
||||
The root is the target's packed-struct policy (`Opts.PackStruct = 1`,
|
||||
`UseBitFieldTypeAlignment = false`) not honoring over-alignment on members
|
||||
and structs. Cost L: an ABI-level layout change, and it needs a decision about
|
||||
what the 1987-compatible packed rule should do with `aligned(N)`.
|
||||
|
||||
### 4.6 Pointer↔integer model — 4 rows, out
|
||||
|
||||
`920428-1`, `pr103255`, `pr38051`, `pr58209`.
|
||||
|
||||
These test `(int)/(long)/(size_t)ptr` arithmetic as if a pointer value were a
|
||||
byte address. On this ABI it is a **bit** address: a probe
|
||||
(`probes/ptrdiff.c`) returns status `8` for
|
||||
`(int)&a[1] - (int)&a[0]` with `char a[2]`. The tests then add byte counts to
|
||||
integer-cast pointers (`ss + 1`, `srcp1 += 1`, `s + sizeof(T)`) or compare a
|
||||
pointer cast to a byte address, so they are invalid for the target model, not
|
||||
miscompiled. `pr103255` additionally compares `(size_t)&h->b` with
|
||||
`ADDR + OFF + offsetof` as a byte address. Curate these with the bit-pointer
|
||||
reason; no M13 code change.
|
||||
|
||||
### 4.7 Signed zero / signbit — 3 rows, M
|
||||
|
||||
`20080502-1`, `pr35456`, `pr44683`.
|
||||
|
||||
Probes: `pr35456` returns `1` (`not_fabs(-0.0)` loses the sign), `pr44683`
|
||||
returns `3` (`__builtin_copysign(1.0, -0.0) < 0.0` is false), and `20080502-1`
|
||||
returns `1` (`long double` signbit / literal comparison). The first two are
|
||||
`-0.0` sign preservation and `copysign`; `20080502-1` may be the long-double
|
||||
representation. Cost M: a small set of float semantics, but each needs its own
|
||||
oracle.
|
||||
|
||||
### 4.8 Float↔int conversion — 2 rows, M
|
||||
|
||||
`20031003-1`, `floatunsisf-1`.
|
||||
|
||||
Probes: `20031003-1` returns `3` — **both** `(int)2147483648.0f` and
|
||||
`(int)(float)2147483647` differ from `INT_MAX`; `floatunsisf-1` returns `1`
|
||||
(`(float)volatile 0x80000081` differs from the literal conversion). The former
|
||||
is C UB (out-of-range conversion) that GCC nevertheless tests; the latter is
|
||||
a real unsigned→float rounding case. `20031003-1` passes at `-O2`. Cost M.
|
||||
|
||||
### 4.9 RTS / shim runtime — 2 rows, S–out
|
||||
|
||||
- `991112-1`: the test calls `isprint`. The 1990 `rts.lib` `_isprint` reads
|
||||
`__ctypes_` at `01A080A0`, which is zero in the bare tier; a probe returns
|
||||
status 2 (`isprint('a')` is false). This is a bare-tier runtime setup gap,
|
||||
not compiler codegen.
|
||||
- `pr79327`: a probe for `%#hhx` of 0 returns `3` (`"0x0"`); `sdk/shim.c`
|
||||
documents this as a **known pre-existing M5 deviation** (C says `"0"`,
|
||||
one byte) kept byte-identical. It is not a compiler gap; changing it would
|
||||
move the documented shim output and gates.
|
||||
|
||||
### 4.10 Function-instrumentation flag — 1 row, S
|
||||
|
||||
`eeprof-1` carries `dg-options -finstrument-functions`, but
|
||||
`full-suite.sh`'s `dialect_flags()` forwards only `-std`,
|
||||
`-fgnu89-inline`, and `-fwrapv`. Without the flag no
|
||||
`__cyg_profile_func_enter/exit` calls are emitted, so the test's counters stay
|
||||
zero and it aborts. Running the unmodified test with the flag passes at both
|
||||
`-O0` and `-O2`. This is a driver omission, not a compiler bug; it is the one
|
||||
one-flag/one-condition candidate in §5. Task 6 took it: `dialect_flags()` now
|
||||
forwards the flag per row, the row was removed from `full-suite.skip`, and the
|
||||
gate suite passes it (see §9).
|
||||
|
||||
### 4.11 Freestanding builtins — 1 row, out
|
||||
|
||||
`20021127-1` calls `llabs(-1)` after defining `llabs` to `abort()`. The TMS
|
||||
driver forces `-ffreestanding -fno-builtin`, so Clang does not recognize
|
||||
`llabs` as a library builtin and calls the aborting definition. Host Clang
|
||||
folds the same file to `llvm.abs.i64`. This is the target's freestanding
|
||||
policy, not a TMS codegen gap; curate it as such (or revisit hosted mode
|
||||
outside M13).
|
||||
|
||||
## 5. One-flag/one-condition ruling
|
||||
|
||||
At most three one-flag/one-condition fixes may be proposed for M12. The triage
|
||||
supports **one**; the strongest-looking single-change compiler candidate is
|
||||
explicitly rejected.
|
||||
|
||||
### Accepted candidate (harness, not compiler): forward `-finstrument-functions`
|
||||
|
||||
Add the flag to `dialect_flags()` in `scripts/tests/m7/full-suite.sh` when the
|
||||
source's `dg-options` asks for it. Why it qualifies:
|
||||
|
||||
- Single shared cause: the driver drops one dg-option; the test compiles and
|
||||
passes unchanged when it is forwarded (verified at `-O0` and `-O2`).
|
||||
- One flag/one condition, one row affected (`eeprof-1`), no other abort row
|
||||
requests the flag, and no compiler or ABI change.
|
||||
- It is a harness fix, so it was taken as its own Task 6 commit: the
|
||||
`eeprof-1` curated row is removed with the recorded flip. This Task 5
|
||||
document did not edit the skip file.
|
||||
|
||||
### Rejected: `BigEndian = false` in `TMS34010TargetInfo`
|
||||
|
||||
This looked like the textbook one-flag/one-condition candidate: it would make
|
||||
`__BYTE_ORDER__` agree with the little-endian DataLayout and flips `bitfld-6`, `bitfld-7`,
|
||||
`20230630-3`, and `pr65401` at both levels (and `20230630-1` through the full
|
||||
loader). But the same change flips `20230630-2` and `20230630-4` from pass to
|
||||
`0x86`, because they then select `scalar_storage_order("big-endian")`, which
|
||||
the target does not honor. A single-change fix that regresses two passing rows
|
||||
is not a clean single-cause fix. The endianness macro and
|
||||
`scalar_storage_order` belong together in M13.
|
||||
|
||||
### Rejected: shim `%#x`/`%#X` zero prefix
|
||||
|
||||
`pr79327` would flip if `emit_uint()` stopped printing `0x` for zero, but the
|
||||
deviation is explicitly documented in `sdk/shim.c` as a pre-existing M5
|
||||
byte-identical behavior. Changing it would move shim output and gate bytes;
|
||||
not a safe M12 one-flag fix.
|
||||
|
||||
No other group qualifies: varargs, vectors, wide bitfields, alignment,
|
||||
signed zero, and conversions are multi-line lowering/ABI work; pointer↔int
|
||||
and freestanding builtins are target-model/policy, not defects to fix.
|
||||
|
||||
## 6. Proposed M13 scope
|
||||
|
||||
Ordered by files affected, with cost and dependencies. The counts cover 54
|
||||
rows; 25 of them (varargs + vectors) are the first two items.
|
||||
|
||||
| order | cause | rows | cost | note |
|
||||
|---:|---|---:|---|---|
|
||||
| 1 | aggregate varargs | 13 | L | overlaps M13's ABI-shape work; one caller/callee/`va_arg` contract |
|
||||
| 2 | vector arithmetic | 12 | L | `-O0` lowering/scalarization; 5 rows already pass at `-O2` |
|
||||
| 3 | 64-bit / packed bitfields | 7 | M | wide and packed extraction/insertion; oracle-backed |
|
||||
| 4 | endianness macro + SSO | 5 | M | fix `__BYTE_ORDER__`/`BigEndian` **and** reversed storage order; guard the two `20230630-*` passers |
|
||||
| 5 | packed/over-alignment ABI | 4 | L | `aligned(N)` under the packed default; ABI decision first |
|
||||
| 6 | signed zero / signbit | 3 | M | `-0.0`, `copysign`, long double |
|
||||
| 7 | float↔int conversion | 2 | M | `20031003-1` is UB; decide whether to chase GCC's answer |
|
||||
| — | pointer↔int model | 4 | out | re-curate with the bit-pointer reason; no code |
|
||||
| — | RTS / shim runtime | 2 | out | bare-tier `__ctypes_` / documented `%#x` deviation |
|
||||
| — | freestanding builtins | 1 | out | `-ffreestanding -fno-builtin` is deliberate |
|
||||
| M12 (done) | instrumentation flag | 1 | S | the accepted one-flag/one-condition harness fix; `eeprof-1` flipped in Task 6 |
|
||||
|
||||
Suggested M13 execution order: **varargs → vectors → wide bitfields →
|
||||
endianness+SSO → alignment**. Take the two float groups after the structural
|
||||
work, and keep the four pointer↔int rows and the two runtime rows curated
|
||||
with accurate reasons rather than spending M13 on them.
|
||||
|
||||
## 7. Curated label vs actual cause
|
||||
|
||||
The curated labels are not a cause taxonomy. This is the most important input
|
||||
for M13 planning:
|
||||
|
||||
| curated class | rows | actual causes |
|
||||
|---|---:|---|
|
||||
| `runtime-abort` | 14 | 4 vector, 3 endianness, 2 pointer↔int, 2 RTS/shim, 1 alignment, 1 wide bitfield, 1 instrumentation |
|
||||
| `runtime-abort-alignment` | 3 | 3 packed/over-alignment |
|
||||
| `runtime-abort-bitfield` | 9 | **7 aggregate varargs**, 2 wide bitfields |
|
||||
| `runtime-abort-float` | 5 | 3 signed zero, 1 conversion, 1 vector |
|
||||
| `runtime-abort-i64` | 10 | 4 wide bitfields, 2 vector, 2 pointer↔int, 1 conversion, 1 freestanding builtin |
|
||||
| `runtime-abort-varargs` | 6 | 6 aggregate varargs |
|
||||
| `runtime-abort-vector` | 5 | 5 vector |
|
||||
| `runtime-bitfield` | 2 | 2 endianness |
|
||||
|
||||
In particular, the `i64` label contains **no** plain 64-bit-codegen row: its one
|
||||
conversion row (`floatunsisf-1`) is float↔int, and the rest are wide
|
||||
bitfields, vectors, or pointer↔int. The `931004-*` rows are the clearest
|
||||
mislabel: seven vararg tests curated as bitfields.
|
||||
|
||||
## 8. Limits and concerns
|
||||
|
||||
- **No abort PC.** The bare checker writes only the result block; it has no
|
||||
PC hook, and every discovered test is silent. The status word plus the
|
||||
source predicate is the evidence, and representative probes localize the
|
||||
group causes. A future harness could tap the `abort` symbol/return address
|
||||
in MAME, but that is a runner change, not this triage.
|
||||
- **Probes are representative, not exhaustive.** The 13 varargs rows share the
|
||||
same `va_arg` shape; one probe proves the first aggregate is wrong. The 12
|
||||
vector rows share lowering; one probe proves vector add is wrong. Individual
|
||||
rows may have additional causes (e.g. `pr123625` also has `i64` and `switch`
|
||||
structure), which M13 will find when it touches each family.
|
||||
- **`-O2` passes are not correctness evidence.** They show generic
|
||||
optimization can fold the failing shape; the suite gate is `-O0`.
|
||||
- **`20031003-1` is C UB** (out-of-range float→int). It is listed as a
|
||||
conversion difference, not a promise to match GCC's saturated answer.
|
||||
- **`20230630-1` has a bare-tier host segfault** once its check passes. Any
|
||||
endianness fix must either add it to `full-suite.full-loader` (it passes
|
||||
there) or resolve the MAME instability first.
|
||||
- **The endianness one-flag change is a trap.** The regression on `20230630-2/-4`
|
||||
is the reason it is not proposed; record it before M13 starts.
|
||||
|
||||
## 9. Raw evidence
|
||||
|
||||
- Harness: `scripts/tests/m12/abort-triage.sh`
|
||||
- Raw Markdown table: `build/m12-abort-triage/abort-triage.md`
|
||||
- Machine-readable tables: `build/m12-abort-triage/abort-triage.tsv`,
|
||||
`build/m12-abort-triage/abort-triage.evidence.tsv`
|
||||
- Per-test logs and results: `build/m12-abort-triage/logs/` and
|
||||
`build/m12-abort-triage/run-O0/` / `run-O2/`
|
||||
- Representative probe sources: `scripts/tests/m12/probes/` (with its
|
||||
`README.md`, `cause-map.tsv` and historical `logs/`); the same files were
|
||||
originally written under `build/m12-abort-triage/probes/`
|
||||
|
||||
## 10. Task 6 outcome
|
||||
|
||||
`eeprof-1` is the only row this triage fixes in M12. Task 6 added
|
||||
`-finstrument-functions` forwarding to `dialect_flags()` (per row, when
|
||||
`dg-options` asks for it), verified the unmodified test at `-O0` and `-O2`
|
||||
through the M5 runner, and removed the curated row. The other 53 rows stay
|
||||
curated with the causes above and are M13's input. The suite accounting moves
|
||||
by this one row (1,618 → 1,635 pass, 294 → 277 skip across all M12 flips; see
|
||||
the README's M12 section for the per-row list).
|
||||
@@ -458,6 +458,492 @@ plan/ledger ruling).
|
||||
> `JR`/`MMTM`, and the curated conformance tier. **Debug info is M7** per
|
||||
> the M6 plan and ledger ruling (`progress.md`), not M6.
|
||||
|
||||
### M7 — correctness residuals, object/debug, hardware, conformance
|
||||
|
||||
M7 closes the M6 boundary in four sequential sub-milestones. Each has its own
|
||||
design/plan, subagent-driven execution, task reviews, final whole-branch
|
||||
review, and a push of the `m7` branch (default unchanged unless the user
|
||||
asks). M2–M6 remain binding.
|
||||
|
||||
- **M7.1 — correctness and ABI residuals.** (a) The `-O2` bit-pointer
|
||||
semantic barrier: `tms-clang` scales GEPs to calls to an opaque
|
||||
`@__tms_bitptr(i32 bitoff, ptr base)` before the optimizer, scales only the
|
||||
optimizer-created byte GEPs afterwards, then lowers the bitptr calls to
|
||||
`inttoptr(add(ptrtoint,...))` and runs a final instcombine. This removes the
|
||||
`p += n` over-scale while preserving the M0 `int_diff = 8/32` contract; the
|
||||
shim `memmove` workaround is removed. (b) The sub-byte array/nested-record
|
||||
stride: emit a loud, default-on diagnostic for arrays and nested members of
|
||||
records whose bit content is not a byte multiple (TI advances by the bit
|
||||
content; Clang's byte-rounded `sizeof` would silently diverge), or implement
|
||||
the bit-content stride if a sound lowering is found. (c) `.data`
|
||||
initializers for i64, aggregates/unions and bitfield globals, including the
|
||||
object path and relocations; i64 words are little-endian/least-significant
|
||||
first. (d) Keep the nonzero byte-offset narrow-load/store guard.
|
||||
- **M7.2 — object/debug.** (a) Debug info in the native TI-COFF object:
|
||||
`llc -march=tms34010 -filetype=obj` on a module with `!dbg` metadata emits
|
||||
DWARF line/source sections (`.debug_info`, `.debug_abbrev`, `.debug_line`,
|
||||
`.debug_str`, and the auxiliary sections LLVM produces) as non-allocated
|
||||
COFF sections; long section names use the COFF `/offset` string-table form.
|
||||
The native linker resolves their relocations and, by default, strips them
|
||||
from the load image; `--keep-debug` retains them for tools. M7.2 supports one
|
||||
debug-bearing object per link (multi-TU DWARF merging is loud, M8); the
|
||||
`tms-link --map` output includes the section allocation and global symbol
|
||||
map; source-line information lives in the kept `.debug_line` sections and is
|
||||
dumped/validated with `llvm-dwarfdump` (Task 3), not parsed by the linker. (b) `tools/tms-link`
|
||||
is a native TI-COFF linker: it reads relocatable objects, resolves public
|
||||
symbols including names longer than GSPA's 31-character limit, lays out
|
||||
`.text`/`.data`/`.cinit` in the `prog` region and `.bss` in `ram`, applies
|
||||
the R-RELLONG fixups, and emits a position-dependent linked COFF with
|
||||
`nreloc = 0`, an optional header (entry, text/data/bss start and size) and a
|
||||
map. `.cinit` is a first-class section (TI init-record table: u16 word count,
|
||||
u32 destination, data words), placed after `.data`; the linker defines the
|
||||
public `cinit` symbol. (c) Object-path gates compare `tms-link` output with
|
||||
GSPLNK for the same objects (byte-identical allocated sections, identical
|
||||
symbol addresses, same MAME markers) and cover `.cinit`, >31-character
|
||||
public names, and a `llvm-dwarfdump`-validated debug image.
|
||||
|
||||
M7.2 acceptance: `llc -filetype=obj` emits a debug-bearing TI-COFF whose
|
||||
`.debug_*` sections validate with `llvm-dwarfdump` after the linker keeps them;
|
||||
the default linked image is debug-stripped and the loader/MAME acceptance is
|
||||
unchanged; `tms-link` links the M5 native objects with allocated-section
|
||||
bytes and symbol addresses equal to GSPLNK (the M6 gates continue to link
|
||||
with GSPLNK; both use the same object writer); a C `.cinit` table is placed,
|
||||
relocated and processed by an entry in MAME; two TUs with a 40-character public
|
||||
function link and run; every M2–M7.1 gate stays green.
|
||||
- **M7.3 — runtime and hardware.** (a) The wider Xlib surface: add the
|
||||
remaining ROM-validated entries from the Ghidra/dis34 table
|
||||
(`XMapSubwindows`, `XChangeWindowAttributes`, `XConfigureWindow`,
|
||||
`XInternAtom`, `XChangeProperty`, `XChangeGC`), extend `x11m4.h`, and add a
|
||||
client (`xmore`) that exercises them together with text (`XLoadFont`,
|
||||
`XDrawString`), drawing, and a heap image (`XCreateImage`/`XGetImage`/
|
||||
`XPutImage`/`XDestroyImage`), with MAME markers and no X errors;
|
||||
`scripts/m4/validate-syms.sh` validates every added address. (b) stderr
|
||||
capture: the conformance shim exposes a distinct `stderr` stream
|
||||
(`fprintf`/`fputs`/`fputc`/`fwrite`) into a second buffer/length cell, the
|
||||
runner and MAME check compare it (`--expect-stderr`/`;stderr=`), and
|
||||
selftests cover empty, non-empty and truncated stderr. (c) Real-hardware
|
||||
validation for the VT1200: a harness builds the marker client at the proven
|
||||
hardware origins (`018C0000`/`018D0000`/`018D8000`), runs the same COFF in
|
||||
MAME (the permanent acceptance), and, with `VT1200_HOST` set, drives
|
||||
`dwt/loader/hostload.py --marker` over rdebug against the real unit. The
|
||||
unit is unavailable for the first two weeks, so the hardware run is
|
||||
**DEFERRED** and does not block M7; the harness and its MAME-equivalent
|
||||
acceptance are delivered now.
|
||||
|
||||
M7.3 acceptance: `xmore` runs in MAME with the expected markers and no X
|
||||
errors, and every added Xlib address passes `validate-syms`; the stderr
|
||||
selftests prove empty, formatted and truncated stderr; the hardware gate
|
||||
passes its MAME marker check and reports `HARDWARE: DEFERRED` without a unit
|
||||
(the same command runs `hostload.py --marker` when `VT1200_HOST` is set); every
|
||||
M2–M7.2 gate stays green.
|
||||
- **M7.4 — conformance and performance.** (a) Full external suites: run the
|
||||
pinned GCC 16.2.0 `gcc.c-torture/execute` corpus (1,692 files) and the
|
||||
c-testsuite `single-exec` corpus (220) beyond the curated lists, at `-O0`
|
||||
with the conformance classifier; every test is pass, an honest
|
||||
feature/curation skip with a reason, or a recorded failure category — never
|
||||
an unclassified crash. The bounded `-O2` subsets stay as the optimization
|
||||
smoke tier. (b) Performance: an i64 divide/remainder fast path that, after
|
||||
the signed absolute-value normalization, uses one 32-bit `DIVU` when both
|
||||
normalized high words are zero instead of the 64-step restoring loop (the
|
||||
signed forms divide magnitudes, so they also select `DIVU`), with the same
|
||||
quotient/remainder sign fixup, unit/asm coverage, the M6 i64 gate, and a
|
||||
cycle/frame-based measurement gate. (c) Final M7
|
||||
docs, exact counts, known limitations, and the M7/M8 boundary (M8 owns
|
||||
multi-TU DWARF merging, `.lib` linking, the real VT1200 run if still
|
||||
deferred, and any remaining performance work).
|
||||
|
||||
M7.4 acceptance (met, M7 complete): the full pinned corpora account for
|
||||
**1,912** files — c-torture **1,692 = 1,366 pass / 326 skip / 0 fail / 0
|
||||
crash** and c-testsuite **220 = 210 pass / 10 skip / 0 fail / 0 crash** —
|
||||
with every skip carrying a classifier or curation reason and the 272 curated
|
||||
rows re-run without skips (272/272 still failed). The i64 fast path uses one
|
||||
32-bit `DIVU` when both normalized operands' high words are zero; the
|
||||
implementation divides magnitudes for the signed forms as well, so `DIVU` is
|
||||
emitted and `DIVS` is not (this matches the M6 loop's unsigned
|
||||
compare/subtract). The MAME measurement is `fast_frames=90 slow_frames=2424
|
||||
ratio=26.9` for the same 16,384 iterations, status `600D600D`, checksums
|
||||
`000000011E6F9AB4`/`00000000007512AE`. Every M2–M7.3 gate stays green; lit is
|
||||
**118/118** (114 CodeGen + 4 MC) and the shipped c-testsuite tier remains the
|
||||
curated 48 pass / 172 skip. The real VT1200 run is still **DEFERRED**; M8
|
||||
owns multi-TU DWARF merging, `.lib` linking under `tms-link`, the hardware
|
||||
run, the remaining conformance classes and further performance work.
|
||||
|
||||
M7.1 acceptance: the `p += n` shape is correct at the default `-O2` with one
|
||||
scale; M0 `int_diff` 8/32; the stride diagnostic fires for the oracle shapes
|
||||
and not for byte-multiple records; `.data` i64/aggregate/bitfield globals
|
||||
assemble/link/load with exact bytes; every M2–M6 gate stays green; MAME and
|
||||
the dwt loader are the acceptance environment.
|
||||
|
||||
### M8 — object/link completeness, conformance depth, hardware
|
||||
|
||||
M8 closes the M7/M8 boundary in four workstreams, using the same plan,
|
||||
subagent-driven execution, review and push discipline as M7. The `m7` branch
|
||||
is the M8 baseline and the repository default; M8 work is on `m8` and does not
|
||||
change the default unless the user asks.
|
||||
|
||||
- **M8.1 — native `.lib` linking.** `tools/tms-link` reads System V/`ar`
|
||||
archives (the 1990 `flib.lib`/`rts.lib` are `!<arch>` with TI-COFF members),
|
||||
performs iterative selective extraction of members that define needed
|
||||
symbols, resolves duplicate/undefined symbols loudly, and exposes the
|
||||
libraries through the CLI and the `M4_LINKER=tms-link` path. GSPLNK remains
|
||||
the oracle; the M5/M6 native and runtime gates must produce the same
|
||||
allocated bytes/symbol addresses (and MAME markers) with either linker.
|
||||
Acceptance: M4/M5/M6 native links that need `flib`/`rts` link with
|
||||
`tms-link`, produce a loader-accepted image with the expected markers, and
|
||||
match GSPLNK on the allocated image; unmatched/duplicate archive symbols
|
||||
fail loudly.
|
||||
- **M8.2 — multi-TU DWARF merging.** The native linker merges debug
|
||||
information from multiple debug-bearing objects: concatenate `.debug_info`
|
||||
CUs while adjusting `.debug_abbrev`/`.debug_str_offsets`/`.debug_addr`/
|
||||
`.debug_line` section-relative contributions and their relocations; keep
|
||||
section-relative offsets correct, resolve line/file tables, and validate the
|
||||
result with `llvm-dwarfdump`. The default load image remains debug-stripped;
|
||||
`--keep-debug` is the tool image. Acceptance: a two- or three-TU program
|
||||
built with debug info links with `--keep-debug`, `llvm-dwarfdump` reports
|
||||
every TU's functions/lines/addresses, and the stripped image still runs in
|
||||
MAME; a single-TU link remains byte-compatible with M7.
|
||||
- **M8.3 — conformance depth and performance.** Raise the full-suite pass
|
||||
rate by fixing or honestly re-curating the remaining classes (codegen
|
||||
rotates/`cttz`/`bswap`/`blockaddress`/vectors, inline-asm constraints,
|
||||
sret/aggregate/variadic/float returns, VLAs, nested functions, libm and the
|
||||
frame-limited timeouts), and extend performance work beyond the 32-bit i64
|
||||
fast path (e.g. a 64/32 path when the divisor fits 32 bits) with measured
|
||||
evidence. Acceptance: the full pinned corpora still account for every file
|
||||
with 0 unclassified crashes and an honest skip list; the newly fixed classes
|
||||
flip to pass and are recorded; any new performance path is measured against
|
||||
the existing slow path.
|
||||
- **M8.4 — hardware and close-out.** Run the real VT1200 hardware harness when
|
||||
the unit is available (the harness and MAME-equivalent acceptance already
|
||||
exist), record the real-unit evidence, and produce the final M8 docs/counts/
|
||||
limitations and the M8/M9 boundary. The hardware run remains deferred and
|
||||
does not block M8.1–M8.3; if it is still unavailable, mark it deferred and
|
||||
state that explicitly.
|
||||
|
||||
M8.3 also runs the corpora on a bare-metal MAME tier by default (sections
|
||||
mapped, `.bss` zeroed, PC/SP set, no firmware/loader), using the 2ine-hosted
|
||||
1990 OS/2 assembler and `tms-link`; the curated M5/M6 loader gates, X11/runtime
|
||||
and an explicit full-loader exception list keep the loader tier. The accounting
|
||||
and acceptance counts are unchanged.
|
||||
|
||||
M8.1 acceptance: a library-only link (no GSPLNK) resolves the needed members
|
||||
and runs; M8.2 acceptance: multi-TU debug links and validates; M8.3
|
||||
acceptance: the full corpora remain fully accounted with the recorded flips;
|
||||
M8.4 acceptance: the final docs/boundary are accurate and the hardware status
|
||||
is explicit.
|
||||
|
||||
M8 acceptance (met, M8 complete): `tms-link` reads the System V `ar`
|
||||
`FLIB.LIB`/`RTS.LIB`, extracts needed members iteratively and links the M4/M5/
|
||||
M6 library programs with allocated bytes, section metadata and public symbols
|
||||
equal to GSPLNK 2.00 (`scripts/tests/m8/native-lib.sh`, 3 sections, 16 public
|
||||
`C_EXT` addresses, MAME markers). Multi-TU `--keep-debug` concatenates and
|
||||
rehomes the supported DWARF5 sections; `llvm-dwarfdump` shows both TUs'
|
||||
functions, lines and linked PCs, the stripped image runs in MAME, and the
|
||||
single-TU link is byte-identical to M7 (`scripts/tests/m8/dwarf-multi.sh`).
|
||||
The bit-op class (rotate/`cttz`/`ctpop`/`ctlz`/`bswap`) lowers without invented
|
||||
instructions. At M8 the three-phase gate measured the 64/32 i64 divide path at
|
||||
**218** frames versus **2,440** for the 64-step loop (11.2×) and the fits-32
|
||||
path at **87** (28.0×), status `600D600D`, checksums
|
||||
`000000011E6F9AB4`/`00000000007512AE`/`00025AF70AF974E0`; M9.3 makes the gate
|
||||
four-phase, narrows the wide input to force the two-`DIVU` helper, and re-pins
|
||||
the wide checksum (see the M9 acceptance). The fresh end-to-end full suite
|
||||
accounts for **1,912 = 1,596 pass / 316 skip / 0 fail / 0 crash** (c-torture
|
||||
**1,386 / 306**, c-testsuite **210 / 10**), with 64 classifier plus 252
|
||||
curated skips, each with a reason; the 20 flipped rows are the six rotates,
|
||||
six `cttz`, four `bswap` and four per-test `LOADER_END=2000` runtime rows.
|
||||
Lit is **120/120** (116 CodeGen + 4 MC) and clang Sema/CodeGen **5/5**. The
|
||||
real VT1200 run remains **DEFERRED** (`VT1200_HOST` unset; the hardware gate
|
||||
prints `HARDWARE: DEFERRED` on the MAME-equivalent acceptance). M9 closed vector
|
||||
`.data` and inline-asm `r`, the DWARF future-producer/`.debug_rnglists`
|
||||
caveats and the 64/32 divide path; M10 owns the remaining classes
|
||||
(`blockaddress`, vector runtime, inline-asm memory constraints, nested
|
||||
functions, VLAs, sret/aggregate/variadic/float returns, libm, runtime aborts),
|
||||
the pre-existing `pr63843` hang, further performance work and the real VT1200
|
||||
run when the unit is available.
|
||||
|
||||
### M9 — conformance classes, debug depth, performance
|
||||
|
||||
M9 builds on the M8 baseline (`m8`, default) and uses the same plan,
|
||||
subagent-driven loop, review and push discipline. Work is on `m9`; the default
|
||||
is promoted to `m9` only after the final review, per the repository policy.
|
||||
|
||||
- **M9.1 — conformance classes.** Remove the highest-value remaining M8 skips:
|
||||
vector `.data` initializers (integer/fp vector constants emitted as their
|
||||
exact element bytes in the raw and object paths) and inline-asm `r`/`=r`
|
||||
register constraints (map the target's A-register classes; reject
|
||||
unsupported constraints loudly). The affected full-suite rows must flip to
|
||||
pass and be recorded; `blockaddress`, nested functions, VLAs, sret/
|
||||
aggregate/variadic/float returns and libm remain explicit M10 boundaries.
|
||||
- **M9.2 — debug/linker depth.** Replace the M8 raw-offset assumption with a
|
||||
form-aware DWARF walker (or an input gate that rejects any unrelocated
|
||||
section-relative field), add a `.debug_rnglists` fixture and merged-range
|
||||
validation, and keep the single-TU output byte-compatible. The default load
|
||||
image stays stripped; `--keep-debug` remains the tool image.
|
||||
- **M9.3 — performance.** Add a single `DIVU` 64/32 fast path when the divisor
|
||||
fits 32 bits and the quotient fits (or another equally justified path),
|
||||
measured against the M8 64/32 two-DIVU path and the 64-step loop. The bare
|
||||
conformance tier remains the default; no test-accounting regression.
|
||||
- **M9.4 — hardware and close-out.** Run the real VT1200 harness when the unit
|
||||
is available; otherwise keep `HARDWARE: DEFERRED` explicit. Produce the final
|
||||
M9 docs/counts/limitations and the M9/M10 boundary.
|
||||
|
||||
M9 acceptance (met, M9 complete): vector `.data` and inline-asm `r`/`=r`
|
||||
constraints are fixed with **22** recorded flips (20 inline-asm `r`, `simd-5`
|
||||
and `pr123625-2`), and the five remaining candidates stay curated with
|
||||
corrected reasons (i64 `r` pair, timeout, two vector runtime aborts, memory
|
||||
operand). Lit is **129/129** (125 CodeGen + 4 MC). The multi-object
|
||||
`--keep-debug` path walks every form and refuses pre-v5 producers and any
|
||||
unrelocated section-relative field loudly; the two-TU `.debug_rnglists`
|
||||
fixture and a real `-O2 -g` producer both validate with `llvm-dwarfdump`, the
|
||||
single-TU bytes keep the M8 layout, and the stripped image still runs. The
|
||||
four-phase i64 gate measures fast **88**, slow **3,302**, wide **221** and
|
||||
div32 **120** frames — **37.5×** (fast) and **14.9×** (wide) versus the loop,
|
||||
and **1.8×** for div32 versus the two-DIVU wide phase — with
|
||||
status `600D600D` and checksums `000000011E6F9AB4`/`00000000007512AE`/
|
||||
`F56810CFEDA9D656`/`00002C61C63842EE`; the new path is correct for
|
||||
signed/unsigned, divide-by-zero UB, and `INT64_MIN` (which never fits 32 bits:
|
||||
it keeps the two-step helper for a divisor of at most `2^31` and takes the
|
||||
single-`DIVU` path for a divisor in `(2^31, 2^32)`). The fresh two-tier full
|
||||
suite accounts for every file: **1,912 = 1,618 pass / 294 skip / 0 fail / 0
|
||||
crash** (c-torture **1,408 / 284**, c-testsuite **210 / 10**), with every skip
|
||||
carrying a reason and the 10 full-loader exceptions explicit. Every M2–M8.4
|
||||
gate stays green and the new M9 lit/DWARF gates pass, while the real VT1200
|
||||
run remains **DEFERRED**. M9 is complete; the remaining classes are the M9/M10
|
||||
boundary.
|
||||
|
||||
### M10 — the native clang pipeline (Phase 2)
|
||||
|
||||
M10 moves the bit-address transform and this target's compile defaults into
|
||||
the target, so native `clang --target=tms34010 -c` is correct for pointer code
|
||||
at `-O0` and `-O2` with **no extra flags
|
||||
and no wrapper**. `m10` is the repository default (the promotion lands with this
|
||||
push; `m9` is the previous snapshot). The binding design is
|
||||
`2026-11-17-tms34010-phase-2-3-design.md` §7.
|
||||
|
||||
- **The `ToolChain`.** A minimal `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}`
|
||||
(`BareMetal` subclass, registered in `CMakeLists.txt`/`Driver.cpp`) supplies
|
||||
`-ffreestanding`, `-fno-builtin`, `-mllvm -replexitval=never`,
|
||||
`-disable-O0-optnone` and no system includes; `-c`/`-S` are the surface (no
|
||||
link job yet).
|
||||
- **The pipeline.** `registerPassBuilderCallbacks` runs the
|
||||
`@__tms_bitptr` barrier at pipeline start (plus lowering at `-O0`) and
|
||||
scale → lower → final InstCombine at optimizer-last (gated to `Level != O0`);
|
||||
a `"tms.bitaddr"` module flag (absent → `1` → `2`) makes it idempotent, and a
|
||||
legacy lowering pass in `addISelPrepare` is the codegen safety net.
|
||||
- **`tms-clang`** becomes a thin flag mapper; the four gates that traced its
|
||||
internals assert the same invariants at the driver seam.
|
||||
|
||||
M10 acceptance (met, M10 complete): native
|
||||
`clang/test/CodeGen/TMS34010/bitaddr-o0.c`/`bitaddr-o2.c` pin `p[1]` → `ADDI
|
||||
32` (i32), `ADDI 16` (`short`), `ADDI 32` (`char p[4]`) at `-O0` and `-O2`, and
|
||||
an ordinary `sumto` loop compiles at `-O2` with no extra flags;
|
||||
`bitaddr-static-vararg.c` pins the guard at `-O0`/`-O1`/`-O2`,
|
||||
`float-const-o2.c` pins the pre-optimizer f32/f64 constant protection, and
|
||||
`tms34010-defaults.c` pins the `ToolChain` defaults. Native `-O0` (and `-O0
|
||||
-g`) objects are **byte-identical** to the M9 path across the 23-file corpus
|
||||
(`scripts/tests/m10/equivalence.sh`, **46/46** at `-O0` and `-O0 -g`);
|
||||
idempotency is
|
||||
`scripts/tests/m10/bitaddr-idempotent.sh`. TMS34010 lit is **132/132** (128
|
||||
CodeGen + 4 MC) and clang is **10** (8 CodeGen + the driver
|
||||
`tms34010-defaults.c` + the Sema subbyte-stride test), for **142** lit in
|
||||
total; the serial M0–M8 gate list is **58 invocations across 54 distinct gate
|
||||
scripts, all passing**, with `HARDWARE: DEFERRED`.
|
||||
The fresh two-tier full
|
||||
suite is unchanged at **1,912 = 1,618 pass / 294 skip / 0 fail / 0 crash**, the
|
||||
four-phase i64 gate is unchanged at fast **88** / slow **3,302** / wide **221** /
|
||||
div32 **120** frames (37.5× / 14.9× / 1.8×, checksums
|
||||
`000000011E6F9AB4`/`00000000007512AE`/`F56810CFEDA9D656`/`00002C61C63842EE`),
|
||||
and the hardware run remains **DEFERRED**. `m5/jr.sh` re-pins the linked
|
||||
`.text` to **910** bytes (the first M10 pin of 850 was measured through the
|
||||
pre-fix `-O2` bit-offset-aliasing and float-constant-folding hazards; the
|
||||
correctness fixes below cost instructions and restore the M9 legacy value;
|
||||
the JR count is unchanged).
|
||||
|
||||
The `-O2` bit-address aliasing gap is fixed with three changes. (1)
|
||||
DAGCombiner's `BaseIndexOffset` aliasing reads address offsets in **bytes**, so
|
||||
every target-computed bit offset now routes through a `TMS34010ISD::BITADDR`
|
||||
node (selected straight to `ADDI`) for the f64/i64/aggregate return-slot and
|
||||
hidden-return reads; `BaseIndexOffset` does not match the custom node, so
|
||||
aliasing falls back to the byte-accurate `MachinePointerInfo` and the
|
||||
program-order chain is kept, and a zero offset stays the base itself so `-O0`
|
||||
objects remain byte-identical. (2) `f32`/`f64` literals are protected
|
||||
**before** the optimizer: `TMS34010LowerFloatConstantsPass` runs at clang
|
||||
pipeline start for `-O1`+ and replaces each literal store/return/argument with
|
||||
a volatile load from a GSP-initialised global, so the middle-end cannot fold
|
||||
`bitcast(float C to i32)` to IEEE bits (the late llc pass keeps plain loads and
|
||||
still covers `-O0`). (3) Closing those two exposed the underlying class: any
|
||||
address built as `inttoptr(add(ptrtoint, bits))` folds to a plain `ISD::ADD` on
|
||||
this 32-bit-pointer target, so ordinary source pointer arithmetic was still
|
||||
miscompiled at `-O2` (reproducer `p[0]=v; p[1]=w; ((char*)p)[5]=0x7f;` stored
|
||||
the byte before the word store). This is the bit-address aliasing mechanism,
|
||||
fixed by a target intrinsic `llvm.tms34010.bitaddr` that lowers to `BITADDR` and
|
||||
is now used by **every** runtime pointer-offset emitter — the barrier lowering,
|
||||
the aggregate/i64/narrow-mem leaves and both GEP-scaling passes (regression
|
||||
tests `m10-bitaddr-chain-i64.ll`, `bitaddr-chain-o2.c`). The residual is
|
||||
documented: `scaleConstantGep` emits a compile-time `ConstantExpr` address,
|
||||
which cannot hold a call, so it folds to a `GlobalAddress+offset` and no
|
||||
runtime `ADD` exists to mis-decompose (not reachable at `-O2`). With
|
||||
these, `m6/float.sh` (8 float markers), `m6/aggregate.sh` (2 markers),
|
||||
`m6/i64.sh`, `m6/bitfield.sh`, `m6/varargs.sh` and `m6/runtime.sh` all pass at
|
||||
`-O0` and `-O2`. `scripts/m3/run.sh` compiles `branch` with `-fno-inline` at
|
||||
`-O2` (chosen over `-O0` to keep the pinned condition codes), so
|
||||
`m3/dis-roundtrip.sh` keeps its `_sumto`/`_max2`/`_lt` calls to check. The
|
||||
**M10/M11 boundary** is Phase 3: a committed CRT
|
||||
(`crt0.o` via `llvm-mc`), headers, `libtms.a`, a sysroot and a `tms-link` link
|
||||
job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper.
|
||||
(The M11 design corrected the CRT build path: `llc -filetype=obj`, not
|
||||
`llvm-mc` — see the M11 section below.)
|
||||
|
||||
### M11 — the conventional toolchain (Phase 3)
|
||||
|
||||
M11 closes the gap between "a compiler that emits objects" and "a toolchain you
|
||||
can use": `clang --target=tms34010 hello.c -o hello` links a loader-valid TI-COFF
|
||||
image through `tms-link`, with a CRT, headers and a C library discovered through
|
||||
a sysroot — after one `scripts/tms-sdk`. The binding design is
|
||||
`2026-11-18-tms34010-m11-conventional-toolchain-design.md` §8.
|
||||
|
||||
- **The sysroot.** `scripts/tms-sdk [--sysroot DIR]` builds `sdk/crt0.ll` with
|
||||
`llc -march=tms34010 -filetype=obj` and `sdk/{shim,heap}.c` with
|
||||
`clang --target=tms34010 -O2 -c` plus `llvm-ar rcsD` into `libtms.a`, then
|
||||
installs `<sysroot>/{include,lib,bin}`: the **10** headers (`assert, limits,
|
||||
math, stdarg, stdbool, stddef, stdint, stdio, stdlib, string` — there is no
|
||||
`ctype.h`), `lib/{crt0.o,libtms.a,flib.lib,rts.lib}` and the
|
||||
`tms-link`/`tmscoff.py` pair. The default sysroot is
|
||||
`<clang -print-resource-dir>/tms34010-unknown-none`; `--sysroot DIR` installs
|
||||
elsewhere (the driver then needs `--tms-sysroot=DIR`). Installing is
|
||||
idempotent: `llc` and `llvm-ar rcsD` rebuild byte-identically.
|
||||
- **The CRT.** `sdk/crt0.ll` is a `naked` `_start` with inline asm blocks, built
|
||||
by `llc -filetype=obj`: `llvm-mc` emits ELF for this triple (and the generic
|
||||
COFF path refuses a non-Windows triple), so the target's TI-COFF writer is
|
||||
reachable only through CodeGen. The rewrite preserves the contract, not the
|
||||
text: `setf 16/32`, the 4 KiB `_cstack`, the `{"conformance", NULL}` argv, the
|
||||
result block at `01B00000`/`40`/`60`, the output buffers `01B10000`/`01B30000`,
|
||||
and the `_start` symbol for `--entry`.
|
||||
- **The link job.** `TMS34010Linker` invokes `<sysroot>/bin/tms-link` (or
|
||||
`--tms-linker=PATH`) with `--entry _start --text 018A0000 --bss 01A00000
|
||||
--prog-len 40000h --ram-len 80000h`, a default `--map`, `-g` → `--keep-debug`
|
||||
(not `-g0`/`-ggdb0`), `-Wl,` passthrough (with `-Map=`/`-Map,<file>`
|
||||
translated to `--map=<file>`), the CRT, the user objects, `libtms.a flib.lib
|
||||
rts.lib`, `-L <sysroot>/lib` and the user `-L`/`-l`. A missing
|
||||
sysroot/linker/`python3` is a named diagnostic pointing at `scripts/tms-sdk`
|
||||
(except `python3`, which names installing `python3`) — `python3` is a
|
||||
link-time dependency because `tms-link` is a Python program. A sysroot
|
||||
directory that exists but lacks `crt0.o`/`libtms.a`/`flib.lib`/`rts.lib`
|
||||
names the missing artifact instead of handing `tms-link` a bare name.
|
||||
- **Link-reduction knobs.** `-nostartfiles` drops `crt0.o`, `-nodefaultlibs`
|
||||
drops `libtms`/`flib`/`rts`, `-nostdlib` implies both. `-l tms` links
|
||||
`libtms.a` once per request (a repeated `-l tms` links the archive again).
|
||||
- **`tms-cc`** stays as a compatibility alias; new documentation points at
|
||||
`clang --target=tms34010`.
|
||||
|
||||
M11 acceptance: `scripts/tests/m11/{sdk,crt,e2e}.sh` PASS — the headline
|
||||
command from a clean shell, two TUs, `-c`/`-S`/`-E`, `-O0`/`-O2`, `-g` vs
|
||||
stripped, `-nostdlib`, and the no-checkout-path assertion. TMS34010 lit is
|
||||
**132/132** (128 CodeGen + 4 MC), clang **13** (10 CodeGen + 2 Driver + 1 Sema),
|
||||
`tools/tms-link`/`tools/tms-bitaddr` tests PASS, the two-tier suite is unchanged
|
||||
at **1,912 = 1,618 pass / 294 skip / 0 fail / 0 crash**, the four-phase i64
|
||||
gate is unchanged at fast **88** / slow **3,302** / wide **221** / div32 **120**
|
||||
frames (37.5× / 14.9× / 1.8×, checksums `000000011E6F9AB4` /
|
||||
`00000000007512AE` / `F56810CFEDA9D656` / `00002C61C63842EE`), and
|
||||
`HARDWARE: DEFERRED`. The linker emits images that pass
|
||||
`scripts/m4/coff-check.py` unaided: M11 moved the `.bss` rounding into
|
||||
`tms-link`, so `coff-check.py --repair` is no longer on the production path (it
|
||||
survives only for the legacy GSPLNK harness). Known limitations: a bare
|
||||
`-Wl,-Map` sets an explicit-map request but names no file, so it suppresses the
|
||||
default map and produces none (use `-Wl,-Map=<file>`) — and a repeated `-l tms`
|
||||
under `-nodefaultlibs` duplicates the archive. The Task 6
|
||||
sweep's one stale M7 gate check was fixed in `7fcae6e`: `m7/debug.sh` now
|
||||
asserts the `llvm.tms34010.bitaddr` spelling (the M10 aliasing fix replaced the
|
||||
`add i32` lowering) and still requires `!dbg` on the barrier instructions.
|
||||
### M12 — tractable conformance gaps, and the abort triage
|
||||
|
||||
M12 takes the conformance classes with known backend/driver mechanics and
|
||||
turns the largest unknown bucket (runtime aborts) into a costed M13 list. The
|
||||
binding design is
|
||||
`2026-11-19-tms34010-m12-tractable-gaps-design.md`; the triage report is
|
||||
`../research/2026-11-19-tms34010-abort-triage.md`. Branch `m12` is the
|
||||
milestone branch on both repositories; promotion is pending the controller's
|
||||
review (`m11` remains the default until then).
|
||||
|
||||
- **The 17 flips, row by row.** The inline-asm memory rows `pr103376`,
|
||||
`pr40022`, `pr40657`, `pr56866`, `pr65053-2`, `pr68328`, `pr81588`,
|
||||
`pr82954`, `pr85156`, `pr94130` (10); the computed-goto rows `920501-3`,
|
||||
`990208-1` (2); the level-0 frame rows `20030811-1`, `frame-address`,
|
||||
`pr17377` (3); the dynamic-alloca row `20070824-1` (1); and `eeprof-1` (1),
|
||||
the one-flag/one-condition harness fix that forwards
|
||||
`-finstrument-functions` from the test's own `dg-options`. The eleventh
|
||||
inline-asm row, `stkalign`, now selects its memory operand but aborts on
|
||||
`__alignof__(s) == 64` under the packed-struct ABI; it was re-reasoned as
|
||||
`runtime-abort-alignment`, not flipped. Suite accounting is
|
||||
**1,912 = 1,635 pass / 277 skip / 0 fail / 0 crash** (1,618 + 17,
|
||||
294 − 17; c-torture 1,425/267, c-testsuite 210/10).
|
||||
- **Inline-asm memory operands; the `ST`/`o`/`V` decisions.**
|
||||
`SelectInlineAsmMemoryOperand` matches the reachable load/store addressing
|
||||
forms for `m` and `g`; an unmatchable operand is a named error. A selected
|
||||
memory operand must also print: `PrintAsmMemoryOperand` emits `*An` or
|
||||
`*An(disp)` with the folded bit displacement (`SP` for `A15`), pinned by a
|
||||
`-no-integrated-as` check; previously only empty templates worked. `o`
|
||||
accepts only the non-post-increment, non-negative-displacement form. `V` stays loud:
|
||||
`InlineAsm::ConstraintCode` has no `V` and `SelectionDAGBuilder` asserts
|
||||
before the target hook, so it needs a core enum change outside this charter.
|
||||
`"st"` joins `getGCCRegNames()` so `~{st}` is a nameable clobber, while `ST`
|
||||
remains outside every register class and every operand constraint (no
|
||||
allocation, no save/restore, value operands still rejected).
|
||||
- **`jump Rd` and computed goto.** The ISA's indirect jump (opcode `0x0160`,
|
||||
vendor ONEREG table) is implemented end to end (instruction definition, MC
|
||||
encoding `jump A0` = `[0x60, 0x01]`, parser, printer, disassembler);
|
||||
`ISD::BRIND` lowers to it, and `ISD::BlockAddress` lowers to a
|
||||
section-relative **bit** address through the normal `MOVI`/R-RELLONG path —
|
||||
no absolute load address.
|
||||
- **Level-0 frame intrinsics, with the capture mechanism.** The return word is
|
||||
on the system stack at `SP + NumSaved*32` measured from the post-FP/`MMTM`
|
||||
pointer. A use-site SP-relative load was reproduced sinking into the
|
||||
saved-STK push window at `-O1`/`-O2` (it read the saved `A13`); the shipped
|
||||
lowering captures the word once in the prologue — after the FP/callee-save
|
||||
pushes — into a normal `A13`-relative stack object with matching
|
||||
fixed-stack MMOs, and every `llvm.returnaddress(0)` use loads that stable
|
||||
slot. The two capture-scratch pushes move SP, so the sequence forms
|
||||
`SP + (NumSaved + 2)*32`:
|
||||
`PUSH32 A0; PUSH32 A1; MOVE A15, A0;
|
||||
ADDI A0, A0, (1 + CSI.size() + 2)*32; MOVE32Load A0, A0; MOVEFP A1;
|
||||
[ADDI slotoff, A1]; MOVE32Store A0, A1; POP32 A1; POP32 A0`.
|
||||
`llvm.frameaddress(0)` is `A13`. Levels above 0 stay a named error naming
|
||||
the intrinsic and level.
|
||||
- **Dynamic alloca.** The byte→bit scale already existed; the failure was the
|
||||
M8 shape assertion firing when the DAG constant-folds the `SHL 3` for a
|
||||
non-entry-block constant-count alloca (`20070824-1`). Both the constant and
|
||||
variable shapes now scale explicitly and no node shape is asserted.
|
||||
- **Abort triage (M13 input).** `scripts/tests/m12/abort-triage.sh` discovers
|
||||
the abort rows from the curated table and re-runs each at `-O0` and `-O2`:
|
||||
**54 rows** (52 aborts + 2 wrong results), **108 runs in 133 s**, **11
|
||||
causes** — aggregate varargs 13, vectors 12, 64-bit/packed bitfields 7,
|
||||
endian macro + SSO 5, packed/over-alignment 4, pointer↔int 4, signed zero 3,
|
||||
float↔int 2, RTS/shim 2, instrumentation 1, freestanding builtins 1. The
|
||||
report (`docs/superpowers/research/2026-11-19-tms34010-abort-triage.md`)
|
||||
carries the per-file evidence and §6's M13 ordering: **varargs → vectors →
|
||||
wide bitfields → endianness+SSO → alignment**, then the float groups.
|
||||
`eeprof-1` is the only row fixed here. The endianness `BigEndian = false`
|
||||
single change is rejected: it regresses `20230630-2`/`-4` once they select
|
||||
`scalar_storage_order("big-endian")`.
|
||||
- **Permanently out of scope.** Nested functions (30 rows; clang frontend
|
||||
refusal), VLA-in-struct (9; `will never be supported`), dialect strictness
|
||||
(8; `-Wint-conversion`/`-Wparen`/K&R under the pinned language mode) and
|
||||
timeouts/region limits (37; loader budget or the 45 KiB/64 KiB image
|
||||
regions). The triage's pointer↔int (4), RTS/shim (2) and freestanding
|
||||
builtins (1) are target-model/runtime policy and stay curated as well.
|
||||
- **The M12/M13 boundary.** M13 is the ABI shapes (sret,
|
||||
aggregate/variadic/float arguments and returns) plus the triaged abort
|
||||
causes in the order above; M14 is performance and the real VT1200 run
|
||||
(still `HARDWARE: DEFERRED`); M15 is optional hosted I/O. Every M0–M11 gate
|
||||
and the M11 end-to-end build stay green, and the four-phase divide gate is
|
||||
unchanged (88/3,302/221/120).
|
||||
|
||||
M12 acceptance: the full suite is **0 fail / 0 crash** with the accounting
|
||||
above; TMS34010 lit **142/142** (137 CodeGen + 5 MC), clang **15** (12 CodeGen +
|
||||
2 Driver + 1 Sema), the Generic sweep **197 = 152 pass / 45 unsupported**
|
||||
(`addr-label` flips with `blockaddress`), `tools/tms-link` and
|
||||
`tools/tms-bitaddr` PASS; the M11 gates, M10 equivalence (46/0) and the
|
||||
M0–M11 serial list PASS; `HARDWARE: DEFERRED`.
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
| risk | mitigation |
|
||||
|
||||
@@ -0,0 +1,474 @@
|
||||
# TMS34010 Phase 2 and Phase 3 — native clang pipeline and conventional toolchain
|
||||
|
||||
Status: proposed, revised after the builder check. Phase 1 (`tms-cc` usability
|
||||
driver) is complete and pushed on `m9` (project `55a0991`, compiler
|
||||
`4e7d48d2717e`).
|
||||
|
||||
Decisions already taken by the human partner:
|
||||
|
||||
| Decision | Choice |
|
||||
|---|---|
|
||||
| Phase 2 mechanism | Target-level pass hooks (Approach A) |
|
||||
| Phase 3 library scope | Freestanding, conventional UX (shim + SDK runtimes behind CRT/headers/ToolChain) |
|
||||
| clang-level defaults (`-replexitval=never`, `-ffreestanding`, …) | A minimal `ToolChain` lands in Phase 2 |
|
||||
| M10 success criterion | Runtime and suite equivalence, not byte-identical objects |
|
||||
| Vendor `flib`/`rts` archives | Committed to the repository |
|
||||
|
||||
## 1. Intent and why
|
||||
|
||||
Phase 1 gave a working one-command build (`scripts/tms-cc hello.c -o hello.coff`)
|
||||
but it hides a pipeline only the wrapper script knows about. Native
|
||||
`clang --target=tms34010 -c` still **miscompiles pointer code**. Verified on
|
||||
`m9`:
|
||||
|
||||
```c
|
||||
int load(int *p) { return p[1]; }
|
||||
```
|
||||
|
||||
- `clang --target=tms34010 -O0 -S` → `ADDI 4, A0` (byte offset — wrong; a 32-bit
|
||||
element is 32 bit-addresses away)
|
||||
- `scripts/tms-clang` + `llc` → `ADDI 32, A0` (bit offset — correct)
|
||||
|
||||
The cause is structural: LLVM GEP indices are byte units, TMS34010 pointers are
|
||||
bit addresses, and the optimizer re-forms byte GEPs from
|
||||
`inttoptr(add(ptrtoint, …))` unless an opaque barrier blocks it. Correctness
|
||||
needs three ordered steps — **pre-optimizer barrier → middle-end →
|
||||
post-optimizer scale, lower, final InstCombine**.
|
||||
|
||||
The builder check also showed the wrapper hides more than the barrier. Native
|
||||
`clang -O2 -c` fails on an ordinary loop because `IndVarSimplify` rewrites the
|
||||
loop's exit value into an i33 multiply that the target rejects;
|
||||
`scripts/tms-clang` avoids it with `-replexitval=never`, a pass option no
|
||||
`TargetMachine` can set. The wrapper additionally supplies `-ffreestanding`,
|
||||
`-fno-builtin`, `-nostdinc`, `-Xclang -disable-O0-optnone`, a pre-optimizer
|
||||
static-variadic guard, and `instcombine<no-verify-fixpoint>`. So Phase 2 is "the
|
||||
target owns the transform **and** the target's compile defaults", not the
|
||||
transform alone.
|
||||
|
||||
Phase 3 then makes the whole flow conventional: a CRT, headers, a library and a
|
||||
link job, so `clang --target=tms34010 hello.c -o hello` works with no wrapper
|
||||
and no project variables.
|
||||
|
||||
These are projects, not small changes. They map onto the repository's milestone
|
||||
pattern as **M10 (Phase 2)** and **M11 (Phase 3)**.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
### Phase 2 (M10)
|
||||
|
||||
1. `clang --target=tms34010 -c` is semantically correct for pointer code at
|
||||
`-O0` and `-O2`, with **no extra flags** and no wrapper script.
|
||||
2. `clang --target=tms34010 -O2 -c` compiles ordinary loop code (the i33 /
|
||||
`-replexitval` class) without the user passing anything.
|
||||
3. The transform lives in the target: `llvm/lib/Target/TMS34010/`, registered
|
||||
through `TMS34010TargetMachine::registerPassBuilderCallbacks`.
|
||||
4. A **minimal `ToolChain`** supplies this target's compile defaults
|
||||
(freestanding, no builtins, no system includes, `-replexitval=never`).
|
||||
5. `scripts/tms-clang` keeps its command-line contract but becomes a thin
|
||||
`clang` wrapper.
|
||||
6. Gates that observe the wrapper's internals are re-pointed at the new seam.
|
||||
7. Every M2–M9 gate, lit test and the 1,618-pass full suite stays green.
|
||||
|
||||
### Phase 3 (M11)
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` produces a loadable TI-COFF image
|
||||
that runs under `tms-run`, with no project wrapper and no `M4_*` variables.
|
||||
2. A committed, reproducible **CRT** (`crt0`), **headers** and **library**
|
||||
(`libtms.a`), plus the committed vendor `flib.lib`/`rts.lib`, resolved
|
||||
through a sysroot.
|
||||
3. The driver owns the link step: `tms-link` is the linker job, with `-l`, `-L`,
|
||||
`-nostdlib`, `-Wl,` and layout options passed through.
|
||||
4. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multiple TUs and `-nostdlib` behave the
|
||||
way they do for any freestanding clang target.
|
||||
5. Phase 1's user-visible behaviour (`printf` output via `tms-run`) is preserved.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- **Hosted C library.** No file I/O, no console/terminal driver, no `libm`, no
|
||||
locale. `printf` continues to write the conformance result block.
|
||||
- **lld.** TI-COFF is not an lld flavour; `tms-link` remains the linker.
|
||||
- **LTO.** Bitcode leaving a completed pipeline is final; re-optimizing it is
|
||||
unsupported.
|
||||
- **Changing the TI ABI, the all-stack convention, the GSPA/GSPLNK oracle, or
|
||||
the pointer model.**
|
||||
- **Replacing `llc`'s IR contract.** Hand-written IR passed straight to `llc`
|
||||
keeps the M9 meaning (§7.4).
|
||||
- **Byte-identical objects.** Explicitly dropped: native `-O2` IRGen differs
|
||||
from M9's `clang -O0` IRGen + `opt`, and `-O2` codegen differs from `llc -O0`
|
||||
(measured 424 vs 416 bytes on an integer-only file, different block layout).
|
||||
- Real VT1200 hardware validation (still deferred; no unit).
|
||||
|
||||
## 4. Anti-goals
|
||||
|
||||
- A user-visible flag that must be remembered for correctness. Correctness and
|
||||
this target's compile defaults are properties of the target.
|
||||
- Divergence in generic clang/LLVM beyond (a) the new
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` and (b) its two registration
|
||||
edits. Exported as patch `0005`, extended by Phase 3.
|
||||
- Two implementations of the transform that can drift. `tools/tms-bitaddr`
|
||||
becomes a **test oracle**, not a second production path.
|
||||
- Silently changing what a gate measures. Any gate edit must preserve the
|
||||
invariant it was asserting.
|
||||
|
||||
## 5. Current state (verified on `m9`)
|
||||
|
||||
| Fact | Evidence |
|
||||
|---|---|
|
||||
| The transform is a standalone IR rewriter, not a pass | `tools/tms-bitaddr/bitscale.cpp` parses IR, mutates it, writes it; modes `--bitptr --scale --normalize --lower-bitptr` |
|
||||
| `clang -O2` fails on ordinary loops | `IndVarSimplify` exit-value rewrite → i33 multiply → `TMS34010RejectUnsupportedIR` fatal |
|
||||
| M9 avoids it with a pass option | `scripts/tms-clang`: `opt -passes='default<O2>' -replexitval=never` |
|
||||
| The wrapper carries freestanding defaults | `clang --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone -ffreestanding -fno-builtin -nostdinc` (always `-O0` IRGen) |
|
||||
| A pre-optimizer guard lives in the wrapper | awk scan rejecting `internal` variadic definitions with no `llvm.va_start` (DAE would drop `...`) |
|
||||
| A final InstCombine needs an option | `instcombine<no-verify-fixpoint>` for the shim's `emit_uint64` `zext … nneg` fixpoint |
|
||||
| Gates observe the wrapper's internals | `m3/run.sh` and `m5/jr.sh` inject `opt` wrappers; `m5/policy.sh` traces `opt` arguments; `m4/mul.sh` greps `scripts/tms-clang` for the flag |
|
||||
| The target already assumes bit offsets in codegen | `TMS34010PassConfig::addIRPasses()` hosts `ScaleMemExpansionGEPs`, `ExpandAggMem`, `LowerI64`, `ExpandNarrowMem` |
|
||||
| clang builds a `PassBuilder` **with** the `TargetMachine` | `clang/lib/CodeGen/BackendUtil.cpp:937` |
|
||||
| so target pass callbacks are reachable from clang | `PassBuilder::PassBuilder` calls `TM->registerPassBuilderCallbacks(*this)` (`llvm/lib/Passes/PassBuilder.cpp:581`) |
|
||||
| Pipeline-start callbacks run at `-O0` | `PassBuilderPipelines.cpp:2438`, inside `buildO0DefaultPipeline` |
|
||||
| Optimizer-last callbacks do **not** run at `-O0` | `invokeOptimizerLastEPCallbacks` only at `:1692`, `:1933`, `:2524` |
|
||||
| `llc` runs no new-PM pipeline | `llc.cpp:839` only calls `Target->addPassesToEmitFile` |
|
||||
| `opt` builds no `TargetMachine` | `tools/opt/NewPMDriver.cpp` registers plugin callbacks only |
|
||||
| The driver has no TMS34010 `ToolChain` | no `tms34010` under `clang/lib/Driver/` |
|
||||
| The native link needs a repair step today | `scripts/m4/run.sh` runs `coff-check.py --repair --entry 018A0000` on every linked image |
|
||||
| SDK `flib`/`rts` are generated, not committed | `build/m6-sdk/{flib,rts}.lib`, extracted from the 1987 vendor image |
|
||||
| A TMS34010 MC assembler exists | `llvm/test/MC/TMS34010` (4 tests) — usable for a committed CRT |
|
||||
| `tms-link` reads System V `ar` archives | M8.1 (`scripts/tests/m8/native-lib.sh`) |
|
||||
|
||||
## 6. Approaches considered
|
||||
|
||||
### Phase 2
|
||||
|
||||
**A. Target-level pass hooks (chosen).** Barrier on the pipeline-start extension
|
||||
point; scale/lower/final-InstCombine on optimizer-last (`-O0` handles both in
|
||||
the start callback, §7.3); registered from
|
||||
`TMS34010TargetMachine::registerPassBuilderCallbacks`. No user flag, and the
|
||||
transform stays inside the target directory.
|
||||
|
||||
**B. In-tree clang frontend patch.** Insert the passes in
|
||||
`clang/lib/CodeGen/BackendUtil.cpp`. Explicit ordering, but the fork's first
|
||||
divergence in generic clang code, re-carried on every LLVM bump. Rejected: A
|
||||
covers every clang path because clang passes its `TargetMachine` to the
|
||||
`PassBuilder`.
|
||||
|
||||
**C. Out-of-tree pass plugin plus an opt-in flag.** Smallest divergence, but
|
||||
correctness becomes flag-dependent and forgettable. Rejected: it does not
|
||||
satisfy "plain clang is correct".
|
||||
|
||||
**Rejected outright: bit units in `DataLayout`.** LLVM's addressing unit is the
|
||||
byte and `getTypeAllocSize` is byte-quantised; a bit-unit GEP cannot be
|
||||
expressed. That is why the barrier exists.
|
||||
|
||||
**Amendment after the builder check.** A alone is not sufficient: the
|
||||
`-replexitval`, freestanding and include defaults cannot come from a
|
||||
`TargetMachine`. They come from a minimal `ToolChain`, which is also the natural
|
||||
home for Phase 3's sysroot and link job. This keeps one driver file rather than
|
||||
two phases of driver surgery, and it means Phase 3 extends a file instead of
|
||||
introducing one.
|
||||
|
||||
### Phase 3
|
||||
|
||||
**A. Dedicated `ToolChain` + sysroot + CRT + `libtms.a` (chosen).** Follows how
|
||||
freestanding clang targets work, gives conventional `-I`/`-l`/`-L`/`-nostdlib`
|
||||
behaviour, and keeps `tms-link` behind a normal link job.
|
||||
|
||||
**B. Keep `tms-cc` and only rename it.** Cheapest, but it keeps a project script
|
||||
as the interface and cannot satisfy `clang hello.c -o hello`.
|
||||
|
||||
**C. Target the vendor 2ine/VT1200 OS environment.** Real OS applications, but a
|
||||
different runtime contract and acceptance path. Rejected: the chosen scope is
|
||||
freestanding with conventional UX.
|
||||
|
||||
## 7. Phase 2 (M10) design
|
||||
|
||||
### 7.1 Pass inventory
|
||||
|
||||
Port `tools/tms-bitaddr/bitscale.cpp` into new-PM passes under
|
||||
`llvm/lib/Target/TMS34010/`:
|
||||
|
||||
| New pass | Source mode | Responsibility |
|
||||
|---|---|---|
|
||||
| `TMS34010BitPtrPass` | `--bitptr` | Replace every GEP (and `inttoptr` of a bit addend over `ptrtoint`) with `@__tms_bitptr(i32 bitoff, ptr base)`; rewrite constant-expression GEPs as `inttoptr(add(ptrtoint, 8*off))`; copy `!dbg`; run the static-variadic guard (§7.6) |
|
||||
| `TMS34010ScaleGEPPass` | `--scale` | Multiply optimizer-created byte-GEP indices by 8; keep the `switch.table.*` special case |
|
||||
| `TMS34010LowerBitPtrPass` | `--lower-bitptr` | Replace each call with `inttoptr(add(ptrtoint base, bitoff))`, then drop the declaration |
|
||||
|
||||
`--normalize` is not ported: nothing in the shipped pipeline calls it, and its
|
||||
input contract is what `llc` does natively. The tool keeps the mode for its own
|
||||
tests and stays the equivalence oracle.
|
||||
|
||||
The port is a rewrite into `PassInfoMixin` form, not a move: the current code is
|
||||
a `main()`-driven module mutator.
|
||||
|
||||
### 7.2 Pipeline registration
|
||||
|
||||
`TMS34010TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB)`:
|
||||
|
||||
```
|
||||
PB.registerPipelineStartEPCallback(<level L: append barrier; if L == O0 also
|
||||
append lower>);
|
||||
PB.registerOptimizerLastEPCallback(<append scale → lower → instcombine>);
|
||||
```
|
||||
|
||||
At `-O0` no optimizer runs, so there are no optimizer-created GEPs to scale and
|
||||
no InstCombine is needed; adding one would move `-O0` output away from the M9
|
||||
path. `-O0` therefore runs barrier + lower only, which is what makes the
|
||||
byte-identity check possible.
|
||||
|
||||
`TMS34010PassConfig::addISelPrepare()` prepends `<lower → instcombine>` for IR
|
||||
that reaches codegen still holding barrier calls (hand-written or intermediate
|
||||
IR). It is placed before `TargetPassConfig::addISelPrepare()` so it runs before
|
||||
`PreISelIntrinsicLowering`/`CodeGenPrepare`, matching M9's "lower before the
|
||||
backend sees it". `TMS34010PassConfig::addIRPasses()` is unchanged.
|
||||
|
||||
The final InstCombine is constructed with
|
||||
`InstCombineOptions().setVerifyFixpoint(false)` — the in-tree equivalent of the
|
||||
wrapper's `instcombine<no-verify-fixpoint>`.
|
||||
|
||||
Consequences that make this safe:
|
||||
|
||||
- `clang` reaches the hooks because it builds `PassBuilder PB(TM.get(), …)`.
|
||||
- `llc` never builds a new-PM pipeline, so **direct `llc` on IR keeps the M9
|
||||
contract** and the 129 lit tests are unaffected.
|
||||
- `opt` builds no `TargetMachine`, so `opt` never fires the hooks.
|
||||
|
||||
### 7.3 State machine (idempotency)
|
||||
|
||||
A module flag carries the state so the barrier cannot run twice:
|
||||
|
||||
| Flag `"tms.bitaddr"` | Meaning | Pipeline start | Optimizer last | Codegen (`addISelPrepare`) |
|
||||
|---|---|---|---|---|
|
||||
| absent | not ours / hand-written IR | apply barrier → `1`; at `-O0` immediately lower → `2` | skip | skip |
|
||||
| `1` | barriered, not lowered | skip | scale, lower, instcombine → `2` | lower, instcombine → `2` |
|
||||
| `2` | lowered / final | skip | skip | skip |
|
||||
|
||||
Flag: `Module::addModuleFlag(ModFlagBehavior::Override, "tms.bitaddr", i32)`, set
|
||||
only by the pass performing the transition.
|
||||
|
||||
Because `-O0` lowers inside the start callback, **clang never emits state-1
|
||||
IR**, which closes the previous hole where `clang -O0 -emit-llvm` → `opt -O2` →
|
||||
`llc` would have lowered unscaled optimizer GEPs.
|
||||
|
||||
Scenario check:
|
||||
|
||||
| Command | Result |
|
||||
|---|---|
|
||||
| `clang -O2 -c` | barrier → optimize → scale/lower/instcombine → codegen skips |
|
||||
| `clang -O0 -c` | barrier + lower + instcombine in the start callback |
|
||||
| `clang -O0 -S -emit-llvm` then `llc` | state 2; `llc` skips |
|
||||
| `clang -O2 -S -emit-llvm` then `llc` | state 2; `llc` skips |
|
||||
| `clang -O2` on state-1 IR | barrier skipped, optimization + lowering run once |
|
||||
| `llc` on hand-written IR | no flag → untouched (M9 meaning) |
|
||||
| `opt` on state-2 IR | hooks never fire; optimizing final IR is unsupported (§7.5) |
|
||||
|
||||
### 7.4 Why `llc`'s contract must not change
|
||||
|
||||
`m2-late-gep.ll` pins `getelementptr i8, ptr %p, i32 24` → `ADDI 24`: for `i8`
|
||||
GEPs the byte offset *is* the bit offset. A barrier inside `llc` would turn every
|
||||
such test into `ADDI 192` and redefine the IR contract the gate suite is built
|
||||
on. The hooks therefore live only in the new-PM pipeline, which `llc` does not
|
||||
build. This is a design invariant.
|
||||
|
||||
### 7.5 Limitations to document
|
||||
|
||||
- IR emitted by a completed `clang` pipeline (`-emit-llvm`) is **final**;
|
||||
re-optimizing it with `clang`/`opt -O2` is unsupported.
|
||||
- LTO is unsupported for this target (bitcode is already lowered).
|
||||
- The barrier must preserve `!dbg`; this keeps `-g -c` DWARF correct (M9.2
|
||||
depends on it).
|
||||
|
||||
### 7.6 Minimal `ToolChain` (new in M10)
|
||||
|
||||
`clang/lib/Driver/ToolChains/TMS34010.{h,cpp}`, registered in
|
||||
`clang/lib/Driver/ToolChains/CMakeLists.txt` and the driver's target selection so
|
||||
`tms34010-unknown-none` (and plain `--target=tms34010`) resolve to it.
|
||||
|
||||
M10 responsibilities (the whole file is ~150 lines):
|
||||
|
||||
- `addClangTargetOptions`: append `-ffreestanding`, `-fno-builtin`,
|
||||
`-mllvm -replexitval=never`, and `-disable-O0-optnone` (the last because the
|
||||
legacy M9 path ran `-O0` without the `optnone` attribute, so the flag keeps
|
||||
native `-O0 -c` objects byte-identical to the M9 path).
|
||||
- Include behaviour: no system include directories (`-nostdinc` semantics
|
||||
without the flag); `-I` still works.
|
||||
- Keep object emission as today (integrated TI-COFF writer, no external
|
||||
assembler).
|
||||
- No link job yet: `-c`/`-S` are the M10 surface; linking stays with `tms-cc`
|
||||
until M11.
|
||||
|
||||
The static-variadic guard moves into `TMS34010BitPtrPass` as a pre-optimizer
|
||||
rejection: an `internal`/`private` variadic definition with no
|
||||
`llvm.va_start`/`va_arg` in the body is diagnosed with the same message the
|
||||
wrapper prints today.
|
||||
|
||||
### 7.7 What `tms-clang` becomes, and the gates that must change
|
||||
|
||||
`scripts/tms-clang` becomes a flag mapper:
|
||||
|
||||
| `tms-clang` flag | becomes |
|
||||
|---|---|
|
||||
| `-O0` / `-O2` | `clang --target=tms34010 -O0` / `-O2` |
|
||||
| `-g` | `-g` |
|
||||
| `-I dir` | `-I dir` |
|
||||
| `-o OUT.ll` | `-S -emit-llvm -o OUT.ll` |
|
||||
| `$TMS_CLANG_EXTRA_FLAGS` | passed through unchanged |
|
||||
| `$TMS_OPT` / `$TMS_BITADDR` | no longer used |
|
||||
|
||||
Gate edits required (same invariant, new seam):
|
||||
|
||||
| Gate | Today | M10 |
|
||||
|---|---|---|
|
||||
| `scripts/tests/m3/run.sh`, `scripts/tests/m5/jr.sh` | inject an `opt` wrapper to add `-replexitval=never` | pass nothing; assert the compile succeeds and the loop shape survives in the emitted IR |
|
||||
| `scripts/tests/m5/policy.sh` | traces `opt` arguments, asserts the flag and no `-switch-to-lookup` | asserts `-replexitval=never` appears in `clang -###` output (the ToolChain seam) and inspects the final IR/asm for the same shapes |
|
||||
| `scripts/tests/m4/mul.sh` | greps `scripts/tms-clang` for the flag | greps the ToolChain source/defaults, or asserts via `clang -###` |
|
||||
|
||||
### 7.8 Acceptance (M10)
|
||||
|
||||
1. **Native correctness:** `clang/test/CodeGen/TMS34010/` tests for `p[1]`
|
||||
(i32 → `ADDI 32`), byte/struct pointers, array indexing and pointer
|
||||
difference at `-O0` and `-O2`; an ordinary `for` loop compiles at `-O2`
|
||||
without extra flags.
|
||||
2. **Native end-to-end:** the pointer programs run correctly end to end
|
||||
(compile with native clang, link with the existing `tms-cc`/`tms-link` path,
|
||||
run under MAME) at `-O0` and `-O2`.
|
||||
3. **Equivalence (chosen criterion):** the full suite stays **1,618 pass / 294
|
||||
skip / 0 fail / 0 crash**; suite markers and checksums are unchanged; i64div
|
||||
stays 88/3302/221/120 with the same four checksums; a curated asm-shape set
|
||||
(pointer arithmetic, struct offsets, switch tables, aggregate returns)
|
||||
matches M9's shapes.
|
||||
4. **Pass equivalence:** proven end-to-end, because individual new-PM passes are
|
||||
not addressable from `opt` (it builds no `TargetMachine`): `clang -O0 -c`
|
||||
objects must be byte-identical to the M9 path, which exercises the barrier
|
||||
and lowering port directly, while the scaling pass is pinned by the M5 policy
|
||||
gate (switch table) and an `-O2` asm-shape set.
|
||||
5. **Unchanged gates:** lit 129/129 plus the new tests, clang 5/5 plus driver
|
||||
tests, every M2–M9 gate green after the §7.7 edits, which are reviewed as
|
||||
part of the milestone.
|
||||
6. **No user flags:** `clang --target=tms34010 -O2 -c` with nothing else.
|
||||
|
||||
## 8. Phase 3 (M11) design
|
||||
|
||||
### 8.1 Driver link job
|
||||
|
||||
Extend the M10 `ToolChain` with a link job invoking `tms-link`: `-o`,
|
||||
`--entry _start`, `--text`, `--bss`, `--prog-len`, `--ram-len`, libraries,
|
||||
optional `--map`. `-Wl,…` passes through; `-nostdlib` removes CRT and default
|
||||
libraries; `-g` maps to `--keep-debug` (and the default stays stripped).
|
||||
|
||||
**Linker prerequisite:** the production path must not depend on
|
||||
`coff-check.py --repair`. `tms-link` must emit a loader-valid image unaided
|
||||
(valid file/optional header, even `.bss`), and `coff-check.py` stays a *checker*
|
||||
in the gates. This is small linker work added to M11.1.
|
||||
|
||||
### 8.2 CRT, headers, library, sysroot
|
||||
|
||||
| Artifact | Source | Build |
|
||||
|---|---|---|
|
||||
| `crt0.o` | `sdk/crt0.asm`, generalised from `conformance/entry.asm`: `setf`, stack setup, call `main`, write status/magic | `llvm-mc -triple=tms34010 -filetype=obj`, reproducible |
|
||||
| headers | `sdk/include/` (moved from `scripts/tests/m5/conformance/include`) | installed into the sysroot |
|
||||
| `libtms.a` | `sdk/shim.c`, `sdk/heap.c` (printf family, `malloc`/`free`, `mem*`/`str*`) | System V `ar`, which `tms-link` reads |
|
||||
| `flib.lib`, `rts.lib` | committed copies of the extracted 1987 vendor archives | linked by default for the shim's `%f` path |
|
||||
|
||||
The sysroot layout is `lib/clang/<ver>/tms34010-unknown-none/{include,lib}` plus
|
||||
a `--tms-sysroot=` override. Because the vendor archives are committed and the
|
||||
CRT is reproducible, `clang --target=tms34010 hello.c -o hello` needs no
|
||||
project variables and no SDK extraction step.
|
||||
|
||||
The conformance harness and `tms-cc` point at the relocated headers rather than
|
||||
keeping a second copy.
|
||||
|
||||
### 8.3 Command surface after Phase 3
|
||||
|
||||
```
|
||||
clang --target=tms34010 hello.c -o hello # CRT + libtms + flib/rts + tms-link
|
||||
clang --target=tms34010 -c hello.c -o hello.o # TI-COFF object
|
||||
clang --target=tms34010 -S hello.c -o hello.s # GSPA assembly
|
||||
clang --target=tms34010 -O2 -g a.c b.c -o app # multi-TU, debug kept
|
||||
clang --target=tms34010 -nostdlib -Wl,--entry=_start ...
|
||||
tms-run hello # unchanged
|
||||
```
|
||||
|
||||
`scripts/tms-cc` stays as a compatibility alias adding `--run` and the project's
|
||||
default layout; it is no longer the recommended interface.
|
||||
|
||||
### 8.4 Acceptance (M11)
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` then `tms-run hello` prints
|
||||
`hello` with status 0, from a shell with no project variables set.
|
||||
2. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multi-TU and `-nostdlib` behave
|
||||
conventionally; `clang/test/Driver/TMS34010*.c` pins the link and include
|
||||
command lines.
|
||||
3. The CRT rebuilds byte-identically from source with no DOSBox/2ine dependency,
|
||||
and the committed vendor archives match the extracted originals.
|
||||
4. The single-command flow builds one M4/M5/M6 harness program unchanged.
|
||||
5. M2–M10 gates, lit, the conformance full suite and the i64div numbers are
|
||||
unchanged.
|
||||
|
||||
## 9. Constraints
|
||||
|
||||
- Branch `m10` from `m9`; `m11` from `m10` after Phase 2 is promoted. Default
|
||||
promotion only after a clean whole-branch review, per standing policy.
|
||||
- LLVM/Clang stay pinned at 23.1.5. `patches/llvm/0001..0004` stay as they are;
|
||||
Phase 2 adds `0005` (the `ToolChain` and its registration), extended in
|
||||
Phase 3.
|
||||
- Every existing gate, the TI ABI, the all-stack convention, GSPLNK as the
|
||||
byte/symbol oracle and the two-tier conformance harness stay intact.
|
||||
- No force-push, no default-branch change, no history rewrite.
|
||||
- `-O0` and `-O2` are both first-class.
|
||||
|
||||
## 10. Risks and mitigations
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Barrier applied twice | Module-flag state machine (§7.3) with the scenario table as tests |
|
||||
| `llc`'s IR contract silently changes | Hooks only in the new-PM pipeline; `m2-late-gep.ll` and the 129 lit tests guard it |
|
||||
| Codegen-created late GEPs after lowering | Lowering in `addISelPrepare` before `CodeGenPrepare`, matching M9 order; `addrSinkUsingGEPs` stays disabled |
|
||||
| Debug info lost in the port | Barrier copies `!dbg`; M9.2 gates (`m9/dwarf-ranges.sh`, `m8/dwarf-multi.sh`, `m7/debug.sh`) must pass unchanged |
|
||||
| Pass port drifts from the oracle | `tools/tms-bitaddr` retained as the oracle (§7.8.4) |
|
||||
| Gate edits weaken coverage | Each §7.7 edit must assert the same invariant at the new seam and be reviewed |
|
||||
| `-replexitval` regresses on other loop shapes | Full suite plus the M3/M5 loop gates; the flag is a compile-time policy, not codegen |
|
||||
| Native `-O2` differs from M9 in size | Accepted by decision; behaviour gates (§7.8.3) replace byte identity |
|
||||
| Driver file grows into two phases of surgery | One file from M10, extended rather than rewritten in M11 |
|
||||
| `coff-check --repair` hides a tms-link defect | M11.1 fixes `tms-link`; the checker stays in the gate with `--repair` removed from production |
|
||||
| Committed vendor archives drift | Gate compares the committed copies against freshly extracted ones |
|
||||
| Two copies of headers/CRT | Phase 3 relocates the single source and regenerates harness paths |
|
||||
|
||||
## 11. Sequencing and what is left to the builder
|
||||
|
||||
**M10.0** minimal `ToolChain` (defaults + include behaviour) → **M10.1** pass
|
||||
port + oracle equivalence → **M10.2** pipeline hooks + state machine →
|
||||
**M10.3** `tms-clang` rewrite, gate edits, equivalence sweep → **M10.4**
|
||||
docs/gates/promote.
|
||||
|
||||
**M11.1** link job + `tms-link` header fix → **M11.2** `crt0` via `llvm-mc` →
|
||||
**M11.3** headers, `libtms.a`, committed vendor archives, sysroot → **M11.4**
|
||||
single-command end-to-end, docs, gates, promote.
|
||||
|
||||
Left to the builder (verify during implementation, do not re-litigate):
|
||||
|
||||
1. Exact pass signatures; whether InstCombine is added via
|
||||
`createInstructionCombiningPass`/`InstCombinePass(InstCombineOptions...)`.
|
||||
2. Whether `addISelPrepare` prepending is sufficient or `addIRPasses` also needs
|
||||
the safety-net lowering (measure both `-O0` outputs).
|
||||
3. Module-flag name/behaviour enum (`"tms.bitaddr"` / `Override` proposed).
|
||||
4. Whether the static-variadic guard belongs in the barrier pass or a separate
|
||||
pre-opt pass in the same callback.
|
||||
5. Sysroot resolution order (`-resource-dir` relative versus `--tms-sysroot`).
|
||||
6. Whether `libtms.a` is always linked or gated on `-l tms`, and how `flib`/`rts`
|
||||
are selected (`%f` needs them; `-nostdlib` must not).
|
||||
7. Whether `tms-cc`'s `--run` stays in the script.
|
||||
|
||||
## 12. Decisions log
|
||||
|
||||
| Decision | Choice | By |
|
||||
|---|---|---|
|
||||
| Phase 2 mechanism | Target-level pass hooks (Approach A) | user |
|
||||
| clang-level defaults (`replexitval`, freestanding, includes) | Minimal `ToolChain` in Phase 2, extended in Phase 3 | user |
|
||||
| M10 success criterion | Runtime + suite equivalence | user |
|
||||
| Vendor `flib`/`rts` | Committed to the repo | user |
|
||||
| Phase 3 library scope | Freestanding, conventional UX (no hosted libc/file I/O/libm) | user |
|
||||
| Milestone mapping | Phase 2 = M10, Phase 3 = M11 | this doc |
|
||||
| `-O0` pipeline | Barrier + lower in the start callback; no state-1 IR from clang | this doc |
|
||||
| `tms-bitaddr` fate | Test oracle, not a production path | this doc |
|
||||
| `llc` IR contract | Unchanged (bit offsets by definition) | this doc |
|
||||
| `-g` at link | Maps to `--keep-debug`; default stays stripped | this doc |
|
||||
| `coff-check.py --repair` | Leaves the production path; `tms-link` emits valid images | this doc |
|
||||
| Gate edits for the new seam | Required and reviewed (§7.7) | this doc |
|
||||
@@ -0,0 +1,306 @@
|
||||
# TMS34010 M11 (Phase 3) — Conventional Toolchain Design
|
||||
|
||||
Status: proposed. M10 is complete and `m10` is the default on both repositories
|
||||
(project `4809185`, compiler `7fc2ac37b5ad`). This document also carries the
|
||||
short roadmap for M12 and later.
|
||||
|
||||
Decision already taken by the human partner: M11 is Phase 3 of
|
||||
`docs/superpowers/specs/2026-11-17-tms34010-phase-2-3-design.md` §8 — a
|
||||
freestanding toolchain with conventional UX — and its artifacts are discovered
|
||||
through a resource-directory sysroot built and installed by a script
|
||||
(approach A below).
|
||||
|
||||
## 1. Intent and why
|
||||
|
||||
M10 made `clang --target=tms34010 -c` correct. M11 closes the remaining gap
|
||||
between "a compiler that emits objects" and "a toolchain you can use": a
|
||||
single command that produces a runnable image.
|
||||
|
||||
Today the pieces exist but only the project knows how to wire them:
|
||||
|
||||
- `scripts/tms-cc` compiles each TU through `scripts/tms-clang` and `llc`, then
|
||||
drives `scripts/m4/run.sh` with `M4_*` environment variables, which assembles
|
||||
`entry.asm` with the 1987 tools and links with `tools/tms-link`.
|
||||
- Headers live in `scripts/tests/m5/conformance/include`; the runtime is
|
||||
`shim.c` + `heap.c` compiled on every invocation; the SDK archives come from
|
||||
`build/m6-sdk`.
|
||||
- Nothing tells `clang` where a CRT, headers or a library are.
|
||||
|
||||
The goal is that a user with a built compiler and one setup command can run:
|
||||
|
||||
```sh
|
||||
clang --target=tms34010 hello.c -o hello
|
||||
tms-run hello
|
||||
```
|
||||
|
||||
and see `hello`, with no project variables, no wrapper script, and no DOSBox.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
1. `clang --target=tms34010 hello.c -o hello` links to a loader-valid TI-COFF
|
||||
image through `tms-link`, with a CRT, headers and a C library found through
|
||||
a sysroot.
|
||||
2. The sysroot is produced from in-repo sources by one documented command and
|
||||
installed at a relocatable, conventional location.
|
||||
3. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, multiple TUs, `-I`, `-L`, `-l` and
|
||||
`-nostdlib` behave the way they do for any freestanding clang target, and
|
||||
`-###` shows the real compile and link jobs.
|
||||
4. The CRT is reproducible from source with `llc` — no DOSBox, no 2ine, no
|
||||
vendor assembler. (`llvm-mc` cannot be used: it emits ELF for this triple, and
|
||||
the generic COFF path refuses a non-Windows triple. The target's TI-COFF
|
||||
writer is reachable only through CodeGen, so the CRT is an IR file whose
|
||||
`_start` is `naked` with inline assembly.)
|
||||
5. `libtms.a` is built from `shim.c` + `heap.c` with `llvm-ar`; the committed
|
||||
vendor `flib.lib`/`rts.lib` supply the `%f` formatting path.
|
||||
6. `tms-link` emits a loader-valid image on its own, so the production path no
|
||||
longer needs `coff-check.py --repair`.
|
||||
7. Every M0–M10 gate, the lit suites and the 1,912-row conformance suite stay
|
||||
unchanged.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- **Hosted C library.** No file I/O, no console driver, no `libm`, no locale.
|
||||
`printf` keeps writing the conformance result block that `tms-run` reads.
|
||||
- **A new linker.** `tms-link` stays the linker; M11 only calls it correctly.
|
||||
- **lld.** TI-COFF is not an lld flavour.
|
||||
- **Changing the TI ABI, the all-stack convention, the pointer model, or the
|
||||
M10 pipeline.** M11 adds no codegen behaviour.
|
||||
- **Bare-metal debugger integration** beyond `-g` → `--keep-debug`.
|
||||
- **Removing `tms-cc`.** It stays as a compatibility alias.
|
||||
|
||||
## 4. Anti-goals
|
||||
|
||||
- A driver that shells out to project scripts or bakes a checkout path into
|
||||
`clang`. Both break the "conventional toolchain" property.
|
||||
- Committing built `crt0.o`/`libtms.a`. Sources are the truth; a drift gate is
|
||||
still cheaper than a checked-in binary.
|
||||
- Growing the driver patch into generic clang code. The fork's driver change
|
||||
stays inside `clang/lib/Driver/ToolChains/TMS34010.*` plus its two
|
||||
registration lines, exported as an extension of patch `0005`.
|
||||
- Making the conformance harness depend on the installed sysroot in a way that
|
||||
breaks its hermetic MAME runs.
|
||||
|
||||
## 5. Constraints
|
||||
|
||||
- LLVM/Clang stay pinned at 23.1.5; the fork's exported patches remain
|
||||
`patches/llvm/0001..0005`.
|
||||
- Branch `m11` from `m10`; promote only after a clean whole-branch review, per
|
||||
standing repository policy.
|
||||
- Every existing gate and the two-tier harness stay green; `HARDWARE` stays
|
||||
`DEFERRED` until a unit exists.
|
||||
- No force-push, no history rewrite.
|
||||
- `clang --target=tms34010 -c` (M10's contract) must not regress, including
|
||||
`-O0` byte identity with the M9 path.
|
||||
|
||||
## 6. Current state (verified on `m10`)
|
||||
|
||||
| Fact | Evidence |
|
||||
|---|---|
|
||||
| CodeGen emits TI-COFF; `llvm-mc` does not | `llc -march=tms34010 -filetype=obj` writes the target's COFF object; `llvm-mc -triple=tms34010 -filetype=obj` writes ELF (`7f 45 4c 46`), and `-triple=tms34010-unknown-none-coff` aborts with "cannot initialize MC for non-Windows COFF object files" |
|
||||
| A `naked` function keeps inline asm verbatim | `llc` on a `naked` `_start` with `setf`/`movi`/`move`/`rets` inline asm emits no prologue and no epilogue |
|
||||
| `tms-link` already has the driver's surface | `--entry --text --data --cinit --bss --prog-len --ram-len --map --keep-debug -L -l` |
|
||||
| A working `_start` exists | `scripts/tests/m5/conformance/entry.asm`: `setf` 16/32, 4 KiB `_cstack`, argv vector `{"conformance", NULL}`, result block at `01B00000`/`20`/`40`/`60`, output buffers `01B10000`/`01B30000`, `exit`/`abort` publish status themselves |
|
||||
| Headers exist but uninstalled | 10 headers in `scripts/tests/m5/conformance/include` (`assert, limits, math, stdarg, stdbool, stddef, stdint, stdio, stdlib, string`) |
|
||||
| Runtime sources exist | `scripts/tests/m5/conformance/{shim.c,heap.c}` |
|
||||
| SDK archives are extracted, not committed | `build/m6-sdk/{flib,rts}.lib`; the design commits them in M11 |
|
||||
| The link path needs a repair step today | `scripts/m4/run.sh` always runs `coff-check.py --repair --entry 018A0000` |
|
||||
| The driver file exists | `clang/lib/Driver/ToolChains/TMS34010.{h,cpp}` from M10, patched by `0005` |
|
||||
| No sysroot or link job exists | `clang -###` shows compile jobs only |
|
||||
|
||||
## 7. Approaches considered
|
||||
|
||||
**A. Resource-directory sysroot, built and installed by a script (chosen).**
|
||||
`sdk/` holds the sources; `scripts/tms-sdk` builds `crt0.o` and `libtms.a` and
|
||||
installs them, with the headers and the committed vendor archives, into
|
||||
`<resource-dir>/tms34010-unknown-none/{include,lib}`. The `ToolChain` searches
|
||||
there. Sources stay authoritative, the location is the conventional one for
|
||||
cross targets, and clang stays relocatable. Cost: one setup command after a
|
||||
compiler build.
|
||||
|
||||
**B. Repo-relative `sdk/` with committed prebuilt artifacts.** No setup step,
|
||||
but it bakes a checkout path into the driver, breaks when clang moves, and puts
|
||||
binaries in git that can drift. Rejected: it trades a real property
|
||||
(relocatable clang) for skipping one command.
|
||||
|
||||
**C. Explicit `--tms-sysroot` only.** Most predictable, worst UX, and it fails
|
||||
goal 1 (working from a shell with no flags). Rejected.
|
||||
|
||||
**Why A.** It is the only option that keeps both properties the milestone is
|
||||
for: a single conventional command, and a clang that can be moved or installed
|
||||
anywhere.
|
||||
|
||||
## 8. Design
|
||||
|
||||
### 8.1 Artifacts and layout
|
||||
|
||||
| Source | Built by | Installed to |
|
||||
|---|---|---|
|
||||
| `sdk/crt0.ll` (a `naked` `_start` with inline asm) | `llc -march=tms34010 -filetype=obj` | `<sysroot>/lib/crt0.o` |
|
||||
| `sdk/shim.c`, `sdk/heap.c` | `clang --target=tms34010 -c` + `llvm-ar` | `<sysroot>/lib/libtms.a` |
|
||||
| `sdk/include/*.h` (moved from the conformance harness) | — | `<sysroot>/include/` |
|
||||
| `sdk/lib/{flib,rts}.lib` (committed copies of the extracted 1987 archives) | — | `<sysroot>/lib/` |
|
||||
| `tools/tms-link/{tms-link,tmscoff.py}` | copied as a pair (the script imports its sibling) | `<sysroot>/bin/` |
|
||||
|
||||
The installed linker is a Python program: `python3` is a documented runtime
|
||||
dependency of the toolchain, and the driver reports its absence by name rather
|
||||
than as a bare link failure.
|
||||
|
||||
`<resource-dir>` is `clang -print-resource-dir` (for this fork,
|
||||
`build/llvm-clean-build/lib/clang/23`), so the sysroot defaults to
|
||||
`<resource-dir>/tms34010-unknown-none`.
|
||||
|
||||
`scripts/tms-sdk` performs all four steps, is idempotent, and accepts
|
||||
`--sysroot DIR` to install elsewhere (the driver then needs
|
||||
`--tms-sysroot=DIR`). The conformance harness points at `sdk/` for its headers
|
||||
so there is exactly one copy.
|
||||
|
||||
### 8.2 Driver discovery and the link job
|
||||
|
||||
`TMS34010ToolChain` gains:
|
||||
|
||||
- **Sysroot search order:** `--tms-sysroot=DIR`, then `--sysroot`/`-isysroot`,
|
||||
then `<resource-dir>/tms34010-unknown-none`. Headers come from
|
||||
`<sysroot>/include`; libraries from `<sysroot>/lib` plus `-L` paths.
|
||||
- **A link `Tool`** (`TMS34010Linker`) that invokes the installed
|
||||
`tms-link`. **Linker discovery:** `--tms-linker=PATH` first, otherwise
|
||||
`<sysroot>/bin/tms-link` — the same sysroot the headers and libraries come
|
||||
from, so one setup command covers everything and nothing is baked into the
|
||||
driver. A missing sysroot, a missing linker or a missing `python3` is a named
|
||||
diagnostic, never a bare link error; the first two point at `scripts/tms-sdk`
|
||||
and the `python3` one says to install `python3`.
|
||||
|
||||
Arguments: `-o <output>`, `--entry _start`, `--text 018A0000`,
|
||||
`--bss 01A00000`, `--prog-len 40000h`, `--ram-len 80000h`,
|
||||
`--map <output>.map` when `-Wl,-Map` is absent, the objects, then
|
||||
`libtms.a`, `flib.lib`, `rts.lib` (unless `-nostdlib`/`-nodefaultlibs`), then
|
||||
user `-L`/`-l`. `-Wl,` arguments pass through verbatim.
|
||||
- **`-g`** also passes `--keep-debug` to the link so the image keeps its DWARF;
|
||||
the default stays stripped.
|
||||
- **`-###`** shows both jobs, and `clang/test/Driver/TMS34010-link.c` pins the
|
||||
link command line and the include path.
|
||||
|
||||
Compile jobs are unchanged from M10.
|
||||
|
||||
### 8.3 CRT contract
|
||||
|
||||
`sdk/crt0.ll` expresses the CRT as LLVM IR: `_start` is a `naked` function whose
|
||||
body is a sequence of `call void asm sideeffect "…"` blocks (`setf`, `movi`,
|
||||
`move`, `calla _main`, the status/magic stores, `rets`), plus globals for
|
||||
`_conformance_name` (`"conformance\0"`), `_conformance_argv` and `_cstack`.
|
||||
`llc -filetype=obj` lowers it through CodeGen and the target's TI-COFF writer,
|
||||
which is the only path that emits this object format; `llvm-mc` is not usable
|
||||
(see the current-state table). `naked` is required so no prologue touches the
|
||||
stack before `_start` sets it.
|
||||
|
||||
What the rewrite must preserve is the **contract**, not the text:
|
||||
|
||||
- `setf 16,1,0` / `setf 32,0,1`, and a 4 KiB `_cstack` at 16-bit alignment;
|
||||
- the two-element argv vector `{"conformance", NULL}` so `main(int, char**)`
|
||||
keeps working (`main(void)` is unaffected);
|
||||
- the result block exactly as today: status at `01B00000`, magic at
|
||||
`01B00040` set after `main` returns, and `libtms`'s output/error buffers at
|
||||
`01B10000`/`01B30000` with their length cells;
|
||||
- the `_start` symbol that `--entry _start` names;
|
||||
- `exit`/`abort` in `libtms` still publish status and spin.
|
||||
|
||||
Those addresses and sizes are the interface `tms-run` and the conformance
|
||||
harness already rely on.
|
||||
|
||||
### 8.4 Library policy
|
||||
|
||||
`libtms.a` always links when the CRT does. `flib.lib`/`rts.lib` are needed by
|
||||
`libtms`'s `%f` path, so they link by default. The conventional knobs are
|
||||
independent: `-nostartfiles` drops `crt0.o` but keeps the libraries,
|
||||
`-nodefaultlibs` keeps `crt0.o` but drops `libtms`/`flib`/`rts`, and
|
||||
`-nostdlib` implies both. `-l tms` is accepted and is a no-op beyond ensuring
|
||||
the archive is present once. Order is fixed: CRT, user objects, `libtms`,
|
||||
`flib`, `rts`, user `-l` archives.
|
||||
|
||||
### 8.5 `tms-link` prerequisite
|
||||
|
||||
`coff-check.py --repair` leaves the production path. `tms-link` must emit a
|
||||
valid file header, optional header and section table, and round `.bss` to whole
|
||||
16-bit words itself; `coff-check.py` stays in the gates as a checker (`--repair`
|
||||
becomes test-only). This is small linker work and it is the reason the link job
|
||||
can stay clean.
|
||||
|
||||
### 8.6 `tms-cc`
|
||||
|
||||
Kept as a compatibility alias documented as such: it adds `--run` and the
|
||||
project's M4 defaults. New documentation points at `clang --target=tms34010`.
|
||||
It is not deleted in M11.
|
||||
|
||||
### 8.7 Acceptance
|
||||
|
||||
1. From a clean shell after `scripts/tms-sdk`:
|
||||
`clang --target=tms34010 hello.c -o hello` then `tms-run hello` prints
|
||||
`hello` with status 0. No `M4_*`, `TMS_*`, or include paths set.
|
||||
2. `-c`, `-S`, `-E`, `-O0`, `-O2`, `-g`, two-TU linking and `-nostdlib` all
|
||||
behave conventionally; `clang/test/Driver/TMS34010-link.c` pins the jobs.
|
||||
3. `crt0.o` and `libtms.a` rebuild byte-identically from `sdk/` (`llc`
|
||||
self-consistency, not parity with the 1987 assembler), and a gate compares
|
||||
the committed `flib.lib`/`rts.lib` against the extracted originals.
|
||||
4. One existing M4/M5/M6 harness program builds through the new path and still
|
||||
passes its MAME markers. (M11 adds no separate harness-program-through-driver
|
||||
case: `scripts/tests/m11/e2e.sh` plus the unchanged full suite cover that
|
||||
risk.)
|
||||
5. The conformance suite stays `1,912 = 1,618 / 294 / 0 / 0`; lit and every
|
||||
M0–M10 gate stay green; `HARDWARE: DEFERRED`.
|
||||
|
||||
## 9. What is left to the builder
|
||||
|
||||
1. Whether `scripts/tms-sdk` is a shell script, a CMake custom target, or both
|
||||
(a `make sdk` shim is likely enough).
|
||||
2. The exact `Tool` subclass shape (`GnuTool`-style vs plain `Tool`), and
|
||||
whether `-Wl,` parsing belongs in the Tool or the ToolChain.
|
||||
3. Whether `libtms` also carries `__tms_bitptr`-adjacent helpers or stays
|
||||
purely C.
|
||||
4. The precise `clang -###` line splits the driver test pins.
|
||||
5. Whether `-Map` defaults on or only on `-Wl,-Map` (leaning: default on, next
|
||||
to the output, because the map is the debugging surface this toolchain has).
|
||||
6. How the installed `tms-link` should signal a missing interpreter (shebang
|
||||
plus the driver's pre-flight check), and whether `tms-sdk` normalises the
|
||||
copied pair's permissions.
|
||||
|
||||
## 10. Risks and mitigations
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Sysroot drift from sources | `scripts/tms-sdk` is the only writer; a gate rebuilds and compares the CRT and library |
|
||||
| Committed vendor archives drift | A gate compares them against freshly extracted copies |
|
||||
| Installed linker drifts from `tools/tms-link` | `scripts/tms-sdk` copies it; a gate compares the installed pair against the sources |
|
||||
| `python3` missing at link time | The driver detects it and names `scripts/tms-sdk` and `python3` in the diagnostic |
|
||||
| The IR CRT shifts the runtime contract | The contract list in §8.3 is the test: `tms-run` output, argv, status and buffer addresses |
|
||||
| `naked` + inline asm is fragile across LLVM bumps | The CRT gate pins the emitted bytes and `llc`'s no-prologue output |
|
||||
| Driver bakes in a checkout path | Discovery is resource-dir relative; the driver test asserts it |
|
||||
| Link failures from an uninstalled sysroot | A missing sysroot is a named diagnostic telling the user to run `scripts/tms-sdk`, not a link error |
|
||||
| `tms-link` header defects surface late | M11.1 fixes the linker first and `coff-check` gates it |
|
||||
| Conformance harness forks its headers | Harness and sysroot share `sdk/include` |
|
||||
| `-g` silently stripped | Driver test pins `--keep-debug`; an M8-style dwarfdump check confirms the linked image |
|
||||
| Driver patch grows into generic clang | All new code stays in `ToolChains/TMS34010.*`; patch `0005` grows, nothing else |
|
||||
|
||||
## 11. Roadmap after M11
|
||||
|
||||
| Milestone | Scope | Why this order |
|
||||
|---|---|---|
|
||||
| **M12 — conformance classes** | inline-asm memory constraints (`m`/`o`/`V`), the `ST` clobber, `blockaddress`, nested functions, VLAs, sret/aggregate/variadic/float returns, runtime aborts, `pr63843` | Raises the suite's pass rate from 1,618 and removes the largest remaining silent-failure classes |
|
||||
| **M13 — performance and hardware** | attribute the slow-phase 2,440 → 3,302-frame delta; further divide/loop work; the real VT1200 run when a unit exists | Needs a stable correctness baseline (M10–M12) before measuring |
|
||||
| **M14 — hosted I/O (optional)** | real console/serial output, then file APIs; a terminal `printf` instead of the result block | Largest scope and the least certain requirement; deliberately last |
|
||||
|
||||
Each milestone gets its own design and plan; this table only fixes the order.
|
||||
|
||||
## 12. Decisions log
|
||||
|
||||
| Decision | Choice | By |
|
||||
|---|---|---|
|
||||
| M11 scope | Phase 3: freestanding toolchain with conventional UX | user (earlier) |
|
||||
| Artifact discovery | Resource-directory sysroot built and installed by `scripts/tms-sdk` (approach A) | user |
|
||||
| Linker discovery | `scripts/tms-sdk` installs `tms-link` + `tmscoff.py` into `<sysroot>/bin/`; the driver resolves it relative to the sysroot, `--tms-linker=` overrides | user |
|
||||
| CRT source/build | `sdk/crt0.ll` (naked `_start` + inline asm) built by `llc`; acceptance is `llc` self-consistency | this doc (corrected during M11 execution: `llvm-mc` emits ELF) |
|
||||
| Link-reduction knobs | `-nostartfiles`, `-nodefaultlibs`, `-nostdlib` all supported | this doc |
|
||||
| `libtms.a` fidelity | Rebuild-and-compare against `sdk/`, plus the suite | this doc |
|
||||
| Vendor archives | Committed to the repo, compared by a gate | user (earlier) |
|
||||
| Hosted libc | Out of scope | user (earlier) |
|
||||
| `tms-cc` | Kept as a compatibility alias | this doc |
|
||||
| `coff-check --repair` | Leaves the production path; `tms-link` emits valid images | this doc |
|
||||
| Milestone order | M11 → M12 (conformance) → M13 (performance/hardware) → M14 (hosted I/O, optional) | this doc |
|
||||
@@ -0,0 +1,274 @@
|
||||
# TMS34010 M12 — Tractable Conformance Gaps (Design)
|
||||
|
||||
Status: proposed. M11 is complete and `m11` is the default on both repositories
|
||||
(project `536c80a`, compiler `18b7fc9cd6df`).
|
||||
|
||||
The human partner chose this split: M12 takes the gaps that are backend or
|
||||
driver work with known mechanics, and **nested functions and VLA-in-struct are
|
||||
out of scope permanently** because both are frontend refusals, not gaps in our
|
||||
backend. The runtime-abort class is triaged here and fixed in M13.
|
||||
|
||||
## 1. Intent and why
|
||||
|
||||
The suite accounts for 1,912 files: 1,618 pass, 294 skip, none fail. The skips
|
||||
are curated, not random — each carries a reason. This milestone removes the
|
||||
ones that are genuinely ours and reachable, and turns the largest unknown
|
||||
bucket ("runtime aborts", 58 files) into a costed list.
|
||||
|
||||
Everything below was verified against the `m11` compiler, not inferred from the
|
||||
skip file.
|
||||
|
||||
| Class | Files | Verified failure | Verdict |
|
||||
|---|---|---|---|
|
||||
| inline-asm memory constraints | 11 | `LLVM ERROR: TMS34010: inline asm memory constraints ('m'/'o'/'V') are not supported; use a register or an immediate operand` — the target's own diagnostic, added deliberately in M9. All eleven use `m`/`g` with an empty template; **no corpus row uses `o`, `V`, or `~{st}`** | ours, bounded |
|
||||
| `ST` clobber | 0 (feature) | `ST` exists in `TMS34010RegisterInfo.td:46` but not in clang's GCC register list (`clang/lib/Basic/Targets/TMS34010.cpp:73`), so `~{st}` cannot be named | ours, small, no suite flip |
|
||||
| inline-asm, not memory-operand | 2 | `20030222-1`: i64 value tied to a 32-bit `r`; `990413-2`: an x86-only test (`=t`) that does not belong in this corpus | out of scope (separate gaps) |
|
||||
| `blockaddress` + computed goto | 2 | `llc`: `Cannot select: BlockAddress<@execute, %base>`; and `920501-3` needs an indirect branch the backend cannot select (the ISA has `jump Rd`, unimplemented) | ours, bounded |
|
||||
| return/frame address | 3 of 5 | `LLVM ERROR: TMS34010: unexpected custom lowering operation (return address)` / `(frame address)`. `20010122-1` checks level 1 and `20030323-1` walks to level 100; only `20030811-1`, `frame-address`, `pr17377` are level-0 | ours, bounded |
|
||||
| dynamic alloca scaling | 1 | `dynamic alloca size scaling assertion` (`c-torture/20070824-1`) | ours, bounded |
|
||||
| runtime aborts | 49–51 | compile and run, then abort with status `0x86` or a wrong result (i64, bitfield, varargs, vector, float, plain) | **triage only** |
|
||||
| nested functions | 30 | clang: `error: function definition is not allowed here` | out of scope |
|
||||
| VLA in struct | 9 | clang: `fields must have a constant size: 'variable length array in structure' extension will never be supported` | out of scope |
|
||||
| dialect strictness | 8 | `-Wint-conversion`, `-Wparen`, K&R-style errors under the pinned language mode | out of scope |
|
||||
| timeouts, region limits | 37 | loader budget or the 45 KiB/64 KiB image region | out of scope (environment) |
|
||||
|
||||
So M12 can flip **17 files** (11 + 2 + 3 + 1) plus at most three abort fixes, and
|
||||
must produce one new artefact: the abort triage report.
|
||||
|
||||
## 2. Goals
|
||||
|
||||
1. Inline-asm `m`/`o`/`V` memory operands work for the addressing modes this
|
||||
target can select, with unsupported shapes still loud and named.
|
||||
2. `~{st}` is a nameable clobber, and using `ST` as a value operand stays
|
||||
rejected.
|
||||
3. Computed `goto` works: `blockaddress` lowers to a section-relative bit
|
||||
address and jumps correctly.
|
||||
4. `llvm.returnaddress(0)` and `llvm.frameaddress(0)` lower on this ABI; levels
|
||||
above 0 stay a named error.
|
||||
5. Dynamic allocas (VLAs and `alloca`) scale sizes in bits correctly.
|
||||
6. **Abort triage:** the set is *discovered*, not asserted — every curated
|
||||
`runtime-abort*` and runtime-wrong-result row is re-run uncurated at `-O0`
|
||||
and `-O2`, its failure mode captured, and the results grouped into named
|
||||
causes with evidence and a proposed M13 cost. At most three single-cause cheap fixes may
|
||||
be taken inside M12; everything else is deferred with a recorded reason.
|
||||
7. Each fixed class flips its files in the full suite, and the accounting is
|
||||
re-recorded (pass count rises, skip count falls by the same amount).
|
||||
8. All M0–M11 gates, the M11 end-to-end build and the two-tier harness stay
|
||||
green.
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
- **Nested functions** and **VLA in struct**: frontend features clang refuses;
|
||||
implementing them means LLVM frontend work outside this milestone's charter.
|
||||
They stay curated with those reasons.
|
||||
- **ABI shapes** (sret, aggregate/variadic/float arguments and returns): M13,
|
||||
together with the aborts they probably overlap.
|
||||
- **Dialect strictness** (the 8 `compile:` rows): the corpus is compiled in a
|
||||
pinned language mode; relaxing it would change what the suite measures.
|
||||
- **Timeouts and region limits**: environment, not compiler defects.
|
||||
- **Performance work and the hardware run**: M14.
|
||||
- **Hosted I/O**: M15, optional.
|
||||
|
||||
## 4. Anti-goals
|
||||
|
||||
- Un-curating a test without fixing it. A class is flipped only when its
|
||||
reason is gone.
|
||||
- Supporting memory operands by falling back to a register copy behind the
|
||||
user's back. If a shape cannot be an address, it stays an error that names
|
||||
the constraint and the operand shape.
|
||||
- A blockaddress implementation that bakes in a load address or breaks the
|
||||
pic-free model.
|
||||
- Making `returnaddress`/`frameaddress` return plausible nonsense for levels
|
||||
the ABI cannot express.
|
||||
- A triage report that lists "aborts" as one bucket. Its whole value is named
|
||||
causes.
|
||||
|
||||
## 5. Constraints
|
||||
|
||||
- LLVM/Clang stay pinned at 23.1.5; branch `m12` from `m11`; promote only after
|
||||
a clean whole-branch review.
|
||||
- No TI ABI change: the all-stack convention, argument slots, and the bit
|
||||
pointer model stay as they are.
|
||||
- Every gate stays green; the suite stays `0 fail / 0 crash`; the abort triage
|
||||
may not turn a curated skip into a *failure* row.
|
||||
- No gate expectation, checksum or recorded count moves except the suite rows
|
||||
this milestone legitimately flips (and those are recorded individually).
|
||||
- Build with `-j4` on this host (unbounded builds have been OOM-killed).
|
||||
|
||||
## 6. Approaches considered
|
||||
|
||||
### 6.1 Inline-asm memory operands
|
||||
|
||||
**A. Full addressing-mode support (chosen).** Teach `SelectInlineAsmMemoryOperands`
|
||||
and `TMS34010DAGToDAGISel` to match the ISA's memory forms — `*An`,
|
||||
`*An(disp)`, `*An+`, `*-An`, `*An(disp),N` — and let LLVM pick one for an `m`
|
||||
operand. `o` (offsettable) and `V` (non-offsettable) map onto the same matcher
|
||||
with their respective restrictions. Unmatchable shapes stay loud.
|
||||
|
||||
**B. Minimal support.** Accept only a plain `*An` and keep everything else
|
||||
loud. Less work, but the 13 files use varied shapes and most would stay
|
||||
skipped.
|
||||
|
||||
**C. Keep it loud.** Costs nothing and flips nothing; rejected because these
|
||||
are ordinary C `asm` statements the corpus already contains.
|
||||
|
||||
**Why A.** The ISA has few, regular memory forms; the matcher is the natural
|
||||
home for them, and the loud fallback keeps the residual honest.
|
||||
|
||||
### 6.2 Abort triage
|
||||
|
||||
**A. Full uncurated re-run (chosen).** Re-run all 58 with the same driver, at
|
||||
both `-O0` and `-O2`, capture status and the first wrong marker or abort site,
|
||||
then group. Costs one MAME pass but produces evidence for every file.
|
||||
|
||||
**B. Sample.** Cheap, but a plan built on a sample repeats last milestone's
|
||||
guesswork; rejected.
|
||||
|
||||
**C. Fix-as-you-go.** Debug each abort inside M12. Rejected: unbounded, and the
|
||||
milestone's point is to make M13 plannable.
|
||||
|
||||
## 7. Design
|
||||
|
||||
### 7.1 Inline-asm memory constraints
|
||||
|
||||
- `TMS34010TargetLowering::getConstraintType` already distinguishes `m`; add
|
||||
`TMS34010TargetLowering::SelectInlineAsmMemoryOperand` (the hook M9 replaced
|
||||
with a fatal error) that produces a memory operand the DAG can select.
|
||||
- Add a `TMS34010DAGToDAGISel` matcher for the five memory forms, reusing the
|
||||
existing addressing-mode selection used by loads/stores.
|
||||
- `constraint 'o'` requires a non-post-increment, non-negative-displacement
|
||||
form. `'V'` stays loud: `InlineAsm::ConstraintCode` has no `V`, and
|
||||
`SelectionDAGBuilder` asserts on an unknown memory constraint before the
|
||||
target hook runs, so honouring its "non-offsettable" restriction would need
|
||||
a core LLVM enum change — outside this milestone's target-only charter.
|
||||
- Tests: one `.c` per form at `-O0` and `-O2`, plus a negative for an
|
||||
unmatchable operand, and a check that the emitted asm uses the expected
|
||||
addressing form rather than a register copy.
|
||||
|
||||
### 7.2 `ST` clobber
|
||||
|
||||
- Add `"st"` to `TMS34010TargetInfo::getGCCRegNames()`; `ST` already exists in
|
||||
the register info (`TMS34010RegisterInfo.td:46`).
|
||||
- Keep `ST` out of the allocatable set and out of the inline-asm *operand*
|
||||
classes; only the clobber path accepts it.
|
||||
- Tests: `~{st}` accepted, no save/restore emitted for it (it is a status
|
||||
register), and `asm("" : "=r"(x) : ...)` unchanged.
|
||||
|
||||
### 7.3 `blockaddress` and computed goto
|
||||
|
||||
- Lower `ISD::BlockAddress` in `TMS34010TargetLowering::LowerOperation` to the
|
||||
target's address node for a label: a section-relative bit address with the
|
||||
existing relocation machinery, no absolute load address.
|
||||
- Add the ISA's indirect jump `jump Rd` (opcode `0x0160`, documented in the
|
||||
vendor README) end to end: instruction definition, MC encoding, asm parser,
|
||||
printer and disassembler, and `ISD::BRIND` lowering to it. Without this,
|
||||
`goto *` cannot select even once the constant works.
|
||||
- Tests: computed `goto` in C at `-O0`/`-O2` for both corpus shapes; an `llc`
|
||||
lit test that the constant is a `.text`-relative bit address; MC tests for
|
||||
the encoding, parser and disassembler; and a negative that an out-of-range
|
||||
target stays loud.
|
||||
|
||||
### 7.4 Return and frame address
|
||||
|
||||
- The return address lives on the **system stack**, not at an `A13`-relative
|
||||
slot: after the callee's FP/callee-save `MMTM` the word is at
|
||||
`SP + NumSaved*32` (`NumSaved = 1 + callee-save-count`). The shipped
|
||||
lowering captures it once in the prologue; the two capture-scratch pushes
|
||||
put it at `SP + (NumSaved + 2)*32`, and the copy is stored in an `A13`
|
||||
slot. Level 0 reads that stable frame slot, not an `SP`-relative load at
|
||||
the use site (which can sink into the caller's saved-STK push window).
|
||||
- `llvm.frameaddress(0)` is the current frame pointer (`A13`).
|
||||
- Levels above 0: keep the loud error, but name the intrinsic and the level.
|
||||
`20010122-1` (level 1) and `20030323-1` (levels 1–100) stay curated with a
|
||||
precise "level > 0 unsupported" reason.
|
||||
- Tests: the three level-0 corpus files, plus lit covering level 0 and the
|
||||
loud non-zero case.
|
||||
|
||||
### 7.5 Dynamic alloca scaling
|
||||
|
||||
- Reproduce `c-torture/20070824-1`; the recorded failure is a size-scaling
|
||||
assertion. Fix the bit-vs-byte scaling in the dynamic-alloca path so the
|
||||
stack adjustment matches the pointer arithmetic (both are bit units).
|
||||
- Test: the corpus file plus a lit case pinning the stack-adjust arithmetic for
|
||||
a non-constant size.
|
||||
|
||||
### 7.6 Abort triage (deliverable, not a fix)
|
||||
|
||||
- A harness `scripts/tests/m12/abort-triage.sh` that re-runs each of the 58
|
||||
abort rows through the standard driver at `-O0` and `-O2`, capturing status,
|
||||
the completion magic, and the first differing marker/abort PC.
|
||||
- Output: `docs/superpowers/research/2026-11-19-tms34010-abort-triage.md`, one
|
||||
row per file with class → cause → evidence → estimated cost, plus a summary
|
||||
by cause.
|
||||
- Ruling: at most three fixes may be taken inside M12, each only if the triage
|
||||
shows a single shared cause with a one-line fix; all others defer to M13. Any
|
||||
taken fix is its own task with a recorded flip.
|
||||
|
||||
### 7.7 Suite accounting
|
||||
|
||||
Each class fix records the exact flipped rows in `full-suite.skip`'s removal
|
||||
commit and in the docs. The final numbers are expected to be
|
||||
**1,618 + N pass / 294 − N skip**, with N ≈ 20 (13 inline-asm + 2 blockaddress
|
||||
+ 4 return/frame address + 1 dynamic alloca), plus any abort fixes.
|
||||
|
||||
## 8. Acceptance
|
||||
|
||||
1. The 10 memory-constraint rows pass (`stkalign` is re-reasoned, not
|
||||
flipped); `~{st}` is accepted as a clobber;
|
||||
unmatchable shapes and `V` still fail with a named error.
|
||||
2. Both `blockaddress` rows pass with correct control flow at `-O0` and `-O2`,
|
||||
including the new `jump Rd` encoding, parser and disassembler tests.
|
||||
3. The three level-0 return/frame-address rows pass; levels above 0 stay a
|
||||
named error.
|
||||
4. The dynamic-alloca row passes.
|
||||
5. The abort triage report exists, covers the harness-discovered set, groups it
|
||||
by named cause, and proposes an M13 scope with costs.
|
||||
6. The full suite is re-recorded with `0 fail / 0 crash`, pass/skip consistent,
|
||||
and each flip individually justified.
|
||||
7. All M0–M11 gates green, M11's `clang hello.c -o hello` still works, i64div
|
||||
numbers unchanged, `HARDWARE: DEFERRED`.
|
||||
|
||||
## 9. Risks and mitigations
|
||||
|
||||
| Risk | Mitigation |
|
||||
|---|---|
|
||||
| Memory-operand matcher accepts a shape it selects wrongly | Each form has an asm-shape test; unmatchable shapes stay loud |
|
||||
| `ST` becomes allocatable by accident | Register class untouched; test asserts it never appears as an operand class |
|
||||
| Blockaddress bakes a load address | Lit test pins the section-relative form and a link-time check that `--text` relocation still works |
|
||||
| `returnaddress` picks the wrong slot | The four corpus files run in MAME; a wrong slot aborts loudly |
|
||||
| Abort triage turns a skip into a crash row | The triage re-runs out of tree and never edits the curated file unless a fix lands |
|
||||
| Suite accounting drifts | Flips recorded per row; the report shows the arithmetic |
|
||||
|
||||
## 10. What is left to the builder
|
||||
|
||||
1. Which of the five memory forms `o`/`V` should accept (the ISA table decides;
|
||||
document the mapping).
|
||||
2. Whether `returnaddress` can rely on a fixed A13 displacement or needs the
|
||||
frame-size recorded in the function.
|
||||
3. Whether the dynamic-alloca failure is one bug or two (size and alignment).
|
||||
4. The triage harness's exact failure-capture (marker diff vs abort PC).
|
||||
5. Which three abort fixes, if any, meet the one-line bar.
|
||||
|
||||
## 11. Roadmap (renumbered)
|
||||
|
||||
| Milestone | Scope |
|
||||
|---|---|
|
||||
| **M12 (this)** | inline-asm memory constraints + `ST` clobber, `blockaddress`, return/frame address, dynamic alloca, abort triage |
|
||||
| **M13** | ABI shapes (sret, aggregate/variadic/float args and returns) and the abort causes triaged here |
|
||||
| **M14** | performance and the real VT1200 run |
|
||||
| **M15** | hosted I/O (optional) |
|
||||
| out of scope for good | nested functions, VLA in struct (frontend refusals), dialect strictness, timeouts and region limits |
|
||||
|
||||
## 12. Decisions log
|
||||
|
||||
| Decision | Choice | By |
|
||||
|---|---|---|
|
||||
| Split the conformance work | Feature/gap classes in M12, ABI + aborts in M13 | user |
|
||||
| Nested functions | Permanently out of scope (clang frontend feature) | user |
|
||||
| Return/frame address | Level 0 only; levels above 0 stay a named error | user |
|
||||
| Computed goto | Add `jump Rd` + `BRIND` lowering so both rows flip | user |
|
||||
| `V` constraint | Kept loud (needs a core LLVM enum change) | this doc |
|
||||
| Inline-asm flips | 10 rows; `stkalign` is re-reasoned, and `ST` is a feature-only change | this doc |
|
||||
| VLA in struct | Out of scope (clang: "will never be supported") | this doc |
|
||||
| Memory operands | Full addressing-mode support with a loud fallback | this doc |
|
||||
| Abort handling in M12 | Triage only, at most three one-line fixes | this doc |
|
||||
@@ -0,0 +1,787 @@
|
||||
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
index ae3eecc60fc7..eef40fc1306d 100644
|
||||
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
|
||||
@@ -787,6 +787,14 @@ def warn_drv_darwin_sdk_invalid_settings : Warning<
|
||||
InGroup<DiagGroup<"darwin-sdk-settings">>;
|
||||
|
||||
def err_missing_sysroot : Error<"no such sysroot directory: '%0'">;
|
||||
+def err_drv_tms34010_missing_sysroot : Error<
|
||||
+ "TMS34010 sysroot not found: '%0'; run 'scripts/tms-sdk' to build and install it">;
|
||||
+def err_drv_tms34010_missing_linker : Error<
|
||||
+ "TMS34010 linker not found: '%0'; run 'scripts/tms-sdk' to install it">;
|
||||
+def err_drv_tms34010_missing_python3 : Error<
|
||||
+ "python3 not found on PATH; the TMS34010 linker requires it (install python3)">;
|
||||
+def err_drv_tms34010_missing_artifact : Error<
|
||||
+ "TMS34010 sysroot is incomplete: '%0' is missing; run 'scripts/tms-sdk' to install it">;
|
||||
def err_drv_darwin_sdk_missing_arclite : Error<
|
||||
"SDK does not contain 'libarclite' at the path '%0'; try increasing the minimum deployment target">;
|
||||
|
||||
diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td
|
||||
index f893d858d526..5ada0996811e 100644
|
||||
--- a/clang/include/clang/Options/Options.td
|
||||
+++ b/clang/include/clang/Options/Options.td
|
||||
@@ -6981,6 +6981,14 @@ def _help_hidden : Flag<["--"], "help-hidden">,
|
||||
HelpText<"Display help for hidden options">;
|
||||
def _sysroot_EQ : Joined<["--"], "sysroot=">, Visibility<[ClangOption, FlangOption]>;
|
||||
def _sysroot : Separate<["--"], "sysroot">, Alias<_sysroot_EQ>;
|
||||
+def tms_sysroot_EQ : Joined<["--"], "tms-sysroot=">,
|
||||
+ Visibility<[ClangOption, FlangOption]>,
|
||||
+ HelpText<"Use the given directory as the TMS34010 sysroot (default: "
|
||||
+ "<resource-dir>/tms34010-unknown-none)">;
|
||||
+def tms_linker_EQ : Joined<["--"], "tms-linker=">,
|
||||
+ Visibility<[ClangOption, FlangOption]>,
|
||||
+ HelpText<"Use the given executable as the TMS34010 linker (default: "
|
||||
+ "<sysroot>/bin/tms-link)">;
|
||||
def no_xcselect : Flag<["--"], "no-xcselect">,
|
||||
HelpText<"Disable xcselect SDK injection on macOS">;
|
||||
|
||||
diff --git a/clang/lib/Basic/Targets/TMS34010.cpp b/clang/lib/Basic/Targets/TMS34010.cpp
|
||||
index ad27642ae9aa..37cf9243e848 100644
|
||||
--- a/clang/lib/Basic/Targets/TMS34010.cpp
|
||||
+++ b/clang/lib/Basic/Targets/TMS34010.cpp
|
||||
@@ -76,6 +76,9 @@ ArrayRef<const char *> TMS34010TargetInfo::getGCCRegNames() const {
|
||||
"a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
|
||||
"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7",
|
||||
"b8", "b9", "b10", "b11", "b12", "b13", "b14", "b15",
|
||||
+ // The status register is nameable as a clobber only: ST is outside
|
||||
+ // every register class, so it can never be chosen as an operand.
|
||||
+ "st",
|
||||
};
|
||||
return Names;
|
||||
}
|
||||
diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt
|
||||
index 506536cdc04f..71ce08e3e5b6 100644
|
||||
--- a/clang/lib/Driver/CMakeLists.txt
|
||||
+++ b/clang/lib/Driver/CMakeLists.txt
|
||||
@@ -91,6 +91,7 @@ add_clang_library(clangDriver
|
||||
ToolChains/SPIRVOpenMP.cpp
|
||||
ToolChains/SYCL.cpp
|
||||
ToolChains/TCE.cpp
|
||||
+ ToolChains/TMS34010.cpp
|
||||
ToolChains/UEFI.cpp
|
||||
ToolChains/VEToolchain.cpp
|
||||
ToolChains/WebAssembly.cpp
|
||||
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
|
||||
index e606cdc4c1cf..8a36e6a29fae 100644
|
||||
--- a/clang/lib/Driver/Driver.cpp
|
||||
+++ b/clang/lib/Driver/Driver.cpp
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "ToolChains/Serenity.h"
|
||||
#include "ToolChains/Solaris.h"
|
||||
#include "ToolChains/TCE.h"
|
||||
+#include "ToolChains/TMS34010.h"
|
||||
#include "ToolChains/UEFI.h"
|
||||
#include "ToolChains/VEToolchain.h"
|
||||
#include "ToolChains/WebAssembly.h"
|
||||
@@ -7287,6 +7288,9 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
|
||||
case llvm::Triple::msp430:
|
||||
TC = std::make_unique<toolchains::MSP430ToolChain>(*this, Target, Args);
|
||||
break;
|
||||
+ case llvm::Triple::tms34010:
|
||||
+ TC = std::make_unique<toolchains::TMS34010ToolChain>(*this, Target, Args);
|
||||
+ break;
|
||||
case llvm::Triple::riscv32:
|
||||
case llvm::Triple::riscv64:
|
||||
case llvm::Triple::riscv32be:
|
||||
diff --git a/clang/lib/Driver/ToolChains/TMS34010.cpp b/clang/lib/Driver/ToolChains/TMS34010.cpp
|
||||
new file mode 100644
|
||||
index 000000000000..238913e830b0
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/TMS34010.cpp
|
||||
@@ -0,0 +1,264 @@
|
||||
+//===--- TMS34010.cpp - TMS34010 ToolChain ----------------------*- C++ -*-===//
|
||||
+//
|
||||
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
+// See https://llvm.org/LICENSE.txt for license information.
|
||||
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
+//
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+#include "TMS34010.h"
|
||||
+
|
||||
+#include "clang/Driver/Compilation.h"
|
||||
+#include "clang/Driver/Driver.h"
|
||||
+#include "clang/Driver/InputInfo.h"
|
||||
+#include "clang/Driver/Tool.h"
|
||||
+#include "clang/Options/Options.h"
|
||||
+#include "llvm/Option/ArgList.h"
|
||||
+#include "llvm/Support/FileSystem.h"
|
||||
+#include "llvm/Support/Path.h"
|
||||
+#include "llvm/Support/Program.h"
|
||||
+
|
||||
+using namespace clang;
|
||||
+using namespace clang::driver;
|
||||
+using namespace clang::driver::toolchains;
|
||||
+using namespace clang::driver::tools;
|
||||
+using namespace llvm::opt;
|
||||
+
|
||||
+TMS34010ToolChain::TMS34010ToolChain(const Driver &D, const llvm::Triple &Triple,
|
||||
+ const ArgList &Args)
|
||||
+ : BareMetal(D, Triple, Args) {
|
||||
+ // Sysroot search order: --tms-sysroot=DIR, then --sysroot/-isysroot, then the
|
||||
+ // resource directory. Nothing here bakes a checkout path: the resource-dir
|
||||
+ // fallback is derived from the clang binary, so the toolchain stays
|
||||
+ // relocatable.
|
||||
+ if (const Arg *A = Args.getLastArg(options::OPT_tms_sysroot_EQ))
|
||||
+ SysRoot = A->getValue();
|
||||
+ else if (const Arg *A = Args.getLastArg(options::OPT__sysroot_EQ,
|
||||
+ options::OPT_isysroot))
|
||||
+ SysRoot = A->getValue();
|
||||
+ else {
|
||||
+ SmallString<128> P(D.ResourceDir);
|
||||
+ llvm::sys::path::append(P, "tms34010-unknown-none");
|
||||
+ SysRoot = std::string(P.str());
|
||||
+ }
|
||||
+
|
||||
+ // Objects and libraries come from <sysroot>/lib.
|
||||
+ SmallString<128> LibDir(SysRoot);
|
||||
+ llvm::sys::path::append(LibDir, "lib");
|
||||
+ getFilePaths().push_back(std::string(LibDir.str()));
|
||||
+ getLibraryPaths().push_back(std::string(LibDir.str()));
|
||||
+}
|
||||
+
|
||||
+void TMS34010ToolChain::addClangTargetOptions(
|
||||
+ const ArgList &DriverArgs, ArgStringList &CC1Args, BoundArch BA,
|
||||
+ Action::OffloadKind DeviceOffloadKind) const {
|
||||
+ // The TMS34010 backend has no native 33-bit multiply, so IndVarSimplify's
|
||||
+ // i33 exit-value rewrite would otherwise reach code generation and abort on
|
||||
+ // an ordinary loop. Disable that rewrite, and compile freestanding with no
|
||||
+ // builtins (there is no libc for this target yet).
|
||||
+ CC1Args.push_back("-ffreestanding");
|
||||
+ CC1Args.push_back("-fno-builtin");
|
||||
+ CC1Args.push_back("-mllvm");
|
||||
+ CC1Args.push_back("-replexitval=never");
|
||||
+ // The legacy tms-clang path ran the -O0 pipeline without the `optnone`
|
||||
+ // attribute (it passed -disable-O0-optnone), so its -O0 objects carry the
|
||||
+ // mem2reg'd shape and no per-parameter spill slot. Match that so native
|
||||
+ // `clang --target=tms34010 -O0 -c` stays byte-identical to the M9 path.
|
||||
+ CC1Args.push_back("-disable-O0-optnone");
|
||||
+
|
||||
+ BareMetal::addClangTargetOptions(DriverArgs, CC1Args, BA, DeviceOffloadKind);
|
||||
+}
|
||||
+
|
||||
+void TMS34010ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
|
||||
+ ArgStringList &CC1Args) const {
|
||||
+ if (DriverArgs.hasArg(options::OPT_nostdinc))
|
||||
+ return;
|
||||
+
|
||||
+ // The target's headers live in <sysroot>/include; the builtin headers keep
|
||||
+ // being found through -resource-dir, matching the M10 freestanding defaults.
|
||||
+ if (!DriverArgs.hasArg(options::OPT_nostdlibinc)) {
|
||||
+ SmallString<128> IncDir(SysRoot);
|
||||
+ llvm::sys::path::append(IncDir, "include");
|
||||
+ addSystemInclude(DriverArgs, CC1Args, IncDir.str());
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+Tool *TMS34010ToolChain::buildLinker() const {
|
||||
+ return new tools::tms34010::TMS34010Linker(*this);
|
||||
+}
|
||||
+
|
||||
+void tms34010::TMS34010Linker::ConstructJob(
|
||||
+ Compilation &C, const JobAction &JA, const InputInfo &Output,
|
||||
+ const InputInfoList &Inputs, const ArgList &Args,
|
||||
+ const char *LinkingOutput) const {
|
||||
+ const auto &TC =
|
||||
+ static_cast<const toolchains::TMS34010ToolChain &>(getToolChain());
|
||||
+ const Driver &D = TC.getDriver();
|
||||
+ const std::string &SysRoot = TC.getTMS34010SysRoot();
|
||||
+
|
||||
+ // Linker discovery: --tms-linker=PATH first, else <sysroot>/bin/tms-link.
|
||||
+ const bool UseDefaultLinker = !Args.hasArg(options::OPT_tms_linker_EQ);
|
||||
+ std::string Linker;
|
||||
+ if (const Arg *A = Args.getLastArg(options::OPT_tms_linker_EQ)) {
|
||||
+ Linker = A->getValue();
|
||||
+ } else {
|
||||
+ SmallString<128> DefaultLinker(SysRoot);
|
||||
+ llvm::sys::path::append(DefaultLinker, "bin", "tms-link");
|
||||
+ Linker = std::string(DefaultLinker.str());
|
||||
+ }
|
||||
+
|
||||
+ // A missing sysroot, a missing linker or a missing python3 is a named
|
||||
+ // diagnostic telling the user to run scripts/tms-sdk -- never a bare link
|
||||
+ // error. The explicit --tms-linker path is trusted verbatim, so neither the
|
||||
+ // linker-existence nor the python3 check applies to it.
|
||||
+ if (!llvm::sys::fs::exists(SysRoot)) {
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_sysroot) << SysRoot;
|
||||
+ return;
|
||||
+ }
|
||||
+ if (UseDefaultLinker && !llvm::sys::fs::exists(Linker)) {
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_linker) << Linker;
|
||||
+ return;
|
||||
+ }
|
||||
+ // The installed tms-link is a Python program; name python3 if it is missing.
|
||||
+ if (UseDefaultLinker && !llvm::sys::findProgramByName("python3")) {
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_python3);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ // Fixed link order: CRT, user objects, the three default libraries, then
|
||||
+ // user -L/-l archives.
|
||||
+ const bool WantStartFiles =
|
||||
+ !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
|
||||
+ const bool WantDefaultLibs =
|
||||
+ !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs);
|
||||
+
|
||||
+ // A sysroot directory can exist while the artifacts the default link needs
|
||||
+ // are absent (a partial install). Name the missing file instead of handing
|
||||
+ // tms-link a bare name it will fail to open.
|
||||
+ bool MissingArtifact = false;
|
||||
+ auto CheckArtifact = [&](StringRef Name) {
|
||||
+ SmallString<128> P(SysRoot);
|
||||
+ llvm::sys::path::append(P, "lib", Name);
|
||||
+ if (llvm::sys::fs::exists(P))
|
||||
+ return;
|
||||
+ D.Diag(diag::err_drv_tms34010_missing_artifact) << std::string(P.str());
|
||||
+ MissingArtifact = true;
|
||||
+ };
|
||||
+ if (WantStartFiles)
|
||||
+ CheckArtifact("crt0.o");
|
||||
+ if (WantDefaultLibs) {
|
||||
+ CheckArtifact("libtms.a");
|
||||
+ CheckArtifact("flib.lib");
|
||||
+ CheckArtifact("rts.lib");
|
||||
+ }
|
||||
+ if (MissingArtifact)
|
||||
+ return;
|
||||
+
|
||||
+ ArgStringList CmdArgs;
|
||||
+
|
||||
+ CmdArgs.push_back("-o");
|
||||
+ CmdArgs.push_back(Output.getFilename());
|
||||
+
|
||||
+ CmdArgs.push_back("--entry");
|
||||
+ CmdArgs.push_back("_start");
|
||||
+ CmdArgs.push_back("--text");
|
||||
+ CmdArgs.push_back("018A0000");
|
||||
+ CmdArgs.push_back("--bss");
|
||||
+ CmdArgs.push_back("01A00000");
|
||||
+ CmdArgs.push_back("--prog-len");
|
||||
+ CmdArgs.push_back("40000h");
|
||||
+ CmdArgs.push_back("--ram-len");
|
||||
+ CmdArgs.push_back("80000h");
|
||||
+
|
||||
+ // -Wl,-Map suppresses the default --map; -Wl,-Map=<file> and the
|
||||
+ // -Wl,-Map,<file> comma form select an explicit map file. tms-link spells
|
||||
+ // its map option --map, so both forms become --map=<file> below.
|
||||
+ auto WlValues = Args.getAllArgValues(options::OPT_Wl_COMMA);
|
||||
+ bool HasExplicitMap = false;
|
||||
+ for (const std::string &Value : WlValues) {
|
||||
+ StringRef V(Value);
|
||||
+ if (V == "-Map" || V.starts_with("-Map="))
|
||||
+ HasExplicitMap = true;
|
||||
+ }
|
||||
+
|
||||
+ // The map is this toolchain's debugging surface: default it next to the
|
||||
+ // output unless the user asked for a -Wl,-Map* form.
|
||||
+ if (!HasExplicitMap) {
|
||||
+ std::string MapFile = std::string(Output.getFilename()) + ".map";
|
||||
+ CmdArgs.push_back("--map");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(MapFile));
|
||||
+ }
|
||||
+
|
||||
+ // -g keeps the DWARF in the linked image; the default stays stripped. -g0
|
||||
+ // (and -ggdb0) request no debug info, so they must not add --keep-debug.
|
||||
+ if (Arg *A = Args.getLastArg(options::OPT_g_Group))
|
||||
+ if (!A->getOption().matches(options::OPT_g0) &&
|
||||
+ !A->getOption().matches(options::OPT_ggdb0))
|
||||
+ CmdArgs.push_back("--keep-debug");
|
||||
+
|
||||
+ // Pass the remaining -Wl, arguments through verbatim, translating the map
|
||||
+ // requests. -Wl,-Map,<file> keeps the path in the following comma element.
|
||||
+ for (size_t I = 0, E = WlValues.size(); I != E; ++I) {
|
||||
+ StringRef V(WlValues[I]);
|
||||
+ if (V == "-Map") {
|
||||
+ // A bare -Wl,-Map has no path and produces no map (it still suppresses
|
||||
+ // the default map, as above); a following element is the map path.
|
||||
+ if (I + 1 != E) {
|
||||
+ std::string MapArg = "--map=" + std::string(WlValues[++I]);
|
||||
+ CmdArgs.push_back(Args.MakeArgString(MapArg));
|
||||
+ }
|
||||
+ continue;
|
||||
+ }
|
||||
+ if (V.starts_with("-Map=")) {
|
||||
+ std::string MapArg = "--map=" + std::string(V.drop_front(5));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(MapArg));
|
||||
+ continue;
|
||||
+ }
|
||||
+ CmdArgs.push_back(Args.MakeArgString(V));
|
||||
+ }
|
||||
+
|
||||
+ // Fixed link order: CRT, user objects, the three default libraries, then
|
||||
+ // user -L/-l archives.
|
||||
+ if (WantStartFiles)
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
|
||||
+
|
||||
+ for (const auto &II : Inputs) {
|
||||
+ if (II.isFilename())
|
||||
+ CmdArgs.push_back(II.getFilename());
|
||||
+ }
|
||||
+
|
||||
+ if (WantDefaultLibs) {
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("libtms.a")));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("flib.lib")));
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("rts.lib")));
|
||||
+ }
|
||||
+
|
||||
+ // Make the sysroot's own library directory reachable for -l lookups before
|
||||
+ // any user -L paths.
|
||||
+ SmallString<128> SysRootLib(SysRoot);
|
||||
+ llvm::sys::path::append(SysRootLib, "lib");
|
||||
+ CmdArgs.push_back("-L");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(SysRootLib.str()));
|
||||
+
|
||||
+ for (const std::string &LibPath : Args.getAllArgValues(options::OPT_L)) {
|
||||
+ CmdArgs.push_back("-L");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(LibPath));
|
||||
+ }
|
||||
+ for (const std::string &Lib : Args.getAllArgValues(options::OPT_l)) {
|
||||
+ // -l tms means "ensure libtms.a is linked". With the defaults it is already
|
||||
+ // a positional input, so it is a no-op; with -nodefaultlibs/-nostdlib the
|
||||
+ // user's -l tms is the only request, so resolve it to the archive so it is
|
||||
+ // linked once per request (repeating -l tms links the archive again).
|
||||
+ if (StringRef(Lib) == "tms") {
|
||||
+ if (!WantDefaultLibs)
|
||||
+ CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("libtms.a")));
|
||||
+ continue;
|
||||
+ }
|
||||
+ CmdArgs.push_back("-l");
|
||||
+ CmdArgs.push_back(Args.MakeArgString(Lib));
|
||||
+ }
|
||||
+
|
||||
+ C.addCommand(std::make_unique<Command>(
|
||||
+ JA, *this, ResponseFileSupport::None(),
|
||||
+ Args.MakeArgString(Linker), CmdArgs, Inputs, Output));
|
||||
+}
|
||||
diff --git a/clang/lib/Driver/ToolChains/TMS34010.h b/clang/lib/Driver/ToolChains/TMS34010.h
|
||||
new file mode 100644
|
||||
index 000000000000..e69011479677
|
||||
--- /dev/null
|
||||
+++ b/clang/lib/Driver/ToolChains/TMS34010.h
|
||||
@@ -0,0 +1,68 @@
|
||||
+//===--- TMS34010.h - TMS34010 ToolChain ------------------------*- C++ -*-===//
|
||||
+//
|
||||
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
+// See https://llvm.org/LICENSE.txt for license information.
|
||||
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
+//
|
||||
+//===----------------------------------------------------------------------===//
|
||||
+
|
||||
+#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
+#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
+
|
||||
+#include "BareMetal.h"
|
||||
+#include "clang/Driver/Tool.h"
|
||||
+
|
||||
+namespace clang {
|
||||
+namespace driver {
|
||||
+namespace toolchains {
|
||||
+
|
||||
+class LLVM_LIBRARY_VISIBILITY TMS34010ToolChain : public BareMetal {
|
||||
+public:
|
||||
+ TMS34010ToolChain(const Driver &D, const llvm::Triple &Triple,
|
||||
+ const llvm::opt::ArgList &Args);
|
||||
+
|
||||
+ void
|
||||
+ addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
|
||||
+ llvm::opt::ArgStringList &CC1Args, BoundArch BA,
|
||||
+ Action::OffloadKind DeviceOffloadKind) const override;
|
||||
+
|
||||
+ void
|
||||
+ AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
|
||||
+ llvm::opt::ArgStringList &CC1Args) const override;
|
||||
+
|
||||
+ /// The sysroot this target's headers, libraries and linker come from,
|
||||
+ /// resolved from --tms-sysroot=, --sysroot/-isysroot, or the resource dir.
|
||||
+ std::string getTMS34010SysRoot() const { return SysRoot; }
|
||||
+
|
||||
+protected:
|
||||
+ Tool *buildLinker() const override;
|
||||
+
|
||||
+private:
|
||||
+ std::string SysRoot;
|
||||
+};
|
||||
+
|
||||
+} // namespace toolchains
|
||||
+
|
||||
+namespace tools {
|
||||
+namespace tms34010 {
|
||||
+
|
||||
+class LLVM_LIBRARY_VISIBILITY TMS34010Linker final : public Tool {
|
||||
+public:
|
||||
+ TMS34010Linker(const ToolChain &TC)
|
||||
+ : Tool("tms34010::Linker", "tms-link", TC) {}
|
||||
+
|
||||
+ bool isLinkJob() const override { return true; }
|
||||
+ bool hasIntegratedCPP() const override { return false; }
|
||||
+
|
||||
+ void ConstructJob(Compilation &C, const JobAction &JA,
|
||||
+ const InputInfo &Output, const InputInfoList &Inputs,
|
||||
+ const llvm::opt::ArgList &TCArgs,
|
||||
+ const char *LinkingOutput) const override;
|
||||
+};
|
||||
+
|
||||
+} // namespace tms34010
|
||||
+} // namespace tools
|
||||
+} // namespace driver
|
||||
+} // namespace clang
|
||||
+
|
||||
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_TMS34010_H
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-chain-o2.c b/clang/test/CodeGen/TMS34010/bitaddr-chain-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..8d4a838ac157
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-chain-o2.c
|
||||
@@ -0,0 +1,24 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// Source-level pointer arithmetic goes through the pre-optimizer barrier
|
||||
+// (@__tms_bitptr) and is lowered back by tms34010LowerBitPtr. If that lowering
|
||||
+// emitted the foldable `inttoptr(add(ptrtoint base, off))` form, the already-bit
|
||||
+// offsets would fold to a plain ISD::ADD on `p:32` and DAGCombiner's
|
||||
+// BaseIndexOffset aliasing would read them as *bytes*: the word store to p+32
|
||||
+// bits and the byte store to p+40 bits would be misread as +32 and +40 bytes
|
||||
+// and reported non-aliasing, and parallelizeChainedStores would hoist the byte
|
||||
+// store ahead of the word store (the word store then overwrites the byte).
|
||||
+//
|
||||
+// The lowering emits llvm.tms34010.bitaddr instead, which lowers to a
|
||||
+// TMS34010ISD::BITADDR node that BaseIndexOffset cannot decompose, so the byte
|
||||
+// store keeps its program-order position after the word store.
|
||||
+
|
||||
+void f(int *p, int v, int w) { p[0] = v; p[1] = w; ((char *)p)[5] = 0x7f; }
|
||||
+
|
||||
+// The word store to p+32 bits (MOVE ..., *..., 1 after ADDI 32) must be
|
||||
+// scheduled before the byte store to p+40 bits (MOVB after ADDI 40).
|
||||
+// CHECK-LABEL: _f:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK: MOVE A{{[0-9]+}}, *A{{[0-9]+}}, 1
|
||||
+// CHECK: ADDI 40, A{{[0-9]+}}
|
||||
+// CHECK: MOVB A{{[0-9]+}}, *A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o0.c b/clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
new file mode 100644
|
||||
index 000000000000..e62cab807aa3
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o0.c
|
||||
@@ -0,0 +1,18 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// The bit-address barrier hides each source GEP behind an opaque
|
||||
+// @__tms_bitptr(i32 bitoff, ptr base) call before the optimizer, and -O0
|
||||
+// lowers it straight back to the bit-addressed inttoptr(add) form, so a
|
||||
+// byte-indexed GEP must reach codegen as an 8x bit offset.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+short load_h(short *p) { return p[1]; }
|
||||
+int load_b(char *p) { return p[4]; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _load_h:
|
||||
+// CHECK: ADDI 16, A{{[0-9]+}}
|
||||
+// CHECK-LABEL: _load_b:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o1.c b/clang/test/CodeGen/TMS34010/bitaddr-o1.c
|
||||
new file mode 100644
|
||||
index 000000000000..acefd9de2af6
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o1.c
|
||||
@@ -0,0 +1,20 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O1 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// The -O0 sibling (bitaddr-o0.c) pins the byte-indexed-GEP bit-address shape
|
||||
+// on the no-optimizer path. -O1 takes the optimizer-last path instead: the
|
||||
+// bit-address barrier hides each source GEP before the optimizer, the post-opt
|
||||
+// scale rescales the byte GEPs the optimizer creates, and lowering undoes the
|
||||
+// barrier. This test pins the same shape on that path, which is otherwise
|
||||
+// covered only indirectly by the static-variadic guard test.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+short load_h(short *p) { return p[1]; }
|
||||
+int load_b(char *p) { return p[4]; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _load_h:
|
||||
+// CHECK: ADDI 16, A{{[0-9]+}}
|
||||
+// CHECK-LABEL: _load_b:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-o2.c b/clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..39b0f38ce948
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-o2.c
|
||||
@@ -0,0 +1,17 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// At -O2 the barrier hides source GEPs before the optimizer, the post-opt
|
||||
+// scale rescales the byte GEPs the optimizer creates, lowering undoes the
|
||||
+// barrier, and a final instcombine canonicalizes the result, so a byte-indexed
|
||||
+// GEP must still reach codegen as an 8x bit offset. `-replexitval=never` is
|
||||
+// the ToolChain default (Task 1); %clang_cc1 bypasses the driver, so it is
|
||||
+// passed explicitly to keep the `sumto` loop below the i33 closed-form
|
||||
+// rewrite.
|
||||
+
|
||||
+int load_i(int *p) { return p[1]; }
|
||||
+int sumto(int n) { int s = 0; for (int i = 0; i <= n; i++) s += i; return s; }
|
||||
+
|
||||
+// CHECK-LABEL: _load_i:
|
||||
+// CHECK: ADDI 32, A{{[0-9]+}}
|
||||
+// CHECK-NOT: ADDI 4, A
|
||||
+// CHECK-LABEL: _sumto:
|
||||
diff --git a/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c b/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
new file mode 100644
|
||||
index 000000000000..fc6867b143b4
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/bitaddr-static-vararg.c
|
||||
@@ -0,0 +1,6 @@
|
||||
+// RUN: not %clang_cc1 -triple tms34010-unknown-none -O1 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
+// RUN: not %clang_cc1 -triple tms34010-unknown-none -O2 -emit-obj %s -o /dev/null 2>&1 | FileCheck %s
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -emit-obj %s -o /dev/null
|
||||
+// CHECK: static variadic definition 'sum' loses its '...' arguments when optimizing
|
||||
+static int sum(int n, ...) { int *p = &n; return p[0] + p[1]; }
|
||||
+int call(void) { return sum(1, 2); }
|
||||
diff --git a/clang/test/CodeGen/TMS34010/float-const-o2.c b/clang/test/CodeGen/TMS34010/float-const-o2.c
|
||||
new file mode 100644
|
||||
index 000000000000..4f244591b61a
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/float-const-o2.c
|
||||
@@ -0,0 +1,26 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -mllvm -replexitval=never -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// A float literal stored to memory through a union (or returned by a helper
|
||||
+// whose constant result IPSCCP propagates) must be materialised from a
|
||||
+// GSP-initialised global. The early float-constant protection keeps the
|
||||
+// constant a load before the optimizer can fold it through the union bitcast
|
||||
+// to its IEEE bits; the AsmPrinter then emits the GSP words.
|
||||
+
|
||||
+typedef unsigned int u32;
|
||||
+typedef union { float f; u32 u; } fu;
|
||||
+extern volatile u32 markers[];
|
||||
+
|
||||
+static void mark_f(u32 n, float v) { fu x; x.f = v; markers[n] = x.u; }
|
||||
+float fnegzero(void) { return -0.0f; }
|
||||
+
|
||||
+void run(void) {
|
||||
+ mark_f(0, 7.0f); // GSP 41700000h, never IEEE 40E00000h
|
||||
+ mark_f(1, fnegzero()); // GSP +0, never IEEE -0 (80000000h)
|
||||
+}
|
||||
+
|
||||
+// 7.0f is GSP 41700000h and -0.0f canonicalises to +0 (all zeroes); the IEEE
|
||||
+// bits (40E00000h / 80000000h) must never be stored anywhere.
|
||||
+// CHECK-DAG: .long 41700000h
|
||||
+// CHECK-DAG: .long 00000000h
|
||||
+// CHECK-NOT: .long 40E00000h
|
||||
+// CHECK-NOT: .long 80000000h
|
||||
diff --git a/clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c b/clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c
|
||||
new file mode 100644
|
||||
index 000000000000..9a1512116c74
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/m12-inline-asm-mem.c
|
||||
@@ -0,0 +1,19 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O2 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// M12: an `m` operand is a memory operand the backend can now address. The
|
||||
+// asm template is empty, so the bar is that the selector finds a valid
|
||||
+// TMS34010 address for the operand instead of the M9 named error; the
|
||||
+// addressing form itself is covered by m12-inline-asm-mem-forms.ll.
|
||||
+int load_via_asm(int *p) {
|
||||
+ int x;
|
||||
+ __asm__ volatile("" : "=r"(x) : "m"(*p) : "memory");
|
||||
+ return x;
|
||||
+}
|
||||
+int store_via_asm(int *p, int v) {
|
||||
+ __asm__ volatile("" : : "m"(*p), "r"(v) : "memory");
|
||||
+ return v;
|
||||
+}
|
||||
+// CHECK-LABEL: _load_via_asm:
|
||||
+// CHECK-NOT: error:
|
||||
+// CHECK-LABEL: _store_via_asm:
|
||||
diff --git a/clang/test/CodeGen/TMS34010/m12-inline-asm-st.c b/clang/test/CodeGen/TMS34010/m12-inline-asm-st.c
|
||||
new file mode 100644
|
||||
index 000000000000..ca1f041f709d
|
||||
--- /dev/null
|
||||
+++ b/clang/test/CodeGen/TMS34010/m12-inline-asm-st.c
|
||||
@@ -0,0 +1,11 @@
|
||||
+// RUN: %clang_cc1 -triple tms34010-unknown-none -O0 -S -o - %s | FileCheck %s
|
||||
+//
|
||||
+// M12: `st` names the status register as a clobber. Before M12 clang rejected
|
||||
+// the name ("unknown register name 'st' in asm") because getGCCRegNames()
|
||||
+// listed only the A/B files. ST stays out of every register class and out of
|
||||
+// the operand constraints, so this only makes the clobber nameable.
|
||||
+int clobber_st(int x) {
|
||||
+ __asm__ volatile("" : "+r"(x) : : "st");
|
||||
+ return x;
|
||||
+}
|
||||
+// CHECK-LABEL: _clobber_st:
|
||||
diff --git a/clang/test/Driver/TMS34010-link.c b/clang/test/Driver/TMS34010-link.c
|
||||
new file mode 100644
|
||||
index 000000000000..3b067d9eb3b6
|
||||
--- /dev/null
|
||||
+++ b/clang/test/Driver/TMS34010-link.c
|
||||
@@ -0,0 +1,147 @@
|
||||
+// Check that the TMS34010 driver discovers its sysroot and turns a link into a
|
||||
+// real tms-link job, and that the link-reduction knobs, -g and -Wl, behave.
|
||||
+//
|
||||
+// The link cases below use a fake sysroot so the test is hermetic and does
|
||||
+// not depend on `scripts/tms-sdk` having been run: the CRT and the three
|
||||
+// libraries are empty placeholders under <sysroot>/lib, and the linker is the
|
||||
+// touched placeholder under <sysroot>/bin.
|
||||
+
|
||||
+// RUN: rm -rf %t.sysroot && mkdir -p %t.sysroot/bin %t.sysroot/lib %t.sysroot/include
|
||||
+// RUN: touch %t.sysroot/bin/tms-link %t.sysroot/lib/crt0.o %t.sysroot/lib/libtms.a %t.sysroot/lib/flib.lib %t.sysroot/lib/rts.lib
|
||||
+
|
||||
+// Default link: the sysroot linker, the fixed flags, the CRT, the object and
|
||||
+// the three default libraries, plus the sysroot include path and a default map.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot %s -o %t.out 2>&1 | FileCheck %s --check-prefix=DEFAULT
|
||||
+// DEFAULT: "-internal-isystem" "{{.*}}sysroot{{/|\\}}include"
|
||||
+// DEFAULT: "{{.*}}tms-link"
|
||||
+// DEFAULT-SAME: "-o" "{{.*}}.out"
|
||||
+// DEFAULT-SAME: "--entry" "_start"
|
||||
+// DEFAULT-SAME: "--text" "018A0000"
|
||||
+// DEFAULT-SAME: "--bss" "01A00000"
|
||||
+// DEFAULT-SAME: "--prog-len" "40000h"
|
||||
+// DEFAULT-SAME: "--ram-len" "80000h"
|
||||
+// DEFAULT-SAME: "--map" "{{.*}}.out.map"
|
||||
+// DEFAULT-SAME: crt0.o
|
||||
+// DEFAULT-SAME: libtms.a
|
||||
+// DEFAULT-SAME: flib.lib
|
||||
+// DEFAULT-SAME: rts.lib
|
||||
+// DEFAULT-SAME: "-L" "{{.*}}sysroot{{/|\\}}lib"
|
||||
+
|
||||
+// -nostdlib drops the CRT and all three libraries.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nostdlib %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOSTDLIB
|
||||
+// NOSTDLIB: "{{.*}}tms-link"
|
||||
+// NOSTDLIB-NOT: crt0.o
|
||||
+// NOSTDLIB-NOT: libtms.a
|
||||
+// NOSTDLIB-NOT: flib.lib
|
||||
+// NOSTDLIB-NOT: rts.lib
|
||||
+
|
||||
+// -nostartfiles drops only the CRT; the libraries remain.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nostartfiles %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOSTART
|
||||
+// NOSTART: "{{.*}}tms-link"
|
||||
+// NOSTART-NOT: crt0.o
|
||||
+// NOSTART-SAME: libtms.a
|
||||
+// NOSTART-SAME: flib.lib
|
||||
+// NOSTART-SAME: rts.lib
|
||||
+
|
||||
+// -nodefaultlibs keeps the CRT but drops the three libraries.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nodefaultlibs %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NODEFLTLIBS
|
||||
+// NODEFLTLIBS: "{{.*}}tms-link"
|
||||
+// NODEFLTLIBS-SAME: crt0.o
|
||||
+// NODEFLTLIBS-NOT: libtms.a
|
||||
+// NODEFLTLIBS-NOT: flib.lib
|
||||
+// NODEFLTLIBS-NOT: rts.lib
|
||||
+
|
||||
+// With -nodefaultlibs, -l tms is the user's only way to ask for the archive;
|
||||
+// it must resolve to libtms.a exactly once, with no flib/rts.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -nodefaultlibs -l tms %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NODEFL_LTMS
|
||||
+// NODEFL_LTMS: "{{.*}}tms-link"
|
||||
+// NODEFL_LTMS-SAME: crt0.o
|
||||
+// NODEFL_LTMS-SAME: libtms.a
|
||||
+// NODEFL_LTMS-NOT: libtms.a
|
||||
+// NODEFL_LTMS-NOT: flib.lib
|
||||
+// NODEFL_LTMS-NOT: rts.lib
|
||||
+// NODEFL_LTMS-NOT: "-l" "tms"
|
||||
+
|
||||
+// -g adds --keep-debug.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -g %s -o %t.out 2>&1 | FileCheck %s --check-prefix=G
|
||||
+// G: "{{.*}}tms-link"
|
||||
+// G-SAME: "--keep-debug"
|
||||
+
|
||||
+// -g0 and -ggdb0 request no debug info, so no --keep-debug.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -g0 %s -o %t.out 2>&1 | FileCheck %s --check-prefix=G0
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -ggdb0 %s -o %t.out 2>&1 | FileCheck %s --check-prefix=G0
|
||||
+// G0: "{{.*}}tms-link"
|
||||
+// G0-NOT: "--keep-debug"
|
||||
+
|
||||
+// -Wl, arguments pass through verbatim.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -Wl,--prog-len=80000h %s -o %t.out 2>&1 | FileCheck %s --check-prefix=WL
|
||||
+// WL: "{{.*}}tms-link"
|
||||
+// WL-SAME: "--prog-len=80000h"
|
||||
+
|
||||
+// -Wl,-Map=<file> selects that map file and suppresses the default --map.
|
||||
+// The NOT range starts at the linker token so a stray default map (which
|
||||
+// would be emitted before the translated --map=) is caught too.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -Wl,-Map=foo.map %s -o %t.out 2>&1 | FileCheck %s --check-prefix=MAPEQ
|
||||
+// MAPEQ: "{{.*}}tms-link"
|
||||
+// MAPEQ-NOT: "--map" "{{.*}}.out.map"
|
||||
+// MAPEQ: "--map=foo.map"
|
||||
+// MAPEQ-NOT: "foo.map"
|
||||
+
|
||||
+// -Wl,-Map,<file> (the comma form) consumes the next element as the map path
|
||||
+// instead of forwarding the filename as a linker input.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -Wl,-Map,foo.map %s -o %t.out 2>&1 | FileCheck %s --check-prefix=MAPCOMMA
|
||||
+// MAPCOMMA: "{{.*}}tms-link"
|
||||
+// MAPCOMMA-NOT: "--map" "{{.*}}.out.map"
|
||||
+// MAPCOMMA: "--map=foo.map"
|
||||
+// MAPCOMMA-NOT: "foo.map"
|
||||
+
|
||||
+// --tms-linker=PATH replaces the sysroot linker.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot --tms-linker=/tmp/x %s -o %t.out 2>&1 | FileCheck %s --check-prefix=LINKER
|
||||
+// LINKER: "/tmp/x"
|
||||
+// LINKER-SAME: "--entry" "_start"
|
||||
+
|
||||
+// -l tms is accepted and does not duplicate libtms.a.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -l tms %s -o %t.out 2>&1 | FileCheck %s --check-prefix=LTMS
|
||||
+// LTMS: "{{.*}}tms-link"
|
||||
+// LTMS-SAME: libtms.a
|
||||
+// LTMS-NOT: "-l" "tms"
|
||||
+
|
||||
+// A nonexistent sysroot is a named diagnostic, not a link error.
|
||||
+// RUN: not %clang -### --target=tms34010 --tms-sysroot=/nope %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOSYSROOT
|
||||
+// NOSYSROOT: error: TMS34010 sysroot not found
|
||||
+// NOSYSROOT-SAME: run 'scripts/tms-sdk'
|
||||
+// NOSYSROOT-NOT: "tms-link"
|
||||
+
|
||||
+// A sysroot without bin/tms-link is a named diagnostic, not a link error.
|
||||
+// RUN: rm -rf %t.nolink && mkdir -p %t.nolink
|
||||
+// RUN: not %clang -### --target=tms34010 --tms-sysroot=%t.nolink %s -o %t.out 2>&1 | FileCheck %s --check-prefix=NOLINKER
|
||||
+// NOLINKER: error: TMS34010 linker not found
|
||||
+// NOLINKER-SAME: run 'scripts/tms-sdk'
|
||||
+// NOLINKER-NOT: "tms-link"
|
||||
+
|
||||
+// A sysroot directory that exists but lacks the artifacts the default link
|
||||
+// needs names each missing file and points at scripts/tms-sdk, instead of
|
||||
+// handing tms-link bare names.
|
||||
+// RUN: rm -rf %t.partial && mkdir -p %t.partial/bin %t.partial/lib %t.partial/include
|
||||
+// RUN: touch %t.partial/bin/tms-link
|
||||
+// RUN: not %clang -### --target=tms34010 --tms-sysroot=%t.partial %s -o %t.out 2>&1 | FileCheck %s --check-prefix=PARTIAL
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}crt0.o' is missing
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}libtms.a' is missing
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}flib.lib' is missing
|
||||
+// PARTIAL-DAG: error: TMS34010 sysroot is incomplete: '{{.*}}rts.lib' is missing
|
||||
+// PARTIAL-DAG: run 'scripts/tms-sdk'
|
||||
+
|
||||
+// With -nostdlib nothing is needed from the sysroot's lib directory, so the
|
||||
+// same partial sysroot still reaches the (placeholder) linker.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.partial -nostdlib %s -o %t.out 2>&1 | FileCheck %s --check-prefix=PARTIALNOSTDLIB
|
||||
+// PARTIALNOSTDLIB: "{{.*}}tms-link"
|
||||
+// PARTIALNOSTDLIB-NOT: sysroot is incomplete
|
||||
+
|
||||
+// Compile-only modes emit no link job.
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -c %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -S %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -E %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// RUN: %clang -### --target=tms34010 --tms-sysroot=%t.sysroot -S -emit-llvm %s 2>&1 | FileCheck %s --check-prefix=NOLINK
|
||||
+// NOLINK-NOT: tms-link
|
||||
+
|
||||
+int f(int n) { return n + 1; }
|
||||
diff --git a/clang/test/Driver/tms34010-defaults.c b/clang/test/Driver/tms34010-defaults.c
|
||||
new file mode 100644
|
||||
index 000000000000..568a4a0b3434
|
||||
--- /dev/null
|
||||
+++ b/clang/test/Driver/tms34010-defaults.c
|
||||
@@ -0,0 +1,9 @@
|
||||
+// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=FLAGS
|
||||
+// RUN: %clang -### --target=tms34010 -c %s 2>&1 | FileCheck %s --check-prefix=NOSYS
|
||||
+// FLAGS: "-cc1" {{.*}}-ffreestanding
|
||||
+// FLAGS-SAME: -fno-builtin
|
||||
+// FLAGS-SAME: "-mllvm" "-replexitval=never"
|
||||
+// FLAGS-SAME: "-disable-O0-optnone"
|
||||
+// NOSYS: "-internal-isystem" "{{.*}}tms34010-unknown-none{{/|\\}}include"
|
||||
+// NOSYS-NOT: "-internal-isystem" "/usr/"
|
||||
+int f(int n) { return n + 1; }
|
||||
+16
-15
@@ -25,7 +25,7 @@
|
||||
# (250,200) inside the mapped window. A markers-only or root-window bit is a
|
||||
# failure.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# Overridable: TMS_CLANG TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# SDK_IMG M3_WORK M3_COFF M3_SDK LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
@@ -34,8 +34,6 @@ DIR=$ROOT/scripts/m3
|
||||
|
||||
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}
|
||||
@@ -59,7 +57,7 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
for tool in "$TMS_CLANG" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
@@ -68,19 +66,22 @@ mkdir -p "$(dirname "$COFF")"
|
||||
|
||||
# IndVarSimplify's exit-value replacement turns sumto's loop into an i33
|
||||
# multiply (n*(n+1)/2), and this target has no multiply or i64 support: llc
|
||||
# then dies selecting umul_lohi. Keep the loop (which is the point of the M3
|
||||
# branch test) by disabling only that rewrite, and only for branch.c; xhello
|
||||
# and layout use the normal optimizer pipeline. branch.c itself is unchanged.
|
||||
OPT_NOREPLEXIT=$WORK/opt-keep-loops
|
||||
printf '#!/bin/sh\nexec "%s" -replexitval=never "$@"\n' "$TMS_OPT" > "$OPT_NOREPLEXIT"
|
||||
chmod +x "$OPT_NOREPLEXIT"
|
||||
|
||||
# then dies selecting umul_lohi. The TMS34010 ToolChain passes
|
||||
# -mllvm -replexitval=never, so the ordinary tms-clang -O2 pipeline keeps the
|
||||
# loop (the point of the M3 branch test) with no local opt wrapper.
|
||||
echo "== compile and select"
|
||||
export TMS_CLANG TMS_BITADDR
|
||||
export TMS_CLANG
|
||||
for name in xhello branch layout; do
|
||||
opt=$TMS_OPT
|
||||
[ "$name" = branch ] && opt=$OPT_NOREPLEXIT
|
||||
TMS_OPT=$opt "$ROOT/scripts/tms-clang" -O2 -I "$DIR" -o "$ASM/$name.ll" "$DIR/$name.c"
|
||||
# branch.c needs -fno-inline: at -O2 clang inlines sumto/max2/lt into
|
||||
# branch_test and constant-folds sumto(10), so the disassembler round-trip
|
||||
# would have no _sumto/_max2/_lt calls to check. -O0 would stop the inlining
|
||||
# too, but it also changes the branch condition codes the round-trip pins
|
||||
# (sumto LT/EQ, max2 GT); -fno-inline keeps the -O2 shapes and just leaves
|
||||
# the calls in place.
|
||||
extra=
|
||||
[ "$name" = branch ] && extra=-fno-inline
|
||||
TMS_CLANG_EXTRA_FLAGS=$extra "$ROOT/scripts/tms-clang" -O2 -I "$DIR" \
|
||||
-o "$ASM/$name.ll" "$DIR/$name.c"
|
||||
"$TMS_LLC" -march=tms34010 -O0 -filetype=asm \
|
||||
"$ASM/$name.ll" -o "$ASM/$name.s" \
|
||||
|| fail "llc failed for $name.c"
|
||||
|
||||
Executable
+236
@@ -0,0 +1,236 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Validate (and repair) a linked TI-COFF image for the VT1200 loader.
|
||||
|
||||
GSPLNK 2.00 has two observed output shapes that the loader rejects:
|
||||
|
||||
* when the test object has no initialised .data, it writes a fully zeroed
|
||||
20-byte file header + 28-byte optional header, while the section table at
|
||||
byte 48 is valid (loader status 3, "bad COFF magic");
|
||||
* an odd-length .bss makes the section's bit size not a whole word (loader
|
||||
status 4, "section size not whole words").
|
||||
|
||||
This helper validates the magic, the section table and the section sizes. With
|
||||
--repair it reconstructs the zeroed header/optional header from the intact
|
||||
section table and the linker map entry point, and rounds only .bss up to a
|
||||
16-bit word. It never touches .text/.data contents or the entry point.
|
||||
|
||||
Usage: coff-check.py [--repair] [--entry HEX] FILE
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import struct
|
||||
import sys
|
||||
|
||||
FILE_MAGIC = 0x0090
|
||||
OPT_MAGIC = 0x0108
|
||||
OPT_VERSION = 0x00C7
|
||||
FILE_FLAGS = 0x0103
|
||||
OPT_HDR_SIZE = 28
|
||||
ZERO_HEADER_SIZE = 20 + OPT_HDR_SIZE
|
||||
|
||||
|
||||
def u16(data, off):
|
||||
return struct.unpack_from("<H", data, off)[0]
|
||||
|
||||
|
||||
def u32(data, off):
|
||||
return struct.unpack_from("<I", data, off)[0]
|
||||
|
||||
|
||||
def put_u16(data, off, value):
|
||||
struct.pack_into("<H", data, off, value)
|
||||
|
||||
|
||||
def put_u32(data, off, value):
|
||||
struct.pack_into("<I", data, off, value)
|
||||
|
||||
|
||||
def section_at(data, off):
|
||||
raw = data[off:off + 8]
|
||||
name = raw.split(b"\0", 1)[0].decode("ascii", "replace")
|
||||
return {
|
||||
"off": off,
|
||||
"name": name,
|
||||
"paddr": u32(data, off + 8),
|
||||
"size": u32(data, off + 16),
|
||||
"scnptr": u32(data, off + 20),
|
||||
"flags": u32(data, off + 36),
|
||||
}
|
||||
|
||||
|
||||
def parse(data):
|
||||
if len(data) < 20:
|
||||
raise ValueError("file is shorter than the 20-byte COFF header")
|
||||
magic = u16(data, 0)
|
||||
nscns = u16(data, 2)
|
||||
opt = u16(data, 16)
|
||||
return {
|
||||
"magic": magic,
|
||||
"nscns": nscns,
|
||||
"opthdr": opt,
|
||||
"optmagic": u16(data, 20) if opt else 0,
|
||||
"entry": u32(data, 20 + 16) if opt else 0,
|
||||
"textstart": u32(data, 20 + 20) if opt else 0,
|
||||
}
|
||||
|
||||
|
||||
def scan_recoverable_sections(data):
|
||||
"""Recover the section table of GSPLNK's zero-header shape.
|
||||
|
||||
GSPLNK always leaves the 20-byte file header and 28-byte optional header
|
||||
(48 bytes) zero, then writes the section table at byte 48. Stop at the
|
||||
first entry whose name does not start with '.', so a trailing symbol table
|
||||
is not mistaken for a section.
|
||||
"""
|
||||
if len(data) < ZERO_HEADER_SIZE + 40:
|
||||
raise ValueError("no room for a recovered section table")
|
||||
sections = []
|
||||
off = ZERO_HEADER_SIZE
|
||||
while off + 40 <= len(data) and len(sections) < 96:
|
||||
sec = section_at(data, off)
|
||||
if not sec["name"].startswith("."):
|
||||
break
|
||||
sections.append(sec)
|
||||
off += 40
|
||||
if not sections:
|
||||
raise ValueError("zero header and no section table at byte 48")
|
||||
return sections
|
||||
|
||||
|
||||
def validate(data, sections, label):
|
||||
bad = []
|
||||
for sec in sections:
|
||||
name = sec["name"]
|
||||
size = sec["size"]
|
||||
if not name:
|
||||
bad.append("empty section name")
|
||||
if size % 16 != 0 and name != ".bss":
|
||||
bad.append(f"{name}: bit size {size} is not a whole word")
|
||||
if name == ".bss" and size % 16 != 0:
|
||||
bad.append(".bss: bit size %d is not a whole word" % size)
|
||||
# scnptr points at raw bytes for non-.bss sections; the file must
|
||||
# contain size/8 bytes there. .bss has no file payload.
|
||||
if name != ".bss" and sec["scnptr"]:
|
||||
need = sec["scnptr"] + (size + 7) // 8
|
||||
if need > len(data):
|
||||
bad.append(f"{name}: payload ends past EOF ({need} > {len(data)})")
|
||||
if bad:
|
||||
raise ValueError(f"{label}: " + "; ".join(bad))
|
||||
|
||||
|
||||
def repair(data, entry):
|
||||
header_zero = data[:20] == b"\0" * 20
|
||||
opt_zero = data[20:ZERO_HEADER_SIZE] == b"\0" * OPT_HDR_SIZE
|
||||
changed = []
|
||||
|
||||
if header_zero and opt_zero:
|
||||
sections = scan_recoverable_sections(data)
|
||||
names = {sec["name"]: sec for sec in sections}
|
||||
for required in (".text", ".data", ".bss"):
|
||||
if required not in names:
|
||||
raise ValueError(f"recoverable header lacks {required}")
|
||||
text = names[".text"]
|
||||
dat = names[".data"]
|
||||
bss = names[".bss"]
|
||||
bss_size = (bss["size"] + 15) & ~15
|
||||
if bss_size != bss["size"]:
|
||||
put_u32(data, bss["off"] + 16, bss_size)
|
||||
changed.append(f".bss size {bss['size']} -> {bss_size} bits")
|
||||
|
||||
# File header: magic, section count, timestamp, symbol pointer/count,
|
||||
# optional-header size, flags.
|
||||
put_u16(data, 0, FILE_MAGIC)
|
||||
put_u16(data, 2, len(sections))
|
||||
put_u32(data, 4, 0)
|
||||
put_u32(data, 8, 0)
|
||||
put_u32(data, 12, 0)
|
||||
put_u16(data, 16, OPT_HDR_SIZE)
|
||||
put_u16(data, 18, FILE_FLAGS)
|
||||
# Optional header: magic, version, text/data/bss bits, entry and the
|
||||
# text/data origins.
|
||||
put_u16(data, 20, OPT_MAGIC)
|
||||
put_u16(data, 22, OPT_VERSION)
|
||||
put_u32(data, 24, text["size"])
|
||||
put_u32(data, 28, dat["size"])
|
||||
put_u32(data, 32, bss_size)
|
||||
put_u32(data, 36, entry)
|
||||
put_u32(data, 40, text["paddr"])
|
||||
put_u32(data, 44, dat["paddr"])
|
||||
changed.append("reconstructed zeroed file/optional header")
|
||||
return changed, sections
|
||||
|
||||
info = parse(data)
|
||||
if info["magic"] != FILE_MAGIC:
|
||||
raise ValueError(f"bad COFF magic {info['magic']:#06x}, want {FILE_MAGIC:#06x}")
|
||||
if info["nscns"] == 0 or info["opthdr"] != OPT_HDR_SIZE:
|
||||
raise ValueError(
|
||||
f"invalid header nscns={info['nscns']} opthdr={info['opthdr']}")
|
||||
base = 20 + info["opthdr"]
|
||||
if base + info["nscns"] * 40 > len(data):
|
||||
raise ValueError("section table runs past EOF")
|
||||
sections = [section_at(data, base + i * 40) for i in range(info["nscns"])]
|
||||
|
||||
for sec in sections:
|
||||
if sec["name"] == ".bss" and sec["size"] % 16 != 0:
|
||||
new_size = (sec["size"] + 15) & ~15
|
||||
put_u32(data, sec["off"] + 16, new_size)
|
||||
# Keep the optional header's bss-size field consistent.
|
||||
put_u32(data, 32, new_size)
|
||||
changed.append(f".bss size {sec['size']} -> {new_size} bits")
|
||||
sec["size"] = new_size
|
||||
return changed, sections
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser(description=__doc__)
|
||||
ap.add_argument("--repair", action="store_true",
|
||||
help="repair the observed GSPLNK header/.bss shapes")
|
||||
ap.add_argument("--entry", default="018A0000",
|
||||
help="entry bit address for a reconstructed header")
|
||||
ap.add_argument("file")
|
||||
args = ap.parse_args()
|
||||
try:
|
||||
entry = int(args.entry, 16) if not args.entry.startswith("0x") else int(args.entry, 0)
|
||||
except ValueError:
|
||||
print(f"coff-check: bad --entry {args.entry}", file=sys.stderr)
|
||||
return 2
|
||||
try:
|
||||
data = bytearray(open(args.file, "rb").read())
|
||||
except OSError as exc:
|
||||
print(f"coff-check: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
try:
|
||||
info = parse(data)
|
||||
zero_header = info["magic"] == 0 and info["nscns"] == 0
|
||||
if zero_header and not args.repair:
|
||||
raise ValueError("zeroed file/optional header (GSPLNK shape); rerun with --repair")
|
||||
if args.repair:
|
||||
changed, sections = repair(data, entry)
|
||||
if changed:
|
||||
with open(args.file, "wb") as out:
|
||||
out.write(data)
|
||||
for item in changed:
|
||||
print(f"coff-check: repaired {item}")
|
||||
info = parse(data)
|
||||
if info["magic"] != FILE_MAGIC:
|
||||
raise ValueError(f"bad COFF magic {info['magic']:#06x}")
|
||||
if info["nscns"] == 0 or info["opthdr"] != OPT_HDR_SIZE:
|
||||
raise ValueError(
|
||||
f"invalid header nscns={info['nscns']} opthdr={info['opthdr']}")
|
||||
base = 20 + info["opthdr"]
|
||||
if base + info["nscns"] * 40 > len(data):
|
||||
raise ValueError("section table runs past EOF")
|
||||
sections = [section_at(data, base + i * 40) for i in range(info["nscns"])]
|
||||
validate(data, sections, "post-repair")
|
||||
except ValueError as exc:
|
||||
print(f"coff-check: FAIL: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
names = ",".join(sec["name"] for sec in sections)
|
||||
print(f"coff-check: OK sections={len(sections)} [{names}] entry={info['entry']:#010x}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+139
-15
@@ -16,8 +16,14 @@
|
||||
# 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_EXTRA_CFLAGS="-std=..." extra tms-clang language flags (default empty;
|
||||
# the conformance sweep uses this for c-torture's
|
||||
# gnu89 dialect; shipped gates pass nothing)
|
||||
# M4_NATIVE=1 compile with llc -filetype=obj and link the
|
||||
# objects with GSPLNK (the default is GSPA text)
|
||||
# M4_NATIVE_SKIP_ASM=1 in native mode, do not also emit .s for a TU
|
||||
# whose raw GSPA form is intentionally rejected
|
||||
# (for example an odd-offset pointer record)
|
||||
# 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
|
||||
@@ -25,10 +31,26 @@
|
||||
# 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_LINKER=tms-link native-mode opt-in: link the GSPA entry/extras
|
||||
# objects and any M4_NATIVE_LIBS/M4_NATIVE_RTS
|
||||
# archives with tools/tms-link instead of GSPLNK
|
||||
# (default: gsplnk, which remains the oracle).
|
||||
# Requires M4_NATIVE=1.
|
||||
# M4_OS2=1 assemble/link with the 1990 r5.01 OS/2 tools
|
||||
# under 2ine+qemu-i386 instead of DOSBox (run
|
||||
# scripts/m8/setup-os2.sh first; the 1987
|
||||
# GSPA/GSPLNK oracle is still the default)
|
||||
# M4_OS2_LX=/path ../../2ine-tms34010/build-qemu/lx_loader
|
||||
# M4_OS2_SDK=/path extracted r5.01 tree (bin/ and lib/)
|
||||
# M4_SKIP_MAME=1 stop after a clean GSPA/GSPLNK link
|
||||
# M4_COFF_REPAIR=1 validate the linked COFF magic/section sizes and
|
||||
# repair GSPLNK's observed zero-header and
|
||||
# odd-.bss shapes (default 1; set 0 to validate
|
||||
# only and fail on the defect)
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC MAME DOSBOX DOSBOX_CONF
|
||||
# SDK_IMG M4_WORK M4_COFF M4_SDK M4_SYMS LOADER_AT LOADER_END
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC TMS_LINK MAME DOSBOX
|
||||
# DOSBOX_CONF SDK_IMG M4_WORK M4_COFF M4_SDK M4_SYMS LOADER_AT
|
||||
# LOADER_END M4_COFF_REPAIR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
@@ -39,6 +61,7 @@ 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_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
|
||||
MAME=${MAME:-$ROOT/build/mame-src/vt1200}
|
||||
DOSBOX=${DOSBOX:-dosbox}
|
||||
@@ -61,12 +84,17 @@ 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:-}
|
||||
EXTRA_CFLAGS=${M4_EXTRA_CFLAGS:-}
|
||||
NATIVE=${M4_NATIVE:-0}
|
||||
OS2=${M4_OS2:-0}
|
||||
NATIVE_SKIP_ASM=${M4_NATIVE_SKIP_ASM:-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}
|
||||
LINKER=${M4_LINKER:-gsplnk}
|
||||
COFF_REPAIR=${M4_COFF_REPAIR:-1}
|
||||
|
||||
fail() {
|
||||
echo "m4: $*" >&2
|
||||
@@ -76,6 +104,14 @@ fail() {
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR" "$TMS_LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
case $LINKER in
|
||||
gsplnk|tms-link) ;;
|
||||
*) fail "M4_LINKER must be 'gsplnk' or 'tms-link', got '$LINKER'" ;;
|
||||
esac
|
||||
if [ "$LINKER" = tms-link ]; then
|
||||
[ "$NATIVE" = 1 ] || fail "M4_LINKER=tms-link requires M4_NATIVE=1"
|
||||
[ -x "$TMS_LINK" ] || fail "missing tms-link: $TMS_LINK"
|
||||
fi
|
||||
[ -f "$ENTRY" ] || fail "missing entry: $ENTRY"
|
||||
|
||||
mkdir -p "$ASM" "$WORK/evidence" "$WORK/run/nvram" "$WORK/run/cfg"
|
||||
@@ -83,6 +119,7 @@ mkdir -p "$(dirname "$COFF")"
|
||||
|
||||
echo "== compile and select ($CLANG_OPT / llc $LLC_OPT)"
|
||||
export TMS_CLANG TMS_OPT TMS_BITADDR
|
||||
export TMS_CLANG_EXTRA_FLAGS="$EXTRA_CFLAGS"
|
||||
for name in $SOURCES; do
|
||||
case $name in
|
||||
*/*) src=$name ;;
|
||||
@@ -93,15 +130,20 @@ for name in $SOURCES; do
|
||||
# shellcheck disable=SC2086
|
||||
"$ROOT/scripts/tms-clang" "$CLANG_OPT" $EXTRA_INCLUDES \
|
||||
-o "$ASM/$base.ll" "$src"
|
||||
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
||||
"$ASM/$base.ll" -o "$ASM/$base.s" \
|
||||
|| fail "llc -filetype=asm failed for $name"
|
||||
if [ "$NATIVE" = 1 ]; then
|
||||
if [ "$NATIVE_SKIP_ASM" != 1 ]; then
|
||||
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
||||
"$ASM/$base.ll" -o "$ASM/$base.s" \
|
||||
|| fail "llc -filetype=asm failed for $name"
|
||||
fi
|
||||
"$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
|
||||
"$TMS_LLC" -march=tms34010 "$LLC_OPT" -filetype=asm \
|
||||
"$ASM/$base.ll" -o "$ASM/$base.s" \
|
||||
|| fail "llc -filetype=asm failed for $name"
|
||||
echo " $base.s: $(grep -c . "$ASM/$base.s") lines"
|
||||
fi
|
||||
done
|
||||
@@ -161,6 +203,12 @@ strip_end() {
|
||||
sed '/^[[:space:]]*\.end[[:space:]]*$/d' "$1"
|
||||
}
|
||||
|
||||
# Optional host-side 1990 OS/2 r5.01 assembler/linker path (2ine + qemu-i386).
|
||||
if [ "$OS2" = 1 ]; then
|
||||
. "$ROOT/scripts/m8/os2-toolchain.sh"
|
||||
os2_init
|
||||
fi
|
||||
|
||||
EXTRAS=
|
||||
if [ -n "${M4_EXTRA_ASM:-}" ]; then
|
||||
for extra in $M4_EXTRA_ASM; do
|
||||
@@ -213,10 +261,20 @@ if [ "$NATIVE" = 1 ]; then
|
||||
[ -f "$SDK/RTS.LIB" ] || fail "RTS.LIB not extracted into $SDK"
|
||||
NATIVE_LIBS="$NATIVE_LIBS rts.lib"
|
||||
fi
|
||||
# Resolve the library names to SDK paths for tms-link. GSPLNK keeps
|
||||
# consuming the -l lines in M4.CMD; the order is identical.
|
||||
NATIVE_LIB_PATHS=
|
||||
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"
|
||||
if [ -f "$lib" ]; then
|
||||
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $lib"
|
||||
elif [ -f "$SDK/$dos" ]; then
|
||||
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $SDK/$dos"
|
||||
elif [ -f "$SDK/$lib" ]; then
|
||||
NATIVE_LIB_PATHS="$NATIVE_LIB_PATHS $SDK/$lib"
|
||||
else
|
||||
fail "$lib not extracted into $SDK"
|
||||
fi
|
||||
done
|
||||
{
|
||||
printf '%s\n' '-a' '-o M4.OUT' '-m M4.MAP' '-e _start'
|
||||
@@ -277,7 +335,33 @@ run_dosbox() {
|
||||
-noprimaryconf -nolocalconf "$@" > "$WORK/dosbox.log" 2>&1
|
||||
}
|
||||
|
||||
if [ "$NATIVE" = 1 ] && [ -n "$EXTRAS" ]; then
|
||||
if [ "$OS2" = 1 ]; then
|
||||
os2_gspa M4
|
||||
if [ -f "$SDK/M4EXT.ASM" ]; then
|
||||
os2_gspa M4EXT
|
||||
fi
|
||||
# tms-link is a host tool and runs below; the asm/GSPLNK path links here.
|
||||
if [ "$NATIVE" != 1 ] || [ "$LINKER" != tms-link ]; then
|
||||
os2_gsplnk
|
||||
fi
|
||||
elif [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
||||
# tms-link is a host tool: GSPA still assembles the entry/extras objects,
|
||||
# but GSPLNK is not run.
|
||||
if [ -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 "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 "exit" -exit \
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
fi
|
||||
elif [ "$NATIVE" = 1 ] && [ -n "$EXTRAS" ]; then
|
||||
run_dosbox \
|
||||
-c "mount c $SDK" -c "c:" \
|
||||
-c "gspa M4 M4.obj M4.lst -l" \
|
||||
@@ -294,6 +378,23 @@ else
|
||||
|| { tail -20 "$WORK/dosbox.log" >&2; fail "DOSBox failed"; }
|
||||
fi
|
||||
|
||||
if [ "$NATIVE" = 1 ] && [ "$LINKER" = tms-link ]; then
|
||||
TMSLINK_INPUTS=
|
||||
for obj in $NATIVE_OBJS; do
|
||||
TMSLINK_INPUTS="$TMSLINK_INPUTS $SDK/$obj"
|
||||
done
|
||||
echo "== link with tools/tms-link"
|
||||
# shellcheck disable=SC2086
|
||||
"$TMS_LINK" -o "$SDK/M4.OUT" --map "$SDK/M4.MAP" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 \
|
||||
--prog-len "$NATIVE_PROG_LEN" --ram-len "$NATIVE_RAM_LEN" \
|
||||
$TMSLINK_INPUTS $NATIVE_LIB_PATHS \
|
||||
|| fail "tms-link failed"
|
||||
# Keep the pre-coff-check image so parity gates can compare tms-link's
|
||||
# raw output; the repaired $COFF below remains the loader image.
|
||||
cp "$SDK/M4.OUT" "$WORK/M4.RAW.OUT"
|
||||
fi
|
||||
|
||||
check_lst() {
|
||||
lst=$1
|
||||
[ -f "$SDK/$lst.LST" ] \
|
||||
@@ -309,16 +410,35 @@ check_lst() {
|
||||
|
||||
check_lst M4
|
||||
[ -z "$EXTRAS" ] || [ "$NATIVE" != 1 ] || check_lst M4EXT
|
||||
[ -f "$SDK/M4.OUT" ] || fail "GSPLNK produced no M4.OUT"
|
||||
[ -f "$SDK/M4.OUT" ] || fail "$LINKER 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=$(awk '$2 == "_start" { print $1; exit }' "$WORK/m4.map" | tr 'a-f' 'A-F')
|
||||
[ "$ENTRY_ADDR" = "018A0000" ] || fail "linker entry _start is '$ENTRY_ADDR', want 018A0000"
|
||||
grep -q 'ENTRY POINT SYMBOL: "_start"' "$WORK/m4.map" \
|
||||
|| fail "linker map has no _start entry point"
|
||||
|
||||
# GSPLNK 2.00 can zero the 48-byte file+optional header (observed on links
|
||||
# whose test object contributed no initialized .data), and can emit an odd
|
||||
# .bss size.
|
||||
# Validate every linked COFF and repair only those two known shapes; any other
|
||||
# malformed image is a hard link failure.
|
||||
command -v python3 >/dev/null 2>&1 || fail "python3 is required for COFF validation"
|
||||
if [ "$COFF_REPAIR" = 1 ]; then
|
||||
coff_out=$(python3 "$ROOT/scripts/m4/coff-check.py" --repair \
|
||||
--entry "$ENTRY_ADDR" "$COFF" 2>&1) \
|
||||
|| { printf '%s\n' "$coff_out" | sed 's/^/ /' >&2; \
|
||||
fail "COFF validation/repair failed for $COFF"; }
|
||||
else
|
||||
coff_out=$(python3 "$ROOT/scripts/m4/coff-check.py" --entry "$ENTRY_ADDR" \
|
||||
"$COFF" 2>&1) \
|
||||
|| { printf '%s\n' "$coff_out" | sed 's/^/ /' >&2; \
|
||||
fail "COFF validation failed for $COFF"; }
|
||||
fi
|
||||
printf '%s\n' "$coff_out" | sed 's/^/ /'
|
||||
echo " linked .text at 018A0000, M4.OUT -> $COFF"
|
||||
|
||||
if [ -n "${M4_SKIP_MAME:-}" ]; then
|
||||
@@ -351,15 +471,19 @@ timeout "${MAME_TIMEOUT:-900}" "$MAME" vt1200 \
|
||||
> "$WORK/mame.log" 2>&1 \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "MAME run failed"; }
|
||||
|
||||
MARKERS=$(grep -E '^M4: ' "$WORK/mame.log" | tail -1 || true)
|
||||
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; fail "MAME produced no M4 markers"; }
|
||||
MARKERS=$(grep -E '^(M4|M7|M8 LIB): ' "$WORK/mame.log" | tail -1 || true)
|
||||
[ -n "$MARKERS" ] || { tail -30 "$WORK/mame.log" >&2; fail "MAME produced no M4/M7/M8 LIB markers"; }
|
||||
echo " $MARKERS"
|
||||
|
||||
grep -q 'LOADER: result status=0 (OK)' "$WORK/mame.log" \
|
||||
|| { grep 'LOADER: result' "$WORK/mame.log" >&2 || true; fail "COFF loader did not report status 0"; }
|
||||
grep -q 'placed \.text .* 0 differing' "$WORK/mame.log" \
|
||||
|| fail "COFF loader could not verify the placed .text bytes"
|
||||
grep -q '^M4 MAME: PASS' "$WORK/mame.log" \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "M4 marker check failed"; }
|
||||
grep -qE '^M[47] MAME: PASS|^M8 LIB MAME: PASS' "$WORK/mame.log" \
|
||||
|| { tail -30 "$WORK/mame.log" >&2; fail "marker check failed"; }
|
||||
|
||||
echo "M4 MAME: PASS"
|
||||
case "$MARKERS" in
|
||||
M7:*) echo "M7 MAME: PASS" ;;
|
||||
M8\ LIB:*) echo "M8 LIB MAME: PASS" ;;
|
||||
*) echo "M4 MAME: PASS" ;;
|
||||
esac
|
||||
+107
-1
@@ -39,6 +39,16 @@ ROM_HI=$((0x3FFFFFFF))
|
||||
MAPWINDOW=$((0x3FD64F60))
|
||||
RAISEWINDOW=$((0x3FD645B0))
|
||||
|
||||
# M7.3 wider surface: the six GUI_APPS table entries, pinned as addresses as
|
||||
# well as by opcode/helper. A table edit to a different builder with the same
|
||||
# opcode still fails here.
|
||||
WIDER_MAPSUBWINDOWS=$((0x3FD64BF0))
|
||||
WIDER_CHANGEWATTRS=$((0x3FD38770))
|
||||
WIDER_CONFIGUREWINDOW=$((0x3FD3A510))
|
||||
WIDER_INTERNATOM=$((0x3FD5E420))
|
||||
WIDER_CHANGEPROPERTY=$((0x3FD37330))
|
||||
WIDER_CHANGEGC=$((0x3F999F80))
|
||||
|
||||
fail() {
|
||||
echo "m4 validate-syms: FAIL: $*" >&2
|
||||
exit 1
|
||||
@@ -79,6 +89,10 @@ require_match() { # require_match DIS_TEXT ERE WHAT
|
||||
}
|
||||
}
|
||||
|
||||
require_addr() { # require_addr NAME ADDR WANT WHAT
|
||||
[ "$(($2))" -eq "$3" ] || fail "$1 is $2, expected $(printf '0x%08X' "$3") ($4)"
|
||||
}
|
||||
|
||||
check_prologue() { # check_prologue NAME ADDR
|
||||
_name=$1
|
||||
_addr=$2
|
||||
@@ -229,6 +243,97 @@ check_xcreateimage() {
|
||||
echo " ok XCreateImage allocates an 88-byte XImage"
|
||||
}
|
||||
|
||||
# The M7.3 wider surface: six public entries from the GUI_APPS table. Each
|
||||
# body is the ROM request builder named by that table, so pin the request
|
||||
# opcode (and the helper each builder calls) rather than trusting the name.
|
||||
# XMapSubwindows opcode 9
|
||||
# XChangeWindowAttributes opcode 2, values walker 0x3FDA A550
|
||||
# XConfigureWindow opcode 12, fixed CWX|CWY|CWWidth|CWHeight mask 15
|
||||
# XInternAtom opcode 16, strlen on the name
|
||||
# XChangeProperty opcode 18, blit_copy for the value bytes
|
||||
# XChangeGC opcode 56 (0x38), GC cache serializer 0x3F997AD0
|
||||
check_wider_xlib() {
|
||||
_addr=$(sym_addr XMapSubwindows)
|
||||
[ -n "$_addr" ] || fail "table has no XMapSubwindows entry"
|
||||
require_addr XMapSubwindows "$_addr" "$WIDER_MAPSUBWINDOWS" "GUI_APPS"
|
||||
dis_at "$((_addr))" 384 "$TMP/mapsubwindows"
|
||||
require_match "$TMP/mapsubwindows" 'movk[[:space:]]+9,[[:space:]]+a[0-9]+' \
|
||||
"XMapSubwindows does not build MapSubwindows request opcode 9"
|
||||
require_match "$TMP/mapsubwindows" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XMapSubwindows does not write its request opcode to the buffer"
|
||||
echo " ok XMapSubwindows builds MapSubwindows opcode 9"
|
||||
|
||||
_addr=$(sym_addr XChangeWindowAttributes)
|
||||
[ -n "$_addr" ] || fail "table has no XChangeWindowAttributes entry"
|
||||
require_addr XChangeWindowAttributes "$_addr" "$WIDER_CHANGEWATTRS" "GUI_APPS"
|
||||
dis_at "$((_addr))" 448 "$TMP/changewattrs"
|
||||
require_match "$TMP/changewattrs" 'movk[[:space:]]+2,[[:space:]]+a[0-9]+' \
|
||||
"XChangeWindowAttributes does not build ChangeWindowAttributes request opcode 2"
|
||||
require_match "$TMP/changewattrs" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XChangeWindowAttributes does not write its request opcode to the buffer"
|
||||
require_match "$TMP/changewattrs" 'calla[[:space:]]+0x3fdaa550' \
|
||||
"XChangeWindowAttributes does not call the XSetWindowAttributes value walker"
|
||||
echo " ok XChangeWindowAttributes builds opcode 2 + value walker"
|
||||
|
||||
_addr=$(sym_addr XConfigureWindow)
|
||||
[ -n "$_addr" ] || fail "table has no XConfigureWindow entry"
|
||||
require_addr XConfigureWindow "$_addr" "$WIDER_CONFIGUREWINDOW" "GUI_APPS"
|
||||
dis_at "$((_addr))" 448 "$TMP/configurewindow"
|
||||
require_match "$TMP/configurewindow" 'movk[[:space:]]+12,[[:space:]]+a[0-9]+' \
|
||||
"XConfigureWindow does not build ConfigureWindow request opcode 12"
|
||||
require_match "$TMP/configurewindow" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XConfigureWindow does not write its request opcode to the buffer"
|
||||
require_match "$TMP/configurewindow" 'movk[[:space:]]+15,[[:space:]]+a[0-9]+' \
|
||||
"XConfigureWindow does not arm the fixed CWX|CWY|CWWidth|CWHeight mask 15"
|
||||
require_match "$TMP/configurewindow" '\*a13\(0xffa0\)' \
|
||||
"XConfigureWindow does not read the x argument (a13-12)"
|
||||
require_match "$TMP/configurewindow" '\*a13\(0xff80\)' \
|
||||
"XConfigureWindow does not read the y argument (a13-16)"
|
||||
require_match "$TMP/configurewindow" '\*a13\(0xff60\)' \
|
||||
"XConfigureWindow does not read the width argument (a13-20)"
|
||||
require_match "$TMP/configurewindow" '\*a13\(0xff40\)' \
|
||||
"XConfigureWindow does not read the height argument (a13-24)"
|
||||
echo " ok XConfigureWindow builds opcode 12, fixed mask 15, x/y/width/height"
|
||||
|
||||
_addr=$(sym_addr XInternAtom)
|
||||
[ -n "$_addr" ] || fail "table has no XInternAtom entry"
|
||||
require_addr XInternAtom "$_addr" "$WIDER_INTERNATOM" "GUI_APPS"
|
||||
dis_at "$((_addr))" 512 "$TMP/internatom"
|
||||
require_match "$TMP/internatom" 'movk[[:space:]]+16,[[:space:]]+a[0-9]+' \
|
||||
"XInternAtom does not build InternAtom request opcode 16"
|
||||
require_match "$TMP/internatom" 'calla[[:space:]]+0x3fb458d0' \
|
||||
"XInternAtom does not strlen the atom name"
|
||||
require_match "$TMP/internatom" '\*a13\(0xffa0\)' \
|
||||
"XInternAtom does not read the only_if_exists argument (a13-12)"
|
||||
echo " ok XInternAtom builds opcode 16, strlens the name"
|
||||
|
||||
_addr=$(sym_addr XChangeProperty)
|
||||
[ -n "$_addr" ] || fail "table has no XChangeProperty entry"
|
||||
require_addr XChangeProperty "$_addr" "$WIDER_CHANGEPROPERTY" "GUI_APPS"
|
||||
dis_at "$((_addr))" 512 "$TMP/changeproperty"
|
||||
require_match "$TMP/changeproperty" 'movk[[:space:]]+18,[[:space:]]+a[0-9]+' \
|
||||
"XChangeProperty does not build ChangeProperty request opcode 18"
|
||||
require_match "$TMP/changeproperty" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XChangeProperty does not write its request opcode to the buffer"
|
||||
require_match "$TMP/changeproperty" 'calla[[:space:]]+0x3fb44400' \
|
||||
"XChangeProperty does not copy its value bytes through blit_copy"
|
||||
require_match "$TMP/changeproperty" '\*a13\(0xff00\)' \
|
||||
"XChangeProperty does not read the nelements argument (a13-32)"
|
||||
echo " ok XChangeProperty builds opcode 18, blit_copy value bytes"
|
||||
|
||||
_addr=$(sym_addr XChangeGC)
|
||||
[ -n "$_addr" ] || fail "table has no XChangeGC entry"
|
||||
require_addr XChangeGC "$_addr" "$WIDER_CHANGEGC" "GUI_APPS"
|
||||
dis_at "$((_addr))" 512 "$TMP/changegc"
|
||||
require_match "$TMP/changegc" 'movi[[:space:]]+0x38,[[:space:]]+a[0-9]+' \
|
||||
"XChangeGC does not build ChangeGC request opcode 56 (0x38)"
|
||||
require_match "$TMP/changegc" 'movb[[:space:]]+a[0-9]+,[[:space:]]+\*a[0-9]+' \
|
||||
"XChangeGC does not write its request opcode to the buffer"
|
||||
require_match "$TMP/changegc" 'calla[[:space:]]+0x3f997ad0' \
|
||||
"XChangeGC does not call the GC value-cache serializer"
|
||||
echo " ok XChangeGC builds opcode 56, flushes the GC value cache"
|
||||
}
|
||||
|
||||
# The error-handler setters write the per-process XG block: IO at +0x40,
|
||||
# protocol error at +0x60. The defaults are the ROM's _XDefaultIOError and
|
||||
# _XDefaultError.
|
||||
@@ -273,6 +378,7 @@ check_image_requests
|
||||
check_font_copy
|
||||
check_pixmap_focus
|
||||
check_xcreateimage
|
||||
check_wider_xlib
|
||||
check_error_handlers
|
||||
|
||||
echo "m4 validate-syms: PASS ($count v2.2 entries in ROM, aligned, prologues valid; XMapWindow/XRaiseWindow pinned)"
|
||||
echo "m4 validate-syms: PASS ($count v2.2 entries in ROM, aligned, prologues valid; XMapWindow/XRaiseWindow pinned; M7.3 wider Xlib opcodes pinned)"
|
||||
+141
-3
@@ -230,6 +230,107 @@ typedef union _XEvent {
|
||||
#define XYPixmap 1
|
||||
#define ZPixmap 2
|
||||
|
||||
/*
|
||||
* M7.3 wider Xlib surface. The VT1200 ROM is X11R4: these are the X11R4
|
||||
* value-mask bits and struct layouts (32-bit fields, packed by the TMS34010
|
||||
* C ABI). The ROM's own request builders use the same ordering: the
|
||||
* ConfigureWindow entry arms CWX|CWY|CWWidth|CWHeight (mask 15), and the
|
||||
* window-attributes walker reads background_pixel from byte 4.
|
||||
*/
|
||||
typedef struct {
|
||||
int x, y;
|
||||
int width, height;
|
||||
int border_width;
|
||||
Window sibling;
|
||||
int stack_mode;
|
||||
} XWindowChanges;
|
||||
|
||||
#define CWBackPixmap (1L << 0)
|
||||
#define CWBackPixel (1L << 1)
|
||||
#define CWBorderPixmap (1L << 2)
|
||||
#define CWBorderPixel (1L << 3)
|
||||
#define CWBitGravity (1L << 4)
|
||||
#define CWWinGravity (1L << 5)
|
||||
#define CWBackingStore (1L << 6)
|
||||
#define CWBackingPlanes (1L << 7)
|
||||
#define CWBackingPixel (1L << 8)
|
||||
#define CWOverrideRedirect (1L << 9)
|
||||
#define CWSaveUnder (1L << 10)
|
||||
#define CWEventMask (1L << 11)
|
||||
#define CWDontPropagate (1L << 12)
|
||||
#define CWColormap (1L << 13)
|
||||
#define CWCursor (1L << 14)
|
||||
|
||||
#define CWX (1L << 0)
|
||||
#define CWY (1L << 1)
|
||||
#define CWWidth (1L << 2)
|
||||
#define CWHeight (1L << 3)
|
||||
#define CWBorderWidth (1L << 4)
|
||||
#define CWSibling (1L << 5)
|
||||
#define CWStackMode (1L << 6)
|
||||
|
||||
/* X11R4 XSetWindowAttributes: background_pixel is byte 4 (CWBackPixel). */
|
||||
typedef struct {
|
||||
unsigned long background_pixmap;
|
||||
unsigned long background_pixel;
|
||||
unsigned long border_pixmap;
|
||||
unsigned long border_pixel;
|
||||
int bit_gravity;
|
||||
int win_gravity;
|
||||
int backing_store;
|
||||
unsigned long backing_planes;
|
||||
unsigned long backing_pixel;
|
||||
Bool save_under;
|
||||
long event_mask;
|
||||
long do_not_propagate_mask;
|
||||
Bool override_redirect;
|
||||
Colormap colormap;
|
||||
Cursor cursor;
|
||||
} XSetWindowAttributes;
|
||||
|
||||
/* X11R4 XGCValues: the ROM value walker reads GCFont's field at byte 60. */
|
||||
typedef struct {
|
||||
int function;
|
||||
unsigned long plane_mask;
|
||||
unsigned long foreground;
|
||||
unsigned long background;
|
||||
int line_width;
|
||||
int line_style;
|
||||
int cap_style;
|
||||
int join_style;
|
||||
int fill_style;
|
||||
int fill_rule;
|
||||
int arc_mode;
|
||||
Pixmap tile;
|
||||
Pixmap stipple;
|
||||
int ts_x_origin;
|
||||
int ts_y_origin;
|
||||
Font font;
|
||||
int subwindow_mode;
|
||||
int graphics_exposures;
|
||||
int clip_x_origin;
|
||||
int clip_y_origin;
|
||||
Pixmap clip_mask;
|
||||
int dash_offset;
|
||||
char dashes;
|
||||
} XGCValues;
|
||||
|
||||
#define GCFunction (1L << 0)
|
||||
#define GCPlaneMask (1L << 1)
|
||||
#define GCForeground (1L << 2)
|
||||
#define GCBackground (1L << 3)
|
||||
#define GCLineWidth (1L << 4)
|
||||
#define GCLineStyle (1L << 5)
|
||||
#define GCCapStyle (1L << 6)
|
||||
#define GCJoinStyle (1L << 7)
|
||||
#define GCFillStyle (1L << 8)
|
||||
#define GCFillRule (1L << 9)
|
||||
#define GCTile (1L << 10)
|
||||
#define GCStipple (1L << 11)
|
||||
#define GCTileStipXOrigin (1L << 12)
|
||||
#define GCTileStipYOrigin (1L << 13)
|
||||
#define GCFont (1L << 14)
|
||||
|
||||
#define True 1
|
||||
#define False 0
|
||||
#define None 0L
|
||||
@@ -241,9 +342,10 @@ typedef int (*XIOErrorHandler)(Display *);
|
||||
* Real Xlib entry points. The VT1200 ROM exports these names; Task 5
|
||||
* validates their bit addresses in symbols/vt1200-v22.syms.
|
||||
*
|
||||
* XCreateGC's XGCValues* and XLookupString's XComposeStatus* are modelled as
|
||||
* void*: the layout is not needed by the M4 clients and the 32-bit pointer
|
||||
* ABI is unchanged.
|
||||
* XCreateGC's values argument stays void* (the 32-bit pointer ABI is
|
||||
* unchanged); the X11R4 XGCValues layout is declared above for the M7.3
|
||||
* wider-surface client and its offset checks. XLookupString's
|
||||
* XComposeStatus* is modelled as void*.
|
||||
*/
|
||||
extern Display *XOpenDisplay(const char *name);
|
||||
extern Window XCreateSimpleWindow(Display *display, Window parent, int x, int y,
|
||||
@@ -252,6 +354,38 @@ extern Window XCreateSimpleWindow(Display *display, Window parent, int x, int y,
|
||||
unsigned long border,
|
||||
unsigned long background);
|
||||
extern int XMapWindow(Display *display, Window window);
|
||||
/*
|
||||
* M7.3 wider surface, validated in symbols/vt1200-v22.syms.
|
||||
*
|
||||
* XMapSubwindows maps every child of `window` (MapSubwindows opcode 9).
|
||||
*/
|
||||
extern int XMapSubwindows(Display *display, Window window);
|
||||
/*
|
||||
* The ROM's ConfigureWindow entry (0x3FD3A510) is the fixed-mask builder:
|
||||
* opcode 12, value-mask CWX|CWY|CWWidth|CWHeight, and four scalar arguments.
|
||||
* That is Xlib's XMoveResizeWindow call shape, not the XWindowChanges-pointer
|
||||
* shape; XWindowChanges above documents the same four values.
|
||||
*/
|
||||
extern int XConfigureWindow(Display *display, Window window, int x, int y,
|
||||
unsigned int width, unsigned int height);
|
||||
/* ChangeWindowAttributes opcode 2 (XSetWindowAttributes value walker). */
|
||||
extern int XChangeWindowAttributes(Display *display, Window window,
|
||||
unsigned long valuemask,
|
||||
XSetWindowAttributes *attributes);
|
||||
/* InternAtom opcode 16; only_if_exists False creates the atom. */
|
||||
extern Atom XInternAtom(Display *display, const char *name,
|
||||
Bool only_if_exists);
|
||||
/* ChangeProperty opcode 18; format 8, mode PropModeReplace = 0. */
|
||||
extern int XChangeProperty(Display *display, Window window, Atom property,
|
||||
Atom type, int format, int mode,
|
||||
const unsigned char *data, int nelements);
|
||||
/*
|
||||
* ChangeGC opcode 56. The ROM entry's public shape is (display, gc): it
|
||||
* serializes the GC's pending value cache (the same serializer the drawing
|
||||
* primitives call). Values are selected by the cache setters, e.g.
|
||||
* XSetForeground, or by XCreateGC's XGCValues.
|
||||
*/
|
||||
extern int XChangeGC(Display *display, GC gc);
|
||||
/* CreatePixmap opcode 0x35; depth 1 for the image client's 1-bit pixmap. */
|
||||
extern Pixmap XCreatePixmap(Display *display, Drawable drawable,
|
||||
unsigned int width, unsigned int height,
|
||||
@@ -298,6 +432,10 @@ extern XImage *XCreateImage(Display *display, Visual *visual,
|
||||
extern int XPutImage(Display *display, Drawable drawable, GC gc, XImage *image,
|
||||
int src_x, int src_y, int dest_x, int dest_y,
|
||||
unsigned int width, unsigned int height);
|
||||
/* GetImage opcode 0x49: synchronous reply; format is XYPixmap or ZPixmap. */
|
||||
extern XImage *XGetImage(Display *display, Drawable drawable, int x, int y,
|
||||
unsigned int width, unsigned int height,
|
||||
unsigned long plane_mask, int format);
|
||||
extern int XDestroyImage(XImage *image);
|
||||
extern XErrorHandler XSetErrorHandler(XErrorHandler handler);
|
||||
extern XIOErrorHandler XSetIOErrorHandler(XIOErrorHandler handler);
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
# 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_NATIVE_LINKER=tms-link runs the same native builds through tools/tms-link
|
||||
# (the termtris run also exercises the rts.lib archive path); the default is
|
||||
# GSPLNK, which remains the oracle.
|
||||
#
|
||||
# Overridable: TMS_CLANG TMS_OPT TMS_BITADDR TMS_LLC LLVM_BIN M5_NATIVE_LINKER
|
||||
# M5_XSHOW_WORK TERMTRIS_WORK TERMTRIS_SDK VT1200_TERMTRIS
|
||||
# M4_SDK DOSBOX DOSBOX_CONF SDK_IMG MAME LOADER_AT LOADER_END
|
||||
set -eu
|
||||
@@ -23,6 +27,7 @@ MODE=${1:-termtris}
|
||||
DIR=$ROOT/scripts/m4
|
||||
TERMTRIS_DIR=$DIR/termtris
|
||||
VENDOR=${VT1200_TERMTRIS:-$ROOT/vendor/vt1200-termtris}
|
||||
LINKER=${M5_NATIVE_LINKER:-gsplnk}
|
||||
|
||||
fail() {
|
||||
echo "M5 native driver: $*" >&2
|
||||
@@ -33,6 +38,7 @@ case $MODE in
|
||||
xshow)
|
||||
WORK=${M5_XSHOW_WORK:-$ROOT/build/m5-native-xshow}
|
||||
M4_NATIVE=1 \
|
||||
M4_LINKER="$LINKER" \
|
||||
M4_SOURCES="xshow xgfix" \
|
||||
M4_ENTRY="$DIR/xshow-entry.asm" \
|
||||
M4_CHECK_LUA="$DIR/xshow-check.lua" \
|
||||
@@ -61,6 +67,7 @@ termtris)
|
||||
# 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_LINKER="$LINKER" \
|
||||
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" \
|
||||
|
||||
@@ -24,6 +24,16 @@
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
|
||||
; Clear the shim's stream lengths. This entry does not otherwise touch
|
||||
; the result block, and the shim's shadows cannot repair a cell it never
|
||||
; writes (an empty stream), so clear both cells here.
|
||||
movi 01B00020h, a1
|
||||
sub a0, a0
|
||||
move a0, *a1, 1
|
||||
movi 01B00060h, a1
|
||||
move a0, *a1, 1
|
||||
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _runtime_run
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
; cinit-entry.asm -- M7.2 `.cinit` gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; The `.cinit` loop is byte-for-byte the termtris `_start` loop from
|
||||
; vendor/vt1200-termtris/apps/termtris/src/vt1200/entry.asm:
|
||||
;
|
||||
; movi cinit,a9
|
||||
; move *a9+,count ; u16 data-word count
|
||||
; jrz done
|
||||
; move *a9+,dest,1 ; u32 destination (a TMS34010 bit address)
|
||||
; move *a9+,*dest+ ; copy `count` words
|
||||
;
|
||||
; The public `cinit` symbol is defined at offset 0 of this object's empty
|
||||
; `.cinit` section (the termtris cinit.asm shape), so the linker places it at
|
||||
; the `.cinit` origin and the C table (concatenated after this zero-size input
|
||||
; section) is the record the loop reads. GSPA emits this object's sections in
|
||||
; the order .text/.data/.bss/.cinit; tms-link accepts that GSPA order as well
|
||||
; as the llc .text/.data/.cinit/.bss order.
|
||||
;
|
||||
; After the copy loop the entry calls cinit_probe(), which returns the sum of
|
||||
; the three copied words; that value is the 018A8000 marker.
|
||||
.ref _cinit_probe
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 32,0,1
|
||||
movi _cstack,a14
|
||||
move a14,a13
|
||||
|
||||
movi cinit,a9
|
||||
ci_loop:
|
||||
setf 16,0,0
|
||||
move *a9+,a11
|
||||
jrz ci_done
|
||||
move *a9+,a10,1
|
||||
ci_copy:
|
||||
move *a9+,*a10+
|
||||
dsjs a11,ci_copy
|
||||
jruc ci_loop
|
||||
ci_done:
|
||||
setf 32,0,1
|
||||
move a13,a14
|
||||
calla _cinit_probe
|
||||
move a8,@018A8000h,1
|
||||
rets
|
||||
|
||||
.sect ".cinit"
|
||||
.globl cinit
|
||||
cinit:
|
||||
|
||||
.bss _cstack,32768,16
|
||||
.end
|
||||
@@ -0,0 +1,51 @@
|
||||
/* M7.2 `.cinit` gate table: the TI init-record format in C.
|
||||
*
|
||||
* The TI format is a sequence of records:
|
||||
*
|
||||
* packed struct {
|
||||
* unsigned short count; // data word count
|
||||
* unsigned long destination; // TMS34010 *bit* address
|
||||
* unsigned short data[count];
|
||||
* };
|
||||
*
|
||||
* terminated by a zero count. `cinit-entry.asm` defines the public `cinit`
|
||||
* symbol at the start of its own empty `.cinit` section (the termtris
|
||||
* `cinit.asm` shape) and walks this table exactly like the termtris `_start`:
|
||||
* `movi cinit,a9; move *a9+,count; move *a9+,dst,1; copy count words`.
|
||||
*
|
||||
* The destination is a pointer-typed union member rather than a plain
|
||||
* `unsigned long` initialised with `(unsigned long)&cinit_target`. Both are
|
||||
* the same packed 32-bit field at byte offset 2, but the object writer emits a
|
||||
* relocation only for a pointer constant; casting the address to an integer
|
||||
* produces an LLVM `ptrtoint` constant expression that the `.data`/.cinit
|
||||
* emitter deliberately rejects as unsupported. The pointer value *is* the
|
||||
* TMS34010 bit address in this ABI, so the linked field is the resolved bit
|
||||
* address the entry loop needs. The record header is packed, so the 32-bit
|
||||
* destination sits at bit offset 16 and the linker resolves it as an ordinary
|
||||
* R-RELLONG field (the CPU copy loop is bit-addressed).
|
||||
*/
|
||||
|
||||
unsigned short cinit_target[4];
|
||||
|
||||
struct __attribute__((packed)) cinit_record {
|
||||
unsigned short count;
|
||||
union {
|
||||
unsigned long destination;
|
||||
unsigned short *address;
|
||||
} target;
|
||||
unsigned short data[3];
|
||||
unsigned short end;
|
||||
};
|
||||
|
||||
/* The table lives in `.cinit`; the entry object contributes the `cinit`
|
||||
* symbol at offset 0 of the concatenated section. */
|
||||
__attribute__((section(".cinit")))
|
||||
const struct cinit_record cinit_table = {
|
||||
3, { .address = cinit_target }, { 0x1111, 0x2222, 0x3333 }, 0
|
||||
};
|
||||
|
||||
/* Called by the entry after the copy loop; returns the sum of the copied
|
||||
* words (0x1111 + 0x2222 + 0x3333 = 0x6666). */
|
||||
int cinit_probe(void) {
|
||||
return cinit_target[0] + cinit_target[1] + cinit_target[2];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
; debug-entry.asm -- M7.2 debug-info gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; debug.c is linked first so debug_mul is the text-origin function and its
|
||||
; DWARF low PC is the expected 0x314000 (text origin 018A0000 / 8). This
|
||||
; entry calls debug_mul(), debug_add() and debug_ptr() and stores their
|
||||
; results, 43, 14 and 30, at 018A8000, 018A8020 and 018A8040.
|
||||
;
|
||||
; debug_ptr() takes no argument: it uses the .data debug_index (2) for the
|
||||
; pointer update, so the entry needs no argument-pushing sequence.
|
||||
.ref _debug_mul
|
||||
.ref _debug_add
|
||||
.ref _debug_ptr
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16,1,0
|
||||
setf 32,0,1
|
||||
movi _cstack,a14
|
||||
move a14,a13
|
||||
calla _debug_mul
|
||||
move a8,@018A8000h,1
|
||||
calla _debug_add
|
||||
move a8,@018A8020h,1
|
||||
calla _debug_ptr
|
||||
move a8,@018A8040h,1
|
||||
rets
|
||||
|
||||
.bss _cstack,32768,16
|
||||
.end
|
||||
@@ -0,0 +1,37 @@
|
||||
int debug_mul(void) {
|
||||
int product = 42;
|
||||
return product + 1;
|
||||
}
|
||||
|
||||
int debug_add(void) {
|
||||
int sum = 7;
|
||||
return sum + 7;
|
||||
}
|
||||
|
||||
int debug_array[4] = {10, 20, 30, 40};
|
||||
int debug_index = 2;
|
||||
|
||||
int debug_ptr(void) {
|
||||
int *p = debug_array;
|
||||
p += debug_index;
|
||||
return *p;
|
||||
}
|
||||
|
||||
/* M7.2 debug-info gate driver.
|
||||
*
|
||||
* Three functions, so the linked `.debug_info` has three subprograms and the
|
||||
* second/third `.text` offsets are nonzero. debug_mul returns 43,
|
||||
* debug_add returns 14 and debug_ptr returns debug_array[2] = 30; the entry
|
||||
* stores them at 018A8000/018A8020/018A8040 after the stripped link is loaded
|
||||
* in MAME.
|
||||
*
|
||||
* debug_ptr is the bit-pointer barrier coverage: `p += debug_index` is a
|
||||
* runtime `getelementptr` that --bitptr rewrites, so the -O0 gate proves the
|
||||
* line row survives that rewrite; debug.sh also builds this TU at -O2 -g to
|
||||
* exercise opt/--scale/--lower-bitptr/instcombine.
|
||||
*
|
||||
* The declarations are on lines 1, 6 and 14; the first local-variable /
|
||||
* pointer-update lines are 2, 7, 15 and 16; debug.sh asserts those
|
||||
* `.debug_line` rows and the DW_AT_decl_line values. The comment is
|
||||
* deliberately after the code so the line numbers stay stable.
|
||||
*/
|
||||
Executable
+224
@@ -0,0 +1,224 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Wrap linked TI-COFF `.debug_*` sections in a minimal ELF32 container.
|
||||
|
||||
The TMS34010 native path is TI-COFF end to end; `llvm-dwarfdump` reads ELF,
|
||||
Mach-O and Wasm, not the 1987 TI COFF variant. This test-only helper extracts
|
||||
the non-allocated `.debug_*` sections from a `tms-link --keep-debug` image and
|
||||
writes an ELF32 little-endian relocatable container with section headers and a
|
||||
`.shstrtab` but no program headers or symbol table.
|
||||
|
||||
No addresses or relocations are rewritten: `tms-link` has already resolved the
|
||||
DWARF byte addresses (for example `.debug_addr` holds 0x314000 for text origin
|
||||
0x018A0000), and DWARF section-internal offsets are section-relative.
|
||||
|
||||
Usage:
|
||||
elf-debug-wrap.py -o OUT.elf LINKED.coff [SECTION ...]
|
||||
|
||||
With no SECTION arguments every `.debug_*` section is wrapped. The input is
|
||||
parsed directly (the helper has no project dependencies) so the debug gate can
|
||||
assert the linked TI-COFF and the ELF wrapper independently.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import struct
|
||||
import sys
|
||||
|
||||
MAGIC = 0x0090
|
||||
|
||||
|
||||
class WrapError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _u16(data, off):
|
||||
return struct.unpack_from("<H", data, off)[0]
|
||||
|
||||
|
||||
def _u32(data, off):
|
||||
return struct.unpack_from("<I", data, off)[0]
|
||||
|
||||
|
||||
def _string_at(table, offset, what):
|
||||
if offset < 4:
|
||||
raise WrapError("%s string-table offset %d is inside the 4-byte size "
|
||||
"field" % (what, offset))
|
||||
end = table.find(b"\0", offset)
|
||||
if end < 0:
|
||||
raise WrapError("%s string-table entry at %d is not terminated"
|
||||
% (what, offset))
|
||||
return table[offset:end].decode("latin1")
|
||||
|
||||
|
||||
def read_coff(path):
|
||||
with open(path, "rb") as fh:
|
||||
data = fh.read()
|
||||
if len(data) < 20:
|
||||
raise WrapError("%s: shorter than a COFF file header" % path)
|
||||
machine, nscns, _timdat, symptr, nsyms, opthdr, _flags = \
|
||||
struct.unpack_from("<HHIIIHH", data, 0)
|
||||
if machine != MAGIC:
|
||||
raise WrapError("%s: machine %#06x, expected %#06x"
|
||||
% (path, machine, MAGIC))
|
||||
if nscns == 0:
|
||||
raise WrapError("%s: no sections" % path)
|
||||
|
||||
string_table = b""
|
||||
if nsyms:
|
||||
string_base = symptr + nsyms * 18
|
||||
if string_base + 4 > len(data):
|
||||
raise WrapError("%s: symbol/string table runs past EOF" % path)
|
||||
size = _u32(data, string_base)
|
||||
if size < 4 or string_base + size > len(data):
|
||||
raise WrapError("%s: implausible string-table size %d"
|
||||
% (path, size))
|
||||
string_table = data[string_base:string_base + size]
|
||||
|
||||
sections = []
|
||||
base = 20 + opthdr
|
||||
for i in range(nscns):
|
||||
off = base + i * 40
|
||||
if off + 40 > len(data):
|
||||
raise WrapError("%s: section header %d past EOF" % (path, i))
|
||||
raw_name = data[off:off + 8]
|
||||
if raw_name.startswith(b"/"):
|
||||
digits = raw_name[1:].split(b"\0", 1)[0]
|
||||
if not digits.isdigit():
|
||||
raise WrapError("%s: bad long section name %r"
|
||||
% (path, raw_name))
|
||||
name = _string_at(string_table, int(digits),
|
||||
"%s: section %d" % (path, i + 1))
|
||||
else:
|
||||
name = raw_name.split(b"\0", 1)[0].decode("latin1")
|
||||
paddr, vaddr, size, scnptr, relptr, _lnnoptr, nreloc, _nlnno, flags = \
|
||||
struct.unpack_from("<IIIIIIHHI", data, off + 8)
|
||||
if size % 8:
|
||||
raise WrapError("%s: section %r size %d bits is not whole bytes"
|
||||
% (path, name, size))
|
||||
blob = b""
|
||||
if size and name != ".bss":
|
||||
if scnptr + size // 8 > len(data):
|
||||
raise WrapError("%s: section %r raw data runs past EOF"
|
||||
% (path, name))
|
||||
blob = data[scnptr:scnptr + size // 8]
|
||||
sections.append(dict(name=name, paddr=paddr, vaddr=vaddr, size=size,
|
||||
flags=flags, nreloc=nreloc, raw=blob))
|
||||
|
||||
by_name = {s["name"]: s for s in sections}
|
||||
if len(by_name) != len(sections):
|
||||
raise WrapError("%s: duplicate section names" % path)
|
||||
return sections
|
||||
|
||||
|
||||
def build_elf(sections):
|
||||
# Only the section-header table and the section payloads exist; the DWARF
|
||||
# data is already absolute, so no symbol table or relocations are needed.
|
||||
shstr = bytearray(b"\0")
|
||||
name_off = {}
|
||||
for sec in sections:
|
||||
name_off[sec["name"]] = len(shstr)
|
||||
shstr.extend(sec["name"].encode("latin1"))
|
||||
shstr.append(0)
|
||||
shstr_name = len(shstr)
|
||||
shstr.extend(b".shstrtab\0")
|
||||
|
||||
shnum = len(sections) + 2 # null section + payload sections + shstrtab
|
||||
shoff = 52
|
||||
cursor = (shoff + shnum * 40 + 3) & ~3
|
||||
payload_off = []
|
||||
for sec in sections:
|
||||
payload_off.append(cursor)
|
||||
cursor += len(sec["raw"])
|
||||
cursor = (cursor + 3) & ~3
|
||||
shstr_off = cursor
|
||||
cursor += len(shstr)
|
||||
total = (cursor + 3) & ~3
|
||||
|
||||
out = bytearray(total)
|
||||
e_ident = b"\x7fELF" + bytes([1, 1, 1, 0]) + bytes(8) # 32-bit LE v1
|
||||
struct.pack_into("<16sHHIIIIIHHHHHH", out, 0, e_ident,
|
||||
1, # e_type ET_REL
|
||||
# EM_386 keeps llvm-dwarfdump from warning about an
|
||||
# unknown machine (there is no standard TMS34010 EM_*).
|
||||
3, # e_machine EM_386
|
||||
1, # e_version
|
||||
0, # e_entry
|
||||
0, # e_phoff (no program headers)
|
||||
shoff, # e_shoff
|
||||
0, # e_flags
|
||||
52, # e_ehsize
|
||||
0, 0, # e_phentsize, e_phnum
|
||||
40, # e_shentsize
|
||||
shnum, # e_shnum
|
||||
shnum - 1) # e_shstrndx
|
||||
|
||||
for i, sec in enumerate(sections, start=1):
|
||||
off = shoff + i * 40
|
||||
struct.pack_into("<IIIIIIIIII", out, off,
|
||||
name_off[sec["name"]],
|
||||
1, # SHT_PROGBITS
|
||||
0, # no sh_flags
|
||||
0, # sh_addr (DWARF is absolute)
|
||||
payload_off[i - 1],
|
||||
len(sec["raw"]),
|
||||
0, 0, # sh_link, sh_info
|
||||
1, # sh_addralign
|
||||
0) # sh_entsize
|
||||
out[payload_off[i - 1]:payload_off[i - 1] + len(sec["raw"])] = \
|
||||
sec["raw"]
|
||||
|
||||
off = shoff + (shnum - 1) * 40
|
||||
struct.pack_into("<IIIIIIIIII", out, off, shstr_name, 3, 0, 0,
|
||||
shstr_off, len(shstr), 0, 0, 1, 0)
|
||||
out[shstr_off:shstr_off + len(shstr)] = shstr
|
||||
return bytes(out)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
p = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
p.add_argument("-o", "--output", required=True, metavar="OUT.elf",
|
||||
help="ELF32 output container")
|
||||
p.add_argument("coff", metavar="LINKED.coff",
|
||||
help="linked TI-COFF with --keep-debug")
|
||||
p.add_argument("sections", nargs="*", metavar="SECTION",
|
||||
help="debug section names to include (default: all "
|
||||
".debug_*)")
|
||||
args = p.parse_args(argv)
|
||||
try:
|
||||
all_sections = read_coff(args.coff)
|
||||
by_name = {s["name"]: s for s in all_sections}
|
||||
if args.sections:
|
||||
missing = [n for n in args.sections if n not in by_name]
|
||||
if missing:
|
||||
raise WrapError("%s: missing section(s): %s"
|
||||
% (args.coff, ", ".join(missing)))
|
||||
chosen = [by_name[n] for n in args.sections]
|
||||
else:
|
||||
chosen = [s for s in all_sections
|
||||
if s["name"].startswith(".debug_")]
|
||||
if not chosen:
|
||||
raise WrapError("%s: no .debug_* sections to wrap" % args.coff)
|
||||
for sec in chosen:
|
||||
if not sec["name"].startswith(".debug_"):
|
||||
raise WrapError("%s: %r is not a .debug_* section"
|
||||
% (args.coff, sec["name"]))
|
||||
if sec["paddr"] != 0 or sec["vaddr"] != 0:
|
||||
raise WrapError("%s: debug section %r has paddr/vaddr "
|
||||
"%#x/%#x, expected 0/0"
|
||||
% (args.coff, sec["name"], sec["paddr"],
|
||||
sec["vaddr"]))
|
||||
elf = build_elf(chosen)
|
||||
with open(args.output, "wb") as fh:
|
||||
fh.write(elf)
|
||||
print("elf-debug-wrap: %s <- %s (%s)"
|
||||
% (args.output, args.coff,
|
||||
" ".join("%s=%dB" % (s["name"], len(s["raw"]))
|
||||
for s in chosen)))
|
||||
return 0
|
||||
except (WrapError, OSError) as exc:
|
||||
print("elf-debug-wrap: error: %s" % exc, file=sys.stderr)
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,111 @@
|
||||
-- hw-check.lua -- M7.3 real-hardware marker gate, MAME-equivalent acceptance.
|
||||
--
|
||||
-- Loads the same COFF that hostload.py sends to the real unit
|
||||
-- (scripts/m7/hwmark.c, linked at .text 018C0000 / .data 018D0000 /
|
||||
-- .bss 018D8000) through vendor/vt1200/dwt/loader/loader.lua, then requires
|
||||
-- exactly what hostload.py's verify_markers() requires:
|
||||
--
|
||||
-- 018E0000 start == the loader result block's entry (018C0000)
|
||||
-- 018E0020 data == 0xDEADBEEF (copied .data)
|
||||
-- 018E0040 data2 == 0x12345678 (copied .data)
|
||||
-- 018E0060 bss == 0 (zeroed .bss; loader pre-fills A5A5)
|
||||
-- 018E0080 count advances (the child is scheduled, not jumped)
|
||||
--
|
||||
-- and that the loader result status is 0. LOADER_AT/LOADER_END come from the
|
||||
-- M4-style environment; the counter is sampled after the child has run, then
|
||||
-- again one frame before the loader exits.
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local RESULT = 0x01882D00
|
||||
|
||||
local CELLS = {
|
||||
{ 0x018E0000, "start" },
|
||||
{ 0x018E0020, "data" },
|
||||
{ 0x018E0040, "data2" },
|
||||
{ 0x018E0060, "bss" },
|
||||
{ 0x018E0080, "count" },
|
||||
}
|
||||
|
||||
-- First sample: a few frames after injection, so the child has started.
|
||||
-- Second sample: the last frame before loader.lua inspects and exits.
|
||||
local SAMPLE0 = math.max(AT + 5, ENDF - 11)
|
||||
local SAMPLE1 = ENDF - 1
|
||||
|
||||
local frames = 0
|
||||
local first_count = nil
|
||||
local checked = false
|
||||
|
||||
local function r32(prog, addr)
|
||||
local ok, v = pcall(function() return prog:read_u32(addr) end)
|
||||
if ok then return v end
|
||||
return nil
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
|
||||
if frames == SAMPLE0 and first_count == nil then
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
first_count = r32(prog, 0x018E0080)
|
||||
end
|
||||
|
||||
if frames == SAMPLE1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local v = {}
|
||||
for _, cell in ipairs(CELLS) do
|
||||
v[cell[2]] = r32(prog, cell[1])
|
||||
end
|
||||
local status = r32(prog, RESULT + 0x000)
|
||||
local entry = r32(prog, RESULT + 0x020)
|
||||
local count0 = first_count or 0
|
||||
local count1 = v.count or 0
|
||||
|
||||
print(string.format(
|
||||
"M7 HW: start=0x%08X data=0x%08X data2=0x%08X bss=0x%08X count=%d->%d status=%d entry=0x%08X",
|
||||
v.start or 0, v.data or 0, v.data2 or 0, v.bss or 0,
|
||||
count0, count1, status or -1, entry or 0))
|
||||
|
||||
local problems = {}
|
||||
if status ~= 0 then
|
||||
problems[#problems + 1] = string.format("loader status=%s, want 0",
|
||||
tostring(status))
|
||||
end
|
||||
if entry ~= 0x018C0000 then
|
||||
problems[#problems + 1] = string.format(
|
||||
"loader entry=0x%08X, want 0x018C0000", entry or 0)
|
||||
end
|
||||
if v.start ~= entry then
|
||||
problems[#problems + 1] = string.format(
|
||||
"start=0x%08X, want the entry 0x%08X", v.start or 0, entry or 0)
|
||||
end
|
||||
if v.data ~= 0xDEADBEEF then
|
||||
problems[#problems + 1] = string.format("data=0x%08X, want 0xDEADBEEF",
|
||||
v.data or 0)
|
||||
end
|
||||
if v.data2 ~= 0x12345678 then
|
||||
problems[#problems + 1] = string.format(
|
||||
"data2=0x%08X, want 0x12345678", v.data2 or 0)
|
||||
end
|
||||
if v.bss ~= 0 then
|
||||
problems[#problems + 1] = string.format("bss=0x%08X, want 0",
|
||||
v.bss or 0)
|
||||
end
|
||||
if count0 <= 0 or count1 <= count0 then
|
||||
problems[#problems + 1] = string.format(
|
||||
"count did not advance (%d -> %d)", count0, count1)
|
||||
end
|
||||
|
||||
if #problems == 0 then
|
||||
print("M7 HW MAME: PASS")
|
||||
else
|
||||
for _, p in ipairs(problems) do
|
||||
print("M7 HW: FAIL: " .. p)
|
||||
end
|
||||
print("M7 HW MAME: FAIL")
|
||||
end
|
||||
end
|
||||
end, "m7-hw-check")
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* hwmark.c -- M7.3 real-hardware marker client, built at the proven VT1200
|
||||
* hardware origins:
|
||||
*
|
||||
* .text 018C0000h
|
||||
* .data 018D0000h
|
||||
* .bss 018D8000h
|
||||
*
|
||||
* This is the COFF image that dwt/loader/hostload.py pokes and that
|
||||
* dwt/loader/loader.asm places through create_process. The marker cells are
|
||||
* the ones hostload.py's MARKER_CELLS names (all TMS34010 *bit* addresses):
|
||||
*
|
||||
* 018E0000 _start address at run time (must equal the loader entry)
|
||||
* 018E0020 d_magic read from .data (must be DEADBEEF)
|
||||
* 018E0040 d_two read from .data (must be 12345678)
|
||||
* 018E0060 b_zero read from .bss (must be 0)
|
||||
* 018E0080 b_counter, a live counter (must advance)
|
||||
*
|
||||
* The M7.3 brief prefers a C-only entry when the compiler can express it, so
|
||||
* `start` is an ordinary C function and the COFF entry point is `_start`.
|
||||
* create_process() supplies the process stack (the firmware allocates it; the
|
||||
* xhello trace records a valid entry A14). The MAME run proves the generated
|
||||
* prologue did not fault and the markers/counter are correct, not that A14/SP
|
||||
* point at the create_process stack; the real-unit run (VT1200_HOST) is the
|
||||
* hardware confirmation. The `.data` pointer
|
||||
* initializer below is supported as an ordinary pointer relocation, so no
|
||||
* `ptrtoint` constant initializer and no assembly entry are needed.
|
||||
*
|
||||
* The loader zeroes .bss after the harness has pre-filled it with A5A5, so a
|
||||
* zero at 018E0060 is the loader's work, not fresh RAM. The delay loop is
|
||||
* marker.asm's 2000h `dsjs` delay: the child stays scheduled but does not burn
|
||||
* the cooperative scheduler with an unbroken hot loop.
|
||||
*/
|
||||
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018E0000u + (n) * 0x20u))
|
||||
|
||||
/* Initialised .data: the loader must copy these bytes from the COFF. */
|
||||
unsigned int d_magic = 0xDEADBEEFu;
|
||||
unsigned int d_two = 0x12345678u;
|
||||
|
||||
/* Uninitialised .bss: the loader must zero these. */
|
||||
unsigned int b_zero;
|
||||
unsigned int b_counter;
|
||||
|
||||
void start(void);
|
||||
|
||||
/*
|
||||
* The entry address as a relocated pointer, not a ptrtoint constant. The
|
||||
* loader's result block reports the same `_start` bit address as the COFF
|
||||
* entry point, so the runtime start cell proves placement, not a guess.
|
||||
*/
|
||||
void (*const start_address)(void) = start;
|
||||
|
||||
/* A volatile .bss sink keeps the delay loop from being folded away. */
|
||||
static volatile unsigned int delay_sink;
|
||||
|
||||
void start(void) {
|
||||
unsigned int count = 0;
|
||||
|
||||
MARK(0) = (unsigned int)start_address;
|
||||
MARK(1) = d_magic;
|
||||
MARK(2) = d_two;
|
||||
MARK(3) = b_zero;
|
||||
|
||||
for (;;) {
|
||||
unsigned int spin;
|
||||
|
||||
count++;
|
||||
b_counter = count;
|
||||
MARK(4) = count;
|
||||
|
||||
for (spin = 0; spin < 0x2000u; spin++) {
|
||||
delay_sink = spin;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
-a
|
||||
-o M4.OUT
|
||||
-m M4.MAP
|
||||
-e _start
|
||||
M4.obj
|
||||
MEMORY
|
||||
{
|
||||
prog: origin = 018A0000h, length = 40000h
|
||||
ram: origin = 01A00000h, length = 80000h
|
||||
}
|
||||
SECTIONS
|
||||
{
|
||||
.text: {} > prog
|
||||
.data: {} > prog
|
||||
.bss: {} > ram
|
||||
}
|
||||
Executable
+133
@@ -0,0 +1,133 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Assert the M7.4 i64div perf marker cells are outside every linked section.
|
||||
|
||||
Usage:
|
||||
i64div-map-check.py MAP MARKER_HEX [PROG_ORIGIN PROG_LEN RAM_ORIGIN RAM_LEN]
|
||||
|
||||
MAP is a GSPLNK 2.00 map (the SECTION ALLOCATION MAP has origin/length in
|
||||
bits) or a tms-link map (the symbol addresses give .text/etext,
|
||||
.data/edata, .bss/end). MARKER_HEX is the marker base bit address; the gate
|
||||
uses up to 16 cells 0x20 bits apart. The optional region arguments are also
|
||||
in hex (bits) and bound .text/.data to prog and .bss/the markers to ram.
|
||||
|
||||
Exit status: 0 = every check passed, 1 = overlap/out-of-region, 2 = the map
|
||||
could not be parsed.
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
def parse_sections(lines):
|
||||
"""Return {name: (start, end)} for .text/.data/.bss."""
|
||||
sections = {}
|
||||
# GSPLNK allocation lines: name page origin length [attributes]
|
||||
for line in lines:
|
||||
m = re.match(
|
||||
r"^\s*(\.\w+)\s+\d+\s+([0-9A-Fa-f]+)\s+([0-9A-Fa-f]+)\b",
|
||||
line)
|
||||
if not m:
|
||||
continue
|
||||
origin = int(m.group(2), 16)
|
||||
length = int(m.group(3), 16)
|
||||
sections[m.group(1)] = (origin, origin + length)
|
||||
if sections:
|
||||
return sections
|
||||
|
||||
# tms-link map: "ADDR .text" / "ADDR etext" style symbol addresses.
|
||||
starts, ends = {}, {}
|
||||
for line in lines:
|
||||
m = re.match(
|
||||
r"^\s*([0-9A-Fa-f]+)\s+(\.\w+|etext|edata|end)\s*$", line)
|
||||
if not m:
|
||||
continue
|
||||
addr = int(m.group(1), 16)
|
||||
name = m.group(2)
|
||||
if name in (".text", ".data", ".bss"):
|
||||
starts[name] = addr
|
||||
else:
|
||||
ends[name] = addr
|
||||
for name, endname in ((".text", "etext"), (".data", "edata"),
|
||||
(".bss", "end")):
|
||||
if name in starts and endname in ends:
|
||||
sections[name] = (starts[name], ends[endname])
|
||||
return sections
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) not in (3, 7):
|
||||
print(__doc__, file=sys.stderr)
|
||||
return 2
|
||||
map_path = sys.argv[1]
|
||||
marker = int(sys.argv[2], 16)
|
||||
marker_end = marker + 16 * 0x20
|
||||
regions = None
|
||||
if len(sys.argv) == 7:
|
||||
prog_origin, prog_len, ram_origin, ram_len = (
|
||||
int(v, 16) for v in sys.argv[3:7])
|
||||
regions = (prog_origin, prog_origin + prog_len,
|
||||
ram_origin, ram_origin + ram_len)
|
||||
|
||||
with open(map_path, encoding="ascii", errors="replace") as f:
|
||||
sections = parse_sections(f.read().splitlines())
|
||||
|
||||
missing = [s for s in (".text", ".data", ".bss") if s not in sections]
|
||||
if missing:
|
||||
print(
|
||||
"i64div perf map: cannot find %s in %s"
|
||||
% (", ".join(missing), map_path),
|
||||
file=sys.stderr)
|
||||
return 2
|
||||
|
||||
ok = True
|
||||
for name in (".text", ".data", ".bss"):
|
||||
lo, hi = sections[name]
|
||||
if marker < hi and marker_end > lo:
|
||||
print(
|
||||
"i64div perf map: markers 0x%08X..0x%08X overlap %s "
|
||||
"0x%08X..0x%08X" % (marker, marker_end, name, lo, hi),
|
||||
file=sys.stderr)
|
||||
ok = False
|
||||
|
||||
if regions is not None:
|
||||
prog_lo, prog_hi, ram_lo, ram_hi = regions
|
||||
for name in (".text", ".data"):
|
||||
lo, hi = sections[name]
|
||||
if lo < prog_lo or hi > prog_hi:
|
||||
print(
|
||||
"i64div perf map: %s 0x%08X..0x%08X is outside prog "
|
||||
"0x%08X..0x%08X" % (name, lo, hi, prog_lo, prog_hi),
|
||||
file=sys.stderr)
|
||||
ok = False
|
||||
lo, hi = sections[".bss"]
|
||||
if lo < ram_lo or hi > ram_hi:
|
||||
print(
|
||||
"i64div perf map: .bss 0x%08X..0x%08X is outside ram "
|
||||
"0x%08X..0x%08X" % (lo, hi, ram_lo, ram_hi),
|
||||
file=sys.stderr)
|
||||
ok = False
|
||||
if marker < ram_lo or marker_end > ram_hi:
|
||||
print(
|
||||
"i64div perf map: markers 0x%08X..0x%08X are outside ram "
|
||||
"0x%08X..0x%08X" % (marker, marker_end, ram_lo, ram_hi),
|
||||
file=sys.stderr)
|
||||
ok = False
|
||||
|
||||
if not ok:
|
||||
return 1
|
||||
|
||||
extents = ", ".join(
|
||||
"%s 0x%08X..0x%08X" % (name, sections[name][0], sections[name][1])
|
||||
for name in (".text", ".data", ".bss"))
|
||||
print(
|
||||
"i64div perf map: %s; markers 0x%08X..0x%08X outside every section"
|
||||
% (extents, marker, marker_end))
|
||||
if regions is not None:
|
||||
print(
|
||||
"i64div perf map: markers inside ram 0x%08X..0x%08X"
|
||||
% (regions[2], regions[3]))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,181 @@
|
||||
-- i64div-perf-check.lua -- measure the M7.4 i64 divide/remainder fast path in
|
||||
-- MAME.
|
||||
--
|
||||
-- Loads the gate COFF with vendor/vt1200/dwt/loader/loader.lua (through the
|
||||
-- M4_LOADER_LUA variable scripts/m4/run.sh exports) and polls the marker
|
||||
-- words once per frame. A MAME frame is a fixed number of emulated 50 MHz
|
||||
-- cycles, so the number of frames between the start marker and each phase's
|
||||
-- completion marker is a reproducible cycle proxy for the equal-iteration
|
||||
-- workloads in scripts/m7/i64div-perf.c:
|
||||
--
|
||||
-- fast phase: 16384 iterations, every divide fits 32 bits -> one DIVU each;
|
||||
-- slow phase: 16384 iterations, both high words nonzero -> the 64-step loop;
|
||||
-- wide phase: 16384 iterations, nonzero dividend high word, 32-bit divisor
|
||||
-- and hi(N) >= D -> two even-destination DIVUs (the M8.3 64/32
|
||||
-- path, quotient needs 33+ bits);
|
||||
-- div32 phase: 16384 iterations, nonzero dividend high word, 32-bit divisor
|
||||
-- and hi(N) < D -> one even-destination DIVU plus the low-word
|
||||
-- N - q*D reconstruction (the M9.3 64/32 path).
|
||||
--
|
||||
-- The gate requires the fast phase to complete in materially fewer frames
|
||||
-- (slow_frames >= 8 * max(fast_frames, 1)) and the slow phase to be long
|
||||
-- enough to measure (>= 20 frames). A sub-frame fast phase is reported as
|
||||
-- fast_frames=0 and compared as one frame, which can only make the check
|
||||
-- harder. The wide phase must also be materially faster than the loop
|
||||
-- (slow_frames >= 4 * max(wide_frames, 1)) and measurable (>= 2 frames).
|
||||
-- The div32 phase must be measurable and materially faster than the M8.3
|
||||
-- two-DIVU wide phase: wide_frames*4 >= div32_frames*5 (1.25x).
|
||||
--
|
||||
-- All four phase checksums are required to equal the deterministic values
|
||||
-- below. They were computed from the same LCG/arithmetic with an independent
|
||||
-- host implementation of scripts/m7/i64div-perf.c (see the header comment
|
||||
-- there):
|
||||
-- fast = 0x000000011E6F9AB4, slow = 0x00000000007512AE,
|
||||
-- wide = 0xF56810CFEDA9D656, div32 = 0x00002C61C63842EE.
|
||||
-- The in-image self-check (marker 7) also covers large 32-bit magnitudes
|
||||
-- (0xFFFFFFFF/7, -123/7 and INT32_MIN/3) plus the 64/32 shapes with hi >= d,
|
||||
-- hi == d, hi < d, INT64_MIN (both the small-divisor two-step case and the
|
||||
-- 0xFFFFFFFF single-DIVU case, signed and unsigned magnitude) and the M9.3
|
||||
-- single-DIVU cases (0x1_00000000/3, 0x1_FFFFFFFF/0x10000, -2^32/3 and
|
||||
-- 2^32/-3), so a wrong quotient or remainder fails before the timing
|
||||
-- comparison.
|
||||
--
|
||||
-- Markers at 01A20000h, 0x20 bits apart (free RAM above the 4 KiB entry stack;
|
||||
-- scripts/m7/i64div-map-check.py asserts they are outside .text/.data/.bss):
|
||||
-- 0 start 0x51A47A11 | 1/2 fast checksum | 3 fast done 0xFA57D01E
|
||||
-- 4/5 slow checksum | 6 slow done 0x5104D0E5 | 7 status 0x600D600D
|
||||
-- 8 wide done 0x81DE0D0E | 9/10 wide checksum
|
||||
-- 11 div32 done 0x6432D0E5 | 12/13 div32 checksum
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "5000")
|
||||
local BASE = 0x01A20000
|
||||
local START = 0x51A47A11
|
||||
local FAST_DONE = 0xFA57D01E
|
||||
local SLOW_DONE = 0x5104D0E5
|
||||
local WIDE_DONE = 0x81DE0D0E
|
||||
local DIV32_DONE = 0x6432D0E5
|
||||
local STATUS_OK = 0x600D600D
|
||||
local FAST_HI, FAST_LO = 0x00000001, 0x1E6F9AB4
|
||||
local SLOW_HI, SLOW_LO = 0x00000000, 0x007512AE
|
||||
local WIDE_HI, WIDE_LO = 0xF56810CF, 0xEDA9D656
|
||||
local DIV32_HI, DIV32_LO = 0x00002C61, 0xC63842EE
|
||||
|
||||
local frames = 0
|
||||
local start_f, fast_f, slow_f, wide_f, div32_f
|
||||
local reported = false
|
||||
|
||||
local function rd(n)
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
return prog:read_u32(BASE + n * 0x20)
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
|
||||
if start_f == nil and rd(0) == START then
|
||||
start_f = frames
|
||||
end
|
||||
if start_f ~= nil and fast_f == nil and rd(3) == FAST_DONE then
|
||||
fast_f = frames
|
||||
end
|
||||
if fast_f ~= nil and slow_f == nil and rd(6) == SLOW_DONE then
|
||||
slow_f = frames
|
||||
end
|
||||
if slow_f ~= nil and wide_f == nil and rd(8) == WIDE_DONE then
|
||||
wide_f = frames
|
||||
end
|
||||
if wide_f ~= nil and div32_f == nil and rd(11) == DIV32_DONE then
|
||||
div32_f = frames
|
||||
end
|
||||
|
||||
if div32_f ~= nil and not reported then
|
||||
reported = true
|
||||
local fast_frames = fast_f - start_f
|
||||
local slow_frames = slow_f - fast_f
|
||||
local wide_frames = wide_f - slow_f
|
||||
local div32_frames = div32_f - wide_f
|
||||
local basis = fast_frames
|
||||
if basis < 1 then
|
||||
basis = 1
|
||||
end
|
||||
local wide_basis = wide_frames
|
||||
if wide_basis < 1 then
|
||||
wide_basis = 1
|
||||
end
|
||||
local div32_basis = div32_frames
|
||||
if div32_basis < 1 then
|
||||
div32_basis = 1
|
||||
end
|
||||
local status = rd(7)
|
||||
local cs_fast_hi, cs_fast_lo = rd(2), rd(1)
|
||||
local cs_slow_hi, cs_slow_lo = rd(5), rd(4)
|
||||
local cs_wide_hi, cs_wide_lo = rd(10), rd(9)
|
||||
local cs_div32_hi, cs_div32_lo = rd(13), rd(12)
|
||||
local ratio = slow_frames / basis
|
||||
local wide_ratio = slow_frames / wide_basis
|
||||
local div32_ratio = wide_frames / div32_basis
|
||||
|
||||
local cs_ok = cs_fast_hi == FAST_HI and cs_fast_lo == FAST_LO
|
||||
and cs_slow_hi == SLOW_HI and cs_slow_lo == SLOW_LO
|
||||
and cs_wide_hi == WIDE_HI and cs_wide_lo == WIDE_LO
|
||||
and cs_div32_hi == DIV32_HI and cs_div32_lo == DIV32_LO
|
||||
local ok = status == STATUS_OK and cs_ok
|
||||
and slow_frames >= 20
|
||||
and slow_frames >= 8 * basis
|
||||
and wide_frames >= 2
|
||||
and slow_frames >= 4 * wide_basis
|
||||
and div32_frames >= 2
|
||||
and wide_frames * 4 >= div32_basis * 5
|
||||
|
||||
print(string.format(
|
||||
"M7: i64div perf: start=%d fast_done=%d slow_done=%d "
|
||||
.. "wide_done=%d div32_done=%d fast_frames=%d "
|
||||
.. "slow_frames=%d wide_frames=%d div32_frames=%d "
|
||||
.. "ratio=%.1f wide_ratio=%.1f div32_ratio=%.1f "
|
||||
.. "status=%08X cs_fast=%08X%08X cs_slow=%08X%08X "
|
||||
.. "cs_wide=%08X%08X cs_div32=%08X%08X "
|
||||
.. "cs_expected=%08X%08X/%08X%08X/%08X%08X/%08X%08X cs=%s",
|
||||
start_f, fast_f, slow_f, wide_f, div32_f, fast_frames,
|
||||
slow_frames, wide_frames, div32_frames, ratio, wide_ratio,
|
||||
div32_ratio,
|
||||
status, cs_fast_hi, cs_fast_lo, cs_slow_hi, cs_slow_lo,
|
||||
cs_wide_hi, cs_wide_lo, cs_div32_hi, cs_div32_lo,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO, WIDE_HI, WIDE_LO,
|
||||
DIV32_HI, DIV32_LO,
|
||||
cs_ok and "ok" or "BAD"))
|
||||
|
||||
if ok then
|
||||
print("M7 MAME: PASS")
|
||||
else
|
||||
print(string.format(
|
||||
"M7 MAME: FAIL (status=%08X checksums=%s "
|
||||
.. "fast_frames=%d slow_frames=%d wide_frames=%d "
|
||||
.. "div32_frames=%d; "
|
||||
.. "want status %08X, fast %08X%08X, slow %08X%08X, "
|
||||
.. "wide %08X%08X, div32 %08X%08X, "
|
||||
.. "slow_frames >= 20 and >= 8*max(fast_frames,1), "
|
||||
.. "wide_frames >= 2 and "
|
||||
.. "slow_frames >= 4*max(wide_frames,1), "
|
||||
.. "div32_frames >= 2 and "
|
||||
.. "4*wide_frames >= 5*max(div32_frames,1))",
|
||||
status, cs_ok and "ok" or "BAD",
|
||||
fast_frames, slow_frames, wide_frames, div32_frames,
|
||||
STATUS_OK,
|
||||
FAST_HI, FAST_LO, SLOW_HI, SLOW_LO,
|
||||
WIDE_HI, WIDE_LO, DIV32_HI, DIV32_LO))
|
||||
end
|
||||
elseif frames == ENDF - 1 and not reported then
|
||||
reported = true
|
||||
local seen = string.format(
|
||||
"start=%s fast_done=%s slow_done=%s wide_done=%s "
|
||||
.. "div32_done=%s",
|
||||
tostring(start_f), tostring(fast_f), tostring(slow_f),
|
||||
tostring(wide_f), tostring(div32_f))
|
||||
print(string.format(
|
||||
"M7: i64div perf: incomplete at frame %d at marker 0x%08X",
|
||||
frames, BASE))
|
||||
print("M7 MAME: FAIL (timed out: " .. seen .. ")")
|
||||
end
|
||||
end, "i64div-perf-check")
|
||||
@@ -0,0 +1,19 @@
|
||||
; i64div-perf-entry.asm -- M7.4 i64 divide/remainder performance gate entry,
|
||||
; linked at bit 018A0000 by scripts/tests/m7/i64div.sh through
|
||||
; scripts/m4/run.sh.
|
||||
;
|
||||
; Sets the TI C field sizes, points STK/FP at the gate stack and calls
|
||||
; i64div_perf_run(), which writes the phase markers and returns. The loader
|
||||
; harness inspects the markers at LOADER_END-1, so no post-return sentinel is
|
||||
; needed; the program's last marker write is the slow-phase completion flag.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _i64div_perf_run
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,354 @@
|
||||
/* M7.4/M8.3/M9.3 i64 divide/remainder fast-path performance driver.
|
||||
*
|
||||
* Four equal-iteration workloads exercise the paths of
|
||||
* TMS34010LowerI64::lowerDivRem:
|
||||
*
|
||||
* fast phase: both operands fit 32 bits after the signed magnitude
|
||||
* normalization, so the compiler emits one 32-bit DIVU (plus
|
||||
* the div/mul/sub remainder reconstruction) instead of the
|
||||
* 64-step restoring loop;
|
||||
* slow phase: both operands have nonzero high words, so the 64-step loop
|
||||
* runs for each of the four i64 div/rem forms;
|
||||
* wide phase: the dividend has a nonzero high word but the divisor fits
|
||||
* 32 bits and the quotient needs 33+ bits (hi(N) >= D), so
|
||||
* the M8.3 64/32 path emits two even-destination DIVUs (q1/r1
|
||||
* then q0/r0) instead of the 64-step loop;
|
||||
* div32 phase: the dividend has a nonzero high word but the quotient fits
|
||||
* 32 bits (hi(N) < D), so the M9.3 path emits one
|
||||
* even-destination DIVU plus the low-word N - q*D remainder
|
||||
* reconstruction.
|
||||
*
|
||||
* The loop bodies are driven by a volatile iteration count and volatile
|
||||
* seeds, and every result feeds a volatile accumulator that is published in
|
||||
* the marker words, so neither phase can be constant-folded or discarded.
|
||||
*
|
||||
* Markers (0x20 bits apart at 01A20000h, the free RAM area above the 4 KiB
|
||||
* entry stack at 01A00000h; outside .text/.data/.bss, see
|
||||
* scripts/m7/i64div-map-check.py):
|
||||
* 0 start 0x51A47A11
|
||||
* 1 fast checksum low (printed evidence)
|
||||
* 2 fast checksum high
|
||||
* 3 fast phase done 0xFA57D01E
|
||||
* 4 slow checksum low (printed evidence)
|
||||
* 5 slow checksum high
|
||||
* 6 slow phase done 0x5104D0E5
|
||||
* 7 self-check status 0x600D600D on success
|
||||
* 8 wide phase done 0x81DE0D0E
|
||||
* 9 wide checksum low (printed evidence)
|
||||
* 10 wide checksum high
|
||||
* 11 div32 phase done 0x6432D0E5
|
||||
* 12 div32 checksum low (printed evidence)
|
||||
* 13 div32 checksum high
|
||||
*
|
||||
* The self-check runs known i64 divisions first (fast and slow, unsigned and
|
||||
* signed, including full-width low words and the INT32_MIN magnitude), so the
|
||||
* timing comparison is between two correct paths rather than between a
|
||||
* fast-but-wrong path and the loop. scripts/m7/i64div-perf-check.lua polls
|
||||
* the markers once per MAME frame, turns the frame numbers into the gate's
|
||||
* cycle proxy, and requires the exact phase checksums. With the 16384
|
||||
* iterations above the deterministic LCG workloads produce
|
||||
* fast = 0x000000011E6F9AB4, slow = 0x00000000007512AE,
|
||||
* wide = 0xF56810CFEDA9D656, div32 = 0x00002C61C63842EE
|
||||
* (checked against an independent host implementation of this file; the
|
||||
* target compiler must produce the same integer results).
|
||||
*/
|
||||
|
||||
typedef unsigned int u32;
|
||||
typedef int s32;
|
||||
typedef unsigned long long u64;
|
||||
typedef long long s64;
|
||||
|
||||
#define MARK(n) (*(volatile u32 *)(0x01A20000u + (u32)(n) * 0x20u))
|
||||
|
||||
#define PERF_START 0x51A47A11u
|
||||
#define PERF_FAST_DONE 0xFA57D01Eu
|
||||
#define PERF_SLOW_DONE 0x5104D0E5u
|
||||
#define PERF_WIDE_DONE 0x81DE0D0Eu
|
||||
#define PERF_DIV32_DONE 0x6432D0E5u
|
||||
#define PERF_STATUS_OK 0x600D600Du
|
||||
#define PERF_STATUS_BAD 0xBAD0BAD0u
|
||||
|
||||
/* 16384 iterations put the fast phase at a few frames and the slow phase at a
|
||||
* few hundred frames on the emulated 50 MHz part, with a wide margin under
|
||||
* the gate-local loader budget (5000 frames by default). The count is volatile so the optimizer keeps
|
||||
* a real loop and does not unroll it into a folded constant. */
|
||||
static volatile u32 perf_iters = 16384u;
|
||||
|
||||
/* Seeds are volatile for the same reason: the divisions must really execute. */
|
||||
static volatile u64 seed_a = 0x0000000012345678ull;
|
||||
static volatile u64 seed_b = 0x000000009ABCDEF1ull;
|
||||
|
||||
/* Known-value inputs (values pinned by the M6 i64 gate). */
|
||||
static volatile u64 sc_n1 = 0x123456789ABCDEF0ull;
|
||||
static volatile u64 sc_d1 = 0x0000000000001234ull;
|
||||
static volatile u64 sc_d2 = 0x0000000123456789ull;
|
||||
static volatile s64 sc_n3 = -1000000000000ll;
|
||||
static volatile s64 sc_d3 = 7ll;
|
||||
static volatile s64 sc_n4 = 123ll;
|
||||
static volatile s64 sc_d4 = -7ll;
|
||||
|
||||
/* Fast-path cases with large low words: the high word is zero (or the value
|
||||
* is a negative 32-bit value whose magnitude still fits), so the quotient and
|
||||
* remainder must come from the 32-bit DIVU, not the loop. */
|
||||
static volatile u64 sc_max32 = 0xFFFFFFFFull;
|
||||
static volatile u64 sc_seven = 7ull;
|
||||
static volatile s64 sc_neg123 = -123ll;
|
||||
static volatile s64 sc_int32min = -2147483648ll;
|
||||
static volatile s64 sc_three = 3ll;
|
||||
static volatile s64 sc_three_neg = -3ll;
|
||||
|
||||
/* M8.3/M9.3 64/32-path cases: nonzero dividend high word, 32-bit divisor.
|
||||
* The first, second and unsigned INT64_MIN-magnitude cases exercise the
|
||||
* two-step form where the quotient needs 33+ bits (hi >= d), so q1 is nonzero
|
||||
* and both even-destination divides run. The third has hi < d and takes the
|
||||
* M9.3 single-DIVU path. INT64_MIN never fits 32 bits (magnitude high word
|
||||
* 0x80000000): divisors <= 2^31 keep it on the two-step helper, while a
|
||||
* divisor in (2^31, 2^32), e.g. 0xFFFFFFFF, has hi(|N|) < d and takes the
|
||||
* single-DIVU path; the self-check below covers both. */
|
||||
static volatile u64 sc_wide1 = 0xFEDCBA9876543210ull;
|
||||
static volatile u64 sc_wide_d1 = 0x12345678ull;
|
||||
static volatile u64 sc_wide2 = 0xFFFFFFFFFFFFFFFFull;
|
||||
static volatile u64 sc_wide_d2 = 0xFFFFFFFFull;
|
||||
static volatile u64 sc_wide3 = 0x00000001FFFFFFFFull;
|
||||
static volatile u64 sc_wide4 = 0x8000000000000000ull;
|
||||
static volatile s64 sc_int64min = -9223372036854775807ll - 1ll;
|
||||
|
||||
/* M9.3 single-DIVU 64/32 cases: a nonzero dividend high word with hi < d so
|
||||
* the whole quotient fits 32 bits. 0x1_00000000 / 3 is the canonical
|
||||
* q = 0x55555555, r = 1 case; the negative form exercises the shared signed
|
||||
* fixup on the new path. */
|
||||
static volatile u64 sc_div32_n = 0x0000000100000000ull;
|
||||
static volatile u64 sc_div32_d = 3ull;
|
||||
static volatile u64 sc_div32_n2 = 0x00000001FFFFFFFFull;
|
||||
static volatile u64 sc_div32_d2 = 0x0000000000010000ull;
|
||||
static volatile s64 sc_div32_neg = -4294967296ll;
|
||||
|
||||
static u32 lcg(u32 x)
|
||||
{
|
||||
return x * 1103515245u + 12345u;
|
||||
}
|
||||
|
||||
/* Known-value checks for both paths, unsigned and signed, including the
|
||||
* full-width low words and INT32_MIN. */
|
||||
static u32 selfcheck(void)
|
||||
{
|
||||
u64 q, r;
|
||||
s64 sq, sr;
|
||||
u32 ok = 1;
|
||||
|
||||
q = sc_n1 / sc_d1;
|
||||
r = sc_n1 % sc_d1;
|
||||
ok &= (q == 0x00010004C016906Bull) && (r == 0x334ull);
|
||||
|
||||
/* Divisor above 32 bits: the restoring loop. */
|
||||
q = sc_n1 / sc_d2;
|
||||
r = sc_n1 % sc_d2;
|
||||
ok &= (q == 0x0000000010000000ull) && (r == 0x0ABCDEF0ull);
|
||||
|
||||
/* Both signed values fit after normalization: the signed fast path. */
|
||||
sq = sc_n4 / sc_d4;
|
||||
sr = sc_n4 % sc_d4;
|
||||
ok &= (sq == -17ll) && (sr == 4ll);
|
||||
|
||||
/* Fast paths with large low words. A wrong 32-bit quotient/remainder
|
||||
* for a full-width magnitude (or for INT32_MIN's magnitude 2^31) must
|
||||
* fail here before the timing comparison. */
|
||||
q = sc_max32 / sc_seven;
|
||||
r = sc_max32 % sc_seven;
|
||||
ok &= (q == 0x0000000024924924ull) && (r == 3ull);
|
||||
|
||||
/* sc_d3 is the signed 7: sc_seven is u64, so mixing it with a negative
|
||||
* s64 would make the comparison unsigned (the same C conversion the
|
||||
* target performs). */
|
||||
sq = sc_neg123 / sc_d3;
|
||||
sr = sc_neg123 % sc_d3;
|
||||
ok &= (sq == -17ll) && (sr == -4ll);
|
||||
|
||||
sq = sc_int32min / sc_three;
|
||||
sr = sc_int32min % sc_three;
|
||||
ok &= (sq == -715827882ll) && (sr == -2ll);
|
||||
|
||||
/* A large signed dividend: the signed wide path (32-bit divisor 7). */
|
||||
sq = sc_n3 / sc_d3;
|
||||
sr = sc_n3 % sc_d3;
|
||||
ok &= (sq == -142857142857ll) && (sr == -1ll);
|
||||
|
||||
/* M8.3 64/32 path with hi >= d: the quotient needs 36 bits. */
|
||||
q = sc_wide1 / sc_wide_d1;
|
||||
r = sc_wide1 % sc_wide_d1;
|
||||
ok &= (q == 0x0000000E00000077ull) && (r == 0x48ull);
|
||||
|
||||
/* M8.3 64/32 path with hi == d: the quotient needs 33 bits. */
|
||||
q = sc_wide2 / sc_wide_d2;
|
||||
r = sc_wide2 % sc_wide_d2;
|
||||
ok &= (q == 0x0000000100000001ull) && (r == 0ull);
|
||||
|
||||
/* M8.3 64/32 path with hi < d: it now takes the M9.3 single divide. */
|
||||
q = sc_wide3 / sc_wide_d2;
|
||||
r = sc_wide3 % sc_wide_d2;
|
||||
ok &= (q == 2ull) && (r == 1ull);
|
||||
|
||||
/* M9.3 single-DIVU 64/32 path: hi < d (0x1 < 3 and 0x1 < 0x10000). */
|
||||
q = sc_div32_n / sc_div32_d;
|
||||
r = sc_div32_n % sc_div32_d;
|
||||
ok &= (q == 0x55555555ull) && (r == 1ull);
|
||||
|
||||
q = sc_div32_n2 / sc_div32_d2;
|
||||
r = sc_div32_n2 % sc_div32_d2;
|
||||
ok &= (q == 0x1FFFFull) && (r == 0xFFFFull);
|
||||
|
||||
sq = sc_div32_neg / sc_three;
|
||||
sr = sc_div32_neg % sc_three;
|
||||
ok &= (sq == -1431655765ll) && (sr == -1ll);
|
||||
|
||||
/* M8.3 unsigned INT64_MIN magnitude and signed INT64_MIN / 3. */
|
||||
q = sc_wide4 / sc_three;
|
||||
r = sc_wide4 % sc_three;
|
||||
ok &= (q == 0x2AAAAAAAAAAAAAAAull) && (r == 2ull);
|
||||
|
||||
sq = sc_int64min / sc_three;
|
||||
sr = sc_int64min % sc_three;
|
||||
ok &= (sq == -3074457345618258602ll) && (sr == -2ll);
|
||||
|
||||
/* INT64_MIN magnitude with a divisor above 2^31: hi(|N|) = 0x80000000
|
||||
* < 0xFFFFFFFF, so it takes the M9.3 single-DIVU path (unsigned and
|
||||
* signed). q = r = 2^31 in magnitude; the signed remainder keeps the
|
||||
* dividend's sign. */
|
||||
q = sc_wide4 / sc_max32;
|
||||
r = sc_wide4 % sc_max32;
|
||||
ok &= (q == 0x80000000ull) && (r == 0x80000000ull);
|
||||
|
||||
sq = sc_int64min / (s64)sc_max32;
|
||||
sr = sc_int64min % (s64)sc_max32;
|
||||
ok &= (sq == -2147483648ll) && (sr == -2147483648ll);
|
||||
|
||||
/* M9.3 single-DIVU 64/32 path with a negative 32-bit-magnitude divisor:
|
||||
* 2^32 / -3 = -1431655765 r 1 (the quotient sign is the sign XOR, the
|
||||
* remainder follows the dividend). */
|
||||
sq = (s64)sc_div32_n / (s64)sc_three_neg;
|
||||
sr = (s64)sc_div32_n % (s64)sc_three_neg;
|
||||
ok &= (sq == -1431655765ll) && (sr == 1ll);
|
||||
|
||||
return ok ? PERF_STATUS_OK : PERF_STATUS_BAD;
|
||||
}
|
||||
|
||||
/* Small operands: the high words are zero, so the four divisions take the
|
||||
* 32-bit fast path. The signed forms cast a 32-bit value to i64; a negative
|
||||
* value still has a 32-bit magnitude, so it also takes the fast path. */
|
||||
static void run_fast(void)
|
||||
{
|
||||
u64 acc = 0;
|
||||
u64 a = seed_a;
|
||||
u64 b = seed_b;
|
||||
u32 n = perf_iters;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
a = (u64)(lcg((u32)a) & 0x7FFFFFFFu) + 1u;
|
||||
b = (u64)(lcg((u32)b) & 0x0000FFFFu) + 1u;
|
||||
acc += a / b;
|
||||
acc ^= a % b;
|
||||
acc += (u64)((s64)(s32)a / (s64)(s32)b);
|
||||
acc ^= (u64)((s64)(s32)a % (s64)(s32)b);
|
||||
}
|
||||
|
||||
MARK(1) = (u32)acc;
|
||||
MARK(2) = (u32)(acc >> 32);
|
||||
MARK(3) = PERF_FAST_DONE;
|
||||
}
|
||||
|
||||
/* Nonzero high words in both operands: all four forms take the 64-step
|
||||
* restoring loop. The same iteration count as the fast phase makes the frame
|
||||
* counts directly comparable. */
|
||||
static void run_slow(void)
|
||||
{
|
||||
u64 acc = 0;
|
||||
u64 a = seed_a;
|
||||
u64 b = seed_b;
|
||||
u32 n = perf_iters;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
a = ((u64)(1u + (lcg((u32)(a >> 32)) & 0xFFFFu)) << 32)
|
||||
| (u64)(lcg((u32)a) | 1u);
|
||||
b = ((u64)(1u + (lcg((u32)(b >> 32)) & 0x00FFu)) << 32)
|
||||
| (u64)(lcg((u32)b) | 1u);
|
||||
acc += a / b;
|
||||
acc ^= a % b;
|
||||
acc += (u64)((s64)a / (s64)b);
|
||||
acc ^= (u64)((s64)a % (s64)b);
|
||||
}
|
||||
|
||||
MARK(4) = (u32)acc;
|
||||
MARK(5) = (u32)(acc >> 32);
|
||||
MARK(6) = PERF_SLOW_DONE;
|
||||
}
|
||||
|
||||
/* Nonzero dividend high word, 32-bit divisor, hi(N) >= D: all four forms take
|
||||
* the M8.3 two-step 64/32 path (two even-destination DIVUs) instead of the
|
||||
* 64-step loop. The high word mask 0x80000000|(lcg & 0x7FFEFFFF) keeps
|
||||
* hi(N) in [0x80000000, 0xFFFEFFFF] and the divisor at most 0x10000, so the
|
||||
* unsigned high word is at least 0x10000. For the signed forms the
|
||||
* magnitude's high word is 0xFFFFFFFF - hi(N), i.e. in [0x10000, 0x7FFFFFFF],
|
||||
* so the negated magnitude is also >= 2^32 and every signed division takes
|
||||
* the same two-step helper. */
|
||||
static void run_wide(void)
|
||||
{
|
||||
u64 acc = 0;
|
||||
u64 a = seed_a;
|
||||
u64 b = seed_b;
|
||||
u32 n = perf_iters;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
a = ((u64)(0x80000000u
|
||||
| (lcg((u32)(a >> 32)) & 0x7FFEFFFFu)) << 32)
|
||||
| (u64)(lcg((u32)a) | 1u);
|
||||
b = (u64)(1u + (lcg((u32)b) & 0x0000FFFFu));
|
||||
acc += a / b;
|
||||
acc ^= a % b;
|
||||
acc += (u64)((s64)a / (s64)b);
|
||||
acc ^= (u64)((s64)a % (s64)b);
|
||||
}
|
||||
|
||||
MARK(9) = (u32)acc;
|
||||
MARK(10) = (u32)(acc >> 32);
|
||||
MARK(8) = PERF_WIDE_DONE;
|
||||
}
|
||||
|
||||
/* Nonzero dividend high word, 32-bit divisor, hi(N) < D: all four forms take
|
||||
* the M9.3 single-even-destination-DIVU path. The dividend high word is at
|
||||
* most 0x10000 and the divisor is at least 0x10001, so the quotient always
|
||||
* fits 32 bits and the single divide produces it. */
|
||||
static void run_div32(void)
|
||||
{
|
||||
u64 acc = 0;
|
||||
u64 a = seed_a;
|
||||
u64 b = seed_b;
|
||||
u32 n = perf_iters;
|
||||
u32 i;
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
a = ((u64)(1u + (lcg((u32)(a >> 32)) & 0xFFFFu)) << 32)
|
||||
| (u64)(lcg((u32)a) | 1u);
|
||||
b = (u64)(0x10001u + (lcg((u32)b) & 0x0000FFFFu));
|
||||
acc += a / b;
|
||||
acc ^= a % b;
|
||||
acc += (u64)((s64)a / (s64)b);
|
||||
acc ^= (u64)((s64)a % (s64)b);
|
||||
}
|
||||
|
||||
MARK(12) = (u32)acc;
|
||||
MARK(13) = (u32)(acc >> 32);
|
||||
MARK(11) = PERF_DIV32_DONE;
|
||||
}
|
||||
|
||||
void i64div_perf_run(void)
|
||||
{
|
||||
MARK(7) = selfcheck();
|
||||
MARK(0) = PERF_START;
|
||||
run_fast();
|
||||
run_slow();
|
||||
run_wide();
|
||||
run_div32();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/* M7.2 long-public-name gate, TU A.
|
||||
*
|
||||
* The public function name is 44 characters (45 with the C `_` prefix),
|
||||
* longer than GSPA 2.00's 31-character symbol limit. The object path keeps it
|
||||
* intact; tms-link resolves the cross-TU reference from longname-b.c and writes
|
||||
* the full name into its map.
|
||||
*/
|
||||
|
||||
int tms34010_public_function_name_longer_than_31(void) {
|
||||
return 42;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/* M7.2 long-public-name gate, TU B.
|
||||
*
|
||||
* Declares and calls the 44-character public function from longname-a.c. The
|
||||
* call is a normal undefined-external R-RELLONG in this object; tms-link
|
||||
* resolves it to TU A's definition without truncating either name.
|
||||
*/
|
||||
|
||||
int tms34010_public_function_name_longer_than_31(void);
|
||||
|
||||
int longname_call(void) {
|
||||
return tms34010_public_function_name_longer_than_31() + 1;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
; longname-entry.asm -- M7.2 long-public-name gate entry, linked at 018A0000.
|
||||
;
|
||||
; Calls the short-named TU B wrapper (which calls the 44-character public
|
||||
; function in TU A) and stores its result, 43, at 018A8000. GSPA never sees
|
||||
; the long name: it only assembles the short `_longname_call` reference, so
|
||||
; the gate exercises tms-link's long-name symbol resolution rather than GSPA's
|
||||
; 31-character truncation.
|
||||
.ref _longname_call
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16,1,0
|
||||
setf 32,0,1
|
||||
movi _cstack,a14
|
||||
move a14,a13
|
||||
calla _longname_call
|
||||
move a8,@018A8000h,1
|
||||
rets
|
||||
|
||||
.bss _cstack,32768,16
|
||||
.end
|
||||
@@ -0,0 +1,149 @@
|
||||
-- xmore-check.lua -- load the M7.3 wider-Xlib COFF with dwt/loader/loader.lua,
|
||||
-- then prove the markers and the window pixels.
|
||||
--
|
||||
-- M4_LOADER_LUA path to vendor/vt1200/dwt/loader/loader.lua
|
||||
-- LOADER_END loader inspection/exit frame (default 3400)
|
||||
--
|
||||
-- Markers (0x20 bits apart, read at LOADER_END-1):
|
||||
-- 018A8000 parent Window id, nonzero
|
||||
-- 018A8020 child Window id, nonzero
|
||||
-- 018A8040 gc GC pointer, nonzero
|
||||
-- 018A8060 atom XInternAtom("WM_NAME"): nonzero atom, or
|
||||
-- 0xFFFFFFFF documented skip (the ROM _XSend path
|
||||
-- that carries the name does not complete here)
|
||||
-- 018A8080 property 1 after the XChangeProperty call site ran (no
|
||||
-- server read-back; zero X errors is the only
|
||||
-- runtime check)
|
||||
-- 018A80A0 configure client-computed (child width << 16) | height
|
||||
-- (0x00C80096); the move is pixel-proven, the size
|
||||
-- is not read back
|
||||
-- 018A80C0 font XLoadFont("fixed"), nonzero
|
||||
-- 018A80E0 image (pixel << 8) | flags (0x13F when the full
|
||||
-- XCreateImage/XGetImage/XPutImage/XDestroyImage
|
||||
-- round trip worked: pixel=1 and flags=0x3F)
|
||||
-- 018A8100 errors X protocol error count (0)
|
||||
-- 018A8120 stage 14 = InternAtom attempted (skip), 15 = returned
|
||||
-- 018A8140 attrs 1 after the XChangeWindowAttributes call site ran;
|
||||
-- the real proof is the black CWBackPixel margin
|
||||
-- (the ROM builder does not set A8)
|
||||
-- 018A8160 gcchange XChangeGC source call count (2); runtime entry is
|
||||
-- not proven, and the ROM entry is a cache flush
|
||||
-- 018A8180 text set pixels in the XDrawString band (0,126) 64x16
|
||||
-- 018A81A0 display Display pointer stored just before XInternAtom
|
||||
-- 018A81C0 fill (FILL_W << 16) | FILL_H (0xA00078), pins the
|
||||
-- margin sample's fill geometry
|
||||
--
|
||||
-- Geometry: parent at screen (100,100) 400x300 (the WM leaves a top-level
|
||||
-- client window at its requested origin, as the M4 xshow gate proves), child
|
||||
-- configured to (20,20) 200x150. The child is created with background 1
|
||||
-- (white), then CWBackPixel=0 (black). The 160x120 black fill leaves a
|
||||
-- right/bottom margin; screen (300,240) is in that margin, so it is black only
|
||||
-- because of the window attribute (without it the child background is white).
|
||||
-- The white rectangle is at child (0,0) 32x32 (screen 120,120), the heap image
|
||||
-- at child (40,32) (screen 160,152; 32-bit aligned) and the XGetImage result
|
||||
-- put back at child (104,32) (screen 224,152). The text is drawn at baseline
|
||||
-- child (4,140) on the black margin, and the XGetImage band (child 0,126 64x16)
|
||||
-- counts its white glyph pixels.
|
||||
--
|
||||
-- The printed "parent(...)" coordinate is screen minus the parent origin
|
||||
-- (100,100), i.e. parent-relative, not child-relative (the child is at 20,20
|
||||
-- inside the parent).
|
||||
--
|
||||
-- Pixel sampling reads the exact VRAM bit address (VR319: 2048-bit rows,
|
||||
-- LSB-first), not a whole unaligned word. If XConfigureWindow did not move the
|
||||
-- child from its created (40,40), the p_rect sample (screen 128,128) is outside
|
||||
-- the child and p_back (screen 240,160) maps outside the put-back image; p_img
|
||||
-- alone would still be white (it would land inside the 32x32 rectangle).
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "3400")
|
||||
local VRAM_BASE = 0x04000000
|
||||
local VRAM_PITCH = 2048
|
||||
local WIN_X, WIN_Y = 100, 100
|
||||
|
||||
local frames = 0
|
||||
local checked = false
|
||||
|
||||
local function read_bit(prog, sx, sy)
|
||||
local bit = VRAM_BASE + sy * VRAM_PITCH + sx
|
||||
return prog:read_u16(bit) % 2, bit
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
|
||||
if frames == ENDF - 1 and not checked then
|
||||
checked = true
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local m = {}
|
||||
for i = 0, 14 do
|
||||
m[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
|
||||
print(string.format(
|
||||
"M7: window=0x%X child=0x%X gc=0x%X atom=0x%X property_called=%d configure=0x%X font=0x%X image=0x%X errors=%d stage=%d attrs_called=%d gcchange=%d text=%d display=0x%X fill=0x%X",
|
||||
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], m[13], m[14]))
|
||||
|
||||
local function sample(sx, sy, want)
|
||||
local b, bit = read_bit(prog, sx, sy)
|
||||
print(string.format(
|
||||
"M7: pixel screen(%d,%d) parent(%d,%d) bit=0x%08X value=%d %s",
|
||||
sx, sy, sx - WIN_X, sy - WIN_Y, bit, b,
|
||||
b == 1 and "white" or "black"))
|
||||
return b == want
|
||||
end
|
||||
|
||||
-- (screen x, screen y, expected); parent-relative coordinates.
|
||||
local p_rect = sample(128, 128, 1) -- parent (28,28): XFillRectangle
|
||||
local p_img = sample(170, 162, 1) -- parent (70,62): heap XPutImage
|
||||
local p_back = sample(240, 160, 1) -- parent (140,60): put back
|
||||
local p_bg = sample(300, 240, 0) -- parent (200,140): CWBackPixel margin
|
||||
|
||||
local configure_want = 200 * 65536 + 150
|
||||
local image_want = 0x13F
|
||||
local atom_skip = (m[3] == 0xFFFFFFFF)
|
||||
local atom_ok = (m[3] ~= 0 and m[3] ~= 0xFFFFFFFF
|
||||
and m[3] ~= 0xFFFFFFFE)
|
||||
local stage_ok = (atom_skip and m[9] == 14)
|
||||
or (atom_ok and m[9] == 15)
|
||||
local text_want_max = 64 * 16
|
||||
local ok = m[0] ~= 0 and m[1] ~= 0 and m[2] ~= 0
|
||||
and (atom_skip or atom_ok)
|
||||
and m[4] == 1 and m[5] == configure_want and m[6] ~= 0
|
||||
and m[7] == image_want and m[8] == 0 and stage_ok
|
||||
and m[10] == 1 and m[11] == 2
|
||||
and m[12] > 0 and m[12] < text_want_max
|
||||
and m[13] ~= 0 and m[14] == 0xA00078
|
||||
and p_rect and p_img and p_back and p_bg
|
||||
|
||||
print(string.format(
|
||||
"M7: text band child(0,126) 64x16 set_pixels=%d (%s); "
|
||||
.. "gcchange=%d (source call sites; runtime entry not proven); "
|
||||
.. "attrs_called=%d; property_called=%d (call site ran, no "
|
||||
.. "server read-back)",
|
||||
m[12], (m[12] > 0 and m[12] < text_want_max) and "ok" or "BAD",
|
||||
m[11], m[10], m[4]))
|
||||
|
||||
if atom_skip then
|
||||
print("M7: internatom=SKIP (ROM _XSend scatter path blocks; "
|
||||
.. "WM_NAME written with predefined atom 39; the display "
|
||||
.. "marker only proves the connection was live before the "
|
||||
.. "call; the isolated probe is narrative entry evidence)")
|
||||
elseif atom_ok then
|
||||
print(string.format("M7: internatom=0x%X", m[3]))
|
||||
end
|
||||
|
||||
if ok then
|
||||
print("M7 MAME: PASS")
|
||||
else
|
||||
print(string.format(
|
||||
"M7 MAME: FAIL (window=0x%X child=0x%X gc=0x%X atom=0x%X property_called=%d configure=0x%X font=0x%X image=0x%X errors=%d stage=%d attrs_called=%d gcchange=%d text=%d display=0x%X fill=0x%X; pixels rect=%s image=%s putback=%s margin=%s)",
|
||||
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], m[13], m[14],
|
||||
tostring(p_rect), tostring(p_img), tostring(p_back),
|
||||
tostring(p_bg)))
|
||||
end
|
||||
end
|
||||
end, "xmore-check")
|
||||
@@ -0,0 +1,25 @@
|
||||
; xmore-entry.asm -- M7.3 wider-Xlib client entry, linked at bit 018A0000.
|
||||
;
|
||||
; Installs the TI all-stack ABI fields and the 4 KiB stack, then calls the
|
||||
; compiled xmore() client. Markers (0x20 bits apart):
|
||||
; 018A8000 parent nonzero
|
||||
; 018A8020 child nonzero
|
||||
; 018A8040 gc nonzero
|
||||
; 018A8060 atom WM_NAME atom, or 0xFFFFFFFF documented skip
|
||||
; 018A8080 property post-call flag, 1 (no server read-back)
|
||||
; 018A80A0 configure (width << 16) | height (client-computed; move pixel-proven)
|
||||
; 018A80C0 font XLoadFont("fixed") handle
|
||||
; 018A80E0 image (pixel << 8) | round-trip flags
|
||||
; 018A8100 errors 0
|
||||
; 018A8120 stage last completed step (14 skip, 15 atom returned)
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _xmore
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,456 @@
|
||||
/*
|
||||
* xmore.c -- the M7.3 wider VT1200 Xlib surface client.
|
||||
*
|
||||
* The client opens the ROM X display, builds one parent window and one child
|
||||
* window, maps the children with XMapSubwindows, moves/resizes the child with
|
||||
* the ROM's fixed-mask XConfigureWindow builder, writes the parent's WM_NAME
|
||||
* property (XChangeProperty), changes the child's background with
|
||||
* XChangeWindowAttributes, changes the GC foreground with XChangeGC, loads a
|
||||
* font and draws text (XLoadFont + XDrawString) and a rectangle, and performs
|
||||
* a heap image round trip: XCreateImage with malloc'd bytes, XPutImage,
|
||||
* XGetImage of the same region, a second XPutImage of the returned image, then
|
||||
* XDestroyImage on both. XInternAtom("WM_NAME") is the last surface call.
|
||||
*
|
||||
* The child is created with background 1 (white) and then given
|
||||
* CWBackPixel=0 (black); the 160x120 black fill leaves a right/bottom margin
|
||||
* that only the window attribute can make black. The text is drawn on that
|
||||
* margin and its pixels are counted from an XGetImage band.
|
||||
*
|
||||
* Markers live at 0x018A8000 + n*0x20 (bit addresses):
|
||||
* 0 parent Window id (nonzero)
|
||||
* 1 child Window id (nonzero; the XMapSubwindows child)
|
||||
* 2 gc GC pointer (nonzero)
|
||||
* 3 atom XInternAtom("WM_NAME") result:
|
||||
* nonzero the call returned the atom
|
||||
* 0xFFFFFFFF the call was attempted but blocked; the
|
||||
* surface is kept and the skip is explicit
|
||||
* 0xFFFFFFFE the call returned None
|
||||
* 4 property 1 after the XChangeProperty call site ran (no server
|
||||
* read-back; the zero X-error count is the only runtime
|
||||
* check)
|
||||
* 5 configure client-computed (child width << 16) | child height; the
|
||||
* move is pixel-proven, the size is not read back
|
||||
* 6 font XLoadFont("fixed") handle (nonzero; the GC uses the
|
||||
* server default font, see the CreateGC note below)
|
||||
* 7 image (get_pixel << 8) | flags:
|
||||
* 0x01 XCreateImage, 0x02 XGetImage returned an image,
|
||||
* 0x04 the XGetImage pixel word was all white,
|
||||
* 0x08 XPutImage of the returned image,
|
||||
* 0x10 XDestroyImage both images,
|
||||
* 0x20 XGetImage was usable (not skipped)
|
||||
* all six flags plus a white pixel is 0x13F
|
||||
* 8 errors X protocol error count (0)
|
||||
* 9 stage last completed step (14 = XInternAtom attempted after
|
||||
* everything else; 15 = it returned and the property was
|
||||
* rewritten with that atom)
|
||||
* 10 attrs 1 after the XChangeWindowAttributes call site ran; the
|
||||
* real proof is the black CWBackPixel margin sampled by the
|
||||
* gate (the ROM builder does not set A8)
|
||||
* 11 gcchange count of XChangeGC source call sites (2). The ROM entry is
|
||||
* the 2-arg GC-cache flush; this counts the calls in source,
|
||||
* not their runtime entry.
|
||||
* 12 text set pixels counted in the XDrawString band (64x16 at
|
||||
* child 0,126) after XGetImage; must be > 0 and below the
|
||||
* band size
|
||||
* 13 display Display pointer stored just before XInternAtom; proves the
|
||||
* connection was live at the pre-call marker, not that the
|
||||
* call was entered
|
||||
* 14 fill (FILL_W << 16) | FILL_H, so the hard-coded margin sample
|
||||
* cannot silently become vacuous if the fill changes
|
||||
*
|
||||
* The image marker distinguishes a usable XGetImage (0x13F) from a failed or
|
||||
* skipped one; a failed call clears IMG_USABLE and the gate names it.
|
||||
*
|
||||
* XInternAtom is deliberately last. The ROM's _XSend (0x3F9B44C0) is the
|
||||
* scatter/service-write path used for InternAtom's name bytes (and for
|
||||
* XPutImage's direct-send path); the M4 xshow client already records that
|
||||
* this path does not make progress in the loader harness. The call is kept in
|
||||
* the surface, and marker 3 records the documented skip instead of dropping
|
||||
* it. The WM_NAME property is therefore written first with the predefined
|
||||
* X11R4 atom XA_WM_NAME (39), which the server knows without an InternAtom.
|
||||
* If XInternAtom does return (the real unit), the client rewrites the property
|
||||
* with the returned atom and advances to stage 15.
|
||||
*
|
||||
* Two ROM/Xlib details matter:
|
||||
* - XChangeProperty copies the value bytes with the ROM blitter entry
|
||||
* blit_copy (0x3FB44400), just as _XPutImage does. A loader child starts
|
||||
* with a zeroed blitter context, so prime it once before the property.
|
||||
* - The ROM XChangeGC entry is (display, gc): it serializes the GC value
|
||||
* cache that XSetForeground/XSetFont marked dirty. The drawing
|
||||
* primitives call the same serializer, but the explicit call is what the
|
||||
* gate exercises.
|
||||
*/
|
||||
#include "x11m4.h"
|
||||
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n) * 0x20u))
|
||||
|
||||
#define PARENT_X 100
|
||||
#define PARENT_Y 100
|
||||
#define PARENT_W 400
|
||||
#define PARENT_H 300
|
||||
|
||||
/* Created at (40,40) 240x160, then configured to (20,20) 200x150. */
|
||||
#define CHILD_X 20
|
||||
#define CHILD_Y 20
|
||||
#define CHILD_W 200
|
||||
#define CHILD_H 150
|
||||
|
||||
#define IMG_W 64
|
||||
#define IMG_H 64
|
||||
#define IMG_BPL (IMG_W / 8)
|
||||
|
||||
/* The black fill leaves a margin so the CWBackPixel background is visible. */
|
||||
#define FILL_W 160
|
||||
#define FILL_H 120
|
||||
|
||||
/* XDrawString("xmore") at baseline (4,140), on the black bottom margin. */
|
||||
#define TEXT_X 4
|
||||
#define TEXT_Y 140
|
||||
#define TEXT_LEN 5
|
||||
#define TEXT_BAND_X 0
|
||||
#define TEXT_BAND_Y 126
|
||||
#define TEXT_BAND_W 64
|
||||
#define TEXT_BAND_H 16
|
||||
|
||||
#define XA_STRING 31
|
||||
#define XA_WM_NAME 39
|
||||
#define PropModeReplace 0
|
||||
|
||||
#define INTERNATOM_SKIPPED 0xFFFFFFFFu
|
||||
#define INTERNATOM_NONE 0xFFFFFFFEu
|
||||
|
||||
/*
|
||||
* The wider-surface ABI, pinned here so a header edit cannot silently change
|
||||
* the offsets the ROM request builders read (X11R4 32-bit structs: 4-byte
|
||||
* fields). XWindowChanges.width=8; XSetWindowAttributes.background_pixel=4
|
||||
* (CWBackPixel); XGCValues.font=60 (GCFont; the ROM walker reads byte 60).
|
||||
*/
|
||||
_Static_assert(__builtin_offsetof(XWindowChanges, width) == 8,
|
||||
"XWindowChanges.width must be at byte 8");
|
||||
_Static_assert(__builtin_offsetof(XSetWindowAttributes, background_pixel) == 4,
|
||||
"XSetWindowAttributes.background_pixel must be at byte 4");
|
||||
_Static_assert(__builtin_offsetof(XGCValues, font) == 60,
|
||||
"XGCValues.font must be at byte 60");
|
||||
|
||||
#define IMG_CREATED 0x01
|
||||
#define IMG_GOT 0x02
|
||||
#define IMG_PIXEL 0x04
|
||||
#define IMG_PUT 0x08
|
||||
#define IMG_DESTROYED 0x10
|
||||
#define IMG_USABLE 0x20
|
||||
|
||||
/* The ROM allocator (symbols/vt1200-v22.syms: malloc/free). */
|
||||
extern void *malloc(unsigned int size);
|
||||
extern void free(void *p);
|
||||
|
||||
static int xerrors;
|
||||
/* The two explicit XChangeGC call sites (marker 11). */
|
||||
static unsigned int gc_changes;
|
||||
|
||||
static int on_error(Display *d, XErrorEvent *e) {
|
||||
(void)d;
|
||||
(void)e;
|
||||
xerrors++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The ROM sleep through a function pointer, as the M4 client does. */
|
||||
static int (*volatile vt_sleep)(int) = sleep;
|
||||
|
||||
/* XImage.data is heap memory here, so the ROM destructor may free it. */
|
||||
static XImage *heap_image;
|
||||
|
||||
/*
|
||||
* The blitter is process-global and starts zeroed in a loader child. Prime
|
||||
* it with a four-byte self-copy before XChangeProperty's value copy.
|
||||
*/
|
||||
static void prime_blitter(void) {
|
||||
static unsigned int word;
|
||||
blit_copy(&word, &word, 4);
|
||||
}
|
||||
|
||||
static void clear_black(Display *d, Window w, GC gc) {
|
||||
XSetForeground(d, gc, 0);
|
||||
XChangeGC(d, gc);
|
||||
gc_changes++;
|
||||
/* Leave the child's right/bottom margin to the CWBackPixel background. */
|
||||
XFillRectangle(d, w, gc, 0, 0, FILL_W, FILL_H);
|
||||
}
|
||||
|
||||
static void draw_white(Display *d, Window w, GC gc) {
|
||||
XSetForeground(d, gc, 1);
|
||||
XChangeGC(d, gc);
|
||||
gc_changes++;
|
||||
/* The drawing call and the text call, both after the GC change. The
|
||||
* text sits on the black CWBackPixel margin so its pixels are countable. */
|
||||
XFillRectangle(d, w, gc, 0, 0, 32, 32);
|
||||
XDrawString(d, w, gc, TEXT_X, TEXT_Y, "xmore", TEXT_LEN);
|
||||
}
|
||||
|
||||
/*
|
||||
* Prove XDrawString with pixels: XGetImage the text band and count set bits.
|
||||
* The band is black CWBackPixel background; white glyphs make the count
|
||||
* nonzero. A solid white count (>= the band size) would mean the band was not
|
||||
* contrasting, so the gate also requires it below the band size.
|
||||
*/
|
||||
static void text_pixels(Display *d, Window w) {
|
||||
XImage *im = XGetImage(d, w, TEXT_BAND_X, TEXT_BAND_Y, TEXT_BAND_W,
|
||||
TEXT_BAND_H, ~0L, XYPixmap);
|
||||
unsigned int count = 0;
|
||||
int y, x;
|
||||
|
||||
if (!im) {
|
||||
MARK(12) = 0;
|
||||
return;
|
||||
}
|
||||
if (im->data) {
|
||||
for (y = 0; y < TEXT_BAND_H; y++) {
|
||||
unsigned int *row = (unsigned int *)(void *)(im->data +
|
||||
y * im->bytes_per_line);
|
||||
for (x = 0; x < (TEXT_BAND_W / 8) / 4; x++) {
|
||||
unsigned int v = row[x];
|
||||
while (v) {
|
||||
count += v & 1u;
|
||||
v >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
MARK(12) = count;
|
||||
XDestroyImage(im);
|
||||
}
|
||||
|
||||
static void image_roundtrip(Display *d, Window w, GC gc) {
|
||||
char *bytes;
|
||||
XImage *got;
|
||||
unsigned int flags = 0;
|
||||
unsigned int pixel = 0;
|
||||
int i;
|
||||
int destroyed = 0;
|
||||
|
||||
bytes = (char *)malloc(IMG_BPL * IMG_H);
|
||||
if (bytes) {
|
||||
unsigned int *words = (unsigned int *)bytes;
|
||||
for (i = 0; i < (IMG_BPL * IMG_H) / 4; i++)
|
||||
words[i] = 0xFFFFFFFFu;
|
||||
}
|
||||
heap_image = XCreateImage(d, 0, 1, XYBitmap, 0, bytes, IMG_W, IMG_H, 32,
|
||||
IMG_BPL);
|
||||
if (!heap_image) {
|
||||
if (bytes)
|
||||
free(bytes);
|
||||
MARK(7) = 0;
|
||||
return;
|
||||
}
|
||||
flags |= IMG_CREATED;
|
||||
heap_image->byte_order = LSBFirst;
|
||||
heap_image->bitmap_bit_order = LSBFirst;
|
||||
|
||||
/* A 32-bit-aligned destination x (screen 100+20+40 = 160) is required by
|
||||
* the server's 1-bit bitmap copy path, as the M4 xshow client found. */
|
||||
if (XPutImage(d, w, gc, heap_image, 0, 0, 40, 32, IMG_W, IMG_H))
|
||||
flags |= IMG_PUT;
|
||||
|
||||
XSync(d, 0);
|
||||
|
||||
got = XGetImage(d, w, 40, 32, IMG_W, IMG_H, ~0L, XYPixmap);
|
||||
if (!got) {
|
||||
/* The call ran and failed. Destroy our half of the surface and leave
|
||||
* the caller's stage at 12 (the text-pixel step), so the check names
|
||||
* XGetImage. */
|
||||
if (XDestroyImage(heap_image))
|
||||
flags |= IMG_DESTROYED;
|
||||
heap_image = 0;
|
||||
MARK(7) = flags;
|
||||
return;
|
||||
}
|
||||
|
||||
flags |= IMG_GOT | IMG_USABLE;
|
||||
/* The region is all white: the first 32 bits of row 0 are all ones. */
|
||||
if (got->data && *(unsigned int *)(void *)got->data == 0xFFFFFFFFu) {
|
||||
flags |= IMG_PIXEL;
|
||||
pixel = 1;
|
||||
}
|
||||
/* Put the returned heap image back at child x=104 (screen 224). */
|
||||
if (XPutImage(d, w, gc, got, 0, 0, 104, 32, IMG_W, IMG_H))
|
||||
flags |= IMG_PUT;
|
||||
if (XDestroyImage(got))
|
||||
destroyed++;
|
||||
if (XDestroyImage(heap_image))
|
||||
destroyed++;
|
||||
heap_image = 0;
|
||||
if (destroyed == 2)
|
||||
flags |= IMG_DESTROYED;
|
||||
|
||||
MARK(7) = (pixel << 8) | flags;
|
||||
}
|
||||
|
||||
int xmore(void) {
|
||||
Display *d;
|
||||
Window root;
|
||||
Window parent;
|
||||
Window child;
|
||||
GC gc;
|
||||
Font font;
|
||||
XSetWindowAttributes attrs = {0};
|
||||
XWindowChanges wc;
|
||||
int tries;
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= 14; i++)
|
||||
MARK(i) = 0;
|
||||
|
||||
if (!vt_install_xg())
|
||||
return -1;
|
||||
|
||||
d = 0;
|
||||
for (tries = 0; tries < 40; tries++) {
|
||||
d = XOpenDisplay("0::0");
|
||||
if (d)
|
||||
break;
|
||||
vt_sleep(50);
|
||||
}
|
||||
if (!d)
|
||||
return -1;
|
||||
MARK(9) = 1;
|
||||
|
||||
XSetErrorHandler(on_error);
|
||||
prime_blitter();
|
||||
|
||||
root = vt_root(d);
|
||||
parent = XCreateSimpleWindow(d, root, PARENT_X, PARENT_Y, PARENT_W,
|
||||
PARENT_H, 0, 0, 0);
|
||||
MARK(0) = (unsigned)parent;
|
||||
/* Background 1 (white) at creation: CWBackPixel must make it black. */
|
||||
child = XCreateSimpleWindow(d, parent, 40, 40, 240, 160, 0, 0, 1);
|
||||
MARK(1) = (unsigned)child;
|
||||
MARK(9) = 2;
|
||||
|
||||
/* opcode 9: map both the parent's children (the child above). */
|
||||
XMapSubwindows(d, parent);
|
||||
MARK(9) = 3;
|
||||
|
||||
/*
|
||||
* opcode 12 with the ROM's fixed CWX|CWY|CWWidth|CWHeight mask. The
|
||||
* XWindowChanges record holds the same four values; the X11R4 client
|
||||
* API's mask is implied by the entry.
|
||||
*/
|
||||
wc.x = CHILD_X;
|
||||
wc.y = CHILD_Y;
|
||||
wc.width = CHILD_W;
|
||||
wc.height = CHILD_H;
|
||||
wc.border_width = 0;
|
||||
wc.sibling = 0;
|
||||
wc.stack_mode = 0;
|
||||
XConfigureWindow(d, child, wc.x, wc.y, (unsigned int)wc.width,
|
||||
(unsigned int)wc.height);
|
||||
/*
|
||||
* The configure marker is client-computed: it records the four values
|
||||
* passed to the ROM builder. The move is pixel-proven below; the size is
|
||||
* not read back from the server.
|
||||
*/
|
||||
MARK(5) = ((unsigned int)wc.width << 16) | (unsigned int)wc.height;
|
||||
MARK(9) = 4;
|
||||
|
||||
/*
|
||||
* The property value first goes through the predefined XA_WM_NAME atom,
|
||||
* so the XChangeProperty surface is exercised even if XInternAtom cannot
|
||||
* complete below. Marker 4 is a plain post-call flag: the ROM builder
|
||||
* never sets A8, so there is no return value or server read-back; zero X
|
||||
* errors is the only runtime check.
|
||||
*/
|
||||
XChangeProperty(d, parent, XA_WM_NAME, XA_STRING, 8, PropModeReplace,
|
||||
(const unsigned char *)"xmore", 5);
|
||||
MARK(4) = 1;
|
||||
MARK(9) = 5;
|
||||
|
||||
/* The struct was zero-initialized at its declaration; only
|
||||
* CWBackPixel's byte 4 is selected here. */
|
||||
attrs.background_pixel = 0;
|
||||
XChangeWindowAttributes(d, child, CWBackPixel, &attrs);
|
||||
/* Post-call flag only; the black margin is the real attribute proof. */
|
||||
MARK(10) = 1;
|
||||
MARK(9) = 6;
|
||||
|
||||
/*
|
||||
* Map the top-level parent after the child is mapped, then let the WM
|
||||
* frame it before drawing: an X11 map fills the background and would
|
||||
* erase anything drawn while the window is still unmapped.
|
||||
*/
|
||||
XMapWindow(d, parent);
|
||||
XSync(d, 0);
|
||||
vt_sleep(300);
|
||||
MARK(9) = 7;
|
||||
|
||||
font = XLoadFont(d, "fixed");
|
||||
MARK(6) = (unsigned)font;
|
||||
MARK(9) = 8;
|
||||
|
||||
/*
|
||||
* The GC uses the server's default font. XLoadFont is still exercised
|
||||
* above (marker 6); its returned value is a ROM font handle, not the
|
||||
* server font XID, so passing it as GCFont makes CreateGC fail BadFont.
|
||||
* The default GC font is the 6x13 cell the termtris client documents.
|
||||
*/
|
||||
gc = XCreateGC(d, child, 0, 0);
|
||||
MARK(2) = (unsigned)gc;
|
||||
MARK(9) = 9;
|
||||
|
||||
clear_black(d, child, gc);
|
||||
MARK(9) = 10;
|
||||
|
||||
draw_white(d, child, gc);
|
||||
MARK(9) = 11;
|
||||
|
||||
/* XGetImage the text band and count its white pixels (marker 12). */
|
||||
text_pixels(d, child);
|
||||
MARK(9) = 12;
|
||||
|
||||
image_roundtrip(d, child, gc);
|
||||
/* Only a usable XGetImage advances the image stage. */
|
||||
if ((MARK(7) & IMG_USABLE) != 0) {
|
||||
XSync(d, 0);
|
||||
MARK(8) = (unsigned)xerrors;
|
||||
MARK(9) = 13;
|
||||
} else {
|
||||
MARK(8) = (unsigned)xerrors;
|
||||
}
|
||||
|
||||
/*
|
||||
* Last: the InternAtom surface. The skip marker and the live Display
|
||||
* pointer are written before the call so a blocked _XSend still leaves
|
||||
* the documented state behind. The marker proves only that the
|
||||
* connection was live before the call; entry into the ROM function is
|
||||
* not proven by it (the report's isolated probe is narrative evidence).
|
||||
*/
|
||||
MARK(13) = (unsigned)d;
|
||||
MARK(11) = gc_changes;
|
||||
MARK(14) = ((unsigned)FILL_W << 16) | (unsigned)FILL_H;
|
||||
MARK(3) = INTERNATOM_SKIPPED;
|
||||
MARK(9) = 14;
|
||||
{
|
||||
Atom a = XInternAtom(d, "WM_NAME", False);
|
||||
|
||||
if (a) {
|
||||
MARK(3) = (unsigned)a;
|
||||
XChangeProperty(d, parent, a, XA_STRING, 8, PropModeReplace,
|
||||
(const unsigned char *)"xmore", 5);
|
||||
MARK(4) = 1;
|
||||
MARK(9) = 15;
|
||||
} else {
|
||||
MARK(3) = INTERNATOM_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not return: returning tears the process (and its windows) down before
|
||||
* the harness reads the markers and VRAM. Keep the connection drained and
|
||||
* hold the last completed stage so a failed call stays visible.
|
||||
*/
|
||||
for (;;) {
|
||||
MARK(8) = (unsigned)xerrors;
|
||||
MARK(11) = gc_changes;
|
||||
XFlush(d);
|
||||
vt_sleep(5);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
int debug_a_base = 3;
|
||||
|
||||
int debug_a_mul(void) {
|
||||
int product = debug_a_base * 7;
|
||||
return product + 1;
|
||||
}
|
||||
|
||||
int debug_a_add(void) {
|
||||
int sum = debug_a_base + 4;
|
||||
return sum * 2;
|
||||
}
|
||||
|
||||
/* M8.2 multi-TU debug gate, first translation unit.
|
||||
*
|
||||
* Two functions with distinct source lines; debug_a_mul returns 22 and
|
||||
* debug_a_add returns 14. debug-b.c is the second debug-bearing TU, and
|
||||
* debug-entry.asm calls all four functions so the linked image exercises both
|
||||
* units at runtime. The comment is after the code so the line numbers used by
|
||||
* dwarf-multi.sh stay stable.
|
||||
*/
|
||||
@@ -0,0 +1,19 @@
|
||||
int debug_b_base = 5;
|
||||
|
||||
int debug_b_sub(void) {
|
||||
int diff = debug_b_base - 2;
|
||||
return diff * 3;
|
||||
}
|
||||
|
||||
int debug_b_mul(void) {
|
||||
int factor = debug_b_base + 1;
|
||||
return factor * factor;
|
||||
}
|
||||
|
||||
/* M8.2 multi-TU debug gate, second translation unit.
|
||||
*
|
||||
* debug_b_sub returns 9 and debug_b_mul returns 36. The TU's `.text` is
|
||||
* concatenated after debug-a.c's, so its functions and DWARF addresses are at
|
||||
* nonzero text offsets; dwarf-multi.sh asserts the rehomed CU/section bases
|
||||
* and the linked low PCs.
|
||||
*/
|
||||
@@ -0,0 +1,31 @@
|
||||
; debug-entry.asm -- M8.2 multi-TU debug gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; debug-a.o is linked first and debug-b.o second, so debug_a_mul is the text
|
||||
; origin function (DWARF low PC 0x314000), debug-b's functions are at nonzero
|
||||
; text offsets, and _start follows both TUs. The entry calls all four
|
||||
; functions and stores their results (22, 14, 9, 36) at 018A8000, 018A8020,
|
||||
; 018A8040 and 018A8060; debug-multi-check.lua reads them after the stripped
|
||||
; image loads.
|
||||
.ref _debug_a_mul
|
||||
.ref _debug_a_add
|
||||
.ref _debug_b_sub
|
||||
.ref _debug_b_mul
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16,1,0
|
||||
setf 32,0,1
|
||||
movi _cstack,a14
|
||||
move a14,a13
|
||||
calla _debug_a_mul
|
||||
move a8,@018A8000h,1
|
||||
calla _debug_a_add
|
||||
move a8,@018A8020h,1
|
||||
calla _debug_b_sub
|
||||
move a8,@018A8040h,1
|
||||
calla _debug_b_mul
|
||||
move a8,@018A8060h,1
|
||||
rets
|
||||
|
||||
.bss _cstack,32768,16
|
||||
.end
|
||||
@@ -0,0 +1,19 @@
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
local frames = 0
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == tonumber(os.getenv("LOADER_END") or "2700") - 1 then
|
||||
local prog = manager.machine.devices[':maincpu'].spaces['program']
|
||||
local a_mul = prog:read_u32(0x018A8000)
|
||||
local a_add = prog:read_u32(0x018A8020)
|
||||
local b_sub = prog:read_u32(0x018A8040)
|
||||
local b_mul = prog:read_u32(0x018A8060)
|
||||
print(string.format("DEBUG MULTI: a_mul=%d a_add=%d b_sub=%d b_mul=%d",
|
||||
a_mul, a_add, b_sub, b_mul))
|
||||
if a_mul == 22 and a_add == 14 and b_sub == 9 and b_mul == 36 then
|
||||
print("DEBUG MULTI MAME: PASS")
|
||||
else
|
||||
print("DEBUG MULTI MAME: FAIL (want 22/14/9/36)")
|
||||
end
|
||||
end
|
||||
end, "debug-multi-check")
|
||||
@@ -0,0 +1,34 @@
|
||||
-- lib-check.lua -- read the M8 native-library gate marker words.
|
||||
--
|
||||
-- The driver writes five words at 018A8000 + n*0x20:
|
||||
-- 0: (int)(1.5 + 2.5) == 4 (flib FD$ADD + FD$DTOI)
|
||||
-- 1: (int)(1.5 * 2.5) == 3 (flib FD$MUL + FD$DTOI)
|
||||
-- 2: isascii('A') != 0 (rts.lib _isascii)
|
||||
-- 3: isascii(0xC8) == 0 (rts.lib _isascii)
|
||||
-- 4: 0x4C494231 ("LIB1" sentinel)
|
||||
|
||||
dofile(os.getenv("M4_LOADER_LUA"))
|
||||
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "3400")
|
||||
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 got = {}
|
||||
for i = 0, 4 do
|
||||
got[i] = prog:read_u32(0x018A8000 + i * 0x20)
|
||||
end
|
||||
print(string.format("M8 LIB: sum=%d product=%d asciiA=%d asciiC8=%d sentinel=%08X",
|
||||
got[0], got[1], got[2], got[3], got[4]))
|
||||
if got[0] == 4 and got[1] == 3 and got[2] ~= 0 and
|
||||
got[3] == 0 and got[4] == 0x4C494231 then
|
||||
print("M8 LIB MAME: PASS")
|
||||
else
|
||||
print("M8 LIB MAME: FAIL (want 4 3 nonzero 0 4C494231)")
|
||||
end
|
||||
end
|
||||
end, "m8-lib-check")
|
||||
@@ -0,0 +1,16 @@
|
||||
; lib-entry.asm -- M8 native-library gate entry, linked at bit 018A0000.
|
||||
;
|
||||
; Calls the compiled driver libcheck_test(), which uses flib.lib doubles and
|
||||
; rts.lib _isascii. Marker words live at 018A8000 + n*0x20 and are checked by
|
||||
; lib-check.lua.
|
||||
.text
|
||||
.globl _start
|
||||
_start:
|
||||
setf 16, 1, 0
|
||||
setf 32, 0, 1
|
||||
movi _cstack, a14
|
||||
move a14, a13
|
||||
calla _libcheck_test
|
||||
rets
|
||||
|
||||
.bss _cstack, 32768, 16 ; 32768 bits = 4096 bytes
|
||||
@@ -0,0 +1,26 @@
|
||||
/* M8 native-library gate driver.
|
||||
*
|
||||
* The double operations lower to flib.lib's FD$ADD/FD$MUL and the fptosi
|
||||
* conversions to FD$DTOI; isascii is the rts.lib member. The markers are
|
||||
* fixed bit addresses in the prog region because the linker map's symbol
|
||||
* values are not needed by this tiny check.
|
||||
*/
|
||||
#define MARK(n) (*(volatile unsigned int *)(0x018A8000u + (n) * 0x20u))
|
||||
|
||||
extern int isascii(int);
|
||||
|
||||
static volatile double fa = 1.5;
|
||||
static volatile double fb = 2.5;
|
||||
|
||||
int libcheck_test(void)
|
||||
{
|
||||
double sum = fa + fb;
|
||||
double product = fa * fb;
|
||||
|
||||
MARK(0) = (unsigned)(int)sum; /* 4: FD$ADD + FD$DTOI */
|
||||
MARK(1) = (unsigned)(int)product; /* 3: FD$MUL + FD$DTOI */
|
||||
MARK(2) = (unsigned)isascii('A'); /* 1: rts.lib _isascii */
|
||||
MARK(3) = (unsigned)isascii(0xC8); /* 0: rts.lib _isascii */
|
||||
MARK(4) = 0x4C494231u; /* "LIB1" sentinel */
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#!/bin/sh
|
||||
# os2-toolchain.sh -- run the 1990 TI r5.01 OS/2 tools under 2ine/qemu-i386.
|
||||
#
|
||||
# Sourced by scripts/m4/run.sh when M4_OS2=1. The 1990 tools are 16-bit OS/2
|
||||
# 1.x NE programs; the patched 2ine loader runs them on a 64-bit Linux host
|
||||
# via qemu-i386 (the plain lx_loader needs a kernel with 16-bit LDT support).
|
||||
#
|
||||
# Environment:
|
||||
# M4_OS2=1 enable this path
|
||||
# M4_OS2_2INE=PATH 2ine checkout (default /home/arti/os2-work/2ine-tms34010)
|
||||
# M4_OS2_LX=PATH lx_loader (default $2ine/build/lx_loader; the
|
||||
# build-qemu wrapper is the fallback)
|
||||
# M4_OS2_SDK=PATH extracted r5.01 tree with bin/ and lib/
|
||||
# M4_OS2_ROOT=PATH parent of the default 2ine/os2-501 (default /home/arti/os2-work)
|
||||
#
|
||||
# The functions expect run.sh globals: WORK, SDK, fail, NATIVE_OBJS,
|
||||
# NATIVE_LIBS. Outputs are copied back with the uppercase names run.sh uses.
|
||||
|
||||
os2_init() {
|
||||
OS2_2INE=${M4_OS2_2INE:-${M4_OS2_ROOT:-/home/arti/os2-work}/2ine-tms34010}
|
||||
OS2_LX=${M4_OS2_LX:-$OS2_2INE/build/lx_loader}
|
||||
if [ ! -x "$OS2_LX" ] && [ -x "$OS2_2INE/build-qemu/lx_loader" ]; then
|
||||
OS2_LX=$OS2_2INE/build-qemu/lx_loader
|
||||
fi
|
||||
OS2_SDK=${M4_OS2_SDK:-${M4_OS2_ROOT:-/home/arti/os2-work}/os2-501}
|
||||
|
||||
[ -x "$OS2_LX" ] || fail "M4_OS2=1: missing 2ine lx_loader: $OS2_LX (run scripts/m8/setup-os2.sh)"
|
||||
[ -f "$OS2_SDK/bin/gspa.exe" ] \
|
||||
|| fail "M4_OS2=1: missing OS/2 gspa.exe under $OS2_SDK/bin (run scripts/m8/setup-os2.sh)"
|
||||
case $OS2_LX in
|
||||
*/build-qemu/*)
|
||||
command -v qemu-i386 >/dev/null 2>&1 \
|
||||
|| fail "M4_OS2=1: qemu-i386 is required for the build-qemu wrapper" ;;
|
||||
esac
|
||||
|
||||
OS2_QEMU=$OS2_2INE/build-qemu/lx_loader
|
||||
OS2_DIR=$WORK/os2
|
||||
rm -rf "$OS2_DIR"
|
||||
mkdir -p "$OS2_DIR"
|
||||
# 2ine loads its OS/2 import modules from the working directory.
|
||||
for so in "$OS2_2INE"/build/lib*.so; do
|
||||
[ -e "$so" ] && ln -sf "$so" "$OS2_DIR/"
|
||||
done
|
||||
cp "$OS2_SDK/bin/gspa.exe" "$OS2_DIR/"
|
||||
cp "$OS2_SDK/bin/gsplnk.exe" "$OS2_DIR/"
|
||||
cp "$OS2_SDK/lib/rts.lib" "$OS2_SDK/lib/flib.lib" "$OS2_DIR/" 2>/dev/null || true
|
||||
}
|
||||
|
||||
os2_gspa() { # os2_gspa NAME (M4 or M4EXT)
|
||||
_name=$1
|
||||
[ -f "$SDK/$_name.ASM" ] || fail "M4_OS2: missing $SDK/$_name.ASM"
|
||||
cp "$SDK/$_name.ASM" "$OS2_DIR/$_name.ASM"
|
||||
|
||||
_gspa() { # _gspa LX
|
||||
( cd "$OS2_DIR" && \
|
||||
"$1" ./gspa.exe "$_name.ASM" "$_name.obj" "$_name.lst" -l \
|
||||
) > "$OS2_DIR/$_name.gspa.log" 2>&1 || true
|
||||
}
|
||||
rm -f "$OS2_DIR/$_name.lst" "$OS2_DIR/$_name.obj"
|
||||
_gspa "$OS2_LX"
|
||||
if ! grep -q 'No Errors' "$OS2_DIR/$_name.lst" 2>/dev/null; then
|
||||
# The direct 2ine loader can hit its segment assertion on some large
|
||||
# inputs; qemu-i386 is the reliable fallback.
|
||||
if [ -x "$OS2_QEMU" ] && [ "$OS2_LX" != "$OS2_QEMU" ]; then
|
||||
echo " note: direct 2ine gspa failed; retrying under qemu" >&2
|
||||
_gspa "$OS2_QEMU"
|
||||
fi
|
||||
fi
|
||||
grep -q 'No Errors' "$OS2_DIR/$_name.lst" 2>/dev/null || {
|
||||
cat "$OS2_DIR/$_name.gspa.log" >&2
|
||||
fail "OS/2 gspa failed for $_name"
|
||||
}
|
||||
cp "$OS2_DIR/$_name.obj" "$SDK/$_name.OBJ"
|
||||
cp "$OS2_DIR/$_name.lst" "$SDK/$_name.LST"
|
||||
}
|
||||
|
||||
os2_gsplnk() {
|
||||
# Copy every object the linker command may reference, plus the lowercase
|
||||
# library names the 5.01 command file uses.
|
||||
for obj in "$SDK"/*.OBJ "$SDK"/*.obj; do
|
||||
[ -e "$obj" ] && cp "$obj" "$OS2_DIR/"
|
||||
done
|
||||
# Copy every library the command file may reference; the 1987/1990 files
|
||||
# are uppercase on disk while the linker command uses lowercase names.
|
||||
for lib in "$SDK"/*.LIB "$SDK"/*.lib; do
|
||||
[ -e "$lib" ] || continue
|
||||
_low=$(basename "$lib" | tr '[:upper:]' '[:lower:]')
|
||||
cp "$lib" "$OS2_DIR/$_low"
|
||||
done
|
||||
cp "$SDK/M4.CMD" "$OS2_DIR/M4.CMD"
|
||||
rm -f "$OS2_DIR/M4.OUT" "$OS2_DIR/M4.MAP"
|
||||
_gsplnk() {
|
||||
( cd "$OS2_DIR" && "$1" ./gsplnk.exe M4.CMD ) \
|
||||
> "$OS2_DIR/M4.gsplnk.log" 2>&1 || true
|
||||
}
|
||||
_gsplnk "$OS2_LX"
|
||||
if [ ! -f "$OS2_DIR/M4.OUT" ] && [ -x "$OS2_QEMU" ] \
|
||||
&& [ "$OS2_LX" != "$OS2_QEMU" ]; then
|
||||
echo " note: direct 2ine gsplnk failed; retrying under qemu" >&2
|
||||
_gsplnk "$OS2_QEMU"
|
||||
fi
|
||||
[ -f "$OS2_DIR/M4.OUT" ] || {
|
||||
cat "$OS2_DIR/M4.gsplnk.log" >&2
|
||||
fail "OS/2 gsplnk failed"
|
||||
}
|
||||
cp "$OS2_DIR/M4.OUT" "$SDK/M4.OUT"
|
||||
cp "$OS2_DIR/M4.MAP" "$SDK/M4.MAP"
|
||||
}
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
#!/bin/sh
|
||||
# setup-os2.sh -- provision the 1990 TI r5.01 OS/2 toolchain for the harness.
|
||||
#
|
||||
# The r5.01 tools are 16-bit OS/2 1.x NE console programs. They run on a
|
||||
# 64-bit Linux host through the patched 2ine loader under qemu-i386 (the plain
|
||||
# lx_loader needs a kernel with 16-bit LDT support; qemu-i386 provides it).
|
||||
#
|
||||
# scripts/m8/setup-os2.sh
|
||||
#
|
||||
# Environment:
|
||||
# M4_OS2_ROOT install root (default $HOME/os2-work)
|
||||
# M4_OS2_2INE 2ine checkout (default $M4_OS2_ROOT/2ine-tms34010)
|
||||
# M4_OS2_SDK extracted r5.01 tree (default $M4_OS2_ROOT/os2-501)
|
||||
#
|
||||
# Then run gates with M4_OS2=1 (and optionally M4_LINKER=tms-link). The
|
||||
# default harness remains the 1987 DOSBox GSPA/GSPLNK oracle.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
OS2_ROOT=${M4_OS2_ROOT:-$HOME/os2-work}
|
||||
TWOINE=${M4_OS2_2INE:-$OS2_ROOT/2ine-tms34010}
|
||||
SDK=${M4_OS2_SDK:-$OS2_ROOT/os2-501}
|
||||
SDK_SRC="$ROOT/vendor/vt1200/tools/tms34010-sdk/1990-11 TMS340 Family SDK"
|
||||
|
||||
fail() { echo "setup-os2: FAIL: $*" >&2; exit 1; }
|
||||
|
||||
command -v git >/dev/null 2>&1 || fail "git is required"
|
||||
command -v cmake >/dev/null 2>&1 || fail "cmake is required"
|
||||
command -v unzip >/dev/null 2>&1 || fail "unzip is required"
|
||||
# The direct loader is preferred; qemu-i386 is only needed as a fallback on
|
||||
# kernels without 16-bit LDT support.
|
||||
|
||||
|
||||
if [ ! -x "$TWOINE/build/lx_loader" ]; then
|
||||
echo "== clone and build 2ine-tms34010 into $TWOINE"
|
||||
mkdir -p "$(dirname "$TWOINE")"
|
||||
[ -d "$TWOINE/.git" ] || \
|
||||
git clone https://git.wut.ee/opencode.energia.arti.ee/2ine-tms34010.git "$TWOINE"
|
||||
cmake -S "$TWOINE" -B "$TWOINE/build" -DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_POLICY_VERSION_MINIMUM=3.5
|
||||
cmake --build "$TWOINE/build" -j"${JOBS:-$(nproc)}"
|
||||
fi
|
||||
|
||||
LX=${M4_OS2_LX:-$TWOINE/build/lx_loader}
|
||||
if [ ! -x "$LX" ]; then
|
||||
# Kernel fallback: wrap the loader in qemu-i386 (which provides 16-bit LDT
|
||||
# support even when CONFIG_X86_16BIT is off).
|
||||
command -v qemu-i386 >/dev/null 2>&1 \
|
||||
|| fail "lx_loader is missing and qemu-i386 is unavailable"
|
||||
mkdir -p "$TWOINE/build-qemu"
|
||||
cat > "$TWOINE/build-qemu/lx_loader" <<EOF
|
||||
#!/bin/sh
|
||||
exec qemu-i386 "$TWOINE/build/lx_loader" "\$@"
|
||||
EOF
|
||||
chmod +x "$TWOINE/build-qemu/lx_loader"
|
||||
LX=$TWOINE/build-qemu/lx_loader
|
||||
fi
|
||||
|
||||
if [ ! -f "$SDK/bin/gspa.exe" ]; then
|
||||
echo "== extract the r5.01 tools into $SDK"
|
||||
[ -f "$SDK_SRC/1990-11-19 TMS340 Family Code Generation Tools (1 of 2) r5.01 rev2564062-1641.zip" ] \
|
||||
|| fail "missing the r5.01 tools zip under $SDK_SRC"
|
||||
mkdir -p "$SDK/bin" "$SDK/lib" "$SDK/work"
|
||||
unzip -oq "$SDK_SRC/1990-11-19 TMS340 Family Code Generation Tools (1 of 2) r5.01 rev2564062-1641.zip" -d "$SDK/bin"
|
||||
unzip -oq "$SDK_SRC/1990-11-19 TMS340 Family Code Generation Tools (2 of 2) r5.01 rev2564062-1641.zip" -d "$SDK/lib"
|
||||
fi
|
||||
|
||||
[ -f "$SDK/bin/gspa.exe" ] || fail "gspa.exe missing after extraction"
|
||||
[ -x "$LX" ] || fail "lx_loader missing: $LX"
|
||||
|
||||
# Smoke test: assemble an empty source in a throw-away work dir.
|
||||
TMP=$(mktemp -d "$OS2_ROOT/os2-smoke.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
for so in "$TWOINE"/build/lib*.so; do [ -e "$so" ] && ln -sf "$so" "$TMP/"; done
|
||||
cp "$SDK/bin/gspa.exe" "$TMP/"
|
||||
: > "$TMP/t.asm"
|
||||
( cd "$TMP" && "$LX" ./gspa.exe t.asm > gspa.log 2>&1 ) || true
|
||||
if ! grep -q 'No Errors' "$TMP/gspa.log"; then
|
||||
# Retry through qemu if the direct loader cannot allocate 16-bit LDTs.
|
||||
if [ "$LX" = "$TWOINE/build/lx_loader" ] && command -v qemu-i386 >/dev/null 2>&1; then
|
||||
mkdir -p "$TWOINE/build-qemu"
|
||||
cat > "$TWOINE/build-qemu/lx_loader" <<EOF
|
||||
#!/bin/sh
|
||||
exec qemu-i386 "$TWOINE/build/lx_loader" "\$@"
|
||||
EOF
|
||||
chmod +x "$TWOINE/build-qemu/lx_loader"
|
||||
LX=$TWOINE/build-qemu/lx_loader
|
||||
( cd "$TMP" && "$LX" ./gspa.exe t.asm > gspa.log 2>&1 ) || true
|
||||
fi
|
||||
grep -q 'No Errors' "$TMP/gspa.log" \
|
||||
|| { cat "$TMP/gspa.log" >&2; fail "gspa smoke test failed"; }
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
|
||||
OS/2 r5.01 toolchain ready:
|
||||
M4_OS2_ROOT=$OS2_ROOT
|
||||
M4_OS2_2INE=$TWOINE
|
||||
M4_OS2_LX=$LX
|
||||
M4_OS2_SDK=$SDK
|
||||
|
||||
Use it with:
|
||||
M4_OS2=1 scripts/tests/m7/full-suite.sh --corpus all --work build/m8-os2-full
|
||||
M4_OS2=1 M4_LINKER=tms-link scripts/tests/m5/c-torture.sh
|
||||
M4_OS2=1 scripts/m4/run.sh # asm path: OS/2 gspa + OS/2 gsplnk
|
||||
|
||||
The default harness still uses the 1987 DOSBox GSPA/GSPLNK oracle.
|
||||
EOF
|
||||
@@ -0,0 +1,24 @@
|
||||
/* M9.2 range-list fixture A: -O2 -g loop/inlining shape that makes LLVM emit
|
||||
* a non-contiguous DW_TAG_inlined_subroutine and therefore .debug_rnglists.
|
||||
* Compiled by scripts/tests/m9/dwarf-ranges.sh; not a runtime test. */
|
||||
static inline __attribute__((always_inline)) int m9_inc(int x) {
|
||||
if (x & 1)
|
||||
return x + 1;
|
||||
return x + 3;
|
||||
}
|
||||
|
||||
int m9_range_one(int a) {
|
||||
int sum = 0;
|
||||
int i;
|
||||
for (i = 0; i < a; i++)
|
||||
sum += m9_inc(i);
|
||||
return sum;
|
||||
}
|
||||
|
||||
static int m9_helper(int q) {
|
||||
return q * 5;
|
||||
}
|
||||
|
||||
int m9_range_two(int a) {
|
||||
return m9_helper(a) + m9_range_one(a);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/* M9.2 range-list fixture B: a second TU with the same loop/inlining shape so
|
||||
* the multi-TU merge has two .debug_rnglists contributions to rehome. */
|
||||
static inline __attribute__((always_inline)) int m9_dec(int x) {
|
||||
if (x & 2)
|
||||
return x - 1;
|
||||
return x - 3;
|
||||
}
|
||||
|
||||
int m9_range_three(int a) {
|
||||
int sum = 1;
|
||||
for (int i = 0; i < a; i++)
|
||||
sum += m9_dec(i);
|
||||
return sum;
|
||||
}
|
||||
|
||||
int m9_range_four(int a) {
|
||||
return m9_range_three(a) * 3;
|
||||
}
|
||||
Executable
+276
@@ -0,0 +1,276 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Write two TI-COFF objects that actually emit DWARF v5 `.debug_rnglists`.
|
||||
|
||||
The M8 fixtures (-O0 and a straight-line -O2 shape) never emitted a range list,
|
||||
so the merge's `.debug_rnglists` whitelist was untested. This helper emits the
|
||||
section directly: a well-formed CU per object with
|
||||
|
||||
* ``DW_AT_rnglists_base`` (``DW_FORM_sec_offset`` into .debug_rnglists),
|
||||
* ``DW_AT_addr_base`` (``DW_FORM_sec_offset`` into .debug_addr),
|
||||
* ``DW_AT_ranges`` (``DW_FORM_rnglistx`` index 0),
|
||||
* a range list with one ``DW_RLE_start_end`` (absolute, relocated .text
|
||||
addresses) and one ``DW_RLE_startx_length`` (index into .debug_addr),
|
||||
* a subprogram DIE with a relocated ``DW_FORM_addr`` low PC.
|
||||
|
||||
Every section-relative field carries an R-RELLONG relocation, so the objects
|
||||
also pass the form-aware input gate. ``scripts/tests/m9/dwarf-ranges.sh``
|
||||
links them, wraps the result in the M7 ELF container and validates the ranges
|
||||
with ``llvm-dwarfdump``. The same gate also has a real `-O2 -g` producer case
|
||||
(loop/inline shapes can make LLVM emit non-contiguous inlined ranges); this
|
||||
synthetic fixture keeps the `start_end`/`startx_length` and offset-rehoming
|
||||
forms deterministic.
|
||||
|
||||
Usage: dwarf-ranges-fixture.py OUTDIR [--tag AB]
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
MAGIC = 0x0090
|
||||
R_RELLONG = 0x11
|
||||
S_TEXT = 0x20
|
||||
S_DATA = 0x40
|
||||
S_BSS = 0x80
|
||||
C_EXT = 2
|
||||
C_STAT = 3
|
||||
|
||||
TEXT_ORIGIN = 0x018A0000
|
||||
TEXT_BYTES = 16
|
||||
|
||||
|
||||
def uleb(value):
|
||||
out = bytearray()
|
||||
while True:
|
||||
byte = value & 0x7F
|
||||
value >>= 7
|
||||
if value:
|
||||
out.append(byte | 0x80)
|
||||
else:
|
||||
out.append(byte)
|
||||
return bytes(out)
|
||||
|
||||
|
||||
class Section:
|
||||
def __init__(self, name, flags, data=b"", bits=None):
|
||||
self.name = name
|
||||
self.flags = flags
|
||||
self.data = bytearray(data)
|
||||
self.bits = len(self.data) * 8 if bits is None else bits
|
||||
self.relocs = [] # (byte offset, symbol name)
|
||||
|
||||
def reloc(self, offset, symbol):
|
||||
self.relocs.append((offset, symbol))
|
||||
return offset
|
||||
|
||||
|
||||
def debug_abbrev():
|
||||
return (
|
||||
b"\x01\x11\x01" # 1: DW_TAG_compile_unit, children
|
||||
b"\x03\x0e" # DW_AT_name, DW_FORM_strp
|
||||
b"\x73\x17" # DW_AT_addr_base, DW_FORM_sec_offset
|
||||
b"\x74\x17" # DW_AT_rnglists_base, sec_offset
|
||||
b"\x55\x23" # DW_AT_ranges, DW_FORM_rnglistx
|
||||
b"\x00\x00"
|
||||
b"\x02\x2e\x00" # 2: DW_TAG_subprogram, no children
|
||||
b"\x03\x0e" # DW_AT_name, DW_FORM_strp
|
||||
b"\x11\x01" # DW_AT_low_pc, DW_FORM_addr
|
||||
b"\x12\x06" # DW_AT_high_pc, DW_FORM_data4
|
||||
b"\x00\x00"
|
||||
b"\x00")
|
||||
|
||||
|
||||
def build(tag):
|
||||
"""One object whose single function sits at .text offset 0."""
|
||||
cu_name = ("rng-%s.c" % tag).encode("ascii")
|
||||
fn_name = ("rng_" + tag).encode("ascii")
|
||||
strings = cu_name + b"\0" + fn_name + b"\0"
|
||||
cu_off = 0
|
||||
fn_off = len(cu_name) + 1
|
||||
|
||||
sections = [
|
||||
Section(".text", S_TEXT, b"\0" * TEXT_BYTES),
|
||||
Section(".data", S_DATA),
|
||||
Section(".bss", S_BSS, bits=0),
|
||||
]
|
||||
abbrev = Section(".debug_abbrev", 0, debug_abbrev())
|
||||
sections.append(abbrev)
|
||||
|
||||
# .debug_info: v5 CU header + root DIE (code 1) + subprogram (2).
|
||||
info_section = Section(".debug_info", 0, b"\0\0\0\0")
|
||||
info = info_section.data
|
||||
info += struct.pack("<HBB", 5, 1, 4) # version, DW_UT_compile, addrsize
|
||||
info += b"\0\0\0\0" # abbrev offset (relocated)
|
||||
info_section.reloc(8, ".debug_abbrev")
|
||||
|
||||
info += b"\x01" # root DIE
|
||||
info += struct.pack("<I", cu_off) # DW_AT_name -> .debug_str
|
||||
info_section.reloc(len(info) - 4, ".debug_str")
|
||||
info += struct.pack("<I", 8) # DW_AT_addr_base -> .debug_addr
|
||||
info_section.reloc(len(info) - 4, ".debug_addr")
|
||||
info += struct.pack("<I", 12) # DW_AT_rnglists_base -> header end
|
||||
info_section.reloc(len(info) - 4, ".debug_rnglists")
|
||||
info += uleb(0) # DW_AT_ranges, rnglistx index 0
|
||||
info += b"\x02" # subprogram DIE
|
||||
info += struct.pack("<I", fn_off) # DW_AT_name
|
||||
info_section.reloc(len(info) - 4, ".debug_str")
|
||||
info += struct.pack("<I", 0) # DW_AT_low_pc, linked .text
|
||||
info_section.reloc(len(info) - 4, ".text")
|
||||
info += struct.pack("<I", 4) # DW_AT_high_pc (byte size)
|
||||
info += b"\x00" # end of the root's children
|
||||
struct.pack_into("<I", info, 0, len(info) - 4)
|
||||
sections.append(info_section)
|
||||
|
||||
sections.append(Section(".debug_str", 0, strings))
|
||||
|
||||
# .debug_addr: unit header + two 4-byte addresses (text+8, text+12).
|
||||
addr_section = Section(".debug_addr", 0, b"\0\0\0\0")
|
||||
addr = addr_section.data
|
||||
addr += struct.pack("<HBB", 5, 4, 0)
|
||||
for value in (8, 12):
|
||||
addr += struct.pack("<I", value)
|
||||
addr_section.reloc(len(addr) - 4, ".text")
|
||||
struct.pack_into("<I", addr, 0, len(addr) - 4)
|
||||
sections.append(addr_section)
|
||||
|
||||
# .debug_rnglists: header (12 bytes) + one offset entry (base = 12).
|
||||
rng_section = Section(".debug_rnglists", 0, b"\0\0\0\0")
|
||||
rng = rng_section.data
|
||||
rng += struct.pack("<HBB", 5, 4, 0)
|
||||
rng += struct.pack("<I", 1) # offset_entry_count
|
||||
rng += struct.pack("<I", 4) # offset[0]: list at base + 4
|
||||
assert len(rng) == 16, len(rng)
|
||||
rng += b"\x06" # DW_RLE_start_end
|
||||
rng += struct.pack("<I", 0) # start = text + 0
|
||||
rng_section.reloc(len(rng) - 4, ".text")
|
||||
rng += struct.pack("<I", 4) # end = text + 4
|
||||
rng_section.reloc(len(rng) - 4, ".text")
|
||||
rng += b"\x03" + uleb(0) + uleb(4) # DW_RLE_startx_length: addr[0] .. +4
|
||||
rng += b"\x00" # DW_RLE_end_of_list
|
||||
struct.pack_into("<I", rng, 0, len(rng) - 4)
|
||||
sections.append(rng_section)
|
||||
|
||||
# Section sizes were captured at construction; the unit builders above
|
||||
# append to the byte arrays afterwards.
|
||||
for sec in sections:
|
||||
if sec.name != ".bss":
|
||||
sec.bits = len(sec.data) * 8
|
||||
|
||||
return sections
|
||||
|
||||
|
||||
def short_name(name):
|
||||
return len(name.encode("latin1")) <= 8
|
||||
|
||||
|
||||
def write_object(path, sections, tag):
|
||||
"""Serialise one relocatable TI-COFF object.
|
||||
|
||||
Relocation targets are section symbols (matching the LLVM producer), plus
|
||||
an external ``_rng_<tag>`` in .text so the linked image names the function.
|
||||
"""
|
||||
section_symbols = {}
|
||||
symbols = [] # (name, value, secno, class, naux, aux)
|
||||
record = 0
|
||||
for index, sec in enumerate(sections, start=1):
|
||||
section_symbols[sec.name] = record
|
||||
aux = struct.pack("<III", sec.bits, 0, 0).ljust(18, b"\0")
|
||||
symbols.append((sec.name, 0, index, C_STAT, 1, aux))
|
||||
record += 2 # main record + one aux record
|
||||
symbols.append(("_rng_" + tag, 0, 1, C_EXT, 0, b""))
|
||||
record += 1
|
||||
|
||||
string_table = bytearray(b"\0\0\0\0")
|
||||
sec_name_offsets = {}
|
||||
for sec in sections:
|
||||
if not short_name(sec.name):
|
||||
sec_name_offsets[sec.name] = len(string_table)
|
||||
string_table.extend(sec.name.encode("latin1") + b"\0")
|
||||
sym_name_offsets = {}
|
||||
for name, _value, _secno, _class, _naux, _aux in symbols:
|
||||
if not short_name(name):
|
||||
sym_name_offsets[name] = len(string_table)
|
||||
string_table.extend(name.encode("latin1") + b"\0")
|
||||
struct.pack_into("<I", string_table, 0, len(string_table))
|
||||
|
||||
nsyms = sum(1 + naux for _n, _v, _s, _c, naux, _a in symbols)
|
||||
if nsyms != record:
|
||||
raise SystemExit("internal: symbol record count mismatch")
|
||||
header_size = 20 + 40 * len(sections)
|
||||
cursor = header_size
|
||||
payload = []
|
||||
for sec in sections:
|
||||
if sec.bits and sec.name != ".bss":
|
||||
payload.append(cursor)
|
||||
cursor += len(sec.data)
|
||||
else:
|
||||
payload.append(0)
|
||||
relptr = []
|
||||
for sec in sections:
|
||||
if sec.relocs:
|
||||
relptr.append(cursor)
|
||||
cursor += 10 * len(sec.relocs)
|
||||
else:
|
||||
relptr.append(0)
|
||||
symptr = cursor
|
||||
cursor += nsyms * 18 + len(string_table)
|
||||
|
||||
out = bytearray()
|
||||
out.extend(struct.pack("<HHIIIHH", MAGIC, len(sections), 0, symptr,
|
||||
nsyms, 0, 0))
|
||||
for sec, ptr, rptr in zip(sections, payload, relptr):
|
||||
if short_name(sec.name):
|
||||
raw_name = sec.name.encode("latin1").ljust(8, b"\0")
|
||||
else:
|
||||
raw_name = ("/%d" % sec_name_offsets[sec.name]).encode("ascii")
|
||||
out.extend(raw_name.ljust(8, b"\0"))
|
||||
out.extend(struct.pack("<IIIIIIHHI", 0, 0, sec.bits, ptr, rptr, 0,
|
||||
len(sec.relocs), 0, sec.flags))
|
||||
for sec, ptr in zip(sections, payload):
|
||||
if ptr:
|
||||
out.extend(sec.data)
|
||||
for sec, rptr in zip(sections, relptr):
|
||||
if not rptr:
|
||||
continue
|
||||
for offset, name in sec.relocs:
|
||||
out.extend(struct.pack("<IIH", offset * 8,
|
||||
section_symbols[name], R_RELLONG))
|
||||
for name, value, secno, sclass, naux, aux in symbols:
|
||||
if short_name(name):
|
||||
raw_name = name.encode("latin1").ljust(8, b"\0")
|
||||
else:
|
||||
raw_name = b"\0\0\0\0" + struct.pack("<I", sym_name_offsets[name])
|
||||
out.extend(raw_name)
|
||||
out.extend(struct.pack("<IhHBB", value, secno, 0, sclass, naux))
|
||||
out.extend(aux)
|
||||
out.extend(string_table)
|
||||
|
||||
if len(out) != cursor:
|
||||
raise SystemExit("internal: %s size %d != planned %d"
|
||||
% (path, len(out), cursor))
|
||||
with open(path, "wb") as fh:
|
||||
fh.write(out)
|
||||
return len(out)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("outdir", metavar="OUTDIR")
|
||||
parser.add_argument("--tag", default="ab",
|
||||
help="the two single-letter tags")
|
||||
args = parser.parse_args(argv)
|
||||
if len(args.tag) != 2:
|
||||
parser.error("--tag must be two characters (one per object)")
|
||||
os.makedirs(args.outdir, exist_ok=True)
|
||||
for tag in args.tag:
|
||||
path = os.path.join(args.outdir, "rng-%s.o" % tag)
|
||||
size = write_object(path, build(tag), tag)
|
||||
print("dwarf-ranges-fixture: %s (%d bytes, .text %d bits)"
|
||||
% (path, size, TEXT_BYTES * 8))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -3,3 +3,9 @@ int int_diff4(int *p) { return (int)(p + 1) - (int)p; }
|
||||
long pd_char(char *a, char *b) { return a - b; }
|
||||
long pd_int(int *a, int *b) { return a - b; }
|
||||
int late(char *p, char *q) { return (char *)((unsigned)p + 24) == q; }
|
||||
int late64(char *p, char *q) {
|
||||
return (char *)((unsigned long long)(unsigned)p + 24) == q;
|
||||
}
|
||||
int late64s(char *p, char *q) {
|
||||
return (char *)((long long)(int)p + 24) == q;
|
||||
}
|
||||
+35
-3
@@ -13,14 +13,46 @@ grep -A2 'define.*@int_diff(' "$OUT/pdiff.ll" | grep -q 'ret i32 8'
|
||||
grep -A2 'define.*@int_diff4' "$OUT/pdiff.ll" | grep -q 'ret i32 32'
|
||||
grep -A6 'define.*@pd_char' "$OUT/pdiff.ll" | grep -Eq 'sdiv|ashr|udiv'
|
||||
grep -A6 'define.*@pd_int' "$OUT/pdiff.ll" | grep -Eq 'sdiv|ashr|udiv'
|
||||
grep -Eq 'add i32 %bit.base[0-9]*, 24' "$OUT/pdiff.ll"
|
||||
# The final instcombine canonicalizes the lowered `inttoptr(add(ptrtoint, 24))`
|
||||
# into `getelementptr i8, %p, 24`; llc treats a GEP index as a bit offset, so
|
||||
# either shape carries the M0 24-bit addend. Scope the positive to `late`
|
||||
# itself (the identical `late64` line must not satisfy it); keep the 192
|
||||
# rejection file-wide.
|
||||
grep -A6 'define.*@late(' "$OUT/pdiff.ll" \
|
||||
| grep -Eq 'add i32 %bit\.base[0-9]*, 24|getelementptr i8, ptr %p, i32 24'
|
||||
if grep -Eq 'add i32 %bit\.base[0-9]*, 192|getelementptr i8, ptr %p, i32 192' \
|
||||
"$OUT/pdiff.ll"; then
|
||||
echo "M0 pipeline: FAIL: late GEP was scaled twice (192)" >&2
|
||||
exit 1
|
||||
fi
|
||||
# The 64-bit pointer-int shapes (`(unsigned long long)(unsigned)p + 24` and
|
||||
# `(long long)(int)p + 24`) must take the same 24-bit low word, not 192.
|
||||
for fn in late64 late64s; do
|
||||
grep -A6 "define.*@$fn(" "$OUT/pdiff.ll" \
|
||||
| grep -Eq 'add i32 %bit\.base[0-9]*, 24|getelementptr i8, ptr %p, i32 24'
|
||||
if grep -A6 "define.*@$fn(" "$OUT/pdiff.ll" \
|
||||
| grep -Eq 'add i32 %bit\.base[0-9]*, 192|getelementptr i8, ptr %p, i32 192'; then
|
||||
echo "M0 pipeline: FAIL: $fn over-scaled to 192" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
"$TMS_OPT" -passes=verify -disable-output "$OUT/pdiff.ll"
|
||||
|
||||
"$ROOT/scripts/tms-clang" -O2 -I "$ROOT/spike" -o "$OUT/xclient.ll" "$ROOT/spike/xclient.c"
|
||||
test "$(grep -c getelementptr "$OUT/xclient.ll")" -eq 0
|
||||
# The M7.1 barrier is gone after lowering, and any GEP the final instcombine
|
||||
# creates from a lowered inttoptr is the `i8` bit-index form. A typed GEP here
|
||||
# would mean a byte offset escaped the post-opt --scale.
|
||||
if grep -q '__tms_bitptr' "$OUT/xclient.ll"; then
|
||||
echo "M0 pipeline: FAIL: __tms_bitptr was not lowered" >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep 'getelementptr' "$OUT/xclient.ll" | grep -qv 'getelementptr i8'; then
|
||||
echo "M0 pipeline: FAIL: a typed (byte) GEP escaped the post-opt scale" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -Eq 'add i32 %bit.base[0-9]*, 1056' "$OUT/xclient.ll"
|
||||
grep -Eq 'mul i32 [^,]+, 640' "$OUT/xclient.ll"
|
||||
grep -Eq 'add i32 %bit.addr[0-9]*, 320' "$OUT/xclient.ll"
|
||||
grep -Eq 'add i32 %bit\.(base|addr)[0-9]*, 320' "$OUT/xclient.ll"
|
||||
"$TMS_OPT" -passes=verify -disable-output "$OUT/xclient.ll"
|
||||
|
||||
"$ROOT/scripts/tms-clang" -O0 -o "$OUT/pdiff.o0.ll" "$ROOT/scripts/tests/m0/ptrdiff.c"
|
||||
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
#!/bin/sh
|
||||
# M10 Task 3 gate: bit-address pipeline idempotency and the codegen safety net.
|
||||
#
|
||||
# scripts/tests/m10/bitaddr-idempotent.sh
|
||||
#
|
||||
# Task 3 records the bit-address barrier/lowering lifecycle in the module flag
|
||||
# "tms.bitaddr" (1 = barriered, not lowered; 2 = lowered/final) and adds a
|
||||
# legacy codegen pass so a module that still holds an @__tms_bitptr call when it
|
||||
# reaches llc is lowered instead of emitted as a CALLA. This gate checks:
|
||||
#
|
||||
# 1. clang --target=tms34010 -O0 -S -emit-llvm on a pointer file leaves the
|
||||
# module flagged "tms.bitaddr" = 2 (lowered) with no @__tms_bitptr call;
|
||||
# 2. re-running the identical command produces byte-identical IR (idempotent);
|
||||
# 3. llc emits ADDI 32 for p[1] (a bit offset, not the byte offset 4);
|
||||
# 4. clang -c produces a TI-COFF object starting with the 0x0090 magic.
|
||||
#
|
||||
# Step 4 asserts the TI-COFF magic directly rather than running
|
||||
# scripts/m4/coff-check.py: that validator is linked-image specific (it requires
|
||||
# GSPLNK's optional header) and rejects a plain object ("invalid header
|
||||
# nscns=... opthdr=0").
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC M10_BITADDR_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
WORK=${M10_BITADDR_WORK:-$ROOT/build/m10-bitaddr-idempotent}
|
||||
|
||||
fail() {
|
||||
echo "m10 bitaddr idempotent: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$CLANG" ] || fail "missing clang: $CLANG (build the fork or set CLANG=...)"
|
||||
[ -x "$LLC" ] || fail "missing llc: $LLC (build the fork or set LLC=...)"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
cat > "$WORK/src.c" <<'EOF'
|
||||
int load_i(int *p) { return p[1]; }
|
||||
EOF
|
||||
|
||||
echo "== clang -O0 -S -emit-llvm (run1) -> flag 2, no barrier"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -o "$WORK/run1.ll" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -S -emit-llvm failed"
|
||||
grep -q '"tms.bitaddr", i32 2' "$WORK/run1.ll" \
|
||||
|| { grep -n 'tms.bitaddr\|__tms_bitptr' "$WORK/run1.ll" >&2 || true; \
|
||||
fail "run1.ll does not carry tms.bitaddr = 2"; }
|
||||
if grep -q '__tms_bitptr' "$WORK/run1.ll"; then
|
||||
fail "run1.ll still contains @__tms_bitptr (the barrier was not lowered)"
|
||||
fi
|
||||
|
||||
echo "== re-run the identical command -> byte-identical IR"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -o "$WORK/run2.ll" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -S -emit-llvm (run2) failed"
|
||||
cmp "$WORK/run1.ll" "$WORK/run2.ll" \
|
||||
|| fail "the second compile is not byte-identical (not idempotent)"
|
||||
|
||||
# Re-entry: feed the already-lowered IR back through clang as IR input. The
|
||||
# barrier must see "tms.bitaddr" = 2 and skip, and the lowering must see a value
|
||||
# other than 1 and skip, so the re-entered module keeps flag 2, has no
|
||||
# @__tms_bitptr call, and is unchanged except for the ModuleID (which is the
|
||||
# input file's path, not the original source's).
|
||||
echo "== re-enter the lowered IR through clang -x ir -> still flag 2, unchanged"
|
||||
"$CLANG" --target=tms34010 -O0 -S -emit-llvm -x ir \
|
||||
-o "$WORK/reentered.ll" "$WORK/run1.ll" \
|
||||
|| fail "clang -O0 -S -emit-llvm -x ir failed on run1.ll"
|
||||
grep -q '"tms.bitaddr", i32 2' "$WORK/reentered.ll" \
|
||||
|| fail "reentered.ll does not carry tms.bitaddr = 2"
|
||||
if grep -q '__tms_bitptr' "$WORK/reentered.ll"; then
|
||||
fail "reentered.ll still contains @__tms_bitptr (the barrier was re-applied)"
|
||||
fi
|
||||
grep -v '^; ModuleID' "$WORK/run1.ll" > "$WORK/run1.noid"
|
||||
grep -v '^; ModuleID' "$WORK/reentered.ll" > "$WORK/reentered.noid"
|
||||
cmp "$WORK/run1.noid" "$WORK/reentered.noid" \
|
||||
|| fail "the re-entered IR differs beyond the ModuleID line"
|
||||
|
||||
echo "== llc emits ADDI 32 for p[1] from the flagged IR"
|
||||
"$LLC" -march=tms34010 -O0 -filetype=asm -o "$WORK/run1.s" "$WORK/run1.ll" \
|
||||
|| fail "llc -filetype=asm failed on run1.ll"
|
||||
grep -Eq '^[[:space:]]*ADDI[[:space:]]+32([^0-9]|$)' "$WORK/run1.s" \
|
||||
|| { cat "$WORK/run1.s" >&2; fail "run1.s lacks ADDI 32 for p[1]"; }
|
||||
if grep -Eq '^[[:space:]]*ADDI[[:space:]]+4([^0-9]|$)' "$WORK/run1.s"; then
|
||||
cat "$WORK/run1.s" >&2
|
||||
fail "run1.s emits ADDI 4 (a byte offset, not the bit offset 32)"
|
||||
fi
|
||||
|
||||
echo "== clang -c produces a TI-COFF object with the 0x0090 magic"
|
||||
"$CLANG" --target=tms34010 -O0 -c -o "$WORK/native.o" "$WORK/src.c" \
|
||||
|| fail "clang -O0 -c failed"
|
||||
python3 - "$WORK/native.o" <<'PY' || fail "native.o magic is wrong"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if not data:
|
||||
sys.exit("native.o is empty")
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
print(" native.o: %d bytes, TI-COFF magic 90 00" % len(data))
|
||||
PY
|
||||
|
||||
echo "m10 bitaddr idempotent: PASS"
|
||||
Executable
+179
@@ -0,0 +1,179 @@
|
||||
#!/bin/sh
|
||||
# M10 Task 4 gate: native/legacy object equivalence at -O0, and -O2 shape pinning.
|
||||
#
|
||||
# scripts/tests/m10/equivalence.sh
|
||||
#
|
||||
# Phase 1 (byte identity): every corpus translation unit is compiled twice and
|
||||
# the objects must be byte-identical:
|
||||
#
|
||||
# native: clang --target=tms34010 -O0 [-g] -c "$f" -o native.o
|
||||
# legacy: scripts/tests/m10/legacy-tms-clang -O0 [-g] -o legacy.ll "$f"
|
||||
# then llc -march=tms34010 -O0 -filetype=obj legacy.ll -o legacy.o
|
||||
#
|
||||
# The frozen legacy-tms-clang (byte-identical to the m9 tms-clang) is the oracle;
|
||||
# native clang must reproduce it exactly. The corpus is every *.c in scripts/m4,
|
||||
# scripts/m5 and scripts/m6 plus the M5 conformance shim and heap. layout-ti.c is
|
||||
# excluded: it is the 1987 TI compiler's reference source (a union/struct tag
|
||||
# reuse modern clang rejects) whose output layout-ti.s is the golden for
|
||||
# scripts/tests/m4/layout.sh; it is not a clang-compilable input.
|
||||
#
|
||||
# Phase 2 (behaviour): a heredoc fixture is compiled at -O2 and its asm shapes are
|
||||
# FileChecked to pin the post-optimizer scaling pass on optimizer-created GEPs
|
||||
# (SROA aggregate strides, switch tables, aggregate-return .fca.N.gep loads).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC FILECHECK M10_EQUIV_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
FILECHECK=${FILECHECK:-$LLVM_BIN/FileCheck}
|
||||
LEGACY=$ROOT/scripts/tests/m10/legacy-tms-clang
|
||||
WORK=${M10_EQUIV_WORK:-$ROOT/build/m10-equivalence}
|
||||
INC=$ROOT/sdk/include
|
||||
|
||||
# The frozen legacy script derives its ROOT from its own path
|
||||
# (scripts/tests/m10), so its default tool paths are wrong. Point it at the real
|
||||
# build tools explicitly. TMS_OPT is only consulted for the -O2 branch the
|
||||
# gate never uses, but the script's tool check requires it to exist.
|
||||
export TMS_CLANG=$CLANG
|
||||
export TMS_OPT=$LLVM_BIN/opt
|
||||
export TMS_BITADDR=$ROOT/tools/tms-bitaddr/tms-bitaddr
|
||||
|
||||
fail() {
|
||||
echo "m10 equivalence: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
[ -x "$CLANG" ] || fail "missing clang: $CLANG (build the fork or set CLANG=...)"
|
||||
[ -x "$LLC" ] || fail "missing llc: $LLC (build the fork or set LLC=...)"
|
||||
[ -x "$FILECHECK" ] || fail "missing FileCheck: $FILECHECK"
|
||||
[ -x "$LEGACY" ] || fail "missing legacy oracle: $LEGACY"
|
||||
[ -x "$TMS_BITADDR" ] || fail "missing tms-bitaddr: $TMS_BITADDR"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# Emit one corpus path per line. layout-ti.c is the TI-compiler golden source.
|
||||
corpus() {
|
||||
for f in "$ROOT"/scripts/m4/*.c "$ROOT"/scripts/m5/*.c "$ROOT"/scripts/m6/*.c; do
|
||||
case "$f" in
|
||||
*layout-ti.c) ;;
|
||||
*) printf '%s\n' "$f" ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' "$ROOT/sdk/shim.c"
|
||||
printf '%s\n' "$ROOT/sdk/heap.c"
|
||||
}
|
||||
|
||||
# compare_mode MODE -- compile every corpus file native vs legacy and cmp.
|
||||
# Prints a per-mode summary and sets TOTPASS/TOTFAIL (global).
|
||||
compare_mode() {
|
||||
mode=$1
|
||||
pass=0
|
||||
failn=0
|
||||
echo "== equivalence at $mode"
|
||||
for f in $(corpus); do
|
||||
base=$(basename "$f")
|
||||
native=$WORK/$base.native.o
|
||||
legacy=$WORK/$base.legacy.ll
|
||||
legacyobj=$WORK/$base.legacy.o
|
||||
# shellcheck disable=SC2086
|
||||
if ! "$CLANG" --target=tms34010 $mode -I "$INC" -c "$f" -o "$native" \
|
||||
2> "$WORK/$base.native.err"; then
|
||||
echo "FAIL (native compile) $base"
|
||||
sed 's/^/ /' "$WORK/$base.native.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
# shellcheck disable=SC2086
|
||||
if ! "$LEGACY" $mode -I "$INC" -o "$legacy" "$f" \
|
||||
2> "$WORK/$base.legacy.err"; then
|
||||
echo "FAIL (legacy compile) $base"
|
||||
sed 's/^/ /' "$WORK/$base.legacy.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
if ! "$LLC" -march=tms34010 -O0 -filetype=obj "$legacy" -o "$legacyobj" \
|
||||
2>> "$WORK/$base.legacy.err"; then
|
||||
echo "FAIL (llc) $base"
|
||||
sed 's/^/ /' "$WORK/$base.legacy.err" >&2
|
||||
failn=$((failn + 1))
|
||||
continue
|
||||
fi
|
||||
if cmp -s "$native" "$legacyobj"; then
|
||||
pass=$((pass + 1))
|
||||
echo "OK $base"
|
||||
else
|
||||
echo "DIFF $base"
|
||||
failn=$((failn + 1))
|
||||
fi
|
||||
done
|
||||
echo "m10 equivalence [$mode]: pass=$pass fail=$failn"
|
||||
TOTPASS=$((TOTPASS + pass))
|
||||
TOTFAIL=$((TOTFAIL + failn))
|
||||
}
|
||||
|
||||
TOTPASS=0
|
||||
TOTFAIL=0
|
||||
|
||||
compare_mode "-O0"
|
||||
compare_mode "-O0 -g"
|
||||
|
||||
echo "m10 equivalence: pass=$TOTPASS fail=$TOTFAIL"
|
||||
|
||||
if [ "$TOTFAIL" -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Phase 2: pin the post-optimizer scaling pass on optimizer-created GEPs at -O2.
|
||||
echo "== -O2 shape pinning"
|
||||
cat > "$WORK/o2.c" <<'EOF'
|
||||
struct S { int a; int b; };
|
||||
int load_i(int *p) { return p[1]; }
|
||||
int stride(struct S *p) { return p[3].b; }
|
||||
int sw_tab(int c) {
|
||||
switch (c) {
|
||||
case 10: return 7;
|
||||
case 11: return 3;
|
||||
case 12: return 9;
|
||||
case 13: return 1;
|
||||
case 14: return 5;
|
||||
case 15: return 2;
|
||||
case 16: return 8;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
__attribute__((noinline)) struct S mk(int a, int b) { struct S s; s.a = a; s.b = b; return s; }
|
||||
int use_mk(int a, int b) { return mk(a, b).b; }
|
||||
EOF
|
||||
"$CLANG" --target=tms34010 -O2 -S -o "$WORK/o2.s" "$WORK/o2.c" \
|
||||
|| fail "clang -O2 -S failed on the shape fixture"
|
||||
cat > "$WORK/o2.checks" <<'EOF'
|
||||
CHECK-LABEL: _load_i:
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
CHECK-NOT: ADDI 4, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _stride:
|
||||
; The p[3] and .b offsets are now llvm.tms34010.bitaddr (BITADDR) nodes, so
|
||||
; the field offset stays relative instead of folding to the absolute 224.
|
||||
CHECK: ADDI 192, A{{[0-9]+}}
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
CHECK-NOT: ADDI 28, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _sw_tab:
|
||||
CHECK: SLL 3, A{{[0-9]+}}
|
||||
CHECK: MOVB {{.*}}A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _mk:
|
||||
CHECK: ADDI 32, A{{[0-9]+}}
|
||||
|
||||
CHECK-LABEL: _use_mk:
|
||||
CHECK: CALLA _mk
|
||||
CHECK: ADDI -32, A{{[0-9]+}}
|
||||
EOF
|
||||
"$FILECHECK" "$WORK/o2.checks" < "$WORK/o2.s" \
|
||||
|| fail "-O2 shape pinning failed"
|
||||
|
||||
echo "m10 equivalence: PASS"
|
||||
Executable
+178
@@ -0,0 +1,178 @@
|
||||
#!/bin/sh
|
||||
# tms-clang -- C IR pipeline: clang IR, the --bitptr semantic barrier, optimize,
|
||||
# scale the late byte-indexed GEPs, lower the barrier, and restore the M0
|
||||
# pointer-difference folding.
|
||||
#
|
||||
# Usage: tms-clang [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c
|
||||
#
|
||||
# -O0: clang IR -> --bitptr -> --lower-bitptr -> OUT (bit-addressed).
|
||||
# -O2 (the default): clang IR -> --bitptr -> opt -> --scale -> --lower-bitptr
|
||||
# -> opt -passes=instcombine -> OUT.
|
||||
#
|
||||
# -g passes clang -g through to the IR; the barrier passes copy !dbg
|
||||
# locations, so llc -filetype=obj emits the DWARF `.debug_*` sections. The
|
||||
# asm path still has no GSPA-assemblable debug directives.
|
||||
#
|
||||
# The barrier is required by the M0/M2 pointer model: pointers are bit
|
||||
# addresses, so `(int)(p + n) - (int)p` must be 8n at run time (the optimizer's
|
||||
# DataLayout would otherwise fold it to n). `--bitptr` replaces every GEP (and
|
||||
# an inttoptr of a bit addend over a ptrtoint base) with an opaque
|
||||
# @__tms_bitptr(i32 bitoff, ptr base) call, so InstCombine cannot canonicalize
|
||||
# the already-scaled bit offset back into a byte-indexed GEP; the M6 post-opt
|
||||
# `--scale` then multiplied that index by 8 again (the `p += n` over-scale, and
|
||||
# the reason the shim's memmove used constant end-pointer steps).
|
||||
#
|
||||
# The optimizer still creates genuinely byte-indexed GEPs (SROA aggregate
|
||||
# splits, switch tables), so the post-opt `--scale` is needed for those. By
|
||||
# then every original GEP is a call, so the pass only sees optimizer-created
|
||||
# byte GEPs. `--normalize` is not used there: it would treat those byte
|
||||
# offsets as already-scaled bits, which an aggregate return's `.fca.N.gep`
|
||||
# load (+4 bytes, not +4 bits) turns into an 8x address bug.
|
||||
#
|
||||
# `--lower-bitptr` then replaces each call with inttoptr(add(ptrtoint base,
|
||||
# bitoff)) and the final instcombine restores the M0 pointer-difference folding
|
||||
# (`int_diff` 8/32, the pointer-difference divide) and canonicalizes the
|
||||
# lowered bit GEPs, which llc already treats as bit offsets.
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/.." && pwd)
|
||||
# The fork build (TMS34010 target + clang bit-address changes). The older
|
||||
# `build/llvm-build` tree is a stock clang without the target and has no
|
||||
# matching opt, so it is not a usable default.
|
||||
TMS_CLANG=${TMS_CLANG:-$ROOT/build/llvm-clean-build/bin/clang}
|
||||
TMS_OPT=${TMS_OPT:-$ROOT/build/llvm-clean-build/bin/opt}
|
||||
TMS_BITADDR=${TMS_BITADDR:-$ROOT/tools/tms-bitaddr/tms-bitaddr}
|
||||
# Extra language flags from the caller (M4_EXTRA_CFLAGS). The conformance
|
||||
# c-torture sweep uses this for -std=gnu89; shipped gates leave it empty.
|
||||
TMS_CLANG_EXTRA_FLAGS=${TMS_CLANG_EXTRA_FLAGS:-}
|
||||
|
||||
for tool in "$TMS_CLANG" "$TMS_OPT" "$TMS_BITADDR"; do
|
||||
if [ ! -x "$tool" ]; then
|
||||
echo "tms-clang: missing tool: $tool" >&2
|
||||
echo "tms-clang: build the fork (build/llvm-clean-build/bin) or set" \
|
||||
"TMS_CLANG/TMS_OPT/TMS_BITADDR" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
OPTIMIZE=1
|
||||
DEBUG_FLAGS=
|
||||
INCLUDES=
|
||||
OUT=
|
||||
IN=
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [-O0|-O2] [-g] [-I dir] -o OUT.ll IN.c" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-O0) OPTIMIZE=0; shift ;;
|
||||
-O2) OPTIMIZE=1; shift ;;
|
||||
-g) DEBUG_FLAGS=-g; shift ;;
|
||||
-I) [ $# -ge 2 ] || usage; INCLUDES="$INCLUDES -I $2"; shift 2 ;;
|
||||
-I*) INCLUDES="$INCLUDES $1"; shift ;;
|
||||
-o) [ $# -ge 2 ] || usage; OUT=$2; shift 2 ;;
|
||||
-*) usage ;;
|
||||
*) [ -z "$IN" ] || usage; IN=$1; shift ;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ -n "$IN" ] || usage
|
||||
[ -n "$OUT" ] || usage
|
||||
|
||||
TMP=$(mktemp -d "${TMPDIR:-/tmp}/tms-clang.XXXXXX")
|
||||
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
|
||||
|
||||
# shellcheck disable=SC2086
|
||||
"$TMS_CLANG" --target=tms34010-unknown-none -O0 -Xclang -disable-O0-optnone \
|
||||
$DEBUG_FLAGS -S -emit-llvm -ffreestanding -fno-builtin -nostdinc $INCLUDES \
|
||||
$TMS_CLANG_EXTRA_FLAGS \
|
||||
-o "$TMP/step1.ll" "$IN"
|
||||
|
||||
# A `static` variadic definition is local, so DeadArgumentElimination removes
|
||||
# its `...` when nothing keeps the varargs alive and rewrites every call site
|
||||
# to drop the extra arguments. The M4 contiguous-stack walk in the body still
|
||||
# reads those slots, so -O2 silently miscompiles it. Reject that shape before
|
||||
# opt, but leave a definition that genuinely uses a va_list alone (M6):
|
||||
# llvm.va_start/va_arg keep `...` through DAE, and the target lowers the walk
|
||||
# from the named argument area rather than the last fixed parameter. -O0
|
||||
# (which M4's varargs gate uses) and external definitions such as sprintf are
|
||||
# unaffected.
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
STATIC_VARARG=$(awk '
|
||||
/^define / {
|
||||
in_def = 1
|
||||
sig = $0
|
||||
va_start = 0
|
||||
next
|
||||
}
|
||||
in_def && /llvm\.va_start|va_arg ptr/ { va_start = 1 }
|
||||
in_def && /^}/ {
|
||||
if (!va_start &&
|
||||
sig ~ /[^A-Za-z0-9_](internal|private)[^A-Za-z0-9_]/ &&
|
||||
sig ~ /\.\.\./) {
|
||||
print sig
|
||||
exit
|
||||
}
|
||||
in_def = 0
|
||||
}
|
||||
' "$TMP/step1.ll")
|
||||
if [ -n "$STATIC_VARARG" ]; then
|
||||
NAME=$(printf '%s\n' "$STATIC_VARARG" |
|
||||
sed -n 's/.*@\([A-Za-z0-9_.$-]*\)(.*/\1/p')
|
||||
echo "tms-clang: error: static variadic definition '${NAME:-?}' loses its" \
|
||||
"'...' arguments at -O2 (dead argument elimination); remove 'static'" \
|
||||
"or compile with -O0" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Hide every source GEP (and source pointer-int arithmetic) behind the opaque
|
||||
# bit-pointer barrier before the optimizer, so the bit-addressed model survives
|
||||
# without being re-canonicalized into byte GEPs.
|
||||
run_bitaddr() { # run_bitaddr MODE IN OUT
|
||||
if ! "$TMS_BITADDR" "$1" "$2" "$3" 2> "$TMP/bitaddr.err"; then
|
||||
cat "$TMP/bitaddr.err" >&2
|
||||
echo "tms-clang: error: tms-bitaddr $1 failed on $2" >&2
|
||||
exit 1
|
||||
fi
|
||||
cp "$TMP/bitaddr.err" "$TMP/bitaddr-$1.log"
|
||||
}
|
||||
|
||||
run_bitaddr --bitptr "$TMP/step1.ll" "$TMP/bitptr.ll"
|
||||
|
||||
mkdir -p "$(dirname "$OUT")"
|
||||
|
||||
if [ "$OPTIMIZE" -eq 1 ]; then
|
||||
# i64 exists since M6, but IndVarSimplify's exit-value replacement still
|
||||
# rewrites a loop's final value into a closed-form i33 multiply (e.g.
|
||||
# n*(n+1)/2 for sumto), which is an unsupported shape for this 32-bit
|
||||
# target. -replexitval is an option of IndVarSimplify; disabling only that
|
||||
# rewrite keeps the loop, which is what ordinary -O2 code needs. This is a
|
||||
# driver policy, not a target TTI policy: opt runs without a target machine
|
||||
# here. llc diagnoses the raw i33 shape reached by an opt run that omits
|
||||
# this flag (m5-policy.ll).
|
||||
"$TMS_OPT" -passes='default<O2>' -replexitval=never \
|
||||
-S "$TMP/bitptr.ll" -o "$TMP/opt.ll"
|
||||
# The optimizer may create new byte-indexed GEPs (SROA aggregate splits,
|
||||
# switch tables), so scale those. Every source GEP is still an opaque call,
|
||||
# so this pass cannot see (and re-scale) an already-bit offset.
|
||||
run_bitaddr --scale "$TMP/opt.ll" "$TMP/scaled.ll"
|
||||
# Lower the barrier and restore the M0 pointer-difference folding. The
|
||||
# lowered inttoptr(add) shapes canonicalize to GEPs whose index is already
|
||||
# a bit count; llc treats a GEP index as a bit offset, and no scale follows.
|
||||
# `no-verify-fixpoint` suppresses only InstCombine's idempotence check: the
|
||||
# M6 shim's emit_uint64 has a `zext i32 %base to i64` that a second run
|
||||
# would re-mark `nneg`, which the verifier reports as "did not reach a
|
||||
# fixpoint". The first run's output is the intended IR and all gates pass
|
||||
# with it; the flag is the documented escape for this known shape.
|
||||
run_bitaddr --lower-bitptr "$TMP/scaled.ll" "$TMP/lowered.ll"
|
||||
"$TMS_OPT" -passes='instcombine<no-verify-fixpoint>' \
|
||||
-S "$TMP/lowered.ll" -o "$OUT"
|
||||
else
|
||||
# No optimizer, so no byte GEPs can be created; lower the barrier directly
|
||||
# back to the historical bit-addressed inttoptr(add) form.
|
||||
run_bitaddr --lower-bitptr "$TMP/bitptr.ll" "$OUT"
|
||||
fi
|
||||
Executable
+146
@@ -0,0 +1,146 @@
|
||||
#!/bin/sh
|
||||
# M11 Task 2 gate: the CRT built with llc, linked and run end to end.
|
||||
#
|
||||
# scripts/tests/m11/crt.sh
|
||||
#
|
||||
# Builds sdk/crt0.ll with llc -march=tms34010 -filetype=obj (the TI-COFF
|
||||
# object path; llvm-mc's MC path emits ELF, which tms-link cannot read),
|
||||
# compiles a heredoc main.c and the existing conformance shim with
|
||||
# clang --target=tms34010 -O2 -c, links everything with tools/tms-link, and
|
||||
# runs the image with scripts/tms-run. The CRT contract is the result block
|
||||
# the conformance shim and tms-run already share: main returns 7, so the run
|
||||
# must report `status: 7` and stdout exactly `1 conformance`
|
||||
# (argv = { "conformance", NULL }). It also pins the CRT object size and
|
||||
# asserts the emitted `_start` has no frame prologue before its inline-asm
|
||||
# block (the `naked` attribute must survive).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC TMS_LINK M11_CRT_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
TMS_LINK=${TMS_LINK:-$ROOT/tools/tms-link/tms-link}
|
||||
WORK=${M11_CRT_WORK:-$ROOT/build/m11-crt}
|
||||
|
||||
CRT0=$ROOT/sdk/crt0.ll
|
||||
SHIM=$ROOT/sdk/shim.c
|
||||
CONF_INCLUDE=$ROOT/sdk/include
|
||||
# The shim's %f path pulls FD$* float-library symbols; link the committed
|
||||
# 1990 flib/rts archives from sdk/lib (the same files a production install
|
||||
# places in <sysroot>/lib) to satisfy them.
|
||||
FLIB=$ROOT/sdk/lib/flib.lib
|
||||
RTS=$ROOT/sdk/lib/rts.lib
|
||||
|
||||
fail() {
|
||||
echo "m11 crt: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
for tool in "$CLANG" "$LLC"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -x "$TMS_LINK" ] || fail "missing linker: $TMS_LINK"
|
||||
[ -f "$CRT0" ] || fail "missing CRT source: $CRT0"
|
||||
[ -f "$SHIM" ] || fail "missing conformance shim: $SHIM"
|
||||
[ -f "$FLIB" ] || fail "missing flib.lib: $FLIB"
|
||||
[ -f "$RTS" ] || fail "missing rts.lib: $RTS"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
echo "== build $CRT0 with llc (TI-COFF object)"
|
||||
"$LLC" -march=tms34010 -filetype=obj "$CRT0" -o "$WORK/crt0.o" \
|
||||
|| fail "llc could not build $CRT0"
|
||||
python3 - "$WORK/crt0.o" <<'PY' || fail "crt0.o is not TI-COFF"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
print(" crt0.o: %d bytes, TI-COFF magic 90 00" % len(data))
|
||||
PY
|
||||
|
||||
# Pin the CRT's size: the naked _start's code must not grow a frame.
|
||||
SIZE=$(wc -c < "$WORK/crt0.o")
|
||||
[ "$SIZE" -eq 540 ] \
|
||||
|| fail "crt0.o size changed: $SIZE bytes (want the pinned 540)"
|
||||
|
||||
echo "== check _start has no prologue before its inline-asm block"
|
||||
"$LLC" -march=tms34010 -filetype=asm "$CRT0" -o "$WORK/crt0.s" \
|
||||
|| fail "llc could not emit assembly for $CRT0"
|
||||
# Everything from the _start label up to the first inline-asm block (;APP).
|
||||
awk '/^_start:/{f=1} f&&/;APP/{exit} f' "$WORK/crt0.s" > "$WORK/start-pre.s"
|
||||
# A non-naked function starts with the frame setup (push A13, save registers,
|
||||
# point A14 past the frame). Any of those before the asm block means the
|
||||
# `naked` attribute was lost.
|
||||
if grep -Eq 'MMTM[[:space:]]+SP|MOVE[[:space:]]+A13,[[:space:]]*-\*SP|ADDI[[:space:]]+-?[0-9]+,[[:space:]]*A14' "$WORK/start-pre.s"; then
|
||||
fail "naked _start gained a frame prologue: $(tr '\n' ' ' < "$WORK/start-pre.s")"
|
||||
fi
|
||||
|
||||
cat > "$WORK/main.c" <<'EOF'
|
||||
int main(int argc, char **argv) { printf("%d %s\n", argc, argv[0]); return 7; }
|
||||
EOF
|
||||
|
||||
echo "== compile main.c and shim.c"
|
||||
# The heredoc main.c calls printf without a declaration; force-include the
|
||||
# conformance stdio.h so it compiles as written.
|
||||
"$CLANG" --target=tms34010 -O2 -c -include stdio.h -I "$CONF_INCLUDE" \
|
||||
"$WORK/main.c" -o "$WORK/main.o" \
|
||||
|| fail "clang -c main.c failed"
|
||||
"$CLANG" --target=tms34010 -O2 -c "$SHIM" -o "$WORK/shim.o" \
|
||||
|| fail "clang -c shim.c failed"
|
||||
|
||||
echo "== link with tms-link"
|
||||
"$TMS_LINK" -o "$WORK/crt.coff" --entry _start \
|
||||
--text 018A0000 --bss 01A00000 --prog-len 40000h --ram-len 80000h \
|
||||
"$WORK/crt0.o" "$WORK/main.o" "$WORK/shim.o" "$FLIB" "$RTS" \
|
||||
|| fail "tms-link failed"
|
||||
|
||||
echo "== run with tms-run"
|
||||
# tms-run exits nonzero for a nonzero status (it is built for status 0), so
|
||||
# capture its stdout and check the contract ourselves.
|
||||
"$ROOT/scripts/tms-run" "$WORK/crt.coff" > "$WORK/run.out" 2> "$WORK/run.err" \
|
||||
|| true
|
||||
if [ -s "$WORK/run.err" ]; then
|
||||
cat "$WORK/run.err" >&2
|
||||
fail "tms-run failed (see stderr above)"
|
||||
fi
|
||||
|
||||
python3 - "$WORK/run.out" <<'PY' || fail "contract check failed"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
fields = {}
|
||||
for line in data.split(b"\n"):
|
||||
for key in (b"status: ", b"magic: "):
|
||||
if line.startswith(key):
|
||||
fields[key] = line[len(key):].split(b" ", 1)[0]
|
||||
|
||||
status = fields.get(b"status: ")
|
||||
magic = fields.get(b"magic: ")
|
||||
if status != b"7":
|
||||
sys.exit("expected `status: 7`, got %r (full output: %r)"
|
||||
% (status, data))
|
||||
if magic != b"434F4E46":
|
||||
sys.exit("expected `magic: 434F4E46`, got %r (full output: %r)"
|
||||
% (magic, data))
|
||||
|
||||
marker = b"stdout:\n"
|
||||
if marker not in data:
|
||||
sys.exit("tms-run printed no stdout (full output: %r)" % (data,))
|
||||
out = data.split(marker, 1)[1]
|
||||
# tms-run appends a newline when the captured stream did not end with one;
|
||||
# the contract is the 12 bytes `1 conformance` with no trailing newline.
|
||||
if out.endswith(b"\n"):
|
||||
out = out[:-1]
|
||||
if out != b"1 conformance":
|
||||
sys.exit("stdout is not exactly `1 conformance` (got %r, full output: %r)"
|
||||
% (out, data))
|
||||
|
||||
sys.stdout.write(" status 7, magic 434F4E46, stdout `1 conformance`\n")
|
||||
PY
|
||||
|
||||
echo "m11 crt: PASS"
|
||||
Executable
+265
@@ -0,0 +1,265 @@
|
||||
#!/bin/sh
|
||||
# M11 Task 5 gate: the single-command build, end to end.
|
||||
#
|
||||
# scripts/tests/m11/e2e.sh
|
||||
#
|
||||
# The milestone's headline acceptance: after one `scripts/tms-sdk` (no
|
||||
# arguments), a plain `clang --target=tms34010 hello.c -o hello` from a
|
||||
# directory outside the repo links a loader-valid image that `tms-run`
|
||||
# executes, with no project variables and no sysroot flag. The isolated
|
||||
# sub-cases (two TUs, -I with a custom header and -L/-l with a user archive,
|
||||
# -c, -S, -E, -O0/-O2, -g vs stripped, -nostdlib with a
|
||||
# user _start, and the -### no-checkout-path assertion) run against a temp
|
||||
# sysroot installed with `scripts/tms-sdk --sysroot`, so the default
|
||||
# discovery path is exercised exactly once and nothing depends on a repo
|
||||
# source tree.
|
||||
#
|
||||
# The compiler, the installer and the runner are invoked through absolute
|
||||
# repo paths; the only environment the compile/link sees is a scrubbed one
|
||||
# (no M4_*/TMS_*/CPATH/LIBRARY_PATH/COMPILER_PATH), so PATH (which tms-link
|
||||
# needs to find python3) is the sole inherited convenience.
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC LLVM_AR
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
LLVM_AR=${LLVM_AR:-$LLVM_BIN/llvm-ar}
|
||||
TMS_SDK=$ROOT/scripts/tms-sdk
|
||||
TMS_RUN=$ROOT/scripts/tms-run
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/m11-e2e.XXXXXX")
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
SYSROOT=$WORK/sysroot
|
||||
|
||||
fail() {
|
||||
echo "m11 e2e: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Scrub the environment the compile/link sees: the toolchain must need no
|
||||
# M4_*/TMS_* variable, no host include/library path and no tool-search
|
||||
# override. PATH survives (tms-link's shebang and the driver's python3
|
||||
# pre-flight both search it).
|
||||
clean() {
|
||||
env -u M4_WORK -u M4_SDK -u M4_COFF -u M4_SOURCES -u M4_ENTRY \
|
||||
-u M4_NATIVE -u M4_LINKER -u M4_SKIP_MAME -u M4_CLANG_OPT \
|
||||
-u M4_LLC_OPT -u M4_EXTRA_INCLUDES -u M4_EXTRA_CFLAGS \
|
||||
-u M4_NATIVE_PROG_LEN -u M4_NATIVE_RAM_LEN -u M4_NATIVE_LIBS \
|
||||
-u M4_OS2 -u M4_OS2_LX \
|
||||
-u TMS_CLANG -u TMS_LLC -u TMS_OPT -u TMS_BITADDR \
|
||||
-u TMS_CLANG_EXTRA_FLAGS -u TMS_LINKER \
|
||||
-u CLANG -u LLC -u LLVM_AR -u LLVM_BIN \
|
||||
-u CPATH -u C_INCLUDE_PATH -u CPLUS_INCLUDE_PATH \
|
||||
-u OBJC_INCLUDE_PATH -u LIBRARY_PATH \
|
||||
-u COMPILER_PATH -u GCC_EXEC_PREFIX \
|
||||
"$@"
|
||||
}
|
||||
|
||||
# run_check IMAGE WANT DESC -- run the image with tms-run and assert the
|
||||
# result contract: status 0, magic 434F4E46, and stdout exactly WANT.
|
||||
run_check() {
|
||||
img=$1
|
||||
want=$2
|
||||
desc=$3
|
||||
"$TMS_RUN" "$img" > "$WORK/run.out" 2> "$WORK/run.err" \
|
||||
|| { cat "$WORK/run.err" >&2; fail "$desc: tms-run failed"; }
|
||||
python3 - "$WORK/run.out" "$want" <<'PY' || fail "$desc: output mismatch"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
want = sys.argv[2].encode()
|
||||
status = magic = None
|
||||
for line in data.split(b"\n"):
|
||||
if line.startswith(b"status: "):
|
||||
status = line[len(b"status: "):].split(b" ", 1)[0]
|
||||
elif line.startswith(b"magic: "):
|
||||
magic = line[len(b"magic: "):].split(b" ", 1)[0]
|
||||
if status != b"0":
|
||||
sys.exit("status %r != 0 (full: %r)" % (status, data))
|
||||
if magic != b"434F4E46":
|
||||
sys.exit("magic %r != 434F4E46 (full: %r)" % (magic, data))
|
||||
marker = b"stdout:\n"
|
||||
if want == b"":
|
||||
if marker in data:
|
||||
sys.exit("unexpected stdout in %r" % (data,))
|
||||
else:
|
||||
if marker not in data:
|
||||
sys.exit("no stdout marker in %r" % (data,))
|
||||
out = data.split(marker, 1)[1]
|
||||
if out.endswith(b"\n"):
|
||||
out = out[:-1]
|
||||
if out != want:
|
||||
sys.exit("stdout %r != want %r (full: %r)" % (out, want, data))
|
||||
PY
|
||||
}
|
||||
|
||||
[ -x "$TMS_SDK" ] || fail "missing installer: $TMS_SDK"
|
||||
[ -x "$TMS_RUN" ] || fail "missing runner: $TMS_RUN"
|
||||
for tool in "$CLANG" "$LLC" "$LLVM_AR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
|
||||
cd "$WORK"
|
||||
|
||||
# --- Part A: the headline command through the default discovery path ------
|
||||
# Install the real resource-dir sysroot (no --sysroot argument), then run the
|
||||
# plain command with no sysroot flag and no project environment.
|
||||
echo "== install the default resource-dir sysroot (tms-sdk, no arguments)"
|
||||
clean "$TMS_SDK" || fail "default tms-sdk install failed"
|
||||
|
||||
cat > hello.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int main(void) { printf("hello\n"); return 0; }
|
||||
EOF
|
||||
|
||||
echo "== clang --target=tms34010 hello.c -o hello (no flags, no env)"
|
||||
clean "$CLANG" --target=tms34010 hello.c -o hello \
|
||||
|| fail "headline command failed"
|
||||
[ -f hello ] || fail "headline command produced no image"
|
||||
[ -f hello.map ] || fail "headline command produced no hello.map"
|
||||
|
||||
run_check hello "hello" "headline" || fail "headline run failed"
|
||||
# The default link is stripped: the map has no .debug_* sections.
|
||||
grep -q '\.debug_' hello.map \
|
||||
&& fail "default link keeps .debug_* sections (should be stripped)" || true
|
||||
|
||||
# --- Part B: isolated sub-cases against a temp sysroot --------------------
|
||||
echo "== install a temp sysroot for the isolated sub-cases"
|
||||
clean "$TMS_SDK" --sysroot "$SYSROOT" || fail "temp sysroot install failed"
|
||||
|
||||
# 1. two TUs link and run.
|
||||
cat > add.c <<'EOF'
|
||||
int add(int a, int b) { return a + b; }
|
||||
EOF
|
||||
cat > main.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
int add(int, int);
|
||||
int main(void) { printf("add=%d\n", add(20, 22)); return 0; }
|
||||
EOF
|
||||
echo "== two-TU link (add.c + main.c)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" add.c main.c -o add42 \
|
||||
|| fail "two-TU link failed"
|
||||
run_check add42 "add=42" "two-TU" || fail "two-TU run failed"
|
||||
|
||||
# 1b. -I, -L and -l end to end: a header from a custom include directory and a
|
||||
# small user archive whose member main calls.
|
||||
mkdir -p inc libsrc libdir
|
||||
cat > inc/answer.h <<'EOF'
|
||||
#define ANSWER 42
|
||||
int user_answer(void);
|
||||
EOF
|
||||
cat > libsrc/user.c <<'EOF'
|
||||
#include "answer.h"
|
||||
int user_answer(void) { return ANSWER; }
|
||||
EOF
|
||||
cat > uselib.c <<'EOF'
|
||||
#include <stdio.h>
|
||||
#include "answer.h"
|
||||
int main(void) { printf("user=%d\n", user_answer()); return 0; }
|
||||
EOF
|
||||
echo "== -I header and -L/-l user archive"
|
||||
clean "$CLANG" --target=tms34010 -c -I inc libsrc/user.c -o user.o \
|
||||
|| fail "-I compile of the user library failed"
|
||||
clean "$LLVM_AR" rcsD libdir/libuser.a user.o \
|
||||
|| fail "building the user archive failed"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" \
|
||||
-I inc uselib.c -L libdir -l user -o uselib \
|
||||
|| fail "-I/-L/-l link failed"
|
||||
run_check uselib "user=42" "-I/-L/-l" || fail "-I/-L/-l run failed"
|
||||
|
||||
# 2. -c produces a TI-COFF object.
|
||||
echo "== -c (object)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -c hello.c -o hello.o \
|
||||
|| fail "-c failed"
|
||||
python3 - hello.o <<'PY' || fail "hello.o is not TI-COFF"
|
||||
import sys
|
||||
|
||||
data = open(sys.argv[1], "rb").read()
|
||||
if len(data) < 2 or data[:2] != b"\x90\x00":
|
||||
sys.exit("first two bytes are %r, want the TI-COFF magic 90 00"
|
||||
% (data[:2],))
|
||||
PY
|
||||
|
||||
# 3. -S produces GSPA assembly naming main and the printf call.
|
||||
echo "== -S (assembly)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -S hello.c -o hello.s \
|
||||
|| fail "-S failed"
|
||||
grep -q '_main' hello.s || fail "hello.s has no _main symbol"
|
||||
grep -q '_printf' hello.s || fail "hello.s has no _printf call"
|
||||
|
||||
# 4. -E produces preprocessed source (headers resolved, source present).
|
||||
echo "== -E (preprocessed)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -E hello.c -o hello.i \
|
||||
|| fail "-E failed"
|
||||
grep -q 'int printf(const char \*fmt, ...);' hello.i \
|
||||
|| fail "hello.i did not expand the stdio.h printf declaration"
|
||||
grep -q 'printf("hello\\n")' hello.i \
|
||||
|| fail "hello.i lost the hello.c source line"
|
||||
|
||||
# 5. -O0 and -O2 both run correctly.
|
||||
for opt in -O0 -O2; do
|
||||
tag=$(echo "$opt" | tr -d -)
|
||||
echo "== $opt"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" \
|
||||
"$opt" hello.c -o "hello_$tag" || fail "$opt link failed"
|
||||
run_check "hello_$tag" "hello" "$opt" || fail "$opt run failed"
|
||||
done
|
||||
|
||||
# 6. -g keeps the .debug_* sections in the linked image; the default link
|
||||
# (hello_O0/hello_O2 above, and hello in Part A) is stripped.
|
||||
echo "== -g keeps .debug_* (vs stripped default)"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" -g hello.c -o hello_g \
|
||||
|| fail "-g link failed"
|
||||
grep -q '\.debug_' hello_g.map || fail "-g link has no .debug_* sections"
|
||||
grep -q '\.debug_' hello_O0.map \
|
||||
&& fail "default link keeps .debug_* sections (should be stripped)" || true
|
||||
|
||||
# 7. -nostdlib drops the CRT and the user supplies _start.
|
||||
cat > nostdlib.c <<'EOF'
|
||||
/* On this target C globals gain a leading underscore, so a C function named
|
||||
* `start` lands on the `_start` symbol the link job uses as its entry. */
|
||||
__attribute__((naked)) void start(void) {
|
||||
__asm__ volatile(
|
||||
"setf 16, 1, 0\n\t"
|
||||
"setf 32, 0, 1\n\t"
|
||||
"movi 0x01B00000, a1\n\t"
|
||||
"sub a0, a0\n\t"
|
||||
"move a0, *a1, 1\n\t"
|
||||
"movi 0x01B00040, a1\n\t"
|
||||
"movi 0x434F4E46, a0\n\t"
|
||||
"move a0, *a1, 1\n"
|
||||
"1: jruc 1b\n\t");
|
||||
}
|
||||
EOF
|
||||
echo "== -nostdlib with a user _start"
|
||||
clean "$CLANG" --target=tms34010 --tms-sysroot="$SYSROOT" \
|
||||
-nostdlib nostdlib.c -o nostdlib_img || fail "-nostdlib link failed"
|
||||
grep -q '"_start"' nostdlib_img.map \
|
||||
|| fail "-nostdlib image has no _start entry"
|
||||
run_check nostdlib_img "" "-nostdlib" || fail "-nostdlib run failed"
|
||||
|
||||
# 8. -### must show the sysroot-derived linker/include/CRT/libraries and
|
||||
# never a repo source path (the driver shells out only to the installed
|
||||
# sysroot; it never bakes in the checkout's sdk/tools/scripts trees).
|
||||
echo "== -### contains no checkout path"
|
||||
clean "$CLANG" -### --target=tms34010 --tms-sysroot="$SYSROOT" hello.c -o hello \
|
||||
> "$WORK/verbose.txt" 2>&1
|
||||
grep -Fq "$SYSROOT/bin/tms-link" "$WORK/verbose.txt" \
|
||||
|| fail "-### does not invoke the sysroot linker"
|
||||
grep -Fq "$SYSROOT/include" "$WORK/verbose.txt" \
|
||||
|| fail "-### does not use the sysroot include path"
|
||||
for src in "$SYSROOT/lib/crt0.o" "$SYSROOT/lib/libtms.a" \
|
||||
"$SYSROOT/lib/flib.lib" "$SYSROOT/lib/rts.lib"; do
|
||||
grep -Fq "$src" "$WORK/verbose.txt" \
|
||||
|| fail "-### does not reference $src"
|
||||
done
|
||||
for leak in "$ROOT/sdk" "$ROOT/tools/tms-link" "$ROOT/scripts" \
|
||||
"$ROOT/build/m6-sdk"; do
|
||||
grep -Fq "$leak" "$WORK/verbose.txt" \
|
||||
&& fail "-### leaks a repo source path: $leak" || true
|
||||
done
|
||||
|
||||
echo "m11 e2e: PASS"
|
||||
Executable
+166
@@ -0,0 +1,166 @@
|
||||
#!/bin/sh
|
||||
# M11 Task 3 gate: the sysroot installer and its installed layout.
|
||||
#
|
||||
# scripts/tests/m11/sdk.sh
|
||||
#
|
||||
# Runs scripts/tms-sdk --sysroot "$TMP/sysroot" and asserts:
|
||||
# - the seven expected layout entries exist (include/, lib/{crt0.o,libtms.a,
|
||||
# flib.lib,rts.lib}, bin/{tms-link,tmscoff.py}) and every sdk/include/*.h
|
||||
# is installed;
|
||||
# - the installed tms-link is executable;
|
||||
# - `llvm-ar t libtms.a` lists exactly shim.o and heap.o;
|
||||
# - a second install is idempotent (crt0.o and libtms.a are byte-identical);
|
||||
# - the installed crt0.o matches a fresh llc build of sdk/crt0.ll;
|
||||
# - the installed libtms.a matches a fresh llvm-ar rcsD build of the same
|
||||
# shim.o/heap.o objects;
|
||||
# - the installed tms-link/tmscoff.py match tools/tms-link/*;
|
||||
# - a directory that is not an M11 sysroot (no marker) is refused before its
|
||||
# include/ is touched;
|
||||
# - reinstalling removes a header deleted from sdk/include;
|
||||
# - sdk/lib/{flib,rts}.lib match build/m6-sdk/{flib,rts}.lib when those exist
|
||||
# (otherwise the comparison prints SKIP (vendor tree absent)).
|
||||
#
|
||||
# Overridable: LLVM_BIN CLANG LLC LLVM_AR M11_SDK_WORK
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
LLVM_BIN=${LLVM_BIN:-$ROOT/build/llvm-clean-build/bin}
|
||||
CLANG=${CLANG:-$LLVM_BIN/clang}
|
||||
LLC=${LLC:-$LLVM_BIN/llc}
|
||||
LLVM_AR=${LLVM_AR:-$LLVM_BIN/llvm-ar}
|
||||
TMS_SDK=$ROOT/scripts/tms-sdk
|
||||
WORK=${M11_SDK_WORK:-$ROOT/build/m11-sdk}
|
||||
SYSROOT=$WORK/sysroot
|
||||
# A temporary header used to prove that a reinstall removes deleted headers.
|
||||
EXTRA_HEADER=$ROOT/sdk/include/zz-m11-sdk-gate.h
|
||||
|
||||
fail() {
|
||||
echo "m11 sdk: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
rm -f "$EXTRA_HEADER"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
[ -x "$TMS_SDK" ] || fail "missing installer: $TMS_SDK"
|
||||
for tool in "$CLANG" "$LLC" "$LLVM_AR"; do
|
||||
[ -x "$tool" ] || fail "missing tool: $tool"
|
||||
done
|
||||
[ -f "$ROOT/sdk/crt0.ll" ] || fail "missing CRT source: $ROOT/sdk/crt0.ll"
|
||||
[ -f "$ROOT/sdk/shim.c" ] || fail "missing shim source: $ROOT/sdk/shim.c"
|
||||
[ -f "$ROOT/sdk/heap.c" ] || fail "missing heap source: $ROOT/sdk/heap.c"
|
||||
|
||||
rm -rf "$WORK"
|
||||
mkdir -p "$WORK"
|
||||
|
||||
# A non-empty directory without the install marker is not ours to overwrite.
|
||||
echo "== refuse a non-M11 sysroot directory"
|
||||
FOREIGN=$WORK/foreign
|
||||
mkdir -p "$FOREIGN/include"
|
||||
echo keep > "$FOREIGN/include/keepme.h"
|
||||
if "$TMS_SDK" --sysroot "$FOREIGN" > "$WORK/foreign.log" 2>&1; then
|
||||
fail "tms-sdk overwrote a directory that is not an M11 sysroot"
|
||||
fi
|
||||
grep -q "not an M11 sysroot" "$WORK/foreign.log" \
|
||||
|| fail "refusal did not explain that the directory is not an M11 sysroot"
|
||||
[ -f "$FOREIGN/include/keepme.h" ] \
|
||||
|| fail "refused install deleted include/keepme.h"
|
||||
[ ! -e "$FOREIGN/.tms-sdk" ] \
|
||||
|| fail "refused install wrote an install marker"
|
||||
|
||||
echo "== install to $SYSROOT"
|
||||
"$TMS_SDK" --sysroot "$SYSROOT" || fail "first install failed"
|
||||
|
||||
# 1. the seven layout entries.
|
||||
for f in \
|
||||
"$SYSROOT/lib/crt0.o" \
|
||||
"$SYSROOT/lib/libtms.a" \
|
||||
"$SYSROOT/lib/flib.lib" \
|
||||
"$SYSROOT/lib/rts.lib" \
|
||||
"$SYSROOT/bin/tms-link" \
|
||||
"$SYSROOT/bin/tmscoff.py"; do
|
||||
[ -f "$f" ] || fail "missing installed file: $f"
|
||||
done
|
||||
[ -d "$SYSROOT/include" ] || fail "missing installed include directory"
|
||||
[ -x "$SYSROOT/bin/tms-link" ] || fail "installed tms-link is not executable"
|
||||
[ -f "$SYSROOT/.tms-sdk" ] || fail "missing install marker: $SYSROOT/.tms-sdk"
|
||||
for h in "$ROOT"/sdk/include/*.h; do
|
||||
[ -f "$SYSROOT/include/$(basename "$h")" ] \
|
||||
|| fail "missing installed header: $(basename "$h")"
|
||||
done
|
||||
|
||||
# The installed linker pair must be the project sources (a real
|
||||
# installed-vs-source check, not a copy of the destination onto itself).
|
||||
cmp "$SYSROOT/bin/tms-link" "$ROOT/tools/tms-link/tms-link" \
|
||||
|| fail "installed tms-link differs from tools/tms-link/tms-link"
|
||||
cmp "$SYSROOT/bin/tmscoff.py" "$ROOT/tools/tms-link/tmscoff.py" \
|
||||
|| fail "installed tmscoff.py differs from tools/tms-link/tmscoff.py"
|
||||
|
||||
# 2. libtms.a members are exactly shim.o and heap.o.
|
||||
"$LLVM_AR" t "$SYSROOT/lib/libtms.a" > "$WORK/ar-t.txt" \
|
||||
|| fail "llvm-ar t libtms.a failed"
|
||||
for m in shim.o heap.o; do
|
||||
grep -qx "$m" "$WORK/ar-t.txt" || fail "libtms.a has no $m member"
|
||||
done
|
||||
if [ "$(wc -l < "$WORK/ar-t.txt")" -ne 2 ]; then
|
||||
fail "libtms.a has unexpected members: $(tr '\n' ' ' < "$WORK/ar-t.txt")"
|
||||
fi
|
||||
|
||||
# Snapshot the build outputs before the idempotency re-install.
|
||||
cp "$SYSROOT/lib/crt0.o" "$WORK/crt0.first.o"
|
||||
cp "$SYSROOT/lib/libtms.a" "$WORK/libtms.first.a"
|
||||
|
||||
# 3. a second install is idempotent (byte-identical rebuilds), and a third
|
||||
# install after deleting a source header removes the stale installed one.
|
||||
echo "== re-install (idempotency)"
|
||||
printf '/* gate-only header */\n' > "$EXTRA_HEADER"
|
||||
"$TMS_SDK" --sysroot "$SYSROOT" || fail "second install failed"
|
||||
cmp "$SYSROOT/lib/crt0.o" "$WORK/crt0.first.o" \
|
||||
|| fail "crt0.o changed across reinstall"
|
||||
cmp "$SYSROOT/lib/libtms.a" "$WORK/libtms.first.a" \
|
||||
|| fail "libtms.a changed across reinstall"
|
||||
[ -f "$SYSROOT/include/$(basename "$EXTRA_HEADER")" ] \
|
||||
|| fail "install did not copy $(basename "$EXTRA_HEADER")"
|
||||
|
||||
echo "== re-install after deleting a header (stale header removal)"
|
||||
rm -f "$EXTRA_HEADER"
|
||||
"$TMS_SDK" --sysroot "$SYSROOT" || fail "third install failed"
|
||||
[ ! -e "$SYSROOT/include/$(basename "$EXTRA_HEADER")" ] \
|
||||
|| fail "stale header survived a reinstall: $(basename "$EXTRA_HEADER")"
|
||||
|
||||
# 4. the installed crt0.o matches a fresh llc build.
|
||||
echo "== fresh crt0.o (llc)"
|
||||
"$LLC" -march=tms34010 -filetype=obj "$ROOT/sdk/crt0.ll" -o "$WORK/crt0.fresh.o" \
|
||||
|| fail "fresh llc build of sdk/crt0.ll failed"
|
||||
cmp "$SYSROOT/lib/crt0.o" "$WORK/crt0.fresh.o" \
|
||||
|| fail "installed crt0.o differs from a fresh llc build"
|
||||
|
||||
# 5. the installed libtms.a matches a fresh llvm-ar rcsD build.
|
||||
echo "== fresh libtms.a (llvm-ar rcsD)"
|
||||
"$CLANG" --target=tms34010 -O2 -c -I "$ROOT/sdk/include" \
|
||||
"$ROOT/sdk/shim.c" -o "$WORK/shim.o" || fail "fresh shim.o build failed"
|
||||
"$CLANG" --target=tms34010 -O2 -c -I "$ROOT/sdk/include" \
|
||||
"$ROOT/sdk/heap.c" -o "$WORK/heap.o" || fail "fresh heap.o build failed"
|
||||
( cd "$WORK" && "$LLVM_AR" rcsD libtms.fresh.a shim.o heap.o ) \
|
||||
|| fail "fresh llvm-ar build failed"
|
||||
cmp "$SYSROOT/lib/libtms.a" "$WORK/libtms.fresh.a" \
|
||||
|| fail "installed libtms.a differs from a fresh llvm-ar build"
|
||||
|
||||
# 6. the committed vendor archives match the extracted originals.
|
||||
echo "== vendor archive comparison"
|
||||
if [ -f "$ROOT/build/m6-sdk/flib.lib" ]; then
|
||||
cmp "$ROOT/sdk/lib/flib.lib" "$ROOT/build/m6-sdk/flib.lib" \
|
||||
|| fail "sdk/lib/flib.lib differs from build/m6-sdk/flib.lib"
|
||||
else
|
||||
echo " SKIP (vendor tree absent): no build/m6-sdk/flib.lib to compare"
|
||||
fi
|
||||
if [ -f "$ROOT/build/m6-sdk/rts.lib" ]; then
|
||||
cmp "$ROOT/sdk/lib/rts.lib" "$ROOT/build/m6-sdk/rts.lib" \
|
||||
|| fail "sdk/lib/rts.lib differs from build/m6-sdk/rts.lib"
|
||||
else
|
||||
echo " SKIP (vendor tree absent): no build/m6-sdk/rts.lib to compare"
|
||||
fi
|
||||
|
||||
echo "m11 sdk: PASS"
|
||||
Executable
+524
@@ -0,0 +1,524 @@
|
||||
#!/bin/sh
|
||||
# M12 runtime-abort triage harness (serial; evidence only, edits nothing).
|
||||
#
|
||||
# scripts/tests/m12/abort-triage.sh [options]
|
||||
#
|
||||
# Discovers the curated runtime-abort rows from full-suite.skip -- every row
|
||||
# whose reason starts with "runtime-abort" plus every wrong-result row whose
|
||||
# reason says so -- then re-runs each one at -O0 and -O2 through the M5
|
||||
# conformance runner with the same settings the M7 full-suite driver uses.
|
||||
# The curated skip table is only read; this harness cannot flip a row.
|
||||
#
|
||||
# For every row it records the runner result, the status word, the completion
|
||||
# magic, a status-derived marker (a non-zero status or a missing magic -- the
|
||||
# silent tests expose no output marker), and the first difference between -O0
|
||||
# and -O2. Per-opt logs and result.txt files are retained so the research
|
||||
# document can cite them; the per-opt work dirs are run-O0/ and run-O2/.
|
||||
#
|
||||
# --work DIR work/results directory (default build/m12-abort-triage)
|
||||
# --timeout SEC per-test MAME timeout (default 120)
|
||||
# --redo re-run rows already recorded
|
||||
# --limit N attempt at most N rows (sample use)
|
||||
# -h, --help this help (exit 0)
|
||||
#
|
||||
# Overridable: M12_ABORT_WORK M12_ABORT_TIMEOUT
|
||||
# LLVM_BIN TMS_CLANG TMS_LLC MAME LOADER_AT LOADER_END
|
||||
set -eu
|
||||
|
||||
ROOT=$(cd "$(dirname "$0")/../../.." && pwd)
|
||||
HERE=$(cd "$(dirname "$0")" && pwd)
|
||||
SKIP_FILE=$ROOT/scripts/tests/m7/full-suite.skip
|
||||
GNU89_FILE=$ROOT/scripts/tests/m7/full-suite.gnu89
|
||||
LOADER_FILE=$ROOT/scripts/tests/m7/full-suite.loader-end
|
||||
FULL_LOADER_FILE=$ROOT/scripts/tests/m7/full-suite.full-loader
|
||||
CONFORMANCE_DIR=${M5_CONFORMANCE_DIR:-$ROOT/scripts/tests/m5/conformance}
|
||||
RUN=$CONFORMANCE_DIR/run.sh
|
||||
C_TORTURE_DIR=${C_TORTURE_DIR:-$ROOT/vendor/conformance/gcc-16.2.0/gcc/testsuite/gcc.c-torture/execute}
|
||||
C_TESTSUITE_DIR=${C_TESTSUITE_DIR:-$ROOT/vendor/conformance/c-testsuite/tests/single-exec}
|
||||
|
||||
WORK=${M12_ABORT_WORK:-$ROOT/build/m12-abort-triage}
|
||||
TIME_LIMIT=${M12_ABORT_TIMEOUT:-120}
|
||||
LOADER_AT=${LOADER_AT:-200}
|
||||
LOADER_END=${LOADER_END:-1000}
|
||||
REDO=0
|
||||
LIMIT=0
|
||||
EVIDENCE=$WORK/abort-triage.evidence.tsv
|
||||
TSV=$WORK/abort-triage.tsv
|
||||
TABLE=$WORK/abort-triage.md
|
||||
|
||||
fail() {
|
||||
echo "abort-triage: FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
sed -n '2,/^set -eu/p' "$0" | sed '$d' | sed 's/^# \{0,1\}//' >&2
|
||||
exit "${1:-1}"
|
||||
}
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--work)
|
||||
[ $# -ge 2 ] || usage
|
||||
WORK=$2
|
||||
EVIDENCE=$WORK/abort-triage.evidence.tsv
|
||||
TSV=$WORK/abort-triage.tsv
|
||||
TABLE=$WORK/abort-triage.md
|
||||
shift 2
|
||||
;;
|
||||
--timeout)
|
||||
[ $# -ge 2 ] || usage
|
||||
TIME_LIMIT=$2
|
||||
shift 2
|
||||
;;
|
||||
--redo)
|
||||
REDO=1
|
||||
shift
|
||||
;;
|
||||
--limit)
|
||||
[ $# -ge 2 ] || usage
|
||||
LIMIT=$2
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage 0
|
||||
;;
|
||||
*)
|
||||
fail "unknown option: $1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case $TIME_LIMIT in
|
||||
''|*[!0-9]*) fail "timeout must be a positive integer: '$TIME_LIMIT'" ;;
|
||||
esac
|
||||
[ "$TIME_LIMIT" -gt 0 ] || fail "timeout must be a positive integer"
|
||||
case $LIMIT in
|
||||
''|*[!0-9]*) fail "--limit must be a non-negative integer: '$LIMIT'" ;;
|
||||
esac
|
||||
|
||||
[ -f "$SKIP_FILE" ] || fail "missing skip table: $SKIP_FILE"
|
||||
[ -f "$GNU89_FILE" ] || fail "missing gnu89 list: $GNU89_FILE"
|
||||
[ -f "$LOADER_FILE" ] || fail "missing loader-end list: $LOADER_FILE"
|
||||
[ -f "$RUN" ] || fail "missing conformance runner: $RUN"
|
||||
[ -d "$C_TORTURE_DIR" ] || fail "missing pinned c-torture tree: $C_TORTURE_DIR"
|
||||
[ -d "$C_TESTSUITE_DIR" ] || fail "missing pinned c-testsuite tree: $C_TESTSUITE_DIR"
|
||||
|
||||
mkdir -p "$WORK/logs" "$WORK/run-O0" "$WORK/run-O2"
|
||||
|
||||
# Discover, never hardcode. The two accepted shapes are the reason prefix
|
||||
# runtime-abort* and the wrong-result rows (reason says "wrong ... result").
|
||||
# Order follows the curated file so a diff is readable.
|
||||
ROWS=$WORK/abort-rows.tsv
|
||||
CLASSES=$WORK/abort-classes.tsv
|
||||
: > "$ROWS"
|
||||
: > "$CLASSES"
|
||||
while IFS= read -r line; do
|
||||
case $line in
|
||||
''|\#*) continue ;;
|
||||
esac
|
||||
id=${line%% *}
|
||||
reason=${line#* }
|
||||
[ "$id" != "$line" ] || fail "malformed skip row (no tab): $line"
|
||||
case $reason in
|
||||
runtime-abort*) ;;
|
||||
*wrong*result*) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
corpus=${id%%/*}
|
||||
name=${id#*/}
|
||||
[ "$corpus" != "$id" ] || fail "malformed skip id: $id"
|
||||
case $corpus in
|
||||
c-torture) src=$C_TORTURE_DIR/$name.c ;;
|
||||
c-testsuite) src=$C_TESTSUITE_DIR/$name.c ;;
|
||||
*) fail "unknown corpus in curated row: $id" ;;
|
||||
esac
|
||||
[ -f "$src" ] || fail "curated abort row names a missing source: $id"
|
||||
cls=${reason%%:*}
|
||||
printf '%s\t%s\n' "$id" "$reason" >> "$ROWS"
|
||||
printf '%s\t%s\t%s\n' "$id" "$cls" "$reason" >> "$CLASSES"
|
||||
done < "$SKIP_FILE"
|
||||
[ -s "$ROWS" ] || fail "discovered no runtime-abort rows in $SKIP_FILE"
|
||||
DISCOVERED=$(wc -l < "$ROWS" | tr -d ' ')
|
||||
|
||||
# Reuse the driver's dialect and loader-budget rules so a row is run under the
|
||||
# conditions the full suite would use if it were not curated.
|
||||
dialect_flags() {
|
||||
corpus=$1
|
||||
name=$2
|
||||
src=$3
|
||||
if [ "$corpus" != c-torture ]; then
|
||||
return 0
|
||||
fi
|
||||
directives=$(grep -E 'dg-(additional-)?options' "$src" 2>/dev/null || true)
|
||||
std=$(printf '%s\n' "$directives" \
|
||||
| grep -o -- '-std=[A-Za-z0-9+_-]*' | head -n 1 || true)
|
||||
if [ -n "$std" ]; then
|
||||
flags=$std
|
||||
elif grep -Fxq "$name" "$GNU89_FILE"; then
|
||||
flags=-std=gnu89
|
||||
else
|
||||
flags=
|
||||
fi
|
||||
if printf '%s\n' "$directives" | grep -q -- '-fgnu89-inline'; then
|
||||
flags="${flags:+$flags }-fgnu89-inline"
|
||||
fi
|
||||
if printf '%s\n' "$directives" | grep -q -- '-fwrapv'; then
|
||||
flags="${flags:+$flags }-fwrapv"
|
||||
fi
|
||||
if printf '%s\n' "$directives" | grep -q -- '-finstrument-functions'; then
|
||||
flags="${flags:+$flags }-finstrument-functions"
|
||||
fi
|
||||
printf '%s' "$flags"
|
||||
}
|
||||
|
||||
loader_end_for() {
|
||||
awk -F '\t' -v id="$1" '$1 == id { print $2; exit }' "$LOADER_FILE"
|
||||
}
|
||||
|
||||
full_loader_for() {
|
||||
awk -F '\t' -v n="$1" '$1 == n && $1 !~ /^#/ { print $2 "\t" $3; exit }' \
|
||||
"$FULL_LOADER_FILE"
|
||||
}
|
||||
|
||||
# Stable driver-compatible category for a failed runner invocation. The
|
||||
# ordering mirrors scripts/tests/m7/full-suite.sh classify_failure().
|
||||
classify_failure() {
|
||||
log=$1
|
||||
rc=$2
|
||||
runwork=$3
|
||||
if [ -n "$runwork" ] && [ -f "$runwork/result.txt" ] \
|
||||
&& grep -q '== run the COFF in MAME' "$log" 2>/dev/null; then
|
||||
loader_hex=$(sed -n 's/^loader=//p' "$runwork/result.txt" \
|
||||
| tr -d '\r' | head -n 1)
|
||||
case $loader_hex in
|
||||
''|00000000) ;;
|
||||
*)
|
||||
echo loader
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
case $rc in
|
||||
124|137)
|
||||
echo timeout
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
if grep -q 'MAME exited 124' "$log" 2>/dev/null \
|
||||
|| grep -q 'timed out' "$log" 2>/dev/null; then
|
||||
echo timeout
|
||||
elif grep -q 'no completion magic' "$log" 2>/dev/null; then
|
||||
echo timeout
|
||||
elif grep -q 'LLVM ERROR:' "$log" 2>/dev/null \
|
||||
|| grep -q 'PLEASE submit a bug report' "$log" 2>/dev/null \
|
||||
|| grep -q 'Stack dump' "$log" 2>/dev/null \
|
||||
|| grep -q 'Aborted' "$log" 2>/dev/null \
|
||||
|| grep -q 'Segmentation fault' "$log" 2>/dev/null \
|
||||
|| grep -q 'Bus error' "$log" 2>/dev/null \
|
||||
|| grep -q 'Illegal instruction' "$log" 2>/dev/null; then
|
||||
echo crash
|
||||
elif grep -q 'missing tool:' "$log" 2>/dev/null \
|
||||
|| grep -q 'classifier error' "$log" 2>/dev/null \
|
||||
|| grep -q 'missing source' "$log" 2>/dev/null \
|
||||
|| grep -q 'missing expected output' "$log" 2>/dev/null; then
|
||||
echo harness
|
||||
elif grep -q 'COFF loader rejected' "$log" 2>/dev/null; then
|
||||
echo loader
|
||||
elif grep -q 'output mismatch' "$log" 2>/dev/null \
|
||||
|| grep -q 'stderr mismatch' "$log" 2>/dev/null \
|
||||
|| grep -q 'output truncated' "$log" 2>/dev/null \
|
||||
|| grep -q 'stderr truncated' "$log" 2>/dev/null; then
|
||||
echo output
|
||||
elif grep -q 'status mismatch' "$log" 2>/dev/null; then
|
||||
echo status
|
||||
elif grep -q 'compile/link failed' "$log" 2>/dev/null \
|
||||
|| grep -q 'linker produced no map' "$log" 2>/dev/null \
|
||||
|| grep -q 'has no M4 LINK: PASS' "$log" 2>/dev/null \
|
||||
|| grep -q 'linker produced no COFF' "$log" 2>/dev/null; then
|
||||
echo compile
|
||||
elif grep -q 'MAME produced no CONF result' "$log" 2>/dev/null \
|
||||
|| grep -q 'loader did not verify' "$log" 2>/dev/null \
|
||||
|| grep -q 'result file has no' "$log" 2>/dev/null \
|
||||
|| grep -q 'MAME exited' "$log" 2>/dev/null; then
|
||||
echo crash
|
||||
elif grep -q '^CONFORMANCE: FAIL ' "$log" 2>/dev/null; then
|
||||
echo status
|
||||
else
|
||||
echo unclassified
|
||||
fi
|
||||
}
|
||||
|
||||
result_field() {
|
||||
file=$1
|
||||
key=$2
|
||||
if [ ! -f "$file" ]; then
|
||||
printf ''
|
||||
return 0
|
||||
fi
|
||||
sed -n "s/^$key=//p" "$file" | tr -d '\r' | head -n 1
|
||||
}
|
||||
|
||||
# Decode the runner's uppercase hex stdout and return its last non-empty line,
|
||||
# sanitised to printable ASCII. This is normally the test's last check before
|
||||
# an abort (many c-torture tests print a marker per subtest).
|
||||
decode_lastline() {
|
||||
printf '%s\n' "$1" | awk 'BEGIN { hex = "0123456789ABCDEF" }
|
||||
{
|
||||
s = toupper($0)
|
||||
if (length(s) % 2 == 1) s = "0" s
|
||||
out = ""
|
||||
for (i = 1; i < length(s); i += 2) {
|
||||
hi = index(hex, substr(s, i, 1)) - 1
|
||||
lo = index(hex, substr(s, i + 1, 1)) - 1
|
||||
if (hi < 0 || lo < 0) continue
|
||||
out = out sprintf("%c", hi * 16 + lo)
|
||||
}
|
||||
n = split(out, lines, "\n")
|
||||
last = ""
|
||||
for (j = 1; j <= n; j++) {
|
||||
line = lines[j]
|
||||
gsub(/[^ -~]/, ".", line)
|
||||
gsub(/^[ \t]+|[ \t]+$/, "", line)
|
||||
if (line != "") last = line
|
||||
}
|
||||
printf "%s", last
|
||||
}'
|
||||
}
|
||||
|
||||
run_one() {
|
||||
id=$1
|
||||
opt=$2
|
||||
corpus=${id%%/*}
|
||||
name=${id#*/}
|
||||
safe_id=$(printf '%s' "$id" | tr -c 'A-Za-z0-9._-' '_')
|
||||
src=
|
||||
expected=
|
||||
case $corpus in
|
||||
c-torture) src=$C_TORTURE_DIR/$name.c ;;
|
||||
c-testsuite)
|
||||
src=$C_TESTSUITE_DIR/$name.c
|
||||
expected=$C_TESTSUITE_DIR/$name.c.expected
|
||||
[ -f "$expected" ] || expected=$C_TESTSUITE_DIR/$name.expected
|
||||
;;
|
||||
esac
|
||||
|
||||
logdir=$WORK/logs/$opt/$corpus
|
||||
mkdir -p "$logdir"
|
||||
log=$logdir/$name.log
|
||||
runwork=$WORK/run-${opt#-}/$safe_id
|
||||
|
||||
extra_cflags=$(dialect_flags "$corpus" "$name" "$src")
|
||||
test_loader_end=$(loader_end_for "$id")
|
||||
[ -n "$test_loader_end" ] || test_loader_end=$LOADER_END
|
||||
|
||||
bare=1
|
||||
full_row=$(full_loader_for "$name")
|
||||
full_linker=os2
|
||||
if [ -n "$full_row" ]; then
|
||||
bare=0
|
||||
full_linker=$(printf '%s' "$full_row" | cut -f2)
|
||||
[ -n "$full_linker" ] || full_linker=os2
|
||||
fi
|
||||
os2=1
|
||||
if [ "$bare" = 0 ] && [ "$full_linker" = 1987 ]; then
|
||||
os2=0
|
||||
fi
|
||||
|
||||
start=$(date +%s)
|
||||
set +e
|
||||
if [ "$corpus" = c-torture ]; then
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$test_loader_end \
|
||||
MAME_TIMEOUT=$TIME_LIMIT \
|
||||
M5_CONFORMANCE_WORK=$WORK/run-${opt#-} \
|
||||
M5_CONFORMANCE_CLANG_OPT=$opt M5_CONFORMANCE_LLC_OPT=$opt \
|
||||
M5_CONFORMANCE_MODE=native \
|
||||
M5_CONFORMANCE_BARE=$bare \
|
||||
M4_OS2=$os2 \
|
||||
M5_CONFORMANCE_EXTRA_CFLAGS=$extra_cflags \
|
||||
timeout --kill-after=10 "$((TIME_LIMIT + 90))" \
|
||||
"$RUN" --id "$id" --classify --mode native \
|
||||
--expect-status 0 --ignore-output --timeout "$TIME_LIMIT" \
|
||||
"$src" > "$log" 2>&1
|
||||
else
|
||||
LOADER_AT=$LOADER_AT LOADER_END=$test_loader_end \
|
||||
MAME_TIMEOUT=$TIME_LIMIT \
|
||||
M5_CONFORMANCE_WORK=$WORK/run-${opt#-} \
|
||||
M5_CONFORMANCE_CLANG_OPT=$opt M5_CONFORMANCE_LLC_OPT=$opt \
|
||||
M5_CONFORMANCE_MODE=native \
|
||||
M5_CONFORMANCE_BARE=$bare \
|
||||
M4_OS2=$os2 \
|
||||
M5_CONFORMANCE_EXTRA_CFLAGS= \
|
||||
timeout --kill-after=10 "$((TIME_LIMIT + 90))" \
|
||||
"$RUN" --id "$id" --classify --mode native \
|
||||
--expect-status 0 --expect-output-file "$expected" \
|
||||
--timeout "$TIME_LIMIT" "$src" > "$log" 2>&1
|
||||
fi
|
||||
rc=$?
|
||||
set -e
|
||||
end=$(date +%s)
|
||||
printf '%s\n' "$rc" > "$log.rc"
|
||||
elapsed=$((end - start))
|
||||
|
||||
case $rc in
|
||||
0)
|
||||
result=pass
|
||||
;;
|
||||
2)
|
||||
if grep -q '^CONFORMANCE: SKIP ' "$log" 2>/dev/null; then
|
||||
skip_reason=$(sed -n 's/^CONFORMANCE: SKIP id=[^ ]* reason=//p' \
|
||||
"$log" | head -n 1)
|
||||
[ -n "$skip_reason" ] || skip_reason=classifier
|
||||
result="skip:$skip_reason"
|
||||
else
|
||||
category=$(classify_failure "$log" "$rc" "$runwork")
|
||||
result="fail:$category"
|
||||
fi
|
||||
;;
|
||||
1)
|
||||
category=$(classify_failure "$log" "$rc" "$runwork")
|
||||
result="fail:$category"
|
||||
;;
|
||||
124|137)
|
||||
result=fail:timeout
|
||||
;;
|
||||
*)
|
||||
result=fail:crash
|
||||
;;
|
||||
esac
|
||||
|
||||
result_file=$runwork/result.txt
|
||||
status=$(result_field "$result_file" status)
|
||||
magic=$(result_field "$result_file" magic)
|
||||
out=$(result_field "$result_file" out)
|
||||
err=$(result_field "$result_file" err)
|
||||
len=$(result_field "$result_file" len)
|
||||
printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' \
|
||||
"$id" "$opt" "$rc" "$result" "$status" "$magic" "$out" "$err" \
|
||||
"$len" "$log" >> "$EVIDENCE"
|
||||
printf '%-44s %-2s %-12s status=%s magic=%s (%ss)\n' \
|
||||
"$id" "$opt" "$result" "${status:-none}" "${magic:-none}" "$elapsed"
|
||||
}
|
||||
|
||||
if [ "$REDO" -eq 1 ]; then
|
||||
rm -f "$EVIDENCE"
|
||||
fi
|
||||
[ -f "$EVIDENCE" ] || : > "$EVIDENCE"
|
||||
|
||||
ROWS_ATTEMPTED=0
|
||||
while IFS= read -r row; do
|
||||
[ -n "$row" ] || continue
|
||||
if [ "$LIMIT" -gt 0 ] && [ "$ROWS_ATTEMPTED" -ge "$LIMIT" ]; then
|
||||
break
|
||||
fi
|
||||
id=${row%% *}
|
||||
for opt in -O0 -O2; do
|
||||
if [ "$REDO" -eq 0 ] \
|
||||
&& awk -F '\t' -v i="$id" -v o="$opt" \
|
||||
'$1 == i && $2 == o { found = 1 } END { exit !found }' \
|
||||
"$EVIDENCE" 2>/dev/null; then
|
||||
continue
|
||||
fi
|
||||
run_one "$id" "$opt"
|
||||
done
|
||||
ROWS_ATTEMPTED=$((ROWS_ATTEMPTED + 1))
|
||||
done < "$ROWS"
|
||||
|
||||
# --- assemble the machine-readable TSV and the raw Markdown table ----------
|
||||
# One row per discovered file, joining the curated class table with the two
|
||||
# opt-level evidence lines. A missing opt level is shown as "not-run".
|
||||
awk -F '\t' '
|
||||
FNR == NR { cls[$1] = $2; next }
|
||||
{
|
||||
id = $1; opt = $2; rc = $3; result = $4
|
||||
stv = $5; mgv = $6; outv = $7; errv = $8; logf = $10
|
||||
if (!(id in seen)) { seen[id] = 1; order[++n] = id }
|
||||
res[id, opt] = result
|
||||
st[id, opt] = stv
|
||||
mg[id, opt] = mgv
|
||||
out[id, opt] = outv
|
||||
err[id, opt] = errv
|
||||
logp[id, opt] = logf
|
||||
}
|
||||
END {
|
||||
print "corpus/name\tcurated class\t-O0 result\t-O2 result\tstatus O0\tstatus O2\tmagic O0\tmagic O2\tfirst differing marker\tfirst O0/O2 difference\tevidence"
|
||||
for (k = 1; k <= n; k++) {
|
||||
id = order[k]
|
||||
s0 = st[id, "-O0"]; s2 = st[id, "-O2"]
|
||||
m0 = mg[id, "-O0"]; m2 = mg[id, "-O2"]
|
||||
r0 = res[id, "-O0"]; r2 = res[id, "-O2"]
|
||||
if (r0 == "") r0 = "not-run"
|
||||
if (r2 == "") r2 = "not-run"
|
||||
marker = ""
|
||||
if (s0 != "" && s0 != "00000000") marker = "status=" s0
|
||||
if (s2 != "" && s2 != "00000000")
|
||||
marker = marker (marker == "" ? "" : "; ") "status=" s2
|
||||
if (m0 != "" && m0 != "434F4E46")
|
||||
marker = marker (marker == "" ? "" : "; ") "magic=" m0
|
||||
if (m2 != "" && m2 != "434F4E46")
|
||||
marker = marker (marker == "" ? "" : "; ") "magic=" m2
|
||||
if (marker == "") {
|
||||
if (r0 ~ /^fail:/ || r2 ~ /^fail:/) marker = "runner " r0 " / " r2
|
||||
else marker = "-"
|
||||
}
|
||||
diff = ""
|
||||
if (r0 != "not-run" && r2 != "not-run") {
|
||||
if (s0 != s2) diff = "status " s0 " -> " s2
|
||||
else if (out[id, "-O0"] != out[id, "-O2"]) diff = "stdout bytes differ"
|
||||
else if (err[id, "-O0"] != err[id, "-O2"]) diff = "stderr bytes differ"
|
||||
else diff = "none"
|
||||
} else diff = "not-run"
|
||||
ev = logp[id, "-O2"]
|
||||
if (ev == "") ev = logp[id, "-O0"]
|
||||
printf "%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", \
|
||||
id, cls[id], r0, r2, s0, s2, m0, m2, marker, diff, ev
|
||||
}
|
||||
}' "$CLASSES" "$EVIDENCE" > "$TSV"
|
||||
|
||||
# Markdown table: add the decoded last output line (the abort marker) by
|
||||
# re-reading each result.txt through the shell decoder once per row.
|
||||
{
|
||||
echo "# M12 runtime-abort triage (raw)"
|
||||
echo
|
||||
echo "- generated: $(date -u '+%Y-%m-%dT%H:%M:%SZ')"
|
||||
echo "- discovered rows: $DISCOVERED (from scripts/tests/m7/full-suite.skip; the file was not modified)"
|
||||
echo "- opt levels: -O0 and -O2"
|
||||
echo "- per-test MAME timeout: ${TIME_LIMIT}s, outer wall $((TIME_LIMIT + 90))s"
|
||||
echo "- work: $WORK"
|
||||
echo
|
||||
echo "| corpus/name | curated class | -O0 | -O2 | status (-O0 / -O2) | magic (-O0 / -O2) | last output marker | first O0/O2 difference |"
|
||||
echo "|---|---|---|---|---|---|---|---|"
|
||||
} > "$TABLE"
|
||||
|
||||
tail -n +2 "$TSV" | while IFS=' ' read -r id cls r0 r2 s0 s2 m0 m2 marker diff ev; do
|
||||
o0file=$WORK/run-O0/$(printf '%s' "$id" | tr -c 'A-Za-z0-9._-' '_')/result.txt
|
||||
o2file=$WORK/run-O2/$(printf '%s' "$id" | tr -c 'A-Za-z0-9._-' '_')/result.txt
|
||||
line0=$(decode_lastline "$(result_field "$o0file" out)")
|
||||
line2=$(decode_lastline "$(result_field "$o2file" out)")
|
||||
[ -n "$line0" ] || line0=-
|
||||
[ -n "$line2" ] || line2=-
|
||||
outmarker=$line0
|
||||
if [ "$line0" != "$line2" ]; then
|
||||
outmarker="$line0 / $line2"
|
||||
fi
|
||||
printf '| %s | %s | %s | %s | %s / %s | %s / %s | %s | %s |\n' \
|
||||
"$id" "$cls" "$r0" "$r2" "${s0:--}" "${s2:--}" "${m0:--}" "${m2:--}" \
|
||||
"$outmarker" "$diff" >> "$TABLE"
|
||||
done
|
||||
|
||||
# Summary by curated class, counted from the discovered rows (not guessed).
|
||||
{
|
||||
echo
|
||||
echo "## Discovered rows by curated class"
|
||||
echo
|
||||
echo "| class | rows |"
|
||||
echo "|---|---|"
|
||||
cut -f2 "$CLASSES" | LC_ALL=C sort | uniq -c \
|
||||
| awk '{ printf "| %s | %d |\n", $2, $1 }'
|
||||
} >> "$TABLE"
|
||||
|
||||
echo
|
||||
echo "abort-triage: discovered $DISCOVERED rows"
|
||||
echo "abort-triage: table $TABLE"
|
||||
echo "abort-triage: tsv $TSV"
|
||||
echo "abort-triage: logs $WORK/logs"
|
||||
@@ -0,0 +1,61 @@
|
||||
# M12 abort-triage probes
|
||||
|
||||
Source for the representative probes cited by
|
||||
`docs/superpowers/research/2026-11-19-tms34010-abort-triage.md` (§4 causes,
|
||||
§5 one-flag ruling). They are kept in the repository so the triage's
|
||||
load-bearing claims can be re-inspected and re-run; the historical run logs
|
||||
are under `logs/`.
|
||||
|
||||
Each probe is compiled and run through the same M5 conformance runner and the
|
||||
same bare-tier settings the triage harness uses. From the repository root:
|
||||
|
||||
```sh
|
||||
probe=simd1probe
|
||||
M5_CONFORMANCE_WORK=build/m12-probe-run \
|
||||
M5_CONFORMANCE_MODE=native M5_CONFORMANCE_BARE=1 \
|
||||
M5_CONFORMANCE_CLANG_OPT=-O0 M5_CONFORMANCE_LLC_OPT=-O0 \
|
||||
M4_OS2=1 LOADER_AT=200 LOADER_END=1000 MAME_TIMEOUT=120 \
|
||||
scripts/tests/m5/conformance/run.sh --id "probe/$probe" --classify \
|
||||
--mode native --expect-status 0 --ignore-output --timeout 120 \
|
||||
"scripts/tests/m12/probes/$probe.c"
|
||||
```
|
||||
|
||||
The probe's `main` return value becomes the runner status under
|
||||
`--expect-status 0`, so a `CONFORMANCE: FAIL ... status=0000000A` line means
|
||||
the probe returned 10. `logs/` keeps the original run output, including the
|
||||
`MAME exited 139` cases.
|
||||
|
||||
The endianness probes (`pr65401probe.c`, and the `20230630-*`/`bitfld-*` files
|
||||
run under the override) add the frontend-only macro override:
|
||||
|
||||
```sh
|
||||
M5_CONFORMANCE_EXTRA_CFLAGS='-U__BIG_ENDIAN__ -D__BYTE_ORDER__=1234'
|
||||
```
|
||||
|
||||
## What each probe shows
|
||||
|
||||
| Probe | Claim it supports | Observed |
|
||||
|---|---|---|
|
||||
| `va931004probe.c` | aggregate `va_arg` returns the wrong struct; the trailing `long` is never reached (§4.1) | status `0x1` |
|
||||
| `simd1probe.c` | vector **add** is already wrong; first failing check is `k = i + j` (§4.2) | status `0xA` |
|
||||
| `astkalign.c` | `__alignof__(aligned(64))` is clamped under the packed default (§4.5) | status `0x1` |
|
||||
| `azerolen.c` | zero-length-array struct alignment differs from its `int` (§4.5) | status `0x2` |
|
||||
| `a20010904.c` | `return (char-diff & 31)` folds to 0 (§4.5) | pass (`0`) |
|
||||
| `a20010904b.c` | the same expression as `if (expr & 31) return 1` folds to true (§4.5) | status `0x1` |
|
||||
| `a20010904c.c` | the probe's own linked stride is small; the corpus mismatch is the real 1028-byte stride (§4.5) | pass (`0`) |
|
||||
| `ptrdiff.c` | `(int)&a[1] - (int)&a[0]` is in bit units, not bytes (§4.6) | status `0x8` |
|
||||
| `fpr35456.c` | `x >= 0 ? x : -x` loses the sign of `-0.0` (§4.7) | status `0x1` |
|
||||
| `fpr44683.c` | `copysign(1.0, -0.0) < 0.0` is false (§4.7) | status `0x3` |
|
||||
| `f20080502.c` | `long double` signbit path differs (§4.7) | status `0x1` |
|
||||
| `f20031003.c` | both out-of-range float→int conversions differ from `INT_MAX` (§4.8) | status `0x3` |
|
||||
| `ffloatunsisf.c` | unsigned→float rounding differs from the literal conversion (§4.8) | status `0x1` |
|
||||
| `isprint.c` | bare-tier `_isprint` reads a zero `__ctypes_` (§4.9) | no log retained; `isprint('a') == 1` is false |
|
||||
| `sprintfhex.c` | `sprintf("%#hhx", 0)` returns 3, i.e. `"0x0"` (§4.9) | status `0x3` |
|
||||
| `sprintf6.c` | the same `%#hhx`-of-zero deviation inside the full test's checks (§4.9) | status `0x2` |
|
||||
| `pr65401probe.c` | the test's own loops pass with the little-endian macro override; the failure is the `__BYTE_ORDER__` branch (§4.4) | pass with override |
|
||||
| `firstbyte.c`, `firstbyte3.c` | bitfield first-byte extraction probes (§4.4) | `firstbyte.c` host-segfaults (`MAME exited 139`); the bare-tier instability noted in §8 |
|
||||
| `20230630-1` (`log-e-*`) | the macro override passes through the full loader; the bare tier host-segfaults (§4.4, §8) | pass (full loader); `MAME exited 139` (bare `-O0`) |
|
||||
|
||||
`isprint.c` and `sprintfret.c`/`sprintfret2.c` are retained sources whose
|
||||
historical logs were not kept; their claims are stated in the research
|
||||
document and are reproducible with the command above.
|
||||
@@ -0,0 +1,4 @@
|
||||
typedef struct x { int a; int b; } __attribute__((aligned(32))) X;
|
||||
typedef struct y { X x[32]; int c; } Y;
|
||||
Y y[2];
|
||||
int main(void){ return ((char*)&y[1] - (char*)&y[0]) & 31; }
|
||||
@@ -0,0 +1,4 @@
|
||||
typedef struct x { int a; int b; } __attribute__((aligned(32))) X;
|
||||
typedef struct y { X x[32]; int c; } Y;
|
||||
Y y[2];
|
||||
int main(void){ if (((char*)&y[1] - (char*)&y[0]) & 31) return 1; return 0; }
|
||||
@@ -0,0 +1,4 @@
|
||||
typedef struct x { int a; int b; } __attribute__((aligned(32))) X;
|
||||
typedef struct y { X x[32]; int c; } Y;
|
||||
Y y[2];
|
||||
int main(void){ long d = (char*)&y[1] - (char*)&y[0]; return (int)(d >> 8); }
|
||||
@@ -0,0 +1 @@
|
||||
int main(void){ static struct { char c __attribute__((aligned(64))); } s; return __alignof__(s); }
|
||||
@@ -0,0 +1,3 @@
|
||||
typedef int word __attribute__((mode(word)));
|
||||
struct foo { word x; word y[0]; };
|
||||
int main(){ return (sizeof(word)!=sizeof(struct foo)) + 2*(__alignof__(word)!=__alignof__(struct foo)); }
|
||||
@@ -0,0 +1,54 @@
|
||||
c-torture/20010904-1 align-packed-abi L
|
||||
c-torture/20010904-2 align-packed-abi L
|
||||
c-torture/20021127-1 freestanding-builtin out
|
||||
c-torture/20031003-1 float-conv M
|
||||
c-torture/20050604-1 vector-ops L
|
||||
c-torture/20050607-1 vector-ops L
|
||||
c-torture/20060420-1 vector-ops L
|
||||
c-torture/20080502-1 signed-zero M
|
||||
c-torture/20230630-1 endian-macro+sso M
|
||||
c-torture/20230630-3 endian-macro+sso M
|
||||
c-torture/920428-1 ptr-int-model out
|
||||
c-torture/920625-1 aggregate-varargs L
|
||||
c-torture/931004-10 aggregate-varargs L
|
||||
c-torture/931004-12 aggregate-varargs L
|
||||
c-torture/931004-14 aggregate-varargs L
|
||||
c-torture/931004-2 aggregate-varargs L
|
||||
c-torture/931004-4 aggregate-varargs L
|
||||
c-torture/931004-6 aggregate-varargs L
|
||||
c-torture/931004-8 aggregate-varargs L
|
||||
c-torture/991112-1 rts-shim S
|
||||
c-torture/bitfld-3 bitfield-64 M
|
||||
c-torture/bitfld-5 bitfield-64 M
|
||||
c-torture/bitfld-6 endian-macro+sso M
|
||||
c-torture/bitfld-7 endian-macro+sso M
|
||||
c-torture/eeprof-1 instr-flag S
|
||||
c-torture/floatunsisf-1 float-conv M
|
||||
c-torture/pr103255 ptr-int-model out
|
||||
c-torture/pr123625 vector-ops L
|
||||
c-torture/pr32244-1 bitfield-64 M
|
||||
c-torture/pr34971 bitfield-64 M
|
||||
c-torture/pr35456 signed-zero M
|
||||
c-torture/pr38051 ptr-int-model out
|
||||
c-torture/pr38151 aggregate-varargs L
|
||||
c-torture/pr44575 aggregate-varargs L
|
||||
c-torture/pr44683 signed-zero M
|
||||
c-torture/pr57344-3 bitfield-64 M
|
||||
c-torture/pr57344-4 bitfield-64 M
|
||||
c-torture/pr58209 ptr-int-model out
|
||||
c-torture/pr65401 endian-macro+sso M
|
||||
c-torture/pr65427 vector-ops L
|
||||
c-torture/pr79327 rts-shim S
|
||||
c-torture/pr79737-2 bitfield-64 M
|
||||
c-torture/pr85169 vector-ops L
|
||||
c-torture/pr94412 vector-ops L
|
||||
c-torture/scal-to-vec1 vector-ops L
|
||||
c-torture/scal-to-vec2 vector-ops L
|
||||
c-torture/scal-to-vec3 vector-ops L
|
||||
c-torture/simd-1 vector-ops L
|
||||
c-torture/simd-2 vector-ops L
|
||||
c-torture/stdarg-3 aggregate-varargs L
|
||||
c-torture/stkalign align-packed-abi L
|
||||
c-torture/strct-stdarg-1 aggregate-varargs L
|
||||
c-torture/strct-varg-1 aggregate-varargs L
|
||||
c-torture/zerolen-2 align-packed-abi L
|
||||
|
@@ -0,0 +1,3 @@
|
||||
int f1(){ return (int)2147483648.0f; }
|
||||
int f2(){ return (int)(float)(2147483647); }
|
||||
int main(){ return (f1()!=2147483647) + 2*(f2()!=2147483647); }
|
||||
@@ -0,0 +1,2 @@
|
||||
long double __attribute__((noinline)) foo (long double x) { return __builtin_signbit(x) ? 3.1415926535897932384626433832795029L : 0.0; }
|
||||
int main(void){ return foo(-1.0L) != 3.1415926535897932384626433832795029L; }
|
||||
@@ -0,0 +1,3 @@
|
||||
volatile unsigned u = 0x80000081;
|
||||
volatile float f1, f2;
|
||||
int main(void){ f1=(float)u; f2=(float)0x80000081; return f1!=f2; }
|
||||
@@ -0,0 +1,2 @@
|
||||
struct S { short int i : 12; char c1 : 1; char c2 : 1; char c3 : 1; char c4 : 1; };
|
||||
int main(void) { struct S s0 = { 341, 1, 1, 1, 1 }; volatile char *p = (char *)&s0; return (unsigned char)*p; }
|
||||
@@ -0,0 +1,2 @@
|
||||
struct S { __INT32_TYPE__ i : 24; char c1:1,c2:1,c3:1,c4:1,c5:1,c6:1,c7:1,c8:1; };
|
||||
int main(void) { struct S s0 = { 1193046,1,1,1,1,1,1,1,1 }; char *p=(char*)&s0; return (unsigned char)*p; }
|
||||
@@ -0,0 +1,2 @@
|
||||
double __attribute__((noinline)) not_fabs (double x) { return x >= 0.0 ? x : -x; }
|
||||
int main(){ double x=-0.0; double y=not_fabs(x); return __builtin_signbit(y)?0:1; }
|
||||
@@ -0,0 +1,2 @@
|
||||
int __attribute__((noinline,noclone)) copysign_bug (double x){ if (x != 0.0 && (x*0.5 == x)) return 1; if (__builtin_copysign(1.0,x) < 0.0) return 2; return 3; }
|
||||
int main(void){ double x=-0.0; return copysign_bug(x); }
|
||||
@@ -0,0 +1,2 @@
|
||||
int isprint(int);
|
||||
int main(void) { return isprint('a') == 1 ? 0 : (isprint('a') ? 1 : 2); }
|
||||
@@ -0,0 +1,12 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (20230630-1-O0, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/20230630-1-O0/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
Warning: -video none doesn't make much sense without -seconds_to_run
|
||||
ALSA lib seq_hw.c:540:(snd_seq_hw_open) open /dev/snd/seq failed: Permission denied
|
||||
vt1200: screen_update#1 frame=0 clip_y=0..0 screen=1280x901
|
||||
vt1200: screen_update#2 frame=0 clip_y=1..900 screen=1280x901
|
||||
vt1200: guard#1 frame=0 dump_frame=-1 dump_ram=-1
|
||||
BARE: entry=018A0000 sp=01A80000 sections=3
|
||||
Segmentation fault
|
||||
conformance: FAIL: MAME exited 139
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (20230630-1-O2, -O2, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/20230630-1-O2/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=20230630-1-O2 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (20230630-3-O0, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/20230630-3-O0/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=20230630-3-O0 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (20230630-3-O2, -O2, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/20230630-3-O2/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=20230630-3-O2 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (bitfld-6-O0, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/bitfld-6-O0/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=bitfld-6-O0 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (bitfld-6-O2, -O2, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/bitfld-6-O2/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=bitfld-6-O2 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (bitfld-7-O0, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/bitfld-7-O0/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=bitfld-7-O0 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (bitfld-7-O2, -O2, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work-endian/bitfld-7-O2/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=bitfld-7-O2 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (a20010904, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/a20010904/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=a20010904 status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (astkalign, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/astkalign/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=astkalign status=00000001 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000001
|
||||
work dir: /tmp/opencode/abort-probes/work2/astkalign
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (azerolen, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/azerolen/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=azerolen status=00000002 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000002
|
||||
work dir: /tmp/opencode/abort-probes/work2/azerolen
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (f20031003, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/f20031003/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=f20031003 status=00000003 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000003
|
||||
work dir: /tmp/opencode/abort-probes/work2/f20031003
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (f20080502, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/f20080502/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=f20080502 status=00000001 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000001
|
||||
work dir: /tmp/opencode/abort-probes/work2/f20080502
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (ffloatunsisf, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/ffloatunsisf/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=ffloatunsisf status=00000001 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000001
|
||||
work dir: /tmp/opencode/abort-probes/work2/ffloatunsisf
|
||||
@@ -0,0 +1,12 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (firstbyte, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/firstbyte/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
Warning: -video none doesn't make much sense without -seconds_to_run
|
||||
ALSA lib seq_hw.c:540:(snd_seq_hw_open) open /dev/snd/seq failed: Permission denied
|
||||
vt1200: screen_update#1 frame=0 clip_y=0..0 screen=1280x901
|
||||
vt1200: screen_update#2 frame=0 clip_y=1..900 screen=1280x901
|
||||
vt1200: guard#1 frame=0 dump_frame=-1 dump_ram=-1
|
||||
BARE: entry=018A0000 sp=01A80000 sections=3
|
||||
Segmentation fault
|
||||
conformance: FAIL: MAME exited 139
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (fpr35456, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/fpr35456/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=fpr35456 status=00000001 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000001
|
||||
work dir: /tmp/opencode/abort-probes/work2/fpr35456
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (fpr44683, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/fpr44683/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=fpr44683 status=00000003 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000003
|
||||
work dir: /tmp/opencode/abort-probes/work2/fpr44683
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (sprintf6, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work2/sprintf6/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=sprintf6 status=00000002 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000002
|
||||
work dir: /tmp/opencode/abort-probes/work2/sprintf6
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (a20010904b, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work3/a20010904b/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=a20010904b status=00000001 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000001
|
||||
work dir: /tmp/opencode/abort-probes/work3/a20010904b
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (a20010904c, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work3/a20010904c/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=a20010904c status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
@@ -0,0 +1,7 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (sprintfhex, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work3/sprintfhex/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: FAIL id=sprintfhex status=00000003 expected_status=00000000 stdout_len=0 stderr_len=0
|
||||
status mismatch: expected 00000000, got 00000003
|
||||
work dir: /tmp/opencode/abort-probes/work3/sprintfhex
|
||||
@@ -0,0 +1,5 @@
|
||||
== extract the 1990 flib.lib/rts.lib for the shim's %f
|
||||
== compile and link (pr65401probe, -O0, mode=native)
|
||||
linked /tmp/opencode/abort-probes/work4/pr65401probe/m4/m4.coff (native)
|
||||
== run the COFF in MAME (native bare)
|
||||
CONFORMANCE: PASS id=pr65401probe status=00000000 stdout_len=0 stderr_len=0 link=native
|
||||
Loaded 100 of 208 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user