1 ;------------------------------------------------------------------------------
3 ; Transition from 16 bit real mode into 32 bit flat protected mode
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
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.
14 ;------------------------------------------------------------------------------
16 %define SEC_DEFAULT_CR0 0x40000023
17 %define SEC_DEFAULT_CR4 0x640
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
30 TransitionFromReal16To32BitFlat:
32 debugShowPostCode POSTCODE_16BIT_MODE
39 mov bx, ADDR16_OF(gdtr)
43 mov eax, SEC_DEFAULT_CR0
46 jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)
48 jumpTo32BitAndLandHere:
50 mov eax, SEC_DEFAULT_CR4
53 debugShowPostCode POSTCODE_32BIT_MODE
62 OneTimeCallRet TransitionFromReal16To32BitFlat
67 dw GDT_END - GDT_BASE - 1 ; GDT limit
73 ; Macros for GDT entries
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)
81 ; Type: data, expand-up, writable, accessed
84 ; Type: execute, readable, expand-up, accessed
85 %define CODE32_TYPE 0xb
87 ; Type: execute, readable, expand-up, accessed
88 %define CODE64_TYPE 0xb
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)
96 ; The Global Descriptor Table (GDT)
101 NULL_SEL equ $-GDT_BASE
105 DB 0 ; sys flag, dpl, type
106 DB 0 ; limit 19:16, flags
109 ; linear data segment descriptor
110 LINEAR_SEL equ $-GDT_BASE
111 DW 0xffff ; limit 15:0
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)
118 ; linear code segment descriptor
119 LINEAR_CODE_SEL equ $-GDT_BASE
120 DW 0xffff ; limit 15:0
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)
128 ; linear code (64-bit) segment descriptor
129 LINEAR_CODE64_SEL equ $-GDT_BASE
130 DW 0xffff ; limit 15:0
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)