• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1;; @file
2;  This is the code that goes from real-mode to protected mode.
3;  It consumes the reset vector, configures the stack.
4;
5; Copyright (c) 2015, 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 assembler characteristics
17;
18.586p
19.xmm
20.model flat, c
21
22EXTRN   TempRamInitApi:NEAR
23EXTRN   FspInitApi:NEAR
24
25;
26; Contrary to the name, this file contains 16 bit code as well.
27;
28_TEXT_REALMODE      SEGMENT PARA PUBLIC USE16 'CODE'
29                    ASSUME  CS:_TEXT_REALMODE, DS:_TEXT_REALMODE
30
31;----------------------------------------------------------------------------
32;
33; Procedure:    _ModuleEntryPoint
34;
35; Input:        None
36;
37; Output:       None
38;
39; Destroys:     Assume all registers
40;
41; Description:
42;
43;   Transition to non-paged flat-model protected mode from a
44;   hard-coded GDT that provides exactly two descriptors.
45;   This is a bare bones transition to protected mode only
46;   used for a while in PEI and possibly DXE.
47;
48;   After enabling protected mode, a far jump is executed to
49;   transfer to PEI using the newly loaded GDT.
50;
51; Return:       None
52;
53;----------------------------------------------------------------------------
54align 16
55_ModuleEntryPoint      PROC C PUBLIC
56  ;
57  ; Load the GDT table in GdtDesc
58  ;
59  mov     esi, OFFSET GdtDesc
60  db      66h
61  lgdt    fword ptr cs:[si]
62
63  ;
64  ; Transition to 16 bit protected mode
65  ;
66  mov     eax, cr0                   ; Get control register 0
67  or      eax, 00000003h             ; Set PE bit (bit #0) & MP bit (bit #1)
68  mov     cr0, eax                   ; Activate protected mode
69
70  ;
71  ; Now we're in 16 bit protected mode
72  ; Set up the selectors for 32 bit protected mode entry
73  ;
74  mov     ax, SYS_DATA_SEL
75  mov     ds, ax
76  mov     es, ax
77  mov     fs, ax
78  mov     gs, ax
79  mov     ss, ax
80
81  ;
82  ; Transition to Flat 32 bit protected mode
83  ; The jump to a far pointer causes the transition to 32 bit mode
84  ;
85  mov esi, offset ProtectedModeEntryLinearAddress
86  jmp     fword ptr cs:[si]
87
88_ModuleEntryPoint   ENDP
89
90_TEXT_REALMODE      ENDS
91
92.code
93;
94; Protected mode portion initializes stack, configures cache, and calls C entry point
95;
96
97;----------------------------------------------------------------------------
98;
99; Procedure:    ProtectedModeEntryPoint
100;
101; Input:        Executing in 32 Bit Protected (flat) mode
102;               cs: 0-4GB
103;               ds: 0-4GB
104;               es: 0-4GB
105;               fs: 0-4GB
106;               gs: 0-4GB
107;               ss: 0-4GB
108;
109; Output:       This function never returns
110;
111; Destroys:
112;               ecx
113;               edi
114;               esi
115;               esp
116;
117; Description:
118;               Perform any essential early platform initilaisation
119;               Setup a stack
120;
121;----------------------------------------------------------------------------
122
123ProtectedModeEntryPoint PROC NEAR C PUBLIC
124  ;
125  ; Dummy function. Consume 2 API to make sure they can be linked.
126  ;
127  mov  eax, TempRamInitApi
128  mov  eax, FspInitApi
129
130  ; Should never return
131  jmp  $
132
133ProtectedModeEntryPoint ENDP
134
135;
136; ROM-based Global-Descriptor Table for the PEI Phase
137;
138align 16
139PUBLIC  BootGdtTable
140
141;
142; GDT[0]: 0x00: Null entry, never used.
143;
144NULL_SEL        equ     $ - GDT_BASE        ; Selector [0]
145GDT_BASE:
146BootGdtTable    DD      0
147                DD      0
148;
149; Linear code segment descriptor
150;
151LINEAR_CODE_SEL equ     $ - GDT_BASE        ; Selector [0x8]
152        DW      0FFFFh                      ; limit 0xFFFF
153        DW      0                           ; base 0
154        DB      0
155        DB      09Bh                        ; present, ring 0, data, expand-up, not-writable
156        DB      0CFh                        ; page-granular, 32-bit
157        DB      0
158;
159; System data segment descriptor
160;
161SYS_DATA_SEL    equ     $ - GDT_BASE        ; Selector [0x10]
162        DW      0FFFFh                      ; limit 0xFFFF
163        DW      0                           ; base 0
164        DB      0
165        DB      093h                        ; present, ring 0, data, expand-up, not-writable
166        DB      0CFh                        ; page-granular, 32-bit
167        DB      0
168
169GDT_SIZE        EQU     $ - BootGDTtable    ; Size, in bytes
170
171;
172; GDT Descriptor
173;
174GdtDesc:                                    ; GDT descriptor
175        DW      GDT_SIZE - 1                ; GDT limit
176        DD      OFFSET BootGdtTable         ; GDT base address
177
178ProtectedModeEntryLinearAddress   LABEL   FWORD
179ProtectedModeEntryLinearOffset    LABEL   DWORD
180  DD      OFFSET ProtectedModeEntryPoint  ; Offset of our 32 bit code
181  DW      LINEAR_CODE_SEL
182
183END
184