summaryrefslogtreecommitdiffstats
path: root/memtestEDK/Memtest/GetRootSystemDescriptionPointer/GetRootSystemDescriptionPointer.c
blob: b9e3e48e6f3846bc1605f72be72bad42c916cad4 (plain) (blame)
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <stdio.h>

#include <stdint.h>
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiApplicationEntryPoint.h>

struct RSDPDescriptor {
 char Signature[8];
 uint8_t Checksum;
 char OEMID[6];
 uint8_t Revision;
 uint32_t RsdtAddress;
} __attribute__ ((packed));

EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
    UINTN NumberOfTableEntries = SystemTable->NumberOfTableEntries;
    EFI_CONFIGURATION_TABLE *ConfigurationTable = SystemTable->ConfigurationTable;



    Print(L"NumberOfTableEntries: %d\n", NumberOfTableEntries);

    for (int i = 0; i < NumberOfTableEntries; i++) {
    	EFI_GUID guid = ConfigurationTable->VendorGuid;
    	UINT32 Data1 = guid.Data1;
		UINT16 Data2 = guid.Data2;
		UINT16 Data3 = guid.Data3;
		UINT8 Data4[8];
		Data4[0] = guid.Data4[0];

		if (Data1 == 0xEB9D2D30) {
			// ACPI 1.0
			// TODO check other fields
    		// VOID *VendorTable

    		Print(L"ConfigurationTable pointer: %p\n", ConfigurationTable);
    		Print(L"VendorGuid: %x\n", Data1);
    		Print(L"VendorGuid: %x\n", Data2);
    		Print(L"VendorGuid: %x\n", Data3);
    		for (int j = 0; j < 8; j++) {
    			Print(L"VendorGuid: %x\n", Data4[j]);
    		}

    		struct RSDPDescriptor *VendorTable = ConfigurationTable->VendorTable;

    		char Signature[8];
    		for (int k = 0; k < 8; k++) {
	    		Signature[k] = VendorTable->Signature[k];
    			Print(L"Signature of RootSystemDescriptorTable: %c\n", Signature[k]);
    		}
    		//(L"Signature of RootSystemDescriptorTable: %s\n", Signature);



			uint8_t Checksum = VendorTable->Checksum;
			Print(L"Checksum: %d\n", Checksum);

			char OEMID[6];
			for (int l = 0; l < 6; l++) {
				OEMID[l] = VendorTable->OEMID[l];
				Print(L"OEMID: %c\n", OEMID[l]);
			}

			uint8_t Revision = VendorTable->Revision;
			Print(L"Revision: %d\n", Revision);

			uint32_t RsdtAddress = VendorTable->RsdtAddress;
			Print(L"RsdtAddress: %p\n", RsdtAddress);
			Print(L"VendorTable Adress: %p\n", VendorTable);
    	}
/*
    	if (Data1 == 0x8868E871) {
    		// ACPI 2.0
			// TODO check other fields
    		// VOID *VendorTable

    		Print(L"ConfigurationTable pointer: %p\n", ConfigurationTable);
    		Print(L"VendorGuid: %x\n", Data1);
    		Print(L"VendorGuid: %x\n", Data2);
    		Print(L"VendorGuid: %x\n", Data3);
    		for (int j = 0; j < 8; j++) {
    			Print(L"VendorGuid: %x\n", Data4[j]);
    		}

    		//VOID *VendorTable = ConfigurationTable->VendorTable;

    	}*/

    	ConfigurationTable += 1;
	}

	return EFI_SUCCESS;

}

/*

//EFI_GUID

typedef struct {
UINT32 Data1;
UINT16 Data2;
UINT16 Data3;
UINT8
Data4[8];
} EFI_GUID;*/

/*
typedef struct{
EFI_GUID  VendorGuid; 128-bit GUID
VOID *VendorTable;
} EFI_CONFIGURATION_TABLE;
*/

/*
In ACPI Version 1.0 it has this structure:

struct RSDPDescriptor {
 char Signature[8];
 uint8_t Checksum;
 char OEMID[6];
 uint8_t Revision;
 uint32_t RsdtAddress;
} __attribute__ ((packed));

since Version 2.0 it has been extended, and the following new fields have been added:

struct RSDPDescriptor20 {
 RSDPDescriptor firstPart;
 
 uint32_t Length;
 uint64_t XsdtAddress;
 uint8_t ExtendedChecksum;
 uint8_t reserved[3];
} __attribute__ ((packed));*/

/*UINTN NumberOfTableEntries The number of system configuration tables in the buffer
ConfigurationTable.
EFI_CONFIGURATION_TABLE *ConfigurationTable A pointer to the system configuration tables. The number of
entries in the table is NumberOfTableEntries.*/

/*ACPI5_1_Specification.pdf

5.2.5.2 Finding the RSDP on UEFI Enabled Systems
In Unified Extensible Firmware Interface (UEFI) enabled systems, a pointer to the RSDP structure
exists within the EFI System Table. The OS loader is provided a pointer to the EFI System Table at
invocation. The OS loader must retrieve the pointer to the RSDP structure from the EFI System
Table and convey the pointer to OSPM, using an OS dependent data structure, as part of the hand off
of control from the OS loader to the OS.
The OS loader locates the pointer to the RSDP structure by examining the EFI Configuration Table
within the EFI System Table. EFI Configuration Table entries consist of Globally Unique Identifier
(GUID)/table pointer pairs. The UEFI specification defines two GUIDs for ACPI; one for ACPI 1.0
and the other for ACPI 2.0 or later specification revisions.
The EFI GUID for a pointer to the ACPI 1.0 specification RSDP structure is:

EB9D2D30-2D88-11D3-9A16-0090273FC14D.
The EFI GUID for a pointer to the ACPI 2.0 or later specification RSDP structure is:

8868E871-E4F1-11D3-BC22-0080C73C8881.
The OS loader for an ACPI-compatible OS will search for an RSDP structure pointer using the
current revision GUID first and if it finds one, will use the corresponding RSDP structure pointer. If
the GUID is not found then the OS loader will search for the RSDP structure pointer using the ACPI
1.0 version GUID.
The OS loader must retrieve the pointer to the RSDP structure from the EFI System Table before
assuming platform control via the EFI ExitBootServices interface. See the UEFI Specification for
more information.*/