misc: Change how bios and uefi macros are defined and tested
diff --git a/stage23/Makefile b/stage23/Makefile
index 4c354c41..6f5d012f 100644
--- a/stage23/Makefile
+++ b/stage23/Makefile
@@ -70,12 +70,13 @@ INTERNAL_CFLAGS := \
-DLIMINE_VERSION='"$(LIMINE_VERSION)"' \
-DCOM_OUTPUT=$(COM_OUTPUT) \
-DE9_OUTPUT=$(E9_OUTPUT) \
- -D$(TARGET)=1 \
-I. \
-I..
ifeq ($(TARGET), bios)
INTERNAL_CFLAGS += \
+ -Dbios=1 \
+ -Duefi=0 \
-m32 \
-march=i386 \
-fno-pie
@@ -84,11 +85,15 @@ endif
ifeq ($(TARGET), uefi)
INTERNAL_CFLAGS32 := \
$(INTERNAL_CFLAGS) \
+ -Dbios=0 \
+ -Duefi=1 \
-m32 \
-march=i386 \
-fpie
INTERNAL_CFLAGS += \
+ -Dbios=0 \
+ -Duefi=1 \
-m64 \
-march=x86-64 \
-I../gnu-efi/inc \
diff --git a/stage23/drivers/disk.h b/stage23/drivers/disk.h
index 7df6b71a..4eb5bfd6 100644
--- a/stage23/drivers/disk.h
+++ b/stage23/drivers/disk.h
@@ -6,7 +6,7 @@
#include <stdbool.h>
#include <lib/part.h>
-#if defined (uefi)
+#if uefi == 1
#include <efi.h>
diff --git a/stage23/drivers/disk.s2.c b/stage23/drivers/disk.s2.c
index da285f41..822359ec 100644
--- a/stage23/drivers/disk.s2.c
+++ b/stage23/drivers/disk.s2.c
@@ -2,15 +2,15 @@
#include <stddef.h>
#include <drivers/disk.h>
#include <lib/libc.h>
-#if defined (bios)
+#if bios == 1
# include <lib/real.h>
-#elif defined (uefi)
+#elif uefi == 1
# include <efi.h>
#endif
#include <lib/blib.h>
#include <mm/pmm.h>
-#if defined(bios)
+#if bios == 1
struct bios_drive_params {
uint16_t buf_size;
@@ -194,7 +194,7 @@ void disk_create_index(void) {
#endif
-#if defined (uefi)
+#if uefi == 1
struct volume *disk_volume_from_efi_handle(EFI_HANDLE *efi_handle) {
EFI_STATUS status;
diff --git a/stage23/drivers/edid.c b/stage23/drivers/edid.c
index 1f8f054e..2e3981f0 100644
--- a/stage23/drivers/edid.c
+++ b/stage23/drivers/edid.c
@@ -6,7 +6,7 @@
#include <lib/libc.h>
#include <lib/print.h>
-#if defined (bios)
+#if bios == 1
#include <lib/real.h>
@@ -45,7 +45,7 @@ success:
#endif
-#if defined (uefi)
+#if uefi == 1
#include <efi.h>
diff --git a/stage23/drivers/gop.c b/stage23/drivers/gop.c
index e7eb929a..ada41737 100644
--- a/stage23/drivers/gop.c
+++ b/stage23/drivers/gop.c
@@ -1,4 +1,4 @@
-#if defined (uefi)
+#if uefi == 1
#include <efi.h>
#include <lib/blib.h>
diff --git a/stage23/drivers/gop.h b/stage23/drivers/gop.h
index 704cce2f..087e9f9c 100644
--- a/stage23/drivers/gop.h
+++ b/stage23/drivers/gop.h
@@ -1,7 +1,7 @@
#ifndef __DRIVERS__GOP_H__
#define __DRIVERS__GOP_H__
-#if defined (uefi)
+#if uefi == 1
#include <stdint.h>
#include <stdbool.h>
diff --git a/stage23/drivers/vbe.c b/stage23/drivers/vbe.c
index b7af7556..77856e46 100644
--- a/stage23/drivers/vbe.c
+++ b/stage23/drivers/vbe.c
@@ -1,4 +1,4 @@
-#if defined (bios)
+#if bios == 1
#include <stddef.h>
#include <stdint.h>
diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c
index eff6f093..bac86010 100644
--- a/stage23/drivers/vga_textmode.s2.c
+++ b/stage23/drivers/vga_textmode.s2.c
@@ -1,4 +1,4 @@
-#if defined (bios)
+#if bios == 1
#include <stdint.h>
#include <stddef.h>
diff --git a/stage23/entry.s2.c b/stage23/entry.s2.c
index 86e34a6c..3bfa588d 100644
--- a/stage23/entry.s2.c
+++ b/stage23/entry.s2.c
@@ -25,7 +25,7 @@ extern uint64_t stage3_build_id;
struct volume *boot_volume;
-#if defined (bios)
+#if bios == 1
bool stage3_loaded = false;
static bool stage3_found = false;
diff --git a/stage23/entry.s3.c b/stage23/entry.s3.c
index 955ed966..303e1077 100644
--- a/stage23/entry.s3.c
+++ b/stage23/entry.s3.c
@@ -23,7 +23,7 @@
void stage3_common(void);
-#if defined (uefi)
+#if uefi == 1
__attribute__((naked))
EFI_STATUS efi_main(
__attribute__((unused)) EFI_HANDLE ImageHandle,
@@ -78,7 +78,7 @@ void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
}
#endif
-#if defined (bios)
+#if bios == 1
__attribute__((section(".stage3_build_id")))
uint64_t stage3_build_id = BUILD_ID;
@@ -119,9 +119,9 @@ void stage3_common(void) {
if (!strcmp(proto, "stivale")) {
stivale_load(config, cmdline);
} else if (!strcmp(proto, "stivale2")) {
-#if defined (bios)
+#if bios == 1
void *efi_system_table = NULL;
-#elif defined (uefi)
+#elif uefi == 1
void *efi_system_table = gST;
#endif
diff --git a/stage23/fs/file.s2.c b/stage23/fs/file.s2.c
index ed7a0e8d..2f42ab5b 100644
--- a/stage23/fs/file.s2.c
+++ b/stage23/fs/file.s2.c
@@ -26,7 +26,7 @@ bool fs_get_guid(struct guid *guid, struct volume *part) {
int fopen(struct file_handle *ret, struct volume *part, const char *filename) {
ret->is_memfile = false;
-#if defined (bios)
+#if bios == 1
if (part->pxe) {
struct tftp_file_handle *fd = ext_mem_alloc(sizeof(struct tftp_file_handle));
diff --git a/stage23/lib/acpi.c b/stage23/lib/acpi.c
index 0c9f5e00..0cf01160 100644
--- a/stage23/lib/acpi.c
+++ b/stage23/lib/acpi.c
@@ -14,7 +14,7 @@ uint8_t acpi_checksum(void *ptr, size_t size) {
return sum;
}
-#if defined (bios)
+#if bios == 1
void *acpi_get_rsdp(void) {
size_t ebda = EBDA;
@@ -59,7 +59,7 @@ void acpi_get_smbios(void **smbios32, void **smbios64) {
#endif
-#if defined (uefi)
+#if uefi == 1
#include <efi.h>
diff --git a/stage23/lib/blib.c b/stage23/lib/blib.c
index ae944268..b239f149 100644
--- a/stage23/lib/blib.c
+++ b/stage23/lib/blib.c
@@ -9,7 +9,7 @@
#include <fs/file.h>
#include <mm/pmm.h>
-#if defined (uefi)
+#if uefi == 1
EFI_SYSTEM_TABLE *gST;
EFI_BOOT_SERVICES *gBS;
EFI_RUNTIME_SERVICES *gRT;
@@ -70,7 +70,7 @@ uint64_t sqrt(uint64_t a_nInput) {
return res;
}
-#if defined (uefi)
+#if uefi == 1
bool efi_boot_services_exited = false;
diff --git a/stage23/lib/blib.h b/stage23/lib/blib.h
index ce1815ce..c98b0810 100644
--- a/stage23/lib/blib.h
+++ b/stage23/lib/blib.h
@@ -6,11 +6,11 @@
#include <stdbool.h>
#include <fs/file.h>
#include <lib/part.h>
-#if defined (uefi)
+#if uefi == 1
# include <efi.h>
#endif
-#if defined (uefi)
+#if uefi == 1
extern EFI_SYSTEM_TABLE *gST;
extern EFI_BOOT_SERVICES *gBS;
extern EFI_RUNTIME_SERVICES *gRT;
@@ -24,7 +24,7 @@ bool efi_exit_boot_services(void);
extern struct volume *boot_volume;
-#if defined (bios)
+#if bios == 1
extern bool stage3_loaded;
#endif
diff --git a/stage23/lib/config.c b/stage23/lib/config.c
index 0eccabd6..640741fb 100644
--- a/stage23/lib/config.c
+++ b/stage23/lib/config.c
@@ -33,7 +33,7 @@ int init_config_disk(struct volume *part) {
return init_config(config_size);
}
-#if defined (bios)
+#if bios == 1
int init_config_pxe(void) {
struct tftp_file_handle cfg;
if (tftp_open(&cfg, 0, 69, "limine.cfg")) {
diff --git a/stage23/lib/fb.c b/stage23/lib/fb.c
index dd4df7c6..7d617204 100644
--- a/stage23/lib/fb.c
+++ b/stage23/lib/fb.c
@@ -10,9 +10,9 @@ bool fb_init(struct fb_info *ret,
uint16_t target_width, uint16_t target_height, uint16_t target_bpp) {
bool r;
-#if defined (bios)
+#if bios == 1
r = init_vbe(ret, target_width, target_height, target_bpp);
-#elif defined (uefi)
+#elif uefi == 1
r = init_gop(ret, target_width, target_height, target_bpp);
#endif
diff --git a/stage23/lib/panic.s2.c b/stage23/lib/panic.s2.c
index f2fae794..8b2984bf 100644
--- a/stage23/lib/panic.s2.c
+++ b/stage23/lib/panic.s2.c
@@ -1,7 +1,7 @@
#include <lib/print.h>
#include <lib/real.h>
#include <lib/trace.h>
-#if defined (uefi)
+#if uefi == 1
# include <efi.h>
#endif
#include <lib/blib.h>
@@ -22,10 +22,10 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
print("\n");
print_stacktrace(NULL);
-#if defined (bios)
+#if bios == 1
print("System halted.");
rm_hcf();
-#elif defined (uefi)
+#elif uefi == 1
if (efi_boot_services_exited == false) {
print("Press [ENTER] to return to firmware.");
while (getchar() != '\n');
diff --git a/stage23/lib/part.h b/stage23/lib/part.h
index e34ff5d4..5fbf03d9 100644
--- a/stage23/lib/part.h
+++ b/stage23/lib/part.h
@@ -5,7 +5,7 @@
#include <stddef.h>
#include <stdbool.h>
#include <lib/guid.h>
-#if defined (uefi)
+#if uefi == 1
# include <efi.h>
#endif
@@ -14,9 +14,9 @@
#define END_OF_TABLE (-3)
struct volume {
-#if defined (uefi)
+#if uefi == 1
EFI_HANDLE efi_handle;
-#elif defined (bios)
+#elif bios == 1
int drive;
#endif
@@ -53,7 +53,7 @@ int part_get(struct volume *part, struct volume *volume, int partition);
struct volume *volume_get_by_guid(struct guid *guid);
struct volume *volume_get_by_coord(bool optical, int drive, int partition);
-#if defined (bios)
+#if bios == 1
struct volume *volume_get_by_bios_drive(int drive);
#endif
diff --git a/stage23/lib/part.s2.c b/stage23/lib/part.s2.c
index 1e555bf9..8b53a74e 100644
--- a/stage23/lib/part.s2.c
+++ b/stage23/lib/part.s2.c
@@ -2,7 +2,7 @@
#include <stdint.h>
#include <lib/part.h>
#include <drivers/disk.h>
-#if defined (bios)
+#if bios == 1
# include <lib/real.h>
#endif
#include <lib/libc.h>
@@ -150,9 +150,9 @@ static int gpt_get_part(struct volume *ret, struct volume *volume, int partition
if (!memcmp(&entry.unique_partition_guid, &empty_guid, sizeof(struct guid)))
return NO_PARTITION;
-#if defined (uefi)
+#if uefi == 1
ret->efi_handle = volume->efi_handle;
-#elif defined (bios)
+#elif bios == 1
ret->drive = volume->drive;
#endif
ret->index = volume->index;
@@ -210,9 +210,9 @@ static int mbr_get_logical_part(struct volume *ret, struct volume *extended_part
if (entry.type == 0)
return NO_PARTITION;
-#if defined (uefi)
+#if uefi == 1
ret->efi_handle = extended_part->efi_handle;
-#elif defined (bios)
+#elif bios == 1
ret->drive = extended_part->drive;
#endif
ret->index = extended_part->index;
@@ -288,9 +288,9 @@ static int mbr_get_part(struct volume *ret, struct volume *volume, int partition
struct volume extended_part = {0};
-#if defined (uefi)
+#if uefi == 1
extended_part.efi_handle = volume->efi_handle;
-#elif defined (bios)
+#elif bios == 1
extended_part.drive = volume->drive;
#endif
extended_part.index = volume->index;
@@ -314,9 +314,9 @@ static int mbr_get_part(struct volume *ret, struct volume *volume, int partition
if (entry.type == 0)
return NO_PARTITION;
-#if defined (uefi)
+#if uefi == 1
ret->efi_handle = volume->efi_handle;
-#elif defined (bios)
+#elif bios == 1
ret->drive = volume->drive;
#endif
ret->index = volume->index;
@@ -384,7 +384,7 @@ struct volume *volume_get_by_coord(bool optical, int drive, int partition) {
return NULL;
}
-#if defined (bios)
+#if bios == 1
struct volume *volume_get_by_bios_drive(int drive) {
for (size_t i = 0; i < volume_index_i; i++) {
if (volume_index[i]->drive == drive) {
diff --git a/stage23/lib/readline.c b/stage23/lib/readline.c
index 201780ff..7b58729e 100644
--- a/stage23/lib/readline.c
+++ b/stage23/lib/readline.c
@@ -4,15 +4,15 @@
#include <lib/libc.h>
#include <lib/blib.h>
#include <lib/term.h>
-#if defined (bios)
+#if bios == 1
# include <lib/real.h>
-#elif defined (uefi)
+#elif uefi == 1
# include <efi.h>
#endif
int getchar_internal(uint8_t scancode, uint8_t ascii) {
switch (scancode) {
-#if defined (bios)
+#if bios == 1
case 0x44:
return GETCHAR_F10;
case 0x4b:
@@ -35,7 +35,7 @@ int getchar_internal(uint8_t scancode, uint8_t ascii) {
return GETCHAR_PGDOWN;
case 0x01:
return GETCHAR_ESCAPE;
-#elif defined (uefi)
+#elif uefi == 1
case SCAN_F10:
return GETCHAR_F10;
case SCAN_LEFT:
@@ -73,7 +73,7 @@ int getchar_internal(uint8_t scancode, uint8_t ascii) {
return ascii;
}
-#if defined (bios)
+#if bios == 1
int getchar(void) {
again:;
struct rm_regs r = {0};
@@ -91,7 +91,7 @@ int pit_sleep_and_quit_on_keypress(int seconds) {
}
#endif
-#if defined (uefi)
+#if uefi == 1
int getchar(void) {
again:;
EFI_INPUT_KEY key = {0};
diff --git a/stage23/lib/term.c b/stage23/lib/term.c
index bce44892..4c3e9822 100644
--- a/stage23/lib/term.c
+++ b/stage23/lib/term.c
@@ -12,7 +12,7 @@ void term_vbe(int width, int height) {
term_backend = NOT_READY;
if (!gterm_init(&term_rows, &term_cols, width, height)) {
-#if defined (bios)
+#if bios == 1
// Failed to set VBE properly, default to text mode
term_textmode();
#endif
diff --git a/stage23/lib/term.s2.c b/stage23/lib/term.s2.c
index 1892ab51..9ba2ebf7 100644
--- a/stage23/lib/term.s2.c
+++ b/stage23/lib/term.s2.c
@@ -33,7 +33,7 @@ void (*term_double_buffer_flush)(void);
int term_rows, term_cols;
-#if defined (bios)
+#if bios == 1
void term_textmode(void) {
term_backend = NOT_READY;
diff --git a/stage23/lib/time.c b/stage23/lib/time.c
index 1660c635..27d5ce13 100644
--- a/stage23/lib/time.c
+++ b/stage23/lib/time.c
@@ -1,9 +1,9 @@
#include <stddef.h>
#include <stdint.h>
#include <lib/time.h>
-#if defined (bios)
+#if bios == 1
# include <lib/real.h>
-#elif defined (uefi)
+#elif uefi == 1
# include <efi.h>
#endif
#include <lib/blib.h>
@@ -26,7 +26,7 @@ static uint64_t get_unix_epoch(uint8_t seconds, uint8_t minutes, uint8_t hours,
return (jdn_diff * (60 * 60 * 24)) + hours * 3600 + minutes * 60 + seconds;
}
-#if defined (bios)
+#if bios == 1
uint64_t time(void) {
struct rm_regs r = {0};
@@ -49,7 +49,7 @@ uint64_t time(void) {
}
#endif
-#if defined (uefi)
+#if uefi == 1
uint64_t time(void) {
EFI_TIME time;
uefi_call_wrapper(gRT->GetTime, 2, &time, NULL);
diff --git a/stage23/lib/trace.s2.c b/stage23/lib/trace.s2.c
index 354481a6..1b072b4d 100644
--- a/stage23/lib/trace.s2.c
+++ b/stage23/lib/trace.s2.c
@@ -8,9 +8,9 @@
#include <fs/file.h>
#include <mm/pmm.h>
-#if defined (bios)
+#if bios == 1
extern symbol stage2_map;
-#elif defined (uefi)
+#elif uefi == 1
extern symbol ImageBase;
#endif
@@ -19,12 +19,12 @@ extern symbol full_map;
static char *trace_address(size_t *off, size_t addr) {
char *limine_map;
-#if defined (bios)
+#if bios == 1
if (!stage3_loaded)
limine_map = stage2_map;
else
limine_map = full_map;
-#elif defined (uefi)
+#elif uefi == 1
limine_map = full_map;
addr -= (size_t)ImageBase;
@@ -48,9 +48,9 @@ static char *trace_address(size_t *off, size_t addr) {
void print_stacktrace(size_t *base_ptr) {
if (base_ptr == NULL) {
asm volatile (
-#if defined (bios)
+#if bios == 1
"movl %%ebp, %0"
-#elif defined (uefi)
+#elif uefi == 1
"movq %%rbp, %0"
#endif
: "=g"(base_ptr)
diff --git a/stage23/lib/uri.c b/stage23/lib/uri.c
index 822b3180..4c6d0f53 100644
--- a/stage23/lib/uri.c
+++ b/stage23/lib/uri.c
@@ -141,7 +141,7 @@ static bool uri_guid_dispatch(struct file_handle *fd, char *guid_str, char *path
return true;
}
-#if defined (bios)
+#if bios == 1
static bool uri_tftp_dispatch(struct file_handle *fd, char *root, char *path) {
uint32_t ip;
if (!strcmp(root, "")) {
@@ -166,7 +166,7 @@ static bool uri_tftp_dispatch(struct file_handle *fd, char *root, char *path) {
#endif
static bool uri_boot_dispatch(struct file_handle *fd, char *s_part, char *path) {
-#if defined (bios)
+#if bios == 1
if (boot_volume->pxe)
return uri_tftp_dispatch(fd, s_part, path);
#endif
@@ -222,7 +222,7 @@ bool uri_open(struct file_handle *fd, char *uri) {
ret = uri_guid_dispatch(fd, root, path);
} else if (!strcmp(resource, "uuid")) {
ret = uri_guid_dispatch(fd, root, path);
-#if defined (bios)
+#if bios == 1
} else if (!strcmp(resource, "tftp")) {
ret = uri_tftp_dispatch(fd, root, path);
#endif
diff --git a/stage23/menu.c b/stage23/menu.c
index 9a570c53..c3d67c21 100644
--- a/stage23/menu.c
+++ b/stage23/menu.c
@@ -516,9 +516,9 @@ char *menu(char **cmdline) {
}
// If there is GRAPHICS config key and the value is "yes", enable graphics
-#if defined (bios)
+#if bios == 1
char *graphics = config_get_value(NULL, 0, "GRAPHICS");
-#elif defined (uefi)
+#elif uefi == 1
char *graphics = "yes";
#endif
if (graphics != NULL && !strcmp(graphics, "yes")) {
diff --git a/stage23/mm/pmm.h b/stage23/mm/pmm.h
index dd32e9fa..c2c41faa 100644
--- a/stage23/mm/pmm.h
+++ b/stage23/mm/pmm.h
@@ -20,7 +20,7 @@
extern struct e820_entry_t memmap[];
extern size_t memmap_entries;
-#if defined (uefi)
+#if uefi == 1
extern struct e820_entry_t untouched_memmap[];
extern size_t untouched_memmap_entries;
#endif
@@ -37,7 +37,7 @@ void *ext_mem_alloc_type(size_t count, uint32_t type);
void *conv_mem_alloc(size_t count);
-#if defined (uefi)
+#if uefi == 1
void pmm_reclaim_uefi_mem(void);
void pmm_release_uefi_mem(void);
#endif
diff --git a/stage23/mm/pmm.s2.c b/stage23/mm/pmm.s2.c
index 39fdfc88..95cf2597 100644
--- a/stage23/mm/pmm.s2.c
+++ b/stage23/mm/pmm.s2.c
@@ -7,14 +7,14 @@
#include <lib/blib.h>
#include <lib/libc.h>
#include <lib/print.h>
-#if defined (uefi)
+#if uefi == 1
# include <efi.h>
#endif
#define PAGE_SIZE 4096
#define MEMMAP_MAX_ENTRIES 256
-#if defined (bios)
+#if bios == 1
extern symbol bss_end;
#endif
@@ -51,7 +51,7 @@ void *conv_mem_alloc(size_t count) {
struct e820_entry_t memmap[MEMMAP_MAX_ENTRIES];
size_t memmap_entries = 0;
-#if defined (uefi)
+#if uefi == 1
struct e820_entry_t untouched_memmap[MEMMAP_MAX_ENTRIES];
size_t untouched_memmap_entries = 0;
#endif
@@ -206,7 +206,7 @@ struct e820_entry_t *get_memmap(size_t *entries) {
return memmap;
}
-#if defined (bios)
+#if bios == 1
void init_memmap(void) {
for (size_t i = 0; i < e820_entries; i++) {
if (memmap_entries == MEMMAP_MAX_ENTRIES) {
@@ -253,7 +253,7 @@ void init_memmap(void) {
}
#endif
-#if defined (uefi)
+#if uefi == 1
void init_memmap(void) {
EFI_STATUS status;
@@ -472,14 +472,14 @@ void pmm_release_uefi_mem(void) {
}
#endif
-#if defined (bios)
+#if bios == 1
struct e820_entry_t *get_raw_memmap(size_t *entry_count) {
*entry_count = e820_entries;
return e820_map;
}
#endif
-#if defined (uefi)
+#if uefi == 1
struct e820_entry_t *get_raw_memmap(size_t *entry_count) {
size_t mmap_count = efi_mmap_size / efi_desc_size;
size_t mmap_len = mmap_count * sizeof(struct e820_entry_t);
diff --git a/stage23/protos/chainload.c b/stage23/protos/chainload.c
index f03f2027..586f8f6c 100644
--- a/stage23/protos/chainload.c
+++ b/stage23/protos/chainload.c
@@ -13,11 +13,11 @@
#include <sys/idt.h>
#include <drivers/vga_textmode.h>
#include <mm/pmm.h>
-#if defined (uefi)
+#if uefi == 1
# include <efi.h>
#endif
-#if defined (bios)
+#if bios == 1
__attribute__((noinline))
__attribute__((section(".realmode")))
@@ -107,7 +107,7 @@ void chainload(char *config) {
spinup(drive);
}
-#elif defined (uefi)
+#elif uefi == 1
void chainload(char *config) {
EFI_STATUS status;
diff --git a/stage23/protos/linux.c b/stage23/protos/linux.c
index 60279c3d..b938e455 100644
--- a/stage23/protos/linux.c
+++ b/stage23/protos/linux.c
@@ -513,9 +513,9 @@ void linux_load(char *config, char *cmdline) {
screen_info->blue_size = fbinfo.blue_mask_size;
screen_info->blue_pos = fbinfo.blue_mask_shift;
-#if defined (bios)
+#if bios == 1
screen_info->orig_video_isVGA = VIDEO_TYPE_VLFB;
-#elif defined (uefi)
+#elif uefi == 1
screen_info->orig_video_isVGA = VIDEO_TYPE_EFI;
#endif
@@ -534,7 +534,7 @@ void linux_load(char *config, char *cmdline) {
///////////////////////////////////////
// UEFI
///////////////////////////////////////
-#if defined (uefi)
+#if uefi == 1
efi_exit_boot_services();
memcpy(&boot_params->efi_info.efi_loader_signature, "EL64", 4);
diff --git a/stage23/protos/multiboot1.c b/stage23/protos/multiboot1.c
index 66337cf6..6b815cdd 100644
--- a/stage23/protos/multiboot1.c
+++ b/stage23/protos/multiboot1.c
@@ -206,9 +206,9 @@ void multiboot1_load(char *config, char *cmdline) {
multiboot1_info.fb_blue_mask_size = fbinfo.blue_mask_size;
multiboot1_info.fb_blue_mask_shift = fbinfo.blue_mask_shift;
} else if (header.fb_mode == 1) {
-#if defined (uefi)
+#if uefi == 1
panic("multiboot1: Cannot use text mode with UEFI.");
-#elif defined (bios)
+#elif bios == 1
int rows, cols;
init_vga_textmode(&rows, &cols, false);
@@ -225,15 +225,15 @@ void multiboot1_load(char *config, char *cmdline) {
multiboot1_info.flags |= (1 << 12);
} else {
-#if defined (uefi)
+#if uefi == 1
panic("multiboot1: Cannot use text mode with UEFI.");
-#elif defined (bios)
+#elif bios == 1
int rows, cols;
init_vga_textmode(&rows, &cols, false);
#endif
}
-#if defined (uefi)
+#if uefi == 1
efi_exit_boot_services();
#endif
diff --git a/stage23/protos/stivale.c b/stage23/protos/stivale.c
index a95f0e0c..d559d743 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -57,7 +57,7 @@ struct stivale_struct stivale_struct = {0};
void stivale_load(char *config, char *cmdline) {
// BIOS or UEFI?
-#if defined (bios)
+#if bios == 1
stivale_struct.flags |= (1 << 0);
#endif
@@ -267,15 +267,15 @@ void stivale_load(char *config, char *cmdline) {
stivale_struct.fb_blue_mask_size = fbinfo.blue_mask_size;
stivale_struct.fb_blue_mask_shift = fbinfo.blue_mask_shift;
} else {
-#if defined (uefi)
+#if uefi == 1
panic("stivale: Cannot use text mode with UEFI.");
-#elif defined (bios)
+#elif bios == 1
int rows, cols;
init_vga_textmode(&rows, &cols, false);
#endif
}
-#if defined (uefi)
+#if uefi == 1
efi_exit_boot_services();
#endif
@@ -351,7 +351,7 @@ pagemap_t stivale_build_pagemap(bool level5pg, bool unmap_null) {
return pagemap;
}
-#if defined (uefi)
+#if uefi == 1
extern symbol ImageBase;
#endif
@@ -364,7 +364,7 @@ __attribute__((noreturn)) void stivale_spinup_32(
__attribute__((noreturn)) void stivale_spinup(
int bits, bool level5pg, pagemap_t *pagemap,
uint64_t entry_point, uint64_t _stivale_struct, uint64_t stack) {
-#if defined (bios)
+#if bios == 1
if (bits == 64) {
// If we're going 64, we might as well call this BIOS interrupt
// to tell the BIOS that we are entering Long Mode, since it is in
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 1207af52..b2e697ef 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -54,7 +54,7 @@ static void *get_tag(struct stivale2_header *s, uint64_t id) {
(S)->tags = REPORTED_ADDR((uint64_t)(uintptr_t)TAG); \
})
-#if defined (bios)
+#if bios == 1
extern symbol stivale2_term_write_entry;
#endif
@@ -202,7 +202,7 @@ void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table
struct stivale2_struct_tag_firmware *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_firmware));
tag->tag.identifier = STIVALE2_STRUCT_TAG_FIRMWARE_ID;
-#if defined (bios)
+#if bios == 1
tag->flags = 1 << 0; // bit 0 = BIOS boot
#endif
@@ -362,10 +362,10 @@ void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table
// We provide max allowed string length
tag->flags |= (1 << 1);
-#if defined (bios)
+#if bios == 1
tag->term_write = (uintptr_t)(void *)stivale2_term_write_entry;
tag->max_length = 4096;
-#elif defined (uefi)
+#elif uefi == 1
tag->term_write = (uintptr_t)term_write;
tag->max_length = 0;
#endif
@@ -382,13 +382,8 @@ void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table
fb = &_fb;
}
- if (hdrtag != NULL || (avtag != NULL &&
-#if defined (uefi)
- true
-#else
- false
-#endif
- ) || (avtag != NULL && avtag->preference == 0)) {
+ if (hdrtag != NULL || (avtag != NULL && uefi)
+ || (avtag != NULL && avtag->preference == 0)) {
term_deinit();
if (fb_init(fb, req_width, req_height, req_bpp)) {
@@ -416,9 +411,9 @@ skip_modeset:;
append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
}
} else {
-#if defined (uefi)
+#if uefi == 1
panic("stivale2: Cannot use text mode with UEFI.");
-#elif defined (bios)
+#elif bios == 1
int rows, cols;
init_vga_textmode(&rows, &cols, false);
@@ -452,7 +447,7 @@ skip_modeset:;
}
}
-#if defined (bios)
+#if bios == 1
//////////////////////////////////////////////
// Create PXE struct tag
//////////////////////////////////////////////
@@ -486,7 +481,7 @@ skip_modeset:;
if (bits == 64)
pagemap = stivale_build_pagemap(want_5lv, unmap_null);
-#if defined (uefi)
+#if uefi == 1
efi_exit_boot_services();
#endif
diff --git a/stage23/pxe/pxe.s2.c b/stage23/pxe/pxe.s2.c
index 95b7d4bd..a49ff5c7 100644
--- a/stage23/pxe/pxe.s2.c
+++ b/stage23/pxe/pxe.s2.c
@@ -1,4 +1,4 @@
-#if defined (bios)
+#if bios == 1
#include <lib/print.h>
#include <lib/real.h>
diff --git a/stage23/pxe/tftp.s2.c b/stage23/pxe/tftp.s2.c
index 3d1e6498..6a2c705f 100644
--- a/stage23/pxe/tftp.s2.c
+++ b/stage23/pxe/tftp.s2.c
@@ -1,4 +1,4 @@
-#if defined (bios)
+#if bios == 1
#include <pxe/tftp.h>
#include <pxe/pxe.h>
diff --git a/stage23/sbat.c b/stage23/sbat.c
index fa3dca13..6fadba27 100644
--- a/stage23/sbat.c
+++ b/stage23/sbat.c
@@ -1,4 +1,4 @@
-#if defined (uefi)
+#if uefi == 1
asm (
".section .sbat\n\t"
diff --git a/stage23/sys/a20.s2.c b/stage23/sys/a20.s2.c
index e3e1f8c2..57234b01 100644
--- a/stage23/sys/a20.s2.c
+++ b/stage23/sys/a20.s2.c
@@ -1,4 +1,4 @@
-#if defined (bios)
+#if bios == 1
#include <stdint.h>
#include <stddef.h>
diff --git a/stage23/sys/e820.s2.c b/stage23/sys/e820.s2.c
index ae86646d..03339457 100644
--- a/stage23/sys/e820.s2.c
+++ b/stage23/sys/e820.s2.c
@@ -1,4 +1,4 @@
-#if defined (bios)
+#if bios == 1
#include <stdint.h>
#include <stddef.h>
diff --git a/stage23/sys/exceptions.s2.c b/stage23/sys/exceptions.s2.c
index ea51d3cf..ec80564d 100644
--- a/stage23/sys/exceptions.s2.c
+++ b/stage23/sys/exceptions.s2.c
@@ -3,7 +3,7 @@
#include <lib/trace.h>
#include <lib/print.h>
-#if defined (bios)
+#if bios == 1
static const char *exception_names[] = {
"Division by 0",
diff --git a/stage23/sys/gdt.h b/stage23/sys/gdt.h
index 2132160e..55a297d6 100644
--- a/stage23/sys/gdt.h
+++ b/stage23/sys/gdt.h
@@ -5,10 +5,10 @@
struct gdtr {
uint16_t limit;
-#if defined (uefi)
+#if uefi == 1
uint64_t ptr;
#endif
-#if defined (bios)
+#if bios == 1
uint32_t ptr;
uint32_t pad;
#endif
diff --git a/stage23/sys/gdt.s2.c b/stage23/sys/gdt.s2.c
index bf2f2ebd..d8557b9d 100644
--- a/stage23/sys/gdt.s2.c
+++ b/stage23/sys/gdt.s2.c
@@ -59,13 +59,13 @@ static struct gdt_desc gdt_descs[] = {
}
};
-#if defined (bios)
+#if bios == 1
__attribute__((section(".realmode")))
#endif
struct gdtr gdt = {
sizeof(gdt_descs) - 1,
(uintptr_t)gdt_descs,
-#if defined (bios)
+#if bios == 1
0
#endif
};
diff --git a/stage23/sys/idt.h b/stage23/sys/idt.h
index 856a4a7c..002e74ab 100644
--- a/stage23/sys/idt.h
+++ b/stage23/sys/idt.h
@@ -3,7 +3,7 @@
#include <stdint.h>
-#if defined (bios)
+#if bios == 1
struct idtr {
uint16_t limit;
diff --git a/stage23/sys/idt.s2.c b/stage23/sys/idt.s2.c
index 4d4af156..e5baf3e9 100644
--- a/stage23/sys/idt.s2.c
+++ b/stage23/sys/idt.s2.c
@@ -3,7 +3,7 @@
#include <sys/idt.h>
#include <lib/blib.h>
-#if defined (bios)
+#if bios == 1
static struct idt_entry idt_entries[32];
