Source file src/runtime/defs_windows_arm.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  import (
     8  	"internal/goarch"
     9  	"unsafe"
    10  )
    11  
    12  // NOTE(rsc): _CONTEXT_CONTROL is actually 0x200001 and should include PC, SP, and LR.
    13  // However, empirically, LR doesn't come along on Windows 10
    14  // unless you also set _CONTEXT_INTEGER (0x200002).
    15  // Without LR, we skip over the next-to-bottom function in profiles
    16  // when the bottom function is frameless.
    17  // So we set both here, to make a working _CONTEXT_CONTROL.
    18  const _CONTEXT_CONTROL = 0x200003
    19  
    20  type neon128 struct {
    21  	low  uint64
    22  	high int64
    23  }
    24  
    25  type context struct {
    26  	contextflags uint32
    27  	r0           uint32
    28  	r1           uint32
    29  	r2           uint32
    30  	r3           uint32
    31  	r4           uint32
    32  	r5           uint32
    33  	r6           uint32
    34  	r7           uint32
    35  	r8           uint32
    36  	r9           uint32
    37  	r10          uint32
    38  	r11          uint32
    39  	r12          uint32
    40  
    41  	spr  uint32
    42  	lrr  uint32
    43  	pc   uint32
    44  	cpsr uint32
    45  
    46  	fpscr   uint32
    47  	padding uint32
    48  
    49  	floatNeon [16]neon128
    50  
    51  	bvr      [8]uint32
    52  	bcr      [8]uint32
    53  	wvr      [1]uint32
    54  	wcr      [1]uint32
    55  	padding2 [2]uint32
    56  }
    57  
    58  func (c *context) ip() uintptr { return uintptr(c.pc) }
    59  func (c *context) sp() uintptr { return uintptr(c.spr) }
    60  func (c *context) lr() uintptr { return uintptr(c.lrr) }
    61  
    62  func (c *context) set_ip(x uintptr) { c.pc = uint32(x) }
    63  func (c *context) set_sp(x uintptr) { c.spr = uint32(x) }
    64  func (c *context) set_lr(x uintptr) { c.lrr = uint32(x) }
    65  
    66  // arm does not have frame pointer register.
    67  func (c *context) set_fp(x uintptr) {}
    68  
    69  func (c *context) pushCall(targetPC, resumePC uintptr) {
    70  	// Push LR. The injected call is responsible
    71  	// for restoring LR. gentraceback is aware of
    72  	// this extra slot. See sigctxt.pushCall in
    73  	// signal_arm.go.
    74  	sp := c.sp() - goarch.StackAlign
    75  	c.set_sp(sp)
    76  	*(*uint32)(unsafe.Pointer(sp)) = uint32(c.lr())
    77  	c.set_lr(resumePC)
    78  	c.set_ip(targetPC)
    79  }
    80  
    81  func prepareContextForSigResume(c *context) {
    82  	c.r0 = c.spr
    83  	c.r1 = c.pc
    84  }
    85  
    86  func dumpregs(r *context) {
    87  	print("r0   ", hex(r.r0), "\n")
    88  	print("r1   ", hex(r.r1), "\n")
    89  	print("r2   ", hex(r.r2), "\n")
    90  	print("r3   ", hex(r.r3), "\n")
    91  	print("r4   ", hex(r.r4), "\n")
    92  	print("r5   ", hex(r.r5), "\n")
    93  	print("r6   ", hex(r.r6), "\n")
    94  	print("r7   ", hex(r.r7), "\n")
    95  	print("r8   ", hex(r.r8), "\n")
    96  	print("r9   ", hex(r.r9), "\n")
    97  	print("r10  ", hex(r.r10), "\n")
    98  	print("r11  ", hex(r.r11), "\n")
    99  	print("r12  ", hex(r.r12), "\n")
   100  	print("sp   ", hex(r.spr), "\n")
   101  	print("lr   ", hex(r.lrr), "\n")
   102  	print("pc   ", hex(r.pc), "\n")
   103  	print("cpsr ", hex(r.cpsr), "\n")
   104  }
   105  
   106  func stackcheck() {
   107  	// TODO: not implemented on ARM
   108  }
   109  
   110  type _DISPATCHER_CONTEXT struct {
   111  	controlPc        uint32
   112  	imageBase        uint32
   113  	functionEntry    uintptr
   114  	establisherFrame uint32
   115  	targetIp         uint32
   116  	context          *context
   117  	languageHandler  uintptr
   118  	handlerData      uintptr
   119  }
   120  
   121  func (c *_DISPATCHER_CONTEXT) ctx() *context {
   122  	return c.context
   123  }
   124  

View as plain text