From: Andrew Cooper Date: Mon, 18 Jan 2016 10:48:53 +0000 (+0000) Subject: Rework config.h and head_hvm.S for better paging separation X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=d05119a4679d4464fba6955937f31d0d2447c202;p=people%2Froyger%2Fxen-test-framework.git Rework config.h and head_hvm.S for better paging separation config.h is modified to turn CONFIG_ENV_$foo into the finer grain CONFIG_{PV,HVM}, CONFIG_PAGING_LEVELS and possibly CONFIG_PAGING_PAE. It then undefines the CONFIG_ENV_$foo #define, to prevent mistakes in regular code. Generation of environment_description is also moved into config.h, and it is extended to include paging information. head_hvm.S is then modified to use the finer grain #defines. Specifically, CR4.PAE is only set if CONFIG_PAGING_PAE, and CR3 and CR0.PG are only set if CONFIG_PAGING_LEVELS is greater than 0. The existing setting of CR0.PE is removed, as it is guaranteed always to be set. Signed-off-by: Andrew Cooper --- diff --git a/arch/x86/boot/head_hvm.S b/arch/x86/boot/head_hvm.S index eaa80d5..86909ac 100644 --- a/arch/x86/boot/head_hvm.S +++ b/arch/x86/boot/head_hvm.S @@ -5,36 +5,39 @@ #include #include - .code32 /* Always starts in 32bit flat mode. */ + .code32 /* Always starts in 32bit flat mode. */ +GLOBAL(_start) /* HVM common setup. */ - -/* HVM common setup for pae paging. */ -GLOBAL(_start) - - /* CR4.PAE = 1 */ +#ifdef CONFIG_PAGING_PAE /* CR4.PAE = 1 */ mov $X86_CR4_PAE, %eax mov %eax, %cr4 +#endif /* CONFIG_PAGING_PAE */ - /* CR3 = l?_???map */ -#ifdef __x86_64__ +#if CONFIG_PAGING_LEVELS > 0 /* CR3 = pagetable */ + +#if CONFIG_PAGING_LEVELS == 4 mov $l4_identmap, %eax -#else +#elif CONFIG_PAGING_LEVELS == 3 && defined CONFIG_PAGING_PAE mov $l3_paemap, %eax +#else +# error Bad paging mode #endif + mov %eax, %cr3 +#endif /* CONFIG_PAGING_LEVELS > 0 */ -#ifdef __x86_64__ - /* EFER.LME = 1 */ +#ifdef __x86_64__ /* EFER.LME = 1 */ mov $MSR_EFER, %ecx rdmsr bts $_EFER_LME, %eax wrmsr -#endif +#endif /* __x86_64__ */ - /* CR0.{PG,PE} = 1 */ +#if CONFIG_PAGING_LEVELS > 0 /* CR0.PG = 1 */ mov %cr0, %eax - or $(X86_CR0_PG | X86_CR0_PE), %eax + or $X86_CR0_PG, %eax mov %eax, %cr0 +#endif /* CONFIG_PAGING_LEVELS > 0 */ lgdt gdt_ptr diff --git a/arch/x86/setup.c b/arch/x86/setup.c index 4d092b9..e0cab47 100644 --- a/arch/x86/setup.c +++ b/arch/x86/setup.c @@ -15,23 +15,7 @@ */ uint8_t boot_stack[2 * PAGE_SIZE] __aligned(PAGE_SIZE); -const char *environment_description = -#if defined(CONFIG_PV) - "PV" -#elif defined(CONFIG_HVM) - "HVM" -#else -# error Bad Guest Type -#endif - -#if defined(__x86_64__) - " 64bit" -#elif defined(__i386__) - " 32bit" -#else -# error Bad Width -#endif - ; +const char *environment_description = ENVIRONMENT_DESCRIPTION; #ifdef CONFIG_PV /* Filled in by head_pv.S */ diff --git a/docs/mainpage.dox b/docs/mainpage.dox index eea5a07..c099ae3 100644 --- a/docs/mainpage.dox +++ b/docs/mainpage.dox @@ -42,7 +42,7 @@ To run tests: (see @ref errata first) # xl create test-pv64-example.cfg # cat /var/log/xen/console/guest-test-pv64-example.log --- Xen Test Framework --- - Environment: PV 64bit + Environment: PV 64bit (Long mode 4 levels) Hello World Test result: SUCCESS diff --git a/include/arch/x86/config.h b/include/arch/x86/config.h index 33fd848..48bdf30 100644 --- a/include/arch/x86/config.h +++ b/include/arch/x86/config.h @@ -1,10 +1,55 @@ +/** + * @file include/arch/x86/config.h + * Logic to split an environment into finer-grain @#define's + * + * Converts `CONFIG_ENV_$foo` into: + * - `CONFIG_PV` or `CONFIG_HVM` + * - `CONFIG_PAGING_LEVELS = $num` + * - Possibly `CONFIG_PAGING_PAE` + * + * The `CONFIG_ENV_$foo` is then undefined, to prevent its use in general code. + */ #ifndef XTF_X86_CONFIG_H #define XTF_X86_CONFIG_H -#if defined(CONFIG_ENV_pv64) || defined(CONFIG_ENV_pv32pae) -# define CONFIG_PV -#elif defined(CONFIG_ENV_hvm64) || defined(CONFIG_ENV_hvm32pae) -# define CONFIG_HVM +#if defined(CONFIG_ENV_pv64) + +#define CONFIG_PV +#define CONFIG_PAGING_LEVELS 4 +#define CONFIG_PAGING_PAE +#define ENVIRONMENT_DESCRIPTION "PV 64bit (Long mode 4 levels)" + +#undef CONFIG_ENV_pv64 + +#elif defined(CONFIG_ENV_pv32pae) + +#define CONFIG_PV +#define CONFIG_PAGING_LEVELS 3 +#define CONFIG_PAGING_PAE +#define ENVIRONMENT_DESCRIPTION "PV 32bit (PAE 3 levels)" + +#undef CONFIG_ENV_pv32pae + +#elif defined(CONFIG_ENV_hvm64) + +#define CONFIG_HVM +#define CONFIG_PAGING_LEVELS 4 +#define CONFIG_PAGING_PAE +#define ENVIRONMENT_DESCRIPTION "HVM 64bit (Long mode 4 levels)" + +#undef CONFIG_ENV_hvm64 + +#elif defined(CONFIG_ENV_hvm32pae) + +#define CONFIG_HVM +#define CONFIG_PAGING_LEVELS 3 +#define CONFIG_PAGING_PAE +#define ENVIRONMENT_DESCRIPTION "HVM 32bit (PAE 3 levels)" + +#undef CONFIG_ENV_hvm32pae + +#else +# error Bad environment #endif #endif /* XTF_X86_CONFIG_H */