]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm
StandaloneMmPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / UefiCpuPkg / ResetVector / Vtf0 / Ia16 / Real16ToFlat32.asm
CommitLineData
84a773d1 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; This program and the accompanying materials\r
7; are licensed and made available under the terms and conditions of the BSD License\r
8; which accompanies this distribution. The full text of the license may be found at\r
9; http://opensource.org/licenses/bsd-license.php\r
10;\r
11; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13;\r
14;------------------------------------------------------------------------------\r
15\r
16%define SEC_DEFAULT_CR0 0x40000023\r
17%define SEC_DEFAULT_CR4 0x640\r
18\r
19BITS 16\r
20\r
21;\r
22; Modified: EAX, EBX\r
23;\r
9f75aacc
LE
24; @param[out] DS Selector allowing flat access to all addresses\r
25; @param[out] ES Selector allowing flat access to all addresses\r
26; @param[out] FS Selector allowing flat access to all addresses\r
27; @param[out] GS Selector allowing flat access to all addresses\r
28; @param[out] SS Selector allowing flat access to all addresses\r
29;\r
84a773d1 30TransitionFromReal16To32BitFlat:\r
31\r
32 debugShowPostCode POSTCODE_16BIT_MODE\r
33\r
34 cli\r
35\r
36 mov bx, 0xf000\r
37 mov ds, bx\r
38\r
39 mov bx, ADDR16_OF(gdtr)\r
40\r
41o32 lgdt [cs:bx]\r
42\r
43 mov eax, SEC_DEFAULT_CR0\r
44 mov cr0, eax\r
45\r
46 jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)\r
47BITS 32\r
48jumpTo32BitAndLandHere:\r
49\r
50 mov eax, SEC_DEFAULT_CR4\r
51 mov cr4, eax\r
52\r
53 debugShowPostCode POSTCODE_32BIT_MODE\r
54\r
55 mov ax, LINEAR_SEL\r
56 mov ds, ax\r
57 mov es, ax\r
58 mov fs, ax\r
59 mov gs, ax\r
60 mov ss, ax\r
61\r
62 OneTimeCallRet TransitionFromReal16To32BitFlat\r
63\r
64ALIGN 2\r
65\r
66gdtr:\r
67 dw GDT_END - GDT_BASE - 1 ; GDT limit\r
68 dd ADDR_OF(GDT_BASE)\r
69\r
70ALIGN 16\r
71\r
72;\r
73; Macros for GDT entries\r
74;\r
75\r
76%define PRESENT_FLAG(p) (p << 7)\r
77%define DPL(dpl) (dpl << 5)\r
78%define SYSTEM_FLAG(s) (s << 4)\r
79%define DESC_TYPE(t) (t)\r
80\r
81; Type: data, expand-up, writable, accessed\r
82%define DATA32_TYPE 3\r
83\r
84; Type: execute, readable, expand-up, accessed\r
85%define CODE32_TYPE 0xb\r
86\r
87; Type: execute, readable, expand-up, accessed\r
88%define CODE64_TYPE 0xb\r
89\r
90%define GRANULARITY_FLAG(g) (g << 7)\r
91%define DEFAULT_SIZE32(d) (d << 6)\r
92%define CODE64_FLAG(l) (l << 5)\r
93%define UPPER_LIMIT(l) (l)\r
94\r
95;\r
96; The Global Descriptor Table (GDT)\r
97;\r
98\r
99GDT_BASE:\r
100; null descriptor\r
101NULL_SEL equ $-GDT_BASE\r
102 DW 0 ; limit 15:0\r
103 DW 0 ; base 15:0\r
104 DB 0 ; base 23:16\r
105 DB 0 ; sys flag, dpl, type\r
106 DB 0 ; limit 19:16, flags\r
107 DB 0 ; base 31:24\r
108\r
109; linear data segment descriptor\r
110LINEAR_SEL equ $-GDT_BASE\r
111 DW 0xffff ; limit 15:0\r
112 DW 0 ; base 15:0\r
113 DB 0 ; base 23:16\r
114 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)\r
115 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)\r
116 DB 0 ; base 31:24\r
117\r
118; linear code segment descriptor\r
119LINEAR_CODE_SEL equ $-GDT_BASE\r
120 DW 0xffff ; limit 15:0\r
121 DW 0 ; base 15:0\r
122 DB 0 ; base 23:16\r
123 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)\r
124 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)\r
125 DB 0 ; base 31:24\r
126\r
127%ifdef ARCH_X64\r
128; linear code (64-bit) segment descriptor\r
129LINEAR_CODE64_SEL equ $-GDT_BASE\r
130 DW 0xffff ; limit 15:0\r
131 DW 0 ; base 15:0\r
132 DB 0 ; base 23:16\r
133 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)\r
134 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)\r
135 DB 0 ; base 31:24\r
136%endif\r
137\r
138GDT_END:\r
139\r