| 1 |
# Pactor64 — Raspberry Pi 5 ARM64 Port TODO |
| 2 |
|
| 3 |
## Phase 2: Interrupts + Timer (GIC-400 + ARM Generic Timer) |
| 4 |
|
| 5 |
- [ ] Create `kernel/gic.c` + `kernel/gic.h` |
| 6 |
- [ ] GIC-400 distributor init (GICD_CTLR at 0xFF841000) |
| 7 |
- [ ] GIC-400 CPU interface init (GICC_CTLR at 0xFF842000) |
| 8 |
- [ ] Enable specific IRQs (timer = IRQ 27/30, UART = IRQ 33) |
| 9 |
- [ ] IRQ acknowledge + EOI functions |
| 10 |
- [ ] Create `kernel/timer.c` + `kernel/timer.h` |
| 11 |
- [ ] Read CNTFRQ_EL0 (timer frequency, ~54MHz on Pi 5) |
| 12 |
- [ ] Configure CNTP_TVAL_EL0 for 100Hz tick |
| 13 |
- [ ] Enable timer via CNTP_CTL_EL0 |
| 14 |
- [ ] Timer IRQ handler (PPI 14, IRQ 30 on GIC) |
| 15 |
- [ ] `timer_ticks` counter, `uptime` command |
| 16 |
- [ ] Create `kernel/vectors.S` |
| 17 |
- [ ] Exception vector table (16 entries × 128 bytes) |
| 18 |
- [ ] Sync handler (for SVC, data abort, instruction abort) |
| 19 |
- [ ] IRQ handler (save/restore all registers X0-X30) |
| 20 |
- [ ] FIQ / SError stubs |
| 21 |
- [ ] Set VBAR_EL1 to vector table address |
| 22 |
- [ ] Update `kernel/entry.S` |
| 23 |
- [ ] Configure SCR_EL3 (if running from EL3) |
| 24 |
- [ ] Set VBAR_EL1 |
| 25 |
- [ ] Enable IRQ routing (DAIF.I = 0) |
| 26 |
- [ ] Configure GIC + timer before kernel_main |
| 27 |
- [ ] Update `kernel/main.c` |
| 28 |
- [ ] Add `ticks` command |
| 29 |
- [ ] Add `uptime` command |
| 30 |
- [ ] Timer ISR increments counter |
| 31 |
- [ ] Test on Pi 5: timer ticks increment, uptime works |
| 32 |
|
| 33 |
## Phase 3: Memory Management (MMU + Translation Tables) |
| 34 |
|
| 35 |
- [ ] Create `kernel/mmu.c` + `kernel/mmu.h` |
| 36 |
- [ ] Parse firmware memory map (ATAGS or DTB at x0) |
| 37 |
- [ ] Create translation tables for TTBR1_EL1 (kernel space) |
| 38 |
- [ ] Identity-map kernel region (0x80000, 2MB block) |
| 39 |
- [ ] Map peripheral MMIO region (0xFE000000+) |
| 40 |
- [ ] Map GIC region (0xFF840000+) |
| 41 |
- [ ] Configure MAIR_EL1 (memory attributes) |
| 42 |
- [ ] Configure TCR_EL1 (granule size, VA range) |
| 43 |
- [ ] Enable MMU (SCTLR_EL1.M = 1) |
| 44 |
- [ ] Create `kernel/pmm.c` + `kernel/pmm.h` |
| 45 |
- [ ] Bitmap-based physical page allocator |
| 46 |
- [ ] Parse DTB/ATAGS for available memory regions |
| 47 |
- [ ] `pmm_alloc_page()` / `pmm_free_page()` |
| 48 |
- [ ] Create `kernel/heap.c` or integrate into main |
| 49 |
- [ ] Simple bump allocator or free-list allocator |
| 50 |
- [ ] `kmalloc()` / `kfree()` |
| 51 |
- [ ] Test: malloc works, memory info command |
| 52 |
|
| 53 |
## Phase 4: Syscalls + Userspace (EL0) |
| 54 |
|
| 55 |
- [ ] Create `kernel/syscall.c` + `kernel/syscall.h` |
| 56 |
- [ ] SVC handler (read ESR_EL1 for SVC number from X8) |
| 57 |
- [ ] Syscall dispatch table (Linux ARM64 compatible numbers) |
| 58 |
- [ ] Implement: sys_write(64), sys_read(63), sys_exit(93), sys_brk(214) |
| 59 |
- [ ] Create `kernel/syscall_entry.S` |
| 60 |
- [ ] SVC entry: save all registers (X0-X30, SP_EL0, SPSR_EL1, ELR_EL1) |
| 61 |
- [ ] Switch to kernel stack (from SP_EL1) |
| 62 |
- [ ] Call syscall_dispatch |
| 63 |
- [ ] Restore registers + ERET to EL0 |
| 64 |
- [ ] Create `kernel/elf.c` (port from x86-64) |
| 65 |
- [ ] ELF64 header validation (AArch64 machine type) |
| 66 |
- [ ] Load PT_LOAD segments |
| 67 |
- [ ] Return entry point |
| 68 |
- [ ] Create userspace entry (`libc/start.S`) |
| 69 |
- [ ] `_start` at EL0, set up user stack, call main |
| 70 |
- [ ] SVC #0 for syscalls |
| 71 |
- [ ] Port `libc/start.c` (printf, malloc, strings) |
| 72 |
- [ ] Replace x86 `syscall` instruction with ARM `svc #0` |
| 73 |
- [ ] Use X8 for syscall number (Linux ARM64 ABI) |
| 74 |
- [ ] Create `userspace.ld` (load at 0x400000) |
| 75 |
- [ ] Cross-compile hello.elf for AArch64 |
| 76 |
- [ ] Test: hello.elf runs in EL0, prints via SVC |
| 77 |
|
| 78 |
## Phase 5: Storage + Filesystem + Applications |
| 79 |
|
| 80 |
- [ ] Create `kernel/emmc.c` + `kernel/emmc.h` |
| 81 |
- [ ] EMMC2 controller driver (BCM2712 SD card interface) |
| 82 |
- [ ] Initialize SD card (CMD0, CMD8, ACMD41, CMD2, CMD3, CMD7, CMD17) |
| 83 |
- [ ] Read sectors (single + multi-block) |
| 84 |
- [ ] Write sectors |
| 85 |
- [ ] Integrate ext2 filesystem (port from x86-64) |
| 86 |
- [ ] Connect ext2 block_read callback to EMMC driver |
| 87 |
- [ ] Mount SD card partition |
| 88 |
- [ ] Read files from ext2 |
| 89 |
- [ ] Create `mkcard.sh` |
| 90 |
- [ ] Create FAT32 boot partition (firmware + kernel) |
| 91 |
- [ ] Create ext2 data partition (applications) |
| 92 |
- [ ] Copy firmware files + kernel8.img + config.txt |
| 93 |
- [ ] Port ELF loader to load from filesystem |
| 94 |
- [ ] `load <filename>` command |
| 95 |
- [ ] `execute <filename>` command |
| 96 |
- [ ] Recompile applications for AArch64 |
| 97 |
- [ ] fibonacci.c, primes.c, ascii.c, matrix.c, guess.c, sort.c |
| 98 |
- [ ] hello.elf |
| 99 |
- [ ] Update Makefile cross-compilation targets |
| 100 |
- [ ] Build embedded application registry (same as x86-64) |
| 101 |
- [ ] Test: execute fibonacci on Pi 5 |
| 102 |
|
| 103 |
## Phase 6: Embedded Features |
| 104 |
|
| 105 |
- [ ] GPIO driver (`kernel/gpio.c`) |
| 106 |
- [ ] GPIO function select (FSEL registers) |
| 107 |
- [ ] GPIO set/clear/read |
| 108 |
- [ ] LED blink test |
| 109 |
- [ ] Button input |
| 110 |
- [ ] I2C driver (`kernel/i2c.c`) |
| 111 |
- [ ] BSC (Broadcom Serial Controller) at 0xFE804000 (I2C1) |
| 112 |
- [ ] Init, start, stop, read, write |
| 113 |
- [ ] Sensor reading (e.g., BME280 temperature/humidity) |
| 114 |
- [ ] SPI driver (`kernel/spi.c`) |
| 115 |
- [ ] BCM2712 SPI master |
| 116 |
- [ ] Init, transfer |
| 117 |
- [ ] Framebuffer (`kernel/fb.c`) |
| 118 |
- [ ] Mailbox interface to VideoCore GPU (0xFE00B880) |
| 119 |
- [ ] Allocate framebuffer via mailbox property tags |
| 120 |
- [ ] Pixel drawing, basic text rendering |
| 121 |
- [ ] Replace serial-only output with HDMI display |
| 122 |
- [ ] Network (`kernel/net.c`) |
| 123 |
- [ ] Ethernet via PCIe/USB (Pi 5 uses different NIC than Pi 4) |
| 124 |
- [ ] Or USB CDC Ethernet for simpler approach |
| 125 |
- [ ] PWM (`kernel/pwm.c`) |
| 126 |
- [ ] Servo/motor control |
| 127 |
- [ ] Audio output |
| 128 |
- [ ] Watchdog (`kernel/watchdog.c`) |
| 129 |
- [ ] Hardware watchdog timer |
| 130 |
- [ ] System reset on hang |
| 131 |
|
| 132 |
## Cross-Cutting Tasks |
| 133 |
|
| 134 |
- [ ] Add regression test framework (same pattern as x86-64) |
| 135 |
- [ ] Add memory protection (page permissions for EL0 vs EL1) |
| 136 |
- [ ] Add SMP support (bring up cores 1-3) |
| 137 |
- [ ] Add spinlocks / mutexes for multi-core |
| 138 |
- [ ] Add DMA support for fast SD card / peripheral transfers |
| 139 |
- [ ] Power management (clock gating, sleep states) |
| 140 |
- [ ] Documentation: hardware register map, boot sequence, API reference |
| 141 |
- [ ] Create CI/build script for automated testing |
| 142 |
|