|
| 1 | +/* |
| 2 | + * Copyright (C) <2018> Intel Corporation |
| 3 | + * SPDX-License-Identifier: BSD-3-Clause |
| 4 | + */ |
| 5 | +#include <vcpu.h> |
| 6 | + |
| 7 | + .text |
| 8 | + .align 8 |
| 9 | + .code64 |
| 10 | + .extern restore_msrs |
| 11 | + .extern cpu_ctx |
| 12 | + .extern load_gdtr_and_tr |
| 13 | + |
| 14 | + .global __enter_s3 |
| 15 | +__enter_s3: |
| 16 | + movq %rax, CPU_CONTEXT_OFFSET_RAX + cpu_ctx(%rip) |
| 17 | + movq %rbx, CPU_CONTEXT_OFFSET_RBX + cpu_ctx(%rip) |
| 18 | + movq %rcx, CPU_CONTEXT_OFFSET_RCX + cpu_ctx(%rip) |
| 19 | + movq %rdx, CPU_CONTEXT_OFFSET_RDX + cpu_ctx(%rip) |
| 20 | + movq %rdi, CPU_CONTEXT_OFFSET_RDI + cpu_ctx(%rip) |
| 21 | + movq %rsi, CPU_CONTEXT_OFFSET_RSI + cpu_ctx(%rip) |
| 22 | + movq %rbp, CPU_CONTEXT_OFFSET_RBP + cpu_ctx(%rip) |
| 23 | + movq %rsp, CPU_CONTEXT_OFFSET_RSP + cpu_ctx(%rip) |
| 24 | + movq %r8, CPU_CONTEXT_OFFSET_R8 + cpu_ctx(%rip) |
| 25 | + movq %r9, CPU_CONTEXT_OFFSET_R9 + cpu_ctx(%rip) |
| 26 | + movq %r10, CPU_CONTEXT_OFFSET_R10 + cpu_ctx(%rip) |
| 27 | + movq %r11, CPU_CONTEXT_OFFSET_R11 + cpu_ctx(%rip) |
| 28 | + movq %r12, CPU_CONTEXT_OFFSET_R12 + cpu_ctx(%rip) |
| 29 | + movq %r13, CPU_CONTEXT_OFFSET_R13 + cpu_ctx(%rip) |
| 30 | + movq %r14, CPU_CONTEXT_OFFSET_R14 + cpu_ctx(%rip) |
| 31 | + movq %r15, CPU_CONTEXT_OFFSET_R15 + cpu_ctx(%rip) |
| 32 | + |
| 33 | + pushfq |
| 34 | + popq CPU_CONTEXT_OFFSET_RFLAGS + cpu_ctx(%rip) |
| 35 | + |
| 36 | + sidt CPU_CONTEXT_OFFSET_IDTR + cpu_ctx(%rip) |
| 37 | + sldt CPU_CONTEXT_OFFSET_LDTR + cpu_ctx(%rip) |
| 38 | + |
| 39 | + mov %cr0, %rax |
| 40 | + mov %rax, CPU_CONTEXT_OFFSET_CR0 + cpu_ctx(%rip) |
| 41 | + |
| 42 | + mov %cr3, %rax |
| 43 | + mov %rax, CPU_CONTEXT_OFFSET_CR3 + cpu_ctx(%rip) |
| 44 | + |
| 45 | + mov %cr4, %rax |
| 46 | + mov %rax, CPU_CONTEXT_OFFSET_CR4 + cpu_ctx(%rip) |
| 47 | + |
| 48 | + wbinvd |
| 49 | + |
| 50 | + /* Will add the function call to enter Sx here*/ |
| 51 | + |
| 52 | + |
| 53 | +/* |
| 54 | + * When system resume from S3, trampoline_start64 will |
| 55 | + * jump to restore_s3_context after setup temporary stack. |
| 56 | + */ |
| 57 | +.global restore_s3_context |
| 58 | +restore_s3_context: |
| 59 | + mov CPU_CONTEXT_OFFSET_CR4 + cpu_ctx(%rip), %rax |
| 60 | + mov %rax, %cr4 |
| 61 | + |
| 62 | + mov CPU_CONTEXT_OFFSET_CR3 + cpu_ctx(%rip), %rax |
| 63 | + mov %rax, %cr3 |
| 64 | + |
| 65 | + mov CPU_CONTEXT_OFFSET_CR0 + cpu_ctx(%rip), %rax |
| 66 | + mov %rax, %cr0 |
| 67 | + |
| 68 | + lidt CPU_CONTEXT_OFFSET_IDTR + cpu_ctx(%rip) |
| 69 | + lldt CPU_CONTEXT_OFFSET_LDTR + cpu_ctx(%rip) |
| 70 | + |
| 71 | + mov CPU_CONTEXT_OFFSET_SS + cpu_ctx(%rip), %ss |
| 72 | + mov CPU_CONTEXT_OFFSET_RSP + cpu_ctx(%rip), %rsp |
| 73 | + |
| 74 | + pushq CPU_CONTEXT_OFFSET_RFLAGS + cpu_ctx(%rip) |
| 75 | + popfq |
| 76 | + |
| 77 | + call load_gdtr_and_tr |
| 78 | + call restore_msrs |
| 79 | + |
| 80 | + movq CPU_CONTEXT_OFFSET_RAX + cpu_ctx(%rip), %rax |
| 81 | + movq CPU_CONTEXT_OFFSET_RBX + cpu_ctx(%rip), %rbx |
| 82 | + movq CPU_CONTEXT_OFFSET_RCX + cpu_ctx(%rip), %rcx |
| 83 | + movq CPU_CONTEXT_OFFSET_RDX + cpu_ctx(%rip), %rdx |
| 84 | + movq CPU_CONTEXT_OFFSET_RDI + cpu_ctx(%rip), %rdi |
| 85 | + movq CPU_CONTEXT_OFFSET_RSI + cpu_ctx(%rip), %rsi |
| 86 | + movq CPU_CONTEXT_OFFSET_RBP + cpu_ctx(%rip), %rbp |
| 87 | + movq CPU_CONTEXT_OFFSET_R8 + cpu_ctx(%rip), %r8 |
| 88 | + movq CPU_CONTEXT_OFFSET_R9 + cpu_ctx(%rip), %r9 |
| 89 | + movq CPU_CONTEXT_OFFSET_R10 + cpu_ctx(%rip), %r10 |
| 90 | + movq CPU_CONTEXT_OFFSET_R11 + cpu_ctx(%rip), %r11 |
| 91 | + movq CPU_CONTEXT_OFFSET_R12 + cpu_ctx(%rip), %r12 |
| 92 | + movq CPU_CONTEXT_OFFSET_R13 + cpu_ctx(%rip), %r13 |
| 93 | + movq CPU_CONTEXT_OFFSET_R14 + cpu_ctx(%rip), %r14 |
| 94 | + movq CPU_CONTEXT_OFFSET_R15 + cpu_ctx(%rip), %r15 |
| 95 | + |
| 96 | + retq |
0 commit comments