* [PATCH 1/1] OvmfPkg/Bhyve: Copy Real16ToFlat32.asm and enable cache in CR0
@ 2020-11-23 6:15 Rebecca Cran
2020-11-23 22:27 ` Peter Grehan
2020-11-24 0:03 ` Laszlo Ersek
0 siblings, 2 replies; 3+ messages in thread
From: Rebecca Cran @ 2020-11-23 6:15 UTC (permalink / raw)
To: devel
Cc: Rebecca Cran, Jordan Justen, Laszlo Ersek, Ard Biesheuvel,
Peter Grehan
Copy UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm to
OvmfPkg/Bhyve/ResetVector/Ia16, with one change, as has also been
made in XenResetVector:
- SEC_DEFAULT_CR0: enable cache (bit 30 or CD set to 0)
With the CD bit set to 1, this has the downside on AMD systems of
actually running with the cache disabled, which slows the entire system
to a crawl.
There's no need for this bit to be set in virtualized
environments.
This patch reapplies the change from the freebsd uefi-edk2 repo at
https://github.com/freebsd/uefi-edk2/commit/08c00f4e8d9e3e469bdc2ce92d3aa839cae7cf17
Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
---
.../Bhyve/ResetVector/Ia16/Real16ToFlat32.asm | 142 ++++++++++++++++++
1 file changed, 142 insertions(+)
create mode 100644 OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
diff --git a/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm b/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
new file mode 100644
index 000000000000..fe377ac842f4
--- /dev/null
+++ b/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
@@ -0,0 +1,142 @@
+;------------------------------------------------------------------------------
+; @file
+; Transition from 16 bit real mode into 32 bit flat protected mode
+;
+; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;
+;------------------------------------------------------------------------------
+
+%define SEC_DEFAULT_CR0 0x00000023
+%define SEC_DEFAULT_CR4 0x640
+
+BITS 16
+
+;
+; Modified: EAX, EBX
+;
+; @param[out] DS Selector allowing flat access to all addresses
+; @param[out] ES Selector allowing flat access to all addresses
+; @param[out] FS Selector allowing flat access to all addresses
+; @param[out] GS Selector allowing flat access to all addresses
+; @param[out] SS Selector allowing flat access to all addresses
+;
+TransitionFromReal16To32BitFlat:
+
+ debugShowPostCode POSTCODE_16BIT_MODE
+
+ cli
+
+ mov bx, 0xf000
+ mov ds, bx
+
+ mov bx, ADDR16_OF(gdtr)
+
+o32 lgdt [cs:bx]
+
+ mov eax, SEC_DEFAULT_CR0
+ mov cr0, eax
+
+ jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)
+BITS 32
+jumpTo32BitAndLandHere:
+
+ mov eax, SEC_DEFAULT_CR4
+ mov cr4, eax
+
+ debugShowPostCode POSTCODE_32BIT_MODE
+
+ mov ax, LINEAR_SEL
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ mov ss, ax
+
+ OneTimeCallRet TransitionFromReal16To32BitFlat
+
+ALIGN 2
+
+gdtr:
+ dw GDT_END - GDT_BASE - 1 ; GDT limit
+ dd ADDR_OF(GDT_BASE)
+
+ALIGN 16
+
+;
+; Macros for GDT entries
+;
+
+%define PRESENT_FLAG(p) (p << 7)
+%define DPL(dpl) (dpl << 5)
+%define SYSTEM_FLAG(s) (s << 4)
+%define DESC_TYPE(t) (t)
+
+; Type: data, expand-up, writable, accessed
+%define DATA32_TYPE 3
+
+; Type: execute, readable, expand-up, accessed
+%define CODE32_TYPE 0xb
+
+; Type: execute, readable, expand-up, accessed
+%define CODE64_TYPE 0xb
+
+%define GRANULARITY_FLAG(g) (g << 7)
+%define DEFAULT_SIZE32(d) (d << 6)
+%define CODE64_FLAG(l) (l << 5)
+%define UPPER_LIMIT(l) (l)
+
+;
+; The Global Descriptor Table (GDT)
+;
+
+GDT_BASE:
+; null descriptor
+NULL_SEL equ $-GDT_BASE
+ DW 0 ; limit 15:0
+ DW 0 ; base 15:0
+ DB 0 ; base 23:16
+ DB 0 ; sys flag, dpl, type
+ DB 0 ; limit 19:16, flags
+ DB 0 ; base 31:24
+
+; linear data segment descriptor
+LINEAR_SEL equ $-GDT_BASE
+ DW 0xffff ; limit 15:0
+ DW 0 ; base 15:0
+ DB 0 ; base 23:16
+ DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)
+ DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
+ DB 0 ; base 31:24
+
+; linear code segment descriptor
+LINEAR_CODE_SEL equ $-GDT_BASE
+ DW 0xffff ; limit 15:0
+ DW 0 ; base 15:0
+ DB 0 ; base 23:16
+ DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
+ DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
+ DB 0 ; base 31:24
+
+%ifdef ARCH_X64
+; linear code (64-bit) segment descriptor
+LINEAR_CODE64_SEL equ $-GDT_BASE
+ DW 0xffff ; limit 15:0
+ DW 0 ; base 15:0
+ DB 0 ; base 23:16
+ DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)
+ DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)
+ DB 0 ; base 31:24
+%endif
+
+; linear code segment descriptor
+LINEAR_CODE16_SEL equ $-GDT_BASE
+ DW 0xffff ; limit 15:0
+ DW 0 ; base 15:0
+ DB 0 ; base 23:16
+ DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
+ DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
+ DB 0 ; base 31:24
+
+GDT_END:
+
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] OvmfPkg/Bhyve: Copy Real16ToFlat32.asm and enable cache in CR0
2020-11-23 6:15 [PATCH 1/1] OvmfPkg/Bhyve: Copy Real16ToFlat32.asm and enable cache in CR0 Rebecca Cran
@ 2020-11-23 22:27 ` Peter Grehan
2020-11-24 0:03 ` Laszlo Ersek
1 sibling, 0 replies; 3+ messages in thread
From: Peter Grehan @ 2020-11-23 22:27 UTC (permalink / raw)
To: Rebecca Cran, devel; +Cc: Jordan Justen, Laszlo Ersek, Ard Biesheuvel
Reviewed-by: Peter Grehan <grehan@freebsd.org>
> Copy UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm to
> OvmfPkg/Bhyve/ResetVector/Ia16, with one change, as has also been
> made in XenResetVector:
>
> - SEC_DEFAULT_CR0: enable cache (bit 30 or CD set to 0)
>
> With the CD bit set to 1, this has the downside on AMD systems of
> actually running with the cache disabled, which slows the entire system
> to a crawl.
> There's no need for this bit to be set in virtualized
> environments.
>
> This patch reapplies the change from the freebsd uefi-edk2 repo at
> https://github.com/freebsd/uefi-edk2/commit/08c00f4e8d9e3e469bdc2ce92d3aa839cae7cf17
>
> Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
> ---
> .../Bhyve/ResetVector/Ia16/Real16ToFlat32.asm | 142 ++++++++++++++++++
> 1 file changed, 142 insertions(+)
> create mode 100644 OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
>
> diff --git a/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm b/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
> new file mode 100644
> index 000000000000..fe377ac842f4
> --- /dev/null
> +++ b/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
> @@ -0,0 +1,142 @@
> +;------------------------------------------------------------------------------
> +; @file
> +; Transition from 16 bit real mode into 32 bit flat protected mode
> +;
> +; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
> +; SPDX-License-Identifier: BSD-2-Clause-Patent
> +;
> +;------------------------------------------------------------------------------
> +
> +%define SEC_DEFAULT_CR0 0x00000023
> +%define SEC_DEFAULT_CR4 0x640
> +
> +BITS 16
> +
> +;
> +; Modified: EAX, EBX
> +;
> +; @param[out] DS Selector allowing flat access to all addresses
> +; @param[out] ES Selector allowing flat access to all addresses
> +; @param[out] FS Selector allowing flat access to all addresses
> +; @param[out] GS Selector allowing flat access to all addresses
> +; @param[out] SS Selector allowing flat access to all addresses
> +;
> +TransitionFromReal16To32BitFlat:
> +
> + debugShowPostCode POSTCODE_16BIT_MODE
> +
> + cli
> +
> + mov bx, 0xf000
> + mov ds, bx
> +
> + mov bx, ADDR16_OF(gdtr)
> +
> +o32 lgdt [cs:bx]
> +
> + mov eax, SEC_DEFAULT_CR0
> + mov cr0, eax
> +
> + jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)
> +BITS 32
> +jumpTo32BitAndLandHere:
> +
> + mov eax, SEC_DEFAULT_CR4
> + mov cr4, eax
> +
> + debugShowPostCode POSTCODE_32BIT_MODE
> +
> + mov ax, LINEAR_SEL
> + mov ds, ax
> + mov es, ax
> + mov fs, ax
> + mov gs, ax
> + mov ss, ax
> +
> + OneTimeCallRet TransitionFromReal16To32BitFlat
> +
> +ALIGN 2
> +
> +gdtr:
> + dw GDT_END - GDT_BASE - 1 ; GDT limit
> + dd ADDR_OF(GDT_BASE)
> +
> +ALIGN 16
> +
> +;
> +; Macros for GDT entries
> +;
> +
> +%define PRESENT_FLAG(p) (p << 7)
> +%define DPL(dpl) (dpl << 5)
> +%define SYSTEM_FLAG(s) (s << 4)
> +%define DESC_TYPE(t) (t)
> +
> +; Type: data, expand-up, writable, accessed
> +%define DATA32_TYPE 3
> +
> +; Type: execute, readable, expand-up, accessed
> +%define CODE32_TYPE 0xb
> +
> +; Type: execute, readable, expand-up, accessed
> +%define CODE64_TYPE 0xb
> +
> +%define GRANULARITY_FLAG(g) (g << 7)
> +%define DEFAULT_SIZE32(d) (d << 6)
> +%define CODE64_FLAG(l) (l << 5)
> +%define UPPER_LIMIT(l) (l)
> +
> +;
> +; The Global Descriptor Table (GDT)
> +;
> +
> +GDT_BASE:
> +; null descriptor
> +NULL_SEL equ $-GDT_BASE
> + DW 0 ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB 0 ; sys flag, dpl, type
> + DB 0 ; limit 19:16, flags
> + DB 0 ; base 31:24
> +
> +; linear data segment descriptor
> +LINEAR_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +
> +; linear code segment descriptor
> +LINEAR_CODE_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +
> +%ifdef ARCH_X64
> +; linear code (64-bit) segment descriptor
> +LINEAR_CODE64_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +%endif
> +
> +; linear code segment descriptor
> +LINEAR_CODE16_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +
> +GDT_END:
> +
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] OvmfPkg/Bhyve: Copy Real16ToFlat32.asm and enable cache in CR0
2020-11-23 6:15 [PATCH 1/1] OvmfPkg/Bhyve: Copy Real16ToFlat32.asm and enable cache in CR0 Rebecca Cran
2020-11-23 22:27 ` Peter Grehan
@ 2020-11-24 0:03 ` Laszlo Ersek
1 sibling, 0 replies; 3+ messages in thread
From: Laszlo Ersek @ 2020-11-24 0:03 UTC (permalink / raw)
To: Rebecca Cran, devel; +Cc: Jordan Justen, Ard Biesheuvel, Peter Grehan
On 11/23/20 07:15, Rebecca Cran wrote:
> Copy UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm to
> OvmfPkg/Bhyve/ResetVector/Ia16, with one change, as has also been
> made in XenResetVector:
>
> - SEC_DEFAULT_CR0: enable cache (bit 30 or CD set to 0)
>
> With the CD bit set to 1, this has the downside on AMD systems of
> actually running with the cache disabled, which slows the entire system
> to a crawl.
> There's no need for this bit to be set in virtualized
> environments.
>
> This patch reapplies the change from the freebsd uefi-edk2 repo at
> https://github.com/freebsd/uefi-edk2/commit/08c00f4e8d9e3e469bdc2ce92d3aa839cae7cf17
>
> Signed-off-by: Rebecca Cran <rebecca@bsdio.com>
> ---
> .../Bhyve/ResetVector/Ia16/Real16ToFlat32.asm | 142 ++++++++++++++++++
> 1 file changed, 142 insertions(+)
> create mode 100644 OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
>
> diff --git a/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm b/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
> new file mode 100644
> index 000000000000..fe377ac842f4
> --- /dev/null
> +++ b/OvmfPkg/Bhyve/ResetVector/Ia16/Real16ToFlat32.asm
> @@ -0,0 +1,142 @@
> +;------------------------------------------------------------------------------
> +; @file
> +; Transition from 16 bit real mode into 32 bit flat protected mode
> +;
> +; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>
> +; SPDX-License-Identifier: BSD-2-Clause-Patent
(1) Please prepend your copyright notice here.
With that:
Acked-by: Laszlo Ersek <lersek@redhat.com>
Meta-request: please collect all three patches in a series, and submit
them as a v2 *series* titled "various bhyve tweaks and updates". That's
going to make it *much* easier for me to merge the series.
Conceptually, this is of course not the right thing to do (you were
right to post the patches separately at first), but submitting a pull
request via github is so work intensive that I need to cut corners.
I'm not allowed to collect your separate patches into a single pull
request, but if you post them in a single round-up series, I'm allowed
to pick that up as-is. Of course it means that the patches need to be
correct at the same time; but for these three patches, that shouldn't be
a bug problem.
Thanks!
Laszlo
> +;
> +;------------------------------------------------------------------------------
> +
> +%define SEC_DEFAULT_CR0 0x00000023
> +%define SEC_DEFAULT_CR4 0x640
> +
> +BITS 16
> +
> +;
> +; Modified: EAX, EBX
> +;
> +; @param[out] DS Selector allowing flat access to all addresses
> +; @param[out] ES Selector allowing flat access to all addresses
> +; @param[out] FS Selector allowing flat access to all addresses
> +; @param[out] GS Selector allowing flat access to all addresses
> +; @param[out] SS Selector allowing flat access to all addresses
> +;
> +TransitionFromReal16To32BitFlat:
> +
> + debugShowPostCode POSTCODE_16BIT_MODE
> +
> + cli
> +
> + mov bx, 0xf000
> + mov ds, bx
> +
> + mov bx, ADDR16_OF(gdtr)
> +
> +o32 lgdt [cs:bx]
> +
> + mov eax, SEC_DEFAULT_CR0
> + mov cr0, eax
> +
> + jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)
> +BITS 32
> +jumpTo32BitAndLandHere:
> +
> + mov eax, SEC_DEFAULT_CR4
> + mov cr4, eax
> +
> + debugShowPostCode POSTCODE_32BIT_MODE
> +
> + mov ax, LINEAR_SEL
> + mov ds, ax
> + mov es, ax
> + mov fs, ax
> + mov gs, ax
> + mov ss, ax
> +
> + OneTimeCallRet TransitionFromReal16To32BitFlat
> +
> +ALIGN 2
> +
> +gdtr:
> + dw GDT_END - GDT_BASE - 1 ; GDT limit
> + dd ADDR_OF(GDT_BASE)
> +
> +ALIGN 16
> +
> +;
> +; Macros for GDT entries
> +;
> +
> +%define PRESENT_FLAG(p) (p << 7)
> +%define DPL(dpl) (dpl << 5)
> +%define SYSTEM_FLAG(s) (s << 4)
> +%define DESC_TYPE(t) (t)
> +
> +; Type: data, expand-up, writable, accessed
> +%define DATA32_TYPE 3
> +
> +; Type: execute, readable, expand-up, accessed
> +%define CODE32_TYPE 0xb
> +
> +; Type: execute, readable, expand-up, accessed
> +%define CODE64_TYPE 0xb
> +
> +%define GRANULARITY_FLAG(g) (g << 7)
> +%define DEFAULT_SIZE32(d) (d << 6)
> +%define CODE64_FLAG(l) (l << 5)
> +%define UPPER_LIMIT(l) (l)
> +
> +;
> +; The Global Descriptor Table (GDT)
> +;
> +
> +GDT_BASE:
> +; null descriptor
> +NULL_SEL equ $-GDT_BASE
> + DW 0 ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB 0 ; sys flag, dpl, type
> + DB 0 ; limit 19:16, flags
> + DB 0 ; base 31:24
> +
> +; linear data segment descriptor
> +LINEAR_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +
> +; linear code segment descriptor
> +LINEAR_CODE_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +
> +%ifdef ARCH_X64
> +; linear code (64-bit) segment descriptor
> +LINEAR_CODE64_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +%endif
> +
> +; linear code segment descriptor
> +LINEAR_CODE16_SEL equ $-GDT_BASE
> + DW 0xffff ; limit 15:0
> + DW 0 ; base 15:0
> + DB 0 ; base 23:16
> + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
> + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
> + DB 0 ; base 31:24
> +
> +GDT_END:
> +
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-11-24 0:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-23 6:15 [PATCH 1/1] OvmfPkg/Bhyve: Copy Real16ToFlat32.asm and enable cache in CR0 Rebecca Cran
2020-11-23 22:27 ` Peter Grehan
2020-11-24 0:03 ` Laszlo Ersek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox