Source file src/runtime/defs_windows_amd64.go

     1  // Copyright 2009 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  const _CONTEXT_CONTROL = 0x100001
    13  
    14  type m128a struct {
    15  	low  uint64
    16  	high int64
    17  }
    18  
    19  type context struct {
    20  	p1home               uint64
    21  	p2home               uint64
    22  	p3home               uint64
    23  	p4home               uint64
    24  	p5home               uint64
    25  	p6home               uint64
    26  	contextflags         uint32
    27  	mxcsr                uint32
    28  	segcs                uint16
    29  	segds                uint16
    30  	seges                uint16
    31  	segfs                uint16
    32  	seggs                uint16
    33  	segss                uint16
    34  	eflags               uint32
    35  	dr0                  uint64
    36  	dr1                  uint64
    37  	dr2                  uint64
    38  	dr3                  uint64
    39  	dr6                  uint64
    40  	dr7                  uint64
    41  	rax                  uint64
    42  	rcx                  uint64
    43  	rdx                  uint64
    44  	rbx                  uint64
    45  	rsp                  uint64
    46  	rbp                  uint64
    47  	rsi                  uint64
    48  	rdi                  uint64
    49  	r8                   uint64
    50  	r9                   uint64
    51  	r10                  uint64
    52  	r11                  uint64
    53  	r12                  uint64
    54  	r13                  uint64
    55  	r14                  uint64
    56  	r15                  uint64
    57  	rip                  uint64
    58  	anon0                [512]byte
    59  	vectorregister       [26]m128a
    60  	vectorcontrol        uint64
    61  	debugcontrol         uint64
    62  	lastbranchtorip      uint64
    63  	lastbranchfromrip    uint64
    64  	lastexceptiontorip   uint64
    65  	lastexceptionfromrip uint64
    66  }
    67  
    68  func (c *context) ip() uintptr { return uintptr(c.rip) }
    69  func (c *context) sp() uintptr { return uintptr(c.rsp) }
    70  
    71  // AMD64 does not have link register, so this returns 0.
    72  func (c *context) lr() uintptr      { return 0 }
    73  func (c *context) set_lr(x uintptr) {}
    74  
    75  func (c *context) set_ip(x uintptr) { c.rip = uint64(x) }
    76  func (c *context) set_sp(x uintptr) { c.rsp = uint64(x) }
    77  func (c *context) set_fp(x uintptr) { c.rbp = uint64(x) }
    78  
    79  func (c *context) pushCall(targetPC, resumePC uintptr) {
    80  	sp := c.sp() - goarch.StackAlign
    81  	*(*uintptr)(unsafe.Pointer(sp)) = resumePC
    82  	c.set_sp(sp)
    83  	c.set_ip(targetPC)
    84  }
    85  
    86  func prepareContextForSigResume(c *context) {
    87  	c.r8 = c.rsp
    88  	c.r9 = c.rip
    89  }
    90  
    91  func dumpregs(r *context) {
    92  	print("rax     ", hex(r.rax), "\n")
    93  	print("rbx     ", hex(r.rbx), "\n")
    94  	print("rcx     ", hex(r.rcx), "\n")
    95  	print("rdx     ", hex(r.rdx), "\n")
    96  	print("rdi     ", hex(r.rdi), "\n")
    97  	print("rsi     ", hex(r.rsi), "\n")
    98  	print("rbp     ", hex(r.rbp), "\n")
    99  	print("rsp     ", hex(r.rsp), "\n")
   100  	print("r8      ", hex(r.r8), "\n")
   101  	print("r9      ", hex(r.r9), "\n")
   102  	print("r10     ", hex(r.r10), "\n")
   103  	print("r11     ", hex(r.r11), "\n")
   104  	print("r12     ", hex(r.r12), "\n")
   105  	print("r13     ", hex(r.r13), "\n")
   106  	print("r14     ", hex(r.r14), "\n")
   107  	print("r15     ", hex(r.r15), "\n")
   108  	print("rip     ", hex(r.rip), "\n")
   109  	print("rflags  ", hex(r.eflags), "\n")
   110  	print("cs      ", hex(r.segcs), "\n")
   111  	print("fs      ", hex(r.segfs), "\n")
   112  	print("gs      ", hex(r.seggs), "\n")
   113  }
   114  
   115  type _DISPATCHER_CONTEXT struct {
   116  	controlPc        uint64
   117  	imageBase        uint64
   118  	functionEntry    uintptr
   119  	establisherFrame uint64
   120  	targetIp         uint64
   121  	context          *context
   122  	languageHandler  uintptr
   123  	handlerData      uintptr
   124  }
   125  
   126  func (c *_DISPATCHER_CONTEXT) ctx() *context {
   127  	return c.context
   128  }
   129  

View as plain text