Skip to content

Commit

Permalink
runtime: convert windows/arm64 assembly
Browse files Browse the repository at this point in the history
The assembly is mostly a straightforward conversion of the
equivalent arm assembly.

This CL is part of a stack adding windows/arm64
support (#36439), intended to land in the Go 1.17 cycle.

Change-Id: I61b15d712ade4d3a7285c7680de8e0987aacba10
Reviewed-on: https://go-review.googlesource.com/c/go/+/288828
Trust: Russ Cox <rsc@golang.org>
Trust: Jason A. Donenfeld <Jason@zx2c4.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
  • Loading branch information
rsc committed Feb 19, 2021
1 parent 3527caa commit c7c6c11
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 421 deletions.
7 changes: 7 additions & 0 deletions src/runtime/asm_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ nocgo:

BL runtime·check(SB)

#ifdef GOOS_windows
BL runtime·wintls(SB)
#endif

MOVW 8(RSP), R0 // copy argc
MOVW R0, -8(RSP)
MOVD 16(RSP), R0 // copy argv
Expand Down Expand Up @@ -1111,6 +1115,9 @@ TEXT setg_gcc<>(SB),NOSPLIT,$8
MOVD savedR27-8(SP), R27
RET

TEXT runtime·emptyfunc(SB),0,$0-0
RET

TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0
MOVD ZR, R0
MOVD (R0), R0
Expand Down
1 change: 1 addition & 0 deletions src/runtime/defs_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (

_EXCEPTION_ACCESS_VIOLATION = 0xc0000005
_EXCEPTION_BREAKPOINT = 0x80000003
_EXCEPTION_ILLEGAL_INSTRUCTION = 0xc000001d
_EXCEPTION_FLT_DENORMAL_OPERAND = 0xc000008d
_EXCEPTION_FLT_DIVIDE_BY_ZERO = 0xc000008e
_EXCEPTION_FLT_INEXACT_RESULT = 0xc000008f
Expand Down
1 change: 1 addition & 0 deletions src/runtime/memclr_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// See memclrNoHeapPointers Go doc for important implementation constraints.

// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
// Also called from assembly in sys_windows_arm.s without g (but using Go stack convention).
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-8
MOVW ptr+0(FP), TO
MOVW n+4(FP), N
Expand Down
1 change: 1 addition & 0 deletions src/runtime/memclr_arm64.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// See memclrNoHeapPointers Go doc for important implementation constraints.

// func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
// Also called from assembly in sys_windows_arm64.s without g (but using Go stack convention).
TEXT runtime·memclrNoHeapPointers(SB),NOSPLIT,$0-16
MOVD ptr+0(FP), R0
MOVD n+8(FP), R1
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func tstart_stdcall(newm *m)
// Called by OS using stdcall ABI.
func ctrlhandler()

// Init-time helper
func wintls()

type mOS struct {
threadLock mutex // protects "thread" and prevents closing
thread uintptr // thread handle
Expand Down
1 change: 1 addition & 0 deletions src/runtime/signal_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func isgoexception(info *exceptionrecord, r *context) bool {
case _EXCEPTION_FLT_OVERFLOW:
case _EXCEPTION_FLT_UNDERFLOW:
case _EXCEPTION_BREAKPOINT:
case _EXCEPTION_ILLEGAL_INSTRUCTION: // breakpoint arrives this way on arm64
}
return true
}
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/stubs_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ func save_g()

//go:noescape
func asmcgocall_no_g(fn, arg unsafe.Pointer)

func emptyfunc()
18 changes: 9 additions & 9 deletions src/runtime/sys_windows_arm.s
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,17 @@ done:
BEQ return

// Check if we need to set up the control flow guard workaround.
// On Windows/ARM, the stack pointer must lie within system
// stack limits when we resume from exception.
// On Windows, the stack pointer in the context must lie within
// system stack limits when we resume from exception.
// Store the resume SP and PC on the g0 stack,
// and return to returntramp on the g0 stack. returntramp
// and return to sigresume on the g0 stack. sigresume
// pops the saved PC and SP from the g0 stack, resuming execution
// at the desired location.
// If returntramp has already been set up by a previous exception
// If sigresume has already been set up by a previous exception
// handler, don't clobber the stored SP and PC on the stack.
MOVW 4(R3), R3 // PEXCEPTION_POINTERS->Context
MOVW context_pc(R3), R2 // load PC from context record
MOVW $returntramp<>(SB), R1
MOVW $sigresume<>(SB), R1
CMP R1, R2
B.EQ return // do not clobber saved SP/PC

Expand All @@ -196,9 +196,9 @@ done:
MOVW context_pc(R3), R2
MOVW R2, context_r1(R3)

// Set up context record to return to returntramp on g0 stack
// Set up context record to return to sigresume on g0 stack
MOVW R12, context_spr(R3)
MOVW $returntramp<>(SB), R2
MOVW $sigresume<>(SB), R2
MOVW R2, context_pc(R3)

return:
Expand All @@ -208,8 +208,8 @@ return:
// This is part of the control flow guard workaround.
// It switches stacks and jumps to the continuation address.
// R0 and R1 are set above at the end of sigtramp<>
// in the context that starts executing at returntramp<>.
TEXT returntramp<>(SB),NOSPLIT|NOFRAME,$0
// in the context that starts executing at sigresume<>.
TEXT sigresume<>(SB),NOSPLIT|NOFRAME,$0
// Important: do not smash LR,
// which is set to a live value when handling
// a signal by pushing a call to sigpanic onto the stack.
Expand Down
Loading

0 comments on commit c7c6c11

Please sign in to comment.