summaryrefslogtreecommitdiff
path: root/kernel/include/efi.h
blob: 784b5fbf4bfde969f0bee1987a9660b8de4d0f9d (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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
#pragma once

/*
As per UEFI Specification, version 2.8

You may use this code for any purpose.

This code is provided as-is and includes no claims, warranties, or
representations whether express, implied, or otherwise for
merchantability, fitness for a particular purpose, non-infringement,
absence of latent or other defects, accuracy, or the presence or
absence of errors, whether or not known or discoverable.

*/

// PE32+ Subsystem type for EFI images
#define EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION 10
#define EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
#define EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER 12

// PE32+ Machine type for EFI images
#define EFI_IMAGE_MACHINE_IA32 0x014c
#define EFI_IMAGE_MACHINE_IA64 0x0200
#define EFI_IMAGE_MACHINE_EBC 0x0EBC
#define EFI_IMAGE_MACHINE_x64 0x8664
#define EFI_IMAGE_MACHINE_ARMTHUMB_MIXED 0x01C2
#define EFI_IMAGE_MACHINE_AARCH64 0xAA64
#define EFI_IMAGE_MACHINE_RISCV32 0x5032
#define EFI_IMAGE_MACHINE_RISCV64 0x5064
#define EFI_IMAGE_MACHINE_RISCV128 0x5128

/******************/
/*  Status_Codes  */
/******************/
#define EFI_SUCCESS 0x0000000000000000

#define EFI_WARN_UNKNOWN_GLYPH 0x0000000000000001
#define EFI_WARN_DELETE_FAILURE 0x0000000000000002
#define EFI_WARN_WRITE_FAILURE 0x0000000000000003
#define EFI_WARN_BUFFER_TOO_SMALL 0x0000000000000004
#define EFI_WARN_STALE_DATA 0x0000000000000005
#define EFI_WARN_FILE_SYSTEM 0x0000000000000006
#define EFI_WARN_RESET_REQUIRED 0x0000000000000007

#define EFI_LOAD_ERROR 0x8000000000000001
#define EFI_INVALID_PARAMETER 0x8000000000000002
#define EFI_UNSUPPORTED 0x8000000000000003
#define EFI_BAD_BUFFER_SIZE 0x8000000000000004
#define EFI_BUFFER_TOO_SMALL 0x8000000000000005
#define EFI_NOT_READY 0x8000000000000006
#define EFI_DEVICE_ERROR 0x8000000000000007
#define EFI_WRITE_PROTECTED 0x8000000000000008
#define EFI_OUT_OF_RESOURCES 0x8000000000000009
#define EFI_VOLUME_CORRUPTED 0x800000000000000a
#define EFI_VOLUME_FULL 0x800000000000000b
#define EFI_NO_MEDIA 0x800000000000000c
#define EFI_MEDIA_CHANGED 0x800000000000000d
#define EFI_NOT_FOUND 0x800000000000000e
#define EFI_ACCESS_DENIED 0x800000000000000f
#define EFI_NO_RESPONSE 0x8000000000000010
#define EFI_NO_MAPPING 0x8000000000000011
#define EFI_TIMEOUT 0x8000000000000012
#define EFI_NOT_STARTED 0x8000000000000013
#define EFI_ALREADY_STARTED 0x8000000000000014
#define EFI_ABORTED 0x8000000000000015
#define EFI_ICMP_ERROR 0x8000000000000016
#define EFI_TFTP_ERROR 0x8000000000000017
#define EFI_PROTOCOL_ERROR 0x8000000000000018
#define EFI_INCOMPATIBLE_VERSION 0x8000000000000019
#define EFI_SECURITY_VIOLATION 0x800000000000001a
#define EFI_CRC_ERROR 0x800000000000001b
#define EFI_END_OF_MEDIA 0x800000000000001c
#define EFI_END_OF_FILE 0x800000000000001f
#define EFI_INVALID_LANGUAGE 0x8000000000000020
#define EFI_COMPROMISED_DATA 0x8000000000000021
#define EFI_IP_ADDRESS_CONFLICT 0x8000000000000022
#define EFI_HTTP_ERROR 0x8000000000000023

#define EFI_ERROR(status) ((status) & 0x8000000000000000)

#include <stdint.h>
#include <stddef.h>

typedef uint8_t BOOLEAN;
#define TRUE 1
#define FALSE 0

typedef uintmax_t UINTN;
typedef intmax_t INTN;

typedef uint64_t UINT64;
typedef uint32_t UINT32;
typedef uint16_t UINT16;
typedef uint8_t UINT8;

typedef int64_t INT64;
typedef int32_t INT32;
typedef int16_t INT16;
typedef int8_t INT8;

typedef uint8_t CHAR8;
typedef uint16_t CHAR16;

typedef void VOID;

typedef UINTN EFI_STATUS;

typedef VOID *EFI_HANDLE;
typedef VOID *EFI_EVENT;
typedef UINT64 EFI_LBA;
typedef UINTN EFI_TPL;

typedef UINT64 EFI_PHYSICAL_ADDRESS;

typedef UINT8 EFI_MAC_ADDRESS[4];
typedef UINT8 EFI_IPv4_ADDRESS[4];
typedef UINT8 EFI_IPv6_ADDRESS[16];
typedef UINT8 __attribute__((aligned(4))) EFI_IP_ADDRESS[16];

#define IN
#define OUT
#define OPTIONAL
#define CONST const

// Only true for x64(as far as I know)
#define EFIAPI __attribute__((ms_abi))

/*******************/
/*  Boot_Services  */
/*******************/

//
// CreateEvent
//
typedef VOID *EFI_EVENT;
// These types can be “ORed” together as needed – for example,
// EVT_TIMER might be “ORed” with EVT_NOTIFY_WAIT or
// EVT_NOTIFY_SIGNAL. For actual definitions check the specification.
#define EVT_TIMER 0x80000000
#define EVT_RUNTIME 0x40000000
#define EVT_NOTIFY_WAIT 0x00000100

#define EVT_NOTIFY_SIGNAL 0x00000200
#define EVT_SIGNAL_EXIT_BOOT_SERVICES 0x00000201
#define EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202

typedef VOID(EFIAPI *EFI_EVENT_NOTIFY)(IN EFI_EVENT Event, IN VOID *Context);

typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(
	IN UINT32 Type, IN EFI_TPL NotifyTpl,
	IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
	IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *Event);

//
// CreateEventEx
//
typedef struct {
	UINT32 Data1;
	UINT16 Data2;
	UINT16 Data3;
	UINT8 Data4[8];
} EFI_GUID;
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
	IN UINT32 Type, IN EFI_TPL NotifyTpl,
	IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
	IN CONST VOID *NotifyContext OPTIONAL,
	IN CONST EFI_GUID *EventGroup OPTIONAL, OUT EFI_EVENT *Event);
