1 ;------------------------------------------------------------------------------
3 ; Transition from 16 bit real mode into 32 bit flat protected mode
5 ; Copyright (c) 2008 - 2010, Intel Corporation
6 ; All rights reserved. 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 TransitionFromReal16To32BitFlat:
26 debugShowPostCode POSTCODE_16BIT_MODE
33 mov bx, ADDR16_OF(gdtr)
37 mov eax, SEC_DEFAULT_CR0
40 jmp LINEAR_CODE_SEL:dword ADDR_OF(jumpTo32BitAndLandHere)
42 jumpTo32BitAndLandHere:
44 mov eax, SEC_DEFAULT_CR4
47 debugShowPostCode POSTCODE_32BIT_MODE
56 OneTimeCallRet TransitionFromReal16To32BitFlat
61 dw GDT_END - GDT_BASE - 1 ; GDT limit
67 ; Macros for GDT entries
70 %define PRESENT_FLAG(p) (p << 7)
71 %define DPL(dpl) (dpl << 5)
72 %define SYSTEM_FLAG(s) (s << 4)
73 %define DESC_TYPE(t) (t)
75 ; Type: data, expand-up, writable, accessed
78 ; Type: execute, readable, expand-up, accessed
79 %define CODE32_TYPE 0xb
81 ; Type: execute, readable, expand-up, accessed
82 %define CODE64_TYPE 0xb
84 %define GRANULARITY_FLAG(g) (g << 7)
85 %define DEFAULT_SIZE32(d) (d << 6)
86 %define CODE64_FLAG(l) (l << 5)
87 %define UPPER_LIMIT(l) (l)
90 ; The Global Descriptor Table (GDT)
95 NULL_SEL equ $-GDT_BASE
99 DB 0 ; sys flag, dpl, type
100 DB 0 ; limit 19:16, flags
103 ; linear data segment descriptor
104 LINEAR_SEL equ $-GDT_BASE
105 DW 0xffff ; limit 15:0
108 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(DATA32_TYPE)
109 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
112 ; linear code segment descriptor
113 LINEAR_CODE_SEL equ $-GDT_BASE
114 DW 0xffff ; limit 15:0
117 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE)
118 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(1)|CODE64_FLAG(0)|UPPER_LIMIT(0xf)
122 ; linear code (64-bit) segment descriptor
123 LINEAR_CODE64_SEL equ $-GDT_BASE
124 DW 0xffff ; limit 15:0
127 DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE64_TYPE)
128 DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(1)|UPPER_LIMIT(0xf)