ref: 6e064ade4c10bce0127ebebf6cd1dc2bb24213f5
parent: ceb89c2cd04c695188993fe029698e2e1ee6d457
author: Michael Forney <mforney@mforney.org>
date: Tue Jul 4 08:25:39 EDT 2017
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.
--- a/rt/common.s
+++ b/rt/common.s
@@ -15,25 +15,7 @@
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 @@
jnz .cvtloop
.cvtdone:
ret
-
--- a/rt/start-freebsd.s
+++ b/rt/start-freebsd.s
@@ -1,8 +1,8 @@
.data
-
+/* sys.__cenvp : byte## */
.globl sys$__cenvp
sys$__cenvp:
-.quad 0
+ .quad 0
.text
/*
@@ -9,37 +9,29 @@
* 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 */
- /* 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)
+ /* 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 %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 @@
xorq %rdi,%rdi
movq $1,%rax
syscall
-
--- 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 @@
* 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 @@
xorq %rdi,%rdi
movq $60,%rax
syscall
-
--- 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 @@
* 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 */
--- 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 @@
* 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 */
--- a/rt/start-osx.s
+++ b/rt/start-osx.s
@@ -1,15 +1,8 @@
.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
/*
@@ -16,43 +9,31 @@
* 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__