Add support for a new CPU architecture to AlJefra OS
You need:
mkdir -p arch/<arch_name>/
Create these files, implementing all HAL functions:
| File | Purpose | Key Functions |
|---|---|---|
boot.S |
Assembly entry point | CPU mode setup, stack init, BSS clear, call hal_init |
cpu.c |
CPU operations | hal_cpu_init, hal_cpu_halt, hal_cpu_cycles |
interrupt.c |
Interrupt controller | hal_irq_init, hal_irq_register, hal_irq_eoi |
timer.c |
System timer | hal_timer_init, hal_timer_ns, hal_timer_delay_us |
io.c |
Port I/O + DMA | hal_port_in/out (can be no-ops), hal_dma_alloc |
bus.c |
Device discovery | hal_bus_scan, hal_bus_pci_read32 |
mmu.c |
Page tables | hal_mmu_init, hal_mmu_map, hal_mmu_alloc_pages |
smp.c |
Multi-core | hal_smp_init, hal_smp_start_core, hal_spin_lock |
console.c |
UART output | hal_console_init, hal_console_putc, hal_console_printf |
hal_init.c |
Master init | hal_init() calls all sub-inits in order |
linker.ld |
Memory layout | .text, .rodata, .data, .bss sections |
The boot stub must:
hal_init()kernel_main()Example structure:
.section .text.entry
.global _start
_start:
/* Architecture-specific CPU setup */
/* Set stack pointer */
/* Zero BSS */
/* Call hal_init */
/* Call kernel_main */
/* Infinite halt loop */
Edit Makefile:
ifeq ($(ARCH),new_arch)
CC = new_arch-elf-gcc
AS = new_arch-elf-as
LD = new_arch-elf-ld
ARCH_DIR = arch/new_arch
CFLAGS += -march=...
endif
make ARCH=new_arch
qemu-system-new_arch -machine virt -kernel kernel.bin -serial stdio -nographic
Expected output:
==============================================
AlJefra OS — Universal Boot
Architecture: NewArch
CPU: ...
Cores: 1
RAM: 256 MB
==============================================
[kernel] Scanning buses...
[kernel] Found N devices
...
Test each HAL subsystem:
Each architecture has different memory ordering. Make sure hal_mmio_barrier() uses the correct fence instruction.
DMA buffers may need cache invalidation/flush on non-x86 architectures. Use appropriate barriers.
All HAL structures use little-endian. ARM and RISC-V can be big-endian; ensure your port runs in LE mode.
Some architectures fault on unaligned access. Packed structs in drivers may need alignment wrappers.
Identity mapping simplifies things but may not be possible with all firmware. Document any address translation.
| Feature | Implementation |
|---|---|
| Entry | UEFI or flat binary at 0x40000000 |
| CPU mode | EL1, AArch64, LE |
| MMU | TTBR0_EL1, 4KB granule, 48-bit VA |
| Interrupts | GICv2 (GICD + GICC) or GICv3 |
| Timer | CNTVCT_EL0, CNTFRQ_EL0 |
| SMP | PSCI CPU_ON via SMC/HVC |
| UART | PL011 (QEMU virt: 0x09000000) |
| Barrier | DMB ISH / DSB SY |
| Feature | Implementation |
|---|---|
| Entry | SBI hands off at 0x80000000, DTB in a1 |
| CPU mode | S-mode (supervisor) |
| MMU | Sv48 page tables |
| Interrupts | PLIC (0x0C000000) + CLINT (0x02000000) |
| Timer | rdtime CSR, timebase from DTB |
| SMP | SBI HSM hart_start |
| UART | 16550 (QEMU virt: 0x10000000) or SBI console |
| Barrier | FENCE instruction |