#define EFI_EVENT_GROUP_EXIT_BOOT_SERVICES \
	{ 0x27abf055,                          \
	  0xb1b8,                              \
	  0x4c26,                              \
	  { 0x80, 0x48, 0x74, 0x8f, 0x37, 0xba, 0xa2, 0xdf } }

#define EFI_EVENT_GROUP_VIRTUAL_ADDRESS_CHANGE \
	{ 0x13fa7698,                              \
	  0xc831,                                  \
	  0x49c7,                                  \
	  { 0x87, 0xea, 0x8f, 0x43, 0xfc, 0xc2, 0x51, 0x96 } }

#define EFI_EVENT_GROUP_MEMORY_MAP_CHANGE \
	{ 0x78bee926,                         \
	  0x692f,                             \
	  0x48fd,                             \
	  { 0x9e, 0xdb, 0x1, 0x42, 0x2e, 0xf0, 0xd7, 0xab } }

#define EFI_EVENT_GROUP_READY_TO_BOOT \
	{ 0x7ce88fb3,                     \
	  0x4bd7,                         \
	  0x4679,                         \
	  { 0x87, 0xa8, 0xa8, 0xd8, 0xde, 0xe5, 0xd, 0x2b } }

#define EFI_EVENT_GROUP_RESET_SYSTEM \
	{ 0x62da6a56,                    \
	  0x13fb,                        \
	  0x485a,                        \
	  { 0xa8, 0xda, 0xa3, 0xdd, 0x79, 0x12, 0xcb, 0x6b } }

//
// CloseEvent
//
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(IN EFI_EVENT Event);

//
// SignalEvent
//
typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(IN EFI_EVENT Event);

//
// WaitForEvent
//
typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(IN UINTN NumberOfEvents,
											   IN EFI_EVENT *Event,
											   OUT UINTN *Index);

//
// CheckEvent
//
typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(IN EFI_EVENT Event);

//
// SetTimer
//
typedef enum { TimerCancel, TimerPeriodic, TimerRelative } EFI_TIMER_DELAY;
typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(IN EFI_EVENT Event,
										  IN EFI_TIMER_DELAY Type,
										  IN UINT64 TriggerTime);

//
// RaiseTPL
//
typedef EFI_TPL(EFIAPI *EFI_RAISE_TPL)(IN EFI_TPL NewTpl);
typedef UINTN EFI_TPL;
#define TPL_APPLICATION 4
#define TPL_CALLBACK 8
#define TPL_NOTIFY 16
#define TPL_HIGH_LEVEL 31

//
// RestoreTPL
//
typedef VOID(EFIAPI *EFI_RESTORE_TPL)(IN EFI_TPL OldTpl);

//
// AllocatePages
//
typedef enum {
	AllocateAnyPages,
	AllocateMaxAddress,
	AllocateAddress,
	MaxAllocateType
} EFI_ALLOCATE_TYPE;
typedef enum {
	EfiReservedMemoryType = 0,
	EfiLoaderCode = 1,
	EfiLoaderData = 2,
	EfiBootServicesCode = 3,
	EfiBootServicesData = 4,
	EfiRuntimeServicesCode = 5,
	EfiRuntimeServicesData = 6,
	EfiConventionalMemory = 7,
	EfiUnusableMemory = 8,
	EfiACPIReclaimMemory = 9,
	EfiACPIMemoryNVS = 10,
	EfiMemoryMappedIO = 11,
	EfiMemoryMappedIOPortSpace = 12,
	EfiPalCode = 13,
	EfiPersistentMemory = 14,
	EfiMaxMemoryType = 15
} EFI_MEMORY_TYPE;
typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(
	IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages,
	IN OUT EFI_PHYSICAL_ADDRESS *Memory);

//
// FreePages
//
typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(IN EFI_PHYSICAL_ADDRESS Memory,
										   IN UINTN Pages);

//
// GetMemoryMap
//
typedef UINT64 EFI_VIRTUAL_ADDRESS;
typedef struct {
	UINT32 Type;
	EFI_PHYSICAL_ADDRESS PhysicalStart;
	EFI_VIRTUAL_ADDRESS VirtualStart;
	UINT64 NumberOfPages;
	UINT64 Attribute;
} EFI_MEMORY_DESCRIPTOR;
typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(
	IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap,
	OUT UINTN *MapKey, OUT UINTN *DescriptorSize,
	OUT UINT32 *DescriptorVersion);
#define EFI_MEMORY_UC 0x0000000000000001
#define EFI_MEMORY_WC 0x0000000000000002
#define EFI_MEMORY_WT 0x0000000000000004
#define EFI_MEMORY_WB 0x0000000000000008
#define EFI_MEMORY_UCE 0x0000000000000010
#define EFI_MEMORY_WP 0x0000000000001000
#define EFI_MEMORY_RP 0x0000000000002000
#define EFI_MEMORY_XP 0x0000000000004000
#define EFI_MEMORY_NV 0x0000000000008000
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000
#define EFI_MEMORY_RO 0x0000000000020000
#define EFI_MEMORY_SP 0x0000000000040000
#define EFI_MEMORY_CPU_CRYPTO 0x0000000000080000
#define EFI_MEMORY_RUNTIME 0x8000000000000000
#define EFI_MEMORY_DESCRIPTOR_VERSION 1

//
// AllocatePool
//
typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(IN EFI_MEMORY_TYPE PoolType,
											  IN UINTN Size, OUT VOID **Buffer);

//
// FreePool
//
typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(IN VOID *Buffer);

//
// InstallProtocolInterface
//
typedef enum { EFI_NATIVE_INTERFACE } EFI_INTERFACE_TYPE;
typedef EFI_STATUS(EFIAPI *EFI_INSTALL_PROTOCOL_INTERFACE)(
	IN OUT EFI_HANDLE *Handle, IN EFI_GUID *Protocol,
	IN EFI_INTERFACE_TYPE InterfaceType, IN VOID *Interface);

//
// UninstallProtocolInterface
//
typedef EFI_STATUS(EFIAPI *EFI_UNINSTALL_PROTOCOL_INTERFACE)(
	IN EFI_HANDLE Handle, IN EFI_GUID *Protocol, IN VOID *Interface);

//
// ReinstallProtocolInterface
//
typedef EFI_STATUS(EFIAPI *EFI_REINSTALL_PROTOCOL_INTERFACE)(
	IN EFI_HANDLE Handle, IN EFI_GUID *Protocol, IN VOID *OldInterface,
	IN VOID *NewInterface);

