Source file src/runtime/defs_windows_arm64.go

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package runtime
     6  
     7  // NOTE(rsc): _CONTEXT_CONTROL is actually 0x400001 and should include PC, SP, and LR.
     8  // However, empirically, LR doesn't come along on Windows 10
     9  // unless you also set _CONTEXT_INTEGER (0x400002).
    10  // Without LR, we skip over the next-to-bottom function in profiles
    11  // when the bottom function is frameless.
    12  // So we set both here, to make a working _CONTEXT_CONTROL.
    13  const _CONTEXT_CONTROL = 0x400003
    14  
    15  type neon128 struct {
    16  	low  uint64
    17  	high int64
    18  }
    19  
    20  // See https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-arm64_nt_context
    21  type context struct {
    22  	contextflags uint32
    23  	cpsr         uint32
    24  	x            [31]uint64 // fp is x[29], lr is x[30]
    25  	xsp          uint64
    26  	pc           uint64
    27  	v            [32]neon128
    28  	fpcr         uint32
    29  	fpsr         uint32
    30  	bcr          [8]uint32
    31  	bvr          [8]uint64
    32  	wcr          [2]uint32
    33  	wvr          [2]uint64
    34  }
    35  
    36  func (c *context) ip() uintptr { return uintptr(c.pc) }
    37  func (c *context) sp() uintptr { return uintptr(c.xsp) }
    38  func (c *context) lr() uintptr { return uintptr(c.x[30]) }
    39  
    40  func (c *context) set_ip(x uintptr) { c.pc = uint64(x) }
    41  func (c *context) set_sp(x uintptr) { c.xsp = uint64(x) }
    42  func (c *context) set_lr(x uintptr) { c.x[30] = uint64(x) }
    43  func (c *context) set_fp(x uintptr) { c.x[29] = uint64(x) }
    44  
    45  func prepareContextForSigResume(c *context) {
    46  	c.x[0] = c.xsp
    47  	c.x[1] = c.pc
    48  }
    49  
    50  func dumpregs(r *context) {
    51  	print("r0   ", hex(r.x[0]), "\n")
    52  	print("r1   ", hex(r.x[1]), "\n")
    53  	print("r2   ", hex(r.x[2]), "\n")
    54  	print("r3   ", hex(r.x[3]), "\n")
    55  	print("r4   ", hex(r.x[4]), "\n")
    56  	print("r5   ", hex(r.x[5]), "\n")
    57  	print("r6   ", hex(r.x[6]), "\n")
    58  	print("r7   ", hex(r.x[7]), "\n")
    59  	print("r8   ", hex(r.x[8]), "\n")
    60  	print("r9   ", hex(r.x[9]), "\n")
    61  	print("r10  ", hex(r.x[10]), "\n")
    62  	print("r11  ", hex(r.x[11]), "\n")
    63  	print("r12  ", hex(r.x[12]), "\n")
    64  	print("r13  ", hex(r.x[13]), "\n")
    65  	print("r14  ", hex(r.x[14]), "\n")
    66  	print("r15  ", hex(r.x[15]), "\n")
    67  	print("r16  ", hex(r.x[16]), "\n")
    68  	print("r17  ", hex(r.x[17]), "\n")
    69  	print("r18  ", hex(r.x[18]), "\n")
    70  	print("r19  ", hex(r.x[19]), "\n")
    71  	print("r20  ", hex(r.x[20]), "\n")
    72  	print("r21  ", hex(r.x[21]), "\n")
    73  	print("r22  ", hex(r.x[22]), "\n")
    74  	print("r23  ", hex(r.x[23]), "\n")
    75  	print("r24  ", hex(r.x[24]), "\n")
    76  	print("r25  ", hex(r.x[25]), "\n")
    77  	print("r26  ", hex(r.x[26]), "\n")
    78  	print("r27  ", hex(r.x[27]), "\n")
    79  	print("r28  ", hex(r.x[28]), "\n")
    80  	print("r29  ", hex(r.x[29]), "\n")
    81  	print("lr   ", hex(r.x[30]), "\n")
    82  	print("sp   ", hex(r.xsp), "\n")
    83  	print("pc   ", hex(r.pc), "\n")
    84  	print("cpsr ", hex(r.cpsr), "\n")
    85  }
    86  
    87  func stackcheck() {
    88  	// TODO: not implemented on ARM
    89  }
    90  
    91  type _DISPATCHER_CONTEXT struct {
    92  	controlPc        uint64
    93  	imageBase        uint64
    94  	functionEntry    uintptr
    95  	establisherFrame uint64
    96  	targetIp         uint64
    97  	context          *context
    98  	languageHandler  uintptr
    99  	handlerData      uintptr
   100  }
   101  
   102  func (c *_DISPATCHER_CONTEXT) ctx() *context {
   103  	return c.context
   104  }
   105  

View as plain text