summaryrefslogtreecommitdiff
path: root/rt
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2017-07-04 12:25:39 -0700
committerOri Bernstein <ori@eigenstate.org>2017-07-04 23:27:34 -0700
commit6e064ade4c10bce0127ebebf6cd1dc2bb24213f5 (patch)
tree2c9736734f0be29a352909667cc333afa1134b26 /rt
parentceb89c2cd04c695188993fe029698e2e1ee6d457 (diff)
downloadmc-6e064ade4c10bce0127ebebf6cd1dc2bb24213f5.tar.gz
Simplify _start routines
sys$__environment was unused since 94ee9832f5861c4d09afa12338720eb3a479c342. Delete it and count, which is no longer needed. Simplify _start routines since they no longer need to allocate space for the environment slice and populate it.
Diffstat (limited to 'rt')
-rw-r--r--rt/common.s19
-rw-r--r--rt/start-freebsd.s41
-rw-r--r--rt/start-linux.s49
-rw-r--r--rt/start-netbsd.s50
-rw-r--r--rt/start-openbsd.s50
-rw-r--r--rt/start-osx.s51
6 files changed, 73 insertions, 187 deletions
diff --git a/rt/common.s b/rt/common.s
index 555a243..6cff251 100644
--- a/rt/common.s
+++ b/rt/common.s
@@ -15,24 +15,6 @@ cstrlen:
jne .lenloop
ret
-
-/*
- * Counts the size of the null terminated string vector
- * pointed to by %rbx. Clobbers %r10,%r11
- */
-count:
- xorq %r9,%r9
- movq %rbx,%r11
-.countloop:
- movq (%r11),%r10
- testq %r10,%r10
- jz .countdone
- addq $1,%r9
- addq $8,%r11
- jmp .countloop
-.countdone:
- ret
-
/*
* iterate over the strings for argc, and put
* them into the args array.
@@ -54,4 +36,3 @@ cvt:
jnz .cvtloop
.cvtdone:
ret
-
diff --git a/rt/start-freebsd.s b/rt/start-freebsd.s
index 186a76c..e3795af 100644
--- a/rt/start-freebsd.s
+++ b/rt/start-freebsd.s
@@ -1,45 +1,37 @@
.data
-
+/* sys.__cenvp : byte## */
.globl sys$__cenvp
sys$__cenvp:
-.quad 0
+ .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[:] */
+ /* load argc, argv, envp from stack */
+ movq (%rdi),%rax /* argc */
+ leaq 8(%rdi),%rbx /* argv */
+ leaq 16(%rdi,%rax,8),%rcx /* envp = argv + 8*argc + 8 */
+
+ /* store envp for some syscalls to use without converting */
+ movq %rcx,sys$__cenvp(%rip)
- /* 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)
+ /* stack allocate sizeof(byte[:])*argc */
+ imulq $16,%rax,%rdx
+ subq %rdx,%rsp
+ movq %rsp,%rcx /* args[:] */
/* convert argc, argv to byte[:][:] for args. */
- movq %rsp, %rcx
- movq (%rdi), %rax /* argc */
- leaq 8(%rdi), %rbx /* argv */
- movq (%rdi), %rsi /* saved argc */
- call cvt
- pushq %rsi
- pushq %rdx
+ pushq %rax
+ pushq %rcx
+ call cvt
xorq %rbp,%rbp
/* call pre-main initializers */
@@ -51,4 +43,3 @@ _start:
xorq %rdi,%rdi
movq $1,%rax
syscall
-
diff --git a/rt/start-linux.s b/rt/start-linux.s
index fcc7de1..0c6cf3f 100644
--- a/rt/start-linux.s
+++ b/rt/start-linux.s
@@ -1,13 +1,5 @@
.data
-
-/* sys._environment : byte[:][:] */
-.globl sys$__environment
-sys$__environment:
- .envbase:
- .quad 0 /* env size */
- .envlen:
- .quad 0 /* env ptr */
-
+/* sys.__cenvp : byte## */
.globl sys$__cenvp
sys$__cenvp:
.quad 0
@@ -17,45 +9,31 @@ sys$__cenvp:
* 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 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 (%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[:] */
+ /* load argc, argv, envp from stack */
+ movq (%rbp),%rax /* argc */
+ leaq 8(%rbp),%rbx /* argv */
+ leaq 16(%rbp,%rax,8),%rcx /* envp = argv + 8*argc + 8 */
- /* 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
- movq %r9,.envlen(%rip)
- movq %rdx,.envbase(%rip)
- call cvt
- movq %rcx,%rdx
+ movq %rcx,sys$__cenvp(%rip)
+
+ /* stack allocate sizeof(byte[:])*argc */
+ imulq $16,%rax,%rdx
+ subq %rdx,%rsp
+ movq %rsp,%rcx /* args[:] */
/* convert argc, argv to byte[:][:] for args. */
- movq (%rbp), %rax /* argc */
- leaq 8(%rbp), %rbx /* argv */
- movq (%rbp), %rsi /* saved argc */
+ pushq %rax
+ pushq %rcx
call cvt
- pushq %rsi
- pushq %rdx
xorq %rbp,%rbp
/* call pre-main initializers */
@@ -66,4 +44,3 @@ _start:
xorq %rdi,%rdi
movq $60,%rax
syscall
-
diff --git a/rt/start-netbsd.s b/rt/start-netbsd.s
index bd2d576..a5eecc4 100644
--- a/rt/start-netbsd.s
+++ b/rt/start-netbsd.s
@@ -7,15 +7,7 @@
.long 200000000
.data
-
-/* sys._environment : byte[:][:] */
-.globl sys$__environment
-sys$__environment:
- .envbase:
- .quad 0 /* env size */
- .envlen:
- .quad 0 /* env ptr */
-
+/* sys.__cenvp : byte## */
.globl sys$__cenvp
sys$__cenvp:
.quad 0
@@ -25,45 +17,31 @@ sys$__cenvp:
* 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 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 (%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[:] */
+ /* load argc, argv, envp from stack */
+ movq (%rbp),%rax /* argc */
+ leaq 8(%rbp),%rbx /* argv */
+ leaq 16(%rbp,%rax,8),%rcx /* envp = argv + 8*argc + 8 */
- /* 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
- movq %r9,.envlen(%rip)
- movq %rdx,.envbase(%rip)
- call cvt
- movq %rcx,%rdx
-
+ movq %rcx,sys$__cenvp(%rip)
+
+ /* stack allocate sizeof(byte[:])*argc */
+ imulq $16,%rax,%rdx
+ subq %rdx,%rsp
+ movq %rsp,%rcx /* args[:] */
+
/* convert argc, argv to byte[:][:] for args. */
- movq (%rbp), %rax /* argc */
- leaq 8(%rbp), %rbx /* argv */
- movq (%rbp), %rsi /* saved argc */
+ pushq %rax
+ pushq %rcx
call cvt
- pushq %rsi
- pushq %rdx
xorq %rbp,%rbp
/* call pre-main initializers */
diff --git a/rt/start-openbsd.s b/rt/start-openbsd.s
index 663d865..ad62bf4 100644
--- a/rt/start-openbsd.s
+++ b/rt/start-openbsd.s
@@ -8,15 +8,7 @@
.p2align 2
.data
-
-/* sys._environment : byte[:][:] */
-.globl sys$__environment
-sys$__environment:
- .envbase:
- .quad 0 /* env size */
- .envlen:
- .quad 0 /* env ptr */
-
+/* sys.__cenvp : byte## */
.globl sys$__cenvp
sys$__cenvp:
.quad 0
@@ -26,45 +18,31 @@ sys$__cenvp:
* 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 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 (%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[:] */
+ /* load argc, argv, envp from stack */
+ movq (%rbp),%rax /* argc */
+ leaq 8(%rbp),%rbx /* argv */
+ leaq 16(%rbp,%rax,8),%rcx /* envp = argv + 8*argc + 8 */
- /* 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
- movq %r9,.envlen(%rip)
- movq %rdx,.envbase(%rip)
- call cvt
- movq %rcx,%rdx
-
+ movq %rcx,sys$__cenvp(%rip)
+
+ /* stack allocate sizeof(byte[:])*argc */
+ imulq $16,%rax,%rdx
+ subq %rdx,%rsp
+ movq %rsp,%rcx /* args[:] */
+
/* convert argc, argv to byte[:][:] for args. */
- movq (%rbp), %rax /* argc */
- leaq 8(%rbp), %rbx /* argv */
- movq (%rbp), %rsi /* saved argc */
+ pushq %rax
+ pushq %rcx
call cvt
- pushq %rsi
- pushq %rdx
xorq %rbp,%rbp
/* call pre-main initializers */
diff --git a/rt/start-osx.s b/rt/start-osx.s
index 3d7952f..d904746 100644
--- a/rt/start-osx.s
+++ b/rt/start-osx.s
@@ -1,58 +1,39 @@
.data
-/* sys._environment : byte[:][:] */
-.globl _sys$__environment
-_sys$__environment:
-.envbase:
-.quad 0 /* env size */
-.envlen:
-.quad 0 /* env ptr */
-
+/* sys.__cenvp : byte## */
.globl _sys$__cenvp
_sys$__cenvp:
-.quad 0
+ .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 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 (%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 */
- movq %rbx,_sys$__cenvp(%rip)
- movq %r9,%rax
- movq %rsp, %rcx
- movq %r9,.envlen(%rip)
- movq %rdx,.envbase(%rip)
- call cvt
- movq %rcx,%rdx
+ /* load argc, argv, envp from stack */
+ movq (%rbp),%rax /* argc */
+ leaq 8(%rbp),%rbx /* argv */
+ leaq 16(%rbp,%rax,8),%rcx /* envp = argv + 8*argc + 8 */
+
+ /* store envp for some syscalls to use without converting */
+ movq %rcx,_sys$__cenvp(%rip)
+
+ /* stack allocate sizeof(byte[:])*argc */
+ imulq $16,%rax,%rdx
+ subq %rdx,%rsp
+ movq %rsp,%rcx /* args[:] */
/* convert argc, argv to byte[:][:] for args. */
- movq (%rbp), %rax /* argc */
- leaq 8(%rbp), %rbx /* argv */
- movq (%rbp), %rsi /* saved argc */
+ pushq %rax
+ pushq %rcx
call cvt
- pushq %rsi
- pushq %rdx
xorq %rbp,%rbp
call ___init__