//
// RegisterProtocolNotify
//
typedef EFI_STATUS(EFIAPI *EFI_REGISTER_PROTOCOL_NOTIFY)(
	IN EFI_GUID *Protocol, IN EFI_EVENT Event, OUT VOID **Registration);

//
// LocateHandle
//
typedef enum {
	AllHandles,
	ByRegisterNotify,
	ByProtocol
} EFI_LOCATE_SEARCH_TYPE;
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_HANDLE)(
	IN EFI_LOCATE_SEARCH_TYPE SearchType, IN EFI_GUID *Protocol OPTIONAL,
	IN VOID *SearchKey OPTIONAL, IN OUT UINTN *BufferSize,
	OUT EFI_HANDLE *Buffer);

//
// HandleProtocol
//
typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(IN EFI_HANDLE Handle,
												IN EFI_GUID *Protocol,
												OUT VOID **Interface);

//
// LocateDevicePath
//
typedef struct {
	UINT8 Type;
	UINT8 SubType;
	UINT8 Length[2];
} EFI_DEVICE_PATH_PROTOCOL;
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_DEVICE_PATH)(
	IN EFI_GUID *Protocol, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
	OUT EFI_HANDLE *Device);

//
// OpenProtocol
//
typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL)(IN EFI_HANDLE Handle,
											  IN EFI_GUID *Protocol,
											  OUT VOID **InterfaceOPTIONAL,
											  IN EFI_HANDLE AgentHandle,
											  IN EFI_HANDLE ControllerHandle,
											  IN UINT32 Attributes);
#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001
#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002
#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004
#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008
#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010
#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020

//
// CloseProtocol
//
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_PROTOCOL)(IN EFI_HANDLE Handle,
											   IN EFI_GUID *Protocol,
											   IN EFI_HANDLE AgentHandle,
											   IN EFI_HANDLE ControllerHandle);

//
// OpenProtocolInformation
//
typedef struct {
	EFI_HANDLE AgentHandle;
	EFI_HANDLE ControllerHandle;
	UINT32 Attributes;
	UINT32 OpenCount;
} EFI_OPEN_PROTOCOL_INFORMATION_ENTRY;
typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION)(
	IN EFI_HANDLE Handle, IN EFI_GUID *Protocol,
	OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer,
	OUT UINTN *EntryCount);

//
// ConnectController
//
typedef EFI_STATUS(EFIAPI *EFI_CONNECT_CONTROLLER)(
	IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE *DriverImageHandle OPTIONAL,
	IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
	IN BOOLEAN Recursive);

//
// DisconnectController
//
typedef EFI_STATUS(EFIAPI *EFI_DISCONNECT_CONTROLLER)(
	IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE DriverImageHandle OPTIONAL,
	IN EFI_HANDLE ChildHandle OPTIONAL);

//
// ProtocolsPerHandle
//
typedef EFI_STATUS(EFIAPI *EFI_PROTOCOLS_PER_HANDLE)(
	IN EFI_HANDLE Handle, OUT EFI_GUID ***ProtocolBuffer,
	OUT UINTN *ProtocolBufferCount);

//
// LocateHandleBuffer
//
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_HANDLE_BUFFER)(
	IN EFI_LOCATE_SEARCH_TYPE SearchType, IN EFI_GUID *Protocol OPTIONAL,
	IN VOID *SearchKeyOPTIONAL, IN OUT UINTN *NoHandles,
	OUT EFI_HANDLE **Buffer);

//
// LocateProtocol
//
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(IN EFI_GUID *Protocol,
												IN VOID *Registration OPTIONAL,
												OUT VOID **Interface);

//
// InstallMultipleProtocolInterfaces
//
typedef EFI_STATUS(EFIAPI *EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES)(
	IN OUT EFI_HANDLE *Handle, ...);

//
// UninstallMultipleProtocolInterfaces
//
typedef EFI_STATUS(EFIAPI *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES)(
	IN EFI_HANDLE Handle, ...);

//
// LoadImage
//
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_LOAD)(
	IN BOOLEAN BootPolicy, IN EFI_HANDLE ParentImageHandle,
	IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN VOID *SourceBuffer OPTIONAL,
	IN UINTN SourceSize, OUT EFI_HANDLE *ImageHandle);

//
// StartImage
//
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_START)(IN EFI_HANDLE ImageHandle,
											OUT UINTN *ExitDataSize,
											OUT CHAR16 **ExitData OPTIONAL);

//
// UnloadImage
//
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(IN EFI_HANDLE ImageHandle);

//
// Exit
//
typedef EFI_STATUS(EFIAPI *EFI_EXIT)(IN EFI_HANDLE ImageHandle,
									 IN EFI_STATUS ExitStatus,
									 IN UINTN ExitDataSize,
									 IN CHAR16 *ExitData OPTIONAL);

//
// ExitBootServices
//
typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(IN EFI_HANDLE ImageHandle,
												   IN UINTN MapKey);

//
// SetWatchdogTimer
//
typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(
	IN UINTN Timeout, IN UINT64 WatchdogCode, IN UINTN DataSize,
	IN CHAR16 *WatchdogData OPTIONAL);

//
// Stall
//
typedef EFI_STATUS(EFIAPI *EFI_STALL)(IN UINTN Microseconds);

//
// CopyMem
//
typedef VOID(EFIAPI *EFI_COPY_MEM)(IN VOID *Destination, IN VOID *Source,
								   IN UINTN Length);

//
// SetMem
//
typedef VOID(EFIAPI *EFI_SET_MEM)(IN VOID *Buffer, IN UINTN Size,
								  IN UINT8 Value);

//
// GetNextMonotonicCount
//
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(OUT UINT64 *Count);

//
// InstallConfigurationTable
//
typedef EFI_STATUS(EFIAPI *EFI_INSTALL_CONFIGURATION_TABLE)(IN EFI_GUID *Guid,
															IN VOID *Table);

//
// CalculateCrc32
//
typedef EFI_STATUS(EFIAPI *EFI_CALCULATE_CRC32)(IN VOID *Data,
												IN UINTN DataSize,
												OUT UINT32 *Crc32);

