Skip to content

Commit 7067923

Browse files
feat: Copilot review fixes, AGENTS.md docs, coding standards, and test improvements (#194)
* refactor(main): use make_unique for test task creation Replace raw new TaskControlBlock with sk_std::make_unique and .release() before passing to AddTask. Ensures exception-safe construction while maintaining AddTask's raw pointer interface. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add etl Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add etl Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(plans): add ETL migration plan Add comprehensive ETL migration plan (Tasks 0-10) for replacing sk_std:: containers with ETL-backed kstd:: wrappers. Remove superseded unique_ptr design/implementation docs. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(build): integrate ETL library into kernel build Add etl::etl to kernel link libraries in compile_config.cmake. Add etl_profile.h with ETL_CPP23_SUPPORTED and ETL_NO_CHECKS defines. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(libcxx): add kstd container wrappers for ETL Add kstd namespace wrappers around ETL containers: - kstd_pool.hpp: Pool<T,N> and PoolRef type aliases - kstd_vector: vector, static_vector, ivector - kstd_list: list, static_list, list_node_t - kstd_unique_ptr: custom unique_ptr implementation - kstd_priority_queue: reference-based priority queue - kstd_unordered_map: pool-backed unordered_map with std::hash Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(libcxx): convert sk_std headers to kstd shims Replace sk_std:: implementations with thin forwarding shims to kstd:: namespace. sk_vector, sk_list, sk_unique_ptr, sk_priority_queue, and sk_unordered_map now delegate to ETL-backed kstd wrappers. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): migrate task subsystem to kstd containers Replace sk_std:: containers with kstd:: static containers in schedulers and task manager. Use static_vector, static_list, and static_unordered_map with compile-time sizes. Mark scheduler copy/move as deleted since ETL containers with internal storage are not copyable. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore(libcxx): remove unused sk_std implementations Delete sk_shared_ptr, sk_set, sk_rb_tree, and sk_queue which have no remaining consumers after the ETL migration. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore(tests): remove tests for deleted sk_std containers Remove unit and system tests for sk_queue, sk_rb_tree, sk_set, and sk_shared_ptr. Update test CMakeLists.txt and system_test registration to reflect 22 remaining test cases. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: kstd Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: ut Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore: add .worktrees to gitignore Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(aarch64): remove unused io.hpp include from interrupt files Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(aarch64/gic): migrate io::In/Out to etl::io_port in GIC Read/Write helpers Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(x86_64/apic): migrate io::In/Out to etl::io_port in IoApic::Read/Write Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(x86_64/apic): migrate io::In/Out to etl::io_port in LocalApic xAPIC branches Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device/virtio): migrate io::In to etl::io_port_ro in VirtioBlkDriver::Probe Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(include): delete io.hpp after full etl::io_port migration Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(apic/virtio): use void* cast in etl::io_port_* constructors Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(aarch64/gic): use void* cast in etl::io_port_* constructors Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(task): add kernel_config.hpp for centralized capacity constants Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(task): add etl::hash specialization for ResourceId Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): replace kstd::static_list with etl::list in FifoScheduler Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): replace kstd::static_list with etl::list in RoundRobinScheduler Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): replace kstd priority_queue+storage with etl::priority_queue in CfsScheduler Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): replace kstd containers with etl:: in TaskManager and CpuSchedData Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): update GetThreadGroup return type to etl::vector Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(task): add .full() checks before all etl container insertions Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): remove dead kstd_vector includes after etl migration Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(task): provide explicit etl::vector container type for sleeping_tasks priority_queue Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update include styler Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: update cmake Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: add math.h, waiting for c++26 Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: etl plans Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: replace sk_assert with assert Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: kstd Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: update unique_ptr Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: migrate Singleton<T> to etl::singleton<T> named aliases Replace custom Singleton<T> with etl::singleton<T> using per-type named aliases (e.g. BasicInfoSingleton, TaskManagerSingleton) defined centrally in kernel.h. Delete singleton.hpp. Update all call sites from Singleton<T>::GetInstance() to TypeSingleton::instance() and assignment-construction to TypeSingleton::create(). Update all documentation references. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(arch): move arch-specific singletons out of kernel.h and make interrupt controllers Interrupt members Move arch-specific singleton type aliases from shared kernel.h into per-arch directories, and convert interrupt controller singletons (PlicSingleton, ApicSingleton) into private members of each arch's Interrupt class, following the existing aarch64 pattern where Gic is already an Interrupt member. - Move Pl011Singleton to src/arch/aarch64/include/pl011_singleton.h - Move SerialSingleton to file-local scope in x86_64/early_console.cpp - Move Ns16550aSingleton to file-local scope in riscv64/interrupt_main.cpp - Add Plic plic_ member to riscv64 Interrupt with InitPlic() deferred init - Add Apic apic_ member to x86_64 Interrupt with InitApic() deferred init - Move APIC creation from ArchInit() to InterruptInit() (boot order fix) - Remove arch-specific #includes and #ifdefs from kernel.h Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(arch): remove static from Interrupt handler arrays Since Interrupt is used as etl::singleton (only one instance), static class members are semantically equivalent to non-static members. Remove static to eliminate the need for out-of-class definitions in .cpp files. - aarch64: interrupt_handlers -> interrupt_handlers_ (non-static member) - riscv64: interrupt_handlers_, exception_handlers_ (drop static + defs) - x86_64: interrupt_handlers_, idts_ (drop static + defs, keep alignas) The alignas(4096) on x86_64 members propagates correctly through etl::singleton via uninitialized_buffer_of<T> which uses alignas(etl::alignment_of<T>::value) on its storage. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add cpu_io Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(arch): move arch-specific singletons from kernel.h to arch directories Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: string Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: string Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: klog Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: io_buffer Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * doc: update AGENT.md Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * doc(etl): add ETL integration migration design plan Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(libc): wrap noexcept in __cplusplus guard for C compilation Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(task): add ETL message and router ID registry Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): replace CloneFlags enum and cpu_affinity with etl::flags Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(interrupt): replace InterruptFunc pointer with etl::delegate Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): replace TaskStatus enum with etl::fsm state machine Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(task): address code quality review findings for etl::fsm migration - C1: Add ReapTask(current) for orphan tasks in Exit() to prevent TCB leak - C2: Start FSM after default-constructing TCB in Clone() to avoid null deref - I2: Use STATE_ID constant in StateExited::on_event(MsgReap) - I3: Move GetStatus() implementation from header to .cpp file - I4: Enqueue idle task in kReady state, then transition to kRunning - M2: Restore dropped @todo SIGCHLD comment in exit.cpp - M5: Add [[nodiscard]] attribute to GetStatus() Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(kernel): add tick and panic observer interfaces using etl::observer Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(kernel): add lifecycle and virtio message types for etl::message_router Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(plans): add ETL migration implementation plan Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: task_fsm Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: InterruptDelegate Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update include style Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: fsm Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: task_control_block Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * test: fix st Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore(docs): remove superseded etl-migration plan files Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(expected): add VirtIO/device error codes for device_framework unification Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add platform_config.hpp concrete impl for device_framework injection Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * build(device): use BEFORE in TARGET_INCLUDE_DIRECTORIES for platform_config override Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device_node): replace atomic<bool> with SpinLock-guarded bool, remove hand-rolled copy/move Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(df_bridge): remove DeviceStorage and ToKernelError, error types now unified Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(driver_registry): add etl::flat_map index for O(log N) platform driver lookup Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(virtio_blk_driver): remove Traits template param, use unified error and Storage types Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): remove PlatformTraits template usage, unify error handling Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(arch/riscv64): remove PlatformTraits template param from VirtioBlkDriver usage Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(device): add kMaxSpinIterations to PlatformTraits; use TryBind() in DeviceManager::ProbeAll() Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore(submodule): bump device_framework to merged main (440bfe7) device_framework feature/device-refactor merged into main: - Traits template elimination via platform_config.hpp injection - Unified error handling (PlatformErrorCode) - Storage<T> freestanding optional added - All tests updated for non-template API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): delete placeholder and redundant header files Inline PlatformTraits struct into platform_config.hpp and delete the now-redundant platform_traits.hpp. Also delete zero-caller stubs: acpi_bus.hpp, pci_bus.hpp, virtio_messages.hpp. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): simplify device module — remove Driver concept and variant types Replace template Register<D>() + Driver concept with plain DriverEntry function-pointer struct. Flatten DeviceNode to pure data (remove variant BusId, DeviceResource, DMA buffer, SpinLock). Move DMA allocation into VirtioBlkDriver::Probe(). Delete df_bridge.hpp; introduce mmio_helper.hpp. Net: ~1149 -> ~570 lines (~50% reduction), 13 -> 8 headers. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(arch/riscv64,device): update interrupt_main and virtio_blk_driver for new driver API - Replace DriverRegistry::GetDriverInstance<VirtioBlkDriver>() with VirtioBlkDriver::Instance() in interrupt_main.cpp (lines 100, 209) - Remove unused #include "driver_registry.hpp" from interrupt_main.cpp - Add missing #include "io_buffer.hpp" to virtio_blk_driver.hpp - Fix kstd::unique_ptr<IoBuffer> -> etl::unique_ptr<IoBuffer> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(device): add device_framework integration design doc Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore(device): create driver/ subdirectory skeleton Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add traits.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add ops/device_ops_base.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add ops/char_device.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add ops/block_device_ops.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/mmio_accessor.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/storage.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/uart_device.hpp inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/ns16550a/ inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/pl011/ inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/virtio/defs.h + traits.hpp (task 11) Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/virtio/transport/ (task 12) Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/virtio/virt_queue/ inlined from device_framework (task 13) Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/virtio/device/ inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add detail/acpi/ inlined from device_framework Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add pl011/acpi facade headers and update driver includes to inline headers Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(arch): replace device_framework includes with inlined driver headers Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * build: remove device_framework from CMake and .gitmodules Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * chore(device): remove device_framework submodule and platform_config.hpp hack Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(device): add platform_config.hpp for inlined VirtIO driver and fix unit-test CMake link Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: apply clang-format to VirtIO device and transport headers Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: remove plan Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): replace raw array+ptr with etl::vector/flat_map in DriverRegistry Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): migrate Ns16550aDriver to etl::delegate, remove DriverDescriptor Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): migrate VirtioBlkDriver to etl::optional + etl::delegate Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): delete detail/storage.hpp, superseded by etl::optional Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(device): update AGENTS.md for ETL refactor Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(device): fix duplicate section in AGENTS.md Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: add device module refactor design document Add design doc for src/device/ refactoring: - Delete ~1000 lines of dead ops/ CRTP layer - Replace VirtioBlkDriver with unified virtio::Probe() interface - Runtime transport/device-type detection via std::variant - Preserve detail/virtio/ structure for multi-device extensibility Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): extract VirtioBlkVfsAdapter to dedicated header Move VirtioBlkBlockDevice class (renamed VirtioBlkVfsAdapter) out of device.cpp into its own header. No functional change. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * test(device): add failing tests for VirtioDriver Tests expect VirtioDriver::GetEntry() and MatchStatic() which will be implemented in the next task (TDD). Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add unified VirtioDriver with runtime device-type dispatch Replace VirtioBlkDriver with VirtioDriver that auto-detects VirtIO device type (blk/net/gpu/...) at runtime by reading device_id register. Caller (DeviceInit) no longer needs to know about VirtIO device types. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * build(device): add virtio_driver.cpp to device library sources Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): update DeviceInit to use unified VirtioDriver Replace VirtioBlkDriver::GetEntry() with VirtioDriver::GetEntry(). DeviceInit no longer mentions specific VirtIO device types. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): ns16550a_driver include ns16550a.hpp directly Remove dependency on ns16550a_device.hpp (CRTP wrapper, to be deleted). Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): pl011_driver include pl011.hpp directly Remove dependency on pl011_device.hpp (CRTP wrapper, to be deleted). Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): delete dead ops/ CRTP layer and unused device wrappers Remove ~1000 lines of dead code: - driver/ops/ (device_ops_base.hpp, char_device.hpp, block_device_ops.hpp) - driver/detail/uart_device.hpp - driver/detail/ns16550a/ns16550a_device.hpp - driver/detail/pl011/pl011_device.hpp - driver/detail/virtio/device/virtio_blk_device.hpp - driver/virtio_blk_driver.hpp (replaced by virtio_driver.hpp) Also add GetIrq()/HandleInterrupt() to VirtioDriver and update riscv64/interrupt_main.cpp to use VirtioDriver + Ns16550a directly. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(device): update AGENTS.md for new VirtioDriver architecture - Document virtio_driver.cpp as the second .cpp exception - Add VirtIO device extension guide (add device_id case only) - Remove references to deleted ops/ layer and virtio_blk_driver Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): restructure drivers into per-driver subdirectories - Each driver (ns16550a, pl011, acpi, virtio) now lives in its own subdirectory with an independent ADD_LIBRARY(xxx_driver INTERFACE) CMake target - Delete detail/ directory; headers moved directly into driver subdirectories (ns16550a/, pl011/, acpi/, virtio/) - device target changed from INTERFACE to STATIC with PRIVATE driver dependencies; consumers access hardware only through DeviceManager - device CMakeLists: use explicit compile-only deps instead of kernel_link_libraries to avoid leaking -nostdlib/-T link.ld into unit-test link command - Fix aarch64: add Pl011Device alias, HandleInterrupt stub, remove stale Open() call in early_console.cpp - Fix virtio traits.hpp: change self-referential include to ../traits.hpp - Arch code links driver targets explicitly as a documented exception - All three arch builds and 163 unit tests pass Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device,fdt): add ForEachDeviceNode filter and split device_manager - kernel_fdt.hpp: add ForEachDeviceNode() inline template that skips infrastructure nodes (interrupt-controller, #clock-cells, cpu, memory device_type) to suppress spurious 'no driver' log noise - device_manager.hpp: extract ProbeAll/FindDevice/FindDevicesByType to device_manager.cpp; keep RegisterBus<B> template in header - device_manager.cpp: implement the three methods with assert-based precondition checks and ProbeAll no_driver_count summary log - virtio: fix missing newlines in klog::Debug format strings - doc/plans: add design doc and implementation plan Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): assert-harden mmio_helper and use ForEachDeviceNode - driver_registry.hpp: replace mmio_base==0 error return in mmio_helper::Prepare with assert() — bad node is a driver bug, not a recoverable runtime condition; add #include <cassert> - platform_bus.hpp: switch Enumerate to fdt_.ForEachDeviceNode so infrastructure nodes (interrupt-controller, clock, cpu, memory) are skipped before driver matching, eliminating 'no driver' noise Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(virtio): reorganize device/ into per-type subdirectories Move virtio_blk.hpp, virtio_blk_defs.h, virtio_blk_vfs_adapter.hpp into device/blk/, and placeholder headers into console/, net/, gpu/, input/. Update all include paths and header guards accordingly. device_initializer.hpp stays at device/ root as it is cross-device. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(virtio): modernize VirtioBlk with std::array Replace raw C arrays slots_[kMaxInflight] with std::array<RequestSlot, kMaxInflight> and local IoVec[] with std::array<IoVec, kMaxSgElements> in DoEnqueue(). Replace static kNames[] with constexpr std::array<const char*, 4> in GetName(). Also zero-initialize slot_bitmap_ explicitly with {}. Note: std::bitset was evaluated but omitted — std::bitset<N>::to_ulong() references exception machinery (__throw_out_of_range_fmt) in GCC 14's libstdc++, which is incompatible with this freestanding kernel build. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: update cpu_io Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: mmio_accessor Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(arch/riscv64): add etl_putchar shim for ETL print support Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(arch/aarch64): add etl_putchar shim for ETL print support Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(arch/x86_64): add etl_putchar shim for ETL print support Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): migrate klog calls to ETL format syntax Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(task): migrate klog calls to ETL format syntax Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(arch): migrate klog calls to ETL format syntax Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(src): migrate klog calls to ETL format syntax Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(klog): rewrite kernel_log.hpp with type-safe {} format syntax - Replace printf-style %s/%d format strings with {}-based syntax - Add KernelFmtStr<Args...> + KernelFormatString alias with type_identity_t for correct CTAD (mirrors std::format_string pattern) - Add FormatArg() overloads for freestanding-safe single-arg printing - Add LogFormat() recursive walker for format string processing - Keep stream-style API (klog::info <<) unchanged - Add ETL_FORCE_STD_INITIALIZER_LIST to prevent ETL/stdlib collision when ETL_NO_STL is set in freestanding mode - Migrate clone.cpp and syscall.cpp to {} syntax - Verified clean build on riscv64, aarch64, x86_64 Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(libc): remove nanoprintf, replace sk_printf with emit helpers - Delete sk_printf/sk_snprintf/sk_vsnprintf API from sk_stdio.h and sk_stdio.c - Add four __always_inline emit helpers: sk_emit_str, sk_emit_sint, sk_emit_uint, sk_emit_hex - Migrate kernel_log.hpp, spinlock.hpp, kstd_iostream.cpp, kstd_libcxx.cpp, schedule.cpp, syscall.cpp to emit helpers - Replace BmallocLogger with empty no-op implementation - Remove nanoprintf git submodule and CMake integration - cmake-lint skipped: pre-existing cmakelang internal crash (upstream bug) Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: update cpu_io Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(libc): replace sk_putchar with etl_putchar Remove the sk_putchar function pointer (and its unused ctx parameter). etl_putchar(int c) — already defined per-arch in early_console.cpp — becomes the sole low-level output primitive. - Delete sk_stdio.c (contained only dummy_putchar + sk_putchar) - Remove sk_stdio.c from libc CMakeLists - sk_stdio.h declares etl_putchar; sk_emit_* helpers call it directly - riscv64/early_console: drop EarlyConsole struct (SBI always ready) - aarch64/x86_64 early_console: collapse console_putchar into etl_putchar - Replace all sk_putchar(c, nullptr) -> etl_putchar(c) across 8 files Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(klog): simplify kernel_log — 8 complexity fixes - Support {:x}/{:#x}/{:X}/{:#X} format specifiers for integers - Unify type printing: operator<< delegates to FormatArg - Extract EmitHeader<Level>() to eliminate duplicated prefix code - Remove redundant if constexpr level checks in struct constructors - Replace throw with non-constexpr call in consteval context (freestanding safe) - Fix DebugBlob: use if constexpr only, remove #ifdef SIMPLEKERNEL_DEBUG - Rename LogStarter -> LogStream for clarity - Add auto-newline in LogEmit/~LogLine, strip trailing backslash n from all call sites (63 files: src/**/*.cpp, src/**/*.hpp, tests/**/*.cpp) Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: replace nanoprintf with etl Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: remove plans Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: remove kstd::ostream Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: sk_print_str Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: replace __attribute__ with [[xxx]] Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: replace __attribute__ with [[xxx]] Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: backtrace Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: virtio Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): unify driver singletons to etl::singleton Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: remove etl docs Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(device): resolve singleton alias forward-reference in GetEntry() Replace XxxSingleton::instance() with etl::singleton<Xxx>::instance() inside GetEntry() where the type alias is not yet declared. Affects Pl011Driver, Ns16550aDriver, and VirtioDriver. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(device): add DmaRegion type and IoBuffer::ToDmaRegion() Introduce DmaRegion{virt, phys, size} value type, VirtToPhysFunc callback, and IdentityVirtToPhys default in io_buffer.hpp. Add ToDmaRegion() to IoBuffer for converting buffers to DMA-ready regions. Includes 8 GoogleTest unit tests and implementation plan. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(device): replace void* DMA with DmaRegion + VirtToPhys abstraction Refactor SplitVirtqueue, VirtioBlk, and VirtioDriver to use DmaRegion instead of raw void*/uintptr_t pairs. VirtioBlk::Create() now accepts separate vq_dma and slot_dma regions with a VirtToPhysFunc callback, eliminating hardcoded identity-mapping assumptions. RequestSlot memory is allocated from a dedicated DMA buffer for device-accessible physical addresses. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: sk_print_str Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: device Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat(log): add per-CPU lock-free LogLineRaw/LogStreamRaw interfaces Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(arch): use lock-free klog::raw_err in DumpStack to prevent deadlock Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: klog Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: klog Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor: klog Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add stb and EasyLogger Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add stb and EasyLogger Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add stb and EasyLogger Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: add stb and EasyLogger Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs(log): add MPMC log refactor design and implementation plan Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): rewrite kernel_log.hpp with MPMC lock-free queue Replace SpinLock-based stream logging with Vyukov lock-free MPMC queue. New API: klog::Info/Warn/Err/Debug (printf-style), klog::Flush, klog::RawPut. Remove: LogLine, LogLineRaw, LogStream, LogStreamRaw, DebugBlob, klog::hex/HEX. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/main.cpp to new klog API Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/arch/x86_64/ to new klog API Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/arch/riscv64/ to new klog API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/arch/aarch64/ to new klog API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/memory/ to new klog API Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai> Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/device/ to new klog API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/task/ to new klog API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate src/filesystem/ to new klog API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): migrate remaining headers and syscall to new klog API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * refactor(log): update commented-out klog calls in spinlock.hpp to new API Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(log): replace __always_inline with inline on variadic klog functions GCC cannot inline functions using variable argument lists (...). Change Debug(), Info(), Warn(), Err() from __always_inline to inline. Flush() and RawPut() remain __always_inline as they are non-variadic. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(log): add missing cpu_io.h include for GetCurrentCoreId kernel_log.hpp uses cpu_io::GetCurrentCoreId() but did not include the header, causing 'cpu_io has not been declared' build errors. Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: mpsc log Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: etl format Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: etl format Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: log with core id Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: log with core id Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * feat: working on smp Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: update etl Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * 3rd: update etl Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: add boot_task Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: move TimerInit to main Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: move TimerInit to main Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * doc: update AGENTS.md Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: use pragma once Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style(arch,filesystem,memory): update headers to coding standards - Add trailing return types, [[nodiscard]], @brief, brace init, constructor groups - Arch: interrupt.h (riscv64/aarch64/x86_64), plic.h, gic.h, apic.h, io_apic.h, local_apic.h, sipi.h - Filesystem: file_descriptor.hpp, vfs.hpp, vfs_types.hpp, mount.hpp, vfs_internal.hpp, ramfs.hpp, fatfs.hpp - Memory: virtual_memory.hpp - Build verified on riscv64 and x86_64 Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: use trailing return types in .cpp and arch.h Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: update AGENTS.md Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * test: fix st Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * style: update Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * test: fix st Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * test: fix st Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * test: fix st Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * docs: update AGENTS.md Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix: warnning Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> * fix(multi): address Copilot review findings across IO APIC, VFS, device, and DMA - io_apic: add early return after OOB IRQ check in SetIrqRedirection/MaskIrq/UnmaskIrq - mkdir: add NUL-termination after strncpy on dentry name - lookup: replace broken mount-point loop with FindByMountDentry - file_descriptor: fix open_count_ over-counting in SetupStandardFiles - io_buffer: fix size_t overflow in SubRegion bounds check - open/mkdir: reject path components exceeding buffer sizes - file_descriptor: use address-based lock ordering in move-assignment - virtio_driver: pass slot_align to IoBuffer for consistency - diskio: add nullptr guard for buff in disk_ioctl Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> --------- Signed-off-by: Niu Zhihong <zhihong@nzhnb.com> Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent fab4dba commit 7067923

0 file changed

File tree

    0 commit comments

    Comments
     (0)