Files
LithosAnanke/v4/include/v4/asm.h
T
Claude 3bd81097e1 chore(license): an SPDX header on every source file that had none (LicenseRef-Starship-1.0) [skip ci]
The header scan (Captain Bob, 2026-11-10): 788 source files -- 351 with the
SL-1.0 header, 12 with the old name (docs/working/experiments, kept by
ruling), 31 under someone else's licence (tools/kconfig, Linux's, GPL-2.0:
kept), and 394 with none. Ruled: the SPDX form; capsules (.4th, .f18) and
proofs (.thy) left for a ruling of their own (mkcapsule's 64x16 block format,
content-addressed capsules).

253 files now begin
    SPDX-License-Identifier: LicenseRef-Starship-1.0
    Copyright (c) 2023-2026 Robert A. James
as a /* */ block (C, headers, assembly, linker scripts) or # lines (scripts,
Makefiles, Kconfig; below a shebang or a coding line); tools/mkcapsule.c,
which had the copyright line, gets the SPDX line only.

Not touched: docs/working/ (archive and old campaign material, as the
ruling kept the experiments); v4/system/post_cases.c (generated by
v4/tools/mkpost.py, "do not edit" -- the generator has the header).

Comments only: the kernel builds on amd64, aarch64, riscv64; make -C v4
test-32: 39 programs, 0 failures; every changed script parses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
2026-11-10 04:12:49 +00:00

72 lines
2.7 KiB
C

/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* asm.h -- slot packer for hand-assembled test programs.
*
* This is not the compiler capsule (JUSTIFICATION.md section 9). It exists so
* that tests can write a DECOMPOSITION.md definition opcode by opcode and have
* the slots, literals and branch targets laid out the way section 1.2 and
* section 2 require, instead of packing words by hand in every test.
*
* Layout rules it applies:
*
* - Opcodes fill slots 0..5 left to right; a full word is written out and a
* new one started. Unused slots are padded with `nop`.
* - A literal is `@p` in a slot plus its value in the word after the
* instruction word. Several literals in one word follow it in order.
* - `;` and `ex` close the word, since nothing after them executes.
* - A branch closes the word, since the bits to its right are its address.
* If the next free slot is 4 or 5 the word is closed first, because
* branches are legal in slots 0-3 only.
* - A branch target must lie in the same page as P at the time the branch
* executes, for the reach of the slot it landed in. Otherwise the
* assembler sets its error flag rather than emit a branch that goes
* somewhere else.
*/
#ifndef V4_ASM_H
#define V4_ASM_H
#include "v4/iword.h"
#include "v4/node.h"
typedef struct {
v4_node *n;
v4_cell here; /* address of the word being built */
v4_iword cur;
unsigned slot; /* next free slot, 0..V4_SLOT_COUNT */
v4_cell lit[V4_SLOT_COUNT]; /* literals owed after this word */
unsigned nlit;
int error;
} v4_asm;
/* A branch whose target is not known yet. */
typedef struct {
v4_cell addr; /* the word holding the branch */
unsigned slot;
v4_cell p; /* P when the branch executes */
} v4_asm_ref;
void v4_asm_begin(v4_asm *as, v4_node *n, v4_cell origin);
/* Any opcode that is neither a branch nor `@p`. */
void v4_asm_op(v4_asm *as, unsigned op);
/* `@p` and its value. */
void v4_asm_lit(v4_asm *as, v4_cell value);
/* jump, call, next, if, -if to a known address. */
void v4_asm_branch(v4_asm *as, unsigned op, v4_cell target);
/* The same with the target supplied later by v4_asm_resolve. */
v4_asm_ref v4_asm_branch_fwd(v4_asm *as, unsigned op);
void v4_asm_resolve(v4_asm *as, v4_asm_ref ref, v4_cell target);
/* Close the word being built and return the address of the next one. This is
* how a label is taken: branch targets are word addresses. */
v4_cell v4_asm_label(v4_asm *as);
/* 1 if nothing went wrong so far. Closes the word being built. */
int v4_asm_ok(v4_asm *as);
#endif /* V4_ASM_H */