/**********************/
/*  Runtime_Services  */
/**********************/
#define EFI_RT_SUPPORTED_GET_TIME 0x0001
#define EFI_RT_SUPPORTED_SET_TIME 0x0002
#define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004
#define EFI_RT_SUPPORTED_SET_WAKEUP_TIME 0x0008
#define EFI_RT_SUPPORTED_GET_VARIABLE 0x0010
#define EFI_RT_SUPPORTED_GET_NEXT_VARIABLE_NAME 0x0020
#define EFI_RT_SUPPORTED_SET_VARIABLE 0x0040
#define EFI_RT_SUPPORTED_SET_VIRTUAL_ADDRESS_MAP 0x0080
#define EFI_RT_SUPPORTED_CONVERT_POINTER 0x0100
#define EFI_RT_SUPPORTED_GET_NEXT_HIGH_MONOTONIC_COUNT 0x0200
#define EFI_RT_SUPPORTED_RESET_SYSTEM 0x0400
#define EFI_RT_SUPPORTED_UPDATE_CAPSULE 0x0800
#define EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES 0x1000
#define EFI_RT_SUPPORTED_QUERY_VARIABLE_INFO 0x2000

//
// GetVariable
//
typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(IN CHAR16 *VariableName,
											 IN EFI_GUID *VendorGuid,
											 OUT UINT32 *Attributes OPTIONAL,
											 IN OUT UINTN *DataSize,
											 OUT VOID *Data OPTIONAL);
#define EFI_VARIABLE_NON_VOLATILE 0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
// NOTE: EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS is deprecated
// and should be considered reserved.
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE 0x00000040
#define EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS 0x00000080
#define EFI_VARIABLE_AUTHENTICATION_3_CERT_ID_SHA256 1
typedef struct {
	UINT8 Type;
	UINT32 IdSize;
	// UINT8      Id[IdSize];
} EFI_VARIABLE_AUTHENTICATION_3_CERT_ID;

//
// GetNextVariableName
//
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(
	IN OUT UINTN *VariableNameSize, IN OUT CHAR16 *VariableName,
	IN OUT EFI_GUID *VendorGuid);

//
// SetVariable
//
typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(IN CHAR16 *VariableName,
											 IN EFI_GUID *VendorGuid,
											 IN UINT32 Attributes,
											 IN UINTN DataSize, IN VOID *Data);

//
// QueryVariableInfo
//
typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)(
	IN UINT32 Attributes, OUT UINT64 *MaximumVariableStorageSize,
	OUT UINT64 *RemainingVariableStorageSize, OUT UINT64 *MaximumVariableSize);

//
// GetTime
//
// This represents the current time information
typedef struct {
	UINT16 Year; // 1900 – 9999
	UINT8 Month; // 1 – 12
	UINT8 Day; // 1 – 31
	UINT8 Hour; // 0 – 23
	UINT8 Minute; // 0 – 59
	UINT8 Second; // 0 – 59
	UINT8 Pad1;
	UINT32 Nanosecond; // 0 – 999,999,999
	INT16 TimeZone; // -1440 to 1440 or 2047
	UINT8 Daylight;
	UINT8 Pad2;
} EFI_TIME;
// Bit Definitions for EFI_TIME.Daylight
#define EFI_TIME_ADJUST_DAYLIGHT 0x01
#define EFI_TIME_IN_DAYLIGHT 0x02
// Value Definition for EFI_TIME.TimeZone
#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
// This provides the capabilities of the
// real time clock device as exposed through the EFI interfaces.
typedef struct {
	UINT32 Resolution;
	UINT32 Accuracy;
	BOOLEAN SetsToZero;
} EFI_TIME_CAPABILITIES;
typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(
	OUT EFI_TIME *Time, OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL);

//
// SetTime
//
typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(IN EFI_TIME *Time);

//
// GetWakeupTime
//
typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(OUT BOOLEAN *Enabled,
												OUT BOOLEAN *Pending,
												OUT EFI_TIME *Time);

//
// SetWakeupTime
//
typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(IN BOOLEAN Enable,
												IN EFI_TIME *Time OPTIONAL);

//
// SetVirtualAddressMap
//
typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(
	IN UINTN MemoryMapSize, IN UINTN DescriptorSize,
	IN UINT32 DescriptorVersion, IN EFI_MEMORY_DESCRIPTOR *VirtualMap);

//
// ConvertPointer
//
typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(IN UINTN DebugDisposition,
												IN VOID **Address);
#define EFI_OPTIONAL_PTR 0x00000001

//
// ResetSystem
//
typedef enum {
	EfiResetCold,
	EfiResetWarm,
	EfiResetShutdown,
	EfiResetPlatformSpecific
} EFI_RESET_TYPE;
typedef VOID(EFIAPI *EFI_RESET_SYSTEM)(IN EFI_RESET_TYPE ResetType,
									   IN EFI_STATUS ResetStatus,
									   IN UINTN DataSize,
									   IN VOID *ResetData OPTIONAL);

//
// GetNextHighMonotonicCount
//
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONOTONIC_COUNT)(
	OUT UINT32 *HighCount);

//
// UpdateCapsule
//
typedef struct {
	UINT64 Length;
	union {
		EFI_PHYSICAL_ADDRESS DataBlock;
		EFI_PHYSICAL_ADDRESS ContinuationPointer;
	} Union;
} EFI_CAPSULE_BLOCK_DESCRIPTOR;
typedef struct {
	EFI_GUID CapsuleGuid;
	UINT32 HeaderSize;
	UINT32 Flags;
	UINT32 CapsuleImageSize;
} EFI_CAPSULE_HEADER;
typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)(
	IN EFI_CAPSULE_HEADER **CapsuleHeaderArray, IN UINTN CapsuleCount,
	IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL);

//
// QueryCapsuleCapabilities
//
typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)(
	IN EFI_CAPSULE_HEADER **CapsuleHeaderArray, IN UINTN CapsuleCount,
	OUT UINT64 *MaximumCapsuleSize, OUT EFI_RESET_TYPE *ResetType);

/***********************/
/*  Simple_Text_Stuff  */
/***********************/

//
//
// Input stuff
//
//
#define EFI_SIMPLE_TEXT_INPUT_PROTOCOL_GUID \
	{ 0x387477c1,                           \
	  0x69c7,                               \
	  0x11d2,                               \
	  { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } }

//
// InputReset
//
struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)(
	IN struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This,
	IN BOOLEAN ExtendedVerification);

//
// ReadKeyStroke
//
typedef struct {
	UINT16 ScanCode;
	CHAR16 UnicodeChar;
} EFI_INPUT_KEY;
typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)(
	IN struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, OUT EFI_INPUT_KEY *Key);

typedef struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
	EFI_INPUT_RESET Reset;
	EFI_INPUT_READ_KEY ReadKeyStroke;
	EFI_EVENT WaitForKey;
} EFI_SIMPLE_TEXT_INPUT_PROTOCOL;

//
//
// Output stuff
//
//

