diff options
Diffstat (limited to 'OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm')
-rw-r--r-- | OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm | 123 |
1 files changed, 58 insertions, 65 deletions
diff --git a/OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm b/OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm index d4416ce85e..adf049cf77 100644 --- a/OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm +++ b/OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm @@ -63,78 +63,71 @@ gdtr: 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 ; type
- db 0 ; limit 19:16, flags
- db 0 ; base 31:24
+ 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 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 093h ; present, ring 0, data, expand-up, writable, accessed
- db 0CFh ; page-granular, 32-bit
- db 0
+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 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Bh ; present, ring 0, data, expand-up, writable, accessed
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system data segment descriptor
-SYS_DATA_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 093h ; present, ring 0, data, expand-up, writable, accessed
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; system code segment descriptor
-SYS_CODE_SEL equ $-GDT_BASE
- dw 0FFFFh ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 09Bh ; present, ring 0, data, expand-up, writable, accessed
- db 0CFh ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-LINEAR_CODE64_SEL equ $-GDT_BASE
- DW -1 ; LimitLow
- DW 0 ; BaseLow
- DB 0 ; BaseMid
- DB 9bh
- DB 0afh ; LimitHigh (CS.L=1, CS.D=0)
- DB 0 ; BaseHigh
-
-; spare segment descriptor
-SPARE4_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
-
-; spare segment descriptor
-SPARE5_SEL equ $-GDT_BASE
- dw 0 ; limit 0xFFFFF
- dw 0 ; base 0
- db 0
- db 0 ; present, ring 0, data, expand-up, writable
- db 0 ; page-granular, 32-bit
- db 0
+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
GDT_END:
|