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
5package 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.
13const _CONTEXT_CONTROL = 0x400003
14
15type 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
21type 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
36func (c *context) ip() uintptr { return uintptr(c.pc) }
37func (c *context) sp() uintptr { return uintptr(c.xsp) }
38func (c *context) lr() uintptr { return uintptr(c.x[30]) }
39
40func (c *context) set_ip(x uintptr) { c.pc = uint64(x) }
41func (c *context) set_sp(x uintptr) { c.xsp = uint64(x) }
42func (c *context) set_lr(x uintptr) { c.x[30] = uint64(x) }
43
44func dumpregs(r *context) {
45	print("r0   ", hex(r.x[0]), "\n")
46	print("r1   ", hex(r.x[1]), "\n")
47	print("r2   ", hex(r.x[2]), "\n")
48	print("r3   ", hex(r.x[3]), "\n")
49	print("r4   ", hex(r.x[4]), "\n")
50	print("r5   ", hex(r.x[5]), "\n")
51	print("r6   ", hex(r.x[6]), "\n")
52	print("r7   ", hex(r.x[7]), "\n")
53	print("r8   ", hex(r.x[8]), "\n")
54	print("r9   ", hex(r.x[9]), "\n")
55	print("r10  ", hex(r.x[10]), "\n")
56	print("r11  ", hex(r.x[11]), "\n")
57	print("r12  ", hex(r.x[12]), "\n")
58	print("r13  ", hex(r.x[13]), "\n")
59	print("r14  ", hex(r.x[14]), "\n")
60	print("r15  ", hex(r.x[15]), "\n")
61	print("r16  ", hex(r.x[16]), "\n")
62	print("r17  ", hex(r.x[17]), "\n")
63	print("r18  ", hex(r.x[18]), "\n")
64	print("r19  ", hex(r.x[19]), "\n")
65	print("r20  ", hex(r.x[20]), "\n")
66	print("r21  ", hex(r.x[21]), "\n")
67	print("r22  ", hex(r.x[22]), "\n")
68	print("r23  ", hex(r.x[23]), "\n")
69	print("r24  ", hex(r.x[24]), "\n")
70	print("r25  ", hex(r.x[25]), "\n")
71	print("r26  ", hex(r.x[26]), "\n")
72	print("r27  ", hex(r.x[27]), "\n")
73	print("r28  ", hex(r.x[28]), "\n")
74	print("r29  ", hex(r.x[29]), "\n")
75	print("lr   ", hex(r.x[30]), "\n")
76	print("sp   ", hex(r.xsp), "\n")
77	print("pc   ", hex(r.pc), "\n")
78	print("cpsr ", hex(r.cpsr), "\n")
79}
80
81func stackcheck() {
82	// TODO: not implemented on ARM
83}
84