+++ /dev/null
-#------------------------------------------------------------------------------\r
-#\r
-# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
-# SPDX-License-Identifier: BSD-2-Clause-Patent\r
-#\r
-# Abstract:\r
-#\r
-# This is the code that goes from real-mode to protected mode.\r
-# It consumes the reset vector, configures the stack.\r
-#\r
-#------------------------------------------------------------------------------\r
-\r
-\r
-#\r
-# Contrary to the name, this file contains 16 bit code as well.\r
-#\r
-.text\r
-#----------------------------------------------------------------------------\r
-#\r
-# Procedure: _ModuleEntryPoint\r
-#\r
-# Input: None\r
-#\r
-# Output: None\r
-#\r
-# Destroys: Assume all registers\r
-#\r
-# Description:\r
-#\r
-# Transition to non-paged flat-model protected mode from a\r
-# hard-coded GDT that provides exactly two descriptors.\r
-# This is a bare bones transition to protected mode only\r
-# used for a while in PEI and possibly DXE.\r
-#\r
-# After enabling protected mode, a far jump is executed to\r
-# transfer to PEI using the newly loaded GDT.\r
-#\r
-# Return: None\r
-#\r
-#----------------------------------------------------------------------------\r
-ASM_GLOBAL ASM_PFX(_ModuleEntryPoint)\r
-ASM_PFX(_ModuleEntryPoint):\r
-\r
- #\r
- # Load the GDT table in GdtDesc\r
- #\r
- .byte 0x66,0xbe #movl $GdtDesc, %esi\r
- .long GdtDesc\r
- \r
- .byte 0x66,0x2e,0x0f,0x01,0x14 #lgdt %cs:(%si)\r
-\r
- #\r
- # Transition to 16 bit protected mode\r
- #\r
- .byte 0x0f,0x20,0xc0 #movl %cr0, %eax # Get control register 0\r
- .byte 0x66,0x83,0xc8,0x03 #orl $0x0000003, %eax # Set PE bit (bit #0) & MP bit (bit #1)\r
- .byte 0x0f,0x22,0xc0 #movl %eax, %cr0 # Activate protected mode\r
-\r
- #\r
- # Now we're in 16 bit protected mode\r
- # Set up the selectors for 32 bit protected mode entry\r
- # \r
- .byte 0xb8 #movw SYS_DATA_SEL, %ax\r
- .word SYS_DATA_SEL\r
- \r
- .byte 0x8e,0xd8 #movw %ax, %ds\r
- .byte 0x8e,0xc0 #movw %ax, %es\r
- .byte 0x8e,0xe0 #movw %ax, %fs\r
- .byte 0x8e,0xe8 #movw %ax, %gs\r
- .byte 0x8e,0xd0 #movw %ax, %ss\r
-\r
- #\r
- # Transition to Flat 32 bit protected mode\r
- # The jump to a far pointer causes the transition to 32 bit mode\r
- #\r
- .byte 0x66,0xbe #movl ProtectedModeEntryLinearAddress, %esi\r
- .long ProtectedModeEntryLinearAddress \r
- .byte 0x66,0x2e,0xff,0x2c #jmp %cs:(%esi)\r
-\r
-#\r
-# Protected mode portion initializes stack, configures cache, and calls C entry point\r
-#\r
-\r
-#----------------------------------------------------------------------------\r
-#\r
-# Procedure: ProtectedModeEntryPoint\r
-#\r
-# Input: Executing in 32 Bit Protected (flat) mode\r
-# cs: 0-4GB\r
-# ds: 0-4GB\r
-# es: 0-4GB\r
-# fs: 0-4GB\r
-# gs: 0-4GB\r
-# ss: 0-4GB\r
-#\r
-# Output: This function never returns\r
-#\r
-# Destroys:\r
-# ecx\r
-# edi\r
-# esi\r
-# esp\r
-#\r
-# Description:\r
-# Perform any essential early platform initilaisation\r
-# Setup a stack\r
-#\r
-#----------------------------------------------------------------------------\r
-ProtectedModeEntryPoint:\r
- #\r
- # Dummy function. Consume 2 API to make sure they can be linked.\r
- #\r
- movl ASM_PFX(TempRamInitApi), %eax\r
- movl ASM_PFX(FspInitApi), %eax\r
- #\r
- # Should never return\r
- #\r
- jmp . #'$'\r
-\r
-#\r
-# ROM-based Global-Descriptor Table for the PEI Phase\r
-#\r
-.align 16\r
-#\r
-# GDT[0]: 000h: Null entry, never used.\r
-#\r
-.equ NULL_SEL, . - GDT_BASE # Selector [0]\r
-GDT_BASE: \r
-BootGdtTable: \r
- .long 0\r
- .long 0\r
-#\r
-# Linear code segment descriptor\r
-#\r
-.equ LINEAR_CODE_SEL, . - GDT_BASE # Selector [08h]\r
- .word 0xFFFF # limit 0FFFFh\r
- .word 0 # base 0\r
- .byte 0\r
- .byte 0x9B # present, ring 0, data, expand-up, not-writable\r
- .byte 0xCF # page-granular, 32-bit\r
- .byte 0\r
-#\r
-# System data segment descriptor\r
-#\r
-.equ SYS_DATA_SEL, . - GDT_BASE # Selector [010h]\r
- .word 0xFFFF # limit 0FFFFh\r
- .word 0 # base 0\r
- .byte 0\r
- .byte 0x93 # present, ring 0, data, expand-up, not-writable\r
- .byte 0xCF # page-granular, 32-bit\r
- .byte 0\r
-\r
-.equ GDT_SIZE, . - BootGdtTable # Size, in bytes\r
-\r
-#\r
-# GDT Descriptor\r
-#\r
-GdtDesc: # GDT descriptor\r
- .word GDT_SIZE - 1 \r
- .long BootGdtTable \r
-\r
-ProtectedModeEntryLinearAddress:\r
-ProtectedModeEntryLinearOffset:\r
- .long ProtectedModeEntryPoint\r
- .word LINEAR_CODE_SEL\r