Update the copyright notice format
[mirror_edk2.git] / UefiCpuPkg / ResetVector / Vtf0 / Ia16 / 16RealTo32Flat.asm
CommitLineData
bc252e8e
EB
1;------------------------------------------------------------------------------\r
2; @file\r
3; Transition from 16 bit real mode into 32 bit flat protected mode\r
4;\r
01a1c0fc
HT
5; Copyright (c) 2008 - 2010, Intel Corporation. All rights reserved.<BR>\r
6; This program and the accompanying materials\r
bc252e8e
EB
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
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
132GDT_END:\r
133\r