summaryrefslogtreecommitdiff
path: root/lib/uefi.c3l/src/def.c3i
blob: f595caad2e4ccbc189c3c1f5b86af685b4e18142 (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
module uefi;


/*
 * EFI_HANDLE alias (sec x.x.x of the UEFI 2.11 specification).
 */
typedef EfiHandle = void*;

/*
 * All UEFI strings are wchar_t strings (Wide-Char types).
 */
alias EfiString = ushort[];
alias EfiStringRaw = ushort*;

/*
 * ... But ASCII strings can also be used and dynamically converted to wide ones.
 */
alias AsciiString = char[];
alias AsciiStringRaw = char*;

/*
 * EFI_EVENT alias (sec 7.1.1 of the UEFI 2.11 specification).
 */
typedef EfiEvent = void*;


/*
 * EFI_TABLE_HEADER structure (sec 4.2.1 of the UEFI 2.11 specification).
 *    The same section contains the following constant expressions
 *    as well as the EFI_SYSTEM_TABLE structure.
 */
struct EfiTableHeader @packed
{
    ulong       signature;
    uint        revision;
    uint        header_size;
    uint        crc32;
    uint        _reserved;
}

const ulong EFI_SYSTEM_TABLE_SIGNATURE      = 0x5453595320494249;
const uint  EFI_2_100_SYSTEM_TABLE_REVISION = ((2<<16) | (100));
const uint  EFI_2_90_SYSTEM_TABLE_REVISION  = ((2<<16) | (90));
const uint  EFI_2_80_SYSTEM_TABLE_REVISION  = ((2<<16) | (80));
const uint  EFI_2_70_SYSTEM_TABLE_REVISION  = ((2<<16) | (70));
const uint  EFI_2_60_SYSTEM_TABLE_REVISION  = ((2<<16) | (60));
const uint  EFI_2_50_SYSTEM_TABLE_REVISION  = ((2<<16) | (50));
const uint  EFI_2_40_SYSTEM_TABLE_REVISION  = ((2<<16) | (40));
const uint  EFI_2_31_SYSTEM_TABLE_REVISION  = ((2<<16) | (31));
const uint  EFI_2_30_SYSTEM_TABLE_REVISION  = ((2<<16) | (30));
const uint  EFI_2_20_SYSTEM_TABLE_REVISION  = ((2<<16) | (20));
const uint  EFI_2_10_SYSTEM_TABLE_REVISION  = ((2<<16) | (10));
const uint  EFI_2_00_SYSTEM_TABLE_REVISION  = ((2<<16) | (00));
const uint  EFI_1_10_SYSTEM_TABLE_REVISION  = ((1<<16) | (10));
const uint  EFI_1_02_SYSTEM_TABLE_REVISION  = ((1<<16) | (02));
const uint  EFI_SYSTEM_TABLE_REVISION       = EFI_2_100_SYSTEM_TABLE_REVISION;
const uint  EFI_SPECIFICATION_VERSION       = EFI_SYSTEM_TABLE_REVISION;

/* NOTE: Do NOT pack this struct: firmware_revision being 32-bit causes misalignment */
struct SystemTable
{
    EfiTableHeader              header;
    EfiStringRaw                firmware_vendor;
    uint                        firmware_revision;
    EfiHandle                   conin_handle;
    SimpleTextInputProtocol     *conin;
    EfiHandle                   conout_handle;
    SimpleTextOutputProtocol    *conout;
    EfiHandle                   conerr_handle;
    SimpleTextOutputProtocol    *conerr;
    RuntimeServices             *runtime_services;
    BootServices                *boot_services;
    usz                         num_entries;
    ConfigurationTable          *configuration_table;
}


/*
 * EFI_CONFIGURATION_TABLE structure (sec 4.6.1 of the UEFI 2.11 specification).
 */
struct ConfigurationTable @packed
{
    EfiGuid     vendor_guid;
    void        *vendor_table;
}


/* EFI_BOOT_SERVICES structure (4.4.1) */
const ulong EFI_BOOT_SERVICES_SIGNATURE = 0x56524553544f4f42; //'BOOTSERV' <- EightCC
const uint EFI_BOOT_SERVICES_REVISION   = EFI_SPECIFICATION_VERSION;

struct BootServices @packed
{
    EfiTableHeader              header;

    /* Task priority services (uefi::proto::evt) */
    FnRaiseTpl                  raise_tpl;
    FnRestoreTpl                restore_tpl;

    /* Memory services (uefi::proto::mem) */
    FnAllocatePages             allocate_pages;
    FnFreePages                 free_pages;
    FnGetMemoryMap              get_memory_map;
    FnAllocatePool              allocate_pool;
    FnFreePool                  free_pool;

    /* Event and Timer services (uefi::proto::evt) */
    FnCreateEvent               create_event;
    FnSetTimer                  set_timer;
    FnWaitForEvent              wait_for_event;
    FnSignalEvent               signal_event;
    FnCloseEvent                close_event;
    FnCheckEvent                check_event;

    /* Protocol Handler services (uefi::proto::handler) */
    FnInstallProtocolInterface          install_protocol_interface;
    FnReinstallProtocolInterface        reinstall_protocol_interface;
    FnUninstallProtocolInterface        uninstall_protocol_interface;
    FnHandleProtocol                    handle_protocol;
    void                                *_reserved;   /* alright then */
    FnRegisterProtocolNotify            register_protocol_notify;
    FnLocateHandle                      locate_handle;
    FnLocateDevicePath                  locate_device_path;
    FnInstallConfigurationTable         install_configuration_table;

    /* Image services (uefi::proto::image) */
    FnLoadImage                 load_image;
    FnStartImage                start_image;
    FnExitImage                 exit_image;
    FnUnloadImage               unload_image;
    FnExitBootServices          exit_boot_services;

    /* Misc services (uefi::proto::misc_bs) */
    FnGetNextMonotonicCount     get_next_monotonic_count;
    FnStall                     stall;
    FnSetWatchdogTimer          set_watchdog_timer;

    /* Driver Support services (uefi::proto::handler) */
    FnConnectController         connect_controller;
    FnDisconnectController      disconnect_controller;

    /* Open/Close Protocol services (uefi::proto::handler) */
    FnOpenProtocol              open_protocol;
    FnCloseProtocol             close_protocol;
    FnOpenProtocolInformation   open_protocol_information;

    /* Library services (uefi::proto::handler) */
    FnProtocolsPerHandle                        protocols_per_handle;
    FnLocateHandleBuffer                        locate_handle_buffer;
    FnLocateProtocol                            locate_protocol;
    FnInstallMultipleProtocolInterfaces         install_multiple_protocol_interfaces;
    FnUninstallMultipleProtocolInterfaces       uninstall_multiple_protocol_interfaces;

    /* 32-bit CRC services (uefi::proto::misc_bs) */
    FnCalculateCrc32            calculate_crc32;

    /* More misc/trailing services */
    FnCopyMem                   copy_mem;
    FnSetMem                    set_mem;
    FnCreateEventEx             create_event_ex;
}


struct RuntimeServices @packed
{
    EfiTableHeader              header;

    /* Time services (uefi::proto::time) */
    FnGetTime                   get_time;
    FnSetTime                   set_time;
    FnGetWakeupTime             get_wakeup_time;
    FnSetWakeupTime             set_wakeup_time;

    /* Virtual Memory services (uefi::proto::mem) */
    FnSetVirtualAddressMap      set_virtual_address_map;
    FnConvertPointer            convert_pointer;

    /* Variable services (uefi::proto::variable) */
    FnGetVariable               get_variable;
    FnGetNextVariableName       get_next_variable_name;
    FnSetVariable               set_variable;

    /* Miscellaneous and Capsule services (uefi::proto::misc_rt) */
    FnGetNextHighMonotonicCount get_next_high_monotonic_count;
    FnResetSystem               reset_system;
    FnUpdateCapsule             update_capsule;
    FnQueryCapsuleCapabilities  query_capsule_capabilities;
    FnQueryVariableInfo         query_variable_info;
}



/*
 * EFI_GUID structure (sec x.x.x of the UEFI 2.11 specification).
 */
struct EfiGuid @packed
{
    uint        data1;
    ushort      data2;
    ushort      data3;
    char[8]     data4;
}


/*
 * EFI_TIME structure (sec 8.3.1 of the UEFI 2.11 specification).
 */
struct EfiTime @packed
{
    ushort      year;
    char        month;
    char        day;
    char        hour;
    char        minute;
    char        second;
    char        _pad1;
    uint        nanosecond;
    short       timezone;
    EfiDaylightFlags daylight;
    char        _pad2;
}

bitstruct EfiDaylightFlags : char
{
    bool        adjust          : 0;
    bool        in_daylight     : 1;
    char        reserved        : 2..7;
}

const short EFI_UNSPECIFIED_TIMEZONE = 0x07FF;

/*
 * EFI_TIME_CAPABILITIES (sec 8.3.1 of the UEFI 2.11 specification).
 */
struct EfiTimeCapabilities @packed
{
    uint        resolution;
    uint        accuracy;
    bool        sets_to_zero;
}