//*******************************************************
// UNICODE DRAWING CHARACTERS
//*******************************************************
#define BOXDRAW_HORIZONTAL 0x2500
#define BOXDRAW_VERTICAL 0x2502
#define BOXDRAW_DOWN_RIGHT 0x250c
#define BOXDRAW_DOWN_LEFT 0x2510
#define BOXDRAW_UP_RIGHT 0x2514
#define BOXDRAW_UP_LEFT 0x2518
#define BOXDRAW_VERTICAL_RIGHT 0x251c
#define BOXDRAW_VERTICAL_LEFT 0x2524
#define BOXDRAW_DOWN_HORIZONTAL 0x252c
#define BOXDRAW_UP_HORIZONTAL 0x2534
#define BOXDRAW_VERTICAL_HORIZONTAL 0x253c
#define BOXDRAW_DOUBLE_HORIZONTAL 0x2550
#define BOXDRAW_DOUBLE_VERTICAL 0x2551
#define BOXDRAW_DOWN_RIGHT_DOUBLE 0x2552
#define BOXDRAW_DOWN_DOUBLE_RIGHT 0x2553
#define BOXDRAW_DOUBLE_DOWN_RIGHT 0x2554
#define BOXDRAW_DOWN_LEFT_DOUBLE 0x2555
#define BOXDRAW_DOWN_DOUBLE_LEFT 0x2556
#define BOXDRAW_DOUBLE_DOWN_LEFT 0x2557
#define BOXDRAW_UP_RIGHT_DOUBLE 0x2558
#define BOXDRAW_UP_DOUBLE_RIGHT 0x2559
#define BOXDRAW_DOUBLE_UP_RIGHT 0x255a
#define BOXDRAW_UP_LEFT_DOUBLE 0x255b
#define BOXDRAW_UP_DOUBLE_LEFT 0x255c
#define BOXDRAW_DOUBLE_UP_LEFT 0x255d
#define BOXDRAW_VERTICAL_RIGHT_DOUBLE 0x255e
#define BOXDRAW_VERTICAL_DOUBLE_RIGHT 0x255f
#define BOXDRAW_DOUBLE_VERTICAL_RIGHT 0x2560
#define BOXDRAW_VERTICAL_LEFT_DOUBLE 0x2561
#define BOXDRAW_VERTICAL_DOUBLE_LEFT 0x2562
#define BOXDRAW_DOUBLE_VERTICAL_LEFT 0x2563
#define BOXDRAW_DOWN_HORIZONTAL_DOUBLE 0x2564
#define BOXDRAW_DOWN_DOUBLE_HORIZONTAL 0x2565
#define BOXDRAW_DOUBLE_DOWN_HORIZONTAL 0x2566
#define BOXDRAW_UP_HORIZONTAL_DOUBLE 0x2567
#define BOXDRAW_UP_DOUBLE_HORIZONTAL 0x2568
#define BOXDRAW_DOUBLE_UP_HORIZONTAL 0x2569
#define BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE 0x256a
#define BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL 0x256b
#define BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL 0x256c
//*******************************************************
// EFI Required Block Elements Code Chart
//*******************************************************
#define BLOCKELEMENT_FULL_BLOCK 0x2588
#define BLOCKELEMENT_LIGHT_SHADE 0x2591
//*******************************************************
// EFI Required Geometric Shapes Code Chart
//*******************************************************
#define GEOMETRICSHAPE_UP_TRIANGLE 0x25b2
#define GEOMETRICSHAPE_RIGHT_TRIANGLE 0x25ba
#define GEOMETRICSHAPE_DOWN_TRIANGLE 0x25bc
#define GEOMETRICSHAPE_LEFT_TRIANGLE 0x25c4
//*******************************************************
// EFI Required Arrow shapes
//*******************************************************
#define ARROW_UP 0x2191
#define ARROW_DOWN 0x2193

#define EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL_GUID \
	{ 0x387477c2,                            \
	  0x69c7,                                \
	  0x11d2,                                \
	  { 0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b } }

//
// TestReset
//
struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
	IN BOOLEAN ExtendedVerification);

//
// OutputString
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN CHAR16 *String);

//
// TestString
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN CHAR16 *String);

//
// QueryMode
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber,
	OUT UINTN *Columns, OUT UINTN *Rows);

//
// SetMode
//
typedef EFI_STATUS (*EFIAPI EFI_TEXT_SET_MODE)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN ModeNumber);

//
// SetAttribute
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN Attribute);
//*******************************************************
// Attributes
//*******************************************************
#define EFI_BLACK 0x00
#define EFI_BLUE 0x01
#define EFI_GREEN 0x02
#define EFI_CYAN 0x03
#define EFI_RED 0x04
#define EFI_MAGENTA 0x05
#define EFI_BROWN 0x06
#define EFI_LIGHTGRAY 0x07
#define EFI_BRIGHT 0x08
#define EFI_DARKGRAY 0x08
#define EFI_LIGHTBLUE 0x09
#define EFI_LIGHTGREEN 0x0A
#define EFI_LIGHTCYAN 0x0B
#define EFI_LIGHTRED 0x0C
#define EFI_LIGHTMAGENTA 0x0D
#define EFI_YELLOW 0x0E
#define EFI_WHITE 0x0F

#define EFI_BACKGROUND_BLACK 0x00
#define EFI_BACKGROUND_BLUE 0x10
#define EFI_BACKGROUND_GREEN 0x20
#define EFI_BACKGROUND_CYAN 0x30
#define EFI_BACKGROUND_RED 0x40
#define EFI_BACKGROUND_MAGENTA 0x50
#define EFI_BACKGROUND_BROWN 0x60
#define EFI_BACKGROUND_LIGHTGRAY 0x70
// The foreground color and background color can
//  be OR-ed(|) together to set them both in one call.

//
// ClearScreen
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This);

//
// SetCursorPosition
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN UINTN Column,
	IN UINTN Row);

//
// EnableCursor
//
typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)(
	IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, IN BOOLEAN Visible);

typedef struct {
	INT32 MaxMode; // current settings
	INT32 Mode;
	INT32 Attribute;
	INT32 CursorColumn;
	INT32 CursorRow;
	BOOLEAN CursorVisible;
} SIMPLE_TEXT_OUTPUT_MODE;

typedef struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
	EFI_TEXT_RESET Reset;
	EFI_TEXT_STRING OutputString;
	EFI_TEXT_TEST_STRING TestString;
	EFI_TEXT_QUERY_MODE QueryMode;
	EFI_TEXT_SET_MODE SetMode;
	EFI_TEXT_SET_ATTRIBUTE SetAttribute;
	EFI_TEXT_CLEAR_SCREEN ClearScreen;
	EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
	EFI_TEXT_ENABLE_CURSOR EnableCursor;
	SIMPLE_TEXT_OUTPUT_MODE *Mode;
} EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;

