File: go-context.S

package info (click to toggle)
gcc-arm-none-eabi 15%3A14.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,099,328 kB
  • sloc: cpp: 3,627,108; ansic: 2,571,498; ada: 834,230; f90: 235,082; makefile: 79,231; asm: 74,984; xml: 51,692; exp: 39,736; sh: 33,298; objc: 15,629; python: 15,069; fortran: 14,429; pascal: 7,003; awk: 5,070; perl: 3,106; ml: 285; lisp: 253; lex: 204; haskell: 135
file content (74 lines) | stat: -rw-r--r-- 1,677 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// This provides a simplified version of getcontext and
// setcontext. They are like the corresponding functions
// in libc, but we only save/restore the callee-save
// registers and PC, SP. Unlike the libc functions, we
// don't save/restore the signal masks and floating point
// environment.

#if defined(__x86_64__) && defined(__linux__) && !defined(__CET__)

#define RBP_OFF	(0*8)
#define RBX_OFF	(1*8)
#define R12_OFF	(2*8)
#define R13_OFF	(3*8)
#define R14_OFF	(4*8)
#define R15_OFF	(5*8)
#define SP_OFF	(6*8)
#define PC_OFF	(7*8)

.globl __go_getcontext
.text
__go_getcontext:
	movq	%rbx, RBX_OFF(%rdi)
	movq	%rbp, RBP_OFF(%rdi)
	movq	%r12, R12_OFF(%rdi)
	movq	%r13, R13_OFF(%rdi)
	movq	%r14, R14_OFF(%rdi)
	movq	%r15, R15_OFF(%rdi)

	movq	(%rsp), %rax	// return PC
	movq	%rax, PC_OFF(%rdi)
	leaq	8(%rsp), %rax	// the SP before pushing return PC
	movq	%rax, SP_OFF(%rdi)

	ret

.globl __go_setcontext
.text
__go_setcontext:
	movq	RBX_OFF(%rdi), %rbx
	movq	RBP_OFF(%rdi), %rbp
	movq	R12_OFF(%rdi), %r12
	movq	R13_OFF(%rdi), %r13
	movq	R14_OFF(%rdi), %r14
	movq	R15_OFF(%rdi), %r15
	movq	SP_OFF(%rdi), %rsp
	movq	PC_OFF(%rdi), %rdx

	jmp	*%rdx

.globl __go_makecontext
.text
__go_makecontext:
	addq	%rcx, %rdx

	// Align the SP, and push a dummy return address.
	andq	$~0xf, %rdx
	subq	$8, %rdx
	movq	$0, (%rdx)

	movq	%rdx, SP_OFF(%rdi)
	movq	%rsi, PC_OFF(%rdi)

	ret

	.section	.note.GNU-split-stack,"",@progbits
	.section	.note.GNU-no-split-stack,"",@progbits

#endif

	.section	.note.GNU-stack,"",@progbits