Initial commit: Schunix as it stands before the SchOS rename

An x86-64 operating system built from xv6, now largely rewritten: SMP,
a copy-on-write root filesystem (SchFS), PCI/USB/virtio drivers, a TTF
rasteriser, and a Linux-numbered syscall ABI.

No history before this point -- the tree was never under version control.
This commit exists so the rename that follows has something to undo to.
This commit is contained in:
Nexoniarz 2026-08-09 13:47:01 +02:00
commit d0f7acf9eb
275 changed files with 51417 additions and 0 deletions

44
lib/start.S Normal file
View file

@ -0,0 +1,44 @@
/* SPDX-License-Identifier: Apache-2.0
* Schunix — process entry point.
*
* This has to be assembly, and the reason is worth recording.
*
* exec() hands a new process its arguments in registers, not on the stack:
* kernel/fs/exec.c sets proc->tf->rdi = argc and proc->tf->rsi = argv. Those
* are already the first two SysV argument registers, so _start's entire job
* is to call main and then exit — it must not touch %rdi or %rsi at all.
*
* It used to be written in C, capturing the incoming registers with GCC's
*
* register int argc_reg asm("rdi");
*
* That is not what local register variables mean. Both GCC and clang only
* guarantee the binding when the variable is used as an operand of an inline
* asm statement; reading one to pick up an incoming argument is undefined.
* GCC happened to do the useful thing. clang compiled it to
*
* movl -0x4(%rbp), %eax # two uninitialised stack slots
* movq -0x10(%rbp), %rax
*
* and every program was handed a garbage argc and argv. Nothing crashed --
* init, shmtest and socktest take no arguments and passed their whole test
* suites -- so the only symptom was `inputtest -n 6` quietly ignoring its
* limit. A compiler-dependent way to read registers has no business being in
* C when four instructions of assembly are exactly right.
*/
.text
.globl _start
_start:
xorq %rbp, %rbp /* end the frame-pointer chain here */
/* SysV wants %rsp 16-byte aligned immediately before a call, so that the
* callee sees %rsp+8 aligned once the return address is pushed. Rounding
* down is safe: argc and argv arrive in registers, so nothing below is
* needed. */
andq $-16, %rsp
callq main /* main(%rdi = argc, %rsi = argv) */
callq exit /* exit() is noreturn, but be certain */
1: hlt
jmp 1b