mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-11-14 10:31:59 +00:00
Move x86 architecture dependent per cpu data into a seperate structure and embeded it in per_cpu_region. caller could access architecture dependent member by using prefix 'arch.'. v2->v3: move whose_iwkey, profiling_info and tsc_suspend to x86 v1->v2: rebased on latest repo Tracked-On: #8801 Signed-off-by: hangliu1 <hang1.liu@intel.com> Reviewed-by: Wang, Yu1 <yu1.wang@intel.com> Reviewed-by: Liu, Yifan1 <yifan1.liu@intel.com> Reviewed-by: Chen, Jian Jun<jian.jun.chen@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
/*
|
|
* Copyright (C) 2018-2022 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include <types.h>
|
|
#include <asm/gdt.h>
|
|
#include <per_cpu.h>
|
|
|
|
static void set_tss_desc(struct tss_64_descriptor *desc,
|
|
uint64_t tss, size_t tss_limit, uint32_t type)
|
|
{
|
|
uint32_t u1, u2, u3;
|
|
uint32_t tss_hi_32 = (uint32_t)(tss >> 32U);
|
|
uint32_t tss_lo_32 = (uint32_t)tss;
|
|
|
|
u1 = tss_lo_32 << 16U;
|
|
u2 = tss_lo_32 & 0xFF000000U;
|
|
u3 = (tss_lo_32 & 0x00FF0000U) >> 16U;
|
|
|
|
|
|
desc->low32_value = u1 | (tss_limit & 0xFFFFU);
|
|
desc->base_addr_63_32 = tss_hi_32;
|
|
desc->high32_value = u2 | (type << 8U) | 0x8000U | u3;
|
|
}
|
|
|
|
static inline void load_gdt(struct host_gdt_descriptor *gdtr)
|
|
{
|
|
asm volatile ("lgdt %0" ::"m"(*gdtr));
|
|
}
|
|
|
|
void load_gdtr_and_tr(void)
|
|
{
|
|
struct host_gdt *gdt = &get_cpu_var(arch.gdt);
|
|
struct host_gdt_descriptor gdtr;
|
|
struct tss_64 *tss = &get_cpu_var(arch.tss);
|
|
|
|
/* first entry is not used */
|
|
gdt->rsvd = 0xAAAAAAAAAAAAAAAAUL;
|
|
/* ring 0 code sel descriptor */
|
|
gdt->code_segment_descriptor = 0x00Af9b000000ffffUL;
|
|
/* ring 0 data sel descriptor */
|
|
gdt->data_segment_descriptor = 0x00cf93000000ffffUL;
|
|
|
|
tss->ist1 = (uint64_t)get_cpu_var(arch.mc_stack) + CONFIG_STACK_SIZE;
|
|
tss->ist2 = (uint64_t)get_cpu_var(arch.df_stack) + CONFIG_STACK_SIZE;
|
|
tss->ist3 = (uint64_t)get_cpu_var(arch.sf_stack) + CONFIG_STACK_SIZE;
|
|
tss->ist4 = 0UL;
|
|
|
|
/* tss descriptor */
|
|
set_tss_desc(&gdt->host_gdt_tss_descriptors,
|
|
(uint64_t)tss, sizeof(struct tss_64), TSS_AVAIL);
|
|
|
|
gdtr.len = sizeof(struct host_gdt) - 1U;
|
|
gdtr.gdt = gdt;
|
|
|
|
load_gdt(&gdtr);
|
|
|
|
CPU_LTR_EXECUTE(HOST_GDT_RING0_CPU_TSS_SEL);
|
|
}
|