From: Tulio A M Mendes Date: Sat, 7 Feb 2026 15:50:34 +0000 (-0300) Subject: refactor: rename arch_start to arch_early_setup X-Git-Url: https://projects.tadryanom.me/?a=commitdiff_plain;h=535511f23e320ad0c19a3803cf68b08bb6555c96;p=AdrOS.git refactor: rename arch_start to arch_early_setup --- diff --git a/README.md b/README.md index 018a03e1..f7ab93e8 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ QEMU debug helpers: ## TODO - **Multi-architecture kernel bring-up** - Implement VMM/interrupts/scheduler for ARM/RISC-V/MIPS - - Standardize arch entrypoint behavior (`arch_start`) across architectures + - Standardize arch entrypoint behavior (`arch_early_setup`) across architectures - **Userspace** - Process model (fork/exec/wait), per-process address spaces, and cleanup on `exit` - Syscall ABI expansion (read/open/close, file descriptors, etc.) diff --git a/include/arch/arch_early_setup.h b/include/arch/arch_early_setup.h new file mode 100644 index 00000000..5893e89e --- /dev/null +++ b/include/arch/arch_early_setup.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A M Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + + #ifndef ARCH_EARLY_SETUP_H + #define ARCH_EARLY_SETUP_H + + #include "arch/arch_boot_args.h" + + void arch_early_setup(const struct arch_boot_args* args); + + #endif diff --git a/include/arch/arch_start.h b/include/arch/arch_start.h deleted file mode 100644 index faa317ff..00000000 --- a/include/arch/arch_start.h +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * All rights reserved. - * See LICENSE for details. - * - * Source: https://github.com/tadryanom/AdrOS - */ - -#ifndef ARCH_START_H -#define ARCH_START_H - -#include "arch/arch_boot_args.h" - -void arch_start(const struct arch_boot_args* args); - -#endif diff --git a/src/arch/arm/arch_early_setup.c b/src/arch/arm/arch_early_setup.c new file mode 100644 index 00000000..2e64e9ee --- /dev/null +++ b/src/arch/arm/arch_early_setup.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A M Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + + #include "arch/arch_early_setup.h" +#include "kernel/boot_info.h" + +#include "uart_console.h" + +extern void kernel_main(const struct boot_info* bi); + + void arch_early_setup(const struct arch_boot_args* args) { + (void)args; + + uart_init(); + uart_print("\n[AdrOS] Booting...\n"); + + struct boot_info bi; + bi.arch_magic = 0; + bi.arch_boot_info = 0; + bi.initrd_start = 0; + bi.initrd_end = 0; + bi.cmdline = NULL; + + kernel_main(&bi); + + for(;;) { + __asm__ volatile("wfi"); + } +} diff --git a/src/arch/arm/arch_start.c b/src/arch/arm/arch_start.c deleted file mode 100644 index aa62eddc..00000000 --- a/src/arch/arm/arch_start.c +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * All rights reserved. - * See LICENSE for details. - * - * Source: https://github.com/tadryanom/AdrOS - */ - -#include "arch/arch_start.h" -#include "kernel/boot_info.h" - -#include "uart_console.h" - -extern void kernel_main(const struct boot_info* bi); - -void arch_start(const struct arch_boot_args* args) { - (void)args; - - uart_init(); - uart_print("\n[AdrOS] Booting...\n"); - - struct boot_info bi; - bi.arch_magic = 0; - bi.arch_boot_info = 0; - bi.initrd_start = 0; - bi.initrd_end = 0; - bi.cmdline = NULL; - - kernel_main(&bi); - - for(;;) { - __asm__ volatile("wfi"); - } -} diff --git a/src/arch/arm/boot.S b/src/arch/arm/boot.S index 80516894..4f1f5440 100644 --- a/src/arch/arm/boot.S +++ b/src/arch/arm/boot.S @@ -26,9 +26,9 @@ _start: ldr x0, =stack_top mov sp, x0 - /* Build arch_boot_args (in .bss) and call arch_start(args) */ + /* Build arch_boot_args (in .bss) and call arch_early_setup(args) */ ldr x0, =arch_boot_args - bl arch_start + bl arch_early_setup /* Hang */ 1: wfi diff --git a/src/arch/mips/arch_early_setup.c b/src/arch/mips/arch_early_setup.c new file mode 100644 index 00000000..6518b319 --- /dev/null +++ b/src/arch/mips/arch_early_setup.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A M Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + + #include "arch/arch_early_setup.h" +#include "kernel/boot_info.h" + +#include "uart_console.h" + +extern void kernel_main(const struct boot_info* bi); + + void arch_early_setup(const struct arch_boot_args* args) { + (void)args; + + uart_init(); + uart_print("\n[AdrOS] Booting...\n"); + + struct boot_info bi; + bi.arch_magic = 0; + bi.arch_boot_info = 0; + bi.initrd_start = 0; + bi.initrd_end = 0; + bi.cmdline = NULL; + + kernel_main(&bi); + + for(;;) { + __asm__ volatile("nop"); + } +} diff --git a/src/arch/mips/arch_start.c b/src/arch/mips/arch_start.c deleted file mode 100644 index 12e940d9..00000000 --- a/src/arch/mips/arch_start.c +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * All rights reserved. - * See LICENSE for details. - * - * Source: https://github.com/tadryanom/AdrOS - */ - -#include "arch/arch_start.h" -#include "kernel/boot_info.h" - -#include "uart_console.h" - -extern void kernel_main(const struct boot_info* bi); - -void arch_start(const struct arch_boot_args* args) { - (void)args; - - uart_init(); - uart_print("\n[AdrOS] Booting...\n"); - - struct boot_info bi; - bi.arch_magic = 0; - bi.arch_boot_info = 0; - bi.initrd_start = 0; - bi.initrd_end = 0; - bi.cmdline = NULL; - - kernel_main(&bi); - - for(;;) { - __asm__ volatile("nop"); - } -} diff --git a/src/arch/mips/boot.S b/src/arch/mips/boot.S index f4086b8f..d7bc85b3 100644 --- a/src/arch/mips/boot.S +++ b/src/arch/mips/boot.S @@ -22,14 +22,14 @@ _start: la $sp, stack_top - /* Build arch_boot_args (in .bss) and call arch_start(args) */ + /* Build arch_boot_args (in .bss) and call arch_early_setup(args) */ la $a0, arch_boot_args sw $zero, 0($a0) sw $zero, 4($a0) sw $zero, 8($a0) sw $zero, 12($a0) - jal arch_start + jal arch_early_setup nop 1: diff --git a/src/arch/riscv/arch_early_setup.c b/src/arch/riscv/arch_early_setup.c new file mode 100644 index 00000000..2e64e9ee --- /dev/null +++ b/src/arch/riscv/arch_early_setup.c @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A M Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + + #include "arch/arch_early_setup.h" +#include "kernel/boot_info.h" + +#include "uart_console.h" + +extern void kernel_main(const struct boot_info* bi); + + void arch_early_setup(const struct arch_boot_args* args) { + (void)args; + + uart_init(); + uart_print("\n[AdrOS] Booting...\n"); + + struct boot_info bi; + bi.arch_magic = 0; + bi.arch_boot_info = 0; + bi.initrd_start = 0; + bi.initrd_end = 0; + bi.cmdline = NULL; + + kernel_main(&bi); + + for(;;) { + __asm__ volatile("wfi"); + } +} diff --git a/src/arch/riscv/arch_start.c b/src/arch/riscv/arch_start.c deleted file mode 100644 index aa62eddc..00000000 --- a/src/arch/riscv/arch_start.c +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * All rights reserved. - * See LICENSE for details. - * - * Source: https://github.com/tadryanom/AdrOS - */ - -#include "arch/arch_start.h" -#include "kernel/boot_info.h" - -#include "uart_console.h" - -extern void kernel_main(const struct boot_info* bi); - -void arch_start(const struct arch_boot_args* args) { - (void)args; - - uart_init(); - uart_print("\n[AdrOS] Booting...\n"); - - struct boot_info bi; - bi.arch_magic = 0; - bi.arch_boot_info = 0; - bi.initrd_start = 0; - bi.initrd_end = 0; - bi.cmdline = NULL; - - kernel_main(&bi); - - for(;;) { - __asm__ volatile("wfi"); - } -} diff --git a/src/arch/riscv/boot.S b/src/arch/riscv/boot.S index 2097b985..1c4c5a4f 100644 --- a/src/arch/riscv/boot.S +++ b/src/arch/riscv/boot.S @@ -24,9 +24,9 @@ _start: */ la sp, stack_top - /* Build arch_boot_args (in .bss) and call arch_start(args) */ + /* Build arch_boot_args (in .bss) and call arch_early_setup(args) */ la a0, arch_boot_args - call arch_start + call arch_early_setup /* Hang if return */ 1: wfi diff --git a/src/arch/x86/arch_early_setup.c b/src/arch/x86/arch_early_setup.c new file mode 100644 index 00000000..5d169802 --- /dev/null +++ b/src/arch/x86/arch_early_setup.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: BSD-3-Clause +/* + * Copyright (c) 2018, Tulio A M Mendes + * All rights reserved. + * See LICENSE for details. + * + * Source: https://github.com/tadryanom/AdrOS + */ + + #include "arch/arch_early_setup.h" + +#include "kernel/boot_info.h" + +#include "gdt.h" +#include "idt.h" +#include "uart_console.h" + +#include "multiboot2.h" + +extern void kernel_main(const struct boot_info* bi); + +static uint8_t multiboot_copy[65536]; +static uint32_t multiboot_copy_size; + + void arch_early_setup(const struct arch_boot_args* args) { + uart_init(); + uart_print("\n[AdrOS] Booting...\n"); + + uint32_t magic = (uint32_t)(args ? args->a0 : 0); + uintptr_t mbi_phys = (uintptr_t)(args ? args->a1 : 0); + + if (magic != 0x36d76289) { + uart_print("[ERR] Invalid Multiboot2 Magic!\n"); + } else { + uart_print("[OK] Multiboot2 Magic Confirmed.\n"); + } + + uart_print("[AdrOS] Initializing GDT/TSS...\n"); + gdt_init(); + + uart_print("[AdrOS] Initializing IDT...\n"); + idt_init(); + + struct boot_info bi; + bi.arch_magic = magic; + bi.arch_boot_info = 0; + bi.initrd_start = 0; + bi.initrd_end = 0; + bi.cmdline = NULL; + + if (mbi_phys) { + uint32_t total_size = *(volatile uint32_t*)mbi_phys; + if (total_size >= 8) { + multiboot_copy_size = total_size; + if (multiboot_copy_size > sizeof(multiboot_copy)) { + uart_print("[WARN] Multiboot2 info too large, truncating copy.\n"); + multiboot_copy_size = sizeof(multiboot_copy); + } + + for (uint32_t i = 0; i < multiboot_copy_size; i++) { + multiboot_copy[i] = *(volatile uint8_t*)(mbi_phys + i); + } + bi.arch_boot_info = (uintptr_t)multiboot_copy; + } + } + + if (bi.arch_boot_info) { + struct multiboot_tag* tag; + for (tag = (struct multiboot_tag*)((uint8_t*)bi.arch_boot_info + 8); + tag->type != MULTIBOOT_TAG_TYPE_END; + tag = (struct multiboot_tag*)((uint8_t*)tag + ((tag->size + 7) & ~7))) { + if (tag->type == MULTIBOOT_TAG_TYPE_MODULE) { + struct multiboot_tag_module* mod = (struct multiboot_tag_module*)tag; + bi.initrd_start = mod->mod_start; + bi.initrd_end = mod->mod_end; + break; + } + if (tag->type == MULTIBOOT_TAG_TYPE_CMDLINE) { + struct multiboot_tag_string* s = (struct multiboot_tag_string*)tag; + bi.cmdline = s->string; + } + } + } + + kernel_main(&bi); + + for(;;) { + __asm__ volatile("hlt"); + } +} diff --git a/src/arch/x86/arch_start.c b/src/arch/x86/arch_start.c deleted file mode 100644 index eade7ce3..00000000 --- a/src/arch/x86/arch_start.c +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause -/* - * Copyright (c) 2018, Tulio A M Mendes - * All rights reserved. - * See LICENSE for details. - * - * Source: https://github.com/tadryanom/AdrOS - */ - -#include "arch/arch_start.h" - -#include "kernel/boot_info.h" - -#include "gdt.h" -#include "idt.h" -#include "uart_console.h" - -#include "multiboot2.h" - -extern void kernel_main(const struct boot_info* bi); - -static uint8_t multiboot_copy[65536]; -static uint32_t multiboot_copy_size; - -void arch_start(const struct arch_boot_args* args) { - uart_init(); - uart_print("\n[AdrOS] Booting...\n"); - - uint32_t magic = (uint32_t)(args ? args->a0 : 0); - uintptr_t mbi_phys = (uintptr_t)(args ? args->a1 : 0); - - if (magic != 0x36d76289) { - uart_print("[ERR] Invalid Multiboot2 Magic!\n"); - } else { - uart_print("[OK] Multiboot2 Magic Confirmed.\n"); - } - - uart_print("[AdrOS] Initializing GDT/TSS...\n"); - gdt_init(); - - uart_print("[AdrOS] Initializing IDT...\n"); - idt_init(); - - struct boot_info bi; - bi.arch_magic = magic; - bi.arch_boot_info = 0; - bi.initrd_start = 0; - bi.initrd_end = 0; - bi.cmdline = NULL; - - if (mbi_phys) { - uint32_t total_size = *(volatile uint32_t*)mbi_phys; - if (total_size >= 8) { - multiboot_copy_size = total_size; - if (multiboot_copy_size > sizeof(multiboot_copy)) { - uart_print("[WARN] Multiboot2 info too large, truncating copy.\n"); - multiboot_copy_size = sizeof(multiboot_copy); - } - - for (uint32_t i = 0; i < multiboot_copy_size; i++) { - multiboot_copy[i] = *(volatile uint8_t*)(mbi_phys + i); - } - bi.arch_boot_info = (uintptr_t)multiboot_copy; - } - } - - if (bi.arch_boot_info) { - struct multiboot_tag* tag; - for (tag = (struct multiboot_tag*)((uint8_t*)bi.arch_boot_info + 8); - tag->type != MULTIBOOT_TAG_TYPE_END; - tag = (struct multiboot_tag*)((uint8_t*)tag + ((tag->size + 7) & ~7))) { - if (tag->type == MULTIBOOT_TAG_TYPE_MODULE) { - struct multiboot_tag_module* mod = (struct multiboot_tag_module*)tag; - bi.initrd_start = mod->mod_start; - bi.initrd_end = mod->mod_end; - break; - } - if (tag->type == MULTIBOOT_TAG_TYPE_CMDLINE) { - struct multiboot_tag_string* s = (struct multiboot_tag_string*)tag; - bi.cmdline = s->string; - } - } - } - - kernel_main(&bi); - - for(;;) { - __asm__ volatile("hlt"); - } -} diff --git a/src/arch/x86/boot.S b/src/arch/x86/boot.S index e9e7b548..f57b5222 100644 --- a/src/arch/x86/boot.S +++ b/src/arch/x86/boot.S @@ -71,7 +71,7 @@ _start: /* * Map 0-16MB using 4 page tables. - * With Multiboot2 info copied in arch_start and initrd mapped via VMM, + * With Multiboot2 info copied in arch_early_setup and initrd mapped via VMM, * we only need a small identity window for early bring-up. */ @@ -162,7 +162,7 @@ higher_half_start: pop %ebx /* EBX now has the Multiboot Info address */ pop %eax /* EAX now has the Magic Number */ - /* Build arch_boot_args (in .bss) and call arch_start(args) */ + /* Build arch_boot_args (in .bss) and call arch_early_setup(args) */ mov $arch_boot_args, %ecx mov %eax, 0(%ecx) /* args->a0 = multiboot magic */ mov %ebx, 4(%ecx) /* args->a1 = multiboot info phys */ @@ -170,7 +170,7 @@ higher_half_start: movl $0, 12(%ecx) /* args->a3 = 0 */ push %ecx - call arch_start + call arch_early_setup add $4, %esp /* Hang */