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