From 72f9c9a26ed107d07d50637b9f0c036281b29ee7 Mon Sep 17 00:00:00 2001 From: Jason Chen CJ Date: Thu, 2 Aug 2018 00:45:42 +0800 Subject: [PATCH] pm: use cpu_context for s3 save/restore use structure cpu_context and update offsets in wakeup.S Signed-off-by: Jason Chen CJ --- hypervisor/arch/x86/pm.c | 2 +- hypervisor/arch/x86/wakeup.S | 46 ++++++++++++++++-------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/hypervisor/arch/x86/pm.c b/hypervisor/arch/x86/pm.c index cebeee0e6..f65a1bbc2 100644 --- a/hypervisor/arch/x86/pm.c +++ b/hypervisor/arch/x86/pm.c @@ -5,7 +5,7 @@ #include #include -struct run_context cpu_ctx; +struct cpu_context cpu_ctx; /* whether the host enter s3 success */ uint8_t host_enter_s3_success = 1U; diff --git a/hypervisor/arch/x86/wakeup.S b/hypervisor/arch/x86/wakeup.S index df97d9211..c7d56e475 100644 --- a/hypervisor/arch/x86/wakeup.S +++ b/hypervisor/arch/x86/wakeup.S @@ -68,25 +68,25 @@ __enter_s3: movq %r15, 0x78 + cpu_ctx(%rip) pushfq - /*168U=0xa8=CPU_CONTEXT_OFFSET_RFLAGS*/ - popq 0xa8 + cpu_ctx(%rip) + /*160U=0xa0=CPU_CONTEXT_OFFSET_RFLAGS*/ + popq 0xa0 + cpu_ctx(%rip) - /*504U=0x1f8=CPU_CONTEXT_OFFSET_IDTR*/ - sidt 0x1f8 + cpu_ctx(%rip) - /*536U=0x218=CPU_CONTEXT_OFFSET_LDTR*/ - sldt 0x218 + cpu_ctx(%rip) + /*192U=0xc0=CPU_CONTEXT_OFFSET_IDTR*/ + sidt 0xc0 + cpu_ctx(%rip) + /*216U=0xd8=CPU_CONTEXT_OFFSET_LDTR*/ + sldt 0xd8 + cpu_ctx(%rip) mov %cr0, %rax /*128U=0x80=CPU_CONTEXT_OFFSET_CR0*/ mov %rax, 0x80 + cpu_ctx(%rip) mov %cr3, %rax - /*144U=0x90=CPU_CONTEXT_OFFSET_CR3*/ - mov %rax, 0x90 + cpu_ctx(%rip) + /*184U=0xb8=CPU_CONTEXT_OFFSET_CR3*/ + mov %rax, 0xb8 + cpu_ctx(%rip) mov %cr4, %rax - /*152U=0x98=CPU_CONTEXT_OFFSET_CR4*/ - mov %rax, 0x98 + cpu_ctx(%rip) + /*144U=0x90=CPU_CONTEXT_OFFSET_CR4*/ + mov %rax, 0x90 + cpu_ctx(%rip) wbinvd @@ -113,32 +113,28 @@ __enter_s3: */ .global restore_s3_context restore_s3_context: - /*152U=0x98=CPU_CONTEXT_OFFSET_CR4*/ - mov 0x98 + cpu_ctx(%rip), %rax + /*144U=0x90=CPU_CONTEXT_OFFSET_CR4*/ + mov 0x90 + cpu_ctx(%rip), %rax mov %rax, %cr4 - /*144U=0x90=CPU_CONTEXT_OFFSET_CR3*/ - mov 0x90 + cpu_ctx(%rip), %rax + /*184U=0xb8=CPU_CONTEXT_OFFSET_CR3*/ + mov 0xb8 + cpu_ctx(%rip), %rax mov %rax, %cr3 /*128U=0x80=CPU_CONTEXT_OFFSET_CR0*/ mov 0x80 + cpu_ctx(%rip), %rax mov %rax, %cr0 - /*504U=0x1f8=CPU_CONTEXT_OFFSET_IDTR*/ - lidt 0x1f8 + cpu_ctx(%rip) - /*536U=0x218=CPU_CONTEXT_OFFSET_LDTR*/ - lldt 0x218 + cpu_ctx(%rip) + /*192U=0xc0=CPU_CONTEXT_OFFSET_IDTR*/ + lidt 0xc0 + cpu_ctx(%rip) + /*216U=0xd8=CPU_CONTEXT_OFFSET_LDTR*/ + lldt 0xd8 + cpu_ctx(%rip) - /* - *312U=0x138=CPU_CONTEXT_OFFSET_SS - *32=0x20=CPU_CONTEXT_OFFSET_RSP - */ - mov 0x138 + cpu_ctx(%rip), %ss + /*32=0x20=CPU_CONTEXT_OFFSET_RSP*/ movq 0x20 + cpu_ctx(%rip), %rsp - /*168U=0xa8=CPU_CONTEXT_OFFSET_RFLAGS*/ - pushq 0xa8 + cpu_ctx(%rip) + /*160U=0xa0=CPU_CONTEXT_OFFSET_RFLAGS*/ + pushq 0xa0 + cpu_ctx(%rip) popfq call load_gdtr_and_tr