2018-03-07 20:57:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
|
|
|
*
|
2018-05-26 01:49:13 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2018-03-07 20:57:14 +08:00
|
|
|
*/
|
|
|
|
|
2018-05-22 08:30:50 +08:00
|
|
|
#include <hypervisor.h>
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
static void set_tss_desc(union tss_64_descriptor *desc,
|
|
|
|
void *tss, int tss_limit, int type)
|
|
|
|
{
|
|
|
|
uint32_t u1, u2, u3;
|
|
|
|
|
2018-06-19 18:30:40 +08:00
|
|
|
u1 = (uint32_t)(((uint64_t)tss << 16U) & 0xFFFFFFFFU);
|
|
|
|
u2 = (uint32_t)((uint64_t)tss & 0xFF000000U);
|
|
|
|
u3 = (uint32_t)(((uint64_t)tss & 0x00FF0000U) >> 16U);
|
2018-03-07 20:57:14 +08:00
|
|
|
|
|
|
|
|
2018-06-19 18:30:40 +08:00
|
|
|
desc->fields.low32.value = u1 | (tss_limit & 0xFFFFU);
|
|
|
|
desc->fields.base_addr_63_32 = (uint32_t)((uint64_t)tss >> 32U);
|
|
|
|
desc->fields.high32.value = (u2 | ((uint32_t)type << 8U) | 0x8000U | u3);
|
2018-03-07 20:57:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void load_gdtr_and_tr(void)
|
|
|
|
{
|
|
|
|
struct host_gdt *gdt = &get_cpu_var(gdt);
|
|
|
|
struct host_gdt_descriptor gdtr;
|
|
|
|
struct tss_64 *tss = &get_cpu_var(tss);
|
|
|
|
|
|
|
|
/* first entry is not used */
|
2018-06-19 18:30:40 +08:00
|
|
|
gdt->rsvd = 0xAAAAAAAAAAAAAAAAUL;
|
2018-03-07 20:57:14 +08:00
|
|
|
/* ring 0 code sel descriptor */
|
2018-06-19 18:30:40 +08:00
|
|
|
gdt->host_gdt_code_descriptor.value = 0x00Af9b000000ffffUL;
|
2018-03-07 20:57:14 +08:00
|
|
|
/* ring 0 data sel descriptor */
|
2018-06-19 18:30:40 +08:00
|
|
|
gdt->host_gdt_data_descriptor.value = 0x00cf93000000ffffUL;
|
2018-03-07 20:57:14 +08:00
|
|
|
|
2018-05-22 23:24:07 +08:00
|
|
|
tss->ist1 = (uint64_t)get_cpu_var(mc_stack) + CONFIG_STACK_SIZE;
|
|
|
|
tss->ist2 = (uint64_t)get_cpu_var(df_stack) + CONFIG_STACK_SIZE;
|
|
|
|
tss->ist3 = (uint64_t)get_cpu_var(sf_stack) + CONFIG_STACK_SIZE;
|
2018-03-07 20:57:14 +08:00
|
|
|
tss->ist4 = 0L;
|
|
|
|
|
|
|
|
/* tss descriptor */
|
|
|
|
set_tss_desc(&gdt->host_gdt_tss_descriptors,
|
|
|
|
(void *)tss, sizeof(struct tss_64), TSS_AVAIL);
|
|
|
|
|
|
|
|
gdtr.len = sizeof(struct host_gdt) - 1;
|
|
|
|
gdtr.gdt = gdt;
|
|
|
|
|
|
|
|
asm volatile ("lgdt %0" ::"m"(gdtr));
|
|
|
|
|
|
|
|
CPU_LTR_EXECUTE(HOST_GDT_RING0_CPU_TSS_SEL);
|
|
|
|
}
|