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 - 2016, 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 19extern ASM_PFX(TempRamInitApi) 20 21SECTION .text 22 23%macro RET_ESI 0 24 25 movd esi, mm7 ; restore ESP from MM7 26 jmp esi 27 28%endmacro 29 30; 31; Perform early platform initialization 32; 33global ASM_PFX(SecPlatformInit) 34ASM_PFX(SecPlatformInit): 35 36 RET_ESI 37 38; 39; Protected mode portion initializes stack, configures cache, and calls C entry point 40; 41 42;---------------------------------------------------------------------------- 43; 44; Procedure: ProtectedModeEntryPoint 45; 46; Input: Executing in 32 Bit Protected (flat) mode 47; cs: 0-4GB 48; ds: 0-4GB 49; es: 0-4GB 50; fs: 0-4GB 51; gs: 0-4GB 52; ss: 0-4GB 53; 54; Output: This function never returns 55; 56; Destroys: 57; ecx 58; edi 59; esi 60; esp 61; 62; Description: 63; Perform any essential early platform initilaisation 64; Setup a stack 65; 66;---------------------------------------------------------------------------- 67global ASM_PFX(ProtectedModeEntryPoint) 68ASM_PFX(ProtectedModeEntryPoint): 69 ; 70 ; Dummy function. Consume 2 API to make sure they can be linked. 71 ; 72 mov eax, ASM_PFX(TempRamInitApi) 73 74 ; Should never return 75 jmp $ 76 77; 78; ROM-based Global-Descriptor Table for the PEI Phase 79; 80align 16 81global ASM_PFX(BootGdtTable) 82 83; 84; GDT[0]: 0x00: Null entry, never used. 85; 86NULL_SEL equ $ - GDT_BASE ; Selector [0] 87GDT_BASE: 88ASM_PFX(BootGdtTable): DD 0 89 DD 0 90; 91; Linear code segment descriptor 92; 93LINEAR_CODE_SEL equ $ - GDT_BASE ; Selector [0x8] 94 DW 0FFFFh ; limit 0xFFFF 95 DW 0 ; base 0 96 DB 0 97 DB 09Bh ; present, ring 0, data, expand-up, not-writable 98 DB 0CFh ; page-granular, 32-bit 99 DB 0 100; 101; System data segment descriptor 102; 103SYS_DATA_SEL equ $ - GDT_BASE ; Selector [0x10] 104 DW 0FFFFh ; limit 0xFFFF 105 DW 0 ; base 0 106 DB 0 107 DB 093h ; present, ring 0, data, expand-up, not-writable 108 DB 0CFh ; page-granular, 32-bit 109 DB 0 110 111GDT_SIZE EQU $ - GDT_BASE ; Size, in bytes 112 113; 114; GDT Descriptor 115; 116GdtDesc: ; GDT descriptor 117 DW GDT_SIZE - 1 ; GDT limit 118 DD GDT_BASE ; GDT base address 119 120global ASM_PFX(ProtectedModeEntryLinearAddress) 121global ASM_PFX(ProtectedModeEntryLinearOffset) 122 123ASM_PFX(ProtectedModeEntryLinearAddress): 124ASM_PFX(ProtectedModeEntryLinearOffset): 125 DD ASM_PFX(ProtectedModeEntryPoint) ; Offset of our 32 bit code 126 DW LINEAR_CODE_SEL 127 128