diff --git a/.gitignore b/.gitignore index 17b247e..b0c8347 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vc140.pdb bin/ obj/ qemu.log +disk.vhd \ No newline at end of file diff --git a/OVMF/OVMF_VARS_4M_d.fd b/OVMF/OVMF_VARS_4M_d.fd index cc7f78a..1449dba 100644 Binary files a/OVMF/OVMF_VARS_4M_d.fd and b/OVMF/OVMF_VARS_4M_d.fd differ diff --git a/build.bat b/build.bat index 25f3020..2032d36 100644 --- a/build.bat +++ b/build.bat @@ -3,7 +3,12 @@ setlocal enabledelayedexpansion set ROOT=%~dp0. set SRC=%ROOT%\code -set DEST=%NTLITE_DRIVE% +set VHD=%~dp0disk.vhd + +if not exist "%VHD%" ( + echo ERROR: disk.vhd not found. Run mkimage.bat first. + exit /b 1 +) if exist "obj" rd /s /q "obj" if exist "bin" rd /s /q "bin" @@ -129,6 +134,26 @@ echo Linking video.exe... 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 +:: ---- Mount disk image ---- +echo Mounting disk.vhd as Z: ... +set DPS=%TEMP%\ntlite_mnt_%RANDOM%.txt +( + echo select vdisk file="%VHD%" + echo attach vdisk + echo select partition 1 + echo assign letter=Z + echo exit +) > "%DPS%" +diskpart /s "%DPS%" +del "%DPS%" + +if not exist "Z:\" ( + echo ERROR: Could not mount disk.vhd as Z: + echo If Z: is already in use, change the letter in build.bat and mkimage.bat. + exit /b 1 +) +set DEST=Z: + :: ---- Copy to ESP layout ---- echo Assembling ESP... mkdir "%DEST%\drivers" 2>nul @@ -147,6 +172,18 @@ copy /y "bin\shell.exe" "%DEST%\" copy /y "bin\video.exe" "%DEST%\" 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%\" + +:: ---- Unmount disk image ---- +echo Unmounting disk.vhd... +set DPS=%TEMP%\ntlite_umnt_%RANDOM%.txt +( + echo select vdisk file="%VHD%" + echo detach vdisk + echo exit +) > "%DPS%" +diskpart /s "%DPS%" +del "%DPS%" echo. echo Build complete. diff --git a/code/kernel/ke_irq.c b/code/kernel/ke_irq.c index 2a8a4b8..82c82e6 100644 --- a/code/kernel/ke_irq.c +++ b/code/kernel/ke_irq.c @@ -18,7 +18,12 @@ __declspec(dllexport) void KeIrqRegister(uint8_t irq, void (*handler)(void)) { } void KeIrqDispatch(uint8_t irq) { - // eoi first, handler second because it doesn't work otherwise. + // KeIrqDispatch sends EOI after the handler returns, but the handler switched context before returning. + // The EOI call is still sitting on the idle thread's stack, waiting for that thread to be resumed. + // The LAPIC sees ISR[0x20] still set. Its rule is: don't deliver another interrupt at the same or lower priority until EOI is written. + // So the timer never fires again. The user process runs completely unpreempted until it calls SYS_EXIT_PROCESS, which calls KeYield, which cooperatively switches back + // and only then does the idle thread resume, KeIrqDispatch finally sends its EOI, and the timer starts firing again. + // To fix this we send EOI before calling the handler, not after. gHal->Intc.SendEoi(); if (irq < MAX_IRQS && gIrqHandlers[irq]) gIrqHandlers[irq](); diff --git a/code/video/bink2w64.dll b/code/video/bink2w64.dll new file mode 100644 index 0000000..44111b4 Binary files /dev/null and b/code/video/bink2w64.dll differ diff --git a/mkimage.bat b/mkimage.bat new file mode 100644 index 0000000..686fd67 --- /dev/null +++ b/mkimage.bat @@ -0,0 +1,37 @@ +@echo off +setlocal +set VHD=%~dp0disk.vhd + +echo === nt-lite: create disk image === +echo. + +if exist "%VHD%" ( + echo Removing old disk.vhd... + del "%VHD%" +) + +:: Write a diskpart script to a temp file (avoids pipe/echo escaping issues) +set DPS=%TEMP%\ntlite_mkimg_%RANDOM%.txt +( + echo create vdisk file="%VHD%" maximum=256 type=fixed + echo select vdisk file="%VHD%" + echo attach vdisk + echo create partition primary + echo format fs=fat32 label=NTLITE quick + echo detach vdisk + echo exit +) > "%DPS%" + +echo Creating 256 MB FAT32 image via diskpart... +diskpart /s "%DPS%" +del "%DPS%" + +if exist "%VHD%" ( + echo. + echo disk.vhd ready. Run build.bat to populate it. +) else ( + echo. + echo ERROR: disk.vhd was not created. + echo Make sure you are running as Administrator. + exit /b 1 +) diff --git a/readme.md b/readme.md index 874b206..1311892 100644 --- a/readme.md +++ b/readme.md @@ -26,11 +26,9 @@ It boots into a shell. ## how 2 build -* open env variables -* set `NTLITE_DRIVE` as your thumbdrive (ex. `G:`) -* set `NTLITE_NTPATH` as your thumbdrive (ex. `\\.\PhysicalDrive7`) -* open vs x64 build tools +* open vs x64 build tools as admin * cd into this directory +* `mkimage.bat` * `build.bat` * `run.bat`(ide)/`rund.bat`(ide, debug)/`runa.bat`(ahci)/`runad.bat`(ahci, debug) * enjoy diff --git a/run.bat b/run.bat index 6c6b6ef..f62681b 100644 --- a/run.bat +++ b/run.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.fd -drive format=raw,file=%NTLITE_NTPATH% -serial stdio +@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.fd -drive format=vpc,file=disk.vhd -serial stdio diff --git a/runa.bat b/runa.bat index 1a48adc..4ffe375 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=raw,file=%NTLITE_NTPATH%,if=none,id=disk0 -device ide-hd,bus=ahci.0,drive=disk0 -serial stdio +@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 diff --git a/runad.bat b/runad.bat index f9ebbb6..cf5eb53 100644 --- a/runad.bat +++ b/runad.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=raw,file=%NTLITE_NTPATH%,if=none,id=disk0 -device ide-hd,bus=ahci.0,drive=disk0 -m 4G -serial stdio -d in_asm,cpu_reset,int -D qemu.log -no-reboot -no-shutdown +@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 -m 4G -serial stdio -d in_asm,cpu_reset,int -D qemu.log -no-reboot -no-shutdown diff --git a/rund.bat b/rund.bat index a597b1d..2ff8e3b 100644 --- a/rund.bat +++ b/rund.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.fd -drive format=raw,file=%NTLITE_NTPATH% -m 4G -serial stdio -d in_asm,cpu_reset,int -D qemu.log -no-reboot -no-shutdown +@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.fd -drive format=vpc,file=disk.vhd -m 4G -serial stdio -d in_asm,cpu_reset,int -D qemu.log -no-reboot -no-shutdown