Compare commits

25 Commits
Author SHA1 Message Date
arti 9d704defd0 Merge pull request 'tms34010: Morton's 1994 GCC 2.5.8 cc1, and the hosts TI shipped the tools for' (#15) from opencode.energia.arti.ee/vt1200:docs/tms34010-hosts-and-morton-gcc into master
Reviewed-on: arti/vt1200#15
2026-11-17 05:04:50 +02:00
arti 68bebf7a91 Merge pull request 'docs(tms34010-sdk): as34/ld34 are Morton's 1994 GNU toolchain, not this SDK' (#14) from opencode.energia.arti.ee/vt1200:docs/as34-attribution into master
Reviewed-on: arti/vt1200#14
2026-11-17 04:59:52 +02:00
opencode.energia.arti.ee 0a129016a7 chore(gitignore): ignore MAME's snapshot directory
MAME writes -snapshot to snap/<romname>/ when it is run from the repo root.
The one file there is a 1024x864 VR150 frame of the level-0 diagnostics menu
-- scratch, not evidence.
2026-11-17 02:42:57 +00:00
opencode.energia.arti.ee 311d127673 reference(tms340-hosts): the non-DOS hosts TI shipped the tools for
Research note plus the two manuals and the Third-Party Guide that document
them: TI sold the TMS34010/34020 C compiler and code generation tools for
VAX/VMS, VAX/Ultrix, VAX System V, Apollo Domain/IX and AEGIS, Sun-3,
Sun-4/SunOS and Macintosh/MPW, not just MS-DOS and OS/2.

No public dump of those host builds is known: the archives hold the DOS/OS2
binaries and the manuals, not the 1600 bpi tapes and 800K diskettes.  So
this records what the installation chapters and the 1990 Third-Party Guide
say, and where to keep looking, rather than pretending we have the tools.

PDFs and extracted text come from the same mirror as the tool packages;
SHA256SUMS pins every file.
2026-11-17 02:42:57 +00:00
opencode.energia.arti.ee 632682e436 tools(tms34010-gcc-akpm): Morton's GCC 2.5.8 TMS34010 port (cc1)
The compiler half of Andrew Morton's Unix-hosted TMS34010 toolchain,
recovered from zip.com.au/~akpm/gsptools.html through the Wayback Machine
(snapshot 20080210052433): the 2.5.8 source with the 34010 port, the fixes
needed to build cc1 with a modern 32-bit host GCC (cc1-port.patch), and
build/test scripts.

This is not TI's compiler, and it is cc1 only: no driver and no
preprocessor.  Its runtime, libc and an example live in the gsp tarball
that tools/as34/build.sh already fetches; as34/ld34/dis34 are ported
there.

