diff --git a/app/test.h b/app/test.h index 7267273..904d306 100644 --- a/app/test.h +++ b/app/test.h @@ -52,7 +52,7 @@ extern barrier_t *run_barrier; */ extern spinlock_t *error_mutex; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) /** * The word width (in bits) used for memory testing. */ diff --git a/boot/efi.h b/boot/efi.h index 048f9fc..852c62c 100644 --- a/boot/efi.h +++ b/boot/efi.h @@ -13,7 +13,7 @@ #include -#ifdef __x86_64__ +#if (ARCH_BITS == 64) #define NATIVE_MSB UINT64_C(0x8000000000000000) #else #define NATIVE_MSB 0x80000000 @@ -71,7 +71,7 @@ #define efiapi __attribute__((ms_abi)) -#ifdef __x86_64__ +#if (ARCH_BITS == 64) typedef uint64_t uintn_t; #else typedef uint32_t uintn_t; diff --git a/boot/efisetup.c b/boot/efisetup.c index 54e8be4..c4bbe69 100644 --- a/boot/efisetup.c +++ b/boot/efisetup.c @@ -146,7 +146,7 @@ static void test_frame_buffer(screen_info_t *si) pixel_value.word = (r_value << si->red_pos) | (g_value << si->green_pos) | (b_value << si->blue_pos); uintptr_t lfb_base = si->lfb_base; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (LFB_CAPABILITY_64BIT_BASE & si->capabilities) { lfb_base |= (uintptr_t)si->ext_lfb_base << 32; } @@ -489,7 +489,7 @@ static efi_status_t set_screen_info_from_gop(screen_info_t *si, efi_handle_t *ha si->lfb_width = best_info.h_resolution; si->lfb_height = best_info.v_resolution; si->lfb_base = lfb_base; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (lfb_base >> 32) { si->capabilities |= LFB_CAPABILITY_64BIT_BASE; si->ext_lfb_base = lfb_base >> 32; @@ -669,7 +669,7 @@ static efi_status_t set_efi_info_and_exit_boot_services(efi_handle_t handle, boo goto fail; } -#ifdef __x86_64 +#if (ARCH_BITS == 64) boot_params->efi_info.loader_signature = EFI64_LOADER_SIGNATURE; #else boot_params->efi_info.loader_signature = EFI32_LOADER_SIGNATURE; @@ -679,7 +679,7 @@ static efi_status_t set_efi_info_and_exit_boot_services(efi_handle_t handle, boo boot_params->efi_info.mem_desc_version = mem_desc_version; boot_params->efi_info.mem_map = (uintptr_t)mem_map; boot_params->efi_info.mem_map_size = mem_map_size; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) boot_params->efi_info.sys_tab_hi = (uintptr_t)sys_table >> 32; boot_params->efi_info.mem_map_hi = (uintptr_t)mem_map >> 32; #endif @@ -691,7 +691,7 @@ fail: static void set_e820_map(boot_params_t *params) { uintptr_t mem_map_addr = params->efi_info.mem_map; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) mem_map_addr |= (uintptr_t)params->efi_info.mem_map_hi << 32; #endif size_t mem_map_size = params->efi_info.mem_map_size; diff --git a/build32/Makefile b/build32/Makefile index 3033a05..1eb8e1a 100644 --- a/build32/Makefile +++ b/build32/Makefile @@ -11,7 +11,7 @@ else endif CFLAGS = -std=gnu11 -Wall -Wextra -Wshadow -m32 -march=i586 -fpic -fno-builtin \ - -ffreestanding -fomit-frame-pointer -fno-stack-protector + -ffreestanding -fomit-frame-pointer -fno-stack-protector -DARCH_BITS=32 ifeq ($(DEBUG), 1) CFLAGS+=-ggdb3 -DDEBUG_GDB diff --git a/build64/Makefile b/build64/Makefile index 8e2d259..5e68266 100644 --- a/build64/Makefile +++ b/build64/Makefile @@ -11,7 +11,8 @@ else endif CFLAGS = -std=gnu11 -Wall -Wextra -Wshadow -m64 -march=x86-64 -mno-mmx -mno-sse -mno-sse2 \ - -fpic -fno-builtin -ffreestanding -fomit-frame-pointer -fno-stack-protector + -fpic -fno-builtin -ffreestanding -fomit-frame-pointer -fno-stack-protector \ + -DARCH_BITS=64 ifeq ($(DEBUG), 1) CFLAGS+=-ggdb3 -DDEBUG_GDB diff --git a/system/acpi.c b/system/acpi.c index d81e29e..8abe930 100644 --- a/system/acpi.c +++ b/system/acpi.c @@ -100,7 +100,7 @@ static rsdp_t *scan_for_rsdp(uintptr_t addr, int length) return NULL; } -#ifdef __x86_64__ +#if (ARCH_BITS == 64) static rsdp_t *find_rsdp_in_efi64_system_table(efi64_system_table_t *system_table) { efi64_config_table_t *config_tables = (efi64_config_table_t *)map_region(system_table->config_tables, @@ -150,7 +150,7 @@ static uintptr_t find_rsdp(void) // Search for the RSDP rsdp_t *rp = NULL; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (efi_info->loader_signature == EFI64_LOADER_SIGNATURE) { uintptr_t system_table_addr = (uintptr_t)efi_info->sys_tab_hi << 32 | (uintptr_t)efi_info->sys_tab; system_table_addr = map_region(system_table_addr, sizeof(efi64_system_table_t), true); @@ -279,7 +279,7 @@ static bool parse_fadt(uintptr_t fadt_addr) acpi_config.pm_addr = *(uint32_t *)(fadt_addr+FADT_PM_TMR_BLK_OFFSET); acpi_config.pm_is_io = true; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) acpi_gen_addr_struct *rt; // Get APIC Timer Address diff --git a/system/hwctrl.c b/system/hwctrl.c index 945df87..f04da50 100644 --- a/system/hwctrl.c +++ b/system/hwctrl.c @@ -33,7 +33,7 @@ static efi_runtime_services_t *efi_rs_table = NULL; void hwctrl_init(void) { boot_params_t *boot_params = (boot_params_t *)boot_params_addr; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (boot_params->efi_info.loader_signature == EFI64_LOADER_SIGNATURE) { uintptr_t system_table_addr = (uintptr_t)boot_params->efi_info.sys_tab_hi << 32 | boot_params->efi_info.sys_tab; if (system_table_addr != 0) { diff --git a/system/screen.c b/system/screen.c index 914f17d..b12026a 100644 --- a/system/screen.c +++ b/system/screen.c @@ -306,7 +306,7 @@ void screen_init(void) } lfb_base = screen_info->lfb_base; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (LFB_CAPABILITY_64BIT_BASE & screen_info->capabilities) { lfb_base |= (uintptr_t)screen_info->ext_lfb_base << 32; } diff --git a/system/smbios.c b/system/smbios.c index 5b5d5b1..c42813a 100644 --- a/system/smbios.c +++ b/system/smbios.c @@ -42,7 +42,7 @@ static char *get_tstruct_string(struct tstruct_header *header, uint16_t maxlen, return NULL; } -#ifdef __x86_64__ +#if (ARCH_BITS == 64) static smbiosv2_t *find_smbiosv2_in_efi64_system_table(efi64_system_table_t *system_table) { efi64_config_table_t *config_tables = (efi64_config_table_t *) map_region(system_table->config_tables, system_table->num_config_tables * sizeof(efi64_config_table_t), true); @@ -90,7 +90,7 @@ static uintptr_t find_smbiosv2_adr(void) } } } -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (rp == NULL && efi_info -> loader_signature == EFI64_LOADER_SIGNATURE) { // EFI64 if (rp == NULL && efi_info->loader_signature == EFI64_LOADER_SIGNATURE) { diff --git a/system/usbhcd.c b/system/usbhcd.c index 159b443..9afaf46 100644 --- a/system/usbhcd.c +++ b/system/usbhcd.c @@ -424,7 +424,7 @@ static void reset_usb_controller(hci_info_t *hci) uintptr_t mmio_size = pci_config_read32(bus, dev, func, bar); pci_config_write32(bus, dev, func, bar, base_addr); bool in_io_space = base_addr & 0x1; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) if (!in_io_space && (base_addr & 0x4)) { base_addr += (uintptr_t)pci_config_read32(bus, dev, func, bar + 4) << 32; pci_config_write32(bus, dev, func, bar + 4, 0xffffffff); diff --git a/tests/own_addr.c b/tests/own_addr.c index 8462aaf..612c1cd 100644 --- a/tests/own_addr.c +++ b/tests/own_addr.c @@ -135,7 +135,7 @@ int test_own_addr2(int my_cpu, int stage) // Calculate the offset (in pages) between the virtual address and the physical address. offset = (vm_map[0].pm_base_addr / VM_WINDOW_SIZE) * VM_WINDOW_SIZE; offset = (offset >= VM_PINNED_SIZE) ? offset - VM_PINNED_SIZE : 0; -#ifdef __x86_64__ +#if (ARCH_BITS == 64) // Convert to a byte address offset. This will translate the virtual address into a physical address. offset *= PAGE_SIZE; #else diff --git a/tests/test_helper.h b/tests/test_helper.h index 6dba727..f3ecbf3 100644 --- a/tests/test_helper.h +++ b/tests/test_helper.h @@ -20,7 +20,7 @@ * Test word atomic read and write functions. */ #include "memrw.h" -#ifdef __x86_64__ +#if (ARCH_BITS == 64) #define read_word read64 #define write_word write64 #else @@ -73,7 +73,7 @@ static inline uintptr_t round_up(uintptr_t value, size_t align_size) static inline testword_t prsg(testword_t state) { // This uses the algorithms described at https://en.wikipedia.org/wiki/Xorshift -#ifdef __x86_64__ +#if (ARCH_BITS == 64) state ^= state << 13; state ^= state >> 7; state ^= state << 17;