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:
commit
d0f7acf9eb
275 changed files with 51417 additions and 0 deletions
24
lib/glue.c
Normal file
24
lib/glue.c
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Schunix — first-party userland runtime: _start entry and exit.
|
||||
|
||||
#include "types.h"
|
||||
#include "user.h"
|
||||
|
||||
extern void _xv6_exit(void);
|
||||
|
||||
void
|
||||
exit(void)
|
||||
{
|
||||
_xv6_exit();
|
||||
for (;;);
|
||||
}
|
||||
|
||||
/* _start lives in lib/start.S — it must read incoming registers, which
|
||||
* cannot be expressed portably in C. See that file. */
|
||||
|
||||
void
|
||||
__stack_chk_fail(void)
|
||||
{
|
||||
_xv6_exit();
|
||||
for (;;);
|
||||
}
|
||||
25
lib/initcode.S
Normal file
25
lib/initcode.S
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "syscall.h"
|
||||
#include "traps.h"
|
||||
|
||||
.code64
|
||||
.section .text
|
||||
.global start
|
||||
|
||||
start:
|
||||
lea init(%rip), %rdi
|
||||
lea argv(%rip), %rsi
|
||||
mov $SYS_exec, %rax
|
||||
syscall
|
||||
|
||||
exit:
|
||||
mov $SYS_exit, %rax
|
||||
syscall
|
||||
jmp exit
|
||||
|
||||
init:
|
||||
.string "/bin/init"
|
||||
|
||||
.p2align 3
|
||||
argv:
|
||||
.quad init
|
||||
.quad 0
|
||||
44
lib/start.S
Normal file
44
lib/start.S
Normal 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
|
||||
43
lib/user.ld
Normal file
43
lib/user.ld
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* Simple linker script for the JOS kernel.
|
||||
See the GNU ld 'info' manual ("info ld") to learn the syntax. */
|
||||
|
||||
/* OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") */
|
||||
/* OUTPUT_FORMAT("elf64-x86-64", "elf64-x86-64", "elf64-x86-64") */
|
||||
OUTPUT_FORMAT("elf64-x86-64")
|
||||
OUTPUT_ARCH(i386:x86-64)
|
||||
ENTRY(main)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* Link the kernel at this address: "." means the current address */
|
||||
/* Must be equal to KERNLINK */
|
||||
. = 0x1000;
|
||||
|
||||
PROVIDE(begin = .);
|
||||
|
||||
.text : {
|
||||
*(.text .rela.text .stub .text.* .gnu.linkonce.t.*)
|
||||
}
|
||||
|
||||
.rodata : {
|
||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||
}
|
||||
|
||||
/* The data segment */
|
||||
.data : {
|
||||
*(.data)
|
||||
}
|
||||
|
||||
.bss : {
|
||||
*(.bss)
|
||||
*(COMMON)
|
||||
}
|
||||
|
||||
. = ALIGN(0x1000);
|
||||
|
||||
PROVIDE(end = .);
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.eh_frame .rela.eh_frame .note.GNU-stack)
|
||||
}
|
||||
}
|
||||
110
lib/usys.S
Normal file
110
lib/usys.S
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
#include "syscall.h"
|
||||
#include "traps.h"
|
||||
|
||||
#define SYSCALL(name) \
|
||||
.global name; \
|
||||
name: \
|
||||
mov $SYS_ ## name, %rax; \
|
||||
mov %rcx, %r10 ;\
|
||||
syscall ;\
|
||||
ret
|
||||
|
||||
SYSCALL(fork)
|
||||
.global _xv6_exit
|
||||
_xv6_exit:
|
||||
mov $SYS_exit, %rax
|
||||
mov %rcx, %r10
|
||||
syscall
|
||||
ret
|
||||
SYSCALL(wait)
|
||||
SYSCALL(pipe)
|
||||
SYSCALL(read)
|
||||
SYSCALL(write)
|
||||
SYSCALL(close)
|
||||
SYSCALL(kill)
|
||||
SYSCALL(exec)
|
||||
SYSCALL(open)
|
||||
SYSCALL(mknod)
|
||||
SYSCALL(unlink)
|
||||
SYSCALL(fstat)
|
||||
SYSCALL(link)
|
||||
SYSCALL(mkdir)
|
||||
SYSCALL(chdir)
|
||||
SYSCALL(dup)
|
||||
SYSCALL(dup2)
|
||||
SYSCALL(fcntl)
|
||||
SYSCALL(getpid)
|
||||
SYSCALL(sbrk)
|
||||
SYSCALL(sleep)
|
||||
SYSCALL(uptime)
|
||||
SYSCALL(vga_sync)
|
||||
SYSCALL(getmouse)
|
||||
SYSCALL(lseek)
|
||||
SYSCALL(reboot)
|
||||
SYSCALL(shutdown)
|
||||
SYSCALL(sigfillset)
|
||||
SYSCALL(sigprocmask)
|
||||
SYSCALL(sigwait)
|
||||
SYSCALL(alarm)
|
||||
SYSCALL(waitpid)
|
||||
SYSCALL(setsid)
|
||||
SYSCALL(mmap)
|
||||
SYSCALL(munmap)
|
||||
SYSCALL(delete)
|
||||
SYSCALL(show)
|
||||
SYSCALL(showstat)
|
||||
SYSCALL(ftruncate)
|
||||
SYSCALL(truncate)
|
||||
SYSCALL(rename)
|
||||
SYSCALL(symlink)
|
||||
SYSCALL(readlink)
|
||||
SYSCALL(getuid)
|
||||
SYSCALL(geteuid)
|
||||
SYSCALL(nanosleep)
|
||||
SYSCALL(mprotect)
|
||||
SYSCALL(ioctl)
|
||||
SYSCALL(getcwd)
|
||||
SYSCALL(arch_prctl)
|
||||
SYSCALL(set_tid_address)
|
||||
SYSCALL(set_robust_list)
|
||||
SYSCALL(futex)
|
||||
SYSCALL(clone)
|
||||
SYSCALL(exit_group)
|
||||
SYSCALL(wait4)
|
||||
SYSCALL(getgid)
|
||||
SYSCALL(getegid)
|
||||
SYSCALL(umask)
|
||||
SYSCALL(writev)
|
||||
SYSCALL(readv)
|
||||
SYSCALL(brk)
|
||||
SYSCALL(prlimit)
|
||||
SYSCALL(stat)
|
||||
SYSCALL(lstat)
|
||||
SYSCALL(access)
|
||||
SYSCALL(openat)
|
||||
SYSCALL(fchdir)
|
||||
SYSCALL(enable_linux_abi)
|
||||
SYSCALL(getrlimit)
|
||||
SYSCALL(setuid)
|
||||
SYSCALL(setgid)
|
||||
SYSCALL(getsid)
|
||||
SYSCALL(dup3)
|
||||
SYSCALL(pipe2)
|
||||
SYSCALL(clock_gettime)
|
||||
SYSCALL(getppid)
|
||||
SYSCALL(rt_sigaction)
|
||||
SYSCALL(shmget)
|
||||
SYSCALL(shmat)
|
||||
SYSCALL(shmdt)
|
||||
SYSCALL(socket)
|
||||
SYSCALL(bind)
|
||||
SYSCALL(listen)
|
||||
SYSCALL(accept)
|
||||
SYSCALL(connect)
|
||||
SYSCALL(sendto)
|
||||
SYSCALL(recvfrom)
|
||||
SYSCALL(sockshutdown)
|
||||
SYSCALL(socketpair)
|
||||
SYSCALL(setsockopt)
|
||||
SYSCALL(getsockopt)
|
||||
SYSCALL(mount)
|
||||
Loading…
Reference in a new issue