summaryrefslogtreecommitdiff
path: root/include/efi.h
blob: 2144db60d17fde1f7b6d21114781c6e3841e74dd (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
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
/*
 * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of Hyra nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _EFI_H_
#define _EFI_H_ 1

// 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>

// GCC( and clang) has support for 128 bit integers,
//      for other compilers don't define them;
#ifdef __GNUC__
typedef unsigned __int128 uint128_t;
typedef __int128 int128_t;
#endif // __GNUC__

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

#define NULL 0

typedef uintmax_t uintn_t;
typedef intmax_t  intn_t;

typedef uintn_t efi_status_t;

typedef void *efi_handle_t;
typedef void *efi_event_t;
typedef uint64_t efi_lba_t;
typedef uintn_t  efi_tpl_t;

typedef uint64_t efi_phys_addr_t;

typedef uint8_t efi_mac_addr_t[4];
typedef uint8_t efi_ipv4_addr_t[4];
typedef uint8_t efi_ipv6_address_t[16];
typedef uint8_t __attribute__ ((aligned(4))) EFI_IP_ADDRESS[16];
typedef uintn_t efi_tpl_t;

#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_t
    (__efiapi *EFI_CREATE_EVENT) (
        IN uint32_t             Type,
        IN efi_tpl_t            NotifyTpl,
        IN EFI_EVENT_NOTIFY   NotifyFunction OPTIONAL,
        IN void               *NotifyContext OPTIONAL,
        OUT EFI_EVENT         *Event
        );


//
// CreateEventEx
//
typedef struct {
    uint32_t data1;
    uint16_t data2;
    uint16_t data3;
    uint8_t  data4[8];
} EFI_GUID;
typedef
    efi_status_t
    (__efiapi *EFI_CREATE_EVENT_EX) (
        IN uint32_t    Type,
        IN efi_tpl_t 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_t
    (__efiapi *EFI_CLOSE_EVENT) (
        IN EFI_EVENT Event
        );



//
// SignalEvent
//
typedef
    efi_status_t
    (__efiapi *EFI_SIGNAL_EVENT) (
        IN EFI_EVENT Event
        );


//
// WaitForEvent
//
typedef
    efi_status_t
    (__efiapi *EFI_WAIT_FOR_EVENT) (
        IN uintn_t       NumberOfEvents,
        IN EFI_EVENT   *Event,
        OUT uintn_t      *Index
        );



//
// CheckEvent
//
typedef
    efi_status_t
    (__efiapi *EFI_CHECK_EVENT) (
        IN EFI_EVENT Event
        );


//
// SetTimer
//
typedef enum {
    TimerCancel,
     TimerPeriodic,
     TimerRelative
} EFI_TIMER_DELAY;
typedef
    efi_status_t
    (__efiapi *EFI_SET_TIMER) (
        IN EFI_EVENT           Event,
        IN EFI_TIMER_DELAY     Type,
        IN uint64_t              TriggerTime
        );

//
// RaiseTPL
//
typedef
    efi_tpl_t
    (__efiapi *EFI_RAISE_TPL) (
        IN efi_tpl_t NewTpl
        );
typedef uintn_t efi_tpl_t;
#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_t 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_t
    (__efiapi *EFI_ALLOCATE_PAGES) (
        IN EFI_ALLOCATE_TYPE        type,
        IN EFI_MEMORY_TYPE          memory_type,
        IN uintn_t                    pages,
        IN OUT efi_phys_addr_t *memory
        );

//
// FreePages
//
typedef
    efi_status_t
    (__efiapi *EFI_FREE_PAGES) (
        IN efi_phys_addr_t memory,
        IN uintn_t         pages);

//
// GetMemoryMap
//
typedef uint64_t  EFI_VIRTUAL_ADDRESS;
typedef struct {
    uint32_t        type;
    efi_phys_addr_t   physical_start;
    EFI_VIRTUAL_ADDRESS    virtual_start;
    uint64_t                 number_of_pages;
    uint64_t                 attribute;
} EFI_MEMORY_DESCRIPTOR;
typedef
    efi_status_t
    (__efiapi *EFI_GET_MEMORY_MAP) (
        IN OUT uintn_t                 *memory_map_size,
        IN OUT EFI_MEMORY_DESCRIPTOR *memory_map,
        OUT uintn_t                    *map_key,
        OUT uintn_t                    *descriptor_size,
        OUT uint32_t                   *descriptor_version
        );
#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_t
    (__efiapi *EFI_ALLOCATE_POOL) (
        IN EFI_MEMORY_TYPE   PoolType,
        IN uintn_t             Size,
        OUT void             **Buffer
        );

//
// FreePool
//
typedef
    efi_status_t
    (__efiapi *EFI_FREE_POOL) (
        IN void   *Buffer
        );

//
// InstallProtocolInterface
//
typedef enum {
    EFI_NATIVE_INTERFACE
} EFI_INTERFACE_TYPE;
typedef
    efi_status_t
    (__efiapi *EFI_INSTALL_PROTOCOL_INTERFACE) (
        IN OUT efi_handle_t     *Handle,
        IN EFI_GUID           *Protocol,
        IN EFI_INTERFACE_TYPE InterfaceType,
        IN void               *Interface
        );

//
// UninstallProtocolInterface
//
typedef
    efi_status_t
    (__efiapi *EFI_UNINSTALL_PROTOCOL_INTERFACE) (
        IN efi_handle_t    Handle,
        IN EFI_GUID      *Protocol,
        IN void          *Interface
        );

//
// ReinstallProtocolInterface
//
typedef
    efi_status_t
    (__efiapi *EFI_REINSTALL_PROTOCOL_INTERFACE) (
        IN efi_handle_t Handle,
        IN EFI_GUID   *Protocol,
        IN void       *OldInterface,
        IN void       *NewInterface
        );

//
// RegisterProtocolNotify
//
typedef
    efi_status_t
    (__efiapi *EFI_REGISTER_PROTOCOL_NOTIFY) (
        IN EFI_GUID  *Protocol,
        IN efi_event_t Event,
        OUT void   **Registration
        );

//
// LocateHandle
//
typedef enum {
    AllHandles,
    ByRegisterNotify,
    ByProtocol
} EFI_LOCATE_SEARCH_TYPE;
typedef
    efi_status_t
    (__efiapi *EFI_LOCATE_HANDLE) (
        IN EFI_LOCATE_SEARCH_TYPE  SearchType,
        IN EFI_GUID                *Protocol OPTIONAL,
        IN void                    *SearchKey OPTIONAL,
        IN OUT uintn_t               *BufferSize,
        OUT efi_handle_t             *Buffer
        );

//
// HandleProtocol
//
typedef
    efi_status_t
    (__efiapi *efi_handle_t_PROTOCOL) (
        IN efi_handle_t    Handle,
        IN EFI_GUID      *Protocol,
        OUT void         **Interface
        );

//
// LocateDevicePath
//
typedef struct {
    uint8_t type;
    uint8_t sub_type;
    uint8_t length[2];
} EFI_DEVICE_PATH_PROTOCOL;
typedef
    efi_status_t
    (__efiapi *EFI_LOCATE_DEVICE_PATH) (
        IN EFI_GUID                      *Protocol,
        IN OUT EFI_DEVICE_PATH_PROTOCOL  **DevicePath,
        OUT efi_handle_t                   *Device
        );

//
// OpenProtocol
//
typedef
    efi_status_t
    (__efiapi *EFI_OPEN_PROTOCOL) (
        IN efi_handle_t      Handle,
        IN EFI_GUID        *Protocol,
        OUT void           **InterfaceOPTIONAL,
        IN efi_handle_t      AgentHandle,
        IN efi_handle_t      ControllerHandle,
        IN uint32_t          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_t
    (__efiapi *EFI_CLOSE_PROTOCOL) (
        IN efi_handle_t      Handle,
        IN EFI_GUID        *Protocol,
        IN efi_handle_t      AgentHandle,
        IN efi_handle_t      ControllerHandle
        );

//
// OpenProtocolInformation
//
typedef struct {
    efi_handle_t       agent_handle;
    efi_handle_t       controller_handle;
    uint32_t           attributes;
    uint32_t           open_count;
} EFI_OPEN_PROTOCOL_INFORMATION_ENTRY;
typedef
    efi_status_t
    (__efiapi *EFI_OPEN_PROTOCOL_INFORMATION) (
        IN efi_handle_t                            Handle,
        IN EFI_GUID                              *Protocol,
        OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY  **EntryBuffer,
        OUT uintn_t                                *EntryCount
        );

//
// ConnectController
//
typedef
    efi_status_t
    (__efiapi *EFI_CONNECT_CONTROLLER) (
        IN efi_handle_t                ControllerHandle,
        IN efi_handle_t                *DriverImageHandle  OPTIONAL,
        IN EFI_DEVICE_PATH_PROTOCOL  *RemainingDevicePath OPTIONAL,
        IN BOOLEAN                   Recursive
        );

//
// DisconnectController
//
typedef
    efi_status_t
    (__efiapi *EFI_DISCONNECT_CONTROLLER) (
        IN efi_handle_t ControllerHandle,
        IN efi_handle_t DriverImageHandle OPTIONAL,
        IN efi_handle_t ChildHandle    OPTIONAL
        );

//
// ProtocolsPerHandle
//
typedef
    efi_status_t
    (__efiapi *EFI_PROTOCOLS_PER_HANDLE) (
        IN efi_handle_t Handle,
        OUT EFI_GUID  ***ProtocolBuffer,
        OUT uintn_t     *ProtocolBufferCount
        );

//
// LocateHandleBuffer
//
typedef
    efi_status_t
    (__efiapi *EFI_LOCATE_HANDLE_BUFFER) (
        IN EFI_LOCATE_SEARCH_TYPE  SearchType,
        IN EFI_GUID                *Protocol OPTIONAL,
        IN void                    *SearchKeyOPTIONAL,
        IN OUT uintn_t               *NoHandles,
        OUT efi_handle_t             **Buffer
        );

//
// LocateProtocol
//
typedef
    efi_status_t
    (__efiapi *EFI_LOCATE_PROTOCOL) (
        IN EFI_GUID     *Protocol,
        IN void         *Registration OPTIONAL,
        OUT void        **Interface
        );

//
// InstallMultipleProtocolInterfaces
//
typedef
    efi_status_t
    (__efiapi *EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
        IN OUT efi_handle_t *Handle,
        ...
        );

//
// UninstallMultipleProtocolInterfaces
//
typedef
    efi_status_t
    (__efiapi *EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES) (
        IN efi_handle_t Handle,
        ...
        );

//
// LoadImage
//
typedef
    efi_status_t
    (__efiapi *EFI_IMAGE_LOAD) (
        IN BOOLEAN                    BootPolicy,
        IN efi_handle_t                 ParentImageHandle,
        IN EFI_DEVICE_PATH_PROTOCOL   *DevicePath,
        IN void                       *SourceBuffer OPTIONAL,
        IN uintn_t                      SourceSize,
        OUT efi_handle_t                *ImageHandle
        );

//
// StartImage
//
typedef
    efi_status_t
    (__efiapi *EFI_IMAGE_START) (
        IN efi_handle_t       ImageHandle,
        OUT uintn_t           *ExitDataSize,
        OUT uint16_t          **ExitData OPTIONAL
        );

//
// UnloadImage
//
typedef
    efi_status_t
    (__efiapi *EFI_IMAGE_UNLOAD) (
        IN efi_handle_t       ImageHandle
        );

//
// Exit
//
typedef
    efi_status_t
    (__efiapi *EFI_EXIT) (
        IN efi_handle_t       ImageHandle,
        IN efi_status_t       ExitStatus,
        IN uintn_t            ExitDataSize,
        IN uint16_t           *ExitData OPTIONAL
        );

//
// ExitBootServices
//
typedef
    efi_status_t
    (__efiapi *EFI_EXIT_BOOT_SERVICES) (
        IN efi_handle_t   ImageHandle,
        IN uintn_t        MapKey
        );

//
// SetWatchdogTimer
//
typedef
    efi_status_t
    (__efiapi *EFI_SET_WATCHDOG_TIMER) (
        IN uintn_t        Timeout,
        IN uint64_t       WatchdogCode,
        IN uintn_t        DataSize,
        IN uint16_t       *WatchdogData  OPTIONAL
        );

//
// Stall
//
typedef
    efi_status_t
    (__efiapi *EFI_STALL) (
        IN uintn_t  Microseconds
        );

//
// CopyMem
//
typedef
    void
    (__efiapi *EFI_COPY_MEM) (
        IN void   *Destination,
        IN void   *Source,
        IN uintn_t  Length
        );

//
// SetMem
//
typedef
    void
    (__efiapi *EFI_SET_MEM) (
        IN void   *Buffer,
        IN uintn_t  Size,
        IN uint8_t  Value
        );

//
// GetNextMonotonicCount
//
typedef
    efi_status_t
    (__efiapi *EFI_GET_NEXT_MONOTONIC_COUNT) (
        OUT uint64_t  *Count
        );

//
// InstallConfigurationTable
//
typedef
    efi_status_t
    (__efiapi *EFI_INSTALL_CONFIGURATION_TABLE) (
        IN EFI_GUID  *Guid,
        IN void      *Table
        );

//
// CalculateCrc32
//
typedef
    efi_status_t
    (__efiapi *EFI_CALCULATE_CRC32) (
        IN void     *Data,
        IN uintn_t    DataSize,
        OUT uint32_t  *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_t
    (__efiapi *EFI_GET_VARIABLE) (
        IN uint16_t*VariableName,
        IN EFI_GUID*VendorGuid,
        OUT uint32_t*Attributes OPTIONAL,
        IN OUT uintn_t*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_t         type;
    uint32_t        id_size;
    // uint8_t      Id[IdSize];
} EFI_VARIABLE_AUTHENTICATION_3_CERT_ID;

//
// GetNextVariableName
//
typedef
    efi_status_t
    (__efiapi *EFI_GET_NEXT_VARIABLE_NAME) (
        IN OUT uintn_t      *VariableNameSize,
        IN OUT uint16_t     *VariableName,
        IN OUT EFI_GUID   *VendorGuid
        );

//
// SetVariable
//
typedef
    efi_status_t
    (__efiapi *EFI_SET_VARIABLE) (
        IN uint16_t      *VariableName,
        IN EFI_GUID    *VendorGuid,
        IN uint32_t      Attributes,
        IN uintn_t       DataSize,
        IN void        *Data
        );

//
// QueryVariableInfo
//
typedef
    efi_status_t
    (__efiapi *EFI_QUERY_VARIABLE_INFO) (
        IN uint32_t     Attributes,
        OUT uint64_t    *MaximumVariableStorageSize,
        OUT uint64_t    *RemainingVariableStorageSize,
        OUT uint64_t    *MaximumVariableSize
        );

//
// GetTime
//
// This represents the current time information
typedef struct {
    uint16_t   year;              // 1900 – 9999
    uint8_t   month;              // 1 – 12
    uint8_t   day;                // 1 – 31
    uint8_t   hour;               // 0 – 23
    uint8_t   minute;             // 0 – 59
    uint8_t   second;             // 0 – 59
    uint8_t   pad1; uint32_t   nanosecond;  // 0 – 999,999,999
    int16_t   timezone;           // -1440 to 1440 or 2047
    uint8_t   daylist; uint8_t   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_t   resolution;
    uint32_t   accuracy;
    BOOLEAN  sets_to_zero;
} EFI_TIME_CAPABILITIES;
typedef
    efi_status_t
    (__efiapi *EFI_GET_TIME) (
        OUT EFI_TIME              *Time,
        OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL
        );

//
// SetTime
//
typedef
    efi_status_t
    (__efiapi *EFI_SET_TIME) (
        IN EFI_TIME  *Time
        );

//
// GetWakeupTime
//
typedef
    efi_status_t
    (__efiapi *EFI_GET_WAKEUP_TIME) (
        OUT BOOLEAN  *Enabled,
        OUT BOOLEAN  *Pending,
        OUT EFI_TIME *Time
        );

//
// SetWakeupTime
//
typedef
    efi_status_t
    (__efiapi *EFI_SET_WAKEUP_TIME) (
        IN BOOLEAN  Enable,
        IN EFI_TIME *Time OPTIONAL
        );

//
// SetVirtualAddressMap
//
typedef
    efi_status_t
    (__efiapi *EFI_SET_VIRTUAL_ADDRESS_MAP) (
        IN uintn_t                  MemoryMapSize,
        IN uintn_t                  DescriptorSize,
        IN uint32_t                 DescriptorVersion,
        IN EFI_MEMORY_DESCRIPTOR *VirtualMap
        );

//
// ConvertPointer
//
typedef
    efi_status_t
    (__efiapi *EFI_CONVERT_POINTER) (
        IN uintn_t   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_t     ResetStatus,
        IN uintn_t          DataSize,
        IN void           *ResetData OPTIONAL
        );

//
// GetNextHighMonotonicCount
//
typedef
    efi_status_t
    (__efiapi *EFI_GET_NEXT_HIGH_MONOTONIC_COUNT) (
        OUT uint32_t  *HighCount
        );

//
// UpdateCapsule
//
typedef struct {
    uint64_t                   length;
    union {
        efi_phys_addr_t   data_block;
        efi_phys_addr_t   continuation_pointer;
    } Union;
} EFI_CAPSULE_BLOCK_DESCRIPTOR;
typedef struct {
    EFI_GUID   capsule_guid;
    uint32_t     header_size;
    uint32_t     flags;
    uint32_t     capsule_image_size;
} EFI_CAPSULE_HEADER;
typedef
    efi_status_t
    (__efiapi *EFI_UPDATE_CAPSULE) (
        IN EFI_CAPSULE_HEADER   **CapsuleHeaderArray,
        IN uintn_t                CapsuleCount,
        IN efi_phys_addr_t ScatterGatherList OPTIONAL
        );

//
// QueryCapsuleCapabilities
//
typedef
    efi_status_t
    (__efiapi *EFI_QUERY_CAPSULE_CAPABILITIES) (
        IN EFI_CAPSULE_HEADER    **CapsuleHeaderArray,
        IN uintn_t                 CapsuleCount,
        OUT uint64_t               *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_t
    (__efiapi *EFI_INPUT_RESET) (
        IN struct EFI_SIMPLE_TEXT_INPUT_PROTOCOL  *This,
        IN BOOLEAN                         ExtendedVerification
        );

//
// ReadKeyStroke
//
typedef struct {
    uint16_t   scan_code;
    uint16_t   unicode_char;
} EFI_INPUT_KEY;
typedef
    efi_status_t
    (__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  read_key_stroke;
    efi_event_t           wait_for_key;
} 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_t
    (__efiapi *EFI_TEXT_RESET) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *this,
        IN BOOLEAN                         extendedVerification
        );

//
// OutputString
//
typedef
    efi_status_t
    (__efiapi *EFI_TEXT_STRING) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN uint16_t                          *String
        );

//
// TestString
//
typedef
    efi_status_t
    (__efiapi *EFI_TEXT_TEST_STRING) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN uint16_t              *String
        );

//
// QueryMode
//
typedef
    efi_status_t
    (__efiapi *EFI_TEXT_QUERY_MODE) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN uintn_t              ModeNumber,
        OUT uintn_t              *Columns,
        OUT uintn_t              *Rows
        );

//
// SetMode
//
typedef
    efi_status_t
    (* __efiapi EFI_TEXT_SET_MODE) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN uintn_t                           ModeNumber
        );

//
// SetAttribute
//
typedef
    efi_status_t
    (__efiapi *EFI_TEXT_SET_ATTRIBUTE) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN uintn_t                           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_t
    (__efiapi *EFI_TEXT_CLEAR_SCREEN) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *This
        );

//
// SetCursorPosition
//
typedef
    efi_status_t
    (__efiapi *EFI_TEXT_SET_CURSOR_POSITION) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN uintn_t                           Column,
        IN uintn_t                           Row
        );

//
// EnableCursor
//
typedef
    efi_status_t
    (__efiapi *EFI_TEXT_ENABLE_CURSOR) (
        IN struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
        IN BOOLEAN                         Visible
        );

typedef struct {
    int32_t               max_mode; // current settings
    int32_t               mode;
    int32_t               attribute;
    int32_t               cursor_column;
    int32_t               cursor_row;
    BOOLEAN             cursor_visible;
} SIMPLE_TEXT_OUTPUT_MODE;

typedef struct EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
    EFI_TEXT_RESET                  reset;
    EFI_TEXT_STRING                 output_string;
    EFI_TEXT_TEST_STRING            test_string;
    EFI_TEXT_QUERY_MODE             query_mode;
    EFI_TEXT_SET_MODE               set_mode;
    EFI_TEXT_SET_ATTRIBUTE          set_attribute;
    EFI_TEXT_CLEAR_SCREEN           clear_screen;
    EFI_TEXT_SET_CURSOR_POSITION    set_cursor_position;
    EFI_TEXT_ENABLE_CURSOR          enable_cursor;
    SIMPLE_TEXT_OUTPUT_MODE         *node;
} 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_t  signature;
    uint32_t  revision;
    uint32_t  headerSize;
    uint32_t  crc_32;
    uint32_t  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 raise_tpl; // EFI 1.0+
    EFI_RESTORE_TPL restore_tpl; // EFI 1.0+

    //
    // Memory Services
    //
    EFI_ALLOCATE_PAGES allocate_pages; // EFI 1.0+
    EFI_FREE_PAGES free_pages; // EFI 1.0+
    EFI_GET_MEMORY_MAP get_memory_map; // EFI 1.0+
    EFI_ALLOCATE_POOL allocate_pool; // EFI 1.0+
    EFI_FREE_POOL free_pool; // EFI 1.0+

    //
    // Event & Timer Services
    //
    EFI_CREATE_EVENT create_event; // EFI 1.0+
    EFI_SET_TIMER set_timer; // EFI 1.0+
    EFI_WAIT_FOR_EVENT wait_for_event; // EFI 1.0+
    EFI_SIGNAL_EVENT signal_event; // EFI 1.0+
    EFI_CLOSE_EVENT close_event; // EFI 1.0+
    EFI_CHECK_EVENT check_event; // EFI 1.0+

    //
    // Protocol Handler Services
    //
    EFI_INSTALL_PROTOCOL_INTERFACE install_protocol_interface; // EFI 1.0+
    EFI_REINSTALL_PROTOCOL_INTERFACE reinstall_protocol_interface; // EFI 1.0+
    EFI_UNINSTALL_PROTOCOL_INTERFACE uninstall_protocol_interface; // EFI 1.0+
    efi_handle_t_PROTOCOL handle_protocol; // EFI 1.0+
    void* Reserved; // EFI 1.0+
    EFI_REGISTER_PROTOCOL_NOTIFY register_protocol_notify; // EFI 1.0+
    EFI_LOCATE_HANDLE locate_handle; // EFI 1.0+
    EFI_LOCATE_DEVICE_PATH locate_device_path; // EFI 1.0+
    EFI_INSTALL_CONFIGURATION_TABLE install_configuration_table; // EFI 1.0+

    //
    // Image Services
    //
    EFI_IMAGE_LOAD load_image; // EFI 1.0+
    EFI_IMAGE_START start_image; // EFI 1.0+UEFI Specification, Version 2.8 EFI System Table
    EFI_EXIT Exit; // EFI 1.0+
    EFI_IMAGE_UNLOAD unload_image; // EFI 1.0+
    EFI_EXIT_BOOT_SERVICES exit_boot_services; // EFI 1.0+

    //
    // Miscellaneous Services
    //
    EFI_GET_NEXT_MONOTONIC_COUNT get_next_monotonic_count; // EFI 1.0+
    EFI_STALL Stall; // EFI 1.0+
    EFI_SET_WATCHDOG_TIMER set_watchdog_timer; // EFI 1.0+

    //
    // DriverSupport Services
    //
    EFI_CONNECT_CONTROLLER connect_controller; // EFI 1.1
    EFI_DISCONNECT_CONTROLLER disconnect_controller;// EFI 1.1+

    //
    // Open and Close Protocol Services
    //
    EFI_OPEN_PROTOCOL open_protocol; // EFI 1.1+
    EFI_CLOSE_PROTOCOL close_protocol; // EFI 1.1+
    EFI_OPEN_PROTOCOL_INFORMATION open_protocol_information; // EFI 1.1+

    //
    // Library Services
    //
    EFI_PROTOCOLS_PER_HANDLE protocols_per_handle; // EFI 1.1+
    EFI_LOCATE_HANDLE_BUFFER locate_handle_buffer; // EFI 1.1+
    EFI_LOCATE_PROTOCOL locate_protocol; // EFI 1.1+
    EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES
    install_multiple_protocol_interfaces; // EFI 1.1+
    EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES
    uninstall_multiple_protocol_interfaces; // EFI 1.1+

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

    //
    // Miscellaneous Services
    //
    EFI_COPY_MEM copy_mem; // EFI 1.1+
    EFI_SET_MEM set_mem; // EFI 1.1+UEFI Specification, Version 2.8 EFI System Table
    EFI_CREATE_EVENT_EX create_event_ex; // 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 get_time;
    EFI_SET_TIME set_time;
    EFI_GET_WAKEUP_TIME get_wakeup_time;
    EFI_SET_WAKEUP_TIME set_wakeup_time;

    //
    // Virtual Memory Services
    //
    EFI_SET_VIRTUAL_ADDRESS_MAP set_virtual_address_map;
    EFI_CONVERT_POINTER convert_pointer;

    //
    // Variable Services
    //
    EFI_GET_VARIABLE get_variable;
    EFI_GET_NEXT_VARIABLE_NAME get_next_variable_name;
    EFI_SET_VARIABLE set_variable;

    //
    // Miscellaneous Services
    //
    EFI_GET_NEXT_HIGH_MONOTONIC_COUNT get_next_high_monotonic_count;
    EFI_RESET_SYSTEM reset_system;

    //
    // UEFI 2.0 Capsule Services
    //
    EFI_UPDATE_CAPSULE update_capsule;
    EFI_QUERY_CAPSULE_CAPABILITIES query_capsule_capabilities;

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

typedef struct {
    EFI_GUID    vendor_guid;
    void       *vendor_table;
} 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_t version;
    uint32_t length;
    uint32_t memory_protection_attribute;
} 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_t  version;
    uint32_t  number_of_entries;
    uint32_t  descriptor_size;
    uint32_t  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;
    uint16_t                            *firmware_vendor;
    uint32_t                            firmware_revision;
    efi_handle_t                        console_in_handle;
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL    *con_in;
    efi_handle_t                        console_out_handle;
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *con_out;
    efi_handle_t                        standard_error_handle;
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *std_err;
    EFI_RUNTIME_SERVICES              *runtime_services;
    EFI_BOOT_SERVICES                 *boot_services;
    uintn_t                             number_of_table_entries;
    EFI_CONFIGURATION_TABLE           *configuration_table;
} 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_t red_mask;
    uint32_t green_mask;
    uint32_t blue_mask;
    uint32_t reserved_mask;
} EFI_PIXEL_BITMASK;

typedef struct {
    uint32_t version;
    uint32_t horizontal_resolution;
    uint32_t vertical_resolution;
    EFI_GRAPHICS_PIXEL_FORMAT pixel_format;
    EFI_PIXEL_BITMASK pixel_information;
    uint32_t pixels_per_scan_line;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef
    efi_status_t
    (__efiapi *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE) (
        IN struct EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
        IN uint32_t ModeNumber,
        OUT uintn_t *SizeOfInfo,
        OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
        );

typedef
    efi_status_t
    (__efiapi *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE) (
        IN struct EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
        IN uint32_t ModeNumber
        );

typedef struct {
    uint8_t blue;
    uint8_t green;
    uint8_t red;
    uint8_t reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;
typedef enum {
    EfiBltVideoFill,
    EfiBltVideoToBltBuffer,
    EfiBltBufferToVideo,
    EfiBltVideoToVideo,
    EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;
typedef
    efi_status_t
    (__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_t SourceX,
        IN uintn_t SourceY,
        IN uintn_t DestinationX,
        IN uintn_t DestinationY,
        IN uintn_t Width,
        IN uintn_t Height,
        IN uintn_t Delta OPTIONAL
        );

typedef struct {
    uint32_t MaxMode;
    uint32_t Mode;
    EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
    uintn_t SizeOfInfo;
    efi_phys_addr_t FrameBufferBase;
    uintn_t FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct EFI_GRAPHICS_OUTPUT_PROTOCOL {
    EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE query_mode;
    EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE set_mode;
    EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT blt;
    EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode;
} EFI_GRAPHICS_OUTPUT_PROTOCOL;

//
// ImageEntryPoint
//
typedef
    efi_status_t
    (__efiapi *EFI_IMAGE_ENTRY_POINT) (
        IN efi_handle_t       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_t
    (__efiapi *EFI_MP_SERVICES_GET_NUMBER_OF_PROCESSORS) (
        IN struct EFI_MP_SERVICES_PROTOCOL *This,
        OUT uintn_t *NumberOfProcessors,
        OUT uintn_t *NumberOfEnabledProcessors
        );

typedef struct {
    uint32_t package;
    uint32_t core;
    uint32_t thread;
} EFI_CPU_PHYSICAL_LOCATION;
typedef struct {
    uint64_t processor_id;
    uint32_t status_flag;
    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_t
    (__efiapi *EFI_MP_SERVICES_GET_PROCESSOR_INFO) (
        IN struct EFI_MP_SERVICES_PROTOCOL *This,
        IN uintn_t ProcessorNumber,
        OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
        );

#define END_OF_CPU_LIST 0xffffffff
typedef
    void
    (__efiapi *EFI_AP_PROCEDURE) (
        IN void *ProcedureArgument
        );
typedef
    efi_status_t
    (__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_t WaitEvent OPTIONAL,
        IN uintn_t TimeoutInMicroSeconds,
        IN void *ProcedureArgument OPTIONAL,
        OUT uintn_t **FailedCpuList OPTIONAL
        );

typedef
    efi_status_t
    (__efiapi *EFI_MP_SERVICES_STARTUP_THIS_AP) (
        IN struct EFI_MP_SERVICES_PROTOCOL*This,
        IN EFI_AP_PROCEDURE Procedure,
        IN uintn_t ProcessorNumber,
        IN efi_event_t WaitEvent OPTIONAL,
        IN uintn_t TimeoutInMicroseconds,
        IN void *ProcedureArgument OPTIONAL,
        OUT BOOLEAN *Finished OPTIONAL
        );

typedef
    efi_status_t
    (__efiapi *EFI_MP_SERVICES_SWITCH_BSP) (
        IN struct EFI_MP_SERVICES_PROTOCOL *This,
        IN uintn_t ProcessorNumber,
        IN BOOLEAN EnableOldBSP
        );

typedef
    efi_status_t
    (__efiapi *EFI_MP_SERVICES_ENABLEDISABLEAP) (
        IN struct EFI_MP_SERVICES_PROTOCOL*This,
        IN uintn_t ProcessorNumber,
        IN BOOLEAN EnableAP,
        IN uint32_t *HealthFlag OPTIONAL
        );

typedef
    efi_status_t
    (__efiapi *EFI_MP_SERVICES_WHOAMI) (
        IN struct EFI_MP_SERVICES_PROTOCOL *This,
        OUT uintn_t *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_t resolution_x;
    uint64_t resolution_y;
    uint64_t resolution_z;
    BOOLEAN left_button;
    BOOLEAN right_button;
} EFI_SIMPLE_POINTER_MODE;

struct _EFI_SIMPLE_POINTER_PROTOCOL;

typedef struct {
    int32_t relative_movement_x;
    int32_t relative_movement_y;
    int32_t relative_movement_z;
    BOOLEAN left_button;
    BOOLEAN right_button;
} EFI_SIMPLE_POINTER_STATE;

typedef
    efi_status_t
    (__efiapi *EFI_SIMPLE_POINTER_RESET) (
        IN struct _EFI_SIMPLE_POINTER_PROTOCOL *This,
        IN BOOLEAN ExtendedVerification
        );

typedef
    efi_status_t
    (__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_t WaitForInput;
    EFI_SIMPLE_POINTER_MODE *Mode;
} EFI_SIMPLE_POINTER_PROTOCOL;

// ACPI tables

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

    // For revisions => 2
    uint32_t length;      // Length of the table
    uint64_t xsdtAddress; // Physical address of xdst_t table
    uint8_t extendedChecksum; // Checksum for the entire table, sum of all bytes should equal 0
    uint8_t reserves[3];  // Reserved field.
} rsdp_t;

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_t; // System Description Table Header

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

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

#endif  /* !_EFI_H_ */