Debian Codegraph @

src/arch/x86/thread_switch_64.S

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 /*
4 * Stack layout after pushing all the registers.
5 * +------------+
6 * | ret addr | <-- esp + 0x78
7 * +------------+
8 * | rax | <-- esp + 0x70
9 * +------------+
10 * | rcx | <-- esp + 0x68
11 * +------------+
12 * | rdx | <-- esp + 0x60
13 * +------------+
14 * | rbx | <-- esp + 0x58
15 * +------------+
16 * | rbp | <-- esp + 0x50
17 * +------------+
18 * | rsi | <-- esp + 0x48
19 * +------------+
20 * | rdi | <-- esp + 0x40
21 * +------------+
22 * | r8 | <-- esp + 0x38
23 * +------------+
24 * | r9 | <-- esp + 0x30
25 * +------------+
26 * | r10 | <-- esp + 0x28
27 * +------------+
28 * | r11 | <-- esp + 0x20
29 * +------------+
30 * | r12 | <-- esp + 0x18
31 * +------------+
32 * | r13 | <-- esp + 0x10
33 * +------------+
34 * | r14 | <-- esp + 0x08
35 * +------------+
36 * | r15 | <-- esp + 0x00
37 * +------------+
38 */
39 .global switch_to_thread
40 switch_to_thread:
41 /* Backup registers. */
42 push %rax
43 push %rcx
44 push %rdx
45 push %rbx
46
47 push %rbp
48 push %rsi
49 push %rdi
50
51 push %r8
52 push %r9
53 push %r10
54 push %r11
55 push %r12
56 push %r13
57 push %r14
58 push %r15
59
60 /* Save the current stack */
61 mov %rsp, (%rsi)
62
63 /* Switch to the new stack. */
64 mov %rdi, %rsp
65
66 /* Restore registers. */
67 pop %r15
68 pop %r14
69 pop %r13
70 pop %r12
71 pop %r11
72 pop %r10
73 pop %r9
74 pop %r8
75
76 pop %rdi
77 pop %rsi
78 pop %rbp
79
80 pop %rbx
81 pop %rdx
82 pop %rcx
83 pop %rax
84
85 /* Done. */
86 ret