2022-08-26 23:44:47 +02:00
|
|
|
#ifndef __LIB__MISC_H__
|
|
|
|
#define __LIB__MISC_H__
|
2020-01-22 05:02:12 +01:00
|
|
|
|
|
|
|
#include <stddef.h>
|
2020-01-25 02:05:19 +01:00
|
|
|
#include <stdint.h>
|
2020-10-17 06:23:11 +02:00
|
|
|
#include <stdbool.h>
|
2021-12-31 10:58:05 +01:00
|
|
|
#include <stdnoreturn.h>
|
2021-02-25 11:28:14 +01:00
|
|
|
#include <fs/file.h>
|
2021-03-02 10:23:43 +01:00
|
|
|
#include <lib/part.h>
|
2021-08-16 18:02:28 +02:00
|
|
|
#include <lib/libc.h>
|
2022-09-02 02:29:12 +02:00
|
|
|
#if defined (UEFI)
|
2021-03-02 10:23:43 +01:00
|
|
|
# include <efi.h>
|
|
|
|
#endif
|
|
|
|
|
2022-09-02 02:29:12 +02:00
|
|
|
#if defined (UEFI)
|
2021-03-02 10:23:43 +01:00
|
|
|
extern EFI_SYSTEM_TABLE *gST;
|
|
|
|
extern EFI_BOOT_SERVICES *gBS;
|
|
|
|
extern EFI_RUNTIME_SERVICES *gRT;
|
2021-03-05 04:20:58 +01:00
|
|
|
extern EFI_HANDLE efi_image_handle;
|
2021-04-28 23:41:34 +02:00
|
|
|
extern EFI_MEMORY_DESCRIPTOR *efi_mmap;
|
2021-08-25 22:03:00 +02:00
|
|
|
extern UINTN efi_mmap_size, efi_desc_size;
|
|
|
|
extern UINT32 efi_desc_ver;
|
2021-03-05 04:20:58 +01:00
|
|
|
|
|
|
|
extern bool efi_boot_services_exited;
|
|
|
|
bool efi_exit_boot_services(void);
|
2021-03-02 10:23:43 +01:00
|
|
|
#endif
|
2020-10-01 02:12:13 +02:00
|
|
|
|
2021-10-09 13:32:57 +02:00
|
|
|
extern const char bsd_2_clause[];
|
2021-08-22 18:29:18 +02:00
|
|
|
|
2021-03-11 00:23:44 +01:00
|
|
|
extern struct volume *boot_volume;
|
2020-10-01 02:12:13 +02:00
|
|
|
|
2022-09-02 02:29:12 +02:00
|
|
|
#if defined (BIOS)
|
2021-02-22 06:14:27 +01:00
|
|
|
extern bool stage3_loaded;
|
2021-03-11 00:23:44 +01:00
|
|
|
#endif
|
2020-12-29 01:01:38 +01:00
|
|
|
|
2022-09-11 20:47:57 +02:00
|
|
|
extern bool quiet, serial, editor_enabled, hash_mismatch_panic;
|
2021-05-11 06:46:42 +02:00
|
|
|
|
2021-08-16 18:02:28 +02:00
|
|
|
bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf);
|
2020-11-09 12:31:47 +01:00
|
|
|
|
2022-08-21 00:50:12 +02:00
|
|
|
void get_absolute_path(char *path_ptr, const char *path, const char *pwd);
|
|
|
|
|
2021-11-07 12:29:58 +01:00
|
|
|
uint32_t oct2bin(uint8_t *str, uint32_t max);
|
|
|
|
uint32_t hex2bin(uint8_t *str, uint32_t size);
|
|
|
|
|
2020-09-30 17:29:07 +02:00
|
|
|
uint64_t sqrt(uint64_t a_nInput);
|
2021-07-17 08:19:03 +02:00
|
|
|
size_t get_trailing_zeros(uint64_t val);
|
2020-09-30 17:29:07 +02:00
|
|
|
|
2020-11-02 09:20:34 +01:00
|
|
|
int digit_to_int(char c);
|
2020-04-30 21:19:12 +02:00
|
|
|
uint8_t bcd_to_int(uint8_t val);
|
2021-11-01 20:38:36 +00:00
|
|
|
uint8_t int_to_bcd(uint8_t val);
|
2020-04-30 21:19:12 +02:00
|
|
|
|
2021-12-31 10:58:05 +01:00
|
|
|
noreturn void panic(bool allow_menu, const char *fmt, ...);
|
2020-04-13 08:21:25 +02:00
|
|
|
|
2021-03-04 13:48:31 +01:00
|
|
|
int pit_sleep_and_quit_on_keypress(int seconds);
|
2020-01-22 05:02:12 +01:00
|
|
|
|
2020-11-05 12:50:42 +01:00
|
|
|
uint64_t strtoui(const char *s, const char **end, int base);
|
2020-01-22 05:02:12 +01:00
|
|
|
|
2021-08-16 18:02:28 +02:00
|
|
|
#if defined (__i386__)
|
|
|
|
void memcpy32to64(uint64_t, uint64_t, uint64_t);
|
2022-08-18 17:32:54 +02:00
|
|
|
#elif defined (__x86_64__) || defined (__aarch64__)
|
2021-08-16 18:02:28 +02:00
|
|
|
# define memcpy32to64(X, Y, Z) memcpy((void *)(uintptr_t)(X), (void *)(uintptr_t)(Y), Z)
|
2022-08-18 17:32:54 +02:00
|
|
|
#else
|
|
|
|
#error Unknown architecture
|
2021-08-16 18:02:28 +02:00
|
|
|
#endif
|
|
|
|
|
2022-08-26 21:34:40 +02:00
|
|
|
#define DIV_ROUNDUP(a, b) ({ \
|
|
|
|
__auto_type DIV_ROUNDUP_a = (a); \
|
|
|
|
__auto_type DIV_ROUNDUP_b = (b); \
|
|
|
|
(DIV_ROUNDUP_a + (DIV_ROUNDUP_b - 1)) / DIV_ROUNDUP_b; \
|
|
|
|
})
|
2020-01-22 05:02:12 +01:00
|
|
|
|
2020-09-17 12:06:35 +02:00
|
|
|
#define ALIGN_UP(x, a) ({ \
|
2022-08-26 21:34:40 +02:00
|
|
|
__auto_type ALIGN_UP_value = (x); \
|
|
|
|
__auto_type ALIGN_UP_align = (a); \
|
|
|
|
ALIGN_UP_value = DIV_ROUNDUP(ALIGN_UP_value, ALIGN_UP_align) * ALIGN_UP_align; \
|
|
|
|
ALIGN_UP_value; \
|
2020-09-17 12:06:35 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define ALIGN_DOWN(x, a) ({ \
|
2022-08-26 21:34:40 +02:00
|
|
|
__auto_type ALIGN_DOWN_value = (x); \
|
|
|
|
__auto_type ALIGN_DOWN_align = (a); \
|
|
|
|
ALIGN_DOWN_value = (ALIGN_DOWN_value / ALIGN_DOWN_align) * ALIGN_DOWN_align; \
|
|
|
|
ALIGN_DOWN_value; \
|
2020-09-17 12:06:35 +02:00
|
|
|
})
|
2020-01-22 05:02:12 +01:00
|
|
|
|
2020-05-01 17:19:29 +02:00
|
|
|
#define SIZEOF_ARRAY(array) (sizeof(array) / sizeof(array[0]))
|
|
|
|
|
2021-02-25 01:24:54 +01:00
|
|
|
typedef char symbol[];
|
2020-09-17 12:06:35 +02:00
|
|
|
|
2021-12-31 10:58:05 +01:00
|
|
|
noreturn void stage3_common(void);
|
2021-12-11 19:58:00 +01:00
|
|
|
|
2022-08-18 17:32:54 +02:00
|
|
|
#if defined (__x86_64__) || defined (__i386__)
|
2021-12-31 10:58:05 +01:00
|
|
|
noreturn void common_spinup(void *fnptr, int args, ...);
|
2022-08-18 17:32:54 +02:00
|
|
|
#elif defined (__aarch64__)
|
|
|
|
noreturn void enter_in_current_el(uint64_t entry, uint64_t sp, uint64_t sctlr,
|
|
|
|
uint64_t target_x0);
|
|
|
|
|
|
|
|
noreturn void enter_in_el1(uint64_t entry, uint64_t sp, uint64_t sctlr,
|
|
|
|
uint64_t mair, uint64_t tcr, uint64_t ttbr0,
|
|
|
|
uint64_t ttbr1, uint64_t target_x0);
|
|
|
|
#else
|
|
|
|
#error Unknown architecture
|
|
|
|
#endif
|
2021-03-07 00:52:25 +01:00
|
|
|
|
2021-12-12 18:48:36 +01:00
|
|
|
#define no_unwind __attribute__((section(".no_unwind")))
|
|
|
|
|
2020-01-22 05:02:12 +01:00
|
|
|
#endif
|