]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/XenResetVector/Ia16/Real16ToFlat32.asm
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / OvmfPkg / XenResetVector / Ia16 / Real16ToFlat32.asm
CommitLineData
c05de360
AP
1;------------------------------------------------------------------------------\r
2; @file\r
3; Transition from 16 bit real mode into 32 bit flat protected mode\r
4;\r
5; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
6; Copyright (c) 2019, Citrix Systems, Inc.\r
7; SPDX-License-Identifier: BSD-2-Clause-Patent\r
8;\r
9;------------------------------------------------------------------------------\r
10\r
11%define SEC_DEFAULT_CR0 0x00000023\r
12%define SEC_DEFAULT_CR4 0x640\r
13\r
14BITS 16\r
15\r
16;\r
17; Modified: EAX, EBX\r
18;\r
19; @param[out] DS Selector allowing flat access to all addresses\r
20; @param[out] ES Selector allowing flat access to all addresses\r
21; @param[out] FS Selector allowing flat access to all addresses\r
22; @param[out] GS Selector allowing flat access to all addresses\r
23; @param[out] SS Selector allowing flat access to all addresses\r
24;\r
25TransitionFromReal16To32BitFlat:\r
26\r
27 debugShowPostCode POSTCODE_16BIT_MODE\r
28\r
29 cli\r
30\r
31 mov bx, 0xf000\r
32 mov ds, bx\r
33\r
34 mov bx, ADDR16_OF(gdtr)\r
35\r
36o32 lgdt [cs:bx]\r
37\r
38 mov eax, SEC_DEFAULT_CR0\r
39 mov cr0, eax\r
40\r
41 jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)\r
42BITS 32\r
43jumpTo32BitAndLandHere:\r
44\r
45 mov eax, SEC_DEFAULT_CR4\r
46 mov cr4, eax\r
47\r
48 debugShowPostCode POSTCODE_32BIT_MODE\r
49\r
50 mov ax, LINEAR_SEL\r
51 mov ds, ax\r
52 mov es, ax\r
53 mov fs, ax\r
54 mov gs, ax\r
55 mov ss, ax\r
56\r
f198e254
AP
57 ; parameter for Flat32SearchForBfvBase\r
58 xor eax, eax ; Start searching from top of 4GB for BfvBase\r
59\r
c05de360
AP
60 OneTimeCallRet TransitionFromReal16To32BitFlat\r
61\r
62ALIGN 2\r
63\r
64gdtr:\r
65 dw GDT_END - GDT_BASE - 1 ; GDT limit\r
66 dd ADDR_OF(GDT_BASE)\r
67\r
68ALIGN 16\r
69\r
70;\r
71; Macros for GDT entries\r
72;\r
73\r
74%define PRESENT_FLAG(p) (p << 7)\r
75%define DPL(dpl) (dpl << 5)\r
76%define SYSTEM_FLAG(s) (s << 4)\r
77%define DESC_TYPE(t) (t)\r
78\r
79; Type: data, expand-up, writable, accessed\r
80%define DATA32_TYPE 3\r
81\r
82; Type: execute, readable, expand-up, accessed\r
83%define CODE32_TYPE 0xb\r
84\r
85; Type: execute, readable, expand-up, accessed\r
86%define CODE64_TYPE 0xb\r
87\r
88%define GRANULARITY_FLAG(g) (g << 7)\r
89%define DEFAULT_SIZE32(d) (d << 6)\r
90%define CODE64_FLAG(l) (l << 5)\r
91%define UPPER_LIMIT(l) (l)\r
92\r
93;\r
94; The Global Descriptor Table (GDT)\r
95;\r
96\r
97GDT_BASE:\r
98; null descriptor\r
99NULL_SEL equ $-GDT_BASE\r
100 DW 0 ; limit 15:0\r
101 DW 0 ; base 15:0\r
102 DB 0 ; base 23:16\r
103 DB 0 ; sys flag, dpl, type\r
104 DB 0 ; limit 19:16, flags\r
105 DB 0 ; base 31:24\r
106\r
107; linear data segment descriptor\r
108LINEAR_SEL equ $-GDT_BASE\r
109 DW 0xffff ; limit 15:0\r
110 DW 0 ; base 15:0\r
111 DB 0 ; base 23:16\r
112 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)\r
113 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)\r
114 DB 0 ; base 31:24\r
115\r
116; linear code segment descriptor\r
117LINEAR_CODE_SEL equ $-GDT_BASE\r
118 DW 0xffff ; limit 15:0\r
119 DW 0 ; base 15:0\r
120 DB 0 ; base 23:16\r
121 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)\r
122 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)\r
123 DB 0 ; base 31:24\r
124\r
125%ifdef ARCH_X64\r
126; linear code (64-bit) segment descriptor\r
127LINEAR_CODE64_SEL equ $-GDT_BASE\r
128 DW 0xffff ; limit 15:0\r
129 DW 0 ; base 15:0\r
130 DB 0 ; base 23:16\r
131 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)\r
132 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)\r
133 DB 0 ; base 31:24\r
134%endif\r
135\r
136GDT_END:\r
137\r