Files
nt-lite/build.bat
T

159 lines
6.6 KiB
Batchfile

@echo off
setlocal enabledelayedexpansion
set ROOT=%~dp0.
set SRC=%ROOT%\code
set DEST=G:\
if exist "obj" rd /s /q "obj"
if exist "bin" rd /s /q "bin"
mkdir "obj\boot" 2>nul
mkdir "obj\kernel" 2>nul
mkdir "obj\hal" 2>nul
mkdir "obj\syscall" 2>nul
mkdir "obj\win32" 2>nul
mkdir "obj\drivers" 2>nul
mkdir "obj\shell" 2>nul
mkdir "bin" 2>nul
set CFLAGS=/nologo /W4 /WX /Od /GS- /Gs999999 /Gz /Gy /EHsc- /GR- /Oi /Zi /std:c17 /D_CRT_SECURE_NO_WARNINGS /I"%SRC%\kernel" /I"%SRC%\hal"
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
:: ---- 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 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
)
:: ---- 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
:: ---- Compile HAL ----
echo Compiling hal...
for %%f in (%SRC%\hal\*.c) do (
cl %CFLAGS% /c /Fo"obj\hal\%%~nf.obj" "%%f" || exit /b 1
)
:: ---- Link hal.dll ----
echo Linking hal.dll...
link %LFLAGS% /DLL /OUT:"bin\hal.dll" ^
/ENTRY:HalInitialize /IGNORE:4216 ^
/EXPORT:HalInitialize /EXPORT:HalRegisterScheduler /EXPORT:HalGetApi ^
/EXPORT:IoRegisterDisk ^
obj\printf.obj obj\libc.obj obj\hal\*.obj || exit /b 1
:: ---- Compile kernel ----
echo Compiling kernel...
for %%f in (%SRC%\kernel\*.c) do (
cl %CFLAGS% /c /Fo"obj\kernel\%%~nf.obj" "%%f" || exit /b 1
)
:: ---- Link kernel.exe ----
echo Linking kernel.exe...
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:KernelMain /OUT:"bin\kernel.exe" ^
/PDB:"bin\kernel.pdb" /EXPORT:MmAllocatePool /EXPORT:MmFreePool /EXPORT:IoRegisterFilesystem ^
/EXPORT:KeSignalEvent /EXPORT:MmAllocateContiguous /EXPORT:ObDereferenceObject /EXPORT:KeEventCreate ^
/EXPORT:KeWaitForEvent /EXPORT:KeClearEvent /EXPORT:MmGetPhysicalAddress /EXPORT:DbgPrint /EXPORT:KeIrqDispatch ^
/EXPORT:MmMapPage /EXPORT:MmSetPageProtect ^
bin\hal.lib obj\ini_parser.obj obj\printf.obj obj\libc.obj obj\kernel\*.obj || exit /b 1
:: ---- Compile syscall.dll ----
echo Compiling syscall.dll...
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\syscall.dll" ^
/EXPORT:SysYield /EXPORT:SysAlloc /EXPORT:SysFree ^
/EXPORT:SysCreateThread /EXPORT:SysCloseHandle ^
/EXPORT:SysMutexCreate /EXPORT:SysMutexAcquire /EXPORT:SysMutexRelease ^
/EXPORT:SysSemCreate /EXPORT:SysSemWait /EXPORT:SysSemSignal ^
/EXPORT:SysEventCreate /EXPORT:SysEventSet /EXPORT:SysEventWait ^
/EXPORT:SysQueueCreate /EXPORT:SysQueueSend /EXPORT:SysQueueRecv ^
/EXPORT:SysScreenBlit /EXPORT:SysGetTick /EXPORT:SysSleep ^
/EXPORT:SysExitThread /EXPORT:SysExitProcess /EXPORT:SysDbgPrint ^
obj\syscall\stubs.obj || exit /b 1
:: ---- Compile win32.dll ----
echo Compiling win32.dll...
for %%f in (%SRC%\win32\*.c) do (
cl %CFLAGS% /c /Fo"obj\win32\%%~nf.obj" "%%f" || exit /b 1
)
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\win32.dll" ^
/EXPORT:HeapAlloc /EXPORT:HeapFree /EXPORT:HeapReAlloc ^
/EXPORT:CreateThread /EXPORT:ExitProcess /EXPORT:ExitThread ^
/EXPORT:Sleep /EXPORT:SwitchToThread ^
/EXPORT:CreateMutex /EXPORT:ReleaseMutex /EXPORT:WaitForSingleObject ^
/EXPORT:CreateEvent /EXPORT:SetEvent /EXPORT:CloseHandle ^
/EXPORT:GetTickCount /EXPORT:GetTickCount64 ^
/EXPORT:BitBlt /EXPORT:GetMessage /EXPORT:DispatchMessage /EXPORT:OutputDebugStringA ^
bin\syscall.lib obj\win32\*.obj || exit /b 1
:: ---- Compile drivers ----
echo Compiling drivers...
cl %CFLAGS% /I"%SRC%\hal" /c /Fo"obj\drivers\ide.obj" "%SRC%\drivers\ide\ide.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\ide.sys" /IGNORE:4216 /ENTRY:DriverEntry /EXPORT:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\ide.obj || exit /b 1
cl %CFLAGS% /I"%SRC%\hal" /c /Fo"obj\drivers\ahci.obj" "%SRC%\drivers\ahci\ahci.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\ahci.sys" /IGNORE:4216 /ENTRY:DriverEntry /EXPORT:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\ahci.obj || exit /b 1
cl %CFLAGS% /I"%SRC%\fat32" /c /Fo"obj\drivers\fat32.obj" "%SRC%\drivers\fat32\fat32.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\fat32.sys" /IGNORE:4216 /ENTRY:DriverEntry /EXPORT:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\fat32.obj || exit /b 1
cl %CFLAGS% /I"%SRC%\usb" /c /Fo"obj\drivers\usb.obj" "%SRC%\drivers\usb\usb.c" || exit /b 1
link /nologo /SUBSYSTEM:NATIVE /NODEFAULTLIB /DLL ^
/OUT:"bin\usb.sys" /IGNORE:4216 /ENTRY:DriverEntry /EXPORT:DriverEntry ^
bin\hal.lib bin\kernel.lib obj\libc.obj obj\drivers\usb.obj || exit /b 1
:: ---- Compile shell ----
echo Compiling shell...
for %%f in (%SRC%\shell\*.c) do (
cl %CFLAGS% /c /Fo"obj\shell\%%~nf.obj" "%%f" || exit /b 1
)
:: ---- Link shell.exe ----
echo Linking shell.exe...
link %LFLAGS% /SUBSYSTEM:NATIVE /ENTRY:main ^
/OUT:"bin\shell.exe" /PDB:"bin\shell.pdb" bin\win32.lib obj\libc.obj obj\shell\*.obj || exit /b 1
:: ---- Copy to ESP layout ----
echo Assembling ESP...
mkdir "%DEST%\drivers" 2>nul
mkdir "%DEST%\EFI\BOOT" 2>nul
copy /y "bin\bootx64.efi" "%DEST%\EFI\BOOT\"
copy /y "bin\kernel.exe" "%DEST%\"
copy /y "bin\hal.dll" "%DEST%\"
copy /y "bin\syscall.dll" "%DEST%\"
copy /y "bin\win32.dll" "%DEST%\"
copy /y "bin\ide.sys" "%DEST%\drivers\"
copy /y "bin\ahci.sys" "%DEST%\drivers\"
copy /y "bin\fat32.sys" "%DEST%\drivers\"
copy /y "bin\usb.sys" "%DEST%\drivers\"
copy /y "bin\shell.exe" "%DEST%\"
copy /y "%SRC%\boot.ini" "%DEST%\"
copy /y "%SRC%\drivers\drivers.ini" "%DEST%\drivers\"
echo.
echo Build complete.