/***********************/
/*  Table_Definitions  */
/***********************/

#define EFI_SPECIFICATION_VERSION EFI_SYSTEM_TABLE_REVISION
#define EFI_SYSTEM_TABLE_REVISION EFI_2_8_SYSTEM_TABLE_REVISION

typedef struct {
	UINT64 Signature;
	UINT32 Revision;
	UINT32 HeaderSize;
	UINT32 CRC32;
	UINT32 Reserved;
} EFI_TABLE_HEADER;

#define EFI_BOOT_SERVICES_SIGNATURE 0x56524553544f4f42
#define EFI_BOOT_SERVICES_REVISION EFI_SPECIFICATION_VERSION
typedef struct {
	EFI_TABLE_HEADER Hdr;

	//
	// Task Priority Services
	//
	EFI_RAISE_TPL RaiseTPL; // EFI 1.0+
	EFI_RESTORE_TPL RestoreTPL; // EFI 1.0+

	//
	// Memory Services
	//
	EFI_ALLOCATE_PAGES AllocatePages; // EFI 1.0+
	EFI_FREE_PAGES FreePages; // EFI 1.0+
	EFI_GET_MEMORY_MAP GetMemoryMap; // EFI 1.0+
	EFI_ALLOCATE_POOL AllocatePool; // EFI 1.0+
	EFI_FREE_POOL FreePool; // EFI 1.0+

	//
	// Event & Timer Services
	//
	EFI_CREATE_EVENT CreateEvent; // EFI 1.0+
	EFI_SET_TIMER SetTimer; // EFI 1.0+
	EFI_WAIT_FOR_EVENT WaitForEvent; // EFI 1.0+
	EFI_SIGNAL_EVENT SignalEvent; // EFI 1.0+
	EFI_CLOSE_EVENT CloseEvent; // EFI 1.0+
	EFI_CHECK_EVENT CheckEvent; // EFI 1.0+

	//
	// Protocol Handler Services
	//
	EFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface; // EFI 1.0+
	EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface; // EFI 1.0+
	EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface; // EFI 1.0+
	EFI_HANDLE_PROTOCOL HandleProtocol; // EFI 1.0+
	VOID *Reserved; // EFI 1.0+
	EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify; // EFI 1.0+
	EFI_LOCATE_HANDLE LocateHandle; // EFI 1.0+
	EFI_LOCATE_DEVICE_PATH LocateDevicePath; // EFI 1.0+
	EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable; // EFI 1.0+

	//
	// Image Services
	//
	EFI_IMAGE_LOAD LoadImage; // EFI 1.0+
	EFI_IMAGE_START
		StartImage; // EFI 1.0+UEFI Specification, Version 2.8 EFI System Table
	EFI_EXIT Exit; // EFI 1.0+
	EFI_IMAGE_UNLOAD UnloadImage; // EFI 1.0+
	EFI_EXIT_BOOT_SERVICES ExitBootServices; // EFI 1.0+

	//
	// Miscellaneous Services
	//
	EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount; // EFI 1.0+
	EFI_STALL Stall; // EFI 1.0+
	EFI_SET_WATCHDOG_TIMER SetWatchdogTimer; // EFI 1.0+

	//
	// DriverSupport Services
	//
	EFI_CONNECT_CONTROLLER ConnectController; // EFI 1.1
	EFI_DISCONNECT_CONTROLLER DisconnectController; // EFI 1.1+

	//
	// Open and Close Protocol Services
	//
	EFI_OPEN_PROTOCOL OpenProtocol; // EFI 1.1+
	EFI_CLOSE_PROTOCOL CloseProtocol; // EFI 1.1+
	EFI_OPEN_PROTOCOL_INFORMATION OpenProtocolInformation; // EFI 1.1+

	//
	// Library Services
	//
	EFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle; // EFI 1.1+
	EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer; // EFI 1.1+
	EFI_LOCATE_PROTOCOL LocateProtocol; // EFI 1.1+
	EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES
	InstallMultipleProtocolInterfaces; // EFI 1.1+
	EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES
	UninstallMultipleProtocolInterfaces; // EFI 1.1+

	//
	// 32-bit CRC Services
	//
	EFI_CALCULATE_CRC32 CalculateCrc32; // EFI 1.1+

	//
	// Miscellaneous Services
	//
	EFI_COPY_MEM CopyMem; // EFI 1.1+
	EFI_SET_MEM
		SetMem; // EFI 1.1+UEFI Specification, Version 2.8 EFI System Table
	EFI_CREATE_EVENT_EX CreateEventEx; // UEFI 2.0+
} EFI_BOOT_SERVICES;

