1#------------------------------------------------------------------------------ 2# 3# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> 4# 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# Abstract: 13# 14# This is the code that goes from real-mode to protected mode. 15# It consumes the reset vector, configures the stack. 16# 17#------------------------------------------------------------------------------ 18 19 20# 21# Contrary to the name, this file contains 16 bit code as well. 22# 23.text 24#---------------------------------------------------------------------------- 25# 26# Procedure: _ModuleEntryPoint 27# 28# Input: None 29# 30# Output: None 31# 32# Destroys: Assume all registers 33# 34# Description: 35# 36# Transition to non-paged flat-model protected mode from a 37# hard-coded GDT that provides exactly two descriptors. 38# This is a bare bones transition to protected mode only 39# used for a while in PEI and possibly DXE. 40# 41# After enabling protected mode, a far jump is executed to 42# transfer to PEI using the newly loaded GDT. 43# 44# Return: None 45# 46#---------------------------------------------------------------------------- 47ASM_GLOBAL ASM_PFX(_ModuleEntryPoint) 48ASM_PFX(_ModuleEntryPoint): 49 50 # 51 # Load the GDT table in GdtDesc 52 # 53 .byte 0x66,0xbe #movl $GdtDesc, %esi 54 .long GdtDesc 55 56 .byte 0x66,0x2e,0x0f,0x01,0x14 #lgdt %cs:(%si) 57 58 # 59 # Transition to 16 bit protected mode 60 # 61 .byte 0x0f,0x20,0xc0 #movl %cr0, %eax # Get control register 0 62 .byte 0x66,0x83,0xc8,0x03 #orl $0x0000003, %eax # Set PE bit (bit #0) & MP bit (bit #1) 63 .byte 0x0f,0x22,0xc0 #movl %eax, %cr0 # Activate protected mode 64 65 # 66 # Now we're in 16 bit protected mode 67 # Set up the selectors for 32 bit protected mode entry 68 # 69 .byte 0xb8 #movw SYS_DATA_SEL, %ax 70 .word SYS_DATA_SEL 71 72 .byte 0x8e,0xd8 #movw %ax, %ds 73 .byte 0x8e,0xc0 #movw %ax, %es 74 .byte 0x8e,0xe0 #movw %ax, %fs 75 .byte 0x8e,0xe8 #movw %ax, %gs 76 .byte 0x8e,0xd0 #movw %ax, %ss 77 78 # 79 # Transition to Flat 32 bit protected mode 80 # The jump to a far pointer causes the transition to 32 bit mode 81 # 82 .byte 0x66,0xbe #movl ProtectedModeEntryLinearAddress, %esi 83 .long ProtectedModeEntryLinearAddress 84 .byte 0x66,0x2e,0xff,0x2c #jmp %cs:(%esi) 85 86# 87# Protected mode portion initializes stack, configures cache, and calls C entry point 88# 89 90#---------------------------------------------------------------------------- 91# 92# Procedure: ProtectedModeEntryPoint 93# 94# Input: Executing in 32 Bit Protected (flat) mode 95# cs: 0-4GB 96# ds: 0-4GB 97# es: 0-4GB 98# fs: 0-4GB 99# gs: 0-4GB 100# ss: 0-4GB 101# 102# Output: This function never returns 103# 104# Destroys: 105# ecx 106# edi 107# esi 108# esp 109# 110# Description: 111# Perform any essential early platform initilaisation 112# Setup a stack 113# 114#---------------------------------------------------------------------------- 115ProtectedModeEntryPoint: 116 # 117 # Dummy function. Consume 2 API to make sure they can be linked. 118 # 119 movl ASM_PFX(TempRamInitApi), %eax 120 movl ASM_PFX(FspInitApi), %eax 121 # 122 # Should never return 123 # 124 jmp . #'$' 125 126# 127# ROM-based Global-Descriptor Table for the PEI Phase 128# 129.align 16 130# 131# GDT[0]: 000h: Null entry, never used. 132# 133.equ NULL_SEL, . - GDT_BASE # Selector [0] 134GDT_BASE: 135BootGdtTable: 136 .long 0 137 .long 0 138# 139# Linear code segment descriptor 140# 141.equ LINEAR_CODE_SEL, . - GDT_BASE # Selector [08h] 142 .word 0xFFFF # limit 0FFFFh 143 .word 0 # base 0 144 .byte 0 145 .byte 0x9B # present, ring 0, data, expand-up, not-writable 146 .byte 0xCF # page-granular, 32-bit 147 .byte 0 148# 149# System data segment descriptor 150# 151.equ SYS_DATA_SEL, . - GDT_BASE # Selector [010h] 152 .word 0xFFFF # limit 0FFFFh 153 .word 0 # base 0 154 .byte 0 155 .byte 0x93 # present, ring 0, data, expand-up, not-writable 156 .byte 0xCF # page-granular, 32-bit 157 .byte 0 158 159.equ GDT_SIZE, . - BootGdtTable # Size, in bytes 160 161# 162# GDT Descriptor 163# 164GdtDesc: # GDT descriptor 165 .word GDT_SIZE - 1 166 .long BootGdtTable 167 168ProtectedModeEntryLinearAddress: 169ProtectedModeEntryLinearOffset: 170 .long ProtectedModeEntryPoint 171 .word LINEAR_CODE_SEL 172