summaryrefslogtreecommitdiff
path: root/sysroot/usr/src
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
committerkx <kx@radix-linux.su>2026-10-09 18:00:15 +0300
commit065da3509019b15dd0e678072e6be629e5330bef (patch)
tree69c934c9e786ac048b4fbe8f4c4c5571661521f4 /sysroot/usr/src
parentd130fe27fa753be02ed76fd9b277aa3c3d928eb9 (diff)
downloadlibmcpu-0.4.0.tar.xz
Version 0.4.00.4.0
Diffstat (limited to 'sysroot/usr/src')
-rw-r--r--sysroot/usr/src/mcpu/crt/crt0.S22
-rw-r--r--sysroot/usr/src/mcpu/crt/crt1.S58
-rw-r--r--sysroot/usr/src/mcpu/crt/crti.S67
-rw-r--r--sysroot/usr/src/mcpu/crt/crtn.S20
4 files changed, 167 insertions, 0 deletions
diff --git a/sysroot/usr/src/mcpu/crt/crt0.S b/sysroot/usr/src/mcpu/crt/crt0.S
new file mode 100644
index 0000000..47a0bc0
--- /dev/null
+++ b/sysroot/usr/src/mcpu/crt/crt0.S
@@ -0,0 +1,22 @@
+; MCPU HLL PROGRAM adapter.
+
+.global __mcpu_crt_startup
+.global main
+
+.text
+__mcpu_crt_hll_program:
+_start_life:
+ CALL __mcpu_crt_startup
+
+ ; Persistent McpuStartup is again at top-level SP after RET.
+ LDSP r64@0x7fe00, 8
+ LDSP r64@0x7fe08, 16
+
+ ; main(int64 argc, PTR64 argv)
+ ADJSP -16
+ STSP 0, r64@0x7fe00
+ STSP 8, r64@0x7fe08
+ CALL main
+ ADJSP 16
+
+ EXIT r32@0x7fffc
diff --git a/sysroot/usr/src/mcpu/crt/crt1.S b/sysroot/usr/src/mcpu/crt/crt1.S
new file mode 100644
index 0000000..34880e1
--- /dev/null
+++ b/sysroot/usr/src/mcpu/crt/crt1.S
@@ -0,0 +1,58 @@
+; MCPU HLL MODEL adapter.
+
+.global __mcpu_crt_startup
+.global init
+.global life
+
+.init
+__mcpu_crt_hll_model:
+_start:
+ CALL __mcpu_crt_startup
+
+ ; init(int64 argc, PTR64 argv)
+ LDSP r64@0x7fe00, 8
+ LDSP r64@0x7fe08, 16
+ ADJSP -16
+ STSP 0, r64@0x7fe00
+ STSP 8, r64@0x7fe08
+ CALL init
+ ADJSP 16
+
+ CLR r32@0x7fe10
+ ICMP r32@0x7fffc, r32@0x7fe10
+ JZ .L_init_ok
+ EXIT r32@0x7fffc
+
+.L_init_ok:
+ END
+
+.text
+_life:
+.L_life_loop:
+ CALL life
+
+ ; LIFE_CONTINUE == INT32_MIN == -2147483648.
+ LDI r32@0x7fe10, -2147483648
+ ICMP r32@0x7fffc, r32@0x7fe10
+ JZ .L_life_continue
+
+ CLR r32@0x7fe10
+ ICMP r32@0x7fffc, r32@0x7fe10
+ JZ .L_life_end
+ JS .L_life_reserved
+
+ ; Positive status is a MODEL error.
+ EXIT r32@0x7fffc
+
+.L_life_continue:
+ END
+ JMP .L_life_loop
+
+.L_life_end:
+ EXIT r32@0x7fffc
+
+.L_life_reserved:
+ ; Negative values other than INT32_MIN are reserved by ABI v1.
+ ; Current CRT maps programmer-contract violation to status 1.
+ LDI r32@0x7fe10, 1
+ EXIT r32@0x7fe10
diff --git a/sysroot/usr/src/mcpu/crt/crti.S b/sysroot/usr/src/mcpu/crt/crti.S
new file mode 100644
index 0000000..042a1b0
--- /dev/null
+++ b/sysroot/usr/src/mcpu/crt/crti.S
@@ -0,0 +1,67 @@
+; Common MCPU HLL startup support.
+;
+; This object is part of LibMCPU CRT. It validates McpuStartup, initializes
+; the target runtime hooks, and records whether normal HLL lifetime has begun.
+
+.global __mcpu_libc_init
+.global __mcpu_init_array
+.global __mcpu_crt_startup
+.global __mcpu_crt_state
+
+.data
+.align 8
+__mcpu_crt_state:
+ .integer 64, 0
+
+.text
+__mcpu_crt_startup:
+ ; CALL pushed one 8-byte return PC. McpuStartup therefore begins at
+ ; SP+8 while this helper is active.
+ CLR r64@0x7ff00
+ STORE __mcpu_crt_state, r64@0x7ff00
+
+ ; McpuStartup.version == 1.
+ LDSP r32@0x7ff08, 8
+ LDI r32@0x7ff0c, 1
+ ICMP r32@0x7ff08, r32@0x7ff0c
+ JNZ .L_startup_failure
+
+ ; McpuStartup.size == 32.
+ LDSP r32@0x7ff08, 12
+ LDI r32@0x7ff0c, 32
+ ICMP r32@0x7ff08, r32@0x7ff0c
+ JNZ .L_startup_failure
+
+ ; HLL argc is int64. Reject uint64 values with the sign bit set,
+ ; equivalently argc > 0x7fffffffffffffff.
+ LDSP r64@0x7ff10, 16
+ CLR r64@0x7ff18
+ ICMP r64@0x7ff10, r64@0x7ff18
+ JS .L_startup_failure
+
+ ; argv must be the canonical persistent array immediately following
+ ; the 32-byte McpuStartup structure.
+ LDSP r64@0x7ff20, 24
+ LEASP r64@0x7ff28, 40
+ ICMP r64@0x7ff20, r64@0x7ff28
+ JNZ .L_startup_failure
+
+ ; McpuStartup.reserved is zero in version 1.
+ LDSP r64@0x7ff30, 32
+ ICMP r64@0x7ff30, r64@0x7ff18
+ JNZ .L_startup_failure
+
+ CALL __mcpu_libc_init
+ CALL __mcpu_init_array
+
+ LDI r64@0x7ff00, 1
+ STORE __mcpu_crt_state, r64@0x7ff00
+ RET
+
+.L_startup_failure:
+ ; EXIT must happen with the top-level STACK state restored. Discard
+ ; this helper's return PC without RET, then terminate. _fini sees
+ ; PRE_RUNTIME state and therefore performs END only.
+ ADJSP 8
+ LDI r32@0x7ff38, 1
+ EXIT r32@0x7ff38
diff --git a/sysroot/usr/src/mcpu/crt/crtn.S b/sysroot/usr/src/mcpu/crt/crtn.S
new file mode 100644
index 0000000..aeed44c
--- /dev/null
+++ b/sysroot/usr/src/mcpu/crt/crtn.S
@@ -0,0 +1,20 @@
+; Common MCPU HLL finalization.
+
+.global __mcpu_crt_state
+.global fini
+.global __mcpu_fini_array
+.global __mcpu_libc_fini
+
+.fini
+_fini:
+ LOAD r64@0x7fd00, __mcpu_crt_state
+ LDI r64@0x7fd08, 1
+ ICMP r64@0x7fd00, r64@0x7fd08
+ JNZ .L_pre_runtime
+
+ CALL fini
+ CALL __mcpu_fini_array
+ CALL __mcpu_libc_fini
+
+.L_pre_runtime:
+ END