diff options
author | Andrew Chambers <andrewchamberss@gmail.com> | 2016-01-16 13:35:11 +1300 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2016-05-08 17:20:43 +1200 |
commit | 79c93065bf8467896e078459a91e36dc66ddaaeb (patch) | |
tree | 029fdf5f2761fc8a82c112d8bde84d9212cb287e /rt/start-openbsd.s | |
parent | b332e98485d1c22cb93f3302b83ead9e004d5160 (diff) | |
download | mc-79c93065bf8467896e078459a91e36dc66ddaaeb.tar.gz |
Add initial openbsd skeleton
Diffstat (limited to 'rt/start-openbsd.s')
-rw-r--r-- | rt/start-openbsd.s | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/rt/start-openbsd.s b/rt/start-openbsd.s new file mode 100644 index 0000000..54cd0ce --- /dev/null +++ b/rt/start-openbsd.s @@ -0,0 +1,65 @@ +.data +/* std._environment : byte[:][:] */ +.globl sys$__environment +sys$__environment: +.envbase: +.quad 0 /* env size */ +.envlen: +.quad 0 /* env ptr */ + +.globl sys$__cenvp +sys$__cenvp: +.quad 0 + +.text +/* + * The entry point for the whole program. + * This is called by the OS. In order, it: + * - Sets up all argc entries as slices + * - Sets up all envp entries as slices + * - Converts argc/argv to a slice + * - Stashes envp in std._environment + * - Stashes a raw envp copy in __cenvp (for syscalls to use) + * - Calls main() + */ +.globl _start +_start: + /* stack allocate sizeof(byte[:])*(argc + len(envp)) */ + movq (%rdi),%rax + leaq 16(%rdi,%rax,8), %rbx /* argp = argv + 8*argc + 8 */ + call count + addq %r9,%rax + imulq $16,%rax + subq %rax,%rsp + movq %rsp, %rdx /* saved args[:] */ + + /* convert envp to byte[:][:] for std._environment */ + movq (%rdi),%rax + leaq 16(%rdi,%rax,8), %rbx /* envp = argv + 8*argc + 8 */ + /* store envp for some syscalls to use without spurious conversion. */ + movq %rbx,sys$__cenvp(%rip) + movq %r9,%rax + movq %rsp, %rcx + movq %r9,.envlen(%rip) + movq %rdx,.envbase(%rip) + call cvt + movq %rcx,%rdx + + /* convert argc, argv to byte[:][:] for args. */ + movq (%rdi), %rax /* argc */ + leaq 8(%rdi), %rbx /* argv */ + movq (%rdi), %rsi /* saved argc */ + call cvt + pushq %rsi + pushq %rdx + + /* call pre-main initializers */ + call __init__ + + /* enter the main program */ + call main + /* exit(0) */ + xorq %rdi,%rdi + movq $1,%rax + syscall + |