]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/ResetVector/Ia16/16RealTo32Flat.asm
Add initial version of Open Virtual Machine Firmware (OVMF) platform.
[mirror_edk2.git] / OvmfPkg / ResetVector / Ia16 / 16RealTo32Flat.asm
1 ;------------------------------------------------------------------------------
2 ;
3 ; Copyright (c) 2008, Intel Corporation
4 ; All rights reserved. This program and the accompanying materials
5 ; are licensed and made available under the terms and conditions of the BSD License
6 ; which accompanies this distribution. The full text of the license may be found at
7 ; http://opensource.org/licenses/bsd-license.php
8 ;
9 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 ;
12 ; Module Name:
13 ;
14 ; 16RealTo32Flat.asm
15 ;
16 ; Abstract:
17 ;
18 ; Transition from 16 bit real mode into 32 bit flat protected mode
19 ;
20 ;------------------------------------------------------------------------------
21
22 %define SEC_DEFAULT_CR0 0x40000023
23 %define SEC_DEFAULT_CR4 0x640
24
25 BITS 16
26
27 to32BitFlat:
28
29 writeToSerialPort '1'
30 writeToSerialPort '6'
31 writeToSerialPort ' '
32
33 cli
34
35 mov bx, 0xf000
36 mov ds, bx
37
38 mov bx, ADDR16_OF(gdtr)
39
40 o32 lgdt [bx]
41
42 mov eax, SEC_DEFAULT_CR0
43 mov cr0, eax
44
45 ; mov eax, cr0
46 ; or al, 1
47 ; mov cr0, eax
48
49 jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)
50 BITS 32
51 jumpTo32BitAndLandHere:
52
53 mov eax, SEC_DEFAULT_CR4
54 mov cr4, eax
55
56 writeToSerialPort '3'
57 writeToSerialPort '2'
58 writeToSerialPort ' '
59
60 mov ax, LINEAR_SEL
61 mov ds, ax
62 mov es, ax
63 mov fs, ax
64 mov gs, ax
65 mov ss, ax
66
67 jmp TransitionFrom16RealTo32FlatComplete
68
69 ALIGN 2
70
71 gdtr:
72 dw GDT_END - GDT_BASE - 1 ; GDT limit
73 dd ADDR_OF(GDT_BASE)
74
75 ALIGN 16
76
77 GDT_BASE:
78 ; null descriptor
79 NULL_SEL equ $-GDT_BASE
80 dw 0 ; limit 15:0
81 dw 0 ; base 15:0
82 db 0 ; base 23:16
83 db 0 ; type
84 db 0 ; limit 19:16, flags
85 db 0 ; base 31:24
86
87 ; linear data segment descriptor
88 LINEAR_SEL equ $-GDT_BASE
89 dw 0FFFFh ; limit 0xFFFFF
90 dw 0 ; base 0
91 db 0
92 db 092h ; present, ring 0, data, expand-up, writable
93 db 0CFh ; page-granular, 32-bit
94 db 0
95
96 ; linear code segment descriptor
97 LINEAR_CODE_SEL equ $-GDT_BASE
98 dw 0FFFFh ; limit 0xFFFFF
99 dw 0 ; base 0
100 db 0
101 db 09Ah ; present, ring 0, data, expand-up, writable
102 db 0CFh ; page-granular, 32-bit
103 db 0
104
105 ; system data segment descriptor
106 SYS_DATA_SEL equ $-GDT_BASE
107 dw 0FFFFh ; limit 0xFFFFF
108 dw 0 ; base 0
109 db 0
110 db 092h ; present, ring 0, data, expand-up, writable
111 db 0CFh ; page-granular, 32-bit
112 db 0
113
114 ; system code segment descriptor
115 SYS_CODE_SEL equ $-GDT_BASE
116 dw 0FFFFh ; limit 0xFFFFF
117 dw 0 ; base 0
118 db 0
119 db 09Ah ; present, ring 0, data, expand-up, writable
120 db 0CFh ; page-granular, 32-bit
121 db 0
122
123 ; spare segment descriptor
124 LINEAR_CODE64_SEL equ $-GDT_BASE
125 DW -1 ; LimitLow
126 DW 0 ; BaseLow
127 DB 0 ; BaseMid
128 DB 9bh
129 DB 0afh ; LimitHigh (CS.L=1, CS.D=0)
130 DB 0 ; BaseHigh
131
132 ; spare segment descriptor
133 SPARE4_SEL equ $-GDT_BASE
134 dw 0 ; limit 0xFFFFF
135 dw 0 ; base 0
136 db 0
137 db 0 ; present, ring 0, data, expand-up, writable
138 db 0 ; page-granular, 32-bit
139 db 0
140
141 ; spare segment descriptor
142 SPARE5_SEL equ $-GDT_BASE
143 dw 0 ; limit 0xFFFFF
144 dw 0 ; base 0
145 db 0
146 db 0 ; present, ring 0, data, expand-up, writable
147 db 0 ; page-granular, 32-bit
148 db 0
149
150 GDT_END:
151