build-cc1.sh was verified on Debian 12 / GCC 14.2.0; test-cc1.sh runs
cc1 -> as34 -> ld34 -> raw -> dis34 and checks the generated TMS34010 code
shape (register-argument ABI, recursive callr + mpys).
2026-11-17 02:42:56 +00:00
opencode.energia.arti.ee 8ae6b0bf60 docs(tms34010-sdk): as34/ld34 are Morton's 1994 GNU toolchain, not this SDK
Both notes said the `as34`/`lnk34` names "appear to be a later name or
another part" of TI's package.  They belong to Andrew Morton's 1994
Unix-hosted GNU TMS34010 toolchain (`as34`, `ld34`, `dis34`), which this
project ports in `tools/as34/`; TI's SDK ships GSPA/GSPLNK.  Name the real
owner and keep the point that the TI package has no `as34`.
2026-11-17 02:37:43 +00:00
arti 2b3e1f14f2 Merge pull request 'docs(tms34010-sdk): the r5.01 2ine pipeline and gspcl' (#13) from opencode.energia.arti.ee/vt1200:docs/r5.01-2ine-pipeline into master
Reviewed-on: arti/vt1200#13
2026-11-17 04:32:35 +02:00
opencode b032347cf0 docs(tms34010-sdk): what gspcl chains, the fork's status note, exit codes
Be precise about the driver: `gspcl` chains compile -> optimize -> codegen ->
assemble; `-z` adds the link, and everything after `-z` is a linker option, so
the libraries follow. That form was measured: `gspcl -k -o2 file.c -z -o
file.out rts.lib flib.lib` exits 0 and leaves file.out.

`3bcdfc3` is the fork's `TMS34010.md` status update, not this document's.

The exit status is an observation from the verified runs, not a loader
contract: `lxTerminate` keeps only the low 8 bits of an OS/2 exit code.

Also record the 2026-11-16 re-verification, bring the OS/2 route's heading and
lead in line with its body, and give that route's CMake command the policy
floor CMake 4.x needs.
2026-11-17 02:31:27 +00:00
opencode fecd0a950d docs(tms34010-sdk): drop the broken-2ine caveats
The docs now describe the working r5.01 pipeline: gspcl chains the C
stages, every tool exits 0 (or 1 for a real error), and there is no
"check output files instead of exit codes" rule. The old 139/SIGSEGV
story stays in git history.
2026-11-17 02:30:20 +00:00
opencode cca0383a79 docs(tms34010-sdk): what the 2ine 139 exit status was
gspac and gspcg returning 139 was a real SIGSEGV, not a strange exit
code: they free their automatic data segment (DGROUP), which also holds
the running 16-bit stack, just before DosExit; lxFreeSegment unmapped it
and the 16->32 bridge faulted returning through it. Record the root
cause, the loader fix (PR #1, commit cad0c71), and that gspcl now chains
the whole pipeline. Keep the "check output files" rule for unpatched
loader builds.
2026-11-17 02:30:20 +00:00
arti 6ae2358ae6 Merge pull request 'refactor(termtris): one shared harness for the six tests' (#12) from opencode.siil.arti.ee/vt1200:fix/issue-6-7-termtris-harness into master
Reviewed-on: arti/vt1200#12
2026-11-13 11:56:49 +02:00
arti 717f5ba10e Merge pull request 'docs(xie): the ROM's XImage entry points and the 1-bit format' (#11) from opencode.siil.arti.ee/vt1200:fix/issue-4-ximage into master
Reviewed-on: arti/vt1200#11
2026-11-13 11:56:26 +02:00
arti a06adb1bc8 Merge pull request 'docs(loader): the per-process XG block must exist before XOpenDisplay' (#10) from opencode.siil.arti.ee/vt1200:fix/issue-2-xg-block into master
Reviewed-on: arti/vt1200#10
2026-11-13 11:55:45 +02:00
arti 4554c9274e Merge pull request 'fix(loader): exit the harness on completion, and add LOADER_END=0' (#9) from opencode.siil.arti.ee/vt1200:fix/issue-3-loader-completion into master
Reviewed-on: arti/vt1200#9
2026-11-13 11:54:55 +02:00
opencode 9e7472051d refactor(termtris): one shared harness for the six tests 2026-11-13 09:46:50 +00:00
opencode 2c2ba3bd5f docs(xie): the ROM's XImage entry points and the 1-bit format 2026-11-13 09:36:29 +00:00
opencode 3f6eb56749 docs(loader): document the per-process XG block and add vt_install_xg 2026-11-13 09:26:29 +00:00
opencode 1339b43a3e fix(loader): exit on completion and add LOADER_END=0 2026-11-13 09:22:48 +00:00
arti 0b3db19cef Merge pull request 'docs: XMapWindow is 0x3FD64F60; 0x3FD645B0 is XRaiseWindow' (#8) from opencode.siil.arti.ee/vt1200:fix/issue-1-xmapwindow into master
Reviewed-on: arti/vt1200#8
2026-11-13 11:22:33 +02:00
opencode 6b2ef0690c docs(gui): correct XMapWindow and name 0x3FD645B0 XRaiseWindow 2026-11-13 09:20:18 +00:00
arti 772311bc5b Merge pull request 'termtris: the VT1200 port, running at the VR319 default' (#5) from opencode.siil.arti.ee/vt1200:termtris into master
Reviewed-on: arti/vt1200#5
2026-11-13 08:52:44 +02:00
opencode 58f8f4491c docs(termtris): correct the build commands and solved addresses
Review findings on the documentation:

- The build blocks did not cd, and used paths relative to the repo root
  while build.sh resolves them from the caller's cwd; VT1200.md also
  omitted OUTNAME, so it produced build/main.coff.  Show
  `cd apps/termtris && OUTNAME=termtris ./build.sh ...`.
- The link map quoted .cinit at 018B4B10; it moved to 018B4A60 when the
  Expose branch was removed, and the loader log confirms it.
- VT1200.md still credited the seed portability edit to now_ms(); the
  code uses vt_rand_seed().
- Treat 0x7F as Delete and 0x08 as Backspace, and stop claiming
  FocusIn/FocusOut tracks the game's own manual pause (it does not).
- Say that focus=00400001 is sampled on the click's ButtonRelease;
  quit=1 is the key-delivery proof.
- Record the real ExposureMask consequence (an occluding window is not
  repainted) in VT1200.md's Limits and as a deviation in the design
  spec, instead of only in HANDOFF.md.
2026-11-13 06:15:17 +00:00
opencode 4c7d94ea34 fix(termtris): fix the build runner and the stale-image path
Review findings on the port:

- run() expanded ${LX_RUNNER} while it was unset on the normal path,
  which is a fatal unbound-variable error under `set -eu`; the probe
  only sets it on kernels without 16-bit LDT support.  Default it to
  empty and expand with ${LX_RUNNER:-}.
- Clear each stage's expected output before every retry and require a
  non-empty result, so a stale or partially written file cannot be
  mistaken for success.  Print the loader's captured output when a
  stage really fails instead of discarding it.
- Widen the probe to recognise "modify_ldt" as well as the exact abort
  message.
- run.sh --build passed no OUTNAME, so it built build/main.coff and
  then ran the tracked build/termtris.coff.  Build termtris.coff.
- Stop tracking the generated build/termtris.coff and .map: they are
  rebuilt by every acceptance run, churn on the COFF timestamp, and
  fed the stale-binary trap above.  Add them to .gitignore.
- Correct verify.sh's header comment (it runs all tests, then fails).
2026-11-13 06:15:16 +00:00
opencode 8df2320d6d docs(termtris): re-run acceptance at the VR319 default
The branch's evidence was captured on an older MAME binary whose frames
were VR150 (1024x864).  Rebuild MAME from this tree's driver and re-run
verify.sh --skip-mame at the VR319 default (1280x1024 active).

All six tests pass.  Event counts, focus=00400001, tick=887 and quit=1
are unchanged; only the main-loop counts moved with the frame cadence:
move 650, panels 648, quit 555 (was 354/346/300).  The evidence PNGs are
regenerated at 1280x1024.  Record the numbers and the geometry change in
VT1200.md, TERMTRIS_REPORT.md and HANDOFF.md, and note the qemu-i386
toolchain fallback.
2026-11-12 05:56:56 +00:00
opencode ce40582e9d fix(termtris): run the 2ine loader under qemu-i386 when the kernel lacks 16-bit LDT
The r5.01 tools are 16-bit OS/2 NE programs.  A Linux kernel built
without CONFIG_X86_16BIT (this box's cloud kernel) rejects modify_ldt
for 16-bit segments, so lx_loader aborts at its first segment even
though it is a 32-bit binary.  Probe for that failure and use
qemu-i386, whose linux-user modify_ldt supports 16-bit segments.
LX_RUNNER overrides the choice.  The toolchain output is unchanged:
the build completes in ~10 s and the COFF differs only in its header
timestamp.
2026-11-12 05:35:30 +00:00
69 changed files with 72234 additions and 2450 deletions

No files matched your search

+2
View File
@@ -42,6 +42,7 @@ harness/mame/gui.log
/cfg/
/nvram/
/roms/
/snap/
# Large media: the source recording stays out of git (a YouTube download,
# trivially re-obtainable). The derived frames and contact sheets ARE committed,
@@ -77,4 +78,5 @@ apps/termtris/build/smoke.*
apps/termtris/build/fmt.*
apps/termtris/build/render.*
apps/termtris/build/input.*
apps/termtris/build/termtris.*
apps/termtris/evidence/loader_frame*.png
+37 -37
View File
@@ -1,10 +1,8 @@
# Handoff — termtris running inside the VT1200
Everything here is on branch **`termtris`** of
`https://git.wut.ee/opencode.energia.arti.ee/vt1200.git` (remote `origin`).
The branch was developed in a worktree at
`/home/arti/.local/share/opencode/worktree/26e92e/termtris`; any checkout of the
branch is equivalent.
`https://git.wut.ee/opencode.energia.arti.ee/vt1200.git` (remote `origin`); any
checkout of the branch is equivalent.
```sh
git fetch origin termtris
@@ -14,9 +12,10 @@ apps/termtris/verify.sh
`verify.sh` is the whole acceptance run: ROM checksum, toolchain check, MAME
build (skip with `--skip-mame`), the six tests, the acceptance summary and the
evidence list. It exits non-zero on the first failure and keeps every test log
under `apps/termtris/build/verify_<name>.log`. `RUNTIME` is roughly 12 minutes
once MAME is built; the MAME build itself is the long part.
evidence list. It keeps every test log under
`apps/termtris/build/verify_<name>.log`, runs all six tests even after a
failure, and exits non-zero at the end if any failed. `RUNTIME` is roughly 12
minutes once MAME is built; the MAME build itself is the long part.
## What is done
@@ -36,39 +35,32 @@ high-score panels, moving/rotating/dropping pieces, and `q` to quit.
| game integration, scores, COFF | done, `play.sh`/`play_keys.sh` PASS | `41d3cec` |
| docs + harness report | done | `3e2ddde` |
| review pass (seed, focus, expose, assertions) | done | `7a2cef5` |
| handoff script + this note | done | (this commit) |
| handoff script + this note | done | `a12fb47` |
| qemu-i386 fallback for kernels without 16-bit LDT | done, `verify.sh` PASS | `ce40582` |
| VR319 re-run, regenerated evidence, updated numbers | done, `verify.sh` PASS | (this commit) |
`VT1200.md` is the port documentation; `harness/mame/TERMTRIS_REPORT.md` is the
harness-side report; the design and plan are in
`docs/superpowers/specs/2026-11-03-termtris-vt1200-design.md` and
`docs/superpowers/plans/2026-11-03-termtris-vt1200.md`.
## What is *not* done yet — read this first
## The VR319 re-run — done
All screenshots and the acceptance numbers in the docs were produced with an
**older MAME binary** (`/home/arti/code/k-space/mame0289/vt1200d`, 30 Oct) that
predates the driver's VR319 default. That binary has no `VT1200_MONITOR`, and
its frames are 1024×864, i.e. the old VR150 geometry. The driver in this tree
defaults to **VR319** (1280×1024 active, 1696×1063 raster), which changes the
frame cadence and therefore the frame at which the loader and the tests act.
The screenshots and the acceptance numbers used to come from an **older MAME
binary** (`/home/arti/code/k-space/mame0289/vt1200d`, 30 Oct) that predates the
driver's VR319 default. That binary has no `VT1200_MONITOR`, and its frames are
1024×864, i.e. the old VR150 geometry. The driver in this tree defaults to
**VR319** (1280×1024 active, 1696×1063 raster), which changes the frame cadence
and therefore the frame at which the loader and the tests act.
So on the new box, after `harness/mame/build.sh`:
1. Re-run `apps/termtris/verify.sh --skip-mame` and note the new
`DIAG: loops=... events=... quit=...` values.
2. Re-capture the screenshots (the test scripts write them into
`apps/termtris/evidence/`) and look at them: the board must still be a
bordered well with `[`/`]` tetrominoes, the score/level/lines boxes on the
right, and the preview box. The window is positioned at (80,80) inside a
larger raster, so the PNGs get bigger but the window content is unchanged.
3. Update the numbers in `VT1200.md` ("Acceptance values") and in
`harness/mame/TERMTRIS_REPORT.md`, and say plainly that the earlier figures
were VR150.
If the behaviour itself changes at VR319 (pieces not visible, no events), that
is a real finding, not a formatting detail — the loader acts at frame 2500 and
the keys at 3100–3290, which may need re-timing if the new raster shifts the
frame budget.
The branch has now been re-run against a fresh MAME 0.289 build of this tree's
driver at the VR319 default. `apps/termtris/verify.sh --skip-mame` passes all
six tests, the evidence PNGs were regenerated at **1280×1024**, and the new
`DIAG` values are in `VT1200.md` and `harness/mame/TERMTRIS_REPORT.md`. The
behaviour did not change: same events, same window (`focus=00400001`), same
`quit=1`, board/panels/preview all visible. Only the loop counts moved, because
the VR319 raster runs at a different emulated frame rate. The loader still acts
at frame 2500 and the keys at 3095–3190; no re-timing was needed.
## Prerequisites on the new box
@@ -79,13 +71,21 @@ frame budget.
`tools/tms34010-sdk/1990-11 TMS340 Family SDK/`;
* `vt1200_v22.bin` in the repo root (the harness ROM dir symlinks to it).
The r5.01 tools are 16-bit OS/2 `NE` programs. If the host kernel was built
without `CONFIG_X86_16BIT`, `lx_loader` cannot create their 16-bit LDT
segments and aborts at its first one; `build.sh` detects that and runs the same
loader under `qemu-i386` (install `qemu-user`), or honours an explicit
`LX_RUNNER` command prefix. This box's cloud kernel is one of those; the
generated COFF is unchanged.
`verify.sh` checks the ROM and the 2ine loader before doing anything, and
`harness/mame/build.sh` re-registers the driver in `mame.lst` and builds the
single-driver `vt1200` subtarget.
## Expected results
Last run here (older MAME, VR150 geometry):
Last full run (MAME 0.289, this tree's driver, **VR319 default**, 1280×1024
frames; the earlier figures were VR150):
```
smoke PASS type=2 keycode=194 lookup_n=1 ch=61 ks=0061
@@ -94,9 +94,9 @@ render PASS flus=464C5553 progress=00FFFFFF
input PASS bytes 61 9B 41 9B 42 9B 44 9B 43 30 0A 7F 71 70
(a/up/down/left/right/0/Return/Delete/q/p)
play PASS DIAG: tick=887 quit=0
play_keys PASS move DIAG: loops=354 events=18 focus=00400001 quit=0
panels DIAG: loops=346 events=12 focus=00400001 quit=0
quit DIAG: loops=300 events=10 focus=00400001 quit=1
play_keys PASS move DIAG: loops=650 events=18 last=3 focus=00400001 rev=0 quit=0
panels DIAG: loops=648 events=12 last=3 focus=00400001 rev=0 quit=0
quit DIAG: loops=555 events=10 last=3 focus=00400001 rev=0 quit=1
```
`focus=00400001` is the window the process created; `quit=1` is the game's own
@@ -127,7 +127,7 @@ apps/termtris/
├── src/vt1200/ main.c x11.c xgfix.c compat.c xlib.h scoredb.c *.asm
├── tests/ smoke fmt render input play play_keys (+ .lua drivers)
├── evidence/ screenshots
└── build/termtris.coff the built image (tracked for convenience)
└── build/termtris.coff the built image (ignored; rebuild with build.sh)
```
The tests build from source every run (`play.sh`/`play_keys.sh` rebuild
+51 -22
View File
@@ -13,7 +13,7 @@ loaded into VT1200 RAM and executed by the TMS34010.
| piece | file | role |
|---|---|---|
| game rules | `src/game.c` (upstream) | unchanged logic; one portability edit (`srand((now_ms()))` instead of `time(0)`) |
| game rules | `src/game.c` (upstream) | unchanged logic; one portability edit (`srand(vt_rand_seed())` instead of `time(0)`) |
| term callbacks | `src/vt1200/x11.c` | 80×24 character-cell grid drawn with `XFillRectangle`/`XDrawString` |
| event loop | `src/vt1200/main.c` | `XNextEvent` + `XLookupString`, key map, millisecond clock, `sleep()` |
| scores | `src/vt1200/scoredb.c` | RAM-only high-score table (no filesystem) |
@@ -25,26 +25,42 @@ loaded into VT1200 RAM and executed by the TMS34010.
## Building
```sh
apps/termtris/build.sh src/vt1200/main.c src/game.c src/vt1200/scoredb.c \
src/vt1200/x11.c src/vt1200/compat.c src/vt1200/xgfix.c
cd apps/termtris
OUTNAME=termtris ./build.sh src/vt1200/main.c src/game.c \
src/vt1200/scoredb.c src/vt1200/x11.c src/vt1200/compat.c \
src/vt1200/xgfix.c
```
`build.sh` unpacks the r5.01 SDK zips, runs `gspac`/`gspopt`/`gspcg`/`gspa` and
`gsplnk` through `lx_loader`, and writes `build/<main>.coff` + `.map`. Set
`NINE=` to the 2ine build directory (default `/home/arti/os2-work/2ine/build`).
The 2ine-hosted tools routinely segfault *after* producing their output, so the
script treats an output file as success and retries a missing one; `gspac` needs
`-i.` for the angle-bracket shim headers.
`gsplnk` through `lx_loader`, and writes `build/termtris.coff` + `.map` (without
`OUTNAME` it uses the first source's name). Set `NINE=` to the 2ine build
directory (default `/home/arti/os2-work/2ine/build`). The 2ine-hosted tools
routinely segfault *after* producing their output, so the script clears the
expected output, treats a non-empty file as success, and retries a missing one;
`gspac` needs `-i.` for the angle-bracket shim headers.
The r5.01 programs are 16-bit OS/2 `NE` executables. `lx_loader` is 32-bit but
maps them through 16-bit LDT segments, and a Linux kernel built without
`CONFIG_X86_16BIT` rejects those (`modify_ldt` returns `EINVAL`) — the loader
then aborts at its first segment even though it starts. On such a host
`build.sh` probes for that failure and runs the same loader through
`qemu-i386`, whose linux-user `modify_ldt` does implement 16-bit segments. Set
`LX_RUNNER=qemu-i386` to force a runner, or install `qemu-user` so the fallback
is available. The generated COFF is unchanged; only its header timestamp
differs between builds.
Link map (relevant addresses are **bit** addresses, like everything the
TMS34010 sees):
```
.text 018A0000 .data 018A0000 .cinit 018B4B10
.text 018A0000 .data 018A0000 .cinit 018B4A60
.bss 01A00000
ENTRY POINT SYMBOL: "_start" address: 018a0000
```
The `.cinit` address moves when the code changes; this block matches the
current build's `build/termtris.map`.
An empty `.cinit` makes the linker point `cinit` at `.text`, and the entry
walker would then read an instruction as a record count; when the map says the
section is empty `build.sh` relinks with the one-word `CINITZ.obj` terminator.
@@ -76,8 +92,8 @@ earlier per-cell version (four requests per cell) filled the X socket faster
than the in-machine server could drain it, and an `XSync` per row deadlocked
the client: the debug progress marker stopped at row 20 (`0x00010014`) and the
game never reached its main loop. Batching the row makes a full 80×24 redraw a
few hundred bytes of requests and the loop runs (measured: 300+ iterations
between frames 2500 and 3200).
few hundred bytes of requests and the loop runs (measured at the VR319
default: 650 iterations between frames 2500 and 3200).
## Timing and input
@@ -89,14 +105,16 @@ level 0).
Keys arrive as X11 `KeyPress` events and go through `XLookupString`; letters are
lower-cased and handed to `game_input()`. Arrows are sent as the game's own CSI
codes (`0x9b` + `A`/`B`/`C`/`D`), which `game_input` translates back to
`w`/`s`/`d`/`a`. `0x7F` is Backspace/Delete. `FocusOut` pauses and `FocusIn`
resumes (only if we paused it).
`w`/`s`/`d`/`a`. `0x7F` is Delete (Backspace is `0x08`). `FocusOut` sends `p`
and `FocusIn` sends `p` again, but the flag only tracks focus, not the game's
own pause state: pressing `p` and then moving focus away resumes the game while
it is unfocused.
`ExposureMask` is deliberately **not** selected: the map-time `Expose` arrives
before the game has a current piece, and the game's full-redraw path then draws
a non-existent piece over the top row — visible as a blanked border with stray
`X` tiles. The window is never obscured in this session (the Terminal Manager
sits beside it), so the mask buys nothing. See `HANDOFF.md`.
`X` tiles. The acceptance run never obscures the window (the Terminal Manager
sits beside it), so the mask buys nothing there. See `HANDOFF.md`.
## Running it in MAME
@@ -133,17 +151,25 @@ which copies the sections to their linked addresses and calls
| `evidence/termtris_quit_3200.png` | after `q`: same screen, and the run reports `quit=1` |
| `evidence/render_frame3400.png` | the cell-grid renderer test pattern |
Acceptance values from the last full run (`play_keys.sh`):
Acceptance values from the last full run (`play_keys.sh`, MAME 0.289 with this
tree's driver at the **VR319 default**, 1280×1024 frames). The evidence PNGs
above were regenerated in the same run; they are 1280×1024, where the earlier
ones were 1024×864 VR150 captures.
```
move DIAG: loops=354 events=18 focus=00400001 quit=0
panels DIAG: loops=346 events=12 focus=00400001 quit=0
quit DIAG: loops=300 events=10 focus=00400001 quit=1
move DIAG: loops=650 events=18 last=3 focus=00400001 rev=0 quit=0
panels DIAG: loops=648 events=12 last=3 focus=00400001 rev=0 quit=0
quit DIAG: loops=555 events=10 last=3 focus=00400001 rev=0 quit=1
```
`focus=00400001` is the window this process created (it is the only one in the
run), so the key events were delivered to it, and `quit=1` is the game's own
global after `q`.
`focus=00400001` is the window this process created, sampled on the click's
`ButtonRelease` (it is the only window in the run). It shows the click reached
the right window, not that each later key did; the key-delivery proof is
`quit=1`, the game's own global after `q`. The loop counts are higher than the
old VR150 figures
(`354`/`346`/`300`) only because the VR319 raster runs at a different emulated
frame rate; the event counts, window, and quit result are unchanged, and the
loader/keys still act at frames 2500/3095–3190.
## Limits, stated plainly
@@ -160,6 +186,9 @@ global after `q`.
exit in this OS. Treat that as an observation, not a designed behaviour.
* **The board is text.** Tetrominoes are `[`/`]` tiles, not filled blocks — the
only thing a 1-bit cell can show without a custom font.
* **An occluding window is not repainted.** Because `ExposureMask` is off (the
map-time `Expose` bug above), cells covered by another window stay stale until
the game next draws them. The acceptance run does not exercise this.
The ROM (`vt1200_v22.bin`, md5 `b46a3e442ccb86134d2356bd70d22fd2`) is never
modified; the port lives entirely in RAM.
+31 -2
View File
@@ -32,6 +32,29 @@ if [ ! -x "$WORK/gspac.exe" ]; then
unzip -oq "$Z1" -d "$WORK"
unzip -oq "$Z2" -d "$WORK"
fi
# The r5.01 tools are 16-bit OS/2 NE programs, which 2ine runs through 16-bit
# LDT segments. A Linux kernel built without CONFIG_X86_16BIT rejects those
# (modify_ldt returns EINVAL), so the loader aborts at its first segment even
# though it is a 32-bit binary. Detect that with a probe run and, when needed,
# drive the same loader through qemu-i386, whose linux-user emulation does
# implement the 16-bit LDT. Set LX_RUNNER to a command prefix (for example
# "qemu-i386") to force one; leave it unset to auto-detect.
LX_RUNNER=${LX_RUNNER:-}
if [ -z "$LX_RUNNER" ]; then
probe=$( ( cd "$WORK" && "$LX" ./gspac.exe ) 2>&1 || true )
case $probe in
*failed\ to\ allocate\ LDT\ selector*|*modify_ldt*)
if command -v qemu-i386 >/dev/null 2>&1; then
LX_RUNNER=qemu-i386
else
echo "build.sh: this kernel has no 16-bit LDT support and qemu-i386 is not installed" >&2
echo "build.sh: install qemu-user, or set LX_RUNNER to a working runner" >&2
exit 1
fi
;;
esac
fi
for so in "$NINE"/lib*.so; do
[ -e "$so" ] && ln -sf "$so" "$WORK/"
done
@@ -77,14 +100,20 @@ run() {
_out=$1
shift
i=0
_log=
while [ "$i" -lt 5 ]; do
( cd "$WORK" && "$LX" "$@" ) >/dev/null 2>&1 || true
if [ -f "$WORK/$_out" ]; then
# A stage that crashed after a partial write must not be mistaken
# for success, and an output left by an earlier build must not
# hide a failing stage now.
rm -f "$WORK/$_out"
_log=$( ( cd "$WORK" && ${LX_RUNNER:-} "$LX" "$@" ) 2>&1 || true )
if [ -s "$WORK/$_out" ]; then
return 0
fi
i=$((i + 1))
done
echo "build.sh: stage failed to produce $WORK/$_out: $*" >&2
[ -n "$_log" ] && printf '%s\n' "$_log" | tail -10 >&2
return 1
}
Binary file not shown.
-141
View File
@@ -1,141 +0,0 @@
*****************************************************
TMS340 COFF Linker Version 5.01
*****************************************************
Thu Nov 12 05:18:17 2026
OUTPUT FILE NAME: <MAIN.out>
ENTRY POINT SYMBOL: "_start" address: 018a0000
MEMORY CONFIGURATION
name origin length attributes
-------- -------- --------- ----------
prog 018a0000 000020000 RWIX
ram 01a00000 000040000 RWIX
SECTION ALLOCATION MAP
output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.text 0 018a0000 00014a60
018a0000 00000150 ENTRY.obj (.text)
018a0150 00001db0 MAIN.obj (.text)
018a1f00 0000ce50 GAME.obj (.text)
018aed50 00000d20 SCOREDB.obj (.text)
018afa70 00002a40 X11.obj (.text)
018b24b0 00001640 COMPAT.obj (.text)
018b3af0 00000210 XGFIX.obj (.text)
018b3d00 00000450 rts.lib (.text)
018b4150 000001a0 rts.lib (.text)
018b42f0 00000230 rts.lib (.text)
018b4520 00000150 rts.lib (.text)
018b4670 00000120 rts.lib (.text)
018b4790 00000110 rts.lib (.text)
018b48a0 000001c0 rts.lib (.text)
.cinit 0 018b4a60 000012d0
018b4a60 00000050 MAIN.obj (.cinit)
018b4ab0 00001190 GAME.obj (.cinit)
018b5c40 00000050 SCOREDB.obj (.cinit)
018b5c90 00000050 X11.obj (.cinit)
018b5ce0 00000050 rts.lib (.cinit)
.bss 0 01a00000 0001ec20 UNINITIALIZED
01a00000 00008000 ENTRY.obj (.bss)
01a08000 00000420 MAIN.obj (.bss)
01a08420 00004a40 GAME.obj (.bss)
01a0ce60 00000b80 SCOREDB.obj (.bss)
01a0d9e0 0000f200 X11.obj (.bss)
01a1cbe0 00000020 COMPAT.obj (.bss)
01a1cc00 00002000 XGFIX.obj (.bss)
01a1ec00 00000020 rts.lib (.bss)
.data 0 018a0000 00000000 UNINITIALIZED
GLOBAL SYMBOLS
address name address name
-------- ---- -------- ----
01a00000 .bss 018a0000 .data
018a0000 .data 018a0000 .text
018a0000 .text 018a0000 _start
01a08a20 _blackpf 018a0000 edata
018a3060 _cleanup_game 018a0150 _now_ms
01a083a0 _dbg_events 018a03d0 _vt_rand_seed
01a083e0 _dbg_focus 018a0420 _sleep_ms
01a083c0 _dbg_last 018a0580 _vt_poll_event
01a08380 _dbg_loops 018a0ef0 _vt_handle_event
01a08400 _dbg_rev 018a1820 _wait_display
018b24b0 _fflush 018a1860 _main
018a8600 _game_input 018a1f00 _init_game
018a1f00 _init_game 018a3060 _cleanup_game
018a1860 _main 018a3250 _update
018b3d00 _memcpy 018a8600 _game_input
018b3ea0 _memmove 018af0b0 _read_scores
018b4150 _memset 018af430 _save_score
01a089c0 _monochrome 018af9c0 _print_scores
018a0150 _now_ms 018afa70 _vt_root_window
01a08a00 _onlyascii 018afb50 _vt_x11_init
018af9c0 _print_scores 018b0300 _x11_clearscr
018b2520 _putchar 018b04c0 _x11_reset
01a08960 _quit 018b0500 _x11_cursor
018b42f0 _rand 018b0560 _x11_setcolor
018af0b0 _read_scores 018b0680 _x11_setcursor
01a08a40 _rotstep 018b08d0 _x11_ibmchar
018af430 _save_score 018b0d50 _term_putstr
01a08aa0 _scr 018b0ef0 _vt_x11_flush
018a0420 _sleep_ms 018b2120 _vt_x11_term_init
018b2d30 _sprintf 018b2440 _term_init
018b4450 _srand 018b24b0 _fflush
018a0000 _start 018b2520 _putchar
01a1cbe0 _stdout 018b2d30 _sprintf
018b4520 _strcmp 018b3af0 _vt_install_xg
018b4670 _strcpy 018b3d00 _memcpy
018b4790 _strlen 018b3ea0 _memmove
018b48a0 _strncpy 018b4150 _memset
01a1cb00 _term_clearscr 018b42f0 _rand
01a1cb40 _term_cursor 018b4450 _srand
01a08a80 _term_height 018b4520 _strcmp
01a1cb80 _term_ibmchar 018b4670 _strcpy
018b2440 _term_init 018b4790 _strlen
018b0d50 _term_putstr 018b48a0 _strncpy
01a1cae0 _term_reset 018b4a60 cinit
01a1cb60 _term_setcolor 018b4a60 etext
01a1cb20 _term_setcursor 01a00000 .bss
01a1cbc0 _term_type 01a08380 _dbg_loops
01a08a60 _term_width 01a083a0 _dbg_events
01a1cba0 _termenv 01a083c0 _dbg_last
01a08980 _tick_interval 01a083e0 _dbg_focus
018a3250 _update 01a08400 _dbg_rev
01a089a0 _use_bell 01a08960 _quit
01a089e0 _use_gfxchar 01a08980 _tick_interval
01a0ce60 _username 01a089a0 _use_bell
01a1ca60 _vt_dpy 01a089c0 _monochrome
01a1caa0 _vt_gc 01a089e0 _use_gfxchar
018a0ef0 _vt_handle_event 01a08a00 _onlyascii
018b3af0 _vt_install_xg 01a08a20 _blackpf
018a0580 _vt_poll_event 01a08a40 _rotstep
018a03d0 _vt_rand_seed 01a08a60 _term_width
018afa70 _vt_root_window 01a08a80 _term_height
01a1ca80 _vt_win 01a08aa0 _scr
018b0ef0 _vt_x11_flush 01a0ce60 _username
018afb50 _vt_x11_init 01a1ca60 _vt_dpy
01a1cac0 _vt_x11_progress 01a1ca80 _vt_win
018b2120 _vt_x11_term_init 01a1caa0 _vt_gc
018a1820 _wait_display 01a1cac0 _vt_x11_progress
018b0300 _x11_clearscr 01a1cae0 _term_reset
018b0500 _x11_cursor 01a1cb00 _term_clearscr
018b08d0 _x11_ibmchar 01a1cb20 _term_setcursor
018b04c0 _x11_reset 01a1cb40 _term_cursor
018b0560 _x11_setcolor 01a1cb60 _term_setcolor
018b0680 _x11_setcursor 01a1cb80 _term_ibmchar
018b4a60 cinit 01a1cba0 _termenv
018a0000 edata 01a1cbc0 _term_type
01a1ec20 end 01a1cbe0 _stdout
018b4a60 etext 01a1ec20 end
[77 symbols]
Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 22 KiB

+1 -1
View File
@@ -16,7 +16,7 @@ LOADER="$ROOT/dwt/loader/build/loader.bin"
COFF="$DIR/build/termtris.coff"
if [ "${1:-}" = "--build" ]; then
"$DIR/build.sh" "$DIR/src/vt1200/main.c" "$DIR/src/game.c" \
OUTNAME=termtris "$DIR/build.sh" "$DIR/src/vt1200/main.c" "$DIR/src/game.c" \
"$DIR/src/vt1200/scoredb.c" "$DIR/src/vt1200/x11.c" \
"$DIR/src/vt1200/compat.c" "$DIR/src/vt1200/xgfix.c"
fi
+10 -340
View File
@@ -1,354 +1,24 @@
-- loader.lua -- debugger-assisted COFF loader acceptance harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes:
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
-- * the loader descriptor at 0x01882C00
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
-- or any firmware transport: this is the debugger-assisted milestone.
--
-- The loader itself copies the COFF sections to their linked bit addresses and
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
-- the input and reads the result; it never writes the app's code or markers.
--
-- Env:
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
-- fmt.lua -- six formatted strings, read back from the app's output cells.
-- fmt.sh checks each FMT:n line byte-for-byte.
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
local H = dofile(dir .. "/harness.lua")
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local machine = manager.machine
local FMT_MARK = tonumber(os.getenv("FMT_MARK") or "0x01A00000")
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
end
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
local SNAP = os.getenv("LOADER_SNAP") == "1"
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local RETURN_STUB = 0x01883100
local RETURN_SP = 0x01883110
local function rd(p) return io.open(p, "rb") end
local function slurp(p)
local f, err = rd(p)
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local function rstr(a, n)
local t = {}
for i = 0, n - 1 do
local c = prog:read_u8(a + i * 8)
local c = H.prog:read_u8(a + i * 8)
if c == 0 then break end
t[#t + 1] = string.char(c)
end
return table.concat(t)
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
local TRACE = os.getenv("LOADER_TRACE") == "1"
local frames = 0
local injected = false
local done = false
local last_count = -1
local function status_name(v)
local t = {
[0] = "OK",
[1] = "bad descriptor",
[2] = "truncated COFF / section headers",
[3] = "bad COFF magic",
[4] = "section size not whole words",
[5] = "target outside RAM",
[6] = "target overlaps loader page or COFF buffer",
[7] = "relocation records present (unsupported)",
[8] = "target not in a free-list block",
[9] = "no entry point",
}
return t[v] or ("error " .. tostring(v))
end
local function result_dump()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
poke_bytes(LOADER_BASE, loader)
n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(BUF, coff)
n, bad = verify_bytes(BUF, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(BUF)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
H.result_dump(function()
for i = 0, 5 do
print(string.format("FMT:%d [%s]", i, rstr(FMT_MARK + i * 0x80, 16)))
end
end)
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, MODE)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
-- itself); mode 1 returns here, and the stub resumes the interrupted
-- PC so the caller yields and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
if MODE == 1 then
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
else
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
end
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
-- the return slot so mode=1 would return to the spin stub.
-- Leave SP alone for mode 0: the loader pushes onto the current
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
-- would use the return stub.)
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = A8DESC and DESC or 0
if MODE == 1 then
-- Simulate a CALLA from the current process: push the return
-- address on the *firmware* stack (a real transport would do this).
local sp = cpu.state['SP'].value - 0x20
w32(sp, RETURN_STUB)
cpu.state['SP'].value = sp
end
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
result_dump()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
local base = COFF:match("([^/]+)$") or COFF
if base:find("marker") then
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
hex(r32(0x018E0060)), r32(0x018E0080)))
elseif base:find("xhello") then
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
end
if base:find("fmt") then
for i = 0, 5 do
print(string.format("FMT:%d [%s]", i, rstr(FMT_MARK + i * 0x80, 16)))
end
end
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == AT and not injected then
inject()
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
end
if injected and TRACE and frames == AT + 1 then
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
end
if VERBOSE and frames % 25 == 0 then
result_dump()
end
if base_contains_marker then
local c = r32(0x018E0080)
if c ~= last_count then
if last_count ~= -1 then
print(string.format("LOADER: marker counter %d -> %d (child running)",
last_count, c))
end
last_count = c
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
end, "vt1200-loader")
-- (Lua has no forward use of a name defined later; set a small flag here.)
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
H.run()
+354
View File
@@ -0,0 +1,354 @@
-- harness.lua -- the shared debugger-assisted COFF loader harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes the loader payload at bit 0x01880000,
-- the app's GSPLNK COFF at LOADER_BUF (default bit 0x01900000) and the loader
-- descriptor at 0x01882C00, and sets PC = 0x01880000. No network, no rdebug:
-- this is the debugger-assisted milestone. The loader copies the COFF sections
-- to their linked bit addresses and calls
-- create_process(entry, "LOADER", 0x6000, 1, 0); this harness only pokes the
-- input and reads the result, it never writes the app's code.
--
-- A test is configuration plus hooks:
--
-- local H = dofile(<dir> .. "/harness.lua")
-- H.config{ tablet = "SMOKE" }
-- H.sequence(3100, 20, { { ":lk401:K26", "A" } })
-- H.result_dump(function() print(...) end)
-- H.run()
--
-- Env (the tests/*.sh contract): LOADER_BIN, LOADER_COFF, LOADER_BUF,
-- LOADER_AT, LOADER_END, LOADER_OUT, LOADER_SNAP, LOADER_VERBOSE, and the
-- DIAG_LOOPS/EVENTS/LAST/FOCUS/REV/QUIT/TICK bit addresses (a missing one
-- prints -1).
--
-- The exit is the fixed LOADER_END frame, never an early completion: the tests
-- read the snapshot at that frame (loader_frame<LOADER_END>.png).
local H = {}
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local machine = manager.machine
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
H.machine, H.cpu, H.dbg, H.prog, H.hex = machine, cpu, dbg, prog, hex
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local cfg = {
bin = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin",
coff = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff",
buf = tonumber(os.getenv("LOADER_BUF") or "0x01900000"),
at = tonumber(os.getenv("LOADER_AT") or "2500"),
endf = tonumber(os.getenv("LOADER_END") or "2700"),
out = os.getenv("LOADER_OUT") or "dwt/loader/evidence",
snap = os.getenv("LOADER_SNAP") == "1",
verbose = os.getenv("LOADER_VERBOSE") == "1",
}
local diag = {
loops = tonumber(os.getenv("DIAG_LOOPS") or "0") or 0,
events = tonumber(os.getenv("DIAG_EVENTS") or "0") or 0,
last = tonumber(os.getenv("DIAG_LAST") or "0") or 0,
focus = tonumber(os.getenv("DIAG_FOCUS") or "0") or 0,
rev = tonumber(os.getenv("DIAG_REV") or "0") or 0,
quit = tonumber(os.getenv("DIAG_QUIT") or "0") or 0,
tick = tonumber(os.getenv("DIAG_TICK") or "0") or 0,
}
local function slurp(p)
local f, err = io.open(p, "rb")
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o) return s:byte(o + 1) + s:byte(o + 2) * 256 end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d, sections = {} }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
c.sections[#c.sections + 1] = {
name = d:sub(o + 1, o + 8):gsub("%z", ""),
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
H.r32 = r32
local STATUS = {
"OK", "bad descriptor", "truncated COFF / section headers",
"bad COFF magic", "section size not whole words", "target outside RAM",
"target overlaps loader page or COFF buffer",
"relocation records present (unsupported)",
"target not in a free-list block", "no entry point",
}
local function status_name(v) return STATUS[v + 1] or ("error " .. tostring(v)) end
local loader, coff, app
local function prepare()
loader = slurp(cfg.bin)
coff = slurp(cfg.coff)
app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", cfg.bin, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", cfg.coff, #coff, hex(cfg.buf)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
end
local function dump_result()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function cell(addr) return addr ~= 0 and r32(addr) or -1 end
local function dump_diag()
local focus = diag.focus ~= 0 and string.format("%08X", r32(diag.focus)) or "-1"
print(string.format("DIAG: loops=%d events=%d last=%d focus=%s rev=%d quit=%d",
cell(diag.loops), cell(diag.events), cell(diag.last), focus,
cell(diag.rev), cell(diag.quit)))
print(string.format("DIAG: tick=%d quit=%d", cell(diag.tick), cell(diag.quit)))
end
local events = {}
local frame_hooks = {}
local result_hooks = {}
local done_hooks = {}
local tableted = false
local function field(tag, name)
local port = machine.ioport.ports[tag]
if not port then error("no input port " .. tag) end
local f = port.fields[name]
if not f then error("no field " .. name .. " on " .. tag) end
return f
end
-- Schedule one input event at `frame`, then print `message` (if any).
function H.key(frame, tag, name, value, message)
events[#events + 1] = { frame = frame, field = field(tag, name), value = value, message = message }
end
-- Schedule a log line at a frame.
function H.message(frame, text)
events[#events + 1] = { frame = frame, message = text }
end
-- Schedule a press/release pair for each {tag, field} entry, `step` frames
-- apart, half a step between the press and the release.
function H.sequence(first, step, keys)
local half = math.floor(step / 2)
for i, k in ipairs(keys) do
local f = first + (i - 1) * step
H.key(f, k[1], k[2], 1)
H.key(f + half, k[1], k[2], 0)
end
end
function H.config(opts)
for k, v in pairs(opts or {}) do cfg[k] = v end
if cfg.tablet and not tableted then
tableted = true
local label = type(cfg.tablet) == "string" and cfg.tablet or "LOADER"
H.key(2900, ":tablet:TABLET_X", "Tablet X", 700)
H.key(2900, ":tablet:TABLET_Y", "Tablet Y", 500, label .. ": tablet move")
H.key(3000, ":tablet:TABLET_BTN", "P1 Button 1", 1, label .. ": click down")
H.key(3020, ":tablet:TABLET_BTN", "P1 Button 1", 0, label .. ": click up")
end
end
function H.on_frame(fn) frame_hooks[#frame_hooks + 1] = fn end
function H.result_dump(fn) result_hooks[#result_hooks + 1] = fn end
function H.on_done(fn) done_hooks[#done_hooks + 1] = fn end
local frames = 0
local injected = false
local done = false
local function inject()
-- 1. loader itself
poke_bytes(LOADER_BASE, loader)
local n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(cfg.buf, coff)
n, bad = verify_bytes(cfg.buf, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(cfg.buf)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
end
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (debug resume)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, cfg.buf)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, 0)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. enter the loader. A8=0 selects the fixed descriptor; mode 0 restores
-- the interrupted state and resumes at LD_ORIG_PC, so the caller yields
-- and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = 0
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
dump_result()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
for _, fn in ipairs(result_hooks) do fn() end
dump_diag()
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
local function snapshot()
if not cfg.snap then return end
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if not screen then return end
local out = cfg.out .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
local function fire_events()
for _, e in ipairs(events) do
if e.frame == frames then
if e.field then e.field:set_value(e.value) end
if e.message then print(e.message) end
end
end
end
function H.run()
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
end
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
prepare()
emu.register_frame_done(function()
frames = frames + 1
fire_events()
for _, fn in ipairs(frame_hooks) do fn(frames) end
if frames == cfg.at and not injected then inject() end
if injected and not done and cfg.verbose and frames % 25 == 0 then dump_result() end
if frames >= cfg.endf then
if injected then
done = true
inspect()
for _, fn in ipairs(done_hooks) do fn() end
snapshot()
end
machine:exit()
end
end, "vt1200-loader")
end
return H
+25 -382
View File
@@ -1,387 +1,30 @@
-- loader.lua -- debugger-assisted COFF loader acceptance harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes:
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
-- * the loader descriptor at 0x01882C00
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
-- or any firmware transport: this is the debugger-assisted milestone.
--
-- The loader itself copies the COFF sections to their linked bit addresses and
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
-- the input and reads the result; it never writes the app's code or markers.
--
-- Env:
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
-- input.lua -- main.c's key map against injected keys. input.sh checks the
-- INPUT: line for the mapped byte sequence.
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
local H = dofile(dir .. "/harness.lua")
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local machine = manager.machine
local INPUT_MARK = tonumber(os.getenv("INPUT_MARK") or "0x01A00000")
local ports = machine.ioport.ports
local key_a = ports[":lk401:K26"].fields["A"]
local key_up = ports[":lk401:K77"].fields["Up"]
local key_down = ports[":lk401:K76"].fields["Down"]
local key_left = ports[":lk401:K74"].fields["Left"]
local key_right = ports[":lk401:K75"].fields["Right"]
local key_zero = ports[":lk401:K10"].fields["0 )"]
local key_ret = ports[":lk401:K68"].fields["Return"]
local key_del = ports[":lk401:K67"].fields["Delete"]
local key_q = ports[":lk401:K13"].fields["Q"]
local key_p = ports[":lk401:K22"].fields["P"]
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
end
H.config{ tablet = "INPUT" }
H.sequence(3100, 20, {
{ ":lk401:K26", "A" },
{ ":lk401:K77", "Up" },
{ ":lk401:K76", "Down" },
{ ":lk401:K74", "Left" },
{ ":lk401:K75", "Right" },
{ ":lk401:K10", "0 )" },
{ ":lk401:K68", "Return" },
{ ":lk401:K67", "Delete" },
{ ":lk401:K13", "Q" },
{ ":lk401:K22", "P" },
})
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
local SNAP = os.getenv("LOADER_SNAP") == "1"
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
H.result_dump(function()
local n = H.r32(INPUT_MARK + 0x40)
local t = {}
for i = 0, n - 1 do t[#t + 1] = string.format("%02X", H.r32(INPUT_MARK + (3 + i) * 0x20)) end
print(string.format("INPUT: magic=%08X updates=%d n=%d bytes=%s",
H.r32(INPUT_MARK), H.r32(INPUT_MARK + 0x20), n, table.concat(t, " ")))
end)
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local RETURN_STUB = 0x01883100
local RETURN_SP = 0x01883110
local function rd(p) return io.open(p, "rb") end
local function slurp(p)
local f, err = rd(p)
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function key_step(frames, key)
if frames == 3100 then key_a:set_value(1) end
if frames == 3110 then key_a:set_value(0) end
if frames == 3120 then key_up:set_value(1) end
if frames == 3130 then key_up:set_value(0) end
if frames == 3140 then key_down:set_value(1) end
if frames == 3150 then key_down:set_value(0) end
if frames == 3160 then key_left:set_value(1) end
if frames == 3170 then key_left:set_value(0) end
if frames == 3180 then key_right:set_value(1) end
if frames == 3190 then key_right:set_value(0) end
if frames == 3200 then key_zero:set_value(1) end
if frames == 3210 then key_zero:set_value(0) end
if frames == 3220 then key_ret:set_value(1) end
if frames == 3230 then key_ret:set_value(0) end
if frames == 3240 then key_del:set_value(1) end
if frames == 3250 then key_del:set_value(0) end
if frames == 3260 then key_q:set_value(1) end
if frames == 3270 then key_q:set_value(0) end
if frames == 3280 then key_p:set_value(1) end
if frames == 3290 then key_p:set_value(0) end
end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
local TRACE = os.getenv("LOADER_TRACE") == "1"
local frames = 0
local injected = false
local done = false
local last_count = -1
local function status_name(v)
local t = {
[0] = "OK",
[1] = "bad descriptor",
[2] = "truncated COFF / section headers",
[3] = "bad COFF magic",
[4] = "section size not whole words",
[5] = "target outside RAM",
[6] = "target overlaps loader page or COFF buffer",
[7] = "relocation records present (unsupported)",
[8] = "target not in a free-list block",
[9] = "no entry point",
}
return t[v] or ("error " .. tostring(v))
end
local function result_dump()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
poke_bytes(LOADER_BASE, loader)
n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(BUF, coff)
n, bad = verify_bytes(BUF, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(BUF)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
end
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, MODE)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
-- itself); mode 1 returns here, and the stub resumes the interrupted
-- PC so the caller yields and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
if MODE == 1 then
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
else
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
end
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
-- the return slot so mode=1 would return to the spin stub.
-- Leave SP alone for mode 0: the loader pushes onto the current
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
-- would use the return stub.)
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = A8DESC and DESC or 0
if MODE == 1 then
-- Simulate a CALLA from the current process: push the return
-- address on the *firmware* stack (a real transport would do this).
local sp = cpu.state['SP'].value - 0x20
w32(sp, RETURN_STUB)
cpu.state['SP'].value = sp
end
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
result_dump()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
local base = COFF:match("([^/]+)$") or COFF
if base:find("marker") then
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
hex(r32(0x018E0060)), r32(0x018E0080)))
elseif base:find("xhello") then
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
end
if base:find("input") then
local n = r32(INPUT_MARK + 0x40)
local t = {}
for i = 0, n - 1 do t[#t + 1] = string.format("%02X", r32(INPUT_MARK + (3 + i) * 0x20)) end
print(string.format("INPUT: magic=%08X updates=%d n=%d bytes=%s",
r32(INPUT_MARK), r32(INPUT_MARK + 0x20), n, table.concat(t, " ")))
end
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == 2900 then tabx:set_value(700); taby:set_value(500); print("INPUT: tablet move") end
if frames == 3000 then tabb:set_value(1); print("INPUT: click down") end
if frames == 3020 then tabb:set_value(0); print("INPUT: click up") end
key_step(frames, nil)
if frames == AT and not injected then
inject()
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
end
if injected and TRACE and frames == AT + 1 then
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
end
if VERBOSE and frames % 25 == 0 then
result_dump()
end
if base_contains_marker then
local c = r32(0x018E0080)
if c ~= last_count then
if last_count ~= -1 then
print(string.format("LOADER: marker counter %d -> %d (child running)",
last_count, c))
end
last_count = c
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
end, "vt1200-loader")
-- (Lua has no forward use of a name defined later; set a small flag here.)
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
H.run()
+6 -348
View File
@@ -1,350 +1,8 @@
-- loader.lua -- debugger-assisted COFF loader acceptance harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes:
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
-- * the loader descriptor at 0x01882C00
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
-- or any firmware transport: this is the debugger-assisted milestone.
--
-- The loader itself copies the COFF sections to their linked bit addresses and
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
-- the input and reads the result; it never writes the app's code or markers.
--
-- Env:
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
-- play.lua -- load termtris, click it active, and snapshot the board.
-- play.sh checks LOADER: result status=0, the DIAG tick, and the snapshot.
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
local H = dofile(dir .. "/harness.lua")
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
H.config{ tablet = "PLAY" }
local machine = manager.machine
local PTICK = tonumber(os.getenv("DIAG_TICK") or "0")
local PQUIT = tonumber(os.getenv("DIAG_QUIT") or "0")
local ports = machine.ioport.ports
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
end
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
local SNAP = os.getenv("LOADER_SNAP") == "1"
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local RETURN_STUB = 0x01883100
local RETURN_SP = 0x01883110
local function rd(p) return io.open(p, "rb") end
local function slurp(p)
local f, err = rd(p)
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
local TRACE = os.getenv("LOADER_TRACE") == "1"
local frames = 0
local injected = false
local done = false
local last_count = -1
local function status_name(v)
local t = {
[0] = "OK",
[1] = "bad descriptor",
[2] = "truncated COFF / section headers",
[3] = "bad COFF magic",
[4] = "section size not whole words",
[5] = "target outside RAM",
[6] = "target overlaps loader page or COFF buffer",
[7] = "relocation records present (unsupported)",
[8] = "target not in a free-list block",
[9] = "no entry point",
}
return t[v] or ("error " .. tostring(v))
end
local function result_dump()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
poke_bytes(LOADER_BASE, loader)
n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(BUF, coff)
n, bad = verify_bytes(BUF, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(BUF)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
end
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, MODE)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
-- itself); mode 1 returns here, and the stub resumes the interrupted
-- PC so the caller yields and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
if MODE == 1 then
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
else
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
end
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
-- the return slot so mode=1 would return to the spin stub.
-- Leave SP alone for mode 0: the loader pushes onto the current
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
-- would use the return stub.)
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = A8DESC and DESC or 0
if MODE == 1 then
-- Simulate a CALLA from the current process: push the return
-- address on the *firmware* stack (a real transport would do this).
local sp = cpu.state['SP'].value - 0x20
w32(sp, RETURN_STUB)
cpu.state['SP'].value = sp
end
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
result_dump()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
local base = COFF:match("([^/]+)$") or COFF
if base:find("marker") then
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
hex(r32(0x018E0060)), r32(0x018E0080)))
elseif base:find("xhello") then
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
end
if PTICK ~= 0 or PQUIT ~= 0 then
print(string.format("DIAG: tick=%d quit=%d", PTICK ~= 0 and r32(PTICK) or -1, PQUIT ~= 0 and r32(PQUIT) or -1))
end
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == 2900 then tabx:set_value(700); taby:set_value(500); print("PLAY: tablet move") end
if frames == 3000 then tabb:set_value(1); print("PLAY: click down") end
if frames == 3020 then tabb:set_value(0); print("PLAY: click up") end
if frames == AT and not injected then
inject()
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
end
if injected and TRACE and frames == AT + 1 then
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
end
if VERBOSE and frames % 25 == 0 then
result_dump()
end
if base_contains_marker then
local c = r32(0x018E0080)
if c ~= last_count then
if last_count ~= -1 then
print(string.format("LOADER: marker counter %d -> %d (child running)",
last_count, c))
end
last_count = c
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
end, "vt1200-loader")
-- (Lua has no forward use of a name defined later; set a small flag here.)
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
H.run()
+29 -385
View File
@@ -1,390 +1,34 @@
-- loader.lua -- debugger-assisted COFF loader acceptance harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes:
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
-- * the loader descriptor at 0x01882C00
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
-- or any firmware transport: this is the debugger-assisted milestone.
--
-- The loader itself copies the COFF sections to their linked bit addresses and
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
-- the input and reads the result; it never writes the app's code or markers.
--
-- Env:
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
-- play_keys.lua -- drive the real game through its move, panels and quit
-- paths. play_keys.sh runs one PLAY_MODE per invocation and parses the DIAG
-- loops/events/last/focus/rev/quit line.
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
local H = dofile(dir .. "/harness.lua")
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local MODE = os.getenv("PLAY_MODE") or "move"
print("PLAYKEYS: mode=" .. MODE)
local machine = manager.machine
local PLAY_MODE = os.getenv("PLAY_MODE") or "move"
print("PLAYKEYS: mode="..PLAY_MODE)
local DL = tonumber(os.getenv("DIAG_LOOPS") or "0")
local DE = tonumber(os.getenv("DIAG_EVENTS") or "0")
local DT = tonumber(os.getenv("DIAG_LAST") or "0")
local DF = tonumber(os.getenv("DIAG_FOCUS") or "0")
local DR = tonumber(os.getenv("DIAG_REV") or "0")
local DQ = tonumber(os.getenv("DIAG_QUIT") or "0")
local DTICK = tonumber(os.getenv("DIAG_TICK") or "0")
local ports = machine.ioport.ports
local key_a = ports[":lk401:K26"].fields["A"]
local key_d = ports[":lk401:K28"].fields["D"]
local key_s = ports[":lk401:K27"].fields["S"]
local key_w = ports[":lk401:K14"].fields["W"]
local key_0 = ports[":lk401:K10"].fields["0 )"]
local key_p = ports[":lk401:K22"].fields["P"]
local key_r = ports[":lk401:K16"].fields["R"]
local key_h = ports[":lk401:K31"].fields["H"]
local key_q = ports[":lk401:K13"].fields["Q"]
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
H.key(2900, ":tablet:TABLET_X", "Tablet X", 700)
H.key(2900, ":tablet:TABLET_Y", "Tablet Y", 500, "PLAYKEYS: move")
H.key(3000, ":tablet:TABLET_BTN", "P1 Button 1", 1, "PLAYKEYS: click down")
H.key(3020, ":tablet:TABLET_BTN", "P1 Button 1", 0, "PLAYKEYS: click up")
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
if MODE == "move" then
H.sequence(3100, 20, {
{ ":lk401:K26", "A" },
{ ":lk401:K28", "D" },
{ ":lk401:K27", "S" },
{ ":lk401:K14", "W" },
{ ":lk401:K10", "0 )" },
})
elseif MODE == "panels" then
H.sequence(3100, 20, {
{ ":lk401:K31", "H" },
{ ":lk401:K16", "R" },
})
elseif MODE == "quit" then
H.message(3095, "PLAYKEYS: quit arm")
H.key(3100, ":lk401:K13", "Q", 1, "PLAYKEYS: Q down")
H.key(3110, ":lk401:K13", "Q", 0, "PLAYKEYS: Q up")
end
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
local SNAP = os.getenv("LOADER_SNAP") == "1"
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local RETURN_STUB = 0x01883100
local RETURN_SP = 0x01883110
local function rd(p) return io.open(p, "rb") end
local function slurp(p)
local f, err = rd(p)
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
local TRACE = os.getenv("LOADER_TRACE") == "1"
local frames = 0
local injected = false
local done = false
local last_count = -1
local function status_name(v)
local t = {
[0] = "OK",
[1] = "bad descriptor",
[2] = "truncated COFF / section headers",
[3] = "bad COFF magic",
[4] = "section size not whole words",
[5] = "target outside RAM",
[6] = "target overlaps loader page or COFF buffer",
[7] = "relocation records present (unsupported)",
[8] = "target not in a free-list block",
[9] = "no entry point",
}
return t[v] or ("error " .. tostring(v))
end
local function result_dump()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
poke_bytes(LOADER_BASE, loader)
n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(BUF, coff)
n, bad = verify_bytes(BUF, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(BUF)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
end
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, MODE)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
-- itself); mode 1 returns here, and the stub resumes the interrupted
-- PC so the caller yields and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
if MODE == 1 then
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
else
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
end
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
-- the return slot so mode=1 would return to the spin stub.
-- Leave SP alone for mode 0: the loader pushes onto the current
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
-- would use the return stub.)
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = A8DESC and DESC or 0
if MODE == 1 then
-- Simulate a CALLA from the current process: push the return
-- address on the *firmware* stack (a real transport would do this).
local sp = cpu.state['SP'].value - 0x20
w32(sp, RETURN_STUB)
cpu.state['SP'].value = sp
end
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
result_dump()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
local base = COFF:match("([^/]+)$") or COFF
if base:find("marker") then
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
hex(r32(0x018E0060)), r32(0x018E0080)))
elseif base:find("xhello") then
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
end
if DL ~= 0 then
print(string.format("DIAG: loops=%d events=%d last=%d focus=%08X rev=%d quit=%d", r32(DL), r32(DE), r32(DT), DF ~= 0 and r32(DF) or 0, DR ~= 0 and r32(DR) or 0, DQ ~= 0 and r32(DQ) or 0))
if DTICK ~= 0 then
print(string.format("DIAG: tick=%d", r32(DTICK)))
end
end
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == 2900 then tabx:set_value(700); taby:set_value(500); print("PLAYKEYS: move") end
if frames == 3000 then tabb:set_value(1); print("PLAYKEYS: click down") end
if frames == 3020 then tabb:set_value(0); print("PLAYKEYS: click up") end
if PLAY_MODE == "move" then
if frames == 3100 then key_a:set_value(1) end
if frames == 3110 then key_a:set_value(0) end
if frames == 3120 then key_d:set_value(1) end
if frames == 3130 then key_d:set_value(0) end
if frames == 3140 then key_s:set_value(1) end
if frames == 3150 then key_s:set_value(0) end
if frames == 3160 then key_w:set_value(1) end
if frames == 3170 then key_w:set_value(0) end
if frames == 3180 then key_0:set_value(1) end
if frames == 3190 then key_0:set_value(0) end
elseif PLAY_MODE == "panels" then
if frames == 3100 then key_h:set_value(1) end
if frames == 3110 then key_h:set_value(0) end
if frames == 3120 then key_r:set_value(1) end
if frames == 3130 then key_r:set_value(0) end
elseif PLAY_MODE == "quit" then
if frames == 3095 then print("PLAYKEYS: quit arm") end
if frames == 3100 then print("PLAYKEYS: Q down"); key_q:set_value(1) end
if frames == 3110 then print("PLAYKEYS: Q up"); key_q:set_value(0) end
end
if frames == AT and not injected then
inject()
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
end
if injected and TRACE and frames == AT + 1 then
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
end
if VERBOSE and frames % 25 == 0 then
result_dump()
end
if base_contains_marker then
local c = r32(0x018E0080)
if c ~= last_count then
if last_count ~= -1 then
print(string.format("LOADER: marker counter %d -> %d (child running)",
last_count, c))
end
last_count = c
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
end, "vt1200-loader")
-- (Lua has no forward use of a name defined later; set a small flag here.)
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
H.run()
+12 -342
View File
@@ -1,347 +1,17 @@
-- loader.lua -- debugger-assisted COFF loader acceptance harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes:
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
-- * the loader descriptor at 0x01882C00
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
-- or any firmware transport: this is the debugger-assisted milestone.
--
-- The loader itself copies the COFF sections to their linked bit addresses and
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
-- the input and reads the result; it never writes the app's code or markers.
--
-- Env:
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
-- render.lua -- paint the cell-grid test pattern and snapshot the window. The
-- PNG is the evidence render.sh keeps.
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
local H = dofile(dir .. "/harness.lua")
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local machine = manager.machine
local RENDER_MARK = tonumber(os.getenv("RENDER_MARK") or "0x01A08000")
local X11P = tonumber(os.getenv("X11_PROGRESS") or "0")
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
end
H.result_dump(function()
print(string.format("RENDER: magic=%08X dpy=%08X win=%08X gc=%08X flus=%08X progress=%08X",
H.r32(RENDER_MARK), H.r32(RENDER_MARK + 0x20), H.r32(RENDER_MARK + 0x40),
H.r32(RENDER_MARK + 0x60), H.r32(RENDER_MARK + 0x80),
X11P ~= 0 and H.r32(X11P) or 0))
print(string.format("RENDER: pending=%d", H.r32(RENDER_MARK + 0xA0)))
end)
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
local SNAP = os.getenv("LOADER_SNAP") == "1"
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local RETURN_STUB = 0x01883100
local RETURN_SP = 0x01883110
local function rd(p) return io.open(p, "rb") end
local function slurp(p)
local f, err = rd(p)
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
local TRACE = os.getenv("LOADER_TRACE") == "1"
local frames = 0
local injected = false
local done = false
local last_count = -1
local function status_name(v)
local t = {
[0] = "OK",
[1] = "bad descriptor",
[2] = "truncated COFF / section headers",
[3] = "bad COFF magic",
[4] = "section size not whole words",
[5] = "target outside RAM",
[6] = "target overlaps loader page or COFF buffer",
[7] = "relocation records present (unsupported)",
[8] = "target not in a free-list block",
[9] = "no entry point",
}
return t[v] or ("error " .. tostring(v))
end
local function result_dump()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
poke_bytes(LOADER_BASE, loader)
n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(BUF, coff)
n, bad = verify_bytes(BUF, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(BUF)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
end
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, MODE)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
-- itself); mode 1 returns here, and the stub resumes the interrupted
-- PC so the caller yields and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
if MODE == 1 then
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
else
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
end
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
-- the return slot so mode=1 would return to the spin stub.
-- Leave SP alone for mode 0: the loader pushes onto the current
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
-- would use the return stub.)
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = A8DESC and DESC or 0
if MODE == 1 then
-- Simulate a CALLA from the current process: push the return
-- address on the *firmware* stack (a real transport would do this).
local sp = cpu.state['SP'].value - 0x20
w32(sp, RETURN_STUB)
cpu.state['SP'].value = sp
end
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
result_dump()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
local base = COFF:match("([^/]+)$") or COFF
if base:find("marker") then
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
hex(r32(0x018E0060)), r32(0x018E0080)))
elseif base:find("xhello") then
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
end
if base:find("render") then
print(string.format("RENDER: magic=%08X dpy=%08X win=%08X gc=%08X flus=%08X progress=%08X",
r32(RENDER_MARK), r32(RENDER_MARK + 0x20), r32(RENDER_MARK + 0x40),
r32(RENDER_MARK + 0x60), r32(RENDER_MARK + 0x80),
X11P ~= 0 and r32(X11P) or 0))
print(string.format("RENDER: pending=%d", r32(RENDER_MARK + 0xA0)))
end
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == AT and not injected then
inject()
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
end
if injected and TRACE and frames == AT + 1 then
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
end
if VERBOSE and frames % 25 == 0 then
result_dump()
end
if base_contains_marker then
local c = r32(0x018E0080)
if c ~= last_count then
if last_count ~= -1 then
print(string.format("LOADER: marker counter %d -> %d (child running)",
last_count, c))
end
last_count = c
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
end, "vt1200-loader")
-- (Lua has no forward use of a name defined later; set a small flag here.)
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
H.run()
+14 -350
View File
@@ -1,355 +1,19 @@
-- loader.lua -- debugger-assisted COFF loader acceptance harness.
--
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
-- the OS, then at frame LOADER_AT pokes:
-- * the loader payload at bit 0x01880000 (raw dwt/loader/build/loader.bin)
-- * a GSPLNK COFF image at LOADER_BUF (default bit 0x01900000)
-- * the loader descriptor at 0x01882C00
-- and sets PC = 0x01880000. It does not use the network, the rdebug service
-- or any firmware transport: this is the debugger-assisted milestone.
--
-- The loader itself copies the COFF sections to their linked bit addresses and
-- calls create_process(entry, "LOADER", 0x6000, 1, 0). This script only pokes
-- the input and reads the result; it never writes the app's code or markers.
--
-- Env:
-- LOADER_BIN loader payload (default dwt/loader/build/loader.bin)
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
-- smoke.lua -- Xlib key delivery: click the window, press A, and require a
-- real KeyPress plus XLookupString('a'). smoke.sh greps the SMOKE: line.
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
local H = dofile(dir .. "/harness.lua")
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local machine = manager.machine
local MARK = tonumber(os.getenv("SMOKE_MARK") or "0x01A00000")
local ports = machine.ioport.ports
local key_a = ports[":lk401:K26"].fields["A"]
local tabx = ports[":tablet:TABLET_X"].fields["Tablet X"]
local taby = ports[":tablet:TABLET_Y"].fields["Tablet Y"]
local tabb = ports[":tablet:TABLET_BTN"].fields["P1 Button 1"]
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
if not dbg then
print("LOADER: debugger not enabled; pass -debug")
machine:exit()
return
end
H.config{ tablet = "SMOKE" }
H.key(3100, ":lk401:K26", "A", 1, "SMOKE: A down")
H.key(3120, ":lk401:K26", "A", 0, "SMOKE: A up")
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
local OUT = os.getenv("LOADER_OUT") or "dwt/loader/evidence"
local SNAP = os.getenv("LOADER_SNAP") == "1"
local MODE = tonumber(os.getenv("LOADER_MODE") or "0")
local A8DESC = os.getenv("LOADER_A8_DESC") == "1"
local VERBOSE = os.getenv("LOADER_VERBOSE") == "1"
H.result_dump(function()
print(string.format("SMOKE: magic=%08X dpy=%08X win=%08X n=%d type=%d keycode=%d lookup_n=%d ch=%02X ks=%04X keymark=%08X",
H.r32(MARK + 0x00), H.r32(MARK + 0x20), H.r32(MARK + 0x40), H.r32(MARK + 0x60),
H.r32(MARK + 0x80), H.r32(MARK + 0xA0), H.r32(MARK + 0xC0), H.r32(MARK + 0xE0),
H.r32(MARK + 0x100), H.r32(MARK + 0x120)))
end)
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local RETURN_STUB = 0x01883100
local RETURN_SP = 0x01883110
local function rd(p) return io.open(p, "rb") end
local function slurp(p)
local f, err = rd(p)
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("LOADER: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("LOADER: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr,
app.optmagic and string.format("%04X", app.optmagic) or "none",
hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
end
local TRACE = os.getenv("LOADER_TRACE") == "1"
local frames = 0
local injected = false
local done = false
local last_count = -1
local function status_name(v)
local t = {
[0] = "OK",
[1] = "bad descriptor",
[2] = "truncated COFF / section headers",
[3] = "bad COFF magic",
[4] = "section size not whole words",
[5] = "target outside RAM",
[6] = "target overlaps loader page or COFF buffer",
[7] = "relocation records present (unsupported)",
[8] = "target not in a free-list block",
[9] = "no entry point",
}
return t[v] or ("error " .. tostring(v))
end
local function result_dump()
local st = r32(RESULT + 0x000)
print(string.format(
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
st, status_name(st), hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
poke_bytes(LOADER_BASE, loader)
n, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
n, bad, hex(LOADER_BASE)))
-- 2. COFF image
poke_bytes(BUF, coff)
n, bad = verify_bytes(BUF, coff)
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
n, bad, hex(BUF)))
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
for _, s in ipairs(app.sections) do
if s.flags & 0x80 ~= 0 then
for i = 0, math.floor(s.size / 16) - 1 do
prog:write_u16(s.paddr + i * 16, 0xA5A5)
end
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
hex(s.paddr), hex(s.paddr + s.size)))
end
end
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (spin)
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44)
prog:write_u16(DESC + 0x10, 0x5231)
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, MODE)
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
-- 5. return stub. mode 0 ignores it (the loader jumps to ORIG_PC
-- itself); mode 1 returns here, and the stub resumes the interrupted
-- PC so the caller yields and the scheduler can run the child.
local orig_pc = cpu.state['PC'].value
if MODE == 1 then
prog:write_u16(RETURN_STUB, 0xC080) -- jauc <orig_pc>
prog:write_u16(RETURN_STUB + 0x10, orig_pc & 0xFFFF)
prog:write_u16(RETURN_STUB + 0x20, math.floor(orig_pc / 0x10000) & 0xFFFF)
else
prog:write_u16(RETURN_STUB, 0xC0FF) -- jruc self
end
-- 6. enter the loader. A8=0 selects the fixed descriptor; SP points at
-- the return slot so mode=1 would return to the spin stub.
-- Leave SP alone for mode 0: the loader pushes onto the current
-- process stack, then restores it and resumes at ORIG_PC. (mode 1
-- would use the return stub.)
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = A8DESC and DESC or 0
if MODE == 1 then
-- Simulate a CALLA from the current process: push the return
-- address on the *firmware* stack (a real transport would do this).
local sp = cpu.state['SP'].value - 0x20
w32(sp, RETURN_STUB)
cpu.state['SP'].value = sp
end
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function inspect()
result_dump()
-- Verify the placement from RAM: .text/.data must equal the file bytes.
for _, s in ipairs(app.sections) do
if s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local _, bad = verify_bytes(s.paddr, bytes)
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
s.name, hex(s.paddr), nb, bad))
end
end
local base = COFF:match("([^/]+)$") or COFF
if base:find("marker") then
print(string.format("LOADER: marker app: start=%s data=%s data2=%s bss=%s count=%d",
hex(r32(0x018E0000)), hex(r32(0x018E0020)), hex(r32(0x018E0040)),
hex(r32(0x018E0060)), r32(0x018E0080)))
elseif base:find("xhello") then
print(string.format("LOADER: xhello: stage=%d strlen=%d display=%s root=%s window=%s sync=%s",
r32(0x01890140), r32(0x01890160), hex(r32(0x01890100)),
hex(r32(0x01890110)), hex(r32(0x01890120)), hex(r32(0x01890130))))
end
if base:find("smoke") then
print(string.format("SMOKE: magic=%08X dpy=%08X win=%08X n=%d type=%d keycode=%d lookup_n=%d ch=%02X ks=%04X keymark=%08X",
r32(MARK + 0x00), r32(MARK + 0x20), r32(MARK + 0x40), r32(MARK + 0x60),
r32(MARK + 0x80), r32(MARK + 0xA0), r32(MARK + 0xC0), r32(MARK + 0xE0),
r32(MARK + 0x100), r32(MARK + 0x120)))
end
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == 2900 then tabx:set_value(700); taby:set_value(500); print("SMOKE: tablet move") end
if frames == 3000 then tabb:set_value(1); print("SMOKE: click down") end
if frames == 3020 then tabb:set_value(0); print("SMOKE: click up") end
if frames == 3100 then key_a:set_value(1); print("SMOKE: A down") end
if frames == 3120 then key_a:set_value(0); print("SMOKE: A up") end
if frames == AT and not injected then
inject()
if TRACE then dbg:command("trace /tmp/opencode/ld1.tr") end
end
if injected and TRACE and frames == AT + 1 then
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
end
if VERBOSE and frames % 25 == 0 then
result_dump()
end
if base_contains_marker then
local c = r32(0x018E0080)
if c ~= last_count then
if last_count ~= -1 then
print(string.format("LOADER: marker counter %d -> %d (child running)",
last_count, c))
end
last_count = c
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
end, "vt1200-loader")
-- (Lua has no forward use of a name defined later; set a small flag here.)
base_contains_marker = (COFF:match("([^/]+)$") or ""):find("marker") ~= nil
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
H.run()
+2 -2
View File
@@ -4,8 +4,8 @@
# apps/termtris/verify.sh # build MAME, then run every test
# apps/termtris/verify.sh --skip-mame # use the emulator already installed
#
# Exits non-zero on the first failed check. Each test's full output is kept in
# apps/termtris/build/verify_<name>.log.
# Runs every test even after a failure and exits non-zero if any failed. Each
# test's full output is kept in apps/termtris/build/verify_<name>.log.
set -eu
DIR=$(cd "$(dirname "$0")" && pwd)
+1 -2
View File
@@ -96,8 +96,7 @@ The 1990 **r5.01 OS/2** toolchain under `2ine-tms34010` also builds it (see
`gspopt -O2`: the optimizer hoists the `CTRL_READY` polling load and the
payload waits forever at takeover. `MOVIE.C` is fine at `-O2`. The verified
r5.01 build is `.text` 3,168 bytes, entry `0x018C5C70`, and is MAME-exact at
frames 0 and 180. `gspac`/`gspcg` exit 139 at teardown but still write valid
files.
frames 0 and 180.
## Run in MAME (debugger path)
+1 -2
View File
@@ -110,8 +110,7 @@ MAME frame 0 and frame 180 are **EXACT** with
Caveat: `gspopt -O2` on `MAIN.C` hoists the `CTRL_READY` polling load and
the payload waits forever at takeover. `MOVIE.C` is fine at `-O2`; build
`MAIN.C` without `gspopt`, or add `volatile` to the polling reads. `gspac`
and `gspcg` exit 139 at teardown but still write valid output files.
`MAIN.C` without `gspopt`, or add `volatile` to the polling reads.
`gspa` 5.01 accepted `entry.asm`/`fill.asm` (including `sp`); the `b15`
round-trip difference does not affect this demo.
@@ -96,9 +96,12 @@ changed cells with `XFillRectangle` (background) and `XDrawString` (glyph).
The 6×13 metrics are measured, not assumed. A full redraw is 80×24 cells.
Input: `XSelectInput` with `KeyPressMask|KeyReleaseMask|ButtonPressMask|
ExposureMask|StructureNotifyMask|FocusChangeMask`; the event loop drains
`XNextEvent`; `XLookupString` gives the character/keysym. Arrow keys become
`ESC [ A..D` for `game_input`; `FocusOut` pauses.
StructureNotifyMask|FocusChangeMask`; the event loop drains `XNextEvent`;
`XLookupString` gives the character/keysym. Arrow keys become `ESC [ A..D` for
`game_input`; `FocusOut` pauses. **Deviation (implemented):** `ExposureMask`
was dropped because the map-time `Expose` runs the game's full redraw before a
piece exists and paints a bogus piece; the consequence is that an occluding
window is not repainted. See `apps/termtris/HANDOFF.md`.
Timing: `now_ms()` accumulates `0x1E93C0` deltas; the idle path is
`sleep(min(next_tick - now, 10))`, so the CPU yields to the X server and the OS.
Binary file not shown.
Binary file not shown.
+626
View File
@@ -0,0 +1,626 @@
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 1
0001 ; xshow.asm -- create a 1-bit XImage and XPutImage it o
0002 ;
0003 ; Run as a first-class process created by the COFF load
0004 ; in the rdebug dispatcher's context: a connect made fr
0005 ; accepted at the service layer but the server never re
0006 ;
0007 ; The image is a 32x32 XYBitmap (format 0), depth 1, cr
0008 ; XCreateImage and drawn with XPutImage. Its data is a
0009 ; cells, written into .data at build time, so the PNG s
0010 ; or nothing -- there is nothing to misread.
0011 ;
0012 ; XImage entry points used here (Ghidra address -> bit
0013 ; 7F34092 XCreateImage(d,visual,depth,format,offset,d
0014 ; 7FA06E XPutImage(d,drawable,gc,image,sx,sy,dx,dy,w
0015 ; 7F341B0 XDestroyImage(image)
0016 ; 7FAAAD6 XGetImage(d,drawable,x,y,w,h,plane_mask,for
0017 ; (XGetImage is documented from disassembly; this probe
0018 ;
0019 ; Calling convention: reserve one slot with `move a14,-
0020 ; last-to-first upward through a14, then `calla`. The
0021 ; the return address and the reserved slot, and restore
0022 ; sp/a14 from RAM markers (xtext.asm records that exact
0023 ;
0024 ; Xlib clobbers the CPU's SETF field state, so field 1
0025 ; established after every call. a10/a11/a12 survive ev
0026 ; a9 (the GC) survives XCreateImage and XPutImage; a7 (
0027 ; XPutImage. XDestroyImage saves only a11/a13, so it r
0028 ;
0029 ; Markers:
0030 ; 01890100 display 01890120 window 01890140 stage
0031 ; 01890180 gc 018901A0 XPutImage return 01
0032 ; These are the xhello-compatible cells the runner repo
0033 ; cells sit in the heap and were overwritten after its
0034 ; are mirrored into .bss at 018D8000h (below), which no
0035 ; 018D8000 stage 018D8020 display 018D8040 window
0036 ; 018D8080 image 018D80A0 putret 018D80C0 syncret
0037 ; Stage: 1 start, 2 display, 3 window, 4 mapped, 5 gc,
0038 ; 8 synced; 091h..097h = the step that failed.
0039 ;
0040 ; Scratch argument area: 01894000h (the app's own stack
0041
0042 00000000 .text
0043 00000000 _start:
0044 00000000 0550 setf 16, 0, 0
0045 00000010 0740 setf 32, 0, 1
0046 00000020 098F mmtm sp, a0,a1,a2,a3,a4,a5,a6,a7
00000030 FF00
0047
0048 00000040 09E0 movi 1, a0, L
00000050 00000001
0049 00000070 0780 move a0, @01890140h, 1 ; stage = 1
00000080 01890140
0050 000000A0 0780 move a0, @m_stage, 1
000000B0 00000000+
0051
0052 ; ---- convention check: strlen("0::0") == 4 ---------
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 2
0053 000000D0 A3CF move a14, -*sp, 1
0054 000000E0 09EE movi 01894000h, a14, L
000000F0 01894000
0055 00000110 09E0 movi 3FACE948h, a0, L ; ROM "0::0"
00000120 3FACE948
0056 00000140 920E move a0, *a14+, 1
0057 00000150 0D5F calla 3FB458D0h ; strlen
00000160 3FB458D0
0058 00000180 0550 setf 16, 0, 0
0059 00000190 0740 setf 32, 0, 1
0060 000001A0 0788 move a8, @m_strlen, 1
000001B0 000000E0+
0061 000001D0 09E0 movi 4, a0, L
000001E0 00000004
0062 00000200 4808 cmp a0, a8
0063 00000210 CB00 jrne fail_abi
00000220 0171
0064
0065 ; ---- display = XOpenDisplay("0::0") ----------------
0066 00000230 A3CF move a14, -*sp, 1
0067 00000240 09EE movi 01894000h, a14, L
00000250 01894000
0068 00000270 09E0 movi 3FACE948h, a0, L
00000280 3FACE948
0069 000002A0 920E move a0, *a14+, 1
0070 000002B0 0D5F calla 3F9C2570h ; XOpenDisplay
000002C0 3F9C2570
0071 000002E0 0550 setf 16, 0, 0
0072 000002F0 0740 setf 32, 0, 1
0073 00000300 4D0B move a8, a11
0074 00000310 078B move a11, @01890100h, 1 ; MARK display
00000320 01890100
0075 00000340 078B move a11, @m_display, 1
00000350 00000020+
0076 00000370 4D6B move a11, a11
0077 00000380 CA00 jreq fail_open
00000390 015E
0078 000003A0 09E0 movi 2, a0, L
000003B0 00000002
0079 000003D0 0780 move a0, @01890140h, 1 ; stage = 2
000003E0 01890140
0080 00000400 0780 move a0, @m_stage, 1
00000410 00000000+
0081
0082 ; ---- root = *(*(display+0x480)+0x40) ---------------
0083 00000430 B76A move *a11(0480h), a10, 1
00000440 0480
0084 00000450 B74A move *a10(040h), a10, 1
00000460 0040
0085
0086 ; ---- window = XCreateSimpleWindow(d,root,100,100,400
0087 ; white background (pixel 1), black border, so a black
0088 00000470 A3CF move a14, -*sp, 1
0089 00000480 09EE movi 01894000h, a14, L
00000490 01894000
0090 000004B0 09E0 movi 1, a0, L
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 3
000004C0 00000001
0091 000004E0 920E move a0, *a14+, 1 ; background = 1 (white)
0092 000004F0 09E0 movi 0, a0, L
00000500 00000000
0093 00000520 920E move a0, *a14+, 1 ; border = 0 (black)
0094 00000530 09E0 movi 2, a0, L
00000540 00000002
0095 00000560 920E move a0, *a14+, 1 ; border width
0096 00000570 09E0 movi 200, a0, L
00000580 000000C8
0097 000005A0 920E move a0, *a14+, 1 ; height
0098 000005B0 09E0 movi 400, a0, L
000005C0 00000190
0099 000005E0 920E move a0, *a14+, 1 ; width
0100 000005F0 09E0 movi 100, a0, L
00000600 00000064
0101 00000620 920E move a0, *a14+, 1 ; y
0102 00000630 920E move a0, *a14+, 1 ; x
0103 00000640 934E move a10, *a14+, 1 ; parent = root
0104 00000650 936E move a11, *a14+, 1 ; display
0105 00000660 0D5F calla 3FD41B90h ; XCreateSimpleWindow
00000670 3FD41B90
0106 00000690 0550 setf 16, 0, 0
0107 000006A0 0740 setf 32, 0, 1
0108 000006B0 4D0A move a8, a10
0109 000006C0 078A move a10, @01890120h, 1 ; MARK window
000006D0 01890120
0110 000006F0 078A move a10, @m_window, 1
00000700 00000040+
0111 00000720 4D4A move a10, a10
0112 00000730 CA00 jreq fail_win
00000740 0127
0113 00000750 09E0 movi 3, a0, L
00000760 00000003
0114 00000780 0780 move a0, @01890140h, 1 ; stage = 3
00000790 01890140
0115 000007B0 0780 move a0, @m_stage, 1
000007C0 00000000+
0116
0117 ; ---- XMapWindow(display, window) -------------------
0118 000007E0 A3CF move a14, -*sp, 1
0119 000007F0 09EE movi 01894000h, a14, L
00000800 01894000
0120 00000820 934E move a10, *a14+, 1
0121 00000830 936E move a11, *a14+, 1
0122 00000840 0D5F calla 3FD645B0h ; XMapWindow
00000850 3FD645B0
0123 00000870 0550 setf 16, 0, 0
0124 00000880 0740 setf 32, 0, 1
0125 00000890 09E0 movi 4, a0, L
000008A0 00000004
0126 000008C0 0780 move a0, @01890140h, 1 ; stage = 4
000008D0 01890140
0127 000008F0 0780 move a0, @m_stage, 1
00000900 00000000+
0128
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 4
0129 ; ---- gc = XCreateGC(d, window, 0, NULL) ------------
0130 00000920 A3CF move a14, -*sp, 1
0131 00000930 09EE movi 01894000h, a14, L
00000940 01894000
0132 00000960 09E0 movi 0, a0, L
00000970 00000000
0133 00000990 920E move a0, *a14+, 1 ; values
0134 000009A0 920E move a0, *a14+, 1 ; mask = 0
0135 000009B0 934E move a10, *a14+, 1 ; drawable
0136 000009C0 936E move a11, *a14+, 1 ; display
0137 000009D0 0D5F calla 3F997000h ; XCreateGC
000009E0 3F997000
0138 00000A00 0550 setf 16, 0, 0
0139 00000A10 0740 setf 32, 0, 1
0140 00000A20 4D09 move a8, a9 ; GC
0141 00000A30 0789 move a9, @01890180h, 1 ; MARK gc
00000A40 01890180
0142 00000A60 0789 move a9, @m_gc, 1
00000A70 00000060+
0143 00000A90 4D29 move a9, a9
0144 00000AA0 CA00 jreq fail_gc
00000AB0 00F4
0145
0146 ; ---- XSetForeground(display, gc, 0) -- draw with pen
0147 00000AC0 A3CF move a14, -*sp, 1
0148 00000AD0 09EE movi 01894000h, a14, L
00000AE0 01894000
0149 00000B00 09E0 movi 0, a0, L
00000B10 00000000
0150 00000B30 920E move a0, *a14+, 1 ; pixel = 0
0151 00000B40 932E move a9, *a14+, 1 ; gc
0152 00000B50 936E move a11, *a14+, 1 ; display
0153 00000B60 0D5F calla 3FD99A60h ; XSetForeground
00000B70 3FD99A60
0154 00000B90 0550 setf 16, 0, 0
0155 00000BA0 0740 setf 32, 0, 1
0156 00000BB0 09E0 movi 5, a0, L
00000BC0 00000005
0157 00000BE0 0780 move a0, @01890140h, 1 ; stage = 5
00000BF0 01890140
0158 00000C10 0780 move a0, @m_stage, 1
00000C20 00000000+
0159
0160 ; ---- image = XCreateImage(d, NULL, 1, XYBitmap, 0,
0161 ; bitmap, 32, 32, 32, 0) ---
0162 00000C40 A3CF move a14, -*sp, 1
0163 00000C50 09EE movi 01894000h, a14, L
00000C60 01894000
0164 00000C80 09E0 movi 0, a0, L
00000C90 00000000
0165 00000CB0 920E move a0, *a14+, 1 ; bytes_per_line = 0 (let it comput
0166 00000CC0 09E0 movi 32, a0, L
00000CD0 00000020
0167 00000CF0 920E move a0, *a14+, 1 ; bitmap_pad = 32
0168 00000D00 09E0 movi 32, a0, L
00000D10 00000020
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 5
0169 00000D30 920E move a0, *a14+, 1 ; height
0170 00000D40 920E move a0, *a14+, 1 ; width
0171 00000D50 09E0 movi BITMAP, a0, L
00000D60 00000000"
0172 00000D80 920E move a0, *a14+, 1 ; data
0173 00000D90 09E0 movi 0, a0, L
00000DA0 00000000
0174 00000DC0 920E move a0, *a14+, 1 ; offset
0175 00000DD0 920E move a0, *a14+, 1 ; format = 0 (XYBitmap)
0176 00000DE0 09E0 movi 1, a0, L
00000DF0 00000001
0177 00000E10 920E move a0, *a14+, 1 ; depth = 1
0178 00000E20 4400 sub a0, a0
0179 00000E30 920E move a0, *a14+, 1 ; visual = NULL
0180 00000E40 936E move a11, *a14+, 1 ; display
0181 00000E50 0D5F calla 3F9A0490h ; XCreateImage
00000E60 3F9A0490
0182 00000E80 0550 setf 16, 0, 0
0183 00000E90 0740 setf 32, 0, 1
0184 00000EA0 4D07 move a8, a7 ; image (a7 survives XPutImage)
0185 00000EB0 0788 move a8, @01890160h, 1 ; MARK image
00000EC0 01890160
0186 00000EE0 0788 move a8, @m_image, 1
00000EF0 00000080+
0187 00000F10 4D08 move a8, a8
0188 00000F20 CA00 jreq fail_img
00000F30 00B0
0189 00000F40 09E0 movi 6, a0, L
00000F50 00000006
0190 00000F70 0780 move a0, @01890140h, 1 ; stage = 6
00000F80 01890140
0191 00000FA0 0780 move a0, @m_stage, 1
00000FB0 00000000+
0192
0193 ; ---- let the WM frame/reparent and map the window (x
0194 ; A draw issued before the reparent can be lost, so sy
0195 00000FD0 09EC movi 4, a12, L
00000FE0 00000004
0196 00001000 map_wait:
0197 00001000 A3CF move a14, -*sp, 1
0198 00001010 09EE movi 01894000h, a14, L
00001020 01894000
0199 00001040 09E0 movi 0, a0, L
00001050 00000000
0200 00001070 920E move a0, *a14+, 1 ; discard = 0
0201 00001080 936E move a11, *a14+, 1 ; display
0202 00001090 0D5F calla 3FD9F6B0h ; XSync
000010A0 3FD9F6B0
0203 000010C0 0550 setf 16, 0, 0
0204 000010D0 0740 setf 32, 0, 1
0205 000010E0 3DEC dsjs a12, map_wait
0206
0207 ; ---- XPutImage(d, win, gc, image, 0,0, 20,20, 32,32)
0208 000010F0 A3CF move a14, -*sp, 1
0209 00001100 09EE movi 01894000h, a14, L
00001110 01894000
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 6
0210 00001130 09E0 movi 32, a0, L
00001140 00000020
0211 00001160 920E move a0, *a14+, 1 ; h
0212 00001170 920E move a0, *a14+, 1 ; w
0213 00001180 09E0 movi 20, a0, L
00001190 00000014
0214 000011B0 920E move a0, *a14+, 1 ; dst_y
0215 000011C0 920E move a0, *a14+, 1 ; dst_x
0216 000011D0 4400 sub a0, a0
0217 000011E0 920E move a0, *a14+, 1 ; src_y
0218 000011F0 920E move a0, *a14+, 1 ; src_x
0219 00001200 92EE move a7, *a14+, 1 ; image
0220 00001210 932E move a9, *a14+, 1 ; gc
0221 00001220 934E move a10, *a14+, 1 ; drawable
0222 00001230 936E move a11, *a14+, 1 ; display
0223 00001240 0D5F calla 3F9D0370h ; XPutImage
00001250 3F9D0370
0224 00001270 0550 setf 16, 0, 0
0225 00001280 0740 setf 32, 0, 1
0226 00001290 0788 move a8, @018901A0h, 1 ; MARK putimage return
000012A0 018901A0
0227 000012C0 0788 move a8, @m_putret, 1
000012D0 000000A0+
0228 000012F0 09E0 movi 7, a0, L
00001300 00000007
0229 00001320 0780 move a0, @01890140h, 1 ; stage = 7
00001330 01890140
0230 00001350 0780 move a0, @m_stage, 1
00001360 00000000+
0231
0232 ; ---- control: the same image with h = 16 at dst_y =
0233 ; The PNG must show exactly 16 rows here (src rows 0..
0234 ; what proves the 32-row draw above is the image, not
0235 00001380 A3CF move a14, -*sp, 1
0236 00001390 09EE movi 01894000h, a14, L
000013A0 01894000
0237 000013C0 09E0 movi 16, a0, L
000013D0 00000010
0238 000013F0 920E move a0, *a14+, 1 ; h = 16
0239 00001400 09E0 movi 32, a0, L
00001410 00000020
0240 00001430 920E move a0, *a14+, 1 ; w = 32
0241 00001440 09E0 movi 60, a0, L
00001450 0000003C
0242 00001470 920E move a0, *a14+, 1 ; dst_y = 60
0243 00001480 09E0 movi 20, a0, L
00001490 00000014
0244 000014B0 920E move a0, *a14+, 1 ; dst_x = 20
0245 000014C0 4400 sub a0, a0
0246 000014D0 920E move a0, *a14+, 1 ; src_y = 0
0247 000014E0 920E move a0, *a14+, 1 ; src_x = 0
0248 000014F0 92EE move a7, *a14+, 1 ; image
0249 00001500 932E move a9, *a14+, 1 ; gc
0250 00001510 934E move a10, *a14+, 1 ; drawable
0251 00001520 936E move a11, *a14+, 1 ; display
0252 00001530 0D5F calla 3F9D0370h ; XPutImage
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 7
00001540 3F9D0370
0253 00001560 0550 setf 16, 0, 0
0254 00001570 0740 setf 32, 0, 1
0255
0256 ; ---- flush, twice: the request is only in the client
0257 00001580 A3CF move a14, -*sp, 1
0258 00001590 09EE movi 01894000h, a14, L
000015A0 01894000
0259 000015C0 09E0 movi 0, a0, L
000015D0 00000000
0260 000015F0 920E move a0, *a14+, 1
0261 00001600 936E move a11, *a14+, 1
0262 00001610 0D5F calla 3FD9F6B0h ; XSync
00001620 3FD9F6B0
0263 00001640 0550 setf 16, 0, 0
0264 00001650 0740 setf 32, 0, 1
0265 00001660 0788 move a8, @018901C0h, 1 ; MARK sync return
00001670 018901C0
0266 00001690 0788 move a8, @m_syncret, 1
000016A0 000000C0+
0267
0268 000016C0 A3CF move a14, -*sp, 1
0269 000016D0 09EE movi 01894000h, a14, L
000016E0 01894000
0270 00001700 09E0 movi 0, a0, L
00001710 00000000
0271 00001730 920E move a0, *a14+, 1
0272 00001740 936E move a11, *a14+, 1
0273 00001750 0D5F calla 3FD9F6B0h ; XSync
00001760 3FD9F6B0
0274 00001780 0550 setf 16, 0, 0
0275 00001790 0740 setf 32, 0, 1
0276 000017A0 0788 move a8, @018901C0h, 1
000017B0 018901C0
0277 000017D0 0788 move a8, @m_syncret, 1
000017E0 000000C0+
0278
0279 00001800 09E0 movi 8, a0, L
00001810 00000008
0280 00001830 0780 move a0, @01890140h, 1 ; stage = 8
00001840 01890140
0281 00001860 0780 move a0, @m_stage, 1
00001870 00000000+
0282
0283 ; ---- XDestroyImage(image) --------------------------
0284 00001890 A3CF move a14, -*sp, 1
0285 000018A0 09EE movi 01894000h, a14, L
000018B0 01894000
0286 000018D0 92EE move a7, *a14+, 1
0287 000018E0 0D5F calla 3F9A0D80h ; XDestroyImage
000018F0 3F9A0D80
0288 00001910 0550 setf 16, 0, 0
0289 00001920 0740 setf 32, 0, 1
0290 00001930 C01A jruc done
0291
0292 00001940 fail_abi:
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 8
0293 00001940 09E0 movi 091h, a0, L
00001950 00000091
0294 00001970 C010 jruc failed
0295 00001980 fail_open:
0296 00001980 09E0 movi 092h, a0, L
00001990 00000092
0297 000019B0 C00C jruc failed
0298 000019C0 fail_win:
0299 000019C0 09E0 movi 093h, a0, L
000019D0 00000093
0300 000019F0 C008 jruc failed
0301 00001A00 fail_gc:
0302 00001A00 09E0 movi 095h, a0, L
00001A10 00000095
0303 00001A30 C004 jruc failed
0304 00001A40 fail_img:
0305 00001A40 09E0 movi 096h, a0, L
00001A50 00000096
0306 00001A70 0300 jruc failed
0307 00001A80 failed:
0308 00001A80 0780 move a0, @01890140h, 1
00001A90 01890140
0309 00001AB0 0780 move a0, @m_stage, 1
00001AC0 00000000+
0310
0311 00001AE0 done:
0312 00001AE0 09AF mmfm sp, a0,a1,a2,a3,a4,a5,a6,a7
00001AF0 00FF
0313 00001B00 09E8 movi 0, a8, L
00001B10 00000000
0314 00001B30 0960 rets
0315
0316 00000000 .data
0317 ; 32 rows of 4 bytes, LSB-first pixels: a solid row at
0318 ; at y=31, and a one-pixel diagonal between them. The
0319 ; rows make the drawn height readable straight off the
0320 00000000 BITMAP:
0321 00000000 FF .byte 0FFh, 0FFh, 0FFh, 0FFh, 002h, 000h, 000h, 000h
00000008 FF
00000010 FF
00000018 FF
00000020 02
00000028 00
00000030 00
00000038 00
0322 00000040 04 .byte 004h, 000h, 000h, 000h, 008h, 000h, 000h, 000h
00000048 00
00000050 00
00000058 00
00000060 08
00000068 00
00000070 00
00000078 00
0323 00000080 10 .byte 010h, 000h, 000h, 000h, 020h, 000h, 000h, 000h
00000088 00
00000090 00
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 9
00000098 00
000000A0 20
000000A8 00
000000B0 00
000000B8 00
0324 000000C0 40 .byte 040h, 000h, 000h, 000h, 080h, 000h, 000h, 000h
000000C8 00
000000D0 00
000000D8 00
000000E0 80
000000E8 00
000000F0 00
000000F8 00
0325 00000100 00 .byte 000h, 001h, 000h, 000h, 000h, 002h, 000h, 000h
00000108 01
00000110 00
00000118 00
00000120 00
00000128 02
00000130 00
00000138 00
0326 00000140 00 .byte 000h, 004h, 000h, 000h, 000h, 008h, 000h, 000h
00000148 04
00000150 00
00000158 00
00000160 00
00000168 08
00000170 00
00000178 00
0327 00000180 00 .byte 000h, 010h, 000h, 000h, 000h, 020h, 000h, 000h
00000188 10
00000190 00
00000198 00
000001A0 00
000001A8 20
000001B0 00
000001B8 00
0328 000001C0 00 .byte 000h, 040h, 000h, 000h, 000h, 080h, 000h, 000h
000001C8 40
000001D0 00
000001D8 00
000001E0 00
000001E8 80
000001F0 00
000001F8 00
0329 00000200 00 .byte 000h, 000h, 001h, 000h, 000h, 000h, 002h, 000h
00000208 00
00000210 01
00000218 00
00000220 00
00000228 00
00000230 02
00000238 00
0330 00000240 00 .byte 000h, 000h, 004h, 000h, 000h, 000h, 008h, 000h
00000248 00
00000250 04
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 10
00000258 00
00000260 00
00000268 00
00000270 08
00000278 00
0331 00000280 00 .byte 000h, 000h, 010h, 000h, 000h, 000h, 020h, 000h
00000288 00
00000290 10
00000298 00
000002A0 00
000002A8 00
000002B0 20
000002B8 00
0332 000002C0 00 .byte 000h, 000h, 040h, 000h, 000h, 000h, 080h, 000h
000002C8 00
000002D0 40
000002D8 00
000002E0 00
000002E8 00
000002F0 80
000002F8 00
0333 00000300 00 .byte 000h, 000h, 000h, 001h, 000h, 000h, 000h, 002h
00000308 00
00000310 00
00000318 01
00000320 00
00000328 00
00000330 00
00000338 02
0334 00000340 00 .byte 000h, 000h, 000h, 004h, 000h, 000h, 000h, 008h
00000348 00
00000350 00
00000358 04
00000360 00
00000368 00
00000370 00
00000378 08
0335 00000380 00 .byte 000h, 000h, 000h, 010h, 000h, 000h, 000h, 020h
00000388 00
00000390 00
00000398 10
000003A0 00
000003A8 00
000003B0 00
000003B8 20
0336 000003C0 00 .byte 000h, 000h, 000h, 040h, 0FFh, 0FFh, 0FFh, 0FFh
000003C8 00
000003D0 00
000003D8 40
000003E0 FF
000003E8 FF
000003F0 FF
000003F8 FF
0337 00000400 BITMAP_END:
0338
0339 00000000 .bss m_stage, 32, 1
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 11
0340 00000020 .bss m_display, 32, 1
0341 00000040 .bss m_window, 32, 1
0342 00000060 .bss m_gc, 32, 1
0343 00000080 .bss m_image, 32, 1
0344 000000A0 .bss m_putret, 32, 1
0345 000000C0 .bss m_syncret, 32, 1
0346 000000E0 .bss m_strlen, 32, 1
0347
0348 .end
No Errors, No Warnings
+36
View File
@@ -0,0 +1,36 @@
*****************************************************
GSP COFF Linker, Version 2.00, 87.300
*****************************************************
Fri Nov 13 09:31:54 2026
OUTPUT FILE NAME: <XSHOW.out>
ENTRY POINT SYMBOL: 0
SECTION ALLOCATION MAP
output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.text 0 01840000 00001B40
01840000 00001B40 XSHOW.obj (.text)
.data 0 018D0000 00000400
018D0000 00000400 XSHOW.obj (.data)
.bss 0 018D8000 00000100 UNINITIALIZED
018D8000 00000100 XSHOW.obj (.bss)
GLOBAL SYMBOLS
address name address name
-------- ---- -------- ----
018D8000 .bss 01840000 .text
018D0000 .data 01841B40 etext
01840000 .text 018D0000 .data
018D0400 edata 018D0400 edata
018D8100 end 018D8000 .bss
01841B40 etext 018D8100 end
[6 symbols]
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
"""Print a region of an 8-bit PNG as ASCII, one screen row per line.
The evidence PNGs are captured by MAME under -video none, so there is no
ImageMagick/PIL dependency here: this decodes the PNG with zlib directly
(non-interlaced, 8-bit grey/RGB/RGBA only) and prints '#' for dark pixels.
Usage:
python3 dwt/gui/evidence/png_rows.py PNG X Y W H
"""
import struct
import sys
import zlib
def read_png(path):
data = open(path, "rb").read()
if data[:8] != b"\x89PNG\r\n\x1a\n":
raise SystemExit("not a PNG: " + path)
off, idat = 8, b""
w = h = bitdepth = colour = None
while off < len(data):
length = struct.unpack(">I", data[off:off + 4])[0]
kind = data[off + 4:off + 8]
chunk = data[off + 8:off + 8 + length]
off += 12 + length
if kind == b"IHDR":
w, h, bitdepth, colour, _, _, interlace = struct.unpack(">IIBBBBB", chunk)
if bitdepth != 8 or interlace != 0:
raise SystemExit("only 8-bit non-interlaced PNGs")
elif kind == b"IDAT":
idat += chunk
elif kind == b"IEND":
break
bpp = {0: 1, 2: 3, 4: 2, 6: 4}[colour]
stride = w * bpp
raw = zlib.decompress(idat)
out = bytearray(h * stride)
prev = bytearray(stride)
pos = 0
for y in range(h):
filt = raw[pos]
pos += 1
line = bytearray(raw[pos:pos + stride])
pos += stride
if filt == 1:
for i in range(bpp, stride):
line[i] = (line[i] + line[i - bpp]) & 0xFF
elif filt == 2:
for i in range(stride):
line[i] = (line[i] + prev[i]) & 0xFF
elif filt == 3:
for i in range(stride):
left = line[i - bpp] if i >= bpp else 0
line[i] = (line[i] + ((left + prev[i]) >> 1)) & 0xFF
elif filt == 4:
for i in range(stride):
left = line[i - bpp] if i >= bpp else 0
up = prev[i]
upleft = prev[i - bpp] if i >= bpp else 0
p = left + up - upleft
pa, pb, pc = abs(p - left), abs(p - up), abs(p - upleft)
pred = left if (pa <= pb and pa <= pc) else (up if pb <= pc else upleft)
line[i] = (line[i] + pred) & 0xFF
out[y * stride:(y + 1) * stride] = line
prev = line
return w, h, bpp, bytes(out)
def main():
path, x0, y0, cw, ch = sys.argv[1], *map(int, sys.argv[2:6])
w, _, bpp, px = read_png(path)
for y in range(y0, y0 + ch):
row = "".join("#" if px[(y * w + x) * bpp] < 128 else "." for x in range(x0, x0 + cw))
print("%4d %s" % (y, row))
if __name__ == "__main__":
main()
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+75
View File
@@ -0,0 +1,75 @@
# xshow_frame2650.png, decoded with: python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2650.png 118 118 40 64
# window content origin is screen (102,102): XPutImage dst (20,20) -> row 122,
# dst (20,60) -> row 162. Full 32-row image: 122..153. h=16 control: 162..177.
118 ........................................
119 ........................................
120 ........................................
121 ........................................
122 ....################################....
123 .....#..................................
124 ......#.................................
125 .......#................................
126 ........#...............................
127 .........#..............................
128 ..........#.............................
129 ...........#............................
130 ............#...........................
131 .............#..........................
132 ..............#.........................
133 ...............#........................
134 ................#.......................
135 .................#......................
136 ..................#.....................
137 ...................#....................
138 ....................#...................
139 .....................#..................
140 ......................#.................
141 .......................#................
142 ........................#...............
143 .........................#..............
144 ..........................#.............
145 ...........................#............
146 ............................#...........
147 .............................#..........
148 ..............................#.........
149 ...............................#........
150 ................................#.......
151 .................................#......
152 ..................................#.....
153 ....################################....
154 ........................................
155 ........................................
156 ........................................
157 ........................................
158 ........................................
159 ........................................
160 ........................................
161 ........................................
162 ....################################....
163 .....#..................................
164 ......#.................................
165 .......#................................
166 ........#...............................
167 .........#..............................
168 ..........#.............................
169 ...........#............................
170 ............#...........................
171 .............#..........................
172 ..............#.........................
173 ...............#........................
174 ................#.......................
175 .................#......................
176 ..................#.....................
177 ...................#....................
178 ........................................
179 ........................................
180 ........................................
181 ........................................
# second observation, 30 frames later: the same rows, byte-identical PNG
$ python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2680.png 118 118 40 64 | diff - <(python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2650.png 118 118 40 64)
(no output: identical)
$ md5sum dwt/gui/evidence/xshow_frame2650.png dwt/gui/evidence/xshow_frame2680.png
ab9d63844aa5a3dd9d281a6bee3c76c2 dwt/gui/evidence/xshow_frame2650.png
ab9d63844aa5a3dd9d281a6bee3c76c2 dwt/gui/evidence/xshow_frame2680.png
+37
View File
@@ -0,0 +1,37 @@
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: No such file or directory
vt1200: screen_update#1 frame=0 clip_y=0..0 screen=1280x901
XSHOW: payload dwt/loader/build/loader.bin (1220 B) -> bit 01880000
XSHOW: COFF dwt/gui/build/xshow.coff (1384 B) -> bit 01900000
XSHOW: file magic=0090 nscns=3 opthdr=28 entry=00000000 textstart=01840000
XSHOW: sec .text paddr=01840000 size=6976 bits (872 B) flags=0x20
XSHOW: sec .data paddr=018D0000 size=1024 bits (128 B) flags=0x40
XSHOW: sec .bss paddr=018D8000 size=256 bits (32 B) flags=0x80
XSHOW: .data first 16 bytes: FF FF FF FF 02 00 00 00 04 00 00 00 08 00 00 00
vt1200: screen_update#2 frame=0 clip_y=1..900 screen=1280x901
vt1200: scanline#1 line=1 enabled=1
vt1200: guard#1 frame=0 dump_frame=-1 dump_ram=-1
vt1200: screen_update#3 frame=1 clip_y=0..0 screen=1280x901
vt1200: scanline#2 line=0 enabled=1
vt1200: screen_update#4 frame=1 clip_y=1..1 screen=1280x901
vt1200: scanline#3 line=1 enabled=1
vt1200: scanline#4 line=2 enabled=1
XSHOW: loader poked 610 words, readback 0 bad at 01880000
XSHOW: COFF poked 692 words, readback 0 bad at 01900000
XSHOW: descriptor @01882C00 magic=4C44/5231 buf=01900000 len=1384 mode=0
XSHOW: will resume at 3F579970 after create_process
XSHOW: frame 2500: entered loader at 01880000 (caller SP=007F52B0)
XSHOW: f2540 cells stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001
XSHOW: f2540 mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
XSHOW: f2650 cells stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001
XSHOW: f2650 mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
XSHOW: snapshot /home/arti/.t3/worktrees/vt1200/fix-issue-4-ximage-4368fd1dbccf74ec/dwt/gui/evidence/xshow_frame2650.png ok=true
XSHOW: final cells stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001
XSHOW: final mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
XSHOW: loader status=0 entry=01840000 text=01840000/6976 bits
XSHOW: PC at exit = 3F5799D0
XSHOW: final image@00988130 width=00000020 height=00000020 xoffset=00000000 format=00000000 data=018D0000 byte_order=00000000 bitmap_unit=00000020 bitmap_bit_order=00000000 bitmap_pad=00000020 depth=00000001 bytes_per_line=00000004 bits_per_pixel=00000001
XSHOW: final dpy@0093C910 byte_order=00000000 bitmap_unit=00000020 scanline_pad=00000020 bitmap_bit_order=00000000
XSHOW: final pixmap_formats n=1 list=00367D90
XSHOW: final fmt[0] depth=00000001 bits_per_pixel=00000001 pad=00000020
Average speed: 111.50% (37 seconds)
+3 -2
View File
@@ -14,7 +14,8 @@
-- 3F3F4680 authorisation check
-- 3F706A40 create_process
-- 3FD41B90 XCreateSimpleWindow
-- 3FD645B0 XMapWindow
-- 3FD645B0 XRaiseWindow (ConfigureWindow/CWStackMode; does not map)
-- 3FD64F60 XMapWindow
-- 3FD9F6B0 XSync
--
-- Also snapshots frames on a trigger file: "<prefix> <count> <stride>".
@@ -138,7 +139,7 @@ local function arm()
cmd('bpset 3F706A40,,{ printf "TR CREATE_PROC entry entryarg=%08X nameptr=%08X proc=%08X\\n", d@(a14-32), d@(a14-64), d@0x1b3900 ; g }')
-- window calls
cmd('bpset 3FD41B90,,{ printf "TR CreateSimpleWindow\\n" ; g }')
cmd('bpset 3FD645B0,,{ printf "TR MapWindow\\n" ; g }')
cmd('bpset 3FD645B0,,{ printf "TR RaiseWindow\\n" ; g }')
cmd('bpset 3FD9F6B0,,{ printf "TR XSync\\n" ; g }')
-- xhello progress is tracked through its relocated markers (0189xxxx);
-- the code offsets moved when the setf fix was inserted, so no bpsets here.
+5 -3
View File
@@ -23,7 +23,7 @@
; Xlib entry points (Ghidra address -> bit address):
; 7F384AE XOpenDisplay(name) -> 3F9C2570
; 7FA8372 XCreateSimpleWindow(...) -> 3FD41B90
; 7FAC8B6 XMapWindow(display,window) -> 3FD645B0
; 7FAC8B6 XRaiseWindow(display,window) -> 3FD645B0 (does NOT map)
; 7FB3ED6 XSync(display,discard) -> 3FD9F6B0
; 7F68B1A strlen(s) -> 3FB458D0 (convention check)
;
@@ -116,12 +116,14 @@ _start:
movi 4, a0, L
move a0, @01890140h, 1
; ---- XMapWindow(display, window) ------------------------------
; ---- XRaiseWindow(display, window) ----------------------------
; ConfigureWindow with CWStackMode=Above: raises an already-mapped
; window. It does NOT map it -- XMapWindow is 3FD64F60.
move a14, -*sp, 1
movi 01892000h, a14, L
move a10, *a14+, 1 ; window
move a11, *a14+, 1 ; display
calla 3FD645B0h ; XMapWindow
calla 3FD645B0h ; XRaiseWindow
move @01890420h, sp, 1
move @01890400h, a14, 1
setf 16, 0, 0
+348
View File
@@ -0,0 +1,348 @@
; xshow.asm -- create a 1-bit XImage and XPutImage it onto a mapped window.
;
; Run as a first-class process created by the COFF loader (create_process), NOT
; in the rdebug dispatcher's context: a connect made from the rdebug process is
; accepted at the service layer but the server never reads the X11 setup.
;
; The image is a 32x32 XYBitmap (format 0), depth 1, created by the ROM's own
; XCreateImage and drawn with XPutImage. Its data is a checkerboard of 8x8
; cells, written into .data at build time, so the PNG shows either the pattern
; or nothing -- there is nothing to misread.
;
; XImage entry points used here (Ghidra address -> bit address):
; 7F34092 XCreateImage(d,visual,depth,format,offset,data,w,h,pad,bpl) 3F9A0490
; 7FA06E XPutImage(d,drawable,gc,image,sx,sy,dx,dy,w,h) 3F9D0370
; 7F341B0 XDestroyImage(image) 3F9A0D80
; 7FAAAD6 XGetImage(d,drawable,x,y,w,h,plane_mask,format) 3FD556B0
; (XGetImage is documented from disassembly; this probe does not call it.)
;
; Calling convention: reserve one slot with `move a14,-*sp,1`, push arguments
; last-to-first upward through a14, then `calla`. The callee's `rets 2` pops
; the return address and the reserved slot, and restores a14. Do NOT reload
; sp/a14 from RAM markers (xtext.asm records that exact crash).
;
; Xlib clobbers the CPU's SETF field state, so field 1 (32-bit) is re-
; established after every call. a10/a11/a12 survive every call used here;
; a9 (the GC) survives XCreateImage and XPutImage; a7 (the image) survives
; XPutImage. XDestroyImage saves only a11/a13, so it runs last.
;
; Markers:
; 01890100 display 01890120 window 01890140 stage 01890160 image
; 01890180 gc 018901A0 XPutImage return 018901C0 last XSync
; These are the xhello-compatible cells the runner reports. xhello's own
; cells sit in the heap and were overwritten after its run, so the same values
; are mirrored into .bss at 018D8000h (below), which nothing else uses:
; 018D8000 stage 018D8020 display 018D8040 window 018D8060 gc
; 018D8080 image 018D80A0 putret 018D80C0 syncret 018D80E0 strlen
; Stage: 1 start, 2 display, 3 window, 4 mapped, 5 gc, 6 image, 7 putimage,
; 8 synced; 091h..097h = the step that failed.
;
; Scratch argument area: 01894000h (the app's own stack is elsewhere).
.text
_start:
setf 16, 0, 0
setf 32, 0, 1
mmtm sp, a0,a1,a2,a3,a4,a5,a6,a7
movi 1, a0, L
move a0, @01890140h, 1 ; stage = 1
move a0, @m_stage, 1
; ---- convention check: strlen("0::0") == 4 --------------------
move a14, -*sp, 1
movi 01894000h, a14, L
movi 3FACE948h, a0, L ; ROM "0::0"
move a0, *a14+, 1
calla 3FB458D0h ; strlen
setf 16, 0, 0
setf 32, 0, 1
move a8, @m_strlen, 1
movi 4, a0, L
cmp a0, a8
jrne fail_abi
; ---- display = XOpenDisplay("0::0") ---------------------------
move a14, -*sp, 1
movi 01894000h, a14, L
movi 3FACE948h, a0, L
move a0, *a14+, 1
calla 3F9C2570h ; XOpenDisplay
setf 16, 0, 0
setf 32, 0, 1
move a8, a11
move a11, @01890100h, 1 ; MARK display
move a11, @m_display, 1
move a11, a11
jreq fail_open
movi 2, a0, L
move a0, @01890140h, 1 ; stage = 2
move a0, @m_stage, 1
; ---- root = *(*(display+0x480)+0x40) --------------------------
move *a11(0480h), a10, 1
move *a10(040h), a10, 1
; ---- window = XCreateSimpleWindow(d,root,100,100,400,200,2,0,1)
; white background (pixel 1), black border, so a black bitmap shows.
move a14, -*sp, 1
movi 01894000h, a14, L
movi 1, a0, L
move a0, *a14+, 1 ; background = 1 (white)
movi 0, a0, L
move a0, *a14+, 1 ; border = 0 (black)
movi 2, a0, L
move a0, *a14+, 1 ; border width
movi 200, a0, L
move a0, *a14+, 1 ; height
movi 400, a0, L
move a0, *a14+, 1 ; width
movi 100, a0, L
move a0, *a14+, 1 ; y
move a0, *a14+, 1 ; x
move a10, *a14+, 1 ; parent = root
move a11, *a14+, 1 ; display
calla 3FD41B90h ; XCreateSimpleWindow
setf 16, 0, 0
setf 32, 0, 1
move a8, a10
move a10, @01890120h, 1 ; MARK window
move a10, @m_window, 1
move a10, a10
jreq fail_win
movi 3, a0, L
move a0, @01890140h, 1 ; stage = 3
move a0, @m_stage, 1
; ---- XMapWindow(display, window) -----------------------------
move a14, -*sp, 1
movi 01894000h, a14, L
move a10, *a14+, 1
move a11, *a14+, 1
calla 3FD645B0h ; XMapWindow
setf 16, 0, 0
setf 32, 0, 1
movi 4, a0, L
move a0, @01890140h, 1 ; stage = 4
move a0, @m_stage, 1
; ---- gc = XCreateGC(d, window, 0, NULL) ----------------------
move a14, -*sp, 1
movi 01894000h, a14, L
movi 0, a0, L
move a0, *a14+, 1 ; values
move a0, *a14+, 1 ; mask = 0
move a10, *a14+, 1 ; drawable
move a11, *a14+, 1 ; display
calla 3F997000h ; XCreateGC
setf 16, 0, 0
setf 32, 0, 1
move a8, a9 ; GC
move a9, @01890180h, 1 ; MARK gc
move a9, @m_gc, 1
move a9, a9
jreq fail_gc
; ---- XSetForeground(display, gc, 0) -- draw with pen 0 (black) --
move a14, -*sp, 1
movi 01894000h, a14, L
movi 0, a0, L
move a0, *a14+, 1 ; pixel = 0
move a9, *a14+, 1 ; gc
move a11, *a14+, 1 ; display
calla 3FD99A60h ; XSetForeground
setf 16, 0, 0
setf 32, 0, 1
movi 5, a0, L
move a0, @01890140h, 1 ; stage = 5
move a0, @m_stage, 1
; ---- image = XCreateImage(d, NULL, 1, XYBitmap, 0,
; bitmap, 32, 32, 32, 0) -------------
move a14, -*sp, 1
movi 01894000h, a14, L
movi 0, a0, L
move a0, *a14+, 1 ; bytes_per_line = 0 (let it compute)
movi 32, a0, L
move a0, *a14+, 1 ; bitmap_pad = 32
movi 32, a0, L
move a0, *a14+, 1 ; height
move a0, *a14+, 1 ; width
movi BITMAP, a0, L
move a0, *a14+, 1 ; data
movi 0, a0, L
move a0, *a14+, 1 ; offset
move a0, *a14+, 1 ; format = 0 (XYBitmap)
movi 1, a0, L
move a0, *a14+, 1 ; depth = 1
sub a0, a0
move a0, *a14+, 1 ; visual = NULL
move a11, *a14+, 1 ; display
calla 3F9A0490h ; XCreateImage
setf 16, 0, 0
setf 32, 0, 1
move a8, a7 ; image (a7 survives XPutImage)
move a8, @01890160h, 1 ; MARK image
move a8, @m_image, 1
move a8, a8
jreq fail_img
movi 6, a0, L
move a0, @01890140h, 1 ; stage = 6
move a0, @m_stage, 1
; ---- let the WM frame/reparent and map the window (xtext) -----
; A draw issued before the reparent can be lost, so sync first.
movi 4, a12, L
map_wait:
move a14, -*sp, 1
movi 01894000h, a14, L
movi 0, a0, L
move a0, *a14+, 1 ; discard = 0
move a11, *a14+, 1 ; display
calla 3FD9F6B0h ; XSync
setf 16, 0, 0
setf 32, 0, 1
dsjs a12, map_wait
; ---- XPutImage(d, win, gc, image, 0,0, 20,20, 32,32) ---------
move a14, -*sp, 1
movi 01894000h, a14, L
movi 32, a0, L
move a0, *a14+, 1 ; h
move a0, *a14+, 1 ; w
movi 20, a0, L
move a0, *a14+, 1 ; dst_y
move a0, *a14+, 1 ; dst_x
sub a0, a0
move a0, *a14+, 1 ; src_y
move a0, *a14+, 1 ; src_x
move a7, *a14+, 1 ; image
move a9, *a14+, 1 ; gc
move a10, *a14+, 1 ; drawable
move a11, *a14+, 1 ; display
calla 3F9D0370h ; XPutImage
setf 16, 0, 0
setf 32, 0, 1
move a8, @018901A0h, 1 ; MARK putimage return
move a8, @m_putret, 1
movi 7, a0, L
move a0, @01890140h, 1 ; stage = 7
move a0, @m_stage, 1
; ---- control: the same image with h = 16 at dst_y = 60 --------
; The PNG must show exactly 16 rows here (src rows 0..15): that is
; what proves the 32-row draw above is the image, not the window.
move a14, -*sp, 1
movi 01894000h, a14, L
movi 16, a0, L
move a0, *a14+, 1 ; h = 16
movi 32, a0, L
move a0, *a14+, 1 ; w = 32
movi 60, a0, L
move a0, *a14+, 1 ; dst_y = 60
movi 20, a0, L
move a0, *a14+, 1 ; dst_x = 20
sub a0, a0
move a0, *a14+, 1 ; src_y = 0
move a0, *a14+, 1 ; src_x = 0
move a7, *a14+, 1 ; image
move a9, *a14+, 1 ; gc
move a10, *a14+, 1 ; drawable
move a11, *a14+, 1 ; display
calla 3F9D0370h ; XPutImage
setf 16, 0, 0
setf 32, 0, 1
; ---- flush, twice: the request is only in the client buffer ---
move a14, -*sp, 1
movi 01894000h, a14, L
movi 0, a0, L
move a0, *a14+, 1
move a11, *a14+, 1
calla 3FD9F6B0h ; XSync
setf 16, 0, 0
setf 32, 0, 1
move a8, @018901C0h, 1 ; MARK sync return
move a8, @m_syncret, 1
move a14, -*sp, 1
movi 01894000h, a14, L
movi 0, a0, L
move a0, *a14+, 1
move a11, *a14+, 1
calla 3FD9F6B0h ; XSync
setf 16, 0, 0
setf 32, 0, 1
move a8, @018901C0h, 1
move a8, @m_syncret, 1
movi 8, a0, L
move a0, @01890140h, 1 ; stage = 8
move a0, @m_stage, 1
; ---- XDestroyImage(image) ------------------------------------
move a14, -*sp, 1
movi 01894000h, a14, L
move a7, *a14+, 1
calla 3F9A0D80h ; XDestroyImage
setf 16, 0, 0
setf 32, 0, 1
jruc done
fail_abi:
movi 091h, a0, L
jruc failed
fail_open:
movi 092h, a0, L
jruc failed
fail_win:
movi 093h, a0, L
jruc failed
fail_gc:
movi 095h, a0, L
jruc failed
fail_img:
movi 096h, a0, L
jruc failed
failed:
move a0, @01890140h, 1
move a0, @m_stage, 1
done:
mmfm sp, a0,a1,a2,a3,a4,a5,a6,a7
movi 0, a8, L
rets
.data
; 32 rows of 4 bytes, LSB-first pixels: a solid row at y=0, a solid row
; at y=31, and a one-pixel diagonal between them. The top and bottom
; rows make the drawn height readable straight off the PNG.
BITMAP:
.byte 0FFh, 0FFh, 0FFh, 0FFh, 002h, 000h, 000h, 000h
.byte 004h, 000h, 000h, 000h, 008h, 000h, 000h, 000h
.byte 010h, 000h, 000h, 000h, 020h, 000h, 000h, 000h
.byte 040h, 000h, 000h, 000h, 080h, 000h, 000h, 000h
.byte 000h, 001h, 000h, 000h, 000h, 002h, 000h, 000h
.byte 000h, 004h, 000h, 000h, 000h, 008h, 000h, 000h
.byte 000h, 010h, 000h, 000h, 000h, 020h, 000h, 000h
.byte 000h, 040h, 000h, 000h, 000h, 080h, 000h, 000h
.byte 000h, 000h, 001h, 000h, 000h, 000h, 002h, 000h
.byte 000h, 000h, 004h, 000h, 000h, 000h, 008h, 000h
.byte 000h, 000h, 010h, 000h, 000h, 000h, 020h, 000h
.byte 000h, 000h, 040h, 000h, 000h, 000h, 080h, 000h
.byte 000h, 000h, 000h, 001h, 000h, 000h, 000h, 002h
.byte 000h, 000h, 000h, 004h, 000h, 000h, 000h, 008h
.byte 000h, 000h, 000h, 010h, 000h, 000h, 000h, 020h
.byte 000h, 000h, 000h, 040h, 0FFh, 0FFh, 0FFh, 0FFh
BITMAP_END:
.bss m_stage, 32, 1
.bss m_display, 32, 1
.bss m_window, 32, 1
.bss m_gc, 32, 1
.bss m_image, 32, 1
.bss m_putret, 32, 1
.bss m_syncret, 32, 1
.bss m_strlen, 32, 1
.end
+301
View File
@@ -0,0 +1,301 @@
-- xshow.lua -- run dwt/gui/build/xshow.coff through the COFF loader and report
-- whether the 1-bit XImage reached the screen.
--
-- Same debugger-assisted path as dwt/loader/loader.lua (no network, no rdebug,
-- no sudo): at frame XSHOW_AT it pokes the loader at bit 0x01880000, the COFF
-- at XSHOW_BUF (default 0x01900000), the descriptor at 0x01882C00, and sets
-- PC = 0x01880000. The loader copies the sections and calls create_process().
--
-- Env:
-- XSHOW_AT injection frame (default 2500)
-- XSHOW_END inspection/exit frame (default 2700)
-- XSHOW_SNAP frame to snapshot (default XSHOW_END)
-- XSHOW_COFF COFF (default dwt/gui/build/xshow.coff)
-- XSHOW_BIN loader payload (default dwt/loader/build/loader.bin)
-- XSHOW_BUF COFF buffer bit address (default 0x01900000)
-- XSHOW_OUT evidence dir (default dwt/gui/evidence)
-- XSHOW_NOSNAP 1 = do not write a PNG
--
-- Marker cells (the payload writes both blocks):
-- 01890100/120/140/160/180/1A0/1C0 xhello-compatible cells (heap; may be
-- overwritten after the app finishes)
-- 018D8000/20/40/60/80/A0/C0/E0 .bss mirror: stage, display, window,
-- gc, image, putret, syncret, strlen
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
local machine = manager.machine
local cpu = machine.devices[':maincpu']
local dbg = machine.debugger
local prog = cpu.spaces['program']
if not dbg then
print("XSHOW: debugger not enabled; pass -debug")
machine:exit()
return
end
local AT = tonumber(os.getenv("XSHOW_AT") or "2500")
local ENDF = tonumber(os.getenv("XSHOW_END") or "2700")
local SNAP = tonumber(os.getenv("XSHOW_SNAP") or tostring(ENDF))
local BIN = os.getenv("XSHOW_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("XSHOW_COFF") or "dwt/gui/build/xshow.coff"
local BUF = tonumber(os.getenv("XSHOW_BUF") or "0x01900000")
local OUT = os.getenv("XSHOW_OUT") or "dwt/gui/evidence"
local NOSNAP = os.getenv("XSHOW_NOSNAP") == "1"
local LOADER_BASE = 0x01880000
local DESC = 0x01882C00
local RESULT = 0x01882D00
local function slurp(p)
local f, err = io.open(p, "rb")
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
local s = f:read("*a")
f:close()
return s
end
local function u16(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
end
local function u32(s, o)
return s:byte(o + 1) + s:byte(o + 2) * 256
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
end
local function parse_coff(d)
local c = { data = d }
c.magic = u16(d, 0)
c.nscns = u16(d, 2)
c.opthdr = u16(d, 16)
c.sections = {}
if c.opthdr > 0 then
c.optmagic = u16(d, 20)
c.entry = u32(d, 20 + 16)
c.textstart = u32(d, 20 + 20)
c.datastart = u32(d, 20 + 24)
end
local base = 20 + c.opthdr
for i = 0, c.nscns - 1 do
local o = base + i * 40
local name = d:sub(o + 1, o + 8):gsub("%z", "")
c.sections[#c.sections + 1] = {
name = name,
paddr = u32(d, o + 8),
size = u32(d, o + 16), -- bits
scnptr = u32(d, o + 20),
flags = u32(d, o + 36),
}
end
return c
end
local function poke_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
end
return n
end
local function verify_bytes(bitaddr, data)
local n = math.floor((#data + 1) / 2)
local bad = 0
for i = 0, n - 1 do
local lo = data:byte(i * 2 + 1) or 0
local hi = data:byte(i * 2 + 2) or 0
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
bad = bad + 1
end
end
return n, bad
end
local function w32(a, v) prog:write_u32(a, v) end
local function r32(a)
local ok, v = pcall(function() return prog:read_u32(a) end)
if ok then return v end
return 0xDEADBEEF
end
local loader = slurp(BIN)
local coff = slurp(COFF)
local app = parse_coff(coff)
print(string.format("XSHOW: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
print(string.format("XSHOW: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
print(string.format("XSHOW: file magic=%04X nscns=%d opthdr=%d entry=%s textstart=%s",
app.magic, app.nscns, app.opthdr, hex(app.entry or 0), hex(app.textstart or 0)))
for _, s in ipairs(app.sections) do
print(string.format("XSHOW: sec %-8s paddr=%s size=%d bits (%d B) flags=%#x",
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.flags))
end
-- The .data bytes the probe will hand to XCreateImage, read out of the COFF.
for _, s in ipairs(app.sections) do
if s.name == ".data" and s.scnptr ~= 0 and s.size > 0 then
local nb = math.floor(s.size / 8)
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
local first = {}
for i = 1, math.min(16, #bytes) do first[#first + 1] = string.format("%02X", bytes:byte(i)) end
print(string.format("XSHOW: .data first %d bytes: %s", #first, table.concat(first, " ")))
end
end
local frames = 0
local injected = false
local inspected = false
local snapped = false
local function markers()
return {
stage = r32(0x01890140),
display = r32(0x01890100),
window = r32(0x01890120),
image = r32(0x01890160),
gc = r32(0x01890180),
putret = r32(0x018901A0),
syncret = r32(0x018901C0),
}
end
local function mirror()
return {
stage = r32(0x018D8000),
display = r32(0x018D8020),
window = r32(0x018D8040),
gc = r32(0x018D8060),
image = r32(0x018D8080),
putret = r32(0x018D80A0),
syncret = r32(0x018D80C0),
strlen = r32(0x018D80E0),
}
end
local function report(tag)
local m = markers()
local r = mirror()
print(string.format(
"XSHOW: %s cells stage=%s display=%s window=%s gc=%s image=%s putret=%s syncret=%s",
tag, hex(m.stage), hex(m.display), hex(m.window), hex(m.gc), hex(m.image),
hex(m.putret), hex(m.syncret)))
print(string.format(
"XSHOW: %s mirror stage=%s display=%s window=%s gc=%s image=%s putret=%s syncret=%s strlen=%s",
tag, hex(r.stage), hex(r.display), hex(r.window), hex(r.gc), hex(r.image),
hex(r.putret), hex(r.syncret), hex(r.strlen)))
end
-- Dump the XImage fields the ROM's own code reads (byte offsets are the
-- standard 32-bit XImage layout; 0x120/0x140/0x160 = depth/bpl/bpp).
local IMG_FIELDS = {
{ "width", 0x000 }, { "height", 0x020 }, { "xoffset", 0x040 },
{ "format", 0x060 }, { "data", 0x080 }, { "byte_order", 0x0A0 },
{ "bitmap_unit", 0x0C0 }, { "bitmap_bit_order", 0x0E0 },
{ "bitmap_pad", 0x100 }, { "depth", 0x120 }, { "bytes_per_line", 0x140 },
{ "bits_per_pixel", 0x160 },
}
local function dump_image(ptr, tag)
if ptr == 0 then return end
local parts = {}
for _, f in ipairs(IMG_FIELDS) do
parts[#parts + 1] = string.format("%s=%s", f[1], hex(r32(ptr + f[2])))
end
print(string.format("XSHOW: %s image@%s %s", tag, hex(ptr), table.concat(parts, " ")))
end
local function dump_dpy(ptr, tag)
if ptr == 0 then return end
print(string.format(
"XSHOW: %s dpy@%s byte_order=%s bitmap_unit=%s scanline_pad=%s bitmap_bit_order=%s",
tag, hex(ptr), hex(r32(ptr + 0x1A0)), hex(r32(ptr + 0x1C0)),
hex(r32(ptr + 0x1E0)), hex(r32(ptr + 0x200))))
-- XPutImage's bits_per_pixel check walks dpy->pixmap_formats: count at
-- +0x220, pointer at +0x240, entry stride 0x80 bits, depth at +0x20,
-- bits_per_pixel at +0x40.
local n = r32(ptr + 0x220)
local list = r32(ptr + 0x240)
print(string.format("XSHOW: %s pixmap_formats n=%d list=%s", tag, n, hex(list)))
for i = 0, math.min(n, 8) - 1 do
local e = list + i * 0x80
print(string.format("XSHOW: %s fmt[%d] depth=%s bits_per_pixel=%s pad=%s",
tag, i, hex(r32(e + 0x20)), hex(r32(e + 0x40)), hex(r32(e + 0x60))))
end
end
local function inject()
poke_bytes(LOADER_BASE, loader)
local _, bad = verify_bytes(LOADER_BASE, loader)
print(string.format("XSHOW: loader poked %d words, readback %d bad at %s",
math.floor((#loader + 1) / 2), bad, hex(LOADER_BASE)))
poke_bytes(BUF, coff)
local _, cbad = verify_bytes(BUF, coff)
print(string.format("XSHOW: COFF poked %d words, readback %d bad at %s",
math.floor((#coff + 1) / 2), cbad, hex(BUF)))
w32(DESC + 0x00, 0)
prog:write_u16(DESC + 0x00, 0x4C44) -- "LD"
prog:write_u16(DESC + 0x10, 0x5231) -- "R1"
w32(DESC + 0x20, BUF)
w32(DESC + 0x40, #coff)
w32(DESC + 0x60, 0) -- mode 0: debug-resume
print(string.format("XSHOW: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
local orig_pc = cpu.state['PC'].value
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
print(string.format("XSHOW: will resume at %s after create_process", hex(orig_pc)))
cpu.state['A8'].value = 0
cpu.state['PC'].value = LOADER_BASE
injected = true
print(string.format("XSHOW: frame %d: entered loader at %s (caller SP=%s)",
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
end
local function snapshot(path)
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if not screen then
print("XSHOW: no screen device")
return
end
local ok, err = pcall(function() return screen:snapshot(path) end)
print(string.format("XSHOW: snapshot %s ok=%s %s", path, tostring(ok), tostring(err or "")))
end
emu.register_frame_done(function()
frames = frames + 1
if frames == AT and not injected then inject() end
if injected and not inspected and frames >= AT + 40 then
inspected = true
report("f" .. frames)
end
if injected and frames == SNAP and not snapped then
snapped = true
report("f" .. frames)
if not NOSNAP then snapshot(OUT .. "/xshow_frame" .. frames .. ".png") end
end
if frames >= ENDF then
if injected then
report("final")
local st = r32(RESULT + 0x000)
print(string.format("XSHOW: loader status=%d entry=%s text=%s/%d bits",
st, hex(r32(RESULT + 0x020)),
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060)))
print(string.format("XSHOW: PC at exit = %s", hex(cpu.state['PC'].value)))
local m = markers()
dump_image(m.image, "final")
dump_dpy(m.display, "final")
end
machine:exit()
end
end, "vt1200-xshow")
dbg.visible_cpu = cpu
dbg.execution_state = 'run'
+7 -5
View File
@@ -9,7 +9,7 @@
; XLoadFont(d,"fixed") 3FD4AE80
; XCreateGC(d,win,mask,&values) 3F997000
; XSetForeground(d,gc,1) 3FD99A60
; XMapWindow(d,win) 3FD645B0
; XRaiseWindow(d,win) 3FD645B0 (does NOT map)
; XSync(d,0) / XDrawString(...) loop 3FD9F6B0 / 3FDA0000
;
; The GC is created with a zero value-mask, so the server fills it from the
@@ -49,7 +49,7 @@
; 01842060 window id
; 01842080 GC id returned by XCreateGC
; 018420A0 XSetForeground return
; 018420C0 XMapWindow return
; 018420C0 XRaiseWindow return
; 018420E0 last XSync return
; 01842100 first XDrawString return
; 01842120 second XDrawString return
@@ -180,15 +180,17 @@ _start:
movi 6, a0, L
move a0, @01842000h, 1 ; stage = 6
; ---- XMapWindow(display, window) -----------------------------
; ---- XRaiseWindow(display, window) ---------------------------
; ConfigureWindow with CWStackMode=Above: raises an already-mapped
; window. It does NOT map it -- XMapWindow is 3FD64F60.
move a14, -*sp, 1
movi 01894000h, a14, L
move a10, *a14+, 1 ; window
move a11, *a14+, 1 ; display
calla 3FD645B0h ; XMapWindow
calla 3FD645B0h ; XRaiseWindow
setf 16, 0, 0
setf 32, 0, 1
move a8, @018420C0h, 1 ; MARK map
move a8, @018420C0h, 1 ; MARK raise
movi 7, a0, L
move a0, @01842000h, 1 ; stage = 7
+120 -1
View File
@@ -15,6 +15,7 @@ Read `dwt/notes/LOADER.md` for the full report and
| `loader.asm` | the loader; linked at bit `0x01880000`, raw `.bin` 1220 B |
| `marker.asm` | acceptance app with `.text`/`.data`/`.bss` at three addresses |
| `coff.py` | TI COFF reader/dumper (`summary`, `raw`, `manifest`) |
| `xg.c` | app-side `vt_install_xg()`: installs the per-process Xlib context before `XOpenDisplay` (see below); not part of the loader payload |
| `build.sh` | GSPA/GSPLNK wrapper; keeps the linked COFF |
| `reldemo.sh`, `rel_a.asm`, `rel_b.asm` | relocation and position-dependence demo |
| `loader.lua` | debugger-assisted harness (no network, no rdebug) |
@@ -25,6 +26,84 @@ Read `dwt/notes/LOADER.md` for the full report and
`work/` (the DOS tools extracted from the SDK floppy) and `run/` (private
NVRAM/cfg) are local scratch and ignored.
## The per-process XG block (needed before `XOpenDisplay`)
A process this loader starts with `create_process` begins with **no Xlib
context**. The ROM Xlib finds it through the current-process word:
```
proc = *(u32 *)0x001B3900 ; current PCB (bit address)
pp = *(u32 *)(proc + 0x100) ; per-process user block (bit +0x100 = byte +0x20)
XG = *(u32 *)pp ; per-process Xlib context; 0 in a fresh child
free_list = *(u32 *)(XG + 0xCC0) ; bits; byte +0x198 of the block
```
Verified in the ROM: the current-process helper `0x3F708700` is just
`move @0x1b3900,a8,1; rets`, and both the dequeue path inside `XNextEvent`
(`0x3F9C1CF0`) and its enqueue helper (`0x3F9B89A0`, Xlib's `_XEnq`, called at
`0x3F9C2180`) do `calla 0x3F708700` → `move *a8(0x100),a7` → `move *a7,a7` →
access `*a7(0xcc0)`.
With `XG == 0` the whole XG structure — queue head, queue length, and the free
list at `+0xCC0` — is read from low RAM. Nothing crashes and nothing reports an
error: `XOpenDisplay`, `XCreateSimpleWindow`, `XMapWindow`, `XSync` and all
drawing still work, and the window appears on screen. **Only events fail** —
`XNextEvent` returns zeroed records (`type=0`, `keycode=0`) and never a real
event. That is the symptom to recognise: a client that looks alive and never
reacts.
Install a zeroed ≥1 KiB block before the first Xlib call:
```c
extern int vt_install_xg(void);
if(!vt_install_xg())
return 1; /* no plausible current process / user block */
dpy = XOpenDisplay("0::0"); /* only after the block exists */
```
`xg.c` is that helper. Build it with the app (the C toolchain path used by
`apps/termtris`):
```sh
apps/termtris/build.sh myapp.c dwt/loader/xg.c
```
or copy the file into the app's tree; there is no header — declare
`extern int vt_install_xg(void);`. The termtris port makes the same install
(`apps/termtris/src/vt1200/xgfix.c`) with a `static vt_u32 vt_xg[256]` block
(1 KiB); `xg.c` zeroes its block on each call rather than trusting startup to
clear `.bss`. The helper stores its block's address at `*(u32 *)pp` — it
overwrites XG, not the pointer cell at `proc + 0x100` — and changes RAM only,
never the ROM.
An assembly client does the same two loads and one store:
```
move @1B3900h, a8, 1 ; current PCB
move *a8(100h), a7, 1 ; per-process user block (bit offset 0x100)
movi xg_block, a9 ; a 1 KiB block, zeroed at startup
move a9, *a7, 1 ; XG = block
```
**Ordering:** before `XOpenDisplay`, every time. A draw-only window can get
away without it; the moment the client calls `XNextEvent`, the missing block
turns into "no events, ever".
Measured (2026-11-13): the unmodified termtris smoke client
(`apps/termtris/tests/smoke.c`) linked with `dwt/loader/xg.c` and loaded by
this harness received a real `KeyPress`:
```
SMOKE: magic=534D4F4B dpy=00942290 win=00400001 n=9 type=2 keycode=194 lookup_n=1 ch=61 ks=0061 keymark=4B455950
```
The same client with a stub `vt_install_xg()` that installs nothing runs its
event loop but only sees zeroed records:
`type=0 keycode=0 lookup_n=0 ch=00 ks=0000 keymark=00000000` after 10
iterations. The transcript, including the control, is
`evidence/xg_helper_run.log`.
## Build
```sh
@@ -56,5 +135,45 @@ The script pokes the loader at `0x01880000` and the COFF at `LOADER_BUF`
network, the rdebug service or a firmware transport.
Knobs: `LOADER_MODE=1` (callable/return instead of debug-resume),
`LOADER_A8_DESC=1` (descriptor in `A8`), `LOADER_SNAP=1` (PNG at `LOADER_END`),
`LOADER_A8_DESC=1` (descriptor in `A8`), `LOADER_SNAP=1` (PNG at the exit frame),
`LOADER_VERBOSE=1`, `LOADER_TRACE=1`.
### Environment
| variable | default | meaning |
|---|---|---|
| `LOADER_AT` | `2500` | frame at which the loader and COFF are poked and `PC` is set |
| `LOADER_END` | `2700` | fixed inspection/exit frame; **`0` = run until completion** |
| `LOADER_MAX` | `6000` | `LOADER_END=0` only: give up (with a warning) at this frame |
| `LOADER_BIN` | `dwt/loader/build/loader.bin` | loader payload poked at bit `0x01880000` |
| `LOADER_COFF` | `dwt/loader/build/marker.coff` | app COFF poked at `LOADER_BUF` |
| `LOADER_BUF` | `0x01900000` | COFF buffer bit address |
| `LOADER_OUT` | `dwt/loader/evidence` | directory for the optional PNG |
| `LOADER_SNAP` | `0` | `1` writes `loader_frame<frame>.png` at the exit frame |
### Completion and `LOADER_END=0`
The harness detects completion when all three hold:
1. the loader has written `RESULT_STATUS` (it is `0xFFFFFFFF` until then),
2. `PC` is outside `[LOADER_BASE, LOADER_BASE+0x400)`, and
3. the result block has been unchanged for 10 frames.
On detection it prints one line and sets `done` once:
```
LOADER: complete at frame 2510 status=00000000
```
With a **fixed** `LOADER_END` the run still exits at that frame, so the snapshot
filename and every existing fixed-frame capture are unchanged; the completion
line is informational and suppresses the startup warning. With **`LOADER_END=0`**
the run exits as soon as completion is detected, and if it is not detected by
`LOADER_MAX` it prints
```
LOADER: warning: app still in startup at LOADER_MAX=6000
```
and exits there. With a fixed `LOADER_END` that is reached first, the warning is
`LOADER: warning: app still in startup at LOADER_END=<n>`.
Binary file not shown.
Binary file not shown.
+626
View File
@@ -0,0 +1,626 @@
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 1
0001 ; xshow.asm -- create a 1-bit XImage and XPutImage it o
0002 ;
0003 ; Run as a first-class process created by the COFF load
0004 ; in the rdebug dispatcher's context: a connect made fr
0005 ; accepted at the service layer but the server never re
0006 ;
0007 ; The image is a 32x32 XYBitmap (format 0), depth 1, cr
0008 ; XCreateImage and drawn with XPutImage. Its data is a
0009 ; cells, written into .data at build time, so the PNG s
0010 ; or nothing -- there is nothing to misread.
0011 ;
0012 ; XImage entry points used here (Ghidra address -> bit
0013 ; 7F34092 XCreateImage(d,visual,depth,format,offset,d
0014 ; 7FA06E XPutImage(d,drawable,gc,image,sx,sy,dx,dy,w
0015 ; 7F341B0 XDestroyImage(image)
0016 ; 7FAAAD6 XGetImage(d,drawable,x,y,w,h,plane_mask,for
0017 ; (XGetImage is documented from disassembly; this probe
0018 ;
0019 ; Calling convention: reserve one slot with `move a14,-
0020 ; last-to-first upward through a14, then `calla`. The
0021 ; the return address and the reserved slot, and restore
0022 ; sp/a14 from RAM markers (xtext.asm records that exact
0023 ;
0024 ; Xlib clobbers the CPU's SETF field state, so field 1
0025 ; established after every call. a10/a11/a12 survive ev
0026 ; a9 (the GC) survives XCreateImage and XPutImage; a7 (
0027 ; XPutImage. XDestroyImage saves only a11/a13, so it r
0028 ;
0029 ; Markers:
0030 ; 01890100 display 01890120 window 01890140 stage
0031 ; 01890180 gc 018901A0 XPutImage return 01
0032 ; These are the xhello-compatible cells the runner repo
0033 ; cells sit in the heap and were overwritten after its
0034 ; are mirrored into .bss at 018D8000h (below), which no
0035 ; 018D8000 stage 018D8020 display 018D8040 window
0036 ; 018D8080 image 018D80A0 putret 018D80C0 syncret
0037 ; Stage: 1 start, 2 display, 3 window, 4 mapped, 5 gc,
0038 ; 8 synced; 091h..097h = the step that failed.
0039 ;
0040 ; Scratch argument area: 01894000h (the app's own stack
0041
0042 00000000 .text
0043 00000000 _start:
0044 00000000 0550 setf 16, 0, 0
0045 00000010 0740 setf 32, 0, 1
0046 00000020 098F mmtm sp, a0,a1,a2,a3,a4,a5,a6,a7
00000030 FF00
0047
0048 00000040 09E0 movi 1, a0, L
00000050 00000001
0049 00000070 0780 move a0, @01890140h, 1 ; stage = 1
00000080 01890140
0050 000000A0 0780 move a0, @m_stage, 1
000000B0 00000000+
0051
0052 ; ---- convention check: strlen("0::0") == 4 ---------
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 2
0053 000000D0 A3CF move a14, -*sp, 1
0054 000000E0 09EE movi 01894000h, a14, L
000000F0 01894000
0055 00000110 09E0 movi 3FACE948h, a0, L ; ROM "0::0"
00000120 3FACE948
0056 00000140 920E move a0, *a14+, 1
0057 00000150 0D5F calla 3FB458D0h ; strlen
00000160 3FB458D0
0058 00000180 0550 setf 16, 0, 0
0059 00000190 0740 setf 32, 0, 1
0060 000001A0 0788 move a8, @m_strlen, 1
000001B0 000000E0+
0061 000001D0 09E0 movi 4, a0, L
000001E0 00000004
0062 00000200 4808 cmp a0, a8
0063 00000210 CB00 jrne fail_abi
00000220 0171
0064
0065 ; ---- display = XOpenDisplay("0::0") ----------------
0066 00000230 A3CF move a14, -*sp, 1
0067 00000240 09EE movi 01894000h, a14, L
00000250 01894000
0068 00000270 09E0 movi 3FACE948h, a0, L
00000280 3FACE948
0069 000002A0 920E move a0, *a14+, 1
0070 000002B0 0D5F calla 3F9C2570h ; XOpenDisplay
000002C0 3F9C2570
0071 000002E0 0550 setf 16, 0, 0
0072 000002F0 0740 setf 32, 0, 1
0073 00000300 4D0B move a8, a11
0074 00000310 078B move a11, @01890100h, 1 ; MARK display
00000320 01890100
0075 00000340 078B move a11, @m_display, 1
00000350 00000020+
0076 00000370 4D6B move a11, a11
0077 00000380 CA00 jreq fail_open
00000390 015E
0078 000003A0 09E0 movi 2, a0, L
000003B0 00000002
0079 000003D0 0780 move a0, @01890140h, 1 ; stage = 2
000003E0 01890140
0080 00000400 0780 move a0, @m_stage, 1
00000410 00000000+
0081
0082 ; ---- root = *(*(display+0x480)+0x40) ---------------
0083 00000430 B76A move *a11(0480h), a10, 1
00000440 0480
0084 00000450 B74A move *a10(040h), a10, 1
00000460 0040
0085
0086 ; ---- window = XCreateSimpleWindow(d,root,100,100,400
0087 ; white background (pixel 1), black border, so a black
0088 00000470 A3CF move a14, -*sp, 1
0089 00000480 09EE movi 01894000h, a14, L
00000490 01894000
0090 000004B0 09E0 movi 1, a0, L
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 3
000004C0 00000001
0091 000004E0 920E move a0, *a14+, 1 ; background = 1 (white)
0092 000004F0 09E0 movi 0, a0, L
00000500 00000000
0093 00000520 920E move a0, *a14+, 1 ; border = 0 (black)
0094 00000530 09E0 movi 2, a0, L
00000540 00000002
0095 00000560 920E move a0, *a14+, 1 ; border width
0096 00000570 09E0 movi 200, a0, L
00000580 000000C8
0097 000005A0 920E move a0, *a14+, 1 ; height
0098 000005B0 09E0 movi 400, a0, L
000005C0 00000190
0099 000005E0 920E move a0, *a14+, 1 ; width
0100 000005F0 09E0 movi 100, a0, L
00000600 00000064
0101 00000620 920E move a0, *a14+, 1 ; y
0102 00000630 920E move a0, *a14+, 1 ; x
0103 00000640 934E move a10, *a14+, 1 ; parent = root
0104 00000650 936E move a11, *a14+, 1 ; display
0105 00000660 0D5F calla 3FD41B90h ; XCreateSimpleWindow
00000670 3FD41B90
0106 00000690 0550 setf 16, 0, 0
0107 000006A0 0740 setf 32, 0, 1
0108 000006B0 4D0A move a8, a10
0109 000006C0 078A move a10, @01890120h, 1 ; MARK window
000006D0 01890120
0110 000006F0 078A move a10, @m_window, 1
00000700 00000040+
0111 00000720 4D4A move a10, a10
0112 00000730 CA00 jreq fail_win
00000740 0127
0113 00000750 09E0 movi 3, a0, L
00000760 00000003
0114 00000780 0780 move a0, @01890140h, 1 ; stage = 3
00000790 01890140
0115 000007B0 0780 move a0, @m_stage, 1
000007C0 00000000+
0116
0117 ; ---- XMapWindow(display, window) -------------------
0118 000007E0 A3CF move a14, -*sp, 1
0119 000007F0 09EE movi 01894000h, a14, L
00000800 01894000
0120 00000820 934E move a10, *a14+, 1
0121 00000830 936E move a11, *a14+, 1
0122 00000840 0D5F calla 3FD645B0h ; XMapWindow
00000850 3FD645B0
0123 00000870 0550 setf 16, 0, 0
0124 00000880 0740 setf 32, 0, 1
0125 00000890 09E0 movi 4, a0, L
000008A0 00000004
0126 000008C0 0780 move a0, @01890140h, 1 ; stage = 4
000008D0 01890140
0127 000008F0 0780 move a0, @m_stage, 1
00000900 00000000+
0128
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 4
0129 ; ---- gc = XCreateGC(d, window, 0, NULL) ------------
0130 00000920 A3CF move a14, -*sp, 1
0131 00000930 09EE movi 01894000h, a14, L
00000940 01894000
0132 00000960 09E0 movi 0, a0, L
00000970 00000000
0133 00000990 920E move a0, *a14+, 1 ; values
0134 000009A0 920E move a0, *a14+, 1 ; mask = 0
0135 000009B0 934E move a10, *a14+, 1 ; drawable
0136 000009C0 936E move a11, *a14+, 1 ; display
0137 000009D0 0D5F calla 3F997000h ; XCreateGC
000009E0 3F997000
0138 00000A00 0550 setf 16, 0, 0
0139 00000A10 0740 setf 32, 0, 1
0140 00000A20 4D09 move a8, a9 ; GC
0141 00000A30 0789 move a9, @01890180h, 1 ; MARK gc
00000A40 01890180
0142 00000A60 0789 move a9, @m_gc, 1
00000A70 00000060+
0143 00000A90 4D29 move a9, a9
0144 00000AA0 CA00 jreq fail_gc
00000AB0 00F4
0145
0146 ; ---- XSetForeground(display, gc, 0) -- draw with pen
0147 00000AC0 A3CF move a14, -*sp, 1
0148 00000AD0 09EE movi 01894000h, a14, L
00000AE0 01894000
0149 00000B00 09E0 movi 0, a0, L
00000B10 00000000
0150 00000B30 920E move a0, *a14+, 1 ; pixel = 0
0151 00000B40 932E move a9, *a14+, 1 ; gc
0152 00000B50 936E move a11, *a14+, 1 ; display
0153 00000B60 0D5F calla 3FD99A60h ; XSetForeground
00000B70 3FD99A60
0154 00000B90 0550 setf 16, 0, 0
0155 00000BA0 0740 setf 32, 0, 1
0156 00000BB0 09E0 movi 5, a0, L
00000BC0 00000005
0157 00000BE0 0780 move a0, @01890140h, 1 ; stage = 5
00000BF0 01890140
0158 00000C10 0780 move a0, @m_stage, 1
00000C20 00000000+
0159
0160 ; ---- image = XCreateImage(d, NULL, 1, XYBitmap, 0,
0161 ; bitmap, 32, 32, 32, 0) ---
0162 00000C40 A3CF move a14, -*sp, 1
0163 00000C50 09EE movi 01894000h, a14, L
00000C60 01894000
0164 00000C80 09E0 movi 0, a0, L
00000C90 00000000
0165 00000CB0 920E move a0, *a14+, 1 ; bytes_per_line = 0 (let it comput
0166 00000CC0 09E0 movi 32, a0, L
00000CD0 00000020
0167 00000CF0 920E move a0, *a14+, 1 ; bitmap_pad = 32
0168 00000D00 09E0 movi 32, a0, L
00000D10 00000020
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 5
0169 00000D30 920E move a0, *a14+, 1 ; height
0170 00000D40 920E move a0, *a14+, 1 ; width
0171 00000D50 09E0 movi BITMAP, a0, L
00000D60 00000000"
0172 00000D80 920E move a0, *a14+, 1 ; data
0173 00000D90 09E0 movi 0, a0, L
00000DA0 00000000
0174 00000DC0 920E move a0, *a14+, 1 ; offset
0175 00000DD0 920E move a0, *a14+, 1 ; format = 0 (XYBitmap)
0176 00000DE0 09E0 movi 1, a0, L
00000DF0 00000001
0177 00000E10 920E move a0, *a14+, 1 ; depth = 1
0178 00000E20 4400 sub a0, a0
0179 00000E30 920E move a0, *a14+, 1 ; visual = NULL
0180 00000E40 936E move a11, *a14+, 1 ; display
0181 00000E50 0D5F calla 3F9A0490h ; XCreateImage
00000E60 3F9A0490
0182 00000E80 0550 setf 16, 0, 0
0183 00000E90 0740 setf 32, 0, 1
0184 00000EA0 4D07 move a8, a7 ; image (a7 survives XPutImage)
0185 00000EB0 0788 move a8, @01890160h, 1 ; MARK image
00000EC0 01890160
0186 00000EE0 0788 move a8, @m_image, 1
00000EF0 00000080+
0187 00000F10 4D08 move a8, a8
0188 00000F20 CA00 jreq fail_img
00000F30 00B0
0189 00000F40 09E0 movi 6, a0, L
00000F50 00000006
0190 00000F70 0780 move a0, @01890140h, 1 ; stage = 6
00000F80 01890140
0191 00000FA0 0780 move a0, @m_stage, 1
00000FB0 00000000+
0192
0193 ; ---- let the WM frame/reparent and map the window (x
0194 ; A draw issued before the reparent can be lost, so sy
0195 00000FD0 09EC movi 4, a12, L
00000FE0 00000004
0196 00001000 map_wait:
0197 00001000 A3CF move a14, -*sp, 1
0198 00001010 09EE movi 01894000h, a14, L
00001020 01894000
0199 00001040 09E0 movi 0, a0, L
00001050 00000000
0200 00001070 920E move a0, *a14+, 1 ; discard = 0
0201 00001080 936E move a11, *a14+, 1 ; display
0202 00001090 0D5F calla 3FD9F6B0h ; XSync
000010A0 3FD9F6B0
0203 000010C0 0550 setf 16, 0, 0
0204 000010D0 0740 setf 32, 0, 1
0205 000010E0 3DEC dsjs a12, map_wait
0206
0207 ; ---- XPutImage(d, win, gc, image, 0,0, 20,20, 32,32)
0208 000010F0 A3CF move a14, -*sp, 1
0209 00001100 09EE movi 01894000h, a14, L
00001110 01894000
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 6
0210 00001130 09E0 movi 32, a0, L
00001140 00000020
0211 00001160 920E move a0, *a14+, 1 ; h
0212 00001170 920E move a0, *a14+, 1 ; w
0213 00001180 09E0 movi 20, a0, L
00001190 00000014
0214 000011B0 920E move a0, *a14+, 1 ; dst_y
0215 000011C0 920E move a0, *a14+, 1 ; dst_x
0216 000011D0 4400 sub a0, a0
0217 000011E0 920E move a0, *a14+, 1 ; src_y
0218 000011F0 920E move a0, *a14+, 1 ; src_x
0219 00001200 92EE move a7, *a14+, 1 ; image
0220 00001210 932E move a9, *a14+, 1 ; gc
0221 00001220 934E move a10, *a14+, 1 ; drawable
0222 00001230 936E move a11, *a14+, 1 ; display
0223 00001240 0D5F calla 3F9D0370h ; XPutImage
00001250 3F9D0370
0224 00001270 0550 setf 16, 0, 0
0225 00001280 0740 setf 32, 0, 1
0226 00001290 0788 move a8, @018901A0h, 1 ; MARK putimage return
000012A0 018901A0
0227 000012C0 0788 move a8, @m_putret, 1
000012D0 000000A0+
0228 000012F0 09E0 movi 7, a0, L
00001300 00000007
0229 00001320 0780 move a0, @01890140h, 1 ; stage = 7
00001330 01890140
0230 00001350 0780 move a0, @m_stage, 1
00001360 00000000+
0231
0232 ; ---- control: the same image with h = 16 at dst_y =
0233 ; The PNG must show exactly 16 rows here (src rows 0..
0234 ; what proves the 32-row draw above is the image, not
0235 00001380 A3CF move a14, -*sp, 1
0236 00001390 09EE movi 01894000h, a14, L
000013A0 01894000
0237 000013C0 09E0 movi 16, a0, L
000013D0 00000010
0238 000013F0 920E move a0, *a14+, 1 ; h = 16
0239 00001400 09E0 movi 32, a0, L
00001410 00000020
0240 00001430 920E move a0, *a14+, 1 ; w = 32
0241 00001440 09E0 movi 60, a0, L
00001450 0000003C
0242 00001470 920E move a0, *a14+, 1 ; dst_y = 60
0243 00001480 09E0 movi 20, a0, L
00001490 00000014
0244 000014B0 920E move a0, *a14+, 1 ; dst_x = 20
0245 000014C0 4400 sub a0, a0
0246 000014D0 920E move a0, *a14+, 1 ; src_y = 0
0247 000014E0 920E move a0, *a14+, 1 ; src_x = 0
0248 000014F0 92EE move a7, *a14+, 1 ; image
0249 00001500 932E move a9, *a14+, 1 ; gc
0250 00001510 934E move a10, *a14+, 1 ; drawable
0251 00001520 936E move a11, *a14+, 1 ; display
0252 00001530 0D5F calla 3F9D0370h ; XPutImage
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 7
00001540 3F9D0370
0253 00001560 0550 setf 16, 0, 0
0254 00001570 0740 setf 32, 0, 1
0255
0256 ; ---- flush, twice: the request is only in the client
0257 00001580 A3CF move a14, -*sp, 1
0258 00001590 09EE movi 01894000h, a14, L
000015A0 01894000
0259 000015C0 09E0 movi 0, a0, L
000015D0 00000000
0260 000015F0 920E move a0, *a14+, 1
0261 00001600 936E move a11, *a14+, 1
0262 00001610 0D5F calla 3FD9F6B0h ; XSync
00001620 3FD9F6B0
0263 00001640 0550 setf 16, 0, 0
0264 00001650 0740 setf 32, 0, 1
0265 00001660 0788 move a8, @018901C0h, 1 ; MARK sync return
00001670 018901C0
0266 00001690 0788 move a8, @m_syncret, 1
000016A0 000000C0+
0267
0268 000016C0 A3CF move a14, -*sp, 1
0269 000016D0 09EE movi 01894000h, a14, L
000016E0 01894000
0270 00001700 09E0 movi 0, a0, L
00001710 00000000
0271 00001730 920E move a0, *a14+, 1
0272 00001740 936E move a11, *a14+, 1
0273 00001750 0D5F calla 3FD9F6B0h ; XSync
00001760 3FD9F6B0
0274 00001780 0550 setf 16, 0, 0
0275 00001790 0740 setf 32, 0, 1
0276 000017A0 0788 move a8, @018901C0h, 1
000017B0 018901C0
0277 000017D0 0788 move a8, @m_syncret, 1
000017E0 000000C0+
0278
0279 00001800 09E0 movi 8, a0, L
00001810 00000008
0280 00001830 0780 move a0, @01890140h, 1 ; stage = 8
00001840 01890140
0281 00001860 0780 move a0, @m_stage, 1
00001870 00000000+
0282
0283 ; ---- XDestroyImage(image) --------------------------
0284 00001890 A3CF move a14, -*sp, 1
0285 000018A0 09EE movi 01894000h, a14, L
000018B0 01894000
0286 000018D0 92EE move a7, *a14+, 1
0287 000018E0 0D5F calla 3F9A0D80h ; XDestroyImage
000018F0 3F9A0D80
0288 00001910 0550 setf 16, 0, 0
0289 00001920 0740 setf 32, 0, 1
0290 00001930 C01A jruc done
0291
0292 00001940 fail_abi:
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 8
0293 00001940 09E0 movi 091h, a0, L
00001950 00000091
0294 00001970 C010 jruc failed
0295 00001980 fail_open:
0296 00001980 09E0 movi 092h, a0, L
00001990 00000092
0297 000019B0 C00C jruc failed
0298 000019C0 fail_win:
0299 000019C0 09E0 movi 093h, a0, L
000019D0 00000093
0300 000019F0 C008 jruc failed
0301 00001A00 fail_gc:
0302 00001A00 09E0 movi 095h, a0, L
00001A10 00000095
0303 00001A30 C004 jruc failed
0304 00001A40 fail_img:
0305 00001A40 09E0 movi 096h, a0, L
00001A50 00000096
0306 00001A70 0300 jruc failed
0307 00001A80 failed:
0308 00001A80 0780 move a0, @01890140h, 1
00001A90 01890140
0309 00001AB0 0780 move a0, @m_stage, 1
00001AC0 00000000+
0310
0311 00001AE0 done:
0312 00001AE0 09AF mmfm sp, a0,a1,a2,a3,a4,a5,a6,a7
00001AF0 00FF
0313 00001B00 09E8 movi 0, a8, L
00001B10 00000000
0314 00001B30 0960 rets
0315
0316 00000000 .data
0317 ; 32 rows of 4 bytes, LSB-first pixels: a solid row at
0318 ; at y=31, and a one-pixel diagonal between them. The
0319 ; rows make the drawn height readable straight off the
0320 00000000 BITMAP:
0321 00000000 FF .byte 0FFh, 0FFh, 0FFh, 0FFh, 002h, 000h, 000h, 000h
00000008 FF
00000010 FF
00000018 FF
00000020 02
00000028 00
00000030 00
00000038 00
0322 00000040 04 .byte 004h, 000h, 000h, 000h, 008h, 000h, 000h, 000h
00000048 00
00000050 00
00000058 00
00000060 08
00000068 00
00000070 00
00000078 00
0323 00000080 10 .byte 010h, 000h, 000h, 000h, 020h, 000h, 000h, 000h
00000088 00
00000090 00
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 9
00000098 00
000000A0 20
000000A8 00
000000B0 00
000000B8 00
0324 000000C0 40 .byte 040h, 000h, 000h, 000h, 080h, 000h, 000h, 000h
000000C8 00
000000D0 00
000000D8 00
000000E0 80
000000E8 00
000000F0 00
000000F8 00
0325 00000100 00 .byte 000h, 001h, 000h, 000h, 000h, 002h, 000h, 000h
00000108 01
00000110 00
00000118 00
00000120 00
00000128 02
00000130 00
00000138 00
0326 00000140 00 .byte 000h, 004h, 000h, 000h, 000h, 008h, 000h, 000h
00000148 04
00000150 00
00000158 00
00000160 00
00000168 08
00000170 00
00000178 00
0327 00000180 00 .byte 000h, 010h, 000h, 000h, 000h, 020h, 000h, 000h
00000188 10
00000190 00
00000198 00
000001A0 00
000001A8 20
000001B0 00
000001B8 00
0328 000001C0 00 .byte 000h, 040h, 000h, 000h, 000h, 080h, 000h, 000h
000001C8 40
000001D0 00
000001D8 00
000001E0 00
000001E8 80
000001F0 00
000001F8 00
0329 00000200 00 .byte 000h, 000h, 001h, 000h, 000h, 000h, 002h, 000h
00000208 00
00000210 01
00000218 00
00000220 00
00000228 00
00000230 02
00000238 00
0330 00000240 00 .byte 000h, 000h, 004h, 000h, 000h, 000h, 008h, 000h
00000248 00
00000250 04
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 10
00000258 00
00000260 00
00000268 00
00000270 08
00000278 00
0331 00000280 00 .byte 000h, 000h, 010h, 000h, 000h, 000h, 020h, 000h
00000288 00
00000290 10
00000298 00
000002A0 00
000002A8 00
000002B0 20
000002B8 00
0332 000002C0 00 .byte 000h, 000h, 040h, 000h, 000h, 000h, 080h, 000h
000002C8 00
000002D0 40
000002D8 00
000002E0 00
000002E8 00
000002F0 80
000002F8 00
0333 00000300 00 .byte 000h, 000h, 000h, 001h, 000h, 000h, 000h, 002h
00000308 00
00000310 00
00000318 01
00000320 00
00000328 00
00000330 00
00000338 02
0334 00000340 00 .byte 000h, 000h, 000h, 004h, 000h, 000h, 000h, 008h
00000348 00
00000350 00
00000358 04
00000360 00
00000368 00
00000370 00
00000378 08
0335 00000380 00 .byte 000h, 000h, 000h, 010h, 000h, 000h, 000h, 020h
00000388 00
00000390 00
00000398 10
000003A0 00
000003A8 00
000003B0 00
000003B8 20
0336 000003C0 00 .byte 000h, 000h, 000h, 040h, 0FFh, 0FFh, 0FFh, 0FFh
000003C8 00
000003D0 00
000003D8 40
000003E0 FF
000003E8 FF
000003F0 FF
000003F8 FF
0337 00000400 BITMAP_END:
0338
0339 00000000 .bss m_stage, 32, 1
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
(c) Copyright 1985, 1987, Texas Instruments Inc.
PAGE 11
0340 00000020 .bss m_display, 32, 1
0341 00000040 .bss m_window, 32, 1
0342 00000060 .bss m_gc, 32, 1
0343 00000080 .bss m_image, 32, 1
0344 000000A0 .bss m_putret, 32, 1
0345 000000C0 .bss m_syncret, 32, 1
0346 000000E0 .bss m_strlen, 32, 1
0347
0348 .end
No Errors, No Warnings
+36
View File
@@ -0,0 +1,36 @@
*****************************************************
GSP COFF Linker, Version 2.00, 87.300
*****************************************************
Fri Nov 13 09:31:54 2026
OUTPUT FILE NAME: <XSHOW.out>
ENTRY POINT SYMBOL: 0
SECTION ALLOCATION MAP
output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.text 0 01840000 00001B40
01840000 00001B40 XSHOW.obj (.text)
.data 0 018D0000 00000400
018D0000 00000400 XSHOW.obj (.data)
.bss 0 018D8000 00000100 UNINITIALIZED
018D8000 00000100 XSHOW.obj (.bss)
GLOBAL SYMBOLS
address name address name
-------- ---- -------- ----
018D8000 .bss 01840000 .text
018D0000 .data 01841B40 etext
01840000 .text 018D0000 .data
018D0400 edata 018D0400 edata
018D8100 end 018D8000 .bss
01841B40 etext 018D8100 end
[6 symbols]
Binary file not shown.
+92
View File
@@ -0,0 +1,92 @@
# vt_install_xg() acceptance run — 2026-11-13
Host: Linux, MAME 0.289 single-driver binary
`/home/arti/code/k-space/mame0289/vt1200`.
Worktree: `fix/issue-2-xg-block` (docs + `dwt/loader/xg.c`).
The ROM is unchanged before and after the runs:
```
$ md5sum vt1200_v22.bin
b46a3e442ccb86134d2356bd70d22fd2 vt1200_v22.bin
```
The client is the **unmodified** termtris smoke test
(`apps/termtris/tests/smoke.c`), which calls `vt_install_xg()`, then
`XOpenDisplay("0::0")`, creates and maps a window, selects input, and waits for
a `KeyPress`. Only the helper source differs between the two runs: the first
links `dwt/loader/xg.c`, the second a stub that installs nothing.
## Build
```
$ apps/termtris/build.sh apps/termtris/tests/smoke.c dwt/loader/xg.c
```
Link map excerpt (`apps/termtris/build/smoke.map`):
```
.text 0 018a0000 00000da0
018a0b30 00000270 XG.obj (.text)
.bss 0 01a00000 0000a700 UNINITIALIZED
01a08700 00002000 XG.obj (.bss)
```
`MARK` is the first `_mark` symbol in the map, `0x01a08000`.
## Run — helper installed
```
$ HOME=/tmp/opencode/vt1200-task2/home VT1200_SKIP_LEVEL1=1 \
SMOKE_MARK=0x01a08000 LOADER_AT=2500 LOADER_END=3400 \
LOADER_BIN=$PWD/dwt/loader/build/loader.bin \
LOADER_COFF=$PWD/apps/termtris/build/smoke.coff \
LOADER_OUT=/tmp/opencode/vt1200-task2 \
/home/arti/code/k-space/mame0289/vt1200 vt1200 \
-rompath harness/mame/roms -video none -sound none -nothrottle \
-skip_gameinfo -cfg_directory /tmp/opencode/vt1200-task2/cfg \
-nvram_directory /tmp/opencode/vt1200-task2/nvram \
-debug -debugger none -autoboot_script apps/termtris/tests/smoke.lua \
-autoboot_delay 0
```
Relevant output:
```
LOADER: result status=0 (OK) entry=018A0000 text=018A0000/3488 bits data=018A0DA0/16 bits bss=01A00000/42752 bits relocs=0 pcb=003FEE50 nscns=4 len=1349
LOADER: placed .text at 018A0000: 436 bytes, 0 differing
LOADER: placed .cinit at 018A0DA0: 2 bytes, 0 differing
SMOKE: magic=534D4F4B dpy=00942290 win=00400001 n=9 type=2 keycode=194 lookup_n=1 ch=61 ks=0061 keymark=4B455950
LOADER: PC at inspection = 3F579870
```
`type=2` is `KeyPress`, `keycode=194` is the LK401 `A`, and `keymark=4B455950`
("KEYP") is the client's own marker: the real event reached the client.
## Control — helper replaced by a stub
The stub (`/tmp/opencode/vt1200-task2/xgstub.c`) is:
```c
int
vt_install_xg(void)
{
return 1;
}
```
Built as `OUTNAME=smokectl apps/termtris/build.sh apps/termtris/tests/smoke.c
/tmp/opencode/vt1200-task2/xgstub.c`, then run with the same command and private
directories (`...-ctl-home`, `...-ctl-cfg`, `...-ctl-nvram`) and
`LOADER_COFF=apps/termtris/build/smokectl.coff`:
```
LOADER: result status=0 (OK) entry=018A0000 text=018A0000/2896 bits data=018A0B50/16 bits bss=01A00000/34560 bits relocs=0 pcb=003FEE50 nscns=4 len=1275
SMOKE: magic=534D4F4B dpy=00942290 win=00400001 n=10 type=0 keycode=0 lookup_n=0 ch=00 ks=0000 keymark=00000000
LOADER: PC at inspection = 3F579870
```
The display opens (`dpy=00942290`) and the window is created and mapped
(`win=00400001`), exactly as in the passing run. The event loop runs 10
iterations, but every record is `type=0 keycode=0` and `keymark` stays zero: no
real event ever arrives. This is the symptom the helper exists to prevent.
+87 -24
View File
@@ -17,9 +17,10 @@
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
-- LOADER_AT injection frame (default 2500)
-- LOADER_END inspection/exit frame (default 2700)
-- LOADER_END inspection/exit frame (default 2700; 0 = wait for completion)
-- LOADER_MAX LOADER_END=0 only: give up after this many frames (default 6000)
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
-- LOADER_SNAP 1 = write a PNG at the exit frame (default 0)
-- LOADER_VERBOSE 1 = print the result block every 25 frames
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
@@ -37,6 +38,9 @@ end
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
local MAXF = tonumber(os.getenv("LOADER_MAX") or "6000")
local WAIT = ENDF == 0
local STABLE = 10
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
@@ -177,6 +181,42 @@ local function result_dump()
r32(RESULT + 0x140), r32(RESULT + 0x160)))
end
-- The loader writes RESULT_STATUS last (it is 0xFFFFFFFF until then). The
-- whole result block is the completion signal: status written, PC out of the
-- loader's entry page, and the block unchanged for STABLE frames. This keeps
-- a write that is still in progress from looking final.
local RESULT_CELLS = { 0x000, 0x020, 0x040, 0x060, 0x080, 0x0A0, 0x0C0,
0x0E0, 0x100, 0x120, 0x140, 0x160, 0x180 }
local function result_signature()
local t = {}
for i, off in ipairs(RESULT_CELLS) do
t[i] = string.format("%08X", r32(RESULT + off))
end
return table.concat(t, " ")
end
local stable_signature = nil
local stable_frames = 0
local function complete()
local st = r32(RESULT + 0x000)
local pc = cpu.state['PC'].value
if st == 0xFFFFFFFF or (pc >= LOADER_BASE and pc < LOADER_BASE + 0x400) then
stable_signature = nil
stable_frames = 0
return false
end
local sig = result_signature()
if sig == stable_signature then
stable_frames = stable_frames + 1
else
stable_signature = sig
stable_frames = 1
end
return stable_frames >= STABLE
end
local function inject()
-- 1. loader itself
local n, bad = 0, 0
@@ -273,6 +313,26 @@ local function inspect()
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
end
local finished = false
local function finish()
if finished then return end
finished = true
if injected then
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
end
end
machine:exit()
end
emu.register_frame_done(function()
frames = frames + 1
if frames == AT and not injected then
@@ -283,20 +343,23 @@ emu.register_frame_done(function()
dbg:command("trace off")
print("LOADER: trace written to /tmp/opencode/ld.tr")
end
if injected and not done then
if injected then
if TRACE and frames <= AT + 40 then
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
hex(r32(RESULT + 0x020))))
end
local st = r32(RESULT + 0x000)
-- status 0 means OK; nonzero is final too once parsing has begun
if st ~= 0xFFFFFFFF and not done then
-- The loader writes 0 on success. A nonzero status is final
-- only after it has been written once (it is 0 from power-on,
-- so require the loader to have run: PC no longer at entry or
-- the app counter moved).
-- Status 0 means OK; any nonzero status the loader wrote is final too.
-- done is set exactly once, on the frame completion is detected.
if not done and complete() then
done = true
print(string.format("LOADER: complete at frame %d status=%s",
frames, hex(r32(RESULT + 0x000))))
if WAIT then
finish()
return
end
end
if VERBOSE and frames % 25 == 0 then
result_dump()
@@ -312,22 +375,22 @@ emu.register_frame_done(function()
end
end
end
if frames >= ENDF then
if injected then
done = true
inspect()
if SNAP then
local screen = nil
for _, s in pairs(machine.screens) do screen = s break end
if screen then
local out = OUT .. "/loader_frame" .. frames .. ".png"
local ok, err = pcall(function() return screen:snapshot(out) end)
print(string.format("LOADER: snapshot %s ok=%s %s",
out, tostring(ok), tostring(err or "")))
end
if WAIT then
-- LOADER_END=0: run until completion, but never forever.
if frames >= MAXF then
if not done then
print(string.format("LOADER: warning: app still in startup at LOADER_MAX=%d", MAXF))
end
finish()
end
machine:exit()
elseif frames >= ENDF then
-- A fixed LOADER_END still exits at that frame (the snapshot contract;
-- existing tests read loader_frame<ENDF>.png). Completion is reported
-- above but only LOADER_END=0 asks to exit early.
if not done then
print(string.format("LOADER: warning: app still in startup at LOADER_END=%d", ENDF))
end
finish()
end
end, "vt1200-loader")
+47
View File
@@ -0,0 +1,47 @@
/*
* xg.c -- install a per-process Xlib context before XOpenDisplay.
*
* A process created by `create_process` inherits a per-process user block: the
* current PCB is *(u32 *)0x001B3900 and its cell at bit +0x100 points at that
* block. The first word of the block is the per-process Xlib context (XG),
* and it is zero in a fresh child. The ROM Xlib's event code (XNextEvent,
* 0x3F9C1CF0, and its enqueue helper, 0x3F9B89A0) does
*
* XG = *(*(proc + 0x100)); ; three loads, see xg_install below
* free_list = *(XG + 0xCC0); ; bits = byte 0x198 of the block
*
* so a child with XG == 0 treats low RAM as its event queue: windows, mapping
* and drawing still work, but XNextEvent never delivers an event. This
* helper gives the child a zeroed 1 KiB block. It is a RAM write only; the
* ROM is untouched.
*
* Addresses are TMS34010 bit addresses, as everywhere on this CPU: +0x100 is
* 32 bytes into the PCB and the free-list field is at byte 0x198 of the block.
*
* This is the same code as apps/termtris/src/vt1200/xgfix.c. Build it with
* the C client (apps/termtris/build.sh <main>.c dwt/loader/xg.c) or copy it
* into the app's source tree; declare `extern int vt_install_xg(void);` and
* call it once, before XOpenDisplay.
*/
typedef unsigned long vt_u32;
static vt_u32 vt_xg[256]; /* 1 KiB: covers the 0x198-byte free-list field */
int
vt_install_xg(void)
{
vt_u32 proc, pp;
int i;
proc = *(volatile vt_u32 *)0x001B3900UL;
if(proc < 0x100UL || proc > 0x01FFFFFFUL)
return 0;
pp = *(volatile vt_u32 *)(proc + 0x100UL);
if(pp < 0x100UL || pp > 0x01FFFFFFUL)
return 0;
for(i = 0; i < 256; i++)
vt_xg[i] = 0;
*(volatile vt_u32 *)pp = (vt_u32)vt_xg;
return 1;
}
+2 -1
View File
@@ -362,7 +362,8 @@ Facts for anyone tempted to "just create a window" (details in
(`0x7EE160C` / lookup `0x7EE1B70`). TCP 6000 is a separate, user/node
authorised listener.
* Xlib entry points (bit addresses): `XOpenDisplay` `0x3F9C2570`,
`XCreateSimpleWindow` `0x3FD41B90`, `XMapWindow` `0x3FD645B0`,
`XCreateSimpleWindow` `0x3FD41B90`, `XMapWindow` `0x3FD64F60`,
`XRaiseWindow` `0x3FD645B0` (ConfigureWindow/CWStackMode, does not map),
`XSync` `0x3FD9F6B0`, `XCreateGC` `0x3F997000`, `XDrawString` `0x3FDA0000`.
* **Live result:** a 390-byte payload (poke+jump, no breakpoints) called
`strlen("0::0")` successfully (returned 4) using the firmware ABI, then
+281 -14
View File
@@ -44,7 +44,7 @@ WM `@0x27AA80`).
| what | Ghidra | bits | notes |
|---|---|---|---|
| `create_process(entry,name,stack,1,arg)` | `0x07EE0D48` | `0x3F706A40` | mallocs a 0x39-byte PCB, copies the name, allocates the stack, links it at `@0x1B3860` |
| current-process pointer | — | `0x1B3900` | `+0x100` = user area (fd table) |
| current-process pointer | — | `0x1B3900` | `+0x100` = user area (fd table); its first word is the per-process Xlib context (§10.5) |
| process list head | — | `0x1B3860` | |
| `Main Program` (creates SERVER + SESSIONMGR) | `0x07E69B6A`…`0x07E69C1A` | `0x3F34DB50` | itself a created process (name `Main Program`) |
| X server entry **SERVER** | `0x07E6C522` | `0x3F362910` | dix main; prints `Hello, this is the X server` |
@@ -76,8 +76,9 @@ request buffer), which is how these were named; the DB26 `XDrawString` and DB25
| `XOpenDisplay(name)` | `0x07F384AE` | `0x3F9C2570` | mallocs 0x4D8, parses the name, connects |
| `XParseDisplay` / service lookup | `0x07FA7538` | `0x3FD3A9C0` | splits `host:display.screen`, resolves `"xserver"` |
| `XCreateSimpleWindow(d,p,x,y,w,h,bw,border,bg)` | `0x07FA8372` | `0x3FD41B90` | opcode 1, 9 args |
| `XMapWindow(d,w)` | `0x07FAC8B6` | `0x3FD645B0` | opcode 8, 2 args |
| `XRaiseWindow(d,w)` | `0x07FAC8B6` | `0x3FD645B0` | ConfigureWindow, opcode 12, `CWStackMode` mask `0x40`, value `Above` (0) |
| `XMapSubwindows(d,w)` | `0x07FAC97E` | `0x3FD64BF0` | opcode 9 |
| `XMapWindow(d,w)` | `0x07FAC9EC` | `0x3FD64F60` | opcode 8 (MapWindow), 2 args |
| `XSelectInput(d,w,mask)` | `0x07FB2FAA` | `0x3FD97D50` | ChangeWindowAttributes, mask 0x800 |
| `XChangeWindowAttributes` | `0x07FA70EE` | `0x3FD38770` | opcode 2 |
| `XConfigureWindow` | `0x07FA74A2` | `0x3FD3A510` | opcode 12 |
@@ -93,6 +94,176 @@ request buffer), which is how these were named; the DB26 `XDrawString` and DB25
| internal PolyFillRectangle fast path | `0x07F33D1E` | `0x3F99E8F0` | opcode 70; not a public entry point |
| `strlen` | `0x07F68B1A` | `0x3FB458D0` | used as the ABI check |
**Drift check.** The map/raise pair was mislabelled for a long time, so pin the
names to the request byte rather than to memory. From the repo root:
```
tools/smart34010/dis34 -l -o -b 3FD64F60 -s 0x16C9EC vt1200_v22.bin
# expect: movk 8, a11 ; movb ... *a10 -> MapWindow, opcode 8, length 2
tools/smart34010/dis34 -l -o -b 3FD645B0 -s 0x16C8B6 vt1200_v22.bin
# expect: movk 12, a7 ; movb ... *a10 -> ConfigureWindow, opcode 12,
# then movi 0x40 into the value-mask (CWStackMode) and value 0 (Above)
```
(The `-s` values are file offsets: `(bit_address >> 3) - 0x07E40000`, the ROM's
byte base.)
#### 2.2.1 XImage — the bitmap path
The table above ends at the drawing calls. The image entry points are separate,
and none of them is a request except `XPutImage`/`XGetImage`; `XCreateImage` and
`XDestroyImage` are client-side. Addresses were derived by disassembling
`vt1200_v22.bin` with `tools/smart34010/dis34` and then confirmed live (see
§2.2.2). Bit addresses again; Ghidra = bits / 8.
| Xlib function | Ghidra | bits | shape seen |
|---|---|---|---|
| `XCreateImage(d,visual,depth,format,offset,data,w,h,bitmap_pad,bytes_per_line)` | `0x07F34092` | `0x3F9A0490` | 10 args; `calloc(1,0x58)` (0x3F703D90), fills the struct, `_XInitImageFuncPtrs` (0x3F9A6AA0) |
| `XPutImage(d,drawable,gc,image,src_x,src_y,dst_x,dst_y,w,h)` | `0x07F3A06E` | `0x3F9D0370` | 10 args; clips, checks `bits_per_pixel`, calls the workhorse below |
| `XDestroyImage(image)` | `0x07F341B0` | `0x3F9A0D80` | 1 arg; `free(image->data)`, `free(image->obdata)` if set, `free(image)` |
| `XGetImage(d,drawable,x,y,w,h,plane_mask,format)` | `0x07FAAAD6` | `0x3FD556B0` | 8 args; request opcode **73 (0x49)**, length 5 |
Supporting routines, named so a trace can be followed:
| routine | Ghidra | bits | what it is |
|---|---|---|---|
| PutImage request builder | `0x07F39D8E` | `0x3F9CEC70` | writes opcode **72 (0x48)** at request byte 0, length 6 at byte 2, `format = image->format` at byte 1, then drawable/gc/width/height/dst-x/dst-y/depth; dispatches the pixel copy |
| 1-bit pixel copier | `0x07F3965A` | `0x3F9CB2D0` | used when `depth == 1` **or** `format != ZPixmap`; appends the rows and bumps the request length |
| ZPixmap pixel copier | `0x07F39B18` | `0x3F9CD8C0` | used when `depth != 1` and `format == ZPixmap` |
| PutImage workhorse | `0x07F39E68` | `0x3F9CF340` | clipping, request-band splitting when the image does not fit the client buffer, then the request builder |
| `_XInitImageFuncPtrs` | `0x07F34D54` | `0x3F9A6AA0` | fills `image->f` (get_pixel at `image+0x200`, …) |
| image-field reporter | `0x07F34DA4` | `0x3F9A6D20` | prints `Bad image %s: %d found in routine: %s` (string `0x3F9A7348`) |
**Drift check.** Pin each name to its bytes before trusting the table (`-s` is
the file offset, `(bit_address >> 3) - 0x07E40000`):
```
tools/smart34010/dis34 -l -o -b 3F9D0370 -s 0xFA06E vt1200_v22.bin
# expect: mmtm sp, a5,a7,a9,a10,a11,a12,a13 -> XPutImage
tools/smart34010/dis34 -l -o -b 3F9CEE00 -s 0xF9DC0 vt1200_v22.bin
# expect: movi 0x48 (opcode 72), movb a7,*a11, movk 6 -> PutImage request
tools/smart34010/dis34 -l -o -b 3FD55830 -s 0x16AB06 vt1200_v22.bin
# expect: movi 0x49 (opcode 73), movb a11,*a10, movk 5 -> GetImage request
tools/smart34010/dis34 -l -o -b 3F9A0490 -s 0xF4092 vt1200_v22.bin
# expect: mmtm sp, a3,a5,a7,a9,a10,a11,a13 -> XCreateImage (movi 0x58 follows)
tools/smart34010/dis34 -l -o -b 3F9A0D80 -s 0xF41B0 vt1200_v22.bin
# expect: mmtm sp, a11,a13 -> XDestroyImage
```
**XImage layout.** 32-bit fields; byte offsets as the ROM writes them in
`XCreateImage`, and as read back from a live image in §2.2.2:
| off | field | off | field | off | field |
|---|---|---|---|---|---|
| `0x00` | width | `0x18` | bitmap_unit | `0x30` | red_mask |
| `0x04` | height | `0x1C` | bitmap_bit_order | `0x34` | green_mask |
| `0x08` | xoffset | `0x20` | bitmap_pad | `0x38` | blue_mask |
| `0x0C` | format | `0x24` | depth | `0x3C` | obdata |
| `0x10` | data | `0x28` | bytes_per_line | `0x40` | f.get_pixel … |
| `0x14` | byte_order | `0x2C` | bits_per_pixel | | |
**The format contract, from the code** (not from Xlib headers):
* `XCreateImage` **inherits the orders from the Display**: `image->byte_order =
*(dpy+0x1A0)`, `bitmap_unit = *(dpy+0x1C0)`, `bitmap_bit_order =
*(dpy+0x200)` (`0x3F9A0650`, `0x3F9A0680`, `0x3F9A06B0`). A client does not
have to know or guess them.
* `bits_per_pixel` starts at **1**. Only `format == ZPixmap (2)` replaces it, via
a lookup in the display's pixmap-format list (`dpy+0x220` count, `dpy+0x240`
pointer, entry stride `0x80` bits, depth at entry+`0x20`, bpp at entry+`0x40`;
no match falls back to `depth`). So **XYBitmap (0) and XYPixmap (1) are always
transported as 1 bit per pixel**, whatever `depth` says.
* `bytes_per_line` is computed from `width`/`offset`/`bitmap_pad` when the caller
passes 0 (`0x3F9A09C0`–`0x3F9A0C40`).
* `XCreateImage` itself rejects nothing — no depth, format or order check.
* `XPutImage` refuses exactly one case (`0x3F9D07B0`–`0x3F9D0B70`): `format ==
ZPixmap` **and** `depth != 1` **and** `image->bits_per_pixel` differs from the
display's bits-per-pixel for that depth. It then prints the ROM's own message
and **returns without sending the request**; the caller sees no error.
* Everything else — `depth == 1`, and every non-ZPixmap format — takes the 1-bit
path and never reaches that check.
**The two ROM messages, and what they actually mean here.**
* `XPutImage: bits_per_pixel conversion unimplemented.` — string
`0x3F9D0E80`, printed at `0x3F9D0B40` into Xlib's error stream (`@0x00DAD00`).
It is literal: there is no `bits_per_pixel` conversion path in this Xlib. It
fires only for a ZPixmap image of depth ≠ 1 whose `bits_per_pixel` does not
match the server's; the request is dropped, not rejected over the wire, and
the process continues. A 1-bit `XYBitmap` can never trigger it.
* `XGetImage: Can't get requested memory` — string `0x3FD567A0`, printed at
`0x3FD55D30`. It is the **client-side malloc for the reply data** failing: the
call at `0x3FD55C70` allocates `4 × reply.length` bytes and, on NULL, prints
this and returns NULL (`0x3FD55D60`). It says nothing about the server.
**Minimum image sequence** (same calling convention as §4): `XCreateGC`
(`0x3F997000`, mask 0 is enough) → `XCreateImage` → optional
`XSetForeground` → `XPutImage` → `XSync` (`0x3FD9F6B0`) →
`XDestroyImage`. Map and sync the window once before the put, exactly as for
text: the WM reparents the window, and a draw issued before that can be lost.
The probe in §2.2.2 is this sequence.
#### 2.2.2 The image path, measured
`dwt/gui/xshow.asm` (built with `dwt/loader/build.sh`, run through the COFF
loader — no network, no rdebug) opens its own connection as a `create_process`
child, creates a 400×200 window at 100,100, creates a 32×32 **XYBitmap**
(`depth = 1`, `format = 0`, LSBFirst both ways, `bitmap_unit = 32`,
`bitmap_pad = 32`, `bytes_per_line = 0` so `XCreateImage` computes it), uploads
it with `XPutImage` at window (20,20), syncs twice, and destroys it. A second
`XPutImage` of the same image with `h = 16` at (20,60) is the control.
Measured values from the run (frame 2650, VR150, `VT1200_SKIP_LEVEL1=1`):
```
XSHOW: f2650 mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
XSHOW: final image@00988130 width=00000020 height=00000020 xoffset=00000000 format=00000000 data=018D0000 byte_order=00000000 bitmap_unit=00000020 bitmap_bit_order=00000000 bitmap_pad=00000020 depth=00000001 bytes_per_line=00000004 bits_per_pixel=00000001
XSHOW: final dpy@0093C910 byte_order=00000000 bitmap_unit=00000020 scanline_pad=00000020 bitmap_bit_order=00000000
XSHOW: final pixmap_formats n=1 list=00367D90
XSHOW: final fmt[0] depth=00000001 bits_per_pixel=00000001 pad=00000020
```
Stage 8 is "synced"; the checklist stages 1–7 are start, display, window,
mapped, gc, image, putimage. The picture: `dwt/gui/evidence/xshow_frame2650.png`.
Pixel rows (decoded from that PNG with
`python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2650.png 118 118 40 64`,
saved as `dwt/gui/evidence/xshow_pixels.txt`) show the full 32-row image at
screen 122..153 and the 16-row control at 162..177:
```
122 ....################################....
123 .....#..................................
... (one diagonal pixel per row)
152 ..................................#.....
153 ....################################....
...
162 ....################################....
163 .....#..................................
... (control stops after 16 rows)
177 ...................#....................
```
The same payload run snapshot 30 frames later (`xshow_frame2680.png`, frame
2680) is byte-identical to the 2650 capture (md5
`ab9d63844aa5a3dd9d281a6bee3c76c2`), so the picture is the window's state and
not a transient.
What this proves, and what it does not:
* **Measured:** the ROM's own `XCreateImage` builds the struct described above
from the ten arguments and the display's orders; `XPutImage` of a 1-bit
`XYBitmap` paints exactly `w × h` pixels at the requested destination, honours
a smaller `h`, and returns normally; `XDestroyImage` runs without harm. The
display advertises exactly one pixmap format (depth 1, bpp 1, pad 32).
* **Inferred / not measured:** `XGetImage` is documented from disassembly only —
the probe does not call it (it needs a real GET round trip and its allocation
path). Orders other than LSBFirst are *supposed* to work: the 1-bit copier
picks a normalization routine from a runtime table keyed by
`(bitmap_unit, bitmap_bit_order, byte_order)` for both the image and the
display (`0x3F9CB7C0`–`0x3F9CBB20`), but only LSBFirst/32 was run. A
non-1-bit ZPixmap is untested because the server has no such visual; only the
mismatch message above is established.
### 2.3 X server internals that matter
| what | Ghidra | bits |
@@ -171,22 +342,36 @@ MOVE A11,*A14+,1 ; display
CALLA 0x07FA8372 ; -> window id
```
The full minimum is **4 Xlib calls**:
The full minimum is **4 Xlib calls after one setup step**:
0. **Install the per-process Xlib context first** — see §10.5. It is not an
Xlib call: `pp = *(u32 *)(*(u32 *)0x1B3900 + 0x100); *(u32 *)pp = block;`
with `block` a zeroed ≥1 KiB buffer. Skip it and window creation and
drawing still work, but `XNextEvent` silently never delivers a real event.
1. `XOpenDisplay("0::0")` — `0x3F9C2570`
2. `XCreateSimpleWindow(d, root, x, y, w, h, bw, border, background)` —
`0x3FD41B90`
3. `XMapWindow(d, win)` — `0x3FD645B0`
3. `XMapWindow(d, win)` — `0x3FD64F60`
4. `XSync(d, 0)` — `0x3FD9F6B0` (flush + round trip)
`XMapWindow` is `0x3FD64F60` (MapWindow, opcode 8). `0x3FD645B0` is
**`XRaiseWindow`**, not `XMapWindow`: it sends ConfigureWindow (opcode 12) with
`CWStackMode` = `Above`, which reorders the stacking but **does not map the
window**. The shipped `dwt/gui` payloads call `XRaiseWindow`, so they never map
their window themselves; it still appears framed, so the map is issued on their
behalf (the WM frames top-level client windows). A client that wants to be sure
it is mapped should call `0x3FD64F60`.
To draw text add `XLoadFont(d,"fixed")` (`0x3FD4AE80`), `XCreateGC`
(`0x3F997000`) with `GCFont=0x4000`, `XSetForeground` (`0x3FD99A60`) and
`XDrawString` (`0x3FDA0000`). No event loop is needed for a static window; the
server keeps it after the client goes idle.
`XDrawString` (`0x3FDA0000`). To draw a bitmap add `XCreateImage` +
`XPutImage` (§2.2.1); §2.2.2 is the measured example. No event loop is needed
for a static window; the server keeps it after the client goes idle.
Globals: only the `Display *` is per-app. There is **no global "current
display" to initialise**; `XOpenDisplay` allocates and returns it. Window ids,
GCs and fonts are server-side resources and are valid for any client.
Globals: the `Display *` and the per-process XG block (§10.5) are per-app.
There is **no global "current display" to initialise**; `XOpenDisplay`
allocates and returns it. Window ids, GCs and fonts are server-side resources
and are valid for any client.
## 5. The injection experiment (run) and the verdict
@@ -194,7 +379,7 @@ Payload: `dwt/gui/xhello.asm` → `dwt/gui/build/xhello.bin` (390 B), linked at
`0x01840000`, built with the TI SDK flow (`dwt/gui/build.sh`). It first calls
`strlen("0::0")` as an ABI check (must return 4; if not it returns without
touching Xlib), then `XOpenDisplay`, root lookup, `XCreateSimpleWindow`,
`XMapWindow`, `XSync`, storing a stage counter at bit `0x01850140` and the
`XRaiseWindow`, `XSync`, storing a stage counter at bit `0x01850140` and the
display/window at `0x01850100`/`0x01850120`.
Run: `VT1200_SKIP_LEVEL1=1`, private `-nvram_directory`/`-cfg_directory`,
@@ -326,12 +511,20 @@ live.
| `dwt/gui/probe.lua`, `probe2.lua`, `probe3.lua` | frame snapshots + marker/PC telemetry + accept breakpoint |
| `dwt/gui/run/mame.log` | boot, markers (`strlen=4`, `stage=2`, `disp=0`, `xclients=1`) |
| `dwt/gui/run/gui_frame15571.png` | post-injection frame: normal Terminal Manager, no new window |
| `dwt/gui/xshow.asm` | the XImage probe (§2.2.2): XCreateImage + 2×XPutImage + XDestroyImage |
| `dwt/gui/xshow.lua`, `dwt/gui/build/xshow.coff` | the COFF-loader runner and the linked image it loads |
| `dwt/gui/build/xshow.bin`, `.lst`, `.map` | assembled `.text`, listing, map |
| `dwt/gui/evidence/xshow_frame2650.png` | 32-row diagonal at window (20,20); 16-row control at (20,60) |
| `dwt/gui/evidence/xshow_frame2680.png` | the same picture 30 frames later (byte-identical PNG) |
| `dwt/gui/evidence/xshow_pixels.txt`, `png_rows.py` | the PNG's rows as ASCII, and the dependency-free decoder that produced them |
| `dwt/gui/evidence/xshow_run.log` | the run: stage 8, the live XImage fields, the display's pixmap formats |
## 10. Transport settled: a `create_process` child opens a window
**Verdict: H3 holds, with one payload bug on top.** A process created by the
firmware's own `create_process` connects to the `"xserver"` local service,
completes the X11 setup handshake, creates and maps a window. The final,
completes the X11 setup handshake, creates a window and raises it. It appears
framed (and mapped) on screen. The final,
**breakpoint-free** run shows it at frame 2838:
`dwt/gui/evidence/xhello_window_frame2838.png` (black 400x200 window at 100,100
with the WM frame/title bar, over the Terminal Manager).
@@ -423,7 +616,81 @@ Raw excerpt: `dwt/gui/evidence/transport_evidence.txt`; full trace:
`dwt/gui/run12/debug.log` (instrumented) and `dwt/gui/run13/mame.log`
(breakpoint-free).
### 10.5 The second bug: do not reload `Display *` from the marker cell
### 10.5 The per-process XG block: events need it before `XOpenDisplay`
A child made by `create_process` starts with **no per-process Xlib context**.
The ROM Xlib reaches it through the current-process word and two cells:
```
proc = *(u32 *)0x001B3900 ; current PCB; bit 0x1B3900
pp = *(u32 *)(proc + 0x100) ; per-process user block (bit +0x100 = byte +0x20)
XG = *(u32 *)pp ; per-process Xlib context; 0 in a fresh child
```
This is confirmed by disassembly, not by the field names. `0x3F708700` is the
ROM's "current process" helper, and the event code calls it before each use:
```
3f708700: move @0x1b3900, a8, 1 ; a8 = current PCB
3f708730: rets
...
3f9c23c0: calla 0x3f708700
3f9c23f0: move *a8(0x100), a7, 1 ; a7 = pp
3f9c2410: move *a7, a7, 1 ; a7 = XG
3f9c2420: move *a7(0xcc0), *a11(0), 1 ; free-list head = *(XG + 0xCC0 bits)
3f9c24b0: move a11, *a7(0xcc0), 1 ; used node goes back on the free list
```
That block is inside `XNextEvent` (`0x3F9C1CF0`, which returns at
`0x3F9C2560`). The enqueue helper it calls at `0x3F9C2180` (`0x3F9B89A0`;
Xlib's `_XEnq`) repeats the same three loads and takes a node from
`*(XG + 0xCC0)`:
```
3f9b8a80: calla 0x3f708700
3f9b8ab0: move *a8(0x100), a7, 1
3f9b8ad0: move *a7, a7, 1
3f9b8ae0: move *a7(0xcc0), a11, 1
3f9b8b70: move *a11(0), *a7(0xcc0), 1
```
The ROM is **bit-addressed**: `XG + 0xCC0` bits is byte `+0x198` of the block,
which is where the low-level note `XG + 0x198` comes from.
In a fresh child `XG` is 0, so the whole XG structure — queue head, queue
length, and the free list at `+0xCC0` — is read from low RAM. Whatever happens
to be there becomes the event queue. The result is not a crash: `XOpenDisplay`,
`XCreateSimpleWindow`, `XMapWindow`, `XSync` and every drawing call still work,
because they only build requests — the window really appears. **Events silently
never arrive**: `XNextEvent` returns zeroed records (`type=0`, `keycode=0`) and
never a real `KeyPress`, and nothing reports an error. It reads like a keyboard
or focus problem.
The fix is a RAM write before the first Xlib call:
1. Allocate a **zeroed block of at least 1 KiB** (the termtris port uses
`static vt_u32 vt_xg[256]`, exactly 1 KiB; the `+0x198` field and the queue
nodes live inside it).
2. Read `proc = *(u32 *)0x001B3900` and `pp = *(u32 *)(proc + 0x100)`.
3. Store the block's address into `*(u32 *)pp`.
`dwt/loader/xg.c` implements this as `int vt_install_xg(void)` (returns 1 on
success, 0 if `proc` or `pp` is not a plausible RAM pointer); it zeroes the
block itself rather than trusting startup to clear `.bss`. The termtris port
uses the same three loads and store (`apps/termtris/src/vt1200/xgfix.c`) with
the same 1 KiB block. Both are RAM-only: the ROM is untouched. The ordering
rule is **install it before `XOpenDisplay`**. The ROM re-reads the cell on each
event call, but installing first means no Xlib entry point can ever run with
`XG == 0`, and that is the order the working client uses.
Measured: with the block installed, a `create_process` child receives real
events — the termtris smoke test gets `type=2 keycode=194` and `XLookupString`
returns `a` (`apps/termtris/VT1200.md`, and the loader-tree helper's own run in
`dwt/loader/README.md`). With the install removed, the same client opens and
maps its window, loops in `XNextEvent` and only ever sees zeroed records
(`type=0`, `keycode=0`).
### 10.6 The second bug: do not reload `Display *` from the marker cell
With H3 alone the child still crashed in `XCreateSimpleWindow`. The cause is in
`xhello`, not in the transport: `XOpenDisplay` really returns `0x7C7290`
@@ -437,7 +704,7 @@ window in **a10** — both are callee-saved by every Xlib entry point
re-run `setf 16,0,0; setf 32,0,1` after every Xlib call because Xlib changes the
CPU's field state. The markers are diagnostic only now.
### 10.6 Reproduce
### 10.7 Reproduce
```sh
./dwt/gui/build.sh dwt/gui/xhello.asm 01840000 # 390 B
@@ -462,7 +729,7 @@ python3 dwt/visual/inject.py --host 192.168.99.2 \
`probe_win.lua` contains no `bpset`/`wpset`; the final frame is produced by the
payload alone. Stage markers: `01890140` reaches 6, `01890160` = 4.
### 10.7 Limits
### 10.8 Limits
* The demonstration depends on the `VT1200_SKIP_LEVEL1=1` divergence (as did the
original experiment); it is evidence about the OS/X server, not a real POST.
+25 -14
View File
@@ -11,16 +11,21 @@ Full port documentation: `apps/termtris/VT1200.md`.
## Build
```
apps/termtris/build.sh src/vt1200/main.c src/game.c src/vt1200/scoredb.c \
src/vt1200/x11.c src/vt1200/compat.c src/vt1200/xgfix.c
```sh
cd apps/termtris
OUTNAME=termtris ./build.sh src/vt1200/main.c src/game.c \
src/vt1200/scoredb.c src/vt1200/x11.c src/vt1200/compat.c \
src/vt1200/xgfix.c
```
`build.sh` runs `gspac`/`gspopt`/`gspcg`/`gspa` and `gsplnk` through
`/home/arti/os2-work/2ine/build/lx_loader` against the r5.01 SDK zips under
`tools/tms34010-sdk/1990-11 TMS340 Family SDK/`. Those 2ine-hosted tools
frequently segfault after writing their output, so the wrapper treats an output
file as success and retries a missing one. Two quirks are handled there:
file as success and retries a missing one. A host kernel without
`CONFIG_X86_16BIT` cannot give the 16-bit OS/2 tools their LDT segments; the
wrapper detects that and runs the same loader through `qemu-i386`, whose
linux-user emulation implements them. Two more quirks are handled there:
* `gspac` needs `-i.` for the angle-bracket shim headers;
* an empty `.cinit` makes `cinit` point at `.text`, whose first instruction the
@@ -30,7 +35,7 @@ file as success and retries a missing one. Two quirks are handled there:
Result (map):
```
.text 018A0000 .cinit 018B4B10 .bss 01A00000
.text 018A0000 .cinit 018B4A60 .bss 01A00000
ENTRY POINT SYMBOL: "_start" address: 018a0000
```
@@ -64,8 +69,8 @@ a single `XFlush`. This is not an optimisation for looks:
* an `XSync` per row **deadlocked the client** — the debug marker
`_vt_x11_progress` froze at `0x00010014` (row 20), the main-loop counter
stayed 0 and the game window never got a preview piece. Batching a row makes
a full redraw a few hundred bytes and `loops` reached 300+ between frames
2500 and 3200.
a full redraw a few hundred bytes and `loops` reached 650 between frames
2500 and 3200 (VR319 default).
## Timing and keys
@@ -82,7 +87,7 @@ which draws a bogus piece over the top row (blank border plus stray `X` tiles).
## Reproduce
```sh
cd /home/arti/.local/share/opencode/worktree/26e92e/termtris
apps/termtris/verify.sh # the whole acceptance run
apps/termtris/tests/play.sh # load, click, snapshot
apps/termtris/tests/play_keys.sh # move / panels / quit
apps/termtris/run.sh # interactive MAME session
@@ -93,16 +98,22 @@ The run is `VT1200_SKIP_LEVEL1=1 LOADER_AT=2500` with the loader payload at bit
`dwt/loader/build/loader.bin`, which places the sections and calls
`create_process`.
Last full acceptance run:
Last full acceptance run — MAME 0.289 built from this tree's driver at the
**VR319 default** (1280×1024 active), which is the real unit's monitor. The
earlier figures in this report were VR150 (1024×864):
```
move DIAG: loops=354 events=18 focus=00400001 quit=0
panels DIAG: loops=346 events=12 focus=00400001 quit=0
quit DIAG: loops=300 events=10 focus=00400001 quit=1
move DIAG: loops=650 events=18 last=3 focus=00400001 rev=0 quit=0
panels DIAG: loops=648 events=12 last=3 focus=00400001 rev=0 quit=0
quit DIAG: loops=555 events=10 last=3 focus=00400001 rev=0 quit=1
```
`focus=00400001` is the termtris window, and `quit=1` is the game's global after
`q` — so the keys reached the game, not just the window.
`focus=00400001` is the termtris window, sampled on the click's `ButtonRelease`;
`quit=1` is the game's global after `q`, and that is the proof the key reached
the game, not just the window. The event counts and
the `tick=887` are unchanged from the VR150 run; only the loop counts moved,
because the VR319 raster changes the emulated frame rate. The evidence PNGs
were regenerated in this run and are now 1280×1024.
| evidence | file |
|---|---|
File diff suppressed because it is too large. Load diff
+127
View File
@@ -0,0 +1,127 @@
# TMS34010 toolchain on non-DOS hosts
Investigated 2026-10-30. Short answer:
* TI **did** ship the TMS34010/TMS34020 C compiler and code-generation
tools for **VAX/VMS, VAX/Ultrix, VAX System V, Apollo Domain/IX and
AEGIS, Sun-3, Sun-4/SunOS and Macintosh/MPW** — not just MS-DOS/OS/2.
* **No public dump of those host versions is known.** Public archives
(bitsavers, archive.org, the `tms34010guy` SDK mirror, Macintosh
Garden/Repository) contain the **DOS** and **OS/2** binaries and the
manuals that describe the other hosts, but not the Sun/VMS/Apollo/Mac
tapes or diskettes.
* The only non-DOS binaries actually in hand are the **1990 OS/2 r5.01**
tools already in `tools/tms34010-sdk/` (NE executables; see
`reference/tms34010-sdk.md`).
So: the ports existed and are documented; the media appear to be lost
from public view, though private tapes are known to exist (see Leads).
## 1. Hosts TI supported
Evidence is from the installation chapters and the tools overview of the
two C compiler manuals, plus the 1990 Third-Party Guide's description of
Code Generation Tools r4.00.
| host | evidence | distribution medium |
|---|---|---|
| IBM-PC / TI-PC, PC/MS-DOS | 1986 guide §2.1; 1988 guide §2.1 | 5.25" diskettes |
| VAX/VMS | 1986 guide §2.2; 1988 guide §2.2 | 1600 bpi VMS BACKUP tape, volume `gspc`, save set `gspc.bck`, plus `setup.com` |
| VAX/Ultrix, VAX/UNIX System V | 1986 guide §2.3; 1988 guide §2.3 | 1600 bpi `tar` tape (`tar vx`), tools `gspcpp`, `gspcc`, `gspcg` |
| Apollo Domain/IX, Apollo AEGIS | 1988 guide §1/§2.3 | same `tar` tape (must install under Domain/IX, run under AEGIS) |
| Sun-3 (SunOS) | 1988 guide §1/§2.3 | same `tar` tape |
| Sun-4/SunOS | 1990 Third-Party Guide, TI Code Generation Tools r4.00 | not stated |
| Macintosh/MPW | 1988 guide §2.4 | 800K 3.5" diskette with `Tools/`, `Includes/`, `Libraries/` |
| OS/2 1.x | 1990 r5.01 NE binaries (in hand) | 5.25"/3.5" diskettes |
The 1988 guide's own list (p. 1-3) is: PC-DOS, TI-PC MS-DOS, VAX/VMS,
VAX/Ultrix, Apollo Domain/IX, Apollo AEGIS, Sun-3 Unix, Macintosh/MPW.
The 1990 Third-Party Guide (p. 29) says r4.00 is available for
"PC/MS-DOS, VAX/VMS, VAX/ULTRIX, SUN-3 and SUN-4/O.S, Macintosh/MPW and
Apollo/UNEX System V."
## 2. How to recognise a surviving copy
These strings/names are distinctive enough to search an old tape or disk
image for:
* `testc34.c`, `testc34.cmp`, `testc34.asm` — the compiler self-test
shipped on every C compiler tape/diskette.
* `gspc.bck` and `setup.com` — VMS BACKUP save set and symbol setup
command file. The VMS tape was made on VMS 4.5, 1600 bpi.
* `gspcpp`, `gspcc`, `gspcg`, `gspa`, `gsplnk`, `gspar`, `gsprom` —
UNIX spellings have no extension; VMS versions are `*.exe`.
* `Tools/`, `Includes/`, `Libraries/` folders on an 800K Mac diskette.
## 3. What is actually preserved
| item | where | notes |
|---|---|---|
| 1985 DOS assembly package v1.04 | `tools/tms34010-sdk/1987-05 TMS34010 SDK/` | DOS disk images |
| 1987 DOS Simulator/C/ASM tools v2.00 | same | DOS disk image; the set used for the byte-exact round trip |
| 1990 OS/2 Code Generation Tools r5.01 | `tools/tms34010-sdk/1990-11 TMS340 Family SDK/` | NE/OS2 binaries; **the only preserved non-DOS build** |
| 1990 OS/2 debugger r5.00, graphics library, TIGA SDK | same | DOS-hosted except the code-gen tools |
| 1990 DOS floppy images (`TMS340_Compiler.zip`) | bitsavers / archive.org | DOS, duplicate of the above lineage |
| 1986 C Compiler User's Guide | this directory | covers DOS, VAX/VMS, VAX/Ultrix, VAX System V |
| 1988 C Compiler Reference Guide | this directory | covers the full host list incl. Apollo, Sun-3, Mac/MPW |
| 1990 Third-Party Guide (4th ed.) | this directory | confirms r4.00 host list; third-party compilers |
| SPVS002C production-data datasheet | this directory | scanned; part-number/tools catalogue pages |
| GCC/G++ 2.5.8 TMS34010 port (1994) | `tools/tms34010-gcc-akpm/` | compiler source; `build-cc1.sh` rebuilds a working `cc1` on 32-bit Linux; Morton's `as34`/`ld34` are ported separately in `tools/as34/` |
| ported `as34`/`ld34`/`dis34` | `tools/as34/` | 64-bit Linux port of Morton's binutils, with byte-exact test against the GSPA payload |
`farnell.txt` is empty because that PDF is image-only (no text layer);
`ref1986.txt` and `ref1988.txt` are OCR text from archive.org;
`thirdparty1990.txt` is extracted from the PDF.
## 4. Third-party compilers that ran on those hosts
The 1990 Third-Party Guide is useful if a TI-hosted build never turns up:
* **Unidot, Inc.** — TMS34010 C compiler and assembler/linker/archiver.
Available **in source form for MS-DOS, DEC VAX under VMS, and most Unix
systems**; binary form only for MS-DOS. (p. 209)
* **GLH Ltd.** — GCC-based 340 compilers for Unix workstations. (p. 82)
* **Signature Software MC34010** — macro assembler, linker and job
controller for the **Apple Macintosh** (not a C compiler). (p. 208)
* **Andrew Morton's GCC/G++ 2.5.8 port (1994)** — not a commercial
product, but a real Unix-hosted GCC target for the TMS34010. The
compiler source is saved in `tools/tms34010-gcc-akpm/`, where
`build-cc1.sh` now rebuilds a working `cc1` on modern 32-bit Linux;
Morton's `as34` assembler, `ld34` linker and `dis34` disassembler are
ported and tested in `tools/as34/`.
## 5. Leads and dead ends
* **Best lead:** a `test-drb`/cctalk post titled "Wanted: TI TMS340x0
development system" reports someone holding a **QIC60/QIC150 tape of
the TI 34010 development software for SunOS** (not Solaris), remembered
to include the C compiler. The list archive is private, so this is a
person-to-person lead, not a download.
* `tms34020.uav.nl` and the archived uav.nl asset tree host the manuals
only; `TMS340_Compiler.zip`/`TMS340_Compiler_unpacked.zip` on bitsavers
are 1990 **DOS** floppy images.
* archive.org full-text/software search returns **0** TMS340 software
items; the TMS340 items are all manuals.
* The `tms34010guy/tms34010-sdk` GitHub tree contains only DOS images and
the 1990 OS/2 zips (verified against the full git tree).
* Macintosh Garden / Macintosh Repository searches for TMS340/TIGA find
nothing relevant.
* bitsavers' `/bits/TI/` tree has no TMS340 software, only 990/Explorer.
Absence of a public dump is not proof that none survives: these were
low-volume OEM tapes, and the manuals above are the best identification
guide for anyone who finds one.
## 6. Sources
* 1986 TMS34010 C Compiler User's Guide (SPVU005):
<https://archive.org/details/bitsavers_tiTMS340xxilerUsersGuide_4615125>
* 1988 TMS34010 C Compiler Reference Guide (SPVU005A):
<https://archive.org/details/bitsavers_tiTMS340xxferenceGuide1988_4803971>
(also <https://uav.nl/assets/tms34020/TMS34010_C_Compiler_Reference_Guide_1988.pdf>)
* 1990 TMS340 Third-Party Guide, 4th ed.:
<https://kguttag.com/wp-content/uploads/2023/07/1990-340-Family-THIRD-PARTY-GUIDE-4th-edition.pdf>
* SPVS002C production data (Farnell mirror):
<https://www.farnell.com/datasheets/84292.pdf>
* bitsavers TMS340xx tree:
<https://www.mirrorservice.org/sites/www.bitsavers.org/components/ti/TMS340xx/>
+7
View File
@@ -0,0 +1,7 @@
6e68ca635dc4a890aebfa8c2a8c10f4388b879a1df3455cb6797a1423de34d69 1986_TI_TMS34010_C_Compiler_Users_Guide.pdf
78357c3c9a861a0d19425c3936886dbd62759894a8d7ee1485e03bbe5b2f9e5e 1990_TMS340_Third_Party_Guide_4th.pdf
d760ab2e9192b5b9886a6c9ec2f2163d508796be1fd3153a40c9fee2c015ec41 SPVS002C_TMS34010_production_data.pdf
bf9a9b912044e11184cecaacddedd24e6f2e48365a8be56fb3989d0842bae8a9 TMS34010_C_Compiler_Reference_Guide_1988.pdf
85cd0bd51ebd0eef9d7407b763b9df911fbfe71ae90a465f6c84f110d7c6c160 ref1986.txt
6f9182f27033ada8752885d1a2f5ea833268e9aeb239355e9366f6988fa1841d ref1988.txt
1b3712f6c8af65c64fd8b1bb41fbf5b393d78dce5c36006abb4e37eed5d952a5 thirdparty1990.txt
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+4 -2
View File
@@ -12,8 +12,10 @@ Investigated 2026-10-18. Short version:
DOSBox; using them would need an OS/2 environment. The 1987 DOS tools are the
usable set.
* There is **no `as34` / `lnk34`** in this SDK. The assembler is `GSPA.EXE` and
the linker `GSPLNK.EXE` (the names `smart34010`'s README mentions are from a
later TI package). GSPA 2.00 is enough for the round trip.
the linker `GSPLNK.EXE`. (The `as34`/`ld34` names belong to Andrew Morton's
1994 GNU TMS34010 toolchain; this project ports them in `tools/as34/`.
A later TI devkit may have bundled them, but they are not part of this
package.) GSPA 2.00 is enough for the round trip.
* The C compiler works and links with `rts.lib` into an absolute COFF image.
It is **K&R C, not ANSI**: `int f(int a)` is a syntax error, `int f(a) int a;`
works.
+1
View File
@@ -0,0 +1 @@
build/
+150
View File
@@ -0,0 +1,150 @@
# Andrew Morton's GCC 2.5.8 TMS34010 compiler (1994)
The **compiler half** of Andrew Morton's Unix-hosted TMS34010 toolchain,
recovered from `http://www.zip.com.au/~akpm/gsptools.html` via the Wayback
Machine (snapshot `20080210052433`).
This is **not** TI's compiler. It is a real GCC/G++ 2.5.8 port to the
TMS34010, and the only saved non-DOS TMS34010 C compiler found so far.
## Files
| file | contents |
|---|---|
| `gspcc-2.5.8-tms34010.tar.gz` | GNU C/C++ 2.5.8 source with the TMS34010 port: `34010.h`, `tm.h`, `md`, `dm.c`, `akpm.c`, `akpmflags.c` |
| `cc1-port.patch` | the source fixes needed to build `cc1` with a modern 32-bit host GCC |
| `build-cc1.sh` | extract + patch + build `gcc34` (`cc1`) |
| `test-cc1.sh` | compile a C sample, assemble/link with `tools/as34`, disassemble |
The original was an uncompressed tar with a `.tar.gz` name; it is gzipped
here. The SHA-256 is in `SHA256SUMS`.
## The other half is already in this repo
Morton's **`as34` assembler, `ld34` linker and `dis34` disassembler** are
already ported to 64-bit Linux, patched for modern C/flex, and tested in
`tools/as34/`. That directory's `build.sh` fetches the companion
`gsp.tar.gz` (SHA-256 `efff8e59…f9ef46`) and applies `as34-port.patch`.
That same `gsp.tar.gz` also contains the compiler's runtime and a working
example, extracted by `build.sh` to `tools/as34/build/src/gsp/`:
* `lib/crt0.g` — C startup (sets `SP`, `CONTROL`, calls `_crtInit`/`_main`)
* `lib/libc`, `lib/libg`, `lib/libk` — C/C++ runtime and graphics/kernel libs
* `rom/rommain.cc` → `rom/rommain.g` → `rom/rrom.H00`/`rrom.L00` — the proof
build (see below)
* `app/`, `tests/`, `rom/`
So this directory only vendors the missing compiler source.
## Building cc1 on a modern host (verified)
`build-cc1.sh` rebuilds the compiler proper (`gcc34` = `cc1`) from the
tarball with the 32-bit host compiler:
```sh
tools/tms34010-gcc-akpm/build-cc1.sh
# -> build/src/gspcc/gcc34
```
Verified on Debian 12 / GCC 14.2.0: the result is a 32-bit x86 ELF
(`gcc34: ELF 32-bit LSB pie executable ... for GNU/Linux 3.2.0`) and
reports `GNU C version 2.5.8 (TMS34010)`.
`test-cc1.sh` compiles a three-function C sample, assembles it with the
ported `tools/as34`, links with `ld34`, extracts the text and disassembles
it:
```
PASS: cc1 -> as34 -> ld34 -> 78 bytes
8defc28ed0f90c2797f5d1d2fed0ebe2 sample.bin
```
The resulting code is real TMS34010 (register-argument ABI, `a14`/`fp`
frame, `rets`, recursive `callr` + `mpys`).
### What had to be fixed
| issue | root cause | fix |
|---|---|---|
| `No rule to make target 'cc1'` | GNU make prefers Morton's lower-case `makefile`, which has different targets | use `make -f makefile gcc34` |
| `TARGET_REGPARM undeclared` | `34010.h` has a broken `#ifndef AKPM_REGPARM` branch | build with Morton's own defines, especially `-DAKPM_REGPARM -DAKPM_RETS` (his `makefile` already has them) |
| `MAX_RECOG_OPERANDS undeclared` | first failed build left an empty `insn-config.h`; make then thought it was up to date | always start from a fresh extract (or `make clean`) |
| `genconfig: not found` | 1990s shell found programs in `.`; modern shells do not | `PATH="$PWD:$PATH"` |
| `gvarargs.h`: expected specifiers before `...` | the old `va_dcl`/`__builtin_va_alist` GCC extension is gone | modern shim in `gvarargs.h`: `va_alist` → `...`, `va_start` → `__builtin_va_start(ap, 0)` |
| `conflicting types for 'build'/'gen_rtx'/...` | old-style `f ()` declaration vs new `f (...)` definition | declare the varargs functions as `(...)` in `tree.h`, `expr.h`, `rtl.h`, `output.h`, `combine.c`, `genattrtab.c` |
| host byte order | archived `config.h` is for big-endian Sun-3 | comment out `HOST_WORDS_BIG_ENDIAN` and build 32-bit (`-m32`) |
| modern compiler defaults | old GCC source is K&R C with tentative definitions | `-std=gnu89 -fcommon` |
The patch is `cc1-port.patch`; it is applied to a fresh tarball by
`build-cc1.sh`. It does not depend on the configure-generated `Makefile`.
### Current limits
* `gcc34` is **cc1 only**. It has no driver and no preprocessor: it accepts
preprocessed input, or simple C with no directives. For real sources run
the host `cpp -P` first, or build GCC 2.5.8's `cccp`/driver separately.
* `cc1plus` (`g++34`) is not built here. The first blocker is the old
`obstack.h` `obstack_ptr_grow` macro (`lvalue required as increment
operand` in `cp-decl.c` on GCC 14), plus the same varargs/prototype
treatment; the C++ front end was not pursued.
* Output is Morton `.g` assembly → fixed `as34`/`ld34`, not TI COFF.
* Morton's register-argument ABI is enabled (`-DAKPM_REGPARM`); this
matches the archived `rommain.g` and the prebuilt runtime.
* The host build is 32-bit; `gcc -m32` and 32-bit libc are required.
## Does it produce real binaries?
Yes — the example artifacts in `tools/as34/build/src/gsp/rom/` show the full
pipeline:
* `rommain.cc` is a substantial C++ program (SCC serial setup, timers,
latches, C++ classes; mangled names such as `_flash__Fi`).
* `rommain.g` is the GCC-generated TMS34010 assembly, with `.stabs`,
prologues/epilogues, `calla`, `mmtm`, `rets`.
* `rrom.H00` + `rrom.L00` are the final 32 KB high/low EPROM pair (64 KB of
code+data). Interleaving them and running
`tools/smart34010/dis34 -E rrom.L00 rrom.H00` gives valid code: reset
vector, `setf 16,1,0` / `setf 32,0,1`, `CONTROL` setup, `calla` calls —
matching `lib/crt0.g`.
* The ROM contains compiled `rommain.cc` logic: `movk 3,a0` /
`movi 0xc1,a1` / `call a4` is `WR(3, BM_BITS(11000001))` from
`initSCC()`, and strings such as `%x is circular`, `hello, world` and
`jumping to 0x%x` appear in the image.
Caveats:
* It does **not** emit TI COFF. `as34`/`ld34` use Morton's own link format
(`LINKMAGIC 0x3abf782e`, bit-address flag); `romsplit` turns that into
EPROM high/low files. `ld34/coff.c` is dead code.
* The runtime is for Morton's GSP board: `crt0.g` sets `SP=0xfffffb00`,
programs `CONTROL`, calls `_crtInit` then `_main`. A VT1200 port needs its
own startup and memory layout.
* The archived `config.h` is for a **big-endian Sun-3/m68k host**
(`HOST_WORDS_BIG_ENDIAN`), and the tarball contains no prebuilt `cc1` or
`gcc34`. `build-cc1.sh` now rebuilds `cc1` on 32-bit Linux using
`cc1-port.patch`; see “Building cc1 on a modern host” above.
* TMS34010 only, not TMS34020.
## What Morton changed in GCC
From his own notes:
* GCC assumes a byte is the smallest addressable unit. On the GSP a pointer
is a **bit** address, so every pointer addend must be multiplied by eight.
He patched the places where GCC assumes
`(int)(ptr + i) == (int)ptr + i`; grep the tree for `AKPM`, `34010` and
`GSP` to find them.
* The compiler assumes **FS0 = 5** (32-bit accesses) and **FS1 = 4**
(16-bit accesses); `crt0.g` sets the corresponding `setf` values.
* He added an `interrupt` function qualifier that saves all machine state
so a vector can point directly at the C function.
* The port shares the m68k configuration skeleton; `34010.h` started from
the Sun 68000/68020 header, and `tm.h` still carries m68k-era `ASM_SPEC`
text that a modern driver would need to replace.
## Licence
The GNU parts are GPLv2 (see `gspcc/COPYING`). Morton's own additions carry
no explicit licence header; treat the archive as historical reference
material.
+1
View File
@@ -0,0 +1 @@
f7c847064cc9c686f77e1f4c8f5a8c0f646b5172862f7c8308b7c8e3fa8a9fe8 gspcc-2.5.8-tms34010.tar.gz
+46
View File
@@ -0,0 +1,46 @@
#!/bin/sh
# Build Morton's GCC 2.5.8 TMS34010 cc1 (gcc34) on a modern x86-64 host.
#
# tools/tms34010-gcc-akpm/build-cc1.sh
# CC1_BUILD_DIR=/tmp/cc1 JOBS=4 tools/tms34010-gcc-akpm/build-cc1.sh
#
# Requires a 32-bit host compiler (gcc -m32) and its libc. The result is
# src/gspcc/gcc34 — the compiler proper (cc1), not a driver or preprocessor.
set -eu
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
builddir=${CC1_BUILD_DIR:-"$here/build"}
tarball="$here/gspcc-2.5.8-tms34010.tar.gz"
sha=f7c847064cc9c686f77e1f4c8f5a8c0f646b5172862f7c8308b7c8e3fa8a9fe8
hostcc=${HOST_CC:-gcc}
echo "$sha $tarball" | sha256sum -c -
mkdir -p "$builddir"
if ! printf 'int main(void){return 0;}\n' | "$hostcc" -m32 -x c - -o "$builddir/probe" 2>/dev/null; then
echo "error: $hostcc cannot build 32-bit binaries (-m32)" >&2
echo "install the 32-bit libc/headers (e.g. gcc-multilib on Debian)" >&2
exit 1
fi
rm -rf "$builddir/src"
mkdir -p "$builddir/src"
tar xzf "$tarball" -C "$builddir/src"
cd "$builddir/src/gspcc"
patch -p1 < "$here/cc1-port.patch"
# Keep Morton's 1993 pre-generated parsers; modern bison would regenerate them.
for f in c-parse.c c-parse.h cp-parse.c; do
[ -e "$f" ] && touch "$f"
done
export PATH="$PWD:$PATH"
make -f makefile -j"${JOBS:-1}" gcc34 \
CC="$hostcc -m32 -std=gnu89 -fcommon -O0 -g" \
XCFLAGS="-w -fno-strict-aliasing"
echo
echo "built: $PWD/gcc34"
file "$PWD/gcc34" || true
"$PWD/gcc34" -version 2>&1 | head -1 || true
+112
View File
@@ -0,0 +1,112 @@
--- a/config.h
+++ b/config.h
@@ -33,7 +33,7 @@
#define HOST_BITS_PER_LONG 32
#define HOST_BITS_PER_LONGLONG 64
-#define HOST_WORDS_BIG_ENDIAN
+/* #undef HOST_WORDS_BIG_ENDIAN (x86 host) */
/* target machine dependencies.
tm.h is a symbolic link to the actual target specific file. */
--- a/gvarargs.h
+++ b/gvarargs.h
@@ -1,3 +1,18 @@
+/* Modern-GCC shim: the 1990s va_dcl / __builtin_va_alist extension is gone.
+ All uses in this tree are "f (va_alist) va_dcl" with no named parameter,
+ so map them to a C99 variadic function and use the builtins. */
+#if defined(__GNUC__) && __GNUC__ >= 3
+#ifndef _VARARGS_H
+#define _VARARGS_H
+#define va_alist ...
+#define va_dcl
+#define va_list __builtin_va_list
+#define __gnuc_va_list __builtin_va_list
+#define va_start(AP) __builtin_va_start(AP, 0)
+#define va_end(AP) __builtin_va_end(AP)
+#define va_arg(AP, TYPE) __builtin_va_arg(AP, TYPE)
+#endif
+#else
#ifndef __GNUC__
/* Use the system's macros with the system's compiler. */
#include <varargs.h>
@@ -174,3 +189,5 @@
#endif
#endif /* __GNUC__ */
+
+#endif /* modern GCC shim */
--- a/genattrtab.c
+++ b/genattrtab.c
@@ -359,7 +359,7 @@
static rtx attr_rtx PROTO((enum rtx_code, ...));
static char *attr_printf PROTO((int, char *, ...));
#else
-static rtx attr_rtx ();
+static rtx attr_rtx (...);
static char *attr_printf ();
#endif
--- a/tree.h
+++ b/tree.h
@@ -1066,9 +1066,9 @@
extern tree build_nt PROTO((enum tree_code, ...));
extern tree build_parse_node PROTO((enum tree_code, ...));
#else
-extern tree build ();
-extern tree build_nt ();
-extern tree build_parse_node ();
+extern tree build (...);
+extern tree build_nt (...);
+extern tree build_parse_node (...);
#endif
extern tree build_int_2_wide PROTO((HOST_WIDE_INT, HOST_WIDE_INT));
--- a/expr.h
+++ b/expr.h
@@ -625,8 +625,8 @@
/* Emit library call. These cannot have accurate prototypes since they have
a variable number of args. */
-extern void emit_library_call ();
-extern rtx emit_library_call_value ();
+extern void emit_library_call (...);
+extern rtx emit_library_call_value (...);
/* Expand an assignment that stores the value of FROM into TO. */
extern rtx expand_assignment PROTO((tree, tree, int, int));
--- a/rtl.h
+++ b/rtl.h
@@ -653,8 +653,8 @@
#else
extern rtx bc_gen_rtx ();
-extern rtx gen_rtx ();
-extern rtvec gen_rtvec ();
+extern rtx gen_rtx (...);
+extern rtvec gen_rtvec (...);
#endif
#ifdef BUFSIZ /* stdio.h has been included */
--- a/output.h
+++ b/output.h
@@ -32,7 +32,7 @@
/* Output a string of assembler code, substituting numbers, strings
and fixed syntactic prefixes. */
-extern void asm_fprintf ();
+extern void asm_fprintf (...);
/* Print an integer constant expression in assembler syntax.
Addition and subtraction are the only arithmetic
--- a/combine.c
+++ b/combine.c
@@ -391,7 +391,7 @@
rtx, int));
static int recog_for_combine PROTO((rtx *, rtx, rtx *));
static rtx gen_lowpart_for_combine PROTO((enum machine_mode, rtx));
-static rtx gen_rtx_combine (); /* This is varargs. */
+static rtx gen_rtx_combine (...); /* This is varargs. */
static rtx gen_binary PROTO((enum rtx_code, enum machine_mode,
rtx, rtx));
static rtx gen_unary PROTO((enum rtx_code, enum machine_mode, rtx));
Binary file not shown.
+57
View File
@@ -0,0 +1,57 @@
#!/bin/sh
# Smoke-test the rebuilt cc1: C -> TMS34010 assembly -> as34 -> ld34 -> raw
# binary -> dis34.
#
# tools/tms34010-gcc-akpm/test-cc1.sh
#
# Requires tools/as34 to have been built (tools/as34/build.sh).
set -eu
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
builddir=${CC1_BUILD_DIR:-"$here/build"}
cc1="$builddir/src/gspcc/gcc34"
as34=${AS34:-"$here/../as34/build/src/gsp/binutils/as34/as34"}
ld34=${LD34:-"$here/../as34/build/src/gsp/binutils/ld34/ld34"}
extract="$here/../as34/extract.py"
dis34="$here/../smart34010/dis34"
for f in "$cc1" "$as34" "$ld34" "$extract" "$dis34"; do
[ -e "$f" ] || { echo "missing $f" >&2; exit 1; }
done
work="$builddir/work-cc1"
rm -rf "$work"
mkdir -p "$work"
cd "$work"
cat > sample.c <<'EOF'
int add(int a, int b) { return a + b; }
int sum(int *p, int n)
{
int s = 0;
while (n--)
s += *p++;
return s;
}
int fact(int n) { return n < 2 ? 1 : n * fact(n - 1); }
EOF
"$cc1" -quiet -O -o sample.g sample.c
"$as34" sample.g
"$ld34" -c -T 1800000 -e_add sample.go -o sample.out -m sample.map
python3 "$extract" sample.out sample.bin
"$dis34" -l sample.bin > sample.dis
if ! grep -Eq 'add[[:space:]]+a1, a0' sample.dis; then
echo "FAIL: expected 'add a1,a0' in add()" >&2
cat sample.dis >&2
exit 1
fi
if ! grep -Eq 'mpys' sample.dis; then
echo "FAIL: expected 'mpys' in fact()" >&2
exit 1
fi
echo "PASS: cc1 -> as34 -> ld34 -> $(wc -c < sample.bin) bytes"
md5sum sample.bin
echo "disassembly: $work/sample.dis"
+30 -14
View File
@@ -8,10 +8,11 @@ the patched fork of [2ine](https://github.com/icculus/2ine) at
Unlike the assembler-only state documented when the fork was first published,
the **full C pipeline works**: front end, optimizer, code generator,
assembler, linker and converter. `gspcl` (the one-command driver) still does
not chain its children reliably; drive the four C stages explicitly.
assembler, linker and converter. `gspcl` (the one-command driver) chains the
first four; `-z` adds the link.
Verified 2026-11-01 on x86_64 Arch, against the VT1200 firmware image.
Verified 2026-11-01 on x86_64 Arch, against the VT1200 firmware image; the C
pipeline and `gspcl` re-verified 2026-11-16.
| tool | result |
|---|---|
@@ -22,15 +23,16 @@ Verified 2026-11-01 on x86_64 Arch, against the VT1200 firmware image.
| `gsplnk` (linker) | **works** — absolute placement; `rts.lib` + `flib.lib` |
| `gsprom` (COFF → Tek-hex) | **works** — plain and `-i` EPROM pair |
| `gspar` (archiver) | **works** — lists `rts.lib` members |
| `gspcl` (driver) | **partial** — runs `gspac`, then stops (see §7) |
| `gspcl` (driver) | **works** — chains the compile, optimize, codegen and assemble stages; `-z` adds the link (see §7) |
---
## 1. Build 2ine
The fork's `main` carries the three fixes this needs: the null-selector
mapping (commit `91b78f2`), Arch/CMake-4 ncurses discovery (`a440128`), and
this document's status update (`3bcdfc3`).
The fork's `main` carries the fixes this needs: the null-selector mapping
(commit `91b78f2`), Arch/CMake-4 ncurses discovery (`a440128`), the 16-bit
stack-unmap guard (`cad0c71`), and the fork's `TMS34010.md` status update
(`3bcdfc3`).
Dependencies (Arch):
@@ -191,15 +193,29 @@ register. The 5.01 object is therefore functionally identical to the ROM, but
not byte-identical at that instruction. This is the one exception to the
otherwise one-way assembler compatibility noted in `OS2-501.md`.
## 7. `gspcl` and the exit-status trap
## 7. `gspcl`
`gspcl` finds `gspac` and runs it, then stops without invoking `gspopt` /
`gspcg` / `gspa`. The individual tools frequently exit non-zero after
successful work: `gspac` and `gspcg` return **139** (segfault during teardown),
`gsprom` can return 1. `gspcl` treats the child status as failure.
`gspcl` drives the compile, optimize, codegen and assemble stages (`$LX` as in
§4):
**Check for output files, not exit codes.** The manual pipeline in §4 produces
correct objects and images; the one-command driver does not yet.
```sh
$LX ./gspcl.exe -k -o2 -c HELLO.C
```
`-c` stops before linking and `-k` keeps the assembly, so success leaves
`hello.obj` and `hello.asm` (the tools write lowercase names). `-z` starts the
link, and everything after it is a linker option, so the libraries follow:
```sh
$LX ./gspcl.exe -k -o2 HELLO.C -z -o hello.out rts.lib flib.lib
```
Or run the stages explicitly as in §4.
In the verified runs the driver and the tools exit **0** on success and **1**
for a genuine error such as a missing input or an unwritable output. The loader
keeps only the low 8 bits of an OS/2 exit code (`lxTerminate`), so read a
nonzero status as "inspect the output" rather than as a precise error code.
## 8. What the null-selector fix was
+13 -10
View File
@@ -73,7 +73,7 @@ under real OS/2.
### 2.1 OS/2 1.3 under 86Box — the full toolchain (compile, link, convert)
This is the only route that runs **`gspcl`** today.
This route runs the full toolchain, including **`gspcl`**.
Media: the preinstalled image on archive.org, item `Os21.3VirtualHardDisk`,
file `MicrosoftOs-21.30HardDisk.vhd` (a Virtual-PC dynamic VHD, 500 MiB
@@ -126,13 +126,17 @@ unreliable. Type only letters (name your batch `CG.CMD`, `BK.CMD`, …) one
character at a time, and have the batch print a unique end token so the host
can detect completion by OCR (or just wait and take a screenshot).
### 2.2 2ine — assembler/linker/converter natively, no VM
### 2.2 2ine — the whole toolchain natively, no VM
`gspa`, `gsplnk` and `gsprom` run under
[2ine](https://github.com/icculus/2ine) with a small patch series; the patched
fork lives at **<https://git.wut.ee/opencode.energia.arti.ee/2ine-tms34010>**
(see its `TMS34010.md`). Build it 32-bit (`cmake -S . -B build && cmake --build
build -j2`, needs `gcc-multilib`, `libc6-dev-i386`, `libncurses-dev:i386`).
The whole toolchain runs under
[2ine](https://github.com/icculus/2ine) with a small patch series: the
assembler, linker and converter, and the C front end, optimizer, code
generator and driver. The patched fork lives at
**<https://git.wut.ee/opencode.energia.arti.ee/2ine-tms34010>** (see its
`TMS34010.md`). Build it 32-bit (`cmake -S . -B build
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 && cmake --build build -j2`, needs
`gcc-multilib`, `libc6-dev-i386`, `libncurses-dev:i386`; the policy floor is
for CMake 4.x).
```sh
cd 2ine/build # lx_loader dlopen()s ./lib<module>.so, so cwd matters
@@ -143,9 +147,8 @@ cd 2ine/build # lx_loader dlopen()s ./lib<module>.so, so cwd matters
```
The C pipeline **does** work under the patched fork: a null-selector fix in
`lx_loader.c` unblocks `gspac`, `gspopt` and `gspcg`. `gspcl` itself still
stops after `gspac` because the children exit non-zero at teardown, so drive
the stages explicitly. See `2INE-501.md` for the full end-to-end flow.
`lx_loader.c` unblocks `gspac`, `gspopt` and `gspcg`, and `gspcl` chains the
stages. See `2INE-501.md` for the full end-to-end flow.
---
+2 -1
View File
@@ -34,7 +34,8 @@ The **1987** toolchain runs headless in DOSBox: **GSPA 2.00** (assembler),
**GSPLNK 2.00** (linker), **GSPROM 2.01**, and the **K&R C compiler**.
**There is no `as34`/`lnk34`** — the assembler is `GSPA`. (`smart34010`'s README
names `as34`; that appears to be a later name or another part, not this SDK.)
names `as34`; this project ports Morton's 1994 `as34`/`ld34` in `tools/as34/`;
they are not part of this SDK.)
**The round trip is proven against this exact firmware**: 32 KB at bit
`0x3F208000` reassembles **byte-for-byte identical** (region md5