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