2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_EFI_EMU_HEADER
20 #define GRUB_EFI_EMU_HEADER 1
22 #include <grub/efi/api.h>
23 #include <grub/file.h>
24 #include <grub/memory.h>
26 #define GRUB_EFIEMU_PAGESIZE 4096
28 /* EFI api defined in 32-bit and 64-bit version*/
29 struct grub_efi_system_table32
31 grub_efi_table_header_t hdr
;
32 grub_efi_uint32_t firmware_vendor
;
33 grub_efi_uint32_t firmware_revision
;
34 grub_efi_uint32_t console_in_handler
;
35 grub_efi_uint32_t con_in
;
36 grub_efi_uint32_t console_out_handler
;
37 grub_efi_uint32_t con_out
;
38 grub_efi_uint32_t standard_error_handle
;
39 grub_efi_uint32_t std_err
;
40 grub_efi_uint32_t runtime_services
;
41 grub_efi_uint32_t boot_services
;
42 grub_efi_uint32_t num_table_entries
;
43 grub_efi_uint32_t configuration_table
;
45 typedef struct grub_efi_system_table32 grub_efi_system_table32_t
;
47 struct grub_efi_system_table64
49 grub_efi_table_header_t hdr
;
50 grub_efi_uint64_t firmware_vendor
;
51 grub_efi_uint32_t firmware_revision
;
52 grub_efi_uint32_t pad
;
53 grub_efi_uint64_t console_in_handler
;
54 grub_efi_uint64_t con_in
;
55 grub_efi_uint64_t console_out_handler
;
56 grub_efi_uint64_t con_out
;
57 grub_efi_uint64_t standard_error_handle
;
58 grub_efi_uint64_t std_err
;
59 grub_efi_uint64_t runtime_services
;
60 grub_efi_uint64_t boot_services
;
61 grub_efi_uint64_t num_table_entries
;
62 grub_efi_uint64_t configuration_table
;
64 typedef struct grub_efi_system_table64 grub_efi_system_table64_t
;
66 struct grub_efiemu_runtime_services32
68 grub_efi_table_header_t hdr
;
69 grub_efi_uint32_t get_time
;
70 grub_efi_uint32_t set_time
;
71 grub_efi_uint32_t get_wakeup_time
;
72 grub_efi_uint32_t set_wakeup_time
;
73 grub_efi_uint32_t set_virtual_address_map
;
74 grub_efi_uint32_t convert_pointer
;
75 grub_efi_uint32_t get_variable
;
76 grub_efi_uint32_t get_next_variable_name
;
77 grub_efi_uint32_t set_variable
;
78 grub_efi_uint32_t get_next_high_monotonic_count
;
79 grub_efi_uint32_t reset_system
;
81 typedef struct grub_efiemu_runtime_services32 grub_efiemu_runtime_services32_t
;
83 struct grub_efiemu_runtime_services64
85 grub_efi_table_header_t hdr
;
86 grub_efi_uint64_t get_time
;
87 grub_efi_uint64_t set_time
;
88 grub_efi_uint64_t get_wakeup_time
;
89 grub_efi_uint64_t set_wakeup_time
;
90 grub_efi_uint64_t set_virtual_address_map
;
91 grub_efi_uint64_t convert_pointer
;
92 grub_efi_uint64_t get_variable
;
93 grub_efi_uint64_t get_next_variable_name
;
94 grub_efi_uint64_t set_variable
;
95 grub_efi_uint64_t get_next_high_monotonic_count
;
96 grub_efi_uint64_t reset_system
;
98 typedef struct grub_efiemu_runtime_services64 grub_efiemu_runtime_services64_t
;
100 extern grub_efi_system_table32_t
*grub_efiemu_system_table32
;
101 extern grub_efi_system_table64_t
*grub_efiemu_system_table64
;
103 /* Convenience macros to access currently loaded efiemu */
104 #define grub_efiemu_system_table ((grub_efiemu_sizeof_uintn_t () == 8) \
105 ? (void *) grub_efiemu_system_table64 \
106 : (void *) grub_efiemu_system_table32)
107 #define GRUB_EFIEMU_SIZEOF_OF_UINTN (grub_efiemu_sizeof_uintn_t ())
108 #define GRUB_EFIEMU_SYSTEM_TABLE(x) ((grub_efiemu_sizeof_uintn_t () == 8) \
109 ? grub_efiemu_system_table64->x \
110 : grub_efiemu_system_table32->x)
111 #define GRUB_EFIEMU_SYSTEM_TABLE_SET(x,y) ((grub_efiemu_sizeof_uintn_t () == 8)\
112 ? (grub_efiemu_system_table64->x \
114 : (grub_efiemu_system_table32->x \
116 #define GRUB_EFIEMU_SYSTEM_TABLE_PTR(x) ((grub_efiemu_sizeof_uintn_t () == 8)\
117 ? (void *) (grub_addr_t) \
118 (grub_efiemu_system_table64->x) \
119 : (void *) (grub_addr_t) \
120 (grub_efiemu_system_table32->x))
121 #define GRUB_EFIEMU_SYSTEM_TABLE_VAR(x) ((grub_efiemu_sizeof_uintn_t () == 8) \
123 &(grub_efiemu_system_table64->x) \
125 &(grub_efiemu_system_table32->x))
126 #define GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF(x) \
127 ((grub_efiemu_sizeof_uintn_t () == 8) \
128 ? sizeof(grub_efiemu_system_table64->x)\
129 : sizeof(grub_efiemu_system_table32->x))
130 #define GRUB_EFIEMU_SYSTEM_TABLE_SIZEOF_TOTAL ((grub_efiemu_sizeof_uintn_t () == 8) ? sizeof(*grub_efiemu_system_table64):sizeof(*grub_efiemu_system_table32))
132 /* ELF management definitions and functions */
134 struct grub_efiemu_segment
136 struct grub_efiemu_segment
*next
;
144 typedef struct grub_efiemu_segment
*grub_efiemu_segment_t
;
146 struct grub_efiemu_elf_sym
153 int grub_efiemu_check_header32 (void *ehdr
, grub_size_t size
);
154 int grub_efiemu_check_header64 (void *ehdr
, grub_size_t size
);
155 grub_err_t
grub_efiemu_loadcore_init32 (void *core
,
156 const char *filename
,
157 grub_size_t core_size
,
158 grub_efiemu_segment_t
*segments
);
159 grub_err_t
grub_efiemu_loadcore_init64 (void *core
, const char *filename
,
160 grub_size_t core_size
,
161 grub_efiemu_segment_t
*segments
);
162 grub_err_t
grub_efiemu_loadcore_load32 (void *core
,
163 grub_size_t core_size
,
164 grub_efiemu_segment_t segments
);
165 grub_err_t
grub_efiemu_loadcore_load64 (void *core
,
166 grub_size_t core_size
,
167 grub_efiemu_segment_t segments
);
168 grub_err_t
grub_efiemu_loadcore_unload32 (void);
169 grub_err_t
grub_efiemu_loadcore_unload64 (void);
170 grub_err_t
grub_efiemu_loadcore_unload(void);
171 grub_err_t
grub_efiemu_loadcore_init (grub_file_t file
,
172 const char *filename
);
173 grub_err_t
grub_efiemu_loadcore_load (void);
175 /* Configuration tables manipulation. Definitions and functions */
176 struct grub_efiemu_configuration_table
178 struct grub_efiemu_configuration_table
*next
;
179 grub_efi_guid_t guid
;
180 void * (*get_table
) (void *data
);
181 void (*unload
) (void *data
);
184 struct grub_efiemu_configuration_table32
186 grub_efi_packed_guid_t vendor_guid
;
187 grub_efi_uint32_t vendor_table
;
189 typedef struct grub_efiemu_configuration_table32 grub_efiemu_configuration_table32_t
;
190 struct grub_efiemu_configuration_table64
192 grub_efi_packed_guid_t vendor_guid
;
193 grub_efi_uint64_t vendor_table
;
195 typedef struct grub_efiemu_configuration_table64 grub_efiemu_configuration_table64_t
;
196 grub_err_t
grub_efiemu_unregister_configuration_table (grub_efi_guid_t guid
);
198 grub_efiemu_register_configuration_table (grub_efi_guid_t guid
,
199 void * (*get_table
) (void *data
),
200 void (*unload
) (void *data
),
203 /* Memory management functions */
204 int grub_efiemu_request_memalign (grub_size_t align
, grub_size_t size
,
205 grub_efi_memory_type_t type
);
206 void *grub_efiemu_mm_obtain_request (int handle
);
207 grub_err_t
grub_efiemu_mm_unload (void);
208 grub_err_t
grub_efiemu_mm_do_alloc (void);
209 grub_err_t
grub_efiemu_mm_init (void);
210 void grub_efiemu_mm_return_request (int handle
);
211 grub_efi_memory_type_t
grub_efiemu_mm_get_type (int handle
);
213 /* Drop-in replacements for grub_efi_* and grub_machine_* */
214 int grub_efiemu_get_memory_map (grub_efi_uintn_t
*memory_map_size
,
215 grub_efi_memory_descriptor_t
*memory_map
,
216 grub_efi_uintn_t
*map_key
,
217 grub_efi_uintn_t
*descriptor_size
,
218 grub_efi_uint32_t
*descriptor_version
);
222 grub_efiemu_finish_boot_services (grub_efi_uintn_t
*memory_map_size
,
223 grub_efi_memory_descriptor_t
*memory_map
,
224 grub_efi_uintn_t
*map_key
,
225 grub_efi_uintn_t
*descriptor_size
,
226 grub_efi_uint32_t
*descriptor_version
);
229 grub_efiemu_mmap_iterate (grub_memory_hook_t hook
, void *hook_data
);
230 int grub_efiemu_sizeof_uintn_t (void);
232 grub_efiemu_get_lower_upper_memory (grub_uint64_t
*lower
, grub_uint64_t
*upper
);
234 /* efiemu main control definitions and functions*/
235 typedef enum {GRUB_EFIEMU_NOTLOADED
,
236 GRUB_EFIEMU32
, GRUB_EFIEMU64
} grub_efiemu_mode_t
;
237 struct grub_efiemu_prepare_hook
239 struct grub_efiemu_prepare_hook
*next
;
240 grub_err_t (*hook
) (void *data
);
241 void (*unload
) (void *data
);
244 grub_err_t
grub_efiemu_prepare32 (struct grub_efiemu_prepare_hook
246 struct grub_efiemu_configuration_table
248 grub_err_t
grub_efiemu_prepare64 (struct grub_efiemu_prepare_hook
250 struct grub_efiemu_configuration_table
252 grub_err_t
grub_efiemu_unload (void);
253 grub_err_t
grub_efiemu_prepare (void);
255 grub_efiemu_register_prepare_hook (grub_err_t (*hook
) (void *data
),
256 void (*unload
) (void *data
),
259 /* symbols and pointers */
260 grub_err_t
grub_efiemu_alloc_syms (void);
261 grub_err_t
grub_efiemu_request_symbols (int num
);
262 grub_err_t
grub_efiemu_resolve_symbol (const char *name
,
263 int *handle
, grub_off_t
*off
);
264 grub_err_t
grub_efiemu_register_symbol (const char *name
,
265 int handle
, grub_off_t off
);
266 void grub_efiemu_free_syms (void);
267 grub_err_t
grub_efiemu_write_value (void * addr
, grub_uint32_t value
,
269 int minus_handle
, int ptv_needed
, int size
);
270 grub_err_t
grub_efiemu_write_sym_markers (void);
271 grub_err_t
grub_efiemu_pnvram (void);
272 const char *grub_efiemu_get_default_core_name (void);
273 void grub_efiemu_pnvram_cmd_unregister (void);
274 grub_err_t
grub_efiemu_autocore (void);
275 grub_err_t
grub_efiemu_crc32 (void);
276 grub_err_t
grub_efiemu_crc64 (void);
278 grub_efiemu_set_virtual_address_map (grub_efi_uintn_t memory_map_size
,
279 grub_efi_uintn_t descriptor_size
,
280 grub_efi_uint32_t descriptor_version
281 __attribute__ ((unused
)),
282 grub_efi_memory_descriptor_t
*virtual_map
);
284 grub_err_t
grub_machine_efiemu_init_tables (void);
286 #endif /* ! GRUB_EFI_EMU_HEADER */