mirror of https://review.coreboot.org/STM.git
First steps in getting the image correct
This commit is contained in:
parent
be9ce4f74c
commit
757a1c7aa7
|
@ -0,0 +1 @@
|
|||
Stm/build/*
|
|
@ -3,10 +3,10 @@ cmake_minimum_required(VERSION 3.5)
|
|||
|
||||
project(stm C ASM)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -nostdlib -fno-jump-tables -fPIC -fno-stack-protector -fno-stack-check -include PcdData.h")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -Xlinker -Map=stm.map -s -pie --entry _ModuleEntryPoint -u _ModuleEntryPoint -nostdlib -n -z common-page-size=0x40 -fno-asynchronous-unwind-tables -fno-jump-tables -fPIC -fno-stack-protector -fno-stack-check -include PcdData.h -T ${PROJECT_SOURCE_DIR}/StmPkg/Core/Stm.lds")
|
||||
|
||||
set(CMAKE_ASM_FLAGS "-include BaseAsm.h")
|
||||
set(CMAKE_ASM_CREATE_SHARED_LIBRARY "gcc ${CFLAGS} -o *.o")
|
||||
set(CMAKE_ASM_FLAGS "-include BaseAsm.h -fPIC")
|
||||
set(CMAKE_ASM_CREATE_SHARED_LIBRARY "gcc ${CFLAGS} -o *.o")
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/StmPkg/Core"
|
||||
"${PROJECT_SOURCE_DIR}/StmPkg/EdkII/MdePkg/Include/"
|
||||
|
@ -20,7 +20,7 @@ add_subdirectory(StmPkg/EdkII/MdePkg/Library/BaseMemoryLib)
|
|||
add_subdirectory(StmPkg/EdkII/MdePkg/Library/BasePrintLib)
|
||||
add_subdirectory(StmPkg/EdkII/MdePkg/Library/BaseIoLibIntrinsic)
|
||||
add_subdirectory(StmPkg/EdkII/MdePkg/Library/BasePciLibPciExpress)
|
||||
add_subdirectory(StmPkg/EdkII/MdePkg/Library/BasePciCf8Lib)
|
||||
#add_subdirectory(StmPkg/EdkII/MdePkg/Library/BasePciCf8Lib)
|
||||
add_subdirectory(StmPkg/EdkII/MdePkg/Library/BasePciExpressLib)
|
||||
add_subdirectory(StmPkg/Library/StmLib)
|
||||
add_subdirectory(StmPkg/Library/MpSafeDebugLibSerialPort)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
add_subdirectory(Runtime)
|
||||
add_subdirectory(Init)
|
||||
|
||||
add_library(Stm MODULE
|
||||
add_executable( Stm
|
||||
Cpu.c
|
||||
Dump.c
|
||||
VmcsRecord.c
|
||||
|
@ -10,6 +10,19 @@ add_library(Stm MODULE
|
|||
Init/StmInit.c
|
||||
)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT stm.tmp
|
||||
DEPENDS Stm
|
||||
# POST_BUILD
|
||||
COMMAND ${CMAKE_OBJCOPY} Stm stm.tmp -O binary -S
|
||||
COMMAND ${CMAKE_COMMAND} -E copy stm.tmp stm.bin
|
||||
COMMENT "objcopy Stm to stm.bin"
|
||||
)
|
||||
|
||||
add_custom_target(stm.bin ALL DEPENDS stm.tmp)
|
||||
set_directory_properties(PROPERTIES ADDITIIONAL_MAKE_CLEAN_FILES "stm.bin stm.tmp stm.lds")
|
||||
|
||||
|
||||
add_library(Resource STATIC
|
||||
StmResource.c
|
||||
)
|
||||
|
@ -18,6 +31,11 @@ add_library(EventLog STATIC
|
|||
EventLog.c
|
||||
)
|
||||
|
||||
target_link_libraries(Resource PUBLIC
|
||||
PciLib
|
||||
PciExpressLib
|
||||
)
|
||||
|
||||
add_library(EptLib STATIC
|
||||
Init/EptInit.c
|
||||
Runtime/SmmEptHandler.c
|
||||
|
@ -30,13 +48,13 @@ target_include_directories(EptLib PUBLIC
|
|||
)
|
||||
|
||||
target_link_libraries(Stm PUBLIC
|
||||
#BaseLib
|
||||
BaseLib
|
||||
#BaseMemoryLib
|
||||
#IoLib
|
||||
PciLib
|
||||
#SynchronizationLib
|
||||
#DebugLib
|
||||
StmLib
|
||||
#StmLib
|
||||
PcdLib
|
||||
StmPlatformLib
|
||||
StmRuntime
|
||||
|
@ -52,6 +70,7 @@ target_include_directories(Stm PUBLIC
|
|||
target_include_directories(Resource PUBLIC
|
||||
Runtime)
|
||||
|
||||
|
||||
add_library(PcdData STATIC PcdData.c)
|
||||
|
||||
#GCC:*_*_X64_DLINK_FLAGS == -o $(DEBUG_DIR)/Stm.dll -nostdlib -n -q --gc-sections -z common-page-size=0x40 --entry _ModuleEntryPoint -u _ModuleEntryPoint -Map $(DEST_DIR_DEBUG)/$(BASE_NAME).map -m elf_x86_64 --oformat=elf64-x86-64 --defsym=PECOFF_HEADER_SIZE=0x228 #--script=$(MODULE_DIR)/Stm.lds
|
||||
|
|
|
@ -8,6 +8,7 @@ add_library(StmInit STATIC
|
|||
MsrInit.c
|
||||
Relocate.c
|
||||
PeVmcsInit.c
|
||||
x64/AsmStmInit.S
|
||||
)
|
||||
|
||||
target_include_directories(StmInit PUBLIC
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
#------------------------------------------------------------------------------
|
||||
#
|
||||
# Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php.
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
# Module Name:
|
||||
#
|
||||
# AsmStmInit.s
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
ASM_GLOBAL ASM_PFX(InitializeSmmMonitor)
|
||||
ASM_GLOBAL ASM_PFX(_ModuleEntryPoint)
|
||||
|
||||
.equ STM_API_START, 0x00010001
|
||||
.equ STM_API_INITIALIZE_PROTECTION, 0x00010007
|
||||
|
||||
.equ STM_STACK_SIZE, 0x020000
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# VOID
|
||||
# AsmInitializeSmmMonitor (
|
||||
# VOID
|
||||
# )
|
||||
ASM_PFX(_ModuleEntryPoint):
|
||||
cmpl $STM_API_INITIALIZE_PROTECTION, %eax # for BSP
|
||||
jz GoBsp
|
||||
cmpl $STM_API_START, %eax # for AP
|
||||
jz GoAp
|
||||
jmp DeadLoop
|
||||
|
||||
GoBsp:
|
||||
# Assume ThisOffset is 0
|
||||
# ESP is pointer to stack bottom, NOT top
|
||||
movl $STM_STACK_SIZE, %eax # eax = STM_STACK_SIZE,
|
||||
lock xaddl %eax, (%esp) # eax = ThisOffset, ThisOffset += STM_STACK_SIZE (LOCK instruction)
|
||||
addl $STM_STACK_SIZE, %eax # eax = ThisOffset + STM_STACK_SIZE
|
||||
addl %eax, %esp # esp += ThisOffset + STM_STACK_SIZE
|
||||
|
||||
#
|
||||
# Jump to C code
|
||||
#
|
||||
push %r15
|
||||
push %r14
|
||||
push %r13
|
||||
push %r12
|
||||
push %r11
|
||||
push %r10
|
||||
push %r9
|
||||
push %r8
|
||||
push %rdi
|
||||
push %rsi
|
||||
push %rbp
|
||||
push %rbp # should be rsp
|
||||
push %rbx
|
||||
push %rdx
|
||||
push %rcx
|
||||
movl $STM_API_INITIALIZE_PROTECTION, %eax
|
||||
push %rax
|
||||
movq %rsp, %rcx # parameter
|
||||
subq $0x20, %rsp
|
||||
call ASM_PFX(InitializeSmmMonitor)
|
||||
addq $0x20, %rsp
|
||||
# should never get here
|
||||
jmp DeadLoop
|
||||
|
||||
GoAp:
|
||||
#
|
||||
# assign unique ESP for each processor
|
||||
#
|
||||
# |------------|<-ESP (PerProc)
|
||||
# | Reg |
|
||||
# |------------|
|
||||
# | Stack |
|
||||
# |------------|
|
||||
# | ThisOffset |
|
||||
# +------------+<-ESP (Common)
|
||||
# | Heap |
|
||||
|
||||
# Assume ThisOffset is 0
|
||||
# ESP is pointer to stack bottom, NOT top
|
||||
movl $STM_STACK_SIZE, %eax # eax = STM_STACK_SIZE,
|
||||
lock xaddl %eax, (%esp) # eax = ThisOffset, ThisOffset += STM_STACK_SIZE (LOCK instruction)
|
||||
addl $STM_STACK_SIZE, %eax # eax = ThisOffset + STM_STACK_SIZE
|
||||
addl %eax, %esp # esp += ThisOffset + STM_STACK_SIZE
|
||||
|
||||
#
|
||||
# Jump to C code
|
||||
#
|
||||
push %r15
|
||||
push %r14
|
||||
push %r13
|
||||
push %r12
|
||||
push %r11
|
||||
push %r10
|
||||
push %r9
|
||||
push %r8
|
||||
push %rdi
|
||||
push %rsi
|
||||
push %rbp
|
||||
push %rbp # should be rsp
|
||||
push %rbx
|
||||
push %rdx
|
||||
push %rcx
|
||||
movl $STM_API_START, %eax
|
||||
push %rax
|
||||
movq %rsp, %rcx # parameter
|
||||
subq $0x20, %rsp
|
||||
call ASM_PFX(InitializeSmmMonitor)
|
||||
addq $0x20, %rsp
|
||||
# should never get here
|
||||
DeadLoop:
|
||||
jmp .
|
||||
|
|
@ -66,6 +66,8 @@ target_include_directories(StmRuntime PUBLIC
|
|||
|
||||
target_link_libraries(StmRuntime PUBLIC
|
||||
SynchronizationLib
|
||||
StmPlatformLib
|
||||
EventLog
|
||||
StmLib
|
||||
)
|
||||
|
||||
|
|
|
@ -17,8 +17,97 @@
|
|||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x0 + 0x280;
|
||||
. = ALIGN(0x20);
|
||||
/* HARDWARE_STM_HEADER */
|
||||
. = 0x0;
|
||||
.StmHeaderRevision : {LONG(0)}
|
||||
.MonitorFeatures : {LONG(1)}
|
||||
.GdtrLimit : {LONG(0x47)}
|
||||
.GdtrBaseOffset : {LONG(0x1000)}
|
||||
.CsSelector : {LONG(0x38)}
|
||||
.EipOffset : {LONG(_ModuleEntryPoint)}
|
||||
.EspOffset : {LONG(0)}
|
||||
.Cr3Offset : {LONG(0)}
|
||||
|
||||
/* SOFTWARE_STM_HEADER */
|
||||
|
||||
.StmSpecVerMajor ALIGN(2048) : {BYTE(1)}
|
||||
.StmSpecVerMinor : {BYTE(0)}
|
||||
.Reserved : {SHORT(0)}
|
||||
.StaticImageSize : {LONG(0)}
|
||||
.PerProcDynamicMemorySize : {LONG(0x8000)}
|
||||
.AdditionalDynamicMemorySize : {LONG(0x246000)}
|
||||
|
||||
.StmFeatures : {LONG(0)}
|
||||
.NumberOfRevIDs : {LONG(0)}
|
||||
.StmSmmRevIDs0 : {LONG(0)}
|
||||
. = ALIGN(0x1000);
|
||||
|
||||
/* GDT Entriess */
|
||||
.LimitLow0 : {SHORT(0)}
|
||||
.BaseLow0 : {SHORT(0)}
|
||||
.BaseMid0 : {BYTE(0)}
|
||||
.Attribute0 : {BYTE(0)}
|
||||
.LimitHi0 : {BYTE(0)}
|
||||
.BaseHi0 : {BYTE(0)}
|
||||
|
||||
.LimitLo1 : {SHORT(0)}
|
||||
.BaseLow1 : {SHORT(0)}
|
||||
.BaseMid1 : {BYTE(0)}
|
||||
.Attribute1 : {BYTE(0)}
|
||||
.LimitHi1 : {BYTE(0)}
|
||||
.BaseHi1 : {BYTE(0)}
|
||||
|
||||
.LimitLow2 : {SHORT(0xFFFF)}
|
||||
.BaseLow2 : {SHORT(0)}
|
||||
.BaseMid2 : {BYTE(0)}
|
||||
.Attribute2 : {BYTE(0x9B)}
|
||||
.LimitHi2 : {BYTE(0xCF)}
|
||||
.BaseHi2 : {BYTE(0)}
|
||||
|
||||
.LimitLow3 : {SHORT(0xFFFF)}
|
||||
.BaseLow3 : {SHORT(0)}
|
||||
.BaseMid3 : {BYTE(0)}
|
||||
.Attribute3 : {BYTE(0x93)}
|
||||
.LimitHi3 : {BYTE(0xCF)}
|
||||
.BaseHi3 : {BYTE(0)}
|
||||
|
||||
.LimitLow4 : {SHORT(0)}
|
||||
.BaseLow4 : {SHORT(0)}
|
||||
.BaseMid4 : {BYTE(0)}
|
||||
.Attribute4 : {BYTE(0)}
|
||||
.LimitHi4 : {BYTE(0)}
|
||||
.BaseHi4 : {BYTE(0)}
|
||||
|
||||
.LimitLow5 : {SHORT(104)}
|
||||
.BaseLow5 : {SHORT(0)}
|
||||
.BaseMid5 : {BYTE(0)}
|
||||
.Attribute5 : {BYTE(0x89)}
|
||||
.LimitHi5 : {BYTE(0x80)}
|
||||
.BaseHi5 : {BYTE(0)}
|
||||
|
||||
.LimitLowr6 : {SHORT(0)}
|
||||
.BaseLow6 : {SHORT(0)}
|
||||
.BaseMid6 : {BYTE(0)}
|
||||
.Attribute6 : {BYTE(0)}
|
||||
.LimitHi6 : {BYTE(0)}
|
||||
.BaseHi6 : {BYTE(0)}
|
||||
|
||||
.LimitLow7 : {SHORT(0xFFFF)}
|
||||
.BaseLow7 : {SHORT(0)}
|
||||
.BaseMid7 : {BYTE(0)}
|
||||
.Attribute7 : {BYTE(0x9B)}
|
||||
.LimitHi7 : {BYTE(0xAF)}
|
||||
.BaseHi7 : {BYTE(0)}
|
||||
|
||||
.LimitLow8 : {SHORT(0xFFFF)}
|
||||
.BaseLow8 : {SHORT(0)}
|
||||
.BaseMid8 : {BYTE(0)}
|
||||
.Attribute8 : {BYTE(0x93)}
|
||||
.LimitHi8 : {BYTE(0xCF)}
|
||||
.BaseHi8 : {BYTE(0)}
|
||||
|
||||
|
||||
. = ALIGN(0x1000);
|
||||
.text : {
|
||||
*(.text)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue