[SHELL32_APITEST] Follow-up to #6796 (25e2f5f)
[reactos.git] / boot / freeldr / freeldr / arch / i386 / hwapm.c
1 /*
2 * PROJECT: FreeLoader
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: APM BIOS detection routines
5 * COPYRIGHT: Copyright 2004 Eric Kohl (eric.kohl@reactos.org)
6 */
7
8 #include <freeldr.h>
9
10 #include <debug.h>
11 DBG_DEFAULT_CHANNEL(HWDETECT);
12
13 static BOOLEAN
14 FindApmBios(VOID)
15 {
16 REGS RegsIn, RegsOut;
17
18 /* APM BIOS - Installation check */
19 #if defined(SARCH_PC98)
20 RegsIn.w.ax = 0x9A00;
21 RegsIn.w.bx = 0x0000;
22 Int386(0x1F, &RegsIn, &RegsOut);
23 #else
24 RegsIn.w.ax = 0x5300;
25 RegsIn.w.bx = 0x0000;
26 Int386(0x15, &RegsIn, &RegsOut);
27 #endif
28 if (INT386_SUCCESS(RegsOut) && RegsOut.w.bx == 'PM')
29 {
30 TRACE("Found APM BIOS\n");
31 TRACE("AH: %x\n", RegsOut.b.ah);
32 TRACE("AL: %x\n", RegsOut.b.al);
33 TRACE("BH: %x\n", RegsOut.b.bh);
34 TRACE("BL: %x\n", RegsOut.b.bl);
35 TRACE("CX: %x\n", RegsOut.w.cx);
36
37 return TRUE;
38 }
39
40 TRACE("No APM BIOS found\n");
41
42 return FALSE;
43 }
44
45 VOID
46 DetectApmBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
47 {
48 PCONFIGURATION_COMPONENT_DATA BiosKey;
49 PCM_PARTIAL_RESOURCE_LIST PartialResourceList;
50 ULONG Size;
51
52 if (!FindApmBios())
53 return;
54
55 Size = sizeof(CM_PARTIAL_RESOURCE_LIST) -
56 sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
57
58 /* Set 'Configuration Data' value */
59 PartialResourceList = FrLdrHeapAlloc(Size, TAG_HW_RESOURCE_LIST);
60 if (PartialResourceList == NULL)
61 {
62 ERR("Failed to allocate resource descriptor\n");
63 return;
64 }
65 RtlZeroMemory(PartialResourceList, Size);
66 PartialResourceList->Version = 0;
67 PartialResourceList->Revision = 0;
68 PartialResourceList->Count = 0;
69
70 /* FIXME: Add configuration data */
71
72 /* Create new bus key */
73 FldrCreateComponentKey(SystemKey,
74 AdapterClass,
75 MultiFunctionAdapter,
76 0,
77 0,
78 0xFFFFFFFF,
79 "APM",
80 PartialResourceList,
81 Size,
82 &BiosKey);
83
84 /* Increment bus number */
85 (*BusNumber)++;
86 }
87
88 /* EOF */