summaryrefslogtreecommitdiff
path: root/rt
diff options
context:
space:
mode:
Diffstat (limited to 'rt')
-rw-r--r--rt/start-freebsd.s15
-rw-r--r--rt/start-linux.s11
-rw-r--r--rt/start-netbsd.s15
-rw-r--r--rt/start-openbsd.s10
-rw-r--r--rt/start-osx.s11
5 files changed, 62 insertions, 0 deletions
diff --git a/rt/start-freebsd.s b/rt/start-freebsd.s
index 9c1091b..399fac0 100644
--- a/rt/start-freebsd.s
+++ b/rt/start-freebsd.s
@@ -4,6 +4,10 @@
sys$__cenvp:
.quad 0
+.globl thread$__tls
+thread$__tls:
+ .fill 88 /* sizeof(tlshdr) + (8 * sizeof(void#)) = 24 + 64 */
+
.text
/*
* The entry point for the whole program.
@@ -11,6 +15,7 @@ sys$__cenvp:
* - Sets up all argc entries as slices
* - Converts argc/argv to a slice
* - Stashes a raw envp copy in __cenvp (for syscalls to use)
+ * - Sets up thread local storage for the main thread
* - Calls main()
*/
.globl _start
@@ -35,6 +40,16 @@ _start:
pushq %rcx
call cvt
+ /* set up the intial tls region for the main thread */
+ subq $0x10,%rsp
+ movq $165,%rax /* sysarch */
+ movq $129,%rdi /* Archamd64setfs */
+ leaq thread$__tls(%rip),%rsi
+ movq %rsi,(%rsp)
+ movq %rsp,%rsi
+ syscall
+ addq $0x10,%rsp
+
xorq %rbp,%rbp
/* call pre-main initializers */
call __init__
diff --git a/rt/start-linux.s b/rt/start-linux.s
index 742b4a3..a0cbfb6 100644
--- a/rt/start-linux.s
+++ b/rt/start-linux.s
@@ -4,6 +4,10 @@
sys$__cenvp:
.quad 0
+.globl thread$__tls
+thread$__tls:
+ .fill 88 /* sizeof(tlshdr) + (8 * sizeof(void#)) = 24 + 64 */
+
.text
/*
* The entry point for the whole program.
@@ -11,6 +15,7 @@ sys$__cenvp:
* - Sets up all argc entries as slices
* - Converts argc/argv to a slice
* - Stashes a raw envp copy in __cenvp (for syscalls to use)
+ * - Sets up thread local storage for the main thread
* - Calls main()
*/
.globl _start
@@ -36,6 +41,12 @@ _start:
pushq %rcx
call cvt
+ /* set up the intial tls region for the main thread */
+ movq $158,%rax /* arch_prctl */
+ movq $0x1002,%rdi /* Archsetfs */
+ leaq thread$__tls(%rip),%rsi
+ syscall
+
xorq %rbp,%rbp
/* call pre-main initializers */
call __init__
diff --git a/rt/start-netbsd.s b/rt/start-netbsd.s
index dd3213e..3a6cfc7 100644
--- a/rt/start-netbsd.s
+++ b/rt/start-netbsd.s
@@ -12,6 +12,10 @@
sys$__cenvp:
.quad 0
+.globl thread$__tls
+thread$__tls:
+ .fill 88 /* sizeof(tlshdr) + (8 * sizeof(void#)) = 24 + 64 */
+
.text
/*
* The entry point for the whole program.
@@ -19,6 +23,7 @@ sys$__cenvp:
* - Sets up all argc entries as slices
* - Converts argc/argv to a slice
* - Stashes a raw envp copy in __cenvp (for syscalls to use)
+ * - Sets up thread local storage for the main thread
* - Calls main()
*/
.globl _start
@@ -44,6 +49,16 @@ _start:
pushq %rcx
call cvt
+ /* set up the intial tls region for the main thread */
+ subq $0x10,%rsp
+ movq $165,%rax /* sysarch */
+ movq $15,%rdi /* X8664setfsbase */
+ leaq thread$__tls(%rip),%rsi
+ movq %rsi,(%rsp)
+ movq %rsp,%rsi
+ syscall
+ addq $0x10,%rsp
+
xorq %rbp,%rbp
/* call pre-main initializers */
call __init__
diff --git a/rt/start-openbsd.s b/rt/start-openbsd.s
index c0e061a..eef7b45 100644
--- a/rt/start-openbsd.s
+++ b/rt/start-openbsd.s
@@ -13,6 +13,10 @@
sys$__cenvp:
.quad 0
+.globl thread$__tls
+thread$__tls:
+ .fill 88 /* sizeof(tlshdr) + (8 * sizeof(void#)) = 24 + 64 */
+
.text
/*
* The entry point for the whole program.
@@ -20,6 +24,7 @@ sys$__cenvp:
* - Sets up all argc entries as slices
* - Converts argc/argv to a slice
* - Stashes a raw envp copy in __cenvp (for syscalls to use)
+ * - Sets up thread local storage for the main thread
* - Calls main()
*/
.globl _start
@@ -45,6 +50,11 @@ _start:
pushq %rcx
call cvt
+ /* set up the intial tls region for the main thread */
+ movq $329,%rax /* Sys__set_tcb */
+ leaq thread$__tls(%rip),%rdi
+ syscall
+
xorq %rbp,%rbp
/*
we're done startup, and we kind of want
diff --git a/rt/start-osx.s b/rt/start-osx.s
index b43b30c..a1e1856 100644
--- a/rt/start-osx.s
+++ b/rt/start-osx.s
@@ -4,6 +4,10 @@
_sys$__cenvp:
.quad 0
+.globl thread$__tls
+thread$__tls:
+ .fill 104 /* sizeof(tlshdr) + (8 * sizeof(void#)) = 40 + 64 */
+
.text
/*
* The entry point for the whole program.
@@ -11,6 +15,7 @@ _sys$__cenvp:
* - Sets up all argc entries as slices
* - Converts argc/argv to a slice
* - Stashes a raw envp copy in __cenvp (for syscalls to use)
+ * - Sets up thread local storage for the main thread
* - Calls main()
*/
.globl start
@@ -36,6 +41,12 @@ start:
pushq %rcx
call cvt
+ /* set up the intial tls region for the main thread */
+ movq $0x3000003,%rax /* undocumented setgsbase syscall */
+ leaq thread$__tls(%rip),%rdi
+ movq %rdi,0x20(%rdi) /* also store a copy in __tls.self */
+ syscall
+
xorq %rbp,%rbp
call ___init__
/* enter the main program */