summaryrefslogtreecommitdiff
path: root/rt
diff options
context:
space:
mode:
authorAndrew Chambers <andrewchamberss@gmail.com>2016-01-16 22:54:05 +1300
committerOri Bernstein <ori@eigenstate.org>2016-05-08 17:20:43 +1200
commit95b8caa2f3679d450a19e9b62d8eacb70e51b073 (patch)
tree54e9938e411a56e147e347e49d1f39334108dcbf /rt
parentd42a0a6a77f8baaa2e3e57e23aa495204e9f6642 (diff)
downloadmc-95b8caa2f3679d450a19e9b62d8eacb70e51b073.tar.gz
work on openbsd port
- fix start assembly - update syscall numbers to match openbsd - add openbsd note section
Diffstat (limited to 'rt')
-rw-r--r--rt/start-openbsd.s63
1 files changed, 42 insertions, 21 deletions
diff --git a/rt/start-openbsd.s b/rt/start-openbsd.s
index 54cd0ce..e73c226 100644
--- a/rt/start-openbsd.s
+++ b/rt/start-openbsd.s
@@ -1,15 +1,25 @@
+.section ".note.openbsd.ident", "a"
+ .p2align 2
+ .long 8
+ .long 4
+ .long 1
+ .ascii "OpenBSD\0"
+ .long 0
+ .p2align 2
+
.data
-/* std._environment : byte[:][:] */
+
+/* sys._environment : byte[:][:] */
.globl sys$__environment
sys$__environment:
-.envbase:
-.quad 0 /* env size */
-.envlen:
-.quad 0 /* env ptr */
+ .envbase:
+ .quad 0 /* env size */
+ .envlen:
+ .quad 0 /* env ptr */
.globl sys$__cenvp
sys$__cenvp:
-.quad 0
+ .quad 0
.text
/*
@@ -18,25 +28,37 @@ sys$__cenvp:
* - 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 envp in sys._environment
* - Stashes a raw envp copy in __cenvp (for syscalls to use)
* - Calls main()
*/
.globl _start
_start:
+ /* turn args into a slice */
+ movq %rsp,%rbp
+
/* stack allocate sizeof(byte[:])*(argc + len(envp)) */
- movq (%rdi),%rax
- leaq 16(%rdi,%rax,8), %rbx /* argp = argv + 8*argc + 8 */
+ movq (%rbp),%rax
+ leaq 16(%rbp,%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. */
+ /* stack allocate sizeof(byte[:])*(argc + len(envp)) */
+ movq (%rbp),%rax
+ leaq 16(%rbp,%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 sys._environment */
+ movq (%rbp),%rax
+ leaq 16(%rbp,%rax,8), %rbx /* envp = argv + 8*argc + 8 */
+ /* store envp for some syscalls to use without converting */
movq %rbx,sys$__cenvp(%rip)
movq %r9,%rax
movq %rsp, %rcx
@@ -44,18 +66,17 @@ _start:
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
+ movq (%rbp), %rax /* argc */
+ leaq 8(%rbp), %rbx /* argv */
+ movq (%rbp), %rsi /* saved argc */
+ call cvt
+ pushq %rsi
+ pushq %rdx
/* call pre-main initializers */
call __init__
-
/* enter the main program */
call main
/* exit(0) */