source: mainline/kernel/arch/amd64/src/context.S@ cb7be8f

Last change on this file since cb7be8f was cb7be8f, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Update headers in .S files that incorrectly use #-style comments

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2001-2004 Jakub Jermar
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <abi/asmtool.h>
8#include <arch/context_struct.h>
9#include <arch/vreg.h>
10
11.text
12
13## Save current CPU context
14#
15# Save CPU context to context_t variable
16# pointed by the 1st argument. Returns 1 in EAX.
17#
18FUNCTION_BEGIN(context_save_arch)
19 movq (%rsp), %rdx # the caller's return %rip
20
21 movq %rdx, CONTEXT_OFFSET_PC(%rdi)
22 movq %rsp, CONTEXT_OFFSET_SP(%rdi)
23
24 movq %rbx, CONTEXT_OFFSET_RBX(%rdi)
25 movq %rbp, CONTEXT_OFFSET_RBP(%rdi)
26 movq %r12, CONTEXT_OFFSET_R12(%rdi)
27 movq %r13, CONTEXT_OFFSET_R13(%rdi)
28 movq %r14, CONTEXT_OFFSET_R14(%rdi)
29 movq %r15, CONTEXT_OFFSET_R15(%rdi)
30
31#ifdef MEMORY_MODEL_large
32 movabsq $vreg_ptr, %rsi
33 movq (%rsi), %rsi
34#else
35 movq vreg_ptr, %rsi
36#endif
37 movq %fs:VREG_TP(%rsi), %rsi
38 movq %rsi, CONTEXT_OFFSET_TP(%rdi)
39
40 xorl %eax, %eax # context_save returns 1
41 incl %eax
42 ret
43FUNCTION_END(context_save_arch)
44
45
46## Restore current CPU context
47#
48# Restore CPU context from context_t variable
49# pointed by the 1st argument. Returns 0 in EAX.
50#
51FUNCTION_BEGIN(context_restore_arch)
52 movq CONTEXT_OFFSET_R15(%rdi), %r15
53 movq CONTEXT_OFFSET_R14(%rdi), %r14
54 movq CONTEXT_OFFSET_R13(%rdi), %r13
55 movq CONTEXT_OFFSET_R12(%rdi), %r12
56 movq CONTEXT_OFFSET_RBP(%rdi), %rbp
57 movq CONTEXT_OFFSET_RBX(%rdi), %rbx
58
59 movq CONTEXT_OFFSET_SP(%rdi), %rsp
60
61 movq CONTEXT_OFFSET_PC(%rdi), %rdx
62 movq %rdx, (%rsp)
63
64 movq CONTEXT_OFFSET_TP(%rdi), %rcx
65#ifdef MEMORY_MODEL_large
66 movabsq $vreg_ptr, %rsi
67 movq (%rsi), %rsi
68#else
69 movq vreg_ptr, %rsi
70#endif
71 movq %rcx, %fs:VREG_TP(%rsi)
72
73 xorl %eax, %eax # context_restore returns 0
74 ret
75FUNCTION_END(context_restore_arch)
76
Note: See TracBrowser for help on using the repository browser.