summaryrefslogtreecommitdiff
path: root/Core/EM/BootScriptHide/BootScriptHideDxe.c
blob: 39f15ca593825fc57fae297c1175b401784e11da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2014, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**             5555 Oakbrook Pkwy, Norcross, GA 30093               **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************

//**********************************************************************
// $Header: /Alaska/SOURCE/Modules/BootScriptHide/BootScriptHideDxe.c 1     9/10/14 6:31p Aaronp $
//
// $Revision: 1 $
//
// $Date: 9/10/14 6:31p $
//**********************************************************************
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/BootScriptHide/BootScriptHideDxe.c $
// 
// 1     9/10/14 6:31p Aaronp
// First addition of BootScriptHide emodule.
//**********************************************************************

//**********************************************************************
//<AMI_FHDR_START>
//
// Name:	BootScriptHideDxe.c
//
// Description:	Source file for the DXE driver. This file contains the 
//              code to trigger the SWSMI that will save the boot scripts
//              into SMM. Depending on the boot path, either a legacy
//              boot event or an Exit Boot Services notification will
//              notify the trigger function
//
//<AMI_FHDR_END>
//**********************************************************************

#include <AmiDxeLib.h>
#include <Token.h>
#include <Protocol/SmmControl2.h>

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//  Procedure:      GenerateSaveBootScriptSwSmi
//
//  Description:    Callback function called when either Exit Boot Services is called, 
//                  or a legacy boot event is raised. This function will use the 
//                  SmmControl protocol to trigger a SWSMI.
//
//  Input:
//  IN EFI_EVENT Event - Event that caused this function to be called
//  IN VOID *Context - Context for the event that triggered this function
//
//  Output:
//  None
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID GenerateSaveBootScriptSwSmi (
    IN EFI_EVENT Event, IN VOID *Context
){
    static BOOLEAN BootScriptSaved = FALSE;
    EFI_STATUS Status;
    EFI_SMM_CONTROL2_PROTOCOL  *SmmControl;
    UINT8 SwSmiValue = BOOT_SCRIPT_SAVE_SW_SMI_VALUE;
    
    if (BootScriptSaved){
        pBS->CloseEvent(Event);
        return;
    }
    Status = pBS->LocateProtocol (&gEfiSmmControl2ProtocolGuid, NULL, (VOID **)&SmmControl);
    if (EFI_ERROR(Status)) return;
    SmmControl->Trigger (SmmControl, &SwSmiValue, NULL, FALSE, 0);
    BootScriptSaved = TRUE;
    pBS->CloseEvent(Event);
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
//  Procedure:      BootScriptHideDxeEntryPoint
//
//  Description:    Entry point for the DXE driver. Entry point will register a 
//                  legacy boot event notification function, and a Exit Boot Services
//                  event handler.  The same function is called for the legacy boot
//                  event and the exit boot services notification function.
//
//  Input:
//  IN EFI_HANDLE ImageHandle - The handle that corresponds this this loaded DXE driver
//  IN EFI_SYSTEM_TABLE *SystemTable - Pointer to the EFI System Table
//
//  Output:
//  EFI_STATUS The return status of this function
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS EFIAPI BootScriptHideDxeEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable){
    EFI_EVENT Event;
    
    InitAmiLib(ImageHandle,SystemTable);
    // We're using TPL_NOTIFY here (as oppose to TPL_CALLBACK) to make sure our callback is called prior to NVRAM driver callback.
    // Otherwise we may be unable to read boot time variable in our SMI handler.
    CreateLegacyBootEvent(TPL_NOTIFY, &GenerateSaveBootScriptSwSmi, NULL, &Event);
    pBS->CreateEvent(
        EVT_SIGNAL_EXIT_BOOT_SERVICES,TPL_NOTIFY,
        &GenerateSaveBootScriptSwSmi, NULL, &Event
    );
    return EFI_SUCCESS;
}
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2014, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**             5555 Oakbrook Pkwy, Norcross, GA 30093               **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************