1 /** @file 2 SMM STM support functions 3 4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php. 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 #include <PiSmm.h> 16 #include <Library/DebugLib.h> 17 18 #include "SmmStm.h" 19 20 /// 21 /// Page Table Entry 22 /// 23 #define IA32_PG_P BIT0 24 #define IA32_PG_RW BIT1 25 #define IA32_PG_PS BIT7 26 27 /** 28 29 Create 4G page table for STM. 30 4M Non-PAE page table in IA32 version. 31 32 @param PageTableBase The page table base in MSEG 33 34 **/ 35 VOID 36 StmGen4GPageTable ( 37 IN UINTN PageTableBase 38 ) 39 { 40 UINTN Index; 41 UINT32 *Pte; 42 UINT32 Address; 43 44 Pte = (UINT32*)(UINTN)PageTableBase; 45 46 Address = 0; 47 for (Index = 0; Index < SIZE_4KB / sizeof (*Pte); Index++) { 48 *Pte = Address | IA32_PG_PS | IA32_PG_RW | IA32_PG_P; 49 Pte++; 50 Address += SIZE_4MB; 51 } 52 } 53 54 /** 55 This is SMM exception handle. 56 Consumed by STM when exception happen. 57 58 @param Context STM protection exception stack frame 59 60 @return the EBX value for STM reference. 61 EBX = 0: resume SMM guest using register state found on exception stack. 62 EBX = 1 to 0x0F: EBX contains a BIOS error code which the STM must record in the 63 TXT.ERRORCODE register and subsequently reset the system via 64 TXT.CMD.SYS_RESET. The value of the TXT.ERRORCODE register is calculated as 65 follows: TXT.ERRORCODE = (EBX & 0x0F) | STM_CRASH_BIOS_PANIC 66 EBX = 0x10 to 0xFFFFFFFF - reserved, do not use. 67 68 **/ 69 UINT32 70 EFIAPI 71 SmmStmExceptionHandler ( 72 IN OUT STM_PROTECTION_EXCEPTION_STACK_FRAME Context 73 ) 74 { 75 // TBD - SmmStmExceptionHandler, record information 76 DEBUG ((DEBUG_ERROR, "SmmStmExceptionHandler ...\n")); 77 // 78 // Skip this instruction and continue; 79 // 80 Context.Ia32StackFrame->Rip += Context.Ia32StackFrame->VmcsExitInstructionLength; 81 82 return 0; 83 } 84