]>
Commit | Line | Data |
---|---|---|
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 | |
14 | BITS 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 | |
25 | TransitionFromReal16To32BitFlat:\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 | |
36 | o32 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 | |
42 | BITS 32\r | |
43 | jumpTo32BitAndLandHere:\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 | |
57 | OneTimeCallRet TransitionFromReal16To32BitFlat\r | |
58 | \r | |
59 | ALIGN 2\r | |
60 | \r | |
61 | gdtr:\r | |
62 | dw GDT_END - GDT_BASE - 1 ; GDT limit\r | |
63 | dd ADDR_OF(GDT_BASE)\r | |
64 | \r | |
65 | ALIGN 16\r | |
66 | \r | |
67 | ;\r | |
68 | ; Macros for GDT entries\r | |
69 | ;\r | |
70 | \r | |
71 | %define PRESENT_FLAG(p) (p << 7)\r | |
72 | %define DPL(dpl) (dpl << 5)\r | |
73 | %define SYSTEM_FLAG(s) (s << 4)\r | |
74 | %define DESC_TYPE(t) (t)\r | |
75 | \r | |
76 | ; Type: data, expand-up, writable, accessed\r | |
77 | %define DATA32_TYPE 3\r | |
78 | \r | |
79 | ; Type: execute, readable, expand-up, accessed\r | |
80 | %define CODE32_TYPE 0xb\r | |
81 | \r | |
82 | ; Type: execute, readable, expand-up, accessed\r | |
83 | %define CODE64_TYPE 0xb\r | |
84 | \r | |
85 | %define GRANULARITY_FLAG(g) (g << 7)\r | |
86 | %define DEFAULT_SIZE32(d) (d << 6)\r | |
87 | %define CODE64_FLAG(l) (l << 5)\r | |
88 | %define UPPER_LIMIT(l) (l)\r | |
89 | \r | |
90 | ;\r | |
91 | ; The Global Descriptor Table (GDT)\r | |
92 | ;\r | |
93 | \r | |
94 | GDT_BASE:\r | |
95 | ; null descriptor\r | |
96 | NULL_SEL equ $-GDT_BASE\r | |
97 | DW 0 ; limit 15:0\r | |
98 | DW 0 ; base 15:0\r | |
99 | DB 0 ; base 23:16\r | |
100 | DB 0 ; sys flag, dpl, type\r | |
101 | DB 0 ; limit 19:16, flags\r | |
102 | DB 0 ; base 31:24\r | |
103 | \r | |
104 | ; linear data segment descriptor\r | |
105 | LINEAR_SEL equ $-GDT_BASE\r | |
106 | DW 0xffff ; limit 15:0\r | |
107 | DW 0 ; base 15:0\r | |
108 | DB 0 ; base 23:16\r | |
109 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)\r | |
110 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)\r | |
111 | DB 0 ; base 31:24\r | |
112 | \r | |
113 | ; linear code segment descriptor\r | |
114 | LINEAR_CODE_SEL equ $-GDT_BASE\r | |
115 | DW 0xffff ; limit 15:0\r | |
116 | DW 0 ; base 15:0\r | |
117 | DB 0 ; base 23:16\r | |
118 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)\r | |
119 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)\r | |
120 | DB 0 ; base 31:24\r | |
121 | \r | |
122 | %ifdef ARCH_X64\r | |
123 | ; linear code (64-bit) segment descriptor\r | |
124 | LINEAR_CODE64_SEL equ $-GDT_BASE\r | |
125 | DW 0xffff ; limit 15:0\r | |
126 | DW 0 ; base 15:0\r | |
127 | DB 0 ; base 23:16\r | |
128 | DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)\r | |
129 | DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)\r | |
130 | DB 0 ; base 31:24\r | |
131 | %endif\r | |
132 | \r | |
133 | GDT_END:\r | |
134 | \r |