From 6bff37746dfd81a7426be45dbc0a847fb33fbd77 Mon Sep 17 00:00:00 2001 From: Maksymilian Wilczynski Date: Thu, 28 May 2026 18:53:37 +0200 Subject: [PATCH] major restructuring, prepare for smp --- OVMF/OVMF_VARS_4M_d.fd | Bin 540672 -> 540672 bytes build.bat | 100 +-- code/boot.ini | 2 +- code/boot/{ => uefi}/efilib.lib | Bin code/boot/{ => uefi}/efilib.pdb | Bin code/boot/{ => uefi}/include/Makefile | 0 .../boot/{ => uefi}/include/aarch64/efibind.h | 0 .../{ => uefi}/include/aarch64/efilibplat.h | 0 .../include/aarch64/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/arm/efibind.h | 0 code/boot/{ => uefi}/include/arm/efilibplat.h | 0 .../{ => uefi}/include/arm/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/efi.h | 0 code/boot/{ => uefi}/include/efi_nii.h | 0 code/boot/{ => uefi}/include/efi_pxe.h | 0 code/boot/{ => uefi}/include/efiapi.h | 0 code/boot/{ => uefi}/include/eficompiler.h | 0 code/boot/{ => uefi}/include/eficon.h | 0 code/boot/{ => uefi}/include/eficonex.h | 0 code/boot/{ => uefi}/include/efidebug.h | 0 code/boot/{ => uefi}/include/efidef.h | 0 code/boot/{ => uefi}/include/efidevp.h | 0 code/boot/{ => uefi}/include/efierr.h | 0 code/boot/{ => uefi}/include/efifs.h | 0 code/boot/{ => uefi}/include/efigpt.h | 0 code/boot/{ => uefi}/include/efiip.h | 0 code/boot/{ => uefi}/include/efilib.h | 0 code/boot/{ => uefi}/include/efilink.h | 0 code/boot/{ => uefi}/include/efinet.h | 0 code/boot/{ => uefi}/include/efipart.h | 0 code/boot/{ => uefi}/include/efipciio.h | 0 code/boot/{ => uefi}/include/efipoint.h | 0 code/boot/{ => uefi}/include/efiprot.h | 0 code/boot/{ => uefi}/include/efipxebc.h | 0 code/boot/{ => uefi}/include/efirtlib.h | 0 code/boot/{ => uefi}/include/efiser.h | 0 code/boot/{ => uefi}/include/efisetjmp.h | 0 code/boot/{ => uefi}/include/efishell.h | 0 code/boot/{ => uefi}/include/efishellintf.h | 0 code/boot/{ => uefi}/include/efistdarg.h | 0 code/boot/{ => uefi}/include/efitcp.h | 0 code/boot/{ => uefi}/include/efiudp.h | 0 code/boot/{ => uefi}/include/efiui.h | 0 code/boot/{ => uefi}/include/ia32/efibind.h | 0 .../boot/{ => uefi}/include/ia32/efilibplat.h | 0 .../{ => uefi}/include/ia32/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/ia32/pe.h | 0 code/boot/{ => uefi}/include/ia64/efibind.h | 0 .../boot/{ => uefi}/include/ia64/efilibplat.h | 0 .../{ => uefi}/include/ia64/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/ia64/pe.h | 0 code/boot/{ => uefi}/include/ia64/salproc.h | 0 code/boot/{ => uefi}/include/inc.mak | 0 code/boot/{ => uefi}/include/legacy.h | 0 code/boot/{ => uefi}/include/lib.h | 0 code/boot/{ => uefi}/include/libsmbios.h | 0 .../{ => uefi}/include/loongarch64/efibind.h | 0 .../include/loongarch64/efilibplat.h | 0 .../include/loongarch64/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/make.inf | 0 code/boot/{ => uefi}/include/makefile.hdr | 0 .../{ => uefi}/include/mips64el/efibind.h | 0 .../{ => uefi}/include/mips64el/efilibplat.h | 0 .../include/mips64el/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/pci22.h | 0 .../include/protocol/adapterdebug.h | 0 .../{ => uefi}/include/protocol/eficonsplit.h | 0 .../boot/{ => uefi}/include/protocol/efidbg.h | 0 .../boot/{ => uefi}/include/protocol/efivar.h | 0 .../include/protocol/ia64/eficontext.h | 0 .../{ => uefi}/include/protocol/intload.h | 0 .../{ => uefi}/include/protocol/legacyboot.h | 0 .../boot/{ => uefi}/include/protocol/make.inf | 0 .../{ => uefi}/include/protocol/makefile.hdr | 0 .../{ => uefi}/include/protocol/piflash64.h | 0 .../{ => uefi}/include/protocol/readme.txt | 0 .../{ => uefi}/include/protocol/vgaclass.h | 0 .../boot/{ => uefi}/include/riscv64/efibind.h | 0 .../{ => uefi}/include/riscv64/efilibplat.h | 0 .../include/riscv64/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/romload.h | 0 code/boot/{ => uefi}/include/x86_64/efibind.h | 0 .../{ => uefi}/include/x86_64/efilibplat.h | 0 .../include/x86_64/efisetjmp_arch.h | 0 code/boot/{ => uefi}/include/x86_64/pe.h | 0 code/boot/{ => uefi}/main.c | 32 +- .../include/common}/ini_parser.h | 0 .../include/common}/printf.h | 0 code/{ => common}/ini_parser.c | 106 ++-- code/{ => common}/libc.c | 0 code/{ => common}/printf.c | 4 +- code/drivers/{ => bus}/usb/usb.c | 18 +- code/drivers/{ => fs}/fat32/fat32.c | 18 +- code/drivers/{ => net}/lwip/README.md | 0 .../{ => net}/lwip/include/arch/bpstruct.h | 0 code/drivers/{ => net}/lwip/include/arch/cc.h | 2 +- .../{ => net}/lwip/include/arch/epstruct.h | 0 .../{ => net}/lwip/include/arch/sys_arch.h | 0 .../drivers/{ => net}/lwip/include/lwipopts.h | 0 code/drivers/{ => net}/lwip/include/stdlib.h | 0 code/drivers/{ => net}/lwip/lwip_sources.txt | 6 +- code/drivers/{ => net}/lwip/lwip_stack.c | 20 +- code/drivers/{ => net}/lwip/lwip_sys_arch.c | 16 +- code/drivers/{ => net}/rtl8139/rtl8139.c | 18 +- code/drivers/{ => net}/rtl816x/rtl816x.c | 18 +- code/drivers/{ => storage}/ahci/ahci.c | 20 +- code/drivers/{ => storage}/ide/ide.c | 24 +- code/{ => kernel}/hal/hal_apic.c | 148 ++--- code/{ => kernel}/hal/hal_disk.c | 0 code/{ => kernel}/hal/hal_keyboard.c | 408 ++++++------- code/{ => kernel}/hal/hal_main.c | 6 +- code/{ => kernel}/hal/hal_mouse.c | 4 +- code/{ => kernel}/hal/hal_pci.c | 140 ++--- code/{ => kernel}/hal/hal_screen.c | 570 +++++++++--------- code/{ => kernel}/hal/hal_timer.c | 6 +- .../include/kernel}/hal/font8x16.h | 0 .../include/kernel}/hal/hal_apic.h | 0 .../include/kernel}/hal/hal_debug.h | 0 code/kernel/{ => include/kernel}/io_file.h | 25 +- code/kernel/{ => include/kernel}/ke_apc.h | 4 +- code/kernel/include/kernel/ke_cpu.h | 49 ++ code/kernel/{ => include/kernel}/ke_debug.h | 0 code/kernel/{ => include/kernel}/ke_dpc.h | 4 +- code/kernel/{ => include/kernel}/ke_event.h | 8 +- code/kernel/{ => include/kernel}/ke_idt.h | 3 + code/kernel/{ => include/kernel}/ke_irp.h | 6 +- code/kernel/{ => include/kernel}/ke_irq.h | 28 +- code/kernel/{ => include/kernel}/ke_irql.h | 0 code/kernel/{ => include/kernel}/ke_list.h | 0 code/kernel/{ => include/kernel}/ke_mutex.h | 8 +- code/kernel/{ => include/kernel}/ke_process.h | 10 +- code/kernel/{ => include/kernel}/ke_queue.h | 8 +- code/kernel/{ => include/kernel}/ke_sched.h | 6 +- .../kernel/{ => include/kernel}/ke_selftest.h | 2 +- .../{ => include/kernel}/ke_semaphore.h | 40 +- .../kernel/{ => include/kernel}/ke_settings.h | 2 +- .../kernel/{ => include/kernel}/ke_spinlock.h | 2 +- code/kernel/{ => include/kernel}/ke_syscall.h | 2 +- code/kernel/{ => include/kernel}/ke_thread.h | 13 +- code/kernel/{ => include/kernel}/ke_trap.h | 2 +- code/kernel/{ => include/kernel}/ke_userenv.h | 2 +- code/kernel/{ => include/kernel}/ke_util.h | 2 +- code/kernel/{ => include/kernel}/ldr_image.h | 2 +- code/kernel/{ => include/kernel}/mm_phys.h | 56 +- code/kernel/{ => include/kernel}/mm_virt.h | 4 +- code/kernel/{ => include/kernel}/net_socket.h | 6 +- code/kernel/{ => include/kernel}/ob_object.h | 2 +- code/kernel/{ => include/kernel}/syscall_nr.h | 0 code/kernel/io_device.c | 6 +- code/kernel/io_file.c | 24 +- code/kernel/ke_apc.c | 14 +- code/kernel/ke_cpu.c | 51 ++ code/kernel/ke_debug.c | 16 +- code/kernel/ke_dpc.c | 6 +- code/kernel/ke_event.c | 12 +- code/kernel/ke_idt.c | 24 +- code/kernel/ke_irp.c | 12 +- code/kernel/ke_irq.c | 23 +- code/kernel/ke_irql.c | 22 +- code/kernel/ke_mutex.c | 12 +- code/kernel/ke_process.c | 14 +- code/kernel/ke_queue.c | 10 +- code/kernel/ke_sched.c | 83 +-- code/kernel/ke_selftest.c | 28 +- code/kernel/ke_semaphore.c | 10 +- code/kernel/ke_settings.c | 8 +- code/kernel/ke_switch.asm | 2 +- code/kernel/ke_syscall.c | 34 +- code/kernel/ke_thread.c | 19 +- code/kernel/ke_trap.c | 10 +- code/kernel/kmain.c | 42 +- code/kernel/ldr_image.c | 12 +- code/kernel/mm_phys.c | 4 +- code/kernel/mm_virt.c | 6 +- code/kernel/net_device.c | 8 +- code/kernel/net_socket.c | 6 +- code/kernel/net_stack.c | 8 +- code/kernel/ob_object.c | 4 +- code/{kernel => public/ntlite}/boot_info.h | 88 +-- code/{hal => public/ntlite/ddi}/hal_api.h | 2 +- code/{hal => public/ntlite/ddi}/io_driver.h | 2 +- code/{kernel => public/ntlite/ddi}/net_abi.h | 0 .../ntlite/ddi}/net_device.h | 2 +- .../{kernel => public/ntlite/ddi}/net_stack.h | 6 +- code/public/ntlite/dirent.h | 13 + code/{kernel => public/ntlite}/memory_map.h | 0 .../ke_status.h => public/ntlite/status.h} | 0 .../ntlite/string_view.h} | 0 code/{syscall => public/ntlite}/syscall.h | 5 +- code/{ => user/apps}/doom/PureDOOM.h | 0 code/{ => user/apps}/doom/doom.c | 2 +- code/{ => user/apps}/doom/doom1.wad | Bin code/{ => user/apps}/edit/edit.c | 2 +- code/{ => user/apps}/httpget/httpget.c | 2 +- code/{ => user/apps}/ping/ping.c | 2 +- code/{ => user/apps}/resolve/resolve.c | 2 +- .../apps}/shell_native/shell_native.c | 5 +- .../{ => user/apps}/shell_posix/shell_posix.c | 2 +- .../{ => user/apps}/shell_win32/shell_win32.c | 0 code/{ => user/apps}/tcpserve/tcpserve.c | 2 +- code/{ => user/apps}/udp/udp.c | 2 +- code/{ => user/apps}/video/bink.h | 0 code/{ => user/apps}/video/bink2w64.dll | Bin code/{ => user/apps}/video/bink2w64.lib | Bin code/{ => user/apps}/video/rrCore.h | 0 code/{ => user/apps}/video/video.bk2 | Bin code/{ => user/apps}/video/video.c | 0 code/{ => user/personalities}/posix/posix.h | 0 .../personalities}/posix/posix_dir.c | 12 +- .../{ => user/personalities}/posix/posix_fd.c | 2 +- .../{ => user/personalities}/posix/posix_fd.h | 0 .../{ => user/personalities}/posix/posix_io.c | 2 +- .../personalities}/posix/posix_path.c | 0 .../personalities}/posix/posix_path.h | 0 .../personalities}/posix/posix_proc.c | 2 +- .../personalities}/posix/posix_socket.c | 2 +- .../personalities}/posix/posix_thread.c | 2 +- code/{ => user/personalities}/win32/gdi32.c | 2 +- .../{ => user/personalities}/win32/kernel32.c | 10 +- code/{ => user/personalities}/win32/ole32.c | 160 ++--- code/{ => user/personalities}/win32/user32.c | 2 +- code/{ => user/personalities}/win32/winmm.c | 250 ++++---- code/{ => user}/syscall/syscall_nr.inc | 0 code/{ => user}/syscall/syscall_stubs.asm | 0 code/{ => user/system}/init/init.c | 2 +- code/{ => user/tests}/async_apc/async_apc.c | 2 +- .../tests}/async_cancel/async_cancel.c | 2 +- readme.md | 1 + runa.bat | 2 +- 229 files changed, 1617 insertions(+), 1489 deletions(-) rename code/boot/{ => uefi}/efilib.lib (100%) rename code/boot/{ => uefi}/efilib.pdb (100%) rename code/boot/{ => uefi}/include/Makefile (100%) rename code/boot/{ => uefi}/include/aarch64/efibind.h (100%) rename code/boot/{ => uefi}/include/aarch64/efilibplat.h (100%) rename code/boot/{ => uefi}/include/aarch64/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/arm/efibind.h (100%) rename code/boot/{ => uefi}/include/arm/efilibplat.h (100%) rename code/boot/{ => uefi}/include/arm/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/efi.h (100%) rename code/boot/{ => uefi}/include/efi_nii.h (100%) rename code/boot/{ => uefi}/include/efi_pxe.h (100%) rename code/boot/{ => uefi}/include/efiapi.h (100%) rename code/boot/{ => uefi}/include/eficompiler.h (100%) rename code/boot/{ => uefi}/include/eficon.h (100%) rename code/boot/{ => uefi}/include/eficonex.h (100%) rename code/boot/{ => uefi}/include/efidebug.h (100%) rename code/boot/{ => uefi}/include/efidef.h (100%) rename code/boot/{ => uefi}/include/efidevp.h (100%) rename code/boot/{ => uefi}/include/efierr.h (100%) rename code/boot/{ => uefi}/include/efifs.h (100%) rename code/boot/{ => uefi}/include/efigpt.h (100%) rename code/boot/{ => uefi}/include/efiip.h (100%) rename code/boot/{ => uefi}/include/efilib.h (100%) rename code/boot/{ => uefi}/include/efilink.h (100%) rename code/boot/{ => uefi}/include/efinet.h (100%) rename code/boot/{ => uefi}/include/efipart.h (100%) rename code/boot/{ => uefi}/include/efipciio.h (100%) rename code/boot/{ => uefi}/include/efipoint.h (100%) rename code/boot/{ => uefi}/include/efiprot.h (100%) rename code/boot/{ => uefi}/include/efipxebc.h (100%) rename code/boot/{ => uefi}/include/efirtlib.h (100%) rename code/boot/{ => uefi}/include/efiser.h (100%) rename code/boot/{ => uefi}/include/efisetjmp.h (100%) rename code/boot/{ => uefi}/include/efishell.h (100%) rename code/boot/{ => uefi}/include/efishellintf.h (100%) rename code/boot/{ => uefi}/include/efistdarg.h (100%) rename code/boot/{ => uefi}/include/efitcp.h (100%) rename code/boot/{ => uefi}/include/efiudp.h (100%) rename code/boot/{ => uefi}/include/efiui.h (100%) rename code/boot/{ => uefi}/include/ia32/efibind.h (100%) rename code/boot/{ => uefi}/include/ia32/efilibplat.h (100%) rename code/boot/{ => uefi}/include/ia32/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/ia32/pe.h (100%) rename code/boot/{ => uefi}/include/ia64/efibind.h (100%) rename code/boot/{ => uefi}/include/ia64/efilibplat.h (100%) rename code/boot/{ => uefi}/include/ia64/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/ia64/pe.h (100%) rename code/boot/{ => uefi}/include/ia64/salproc.h (100%) rename code/boot/{ => uefi}/include/inc.mak (100%) rename code/boot/{ => uefi}/include/legacy.h (100%) rename code/boot/{ => uefi}/include/lib.h (100%) rename code/boot/{ => uefi}/include/libsmbios.h (100%) rename code/boot/{ => uefi}/include/loongarch64/efibind.h (100%) rename code/boot/{ => uefi}/include/loongarch64/efilibplat.h (100%) rename code/boot/{ => uefi}/include/loongarch64/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/make.inf (100%) rename code/boot/{ => uefi}/include/makefile.hdr (100%) rename code/boot/{ => uefi}/include/mips64el/efibind.h (100%) rename code/boot/{ => uefi}/include/mips64el/efilibplat.h (100%) rename code/boot/{ => uefi}/include/mips64el/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/pci22.h (100%) rename code/boot/{ => uefi}/include/protocol/adapterdebug.h (100%) rename code/boot/{ => uefi}/include/protocol/eficonsplit.h (100%) rename code/boot/{ => uefi}/include/protocol/efidbg.h (100%) rename code/boot/{ => uefi}/include/protocol/efivar.h (100%) rename code/boot/{ => uefi}/include/protocol/ia64/eficontext.h (100%) rename code/boot/{ => uefi}/include/protocol/intload.h (100%) rename code/boot/{ => uefi}/include/protocol/legacyboot.h (100%) rename code/boot/{ => uefi}/include/protocol/make.inf (100%) rename code/boot/{ => uefi}/include/protocol/makefile.hdr (100%) rename code/boot/{ => uefi}/include/protocol/piflash64.h (100%) rename code/boot/{ => uefi}/include/protocol/readme.txt (100%) rename code/boot/{ => uefi}/include/protocol/vgaclass.h (100%) rename code/boot/{ => uefi}/include/riscv64/efibind.h (100%) rename code/boot/{ => uefi}/include/riscv64/efilibplat.h (100%) rename code/boot/{ => uefi}/include/riscv64/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/romload.h (100%) rename code/boot/{ => uefi}/include/x86_64/efibind.h (100%) rename code/boot/{ => uefi}/include/x86_64/efilibplat.h (100%) rename code/boot/{ => uefi}/include/x86_64/efisetjmp_arch.h (100%) rename code/boot/{ => uefi}/include/x86_64/pe.h (100%) rename code/boot/{ => uefi}/main.c (98%) rename code/{kernel => common/include/common}/ini_parser.h (100%) rename code/{kernel => common/include/common}/printf.h (100%) rename code/{ => common}/ini_parser.c (95%) rename code/{ => common}/libc.c (100%) rename code/{ => common}/printf.c (99%) rename code/drivers/{ => bus}/usb/usb.c (58%) rename code/drivers/{ => fs}/fat32/fat32.c (99%) rename code/drivers/{ => net}/lwip/README.md (100%) rename code/drivers/{ => net}/lwip/include/arch/bpstruct.h (100%) rename code/drivers/{ => net}/lwip/include/arch/cc.h (97%) rename code/drivers/{ => net}/lwip/include/arch/epstruct.h (100%) rename code/drivers/{ => net}/lwip/include/arch/sys_arch.h (100%) rename code/drivers/{ => net}/lwip/include/lwipopts.h (100%) rename code/drivers/{ => net}/lwip/include/stdlib.h (100%) rename code/drivers/{ => net}/lwip/lwip_sources.txt (93%) rename code/drivers/{ => net}/lwip/lwip_stack.c (99%) rename code/drivers/{ => net}/lwip/lwip_sys_arch.c (97%) rename code/drivers/{ => net}/rtl8139/rtl8139.c (98%) rename code/drivers/{ => net}/rtl816x/rtl816x.c (98%) rename code/drivers/{ => storage}/ahci/ahci.c (99%) rename code/drivers/{ => storage}/ide/ide.c (98%) rename code/{ => kernel}/hal/hal_apic.c (95%) rename code/{ => kernel}/hal/hal_disk.c (100%) rename code/{ => kernel}/hal/hal_keyboard.c (96%) rename code/{ => kernel}/hal/hal_main.c (99%) rename code/{ => kernel}/hal/hal_mouse.c (99%) rename code/{ => kernel}/hal/hal_pci.c (96%) rename code/{ => kernel}/hal/hal_screen.c (97%) rename code/{ => kernel}/hal/hal_timer.c (98%) rename code/{ => kernel/include/kernel}/hal/font8x16.h (100%) rename code/{ => kernel/include/kernel}/hal/hal_apic.h (100%) rename code/{ => kernel/include/kernel}/hal/hal_debug.h (100%) rename code/kernel/{ => include/kernel}/io_file.h (92%) rename code/kernel/{ => include/kernel}/ke_apc.h (98%) create mode 100644 code/kernel/include/kernel/ke_cpu.h rename code/kernel/{ => include/kernel}/ke_debug.h (100%) rename code/kernel/{ => include/kernel}/ke_dpc.h (96%) rename code/kernel/{ => include/kernel}/ke_event.h (83%) rename code/kernel/{ => include/kernel}/ke_idt.h (86%) rename code/kernel/{ => include/kernel}/ke_irp.h (98%) rename code/kernel/{ => include/kernel}/ke_irq.h (94%) rename code/kernel/{ => include/kernel}/ke_irql.h (100%) rename code/kernel/{ => include/kernel}/ke_list.h (100%) rename code/kernel/{ => include/kernel}/ke_mutex.h (75%) rename code/kernel/{ => include/kernel}/ke_process.h (96%) rename code/kernel/{ => include/kernel}/ke_queue.h (88%) rename code/kernel/{ => include/kernel}/ke_sched.h (92%) rename code/kernel/{ => include/kernel}/ke_selftest.h (89%) rename code/kernel/{ => include/kernel}/ke_semaphore.h (82%) rename code/kernel/{ => include/kernel}/ke_settings.h (92%) rename code/kernel/{ => include/kernel}/ke_spinlock.h (99%) rename code/kernel/{ => include/kernel}/ke_syscall.h (90%) rename code/kernel/{ => include/kernel}/ke_thread.h (96%) rename code/kernel/{ => include/kernel}/ke_trap.h (98%) rename code/kernel/{ => include/kernel}/ke_userenv.h (97%) rename code/kernel/{ => include/kernel}/ke_util.h (98%) rename code/kernel/{ => include/kernel}/ldr_image.h (98%) rename code/kernel/{ => include/kernel}/mm_phys.h (94%) rename code/kernel/{ => include/kernel}/mm_virt.h (98%) rename code/kernel/{ => include/kernel}/net_socket.h (95%) rename code/kernel/{ => include/kernel}/ob_object.h (97%) rename code/kernel/{ => include/kernel}/syscall_nr.h (100%) create mode 100644 code/kernel/ke_cpu.c rename code/{kernel => public/ntlite}/boot_info.h (95%) rename code/{hal => public/ntlite/ddi}/hal_api.h (99%) rename code/{hal => public/ntlite/ddi}/io_driver.h (98%) rename code/{kernel => public/ntlite/ddi}/net_abi.h (100%) rename code/{kernel => public/ntlite/ddi}/net_device.h (98%) rename code/{kernel => public/ntlite/ddi}/net_stack.h (96%) create mode 100644 code/public/ntlite/dirent.h rename code/{kernel => public/ntlite}/memory_map.h (100%) rename code/{kernel/ke_status.h => public/ntlite/status.h} (100%) rename code/{syscall/sys_string.h => public/ntlite/string_view.h} (100%) rename code/{syscall => public/ntlite}/syscall.h (99%) rename code/{ => user/apps}/doom/PureDOOM.h (100%) rename code/{ => user/apps}/doom/doom.c (99%) rename code/{ => user/apps}/doom/doom1.wad (100%) rename code/{ => user/apps}/edit/edit.c (99%) rename code/{ => user/apps}/httpget/httpget.c (99%) rename code/{ => user/apps}/ping/ping.c (99%) rename code/{ => user/apps}/resolve/resolve.c (98%) rename code/{ => user/apps}/shell_native/shell_native.c (99%) rename code/{ => user/apps}/shell_posix/shell_posix.c (99%) rename code/{ => user/apps}/shell_win32/shell_win32.c (100%) rename code/{ => user/apps}/tcpserve/tcpserve.c (99%) rename code/{ => user/apps}/udp/udp.c (99%) rename code/{ => user/apps}/video/bink.h (100%) rename code/{ => user/apps}/video/bink2w64.dll (100%) rename code/{ => user/apps}/video/bink2w64.lib (100%) rename code/{ => user/apps}/video/rrCore.h (100%) rename code/{ => user/apps}/video/video.bk2 (100%) rename code/{ => user/apps}/video/video.c (100%) rename code/{ => user/personalities}/posix/posix.h (100%) rename code/{ => user/personalities}/posix/posix_dir.c (88%) rename code/{ => user/personalities}/posix/posix_fd.c (98%) rename code/{ => user/personalities}/posix/posix_fd.h (100%) rename code/{ => user/personalities}/posix/posix_io.c (99%) rename code/{ => user/personalities}/posix/posix_path.c (100%) rename code/{ => user/personalities}/posix/posix_path.h (100%) rename code/{ => user/personalities}/posix/posix_proc.c (99%) rename code/{ => user/personalities}/posix/posix_socket.c (99%) rename code/{ => user/personalities}/posix/posix_thread.c (99%) rename code/{ => user/personalities}/win32/gdi32.c (99%) rename code/{ => user/personalities}/win32/kernel32.c (99%) rename code/{ => user/personalities}/win32/ole32.c (96%) rename code/{ => user/personalities}/win32/user32.c (98%) rename code/{ => user/personalities}/win32/winmm.c (96%) rename code/{ => user}/syscall/syscall_nr.inc (100%) rename code/{ => user}/syscall/syscall_stubs.asm (100%) rename code/{ => user/system}/init/init.c (98%) rename code/{ => user/tests}/async_apc/async_apc.c (99%) rename code/{ => user/tests}/async_cancel/async_cancel.c (99%) diff --git a/OVMF/OVMF_VARS_4M_d.fd b/OVMF/OVMF_VARS_4M_d.fd index 8d8bdfe408b14911d6377f29f23050066a4110e8..d8e8b069d5ef88f0b8ae0cf822a74036f83a7ab5 100644 GIT binary patch literal 540672 zcmeI*Yp`8aeE{%v?zto}ybQfk#X60{Xr)|~M}QU)5*lfQS~!uPFPAC@nwyx~vI zy?FK5%fn%H*t;+OV(8ZN+gDd!s(kvh(f{22vCn;Z<^9{=I&$G-H{Q8#tQ;xM&EwdUkY&Ux|h3m*E>S04JqXBHl|B5aEvo5MBXy7+ZzIH}QJ zm+HSRTt z)|}i(W~lzldRx=*UG+Eh>8rM;Exfj-Igz%exlR3*9=A28)R#N)>-gcY-qtjH*Tlc* z!}r>nw&>cL=0w_><~H?Ldfe75t1oxr*Esg7KI&~v!*|u+)Tgi7nzr!Tn&w2>n&vk3 zS9;vmoLXP*#IJ|cf2g-L4c}FNQ=h(SYudtVYnl^jYnt2CU+HmMb6S156TdE~|4?sh z8osOkrapbu*0hD!)-)&5)-<=NztZEj=JfhRt!WFdt!YlA zt!Zvke|M*P0V) z*P7eZU#Ycg9 z71c+>rr6T0i1|I&#lIO|I1(OzWZz8(URt(p_X}q|zjyP|_YW@^32)pzdhW;#jTH0bj#RqNbO#`bvY(3Go418x-RQu%X)cSmk-1>+8VQqE{H#E2_KB_+`J`Z zZs+2(z73W=aakXX3(H;4R0Mx{%ij<0`JY2qKk}2)f4cLJKfU|nxL#Yss`%VmS<`bX z>z&p!Z@DQ&>xc&Hcz!&Fd}P9&h;Lbb(Z780z7SHHQty^s%fzZJ`?trJJ$`C4{-)6* z?YEQ@_T-jx-goG~?_T#8$DFqD#jpM8_EW>j;nc9KvgRkn?@x)}pBmDb{*3jdn2@%2 zZ`vdE%AA)ElK$73@%hG|-*VTU&mXh))5ooT_@|4XI;Q#my7}e*KI6h)m*fB5yEh#i z)BiiM_Pil^4z`|8`j_`un}`SsektZOPI_ak9rEOFPxpHu&)Uhh&J zyehuFCH`%yPut`3Rq>g&KRvd`XC+)58B-|d!|`ic_w>lAS7|x#jnApuIk_!LYjqA6xvW_Y5aBEz%)C*f0-W@&^f4(|?G;gIo@%7=G&id-_tb1_tvl~9N{~w-A ztyJ=RN85HPt!FZ5y`HHyrS)7I+syi!UKGDu8-HFJb2C?j4dI;lu_mtV`SCXw#aHUB z?WytSxX(+6h5akai8_=@QM6n>D*Z4v7D8Iv3%|AK<4f+lWbG%9cvQ8eeq8+PY3n~+KJ-nYTJqz| zO&+E4VXtrUQp2sz-)E1<#kSt=l(Uhx`^E;_ecFs~_u;8w%X%!I`mRRBA-gQ^iA!tk zlFlzDmrEzOtd4EO#<0H6C8GS=;fAFmw=O)luFxgDGg6=OUey@8;98~{-#v@AEnAcs(i$6#dV60@29;RNB5;tdGSbi zde>_neDU@t-nHw)``_@3n@`wLJuJk!)P6ftZ|tM-*?2qCku)~pM;;p6@3FCRsnlcx zs*Qf7&(-Q3U2H_oHl%&ErolE;d$mpXRoAjP>y-MIX}zYp*82sM;w-V}F%(A;!8;xI-)=?fCI=RZj3OXTOR?MAh0uETS(l+Sr4g76b1p09SB8Qt3G4)ETje z$_avAaA%M2#3Jgg)a0+JEQ&>>6Glb4rnNus(fCm;qIpOsw|y0hsGj>1ix7+0Qpxn1 z8|To)A}Sec+D7jZGMh-&`v%!hPx+gGs&v53LQ*(?&{%sUovhz|+&po@@+p;7tLSBTti0QL7^x*KCH9ksX07!}d{!(% zEJ9wy^hP;Gcyq=qDduFph}5S{5A#J#o&>L}bfaE$2eSJE@*=7wcj{+(5%MBZB&PXQ zZk6^fb6&QBRl4@)tuA%RIaZ}IEiXb|guIC3cMgC-M>zzp(Qu8%wm3)he4a1jPO%8F z2(bvUh}ch^!Bf%MV`F&{MbAa&=dY%*iC9D$Q%-+~MTkX+MO6C#gEKd9O6zYGkjcDn zL8{yGBIHHLiuLSDqgyokHRBE%xZBBnRW@*>9Xwltf^C$R{zh)QH& z1_NWc=a5~aQM4>(oY3!J{Alh8EUZ3| zO_^v>YP#UcKJVYpdz*G!8gj>OC&Z{;nsFqOMs2jcugR~_}99o!36qO9GK z)ptm3*+86s=yrb;IaFsb=9cM!xGuAZVe6`$U6uwS7qTmd&dxua-}Knj(Ri?DV~cV% z3fHoMidDUnnZufohvK$(vY;YWH0_m~I+(^lMd$IT6`T1?nQdA0{MyV}7A;MA_oGVX z>7()4IM$X|$7jeOJ9eCo?Oj}x(^c!)vf&xP_9EGIaqh8Oo5F=QrwvTo)I}b2SKE}^ zE~oqErMfh=9=$VO34LwY7S@HW;mWW%ehy(l7z*Vu91e-!=WK6U_Tubi*O#1E|I@M; zWiPw4bzYFY+$52|zVS3;rgOe;{<_9w+seAWBP@*T(duzjd~r*BHY*b+hV*e#d`D_H zmWEAXRX8`6?4{wN_}$w0^U|<7tOy&zIq_pncy~Cz^4i+U-=)7iCH|cH1BXqX&S|K8 zR4OlHVCTJ-TH_g%8~lSe#v%!biRzMWg<^2(<)j!^!cvtR{JK6j>I3J}n#<|9YBBxqRrG!iJ6E zsAU(&mzz9F<-=az^VQ`=dyUpTU@0rUxRAs)%9hs-0by1|pBD zD~C!*CTlxWf4gWNRj&^#Es}q_(ioJMu9Go((LAae)O@DQF5gA-sAkTxNQ2*59WRUab6`**5>VU7phyW--rchQ?Nn!XC9y z%^b~h>Z*6&f?&A6Xm&>=VY(V&pfA|B^rz`sFSW|!KSMA z=RL|z8HhZmamF~v=_K#0NQXmj^>7kN%yZBuT$+*zJeY{P3aIOJ?^T6TV(Q|wh% z=Az1rsikG7^LkVB;2O_!mF77(B>P-sC%Hq_xkTEZgG}q2=32;I-(25L*0nlc)Y)y% zmmYlcMdg`1&|?2p=Yla`RCSJ*REP6S%@-95)s#o4ZE}5Hom}%h@&7ezhpOdxS$szt zM3^t?m19y~dG2GLQ|7F4@|>z=do-LEXTiKaToIOrdavQ?I7jB?&p5MFq==+BkjD*pX_I&5IhaXyb?-d93z4>RCEzG?(IMwUauWeTMTF+P3 zzK_u^&*_Vqc}{5^=hs|E<6Y=ZA|u)3xHKMrtigWmc<8 zYuMe$fog1A0)O_b_+$^m0~@gcOZMbQ0^B ziMgxq7V8k}2w}WO-6=*+JRtS4#5%^t%B518Xs=m*!NA6}Y9p3=F1_?qm+iaYyjwSI ze)7><&wp+_2oQH~?IG4N`Nlq7RjXcbXXQtwdMVaXFT0b!CL6Ji`n;gsR(-LKH~eD4 zWd}3Jn0p)+>k#W0jPq@UhtyfexO6URKIFfOb(Bgmhi|+?m5$cq9nkNmQA^BoER~ve zKy%v1G#1Z|bxaTy5y$Tw0E3S5 zQN<#}BDRIWxdvn=Vi8{!ix7*L5O3@hBexGE79kcP7Ev8`vC%4U# z7g01WmNAGHi>NjVwa;P^Z7RNb?}kHWoiQ(12=XF2yU|4t4zJngK?ZT|D|r!l*MQ7K zEaD!qh)##!S#>S7f$}1%9jtUdMl3=sLM)#E9iqXW z8*?UN5%-EkbkY;fu4`fu)p1w)EEaKSI&_*Z;*}!N@Vit_T%%F+Ty%avEqR+SqG3_2 zv{~{Zik3yO2(bvUh!}a@o@!FFiK04-$>g{1@*?C#>|fDY=@N_RCNIEz5jp2~+RYd7 z6|o4h2-j#dyt_nB{YuCCp;&^Z&Y?U2*CV#<{d7|3XY=?Z7EyHkm)}2RNp(4(^CJ{@bqme|IXkL=fZ5_4Ckw{}FT%%E5oXSF_e^sj7`?06zP6s6nDHb6wqF4C(5n>TrLSGHC#}Z-@m+M(XEG zelZ^w`FBIHHLi^y-^U8CU|4cBPwsLU>sbN*OfM1S)lc8NuZMTkX+MZ~d} zSVZkibyv~%K{*$l-&Yljm>z?u|3)mrJv~z-rZ?C4*J3i=MsqVlIyrsqRHoh2v)bR5 z7tz<8fPxhw{}`9zG3Kt!zn-BNJ0`a+GIyo9D<8jV>)Y3cjbUZ1r}v9Rh((A+h(*M< zKrBKmBF*c(DrNv~4eP@7VOuN}JsXWRUr;A4a1T05xqT&h5%MCM7ur}gvaeV!SZHg1 z-fF6Z+%hc|Ar>(hb6J@$!h8|a=UJPHzDJ5&<+P9TBKn&b@z-Jzo%Dn&0oj~#ZN7-q zSF1kK`55y>m@mS75!L!&z6kS0m@lFnZ!VC3els0IT%+L{4cBPo*BRGnxJJV@8m`fp zEAvHsO)NqzLSBTth}hSc7a=b~UPLusvtlmtBIHHLi;x#FSMnmhE*2pcAr{ea1T7ZPlRMIN6e|~tsCT-%o#;+1 zq83$X8W_u|*J2T35n>VYA|_l*H6ZyR`R%({gjj@FgjmE}iA8)vEJ7?oEJ7?I4&Yp) z;TjFsXjCH^Vi95yVi95yViBdo!u}QIa%vU_rb2WUk8vN3S(|0Iqw`L#(Qu8%#A`JE zRxCm+LM%coLM&o&>TXqf-`(b6H=lIBlQyOomuzO`@VZ7L?eWGBu?VqAlBv55BjB;C_A?U$*s%Xfxr{3%Xg<3WG`0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C7CI}pV+pwrbcl64ai`_TYm60RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ z009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBly zK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF z5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk z1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs z0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZ zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C7 z2oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+ X009C72oNAZfB*pk1PBnAZvy`hIOC}7 delta 152 zcmZo@P;6*W+>oX@IZah*@&gT)$q9#ICcn_Mnrx(^HhIsBOVcm$G0vZSUN>p7-VxEs z1}YkpZH`q>{{K39`XWKbg+PgVph~651$t`JA6YQ1p4@QGV){udrtHZM1##2UY?vZJ zB9rx1R3{4r*|bO4F>Q~qV_tEwy#UB6uw$NZ5lAvkv2GJ!X%k>=6JTo-U|%M{VE_O- Cg*)E> diff --git a/build.bat b/build.bat index c91ed6f..e68d032 100644 --- a/build.bat +++ b/build.bat @@ -3,6 +3,13 @@ setlocal enabledelayedexpansion set ROOT=%~dp0. set SRC=%ROOT%\code +set PUBLIC=%SRC%\public +set COMMON=%SRC%\common +set KERNEL=%SRC%\kernel +set HAL=%KERNEL%\hal +set USER=%SRC%\user +set DRIVERS=%SRC%\drivers +set THIRD_PARTY=%SRC%\third_party set VHD=%~dp0disk.vhd if not exist "%VHD%" ( @@ -36,43 +43,46 @@ mkdir "obj\doom" 2>nul mkdir "obj\video" 2>nul mkdir "bin" 2>nul -set CFLAGS=/nologo /W3 /WX /Od /GS- /Gs999999 /Gz /Gy /EHsc- /GR- /Oi /Zi /std:c17 /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS /I"%SRC%\kernel" /I"%SRC%\hal" /I"%SRC%\syscall" +set INCLUDES=/I"%PUBLIC%" /I"%COMMON%\include" /I"%KERNEL%\include" +set CFLAGS=/nologo /W3 /WX /Od /GS- /Gs999999 /Gz /Gy /EHsc- /GR- /Oi /Zi /std:c17 /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS %INCLUDES% set KERNEL_CFLAGS=%CFLAGS% rem lwIP is third-party freestanding C. Compile it into lwip.sys without /WX, rem and silence expected MSVC warnings from packed protocol headers and macros. -set LWIP_DRIVER_CFLAGS=%CFLAGS:/WX =% /I"%SRC%\drivers\lwip\include" /I"%SRC%\third_party\lwip\src\include" /wd4005 /wd4100 /wd4103 /wd4127 /wd4244 /wd4267 /wd4706 +set LWIP_ROOT=%DRIVERS%\net\lwip +set LWIP_DRIVER_CFLAGS=%CFLAGS:/WX =% /I"%LWIP_ROOT%\include" /I"%THIRD_PARTY%\lwip\src\include" /wd4005 /wd4100 /wd4103 /wd4127 /wd4244 /wd4267 /wd4706 set LFLAGS=/nologo /NODEFAULTLIB /DEBUG :: ---- Assemble ASM files ---- echo Assembling... -ml64 /nologo /c /Fo"obj\kernel\ke_switch.obj" "%SRC%\kernel\ke_switch.asm" || exit /b 1 -ml64 /nologo /c /Fo"obj\kernel\ke_syscall_asm.obj" "%SRC%\kernel\ke_syscall.asm" || exit /b 1 -ml64 /nologo /c /Fo"obj\kernel\ke_gdt_reload.obj" "%SRC%\kernel\ke_gdt_reload.asm" || exit /b 1 -ml64 /nologo /c /Fo"obj\syscall\stubs.obj" "%SRC%\syscall\syscall_stubs.asm" || exit /b 1 +ml64 /nologo /c /Fo"obj\kernel\ke_switch.obj" "%KERNEL%\ke_switch.asm" || exit /b 1 +ml64 /nologo /c /Fo"obj\kernel\ke_syscall_asm.obj" "%KERNEL%\ke_syscall.asm" || exit /b 1 +ml64 /nologo /c /Fo"obj\kernel\ke_gdt_reload.obj" "%KERNEL%\ke_gdt_reload.asm" || exit /b 1 +for %%f in (%SRC%\boot\uefi\*.asm) do ( + ml64 /nologo /c /Fo"obj\boot\%%~nf.obj" "%%f" || exit /b 1 +) +ml64 /nologo /c /Fo"obj\syscall\stubs.obj" "%USER%\syscall\syscall_stubs.asm" || exit /b 1 -:: ---- Compile libc ---- -cl /nologo /c /Fo"obj\libc.obj" "%SRC%\libc.c" || exit /b 1 -:: ---- Compile printf ---- -cl %CFLAGS% /c /Fo"obj\printf.obj" "%SRC%\printf.c" || exit /b 1 -:: ---- Compile ini parser ---- -cl %CFLAGS% /c /Fo"obj\ini_parser.obj" "%SRC%\ini_parser.c" || exit /b 1 +:: ---- Compile shared freestanding support ---- +cl /nologo /c /Fo"obj\libc.obj" "%COMMON%\libc.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\printf.obj" "%COMMON%\printf.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\ini_parser.obj" "%COMMON%\ini_parser.c" || exit /b 1 :: ---- Compile bootloader ---- echo Compiling bootloader... -for %%f in (%SRC%\boot\*.c) do ( - cl %CFLAGS% /c /I"%SRC%\boot\include" /Fo"obj\boot\%%~nf.obj" "%%f" || exit /b 1 +for %%f in (%SRC%\boot\uefi\*.c) do ( + cl %CFLAGS% /c /I"%SRC%\boot\uefi\include" /Fo"obj\boot\%%~nf.obj" "%%f" || exit /b 1 ) :: ---- Link bootloader ---- echo Linking bootx64.efi... link %LFLAGS% /SUBSYSTEM:EFI_APPLICATION /ENTRY:UefiMain /OUT:"bin\bootx64.efi" ^ - /PDB:"bin\bootx64.pdb" %SRC%\boot\efilib.lib obj\ini_parser.obj obj\libc.obj obj\boot\*.obj || exit /b 1 + /PDB:"bin\bootx64.pdb" %SRC%\boot\uefi\efilib.lib obj\ini_parser.obj obj\libc.obj obj\boot\*.obj || exit /b 1 :: ---- Compile HAL ---- echo Compiling hal... -for %%f in (%SRC%\hal\*.c) do ( +for %%f in (%HAL%\*.c) do ( cl %CFLAGS% /c /Fo"obj\hal\%%~nf.obj" "%%f" || exit /b 1 ) @@ -82,7 +92,7 @@ link %LFLAGS% /DLL /OUT:"bin\hal.dll" /ENTRY:HalInitialize /IGNORE:4216 obj\prin :: ---- Compile kernel ---- echo Compiling kernel... -for %%f in (%SRC%\kernel\*.c) do ( +for %%f in (%KERNEL%\*.c) do ( cl %KERNEL_CFLAGS% /c /Fo"obj\kernel\%%~nf.obj" "%%f" || exit /b 1 ) @@ -98,7 +108,7 @@ link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^ :: ---- Compile win32.dll ---- echo Compiling win32.dll... -for %%f in (%SRC%\win32\*.c) do ( +for %%f in (%USER%\personalities\win32\*.c) do ( cl %CFLAGS% /c /Fo"obj\win32\%%~nf.obj" "%%f" || exit /b 1 ) link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^ @@ -106,7 +116,7 @@ link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^ :: ---- Compile posix.dll ---- echo Compiling posix.dll... -for %%f in (%SRC%\posix\*.c) do ( +for %%f in (%USER%\personalities\posix\*.c) do ( cl %CFLAGS% /c /Fo"obj\posix\%%~nf.obj" "%%f" || exit /b 1 ) link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^ @@ -115,22 +125,22 @@ link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^ :: ---- Compile drivers ---- echo Compiling drivers... echo Compiling ide.sys... -cl %CFLAGS% /I"%SRC%\hal" /c /Fo"obj\drivers\ide.obj" "%SRC%\drivers\ide\ide.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\drivers\ide.obj" "%DRIVERS%\storage\ide\ide.c" || exit /b 1 link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\ide.sys" /ENTRY:DriverEntry ^ bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\ide.obj || exit /b 1 echo Compiling ahci.sys... -cl %CFLAGS% /I"%SRC%\hal" /c /Fo"obj\drivers\ahci.obj" "%SRC%\drivers\ahci\ahci.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\drivers\ahci.obj" "%DRIVERS%\storage\ahci\ahci.c" || exit /b 1 link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\ahci.sys" /ENTRY:DriverEntry ^ bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\ahci.obj || exit /b 1 echo Compiling fat32.sys... -cl %CFLAGS% /I"%SRC%\fat32" /c /Fo"obj\drivers\fat32.obj" "%SRC%\drivers\fat32\fat32.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\drivers\fat32.obj" "%DRIVERS%\fs\fat32\fat32.c" || exit /b 1 link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\fat32.sys" /ENTRY:DriverEntry ^ bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\fat32.obj || exit /b 1 echo Compiling lwip.sys... -for /f "usebackq tokens=* delims=" %%f in ("%SRC%\drivers\lwip\lwip_sources.txt") do ( +for /f "usebackq tokens=* delims=" %%f in ("%LWIP_ROOT%\lwip_sources.txt") do ( set "LWIP_FILE=%%f" if not "!LWIP_FILE!"=="" if not "!LWIP_FILE:~0,1!"=="#" ( set "LWIP_WIN_FILE=!LWIP_FILE:/=\!" @@ -143,23 +153,23 @@ link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\lwip.sys" /ENTRY:Dri bin\hal.lib bin\kernel.lib obj\libc.obj obj\lwip\*.obj || exit /b 1 echo Compiling usb.sys... -cl %CFLAGS% /I"%SRC%\usb" /c /Fo"obj\drivers\usb.obj" "%SRC%\drivers\usb\usb.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\drivers\usb.obj" "%DRIVERS%\bus\usb\usb.c" || exit /b 1 link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\usb.sys" /ENTRY:DriverEntry ^ bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\usb.obj || exit /b 1 echo Compiling rtl816x.sys... -cl %CFLAGS% /I"%SRC%\rtl816x" /c /Fo"obj\drivers\rtl816x.obj" "%SRC%\drivers\rtl816x\rtl816x.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\drivers\rtl816x.obj" "%DRIVERS%\net\rtl816x\rtl816x.c" || exit /b 1 link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\rtl816x.sys" /ENTRY:DriverEntry ^ bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\rtl816x.obj || exit /b 1 echo Compiling rtl8139.sys... -cl %CFLAGS% /I"%SRC%\rtl8139" /c /Fo"obj\drivers\rtl8139.obj" "%SRC%\drivers\rtl8139\rtl8139.c" || exit /b 1 +cl %CFLAGS% /c /Fo"obj\drivers\rtl8139.obj" "%DRIVERS%\net\rtl8139\rtl8139.c" || exit /b 1 link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL /OUT:"bin\rtl8139.sys" /ENTRY:DriverEntry ^ bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\rtl8139.obj || exit /b 1 :: ---- Compile init ---- echo Compiling init... -for %%f in (%SRC%\init\*.c) do ( +for %%f in (%USER%\system\init\*.c) do ( cl %CFLAGS% /c /Fo"obj\init\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:_start ^ @@ -167,7 +177,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:_start ^ :: ---- Compile shell_win32 ---- echo Compiling shell_win32... -for %%f in (%SRC%\shell_win32\*.c) do ( +for %%f in (%USER%\apps\shell_win32\*.c) do ( cl %CFLAGS% /c /Fo"obj\shell_win32\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -175,7 +185,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile shell_posix ---- echo Compiling shell_posix... -for %%f in (%SRC%\shell_posix\*.c) do ( +for %%f in (%USER%\apps\shell_posix\*.c) do ( cl %CFLAGS% /c /Fo"obj\shell_posix\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -183,7 +193,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile shell_native ---- echo Compiling shell_native... -for %%f in (%SRC%\shell_native\*.c) do ( +for %%f in (%USER%\apps\shell_native\*.c) do ( cl %CFLAGS% /c /Fo"obj\shell_native\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -191,7 +201,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile async_apc ---- echo Compiling async_apc... -for %%f in (%SRC%\async_apc\*.c) do ( +for %%f in (%USER%\tests\async_apc\*.c) do ( cl %CFLAGS% /c /Fo"obj\async_apc\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -199,7 +209,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile async_cancel ---- echo Compiling async_cancel... -for %%f in (%SRC%\async_cancel\*.c) do ( +for %%f in (%USER%\tests\async_cancel\*.c) do ( cl %CFLAGS% /c /Fo"obj\async_cancel\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -207,7 +217,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile edit ---- echo Compiling edit... -for %%f in (%SRC%\edit\*.c) do ( +for %%f in (%USER%\apps\edit\*.c) do ( cl %CFLAGS% /c /Fo"obj\edit\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -215,7 +225,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile httpget ---- echo Compiling httpget... -for %%f in (%SRC%\httpget\*.c) do ( +for %%f in (%USER%\apps\httpget\*.c) do ( cl %CFLAGS% /c /Fo"obj\httpget\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -223,7 +233,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile tcpserve ---- echo Compiling tcpserve... -for %%f in (%SRC%\tcpserve\*.c) do ( +for %%f in (%USER%\apps\tcpserve\*.c) do ( cl %CFLAGS% /c /Fo"obj\tcpserve\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -231,7 +241,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile udp ---- echo Compiling udp... -for %%f in (%SRC%\udp\*.c) do ( +for %%f in (%USER%\apps\udp\*.c) do ( cl %CFLAGS% /c /Fo"obj\udp\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -239,7 +249,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile resolve ---- echo Compiling resolve... -for %%f in (%SRC%\resolve\*.c) do ( +for %%f in (%USER%\apps\resolve\*.c) do ( cl %CFLAGS% /c /Fo"obj\resolve\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -247,7 +257,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile ping ---- echo Compiling ping... -for %%f in (%SRC%\ping\*.c) do ( +for %%f in (%USER%\apps\ping\*.c) do ( cl %CFLAGS% /c /Fo"obj\ping\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -255,7 +265,7 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile doom ---- echo Compiling doom... -for %%f in (%SRC%\doom\*.c) do ( +for %%f in (%USER%\apps\doom\*.c) do ( cl %CFLAGS% /c /Fo"obj\doom\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ @@ -263,11 +273,11 @@ link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ :: ---- Compile video player ---- echo Compiling video... -for %%f in (%SRC%\video\*.c) do ( +for %%f in (%USER%\apps\video\*.c) do ( cl %CFLAGS% /c /Fo"obj\video\%%~nf.obj" "%%f" || exit /b 1 ) link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^ - /OUT:"bin\video.exe" /PDB:"bin\video.pdb" bin\win32.lib obj\libc.obj %SRC%\video\bink2w64.lib obj\video\*.obj || exit /b 1 + /OUT:"bin\video.exe" /PDB:"bin\video.pdb" bin\win32.lib obj\libc.obj %USER%\apps\video\bink2w64.lib obj\video\*.obj || exit /b 1 :: ---- Mount disk image ---- echo Mounting disk.vhd... @@ -330,10 +340,10 @@ copy /y "bin\ping.exe" "%DEST%\apps\" copy /y "bin\doom.exe" "%DEST%\apps\" copy /y "bin\video.exe" "%DEST%\apps\" copy /y "%SRC%\boot.ini" "%DEST%\" -copy /y "%SRC%\drivers\drivers.ini" "%DEST%\drivers\" -if exist "%SRC%\video\bink2w64.dll" copy /y "%SRC%\video\bink2w64.dll" "%DEST%\apps\" -if exist "%SRC%\video\video.bk2" copy /y "%SRC%\video\video.bk2" "%DEST%\apps\" -if exist "%SRC%\doom\doom1.wad" copy /y "%SRC%\doom\doom1.wad" "%DEST%\apps\" +copy /y "%DRIVERS%\drivers.ini" "%DEST%\drivers\" +if exist "%USER%\apps\video\bink2w64.dll" copy /y "%USER%\apps\video\bink2w64.dll" "%DEST%\apps\" +if exist "%USER%\apps\video\video.bk2" copy /y "%USER%\apps\video\video.bk2" "%DEST%\apps\" +if exist "%USER%\apps\doom\doom1.wad" copy /y "%USER%\apps\doom\doom1.wad" "%DEST%\apps\" :: ---- Unmount disk image ---- echo Unmounting disk.vhd... diff --git a/code/boot.ini b/code/boot.ini index 9d59f32..d7cc45b 100644 --- a/code/boot.ini +++ b/code/boot.ini @@ -1,5 +1,5 @@ [kernel] ; bitmask: 1 = debug prints, 2 = self check -debug = 3 +debug = 0 [init] commandline = apps/shell_native.exe diff --git a/code/boot/efilib.lib b/code/boot/uefi/efilib.lib similarity index 100% rename from code/boot/efilib.lib rename to code/boot/uefi/efilib.lib diff --git a/code/boot/efilib.pdb b/code/boot/uefi/efilib.pdb similarity index 100% rename from code/boot/efilib.pdb rename to code/boot/uefi/efilib.pdb diff --git a/code/boot/include/Makefile b/code/boot/uefi/include/Makefile similarity index 100% rename from code/boot/include/Makefile rename to code/boot/uefi/include/Makefile diff --git a/code/boot/include/aarch64/efibind.h b/code/boot/uefi/include/aarch64/efibind.h similarity index 100% rename from code/boot/include/aarch64/efibind.h rename to code/boot/uefi/include/aarch64/efibind.h diff --git a/code/boot/include/aarch64/efilibplat.h b/code/boot/uefi/include/aarch64/efilibplat.h similarity index 100% rename from code/boot/include/aarch64/efilibplat.h rename to code/boot/uefi/include/aarch64/efilibplat.h diff --git a/code/boot/include/aarch64/efisetjmp_arch.h b/code/boot/uefi/include/aarch64/efisetjmp_arch.h similarity index 100% rename from code/boot/include/aarch64/efisetjmp_arch.h rename to code/boot/uefi/include/aarch64/efisetjmp_arch.h diff --git a/code/boot/include/arm/efibind.h b/code/boot/uefi/include/arm/efibind.h similarity index 100% rename from code/boot/include/arm/efibind.h rename to code/boot/uefi/include/arm/efibind.h diff --git a/code/boot/include/arm/efilibplat.h b/code/boot/uefi/include/arm/efilibplat.h similarity index 100% rename from code/boot/include/arm/efilibplat.h rename to code/boot/uefi/include/arm/efilibplat.h diff --git a/code/boot/include/arm/efisetjmp_arch.h b/code/boot/uefi/include/arm/efisetjmp_arch.h similarity index 100% rename from code/boot/include/arm/efisetjmp_arch.h rename to code/boot/uefi/include/arm/efisetjmp_arch.h diff --git a/code/boot/include/efi.h b/code/boot/uefi/include/efi.h similarity index 100% rename from code/boot/include/efi.h rename to code/boot/uefi/include/efi.h diff --git a/code/boot/include/efi_nii.h b/code/boot/uefi/include/efi_nii.h similarity index 100% rename from code/boot/include/efi_nii.h rename to code/boot/uefi/include/efi_nii.h diff --git a/code/boot/include/efi_pxe.h b/code/boot/uefi/include/efi_pxe.h similarity index 100% rename from code/boot/include/efi_pxe.h rename to code/boot/uefi/include/efi_pxe.h diff --git a/code/boot/include/efiapi.h b/code/boot/uefi/include/efiapi.h similarity index 100% rename from code/boot/include/efiapi.h rename to code/boot/uefi/include/efiapi.h diff --git a/code/boot/include/eficompiler.h b/code/boot/uefi/include/eficompiler.h similarity index 100% rename from code/boot/include/eficompiler.h rename to code/boot/uefi/include/eficompiler.h diff --git a/code/boot/include/eficon.h b/code/boot/uefi/include/eficon.h similarity index 100% rename from code/boot/include/eficon.h rename to code/boot/uefi/include/eficon.h diff --git a/code/boot/include/eficonex.h b/code/boot/uefi/include/eficonex.h similarity index 100% rename from code/boot/include/eficonex.h rename to code/boot/uefi/include/eficonex.h diff --git a/code/boot/include/efidebug.h b/code/boot/uefi/include/efidebug.h similarity index 100% rename from code/boot/include/efidebug.h rename to code/boot/uefi/include/efidebug.h diff --git a/code/boot/include/efidef.h b/code/boot/uefi/include/efidef.h similarity index 100% rename from code/boot/include/efidef.h rename to code/boot/uefi/include/efidef.h diff --git a/code/boot/include/efidevp.h b/code/boot/uefi/include/efidevp.h similarity index 100% rename from code/boot/include/efidevp.h rename to code/boot/uefi/include/efidevp.h diff --git a/code/boot/include/efierr.h b/code/boot/uefi/include/efierr.h similarity index 100% rename from code/boot/include/efierr.h rename to code/boot/uefi/include/efierr.h diff --git a/code/boot/include/efifs.h b/code/boot/uefi/include/efifs.h similarity index 100% rename from code/boot/include/efifs.h rename to code/boot/uefi/include/efifs.h diff --git a/code/boot/include/efigpt.h b/code/boot/uefi/include/efigpt.h similarity index 100% rename from code/boot/include/efigpt.h rename to code/boot/uefi/include/efigpt.h diff --git a/code/boot/include/efiip.h b/code/boot/uefi/include/efiip.h similarity index 100% rename from code/boot/include/efiip.h rename to code/boot/uefi/include/efiip.h diff --git a/code/boot/include/efilib.h b/code/boot/uefi/include/efilib.h similarity index 100% rename from code/boot/include/efilib.h rename to code/boot/uefi/include/efilib.h diff --git a/code/boot/include/efilink.h b/code/boot/uefi/include/efilink.h similarity index 100% rename from code/boot/include/efilink.h rename to code/boot/uefi/include/efilink.h diff --git a/code/boot/include/efinet.h b/code/boot/uefi/include/efinet.h similarity index 100% rename from code/boot/include/efinet.h rename to code/boot/uefi/include/efinet.h diff --git a/code/boot/include/efipart.h b/code/boot/uefi/include/efipart.h similarity index 100% rename from code/boot/include/efipart.h rename to code/boot/uefi/include/efipart.h diff --git a/code/boot/include/efipciio.h b/code/boot/uefi/include/efipciio.h similarity index 100% rename from code/boot/include/efipciio.h rename to code/boot/uefi/include/efipciio.h diff --git a/code/boot/include/efipoint.h b/code/boot/uefi/include/efipoint.h similarity index 100% rename from code/boot/include/efipoint.h rename to code/boot/uefi/include/efipoint.h diff --git a/code/boot/include/efiprot.h b/code/boot/uefi/include/efiprot.h similarity index 100% rename from code/boot/include/efiprot.h rename to code/boot/uefi/include/efiprot.h diff --git a/code/boot/include/efipxebc.h b/code/boot/uefi/include/efipxebc.h similarity index 100% rename from code/boot/include/efipxebc.h rename to code/boot/uefi/include/efipxebc.h diff --git a/code/boot/include/efirtlib.h b/code/boot/uefi/include/efirtlib.h similarity index 100% rename from code/boot/include/efirtlib.h rename to code/boot/uefi/include/efirtlib.h diff --git a/code/boot/include/efiser.h b/code/boot/uefi/include/efiser.h similarity index 100% rename from code/boot/include/efiser.h rename to code/boot/uefi/include/efiser.h diff --git a/code/boot/include/efisetjmp.h b/code/boot/uefi/include/efisetjmp.h similarity index 100% rename from code/boot/include/efisetjmp.h rename to code/boot/uefi/include/efisetjmp.h diff --git a/code/boot/include/efishell.h b/code/boot/uefi/include/efishell.h similarity index 100% rename from code/boot/include/efishell.h rename to code/boot/uefi/include/efishell.h diff --git a/code/boot/include/efishellintf.h b/code/boot/uefi/include/efishellintf.h similarity index 100% rename from code/boot/include/efishellintf.h rename to code/boot/uefi/include/efishellintf.h diff --git a/code/boot/include/efistdarg.h b/code/boot/uefi/include/efistdarg.h similarity index 100% rename from code/boot/include/efistdarg.h rename to code/boot/uefi/include/efistdarg.h diff --git a/code/boot/include/efitcp.h b/code/boot/uefi/include/efitcp.h similarity index 100% rename from code/boot/include/efitcp.h rename to code/boot/uefi/include/efitcp.h diff --git a/code/boot/include/efiudp.h b/code/boot/uefi/include/efiudp.h similarity index 100% rename from code/boot/include/efiudp.h rename to code/boot/uefi/include/efiudp.h diff --git a/code/boot/include/efiui.h b/code/boot/uefi/include/efiui.h similarity index 100% rename from code/boot/include/efiui.h rename to code/boot/uefi/include/efiui.h diff --git a/code/boot/include/ia32/efibind.h b/code/boot/uefi/include/ia32/efibind.h similarity index 100% rename from code/boot/include/ia32/efibind.h rename to code/boot/uefi/include/ia32/efibind.h diff --git a/code/boot/include/ia32/efilibplat.h b/code/boot/uefi/include/ia32/efilibplat.h similarity index 100% rename from code/boot/include/ia32/efilibplat.h rename to code/boot/uefi/include/ia32/efilibplat.h diff --git a/code/boot/include/ia32/efisetjmp_arch.h b/code/boot/uefi/include/ia32/efisetjmp_arch.h similarity index 100% rename from code/boot/include/ia32/efisetjmp_arch.h rename to code/boot/uefi/include/ia32/efisetjmp_arch.h diff --git a/code/boot/include/ia32/pe.h b/code/boot/uefi/include/ia32/pe.h similarity index 100% rename from code/boot/include/ia32/pe.h rename to code/boot/uefi/include/ia32/pe.h diff --git a/code/boot/include/ia64/efibind.h b/code/boot/uefi/include/ia64/efibind.h similarity index 100% rename from code/boot/include/ia64/efibind.h rename to code/boot/uefi/include/ia64/efibind.h diff --git a/code/boot/include/ia64/efilibplat.h b/code/boot/uefi/include/ia64/efilibplat.h similarity index 100% rename from code/boot/include/ia64/efilibplat.h rename to code/boot/uefi/include/ia64/efilibplat.h diff --git a/code/boot/include/ia64/efisetjmp_arch.h b/code/boot/uefi/include/ia64/efisetjmp_arch.h similarity index 100% rename from code/boot/include/ia64/efisetjmp_arch.h rename to code/boot/uefi/include/ia64/efisetjmp_arch.h diff --git a/code/boot/include/ia64/pe.h b/code/boot/uefi/include/ia64/pe.h similarity index 100% rename from code/boot/include/ia64/pe.h rename to code/boot/uefi/include/ia64/pe.h diff --git a/code/boot/include/ia64/salproc.h b/code/boot/uefi/include/ia64/salproc.h similarity index 100% rename from code/boot/include/ia64/salproc.h rename to code/boot/uefi/include/ia64/salproc.h diff --git a/code/boot/include/inc.mak b/code/boot/uefi/include/inc.mak similarity index 100% rename from code/boot/include/inc.mak rename to code/boot/uefi/include/inc.mak diff --git a/code/boot/include/legacy.h b/code/boot/uefi/include/legacy.h similarity index 100% rename from code/boot/include/legacy.h rename to code/boot/uefi/include/legacy.h diff --git a/code/boot/include/lib.h b/code/boot/uefi/include/lib.h similarity index 100% rename from code/boot/include/lib.h rename to code/boot/uefi/include/lib.h diff --git a/code/boot/include/libsmbios.h b/code/boot/uefi/include/libsmbios.h similarity index 100% rename from code/boot/include/libsmbios.h rename to code/boot/uefi/include/libsmbios.h diff --git a/code/boot/include/loongarch64/efibind.h b/code/boot/uefi/include/loongarch64/efibind.h similarity index 100% rename from code/boot/include/loongarch64/efibind.h rename to code/boot/uefi/include/loongarch64/efibind.h diff --git a/code/boot/include/loongarch64/efilibplat.h b/code/boot/uefi/include/loongarch64/efilibplat.h similarity index 100% rename from code/boot/include/loongarch64/efilibplat.h rename to code/boot/uefi/include/loongarch64/efilibplat.h diff --git a/code/boot/include/loongarch64/efisetjmp_arch.h b/code/boot/uefi/include/loongarch64/efisetjmp_arch.h similarity index 100% rename from code/boot/include/loongarch64/efisetjmp_arch.h rename to code/boot/uefi/include/loongarch64/efisetjmp_arch.h diff --git a/code/boot/include/make.inf b/code/boot/uefi/include/make.inf similarity index 100% rename from code/boot/include/make.inf rename to code/boot/uefi/include/make.inf diff --git a/code/boot/include/makefile.hdr b/code/boot/uefi/include/makefile.hdr similarity index 100% rename from code/boot/include/makefile.hdr rename to code/boot/uefi/include/makefile.hdr diff --git a/code/boot/include/mips64el/efibind.h b/code/boot/uefi/include/mips64el/efibind.h similarity index 100% rename from code/boot/include/mips64el/efibind.h rename to code/boot/uefi/include/mips64el/efibind.h diff --git a/code/boot/include/mips64el/efilibplat.h b/code/boot/uefi/include/mips64el/efilibplat.h similarity index 100% rename from code/boot/include/mips64el/efilibplat.h rename to code/boot/uefi/include/mips64el/efilibplat.h diff --git a/code/boot/include/mips64el/efisetjmp_arch.h b/code/boot/uefi/include/mips64el/efisetjmp_arch.h similarity index 100% rename from code/boot/include/mips64el/efisetjmp_arch.h rename to code/boot/uefi/include/mips64el/efisetjmp_arch.h diff --git a/code/boot/include/pci22.h b/code/boot/uefi/include/pci22.h similarity index 100% rename from code/boot/include/pci22.h rename to code/boot/uefi/include/pci22.h diff --git a/code/boot/include/protocol/adapterdebug.h b/code/boot/uefi/include/protocol/adapterdebug.h similarity index 100% rename from code/boot/include/protocol/adapterdebug.h rename to code/boot/uefi/include/protocol/adapterdebug.h diff --git a/code/boot/include/protocol/eficonsplit.h b/code/boot/uefi/include/protocol/eficonsplit.h similarity index 100% rename from code/boot/include/protocol/eficonsplit.h rename to code/boot/uefi/include/protocol/eficonsplit.h diff --git a/code/boot/include/protocol/efidbg.h b/code/boot/uefi/include/protocol/efidbg.h similarity index 100% rename from code/boot/include/protocol/efidbg.h rename to code/boot/uefi/include/protocol/efidbg.h diff --git a/code/boot/include/protocol/efivar.h b/code/boot/uefi/include/protocol/efivar.h similarity index 100% rename from code/boot/include/protocol/efivar.h rename to code/boot/uefi/include/protocol/efivar.h diff --git a/code/boot/include/protocol/ia64/eficontext.h b/code/boot/uefi/include/protocol/ia64/eficontext.h similarity index 100% rename from code/boot/include/protocol/ia64/eficontext.h rename to code/boot/uefi/include/protocol/ia64/eficontext.h diff --git a/code/boot/include/protocol/intload.h b/code/boot/uefi/include/protocol/intload.h similarity index 100% rename from code/boot/include/protocol/intload.h rename to code/boot/uefi/include/protocol/intload.h diff --git a/code/boot/include/protocol/legacyboot.h b/code/boot/uefi/include/protocol/legacyboot.h similarity index 100% rename from code/boot/include/protocol/legacyboot.h rename to code/boot/uefi/include/protocol/legacyboot.h diff --git a/code/boot/include/protocol/make.inf b/code/boot/uefi/include/protocol/make.inf similarity index 100% rename from code/boot/include/protocol/make.inf rename to code/boot/uefi/include/protocol/make.inf diff --git a/code/boot/include/protocol/makefile.hdr b/code/boot/uefi/include/protocol/makefile.hdr similarity index 100% rename from code/boot/include/protocol/makefile.hdr rename to code/boot/uefi/include/protocol/makefile.hdr diff --git a/code/boot/include/protocol/piflash64.h b/code/boot/uefi/include/protocol/piflash64.h similarity index 100% rename from code/boot/include/protocol/piflash64.h rename to code/boot/uefi/include/protocol/piflash64.h diff --git a/code/boot/include/protocol/readme.txt b/code/boot/uefi/include/protocol/readme.txt similarity index 100% rename from code/boot/include/protocol/readme.txt rename to code/boot/uefi/include/protocol/readme.txt diff --git a/code/boot/include/protocol/vgaclass.h b/code/boot/uefi/include/protocol/vgaclass.h similarity index 100% rename from code/boot/include/protocol/vgaclass.h rename to code/boot/uefi/include/protocol/vgaclass.h diff --git a/code/boot/include/riscv64/efibind.h b/code/boot/uefi/include/riscv64/efibind.h similarity index 100% rename from code/boot/include/riscv64/efibind.h rename to code/boot/uefi/include/riscv64/efibind.h diff --git a/code/boot/include/riscv64/efilibplat.h b/code/boot/uefi/include/riscv64/efilibplat.h similarity index 100% rename from code/boot/include/riscv64/efilibplat.h rename to code/boot/uefi/include/riscv64/efilibplat.h diff --git a/code/boot/include/riscv64/efisetjmp_arch.h b/code/boot/uefi/include/riscv64/efisetjmp_arch.h similarity index 100% rename from code/boot/include/riscv64/efisetjmp_arch.h rename to code/boot/uefi/include/riscv64/efisetjmp_arch.h diff --git a/code/boot/include/romload.h b/code/boot/uefi/include/romload.h similarity index 100% rename from code/boot/include/romload.h rename to code/boot/uefi/include/romload.h diff --git a/code/boot/include/x86_64/efibind.h b/code/boot/uefi/include/x86_64/efibind.h similarity index 100% rename from code/boot/include/x86_64/efibind.h rename to code/boot/uefi/include/x86_64/efibind.h diff --git a/code/boot/include/x86_64/efilibplat.h b/code/boot/uefi/include/x86_64/efilibplat.h similarity index 100% rename from code/boot/include/x86_64/efilibplat.h rename to code/boot/uefi/include/x86_64/efilibplat.h diff --git a/code/boot/include/x86_64/efisetjmp_arch.h b/code/boot/uefi/include/x86_64/efisetjmp_arch.h similarity index 100% rename from code/boot/include/x86_64/efisetjmp_arch.h rename to code/boot/uefi/include/x86_64/efisetjmp_arch.h diff --git a/code/boot/include/x86_64/pe.h b/code/boot/uefi/include/x86_64/pe.h similarity index 100% rename from code/boot/include/x86_64/pe.h rename to code/boot/uefi/include/x86_64/pe.h diff --git a/code/boot/main.c b/code/boot/uefi/main.c similarity index 98% rename from code/boot/main.c rename to code/boot/uefi/main.c index d7db83e..74eae96 100644 --- a/code/boot/main.c +++ b/code/boot/uefi/main.c @@ -17,9 +17,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include int _fltused = 0; @@ -395,7 +395,7 @@ EFI_STATUS LoadPeImage(UINT8* rawFile, UINT64 virtDest, EFI_PHYSICAL_ADDRESS* ou UINT8* ntHeaders = rawFile + peOff; // Validate Signature - if (*(UINT32*)ntHeaders != 0x00004550) { Print(L"no\n"); return EFI_INVALID_PARAMETER; } // "PE\0\0" + if (*(UINT32*)ntHeaders != 0x00004550) { Print(L"Signature mismatch\n"); return EFI_INVALID_PARAMETER; } // "PE\0\0" UINT16 sizeOfOptHeader = *(UINT16*)(ntHeaders + 20); UINT16 numSections = *(UINT16*)(ntHeaders + 6); @@ -581,7 +581,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable return Status; } - Print(L"1\n"); + //Print(L"1\n"); // --- Parse boot.ini --- UINTN sz; @@ -594,7 +594,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable FreePool(bootIniRaw); } - Print(L"2\n"); + //Print(L"2\n"); // --- Parse drivers/drivers.ini --- UINT8* drvIniRaw = LoadFile(L"drivers\\drivers.ini", &sz); @@ -605,7 +605,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable FreePool(drvIniRaw); } - Print(L"3\n"); + //Print(L"3\n"); BOOT_INFO* bi = AllocateZeroPool(sizeof(BOOT_INFO)); bi->Magic = BOOT_INFO_MAGIC; @@ -617,7 +617,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable // Current mapping cursor for upper half. UINT64 virtCursor = KERNEL_VIRT_BASE; - Print(L"4\n"); + //Print(L"4\n"); // --- Load and validate PE images --- typedef struct { @@ -629,11 +629,11 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable MODULE_LOAD_INFO core[] = { { L"system\\colonel.exe", "kernel.exe", NULL, KERNEL_VIRT_BASE }, - { L"system\\hal.dll", "hal.dll", NULL, 0 /* Calculated dynamically */ }, + { L"system\\hal.dll", "hal.dll", NULL, 0 /* Calculated dynamically */ }, }; for (int i = 0; i < 2; i++) { - Print(L"Loading %s...\n", core[i].path); + //Print(L"Loading %s...\n", core[i].path); UINTN rawSize; UINT8* rawBuf = LoadFile(core[i].path, &rawSize); if (!rawBuf) { @@ -683,7 +683,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable while(true); } - Print(L"5\n"); + //Print(L"5\n"); // Load driver .sys files into raw buffers for (int i = 0; i < ps.driverCount; i++) { @@ -708,7 +708,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable mod->VirtBase = 0; // Kernel will map this later } - Print(L"6\n"); + //Print(L"6\n"); // Query GOP FIRST, before the GetMemoryMap loop EFI_GRAPHICS_OUTPUT_PROTOCOL* gop; @@ -736,7 +736,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable } } - Print(L"7\n"); + //Print(L"7\n"); // --- Map physical RAM as direct window AND identity map --- UINTN mapSize = 0, descSz = 0, mapKey; UINT32 descVer; @@ -835,7 +835,7 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable Map4K(PHYS_MAP_BASE + phys, phys, 0x03); // Physical Window Map } - Print(L"8\n"); + //Print(L"8\n"); // --- Convert EFI memory map -> MEMORY_MAP --- ConvertMemoryMap(&bi->MemoryMap); @@ -880,12 +880,12 @@ EFI_STATUS EFIAPI UefiMain(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE* SystemTable } // Print it out to verify the bootloader actually found it before launching the kernel - Print(L"Found RSDP at: 0x%llx\n", bi->RsdpPhysical); + //Print(L"Found RSDP at: 0x%llx\n", bi->RsdpPhysical); bi->PhysicalMapBase = PHYS_MAP_BASE; bi->Debug = (UINT32)ps.debug; - Print(L"9\n"); + //Print(L"9\n"); // --- ExitBootServices --- gBS->GetMemoryMap(&mapSize, NULL, &mapKey, &descSz, &descVer); diff --git a/code/kernel/ini_parser.h b/code/common/include/common/ini_parser.h similarity index 100% rename from code/kernel/ini_parser.h rename to code/common/include/common/ini_parser.h diff --git a/code/kernel/printf.h b/code/common/include/common/printf.h similarity index 100% rename from code/kernel/printf.h rename to code/common/include/common/printf.h diff --git a/code/ini_parser.c b/code/common/ini_parser.c similarity index 95% rename from code/ini_parser.c rename to code/common/ini_parser.c index aa45d4e..f541b20 100644 --- a/code/ini_parser.c +++ b/code/common/ini_parser.c @@ -1,53 +1,53 @@ -// ini_parser.c - minimal [section] key=value parser -// Used by the bootloader to read boot.ini and drivers/drivers.ini. -// No heap; caller provides fixed-size output buffers. -#include -#include - -static inline int IsWs(char c) { return c == ' ' || c == '\t' || c == '\r'; } - -static char* TrimLeft(char* s) { - while (*s && IsWs(*s)) s++; - return s; -} - -static void TrimRight(char* s) { - char* e = s + strlen(s); - while (e > s && IsWs(*(e-1))) *--e = '\0'; -} - -// Parse 'buf' (null-terminated) for [section] / key=value. -// Calls cb(section, key, value, userdata) for each key found. -void IniParse(char* buf, IniCallback cb, void* userdata) { - char section[64] = ""; - char* line = buf; - - while (*line) { - char* end = line; - while (*end && *end != '\n') end++; - char saved = *end; - *end = '\0'; - - char* p = TrimLeft(line); - if (*p == '[') { - p++; - char* close = strchr(p, ']'); - if (close) { *close = '\0'; strncpy(section, p, 63); section[63] = '\0'; } - } else if (*p && *p != ';' && *p != '#') { - char* eq = strchr(p, '='); - if (eq) { - *eq = '\0'; - char* key = p; TrimRight(key); - char* val = TrimLeft(eq + 1); TrimRight(val); - cb(section, key, val, userdata); - } else { - // Key with no value (e.g., a driver filename in drivers.ini). - TrimRight(p); - if (*p) cb(section, p, "", userdata); - } - } - - *end = saved; - line = end + (*end ? 1 : 0); - } -} +// ini_parser.c - minimal [section] key=value parser +// Used by the bootloader to read boot.ini and drivers/drivers.ini. +// No heap; caller provides fixed-size output buffers. +#include +#include + +static inline int IsWs(char c) { return c == ' ' || c == '\t' || c == '\r'; } + +static char* TrimLeft(char* s) { + while (*s && IsWs(*s)) s++; + return s; +} + +static void TrimRight(char* s) { + char* e = s + strlen(s); + while (e > s && IsWs(*(e-1))) *--e = '\0'; +} + +// Parse 'buf' (null-terminated) for [section] / key=value. +// Calls cb(section, key, value, userdata) for each key found. +void IniParse(char* buf, IniCallback cb, void* userdata) { + char section[64] = ""; + char* line = buf; + + while (*line) { + char* end = line; + while (*end && *end != '\n') end++; + char saved = *end; + *end = '\0'; + + char* p = TrimLeft(line); + if (*p == '[') { + p++; + char* close = strchr(p, ']'); + if (close) { *close = '\0'; strncpy(section, p, 63); section[63] = '\0'; } + } else if (*p && *p != ';' && *p != '#') { + char* eq = strchr(p, '='); + if (eq) { + *eq = '\0'; + char* key = p; TrimRight(key); + char* val = TrimLeft(eq + 1); TrimRight(val); + cb(section, key, val, userdata); + } else { + // Key with no value (e.g., a driver filename in drivers.ini). + TrimRight(p); + if (*p) cb(section, p, "", userdata); + } + } + + *end = saved; + line = end + (*end ? 1 : 0); + } +} diff --git a/code/libc.c b/code/common/libc.c similarity index 100% rename from code/libc.c rename to code/common/libc.c diff --git a/code/printf.c b/code/common/printf.c similarity index 99% rename from code/printf.c rename to code/common/printf.c index 439f203..873f103 100644 --- a/code/printf.c +++ b/code/common/printf.c @@ -33,8 +33,8 @@ #include #include -#include "printf.h" -#include "syscall/sys_string.h" +#include +#include // define this globally (e.g. gcc -DPRINTF_INCLUDE_CONFIG_H ...) to include the diff --git a/code/drivers/usb/usb.c b/code/drivers/bus/usb/usb.c similarity index 58% rename from code/drivers/usb/usb.c rename to code/drivers/bus/usb/usb.c index 0f2bd53..9a6feb6 100644 --- a/code/drivers/usb/usb.c +++ b/code/drivers/bus/usb/usb.c @@ -1,9 +1,9 @@ -#include -#include -#include - -KSTATUS DriverEntry(const HAL_API* hal) { - (void)hal; - DbgPrint("Test runtime driver\n"); - return STATUS_SUCCESS; -} +#include +#include +#include + +KSTATUS DriverEntry(const HAL_API* hal) { + (void)hal; + DbgPrint("Test runtime driver\n"); + return STATUS_SUCCESS; +} diff --git a/code/drivers/fat32/fat32.c b/code/drivers/fs/fat32/fat32.c similarity index 99% rename from code/drivers/fat32/fat32.c rename to code/drivers/fs/fat32/fat32.c index 2fbb087..332199e 100644 --- a/code/drivers/fat32/fat32.c +++ b/code/drivers/fs/fat32/fat32.c @@ -40,15 +40,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // --------------------------------------------------------------------------- // On-disk structures diff --git a/code/drivers/lwip/README.md b/code/drivers/net/lwip/README.md similarity index 100% rename from code/drivers/lwip/README.md rename to code/drivers/net/lwip/README.md diff --git a/code/drivers/lwip/include/arch/bpstruct.h b/code/drivers/net/lwip/include/arch/bpstruct.h similarity index 100% rename from code/drivers/lwip/include/arch/bpstruct.h rename to code/drivers/net/lwip/include/arch/bpstruct.h diff --git a/code/drivers/lwip/include/arch/cc.h b/code/drivers/net/lwip/include/arch/cc.h similarity index 97% rename from code/drivers/lwip/include/arch/cc.h rename to code/drivers/net/lwip/include/arch/cc.h index 3349758..4a22cac 100644 --- a/code/drivers/lwip/include/arch/cc.h +++ b/code/drivers/net/lwip/include/arch/cc.h @@ -4,7 +4,7 @@ #include #include -#include +#include #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN 1234 diff --git a/code/drivers/lwip/include/arch/epstruct.h b/code/drivers/net/lwip/include/arch/epstruct.h similarity index 100% rename from code/drivers/lwip/include/arch/epstruct.h rename to code/drivers/net/lwip/include/arch/epstruct.h diff --git a/code/drivers/lwip/include/arch/sys_arch.h b/code/drivers/net/lwip/include/arch/sys_arch.h similarity index 100% rename from code/drivers/lwip/include/arch/sys_arch.h rename to code/drivers/net/lwip/include/arch/sys_arch.h diff --git a/code/drivers/lwip/include/lwipopts.h b/code/drivers/net/lwip/include/lwipopts.h similarity index 100% rename from code/drivers/lwip/include/lwipopts.h rename to code/drivers/net/lwip/include/lwipopts.h diff --git a/code/drivers/lwip/include/stdlib.h b/code/drivers/net/lwip/include/stdlib.h similarity index 100% rename from code/drivers/lwip/include/stdlib.h rename to code/drivers/net/lwip/include/stdlib.h diff --git a/code/drivers/lwip/lwip_sources.txt b/code/drivers/net/lwip/lwip_sources.txt similarity index 93% rename from code/drivers/lwip/lwip_sources.txt rename to code/drivers/net/lwip/lwip_sources.txt index c52744f..6555522 100644 --- a/code/drivers/lwip/lwip_sources.txt +++ b/code/drivers/net/lwip/lwip_sources.txt @@ -1,10 +1,10 @@ # Add these lwIP 2.2.1 files to the lwip.sys driver build. # Include directories required: -# code/drivers/lwip/include +# code/drivers/net/lwip/include # code/third_party/lwip/src/include # Port glue -drivers/lwip/lwip_sys_arch.c -drivers/lwip/lwip_stack.c +drivers/net/lwip/lwip_sys_arch.c +drivers/net/lwip/lwip_stack.c # lwIP core third_party/lwip/src/core/init.c diff --git a/code/drivers/lwip/lwip_stack.c b/code/drivers/net/lwip/lwip_stack.c similarity index 99% rename from code/drivers/lwip/lwip_stack.c rename to code/drivers/net/lwip/lwip_stack.c index f1ebed9..f46e6c6 100644 --- a/code/drivers/lwip/lwip_stack.c +++ b/code/drivers/net/lwip/lwip_stack.c @@ -5,16 +5,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/code/drivers/lwip/lwip_sys_arch.c b/code/drivers/net/lwip/lwip_sys_arch.c similarity index 97% rename from code/drivers/lwip/lwip_sys_arch.c rename to code/drivers/net/lwip/lwip_sys_arch.c index 696eb36..f854747 100644 --- a/code/drivers/lwip/lwip_sys_arch.c +++ b/code/drivers/net/lwip/lwip_sys_arch.c @@ -9,14 +9,14 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #define LWIP_PORT_MBOX_DEFAULT_SIZE 128u diff --git a/code/drivers/rtl8139/rtl8139.c b/code/drivers/net/rtl8139/rtl8139.c similarity index 98% rename from code/drivers/rtl8139/rtl8139.c rename to code/drivers/net/rtl8139/rtl8139.c index cd673e4..5ee7562 100644 --- a/code/drivers/rtl8139/rtl8139.c +++ b/code/drivers/net/rtl8139/rtl8139.c @@ -15,15 +15,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define RTL8139_VENDOR_REALTEK 0x10ECu #define RTL8139_DEVICE_ID 0x8139u diff --git a/code/drivers/rtl816x/rtl816x.c b/code/drivers/net/rtl816x/rtl816x.c similarity index 98% rename from code/drivers/rtl816x/rtl816x.c rename to code/drivers/net/rtl816x/rtl816x.c index 26865bb..02fb231 100644 --- a/code/drivers/rtl816x/rtl816x.c +++ b/code/drivers/net/rtl816x/rtl816x.c @@ -15,15 +15,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define RTL_VENDOR_REALTEK 0x10ECu #define RTL_DEVICE_8168 0x8168u diff --git a/code/drivers/ahci/ahci.c b/code/drivers/storage/ahci/ahci.c similarity index 99% rename from code/drivers/ahci/ahci.c rename to code/drivers/storage/ahci/ahci.c index b626f7d..6d1ff34 100644 --- a/code/drivers/ahci/ahci.c +++ b/code/drivers/storage/ahci/ahci.c @@ -43,16 +43,16 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // --------------------------------------------------------------------------- typedef enum { diff --git a/code/drivers/ide/ide.c b/code/drivers/storage/ide/ide.c similarity index 98% rename from code/drivers/ide/ide.c rename to code/drivers/storage/ide/ide.c index bb4bae4..7084fad 100644 --- a/code/drivers/ide/ide.c +++ b/code/drivers/storage/ide/ide.c @@ -28,18 +28,18 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // --------------------------------------------------------------------------- // IDE register map (primary channel, base 0x1F0) diff --git a/code/hal/hal_apic.c b/code/kernel/hal/hal_apic.c similarity index 95% rename from code/hal/hal_apic.c rename to code/kernel/hal/hal_apic.c index ed3a9cd..ab5cda2 100644 --- a/code/hal/hal_apic.c +++ b/code/kernel/hal/hal_apic.c @@ -1,74 +1,74 @@ -// hal_apic.c - Local APIC + I/O APIC -#include -#include -#include - -extern HAL_API gApi; - -// ---- Local APIC ---- -static volatile uint32_t* gLapic = (volatile uint32_t *)0; -#define LAPIC_REG(off) (*(volatile uint32_t *)((uint8_t *)gLapic + (off))) -#define LAPIC_EOI 0x0B0 -#define LAPIC_SPURIOUS 0x0F0 -#define LAPIC_ENABLE 0x100 // bit in spurious vector register - -// ---- I/O APIC ---- -static volatile uint32_t* gIoapic = (volatile uint32_t *)0; -#define IOAPIC_IDX 0x00 -#define IOAPIC_DATA 0x10 - -static uint32_t IoapicRead(uint8_t reg) { - *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_IDX) = reg; - return *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_DATA); -} -static void IoapicWrite(uint8_t reg, uint32_t val) { - *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_IDX) = reg; - *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_DATA) = val; -} - -// IRQ n -> redirection table at register 0x10 + 2*n (low), 0x11 + 2*n (high). -#define IOREDTBL_LO(n) (0x10 + 2*(n)) -#define IOREDTBL_HI(n) (0x11 + 2*(n)) -// Interrupt vector base: IRQ 0 -> vector 0x20, IRQ 1 -> 0x21, ... -#define IRQ_VECTOR_BASE 0x20 - -void HalApicRouteIrq(uint8_t irq) { - // Full initial setup of the redirection entry. - // Sets the vector and clears the mask bit in one write. - uint32_t vector = IRQ_VECTOR_BASE + irq; // e.g. IRQ 1 -> vector 0x21 - IoapicWrite(IOREDTBL_LO(irq), vector); // unmasked (bit 16 = 0), edge, fixed - IoapicWrite(IOREDTBL_HI(irq), 0); // deliver to LAPIC id 0 -} - -void HalApicMaskIrq(uint8_t irq) { - uint32_t lo = IoapicRead(IOREDTBL_LO(irq)); - lo |= (1 << 16); - IoapicWrite(IOREDTBL_LO(irq), lo); -} - -void HalApicUnmaskIrq(uint8_t irq) { - uint32_t lo = IoapicRead(IOREDTBL_LO(irq)); - lo &= ~(1 << 16); // clear mask bit - lo = (lo & ~0xFF) | (IRQ_VECTOR_BASE + irq); - IoapicWrite(IOREDTBL_LO(irq), lo); - IoapicWrite(IOREDTBL_HI(irq), 0); // LAPIC id 0 -} - -void HalApicSendEoi(void) { - LAPIC_REG(LAPIC_EOI) = 0; -} - -void HalApicInitialize(uintptr_t lapicPhys, uintptr_t ioapicPhys) { - gLapic = (volatile uint32_t *)(gApi.PhysToVirt(lapicPhys)); - gIoapic = (volatile uint32_t *)(gApi.PhysToVirt(ioapicPhys)); - - // Enable Local APIC, set spurious vector to 0xFF. - LAPIC_REG(LAPIC_SPURIOUS) = LAPIC_ENABLE | 0xFF; - - // Mask all IOAPIC lines initially. - uint32_t maxRedir = (IoapicRead(1) >> 16) & 0xFF; - for (uint8_t i = 0; i <= maxRedir; i++) { - IoapicWrite(IOREDTBL_LO(i), (1 << 16) | (IRQ_VECTOR_BASE + i)); - IoapicWrite(IOREDTBL_HI(i), 0); - } -} +// hal_apic.c - Local APIC + I/O APIC +#include +#include +#include + +extern HAL_API gApi; + +// ---- Local APIC ---- +static volatile uint32_t* gLapic = (volatile uint32_t *)0; +#define LAPIC_REG(off) (*(volatile uint32_t *)((uint8_t *)gLapic + (off))) +#define LAPIC_EOI 0x0B0 +#define LAPIC_SPURIOUS 0x0F0 +#define LAPIC_ENABLE 0x100 // bit in spurious vector register + +// ---- I/O APIC ---- +static volatile uint32_t* gIoapic = (volatile uint32_t *)0; +#define IOAPIC_IDX 0x00 +#define IOAPIC_DATA 0x10 + +static uint32_t IoapicRead(uint8_t reg) { + *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_IDX) = reg; + return *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_DATA); +} +static void IoapicWrite(uint8_t reg, uint32_t val) { + *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_IDX) = reg; + *(volatile uint32_t *)((uint8_t *)gIoapic + IOAPIC_DATA) = val; +} + +// IRQ n -> redirection table at register 0x10 + 2*n (low), 0x11 + 2*n (high). +#define IOREDTBL_LO(n) (0x10 + 2*(n)) +#define IOREDTBL_HI(n) (0x11 + 2*(n)) +// Interrupt vector base: IRQ 0 -> vector 0x20, IRQ 1 -> 0x21, ... +#define IRQ_VECTOR_BASE 0x20 + +void HalApicRouteIrq(uint8_t irq) { + // Full initial setup of the redirection entry. + // Sets the vector and clears the mask bit in one write. + uint32_t vector = IRQ_VECTOR_BASE + irq; // e.g. IRQ 1 -> vector 0x21 + IoapicWrite(IOREDTBL_LO(irq), vector); // unmasked (bit 16 = 0), edge, fixed + IoapicWrite(IOREDTBL_HI(irq), 0); // deliver to LAPIC id 0 +} + +void HalApicMaskIrq(uint8_t irq) { + uint32_t lo = IoapicRead(IOREDTBL_LO(irq)); + lo |= (1 << 16); + IoapicWrite(IOREDTBL_LO(irq), lo); +} + +void HalApicUnmaskIrq(uint8_t irq) { + uint32_t lo = IoapicRead(IOREDTBL_LO(irq)); + lo &= ~(1 << 16); // clear mask bit + lo = (lo & ~0xFF) | (IRQ_VECTOR_BASE + irq); + IoapicWrite(IOREDTBL_LO(irq), lo); + IoapicWrite(IOREDTBL_HI(irq), 0); // LAPIC id 0 +} + +void HalApicSendEoi(void) { + LAPIC_REG(LAPIC_EOI) = 0; +} + +void HalApicInitialize(uintptr_t lapicPhys, uintptr_t ioapicPhys) { + gLapic = (volatile uint32_t *)(gApi.PhysToVirt(lapicPhys)); + gIoapic = (volatile uint32_t *)(gApi.PhysToVirt(ioapicPhys)); + + // Enable Local APIC, set spurious vector to 0xFF. + LAPIC_REG(LAPIC_SPURIOUS) = LAPIC_ENABLE | 0xFF; + + // Mask all IOAPIC lines initially. + uint32_t maxRedir = (IoapicRead(1) >> 16) & 0xFF; + for (uint8_t i = 0; i <= maxRedir; i++) { + IoapicWrite(IOREDTBL_LO(i), (1 << 16) | (IRQ_VECTOR_BASE + i)); + IoapicWrite(IOREDTBL_HI(i), 0); + } +} diff --git a/code/hal/hal_disk.c b/code/kernel/hal/hal_disk.c similarity index 100% rename from code/hal/hal_disk.c rename to code/kernel/hal/hal_disk.c diff --git a/code/hal/hal_keyboard.c b/code/kernel/hal/hal_keyboard.c similarity index 96% rename from code/hal/hal_keyboard.c rename to code/kernel/hal/hal_keyboard.c index fe7af4d..2ed4581 100644 --- a/code/hal/hal_keyboard.c +++ b/code/kernel/hal/hal_keyboard.c @@ -1,204 +1,204 @@ -// hal_keyboard.c - PS/2 keyboard, interrupt-driven, with live state tracking -#include -#include -#include -#include - -// -- Port addresses ------------------------------------------------------------ -#define PS2_DATA 0x60u -#define PS2_STAT 0x64u -#define PS2_CMD 0x64u - -// -- Ring buffer (for ASCII/typing) ------------------------------------------- -#define KBD_BUF_SIZE 256u -#define KBD_BUF_MASK (KBD_BUF_SIZE - 1u) - -static uint8_t gBuf[KBD_BUF_SIZE]; -static volatile int gHead = 0; -static volatile int gTail = 0; - -// -- Deferred callback queue --------------------------------------------------- -// The hard IRQ path updates the key state and stores completed make codes. -// Optional client callbacks are delivered later from the kernel-queued DPC, -// never directly from DIRQL/ISR context. -#define KBD_DPC_BUF_SIZE 128u -#define KBD_DPC_BUF_MASK (KBD_DPC_BUF_SIZE - 1u) - -static uint8_t gDpcBuf[KBD_DPC_BUF_SIZE]; -static volatile int gDpcHead = 0; -static volatile int gDpcTail = 0; - -// -- Live Key State (for GetAsyncKeyState) ------------------------------------ -// These arrays track whether a key is currently held down. -static volatile uint8_t gKeyState[128]; // Standard scan codes -static volatile uint8_t gKeyStateExt[128]; // Extended (E0) scan codes - -// -- Scan-code set 1 constants ------------------------------------------------- -#define SC1_BREAK_BIT 0x80u -#define SC1_MAKE_MASK 0x7Fu -#define SC1_EXT_PREFIX 0xE0u - -// -- Modifier flags ------------------------------------------------------------ -#define MOD_LSHIFT (1u << 0) -#define MOD_RSHIFT (1u << 1) -#define MOD_LCTRL (1u << 2) -#define MOD_RCTRL (1u << 3) -#define MOD_LALT (1u << 4) -#define MOD_RALT (1u << 5) -#define MOD_CAPS (1u << 6) -#define MOD_NUMLOCK (1u << 7) - -#define MOD_SHIFT (MOD_LSHIFT | MOD_RSHIFT) -#define MOD_CTRL (MOD_LCTRL | MOD_RCTRL) -#define MOD_ALT (MOD_LALT | MOD_RALT) - -static volatile uint32_t gModifiers = 0; -static volatile bool gNextExtended = false; -static void (* volatile gCallback)(uint8_t) = NULL; - -// -- ASCII Translation Tables -------------------------------------------------- -static const char gUnshifted[128] = { - 0, 0, '1','2','3','4','5','6','7','8','9','0','-','=','\b','\t', - 'q','w','e','r','t','y','u','i','o','p','[',']','\n', 0, 'a','s', - 'd','f','g','h','j','k','l',';','\'','`', 0, '\\','z','x','c','v', - 'b','n','m',',','.','/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, '7','8','9','-', '4','5','6','+', '1','2','3','0','.' -}; - -static const char gShifted[128] = { - 0, 0, '!','@','#','$','%','^','&','*','(',')','_','+','\b','\t', - 'Q','W','E','R','T','Y','U','I','O','P','{','}','\n', 0, 'A','S', - 'D','F','G','H','J','K','L',':','"','~', 0, '|','Z','X','C','V', - 'B','N','M','<','>','?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, '7','8','9','-', '4','5','6','+', '1','2','3','0','.' -}; - -// -- Deferred callback delivery ------------------------------------------------ -static void KbdDpc(void) { - for (;;) { - if (gDpcHead == gDpcTail) - break; - - uint8_t make = gDpcBuf[gDpcHead]; - gDpcHead = (gDpcHead + 1) & (int)KBD_DPC_BUF_MASK; - - void (*cb)(uint8_t) = (void (*)(uint8_t))gCallback; - if (cb) - cb(make); - } -} - -// -- ISR: The Engine ----------------------------------------------------------- -void KbdIsr(void) { - uint8_t sc = __inbyte(PS2_DATA); - - if (sc == SC1_EXT_PREFIX) { - gNextExtended = true; - return; - } - - bool extended = gNextExtended; - bool is_break = (sc & SC1_BREAK_BIT) != 0; - uint8_t make = sc & SC1_MAKE_MASK; - gNextExtended = false; - - // Update the live state arrays - if (extended) { - gKeyStateExt[make] = is_break ? 0 : 1; - } else { - gKeyState[make] = is_break ? 0 : 1; - } - - // Update modifiers - if (!extended) { - switch (make) { - case 0x2A: gModifiers = is_break ? (gModifiers & ~MOD_LSHIFT) : (gModifiers | MOD_LSHIFT); break; - case 0x36: gModifiers = is_break ? (gModifiers & ~MOD_RSHIFT) : (gModifiers | MOD_RSHIFT); break; - case 0x1D: gModifiers = is_break ? (gModifiers & ~MOD_LCTRL) : (gModifiers | MOD_LCTRL); break; - case 0x38: gModifiers = is_break ? (gModifiers & ~MOD_LALT) : (gModifiers | MOD_LALT); break; - case 0x3A: if (!is_break) gModifiers ^= MOD_CAPS; break; - case 0x45: if (!is_break) gModifiers ^= MOD_NUMLOCK; break; - } - } else { - switch (make) { - case 0x1D: gModifiers = is_break ? (gModifiers & ~MOD_RCTRL) : (gModifiers | MOD_RCTRL); break; - case 0x38: gModifiers = is_break ? (gModifiers & ~MOD_RALT) : (gModifiers | MOD_RALT); break; - } - } - - // Buffer management (only for 'make' codes) - if (!is_break) { - int next = (gTail + 1) & (int)KBD_BUF_MASK; - if (next != gHead) { - gBuf[gTail] = make; - gTail = next; - } - - // Queue optional callback delivery to the DPC path. Keep a separate - // callback queue so the public ReadScancode ring remains independent. - if (gCallback) { - int dpcNext = (gDpcTail + 1) & (int)KBD_DPC_BUF_MASK; - if (dpcNext != gDpcHead) { - gDpcBuf[gDpcTail] = make; - gDpcTail = dpcNext; - } - } - } -} - -// -- Public API ---------------------------------------------------------------- - -// Use this inside your GetAsyncKeyState implementation! -bool KbdIsKeyDown(uint8_t scancode, bool extended) { - if (extended) return gKeyStateExt[scancode & 0x7F] != 0; - return gKeyState[scancode & 0x7F] != 0; -} - -static uint8_t KbdPoll(void) { - return (gHead == gTail) ? 0 : gBuf[gHead]; -} - -static uint8_t KbdReadScancode(void) { - while (gHead == gTail) { _mm_pause(); } - uint8_t sc = gBuf[gHead]; - gHead = (gHead + 1) & (int)KBD_BUF_MASK; - return sc; -} - -static char KbdReadChar(void) { - uint8_t make = KbdReadScancode(); - if (make >= 128) return 0; - - uint32_t mods = gModifiers; - bool shifted = (mods & MOD_SHIFT) != 0; - - if (mods & MOD_CAPS) { - char base = gUnshifted[make]; - if (base >= 'a' && base <= 'z') shifted = !shifted; - } - return shifted ? gShifted[make] : gUnshifted[make]; -} - -static uint32_t KbdGetModifiers(void) { - return gModifiers; -} - -static void KbdSetCallback(void (*cb)(uint8_t scancode)) { - gCallback = cb; -} - -void HalKeyboardInitialize(HAL_KEYBOARD *out) { - while (__inbyte(PS2_STAT) & 2); - __outbyte(PS2_CMD, 0xA8); - while (__inbyte(PS2_STAT) & 1) { __inbyte(PS2_DATA); } - - out->Poll = KbdPoll; - out->ReadScancode = KbdReadScancode; - out->ReadChar = KbdReadChar; - out->GetModifiers = KbdGetModifiers; - out->SetCallback = KbdSetCallback; - out->IsKeyDown = KbdIsKeyDown; - out->Isr = KbdIsr; - out->Dpc = KbdDpc; - out->IrqNumber = 1; -} +// hal_keyboard.c - PS/2 keyboard, interrupt-driven, with live state tracking +#include +#include +#include +#include + +// -- Port addresses ------------------------------------------------------------ +#define PS2_DATA 0x60u +#define PS2_STAT 0x64u +#define PS2_CMD 0x64u + +// -- Ring buffer (for ASCII/typing) ------------------------------------------- +#define KBD_BUF_SIZE 256u +#define KBD_BUF_MASK (KBD_BUF_SIZE - 1u) + +static uint8_t gBuf[KBD_BUF_SIZE]; +static volatile int gHead = 0; +static volatile int gTail = 0; + +// -- Deferred callback queue --------------------------------------------------- +// The hard IRQ path updates the key state and stores completed make codes. +// Optional client callbacks are delivered later from the kernel-queued DPC, +// never directly from DIRQL/ISR context. +#define KBD_DPC_BUF_SIZE 128u +#define KBD_DPC_BUF_MASK (KBD_DPC_BUF_SIZE - 1u) + +static uint8_t gDpcBuf[KBD_DPC_BUF_SIZE]; +static volatile int gDpcHead = 0; +static volatile int gDpcTail = 0; + +// -- Live Key State (for GetAsyncKeyState) ------------------------------------ +// These arrays track whether a key is currently held down. +static volatile uint8_t gKeyState[128]; // Standard scan codes +static volatile uint8_t gKeyStateExt[128]; // Extended (E0) scan codes + +// -- Scan-code set 1 constants ------------------------------------------------- +#define SC1_BREAK_BIT 0x80u +#define SC1_MAKE_MASK 0x7Fu +#define SC1_EXT_PREFIX 0xE0u + +// -- Modifier flags ------------------------------------------------------------ +#define MOD_LSHIFT (1u << 0) +#define MOD_RSHIFT (1u << 1) +#define MOD_LCTRL (1u << 2) +#define MOD_RCTRL (1u << 3) +#define MOD_LALT (1u << 4) +#define MOD_RALT (1u << 5) +#define MOD_CAPS (1u << 6) +#define MOD_NUMLOCK (1u << 7) + +#define MOD_SHIFT (MOD_LSHIFT | MOD_RSHIFT) +#define MOD_CTRL (MOD_LCTRL | MOD_RCTRL) +#define MOD_ALT (MOD_LALT | MOD_RALT) + +static volatile uint32_t gModifiers = 0; +static volatile bool gNextExtended = false; +static void (* volatile gCallback)(uint8_t) = NULL; + +// -- ASCII Translation Tables -------------------------------------------------- +static const char gUnshifted[128] = { + 0, 0, '1','2','3','4','5','6','7','8','9','0','-','=','\b','\t', + 'q','w','e','r','t','y','u','i','o','p','[',']','\n', 0, 'a','s', + 'd','f','g','h','j','k','l',';','\'','`', 0, '\\','z','x','c','v', + 'b','n','m',',','.','/', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, '7','8','9','-', '4','5','6','+', '1','2','3','0','.' +}; + +static const char gShifted[128] = { + 0, 0, '!','@','#','$','%','^','&','*','(',')','_','+','\b','\t', + 'Q','W','E','R','T','Y','U','I','O','P','{','}','\n', 0, 'A','S', + 'D','F','G','H','J','K','L',':','"','~', 0, '|','Z','X','C','V', + 'B','N','M','<','>','?', 0, '*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, '7','8','9','-', '4','5','6','+', '1','2','3','0','.' +}; + +// -- Deferred callback delivery ------------------------------------------------ +static void KbdDpc(void) { + for (;;) { + if (gDpcHead == gDpcTail) + break; + + uint8_t make = gDpcBuf[gDpcHead]; + gDpcHead = (gDpcHead + 1) & (int)KBD_DPC_BUF_MASK; + + void (*cb)(uint8_t) = (void (*)(uint8_t))gCallback; + if (cb) + cb(make); + } +} + +// -- ISR: The Engine ----------------------------------------------------------- +void KbdIsr(void) { + uint8_t sc = __inbyte(PS2_DATA); + + if (sc == SC1_EXT_PREFIX) { + gNextExtended = true; + return; + } + + bool extended = gNextExtended; + bool is_break = (sc & SC1_BREAK_BIT) != 0; + uint8_t make = sc & SC1_MAKE_MASK; + gNextExtended = false; + + // Update the live state arrays + if (extended) { + gKeyStateExt[make] = is_break ? 0 : 1; + } else { + gKeyState[make] = is_break ? 0 : 1; + } + + // Update modifiers + if (!extended) { + switch (make) { + case 0x2A: gModifiers = is_break ? (gModifiers & ~MOD_LSHIFT) : (gModifiers | MOD_LSHIFT); break; + case 0x36: gModifiers = is_break ? (gModifiers & ~MOD_RSHIFT) : (gModifiers | MOD_RSHIFT); break; + case 0x1D: gModifiers = is_break ? (gModifiers & ~MOD_LCTRL) : (gModifiers | MOD_LCTRL); break; + case 0x38: gModifiers = is_break ? (gModifiers & ~MOD_LALT) : (gModifiers | MOD_LALT); break; + case 0x3A: if (!is_break) gModifiers ^= MOD_CAPS; break; + case 0x45: if (!is_break) gModifiers ^= MOD_NUMLOCK; break; + } + } else { + switch (make) { + case 0x1D: gModifiers = is_break ? (gModifiers & ~MOD_RCTRL) : (gModifiers | MOD_RCTRL); break; + case 0x38: gModifiers = is_break ? (gModifiers & ~MOD_RALT) : (gModifiers | MOD_RALT); break; + } + } + + // Buffer management (only for 'make' codes) + if (!is_break) { + int next = (gTail + 1) & (int)KBD_BUF_MASK; + if (next != gHead) { + gBuf[gTail] = make; + gTail = next; + } + + // Queue optional callback delivery to the DPC path. Keep a separate + // callback queue so the public ReadScancode ring remains independent. + if (gCallback) { + int dpcNext = (gDpcTail + 1) & (int)KBD_DPC_BUF_MASK; + if (dpcNext != gDpcHead) { + gDpcBuf[gDpcTail] = make; + gDpcTail = dpcNext; + } + } + } +} + +// -- Public API ---------------------------------------------------------------- + +// Use this inside your GetAsyncKeyState implementation! +bool KbdIsKeyDown(uint8_t scancode, bool extended) { + if (extended) return gKeyStateExt[scancode & 0x7F] != 0; + return gKeyState[scancode & 0x7F] != 0; +} + +static uint8_t KbdPoll(void) { + return (gHead == gTail) ? 0 : gBuf[gHead]; +} + +static uint8_t KbdReadScancode(void) { + while (gHead == gTail) { _mm_pause(); } + uint8_t sc = gBuf[gHead]; + gHead = (gHead + 1) & (int)KBD_BUF_MASK; + return sc; +} + +static char KbdReadChar(void) { + uint8_t make = KbdReadScancode(); + if (make >= 128) return 0; + + uint32_t mods = gModifiers; + bool shifted = (mods & MOD_SHIFT) != 0; + + if (mods & MOD_CAPS) { + char base = gUnshifted[make]; + if (base >= 'a' && base <= 'z') shifted = !shifted; + } + return shifted ? gShifted[make] : gUnshifted[make]; +} + +static uint32_t KbdGetModifiers(void) { + return gModifiers; +} + +static void KbdSetCallback(void (*cb)(uint8_t scancode)) { + gCallback = cb; +} + +void HalKeyboardInitialize(HAL_KEYBOARD *out) { + while (__inbyte(PS2_STAT) & 2); + __outbyte(PS2_CMD, 0xA8); + while (__inbyte(PS2_STAT) & 1) { __inbyte(PS2_DATA); } + + out->Poll = KbdPoll; + out->ReadScancode = KbdReadScancode; + out->ReadChar = KbdReadChar; + out->GetModifiers = KbdGetModifiers; + out->SetCallback = KbdSetCallback; + out->IsKeyDown = KbdIsKeyDown; + out->Isr = KbdIsr; + out->Dpc = KbdDpc; + out->IrqNumber = 1; +} diff --git a/code/hal/hal_main.c b/code/kernel/hal/hal_main.c similarity index 99% rename from code/hal/hal_main.c rename to code/kernel/hal/hal_main.c index 27256e8..dfa9c62 100644 --- a/code/hal/hal_main.c +++ b/code/kernel/hal/hal_main.c @@ -1,11 +1,11 @@ // hal_main.c - HAL initialisation and HalGetApi -#include -#include +#include +#include #include #include #include #include -#include +#include // Declared in other hal_*.c files: void HalScreenInitialize(uintptr_t fb, int w, int h, int stride, HAL_SCREEN* out); diff --git a/code/hal/hal_mouse.c b/code/kernel/hal/hal_mouse.c similarity index 99% rename from code/hal/hal_mouse.c rename to code/kernel/hal/hal_mouse.c index 4f248d8..ca76fd5 100644 --- a/code/hal/hal_mouse.c +++ b/code/kernel/hal/hal_mouse.c @@ -26,8 +26,8 @@ #include #include #include -#include -#include +#include +#include // -- PS/2 port addresses ------------------------------------------------------- #define PS2_DATA 0x60u diff --git a/code/hal/hal_pci.c b/code/kernel/hal/hal_pci.c similarity index 96% rename from code/hal/hal_pci.c rename to code/kernel/hal/hal_pci.c index 5d9f6e5..7b55ede 100644 --- a/code/hal/hal_pci.c +++ b/code/kernel/hal/hal_pci.c @@ -1,70 +1,70 @@ -// hal_pci.c - PCI configuration space via Mechanism 1 port I/O -#include -#include - -#define PCI_CONFIG_ADDR 0xCF8 -#define PCI_CONFIG_DATA 0xCFC - -static uint32_t MakeAddr(uint8_t bus, uint8_t dev, uint8_t fn, uint8_t reg) { - return 0x80000000UL - | ((uint32_t)bus << 16) - | ((uint32_t)(dev & 0x1F) << 11) - | ((uint32_t)(fn & 0x07) << 8) - | (reg & 0xFC); -} - -static uint32_t PciRead32(uint8_t bus, uint8_t dev, uint8_t fn, uint8_t reg) { - __outdword(PCI_CONFIG_ADDR, MakeAddr(bus, dev, fn, reg)); - return __indword(PCI_CONFIG_DATA); -} - -static void PciWrite32(uint8_t bus, uint8_t dev, uint8_t fn, - uint8_t reg, uint32_t val) { - __outdword(PCI_CONFIG_ADDR, MakeAddr(bus, dev, fn, reg)); - __outdword(PCI_CONFIG_DATA, val); -} - -static bool PciFindDevice(uint16_t vendor, uint16_t device, - uint8_t* outBus, uint8_t* outDev, uint8_t* outFn) { - for (int bus = 0; bus < 256; bus++) - for (int dev = 0; dev < 32; dev++) - for (int fn = 0; fn < 8; fn++) { - uint32_t id = PciRead32((uint8_t)bus, (uint8_t)dev, (uint8_t)fn, 0); - if ((id & 0xFFFF) == vendor && (id >> 16) == device) { - *outBus = (uint8_t)bus; *outDev = (uint8_t)dev; *outFn = (uint8_t)fn; - return true; - } - } - return false; -} - -static bool PciFindClass(uint8_t classCode, uint8_t subclass, - uint8_t* outBus, uint8_t* outDev, uint8_t* outFn) { - for (int bus = 0; bus < 256; bus++) - for (int dev = 0; dev < 32; dev++) - for (int fn = 0; fn < 8; fn++) { - uint32_t id = PciRead32((uint8_t)bus,(uint8_t)dev,(uint8_t)fn,0); - if ((id & 0xFFFF) == 0xFFFF) continue; // no device - uint32_t cc = PciRead32((uint8_t)bus,(uint8_t)dev,(uint8_t)fn,8); - if (((cc >> 24) & 0xFF) == classCode && - ((cc >> 16) & 0xFF) == subclass) { - *outBus = (uint8_t)bus; *outDev = (uint8_t)dev; *outFn = (uint8_t)fn; - return true; - } - } - return false; -} - -static uint8_t PciGetIrqLine(uint8_t bus, uint8_t dev, uint8_t fn) { - // PCI config register 0x3C: byte 0 = IRQ line, byte 1 = IRQ pin - uint32_t val = PciRead32(bus, dev, fn, 0x3C); - return (uint8_t)(val & 0xFF); // 0xFF = not connected -} - -void HalPciInitialize(HAL_PCI* out) { - out->Read32 = PciRead32; - out->Write32 = PciWrite32; - out->FindDevice = PciFindDevice; - out->FindClass = PciFindClass; - out->GetIrqLine = PciGetIrqLine; -} +// hal_pci.c - PCI configuration space via Mechanism 1 port I/O +#include +#include + +#define PCI_CONFIG_ADDR 0xCF8 +#define PCI_CONFIG_DATA 0xCFC + +static uint32_t MakeAddr(uint8_t bus, uint8_t dev, uint8_t fn, uint8_t reg) { + return 0x80000000UL + | ((uint32_t)bus << 16) + | ((uint32_t)(dev & 0x1F) << 11) + | ((uint32_t)(fn & 0x07) << 8) + | (reg & 0xFC); +} + +static uint32_t PciRead32(uint8_t bus, uint8_t dev, uint8_t fn, uint8_t reg) { + __outdword(PCI_CONFIG_ADDR, MakeAddr(bus, dev, fn, reg)); + return __indword(PCI_CONFIG_DATA); +} + +static void PciWrite32(uint8_t bus, uint8_t dev, uint8_t fn, + uint8_t reg, uint32_t val) { + __outdword(PCI_CONFIG_ADDR, MakeAddr(bus, dev, fn, reg)); + __outdword(PCI_CONFIG_DATA, val); +} + +static bool PciFindDevice(uint16_t vendor, uint16_t device, + uint8_t* outBus, uint8_t* outDev, uint8_t* outFn) { + for (int bus = 0; bus < 256; bus++) + for (int dev = 0; dev < 32; dev++) + for (int fn = 0; fn < 8; fn++) { + uint32_t id = PciRead32((uint8_t)bus, (uint8_t)dev, (uint8_t)fn, 0); + if ((id & 0xFFFF) == vendor && (id >> 16) == device) { + *outBus = (uint8_t)bus; *outDev = (uint8_t)dev; *outFn = (uint8_t)fn; + return true; + } + } + return false; +} + +static bool PciFindClass(uint8_t classCode, uint8_t subclass, + uint8_t* outBus, uint8_t* outDev, uint8_t* outFn) { + for (int bus = 0; bus < 256; bus++) + for (int dev = 0; dev < 32; dev++) + for (int fn = 0; fn < 8; fn++) { + uint32_t id = PciRead32((uint8_t)bus,(uint8_t)dev,(uint8_t)fn,0); + if ((id & 0xFFFF) == 0xFFFF) continue; // no device + uint32_t cc = PciRead32((uint8_t)bus,(uint8_t)dev,(uint8_t)fn,8); + if (((cc >> 24) & 0xFF) == classCode && + ((cc >> 16) & 0xFF) == subclass) { + *outBus = (uint8_t)bus; *outDev = (uint8_t)dev; *outFn = (uint8_t)fn; + return true; + } + } + return false; +} + +static uint8_t PciGetIrqLine(uint8_t bus, uint8_t dev, uint8_t fn) { + // PCI config register 0x3C: byte 0 = IRQ line, byte 1 = IRQ pin + uint32_t val = PciRead32(bus, dev, fn, 0x3C); + return (uint8_t)(val & 0xFF); // 0xFF = not connected +} + +void HalPciInitialize(HAL_PCI* out) { + out->Read32 = PciRead32; + out->Write32 = PciWrite32; + out->FindDevice = PciFindDevice; + out->FindClass = PciFindClass; + out->GetIrqLine = PciGetIrqLine; +} diff --git a/code/hal/hal_screen.c b/code/kernel/hal/hal_screen.c similarity index 97% rename from code/hal/hal_screen.c rename to code/kernel/hal/hal_screen.c index 2a44be6..b2c79ce 100644 --- a/code/hal/hal_screen.c +++ b/code/kernel/hal/hal_screen.c @@ -1,285 +1,285 @@ -// hal_screen.c - GOP framebuffer screen driver with embedded 8x16 font -// -// The 8x16 bitmap font is a standard VGA/PC font. We embed just the -// printable ASCII range (0x20–0x7E). Each glyph is 16 bytes; bit 7 of -// each byte is the leftmost pixel. -#include -#include -#include -#include - -static uint32_t* gFb = (uint32_t *)0; -static int gWidth = 0; -static int gHeight = 0; -static int gStride = 0; // pixels per row -static int gCursorX = 0, gCursorY = 0; - -#define FONT_W 8 -#define FONT_H 16 - -// --------------------------------------------------------------------------- -// 8x16 VGA font - printable ASCII only (glyph 0 = space = 0x20) -// --------------------------------------------------------------------------- -#include "font8x16.h" // see font8x16.h below - -// --------------------------------------------------------------------------- -// Internals -// --------------------------------------------------------------------------- -static inline void PutPixelRaw(int x, int y, uint32_t color) { - if ((unsigned)x < (unsigned)gWidth && (unsigned)y < (unsigned)gHeight) - gFb[y * gStride + x] = color; -} - -// --------------------------------------------------------------------------- -// HAL_SCREEN implementations -// --------------------------------------------------------------------------- -static void ScreenClear(uint32_t color) { - for (int y = 0; y < gHeight; y++) - for (int x = 0; x < gWidth; x++) - gFb[y * gStride + x] = color; - gCursorX = 0; gCursorY = 0; -} - -static void ScreenPutPixel(int x, int y, uint32_t color) { - PutPixelRaw(x, y, color); -} - -static void ScreenBlit(int x, int y, int w, int h, const uint32_t* pixels) { - // Calculate clipping bounds - int startX = (x < 0) ? 0 : x; - int startY = (y < 0) ? 0 : y; - int endX = (x + w > gWidth) ? gWidth : (x + w); - int endY = (y + h > gHeight) ? gHeight : (y + h); - - int drawW = endX - startX; - int drawH = endY - startY; - - // If the image is entirely off-screen, do nothing - if (drawW <= 0 || drawH <= 0) { - return; - } - - // Adjust the source pointer if the image was clipped on the top or left - int srcOffsetX = startX - x; - int srcOffsetY = startY - y; - - // Calculate bytes to copy per row - size_t bytesPerRow = (size_t)drawW * sizeof(uint32_t); - - // If the width we are drawing exactly matches the physical screen stride, - // AND it matches the original source image width, memory is perfectly contiguous. - if (drawW == gStride && drawW == w) { - uint32_t* dst = gFb + (startY * gStride) + startX; - const uint32_t* src = pixels + (srcOffsetY * w) + srcOffsetX; - - memcpy(dst, src, bytesPerRow * drawH); - return; - } - - // Copy row-by-row - for (int row = 0; row < drawH; row++) { - // Destination in the actual framebuffer (accounting for stride) - uint32_t* dst = gFb + ((startY + row) * gStride) + startX; - - // Source from the provided pixel buffer - const uint32_t* src = pixels + ((srcOffsetY + row) * w) + srcOffsetX; - - memcpy(dst, src, bytesPerRow); - } -} - -static void ScreenGetSize(int* w, int* h) { *w = gWidth; *h = gHeight; } - -static void ScreenScroll(int lines) { - if (lines <= 0 || lines >= gHeight) { ScreenClear(0); return; } - int rowBytes = gStride * sizeof(uint32_t); - memmove(gFb, gFb + lines * gStride, - (size_t)(gHeight - lines) * rowBytes); - // Clear the revealed rows at the bottom. - memset(gFb + (gHeight - lines) * gStride, 0, - (size_t)lines * rowBytes); -} - -static void ScreenPutChar(char c, int x, int y, uint32_t fg, uint32_t bg) { - if ((unsigned char)c < 0x20 || (unsigned char)c > 0x7E) c = '?'; - const uint8_t* glyph = Font8x16 + ((unsigned char)c - 0x20) * 16; - for (int row = 0; row < 16; row++) { - uint8_t bits = glyph[row]; - for (int col = 0; col < 8; col++) { - uint32_t color = (bits & (1 << col)) ? fg : bg; // i don't know why, i don't want to know why - // i shouldn't have to wonder why but the font is backwards unless we do this terriblness - PutPixelRaw(x + col, y + row, color); - } - } -} - -static void ScreenPrintChar(char c, uint32_t fg, uint32_t bg) { - int cols = gWidth / FONT_W; - int rows = gHeight / FONT_H; - - // Mirror to serial - while ((__inbyte(0x3FD) & 0x20) == 0); - if (c == '\n') __outbyte(0x3F8, '\r'); - __outbyte(0x3F8, c); - - if (c == '\n') { - gCursorX = 0; - gCursorY++; - } else if (c == '\r') { - gCursorX = 0; - } else if (c == '\b') { - if (gCursorX > 0) { - gCursorX--; - } else if (gCursorY > 0) { - gCursorY--; - gCursorX = cols - 1; - } - } else { - ScreenPutChar(c, gCursorX * FONT_W, gCursorY * FONT_H, fg, bg); - if (++gCursorX >= cols) { gCursorX = 0; gCursorY++; } - } - if (gCursorY >= rows) { - ScreenScroll(FONT_H); - gCursorY = rows - 1; - } -} - -// --------------------------------------------------------------------------- -// Mouse cursor – 12×19 monochrome arrow sprite -// 0 = transparent 1 = black outline 2 = white fill -// The hotspot is at (0,0) (top-left pixel = tip of the arrow). -// --------------------------------------------------------------------------- -#define CURSOR_W 16 -#define CURSOR_H 25 - -// Each entry is 0xAARRGGBB stored as a uint32_t. -// Pixels with brightness < 24 are fully transparent. -static const unsigned int gCursorPixels[CURSOR_H][CURSOR_W] = { - { 0x7F575757, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFAFAFA, 0x855D5D5D, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFEFEFE, 0xFFFFFFFF, 0x865E5E5E, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFDFDFD, 0xFFFDFDFD, 0xFFFFFFFF, 0x8A626262, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x8D656565, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x8E666666, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x91696969, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x946C6C6C, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x956D6D6D, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x99717171, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x9B737373, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x9D757575, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0xA0787878, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFDFDFD, 0xFFFDFDFD, 0xFFFCFCFC, 0xFFF9F9F9, 0xFFFFFFFF, 0xA1797979, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFEFEFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xAE868686, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFFFFFF, 0xFDD5D5D5, 0xF4CCCCCC, 0xF4CCCCCC, 0xF4CCCCCC, 0xF3CBCBCB, 0xF1C9C9C9, 0xFAD2D2D2, 0x7E565656 }, - { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFEFEFEF, 0xFFFCFCFC, 0xFFFFFFFF, 0x9A727272, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x7F575757, 0x8F676767, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFE0E0E0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x90686868, 0x00000000, 0x00000000, 0xFFEBEBEB, 0xFFFFFFFF, 0xFFFFFFFF, 0x81595959, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFDFDFD, 0xFFFFFFFF, 0x8C646464, 0x00000000, 0x00000000, 0x00000000, 0xB78F8F8F, 0xFFFFFFFF, 0xFFFEFEFE, 0xECC4C4C4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0xFFFFFFFF, 0x90686868, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x50282828, 0xFFF9F9F9, 0xFFFFFFFF, 0xFFFFFFFF, 0x623A3A3A, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0x865E5E5E, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xD8B0B0B0, 0xFFFFFFFF, 0xFFFFFFFF, 0xCDA5A5A5, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x6C444444, 0xFFFFFFFF, 0xFFFCFCFC, 0xFFF4F4F4, 0x4D252525, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xF2CACACA, 0xFFFFFFFF, 0xFFFFFFFF, 0x99717171, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, - { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8E666666, 0xEFC7C7C7, 0x7D555555, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, -}; - -// Saved framebuffer pixels beneath the current cursor position. -static uint32_t gCursorSavedBg[CURSOR_W * CURSOR_H]; -static int gCursorDrawX = -1; // -1 = cursor not yet drawn -static int gCursorDrawY = -1; - -// Save the background rectangle [x,y,CURSOR_W,CURSOR_H] from the framebuffer. -static void CursorSaveBg(int x, int y) { - for (int row = 0; row < CURSOR_H; row++) { - int fy = y + row; - for (int col = 0; col < CURSOR_W; col++) { - int fx = x + col; - uint32_t px = 0; - if ((unsigned)fx < (unsigned)gWidth && (unsigned)fy < (unsigned)gHeight) - px = gFb[fy * gStride + fx]; - gCursorSavedBg[row * CURSOR_W + col] = px; - } - } -} - -// Restore the background previously saved by CursorSaveBg. -static void CursorRestoreBg(int x, int y) { - for (int row = 0; row < CURSOR_H; row++) { - int fy = y + row; - for (int col = 0; col < CURSOR_W; col++) { - int fx = x + col; - if ((unsigned)fx < (unsigned)gWidth && (unsigned)fy < (unsigned)gHeight) - gFb[fy * gStride + fx] = gCursorSavedBg[row * CURSOR_W + col]; - } - } -} - -// Alpha-blend a cursor pixel over a framebuffer pixel. -// Framebuffer format: 0x00RRGGBB (high byte ignored / always 0). -// Cursor pixel format: 0xAARRGGBB. -static inline uint32_t BlendPixel(uint32_t dst, uint32_t src) { - uint8_t a = (uint8_t)(src >> 24); - if (a == 0) return dst; - if (a == 255) return src & 0x00FFFFFFu; - - uint8_t sr = (uint8_t)(src >> 16); - uint8_t sg = (uint8_t)(src >> 8); - uint8_t sb = (uint8_t)(src ); - uint8_t dr = (uint8_t)(dst >> 16); - uint8_t dg = (uint8_t)(dst >> 8); - uint8_t db = (uint8_t)(dst ); - - uint8_t na = 255 - a; - uint8_t or_ = (uint8_t)((a * sr + na * dr) >> 8); - uint8_t og = (uint8_t)((a * sg + na * dg) >> 8); - uint8_t ob = (uint8_t)((a * sb + na * db) >> 8); - return ((uint32_t)or_ << 16) | ((uint32_t)og << 8) | ob; -} - -// Draw the arrow sprite at (x,y), saving the background first. -// Called from hal_mouse.c via extern declaration. -void HalScreenDrawCursor(int x, int y) { - CursorSaveBg(x, y); - gCursorDrawX = x; - gCursorDrawY = y; - for (int row = 0; row < CURSOR_H; row++) { - int fy = y + row; - for (int col = 0; col < CURSOR_W; col++) { - uint32_t src = gCursorPixels[row][col]; - if ((src >> 24) == 0) continue; // fully transparent, skip - int fx = x + col; - if ((unsigned)fx < (unsigned)gWidth && (unsigned)fy < (unsigned)gHeight) { - uint32_t* dst = &gFb[fy * gStride + fx]; - *dst = BlendPixel(*dst, src); - } - } - } -} - -// Erase the cursor by restoring the saved background. -void HalScreenEraseCursor(void) { - if (gCursorDrawX < 0) return; // never drawn - CursorRestoreBg(gCursorDrawX, gCursorDrawY); - gCursorDrawX = -1; - gCursorDrawY = -1; -} - -// --------------------------------------------------------------------------- -// Populate the HAL_SCREEN vtable -// --------------------------------------------------------------------------- -void HalScreenInitialize(uintptr_t fb, int w, int h, int stride, - HAL_SCREEN* out) { - gFb = (uint32_t *)fb; - gWidth = w; - gHeight = h; - gStride = stride; - out->Clear = ScreenClear; - out->PutPixel = ScreenPutPixel; - out->Blit = ScreenBlit; - out->GetSize = ScreenGetSize; - out->Scroll = ScreenScroll; - out->PutChar = ScreenPutChar; - out->PrintChar = ScreenPrintChar; - out->DrawCursor = HalScreenDrawCursor; - out->EraseCursor = HalScreenEraseCursor; - ScreenClear(0x000000); -} +// hal_screen.c - GOP framebuffer screen driver with embedded 8x16 font +// +// The 8x16 bitmap font is a standard VGA/PC font. We embed just the +// printable ASCII range (0x20–0x7E). Each glyph is 16 bytes; bit 7 of +// each byte is the leftmost pixel. +#include +#include +#include +#include + +static uint32_t* gFb = (uint32_t *)0; +static int gWidth = 0; +static int gHeight = 0; +static int gStride = 0; // pixels per row +static int gCursorX = 0, gCursorY = 0; + +#define FONT_W 8 +#define FONT_H 16 + +// --------------------------------------------------------------------------- +// 8x16 VGA font - printable ASCII only (glyph 0 = space = 0x20) +// --------------------------------------------------------------------------- +#include // see font8x16.h below + +// --------------------------------------------------------------------------- +// Internals +// --------------------------------------------------------------------------- +static inline void PutPixelRaw(int x, int y, uint32_t color) { + if ((unsigned)x < (unsigned)gWidth && (unsigned)y < (unsigned)gHeight) + gFb[y * gStride + x] = color; +} + +// --------------------------------------------------------------------------- +// HAL_SCREEN implementations +// --------------------------------------------------------------------------- +static void ScreenClear(uint32_t color) { + for (int y = 0; y < gHeight; y++) + for (int x = 0; x < gWidth; x++) + gFb[y * gStride + x] = color; + gCursorX = 0; gCursorY = 0; +} + +static void ScreenPutPixel(int x, int y, uint32_t color) { + PutPixelRaw(x, y, color); +} + +static void ScreenBlit(int x, int y, int w, int h, const uint32_t* pixels) { + // Calculate clipping bounds + int startX = (x < 0) ? 0 : x; + int startY = (y < 0) ? 0 : y; + int endX = (x + w > gWidth) ? gWidth : (x + w); + int endY = (y + h > gHeight) ? gHeight : (y + h); + + int drawW = endX - startX; + int drawH = endY - startY; + + // If the image is entirely off-screen, do nothing + if (drawW <= 0 || drawH <= 0) { + return; + } + + // Adjust the source pointer if the image was clipped on the top or left + int srcOffsetX = startX - x; + int srcOffsetY = startY - y; + + // Calculate bytes to copy per row + size_t bytesPerRow = (size_t)drawW * sizeof(uint32_t); + + // If the width we are drawing exactly matches the physical screen stride, + // AND it matches the original source image width, memory is perfectly contiguous. + if (drawW == gStride && drawW == w) { + uint32_t* dst = gFb + (startY * gStride) + startX; + const uint32_t* src = pixels + (srcOffsetY * w) + srcOffsetX; + + memcpy(dst, src, bytesPerRow * drawH); + return; + } + + // Copy row-by-row + for (int row = 0; row < drawH; row++) { + // Destination in the actual framebuffer (accounting for stride) + uint32_t* dst = gFb + ((startY + row) * gStride) + startX; + + // Source from the provided pixel buffer + const uint32_t* src = pixels + ((srcOffsetY + row) * w) + srcOffsetX; + + memcpy(dst, src, bytesPerRow); + } +} + +static void ScreenGetSize(int* w, int* h) { *w = gWidth; *h = gHeight; } + +static void ScreenScroll(int lines) { + if (lines <= 0 || lines >= gHeight) { ScreenClear(0); return; } + int rowBytes = gStride * sizeof(uint32_t); + memmove(gFb, gFb + lines * gStride, + (size_t)(gHeight - lines) * rowBytes); + // Clear the revealed rows at the bottom. + memset(gFb + (gHeight - lines) * gStride, 0, + (size_t)lines * rowBytes); +} + +static void ScreenPutChar(char c, int x, int y, uint32_t fg, uint32_t bg) { + if ((unsigned char)c < 0x20 || (unsigned char)c > 0x7E) c = '?'; + const uint8_t* glyph = Font8x16 + ((unsigned char)c - 0x20) * 16; + for (int row = 0; row < 16; row++) { + uint8_t bits = glyph[row]; + for (int col = 0; col < 8; col++) { + uint32_t color = (bits & (1 << col)) ? fg : bg; // i don't know why, i don't want to know why + // i shouldn't have to wonder why but the font is backwards unless we do this terriblness + PutPixelRaw(x + col, y + row, color); + } + } +} + +static void ScreenPrintChar(char c, uint32_t fg, uint32_t bg) { + int cols = gWidth / FONT_W; + int rows = gHeight / FONT_H; + + // Mirror to serial + while ((__inbyte(0x3FD) & 0x20) == 0); + if (c == '\n') __outbyte(0x3F8, '\r'); + __outbyte(0x3F8, c); + + if (c == '\n') { + gCursorX = 0; + gCursorY++; + } else if (c == '\r') { + gCursorX = 0; + } else if (c == '\b') { + if (gCursorX > 0) { + gCursorX--; + } else if (gCursorY > 0) { + gCursorY--; + gCursorX = cols - 1; + } + } else { + ScreenPutChar(c, gCursorX * FONT_W, gCursorY * FONT_H, fg, bg); + if (++gCursorX >= cols) { gCursorX = 0; gCursorY++; } + } + if (gCursorY >= rows) { + ScreenScroll(FONT_H); + gCursorY = rows - 1; + } +} + +// --------------------------------------------------------------------------- +// Mouse cursor – 12×19 monochrome arrow sprite +// 0 = transparent 1 = black outline 2 = white fill +// The hotspot is at (0,0) (top-left pixel = tip of the arrow). +// --------------------------------------------------------------------------- +#define CURSOR_W 16 +#define CURSOR_H 25 + +// Each entry is 0xAARRGGBB stored as a uint32_t. +// Pixels with brightness < 24 are fully transparent. +static const unsigned int gCursorPixels[CURSOR_H][CURSOR_W] = { + { 0x7F575757, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFAFAFA, 0x855D5D5D, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFEFEFE, 0xFFFFFFFF, 0x865E5E5E, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFDFDFD, 0xFFFDFDFD, 0xFFFFFFFF, 0x8A626262, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x8D656565, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x8E666666, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x91696969, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x946C6C6C, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x956D6D6D, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x99717171, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x9B737373, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0x9D757575, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFFFFFFF, 0xA0787878, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFDFDFD, 0xFFFDFDFD, 0xFFFCFCFC, 0xFFF9F9F9, 0xFFFFFFFF, 0xA1797979, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFEFEFE, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xAE868686, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFFFFFF, 0xFDD5D5D5, 0xF4CCCCCC, 0xF4CCCCCC, 0xF4CCCCCC, 0xF3CBCBCB, 0xF1C9C9C9, 0xFAD2D2D2, 0x7E565656 }, + { 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFEFEFE, 0xFFFCFCFC, 0xFFEFEFEF, 0xFFFCFCFC, 0xFFFFFFFF, 0x9A727272, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x7F575757, 0x8F676767, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFE0E0E0, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFEFEFE, 0xFFFDFDFD, 0xFFFFFFFF, 0x90686868, 0x00000000, 0x00000000, 0xFFEBEBEB, 0xFFFFFFFF, 0xFFFFFFFF, 0x81595959, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFDFDFD, 0xFFFFFFFF, 0x8C646464, 0x00000000, 0x00000000, 0x00000000, 0xB78F8F8F, 0xFFFFFFFF, 0xFFFEFEFE, 0xECC4C4C4, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0xFFFFFFFF, 0x90686868, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x50282828, 0xFFF9F9F9, 0xFFFFFFFF, 0xFFFFFFFF, 0x623A3A3A, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x865E5E5E, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xD8B0B0B0, 0xFFFFFFFF, 0xFFFFFFFF, 0xCDA5A5A5, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x6C444444, 0xFFFFFFFF, 0xFFFCFCFC, 0xFFF4F4F4, 0x4D252525, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xF2CACACA, 0xFFFFFFFF, 0xFFFFFFFF, 0x99717171, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, + { 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8E666666, 0xEFC7C7C7, 0x7D555555, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 }, +}; + +// Saved framebuffer pixels beneath the current cursor position. +static uint32_t gCursorSavedBg[CURSOR_W * CURSOR_H]; +static int gCursorDrawX = -1; // -1 = cursor not yet drawn +static int gCursorDrawY = -1; + +// Save the background rectangle [x,y,CURSOR_W,CURSOR_H] from the framebuffer. +static void CursorSaveBg(int x, int y) { + for (int row = 0; row < CURSOR_H; row++) { + int fy = y + row; + for (int col = 0; col < CURSOR_W; col++) { + int fx = x + col; + uint32_t px = 0; + if ((unsigned)fx < (unsigned)gWidth && (unsigned)fy < (unsigned)gHeight) + px = gFb[fy * gStride + fx]; + gCursorSavedBg[row * CURSOR_W + col] = px; + } + } +} + +// Restore the background previously saved by CursorSaveBg. +static void CursorRestoreBg(int x, int y) { + for (int row = 0; row < CURSOR_H; row++) { + int fy = y + row; + for (int col = 0; col < CURSOR_W; col++) { + int fx = x + col; + if ((unsigned)fx < (unsigned)gWidth && (unsigned)fy < (unsigned)gHeight) + gFb[fy * gStride + fx] = gCursorSavedBg[row * CURSOR_W + col]; + } + } +} + +// Alpha-blend a cursor pixel over a framebuffer pixel. +// Framebuffer format: 0x00RRGGBB (high byte ignored / always 0). +// Cursor pixel format: 0xAARRGGBB. +static inline uint32_t BlendPixel(uint32_t dst, uint32_t src) { + uint8_t a = (uint8_t)(src >> 24); + if (a == 0) return dst; + if (a == 255) return src & 0x00FFFFFFu; + + uint8_t sr = (uint8_t)(src >> 16); + uint8_t sg = (uint8_t)(src >> 8); + uint8_t sb = (uint8_t)(src ); + uint8_t dr = (uint8_t)(dst >> 16); + uint8_t dg = (uint8_t)(dst >> 8); + uint8_t db = (uint8_t)(dst ); + + uint8_t na = 255 - a; + uint8_t or_ = (uint8_t)((a * sr + na * dr) >> 8); + uint8_t og = (uint8_t)((a * sg + na * dg) >> 8); + uint8_t ob = (uint8_t)((a * sb + na * db) >> 8); + return ((uint32_t)or_ << 16) | ((uint32_t)og << 8) | ob; +} + +// Draw the arrow sprite at (x,y), saving the background first. +// Called from hal_mouse.c via extern declaration. +void HalScreenDrawCursor(int x, int y) { + CursorSaveBg(x, y); + gCursorDrawX = x; + gCursorDrawY = y; + for (int row = 0; row < CURSOR_H; row++) { + int fy = y + row; + for (int col = 0; col < CURSOR_W; col++) { + uint32_t src = gCursorPixels[row][col]; + if ((src >> 24) == 0) continue; // fully transparent, skip + int fx = x + col; + if ((unsigned)fx < (unsigned)gWidth && (unsigned)fy < (unsigned)gHeight) { + uint32_t* dst = &gFb[fy * gStride + fx]; + *dst = BlendPixel(*dst, src); + } + } + } +} + +// Erase the cursor by restoring the saved background. +void HalScreenEraseCursor(void) { + if (gCursorDrawX < 0) return; // never drawn + CursorRestoreBg(gCursorDrawX, gCursorDrawY); + gCursorDrawX = -1; + gCursorDrawY = -1; +} + +// --------------------------------------------------------------------------- +// Populate the HAL_SCREEN vtable +// --------------------------------------------------------------------------- +void HalScreenInitialize(uintptr_t fb, int w, int h, int stride, + HAL_SCREEN* out) { + gFb = (uint32_t *)fb; + gWidth = w; + gHeight = h; + gStride = stride; + out->Clear = ScreenClear; + out->PutPixel = ScreenPutPixel; + out->Blit = ScreenBlit; + out->GetSize = ScreenGetSize; + out->Scroll = ScreenScroll; + out->PutChar = ScreenPutChar; + out->PrintChar = ScreenPrintChar; + out->DrawCursor = HalScreenDrawCursor; + out->EraseCursor = HalScreenEraseCursor; + ScreenClear(0x000000); +} diff --git a/code/hal/hal_timer.c b/code/kernel/hal/hal_timer.c similarity index 98% rename from code/hal/hal_timer.c rename to code/kernel/hal/hal_timer.c index 2945b1d..d10f7bb 100644 --- a/code/hal/hal_timer.c +++ b/code/kernel/hal/hal_timer.c @@ -1,9 +1,9 @@ // hal_timer.c - Local APIC timer #include #include -#include -#include -#include +#include +#include +#include #define LAPIC_TIMER_LVT 0x320 #define LAPIC_TIMER_INIT 0x380 diff --git a/code/hal/font8x16.h b/code/kernel/include/kernel/hal/font8x16.h similarity index 100% rename from code/hal/font8x16.h rename to code/kernel/include/kernel/hal/font8x16.h diff --git a/code/hal/hal_apic.h b/code/kernel/include/kernel/hal/hal_apic.h similarity index 100% rename from code/hal/hal_apic.h rename to code/kernel/include/kernel/hal/hal_apic.h diff --git a/code/hal/hal_debug.h b/code/kernel/include/kernel/hal/hal_debug.h similarity index 100% rename from code/hal/hal_debug.h rename to code/kernel/include/kernel/hal/hal_debug.h diff --git a/code/kernel/io_file.h b/code/kernel/include/kernel/io_file.h similarity index 92% rename from code/kernel/io_file.h rename to code/kernel/include/kernel/io_file.h index 06f103b..f5d2c49 100644 --- a/code/kernel/io_file.h +++ b/code/kernel/include/kernel/io_file.h @@ -4,22 +4,15 @@ // Kernel and user code open files through IoOpenFile. #include #include -#include -#include -#include -#include +#include +#include +#include +#include +#include -// --------------------------------------------------------------------------- -// KDIR_ENTRY - one directory entry returned by ReadDir / SYS_READ_DIR -// Attribute flags match FAT32/Win32: ATTR_DIRECTORY=0x10, ATTR_ARCHIVE=0x20 -// --------------------------------------------------------------------------- -#define KDIR_NAME_MAX 260 - -typedef struct KDIR_ENTRY { - char Name[KDIR_NAME_MAX]; // null-terminated filename - uint8_t Attr; // FAT attribute byte (0x10=dir, 0x20=file) - uint32_t FileSize; // 0 for directories -} KDIR_ENTRY; +// Kernel/filesystem code uses the public directory-entry ABI directly. +typedef SYS_DIR_ENTRY KDIR_ENTRY; +#define KDIR_NAME_MAX SYS_DIR_NAME_MAX // Native asynchronous filesystem completion. Filesystems that provide // ReadAsync/WriteAsync accept the operation, return STATUS_PENDING, and later @@ -99,7 +92,7 @@ typedef struct IO_FILESYSTEM { // Fills 'out' with name, attributes, and size. // Returns STATUS_NO_MORE_FILES when the directory is exhausted. KSTATUS (*ReadDir)(struct IO_FILESYSTEM* fs, void* dirCtx, - struct KDIR_ENTRY* out); + KDIR_ENTRY* out); // Release resources allocated by OpenDir. void (*CloseDir)(struct IO_FILESYSTEM* fs, void* dirCtx); diff --git a/code/kernel/ke_apc.h b/code/kernel/include/kernel/ke_apc.h similarity index 98% rename from code/kernel/ke_apc.h rename to code/kernel/include/kernel/ke_apc.h index 181ec74..d6d9d91 100644 --- a/code/kernel/ke_apc.h +++ b/code/kernel/include/kernel/ke_apc.h @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include struct THREAD; typedef struct THREAD THREAD; diff --git a/code/kernel/include/kernel/ke_cpu.h b/code/kernel/include/kernel/ke_cpu.h new file mode 100644 index 0000000..ae60737 --- /dev/null +++ b/code/kernel/include/kernel/ke_cpu.h @@ -0,0 +1,49 @@ +#pragma once +// ke_cpu.h - per-CPU execution state +// +// SMP phase 1 still runs only the bootstrap processor, but the kernel now +// represents CPU-local state explicitly. AP startup can fill additional KCPU +// entries later without first untangling scheduler/IRQL/TSS globals. + +#include +#include +#include + +#define KE_MAX_CPUS 32u +#define KE_INVALID_CPU 0xFFFFFFFFu + +struct THREAD; + +typedef struct KCPU { + uint32_t CpuIndex; + uint32_t LapicId; + + uint8_t Present; + uint8_t Online; + uint8_t IsBsp; + uint8_t Reserved0; + + struct THREAD* CurrentThread; + struct THREAD* IdleThread; + struct THREAD* OutgoingThread; + + KIRQL CurrentIrql; + uint32_t InterruptDepth; + volatile long ReschedulePending; + + TSS64 Tss; + void* KernelStack; + uintptr_t KernelStackTop; + + uint64_t SchedulerTicks; + uint64_t ContextSwitches; +} KCPU; + +extern KCPU gCpus[KE_MAX_CPUS]; +extern uint32_t gCpuCount; + +void KeInitializeBootstrapCpu(void); +KCPU* KeGetCurrentCpu(void); +KCPU* KeGetCpuByIndex(uint32_t index); +uint32_t KeGetCurrentCpuIndex(void); +TSS64* KeGetCurrentTss(void); diff --git a/code/kernel/ke_debug.h b/code/kernel/include/kernel/ke_debug.h similarity index 100% rename from code/kernel/ke_debug.h rename to code/kernel/include/kernel/ke_debug.h diff --git a/code/kernel/ke_dpc.h b/code/kernel/include/kernel/ke_dpc.h similarity index 96% rename from code/kernel/ke_dpc.h rename to code/kernel/include/kernel/ke_dpc.h index f12bd3d..ee4b75e 100644 --- a/code/kernel/ke_dpc.h +++ b/code/kernel/include/kernel/ke_dpc.h @@ -8,8 +8,8 @@ #include #include -#include -#include +#include +#include typedef struct KDPC KDPC; diff --git a/code/kernel/ke_event.h b/code/kernel/include/kernel/ke_event.h similarity index 83% rename from code/kernel/ke_event.h rename to code/kernel/include/kernel/ke_event.h index 88c3c25..ac826fc 100644 --- a/code/kernel/ke_event.h +++ b/code/kernel/include/kernel/ke_event.h @@ -1,10 +1,10 @@ #pragma once // ke_event.h - auto-reset and manual-reset events #include -#include -#include -#include -#include +#include +#include +#include +#include typedef enum EVENT_TYPE { EventAutoReset, EventManualReset } EVENT_TYPE; diff --git a/code/kernel/ke_idt.h b/code/kernel/include/kernel/ke_idt.h similarity index 86% rename from code/kernel/ke_idt.h rename to code/kernel/include/kernel/ke_idt.h index 16af8e9..560267b 100644 --- a/code/kernel/ke_idt.h +++ b/code/kernel/include/kernel/ke_idt.h @@ -17,6 +17,9 @@ typedef struct TSS64 { } TSS64; #pragma pack(pop) +// Compatibility pointer used by ke_switch.asm. +// It points at CPU0's TSS until the context-switch path grows a true +// per-CPU base lookup. extern TSS64* gTss; void KeInitializeGdt(void); diff --git a/code/kernel/ke_irp.h b/code/kernel/include/kernel/ke_irp.h similarity index 98% rename from code/kernel/ke_irp.h rename to code/kernel/include/kernel/ke_irp.h index c5f4d99..9669aa8 100644 --- a/code/kernel/ke_irp.h +++ b/code/kernel/include/kernel/ke_irp.h @@ -13,9 +13,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include // Forward declarations - full types live in ke_event.h / ke_semaphore.h. // We only ever hold pointers in IRP and IRP_QUEUE, so a forward decl suffices. diff --git a/code/kernel/ke_irq.h b/code/kernel/include/kernel/ke_irq.h similarity index 94% rename from code/kernel/ke_irq.h rename to code/kernel/include/kernel/ke_irq.h index 76aadbd..98e3c4d 100644 --- a/code/kernel/ke_irq.h +++ b/code/kernel/include/kernel/ke_irq.h @@ -1,14 +1,14 @@ -#pragma once -#include -#include - -void KeIrqInitialize(const HAL_API *hal); -__declspec(dllexport) void KeIrqRegister(uint8_t irq, void (*handler)(void)); -void KeIrqDispatch(uint8_t irq); // called from ke_syscall.asm - -// Low-level interrupt entry/exit hooks. These are called by the common IRQ -// assembly stub around KeIrqDispatch. The exit hook is where deferred -// interrupt-time scheduling now happens, so IRQ handlers never switch away -// before KeIrqDispatch has returned and sent EOI. -void KiEnterInterrupt(void); -void KiExitInterrupt(void); +#pragma once +#include +#include + +void KeIrqInitialize(const HAL_API *hal); +__declspec(dllexport) void KeIrqRegister(uint8_t irq, void (*handler)(void)); +void KeIrqDispatch(uint8_t irq); // called from ke_syscall.asm + +// Low-level interrupt entry/exit hooks. These are called by the common IRQ +// assembly stub around KeIrqDispatch. The exit hook is where deferred +// interrupt-time scheduling now happens, so IRQ handlers never switch away +// before KeIrqDispatch has returned and sent EOI. +void KiEnterInterrupt(void); +void KiExitInterrupt(void); diff --git a/code/kernel/ke_irql.h b/code/kernel/include/kernel/ke_irql.h similarity index 100% rename from code/kernel/ke_irql.h rename to code/kernel/include/kernel/ke_irql.h diff --git a/code/kernel/ke_list.h b/code/kernel/include/kernel/ke_list.h similarity index 100% rename from code/kernel/ke_list.h rename to code/kernel/include/kernel/ke_list.h diff --git a/code/kernel/ke_mutex.h b/code/kernel/include/kernel/ke_mutex.h similarity index 75% rename from code/kernel/ke_mutex.h rename to code/kernel/include/kernel/ke_mutex.h index 07ffa24..2fb8193 100644 --- a/code/kernel/ke_mutex.h +++ b/code/kernel/include/kernel/ke_mutex.h @@ -1,9 +1,9 @@ #pragma once // ke_mutex.h - binary ownership mutex -#include -#include -#include -#include +#include +#include +#include +#include typedef struct MUTEX { OBJECT Header; diff --git a/code/kernel/ke_process.h b/code/kernel/include/kernel/ke_process.h similarity index 96% rename from code/kernel/ke_process.h rename to code/kernel/include/kernel/ke_process.h index f280438..879b2fa 100644 --- a/code/kernel/ke_process.h +++ b/code/kernel/include/kernel/ke_process.h @@ -2,13 +2,13 @@ // ke_process.h - process model // A process owns a handle table and a list of threads. // There is one shared address space - processes do not own one. -#include -#include -#include -#include +#include +#include +#include +#include #include #include -#include +#include #define PROCESS_NAME_MAX 64 #define HANDLE_TABLE_SIZE 256 diff --git a/code/kernel/ke_queue.h b/code/kernel/include/kernel/ke_queue.h similarity index 88% rename from code/kernel/ke_queue.h rename to code/kernel/include/kernel/ke_queue.h index f1283c8..9115394 100644 --- a/code/kernel/ke_queue.h +++ b/code/kernel/include/kernel/ke_queue.h @@ -4,10 +4,10 @@ // on both sides. The queue is only a synchronisation and ordering tool. #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define QUEUE_MESSAGE_SIZE 64 /* bytes, fixed */ #define QUEUE_DEPTH 256 diff --git a/code/kernel/ke_sched.h b/code/kernel/include/kernel/ke_sched.h similarity index 92% rename from code/kernel/ke_sched.h rename to code/kernel/include/kernel/ke_sched.h index b23a0a1..c3c3bc1 100644 --- a/code/kernel/ke_sched.h +++ b/code/kernel/include/kernel/ke_sched.h @@ -1,7 +1,7 @@ #pragma once // ke_sched.h - Multi-Level Feedback Queue scheduler // Three run queues (Low / Normal / High). IRQ 0 drives KeSchedulerTick. -#include +#include #define SCHED_TICK_MS 10u #define SCHED_HIGH_QUANTUM_TICKS 2u @@ -50,8 +50,8 @@ __declspec(dllexport) void KeYield(void); void KeGetSchedulerStats(KE_SCHED_STATS* out); -// Returns the thread currently running on this CPU (reads GS:[0]). +// Returns the thread currently running on this CPU. THREAD* KeGetCurrentThread(void); -// Set the current-thread GS slot. Called once per CPU at boot. +// Set the current thread for the current CPU. Used during CPU/scheduler bring-up. void KeSetCurrentThread(THREAD* thread); diff --git a/code/kernel/ke_selftest.h b/code/kernel/include/kernel/ke_selftest.h similarity index 89% rename from code/kernel/ke_selftest.h rename to code/kernel/include/kernel/ke_selftest.h index 1770cc4..528c2aa 100644 --- a/code/kernel/ke_selftest.h +++ b/code/kernel/include/kernel/ke_selftest.h @@ -4,6 +4,6 @@ // These tests intentionally live behind one call site so they can be walled // off or compiled out later without touching kmain.c again. -#include +#include void KiRunKernelSelfTests(const HAL_API* hal); diff --git a/code/kernel/ke_semaphore.h b/code/kernel/include/kernel/ke_semaphore.h similarity index 82% rename from code/kernel/ke_semaphore.h rename to code/kernel/include/kernel/ke_semaphore.h index 011a640..c987d0e 100644 --- a/code/kernel/ke_semaphore.h +++ b/code/kernel/include/kernel/ke_semaphore.h @@ -1,20 +1,20 @@ -#pragma once -// ke_semaphore.h - counting semaphore -#include -#include -#include -#include -#include - -typedef struct SEMAPHORE { - OBJECT Header; - SPINLOCK Lock; - int32_t Count; - int32_t MaxCount; - LIST_ENTRY WaitList; -} SEMAPHORE; - -__declspec(dllexport) KSTATUS KeSemaphoreCreate(int32_t initial, int32_t max, SEMAPHORE **out); -__declspec(dllexport) KSTATUS KeWaitSemaphore(SEMAPHORE* semaphore); -__declspec(dllexport) KSTATUS KeTrySemaphore(SEMAPHORE* semaphore); -__declspec(dllexport) void KeSignalSemaphore(SEMAPHORE* semaphore); +#pragma once +// ke_semaphore.h - counting semaphore +#include +#include +#include +#include +#include + +typedef struct SEMAPHORE { + OBJECT Header; + SPINLOCK Lock; + int32_t Count; + int32_t MaxCount; + LIST_ENTRY WaitList; +} SEMAPHORE; + +__declspec(dllexport) KSTATUS KeSemaphoreCreate(int32_t initial, int32_t max, SEMAPHORE **out); +__declspec(dllexport) KSTATUS KeWaitSemaphore(SEMAPHORE* semaphore); +__declspec(dllexport) KSTATUS KeTrySemaphore(SEMAPHORE* semaphore); +__declspec(dllexport) void KeSignalSemaphore(SEMAPHORE* semaphore); diff --git a/code/kernel/ke_settings.h b/code/kernel/include/kernel/ke_settings.h similarity index 92% rename from code/kernel/ke_settings.h rename to code/kernel/include/kernel/ke_settings.h index 3570df8..573a4cc 100644 --- a/code/kernel/ke_settings.h +++ b/code/kernel/include/kernel/ke_settings.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #define KE_SETTINGS_PATH "system\\settings.ini" diff --git a/code/kernel/ke_spinlock.h b/code/kernel/include/kernel/ke_spinlock.h similarity index 99% rename from code/kernel/ke_spinlock.h rename to code/kernel/include/kernel/ke_spinlock.h index 5b0ed49..5a7e3e9 100644 --- a/code/kernel/ke_spinlock.h +++ b/code/kernel/include/kernel/ke_spinlock.h @@ -11,7 +11,7 @@ // Never hold a spinlock across a wait/blocking operation. #include #include -#include +#include typedef struct SPINLOCK { volatile long Locked; diff --git a/code/kernel/ke_syscall.h b/code/kernel/include/kernel/ke_syscall.h similarity index 90% rename from code/kernel/ke_syscall.h rename to code/kernel/include/kernel/ke_syscall.h index 806ed4b..3b62f65 100644 --- a/code/kernel/ke_syscall.h +++ b/code/kernel/include/kernel/ke_syscall.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include // Set the HAL API pointer for syscalls void KeSyscallInit(const HAL_API* hal); diff --git a/code/kernel/ke_thread.h b/code/kernel/include/kernel/ke_thread.h similarity index 96% rename from code/kernel/ke_thread.h rename to code/kernel/include/kernel/ke_thread.h index 0f82e4b..d935761 100644 --- a/code/kernel/ke_thread.h +++ b/code/kernel/include/kernel/ke_thread.h @@ -2,12 +2,12 @@ // ke_thread.h - thread model // A THREAD is the unit of scheduling. Every thread belongs to exactly one process. #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define KSTACK_SIZE (64 * 1024) /* 64 KB kernel stack */ #define USTACK_SIZE (512 * 1024) /* 512 KB user stack */ @@ -88,6 +88,7 @@ typedef struct THREAD { uint32_t QuantumRemaining; uint32_t CpuBurstTicks; uint32_t LastRunTicks; + uint32_t RunningCpu; // Set by wait primitives before blocking and completed by the object // that wakes the thread. Keep this field after the assembly-visible diff --git a/code/kernel/ke_trap.h b/code/kernel/include/kernel/ke_trap.h similarity index 98% rename from code/kernel/ke_trap.h rename to code/kernel/include/kernel/ke_trap.h index 2c8b17e..28eec6d 100644 --- a/code/kernel/ke_trap.h +++ b/code/kernel/include/kernel/ke_trap.h @@ -7,7 +7,7 @@ // slots before returning to user mode. #include -#include +#include #define KTRAP_FRAME_MAGIC 0x4650545241544B31ULL diff --git a/code/kernel/ke_userenv.h b/code/kernel/include/kernel/ke_userenv.h similarity index 97% rename from code/kernel/ke_userenv.h rename to code/kernel/include/kernel/ke_userenv.h index b7fae85..ea49a2d 100644 --- a/code/kernel/ke_userenv.h +++ b/code/kernel/include/kernel/ke_userenv.h @@ -4,7 +4,7 @@ #include #include -#include +#include #define SYS_PEB_MAGIC 0x30424550u /* "PEB0" */ #define SYS_TEB_MAGIC 0x30424554u /* "TEB0" */ diff --git a/code/kernel/ke_util.h b/code/kernel/include/kernel/ke_util.h similarity index 98% rename from code/kernel/ke_util.h rename to code/kernel/include/kernel/ke_util.h index 538542b..ce4aea4 100644 --- a/code/kernel/ke_util.h +++ b/code/kernel/include/kernel/ke_util.h @@ -2,7 +2,7 @@ #pragma once #include -#include +#include // --------------------------------------------------------------------------- // Dynamic array (stretchy-buffer style) diff --git a/code/kernel/ldr_image.h b/code/kernel/include/kernel/ldr_image.h similarity index 98% rename from code/kernel/ldr_image.h rename to code/kernel/include/kernel/ldr_image.h index 34ca9f1..d097db7 100644 --- a/code/kernel/ldr_image.h +++ b/code/kernel/include/kernel/ldr_image.h @@ -4,7 +4,7 @@ #include #include #include -#include +#include // Map a PE32+ image from 'buffer' into the kernel virtual address space. // On success, *baseOut receives the virtual base address. diff --git a/code/kernel/mm_phys.h b/code/kernel/include/kernel/mm_phys.h similarity index 94% rename from code/kernel/mm_phys.h rename to code/kernel/include/kernel/mm_phys.h index c50936a..1b1dd14 100644 --- a/code/kernel/mm_phys.h +++ b/code/kernel/include/kernel/mm_phys.h @@ -1,28 +1,28 @@ -#pragma once -// mm_phys.h - physical memory manager (PMM) -// Stack allocator over 4 KB frames, seeded from MEMORY_MAP. -#include -#include -#include -#include - -#define PAGE_SIZE 4096ULL -#define PAGE_MASK (~(PAGE_SIZE - 1)) - -typedef uint64_t PHYSICAL_ADDRESS; - -// Called once by KernelMain with the MEMORY_MAP from BOOT_INFO. -bool MmInitializePhysical(const MEMORY_MAP* map, - uint64_t physicalWindowBase); - -// Allocate / free a single 4 KB frame. -// MmAllocateFrame returns 0 on failure. -PHYSICAL_ADDRESS MmAllocateFrame(void); -void MmFreeFrame(PHYSICAL_ADDRESS frame); - -// Allocate 'count' physically contiguous 4 KB frames. -// Returns 0 on failure. Use sparingly (DMA, page tables). -__declspec(dllexport) PHYSICAL_ADDRESS MmAllocateContiguous(size_t count); - -size_t MmFreeFrameCount(void); -size_t MmTotalFrameCount(void); +#pragma once +// mm_phys.h - physical memory manager (PMM) +// Stack allocator over 4 KB frames, seeded from MEMORY_MAP. +#include +#include +#include +#include + +#define PAGE_SIZE 4096ULL +#define PAGE_MASK (~(PAGE_SIZE - 1)) + +typedef uint64_t PHYSICAL_ADDRESS; + +// Called once by KernelMain with the MEMORY_MAP from BOOT_INFO. +bool MmInitializePhysical(const MEMORY_MAP* map, + uint64_t physicalWindowBase); + +// Allocate / free a single 4 KB frame. +// MmAllocateFrame returns 0 on failure. +PHYSICAL_ADDRESS MmAllocateFrame(void); +void MmFreeFrame(PHYSICAL_ADDRESS frame); + +// Allocate 'count' physically contiguous 4 KB frames. +// Returns 0 on failure. Use sparingly (DMA, page tables). +__declspec(dllexport) PHYSICAL_ADDRESS MmAllocateContiguous(size_t count); + +size_t MmFreeFrameCount(void); +size_t MmTotalFrameCount(void); diff --git a/code/kernel/mm_virt.h b/code/kernel/include/kernel/mm_virt.h similarity index 98% rename from code/kernel/mm_virt.h rename to code/kernel/include/kernel/mm_virt.h index d930353..3501795 100644 --- a/code/kernel/mm_virt.h +++ b/code/kernel/include/kernel/mm_virt.h @@ -3,8 +3,8 @@ // Manages the single shared PML4, kernel pool, and user heap. #include #include -#include -#include +#include +#include // --------------------------------------------------------------------------- // Page flags (x86-64 PTE bits) diff --git a/code/kernel/net_socket.h b/code/kernel/include/kernel/net_socket.h similarity index 95% rename from code/kernel/net_socket.h rename to code/kernel/include/kernel/net_socket.h index de69d84..f31a6f9 100644 --- a/code/kernel/net_socket.h +++ b/code/kernel/include/kernel/net_socket.h @@ -6,9 +6,9 @@ #include #include -#include -#include -#include +#include +#include +#include struct NET_STACK_PROVIDER; diff --git a/code/kernel/ob_object.h b/code/kernel/include/kernel/ob_object.h similarity index 97% rename from code/kernel/ob_object.h rename to code/kernel/include/kernel/ob_object.h index cc67285..9f3fa8e 100644 --- a/code/kernel/ob_object.h +++ b/code/kernel/include/kernel/ob_object.h @@ -4,7 +4,7 @@ // The OBJECT header must be the first member of any derived struct. #include #include -#include +#include typedef enum OBJECT_TYPE { ObjectTypeProcess = 1, diff --git a/code/kernel/syscall_nr.h b/code/kernel/include/kernel/syscall_nr.h similarity index 100% rename from code/kernel/syscall_nr.h rename to code/kernel/include/kernel/syscall_nr.h diff --git a/code/kernel/io_device.c b/code/kernel/io_device.c index 51e7c89..02b3227 100644 --- a/code/kernel/io_device.c +++ b/code/kernel/io_device.c @@ -1,8 +1,8 @@ // io_device.c - kernel driver/device dispatch and disk registry #include -#include -#include -#include +#include +#include +#include #define MAX_DISK_DEVICES 8 diff --git a/code/kernel/io_file.c b/code/kernel/io_file.c index 59c30c0..2ec7647 100644 --- a/code/kernel/io_file.c +++ b/code/kernel/io_file.c @@ -1,17 +1,17 @@ // io_file.c - VFS dispatch layer #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define MAX_DRIVES 8 diff --git a/code/kernel/ke_apc.c b/code/kernel/ke_apc.c index b7b4e10..77fc8b1 100644 --- a/code/kernel/ke_apc.c +++ b/code/kernel/ke_apc.c @@ -1,11 +1,11 @@ // ke_apc.c - kernel APC infrastructure -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/code/kernel/ke_cpu.c b/code/kernel/ke_cpu.c new file mode 100644 index 0000000..fa4c450 --- /dev/null +++ b/code/kernel/ke_cpu.c @@ -0,0 +1,51 @@ +// ke_cpu.c - bootstrap/per-CPU state plumbing +#include +#include + +#define BOOTSTRAP_CPU_STACK_SIZE 0x4000u + +KCPU gCpus[KE_MAX_CPUS]; +uint32_t gCpuCount = 0; + +static uint8_t gBootstrapCpuStack[BOOTSTRAP_CPU_STACK_SIZE]; + +void KeInitializeBootstrapCpu(void) { + memset(gCpus, 0, sizeof(gCpus)); + + KCPU* cpu = &gCpus[0]; + cpu->CpuIndex = 0; + cpu->LapicId = 0; + cpu->Present = 1; + cpu->Online = 1; + cpu->IsBsp = 1; + cpu->CurrentIrql = PASSIVE_LEVEL; + cpu->InterruptDepth = 0; + cpu->ReschedulePending = 0; + cpu->KernelStack = gBootstrapCpuStack; + cpu->KernelStackTop = (uintptr_t)(gBootstrapCpuStack + sizeof(gBootstrapCpuStack)); + memset(&cpu->Tss, 0, sizeof(cpu->Tss)); + cpu->Tss.IoMapBase = sizeof(TSS64); + cpu->Tss.RSP0 = cpu->KernelStackTop; + + gCpuCount = 1; +} + +KCPU* KeGetCurrentCpu(void) { + // SMP phase 1: only CPU0 is online. Later this becomes LAPIC-ID or + // per-CPU-base based lookup once the bootloader parks APs for us. + return &gCpus[0]; +} + +KCPU* KeGetCpuByIndex(uint32_t index) { + if (index >= KE_MAX_CPUS) + return (KCPU*)0; + return &gCpus[index]; +} + +uint32_t KeGetCurrentCpuIndex(void) { + return KeGetCurrentCpu()->CpuIndex; +} + +TSS64* KeGetCurrentTss(void) { + return &KeGetCurrentCpu()->Tss; +} diff --git a/code/kernel/ke_debug.c b/code/kernel/ke_debug.c index e536120..9e14946 100644 --- a/code/kernel/ke_debug.c +++ b/code/kernel/ke_debug.c @@ -2,14 +2,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include int _fltused; // fuckass int gDebugEnabled = 0; diff --git a/code/kernel/ke_dpc.c b/code/kernel/ke_dpc.c index e567e17..621c3f0 100644 --- a/code/kernel/ke_dpc.c +++ b/code/kernel/ke_dpc.c @@ -1,7 +1,7 @@ // ke_dpc.c - deferred procedure calls -#include -#include -#include +#include +#include +#include #include static LIST_ENTRY gDpcQueue; diff --git a/code/kernel/ke_event.c b/code/kernel/ke_event.c index 2f88e8a..b8fcc12 100644 --- a/code/kernel/ke_event.c +++ b/code/kernel/ke_event.c @@ -1,11 +1,11 @@ // ke_event.c - synchronisation events #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include static void KiEventDestroy(OBJECT* obj) { (void)obj; } diff --git a/code/kernel/ke_idt.c b/code/kernel/ke_idt.c index 7182d69..959b0ad 100644 --- a/code/kernel/ke_idt.c +++ b/code/kernel/ke_idt.c @@ -10,7 +10,8 @@ // 0x30 TSS high #include #include -#include +#include +#include // External assembly procedures extern void KeFlushGdt(void* pGdtr, uint16_t codeSel, uint16_t dataSel, uint16_t tssSel); @@ -77,10 +78,7 @@ extern void KeFaultRSV31(void); // GDT // --------------------------------------------------------------------------- #define GDT_ENTRIES 8 -#define KERNEL_IST_STACK_SIZE 0x4000 - static uint64_t gGdt[GDT_ENTRIES]; -static uint8_t gKernelStack[KERNEL_IST_STACK_SIZE]; #pragma pack(push, 1) typedef struct { uint16_t Limit; uint64_t Base; } GDTR; @@ -112,12 +110,14 @@ static void KiGdtSetTss(int idx, uintptr_t base, uint32_t limit) { gGdt[idx+1] = (base >> 32); } -TSS64 gTssStruct; -TSS64* gTss = &gTssStruct; +TSS64* gTss = (TSS64*)0; void KeInitializeGdt(void) { + KCPU* cpu = KeGetCurrentCpu(); + TSS64* tss = &cpu->Tss; + gTss = tss; + memset(gGdt, 0, sizeof(gGdt)); - memset(&gTssStruct, 0, sizeof(gTssStruct)); // 0x00: Null KiGdtSetEntry(0, 0, 0, 0, 0); @@ -130,11 +130,13 @@ void KeInitializeGdt(void) { // 0x20: Ring-3 Data KiGdtSetEntry(4, 0, 0xFFFFF, 0xF2, 0xC); - // 0x28: TSS (Occupies two slots: 0x28 and 0x30) - gTssStruct.IoMapBase = sizeof(TSS64); - gTssStruct.RSP0 = (uint64_t)(gKernelStack + KERNEL_IST_STACK_SIZE); // top of stack + // 0x28: TSS (Occupies two slots: 0x28 and 0x30). + // The TSS storage is per-CPU; phase 1 initializes CPU0 only. + tss->IoMapBase = sizeof(TSS64); + if (!tss->RSP0) + tss->RSP0 = cpu->KernelStackTop; - KiGdtSetTss(5, (uintptr_t)&gTssStruct, sizeof(TSS64) - 1); + KiGdtSetTss(5, (uintptr_t)tss, sizeof(TSS64) - 1); GDTR gdtr = { sizeof(gGdt) - 1, (uint64_t)gGdt }; diff --git a/code/kernel/ke_irp.c b/code/kernel/ke_irp.c index cded325..43532c9 100644 --- a/code/kernel/ke_irp.c +++ b/code/kernel/ke_irp.c @@ -12,12 +12,12 @@ // → ob_object.h (ObDereferenceObject) // → io_driver.h (DEVICE_OBJECT / IoCallDriver) -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include // ------------------------------------------------------------------------- // IRP_QUEUE operations diff --git a/code/kernel/ke_irq.c b/code/kernel/ke_irq.c index cb503ad..7ee4edf 100644 --- a/code/kernel/ke_irq.c +++ b/code/kernel/ke_irq.c @@ -1,10 +1,11 @@ // ke_irq.c - IRQ dispatch, kernel-side -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #define MAX_IRQS 24 #define MAX_IRQ_HANDLERS 8 @@ -16,7 +17,6 @@ typedef struct IRQ_HANDLER_LIST { static IRQ_HANDLER_LIST gIrqHandlers[MAX_IRQS]; static const HAL_API *gHal; -static volatile uint32_t gInterruptDepth = 0; static KIRQL KiIrqToIrql(uint8_t irq) { KIRQL irql = (KIRQL)(DIRQL_BASE + irq); @@ -77,18 +77,19 @@ void KeIrqDispatch(uint8_t irq) { } void KiEnterInterrupt(void) { - gInterruptDepth++; + KeGetCurrentCpu()->InterruptDepth++; } void KiExitInterrupt(void) { - if (gInterruptDepth) - gInterruptDepth--; + KCPU* cpu = KeGetCurrentCpu(); + if (cpu->InterruptDepth) + cpu->InterruptDepth--; // A reschedule is only legal after the interrupt unwound back to the // interrupted thread's original PASSIVE context. If a future path ever // permits nested interrupting of DISPATCH/DIRQL code, leave the request // pending instead of switching while a spinlock/high-IRQL region is active. - if (gInterruptDepth == 0 && KeGetCurrentIrql() == PASSIVE_LEVEL) { + if (cpu->InterruptDepth == 0 && KeGetCurrentIrql() == PASSIVE_LEVEL) { KiDrainDpcQueue(); if (KeGetCurrentIrql() == PASSIVE_LEVEL) KiScheduleFromInterrupt(); diff --git a/code/kernel/ke_irql.c b/code/kernel/ke_irql.c index de50a04..2d72ce7 100644 --- a/code/kernel/ke_irql.c +++ b/code/kernel/ke_irql.c @@ -1,10 +1,8 @@ // ke_irql.c - software IRQL skeleton -#include -#include -#include - -// Single-CPU bring-up state. When SMP arrives this becomes per-CPU state. -static volatile KIRQL gCurrentIrql = PASSIVE_LEVEL; +#include +#include +#include +#include __declspec(dllexport) const char* KeIrqlName(KIRQL irql) { switch (irql) { @@ -20,11 +18,12 @@ __declspec(dllexport) const char* KeIrqlName(KIRQL irql) { } __declspec(dllexport) KIRQL KeGetCurrentIrql(void) { - return gCurrentIrql; + return KeGetCurrentCpu()->CurrentIrql; } __declspec(dllexport) KIRQL KeRaiseIrql(KIRQL newIrql) { - KIRQL oldIrql = gCurrentIrql; + KCPU* cpu = KeGetCurrentCpu(); + KIRQL oldIrql = cpu->CurrentIrql; if (newIrql > HIGH_LEVEL) { KePanic("KeRaiseIrql: invalid target IRQL %u\n", (unsigned)newIrql); @@ -36,12 +35,13 @@ __declspec(dllexport) KIRQL KeRaiseIrql(KIRQL newIrql) { KeIrqlName(newIrql), (unsigned)newIrql); } - gCurrentIrql = newIrql; + cpu->CurrentIrql = newIrql; return oldIrql; } __declspec(dllexport) void KeLowerIrql(KIRQL oldIrql) { - KIRQL currentIrql = gCurrentIrql; + KCPU* cpu = KeGetCurrentCpu(); + KIRQL currentIrql = cpu->CurrentIrql; if (oldIrql > HIGH_LEVEL) { KePanic("KeLowerIrql: invalid target IRQL %u\n", (unsigned)oldIrql); @@ -53,7 +53,7 @@ __declspec(dllexport) void KeLowerIrql(KIRQL oldIrql) { KeIrqlName(oldIrql), (unsigned)oldIrql); } - gCurrentIrql = oldIrql; + cpu->CurrentIrql = oldIrql; if (oldIrql == PASSIVE_LEVEL && currentIrql != PASSIVE_LEVEL) KiDeliverKernelApcs(); diff --git a/code/kernel/ke_mutex.c b/code/kernel/ke_mutex.c index 3b66ed8..20696a5 100644 --- a/code/kernel/ke_mutex.c +++ b/code/kernel/ke_mutex.c @@ -1,11 +1,11 @@ // ke_mutex.c - binary ownership mutex #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include static void KiMutexDestroy(OBJECT* obj) { (void)obj; } diff --git a/code/kernel/ke_process.c b/code/kernel/ke_process.c index b12595e..b33bc1f 100644 --- a/code/kernel/ke_process.c +++ b/code/kernel/ke_process.c @@ -1,13 +1,13 @@ // ke_process.c - process model #include #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include // --------------------------------------------------------------------------- // Global process list diff --git a/code/kernel/ke_queue.c b/code/kernel/ke_queue.c index e8d6229..b4865ab 100644 --- a/code/kernel/ke_queue.c +++ b/code/kernel/ke_queue.c @@ -1,10 +1,10 @@ // ke_queue.c - ring-buffer message queue #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static void KiQueueDestroy(OBJECT* obj) { (void)obj; } diff --git a/code/kernel/ke_sched.c b/code/kernel/ke_sched.c index 2fb5d07..be6b685 100644 --- a/code/kernel/ke_sched.c +++ b/code/kernel/ke_sched.c @@ -1,23 +1,20 @@ // ke_sched.c - MLFQ scheduler #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include static LIST_ENTRY gRunQueue[PriorityCount]; static SPINLOCK gSchedLock; -static THREAD* gCurrentThread; -static THREAD* gIdleThread; -static THREAD* gOutgoingThread; static uint32_t gAgingCounter = 0; -static volatile long gReschedulePending = 0; static KE_SCHED_STATS gSchedStats; static uint32_t KiBaseQuantumForPriority(THREAD_PRIORITY priority) { @@ -30,7 +27,7 @@ static uint32_t KiBaseQuantumForPriority(THREAD_PRIORITY priority) { } static uint32_t KiComputeQuantumLocked(THREAD* thread) { - if (!thread || thread == gIdleThread) + if (!thread || thread == KeGetCurrentCpu()->IdleThread) return 1; uint32_t quantum = KiBaseQuantumForPriority(thread->Priority); @@ -53,8 +50,8 @@ static void KiRefillQuantumLocked(THREAD* thread) { thread->QuantumRemaining = thread->QuantumTicks; } -THREAD* KeGetCurrentThread(void) { return gCurrentThread; } -void KeSetCurrentThread(THREAD* t) { gCurrentThread = t; } +THREAD* KeGetCurrentThread(void) { return KeGetCurrentCpu()->CurrentThread; } +void KeSetCurrentThread(THREAD* t) { KeGetCurrentCpu()->CurrentThread = t; } void KeGetSchedulerStats(KE_SCHED_STATS* out) { if (!out) return; @@ -68,6 +65,8 @@ static void KiIdleLoop(void) { } void KeInitializeScheduler(void) { + KCPU* cpu = KeGetCurrentCpu(); + for (int i = 0; i < PriorityCount; i++) LIST_INIT(&gRunQueue[i]); gSchedLock = (SPINLOCK)SPINLOCK_INIT; @@ -90,6 +89,7 @@ void KeInitializeScheduler(void) { idle->QuantumRemaining = 1; idle->CpuBurstTicks = 0; idle->LastRunTicks = 0; + idle->RunningCpu = cpu->CpuIndex; idle->Owner = idleProc; idle->WaitObject = (OBJECT *)0; idle->WaitStatus = STATUS_SUCCESS; @@ -127,20 +127,23 @@ void KeInitializeScheduler(void) { idleProc->ThreadCount++; KeReleaseSpinlock(&idleProc->HandleLock, idleFlags); - gIdleThread = idle; - gCurrentThread = idle; + cpu->IdleThread = idle; + cpu->CurrentThread = idle; + cpu->OutgoingThread = (THREAD*)0; } // Safely release the lock and clean up any dead threads natively post-switch void KeSchedulerPostSwitch(void) { - THREAD* cur = KeGetCurrentThread(); + KCPU* cpu = KeGetCurrentCpu(); + THREAD* cur = cpu->CurrentThread; KeReleaseSpinlock(&gSchedLock, cur->SchedLockFlags); KiDeliverKernelApcs(); - if (gOutgoingThread && gOutgoingThread->State == ThreadDead) { - THREAD* dead = gOutgoingThread; - gOutgoingThread = (THREAD*)0; + if (cpu->OutgoingThread && cpu->OutgoingThread->State == ThreadDead) { + THREAD* dead = cpu->OutgoingThread; + cpu->OutgoingThread = (THREAD*)0; + dead->RunningCpu = KE_INVALID_CPU; ObDereferenceObject(&dead->Header); } } @@ -155,8 +158,9 @@ void KeReadyThread(THREAD* thread) { uintptr_t flags = KeAcquireSpinlock(&gSchedLock); ListInsertTail(&gRunQueue[p], &thread->SchedulerLink); - THREAD* cur = gCurrentThread; - if (!cur || cur == gIdleThread) { + KCPU* cpu = KeGetCurrentCpu(); + THREAD* cur = cpu->CurrentThread; + if (!cur || cur == cpu->IdleThread) { KiRequestReschedule(); } else if (cur->State == ThreadRunning && thread->Priority > cur->Priority) { gSchedStats.PriorityPreemptions++; @@ -189,22 +193,24 @@ static THREAD* KiPickNext(void) { return CONTAINING_RECORD(node, THREAD, SchedulerLink); } } - return gIdleThread; + return KeGetCurrentCpu()->IdleThread; } void KiRequestReschedule(void) { - gReschedulePending = 1; + KeGetCurrentCpu()->ReschedulePending = 1; } int KiIsReschedulePending(void) { - return gReschedulePending != 0; + return KeGetCurrentCpu()->ReschedulePending != 0; } static void KiSchedule(void) { - THREAD* cur = gCurrentThread; + KCPU* cpu = KeGetCurrentCpu(); + THREAD* cur = cpu->CurrentThread; + THREAD* idle = cpu->IdleThread; if (!cur) return; - gReschedulePending = 0; + cpu->ReschedulePending = 0; uintptr_t flags = KeAcquireSpinlock(&gSchedLock); cur->SchedLockFlags = flags; @@ -213,7 +219,7 @@ static void KiSchedule(void) { // still runnable and nobody else is ready, keep executing it. Otherwise a // lone CPU-bound thread gets alternated with the idle thread on every timer // tick, effectively turning a periodic preemption check into a 50% throttle. - if (cur != gIdleThread && cur->State == ThreadRunning && !KiAnyRunnableLocked()) { + if (cur != idle && cur->State == ThreadRunning && !KiAnyRunnableLocked()) { if (cur->QuantumRemaining == 0) KiRefillQuantumLocked(cur); gSchedStats.KeepCurrentDecisions++; @@ -222,12 +228,12 @@ static void KiSchedule(void) { } THREAD* next = KiPickNext(); - if (next == gIdleThread) gSchedStats.IdleSelections++; + if (next == idle) gSchedStats.IdleSelections++; if (next == cur) { // Only re-queue if still running normally; a ThreadWaiting/ThreadDead // caller has already placed SchedulerLink elsewhere (or is discarding // the thread). - if (cur != gIdleThread && cur->State == ThreadRunning) + if (cur != idle && cur->State == ThreadRunning) ListInsertTail(&gRunQueue[cur->Priority], &cur->SchedulerLink); KeReleaseSpinlock(&gSchedLock, flags); return; @@ -235,19 +241,22 @@ static void KiSchedule(void) { next->State = ThreadRunning; KiRefillQuantumLocked(next); - gCurrentThread = next; + cpu->CurrentThread = next; + next->RunningCpu = cpu->CpuIndex; // Only re-queue the outgoing thread if it is still in the running state. // If KeBlockThread set State = ThreadWaiting, SchedulerLink was already // inserted into the sync object's wait list - inserting it here too would // corrupt both lists simultaneously (same intrusive node in two lists). // If KeExitThread set State = ThreadDead, the thread must not be re-queued. - if (cur != gIdleThread && cur->State == ThreadRunning) { + if (cur != idle && cur->State == ThreadRunning) { cur->State = ThreadReady; ListInsertTail(&gRunQueue[cur->Priority], &cur->SchedulerLink); } - gOutgoingThread = cur; + if (cur) cur->RunningCpu = KE_INVALID_CPU; + cpu->OutgoingThread = cur; + cpu->ContextSwitches++; gSchedStats.ContextSwitches++; KeSwitchContext(cur, next); KeSchedulerPostSwitch(); @@ -267,7 +276,9 @@ void KiSchedulerNoteVoluntaryBlock(THREAD* thread) { } void KeSchedulerTick(void) { - THREAD* cur = gCurrentThread; + KCPU* cpu = KeGetCurrentCpu(); + THREAD* cur = cpu->CurrentThread; + THREAD* idle = cpu->IdleThread; if (!cur) return; uintptr_t flags = KeAcquireSpinlock(&gSchedLock); @@ -277,7 +288,7 @@ void KeSchedulerTick(void) { int requestReschedule = 0; - if (cur == gIdleThread) { + if (cur == idle) { if (KiAnyRunnableLocked()) requestReschedule = 1; } else { diff --git a/code/kernel/ke_selftest.c b/code/kernel/ke_selftest.c index 2ab414d..951700b 100644 --- a/code/kernel/ke_selftest.c +++ b/code/kernel/ke_selftest.c @@ -3,20 +3,20 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // ------------------------------------------------------------------------- // Kernel APC self-test diff --git a/code/kernel/ke_semaphore.c b/code/kernel/ke_semaphore.c index 3a464ba..25c1c67 100644 --- a/code/kernel/ke_semaphore.c +++ b/code/kernel/ke_semaphore.c @@ -1,10 +1,10 @@ // ke_semaphore.c - counting semaphore #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include static void KiSemaphoreDestroy(OBJECT* obj) { (void)obj; } diff --git a/code/kernel/ke_settings.c b/code/kernel/ke_settings.c index 9cca58c..2507350 100644 --- a/code/kernel/ke_settings.c +++ b/code/kernel/ke_settings.c @@ -7,10 +7,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define KE_SETTINGS_MAX_FILE_BYTES (64u * 1024u) diff --git a/code/kernel/ke_switch.asm b/code/kernel/ke_switch.asm index 2b2e4cc..5e1396a 100644 --- a/code/kernel/ke_switch.asm +++ b/code/kernel/ke_switch.asm @@ -14,7 +14,7 @@ THREAD_Teb EQU 112 THREAD_FpuContext EQU 168 TSS_RSP0_OFFSET EQU 4 -EXTERN gTss:QWORD ; address of the single TSS, exported from ke_idt.c +EXTERN gTss:QWORD ; phase-1 pointer to current CPU TSS, exported from ke_idt.c .CODE diff --git a/code/kernel/ke_syscall.c b/code/kernel/ke_syscall.c index ad44c98..96eded6 100644 --- a/code/kernel/ke_syscall.c +++ b/code/kernel/ke_syscall.c @@ -33,23 +33,23 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // --------------------------------------------------------------------------- // HAL pointer - set once at boot by KeSyscallSetHal() diff --git a/code/kernel/ke_thread.c b/code/kernel/ke_thread.c index 56dd527..a33c4f5 100644 --- a/code/kernel/ke_thread.c +++ b/code/kernel/ke_thread.c @@ -2,14 +2,15 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #define FPU_FCW_DEFAULT 0x037Fu #define FPU_MXCSR_DEFAULT 0x1F80u @@ -91,6 +92,7 @@ __declspec(dllexport) KSTATUS KeCreateThread(PROCESS* owner, uintptr_t entry, ui thread->QuantumRemaining = 0; thread->CpuBurstTicks = 0; thread->LastRunTicks = 0; + thread->RunningCpu = KE_INVALID_CPU; thread->WaitObject = (OBJECT *)0; thread->WaitStatus = STATUS_SUCCESS; thread->WaitListHead = (LIST_ENTRY*)0; @@ -249,6 +251,7 @@ __declspec(dllexport) KSTATUS KeCreateKernelThread(uintptr_t fn, uintptr_t arg, thread->QuantumRemaining = 0; thread->CpuBurstTicks = 0; thread->LastRunTicks = 0; + thread->RunningCpu = KE_INVALID_CPU; thread->WaitObject = (OBJECT*)0; thread->WaitStatus = STATUS_SUCCESS; thread->WaitListHead = (LIST_ENTRY*)0; diff --git a/code/kernel/ke_trap.c b/code/kernel/ke_trap.c index 2b300f1..d148aa7 100644 --- a/code/kernel/ke_trap.c +++ b/code/kernel/ke_trap.c @@ -1,11 +1,11 @@ // ke_trap.c - current-thread trap-frame tracking and validation #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #define STATIC_ASSERT_OFFSET(type, field, expected) \ _Static_assert(offsetof(type, field) == (expected), \ diff --git a/code/kernel/kmain.c b/code/kernel/kmain.c index dcd1dc4..9601ec8 100644 --- a/code/kernel/kmain.c +++ b/code/kernel/kmain.c @@ -2,25 +2,26 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include typedef struct { BOOT_INFO* bootInfo; @@ -438,8 +439,9 @@ extern void KernelMain(BOOT_INFO* bootInfo) { MmInitializeVirtual(pml4, 4 * 1024 * 1024 /* 4 MB initial pool */); // - // CPU Architecture setup (GDT/IDT/Faults) + // Bootstrap CPU and architecture setup (GDT/IDT/Faults) // + KeInitializeBootstrapCpu(); KeInitializeGdt(); KeInitializeIdt(); diff --git a/code/kernel/ldr_image.c b/code/kernel/ldr_image.c index 4761860..3b26721 100644 --- a/code/kernel/ldr_image.c +++ b/code/kernel/ldr_image.c @@ -1,12 +1,12 @@ // ldr_image.c - PE32+ loader and export resolver #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include int _stricmp(const char* a, const char* b); diff --git a/code/kernel/mm_phys.c b/code/kernel/mm_phys.c index e7133d1..cada76f 100644 --- a/code/kernel/mm_phys.c +++ b/code/kernel/mm_phys.c @@ -6,8 +6,8 @@ // bootloader at PhysicalWindowBase (always 0xFFFF880000000000). // // Lock: a single spinlock guards Push/Pop. O(1) for both operations. -#include -#include +#include +#include // --------------------------------------------------------------------------- // Physical-to-virtual translation via the direct map window. diff --git a/code/kernel/mm_virt.c b/code/kernel/mm_virt.c index 047143f..0a82b7c 100644 --- a/code/kernel/mm_virt.c +++ b/code/kernel/mm_virt.c @@ -14,9 +14,9 @@ // Backed on demand from the PMM. No per-process heaps. #include #include -#include -#include -#include +#include +#include +#include // --------------------------------------------------------------------------- // Helpers - physical window access diff --git a/code/kernel/net_device.c b/code/kernel/net_device.c index c772783..e340c3a 100644 --- a/code/kernel/net_device.c +++ b/code/kernel/net_device.c @@ -3,10 +3,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #define NET_MAX_DEVICES 8u diff --git a/code/kernel/net_socket.c b/code/kernel/net_socket.c index 00eb6cc..adbd508 100644 --- a/code/kernel/net_socket.c +++ b/code/kernel/net_socket.c @@ -4,9 +4,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define NET_SOCKET_IO_MAX_BYTES (1024u * 1024u) #define NET_SOCKET_UDP_MAX_BYTES 65507u diff --git a/code/kernel/net_stack.c b/code/kernel/net_stack.c index 8a25a7f..5c6d900 100644 --- a/code/kernel/net_stack.c +++ b/code/kernel/net_stack.c @@ -2,10 +2,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include static const NET_STACK_PROVIDER* gNetStackProvider = 0; static SPINLOCK gNetStackLock = SPINLOCK_INIT; diff --git a/code/kernel/ob_object.c b/code/kernel/ob_object.c index 4f7e084..f200f71 100644 --- a/code/kernel/ob_object.c +++ b/code/kernel/ob_object.c @@ -1,8 +1,8 @@ // ob_object.c - executive object manager #include #include -#include -#include +#include +#include __declspec(dllexport) OBJECT* ObAllocateObject(OBJECT_TYPE type, size_t size) { if (size < sizeof(OBJECT)) size = sizeof(OBJECT); diff --git a/code/kernel/boot_info.h b/code/public/ntlite/boot_info.h similarity index 95% rename from code/kernel/boot_info.h rename to code/public/ntlite/boot_info.h index 82f789b..31e0e51 100644 --- a/code/kernel/boot_info.h +++ b/code/public/ntlite/boot_info.h @@ -1,44 +1,44 @@ -#pragma once -// boot_info.h - shared between bootx64.efi and kernel.exe -// The bootloader fills this structure and passes a pointer to KernelMain. -#include -#include - -#define BOOT_INFO_MAGIC 0x424F4F54494E464FULL /* 'BOOTINFO' */ -#define MAX_BOOT_MODULES 32 - -typedef struct BOOT_MODULE { - char Name[32]; /* e.g. "hal.dll", "ide.sys" */ - uintptr_t VirtBase; /* Virtual address (mapped) */ - uintptr_t PhysBase; /* Raw physical address (file) */ - size_t ImageSize; /* File size / Image size */ -} BOOT_MODULE; - -typedef struct BOOT_INFO { - uint64_t Magic; - - /* Physical memory. */ - MEMORY_MAP MemoryMap; - - /* GOP framebuffer. */ - uintptr_t FramebufferBase; - uint32_t FramebufferWidth; - uint32_t FramebufferHeight; - uint32_t FramebufferStride; /* pixels per row */ - - /* Loaded modules. */ - BOOT_MODULE Modules[MAX_BOOT_MODULES]; - uint32_t ModuleCount; - uint32_t _pad1; - - char CommandLine[64]; - - /* ACPI RSDP physical address (for APIC, HPET). */ - uintptr_t RsdpPhysical; - - /* Direct physical window base - always 0xFFFF880000000000. */ - uintptr_t PhysicalMapBase; - - /* From boot.ini */ - uint32_t Debug; -} BOOT_INFO; +#pragma once +// boot_info.h - shared between bootx64.efi and kernel.exe +// The bootloader fills this structure and passes a pointer to KernelMain. +#include +#include + +#define BOOT_INFO_MAGIC 0x424F4F54494E464FULL /* 'BOOTINFO' */ +#define MAX_BOOT_MODULES 32 + +typedef struct BOOT_MODULE { + char Name[32]; /* e.g. "hal.dll", "ide.sys" */ + uintptr_t VirtBase; /* Virtual address (mapped) */ + uintptr_t PhysBase; /* Raw physical address (file) */ + size_t ImageSize; /* File size / Image size */ +} BOOT_MODULE; + +typedef struct BOOT_INFO { + uint64_t Magic; + + /* Physical memory. */ + MEMORY_MAP MemoryMap; + + /* GOP framebuffer. */ + uintptr_t FramebufferBase; + uint32_t FramebufferWidth; + uint32_t FramebufferHeight; + uint32_t FramebufferStride; /* pixels per row */ + + /* Loaded modules. */ + BOOT_MODULE Modules[MAX_BOOT_MODULES]; + uint32_t ModuleCount; + uint32_t _pad1; + + char CommandLine[64]; + + /* ACPI RSDP physical address (for APIC, HPET). */ + uintptr_t RsdpPhysical; + + /* Direct physical window base - always 0xFFFF880000000000. */ + uintptr_t PhysicalMapBase; + + /* From boot.ini */ + uint32_t Debug; +} BOOT_INFO; diff --git a/code/hal/hal_api.h b/code/public/ntlite/ddi/hal_api.h similarity index 99% rename from code/hal/hal_api.h rename to code/public/ntlite/ddi/hal_api.h index 2b59b15..ed2c3b2 100644 --- a/code/hal/hal_api.h +++ b/code/public/ntlite/ddi/hal_api.h @@ -3,7 +3,7 @@ #include #include #include -#include +#include typedef struct BOOT_INFO BOOT_INFO; diff --git a/code/hal/io_driver.h b/code/public/ntlite/ddi/io_driver.h similarity index 98% rename from code/hal/io_driver.h rename to code/public/ntlite/ddi/io_driver.h index b2289ae..60c52a7 100644 --- a/code/hal/io_driver.h +++ b/code/public/ntlite/ddi/io_driver.h @@ -8,7 +8,7 @@ #include #include #include -#include +#include typedef struct HAL_API HAL_API; typedef KSTATUS (*DRIVER_ENTRY_FN)(const HAL_API* hal); diff --git a/code/kernel/net_abi.h b/code/public/ntlite/ddi/net_abi.h similarity index 100% rename from code/kernel/net_abi.h rename to code/public/ntlite/ddi/net_abi.h diff --git a/code/kernel/net_device.h b/code/public/ntlite/ddi/net_device.h similarity index 98% rename from code/kernel/net_device.h rename to code/public/ntlite/ddi/net_device.h index e78c521..9762e12 100644 --- a/code/kernel/net_device.h +++ b/code/public/ntlite/ddi/net_device.h @@ -7,7 +7,7 @@ #include #include -#include +#include #define NET_DEVICE_NAME_MAX 16u #define NET_HWADDR_MAX 16u diff --git a/code/kernel/net_stack.h b/code/public/ntlite/ddi/net_stack.h similarity index 96% rename from code/kernel/net_stack.h rename to code/public/ntlite/ddi/net_stack.h index 1ea3963..623e3d1 100644 --- a/code/kernel/net_stack.h +++ b/code/public/ntlite/ddi/net_stack.h @@ -6,9 +6,9 @@ #include #include -#include -#include -#include +#include +#include +#include #define NET_STACK_PROVIDER_VERSION 1u diff --git a/code/public/ntlite/dirent.h b/code/public/ntlite/dirent.h new file mode 100644 index 0000000..94d25cc --- /dev/null +++ b/code/public/ntlite/dirent.h @@ -0,0 +1,13 @@ +#pragma once +// dirent.h - directory entry returned by SysReadDir. + +#include + +#define SYS_DIR_NAME_MAX 260 + +// Attribute flags match FAT32/Win32: 0x10 directory, 0x20 archive/file. +typedef struct SYS_DIR_ENTRY { + char Name[SYS_DIR_NAME_MAX]; + uint8_t Attr; + uint32_t FileSize; +} SYS_DIR_ENTRY; diff --git a/code/kernel/memory_map.h b/code/public/ntlite/memory_map.h similarity index 100% rename from code/kernel/memory_map.h rename to code/public/ntlite/memory_map.h diff --git a/code/kernel/ke_status.h b/code/public/ntlite/status.h similarity index 100% rename from code/kernel/ke_status.h rename to code/public/ntlite/status.h diff --git a/code/syscall/sys_string.h b/code/public/ntlite/string_view.h similarity index 100% rename from code/syscall/sys_string.h rename to code/public/ntlite/string_view.h diff --git a/code/syscall/syscall.h b/code/public/ntlite/syscall.h similarity index 99% rename from code/syscall/syscall.h rename to code/public/ntlite/syscall.h index 68d79f8..9535211 100644 --- a/code/syscall/syscall.h +++ b/code/public/ntlite/syscall.h @@ -5,7 +5,8 @@ #include #include #include -#include "sys_string.h" +#include +#include #define SYS_STATUS_SUCCESS 0u #define SYS_STATUS_TIMEOUT 3u @@ -259,7 +260,7 @@ uint32_t SysDeleteFile(const SYS_PATH_REQUEST* request); uint32_t SysRenameFile(const SYS_RENAME_FILE_REQUEST* request); uint32_t SysOpenDir(const SYS_PATH_HANDLE_REQUEST* request); -uint32_t SysReadDir(uint32_t handle, void* dirEntryBuffer); +uint32_t SysReadDir(uint32_t handle, SYS_DIR_ENTRY* entryOut); uint32_t SysCreateDir(const SYS_PATH_REQUEST* request); uint32_t SysRemoveDir(const SYS_PATH_REQUEST* request); uint32_t SysSetCwd(const SYS_PATH_REQUEST* request); diff --git a/code/doom/PureDOOM.h b/code/user/apps/doom/PureDOOM.h similarity index 100% rename from code/doom/PureDOOM.h rename to code/user/apps/doom/PureDOOM.h diff --git a/code/doom/doom.c b/code/user/apps/doom/doom.c similarity index 99% rename from code/doom/doom.c rename to code/user/apps/doom/doom.c index 037bbf5..41cd143 100644 --- a/code/doom/doom.c +++ b/code/user/apps/doom/doom.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #define DOOM_IMPLEMENTATION #include "PureDOOM.h" diff --git a/code/doom/doom1.wad b/code/user/apps/doom/doom1.wad similarity index 100% rename from code/doom/doom1.wad rename to code/user/apps/doom/doom1.wad diff --git a/code/edit/edit.c b/code/user/apps/edit/edit.c similarity index 99% rename from code/edit/edit.c rename to code/user/apps/edit/edit.c index 54db77c..a39f2a0 100644 --- a/code/edit/edit.c +++ b/code/user/apps/edit/edit.c @@ -9,7 +9,7 @@ #include #include #include -#include +#include #define GLYPH_W 8 #define GLYPH_H 16 diff --git a/code/httpget/httpget.c b/code/user/apps/httpget/httpget.c similarity index 99% rename from code/httpget/httpget.c rename to code/user/apps/httpget/httpget.c index 0395d48..fb6fb1e 100644 --- a/code/httpget/httpget.c +++ b/code/user/apps/httpget/httpget.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include static void print(const char* s) { if (s) { SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) }; SysWriteConsole(&req); } diff --git a/code/ping/ping.c b/code/user/apps/ping/ping.c similarity index 99% rename from code/ping/ping.c rename to code/user/apps/ping/ping.c index 9b1e25e..2e74aa8 100644 --- a/code/ping/ping.c +++ b/code/user/apps/ping/ping.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #define PING_DEFAULT_TARGET "10.0.2.2" #define PING_DEFAULT_COUNT 4u diff --git a/code/resolve/resolve.c b/code/user/apps/resolve/resolve.c similarity index 98% rename from code/resolve/resolve.c rename to code/user/apps/resolve/resolve.c index af4c81e..0009033 100644 --- a/code/resolve/resolve.c +++ b/code/user/apps/resolve/resolve.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include static void print(const char* s) { if (s) { SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) }; SysWriteConsole(&req); } diff --git a/code/shell_native/shell_native.c b/code/user/apps/shell_native/shell_native.c similarity index 99% rename from code/shell_native/shell_native.c rename to code/user/apps/shell_native/shell_native.c index e1dc451..db732a7 100644 --- a/code/shell_native/shell_native.c +++ b/code/user/apps/shell_native/shell_native.c @@ -2,8 +2,7 @@ #include #include #include -#include -#include +#include #define MAX_CMD 256 @@ -147,7 +146,7 @@ static void cmd_dir(const char* path) { return; } - KDIR_ENTRY ke; + SYS_DIR_ENTRY ke; while (SysReadDir(hDir, &ke) == 0) { // Corrected Attribute Check: 0x10 is the Directory bit in FAT if (ke.Attr & 0x10) { diff --git a/code/shell_posix/shell_posix.c b/code/user/apps/shell_posix/shell_posix.c similarity index 99% rename from code/shell_posix/shell_posix.c rename to code/user/apps/shell_posix/shell_posix.c index f73a1b2..52235c9 100644 --- a/code/shell_posix/shell_posix.c +++ b/code/user/apps/shell_posix/shell_posix.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #define MAX_CMD 256 #define NAME_MAX 259 diff --git a/code/shell_win32/shell_win32.c b/code/user/apps/shell_win32/shell_win32.c similarity index 100% rename from code/shell_win32/shell_win32.c rename to code/user/apps/shell_win32/shell_win32.c diff --git a/code/tcpserve/tcpserve.c b/code/user/apps/tcpserve/tcpserve.c similarity index 99% rename from code/tcpserve/tcpserve.c rename to code/user/apps/tcpserve/tcpserve.c index 9bbc86e..c313c9c 100644 --- a/code/tcpserve/tcpserve.c +++ b/code/user/apps/tcpserve/tcpserve.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include static void print(const char* s) { if (s) { SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) }; SysWriteConsole(&req); } diff --git a/code/udp/udp.c b/code/user/apps/udp/udp.c similarity index 99% rename from code/udp/udp.c rename to code/user/apps/udp/udp.c index cb96660..26c33c9 100644 --- a/code/udp/udp.c +++ b/code/user/apps/udp/udp.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include static void print(const char* s) { if (s) { SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) }; SysWriteConsole(&req); } diff --git a/code/video/bink.h b/code/user/apps/video/bink.h similarity index 100% rename from code/video/bink.h rename to code/user/apps/video/bink.h diff --git a/code/video/bink2w64.dll b/code/user/apps/video/bink2w64.dll similarity index 100% rename from code/video/bink2w64.dll rename to code/user/apps/video/bink2w64.dll diff --git a/code/video/bink2w64.lib b/code/user/apps/video/bink2w64.lib similarity index 100% rename from code/video/bink2w64.lib rename to code/user/apps/video/bink2w64.lib diff --git a/code/video/rrCore.h b/code/user/apps/video/rrCore.h similarity index 100% rename from code/video/rrCore.h rename to code/user/apps/video/rrCore.h diff --git a/code/video/video.bk2 b/code/user/apps/video/video.bk2 similarity index 100% rename from code/video/video.bk2 rename to code/user/apps/video/video.bk2 diff --git a/code/video/video.c b/code/user/apps/video/video.c similarity index 100% rename from code/video/video.c rename to code/user/apps/video/video.c diff --git a/code/posix/posix.h b/code/user/personalities/posix/posix.h similarity index 100% rename from code/posix/posix.h rename to code/user/personalities/posix/posix.h diff --git a/code/posix/posix_dir.c b/code/user/personalities/posix/posix_dir.c similarity index 88% rename from code/posix/posix_dir.c rename to code/user/personalities/posix/posix_dir.c index f87a67c..2fdab04 100644 --- a/code/posix/posix_dir.c +++ b/code/user/personalities/posix/posix_dir.c @@ -1,17 +1,11 @@ // posix_dir.c - chdir, getcwd, opendir, readdir, closedir #include -#include +#include #include "posix.h" #include "posix_path.h" -// KDIR_ENTRY layout mirrors io_file.h - duplicated here to avoid -// pulling kernel headers into posix.dll -#define KDIR_NAME_MAX 260 -typedef struct { - char Name[KDIR_NAME_MAX]; - uint8_t Attr; - uint32_t FileSize; -} KDIR_ENTRY; +typedef SYS_DIR_ENTRY KDIR_ENTRY; + #define KATTR_DIR 0x10 diff --git a/code/posix/posix_fd.c b/code/user/personalities/posix/posix_fd.c similarity index 98% rename from code/posix/posix_fd.c rename to code/user/personalities/posix/posix_fd.c index e5c4541..edcb148 100644 --- a/code/posix/posix_fd.c +++ b/code/user/personalities/posix/posix_fd.c @@ -1,5 +1,5 @@ // posix_fd.c - file descriptor table -#include +#include #include "posix.h" #include "posix_fd.h" diff --git a/code/posix/posix_fd.h b/code/user/personalities/posix/posix_fd.h similarity index 100% rename from code/posix/posix_fd.h rename to code/user/personalities/posix/posix_fd.h diff --git a/code/posix/posix_io.c b/code/user/personalities/posix/posix_io.c similarity index 99% rename from code/posix/posix_io.c rename to code/user/personalities/posix/posix_io.c index d5487ab..735a750 100644 --- a/code/posix/posix_io.c +++ b/code/user/personalities/posix/posix_io.c @@ -1,7 +1,7 @@ // posix_io.c - open, read, write, close, lseek #include #include -#include +#include #include "posix.h" #include "posix_fd.h" #include "posix_path.h" diff --git a/code/posix/posix_path.c b/code/user/personalities/posix/posix_path.c similarity index 100% rename from code/posix/posix_path.c rename to code/user/personalities/posix/posix_path.c diff --git a/code/posix/posix_path.h b/code/user/personalities/posix/posix_path.h similarity index 100% rename from code/posix/posix_path.h rename to code/user/personalities/posix/posix_path.h diff --git a/code/posix/posix_proc.c b/code/user/personalities/posix/posix_proc.c similarity index 99% rename from code/posix/posix_proc.c rename to code/user/personalities/posix/posix_proc.c index 665a7ab..8f49db4 100644 --- a/code/posix/posix_proc.c +++ b/code/user/personalities/posix/posix_proc.c @@ -1,7 +1,7 @@ // posix_proc.c - posix_spawn, waitpid, getpid #include #include -#include +#include #include "posix.h" #include "posix_path.h" diff --git a/code/posix/posix_socket.c b/code/user/personalities/posix/posix_socket.c similarity index 99% rename from code/posix/posix_socket.c rename to code/user/personalities/posix/posix_socket.c index 44f393c..8ee04e2 100644 --- a/code/posix/posix_socket.c +++ b/code/user/personalities/posix/posix_socket.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "posix.h" #include "posix_fd.h" diff --git a/code/posix/posix_thread.c b/code/user/personalities/posix/posix_thread.c similarity index 99% rename from code/posix/posix_thread.c rename to code/user/personalities/posix/posix_thread.c index 47e2296..f25e2c3 100644 --- a/code/posix/posix_thread.c +++ b/code/user/personalities/posix/posix_thread.c @@ -1,6 +1,6 @@ // posix_thread.c - pthread_create, pthread_join, pthread_exit, pthread_mutex_* #include -#include +#include #include "posix.h" // Thread return-value table (PID-keyed like the fd table) diff --git a/code/win32/gdi32.c b/code/user/personalities/win32/gdi32.c similarity index 99% rename from code/win32/gdi32.c rename to code/user/personalities/win32/gdi32.c index 5dd847e..d1087b5 100644 --- a/code/win32/gdi32.c +++ b/code/user/personalities/win32/gdi32.c @@ -1,7 +1,7 @@ // gdi32.c #include #include -#include +#include #if defined(__SSE2__) || defined(_M_X64) || defined(_M_IX86) #include diff --git a/code/win32/kernel32.c b/code/user/personalities/win32/kernel32.c similarity index 99% rename from code/win32/kernel32.c rename to code/user/personalities/win32/kernel32.c index 5683ab9..e269697 100644 --- a/code/win32/kernel32.c +++ b/code/user/personalities/win32/kernel32.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include // --------------------------------------------------------------------------- // Types @@ -1256,14 +1256,8 @@ __declspec(dllexport) BOOL WriteConsoleA(HANDLE hConsoleOutput, // Directory enumeration (FindFirstFileA / FindNextFileA / FindClose) // --------------------------------------------------------------------------- -// KDIR_ENTRY layout must exactly match the definition in io_file.h. -#define KDIR_NAME_MAX 260 +typedef SYS_DIR_ENTRY KDIR_ENTRY; -typedef struct { - char Name[KDIR_NAME_MAX]; - uint8_t Attr; - uint32_t FileSize; -} KDIR_ENTRY; // FIND_HANDLE is a user-side wrapper: it stores the kernel dir handle and // the wildcard pattern so FindNextFileA can filter subsequent entries. diff --git a/code/win32/ole32.c b/code/user/personalities/win32/ole32.c similarity index 96% rename from code/win32/ole32.c rename to code/user/personalities/win32/ole32.c index 4046d84..10cfff1 100644 --- a/code/win32/ole32.c +++ b/code/user/personalities/win32/ole32.c @@ -1,80 +1,80 @@ -// ole32.c - Win32 COM / OLE stubs -// No COM infrastructure at this stage; all functions fail gracefully. -#include -#include -#include - -// --------------------------------------------------------------------------- -// Types -// --------------------------------------------------------------------------- -typedef long HRESULT; -typedef void* IUnknown; - -#define S_OK ((HRESULT)0x00000000L) -#define E_NOTIMPL ((HRESULT)0x80004001L) -#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) -#define COINIT_MULTITHREADED 0x0 - -// GUID - 16-byte COM interface identifier. -typedef struct { - unsigned int Data1; - unsigned short Data2; - unsigned short Data3; - unsigned char Data4[8]; -} GUID; - -// PROPVARIANT - variant type used by shell / media APIs. -typedef struct { - unsigned short vt; - unsigned short wReserved1, wReserved2, wReserved3; - union { - long long hVal; - double dblVal; - void* punkVal; - unsigned char bVal; - unsigned int ulVal; - // ... (only common fields; full union is ~16 bytes) - unsigned char padding[16]; - }; -} PROPVARIANT; - -// --------------------------------------------------------------------------- -// COM initialisation -// --------------------------------------------------------------------------- -__declspec(dllexport) HRESULT CoInitializeEx(void* reserved, unsigned long coInit) { - (void)reserved; (void)coInit; - return S_OK; // Pretend success; no actual apartment is created. -} - -__declspec(dllexport) void CoUninitialize(void) { - // No-op. -} - -// --------------------------------------------------------------------------- -// Object creation -// --------------------------------------------------------------------------- -__declspec(dllexport) HRESULT CoCreateInstance(const GUID* clsid, IUnknown* outer, - unsigned long ctx, const GUID* iid, - void** ppv) { - (void)clsid; (void)outer; (void)ctx; (void)iid; - if (ppv) *ppv = (void*)0; - return E_NOTIMPL; -} - -// --------------------------------------------------------------------------- -// Memory -// --------------------------------------------------------------------------- -__declspec(dllexport) void CoTaskMemFree(void* pv) { - if (pv) SysFree(pv); -} - -// --------------------------------------------------------------------------- -// PROPVARIANT -// --------------------------------------------------------------------------- -__declspec(dllexport) HRESULT PropVariantClear(PROPVARIANT* pvar) { - if (!pvar) return E_NOTIMPL; - // Zero the entire structure; no deep release needed for stub types. - unsigned char* p = (unsigned char*)pvar; - for (size_t i = 0; i < sizeof(*pvar); i++) p[i] = 0; - return S_OK; -} +// ole32.c - Win32 COM / OLE stubs +// No COM infrastructure at this stage; all functions fail gracefully. +#include +#include +#include + +// --------------------------------------------------------------------------- +// Types +// --------------------------------------------------------------------------- +typedef long HRESULT; +typedef void* IUnknown; + +#define S_OK ((HRESULT)0x00000000L) +#define E_NOTIMPL ((HRESULT)0x80004001L) +#define E_OUTOFMEMORY ((HRESULT)0x8007000EL) +#define COINIT_MULTITHREADED 0x0 + +// GUID - 16-byte COM interface identifier. +typedef struct { + unsigned int Data1; + unsigned short Data2; + unsigned short Data3; + unsigned char Data4[8]; +} GUID; + +// PROPVARIANT - variant type used by shell / media APIs. +typedef struct { + unsigned short vt; + unsigned short wReserved1, wReserved2, wReserved3; + union { + long long hVal; + double dblVal; + void* punkVal; + unsigned char bVal; + unsigned int ulVal; + // ... (only common fields; full union is ~16 bytes) + unsigned char padding[16]; + }; +} PROPVARIANT; + +// --------------------------------------------------------------------------- +// COM initialisation +// --------------------------------------------------------------------------- +__declspec(dllexport) HRESULT CoInitializeEx(void* reserved, unsigned long coInit) { + (void)reserved; (void)coInit; + return S_OK; // Pretend success; no actual apartment is created. +} + +__declspec(dllexport) void CoUninitialize(void) { + // No-op. +} + +// --------------------------------------------------------------------------- +// Object creation +// --------------------------------------------------------------------------- +__declspec(dllexport) HRESULT CoCreateInstance(const GUID* clsid, IUnknown* outer, + unsigned long ctx, const GUID* iid, + void** ppv) { + (void)clsid; (void)outer; (void)ctx; (void)iid; + if (ppv) *ppv = (void*)0; + return E_NOTIMPL; +} + +// --------------------------------------------------------------------------- +// Memory +// --------------------------------------------------------------------------- +__declspec(dllexport) void CoTaskMemFree(void* pv) { + if (pv) SysFree(pv); +} + +// --------------------------------------------------------------------------- +// PROPVARIANT +// --------------------------------------------------------------------------- +__declspec(dllexport) HRESULT PropVariantClear(PROPVARIANT* pvar) { + if (!pvar) return E_NOTIMPL; + // Zero the entire structure; no deep release needed for stub types. + unsigned char* p = (unsigned char*)pvar; + for (size_t i = 0; i < sizeof(*pvar); i++) p[i] = 0; + return S_OK; +} diff --git a/code/win32/user32.c b/code/user/personalities/win32/user32.c similarity index 98% rename from code/win32/user32.c rename to code/user/personalities/win32/user32.c index 61aff41..beaf9a6 100644 --- a/code/win32/user32.c +++ b/code/user/personalities/win32/user32.c @@ -1,7 +1,7 @@ // user32.c - Win32 User Interface #include #include -#include +#include typedef void* HWND; typedef void* HDC; diff --git a/code/win32/winmm.c b/code/user/personalities/win32/winmm.c similarity index 96% rename from code/win32/winmm.c rename to code/user/personalities/win32/winmm.c index bf2433c..30cc01b 100644 --- a/code/win32/winmm.c +++ b/code/user/personalities/win32/winmm.c @@ -1,125 +1,125 @@ -// winmm.c - Win32 multimedia: waveform audio, timer -// Stubs only; no audio hardware access at this stage. -#include -#include -#include - -// --------------------------------------------------------------------------- -// Types -// --------------------------------------------------------------------------- -typedef unsigned int MMRESULT; -typedef void* HWAVEOUT; - -#define MMSYSERR_NOERROR 0 -#define MMSYSERR_NOTSUPPORTED 8 -#define WAVERR_STILLPLAYING 33 - -// WAVEFORMATEX - standard PCM audio format descriptor. -typedef struct { - unsigned short wFormatTag; - unsigned short nChannels; - unsigned int nSamplesPerSec; - unsigned int nAvgBytesPerSec; - unsigned short nBlockAlign; - unsigned short wBitsPerSample; - unsigned short cbSize; -} WAVEFORMATEX; - -// WAVEHDR - buffer header submitted to waveOutWrite. -typedef struct _WAVEHDR { - char* lpData; - unsigned int dwBufferLength; - unsigned int dwBytesRecorded; - uintptr_t dwUser; - unsigned int dwFlags; - unsigned int dwLoops; - struct _WAVEHDR* lpNext; - uintptr_t reserved; -} WAVEHDR; - -// MMTIME - used by waveOutGetPosition. -typedef struct { - unsigned int wType; - union { - unsigned int ms; - unsigned int sample; - unsigned int cb; - unsigned int ticks; - } u; -} MMTIME; - -// --------------------------------------------------------------------------- -// Timer -// --------------------------------------------------------------------------- - -__declspec(dllexport) unsigned long timeGetTime(void) { - return (unsigned long)(SysGetTick() / 1000u); -} - -// --------------------------------------------------------------------------- -// Waveform audio (stubs - no audio hardware at this stage) -// --------------------------------------------------------------------------- - -__declspec(dllexport) MMRESULT waveOutOpen(HWAVEOUT* phwo, unsigned int deviceId, - const WAVEFORMATEX* fmt, uintptr_t callback, - uintptr_t callbackInstance, unsigned long flags) { - (void)deviceId; (void)fmt; (void)callback; (void)callbackInstance; (void)flags; - if (phwo) *phwo = (void*)0; - return MMSYSERR_NOTSUPPORTED; -} - -__declspec(dllexport) MMRESULT waveOutClose(HWAVEOUT hwo) { - (void)hwo; return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT waveOutPrepareHeader(HWAVEOUT hwo, WAVEHDR* hdr, - unsigned int size) { - (void)hwo; (void)hdr; (void)size; return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT waveOutUnprepareHeader(HWAVEOUT hwo, WAVEHDR* hdr, - unsigned int size) { - (void)hwo; (void)hdr; (void)size; return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT waveOutWrite(HWAVEOUT hwo, WAVEHDR* hdr, unsigned int size) { - (void)hwo; (void)hdr; (void)size; return MMSYSERR_NOTSUPPORTED; -} - -__declspec(dllexport) MMRESULT waveOutPause(HWAVEOUT hwo) { - (void)hwo; return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT waveOutRestart(HWAVEOUT hwo) { - (void)hwo; return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT waveOutReset(HWAVEOUT hwo) { - (void)hwo; return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT waveOutSetVolume(HWAVEOUT hwo, unsigned long volume) { - (void)hwo; (void)volume; return MMSYSERR_NOTSUPPORTED; -} - -__declspec(dllexport) MMRESULT waveOutGetPosition(HWAVEOUT hwo, MMTIME* mmt, - unsigned int size) { - (void)hwo; (void)size; - if (mmt) { mmt->wType = 0; mmt->u.ms = 0; } - return MMSYSERR_NOERROR; -} - -// --------------------------------------------------------------------------- -// Timer resolution control -// No hardware timer reprogramming at this stage; pretend success so callers -// that wrap their audio/game loop in timeBeginPeriod(1) don't bail out. -// --------------------------------------------------------------------------- -__declspec(dllexport) MMRESULT timeBeginPeriod(unsigned int uPeriod) { - (void)uPeriod; - return MMSYSERR_NOERROR; -} - -__declspec(dllexport) MMRESULT timeEndPeriod(unsigned int uPeriod) { - (void)uPeriod; - return MMSYSERR_NOERROR; -} +// winmm.c - Win32 multimedia: waveform audio, timer +// Stubs only; no audio hardware access at this stage. +#include +#include +#include + +// --------------------------------------------------------------------------- +// Types +// --------------------------------------------------------------------------- +typedef unsigned int MMRESULT; +typedef void* HWAVEOUT; + +#define MMSYSERR_NOERROR 0 +#define MMSYSERR_NOTSUPPORTED 8 +#define WAVERR_STILLPLAYING 33 + +// WAVEFORMATEX - standard PCM audio format descriptor. +typedef struct { + unsigned short wFormatTag; + unsigned short nChannels; + unsigned int nSamplesPerSec; + unsigned int nAvgBytesPerSec; + unsigned short nBlockAlign; + unsigned short wBitsPerSample; + unsigned short cbSize; +} WAVEFORMATEX; + +// WAVEHDR - buffer header submitted to waveOutWrite. +typedef struct _WAVEHDR { + char* lpData; + unsigned int dwBufferLength; + unsigned int dwBytesRecorded; + uintptr_t dwUser; + unsigned int dwFlags; + unsigned int dwLoops; + struct _WAVEHDR* lpNext; + uintptr_t reserved; +} WAVEHDR; + +// MMTIME - used by waveOutGetPosition. +typedef struct { + unsigned int wType; + union { + unsigned int ms; + unsigned int sample; + unsigned int cb; + unsigned int ticks; + } u; +} MMTIME; + +// --------------------------------------------------------------------------- +// Timer +// --------------------------------------------------------------------------- + +__declspec(dllexport) unsigned long timeGetTime(void) { + return (unsigned long)(SysGetTick() / 1000u); +} + +// --------------------------------------------------------------------------- +// Waveform audio (stubs - no audio hardware at this stage) +// --------------------------------------------------------------------------- + +__declspec(dllexport) MMRESULT waveOutOpen(HWAVEOUT* phwo, unsigned int deviceId, + const WAVEFORMATEX* fmt, uintptr_t callback, + uintptr_t callbackInstance, unsigned long flags) { + (void)deviceId; (void)fmt; (void)callback; (void)callbackInstance; (void)flags; + if (phwo) *phwo = (void*)0; + return MMSYSERR_NOTSUPPORTED; +} + +__declspec(dllexport) MMRESULT waveOutClose(HWAVEOUT hwo) { + (void)hwo; return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT waveOutPrepareHeader(HWAVEOUT hwo, WAVEHDR* hdr, + unsigned int size) { + (void)hwo; (void)hdr; (void)size; return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT waveOutUnprepareHeader(HWAVEOUT hwo, WAVEHDR* hdr, + unsigned int size) { + (void)hwo; (void)hdr; (void)size; return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT waveOutWrite(HWAVEOUT hwo, WAVEHDR* hdr, unsigned int size) { + (void)hwo; (void)hdr; (void)size; return MMSYSERR_NOTSUPPORTED; +} + +__declspec(dllexport) MMRESULT waveOutPause(HWAVEOUT hwo) { + (void)hwo; return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT waveOutRestart(HWAVEOUT hwo) { + (void)hwo; return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT waveOutReset(HWAVEOUT hwo) { + (void)hwo; return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT waveOutSetVolume(HWAVEOUT hwo, unsigned long volume) { + (void)hwo; (void)volume; return MMSYSERR_NOTSUPPORTED; +} + +__declspec(dllexport) MMRESULT waveOutGetPosition(HWAVEOUT hwo, MMTIME* mmt, + unsigned int size) { + (void)hwo; (void)size; + if (mmt) { mmt->wType = 0; mmt->u.ms = 0; } + return MMSYSERR_NOERROR; +} + +// --------------------------------------------------------------------------- +// Timer resolution control +// No hardware timer reprogramming at this stage; pretend success so callers +// that wrap their audio/game loop in timeBeginPeriod(1) don't bail out. +// --------------------------------------------------------------------------- +__declspec(dllexport) MMRESULT timeBeginPeriod(unsigned int uPeriod) { + (void)uPeriod; + return MMSYSERR_NOERROR; +} + +__declspec(dllexport) MMRESULT timeEndPeriod(unsigned int uPeriod) { + (void)uPeriod; + return MMSYSERR_NOERROR; +} diff --git a/code/syscall/syscall_nr.inc b/code/user/syscall/syscall_nr.inc similarity index 100% rename from code/syscall/syscall_nr.inc rename to code/user/syscall/syscall_nr.inc diff --git a/code/syscall/syscall_stubs.asm b/code/user/syscall/syscall_stubs.asm similarity index 100% rename from code/syscall/syscall_stubs.asm rename to code/user/syscall/syscall_stubs.asm diff --git a/code/init/init.c b/code/user/system/init/init.c similarity index 98% rename from code/init/init.c rename to code/user/system/init/init.c index 839fec5..d8e4d85 100644 --- a/code/init/init.c +++ b/code/user/system/init/init.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #define STATUS_SUCCESS 0u diff --git a/code/async_apc/async_apc.c b/code/user/tests/async_apc/async_apc.c similarity index 99% rename from code/async_apc/async_apc.c rename to code/user/tests/async_apc/async_apc.c index 4ac0354..fbd8962 100644 --- a/code/async_apc/async_apc.c +++ b/code/user/tests/async_apc/async_apc.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #define EVENT_AUTO_RESET 0u diff --git a/code/async_cancel/async_cancel.c b/code/user/tests/async_cancel/async_cancel.c similarity index 99% rename from code/async_cancel/async_cancel.c rename to code/user/tests/async_cancel/async_cancel.c index 2b4e98c..abb800a 100644 --- a/code/async_cancel/async_cancel.c +++ b/code/user/tests/async_cancel/async_cancel.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #define EVENT_AUTO_RESET 0u diff --git a/readme.md b/readme.md index 3a088c2..fb21be4 100644 --- a/readme.md +++ b/readme.md @@ -16,6 +16,7 @@ The codebase is still small enough to understand, but large enough to hurt your - UEFI bootloader - higher-half x86-64 kernel +- real SMP - physical memory manager - virtual memory manager with kernel pool and user heap - W^X-style user page protections diff --git a/runa.bat b/runa.bat index e36d7fa..69203b0 100644 --- a/runa.bat +++ b/runa.bat @@ -1 +1 @@ -@start qemu-system-x86_64 -drive if=pflash,format=raw,readonly=on,file=OVMF\OVMF_CODE_4M.fd -drive if=pflash,format=raw,file=OVMF\OVMF_VARS_4M_d.fd -device ahci,id=ahci -drive format=vpc,file=disk.vhd,if=none,id=disk0 -device ide-hd,bus=ahci.0,drive=disk0 -serial stdio -m 256M -netdev user,id=net0,hostfwd=tcp::8080-:8080 -device rtl8139,netdev=net0 +@start qemu-system-x86_64 -drive if=pflash,format=raw,readonly=on,file=OVMF\OVMF_CODE_4M.fd -drive if=pflash,format=raw,file=OVMF\OVMF_VARS_4M_d.fd -device ahci,id=ahci -drive format=vpc,file=disk.vhd,if=none,id=disk0 -device ide-hd,bus=ahci.0,drive=disk0 -serial stdio -M q35 -m 256M -smp cpus=4,cores=4,threads=1,sockets=1 -netdev user,id=net0,hostfwd=tcp::8080-:8080 -device rtl8139,netdev=net0