fix writing by using a virtual image instead of a physical thumbdrive, better document the hack in KeIrqDispatch

This commit is contained in:
maksw committed 2026-05-05 19:33:04 +02:00
1 parent 68b3fdbc63
commit 320a24e1a5
11 files changed
+88 -10

No files matched your search

+1
View File
@@ -2,3 +2,4 @@ vc140.pdb
bin/
obj/
qemu.log
disk.vhd
Binary file not shown.
+38 -1
View File
@@ -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.
+6 -1
View File
@@ -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]();
Binary file not shown.
+37
View File
@@ -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
)
+2 -4
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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