muimaster.library: it is possible to set NULL as entries. Make the code robust to...
[AROS.git] / rom / efi / efi_init.c
blob30ecf3bd1924443f0f2e68ced40315e7ad119f9c
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <resources/efi.h>
8 #include <proto/arossupport.h>
9 #include <proto/kernel.h>
11 #include "efi_intern.h"
13 static BOOL CheckTable(struct EFI_TableHeader *t, UQUAD sig)
15 if (t->Signature != sig)
17 D(bug("[EFI] Table 0x%p bad signature (has 0x%016llX, wanted 0x%016llX)\n", t, t->Signature, sig));
18 return FALSE;
21 /* TODO: Check CRC */
23 return TRUE;
26 AROS_INTH1(static ResetHandler, struct EFIBase *, EFIBase)
28 AROS_INTFUNC_INIT
30 UBYTE action = EFIBase->reset_handler.is_Node.ln_Type;
31 IPTR efiAction;
33 switch (action)
35 case SD_ACTION_COLDREBOOT:
36 efiAction = EFI_Reset_Cold;
37 break;
39 case SD_ACTION_POWEROFF:
40 efiAction = EFI_Reset_Shutdown;
41 break;
43 default:
44 /* Unknown action */
45 return FALSE;
48 /* Use EFI runtime services to perform the action */
49 EFIBase->Runtime->ResetSystem(efiAction, 0, 0, NULL);
51 /* Shut up the compiler, we should never reach this. */
52 return FALSE;
54 AROS_INTFUNC_EXIT
57 static int efi_Init(struct EFIBase *EFIBase)
59 APTR KernelBase;
60 struct TagItem *tag;
62 D(bug("[EFI] Entered efi_Init() at 0x%p\n", efi_Init));
64 KernelBase = OpenResource("kernel.resource");
65 if (!KernelBase)
67 return FALSE;
70 tag = LibFindTagItem(KRN_EFISystemTable, KrnGetBootInfo());
71 if (!tag)
73 D(bug("[EFI] No EFI system table from the bootstrap!\n"));
75 return FALSE;
78 EFIBase->System = (struct EFI_SystemTable *)tag->ti_Data;
79 D(bug("Found EFI system table at 0x%p\n", EFIBase->System));
81 if (!CheckTable(&EFIBase->System->Hdr, EFI_SYSTEM_TABLE_SIGNATURE))
83 D(bug("[EFI] System table broken\n"));
84 return FALSE;
87 if (CheckTable(&EFIBase->System->RuntimeServices->Hdr, EFI_RUNTIME_SERVICES_SIGNATURE))
89 EFIBase->Runtime = EFIBase->System->RuntimeServices;
90 D(bug("[EFI] Valid runtime services table at 0x%p\n", EFIBase->Runtime));
92 /* Install EFI reset/power-off mechanism */
93 EFIBase->reset_handler.is_Node.ln_Pri = -56;
94 EFIBase->reset_handler.is_Node.ln_Name = "EFI reset";
95 EFIBase->reset_handler.is_Code = (VOID_FUNC)ResetHandler;
96 EFIBase->reset_handler.is_Data = EFIBase;
97 AddResetCallback(&EFIBase->reset_handler);
100 return TRUE;
103 ADD2INITLIB(efi_Init, 0);