summaryrefslogtreecommitdiff
path: root/rt/start-freebsd.s
diff options
context:
space:
mode:
Diffstat (limited to 'rt/start-freebsd.s')
-rw-r--r--rt/start-freebsd.s15
1 files changed, 15 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__