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 0x200001 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 (0x200002).
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 = 0x200003
14
15type neon128 struct {
16	low  uint64
17	high int64
18}
19
20type context struct {
21	contextflags uint32
22	r0           uint32
23	r1           uint32
24	r2           uint32
25	r3           uint32
26	r4           uint32
27	r5           uint32
28	r6           uint32
29	r7           uint32
30	r8           uint32
31	r9           uint32
32	r10          uint32
33	r11          uint32
34	r12          uint32
35
36	spr  uint32
37	lrr  uint32
38	pc   uint32
39	cpsr uint32
40
41	fpscr   uint32
42	padding uint32
43
44	floatNeon [16]neon128
45
46	bvr      [8]uint32
47	bcr      [8]uint32
48	wvr      [1]uint32
49	wcr      [1]uint32
50	padding2 [2]uint32
51}
52
53func (c *context) ip() uintptr { return uintptr(c.pc) }
54func (c *context) sp() uintptr { return uintptr(c.spr) }
55func (c *context) lr() uintptr { return uintptr(c.lrr) }
56
57func (c *context) set_ip(x uintptr) { c.pc = uint32(x) }
58func (c *context) set_sp(x uintptr) { c.spr = uint32(x) }
59func (c *context) set_lr(x uintptr) { c.lrr = uint32(x) }
60
61func dumpregs(r *context) {
62	print("r0   ", hex(r.r0), "\n")
63	print("r1   ", hex(r.r1), "\n")
64	print("r2   ", hex(r.r2), "\n")
65	print("r3   ", hex(r.r3), "\n")
66	print("r4   ", hex(r.r4), "\n")
67	print("r5   ", hex(r.r5), "\n")
68	print("r6   ", hex(r.r6), "\n")
69	print("r7   ", hex(r.r7), "\n")
70	print("r8   ", hex(r.r8), "\n")
71	print("r9   ", hex(r.r9), "\n")
72	print("r10  ", hex(r.r10), "\n")
73	print("r11  ", hex(r.r11), "\n")
74	print("r12  ", hex(r.r12), "\n")
75	print("sp   ", hex(r.spr), "\n")
76	print("lr   ", hex(r.lrr), "\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