From a306575cdd19bba07e4f1ee6f53504ff6562e13e Mon Sep 17 00:00:00 2001 From: zxq5 Date: Thu, 16 Jul 2026 20:29:51 +0100 Subject: [PATCH] used AI to generate documentation. verified all documentation is correct and accurately represents the functionality of the emulator --- doc/ISA.md | 147 ----------- doc/reference/dsa-assembly-spec.md | 321 +++++++++++++++++++++++++ doc/reference/dsa-isa-spec.md | 261 ++++++++++++++++++++ doc/reference/dse-executable-spec.md | 166 +++++++++++++ dsa/common/src/isa/instructions/mod.rs | 3 +- dsx/README.md | 3 +- 6 files changed, 752 insertions(+), 149 deletions(-) delete mode 100644 doc/ISA.md create mode 100644 doc/reference/dsa-assembly-spec.md create mode 100644 doc/reference/dsa-isa-spec.md create mode 100644 doc/reference/dse-executable-spec.md diff --git a/doc/ISA.md b/doc/ISA.md deleted file mode 100644 index 93fb8c7..0000000 --- a/doc/ISA.md +++ /dev/null @@ -1,147 +0,0 @@ -## Architecture -32 bit instruction width/word size - -## Instruction Types: - -Type Sizes: - - u16: [16 bits] - - u6: [6 bits] - - Reg: [5 bits] - - Opcode: [6 bits] - -Instruction Types: - - R: [Opcode] [Reg] [Reg] [Reg] [Reg] [u6] - - I: [Opcode] [Reg] [Reg] [u16 ] - -## Instruction Set - -// move -mov [ unused ] -cmov - -// load -ldb -ldbs -ldh -ldhs -ldw - -// store -stb -sth -stw - -// immediate -lli [unused] -lui [unused] - -// comparison -ieq [unused] -ine [unused] -igt [unused] -ige [unused] -ilt [unused] -ile [unused] - -// Jump -jmp [ unused ] // unconditional - -jez // conditional on cmp == 0 -jnz - -jic [ unused ] // conditional on carry -jnc [ unused ] - -// Bitwise -and [unused] // and -nnd [unused] // nand -or [unused] // or -nor [unused] // nor -xor [unused] // xor -xnr [unused] // xnor -not [ unused ] [unused] // not - -// Arithmetic -add -sub -shl // left shift of rshamt+ishamt -shr // right shift - -// Immediate Arithmetic -addi -subi - -// Misc -nop (zero/do nothing) -int -irt -hlt - -// Atomic - -// Atomic Compare and Swap - compares src and dst, if src -acs - -## Assembler Pseudoinstructions -Definitions: - Label - named address, a function or global - -``` -lwi // loads the literal value of Label|Imm into dest - // if src is a Label, take literal value of Label - => lli $src, $dest - => lui $src, $dest -lli // loads the lower 16 bits of the literal value of Label into dest -... -> similarly defined for lui - -ldw // loads the word at the address of Label into dest -... => similarly defined for ldb, ldbs, ldh, ldhs - // load the label value of src into dest with lui/lli - => lli $src, $dest - => lui $src, $dest - => ldw $dest, $dest - -stw // stores the word in src using the address/label that is dest. - // load the literal value of dest into the accumulator with lui/lli - => lli $dest, acc - => lui $dest, acc - => stw $src, acc - -jmp - CASE dest > u16::MAX: - => lli $dest, acc - => lui $dest, acc - => jmp $dest, 0 - CASE dest < u16::MAX: - // assembler inserts the literal value of dest - => jmp $dest, 0 - -jmp - CASE lbl > u16::MAX: - AssemblerError! - CASE lbl < u16::MAX: - => jmp $dest, lbl - -call - => subi spr, 4, spr - => stw pcx, spr, 0 - => jmp $addr - -func - // push bpr - => subi spr, 4, spr - => stw bpr, spr, 0 - // replace bpr with spr - => mov spr, bpr - -return - => mov bpr, spr - // pop bpr - => addi spr, 4, spr - => ldw spr, bpr, 0 - // load return addr - => ldw spr, ret, 0 - => addi, spr, 4, spr - => jmp ret, 4 - -``` diff --git a/doc/reference/dsa-assembly-spec.md b/doc/reference/dsa-assembly-spec.md new file mode 100644 index 0000000..01421f3 --- /dev/null +++ b/doc/reference/dsa-assembly-spec.md @@ -0,0 +1,321 @@ +# DSA Assembly Language Specification + +**Status:** Draft, grounded in the current `assembler` crate (`model.rs`, `expand.rs`, `resolver.rs`, +`codegen.rs`) and the example programs `print.dsa`, `bf.dsa`, `animation.dsa`, `serial.dsa`. + +This describes the assembly language as the current pipeline actually implements it — pseudo-op +expansion, symbol resolution, and argument order all reflect the real `expand.rs`/`codegen.rs` logic, +not just the ISA's hardware semantics (see the companion ISA spec for those). + +--- + +## 1. Source File Structure + +A `.dsa` file is a sequence of directives, labels, and instructions. Comments start with `//` and run to end of line. + +```asm +include print "./print.dsa" // pulls in another module by relative path + +dw display: 0x20000 // data declaration with a label +db message: "hello\0" // string data + +start: // a label — marks the address of the next node + lli 0, rg0 + ... +``` + +### 1.1 Modules and `include` + +```asm +include "" +``` + +`` becomes the namespace prefix used to reference symbols from that file — e.g. `include print "./print.dsa"` lets you call `print::print`, `print::newline`, etc. Each included file is compiled once per program even if reached via multiple include paths (deduplicated by canonicalized file path). Symbols are disambiguated internally by a hash of the defining file's path, not by name alone — two files can each define a label called `start` without collision, as long as they're referenced through their respective module namespace. + +**Known limitation:** cross-module symbol references (`module::symbol`) resolve correctly today +because the current pipeline concatenates all included files' nodes into one list before running +symbol resolution — it is not yet a true separate-compilation linker. A planned `DsoBinary` +intermediate format (see the compiler roadmap if there is one available) will make per-file compilation independent of the whole program; until then, changing any included file requires reassembling the whole program. + +--- + +## 2. Data Declarations + +| Directive | Unit size | Meaning | +|-------------------------|------------------------------------|-------------------------------------------------| +| `db