Skip to content

Commit aa9af27

Browse files
JasonChenCJwenlingz
authored andcommitted
modularization: boot component
Boot component prepares the very basic platform boot env. It finally call into platform initilization entries: - bsp_boot_init & cpu_secondary_init for start up - or restore_s3_context for wakeup this patch is the final one, it did some code clean up and move some definition from vm0_boot.h to boot_context.h. after this patch, the boot component include files: arch/x86/boot/cpu_primary.S arch/x86/boot/trampoline.S arch/x86/boot/cpu_save_boot_ctx.S arch/x86/boot/idt.S boot/reloc.c boot/include/reloc.h include/arch/x86/boot/idt.h include/arch/x86/boot/boot_context.h Tracked-On: #1842 Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
1 parent b54f233 commit aa9af27

File tree

10 files changed

+68
-66
lines changed

10 files changed

+68
-66
lines changed

hypervisor/arch/x86/boot/cpu_primary.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7-
#include <cpu.h>
8-
#include <mmu.h>
9-
#include <gdt.h>
107
#include <idt.h>
11-
#include <msr.h>
128

139
/* NOTE:
1410
*

hypervisor/arch/x86/boot/cpu_save_boot_ctx.S

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7-
#include <vm0_boot.h>
7+
#include <boot_context.h>
88

99
.section entry, "ax"
1010
.align 8
@@ -13,7 +13,7 @@
1313
.global cpu_primary_save_32
1414
cpu_primary_save_32:
1515
/* save context from 32bit mode */
16-
lea vm0_boot_context, %eax
16+
lea boot_context, %eax
1717
sgdt BOOT_CTX_GDT_OFFSET(%eax)
1818
sidt BOOT_CTX_IDT_OFFSET(%eax)
1919
str BOOT_CTX_TR_SEL_OFFSET(%eax)
@@ -50,7 +50,7 @@ cpu_primary_save_32:
5050
.global cpu_primary_save_64
5151
cpu_primary_save_64:
5252
/* save context from 64bit mode */
53-
lea vm0_boot_context(%rip), %r8
53+
lea boot_context(%rip), %r8
5454
sgdt BOOT_CTX_GDT_OFFSET(%r8)
5555
sidt BOOT_CTX_IDT_OFFSET(%r8)
5656
str BOOT_CTX_TR_SEL_OFFSET(%r8)
@@ -90,8 +90,8 @@ cpu_primary_save_64:
9090

9191
.text
9292
.align 8
93-
.global vm0_boot_context
94-
vm0_boot_context:
93+
.global boot_context
94+
boot_context:
9595
.rept SIZE_OF_BOOT_CTX
9696
.byte 0x00
9797
.endr

hypervisor/arch/x86/boot/idt.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66

7-
#include <gdt.h>
87
#include <idt.h>
98

109
.altmacro

hypervisor/arch/x86/boot/trampoline.S

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
*/
1616

1717
#include <spinlock.h>
18-
#include <gdt.h>
19-
#include <cpu.h>
20-
#include <mmu.h>
21-
#include <msr.h>
2218

2319
/* NOTE:
2420
*
@@ -38,8 +34,6 @@
3834
*/
3935

4036
.extern cpu_secondary_init
41-
.extern ld_bss_end
42-
.extern HOST_GDTR
4337

4438
.section .trampoline_reset,"ax"
4539

hypervisor/arch/x86/static_checks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
66
#include <hypervisor.h>
7-
#include <vm0_boot.h>
7+
#include <boot_context.h>
88

99
#define CAT__(A,B) A ## B
1010
#define CAT_(A,B) CAT__(A,B)

hypervisor/bsp/uefi/uefi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <hypervisor.h>
88
#include <multiboot.h>
9+
#include <boot_context.h>
910
#include <vm0_boot.h>
1011