#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552
#define EFI_RUNTIME_SERVICES_REVISION EFI_SPECIFICATION_VERSION
typedef struct {
	EFI_TABLE_HEADER Hdr;

	//
	// Time Services
	//
	EFI_GET_TIME GetTime;
	EFI_SET_TIME SetTime;
	EFI_GET_WAKEUP_TIME GetWakeupTime;
	EFI_SET_WAKEUP_TIME SetWakeupTime;

	//
	// Virtual Memory Services
	//
	EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
	EFI_CONVERT_POINTER ConvertPointer;

	//
	// Variable Services
	//
	EFI_GET_VARIABLE GetVariable;
	EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
	EFI_SET_VARIABLE SetVariable;

	//
	// Miscellaneous Services
	//
	EFI_GET_NEXT_HIGH_MONOTONIC_COUNT GetNextHighMonotonicCount;
	EFI_RESET_SYSTEM ResetSystem;

	//
	// UEFI 2.0 Capsule Services
	//
	EFI_UPDATE_CAPSULE UpdateCapsule;
	EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;

	//
	// Miscellaneous UEFI 2.0 Service
	//
	EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

typedef struct {
	EFI_GUID VendorGuid;
	VOID *VendorTable;
} EFI_CONFIGURATION_TABLE;

#define ACPI_TABLE_GUID \
	{ 0xeb9d2d30,       \
	  0x2d88,           \
	  0x11d3,           \
	  { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }

#define SAL_SYSTEM_TABLE_GUID \
	{ 0xeb9d2d32,             \
	  0x2d88,                 \
	  0x11d3,                 \
	  { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }

#define SMBIOS_TABLE_GUID \
	{ 0xeb9d2d31,         \
	  0x2d88,             \
	  0x11d3,             \
	  { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }

#define SMBIOS3_TABLE_GUID \
	{ 0xf2fd1544,          \
	  0x9794,              \
	  0x4a2c,              \
	  { 0x99, 0x2e, 0xe5, 0xbb, 0xcf, 0x20, 0xe3, 0x94 } }

#define MPS_TABLE_GUID \
	{ 0xeb9d2d2f,      \
	  0x2d88,          \
	  0x11d3,          \
	  { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }

//
// ACPI 2.0 or newer tables should use EFI_ACPI_TABLE_GUID
//
#define EFI_ACPI_TABLE_GUID \
	{ 0x8868e871,           \
	  0xe4f1,               \
	  0x11d3,               \
	  { 0xbc, 0x22, 0x00, 0x80, 0xc7, 0x3c, 0x88, 0x81 } }
#define EFI_ACPI_20_TABLE_GUID EFI_ACPI_TABLE_GUID

#define ACPI_TABLE_GUID \
	{ 0xeb9d2d30,       \
	  0x2d88,           \
	  0x11d3,           \
	  { 0x9a, 0x16, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
#define ACPI_10_TABLE_GUID ACPI_TABLE_GUID

#define EFI_JSON_CONFIG_DATA_TABLE_GUID \
	{ 0x87367f87,                       \
	  0x1119,                           \
	  0x41ce,                           \
	  { 0xaa, 0xec, 0x8b, 0xe0, 0x11, 0x1f, 0x55, 0x8a } }

#define EFI_JSON_CAPSULE_DATA_TABLE_GUID \
	{ 0x35e7a725,                        \
	  0x8dd2,                            \
	  0x4cac,                            \
	  { 0x80, 0x11, 0x33, 0xcd, 0xa8, 0x10, 0x90, 0x56 } }

#define EFI_JSON_CAPSULE_RESULT_TABLE_GUID \
	{ 0xdbc461c3,                          \
	  0xb3de,                              \
	  0x422a,                              \
	  { 0xb9, 0xb4, 0x98, 0x86, 0xfd, 0x49, 0xa1, 0xe5 } }

#define EFI_PROPERTIES_TABLE_VERSION 0x00010000
typedef struct {
	UINT32 Version;
	UINT32 Length;
	UINT32 MemoryProtectionAttribute;
} EFI_PROPERTIES_TABLE;
//
// Memory attribute (Non-defined bits are reserved)
//
#define EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA 0x1
// BIT 0 - description - implies the runtime data is separated from the code

#define EFI_ACPI_TABLE_PROTOCOL_GUID \
	{ 0xffe06bdd,                    \
	  0x6107,                        \
	  0x46a6,                        \
	  { 0x7b, 0xb2, 0x5a, 0x9c, 0x7e, 0xc5, 0x27, 0x5c } }

#define EFI_MEMORY_ATTRIBUTES_TABLE_GUID \
	{ 0xdcfa911d,                        \
	  0x26eb,                            \
	  0x469f,                            \
	  { 0xa2, 0x20, 0x38, 0xb7, 0xdc, 0x46, 0x12, 0x20 } }

//
// EFI_MEMORY_ATTRIBUTES_TABLE
//
typedef struct {
	UINT32 Version;
	UINT32 NumberOfEntries;
	UINT32 DescriptorSize;
	UINT32 Reserved;
	// EFI_MEMORY_DESCRIPTOR Entry[1];
} EFI_MEMORY_ATTRIBUTES_TABLE;

#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249
#define EFI_2_80_SYSTEM_TABLE_REVISION ((2 << 16) | (80))
#define EFI_2_70_SYSTEM_TABLE_REVISION ((2 << 16) | (70))
#define EFI_2_60_SYSTEM_TABLE_REVISION ((2 << 16) | (60))
#define EFI_2_50_SYSTEM_TABLE_REVISION ((2 << 16) | (50))
#define EFI_2_40_SYSTEM_TABLE_REVISION ((2 << 16) | (40))
#define EFI_2_31_SYSTEM_TABLE_REVISION ((2 << 16) | (31))
#define EFI_2_30_SYSTEM_TABLE_REVISION ((2 << 16) | (30))
#define EFI_2_20_SYSTEM_TABLE_REVISION ((2 << 16) | (20))
#define EFI_2_10_SYSTEM_TABLE_REVISION ((2 << 16) | (10))
#define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | (00))
#define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10))
#define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02))
typedef struct {
	EFI_TABLE_HEADER Hdr;
	CHAR16 *FirmwareVendor;
	UINT32 FirmwareRevision;
	EFI_HANDLE ConsoleInHandle;
	EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
	EFI_HANDLE ConsoleOutHandle;
	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
	EFI_HANDLE StandardErrorHandle;
	EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
	EFI_RUNTIME_SERVICES *RuntimeServices;
	EFI_BOOT_SERVICES *BootServices;
	UINTN NumberOfTableEntries;
	EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;

#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
	{ 0x9042a9de,                         \
	  0x23dc,                             \
	  0x4a38,                             \
	  { 0x96, 0xfb, 0x7a, 0xde, 0xd0, 0x80, 0x51, 0x6a } }

struct EFI_GRAPHICS_OUTPUT_PROTOCOL;

typedef enum {
	PixelRedGreenBlueReserved8BitPerColor,
	PixelBlueGreenRedReserved8BitPerColor,
	PixelBitMask,
	PixelBltOnly,
	PixelFormatMax
} EFI_GRAPHICS_PIXEL_FORMAT;

typedef struct {
	UINT32 RedMask;
	UINT32 GreenMask;
	UINT32 BlueMask;
	UINT32 ReservedMask;
} EFI_PIXEL_BITMASK;

typedef struct {
	UINT32 Version;
	UINT32 HorizontalResolution;
	UINT32 VerticalResolution;
	EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
	EFI_PIXEL_BITMASK PixelInformation;
	UINT32 PixelsPerScanLine;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
	IN struct EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber,
	OUT UINTN *SizeOfInfo, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
	IN struct EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber);

typedef struct {
	UINT8 Blue;
	UINT8 Green;
	UINT8 Red;
	UINT8 Reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;
typedef enum {
	EfiBltVideoFill,
	EfiBltVideoToBltBuffer,
	EfiBltBufferToVideo,
	EfiBltVideoToVideo,
	EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
	IN struct EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
	IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
	OPTIONAL IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
	IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX,
	IN UINTN DestinationY, IN UINTN Width, IN UINTN Height,
	IN UINTN Delta OPTIONAL);

typedef struct {
	UINT32 MaxMode;
	UINT32 Mode;
	EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
	UINTN SizeOfInfo;
	EFI_PHYSICAL_ADDRESS FrameBufferBase;
	UINTN FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct EFI_GRAPHICS_OUTPUT_PROTOCOL {
	EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
	EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
	EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
	EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
} EFI_GRAPHICS_OUTPUT_PROTOCOL;

//
// ImageEntryPoint
//
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_ENTRY_POINT)(
	IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable);

#define EFI_MP_SERVICES_PROTOCOL_GUID \
	{ 0x3fdda605,                     \
	  0xa76e,                         \
	  0x4f46,                         \
	  { 0xad, 0x29, 0x12, 0xf4, 0x53, 0x1b, 0x3d, 0x08 } }

struct EFI_MP_SERVICES_PROTOCOL;

typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_GET_NUMBER_OF_PROCESSORS)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, OUT UINTN *NumberOfProcessors,
	OUT UINTN *NumberOfEnabledProcessors);

typedef struct {
	UINT32 Package;
	UINT32 Core;
	UINT32 Thread;
} EFI_CPU_PHYSICAL_LOCATION;
typedef struct {
	UINT64 ProcessorId;
	UINT32 StatusFlag;
	EFI_CPU_PHYSICAL_LOCATION Location;
} EFI_PROCESSOR_INFORMATION;
#define PROCESSOR_AS_BSP_BIT 0x00000001
#define PROCESSOR_ENABLED_BIT 0x00000002
#define PROCESSOR_HEALTH_STATUS_BIT 0x00000004
typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_GET_PROCESSOR_INFO)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, IN UINTN ProcessorNumber,
	OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer);

#define END_OF_CPU_LIST 0xffffffff
typedef VOID(EFIAPI *EFI_AP_PROCEDURE)(IN VOID *ProcedureArgument);
typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_STARTUP_ALL_APS)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, IN EFI_AP_PROCEDURE Procedure,
	IN BOOLEAN SingleThread, IN EFI_EVENT WaitEvent OPTIONAL,
	IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument OPTIONAL,
	OUT UINTN **FailedCpuList OPTIONAL);

typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_STARTUP_THIS_AP)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, IN EFI_AP_PROCEDURE Procedure,
	IN UINTN ProcessorNumber, IN EFI_EVENT WaitEvent OPTIONAL,
	IN UINTN TimeoutInMicroseconds, IN VOID *ProcedureArgument OPTIONAL,
	OUT BOOLEAN *Finished OPTIONAL);

typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_SWITCH_BSP)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, IN UINTN ProcessorNumber,
	IN BOOLEAN EnableOldBSP);

typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_ENABLEDISABLEAP)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, IN UINTN ProcessorNumber,
	IN BOOLEAN EnableAP, IN UINT32 *HealthFlag OPTIONAL);

typedef EFI_STATUS(EFIAPI *EFI_MP_SERVICES_WHOAMI)(
	IN struct EFI_MP_SERVICES_PROTOCOL *This, OUT UINTN *ProcessorNumber);

typedef struct EFI_MP_SERVICES_PROTOCOL {
	EFI_MP_SERVICES_GET_NUMBER_OF_PROCESSORS GetNumberOfProcessors;
	EFI_MP_SERVICES_GET_PROCESSOR_INFO GetProcessorInfo;
	EFI_MP_SERVICES_STARTUP_ALL_APS StartupAllAPs;
	EFI_MP_SERVICES_STARTUP_THIS_AP StartupThisAP;
	EFI_MP_SERVICES_SWITCH_BSP SwitchBSP;
	EFI_MP_SERVICES_ENABLEDISABLEAP EnableDisableAP;
	EFI_MP_SERVICES_WHOAMI WhoAmI;
} EFI_MP_SERVICES_PROTOCOL;

#define EFI_SIMPLE_POINTER_PROTOCOL_GUID \
	{ 0x31878c87,                        \
	  0xb75,                             \
	  0x11d5,                            \
	  { 0x9a, 0x4f, 0x00, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }

typedef struct {
	UINT64 ResolutionX;
	UINT64 ResolutionY;
	UINT64 ResolutionZ;
	BOOLEAN LeftButton;
	BOOLEAN RightButton;
} EFI_SIMPLE_POINTER_MODE;

struct _EFI_SIMPLE_POINTER_PROTOCOL;

typedef struct {
	INT32 RelativeMovementX;
	INT32 RelativeMovementY;
	INT32 RelativeMovementZ;
	BOOLEAN LeftButton;
	BOOLEAN RightButton;
} EFI_SIMPLE_POINTER_STATE;

typedef EFI_STATUS(EFIAPI *EFI_SIMPLE_POINTER_RESET)(
	IN struct _EFI_SIMPLE_POINTER_PROTOCOL *This,
	IN BOOLEAN ExtendedVerification);

typedef EFI_STATUS(EFIAPI *EFI_SIMPLE_POINTER_GET_STATE)(
	IN struct _EFI_SIMPLE_POINTER_PROTOCOL *This,
	IN OUT EFI_SIMPLE_POINTER_STATE *State);

typedef struct _EFI_SIMPLE_POINTER_PROTOCOL {
	EFI_SIMPLE_POINTER_RESET Reset;
	EFI_SIMPLE_POINTER_GET_STATE GetState;
	EFI_EVENT WaitForInput;
	EFI_SIMPLE_POINTER_MODE *Mode;
} EFI_SIMPLE_POINTER_PROTOCOL;

// ACPI tables

typedef struct __attribute__((packed)) RSDP {
	UINT64 signature; // Should be "RSD PTR "
	UINT8 checksum; // Checksum for RSDP v1.0, all of v1.0 bytes added together should equal 0
	UINT8 OEMID[6]; // OEM supplied string
	UINT8 revision; // Revision of this structure
	UINT32 rsdtAddress; // Physical address of RSDT table

	// For revisions => 2
	UINT32 length; // Length of the table
	UINT64 xsdtAddress; // Physical address of XSDT table
	UINT8 extendedChecksum; // Checksum for the entire table, sum of all bytes should equal 0
	UINT8 reserves[3]; // Reserved field.
} RSDP;

typedef struct __attribute__((packed)) {
	uint32_t signature;
	uint32_t length;
	uint8_t revision;
	uint8_t checksum;
	uint8_t OEMID[6];
	uint8_t OEMTableID[8];
	uint32_t OEMRevision;
	uint32_t creatorID;
	uint32_t creatorRevision;
} SDTH; // System Description Table Header

typedef struct __attribute__((packed)) {
	SDTH header;
	uint32_t entry
		[]; // 32 bit physical memory addresses, number of entries is based on the length in the header
} RSDT;

typedef struct __attribute__((packed)) {
	SDTH header;
	uint64_t entry
		[]; // 64 bit physical memory addresses, number of entries is based on the length in the header
} XSDT;