comparison libgo/runtime/go-context.S @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // Copyright 2019 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 // This provides a simplified version of getcontext and
6 // setcontext. They are like the corresponding functions
7 // in libc, but we only save/restore the callee-save
8 // registers and PC, SP. Unlike the libc functions, we
9 // don't save/restore the signal masks and floating point
10 // environment.
11
12 #if defined(__x86_64__) && defined(__linux__) && !defined(__CET__)
13
14 #define RBP_OFF (0*8)
15 #define RBX_OFF (1*8)
16 #define R12_OFF (2*8)
17 #define R13_OFF (3*8)
18 #define R14_OFF (4*8)
19 #define R15_OFF (5*8)
20 #define SP_OFF (6*8)
21 #define PC_OFF (7*8)
22
23 .globl __go_getcontext
24 .text
25 __go_getcontext:
26 movq %rbx, RBX_OFF(%rdi)
27 movq %rbp, RBP_OFF(%rdi)
28 movq %r12, R12_OFF(%rdi)
29 movq %r13, R13_OFF(%rdi)
30 movq %r14, R14_OFF(%rdi)
31 movq %r15, R15_OFF(%rdi)
32
33 movq (%rsp), %rax // return PC
34 movq %rax, PC_OFF(%rdi)
35 leaq 8(%rsp), %rax // the SP before pushing return PC
36 movq %rax, SP_OFF(%rdi)
37
38 ret
39
40 .globl __go_setcontext
41 .text
42 __go_setcontext:
43 movq RBX_OFF(%rdi), %rbx
44 movq RBP_OFF(%rdi), %rbp
45 movq R12_OFF(%rdi), %r12
46 movq R13_OFF(%rdi), %r13
47 movq R14_OFF(%rdi), %r14
48 movq R15_OFF(%rdi), %r15
49 movq SP_OFF(%rdi), %rsp
50 movq PC_OFF(%rdi), %rdx
51
52 jmp *%rdx
53
54 .globl __go_makecontext
55 .text
56 __go_makecontext:
57 addq %rcx, %rdx
58
59 // Align the SP, and push a dummy return address.
60 andq $~0xf, %rdx
61 subq $8, %rdx
62 movq $0, (%rdx)
63
64 movq %rdx, SP_OFF(%rdi)
65 movq %rsi, PC_OFF(%rdi)
66
67 ret
68
69 .section .note.GNU-split-stack,"",@progbits
70 .section .note.GNU-no-split-stack,"",@progbits
71
72 #endif
73
74 .section .note.GNU-stack,"",@progbits