1112
#ifdef CONFIG_EFI_STUB
@@ -36,7 +37,7 @@ int uefi_sw_loader(struct acrn_vm *vm)
3637
{
3738
int ret = 0;
3839
struct acrn_vcpu *vcpu = get_primary_vcpu(vm);
39-
struct acrn_vcpu_regs *vcpu_regs = &vm0_boot_context;
40+
struct acrn_vcpu_regs *vcpu_regs = &boot_context;
4041

4142
ASSERT(vm != NULL, "Incorrect argument");
4243

@@ -47,8 +48,8 @@ int uefi_sw_loader(struct acrn_vm *vm)
4748
/* For UEFI platform, the bsp init regs come from two places:
4849
* 1. saved in efi_boot: gpregs, rip
4950
* 2. saved when HV started: other registers
50-
* We copy the info saved in efi_boot to vm0_boot_context and
51-
* init bsp with vm0_boot_context.
51+
* We copy the info saved in efi_boot to boot_context and
52+
* init bsp with boot_context.
5253
*/
5354
memcpy_s(&(vcpu_regs->gprs), sizeof(struct acrn_gp_regs),
5455
&(efi_ctx->vcpu_regs.gprs), sizeof(struct acrn_gp_regs));

hypervisor/common/vm_load.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <hypervisor.h>
88
#include <zeropage.h>
9+
#include <boot_context.h>
910

1011
#ifdef CONFIG_PARTITION_MODE
1112
static uint32_t create_e820_table(struct e820_entry *param_e820)
@@ -44,14 +45,14 @@ static void prepare_bsp_gdt(struct acrn_vm *vm)
4445
uint64_t gdt_base_hpa;
4546
void *gdt_base_hva;
4647

47-
gdt_base_hpa = gpa2hpa(vm, vm0_boot_context.gdt.base);
48-
if (vm0_boot_context.gdt.base == gdt_base_hpa) {
48+
gdt_base_hpa = gpa2hpa(vm, boot_context.gdt.base);
49+
if (boot_context.gdt.base == gdt_base_hpa) {
4950
return;
5051
} else {
5152
gdt_base_hva = hpa2hva(gdt_base_hpa);
52-
gdt_len = ((size_t)vm0_boot_context.gdt.limit + 1U)/sizeof(uint8_t);
53+
gdt_len = ((size_t)boot_context.gdt.limit + 1U)/sizeof(uint8_t);
5354

54-
(void )memcpy_s(gdt_base_hva, gdt_len, hpa2hva(vm0_boot_context.gdt.base), gdt_len);
55+
(void )memcpy_s(gdt_base_hva, gdt_len, hpa2hva(boot_context.gdt.base), gdt_len);
5556
}
5657

5758
return;
@@ -116,7 +117,7 @@ int general_sw_loader(struct acrn_vm *vm)
116117
pr_dbg("Loading guest to run-time location");
117118

118119
prepare_bsp_gdt(vm);
119-
set_vcpu_regs(vcpu, &vm0_boot_context);
120+
set_vcpu_regs(vcpu, &boot_context);
120121

121122
/* calculate the kernel entry point */
122123
zeropage = (struct zero_page *)sw_kernel->kernel_src_addr;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (C) 2018 Intel Corporation. All rights reserved.
3+
*
4+
* SPDX-License-Identifier: BSD-3-Clause
5+
*/
6+
7+
#ifndef BOOT_CTX_H
8+
#define BOOT_CTX_H
9+
10+
#ifdef ASSEMBLER
11+
#define BOOT_CTX_CR0_OFFSET 176
12+
#define BOOT_CTX_CR3_OFFSET 192
13+
#define BOOT_CTX_CR4_OFFSET 184
14+
#define BOOT_CTX_IDT_OFFSET 144
15+
#define BOOT_CTX_GDT_OFFSET 128
16+
#define BOOT_CTX_LDT_SEL_OFFSET 280
17+
#define BOOT_CTX_TR_SEL_OFFSET 282
18+
#define BOOT_CTX_CS_SEL_OFFSET 268
19+
#define BOOT_CTX_SS_SEL_OFFSET 270
20+
#define BOOT_CTX_DS_SEL_OFFSET 272
21+
#define BOOT_CTX_ES_SEL_OFFSET 274
22+
#define BOOT_CTX_FS_SEL_OFFSET 276
23+
#define BOOT_CTX_GS_SEL_OFFSET 278
24+
#define BOOT_CTX_CS_AR_OFFSET 248
25+
#define BOOT_CTX_CS_LIMIT_OFFSET 252
26+
#define BOOT_CTX_EFER_LOW_OFFSET 200
27+
#define BOOT_CTX_EFER_HIGH_OFFSET 204
28+
#define SIZE_OF_BOOT_CTX 296
29+
#else
30+
#define BOOT_CTX_CR0_OFFSET 176U
31+
#define BOOT_CTX_CR3_OFFSET 192U
32+
#define BOOT_CTX_CR4_OFFSET 184U
33+
#define BOOT_CTX_IDT_OFFSET 144U
34+
#define BOOT_CTX_GDT_OFFSET 128U
35+
#define BOOT_CTX_LDT_SEL_OFFSET 280U
36+
#define BOOT_CTX_TR_SEL_OFFSET 282U
37+
#define BOOT_CTX_CS_SEL_OFFSET 268U
38+
#define BOOT_CTX_SS_SEL_OFFSET 270U
39+
#define BOOT_CTX_DS_SEL_OFFSET 272U
40+
#define BOOT_CTX_ES_SEL_OFFSET 274U
41+
#define BOOT_CTX_FS_SEL_OFFSET 276U
42+
#define BOOT_CTX_GS_SEL_OFFSET 278U
43+
#define BOOT_CTX_CS_AR_OFFSET 248U
44+
#define BOOT_CTX_CS_LIMIT_OFFSET 252U
45+
#define BOOT_CTX_EFER_LOW_OFFSET 200U
46+
#define BOOT_CTX_EFER_HIGH_OFFSET 204U
47+
#define SIZE_OF_BOOT_CTX 296U
48+
struct acrn_vcpu_regs;
49+
extern struct acrn_vcpu_regs boot_context;
50+
#endif /* ASSEMBLER */
51+
#endif /* BOOT_CTX_H */

hypervisor/include/arch/x86/guest/guest.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ int copy_from_gva(struct acrn_vcpu *vcpu, void *h_ptr, uint64_t gva,
220220
*/
221221
int copy_to_gva(struct acrn_vcpu *vcpu, void *h_ptr, uint64_t gva,
222222
uint32_t size, uint32_t *err_code, uint64_t *fault_addr);
223-
extern struct acrn_vcpu_regs vm0_boot_context;
224223
/**
225224
* @}
226225
*/

hypervisor/include/arch/x86/guest/vm0_boot.h

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,6 @@
77
#ifndef VM0_BOOT_H
88
#define VM0_BOOT_H
99

10-
#ifdef ASSEMBLER
11-
#define BOOT_CTX_CR0_OFFSET 176
12-
#define BOOT_CTX_CR3_OFFSET 192
13-
#define BOOT_CTX_CR4_OFFSET 184
14-
#define BOOT_CTX_IDT_OFFSET 144
15-
#define BOOT_CTX_GDT_OFFSET 128
16-
#define BOOT_CTX_LDT_SEL_OFFSET 280
17-
#define BOOT_CTX_TR_SEL_OFFSET 282
18-
#define BOOT_CTX_CS_SEL_OFFSET 268
19-
#define BOOT_CTX_SS_SEL_OFFSET 270
20-
#define BOOT_CTX_DS_SEL_OFFSET 272
21-
#define BOOT_CTX_ES_SEL_OFFSET 274
22-
#define BOOT_CTX_FS_SEL_OFFSET 276
23-
#define BOOT_CTX_GS_SEL_OFFSET 278
24-
#define BOOT_CTX_CS_AR_OFFSET 248
25-
#define BOOT_CTX_CS_LIMIT_OFFSET 252
26-
#define BOOT_CTX_EFER_LOW_OFFSET 200
27-
#define BOOT_CTX_EFER_HIGH_OFFSET 204
28-
#define SIZE_OF_BOOT_CTX 296
29-
#else
30-
#define BOOT_CTX_CR0_OFFSET 176U
31-
#define BOOT_CTX_CR3_OFFSET 192U
32-
#define BOOT_CTX_CR4_OFFSET 184U
33-
#define BOOT_CTX_IDT_OFFSET 144U
34-
#define BOOT_CTX_GDT_OFFSET 128U
35-
#define BOOT_CTX_LDT_SEL_OFFSET 280U
36-
#define BOOT_CTX_TR_SEL_OFFSET 282U
37-
#define BOOT_CTX_CS_SEL_OFFSET 268U
38-
#define BOOT_CTX_SS_SEL_OFFSET 270U
39-
#define BOOT_CTX_DS_SEL_OFFSET 272U
40-
#define BOOT_CTX_ES_SEL_OFFSET 274U
41-
#define BOOT_CTX_FS_SEL_OFFSET 276U
42-
#define BOOT_CTX_GS_SEL_OFFSET 278U
43-
#define BOOT_CTX_CS_AR_OFFSET 248U
44-
#define BOOT_CTX_CS_LIMIT_OFFSET 252U
45-
#define BOOT_CTX_EFER_LOW_OFFSET 200U
46-
#define BOOT_CTX_EFER_HIGH_OFFSET 204U
47-
#define SIZE_OF_BOOT_CTX 296U
48-
4910
#ifdef CONFIG_EFI_STUB
5011
struct efi_context {
5112
struct acrn_vcpu_regs vcpu_regs;
@@ -56,5 +17,5 @@ struct efi_context {
5617
void *get_rsdp_from_uefi(void);
5718
void *get_ap_trampoline_buf(void);
5819
#endif
59-
#endif /* ASSEMBLER */
20+
6021
#endif /* VM0_BOOT_H */

0 commit comments

Comments
 (0)