From 12ada9cd1e1005aca411afc01e5f3119bdb18332 Mon Sep 17 00:00:00 2001 From: Ghostboo124 Date: Fri, 27 Jun 2025 14:52:13 +1000 Subject: [PATCH 1/4] Ensure that the same C standard is used across all builds C17 has been chosen because C23 has the `bool` as a reserved keyword, but bool has been defined in shared/types.h causing errors. --- kernel/Makefile | 2 +- shared/Makefile | 2 +- user/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 5471cb91..db95c26a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -3,7 +3,7 @@ CC = $(ARCH)-gcc LD = $(ARCH)-ld OBJCOPY = $(ARCH)-objcopy -CFLAGS = -g -O0 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -I../user +CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -I../user LDFLAGS = -T $(shell ls *.ld) C_SRC = $(shell find . -name '*.c') diff --git a/shared/Makefile b/shared/Makefile index 7f3ebf38..fb7390db 100644 --- a/shared/Makefile +++ b/shared/Makefile @@ -3,7 +3,7 @@ CC = $(ARCH)-gcc AR = $(ARCH)-ar OBJCOPY = $(ARCH)-objcopy -CFLAGS = -g -O0 -nostdlib -nolibc -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../kernel -Wno-unused-parameter +CFLAGS = -g -O0 -std=c17 -nostdlib -nolibc -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wall -Wextra -mcpu=cortex-a72 -I. -I../kernel -Wno-unused-parameter C_SRC = $(shell find . -name '*.c') CPP_SRC = $(shell find . -name '*.cpp') diff --git a/user/Makefile b/user/Makefile index 48042a7d..fb6b8328 100644 --- a/user/Makefile +++ b/user/Makefile @@ -3,7 +3,7 @@ CC = $(ARCH)-gcc LD = $(ARCH)-ld OBJCOPY = $(ARCH)-objcopy -CFLAGS = -g -O0 -nostdlib -ffreestanding -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -Wno-unused-parameter +CFLAGS = -g -O0 -std=c17 -nostdlib -ffreestanding -Wall -Wextra -mcpu=cortex-a72 -I. -I../shared -Wno-unused-parameter LDFLAGS = -T $(shell ls *.ld) C_SRC = $(shell find . -name '*.c') From a966568a64ef5ff5039e54b8a11bd2b0499902a7 Mon Sep 17 00:00:00 2001 From: Ghostboo124 Date: Fri, 27 Jun 2025 15:18:17 +1000 Subject: [PATCH 2/4] Support for compilers without asm keyword --- kernel/exceptions/exception_handler.c | 4 ++++ kernel/exceptions/irq.c | 4 ++++ kernel/exceptions/timer.c | 4 ++++ kernel/fw/fw_cfg.c | 5 +++++ kernel/memory/mmu.c | 4 ++++ kernel/process/syscall.c | 4 ++++ kernel/virtio/virtio_pci.c | 4 ++++ 7 files changed, 29 insertions(+) diff --git a/kernel/exceptions/exception_handler.c b/kernel/exceptions/exception_handler.c index 3f34039b..712b9e66 100644 --- a/kernel/exceptions/exception_handler.c +++ b/kernel/exceptions/exception_handler.c @@ -8,6 +8,10 @@ #include "theme/theme.h" #include "std/string.h" +#ifndef asm +#define asm __asm__ +#endif + static bool panic_triggered = false; void set_exception_vectors(){ diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index 08d3d56c..3ee71331 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -8,6 +8,10 @@ #include "console/serial/uart.h" #include "networking/network.h" +#ifndef asm +#define asm __asm__ +#endif + #define IRQ_TIMER 30 #define SLEEP_TIMER 27 diff --git a/kernel/exceptions/timer.c b/kernel/exceptions/timer.c index 413a0aa5..3756450b 100644 --- a/kernel/exceptions/timer.c +++ b/kernel/exceptions/timer.c @@ -1,5 +1,9 @@ #include "timer.h" +#ifndef asm +#define asm __asm__ +#endif + static uint64_t _msecs; void timer_reset() { diff --git a/kernel/fw/fw_cfg.c b/kernel/fw/fw_cfg.c index 8b730c8d..3a360cd6 100644 --- a/kernel/fw/fw_cfg.c +++ b/kernel/fw/fw_cfg.c @@ -3,6 +3,10 @@ #include "memory/memory_access.h" #include "kstring.h" +#ifndef asm +#define asm __asm__ +#endif + #define FW_CFG_DATA 0x09020000 #define FW_CFG_CTL (FW_CFG_DATA + 0x8) #define FW_CFG_DMA (FW_CFG_DATA + 0x10) @@ -14,6 +18,7 @@ #define FW_LIST_DIRECTORY 0x19 + static bool checked = false; struct fw_cfg_dma_access { diff --git a/kernel/memory/mmu.c b/kernel/memory/mmu.c index 69274b1e..6a33a4a0 100644 --- a/kernel/memory/mmu.c +++ b/kernel/memory/mmu.c @@ -8,6 +8,10 @@ #include "filesystem/disk.h" #include "memory/page_allocator.h" +#ifndef asm +#define asm __asm__ +#endif + #define MAIR_DEVICE_nGnRnE 0b00000000 #define MAIR_NORMAL_NOCACHE 0b01000100 #define MAIR_IDX_DEVICE 0 diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index 540f3e6a..1e2e8bb0 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -14,6 +14,10 @@ #include "exceptions/timer.h" #include "networking/network.h" +#ifndef asm +#define asm __asm__ +#endif + void sync_el0_handler_c(){ save_context_registers(); save_return_address_interrupt(); diff --git a/kernel/virtio/virtio_pci.c b/kernel/virtio/virtio_pci.c index a7a11ddb..799497db 100644 --- a/kernel/virtio/virtio_pci.c +++ b/kernel/virtio/virtio_pci.c @@ -4,6 +4,10 @@ #include "memory/page_allocator.h" #include "virtio_pci.h" +#ifndef asm +#define asm __asm__ +#endif + #define VIRTIO_STATUS_RESET 0x0 #define VIRTIO_STATUS_ACKNOWLEDGE 0x1 #define VIRTIO_STATUS_DRIVER 0x2 From 6b24c85284919a3b6057708a894469519462ae71 Mon Sep 17 00:00:00 2001 From: Ghostboo124 Date: Fri, 27 Jun 2025 15:31:55 +1000 Subject: [PATCH 3/4] Fixing run script Fixing the shebang to be #!/ instead of #/! Multiplatform support for qemu networking as vmnet-bridged is a MacOS only feature --- run | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/run b/run index 5dc8ca7a..26e3bfd4 100755 --- a/run +++ b/run @@ -1,4 +1,4 @@ -#/!bin/sh +#!/bin/sh echo "Running emulator" @@ -15,19 +15,33 @@ if echo "$XHCI_CAPABILITIES" | grep -q "msi "; then MSI_CAPABILITIES="msi=on,msix=off," fi +OS_TYPE="$(uname)" + +if [[ "$OS_TYPE" == "Darwin" ]]; then + NETARG="vmnet-bridged,id=net0,ifname=en0" + +elif [[ "$OS_TYPE" == "Linux" ]]; then + NETARG="user,id=net0" + +else + echo "Unknown OS: $OS_TYPE" >&2 + exit 1 +fi + + qemu-system-aarch64 \ --M virt \ --cpu cortex-a72 \ --m 512M \ --kernel kernel.elf \ --device virtio-gpu-pci \ --display sdl \ --netdev vmnet-bridged,id=net0,ifname=en0 \ --device virtio-net-pci,netdev=net0 \ --serial mon:stdio \ --drive file=disk.img,if=none,format=raw,id=hd0 \ --device virtio-blk-pci,drive=hd0 \ --device qemu-xhci,${MSI_CAPABILITIES}id=usb \ --device usb-kbd,bus=usb.0 \ --d guest_errors \ -$ARGS + -M virt \ + -cpu cortex-a72 \ + -m 512M \ + -kernel kernel.elf \ + -device virtio-gpu-pci \ + -display sdl \ + -netdev ${NETARG} \ + -device virtio-net-pci,netdev=net0 \ + -serial mon:stdio \ + -drive file=disk.img,if=none,format=raw,id=hd0 \ + -device virtio-blk-pci,drive=hd0 \ + -device qemu-xhci,${MSI_CAPABILITIES}id=usb \ + -device usb-kbd,bus=usb.0 \ + -d guest_errors \ + $ARGS From 9cabe02d539a07904888c6eb1329deaa8ad586f8 Mon Sep 17 00:00:00 2001 From: Ghostboo124 Date: Sat, 28 Jun 2025 08:19:38 +1000 Subject: [PATCH 4/4] Moving the asm fix to shared/types.h --- kernel/exceptions/irq.c | 4 ---- kernel/exceptions/timer.c | 4 ---- kernel/fw/fw_cfg.c | 4 ---- kernel/memory/mmu.c | 4 ---- kernel/process/syscall.c | 4 ---- kernel/virtio/virtio_pci.c | 4 ---- shared/types.h | 6 ++++++ 7 files changed, 6 insertions(+), 24 deletions(-) diff --git a/kernel/exceptions/irq.c b/kernel/exceptions/irq.c index 3ee71331..08d3d56c 100644 --- a/kernel/exceptions/irq.c +++ b/kernel/exceptions/irq.c @@ -8,10 +8,6 @@ #include "console/serial/uart.h" #include "networking/network.h" -#ifndef asm -#define asm __asm__ -#endif - #define IRQ_TIMER 30 #define SLEEP_TIMER 27 diff --git a/kernel/exceptions/timer.c b/kernel/exceptions/timer.c index 3756450b..413a0aa5 100644 --- a/kernel/exceptions/timer.c +++ b/kernel/exceptions/timer.c @@ -1,9 +1,5 @@ #include "timer.h" -#ifndef asm -#define asm __asm__ -#endif - static uint64_t _msecs; void timer_reset() { diff --git a/kernel/fw/fw_cfg.c b/kernel/fw/fw_cfg.c index 3a360cd6..6a29dd9a 100644 --- a/kernel/fw/fw_cfg.c +++ b/kernel/fw/fw_cfg.c @@ -3,10 +3,6 @@ #include "memory/memory_access.h" #include "kstring.h" -#ifndef asm -#define asm __asm__ -#endif - #define FW_CFG_DATA 0x09020000 #define FW_CFG_CTL (FW_CFG_DATA + 0x8) #define FW_CFG_DMA (FW_CFG_DATA + 0x10) diff --git a/kernel/memory/mmu.c b/kernel/memory/mmu.c index 6a33a4a0..69274b1e 100644 --- a/kernel/memory/mmu.c +++ b/kernel/memory/mmu.c @@ -8,10 +8,6 @@ #include "filesystem/disk.h" #include "memory/page_allocator.h" -#ifndef asm -#define asm __asm__ -#endif - #define MAIR_DEVICE_nGnRnE 0b00000000 #define MAIR_NORMAL_NOCACHE 0b01000100 #define MAIR_IDX_DEVICE 0 diff --git a/kernel/process/syscall.c b/kernel/process/syscall.c index 1e2e8bb0..540f3e6a 100644 --- a/kernel/process/syscall.c +++ b/kernel/process/syscall.c @@ -14,10 +14,6 @@ #include "exceptions/timer.h" #include "networking/network.h" -#ifndef asm -#define asm __asm__ -#endif - void sync_el0_handler_c(){ save_context_registers(); save_return_address_interrupt(); diff --git a/kernel/virtio/virtio_pci.c b/kernel/virtio/virtio_pci.c index 799497db..a7a11ddb 100644 --- a/kernel/virtio/virtio_pci.c +++ b/kernel/virtio/virtio_pci.c @@ -4,10 +4,6 @@ #include "memory/page_allocator.h" #include "virtio_pci.h" -#ifndef asm -#define asm __asm__ -#endif - #define VIRTIO_STATUS_RESET 0x0 #define VIRTIO_STATUS_ACKNOWLEDGE 0x1 #define VIRTIO_STATUS_DRIVER 0x2 diff --git a/shared/types.h b/shared/types.h index 0b58af56..0b6dc865 100644 --- a/shared/types.h +++ b/shared/types.h @@ -1,9 +1,15 @@ #pragma once +#ifndef asm +#define asm __asm__ +#endif + #ifdef __cplusplus extern "C" { #endif + + typedef unsigned int uint32_t; typedef long unsigned int size_t; typedef unsigned long uint64_t;