Skip to content

Commit bee80d1

Browse files
committed
draft
1 parent 06356af commit bee80d1

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

src/runtime/cgo/gcc_netbsd_arm64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ _cgo_sys_thread_start(ThreadStart *ts)
4141

4242
pthread_attr_init(&attr);
4343
pthread_attr_getstacksize(&attr, &size);
44+
4445
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
4546
ts->g->stackhi = size;
4647
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);

src/runtime/os_netbsd_arm64.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ func lwp_mcontext_init(mc *mcontextt, stk unsafe.Pointer, mp *m, gp *g, fn uintp
1010
// Machine dependent mcontext initialisation for LWP.
1111
mc.__gregs[_REG_ELR] = uint64(funcPC(lwp_tramp))
1212
mc.__gregs[_REG_X31] = uint64(uintptr(stk))
13-
mc.__gregs[_REG_X0] = uint64(uintptr(unsafe.Pointer(mp)))
14-
mc.__gregs[_REG_X1] = uint64(uintptr(unsafe.Pointer(mp.g0)))
15-
mc.__gregs[_REG_X2] = uint64(fn)
13+
mc.__gregs[_REG_X2] = uint64(uintptr(unsafe.Pointer(mp)))
14+
mc.__gregs[_REG_X3] = uint64(uintptr(unsafe.Pointer(gp)))
15+
mc.__gregs[_REG_X4] = uint64(fn)
1616
}
1717

1818
//go:nosplit

src/runtime/sys_netbsd_arm64.s

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "go_asm.h"
1010
#include "go_tls.h"
11+
#include "tls_arm64.h"
1112
#include "textflag.h"
1213

1314
#define CLOCK_REALTIME 0
@@ -34,6 +35,7 @@
3435
#define SYS__lwp_create 309
3536
#define SYS__lwp_exit 310
3637
#define SYS__lwp_self 311
38+
#define SYS__lwp_setprivate 317
3739
#define SYS__lwp_kill 318
3840
#define SYS__lwp_unpark 321
3941
#define SYS___sigaction_sigtramp 340
@@ -58,16 +60,20 @@ ok:
5860
MOVW R0, ret+24(FP)
5961
RET
6062

63+
6164
TEXT runtime·lwp_tramp(SB),NOSPLIT,$0
62-
CMP $0, R1
63-
BEQ nog
64-
CMP $0, R2
65-
BEQ nog
6665

67-
MOVD R0, g_m(R1)
68-
MOVD R1, g
69-
nog:
70-
CALL (R2)
66+
// Set tpidr_el0 to point at m->tls
67+
MOVD m_tls(R8), R0
68+
BL runtime·settls(SB)
69+
70+
MRS_TPIDR_R0 // get_tls
71+
MOVD R2, g_m(R9)
72+
MOVD R3, g(R0)
73+
//CALL runtime·stackcheck(SB)
74+
75+
// Call fn
76+
CALL (R12)
7177

7278
MOVD $0, R0 // crash (not reached)
7379
MOVD R0, (R8)
@@ -343,6 +349,15 @@ fail:
343349
MOVD $0, R0
344350
MOVD R0, (R0) // crash
345351

352+
// set TLS base to R0
353+
TEXT runtime·settls(SB),NOSPLIT,$8
354+
SVC $SYS__lwp_setprivate
355+
BCS fail
356+
RET
357+
fail:
358+
MOVD $0, R0
359+
MOVD R0, (R0)
360+
346361
TEXT runtime·sysctl(SB),NOSPLIT,$0
347362
MOVD mib+0(FP), R0 // arg 1 - name
348363
MOVW miblen+8(FP), R1 // arg 2 - namelen

src/runtime/tls_arm64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#ifdef GOOS_netbsd
2424
#define TPIDR TPIDRRO_EL0
25+
#define TLSG_IS_VARIABLE
2526
#define MRS_TPIDR_R0 WORD $0xd53bd040 // MRS TPIDRRO_EL0, R0
2627
#endif
2728

0 commit comments

Comments
 (0)