]>
Commit | Line | Data |
---|---|---|
84a773d1 | 1 | ;------------------------------------------------------------------------------\r |
2 | ; @file\r | |
3 | ; Transition from 16 bit real mode into 32 bit flat protected mode\r | |
4 | ;\r | |
6acf7290 | 5 | ; Copyright (c) 2008 - 2022, 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 | |
13 | BITS 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 | 24 | TransitionFromReal16To32BitFlat:\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 | |
35 | o32 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 | |
41 | BITS 32\r | |
42 | jumpTo32BitAndLandHere:\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 | |
58 | ALIGN 2\r | |
59 | \r | |
60 | gdtr:\r | |
61 | dw GDT_END - GDT_BASE - 1 ; GDT limit\r | |
62 | dd ADDR_OF(GDT_BASE)\r | |
63 | \r | |
64 | ALIGN 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 | |
93 | GDT_BASE:\r | |
94 | ; null descriptor\r | |
6acf7290 | 95 | NULL_SEL equ $-GDT_BASE ; Selector [0x0]\r |
84a773d1 | 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 | |
6acf7290 KT |
103 | ; Spare segment descriptor\r |
104 | SPARE1_SEL equ $-GDT_BASE ; Selector [0x8]\r | |
105 | DW 0 ; limit 15:0\r | |
106 | DW 0 ; base 15:0\r | |
107 | DB 0 ; base 23:16\r | |
108 | DB 0 ; sys flag, dpl, type\r | |
109 | DB 0 ; limit 19:16, flags\r | |
110 | DB 0 ; base 31:24\r | |
111 | \r | |
112 | ; linear code segment descriptor\r | |
113 | LINEAR_CODE_SEL equ $-GDT_BASE ; Selector [0x10]\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) ; 09Bh\r | |
118 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf) ; 0CFh\r | |
119 | DB 0 ; base 31:24\r | |
120 | \r | |
84a773d1 | 121 | ; linear data segment descriptor\r |
6acf7290 | 122 | LINEAR_SEL equ $-GDT_BASE ; Selector [0x18]\r |
84a773d1 | 123 | DW 0xffff ; limit 15:0\r |
124 | DW 0 ; base 15:0\r | |
125 | DB 0 ; base 23:16\r | |
6acf7290 KT |
126 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE) ; 093h\r |
127 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf) ; 0CFh\r | |
84a773d1 | 128 | DB 0 ; base 31:24\r |
129 | \r | |
6acf7290 KT |
130 | ; Spare segment descriptor\r |
131 | SPARE2_SEL equ $-GDT_BASE ; Selector [0x20]\r | |
132 | DW 0 ; limit 15:0\r | |
133 | DW 0 ; base 15:0\r | |
134 | DB 0 ; base 23:16\r | |
135 | DB 0 ; sys flag, dpl, type\r | |
136 | DB 0 ; limit 19:16, flags\r | |
137 | DB 0 ; base 31:24\r | |
138 | \r | |
139 | ; linear code (16-bit) segment descriptor\r | |
140 | LINEAR_CODE16_SEL equ $-GDT_BASE ; Selector [0x28]\r | |
84a773d1 | 141 | DW 0xffff ; limit 15:0\r |
142 | DW 0 ; base 15:0\r | |
143 | DB 0 ; base 23:16\r | |
6acf7290 KT |
144 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE) ; 09Bh\r |
145 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIMIT(0xf) ; 08Fh\r | |
84a773d1 | 146 | DB 0 ; base 31:24\r |
147 | \r | |
6acf7290 KT |
148 | ; linear data (16-bit) segment descriptor\r |
149 | LINEAR_DATA16_SEL equ $-GDT_BASE ; Selector [0x30]\r | |
84a773d1 | 150 | DW 0xffff ; limit 15:0\r |
151 | DW 0 ; base 15:0\r | |
152 | DB 0 ; base 23:16\r | |
6acf7290 KT |
153 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE) ; 093h\r |
154 | DB 0\r | |
84a773d1 | 155 | DB 0 ; base 31:24\r |
84a773d1 | 156 | \r |
6acf7290 KT |
157 | ; linear code (64-bit) segment descriptor\r |
158 | LINEAR_CODE64_SEL equ $-GDT_BASE ; Selector [0x38]\r | |
0d7601e5 TL |
159 | DW 0xffff ; limit 15:0\r |
160 | DW 0 ; base 15:0\r | |
161 | DB 0 ; base 23:16\r | |
6acf7290 KT |
162 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE) ; 09Bh\r |
163 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf) ; 0AFh\r | |
0d7601e5 TL |
164 | DB 0 ; base 31:24\r |
165 | \r | |
84a773d1 | 166 | GDT_END:\r |
167 | \r |