├── .gitignore ├── CHANGES.log ├── Makefile ├── ReadMe.old ├── ReadMe.txt ├── WinVBlock.dev ├── changelog.txt ├── config.bat ├── gpl.txt ├── indent.sh ├── indent.txt ├── indent_add.sh ├── makechecked.bat ├── makedist.bat ├── makedriver.bat ├── makefree.bat ├── makeinf.bat ├── makeutils.bat ├── sign.bat └── src ├── aoe ├── aoe.rc ├── bus.c ├── driver.c ├── makedriver.bat ├── makefile ├── protocol.c ├── registry.c ├── wv_stdlib.c └── wv_string.c ├── httpdisk ├── COPYING.TXT ├── MAKEFILE ├── bus.c ├── httpdisk.c ├── httpdisk.rc ├── ksocket.c ├── ksocket.h ├── ktdi.c ├── ktdi.h ├── makedriver.bat └── readme.txt ├── httpdisk_util ├── COPYING.TXT ├── MAKEFILE ├── httpdisk.c ├── httpdisk.rc ├── readme.txt └── sources ├── include ├── aoe.h ├── bus.h ├── byte.h ├── debug.h ├── device.h ├── disk.h ├── driver.h ├── dummy.h ├── filedisk.h ├── grub4dos.h ├── httpdisk.h ├── irp.h ├── mdi.h ├── memdisk.h ├── mount.h ├── msvhd.h ├── portable.h ├── protocol.h ├── ramdisk.h ├── registry.h ├── resource.h ├── safehook.h ├── thread.h ├── winvblock.h ├── wv_stdbool.h ├── wv_stddef.h ├── wv_stdlib.h ├── wv_string.h └── x86.h ├── loader └── loader.c ├── nbp ├── pxe.asm │ ├── Makefile │ ├── aoe.S │ ├── aoe.h │ ├── aoe.ld │ ├── debug.S │ ├── global.S │ ├── int13.S │ ├── lib.S │ └── pxe.S └── pxe.c │ ├── Makefile │ ├── aoe.ld │ ├── asm.S │ ├── asm.h │ ├── debug.S │ ├── lib.c │ ├── lib.h │ ├── libasm.S │ ├── main.c │ ├── main.h │ ├── printf.c │ ├── pxe.c │ └── pxe.h ├── util ├── Wv.ico ├── winvblk.c └── winvblock.rc └── winvblock ├── debug.c ├── device.c ├── disk.c ├── driver.c ├── filedisk ├── filedisk.c ├── grub4dos.c ├── makelib.bat ├── pnp.c ├── scsi.c └── security.c ├── grub4dos ├── fdo.c ├── g4dbus.c └── makelib.bat ├── libbus ├── libbus.c ├── makelib.bat └── pnp.c ├── libdisk ├── dev_ctl.c ├── libdisk.c ├── makelib.bat ├── pnp.c └── scsi.c ├── mainbus ├── busirp.c ├── dummyirp.c ├── mainbus.c ├── mainbus.h ├── makefile └── makelib.bat ├── makedriver.bat ├── memdisk ├── fdo.c ├── makefile ├── makelib.bat └── memdisk.c ├── ramdisk ├── grub4dos.c ├── makelib.bat ├── memdisk.c └── ramdisk.c ├── registry.c ├── safehook ├── fdo.c ├── makelib.bat ├── pdo.c └── probe.c ├── winvblock.rc ├── wv_stdlib.c ├── wv_string.c └── wvlib ├── irp.c ├── makelib.bat └── thread.c /.gitignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | aoe.0 3 | bin 4 | obj 5 | sizes.txt 6 | WinVBlock.layout 7 | *~ 8 | *.err 9 | *.log 10 | *.wrn 11 | *.res 12 | objchk* 13 | objfre* 14 | makefile 15 | sources 16 | *.def 17 | -------------------------------------------------------------------------------- /CHANGES.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/CHANGES.log -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | INCLUDES := $(shell echo | cpp -v 2>&1 | sed -n '/\#include "..." search starts here:/,/End of search list./p' | grep "^ " | sed "s/^ \(.*\)$$/-I\1\/ddk/" | tr "\n" " " | sed "s/ $$//" | sed ":start;s/\/[^\/]*\/\.\.\//\//;t start") 2 | 3 | # Next line is duplicated in config.bat, edit both when adding files. 4 | c := driver.c registry.c bus.c aoedisk.c aoe.c protocol.c debug.c probe.c winvblock.rc 5 | h := driver.h aoe.h protocol.h mount.h portable.h 6 | 7 | # This is also duplicated in config.bat. 8 | # The c style aoe.0 is not yet stable enough to use. 9 | PXESTYLE := asm 10 | #PXESTYLE := c 11 | 12 | all: bin/aoe.0 bin/loader32.exe bin/wvblk32.sys bin/aoe.exe bin/winvblk.inf bin/txtsetup.oem 13 | 14 | clean: 15 | @rm -rf src/obj src/nbp/pxe.asm/obj src/nbp/pxe.c/obj bin 16 | 17 | dist: 18 | @sh -c "unset \`set | cut -f 1 -d \"=\" | egrep -v \"PATH|COMSPEC\"\` 2> /dev/null ; cmd /c makedist.bat" 19 | 20 | free: bin/winvblk.inf bin/txtsetup.oem $(addprefix src/,$c $h) Makefile 21 | @sh -c "unset \`set | cut -f 1 -d \"=\" | egrep -v \"PATH|COMSPEC\"\` 2> /dev/null ; cmd /c makefree.bat" 22 | @touch -r Makefile $(wildcard bin/*.sys) 23 | 24 | checked: bin/winvblk.inf bin/txtsetup.oem $(addprefix src/,$c $h) Makefile 25 | @sh -c "unset \`set | cut -f 1 -d \"=\" | egrep -v \"PATH|COMSPEC\"\` 2> /dev/null ; cmd /c makechecked.bat" 26 | @touch -r Makefile $(wildcard bin/*.sys) 27 | 28 | bin/aoe.0: src/nbp/pxe.$(PXESTYLE)/aoe.0 Makefile 29 | @mkdir -p bin 30 | cp src/nbp/pxe.$(PXESTYLE)/aoe.0 bin 31 | 32 | src/nbp/pxe.$(PXESTYLE)/aoe.0: $(wildcard src/nbp/pxe.$(PXESTYLE)/*.c) $(wildcard src/nbp/pxe.$(PXESTYLE)/*.h) $(wildcard src/nbp/pxe.$(PXESTYLE)/*.S) src/nbp/pxe.$(PXESTYLE)/aoe.ld src/nbp/pxe.$(PXESTYLE)/Makefile Makefile 33 | rm -rf src/nbp/pxe.$(PXESTYLE)/aoe.0 34 | make -C src/nbp/pxe.$(PXESTYLE) 35 | 36 | bin/winvblk.inf bin/txtsetup.oem: makeinf.bat Makefile 37 | @sh -c "unset \`set | cut -f 1 -d \"=\" | egrep -v \"PATH|COMSPEC\"\` 2> /dev/null ; cmd /c makeinf.bat ; exit 0" >/dev/null 2>&1 38 | touch bin/winvblk.inf 39 | touch bin/txtsetup.oem 40 | 41 | src/loader/obj/loader32.o: src/loader/loader.c src/portable.h Makefile 42 | @mkdir -p src/loader/obj 43 | @rm -rf src/loader/obj/loader32.o bin/loader32.exe bin/loader64.exe 44 | gcc $(INCLUDES) -c -Wall src/loader/loader.c -o src/loader/obj/loader32.o 45 | 46 | bin/loader32.exe: src/loader/obj/loader32.o Makefile 47 | @mkdir -p bin 48 | @rm -rf bin/loader32.exe bin/loader64.exe 49 | gcc $(INCLUDES) -Wall src/loader/obj/loader32.o -o bin/loader32.exe -lsetupapi 50 | strip bin/loader32.exe 51 | 52 | src/util/obj/winvblk.o: src/util/winvblk.c src/portable.h src/mount.h Makefile 53 | @mkdir -p src/obj 54 | @rm -rf src/util/obj/winvblk.o bin/aoe.exe 55 | gcc -Wall -c src/util/winvblk.c -o src/util/obj/winvblk.o 56 | 57 | bin/aoe.exe: src/util/obj/winvblk.o Makefile 58 | @mkdir -p bin 59 | @rm -rf bin/aoe.exe 60 | gcc -Wall src/util/obj/winvblk.o -o bin/aoe.exe 61 | strip bin/aoe.exe 62 | 63 | src/obj/driver.o: src/driver.c src/portable.h src/driver.h Makefile 64 | @mkdir -p src/obj 65 | @rm -rf src/obj/driver.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 66 | gcc $(INCLUDES) -c -Wall src/driver.c -o src/obj/driver.o 67 | 68 | src/obj/registry.o: src/registry.c src/portable.h Makefile 69 | @mkdir -p src/obj 70 | @rm -rf src/obj/registry.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 71 | gcc $(INCLUDES) -c -Wall src/registry.c -o src/obj/registry.o 72 | 73 | src/obj/bus.o: src/bus.c src/portable.h src/driver.h src/aoe.h src/mount.h Makefile 74 | @mkdir -p src/obj 75 | @rm -rf src/obj/bus.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 76 | gcc $(INCLUDES) -c -Wall src/bus.c -o src/obj/bus.o 77 | 78 | src/obj/aoedisk.o: src/aoedisk.c src/portable.h src/driver.h src/aoe.h Makefile 79 | @mkdir -p src/obj 80 | @rm -rf src/obj/aoedisk.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 81 | gcc $(INCLUDES) -c -Wall src/aoedisk.c -o src/obj/aoedisk.o 82 | 83 | src/obj/aoe.o: src/aoe.c src/portable.h src/driver.h src/aoe.h src/protocol.h Makefile 84 | @mkdir -p src/obj 85 | @rm -rf src/obj/aoe.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 86 | gcc $(INCLUDES) -c -Wall src/aoe.c -o src/obj/aoe.o 87 | 88 | src/obj/protocol.o: src/protocol.c src/portable.h src/driver.h src/aoe.h src/protocol.h Makefile 89 | @mkdir -p src/obj 90 | @rm -rf src/obj/protocol.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 91 | gcc $(INCLUDES) -c -Wall src/protocol.c -o src/obj/protocol.o 92 | 93 | src/obj/debug.o: src/debug.c src/portable.h src/driver.h src/mount.h Makefile 94 | @mkdir -p src/obj 95 | @rm -rf src/obj/debug.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 96 | gcc $(INCLUDES) -c -Wall src/debug.c -o src/obj/debug.o 97 | 98 | src/obj/probe.o: src/probe.c src/portable.h src/driver.h src/mount.h Makefile 99 | @mkdir -p src/obj 100 | @rm -rf src/obj/probe.o src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 101 | gcc $(INCLUDES) -c -Wall src/probe.c -o src/obj/probe.o 102 | 103 | src/obj/aoe.tmp: src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o probe.o Makefile 104 | @mkdir -p src/obj 105 | @rm -rf src/obj/aoe.tmp src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 106 | @gcc -Wall src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/probe.o -Wl,--base-file,src/obj/aoe.tmp -Wl,--entry,_DriverEntry@8 -nostartfiles -nostdlib -lntoskrnl -lhal -lndis -o null 107 | @rm -rf null.exe 108 | 109 | src/obj/aoe.exp: src/obj/aoe.tmp Makefile 110 | @mkdir -p src/obj 111 | @rm -rf src/obj/aoe.exp bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 112 | @dlltool --dllname wvblk32.sys --base-file src/obj/aoe.tmp --output-exp src/obj/aoe.exp 113 | 114 | bin/wvblk32.sys: src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/probe.o src/obj/aoe.exp Makefile 115 | @mkdir -p bin 116 | @rm -rf bin/wvblk32.sys bin/wvblk64.sys bin/wvblk32.pdb bin/wvblk64.pdb bin/loader64.exe 117 | @gcc -Wall src/obj/driver.o src/obj/registry.o src/obj/bus.o src/obj/aoedisk.o src/obj/aoe.o src/obj/protocol.o src/obj/debug.o src/obj/probe.o -Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,src/obj/aoe.exp -mdll -nostartfiles -nostdlib -lntoskrnl -lhal -lndis -o bin/wvblk32.sys 118 | # strip bin/wvblk32.sys 119 | -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | Licensed under the GPL version 3 or later. Some code licensed under the 2 | GPL version 2 or later. See GPL.TXT. 3 | 4 | After starting each driver, you should use Device Manager or the Found 5 | New Hardware wizard to update the drivers using the .INF files. Please 6 | do this for the WinVBlock driver before installing and starting the 7 | AoE and HTTPDisk drivers. 8 | 9 | 10 | To install using WinVBlk.Exe: 11 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 12 | Copy whichever .Sys files (drivers) you require into the C:\Windows\System32\Drivers\ directory, then run: 13 | 14 | winvblk.exe -cmd install -service xxxxbb 15 | 16 | where xxxxbb is the filename of the driver to install. For example: 17 | 18 | winvblk.exe -cmd install -service wvblk32 19 | 20 | 21 | To install using SC.Exe: 22 | ~~~~~~~~~~~~~~~~~~~~~~~~ 23 | Copy whichever .Sys files (drivers) you require into the whatever directory you like, then run: 24 | 25 | sc create WinVBlock binPath= c:\windows\system32\drivers\wvblk32.sys type= kernel start= boot group= "SCSI miniport" 26 | 27 | where you should substitute the path you've chosen. As another example, for the AoE driver, you could do: 28 | 29 | sc create AoE binPath= c:\windows\system32\drivers\aoe32.sys type= kernel start= boot group= "SCSI Class" 30 | 31 | As another example, for the HTTPDisk driver, you could do: 32 | 33 | sc create HTTPDisk binPath= c:\windows\system32\drivers\wvhttp32.sys type= kernel start= boot group= "SCSI Class" 34 | 35 | 36 | To start the services: 37 | ~~~~~~~~~~~~~~~~~~~~~~ 38 | You may use the Net.Exe command, as in: 39 | 40 | net start winvblock 41 | net start aoe 42 | net start httpdisk 43 | 44 | 45 | - Shao Miller -------------------------------------------------------------------------------- /changelog.txt: -------------------------------------------------------------------------------- 1 | WinVBlock changes are in CHANGES.log 2 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 | 4 | WinVBlock is derived from WinAoE. 5 | 6 | Original ChangeLog.txt from WinAoE follows: 7 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 | 0.97g: 9 | - added changelog.txt 10 | - fixed resend scheduler 11 | - some Makefile fixes 12 | - fixed some spelling in readme.txt 13 | - some changes to mount to not wait for a key after mount and unmount 14 | 15 | 0.97f: 16 | - Initial public release 17 | - revamped Makefile and added bat files to make compiling user-friendly 18 | - Implemented new scheduler 19 | - Implemented multiple disk unmount support (still buggy!) 20 | - added alpha c version of aoe.0 (still disabled in favor of the asm version) 21 | -------------------------------------------------------------------------------- /config.bat: -------------------------------------------------------------------------------- 1 | rem This is the root directory of the ddk. 2 | set ddkdir=c:\winddk\6001.18001 3 | 4 | rem Next two lines are duplicated in Makefile, edit both when adding files or changing pxe style. 5 | set c=driver.c registry.c bus.c bus_pnp.c bus_dev_ctl.c disk.c ramdisk.c filedisk.c memdisk.c grub4dos.c disk_pnp.c disk_dev_ctl.c disk_scsi.c debug.c probe.c winvblock.rc irp.c 6 | set pxestyle=asm 7 | -------------------------------------------------------------------------------- /indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Twice because of some indent bug which changes a file back and forth 3 | indent -bap -bc -bfda -bfde -bl -bli2 -bls -cbi2 -cdb -cdw -nce -ci2 -cli2 -i2 -ip2 -kr -l79 -lp -ncs -nhnl -pcs -pi2 -ppi2 -prs -psl -saf -sai -saw -sc -sob -ts8 $* 4 | indent -bap -bc -bfda -bfde -bl -bli2 -bls -cbi2 -cdb -cdw -nce -ci2 -cli2 -i2 -ip2 -kr -l79 -lp -ncs -nhnl -pcs -pi2 -ppi2 -prs -psl -saf -sai -saw -sc -sob -ts8 $* 5 | -------------------------------------------------------------------------------- /indent.txt: -------------------------------------------------------------------------------- 1 | indent 2 | -bap Force blank lines after procedure bodies 3 | -bc Force newline after comma in declaration 4 | -bfda Break the line before all arguments in a declaration 5 | -bfde Break the line after the last argument in a declaration 6 | -bl Put braces on line after if, etc. 7 | -bli2 Indent braces 2 spaces 8 | -bls Put braces on the line after struct declaration 9 | -cbi2 Indent braces after a case label 2 spaces 10 | -cdb Put comment delimiters on blank lines 11 | -cdw Cuddle while of do {} while with preceding right-brace 12 | -ci2 Continuation indent of 2 spaces 13 | -cli2 Case label indent of 2 spaces 14 | -i2 Set indent level to 2 spaces 15 | -ip2 Indent parameter types in old-style function definitions by 2 spaces 16 | -kr Use Kernighan & Ritchie coding style 17 | -l79 Set maximum line length for non-comment lines to 79 18 | -lp Line up continued lines at parentheses 19 | -nce Do not cuddle else and preceding right-brace 20 | -ncs Do not put a space after cast operators 21 | -nhnl Do not prefer to break long lines at the position of newlines in the input 22 | -pcs Insert a space between the name of the procedure being called and the left-bracket 23 | -pi2 Space 2 spaces of indentation per open parentheses 24 | -ppi2 Request indentation of preprocessor conditional statements 25 | -prs Put a space after every left- and before every right-bracket 26 | -psl Put the type of a procedure on the line before its name 27 | -saf Put a space after each for 28 | -sai Put a space after each if 29 | -saw Put a space after each while 30 | -sc Put the start character at the left of comments 31 | -sob Swallow optional blank lines 32 | -ts2 Set tab size to 2 spaces 33 | -------------------------------------------------------------------------------- /indent_add.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Twice because of some indent bug which changes a file back and forth 3 | indent -bap -bc -bfda -bfde -bl -bli2 -bls -cbi2 -cdb -cdw -nce -ci2 -cli2 -i2 -ip2 -kr -l79 -lp -ncs -nhnl -pcs -pi2 -ppi2 -prs -psl -saf -sai -saw -sc -sob -ts8 $* 4 | indent -bap -bc -bfda -bfde -bl -bli2 -bls -cbi2 -cdb -cdw -nce -ci2 -cli2 -i2 -ip2 -kr -l79 -lp -ncs -nhnl -pcs -pi2 -ppi2 -prs -psl -saf -sai -saw -sc -sob -ts8 $* 5 | git add $* 6 | -------------------------------------------------------------------------------- /makechecked.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | mkdir bin 2>nul 3 | cmd /c makeutils 4 | cmd /c makedriver c 32 5 | cmd /c makedriver c 64 6 | -------------------------------------------------------------------------------- /makedist.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | call config.bat 3 | rd /s /q bin 2>nul 4 | rd /s /q src\obj 2>nul 5 | rd /s /q src\nbp\pxe.asm\obj 2>nul 6 | rd /s /q src\nbp\pxe.c\obj 2>nul 7 | mkdir bin 2>nul 8 | cmd /c makeutils 9 | cmd /c makeinf 10 | cmd /c makedriver f 32 11 | cmd /c makedriver f 64 12 | del bin\loader32.exe 13 | del bin\loader64.exe 14 | del bin\wvblk32.pdb 15 | del bin\wvblk64.pdb 16 | copy src\nbp\pxe.%pxestyle%\aoe.0 bin 17 | -------------------------------------------------------------------------------- /makedriver.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | if "%1" == "" goto help 3 | if "%2" == "" goto help 4 | if "%1" == "/?" goto help 5 | 6 | if "%1" == "f" goto next_1 7 | if "%1" == "c" goto next_1 8 | if "%1" == "32" goto next_2 9 | if "%1" == "64" goto next_2 10 | goto help 11 | 12 | :next_1 13 | if "%1" == "f" set arg1=fre 14 | if "%1" == "c" set arg1=chk 15 | if "%1" == "f" set obj=fre 16 | if "%1" == "c" set obj=chk 17 | if "%2" == "32" goto next_1_ok 18 | if "%2" == "64" goto next_1_ok 19 | goto help 20 | 21 | :next_1_ok 22 | if "%2" == "32" set arg2=w2k 23 | if "%2" == "64" set arg2=wnet amd64 24 | if "%2" == "32" set arch=i386 25 | if "%2" == "64" set arch=amd64 26 | if "%2" == "32" set bits=32 27 | if "%2" == "64" set bits=64 28 | if "%2" == "32" set obj=%obj%_w2k_x86 29 | if "%2" == "64" set obj=%obj%_wnet_amd64 30 | goto run 31 | 32 | :next_2 33 | if "%1" == "32" set arg2=w2k 34 | if "%1" == "64" set arg2=wnet amd64 35 | if "%1" == "32" set arch=i386 36 | if "%1" == "64" set arch=amd64 37 | if "%1" == "32" set bits=32 38 | if "%1" == "64" set bits=64 39 | if "%1" == "32" set obj=w2k_x86 40 | if "%1" == "64" set obj=wnet_amd64 41 | if "%2" == "f" goto next_2_ok 42 | if "%2" == "c" goto next_2_ok 43 | goto help 44 | 45 | :next_2_ok 46 | if "%2" == "f" set arg1=fre 47 | if "%2" == "c" set arg1=chk 48 | if "%2" == "f" set obj=fre_%obj% 49 | if "%2" == "c" set obj=chk_%obj% 50 | goto run 51 | 52 | :help 53 | echo. 54 | echo Usage: "makedriver [f|c] [32|64]" 55 | echo. 56 | goto end 57 | 58 | :run 59 | mkdir bin 2>nul 60 | call config.bat 61 | pushd . 62 | call %ddkdir%\bin\setenv.bat %ddkdir% %arg1% %arg2% 63 | popd 64 | 65 | rem Build order is important here 66 | set sys=winvblock aoe httpdisk 67 | 68 | for /d %%a in (%sys%) do ( 69 | pushd . 70 | cd src\%%a 71 | call makedriver.bat 72 | popd 73 | ) 74 | 75 | :end -------------------------------------------------------------------------------- /makefree.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | mkdir bin 2>nul 3 | cmd /c makeutils 4 | cmd /c makedriver f 32 5 | cmd /c makedriver f 64 6 | -------------------------------------------------------------------------------- /makeinf.bat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/makeinf.bat -------------------------------------------------------------------------------- /makeutils.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | mkdir bin 2>nul 4 | call config.bat 5 | set lib=%ddkdir%\lib 6 | 7 | cd src 8 | 9 | pushd . 10 | call %ddkdir%\bin\setenv.bat %ddkdir% w2k 11 | popd 12 | 13 | pushd . 14 | cd util 15 | rc winvblock.rc 16 | cl /I%CRT_INC_PATH% /I..\include /DWIN32_LEAN_AND_MEAN winvblk.c winvblock.res /Fe..\..\bin\winvblk.exe /link /LIBPATH:%DDK_LIB_DEST%\i386 /LIBPATH:%Lib%\crt\i386 bufferoverflowU.lib advapi32.lib 17 | del winvblk.obj 18 | popd 19 | 20 | pushd . 21 | cd httpdisk_util 22 | build 23 | copy /y obj%obj%\%arch%\httpdisk.exe ..\..\bin 24 | popd 25 | 26 | pushd . 27 | cd loader 28 | cl /I%CRT_INC_PATH% /I..\include /DWIN32_LEAN_AND_MEAN loader.c /Fe..\..\bin\loader32.exe /link /LIBPATH:%DDK_LIB_DEST%\i386 /LIBPATH:%Lib%\crt\i386 setupapi.lib bufferoverflowU.lib 29 | del loader.obj 30 | popd 31 | 32 | pushd . 33 | call %ddkdir%\bin\setenv.bat %ddkdir% wnet amd64 34 | popd 35 | 36 | pushd . 37 | cd loader 38 | cl /I%CRT_INC_PATH% /I..\include /DWIN32_LEAN_AND_MEAN loader.c /Fe..\..\bin\loader64.exe /link /LIBPATH:%DDK_LIB_DEST%\%_BUILDARCH% /LIBPATH:%Lib%\crt\%_BUILDARCH% setupapi.lib bufferoverflowU.lib 39 | del loader.obj 40 | popd 41 | 42 | cd .. -------------------------------------------------------------------------------- /sign.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | echo Signing... 3 | 4 | inf2cat /driver:bin /os:2000,XP_x86,Server2003_x86,Vista_x86,Server2008_x86 5 | 6 | if not exist testcer.cer makecert -r -ss my -n CN="Test Certificate for WinVBlock" testcer.cer 7 | 8 | signtool sign -ac testcer.cer -n "Test Certificate for WinVBlock" -t http://timestamp.verisign.com/scripts/timestamp.dll -d "WinVBlock Driver" bin\*.sys bin\*.cat bin\*.exe -------------------------------------------------------------------------------- /src/aoe/aoe.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/aoe/aoe.rc -------------------------------------------------------------------------------- /src/aoe/makedriver.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set c=driver.c bus.c protocol.c registry.c aoe.rc wv_stdlib.c wv_string.c 4 | 5 | set name=AoE%bits% 6 | 7 | echo INCLUDES=..\include > sources 8 | echo TARGETNAME=%name% >> sources 9 | echo TARGETTYPE=DRIVER >> sources 10 | echo TARGETPATH=obj >> sources 11 | echo TARGETLIBS=..\\..\\bin\\WVBlk%bits%.lib \>> sources 12 | echo $(DDK_LIB_PATH)\\ndis.lib >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_AOE=1 >> sources 15 | 16 | build 17 | copy obj%obj%\%arch%\%name%.sys ..\..\bin >nul 18 | copy obj%obj%\%arch%\%name%.pdb ..\..\bin >nul 19 | copy obj%obj%\%arch%\%name%.lib ..\..\bin >nul -------------------------------------------------------------------------------- /src/aoe/makefile: -------------------------------------------------------------------------------- 1 | !INCLUDE $(NTMAKEENV)\makefile.def 2 | -------------------------------------------------------------------------------- /src/aoe/wv_stdlib.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | #include 21 | #include "wv_stdlib.h" 22 | 23 | PVOID wv_malloc(wv_size_t size) { 24 | return ExAllocatePoolWithTag(NonPagedPool, size, 'EoAW'); 25 | } 26 | 27 | PVOID wv_palloc(wv_size_t size) { 28 | return ExAllocatePoolWithTag(PagedPool, size, 'EoAW'); 29 | } 30 | 31 | PVOID wv_mallocz(wv_size_t size) { 32 | PVOID ptr = ExAllocatePoolWithTag(NonPagedPool, size, 'EoAW'); 33 | return ptr ? RtlZeroMemory(ptr, size), ptr : ptr; 34 | } 35 | 36 | PVOID wv_pallocz(wv_size_t size) { 37 | PVOID ptr = ExAllocatePoolWithTag(PagedPool, size, 'EoAW'); 38 | return ptr ? RtlZeroMemory(ptr, size), ptr : ptr; 39 | } 40 | 41 | VOID wv_free(PVOID ptr) { 42 | ExFreePool(ptr); 43 | return; 44 | } 45 | -------------------------------------------------------------------------------- /src/aoe/wv_string.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | #include 21 | #include "wv_string.h" 22 | 23 | bool wv_memcmpeq(const VOID * s1, const VOID * s2, wv_size_t n) { 24 | return (RtlCompareMemory(s1, s2, n) == n) ? true : false; 25 | } 26 | -------------------------------------------------------------------------------- /src/httpdisk/MAKEFILE: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | -------------------------------------------------------------------------------- /src/httpdisk/httpdisk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/httpdisk.c -------------------------------------------------------------------------------- /src/httpdisk/httpdisk.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/httpdisk.rc -------------------------------------------------------------------------------- /src/httpdisk/ksocket.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/ksocket.c -------------------------------------------------------------------------------- /src/httpdisk/ksocket.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/ksocket.h -------------------------------------------------------------------------------- /src/httpdisk/ktdi.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/ktdi.c -------------------------------------------------------------------------------- /src/httpdisk/ktdi.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/ktdi.h -------------------------------------------------------------------------------- /src/httpdisk/makedriver.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set c=ksocket.c ktdi.c httpdisk.c bus.c httpdisk.rc 4 | 5 | set name=WvHTTP%bits% 6 | 7 | echo INCLUDES=^ 8 | ..\include;^ 9 | $(DDK_INC_PATH);^ 10 | $(BASEDIR)\inc\mfc42;^ 11 | $(BASEDIR)\src\network\inc > sources 12 | 13 | echo TARGETNAME=%name% >> sources 14 | echo TARGETTYPE=DRIVER >> sources 15 | echo TARGETPATH=obj >> sources 16 | echo TARGETLIBS=..\\..\\bin\\WVBlk%bits%.lib \>> sources 17 | echo $(DDK_LIB_PATH)\\ndis.lib \>> sources 18 | echo $(SDK_LIB_PATH)\libcntpr.lib >> sources 19 | echo SOURCES=%c% >> sources 20 | echo C_DEFINES=-DPROJECT_AOE=1 >> sources 21 | 22 | build 23 | copy obj%obj%\%arch%\%name%.sys ..\..\bin >nul 24 | copy obj%obj%\%arch%\%name%.pdb ..\..\bin >nul 25 | copy obj%obj%\%arch%\%name%.lib ..\..\bin >nul -------------------------------------------------------------------------------- /src/httpdisk/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk/readme.txt -------------------------------------------------------------------------------- /src/httpdisk_util/MAKEFILE: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source 3 | # file to this component. This file merely indirects to the real make file 4 | # that is shared by all the driver components of the Windows NT DDK 5 | # 6 | 7 | !INCLUDE $(NTMAKEENV)\makefile.def 8 | -------------------------------------------------------------------------------- /src/httpdisk_util/httpdisk.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk_util/httpdisk.c -------------------------------------------------------------------------------- /src/httpdisk_util/httpdisk.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk_util/httpdisk.rc -------------------------------------------------------------------------------- /src/httpdisk_util/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/httpdisk_util/readme.txt -------------------------------------------------------------------------------- /src/httpdisk_util/sources: -------------------------------------------------------------------------------- 1 | TARGETNAME=httpdisk 2 | TARGETPATH=obj 3 | TARGETTYPE=PROGRAM 4 | UMTYPE=console 5 | INCLUDES=..\include;$(DDK_INC_PATH);$(BASEDIR)\inc\mfc42 6 | USE_MSVCRT=1 7 | TARGETLIBS=$(SDK_LIB_PATH)\ws2_32.lib 8 | SOURCES=httpdisk.c httpdisk.rc 9 | -------------------------------------------------------------------------------- /src/include/aoe.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef AOE_M_AOE_H_ 22 | # define AOE_M_AOE_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * AoE specifics. 28 | */ 29 | 30 | # define htons(x) \ 31 | (UINT16)((((x) << 8) & 0xff00) | (((x) >> 8) & 0xff)) 32 | # define ntohs(x) \ 33 | (UINT16)((((x) << 8) & 0xff00) | (((x) >> 8) & 0xff)) 34 | 35 | # define IOCTL_AOE_SCAN \ 36 | CTL_CODE( \ 37 | FILE_DEVICE_CONTROLLER, \ 38 | 0x800, \ 39 | METHOD_BUFFERED, \ 40 | FILE_READ_DATA | FILE_WRITE_DATA \ 41 | ) 42 | # define IOCTL_AOE_SHOW \ 43 | CTL_CODE( \ 44 | FILE_DEVICE_CONTROLLER, \ 45 | 0x801, \ 46 | METHOD_BUFFERED, \ 47 | FILE_READ_DATA | FILE_WRITE_DATA \ 48 | ) 49 | # define IOCTL_AOE_MOUNT \ 50 | CTL_CODE( \ 51 | FILE_DEVICE_CONTROLLER, \ 52 | 0x802, \ 53 | METHOD_BUFFERED, \ 54 | FILE_READ_DATA | FILE_WRITE_DATA \ 55 | ) 56 | # define IOCTL_AOE_UMOUNT \ 57 | CTL_CODE( \ 58 | FILE_DEVICE_CONTROLLER, \ 59 | 0x803, \ 60 | METHOD_BUFFERED, \ 61 | FILE_READ_DATA | FILE_WRITE_DATA \ 62 | ) 63 | 64 | typedef enum AOE_SEARCH_STATE { 65 | AoeSearchStateSearchNic, 66 | AoeSearchStateGetSize, 67 | AoeSearchStateGettingSize, 68 | AoeSearchStateGetGeometry, 69 | AoeSearchStateGettingGeometry, 70 | AoeSearchStateGetMaxSectsPerPacket, 71 | AoeSearchStateGettingMaxSectsPerPacket, 72 | AoeSearchStateDone, 73 | AoeSearchStates 74 | } AOE_E_SEARCH_STATE, * AOE_EP_SEARCH_STATE; 75 | 76 | /*** Object types */ 77 | typedef struct S_AOE_DEV_ S_AOE_DEV, * SP_AOE_DEV; 78 | 79 | /*** Structure/union definitions */ 80 | struct S_AOE_DEV_ { 81 | PDRIVER_DISPATCH IrpDispatch; 82 | }; 83 | 84 | /** The AoE disk type. */ 85 | typedef struct AOE_DISK { 86 | S_AOE_DEV Dev[1]; 87 | PDEVICE_OBJECT Pdo; 88 | WVL_S_BUS_NODE BusNode[1]; 89 | WVL_S_DISK_T disk[1]; 90 | KSPIN_LOCK SpinLock; 91 | UINT32 MTU; 92 | UCHAR ClientMac[6]; 93 | UCHAR ServerMac[6]; 94 | UINT32 Major; 95 | UINT32 Minor; 96 | UINT32 MaxSectorsPerPacket; 97 | UINT32 Timeout; 98 | KEVENT SearchEvent; 99 | BOOLEAN Boot; 100 | AOE_E_SEARCH_STATE search_state; 101 | /* Current state of the device. */ 102 | WV_E_DEV_STATE State; 103 | /* Previous state of the device. */ 104 | WV_E_DEV_STATE OldState; 105 | } AOE_S_DISK, * AOE_SP_DISK; 106 | 107 | typedef struct AOE_MOUNT_TARGET { 108 | UCHAR ClientMac[6]; 109 | UCHAR ServerMac[6]; 110 | UINT32 Major; 111 | UINT32 Minor; 112 | LONGLONG LBASize; 113 | LARGE_INTEGER ProbeTime; 114 | } AOE_S_MOUNT_TARGET, * AOE_SP_MOUNT_TARGET; 115 | 116 | typedef struct AOE_MOUNT_TARGETS { 117 | UINT32 Count; 118 | AOE_S_MOUNT_TARGET Target[]; 119 | } AOE_S_MOUNT_TARGETS, * AOE_SP_MOUNT_TARGETS; 120 | 121 | typedef struct AOE_MOUNT_DISK { 122 | UINT32 Disk; 123 | UCHAR ClientMac[6]; 124 | UCHAR ServerMac[6]; 125 | UINT32 Major; 126 | UINT32 Minor; 127 | LONGLONG LBASize; 128 | } AOE_S_MOUNT_DISK, * AOE_SP_MOUNT_DISK; 129 | 130 | typedef struct AOE_MOUNT_DISKS { 131 | UINT32 Count; 132 | AOE_S_MOUNT_DISK Disk[]; 133 | } AOE_S_MOUNT_DISKS, * AOE_SP_MOUNT_DISKS; 134 | 135 | extern VOID aoe__reset_probe(void); 136 | 137 | #endif /* AOE_M_AOE_H_ */ 138 | -------------------------------------------------------------------------------- /src/include/bus.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, originally derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WVL_M_BUS_H_ 22 | # define WVL_M_BUS_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Bus specifics 28 | */ 29 | 30 | /** Object types */ 31 | typedef struct S_WVL_MAIN_BUS_PROBE_REGISTRATION 32 | S_WVL_MAIN_BUS_PROBE_REGISTRATION; 33 | struct WVL_BUS_T; 34 | 35 | /** Function types */ 36 | 37 | /** 38 | * Callback for the main bus' initial bus relations probe 39 | * 40 | * @param DeviceObject 41 | * The main bus device 42 | */ 43 | typedef VOID F_WVL_MAIN_BUS_PROBE_REGISTRATION(IN DEVICE_OBJECT *); 44 | 45 | /** 46 | * A bus PnP routine. 47 | * 48 | * @v bus The bus to receive the PnP IRP. 49 | * @v irp The IRP to process. 50 | * @ret NTSTATUS The status of the operation. 51 | */ 52 | typedef NTSTATUS STDCALL WVL_F_BUS_PNP(IN struct WVL_BUS_T *, IN PIRP); 53 | typedef WVL_F_BUS_PNP * WVL_FP_BUS_PNP; 54 | 55 | /** Constants */ 56 | 57 | /* Device state */ 58 | typedef enum WVL_BUS_STATE { 59 | WvlBusStateNotStarted, 60 | WvlBusStateStarted, 61 | WvlBusStateStopPending, 62 | WvlBusStateStopped, 63 | WvlBusStateRemovePending, 64 | WvlBusStateSurpriseRemovePending, 65 | WvlBusStateDeleted, 66 | WvlBusStates 67 | } WVL_E_BUS_STATE, * WVL_EP_BUS_STATE; 68 | 69 | /** Function declarations */ 70 | 71 | /* From ../winvblock/mainbus/mainbus.c */ 72 | 73 | /** 74 | * Add a device to the main bus 75 | * 76 | * @param DeviceObject 77 | * The device to be added 78 | * 79 | * @retval STATUS_SUCCESS 80 | * @retval STATUS_NO_SUCH_DEVICE 81 | * @retval STATUS_INSUFFICIENT_RESOURCES 82 | */ 83 | extern WVL_M_LIB NTSTATUS STDCALL WvlAddDeviceToMainBus( 84 | IN DEVICE_OBJECT * DeviceObject 85 | ); 86 | 87 | /** 88 | * Remove a device from the main bus 89 | * 90 | * @param DeviceObject 91 | * The device to be removed 92 | */ 93 | extern WVL_M_LIB VOID STDCALL WvlRemoveDeviceFromMainBus( 94 | IN DEVICE_OBJECT * DeviceObject 95 | ); 96 | 97 | /** 98 | * Register a callback for the main bus' initial bus relations probe 99 | * 100 | * @param RegistrationRecord 101 | * A record in non-paged memory noting the callback to be performed 102 | * during the initial probe 103 | * 104 | * The record will be deregistered after the callback has been called 105 | */ 106 | extern WVL_M_LIB VOID STDCALL WvlRegisterMainBusInitialProbeCallback( 107 | IN S_WVL_MAIN_BUS_PROBE_REGISTRATION * reg 108 | ); 109 | 110 | /** Struct/union type definitions */ 111 | 112 | /** Registration for the main bus' initial bus relations probe */ 113 | struct S_WVL_MAIN_BUS_PROBE_REGISTRATION { 114 | /** The link in the linked list of all registrations */ 115 | LIST_ENTRY Link[1]; 116 | 117 | /** The callback to be performed during the initial probe */ 118 | F_WVL_MAIN_BUS_PROBE_REGISTRATION * Callback; 119 | }; 120 | 121 | /* The bus type. */ 122 | typedef struct WVL_BUS_T { 123 | PDEVICE_OBJECT LowerDeviceObject; 124 | PDEVICE_OBJECT Pdo; 125 | PDEVICE_OBJECT Fdo; 126 | WVL_E_BUS_STATE OldState; 127 | WVL_E_BUS_STATE State; 128 | WVL_FP_BUS_PNP QueryDevText; 129 | struct { 130 | LIST_ENTRY Nodes; 131 | KSPIN_LOCK NodeLock; 132 | KIRQL NodeLockIrql; 133 | USHORT NodeCount; 134 | } BusPrivate_; 135 | } WVL_S_BUS_T, * WVL_SP_BUS_T; 136 | 137 | /* A child PDO node on a bus. Treat this as an opaque type. */ 138 | typedef struct WVL_BUS_NODE { 139 | struct { 140 | LIST_ENTRY Link; 141 | PDEVICE_OBJECT Pdo; 142 | WVL_SP_BUS_T Bus; 143 | /* The child's unit number relative to the parent bus. */ 144 | UINT32 Num; 145 | } BusPrivate_; 146 | BOOLEAN Linked; 147 | } WVL_S_BUS_NODE, * WVL_SP_BUS_NODE; 148 | 149 | /** Objects */ 150 | 151 | /* From mainbus.c */ 152 | extern WVL_M_LIB WVL_S_BUS_T WvBus; 153 | 154 | /** More function declarations (TODO: Reorganize) */ 155 | 156 | /* Exports. */ 157 | extern WVL_M_LIB VOID WvlBusInit(WVL_SP_BUS_T); 158 | extern WVL_M_LIB VOID STDCALL WvlBusClear(IN WVL_SP_BUS_T); 159 | extern WVL_M_LIB VOID WvlBusLock(IN WVL_SP_BUS_T); 160 | extern WVL_M_LIB VOID WvlBusUnlock(IN WVL_SP_BUS_T); 161 | extern WVL_M_LIB BOOLEAN STDCALL WvlBusInitNode( 162 | OUT WVL_SP_BUS_NODE, 163 | IN PDEVICE_OBJECT 164 | ); 165 | extern WVL_M_LIB NTSTATUS STDCALL WvlBusAddNode( 166 | WVL_SP_BUS_T, 167 | WVL_SP_BUS_NODE 168 | ); 169 | extern WVL_M_LIB NTSTATUS STDCALL WvlBusRemoveNode(WVL_SP_BUS_NODE); 170 | extern WVL_M_LIB UINT32 STDCALL WvlBusGetNodeNum( 171 | IN WVL_SP_BUS_NODE 172 | ); 173 | extern WVL_M_LIB WVL_SP_BUS_NODE STDCALL WvlBusGetNextNode( 174 | IN WVL_SP_BUS_T, 175 | IN WVL_SP_BUS_NODE 176 | ); 177 | extern WVL_M_LIB PDEVICE_OBJECT STDCALL WvlBusGetNodePdo( 178 | IN WVL_SP_BUS_NODE 179 | ); 180 | extern WVL_M_LIB UINT32 STDCALL WvlBusGetNodeCount( 181 | WVL_SP_BUS_T 182 | ); 183 | /* IRP_MJ_PNP dispatcher in libbus/pnp.c */ 184 | extern WVL_M_LIB NTSTATUS STDCALL WvlBusPnp( 185 | IN WVL_SP_BUS_T, 186 | IN PIRP 187 | ); 188 | 189 | #endif /* WVL_M_BUS_H_ */ 190 | -------------------------------------------------------------------------------- /src/include/byte.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_BYTE_H_ 20 | # define WV_M_BYTE_H_ 21 | 22 | /** 23 | * @file 24 | * 25 | * Byte order (endian) specifics 26 | * 27 | */ 28 | 29 | # define byte__array_union( type, name ) \ 30 | union \ 31 | { \ 32 | type val; \ 33 | char bytes[sizeof ( type )]; \ 34 | } \ 35 | name 36 | 37 | /* Function body in header so user-land utility links without WinVBlock */ 38 | static VOID STDCALL 39 | byte__order_swap ( 40 | IN OUT char *bytes, 41 | int count 42 | ) 43 | { 44 | /* 45 | * Just for fun 46 | */ 47 | while ( --count > 0 ) 48 | { 49 | bytes[0] ^= bytes[count]; 50 | bytes[count] ^= bytes[0]; 51 | bytes[0] ^= bytes[count]; 52 | bytes++; 53 | count--; 54 | } 55 | } 56 | 57 | /* Expects a byte_array_union only! */ 58 | # define byte__rev_array_union( x ) \ 59 | byte__order_swap ( x.bytes, sizeof(x.bytes) ) 60 | 61 | #endif /* WV_M_BYTE_H_ */ 62 | -------------------------------------------------------------------------------- /src/include/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * For WinAoE contact information, see http://winaoe.org/ 4 | * 5 | * This file is part of WinVBlock, derived from WinAoE. 6 | * 7 | * WinVBlock is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * WinVBlock is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with WinVBlock. If not, see . 19 | * 20 | * Jul-03-2009@22:39: Initial revision. 21 | */ 22 | 23 | #ifndef WVL_M_DEBUG_H_ 24 | # define WVL_M_DEBUG_H_ 25 | 26 | /** 27 | * @file 28 | * 29 | * Debugging message system. 30 | * 31 | * We wrap the DbgPrint() function in order to automatically display file, 32 | * function and line number in any debugging output messages. 33 | */ 34 | 35 | /** Debugging choices. */ 36 | 37 | /* Debug messages. */ 38 | #define WVL_M_DEBUG 0 39 | 40 | /* Include file. */ 41 | #define WVL_M_DEBUG_FILE 1 42 | 43 | /* Include line number. This depends on WVL_M_DEBUG_FILE */ 44 | #define WVL_M_DEBUG_LINE 1 45 | 46 | /* Include thread. */ 47 | #define WVL_M_DEBUG_THREAD 1 48 | 49 | /* Verbose IRP debugging. This depends on WVL_M_DEBUG */ 50 | #define WVL_M_DEBUG_IRPS 0 51 | 52 | /** End of debugging choices. */ 53 | 54 | /* DBG() macro to output debugging messages. */ 55 | #ifdef DBG 56 | # undef DBG 57 | #endif 58 | #if WVL_M_DEBUG 59 | # define DBG(...) ( \ 60 | WvlDebugPrint( \ 61 | __FILE__, \ 62 | (const PCHAR) __FUNCTION__, \ 63 | __LINE__, \ 64 | __VA_ARGS__ \ 65 | ), \ 66 | DbgPrint(__VA_ARGS__) \ 67 | ) 68 | extern WVL_M_LIB NTSTATUS STDCALL WvlDebugPrint( 69 | IN PCHAR, 70 | IN PCHAR, 71 | IN UINT32, 72 | IN PCHAR, 73 | ... 74 | ); 75 | #else 76 | # define DBG(...) ((VOID) 0) 77 | #endif 78 | 79 | /* Establish macros for verbose IRP debugging messages, if applicable. */ 80 | #if WVL_M_DEBUG && WVL_M_DEBUG_IRPS 81 | # define WVL_M_DEBUG_IRP_START(Do_, Irp_) (WvlDebugIrpStart((Do_), (Irp_))) 82 | # define WVL_M_DEBUG_IRP_END(Irp_, Status_) (WvlDebugIrpEnd((Irp_), (Status_))) 83 | extern WVL_M_LIB VOID STDCALL WvlDebugIrpStart(IN PDEVICE_OBJECT, IN PIRP); 84 | extern VOID STDCALL WvlDebugIrpEnd(IN PIRP, IN NTSTATUS); 85 | #else 86 | # define WVL_M_DEBUG_IRP_START(Do_, Irp_) ((VOID) 0) 87 | # define WVL_M_DEBUG_IRP_END(Irp_, Status_) ((VOID) 0) 88 | #endif 89 | 90 | extern VOID WvlDebugModuleInit(void); 91 | extern VOID WvlDebugModuleUnload(void); 92 | extern WVL_M_LIB NTSTATUS STDCALL WvlError(IN PCHAR, IN NTSTATUS); 93 | 94 | #endif /* WVL_M_DEBUG_H_ */ 95 | -------------------------------------------------------------------------------- /src/include/device.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WV_M_DEVICE_H_ 22 | # define WV_M_DEVICE_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Device specifics. 28 | */ 29 | 30 | typedef enum WV_DEV_STATE { 31 | WvDevStateNotStarted, 32 | WvDevStateStarted, 33 | WvDevStateStopPending, 34 | WvDevStateStopped, 35 | WvDevStateRemovePending, 36 | WvDevStateSurpriseRemovePending, 37 | WvDevStateDeleted, 38 | WvDevStates 39 | } WV_E_DEV_STATE, * WV_EP_DEV_STATE; 40 | 41 | /* Forward declarations. */ 42 | typedef struct WV_DEV_T WV_S_DEV_T, * WV_SP_DEV_T; 43 | 44 | /** 45 | * Device PDO creation routine. 46 | * 47 | * @v dev The device whose PDO should be created. 48 | * @ret pdo Points to the new PDO, or is NULL upon failure. 49 | */ 50 | typedef PDEVICE_OBJECT STDCALL WV_F_DEV_CREATE_PDO(IN WV_SP_DEV_T); 51 | typedef WV_F_DEV_CREATE_PDO * WV_FP_DEV_CREATE_PDO; 52 | extern WVL_M_LIB WV_F_DEV_CREATE_PDO WvDevCreatePdo; 53 | 54 | /** 55 | * Device initialization routine. 56 | * 57 | * @v dev The device being initialized. 58 | */ 59 | typedef BOOLEAN STDCALL WV_F_DEV_INIT(IN WV_SP_DEV_T); 60 | typedef WV_F_DEV_INIT * WV_FP_DEV_INIT; 61 | 62 | /** 63 | * Device PnP ID reponse routine. 64 | * 65 | * @v dev The device being queried for PnP IDs. 66 | * @v query_type The query type. 67 | * @v buf Wide character, 512-element buffer for the 68 | * ID response. 69 | * @ret UINT32 The number of wide characters in the response. 70 | */ 71 | typedef UINT32 STDCALL WV_F_DEV_PNP_ID( 72 | IN WV_SP_DEV_T, 73 | IN BUS_QUERY_ID_TYPE, 74 | IN OUT WCHAR (*)[512] 75 | ); 76 | typedef WV_F_DEV_PNP_ID * WV_FP_DEV_PNP_ID; 77 | extern WVL_M_LIB WV_F_DEV_PNP_ID WvDevPnpId; 78 | 79 | /** 80 | * Device close routine. 81 | * 82 | * @v dev The device being closed. 83 | */ 84 | typedef VOID STDCALL WV_F_DEV_CLOSE(IN WV_SP_DEV_T); 85 | typedef WV_F_DEV_CLOSE * WV_FP_DEV_CLOSE; 86 | extern WVL_M_LIB WV_F_DEV_CLOSE WvDevClose; 87 | 88 | /** 89 | * Device deletion routine. 90 | * 91 | * @v dev_ptr Points to the device to delete. 92 | */ 93 | typedef VOID STDCALL WV_F_DEV_FREE(IN WV_SP_DEV_T); 94 | typedef WV_F_DEV_FREE * WV_FP_DEV_FREE; 95 | extern WVL_M_LIB WV_F_DEV_FREE WvDevFree; 96 | 97 | extern WVL_M_LIB VOID WvDevInit(WV_SP_DEV_T); 98 | extern WVL_M_LIB WV_SP_DEV_T WvDevCreate(void); 99 | 100 | typedef struct WV_DEV_OPS { 101 | WV_FP_DEV_CREATE_PDO CreatePdo; 102 | WV_FP_DEV_INIT Init; 103 | WV_FP_DEV_PNP_ID PnpId; 104 | WV_FP_DEV_CLOSE Close; 105 | WV_FP_DEV_FREE Free; 106 | } WV_S_DEV_OPS, * WV_SP_DEV_OPS; 107 | 108 | /** 109 | * The prototype for a device IRP dispatch. 110 | * 111 | * @v dev Points to the device. 112 | * @v irp Points to the IRP. 113 | * @ret NTSTATUS The status of processing the IRP for the device. 114 | */ 115 | typedef NTSTATUS STDCALL WV_F_DEV_DISPATCH(IN WV_SP_DEV_T, IN PIRP); 116 | typedef WV_F_DEV_DISPATCH * WV_FP_DEV_DISPATCH; 117 | 118 | /** 119 | * The prototype for a device IRP_MJ_DEVICE_CONTROL dispatch. 120 | * 121 | * @v dev Points to the device. 122 | * @v irp Points to the IRP. 123 | * @v code The I/O control code. 124 | * @ret NTSTATUS The status of processing the IRP for the device. 125 | */ 126 | typedef NTSTATUS STDCALL WV_F_DEV_CTL( 127 | IN WV_SP_DEV_T, 128 | IN PIRP, 129 | IN ULONG POINTER_ALIGNMENT 130 | ); 131 | typedef WV_F_DEV_CTL * WV_FP_DEV_CTL; 132 | 133 | /** 134 | * The prototype for a device IRP_MJ_SCSI dispatch. 135 | * 136 | * @v dev Points to the device. 137 | * @v irp Points to the IRP. 138 | * @v code The SCSI function. 139 | * @ret NTSTATUS The status of processing the IRP for the device. 140 | */ 141 | typedef NTSTATUS STDCALL WV_F_DEV_SCSI(IN WV_SP_DEV_T, IN PIRP, IN UCHAR); 142 | typedef WV_F_DEV_SCSI * WV_FP_DEV_SCSI; 143 | 144 | /** 145 | * The prototype for a device IRP_MJ_PNP dispatch. 146 | * 147 | * @v dev Points to the device. 148 | * @v irp Points to the IRP. 149 | * @v code The minor function. 150 | * @ret NTSTATUS The status of processing the IRP for the device. 151 | */ 152 | typedef NTSTATUS STDCALL WV_F_DEV_PNP(IN WV_SP_DEV_T, IN PIRP, IN UCHAR); 153 | typedef WV_F_DEV_PNP * WV_FP_DEV_PNP; 154 | 155 | /* Details common to all devices this driver works with */ 156 | struct WV_DEV_T { 157 | /* For debugging */ 158 | BOOLEAN IsBus; 159 | /* Self is self-explanatory. */ 160 | PDEVICE_OBJECT Self; 161 | /* Points to the parent bus' DEVICE_OBJECT */ 162 | PDEVICE_OBJECT Parent; 163 | /* Points to the driver. */ 164 | PDRIVER_OBJECT DriverObject; 165 | /* Current state of the device. */ 166 | WV_E_DEV_STATE State; 167 | /* Previous state of the device. */ 168 | WV_E_DEV_STATE OldState; 169 | /* Support being a node on a bus. */ 170 | WVL_S_BUS_NODE BusNode; 171 | /* The device operations. */ 172 | WV_S_DEV_OPS Ops; 173 | /* Points to further extensions. */ 174 | PVOID ext; 175 | /* Was the device established at boot time? */ 176 | BOOLEAN Boot; 177 | }; 178 | 179 | extern WVL_M_LIB WV_SP_DEV_T WvDevFromDevObj(PDEVICE_OBJECT); 180 | extern WVL_M_LIB VOID WvDevForDevObj(PDEVICE_OBJECT, WV_SP_DEV_T); 181 | extern WVL_M_LIB PDRIVER_DISPATCH STDCALL WvDevGetIrpHandler( 182 | IN PDEVICE_OBJECT 183 | ); 184 | extern WVL_M_LIB VOID STDCALL WvDevSetIrpHandler( 185 | IN PDEVICE_OBJECT, 186 | IN PDRIVER_DISPATCH 187 | ); 188 | extern WV_F_DEV_DISPATCH WvDevPnpQueryId; 189 | 190 | #endif /* WV_M_DEVICE_H_ */ 191 | -------------------------------------------------------------------------------- /src/include/disk.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WVL_M_DISK_H_ 22 | # define WVL_M_DISK_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Disk device specifics. 28 | */ 29 | 30 | typedef enum WVL_DISK_MEDIA_TYPE { 31 | WvlDiskMediaTypeFloppy, 32 | WvlDiskMediaTypeHard, 33 | WvlDiskMediaTypeOptical, 34 | WvlDiskMediaTypes 35 | } WVL_E_DISK_MEDIA_TYPE, * WVL_EP_DISK_MEDIA_TYPE; 36 | 37 | typedef enum WVL_DISK_STATE { 38 | WvlDiskStateNotStarted, 39 | WvlDiskStateStarted, 40 | WvlDiskStateStopPending, 41 | WvlDiskStateStopped, 42 | WvlDiskStateRemovePending, 43 | WvlDiskStateSurpriseRemovePending, 44 | WvlDiskStateDeleted, 45 | WvlDiskStates 46 | } WVL_E_DISK_STATE, * WVL_EP_DISK_STATE; 47 | 48 | typedef char WVL_A_DISK_BOOT_SECT[512]; 49 | typedef WVL_A_DISK_BOOT_SECT * WVL_AP_DISK_BOOT_SECT; 50 | 51 | typedef enum WVL_DISK_IO_MODE { 52 | WvlDiskIoModeRead, 53 | WvlDiskIoModeWrite, 54 | WvlDiskIoModes 55 | } WVL_E_DISK_IO_MODE, * WVL_EP_DISK_IO_MODE; 56 | 57 | /* Forward declaration. */ 58 | typedef struct WVL_DISK_T WVL_S_DISK_T, * WVL_SP_DISK_T; 59 | 60 | typedef NTSTATUS STDCALL WVL_F_DISK_SCSI( 61 | IN PDEVICE_OBJECT dev_obj, 62 | IN PIRP irp, 63 | IN WVL_SP_DISK_T disk 64 | ); 65 | typedef WVL_F_DISK_SCSI * WVL_FP_DISK_SCSI; 66 | 67 | /** 68 | * Prototype for disk PnP functions. 69 | * 70 | * @v DevObj The disk PDO to process the IRP with. 71 | * @v Irp The IRP to process. 72 | * @v Disk The disk to process the IRP with. 73 | * @ret NTSTATUS The status of the operation. 74 | */ 75 | typedef NTSTATUS STDCALL WVL_F_DISK_PNP( 76 | IN PDEVICE_OBJECT, 77 | IN PIRP, 78 | IN WVL_SP_DISK_T 79 | ); 80 | typedef WVL_F_DISK_PNP * WVL_FP_DISK_PNP; 81 | 82 | /** 83 | * Disk I/O routine. 84 | * 85 | * @v disk Points to the disk's structure. 86 | * @v mode Read/write mode. 87 | * @v start_sector First sector for request. 88 | * @v sector_count Number of sectors to work with. 89 | * @v buffer Buffer to read/write sectors to/from. 90 | * @v irp Interrupt request packet for this request. 91 | * @ret NTSTATUS The status of the operation. 92 | */ 93 | typedef NTSTATUS STDCALL WVL_F_DISK_IO( 94 | IN WVL_SP_DISK_T, 95 | IN WVL_E_DISK_IO_MODE, 96 | IN LONGLONG, 97 | IN UINT32, 98 | IN PUCHAR, 99 | IN PIRP 100 | ); 101 | typedef WVL_F_DISK_IO * WVL_FP_DISK_IO; 102 | extern WVL_M_LIB WVL_F_DISK_IO WvlDiskIo; 103 | 104 | /** 105 | * Maximum transfer length response routine. 106 | * 107 | * @v disk The disk being queried. 108 | * @ret UINT32 The maximum transfer length. 109 | */ 110 | typedef UINT32 WVL_F_DISK_MAX_XFER_LEN(IN WVL_SP_DISK_T); 111 | typedef WVL_F_DISK_MAX_XFER_LEN * WVL_FP_DISK_MAX_XFER_LEN; 112 | extern WVL_M_LIB WVL_F_DISK_MAX_XFER_LEN WvlDiskMaxXferLen; 113 | 114 | /** 115 | * Disk close routine. 116 | * 117 | * @v disk_ptr The disk device being closed. 118 | */ 119 | typedef VOID STDCALL WVL_F_DISK_CLOSE(IN WVL_SP_DISK_T); 120 | typedef WVL_F_DISK_CLOSE * WVL_FP_DISK_CLOSE; 121 | 122 | /** 123 | * Fetch disk unit number routine. 124 | * 125 | * @v disk The disk whose unit number is fetched. 126 | * @ret UCHAR The disk's unit number. 127 | */ 128 | typedef UCHAR STDCALL WVL_F_DISK_UNIT_NUM(IN WVL_SP_DISK_T); 129 | typedef WVL_F_DISK_UNIT_NUM * WVL_FP_DISK_UNIT_NUM; 130 | extern WVL_M_LIB WVL_F_DISK_UNIT_NUM WvlDiskUnitNum; 131 | 132 | typedef struct WVL_DISK_OPS { 133 | WVL_FP_DISK_IO Io; 134 | WVL_FP_DISK_MAX_XFER_LEN MaxXferLen; 135 | WVL_FP_DISK_CLOSE Close; 136 | WVL_FP_DISK_UNIT_NUM UnitNum; 137 | WVL_FP_DISK_PNP PnpQueryId; 138 | WVL_FP_DISK_PNP PnpQueryDevText; 139 | } WVL_S_DISK_OPS, * WVL_SP_DISK_OPS; 140 | 141 | struct WVL_DISK_T { 142 | WVL_E_DISK_MEDIA_TYPE Media; 143 | WVL_S_DISK_OPS disk_ops; 144 | ULONGLONG LBADiskSize; 145 | ULONGLONG Cylinders; 146 | UINT32 Heads; 147 | UINT32 Sectors; 148 | UINT32 SectorSize; 149 | UINT32 SpecialFileCount; 150 | PDEVICE_OBJECT ParentBus; 151 | PVOID ext; 152 | PDRIVER_OBJECT DriverObj; 153 | WVL_E_DISK_STATE OldState; 154 | WVL_E_DISK_STATE State; 155 | /* Do we allow page files? */ 156 | BOOLEAN DenyPageFile; 157 | }; 158 | 159 | /* An MBR C/H/S address and ways to access its components. */ 160 | typedef UCHAR chs[3]; 161 | 162 | #define chs_head(chs) chs[0] 163 | #define chs_sector(chs) (chs[1] & 0x3F) 164 | #define chs_cyl_high(chs) (((UINT16) (chs[1] & 0xC0)) << 2) 165 | #define chs_cyl_low(chs) ((UINT16) chs[2]) 166 | #define chs_cylinder(chs) (chs_cyl_high(chs) | chs_cyl_low(chs)) 167 | 168 | /* An MBR. */ 169 | #ifdef _MSC_VER 170 | # pragma pack(1) 171 | #endif 172 | struct WVL_DISK_MBR { 173 | UCHAR code[440]; 174 | UINT32 disk_sig; 175 | UINT16 pad; 176 | struct { 177 | UCHAR status; 178 | chs chs_start; 179 | UCHAR type; 180 | chs chs_end; 181 | UINT32 lba_start; 182 | UINT32 lba_count; 183 | } partition[4] __attribute__((packed)); 184 | UINT16 mbr_sig; 185 | } __attribute__((__packed__)); 186 | typedef struct WVL_DISK_MBR WVL_S_DISK_MBR, * WVL_SP_DISK_MBR; 187 | #ifdef _MSC_VER 188 | # pragma pack() 189 | #endif 190 | 191 | /** IRP-related. */ 192 | extern WVL_M_LIB NTSTATUS STDCALL WvlDiskPower( 193 | IN PDEVICE_OBJECT, 194 | IN PIRP, 195 | IN WVL_SP_DISK_T 196 | ); 197 | extern WVL_M_LIB NTSTATUS STDCALL WvlDiskSysCtl( 198 | IN PDEVICE_OBJECT, 199 | IN PIRP, 200 | IN WVL_SP_DISK_T 201 | ); 202 | /* IRP_MJ_DEVICE_CONTROL dispatcher from libdisk/dev_ctl.c */ 203 | extern WVL_M_LIB NTSTATUS STDCALL WvlDiskDevCtl( 204 | IN WVL_SP_DISK_T, 205 | IN PIRP, 206 | IN ULONG POINTER_ALIGNMENT 207 | ); 208 | /* IRP_MJ_SCSI dispatcher from libdisk/scsi.c */ 209 | extern WVL_M_LIB WVL_F_DISK_SCSI WvlDiskScsi; 210 | /* IRP_MJ_PNP dispatcher from libdisk/pnp.c */ 211 | extern WVL_M_LIB WVL_F_DISK_PNP WvlDiskPnp; 212 | 213 | /** General. */ 214 | extern WVL_M_LIB NTSTATUS STDCALL WvlDiskCreatePdo( 215 | IN PDRIVER_OBJECT, 216 | IN SIZE_T, 217 | IN WVL_E_DISK_MEDIA_TYPE, 218 | OUT PDEVICE_OBJECT * 219 | ); 220 | extern WVL_M_LIB VOID WvlDiskGuessGeometry( 221 | IN WVL_AP_DISK_BOOT_SECT, 222 | IN OUT WVL_SP_DISK_T 223 | ); 224 | extern WVL_M_LIB VOID STDCALL WvlDiskInit(IN OUT WVL_SP_DISK_T); 225 | /* Objects. */ 226 | extern WVL_M_LIB BOOLEAN WvlDiskIsRemovable[WvlDiskMediaTypes]; 227 | extern WVL_M_LIB PWCHAR WvlDiskCompatIds[WvlDiskMediaTypes]; 228 | 229 | #endif /* WVL_M_DISK_H_ */ 230 | -------------------------------------------------------------------------------- /src/include/filedisk.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2016, Synthetel Corporation. 3 | * Author: Shao Miller 4 | * Copyright (C) 2009-2012, Shao Miller . 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WV_M_FILEDISK_H_ 22 | # define WV_M_FILEDISK_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * File-backed disk specifics 28 | */ 29 | 30 | /** Constants */ 31 | 32 | /** Device flags for the Flags member of an S_WVL_FILEDISK */ 33 | enum E_WVL_FILEDISK_FLAG { 34 | CvWvlFilediskFlagStarted_, 35 | CvWvlFilediskFlagStopping_, 36 | CvWvlFilediskFlagRemoving_, 37 | CvWvlFilediskFlagSurpriseRemoved_, 38 | CvWvlFilediskFlagStarted = 1 << CvWvlFilediskFlagStarted_, 39 | CvWvlFilediskFlagStopping = 1 << CvWvlFilediskFlagStopping_, 40 | CvWvlFilediskFlagRemoving = 1 << CvWvlFilediskFlagRemoving_, 41 | CvWvlFilediskFlagSurpriseRemoved = 1 << CvWvlFilediskFlagSurpriseRemoved_, 42 | CvWvlFilediskFlagZero = 0 43 | }; 44 | 45 | enum E_WVL_FILEDISK_MEDIA_TYPE { 46 | CvWvlFilediskMediaTypeFloppy, 47 | CvWvlFilediskMediaTypeHard, 48 | CvWvlFilediskMediaTypeOptical, 49 | CvWvlFilediskMediaTypes 50 | }; 51 | 52 | /** Object types */ 53 | typedef struct S_WVL_FILEDISK S_WVL_FILEDISK; 54 | typedef enum E_WVL_FILEDISK_MEDIA_TYPE E_WVL_FILEDISK_MEDIA_TYPE; 55 | 56 | typedef struct WV_FILEDISK_T { 57 | WV_S_DEV_EXT DevExt; 58 | WV_S_DEV_T Dev[1]; 59 | WVL_S_DISK_T disk[1]; 60 | HANDLE file; 61 | UINT32 hash; 62 | LARGE_INTEGER offset; 63 | WVL_S_THREAD Thread[1]; 64 | LIST_ENTRY Irps[1]; 65 | KSPIN_LOCK IrpsLock[1]; 66 | PVOID impersonation; 67 | } WV_S_FILEDISK_T, * WV_SP_FILEDISK_T; 68 | 69 | extern NTSTATUS STDCALL WvFilediskAttach(IN PIRP); 70 | extern WV_SP_FILEDISK_T STDCALL WvFilediskCreatePdo(IN WVL_E_DISK_MEDIA_TYPE); 71 | extern VOID STDCALL WvFilediskHotSwap(IN WV_SP_FILEDISK_T, IN PCHAR); 72 | 73 | /** Struct/union type definitions */ 74 | struct S_WVL_FILEDISK { 75 | /** This must be the first member of all extension types */ 76 | WV_S_DEV_EXT DeviceExtension[1]; 77 | /* Security context for file I/O, if impersonating */ 78 | SECURITY_CLIENT_CONTEXT * SecurityContext; 79 | /* Offset (in bytes) into the file */ 80 | LARGE_INTEGER FileOffset; 81 | HANDLE FileHandle; 82 | /** 83 | * Filedisk device flags. Must be accessed atomically (such as with 84 | * InterlockedXxx functions) 85 | */ 86 | volatile LONG Flags; 87 | /** The media type */ 88 | E_WVL_FILEDISK_MEDIA_TYPE MediaType; 89 | /* The size of the disk, in logical blocks (sectors) */ 90 | ULONGLONG LbaDiskSize; 91 | /* The size of a logical block (sector) */ 92 | UINT32 SectorSize; 93 | /* Do we impersonate the user who opened the file? */ 94 | BOOLEAN Impersonate; 95 | }; 96 | 97 | #endif /* WV_M_FILEDISK_H_ */ 98 | -------------------------------------------------------------------------------- /src/include/grub4dos.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef M_GRUB4DOS_H_ 20 | # define M_GRUB4DOS_H_ 21 | 22 | /** 23 | * @file 24 | * 25 | * GRUB4DOS mini-driver 26 | */ 27 | 28 | /** Macros */ 29 | #define M_G4D_SLOTS 8 30 | 31 | /** Object types */ 32 | typedef struct S_WV_G4D_DRIVE_MAPPING_ 33 | S_WV_G4D_DRIVE_MAPPING, 34 | * SP_WV_G4D_DRIVE_MAPPING; 35 | typedef struct S_WV_G4D_BUS S_WV_G4D_BUS; 36 | 37 | /** Function declarations */ 38 | extern DEVICE_OBJECT * WvFilediskCreateG4dDisk( 39 | SP_WV_G4D_DRIVE_MAPPING, 40 | DEVICE_OBJECT * BusDeviceObject, 41 | WVL_E_DISK_MEDIA_TYPE, 42 | UINT32 43 | ); 44 | extern DEVICE_OBJECT * WvRamdiskCreateG4dDisk( 45 | SP_WV_G4D_DRIVE_MAPPING, 46 | DEVICE_OBJECT * BusDeviceObject, 47 | WVL_E_DISK_MEDIA_TYPE, 48 | UINT32 49 | ); 50 | 51 | /* From ../src/winvblock/grub4dos/g4dbus.c */ 52 | 53 | /** 54 | * Process a GRUB4DOS drive mapping slot and produce a PDO 55 | * 56 | * @param BusDeviceObject 57 | * The intended parent bus device for the resulting PDO 58 | * 59 | * @param Slot 60 | * Points to a G4D drive mapping slot near the G4D INT 0x13 hook 61 | * 62 | * @return 63 | * A pointer to the resulting DEVICE_OBJECT, or a null pointer, 64 | * upon failure 65 | */ 66 | extern DEVICE_OBJECT * WvG4dProcessSlot( 67 | IN DEVICE_OBJECT * BusDeviceObject, 68 | IN S_WV_G4D_DRIVE_MAPPING * Slot 69 | ); 70 | 71 | /* From ../src/winvblock/grub4dos/fdo.c */ 72 | 73 | /** FDO IRP dispatcher */ 74 | extern DRIVER_DISPATCH WvG4dIrpDispatch; 75 | 76 | /** Struct/union type definitions */ 77 | 78 | /* From GRUB4DOS 0.4.4's stage2/shared.h */ 79 | struct S_WV_G4D_DRIVE_MAPPING_ { 80 | UCHAR SourceDrive; 81 | UCHAR DestDrive; 82 | UCHAR MaxHead; 83 | UCHAR MaxSector:6; 84 | UCHAR RestrictionX:1; 85 | UINT16 DestMaxCylinder:13; 86 | UINT16 SourceODD:1; 87 | UINT16 DestODD:1; 88 | UINT16 DestLBASupport:1; 89 | UCHAR DestMaxHead; 90 | UCHAR DestMaxSector:6; 91 | UCHAR RestrictionY:1; 92 | UCHAR InSituOption:1; 93 | UINT64 SectorStart; 94 | UINT64 SectorCount; 95 | }; 96 | 97 | /** A GRUB4DOS FDO device extension */ 98 | struct S_WV_G4D_BUS { 99 | /** This must be the first member of all extension types */ 100 | WV_S_DEV_EXT DeviceExtension[1]; 101 | 102 | /** Flags for state that must be accessed atomically */ 103 | volatile LONG Flags; 104 | 105 | /** The GRUB4DOS bus's safe hook PDO (bottom of the device stack) */ 106 | DEVICE_OBJECT * PhysicalDeviceObject; 107 | 108 | /** 109 | * PnP bus relations. 110 | * A GRUB4DOS FDO can have only 9 children, at most 111 | */ 112 | DEVICE_RELATIONS BusRelations[1]; 113 | DEVICE_OBJECT * Padding_[M_G4D_SLOTS]; 114 | 115 | /** A copy of the drive mappings */ 116 | S_WV_G4D_DRIVE_MAPPING DriveMappings[M_G4D_SLOTS]; 117 | 118 | /** Tracks which of the 9 possible nodes need a PDO */ 119 | USHORT NodesNeeded; 120 | 121 | /** A record of the previous INT 0x13 handler in the chain */ 122 | S_X86_SEG16OFF16 PreviousInt13hHandler[1]; 123 | }; 124 | 125 | #endif /* M_GRUB4DOS_H_ */ 126 | -------------------------------------------------------------------------------- /src/include/httpdisk.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/include/httpdisk.h -------------------------------------------------------------------------------- /src/include/irp.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef M_IRP_H_ 20 | 21 | /**** 22 | * @file 23 | * 24 | * IRP specifics. 25 | */ 26 | 27 | /*** Macros */ 28 | #define M_IRP_H_ 29 | 30 | /*** Object types */ 31 | typedef struct S_WVL_IRP_HANDLER_ S_WVL_IRP_HANDLER, * SP_WVL_IRP_HANDLER; 32 | typedef struct S_WVL_IRP_HANDLER_TABLE_ 33 | S_WVL_IRP_HANDLER_TABLE, * SP_WVL_IRP_HANDLER_TABLE; 34 | 35 | /*** Function declarations */ 36 | 37 | /** 38 | * Common IRP completion routine. 39 | * 40 | * @v Irp Points to the IRP to complete. 41 | * @v Info Number of bytes returned for the IRP, or 0. 42 | * @v Status Status for the IRP to complete. 43 | * @ret NTSTATUS Returns the status value, as passed. 44 | */ 45 | extern WVL_M_LIB NTSTATUS STDCALL WvlIrpComplete( 46 | IN PIRP, 47 | IN ULONG_PTR, 48 | IN NTSTATUS 49 | ); 50 | 51 | /** 52 | * Pass an IRP on to a lower device object. 53 | * 54 | * @v Lower Points to the lower device object in the stack. 55 | * @v Irp Points to the IRP to pass. 56 | * @ret NTSTATUS Returns the status value, as returned by the 57 | * lower device object, or STATUS_SUCCESS, if 58 | * no lower device object was passed. 59 | */ 60 | extern WVL_M_LIB NTSTATUS STDCALL WvlIrpPassToLower( 61 | IN PDEVICE_OBJECT Lower, 62 | IN PIRP Irp 63 | ); 64 | 65 | /** 66 | * Pass a power IRP on to a lower device object. 67 | * 68 | * @v Lower Points to the lower device object in the stack. 69 | * @v Irp Points to the power IRP to pass. 70 | * @ret NTSTATUS Returns the status value, as returned by the 71 | * lower device object, or STATUS_SUCCESS, if 72 | * no lower device object was passed. 73 | */ 74 | extern WVL_M_LIB NTSTATUS STDCALL WvlIrpPassPowerToLower( 75 | IN PDEVICE_OBJECT Lower, 76 | IN PIRP Irp 77 | ); 78 | 79 | /** 80 | * Handle an IRP by using a handler table. 81 | * 82 | * @v DevObj Points to the device object. 83 | * @v Irp Points to the IRP to handle. 84 | * @v Table Points to the handler table to use. 85 | * @ret NTSTATUS Returns the status as returned by the handling 86 | * function, or STATUS_NOT_SUPPORTED if the IRP 87 | * is not handled by the handler table. 88 | */ 89 | extern WVL_M_LIB NTSTATUS STDCALL WvlIrpHandleWithTable( 90 | IN PDEVICE_OBJECT DevObj, 91 | IN PIRP Irp, 92 | IN SP_WVL_IRP_HANDLER_TABLE Table 93 | ); 94 | 95 | /*** Struct/union definitions */ 96 | struct S_WVL_IRP_HANDLER_ { 97 | UCHAR Code; 98 | PDRIVER_DISPATCH Function; 99 | }; 100 | 101 | struct S_WVL_IRP_HANDLER_TABLE_ { 102 | BOOLEAN IsMajor; 103 | SIZE_T Count; 104 | SP_WVL_IRP_HANDLER Elements; 105 | }; 106 | 107 | #endif /* M_IRP_H_ */ 108 | -------------------------------------------------------------------------------- /src/include/mdi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2009 H. Peter Anvin - All Rights Reserved 3 | * Copyright 2009 Intel Corporation; author: H. Peter Anvin 4 | * 5 | * This file is part of MEMDISK, part of the Syslinux bootloader suite. 6 | * Minor adaptation for WinVBlock by Shao Miller 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, Inc., 53 Temple Place Ste 330, 11 | * Boston MA 02111-1307, USA; either version 2 of the License, or 12 | * (at your option) any later version; incorporated herein by reference. 13 | */ 14 | #ifndef WV_M_MDI_H_ 15 | # define WV_M_MDI_H_ 16 | 17 | /** 18 | * @file 19 | * 20 | * MEMDISK Information/Installation structure. 21 | */ 22 | 23 | #ifdef _MSC_VER 24 | # pragma pack(1) 25 | #endif 26 | struct WV_MDI_PATCH_AREA { 27 | UINT16 mdi_bytes; 28 | UCHAR mdi_version_minor; 29 | UCHAR mdi_version_major; 30 | UINT32 diskbuf; 31 | UINT32 disksize; 32 | UINT16 cmdline_off, cmdline_seg; 33 | 34 | UINT32 oldint13; 35 | UINT32 oldint15; 36 | 37 | UINT16 olddosmem; 38 | UCHAR bootloaderid; 39 | UCHAR _pad1; 40 | 41 | UINT16 dpt_ptr; 42 | /* End of the official MemDisk_Info */ 43 | UCHAR driveshiftlimit; 44 | UCHAR _pad2; 45 | UINT16 _pad3; 46 | UINT16 memint1588; 47 | 48 | UINT16 cylinders; 49 | UINT16 heads; 50 | UINT32 sectors; 51 | 52 | UINT32 mem1mb; 53 | UINT32 mem16mb; 54 | 55 | UCHAR driveno; 56 | /* WinVBlock does not need anything more. */ 57 | } __attribute__((__packed__)); 58 | typedef struct WV_MDI_PATCH_AREA WV_S_MDI_PATCH_AREA, * WV_SP_MDI_PATCH_AREA; 59 | #ifdef _MSC_VER 60 | # pragma pack() 61 | #endif 62 | 63 | #ifdef _MSC_VER 64 | # pragma pack(1) 65 | #endif 66 | struct WV_MDI_MBFT { 67 | UCHAR Signature[4]; /* ("mBFT") */ 68 | UINT32 Length; 69 | UCHAR Revision; 70 | UCHAR Checksum; 71 | UCHAR OEMID[6]; 72 | UCHAR OEMTableID[8]; 73 | UCHAR Reserved1[12]; 74 | UINT32 SafeHook; 75 | WV_S_MDI_PATCH_AREA mdi; 76 | } __attribute__((__packed__)); 77 | typedef struct WV_MDI_MBFT WV_S_MDI_MBFT, * WV_SP_MDI_MBFT; 78 | #ifdef _MSC_VER 79 | # pragma pack() 80 | #endif 81 | 82 | #endif /* WV_M_MDI_H_ */ 83 | -------------------------------------------------------------------------------- /src/include/memdisk.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef M_MEMDISK_H_ 20 | 21 | /** 22 | * @file 23 | * 24 | * MEMDISK specifics 25 | */ 26 | 27 | /** Macros */ 28 | #define M_MEMDISK_H_ 29 | 30 | /** Object types */ 31 | typedef struct S_WV_MEMDISK_BUS S_WV_MEMDISK_BUS; 32 | 33 | /** Function declarations */ 34 | 35 | extern VOID WvMemdiskFind(void); 36 | extern BOOLEAN WvMemdiskProcessSafeHook( 37 | PUCHAR, 38 | WV_SP_PROBE_SAFE_MBR_HOOK 39 | ); 40 | 41 | /* From ../src/winvblock/memdisk/memdisk.c */ 42 | 43 | /** 44 | * Create a MEMDISK disk 45 | * 46 | * @param Parent 47 | * The safe hook parent of the MEMDISK 48 | * 49 | * @param PhysicalDeviceObject 50 | * Points to the DEVICE_OBJECT pointer to populate with a pointer to 51 | * the created MEMDISK disk 52 | * 53 | * @return 54 | * The status of the operation 55 | */ 56 | extern NTSTATUS WvMemdiskCreateDisk( 57 | IN DEVICE_OBJECT * Parent, 58 | IN DEVICE_OBJECT ** PhysicalDeviceObject 59 | ); 60 | 61 | /* From ../src/winvblock/memdisk/fdo.c */ 62 | 63 | /** FDO IRP dispatcher */ 64 | extern DRIVER_DISPATCH WvMemdiskIrpDispatch; 65 | 66 | /** Struct/union type definitions */ 67 | 68 | /** A MEMDISK FDO device extension */ 69 | struct S_WV_MEMDISK_BUS { 70 | /** This must be the first member of all extension types */ 71 | WV_S_DEV_EXT DeviceExtension[1]; 72 | 73 | /** Flags for state that must be accessed atomically */ 74 | volatile LONG Flags; 75 | 76 | /** The safe hook's PDO (bottom of the device stack) */ 77 | DEVICE_OBJECT * PhysicalDeviceObject; 78 | 79 | /** 80 | * PnP bus relations. 81 | * A MEMDISK FDO can have only two children, at most 82 | */ 83 | DEVICE_RELATIONS BusRelations[1]; 84 | DEVICE_OBJECT * Padding_[1]; 85 | 86 | /** A record of the previous INT 0x13 handler in the chain */ 87 | S_X86_SEG16OFF16 PreviousInt13hHandler[1]; 88 | }; 89 | 90 | #endif /* M_MEMDISK_H_ */ 91 | -------------------------------------------------------------------------------- /src/include/mount.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2008, V. 3 | * Portions copyright (C) 2009-2011, Shao Miller . 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WV_M_MOUNT_H_ 22 | # define WV_M_MOUNT_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Mount command and device control code header. 28 | */ 29 | 30 | # define IOCTL_FILE_ATTACH \ 31 | CTL_CODE( \ 32 | FILE_DEVICE_CONTROLLER, \ 33 | 0x804, \ 34 | METHOD_BUFFERED, \ 35 | FILE_READ_DATA | FILE_WRITE_DATA \ 36 | ) 37 | # define IOCTL_FILE_DETACH \ 38 | CTL_CODE( \ 39 | FILE_DEVICE_CONTROLLER, \ 40 | 0x805, \ 41 | METHOD_BUFFERED, \ 42 | FILE_READ_DATA | FILE_WRITE_DATA \ 43 | ) 44 | 45 | typedef struct WV_MOUNT_DISK { 46 | char type; 47 | int cylinders; 48 | int heads; 49 | int sectors; 50 | } WV_S_MOUNT_DISK, * WV_SP_MOUNT_DISK; 51 | 52 | #endif /* WV_M_MOUNT_H_ */ 53 | -------------------------------------------------------------------------------- /src/include/msvhd.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_MSVHD_H_ 20 | # define WV_M_MSVHD_H_ 21 | 22 | /** 23 | * @file 24 | * 25 | * Microsoft .VHD disk image format specifics. 26 | * Structure details from the VHD Image Format Specification Document[1], 27 | * kindly provided by Microsoft's Open Source Promise[2]. 28 | * 29 | * [1] http://technet.microsoft.com/en-us/virtualserver/bb676673.aspx 30 | * [2] http://www.microsoft.com/interop/osp/default.mspx 31 | * 32 | */ 33 | 34 | /* The .VHD disk image footer format */ 35 | #ifdef _MSC_VER 36 | # pragma pack(1) 37 | #endif 38 | struct WV_MSVHD_FOOTER { 39 | char cookie[8]; 40 | byte__array_union(UINT32, features); 41 | byte__array_union(UINT32, file_ver); 42 | byte__array_union(ULONGLONG, data_offset); 43 | byte__array_union(UINT32, timestamp); 44 | char creator_app[4]; 45 | byte__array_union(UINT32, creator_ver); 46 | byte__array_union(UINT32, creator_os); 47 | byte__array_union(ULONGLONG, orig_size); 48 | byte__array_union(ULONGLONG, cur_size); 49 | byte__array_union(UINT16, geom_cyls); 50 | UCHAR geom_heads; 51 | UCHAR geom_sects_per_track; 52 | byte__array_union(UINT32, type); 53 | byte__array_union(UINT32, checksum); 54 | char uid[16]; 55 | char saved_state; 56 | char reserved[427]; 57 | } __attribute__((__packed__)); 58 | typedef struct WV_MSVHD_FOOTER WV_S_MSVHD_FOOTER, * WV_SP_MSVHD_FOOTER; 59 | #ifdef _MSC_VER 60 | # pragma pack() 61 | #endif 62 | 63 | /* Function body in header so user-land utility links without WinVBlock */ 64 | static VOID STDCALL 65 | msvhd__footer_swap_endian ( 66 | WV_SP_MSVHD_FOOTER footer_ptr 67 | ) 68 | { 69 | byte__rev_array_union ( footer_ptr->features ); 70 | byte__rev_array_union ( footer_ptr->file_ver ); 71 | byte__rev_array_union ( footer_ptr->data_offset ); 72 | byte__rev_array_union ( footer_ptr->timestamp ); 73 | byte__rev_array_union ( footer_ptr->creator_ver ); 74 | byte__rev_array_union ( footer_ptr->creator_os ); 75 | byte__rev_array_union ( footer_ptr->orig_size ); 76 | byte__rev_array_union ( footer_ptr->cur_size ); 77 | byte__rev_array_union ( footer_ptr->geom_cyls ); 78 | byte__rev_array_union ( footer_ptr->type ); 79 | byte__rev_array_union ( footer_ptr->checksum ); 80 | } 81 | 82 | #endif /* WV_M_MSVHD_H_ */ 83 | -------------------------------------------------------------------------------- /src/include/portable.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WV_M_PORTABLE_H_ 22 | # define WV_M_PORTABLE_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Portability definitions 28 | * 29 | */ 30 | 31 | # define NDIS50 1 32 | # define OBJ_KERNEL_HANDLE 0x00000200L 33 | # ifdef _MSC_VER 34 | # define STDCALL 35 | # define __attribute__(x) 36 | typedef unsigned int UINT, 37 | *PUINT; 38 | # endif 39 | 40 | # if _WIN32_WINNT < 0x0502 41 | # ifdef SCSIOP_READ16 42 | # undef SCSIOP_READ16 43 | # define SCSIOP_READ16 0x88 44 | # endif 45 | # ifdef SCSIOP_WRITE16 46 | # undef SCSIOP_WRITE16 47 | # define SCSIOP_WRITE16 0x8a 48 | # endif 49 | # ifdef SCSIOP_VERIFY16 50 | # undef SCSIOP_VERIFY16 51 | # define SCSIOP_VERIFY16 0x8f 52 | # endif 53 | # ifdef SCSIOP_READ_CAPACITY16 54 | # undef SCSIOP_READ_CAPACITY16 55 | # define SCSIOP_READ_CAPACITY16 0x9e 56 | # endif 57 | # endif 58 | 59 | #endif /* WV_M_PORTABLE_H_ */ 60 | -------------------------------------------------------------------------------- /src/include/protocol.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef AOE_M_PROTOCOL_H_ 22 | # define AOE_M_PROTOCOL_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Protocol specifics 28 | * 29 | */ 30 | 31 | extern BOOLEAN STDCALL Protocol_SearchNIC ( 32 | IN PUCHAR Mac 33 | ); 34 | extern UINT32 STDCALL Protocol_GetMTU ( 35 | IN PUCHAR Mac 36 | ); 37 | extern BOOLEAN STDCALL Protocol_Send ( 38 | IN PUCHAR SourceMac, 39 | IN PUCHAR DestinationMac, 40 | IN PUCHAR Data, 41 | IN UINT32 DataSize, 42 | IN PVOID PacketContext 43 | ); 44 | extern NTSTATUS Protocol_Start(void); 45 | extern VOID Protocol_Stop(void); 46 | 47 | #endif /* AOE_M_PROTOCOL_H_ */ 48 | -------------------------------------------------------------------------------- /src/include/ramdisk.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_RAMDISK_H_ 20 | # define WV_M_RAMDISK_H_ 21 | 22 | /** 23 | * @file 24 | * 25 | * RAM disk specifics. 26 | */ 27 | 28 | typedef struct WV_RAMDISK_T { 29 | WV_S_DEV_EXT DevExt; 30 | WV_S_DEV_T Dev[1]; 31 | WVL_S_DISK_T disk[1]; 32 | UINT32 DiskBuf; 33 | UINT32 DiskSize; 34 | WV_FP_DEV_FREE prev_free; 35 | } WV_S_RAMDISK_T, * WV_SP_RAMDISK_T; 36 | 37 | extern WV_SP_RAMDISK_T WvRamdiskCreatePdo(IN WVL_E_DISK_MEDIA_TYPE); 38 | 39 | #endif /* WV_M_RAMDISK_H_ */ 40 | -------------------------------------------------------------------------------- /src/include/registry.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | #ifndef WV_M_REGISTRY_H_ 22 | # define WV_M_REGISTRY_H_ 23 | 24 | /** 25 | * @file 26 | * 27 | * Registry specifics. 28 | */ 29 | 30 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegNoteOsLoadOpts(LPWSTR *); 31 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegOpenKey(LPCWSTR, PHANDLE); 32 | extern WVL_M_LIB VOID STDCALL WvlRegCloseKey(HANDLE); 33 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegFetchKvi( 34 | HANDLE, 35 | LPCWSTR, 36 | PKEY_VALUE_PARTIAL_INFORMATION * 37 | ); 38 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegFetchSz( 39 | HANDLE, 40 | LPCWSTR, 41 | LPWSTR * 42 | ); 43 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegFetchMultiSz( 44 | HANDLE, 45 | LPCWSTR, 46 | LPWSTR ** 47 | ); 48 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegFetchDword( 49 | IN HANDLE, 50 | IN LPCWSTR, 51 | OUT UINT32 * 52 | ); 53 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegStoreSz( 54 | HANDLE, 55 | LPCWSTR, 56 | LPWSTR 57 | ); 58 | extern WVL_M_LIB NTSTATUS STDCALL WvlRegStoreDword( 59 | HANDLE, 60 | LPCWSTR, 61 | UINT32 62 | ); 63 | 64 | #endif /* WV_M_REGISTRY_H_ */ 65 | -------------------------------------------------------------------------------- /src/include/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by winvblk.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | # ifndef APSTUDIO_READONLY_SYMBOLS 10 | # define _APS_NEXT_RESOURCE_VALUE 101 11 | # define _APS_NEXT_COMMAND_VALUE 40001 12 | # define _APS_NEXT_CONTROL_VALUE 1000 13 | # define _APS_NEXT_SYMED_VALUE 101 14 | # endif 15 | #endif 16 | -------------------------------------------------------------------------------- /src/include/safehook.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_PROBE_H_ 20 | # define WV_M_PROBE_H_ 21 | 22 | /** 23 | * @file 24 | * 25 | * "Safe INT 0x13 hook" mini-driver 26 | */ 27 | 28 | /** Object types */ 29 | typedef struct WV_PROBE_SAFE_MBR_HOOK 30 | WV_S_PROBE_SAFE_MBR_HOOK, * WV_SP_PROBE_SAFE_MBR_HOOK; 31 | typedef struct S_WV_SAFEHOOK_PDO_ S_WV_SAFEHOOK_PDO, * SP_WV_SAFEHOOK_PDO; 32 | typedef struct S_WV_SAFE_HOOK_BUS S_WV_SAFE_HOOK_BUS; 33 | 34 | /** Function declarations */ 35 | 36 | /** 37 | * Create a "safe INT 0x13 hook" PDO 38 | * 39 | * @v HookAddr The SEG16:OFF16 address for the hook 40 | * @v SafeHook Points to the safe hook 41 | * @v ParentBus The parent bus for the newly-created safe hook bus 42 | * @ret PDEVICE_OBJECT The newly-create safe hook bus, or NULL upon failure 43 | */ 44 | extern PDEVICE_OBJECT STDCALL WvSafeHookPdoCreate( 45 | IN SP_X86_SEG16OFF16 HookAddr, 46 | IN WV_SP_PROBE_SAFE_MBR_HOOK SafeHook, 47 | IN PDEVICE_OBJECT ParentBus 48 | ); 49 | 50 | /** 51 | * Process a potential INT 0x13 "safe hook" 52 | * 53 | * @param HookAddress 54 | * The SEG16:OFF16 address to probe for a safe hook 55 | * 56 | * @param DeviceObject 57 | * Points to the DEVICE_OBJECT pointer to populate with a pointer to 58 | * the created safe hook device 59 | * 60 | * @retval STATUS_SUCCESS 61 | * @retval STATUS_NOT_SUPPORTED 62 | * The address does not appear to contain a safe hook 63 | * @retval STATUS_INSUFFICIENT_RESOURCES 64 | * A device for the safe hook could not be created 65 | */ 66 | extern WVL_M_LIB NTSTATUS STDCALL WvlCreateSafeHookDevice( 67 | IN S_X86_SEG16OFF16 * HookAddress, 68 | IN OUT DEVICE_OBJECT ** DeviceObject 69 | ); 70 | 71 | /** 72 | * Check if a device is an INT 0x13 "safe hook" 73 | * 74 | * @param DeviceObject 75 | * The device to check. This device must have been created via 76 | * WvlCreateDevice 77 | * 78 | * @retval NULL 79 | * The device is not a safe hook 80 | * @return 81 | * Otherwise, returns a pointer to the safe hook SEG16:OFF16 82 | */ 83 | extern WVL_M_LIB S_X86_SEG16OFF16 * STDCALL WvlGetSafeHook( 84 | IN DEVICE_OBJECT * DeviceObject 85 | ); 86 | 87 | /* From ../src/winvblock/safehook/fdo.c */ 88 | 89 | /** FDO IRP dispatcher */ 90 | DRIVER_DISPATCH WvSafeHookIrpDispatch; 91 | 92 | /** Struct/union type definitions */ 93 | 94 | #ifdef _MSC_VER 95 | # pragma pack(1) 96 | #endif 97 | struct WV_PROBE_SAFE_MBR_HOOK { 98 | UCHAR Jump[3]; 99 | UCHAR Signature[8]; 100 | UCHAR VendorId[8]; 101 | S_X86_SEG16OFF16 PrevHook; 102 | UINT32 Flags; 103 | UINT32 Mbft; /* MEMDISK only. */ 104 | } __attribute__((__packed__)); 105 | #ifdef _MSC_VER 106 | # pragma pack() 107 | #endif 108 | 109 | struct S_WV_SAFEHOOK_PDO_ { 110 | WV_S_DEV_EXT DevExt; 111 | WV_S_PROBE_SAFE_MBR_HOOK SafeHookCopy; 112 | S_X86_SEG16OFF16 Whence; 113 | DEVICE_OBJECT * ParentBus; 114 | DEVICE_OBJECT * Self; 115 | S_WV_SAFEHOOK_PDO * Next; 116 | }; 117 | 118 | struct S_WV_SAFE_HOOK_BUS { 119 | /** This must be the first member of all extension types */ 120 | WV_S_DEV_EXT DeviceExtension[1]; 121 | 122 | /** Flags for state that must be accessed atomically */ 123 | volatile LONG Flags; 124 | 125 | /** The safe hook's PDO (bottom of the device stack) */ 126 | DEVICE_OBJECT * PhysicalDeviceObject; 127 | 128 | /** PnP bus relations. A safe hook can only have one child, at most */ 129 | DEVICE_RELATIONS BusRelations[1]; 130 | 131 | /** A record of the previous INT 0x13 handler in the chain */ 132 | S_X86_SEG16OFF16 PreviousInt13hHandler[1]; 133 | }; 134 | 135 | #endif /* WV_M_PROBE_H_ */ 136 | -------------------------------------------------------------------------------- /src/include/thread.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef M_THREAD_H_ 20 | 21 | /**** 22 | * @file 23 | * 24 | * WinVBlock thread library. 25 | */ 26 | 27 | /*** Macros */ 28 | #define M_THREAD_H_ 29 | 30 | /*** Constants */ 31 | enum E_WVL_THREAD_STATE_ { 32 | WvlThreadStateNotStarted, 33 | WvlThreadStateStarting, 34 | WvlThreadStateStarted, 35 | WvlThreadStateStopping, 36 | WvlThreadStateStopped, 37 | WvlThreadStates 38 | }; 39 | 40 | /*** Object types */ 41 | typedef struct S_WVL_THREAD_ITEM_ WVL_S_THREAD_ITEM, * WVL_SP_THREAD_ITEM; 42 | typedef enum E_WVL_THREAD_STATE_ WVL_E_THREAD_STATE, * WVL_EP_THREAD_STATE; 43 | typedef struct S_WVL_THREAD_ WVL_S_THREAD, * WVL_SP_THREAD; 44 | 45 | /*** Function types */ 46 | typedef VOID STDCALL WVL_F_THREAD_ITEM(IN OUT WVL_SP_THREAD_ITEM); 47 | typedef WVL_F_THREAD_ITEM * WVL_FP_THREAD_ITEM; 48 | 49 | /*** Function declarations */ 50 | extern WVL_M_LIB NTSTATUS WvlThreadStart(IN OUT WVL_SP_THREAD); 51 | extern WVL_M_LIB BOOLEAN STDCALL WvlThreadSendStopAndWait(IN WVL_SP_THREAD); 52 | extern WVL_M_LIB WVL_SP_THREAD WvlThreadGetCurrent(void); 53 | extern WVL_M_LIB BOOLEAN STDCALL WvlThreadAddItem( 54 | IN WVL_SP_THREAD, 55 | IN WVL_SP_THREAD_ITEM 56 | ); 57 | extern WVL_M_LIB WVL_SP_THREAD_ITEM STDCALL WvlThreadGetItem(IN WVL_SP_THREAD); 58 | extern WVL_M_LIB VOID STDCALL WvlThreadTest(IN OUT WVL_SP_THREAD_ITEM); 59 | extern WVL_M_LIB VOID WvlThreadTestMsg(IN PCHAR); 60 | 61 | /*** Struct/union definitions */ 62 | struct S_WVL_THREAD_ITEM_ { 63 | LIST_ENTRY Link; 64 | WVL_FP_THREAD_ITEM Func; 65 | }; 66 | 67 | struct S_WVL_THREAD_ { 68 | WVL_S_THREAD_ITEM Main; 69 | WVL_E_THREAD_STATE State; 70 | KSPIN_LOCK Lock; 71 | KEVENT Signal; 72 | HANDLE Handle; 73 | PETHREAD Thread; 74 | }; 75 | 76 | #endif /* M_THREAD_H_ */ 77 | -------------------------------------------------------------------------------- /src/include/winvblock.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WVL_M_WINVBLOCK_H_ 20 | # define WVL_M_WINVBLOCK_H_ 21 | 22 | /** 23 | * @file 24 | * 25 | * WinVBlock project common material 26 | */ 27 | 28 | #define WvlCountof(array) (sizeof (array) / sizeof *(array)) 29 | #define WvlUnusedParameter(param) ((void) param) 30 | 31 | #define WVL_M_LIT "WinVBlock" 32 | #define WVL_M_WLIT L"WinVBlock" 33 | 34 | /* To export functions while serving as a library. */ 35 | #ifdef PROJECT_WV 36 | # define WVL_M_LIB __declspec(dllexport) 37 | #else 38 | # define WVL_M_LIB __declspec(dllimport) 39 | #endif 40 | 41 | /*** Object types. */ 42 | typedef union U_WV_LARGE_INT_ U_WV_LARGE_INT, UP_WV_LARGE_INT; 43 | 44 | /*** Struct/union definitions. */ 45 | union U_WV_LARGE_INT_ { 46 | LONGLONG longlong; 47 | LARGE_INTEGER large_int; 48 | }; 49 | 50 | #endif /* WVL_M_WINVBLOCK_H_ */ 51 | -------------------------------------------------------------------------------- /src/include/wv_stdbool.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2010, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_STDBOOL_H_ 20 | # define WV_M_STDBOOL_H_ 21 | 22 | /* Boolean type. */ 23 | typedef unsigned short bool; 24 | 25 | /* Boolean values. */ 26 | #define false (0) 27 | #define true (1) 28 | 29 | #endif /* WV_M_STDBOOL_H_ */ 30 | -------------------------------------------------------------------------------- /src/include/wv_stddef.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2010, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_STDDEF_H_ 20 | # define WV_M_STDDEF_H_ 21 | # include "stddef.h" 22 | 23 | /* Type for the size, in bytes, of any object. */ 24 | typedef size_t wv_size_t; 25 | 26 | #endif /* WV_M_STDDEF_H_ */ 27 | -------------------------------------------------------------------------------- /src/include/wv_stdlib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_STDLIB_H_ 20 | # define WV_M_STDLIB_H_ 21 | 22 | #include "wv_stddef.h" 23 | 24 | /* Allocate memory from non-paged memory pool. */ 25 | PVOID wv_malloc(wv_size_t size); 26 | 27 | /* Allocate memory from paged memory pool. */ 28 | PVOID wv_palloc(wv_size_t size); 29 | 30 | /* Allocate memory from non-paged memory pool and fill with zero bits. */ 31 | PVOID wv_mallocz(wv_size_t size); 32 | 33 | /* Allocate memory from paged memory pool and fill with zero bits. */ 34 | PVOID wv_pallocz(wv_size_t size); 35 | 36 | /* Free allocated memory. */ 37 | VOID wv_free(PVOID ptr); 38 | 39 | #endif /* WV_M_STDLIB_H_ */ 40 | -------------------------------------------------------------------------------- /src/include/wv_string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef WV_M_STRING_H_ 20 | # define WV_M_STRING_H_ 21 | # include "wv_stdbool.h" 22 | # include "wv_stddef.h" 23 | 24 | /* Test two byte ranges in memory for equality. */ 25 | bool wv_memcmpeq(const VOID * s1, const VOID * s2, wv_size_t n); 26 | 27 | #endif /* WV_M_STRING_H_ */ 28 | -------------------------------------------------------------------------------- /src/include/x86.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2010-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | #ifndef M_X86_H_ 20 | 21 | /**** 22 | * @file 23 | * 24 | * x86 stuff. 25 | */ 26 | 27 | /*** Macros. */ 28 | #define M_X86_H_ 29 | 30 | /** 31 | * Return a 32-bit, linear address for a SEG16:OFF16 32 | * 33 | * @v Seg16Off16 The WV_SP_PROBE_INT_VECTOR with the 34 | * segment and offset. 35 | * @ret UINT32 The linear address for the segment and offset. 36 | */ 37 | #define M_X86_SEG16OFF16_ADDR(Seg16Off16) \ 38 | ((((UINT32)(Seg16Off16)->Segment) << 4) + (Seg16Off16)->Offset) 39 | 40 | /*** Types. */ 41 | typedef struct S_X86_SEG16OFF16_ S_X86_SEG16OFF16, * SP_X86_SEG16OFF16; 42 | 43 | /*** Struct definitions. */ 44 | #ifdef _MSC_VER 45 | # pragma pack(1) 46 | #endif 47 | struct S_X86_SEG16OFF16_ { 48 | UINT16 Offset; 49 | UINT16 Segment; 50 | } __attribute__((__packed__)); 51 | #ifdef _MSC_VER 52 | # pragma pack() 53 | #endif 54 | 55 | #endif /* M_X86_H_ */ 56 | -------------------------------------------------------------------------------- /src/loader/loader.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2006-2008, V. 3 | * Portions copyright (C) 2009-2011, Shao Miller . 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * 25 | * Driver installation 26 | * 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "portable.h" 35 | #include "winvblock.h" 36 | 37 | #define MAX_CLASS_NAME_LEN 64 38 | 39 | /* typedef BOOL WINAPI (*PROC)(HWND, LPCTSTR, LPCTSTR, DWORD, PBOOL OPTIONAL); 40 | */ 41 | 42 | static VOID 43 | DisplayError ( 44 | char *String 45 | ) 46 | { 47 | CHAR ErrorString[1024]; 48 | UINT32 ErrorCode = GetLastError(); 49 | 50 | printf ( "Error: %s\n", String ); 51 | printf ( "GetLastError: 0x%08x (%d)\n", ErrorCode, ( int )ErrorCode ); 52 | if ( FormatMessage 53 | ( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, 54 | ErrorCode, MAKELANGID ( LANG_NEUTRAL, SUBLANG_DEFAULT ), 55 | ( LPTSTR ) ErrorString, sizeof ( ErrorString ), NULL ) ) 56 | printf ( "%s", ErrorString ); 57 | } 58 | 59 | int 60 | main ( 61 | int argc, 62 | char **argv, 63 | char **envp 64 | ) 65 | { 66 | HDEVINFO DeviceInfoSet = 0; 67 | SP_DEVINFO_DATA DeviceInfoData; 68 | GUID ClassGUID; 69 | TCHAR ClassName[MAX_CLASS_NAME_LEN]; 70 | HINSTANCE Library; 71 | PROC UpdateDriverForPlugAndPlayDevicesA; 72 | BOOL RebootRequired = FALSE; 73 | TCHAR FullFilePath[1024]; 74 | 75 | if ( !GetFullPathName 76 | ( "winvblk.inf", sizeof ( FullFilePath ), FullFilePath, NULL ) ) 77 | goto GetFullPathNameError; 78 | if ( ( Library = LoadLibrary ( "newdev.dll" ) ) == NULL ) 79 | goto LoadLibraryError; 80 | if ( ( UpdateDriverForPlugAndPlayDevicesA = 81 | GetProcAddress ( Library, 82 | "UpdateDriverForPlugAndPlayDevicesA" ) ) == NULL ) 83 | goto GetProcAddressError; 84 | 85 | if ( !SetupDiGetINFClass 86 | ( FullFilePath, &ClassGUID, ClassName, sizeof ( ClassName ), 0 ) ) 87 | goto GetINFClassError; 88 | if ( ( DeviceInfoSet = 89 | SetupDiCreateDeviceInfoList ( &ClassGUID, 90 | 0 ) ) == INVALID_HANDLE_VALUE ) 91 | goto CreateDeviceInfoListError; 92 | DeviceInfoData.cbSize = sizeof ( SP_DEVINFO_DATA ); 93 | if ( !SetupDiCreateDeviceInfo 94 | ( DeviceInfoSet, ClassName, &ClassGUID, NULL, 0, DICD_GENERATE_ID, 95 | &DeviceInfoData ) ) 96 | goto CreateDeviceInfoError; 97 | if ( !SetupDiSetDeviceRegistryProperty 98 | ( DeviceInfoSet, &DeviceInfoData, SPDRP_HARDWAREID, 99 | ( LPBYTE ) WVL_M_LIT "\0\0\0", 100 | ( lstrlen ( WVL_M_LIT "\0\0\0" ) + 1 + 101 | 1 ) * sizeof ( TCHAR ) ) ) 102 | goto SetDeviceRegistryPropertyError; 103 | if ( !SetupDiCallClassInstaller 104 | ( DIF_REGISTERDEVICE, DeviceInfoSet, &DeviceInfoData ) ) 105 | goto CallClassInstallerREGISTERDEVICEError; 106 | 107 | if ( !UpdateDriverForPlugAndPlayDevices 108 | ( 0, WVL_M_LIT "\0\0\0", FullFilePath, INSTALLFLAG_FORCE, 109 | &RebootRequired ) ) 110 | { 111 | DWORD err = GetLastError ( ); 112 | DisplayError ( "UpdateDriverForPlugAndPlayDevices" ); 113 | if ( !SetupDiCallClassInstaller 114 | ( DIF_REMOVE, DeviceInfoSet, &DeviceInfoData ) ) 115 | DisplayError ( "CallClassInstaller(REMOVE)" ); 116 | SetLastError ( err ); 117 | } 118 | if ( RebootRequired ) 119 | printf ( "Need reboot\n" ); 120 | 121 | printf ( "Press enter to remove\n" ); 122 | getchar ( ); 123 | if ( !SetupDiCallClassInstaller 124 | ( DIF_REMOVE, DeviceInfoSet, &DeviceInfoData ) ) 125 | DisplayError ( "CallClassInstaller(REMOVE)" ); 126 | return 0; 127 | 128 | GetFullPathNameError: 129 | DisplayError ( "GetFullPathName" ); 130 | goto end; 131 | LoadLibraryError: 132 | DisplayError ( "LoadLibrary" ); 133 | goto end; 134 | GetProcAddressError: 135 | DisplayError ( "GetProcAddress" ); 136 | goto end; 137 | GetINFClassError: 138 | DisplayError ( "GetINFClass" ); 139 | goto end; 140 | CreateDeviceInfoListError: 141 | DisplayError ( "CreateDeviceInfoList" ); 142 | goto end; 143 | 144 | CreateDeviceInfoError: 145 | DisplayError ( "CreateDeviceInfo" ); 146 | goto cleanup_DeviceInfo; 147 | SetDeviceRegistryPropertyError: 148 | DisplayError ( "SetDeviceRegistryProperty" ); 149 | goto cleanup_DeviceInfo; 150 | CallClassInstallerREGISTERDEVICEError: 151 | DisplayError ( "CallClassInstaller(REGISTERDEVICE)" ); 152 | goto cleanup_DeviceInfo; 153 | 154 | cleanup_DeviceInfo: 155 | SetupDiDestroyDeviceInfoList ( DeviceInfoSet ); 156 | end: 157 | printf ( "Press enter to exit\n" ); 158 | getchar ( ); 159 | return 0; 160 | } 161 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/Makefile: -------------------------------------------------------------------------------- 1 | all: aoe.0 2 | 3 | clean: 4 | rm -rf obj 5 | 6 | obj/aoe.o: aoe.S aoe.h Makefile 7 | @rm -rf aoe.0 8 | @mkdir -p obj 9 | gcc -Wall -c -o obj/aoe.o aoe.S 10 | 11 | obj/pxe.o: pxe.S aoe.h Makefile 12 | @rm -rf aoe.0 13 | @mkdir -p obj 14 | gcc -Wall -c -o obj/pxe.o pxe.S 15 | 16 | obj/int13.o: int13.S aoe.h Makefile 17 | @rm -rf aoe.0 18 | @mkdir -p obj 19 | gcc -Wall -c -o obj/int13.o int13.S 20 | 21 | obj/lib.o: lib.S aoe.h Makefile 22 | @rm -rf aoe.0 23 | @mkdir -p obj 24 | gcc -Wall -c -o obj/lib.o lib.S 25 | 26 | obj/global.o: global.S aoe.h Makefile 27 | @rm -rf aoe.0 28 | @mkdir -p obj 29 | gcc -Wall -c -o obj/global.o global.S 30 | 31 | obj/debug.o: debug.S aoe.h Makefile 32 | @rm -rf aoe.0 33 | @mkdir -p obj 34 | gcc -Wall -c -o obj/debug.o debug.S 35 | 36 | aoe.0: aoe.ld obj/aoe.o obj/pxe.o obj/int13.o obj/lib.o obj/global.o obj/debug.o Makefile 37 | @rm -rf aoe.0 38 | ld -static -T aoe.ld obj/aoe.o obj/pxe.o obj/int13.o obj/lib.o obj/global.o obj/debug.o -o obj/aoe 39 | objcopy -O binary obj/aoe aoe.0 40 | @if [ `expr \`find aoe.0 -printf "%s"\` % 2` == 0 ]; then echo -en "\0" >> aoe.0; fi 41 | @find aoe.0 -printf "%f size: %s\n" 42 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/aoe.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | #include "aoe.h" 22 | 23 | start: 24 | pushfl # save eflags 25 | pushw %ax # save ax 26 | call 0f # pushl ip 27 | 0: popw %ax # popl ip 28 | subw $0b, %ax # offset by 0: to get _start adress 29 | cmpw $0x7c00, %ax # did we start from 0x7c00? 30 | je 0f # if not, print error 31 | popw %ax # restore ax (cosmetic) 32 | popfl # restore flags (cosmetic) 33 | print "\nip is not 0x7c00, can not continue...\n" 34 | halt 35 | 0: movw %cs, %ax # get %cs 36 | cmpw $0x0000, %ax # is %cs 0x0000? 37 | je 0f # if not, print error 38 | popw %ax # restore ax (cosmetic) 39 | popfl # restore flags (cosmetic) 40 | print "\ncs is not 0x0000, can not continue...\n" 41 | halt 42 | 0: popw %ax # restore ax 43 | popfl # restore eflags 44 | ljmp $0x07c0, $0f # realign cs:eip to let start be 0 45 | 46 | 0: movw $0, %bp # use bp to set ss 47 | movw %bp, %ss # setup new stack 48 | movw $0x7c00, %sp # setup sp to below boot sector 49 | movw $0x7c00, %bp # setup bp to the same 50 | 51 | pushfl # everything should have its initial 52 | pushal # values, so push it all on the stack 53 | pushw %ds 54 | pushw %es 55 | pushw %fs 56 | pushw %gs 57 | 58 | int $0x12 # get memory size in kb in ax 59 | shlw $6, %ax # change from kb to paragraphs 60 | movw $_pxesize, %bx # get pxe size 61 | addw $0x0f, %bx # add 15 to round up on paragraph 62 | shrw $4, %bx # change to paragraphs 63 | subw %bx, %ax # calculate target segment 64 | andw $0xffc0, %ax # round down to kb boundry 65 | movw %ax, %es # set es as target segment 66 | shrw $6, %ax # convert to kb for new free mem 67 | pushw $0x0040 # bios area 68 | popw %ds 69 | movw %ax, %ds:0x0013 # store in bios area at 0040:0013 70 | pushw %cs # read from segment 07c0 71 | popw %ds 72 | xorw %si, %si # zero si 73 | xorw %di, %di # zero di 74 | movw $_pxesize, %cx # get size 75 | cld # positive direction 76 | rep movsb # copy ourself to target segment 77 | pushw %es # setup segment for lret 78 | pushw $0f # setup offset for lret 79 | lret # long return into target segment 80 | 81 | 0: print "\nWelcome to AoE Boot...\n\n" 82 | 83 | #ifdef DEBUG 84 | call debuginit # init debug vectors (debug.S) 85 | pushw $0x0000 # set es ready for access to the bios 86 | popw %es # area and loading the boot sector 87 | movw $0x7c00, %di 88 | movw $(0xffff - 0x7c00), %cx 89 | movb $0xcc, %al # int3 (break) 90 | cld 91 | rep stosb # fill 0000:7c00-0000:ffff with breaks 92 | #endif 93 | 94 | call pxeinit # init pxe api and get rootpath (pxe.S) 95 | //movb $0, %cs:_irq # always use polling 96 | call printaoeparameters # print aoe parameters 97 | call getdiskparameters # get disk config (pxe.S) 98 | call printdiskparameters # print disk parameters 99 | call int13init # setup int13 handler (int13.S) 100 | 101 | pushw $0x0000 # set es ready for access to the bios 102 | popw %es # area and loading the boot sector 103 | 1: print "\nBoot from (N)etwork, (H)arddisk or (F)loppy?\n" 104 | pushw $TIMEOUT 105 | call getkey 106 | cmpb $0, %al 107 | je 1f # default to network boot 108 | cmpb $'Z', %al # make input upcase 109 | jna 0f 110 | subb $('a' - 'A'), %al 111 | 0: cmpb $'N', %al 112 | je 1f 113 | cmpb $'H', %al 114 | je 2f 115 | cmpb $'F', %al 116 | je 3f 117 | jmp 1b # input error 118 | 119 | 1: movb $0x80, %cs:_drive # aoe drive is 1st harddisk 120 | movw $aBFT, %bx # calculate aBFT segment boundry 121 | subw %bx, 1 # (x-1) & 0xfff0 + 0x10 122 | andw $0xfff0, %bx 123 | addw $0x10, %bx 124 | 125 | movl $0x54464261, %cs:(%bx) # setup aBFT 126 | movl $(slack - aBFT), %cs:(length - aBFT)(%bx) 127 | movb $1, %cs:(revision - aBFT)(%bx) 128 | movl %cs:_clientmac, %eax # client mac (high 4) 129 | movl %eax, %cs:(clientmac - aBFT)(%bx) 130 | movw %cs:_clientmac + 4, %ax # client mac (low 2) 131 | movw %ax, %cs:(clientmac - aBFT + 4)(%bx) 132 | movw %cs:_major, %ax # major 133 | movw %ax, %cs:(major - aBFT)(%bx) 134 | movb %cs:_minor, %al # minor 135 | movb %al, %cs:(minor - aBFT)(%bx) 136 | 137 | movw $(slack - aBFT), %cx # length 138 | pushw %bx # keep safe 139 | xorb %al, %al # zero checksum 140 | 0: subb %cs:(%bx), %al 141 | incw %bx # by counting through %bx 142 | decw %cx # %cx times... 143 | jnz 0b 144 | popw %bx # get aBFT address and store checksum 145 | movb %al, %cs:(checksum - aBFT)(%bx) 146 | 147 | movb $1, %es:0x0475 # 1 harddisk 148 | movb $0x80, %dl # boot from harddisk 149 | jmp 0f 150 | 2: movb $0x81, %cs:_drive # aoe drive is 2nd harddisk 151 | movb $2, %es:0x0475 # 2 harddisks 152 | movb $0x80, %dl # boot from harddisk 153 | jmp 0f 154 | 3: movb $0x80, %cs:_drive # aoe drive is 1st harddisk 155 | movb $1, %es:0x0475 # 1 harddisk 156 | movb $0x00, %dl # boot from floppy 157 | 158 | 0: movb $0x02, %ah # load sector 0 in 0:7c00 159 | movb $1, %al 160 | movb $0, %ch 161 | movb $1, %cl 162 | movb $0, %dh 163 | pushw $0x0000 164 | popw %es 165 | movw $0x7c00, %bx 166 | int $0x13 167 | jnc 0f 168 | print "Hardware boot failure\n" 169 | halt 170 | 171 | 0: popw %gs # pop everything to revert 172 | popw %fs # to starting state 173 | popw %es 174 | popw %ds 175 | popal 176 | popfl 177 | 178 | movb $0x80, %dl # for ReactOS freeloader 179 | ljmp $0x0000, $0x7c00 # long jump to bootsector 180 | 181 | 182 | # printaoeparameters: print rootpath AoE setting 183 | printaoeparameters: 184 | enter $0, $0 185 | pushw %bx 186 | 187 | print "Boot from: e" 188 | pushw %cs:_major 189 | call printnumber 190 | print "." 191 | pushw %cs:_minor 192 | call printnumber 193 | 194 | xorw %bx, %bx 195 | print " Client Address: " 196 | 0: pushw %cs:_clientmac(%bx) 197 | call printbyte 198 | pushw $':' 199 | call printchar 200 | incw %bx 201 | cmpw $5, %bx 202 | jb 0b 203 | pushw %cs:_clientmac(%bx) 204 | call printbyte 205 | 206 | print " Irq: " 207 | pushw %cs:_irq 208 | call printnumber 209 | cmpb $0, %cs:_irq 210 | jne 0f 211 | print " (polling)" 212 | 213 | 0: call line 214 | popw %bx 215 | leave 216 | ret $0 217 | 218 | # printdiskparameters: prints disk parameters 219 | printdiskparameters: 220 | enter $0, $0 221 | pushl %eax 222 | pushw %bx 223 | 224 | xorw %bx, %bx 225 | print "Server Address: " 226 | 0: pushw %cs:_servermac(%bx) 227 | call printbyte 228 | pushw $':' 229 | call printchar 230 | incw %bx 231 | cmpw $5, %bx 232 | jb 0b 233 | pushw %cs:_servermac(%bx) 234 | call printbyte 235 | call line 236 | 237 | movl %cs:_size, %eax 238 | shrl $11, %eax 239 | print "Disk Size: " 240 | pushl %eax 241 | call printlongnumber 242 | print "M Cylinders: " 243 | pushl %cs:_cylinders 244 | call printlongnumber 245 | print " Heads: " 246 | xorb %ah, %ah 247 | movb %cs:_heads, %al 248 | pushw %ax 249 | call printnumber 250 | print " Sectors: " 251 | movb %cs:_sectors, %al 252 | pushw %ax 253 | call printnumber 254 | call line 255 | 256 | popw %bx 257 | popl %eax 258 | leave 259 | ret $0 260 | 261 | aBFT: 262 | signature: 263 | .org .+4, 0 264 | length: 265 | .org .+4, 0 266 | revision: 267 | .org .+1, 0 268 | checksum: 269 | .org .+1, 0 270 | oemid: 271 | .org .+6, 0 272 | oemtableid: 273 | .org .+8, 0 274 | reserved1: 275 | .org .+12, 0 276 | major: 277 | .org .+2, 0 278 | minor: 279 | .org .+1, 0 280 | reserved2: 281 | .org .+1, 0 282 | clientmac: 283 | .org .+6, 0 284 | slack: 285 | .org .+15, 0 286 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/aoe.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | .code16 22 | //#define DEBUG 23 | //#define CHKSUM 24 | #define SERIAL 25 | 26 | #define BREAK 0 27 | #define TIMEOUT 55 28 | 29 | #define print call printline; .asciz 30 | #define halt jmp haltcpu 31 | #define D call debug; 32 | #define N call ndebug; 33 | 34 | #define AoEdstaddr 0 35 | #define AoEsrcaddr 6 36 | #define AoEprotocol 12 37 | #define AoEver 14 38 | #define AoEflags 14 39 | #define AoEerror 15 40 | #define AoEmajor 16 41 | #define AoEminor 18 42 | #define AoEcommand 19 43 | #define AoEtag 20 44 | #define AoEaflags 24 45 | #define AoEerr 25 46 | #define AoEfeature 25 47 | #define AoEcount 26 48 | #define AoEcmd 27 49 | #define AoEstatus 27 50 | #define AoElba0 28 51 | #define AoElba1 29 52 | #define AoElba2 30 53 | #define AoElba3 31 54 | #define AoElba4 32 55 | #define AoElba5 33 56 | #define AoEreserved 34 57 | #define AoEdata 36 58 | #define AoEsize 1518 59 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/aoe.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | SECTIONS { 22 | . = 0; 23 | .text : {*(*)} 24 | } 25 | PROVIDE(_pxesize = .); 26 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/debug.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | #include "aoe.h" 22 | 23 | .globl _debug_srcaddr, _debug_undi_transmit_packet, _debug_undi_TBD 24 | 25 | _debug: 26 | _debug_dstaddr: .org .+6, 0xff 27 | _debug_srcaddr: .org .+6, 0 28 | _debug_protocol: .word 0x0180 29 | _debug_count: .long 0 30 | _debug_eflags: .long 0 31 | _debug_ip: .word 0 32 | _debug_cs: .word 0 33 | _debug_ds: .word 0 34 | _debug_es: .word 0 35 | _debug_fs: .word 0 36 | _debug_gs: .word 0 37 | _debug_ss: .word 0 38 | _debug_ebp: .long 0 39 | _debug_esp: .long 0 40 | _debug_eax: .long 0 41 | _debug_ebx: .long 0 42 | _debug_ecx: .long 0 43 | _debug_edx: .long 0 44 | _debug_esi: .long 0 45 | _debug_edi: .long 0 46 | _debug_end: 47 | 48 | _debug_undi_transmit_packet: # 0x0008 49 | .word 0 # PXENV_STATUS Status 50 | .byte 0 # UINT8 Protocol 51 | .byte 1 # UINT8 XmitFlag 52 | .long _debug_dstaddr # SEGOFF16 DestAddr 53 | .long _debug_undi_TBD # SEGOFF16 TBD 54 | .org .+(2 * 4), 0 # UINT32 Reserved[2] 55 | 56 | _debug_undi_TBD: 57 | .word (_debug_end - _debug) # UINT16 ImmedLength 58 | .long _debug # SEGOFF16 Xmit 59 | .word 0 # UINT16 DataBlkCount 60 | .org .+(8 * 8), 0 # DataBlk DataBlock[8] 61 | 62 | _count: .long 0 63 | 64 | # sets exception vectors 65 | .globl debuginit 66 | debuginit: 67 | enter $0, $0 68 | pushf 69 | push %es 70 | push $0 71 | pop %es 72 | pushw %cs 73 | popw %es:((0x3 * 4) + 2) 74 | pushw $int3 75 | popw %es:(0x3 * 4) 76 | pop %es 77 | popf 78 | leave 79 | ret $0 80 | 81 | # int3: break (prints cpu state and halts) 82 | int3: 83 | call debug 84 | jmp . 85 | 86 | # count: inceases _count, break when BREAK reached 87 | .globl count 88 | count: 89 | enter $0, $0 90 | pushf 91 | push %eax 92 | incl %cs:_count 93 | mov $BREAK, %eax 94 | cmpl $0, %eax 95 | pop %eax 96 | je 0f 97 | cmpl $BREAK, %cs:_count 98 | jb 0f 99 | print "Break on: " 100 | push $BREAK 101 | call printword 102 | call line 103 | popf 104 | call debug 105 | halt 106 | 0: popf 107 | leave 108 | ret $0 109 | 110 | # debug: prints cpu state 111 | .globl debug 112 | debug: 113 | enter $0, $0 114 | pushfl 115 | pushal 116 | print "count:" 117 | pushl %cs:_count 118 | call printlong 119 | print " cs:" 120 | pushw %cs 121 | call printword 122 | print " ip:" 123 | pushw 2(%bp) 124 | call printword 125 | print " ss:" 126 | pushw %ss 127 | call printword 128 | print " ebp:" 129 | mov %ebp, %eax 130 | mov 0(%bp), %ax 131 | pushl %eax 132 | call printlong 133 | print " esp:" 134 | mov %esp, %eax 135 | mov %bp, %ax 136 | add $4, %ax 137 | pushl %eax 138 | call printlong 139 | call line 140 | 141 | print "eax:" 142 | pushl -8(%bp) 143 | call printlong 144 | print " ebx:" 145 | pushl -20(%bp) 146 | call printlong 147 | print " ecx:" 148 | pushl -12(%bp) 149 | call printlong 150 | print " edx:" 151 | pushl -16(%bp) 152 | call printlong 153 | call line 154 | 155 | print "ds:" 156 | pushw %ds 157 | call printword 158 | print " esi:" 159 | pushl -32(%bp) 160 | call printlong 161 | print " es:" 162 | pushw %es 163 | call printword 164 | print " edi:" 165 | pushl -36(%bp) 166 | call printlong 167 | print " fs:" 168 | pushw %fs 169 | call printword 170 | print " gs:" 171 | pushw %gs 172 | call printword 173 | call line 174 | 175 | mov -4(%bp), %eax 176 | print "ID VIP VIF AC VM RF NT IOPL OF DF IF TF SF ZF AF PF CF EFLAGS\n" 177 | print " " 178 | bt $21, %eax 179 | call printbit 180 | print " " 181 | bt $20, %eax 182 | call printbit 183 | print " " 184 | bt $19, %eax 185 | call printbit 186 | print " " 187 | bt $18, %eax 188 | call printbit 189 | print " " 190 | bt $17, %eax 191 | call printbit 192 | print " " 193 | bt $16, %eax 194 | call printbit 195 | print " " 196 | bt $14, %eax 197 | call printbit 198 | print " " 199 | bt $13, %eax 200 | call printbit 201 | bt $12, %eax 202 | call printbit 203 | print " " 204 | bt $11, %eax 205 | call printbit 206 | print " " 207 | bt $10, %eax 208 | call printbit 209 | print " " 210 | bt $9, %eax 211 | call printbit 212 | print " " 213 | bt $8, %eax 214 | call printbit 215 | print " " 216 | bt $7, %eax 217 | call printbit 218 | print " " 219 | bt $6, %eax 220 | call printbit 221 | print " " 222 | bt $4, %eax 223 | call printbit 224 | print " " 225 | bt $2, %eax 226 | call printbit 227 | print " " 228 | bt $0, %eax 229 | call printbit 230 | print " " 231 | push %eax 232 | call printlong 233 | call line 234 | 235 | popal 236 | popfl 237 | leave 238 | ret $0 239 | 240 | # ndebug: sends cpu state to netword 241 | .globl ndebug 242 | ndebug: 243 | enter $0, $0 244 | pushfl 245 | pushal 246 | 247 | pushl %cs:_count 248 | popl %cs:_debug_count 249 | mov %cs, %cs:_debug_cs 250 | pushw 2(%bp) 251 | popw %cs:_debug_ip 252 | mov %ss, %cs:_debug_ss 253 | mov %ebp, %eax 254 | mov 0(%bp), %ax 255 | mov %eax, %cs:_debug_ebp 256 | mov %esp, %eax 257 | mov %bp, %ax 258 | add $4, %ax 259 | mov %eax, %cs:_debug_esp 260 | pushl -8(%bp) 261 | popl %cs:_debug_eax 262 | pushl -20(%bp) 263 | popl %cs:_debug_ebx 264 | pushl -12(%bp) 265 | popl %cs:_debug_ecx 266 | pushl -16(%bp) 267 | popl %cs:_debug_edx 268 | mov %ds, %cs:_debug_ds 269 | pushl -32(%bp) 270 | popl %cs:_debug_esi 271 | mov %es, %cs:_debug_es 272 | pushl -36(%bp) 273 | popl %cs:_debug_edi 274 | mov %fs, %cs:_debug_fs 275 | mov %gs, %cs:_debug_gs 276 | pushl -4(%bp) 277 | popl %cs:_debug_eflags 278 | 279 | push $0x0008 280 | push $_debug_undi_transmit_packet 281 | call api 282 | 283 | popal 284 | popfl 285 | leave 286 | ret $0 287 | 288 | # step: turns on step debugging 289 | .globl step 290 | step: 291 | enter $0, $0 292 | push %eax 293 | push %es 294 | 295 | xor %ax, %ax 296 | mov %ax, %es 297 | mov %cs, %ax # get segment 298 | shl $16, %eax # offset by 16 299 | mov $_step, %ax # get offset of step function 300 | mov %eax, %es:(4 * 0x1) # save new int1 (step) vector 301 | pushf # push eflags 302 | pop %ax # get flags in ax 303 | or $0x0100, %ax # set the Trap Flag bit 304 | push %ax # push the new eflags back 305 | popf # pop new eflags 306 | 307 | pop %es 308 | pop %eax 309 | leave 310 | ret $0 311 | 312 | _step: enter $0, $0 313 | // push %eax 314 | // push %ebx 315 | // push %ecx 316 | // push %si 317 | // push %ds 318 | push %es 319 | 320 | // lds 2(%bp), %si 321 | // cld 322 | // lodsb 323 | // cmp $0x66, %al 324 | // jne 0f 325 | // lodsb 326 | //0: cmp $0x9d, %al # next is popf or popfl 327 | // jne 0f 328 | // orw $0x0100, 8(%bp) # keep TR on (popped flags) 329 | pushf 330 | 0: orw $0x0100, 6(%bp) # keep TR on (own flags) 331 | popf 332 | // mov 2(%bp), %eax 333 | 334 | pushw $0xb800 335 | pop %es 336 | // xor %ebx, %ebx 337 | //1: mov %eax, %ecx 338 | // shr $28, %ecx 339 | // add $'0', %cl 340 | // cmp $'9', %cl 341 | // jbe 0f 342 | // add $('a' - '9' - 1), %cl 343 | //0: mov $0x07, %ch 344 | // mov %cx, %es:142(,%ebx,2) 345 | // inc %ebx 346 | // cmp $4, %ebx 347 | // jne 0f 348 | // movw $0x073a, %es:142(,%ebx,2) 349 | // inc %ebx 350 | //0: shl $4, %eax 351 | // cmp $9, %ebx 352 | // jne 1b 353 | 354 | pop %es 355 | // pop %ds 356 | // pop %si 357 | // pop %ecx 358 | // pop %ebx 359 | // pop %eax 360 | leave 361 | iret 362 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/global.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | #include "aoe.h" 22 | 23 | .globl _drive, _cylinders, _heads, _sectors, _size 24 | .globl _irq, _clientmac, _servermac, _major, _minor 25 | 26 | _drive: .word 0 27 | _cylinders: .long 0 28 | _heads: .word 0 29 | _sectors: .word 0 30 | _size: .long 0 31 | 32 | _irq: .word 0 33 | _clientmac: .org .+6, 0 34 | _servermac: .org .+6, 0 35 | _major: .word 0 36 | _minor: .word 0 37 | -------------------------------------------------------------------------------- /src/nbp/pxe.asm/lib.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | #include "aoe.h" 22 | 23 | # getticks: get ticks since midnight 24 | # returns: 25 | # ticks in eax 26 | .globl getticks 27 | getticks: 28 | enter $0, $0 29 | pushf 30 | push %cx 31 | push %dx 32 | xor %ah, %ah 33 | int $0x1a 34 | mov %cx, %ax 35 | shl $16, %eax 36 | mov %dx, %ax 37 | pop %dx 38 | pop %cx 39 | popf 40 | leave 41 | ret $0 42 | 43 | # getkey: gets a key with timeout 44 | # (word)bp+4: timeout in ticks 45 | # returns: 46 | # al: ascii value of key, 0 for timeout, change 13 (\r) to 10 (\n) 47 | .globl getkey 48 | getkey: 49 | enter $0, $0 50 | pushf 51 | push %ebx 52 | push %eax 53 | xor %ebx, %ebx 54 | mov 4(%bp), %bx 55 | call getticks 56 | add %eax, %ebx 57 | 0: mov $1, %ah 58 | int $0x16 59 | jnz 0f 60 | call getticks 61 | cmp %ebx, %eax 62 | jb 0b 63 | mov $0, %al 64 | jmp 1f 65 | 0: mov $0, %ah 66 | int $0x16 67 | cmp $'\r', %al 68 | jne 1f 69 | mov $'\n', %al 70 | 1: mov %al, %bl 71 | pop %eax 72 | mov %bl, %al 73 | pop %ebx 74 | popf 75 | leave 76 | ret $2 77 | 78 | # printchar: prints a char 79 | # (word)bp+4: char 80 | .globl printchar 81 | printchar: 82 | enter $0, $0 83 | pushf 84 | pushw %ax 85 | pushw %bx 86 | pushw %dx 87 | movb 4(%bp), %al 88 | cmpb $'\n', %al 89 | jne 0f 90 | pushw $'\r' 91 | call printchar 92 | 0: movb $0x0e, %ah 93 | movb 4(%bp), %al 94 | xorw %bx, %bx 95 | int $0x10 96 | #ifdef SERIAL 97 | pushfl 98 | pushal 99 | // movw $0x00e3, %ax 100 | // movw $0x0000, %dx 101 | // int $0x14 102 | // movb $0x01, %ah 103 | // movb 4(%bp), %al 104 | // movw $0x0000, %dx 105 | // int $0x14 106 | popal 107 | popfl 108 | #endif 109 | pop %dx 110 | pop %bx 111 | pop %ax 112 | popf 113 | leave 114 | ret $2 115 | 116 | .globl line, space, point, d0, d1, d2, d3, d4, d5, d6, d7, d8, d9 117 | # quick chars 118 | line: push $'\n' 119 | jmp 0f 120 | space: push $' ' 121 | jmp 0f 122 | point: push $'.' 123 | jmp 0f 124 | d0: pushw $'0' 125 | jmp 0f 126 | d1: pushw $'1' 127 | jmp 0f 128 | d2: pushw $'2' 129 | jmp 0f 130 | d3: pushw $'3' 131 | jmp 0f 132 | d4: pushw $'4' 133 | jmp 0f 134 | d5: pushw $'5' 135 | jmp 0f 136 | d6: pushw $'6' 137 | jmp 0f 138 | d7: pushw $'7' 139 | jmp 0f 140 | d8: pushw $'8' 141 | jmp 0f 142 | d9: pushw $'9' 143 | 0: call printchar 144 | ret 145 | 146 | # printnumber: prints a decimal number 147 | # (word)bp+4: number 148 | .globl printnumber 149 | printnumber: 150 | enter $0, $0 151 | pushf 152 | push %ax 153 | push %bx 154 | push %cx 155 | push %dx 156 | mov 4(%bp), %ax 157 | xor %cx, %cx 158 | mov $10, %bx 159 | 0: xor %dx, %dx 160 | div %bx 161 | add $0x30, %dx 162 | push %dx 163 | inc %cx 164 | cmp $0, %ax 165 | jne 0b 166 | 0: call printchar 167 | dec %cx 168 | jnz 0b 169 | pop %dx 170 | pop %cx 171 | pop %bx 172 | pop %ax 173 | popf 174 | leave 175 | ret $2 176 | 177 | # printlongnumber: prints a long decimal number 178 | # (long)bp+4: number 179 | .globl printlongnumber 180 | printlongnumber: 181 | enter $0, $0 182 | pushf 183 | push %eax 184 | push %ebx 185 | push %cx 186 | push %edx 187 | mov 4(%bp), %eax 188 | xor %cx, %cx 189 | mov $10, %ebx 190 | 0: xor %edx, %edx 191 | div %ebx 192 | add $0x30, %dx 193 | push %dx 194 | inc %cx 195 | cmp $0, %eax 196 | jne 0b 197 | 0: call printchar 198 | dec %cx 199 | jnz 0b 200 | pop %edx 201 | pop %cx 202 | pop %ebx 203 | pop %eax 204 | popf 205 | leave 206 | ret $4 207 | 208 | # printbyte: prints a byte 209 | # (word)bp+4: byte 210 | .globl printbyte 211 | printbyte: 212 | enter $0, $0 213 | pushf 214 | push %ax 215 | mov 4(%bp), %ax 216 | shr $4, %al 217 | add $0x30, %al 218 | cmp $0x3a, %al 219 | jl 0f 220 | add $39, %al 221 | 0: push %ax 222 | call printchar 223 | mov 4(%bp), %ax 224 | and $0x0f, %al 225 | add $0x30, %al 226 | cmp $0x3a, %al 227 | jl 1f 228 | add $39, %al 229 | 1: push %ax 230 | call printchar 231 | pop %ax 232 | popf 233 | leave 234 | ret $2 235 | 236 | # printword: prints a word 237 | # (word)bp+4: word 238 | .globl printword 239 | printword: 240 | enter $0, $0 241 | pushf 242 | push %ax 243 | mov 4(%bp), %ax 244 | shr $8, %ax 245 | push %ax 246 | call printbyte 247 | push 4(%bp) 248 | call printbyte 249 | pop %ax 250 | popf 251 | leave 252 | ret $2 253 | 254 | # printlong: prints a long 255 | # (long)bp+4: long 256 | .globl printlong 257 | printlong: 258 | enter $0, $0 259 | pushf 260 | push %eax 261 | mov 4(%bp), %eax 262 | shr $16, %eax 263 | push %ax 264 | call printword 265 | push 4(%bp) 266 | call printword 267 | pop %eax 268 | popf 269 | leave 270 | ret $4 271 | 272 | 273 | # printbit: prints "1" if cf flag is set, else print "0" 274 | .globl printbit 275 | printbit: 276 | enter $0, $0 277 | pushf 278 | jc 0f 279 | pushw $'0' 280 | call printchar 281 | jmp 1f 282 | 0: pushw $'1' 283 | call printchar 284 | 1: popf 285 | leave 286 | ret $0 287 | 288 | # printbits: prints a word in bits 289 | # (word)bp+4: word 290 | .globl printbits 291 | printbits: 292 | enter $0, $0 293 | pushf 294 | push %ax 295 | push %cx 296 | mov 4(%bp), %ax 297 | mov $16, %cx 298 | 0: shl $1, %ax 299 | call printbit 300 | loop 0b 301 | pop %cx 302 | pop %ax 303 | popf 304 | leave 305 | ret $2 306 | 307 | # printline: prints a '\0' terminated string, located right behind the call 308 | # return to the instruction behind the '\0' 309 | .globl printline 310 | printline: 311 | enter $0, $0 312 | pushf 313 | push %ax 314 | push %ds 315 | push %si 316 | push %cs 317 | pop %ds 318 | 0: mov 2(%bp), %si # get character address 319 | lodsb # load char string 320 | mov %si, 2(%bp) # store back new return value 321 | cmp $0, %al # until we reach a '\0' 322 | jz 0f 323 | push %ax 324 | call printchar 325 | jmp 0b 326 | 0: pop %si 327 | pop %ds 328 | pop %ax 329 | popf 330 | leave 331 | ret $0 332 | 333 | # printbuffer: prints a buffer 334 | # (long)bp+6: buffer 335 | # (word)bp+4: length 336 | .globl printbuffer 337 | printbuffer: 338 | enter $0, $0 339 | pushf 340 | push %ax 341 | push %bx 342 | push %cx 343 | push %ds 344 | push %si 345 | 346 | cld 347 | lds 6(%bp), %si 348 | xor %bx, %bx 349 | 2: cmpw $0, 4(%bp) 350 | je 2f 351 | push %ds 352 | call printword 353 | push $':' 354 | call printchar 355 | push %si 356 | call printword 357 | call space 358 | 359 | mov 4(%bp), %cx 360 | cmp $0x10, %cx 361 | jb 0f 362 | mov $0x10, %cx 363 | 364 | 0: sub %cx, 4(%bp) 365 | push %cx 366 | 0: call space 367 | lodsb 368 | push %ax 369 | call printbyte 370 | loop 0b 371 | pop %ax 372 | 373 | push %ax 374 | mov $0x11, %cx 375 | sub %ax, %cx 376 | 0: print " " 377 | loop 0b 378 | pop %cx 379 | 380 | sub %cx, %si 381 | 1: lodsb 382 | cmp $0x20, %al 383 | ja 0f 384 | mov $'.', %al 385 | 0: push %ax 386 | call printchar 387 | loop 1b 388 | call line 389 | inc %bx 390 | cmp $20, %bx 391 | jb 0f 392 | print "Press a key\n" 393 | 1: push $0 394 | call getkey 395 | cmp $0, %al 396 | je 1b 397 | xor %bx, %bx 398 | 0: jmp 2b 399 | 400 | 2: pop %si 401 | pop %ds 402 | pop %cx 403 | pop %bx 404 | pop %ax 405 | popf 406 | leave 407 | ret $6 408 | 409 | .globl haltcpu 410 | haltcpu: 411 | sti # hlt to idle the cpu, which 412 | hlt # saves power on laptops and 413 | jmp haltcpu # is nice to cpu usage in vmware 414 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS := -O0 2 | CFLAGS += -nostdlib -fleading-underscore 3 | #CFLAGS += -DMINIMAL 4 | CFLAGS += -DSERIAL 5 | LDFLAGS := -nostdlib -static -T aoe.ld -s 6 | 7 | all: aoe.0 8 | 9 | clean: 10 | rm -rf obj sizes.txt 11 | 12 | obj/asm.o: asm.S Makefile 13 | @rm -rf obj/asm.o aoe.0 14 | @mkdir -p obj 15 | gcc $(CFLAGS) -Wall -c -o obj/asm.o asm.S 16 | 17 | obj/debug.o: debug.S Makefile 18 | @rm -rf obj/debug.o aoe.0 19 | @mkdir -p obj 20 | gcc $(CFLAGS) -Wall -c -o obj/debug.o debug.S 21 | 22 | obj/main.s: main.c main.h asm.h pxe.h lib.h Makefile 23 | @rm -rf obj/main.s obj/main.o aoe.0 24 | @mkdir -p obj 25 | gcc $(CFLAGS) -Wall -S -o obj/main.s main.c 26 | 27 | obj/main.o: obj/main.s Makefile 28 | @rm -rf obj/main.o aoe.0 29 | @mkdir -p obj 30 | gcc $(CFLAGS) -Wall -c -o obj/main.o obj/main.s 31 | 32 | obj/pxe.s: pxe.c pxe.h asm.h Makefile 33 | @rm -rf obj/pxe.s obj/pxe.o aoe.0 34 | @mkdir -p obj 35 | gcc $(CFLAGS) -Wall -S -o obj/pxe.s pxe.c 36 | 37 | obj/pxe.o: obj/pxe.s Makefile 38 | @rm -rf obj/pxe.o aoe.0 39 | @mkdir -p obj 40 | gcc $(CFLAGS) -Wall -c -o obj/pxe.o obj/pxe.s 41 | 42 | obj/libasm.o: libasm.S Makefile 43 | @rm -rf obj/libasm.o aoe.0 44 | @mkdir -p obj 45 | gcc $(CFLAGS) -Wall -c -o obj/libasm.o libasm.S 46 | 47 | obj/lib.s: lib.c lib.h asm.h printf.c Makefile 48 | @rm -rf obj/lib.s obj/lib.o aoe.0 49 | @mkdir -p obj 50 | gcc $(CFLAGS) -Wall -S -o obj/lib.s lib.c 51 | 52 | obj/lib.o: obj/lib.s Makefile 53 | @rm -rf obj/lib.o aoe.0 54 | @mkdir -p obj 55 | gcc $(CFLAGS) -Wall -c -o obj/lib.o obj/lib.s 56 | 57 | aoe.0: aoe.ld obj/asm.o obj/debug.o obj/main.o obj/pxe.o obj/libasm.o obj/lib.o Makefile 58 | @rm -rf aoe.0 59 | ld $(LDFLAGS) obj/asm.o obj/debug.o obj/main.o obj/pxe.o obj/libasm.o obj/lib.o -o obj/aoe 60 | objcopy -O binary obj/aoe aoe.0 61 | @if [ `expr \`find aoe.0 -printf "%s"\` % 2` == 0 ]; then echo -en "\0" >> aoe.0; fi 62 | @find aoe.0 -printf "%f size: %s\n" 63 | ifneq ($(findstring msys,$(MACHTYPE)), msys) 64 | @echo "readelf -s *.o | sort -nr > sizes.txt" 65 | @readelf -s *.o | egrep "FUNC|OBJECT" | tr -s " " | cut -f 4,9 -d " " | sort -nr > sizes.txt 66 | else 67 | @rm -rf sizes.txt 68 | endif 69 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/aoe.ld: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | SECTIONS { 22 | /DISCARD/ : {*(.comment*)} 23 | /DISCARD/ : {*(.note*)} 24 | . = 0; 25 | .text : {*(*)} 26 | 27 | } 28 | PROVIDE(_end = .); 29 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/asm.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | asm ( ".code16gcc" ); 22 | #ifndef _ASM_H 23 | # define _ASM_H 24 | 25 | # include "lib.h" 26 | 27 | typedef struct s_cpu 28 | { 29 | unsigned short gs; 30 | unsigned short fs; 31 | unsigned short es; 32 | unsigned short ds; 33 | unsigned int edi; 34 | unsigned int esi; 35 | unsigned int edx; 36 | unsigned int ecx; 37 | unsigned int ebx; 38 | unsigned int eax; 39 | union 40 | { 41 | unsigned int eflags; 42 | unsigned short flags; 43 | }; 44 | } __attribute__ ( ( __packed__ ) ) t_cpu; 45 | 46 | extern void *end; // end of image from linker 47 | //extern t_cpu cpu; // cpu state struct in asm.S 48 | extern unsigned short segment; // target segment in asm.S 49 | extern int volatile oldint13; 50 | extern int volatile gotisr; 51 | extern int volatile timer; 52 | extern int irq; 53 | 54 | int GETVECTOR ( 55 | int i 56 | ); 57 | void SETVECTOR ( 58 | int i, 59 | int v 60 | ); 61 | int _CHAININTERRUPT ( 62 | int v, 63 | t_cpu * cpu 64 | ); 65 | 66 | # ifdef __MINGW32__ 67 | # define INTERRUPTPROTO(x) \ 68 | extern void _##x(t_cpu *cpu); extern void x() 69 | # else 70 | # define INTERRUPTPROTO(x) \ 71 | ".type __" #x ", @function\n" \ 72 | ".size __" #x ", .-__" #x "\n" \ 73 | extern void _##x(t_cpu *cpu); extern void x() 74 | # endif 75 | # define INTERRUPT(x) asm("\n" \ 76 | ".text\n" \ 77 | ".globl __" #x "\n" \ 78 | "__" #x ":\n" \ 79 | " call _switchstack\n" \ 80 | " call _pushcpu\n" \ 81 | " cli\n" \ 82 | " movzwl %sp, %eax\n" \ 83 | " pushl %eax\n" \ 84 | " movw %cs:_segment, %ds\n" \ 85 | " movw %cs:_segment, %es\n" \ 86 | " call _" #x "\n" \ 87 | " addw $4, %sp\n" \ 88 | " call _popcpu\n" \ 89 | " call _restorestack\n" \ 90 | ".code16\n" \ 91 | " lret $2\n" \ 92 | ".code16gcc\n" \ 93 | "0: lret $2\n" \ 94 | ); \ 95 | void x (t_cpu *cpu) 96 | 97 | void int8 ( 98 | void 99 | ); // in asm.S 100 | void int13 ( 101 | void 102 | ); // in asm.S 103 | void isr ( 104 | void 105 | ); // in asm.S 106 | void nmi ( 107 | void 108 | ); // in asm.S 109 | void i0 ( 110 | void 111 | ); // in asm.S 112 | void i1 ( 113 | void 114 | ); // in asm.S 115 | void i2 ( 116 | void 117 | ); // in asm.S 118 | void i3 ( 119 | void 120 | ); // in asm.S 121 | void i4 ( 122 | void 123 | ); // in asm.S 124 | void i5 ( 125 | void 126 | ); // in asm.S 127 | void i6 ( 128 | void 129 | ); // in asm.S 130 | void i7 ( 131 | void 132 | ); // in asm.S 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/debug.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | .code16gcc 22 | #ifndef MINIMAL 23 | .text 24 | .globl _debug 25 | _debug: 26 | pushl %ebp 27 | mov %esp, %ebp 28 | pushfl 29 | pushl %eax 30 | 31 | movl $0x63733a00, %eax # "cs:" 32 | call _char4 33 | movw %cs, %ax 34 | call _hex4 35 | 36 | call _space 37 | movl $0x69703a00, %eax # "ip:" 38 | call _char4 39 | movw 4(%bp), %ax 40 | subw $6, %ax 41 | call _hex4 42 | 43 | call _space 44 | movl $0x64733a00, %eax # "ds:" 45 | call _char4 46 | movw %ds, %ax 47 | call _hex4 48 | 49 | call _space 50 | movl $0x6561783a, %eax # "eax:" 51 | call _char4 52 | movl -8(%bp), %eax 53 | call _hex8 54 | 55 | call _space 56 | movl $0x6562783a, %eax # "ebx:" 57 | call _char4 58 | movl %ebx, %eax 59 | call _hex8 60 | 61 | call _space 62 | movl $0x6563783a, %eax # "ecx:" 63 | call _char4 64 | movl %ecx, %eax 65 | call _hex8 66 | 67 | call _space 68 | movl $0x6564783a, %eax # "edx:" 69 | call _char4 70 | movl %edx, %eax 71 | call _hex8 72 | 73 | call _line 74 | movl $0x73733a00, %eax # "ss:" 75 | call _char4 76 | movw %ss, %ax 77 | call _hex4 78 | 79 | call _space 80 | movl $0x6562703a, %eax # "ebp:" 81 | call _char4 82 | movl (%bp), %eax 83 | call _hex8 84 | 85 | call _space 86 | movl $0x6573703a, %eax # "esp:" 87 | call _char4 88 | movl %ebp, %eax 89 | addl $8, %eax 90 | call _hex8 91 | 92 | call _space 93 | movl $0x6573693a, %eax # "esi:" 94 | call _char4 95 | movl %esi, %eax 96 | call _hex8 97 | 98 | call _space 99 | movl $0x65733a00, %eax # "es:" 100 | call _char4 101 | movw %es, %ax 102 | call _hex4 103 | 104 | call _space 105 | movl $0x6564693a, %eax # "edi:" 106 | call _char4 107 | movl %edi, %eax 108 | call _hex8 109 | 110 | call _line 111 | movl $0x49442056, %eax # "ID V" 112 | call _char4 113 | movl $0x49502056, %eax # "IP V" 114 | call _char4 115 | movl $0x49462041, %eax # "IF A" 116 | call _char4 117 | movl $0x4320564d, %eax # "C VM" 118 | call _char4 119 | movl $0x20524620, %eax # " RF " 120 | call _char4 121 | movl $0x4e542049, %eax # "NT I" 122 | call _char4 123 | movl $0x4f504c20, %eax # "OPL " 124 | call _char4 125 | movl $0x4f462044, %eax # "OF D" 126 | call _char4 127 | movl $0x46204946, %eax # "F IF" 128 | call _char4 129 | movl $0x20544620, %eax # " TF " 130 | call _char4 131 | movl $0x5346205a, %eax # "SF Z" 132 | call _char4 133 | movl $0x46204146, %eax # "F AF" 134 | call _char4 135 | movl $0x20504620, %eax # " PF " 136 | call _char4 137 | movl $0x43460000, %eax # "CF" 138 | call _char4 139 | 140 | call _space 141 | call _space 142 | call _space 143 | movl $0x66733a00, %eax # "fs:" 144 | call _char4 145 | movw %fs, %ax 146 | call _hex4 147 | 148 | call _space 149 | movl $0x67733a00, %eax # "gs:" 150 | call _char4 151 | movw %gs, %ax 152 | call _hex4 153 | 154 | call _line 155 | movl -4(%bp), %eax 156 | call _space 157 | btl $21, %eax # ID 158 | call _bit 159 | 160 | call _space 161 | call _space 162 | call _space 163 | btl $20, %eax # VIP 164 | call _bit 165 | 166 | call _space 167 | call _space 168 | call _space 169 | btl $19, %eax # VIF 170 | call _bit 171 | 172 | call _space 173 | call _space 174 | btl $18, %eax # AC 175 | call _bit 176 | 177 | call _space 178 | call _space 179 | btl $17, %eax # VM 180 | call _bit 181 | 182 | call _space 183 | call _space 184 | btl $16, %eax # RF 185 | call _bit 186 | 187 | call _space 188 | call _space 189 | btl $14, %eax # NT 190 | call _bit 191 | 192 | call _space 193 | call _space 194 | call _space 195 | btl $13, %eax # IOPL 196 | call _bit 197 | btl $12, %eax # IOPL 198 | call _bit 199 | 200 | call _space 201 | call _space 202 | btl $11, %eax # DF 203 | call _bit 204 | 205 | call _space 206 | call _space 207 | btl $10, %eax # OF 208 | call _bit 209 | 210 | call _space 211 | call _space 212 | btl $9, %eax # IF 213 | call _bit 214 | 215 | call _space 216 | call _space 217 | btl $8, %eax # TF 218 | call _bit 219 | 220 | call _space 221 | call _space 222 | btl $7, %eax # SF 223 | call _bit 224 | 225 | call _space 226 | call _space 227 | btl $6, %eax # ZF 228 | call _bit 229 | 230 | call _space 231 | call _space 232 | btl $4, %eax # AF 233 | call _bit 234 | 235 | call _space 236 | call _space 237 | btl $2, %eax # PF 238 | call _bit 239 | 240 | call _space 241 | call _space 242 | btl $0, %eax # CF 243 | call _bit 244 | 245 | call _space 246 | call _space 247 | call _space 248 | movl $0x45464c41, %eax # "EFLA" 249 | call _char4 250 | movl $0x47533a00, %eax # "GS:" 251 | call _char4 252 | movl -4(%bp), %eax 253 | call _hex8 254 | call _line 255 | 256 | subw $6, %sp 257 | movl $0x67647472, %eax # "gdtr" 258 | call _char4 259 | movb $':', %al 260 | call _char 261 | sgdt -14(%bp) 262 | movw -14(%bp), %ax 263 | call _hex4 264 | movb $':', %al 265 | call _char 266 | movl -12(%bp), %eax 267 | call _hex8 268 | 269 | call _space 270 | movl $0x69647472, %eax # "idtr" 271 | call _char4 272 | movb $':', %al 273 | call _char 274 | sidt -14(%bp) 275 | movw -14(%bp), %ax 276 | call _hex4 277 | movb $':', %al 278 | call _char 279 | movl -12(%bp), %eax 280 | call _hex8 281 | call _line 282 | addw $6, %sp 283 | 284 | popl %eax 285 | popfl 286 | popl %ebp 287 | ret 288 | 289 | _hex8: pushfl 290 | rorl $16, %eax 291 | call _hex4 292 | rorl $16, %eax 293 | call _hex4 294 | popfl 295 | ret 296 | 297 | _hex4: pushfl 298 | rorw $8, %ax 299 | call _hex2 300 | rorw $8, %ax 301 | call _hex2 302 | popfl 303 | ret 304 | 305 | _hex2: pushfl 306 | rorb $4, %al 307 | call _hex 308 | rorb $4, %al 309 | call _hex 310 | popfl 311 | ret 312 | 313 | _hex: pushfl 314 | pushw %ax 315 | andb $0xf, %al 316 | addb $'0', %al 317 | cmpb $'9', %al 318 | jbe 0f 319 | addb $('a' - '9' - 1), %al 320 | 0: call _char 321 | popw %ax 322 | popfl 323 | ret 324 | 325 | _bit: pushfl 326 | pushw %ax 327 | movb $'0', %al 328 | jnc 0f 329 | incb %al 330 | 0: call _char 331 | popw %ax 332 | popfl 333 | ret 334 | 335 | _char4: pushfl 336 | pushl %eax 337 | roll $8, %eax 338 | call _char 339 | roll $8, %eax 340 | testb %al, %al 341 | jz 0f 342 | call _char 343 | roll $8, %eax 344 | testb %al, %al 345 | jz 0f 346 | call _char 347 | roll $8, %eax 348 | testb %al, %al 349 | jz 0f 350 | call _char 351 | 0: popl %eax 352 | popfl 353 | ret 354 | 355 | _space: pushfl 356 | pushw %ax 357 | movb $' ', %al 358 | call _char 359 | popw %ax 360 | popfl 361 | ret 362 | 363 | _line: pushfl 364 | pushw %ax 365 | movb $'\n', %al 366 | call _char 367 | popw %ax 368 | popfl 369 | ret 370 | 371 | _char: pushfl 372 | pushal 373 | pushw %ds 374 | pushw %es 375 | pushw %fs 376 | pushw %gs 377 | pushl %eax 378 | call _putchar 379 | addl $4, %esp 380 | popw %gs 381 | popw %fs 382 | popw %es 383 | popw %ds 384 | popal 385 | popfl 386 | ret 387 | #ifndef __MINGW32__ 388 | .type _debug, @function 389 | .size _debug, .-_debug 390 | #endif 391 | #endif 392 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/lib.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | strtol function copyright by Paul Edwards. 6 | printf.c copyright by Chris Giese. 7 | Don't bother them with questions on WinAoE, but see http://www.winaoe.org/ 8 | 9 | This file is part of WinAoE. 10 | 11 | WinAoE is free software: you can redistribute it and/or modify 12 | it under the terms of the GNU General Public License as published by 13 | the Free Software Foundation, either version 3 of the License, or 14 | (at your option) any later version. 15 | 16 | WinAoE is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with WinAoE. If not, see . 23 | */ 24 | 25 | asm ( ".code16gcc" ); 26 | #include "lib.h" 27 | #include "asm.h" 28 | 29 | size_t 30 | strlen ( 31 | const char *s 32 | ) 33 | { 34 | int l = 0; 35 | while ( s[l] ) 36 | l++; 37 | return l; 38 | } 39 | 40 | int 41 | puts ( 42 | const char *s 43 | ) 44 | { 45 | while ( *s ) 46 | putchar ( *s++ ); 47 | putchar ( '\n' ); 48 | return -1; 49 | } 50 | 51 | int 52 | isspace ( 53 | int c 54 | ) 55 | { 56 | switch ( c ) 57 | { 58 | case ' ': 59 | case '\f': 60 | case '\n': 61 | case '\r': 62 | case '\t': 63 | case '\v': 64 | return 1; 65 | } 66 | return 0; 67 | } 68 | 69 | int 70 | isdigit ( 71 | int c 72 | ) 73 | { 74 | if ( ( c >= '0' ) && ( c <= '9' ) ) 75 | return 1; 76 | return 0; 77 | } 78 | 79 | int 80 | isalpha ( 81 | int c 82 | ) 83 | { 84 | return ( isupper ( c ) || islower ( c ) ); 85 | } 86 | 87 | int 88 | isupper ( 89 | int c 90 | ) 91 | { 92 | if ( ( c >= 'A' ) && ( c <= 'Z' ) ) 93 | return 1; 94 | return 0; 95 | } 96 | 97 | int 98 | islower ( 99 | int c 100 | ) 101 | { 102 | if ( ( c >= 'a' ) && ( c <= 'z' ) ) 103 | return 1; 104 | return 0; 105 | } 106 | 107 | int 108 | toupper ( 109 | int c 110 | ) 111 | { 112 | if ( islower ( c ) ) 113 | return ( ( c & ~0x20 ) & 0xff ); 114 | return c; 115 | } 116 | 117 | int 118 | tolower ( 119 | int c 120 | ) 121 | { 122 | if ( isupper ( c ) ) 123 | return ( c | 0x20 ); 124 | return c; 125 | } 126 | 127 | int 128 | memcmp ( 129 | const void *s1, 130 | const void *s2, 131 | size_t n 132 | ) 133 | { 134 | int i; 135 | if ( s1 == s2 ) 136 | return 0; 137 | for ( i = 0; i < n; i++ ) 138 | { 139 | if ( ( ( unsigned char * )s1 )[i] < ( ( unsigned char * )s2 )[i] ) 140 | return -1; 141 | if ( ( ( unsigned char * )s1 )[i] > ( ( unsigned char * )s2 )[i] ) 142 | return 1; 143 | } 144 | return 0; 145 | } 146 | 147 | void * 148 | memcpy ( 149 | void *dest, 150 | const void *src, 151 | size_t n 152 | ) 153 | { 154 | int i; 155 | if ( src == dest ) 156 | return dest; 157 | if ( src < dest ) 158 | { 159 | for ( i = n - 1; i >= 0; i-- ) 160 | ( ( unsigned char * )dest )[i] = ( ( unsigned char * )src )[i]; 161 | } 162 | else 163 | { 164 | for ( i = 0; i < n; i++ ) 165 | ( ( unsigned char * )dest )[i] = ( ( unsigned char * )src )[i]; 166 | } 167 | return dest; 168 | } 169 | 170 | void * 171 | memset ( 172 | void *s, 173 | int c, 174 | size_t n 175 | ) 176 | { 177 | int i; 178 | for ( i = 0; i < n; i++ ) 179 | ( ( unsigned char * )s )[i] = c; 180 | return s; 181 | } 182 | 183 | // From Public Domain CLib (PDPCLIB) by Paul Edwards 184 | long int 185 | strtol ( 186 | const char *nptr, 187 | char **endptr, 188 | int base 189 | ) 190 | { 191 | long x = 0; 192 | int undecided = 0; 193 | 194 | if ( base == 0 ) 195 | undecided = 1; 196 | while ( 1 ) 197 | { 198 | if ( isdigit ( *nptr ) ) 199 | { 200 | if ( base == 0 ) 201 | { 202 | if ( *nptr == '0' ) 203 | base = 8; 204 | else 205 | { 206 | base = 10; 207 | undecided = 0; 208 | } 209 | } 210 | x = x * base + ( *nptr - '0' ); 211 | nptr++; 212 | } 213 | else if ( isalpha ( *nptr ) ) 214 | { 215 | if ( ( *nptr == 'X' ) || ( *nptr == 'x' ) ) 216 | { 217 | if ( ( base == 0 ) || ( ( base == 8 ) && undecided ) ) 218 | { 219 | base = 16; 220 | undecided = 0; 221 | } 222 | else 223 | break; 224 | } 225 | else 226 | { 227 | x = x * base + ( toupper ( ( unsigned char )*nptr ) - 'A' ) + 10; 228 | nptr++; 229 | } 230 | } 231 | else 232 | break; 233 | } 234 | if ( endptr != NULL ) 235 | *endptr = ( char * )nptr; 236 | return ( x ); 237 | } 238 | 239 | // Include Public Domain printf.c 240 | #include "printf.c" 241 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/lib.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | asm ( ".code16gcc" ); 22 | #ifndef _LIB_H 23 | # define _LIB_H 24 | 25 | # include 26 | 27 | typedef unsigned long size_t; 28 | # define NULL 0 29 | 30 | # define htons(x) (unsigned short)((((x) << 8) & 0xff00) | (((x) >> 8) & 0xff)) 31 | # define ntohs(x) (unsigned short)((((x) << 8) & 0xff00) | (((x) >> 8) & 0xff)) 32 | # define sti() asm volatile ("sti") 33 | # define cli() asm volatile ("cli") 34 | 35 | // in libasm.S 36 | int putchar ( 37 | int c 38 | ); 39 | unsigned char volatile inb ( 40 | int p 41 | ); 42 | void volatile outb ( 43 | unsigned char v, 44 | int p 45 | ); 46 | char getkey ( 47 | int t 48 | ); 49 | void halt ( 50 | void 51 | ); 52 | int volatile segmemcpy ( 53 | int dest, 54 | int src, 55 | size_t n 56 | ); 57 | # ifndef MINIMAL 58 | int segmemset ( 59 | int s, 60 | int c, 61 | size_t n 62 | ); 63 | # define debug() asm volatile ("call _debug":::"memory") 64 | # else 65 | # define debug() 66 | # endif 67 | 68 | // in lib.c 69 | size_t strlen ( 70 | const char *s 71 | ); 72 | int puts ( 73 | const char *s 74 | ); 75 | int isspace ( 76 | int c 77 | ); 78 | int isdigit ( 79 | int c 80 | ); 81 | int isalpha ( 82 | int c 83 | ); 84 | int isupper ( 85 | int c 86 | ); 87 | int islower ( 88 | int c 89 | ); 90 | int toupper ( 91 | int c 92 | ); 93 | int tolower ( 94 | int c 95 | ); 96 | int memcmp ( 97 | const void *s1, 98 | const void *s2, 99 | size_t n 100 | ); 101 | void *memcpy ( 102 | void *dest, 103 | const void *src, 104 | size_t n 105 | ); 106 | void *memset ( 107 | void *s, 108 | int c, 109 | size_t n 110 | ); 111 | 112 | // From Public Domain CLib (PDPCLIB) by Paul Edwards 113 | long int strtol ( 114 | const char *nptr, 115 | char **endptr, 116 | int base 117 | ); 118 | 119 | // From Public Domain printf.c 120 | int vsprintf ( 121 | char *buf, 122 | const char *fmt, 123 | va_list args 124 | ); 125 | int sprintf ( 126 | char *buf, 127 | const char *fmt, 128 | ... 129 | ); 130 | int vprintf ( 131 | const char *fmt, 132 | va_list args 133 | ); 134 | int printf ( 135 | const char *fmt, 136 | ... 137 | ); 138 | 139 | #endif 140 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/libasm.S: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | .code16gcc 22 | 23 | # _putchar: prints a character, returns character printed 24 | .globl _putchar 25 | _putchar: 26 | pushl %ebp # setup ebp and frame pointer 27 | movl %esp, %ebp 28 | pushw %bx # clobbered by int 0x10 29 | 30 | movb 8(%bp), %al # get character 31 | cmpb $'\n', %al # compare character 32 | jne 0f # jump if it was not '\n' 33 | pushl $'\r' # push '\r' to get '\r\n' 34 | call _putchar # print char 35 | addw $4, %sp # clean up stack 36 | 37 | 0: movb $0x0e, %ah # int 0x10, ah 0e: display char 38 | movb 8(%bp), %al # get character 39 | xorw %bx, %bx # clear bx for int 0x10 40 | int $0x10 41 | 42 | #ifdef SERIAL 43 | movw $0x00e3, %ax # int 0x14, ah 00: reset port 44 | movw $0x0000, %dx # com1: 9600,8,n,1 45 | int $0x14 46 | movb $0x01, %ah # int 0x14, ah 01: send byte 47 | movb 8(%bp), %al # get character 48 | movw $0x0000, %dx 49 | int $0x14 50 | #endif 51 | 52 | movzbl 8(%bp), %eax # return character 53 | popw %bx # restore bx 54 | popl %ebp # restore ebp 55 | ret 56 | #ifndef __MINGW32__ 57 | .type _putchar, @function 58 | .size _putchar, .-_putchar 59 | #endif 60 | 61 | # _inb: returns a byte from a port 62 | .globl _inb 63 | _inb: 64 | pushl %ebp # setup ebp and frame pointer 65 | movl %esp, %ebp 66 | movw 8(%bp), %dx # get port 67 | xorl %eax, %eax # clear return value 68 | inb %dx, %al # get data from port 69 | popl %ebp # restore ebp 70 | ret 71 | #ifndef __MINGW32__ 72 | .type _inb, @function 73 | .size _inb, .-_inb 74 | #endif 75 | 76 | # _outb: outputs a byte to a port 77 | .globl _outb 78 | _outb: 79 | pushl %ebp # setup ebp and frame pointer 80 | movl %esp, %ebp 81 | movb 8(%bp), %al # get value 82 | movw 12(%bp), %dx # get port 83 | outb %al, %dx # push data to port 84 | popl %ebp # restore ebp 85 | ret 86 | #ifndef __MINGW32__ 87 | .type _outb, @function 88 | .size _outb, .-_outb 89 | #endif 90 | 91 | # _getkey: returns key from keyboard or 0 if timeout expired 92 | .globl _getkey 93 | _getkey: 94 | pushl %ebp # setup ebp and frame pointer 95 | movl %esp, %ebp 96 | pushfl # save flags for interrupt flag 97 | pushl %ebx # save ebx 98 | sti # enable interrupts for int 0x1a 99 | xorb %ah, %ah # int 0x1a, ah 00: get system time 100 | int $0x1a # returns time in cx:dx 101 | shll $16, %ecx # shift high part left 102 | movw %dx, %cx # add low part 103 | addl 8(%bp), %edx # add timeout value 104 | movl %edx, %ebx # store timeout time in ebx 105 | 0: movb $1, %ah # int 0x16, ah 01: check for key 106 | int $0x16 # ZF is set if there is 107 | jnz 0f # no key available 108 | cmpl $0, 8(%bp) # if timeout is 0, loop 109 | je 0b # till we get a key 110 | xorb %ah, %ah # int 0x1a, ah 00: get system time 111 | int $0x1a # get system time again 112 | shll $16, %ecx # shift high part left 113 | movw %dx, %cx # add low part 114 | cmpl %ebx, %ecx # compare with stored timeout time 115 | jb 0b # loop if not yet reached 116 | xorb %al, %al # return 0 when timeout is reached 117 | jmp 1f 118 | 0: xorb %ah, %ah # int 0x16, ah 00: get key 119 | int $0x16 # get key in al 120 | 1: movzbl %al, %eax # return key in eax 121 | popl %ebx # restore ebx 122 | popfl # restore interrupt flag 123 | popl %ebp # restore ebp 124 | ret 125 | #ifndef __MINGW32__ 126 | .type _getkey, @function 127 | .size _getkey, .-_getkey 128 | #endif 129 | 130 | .globl _halt 131 | _halt: 132 | sti # hlt to idle the cpu, which 133 | hlt # saves power on laptops and 134 | jmp _halt # is nice to cpu usage in vmware 135 | #ifndef __MINGW32__ 136 | .type _halt, @function 137 | .size _halt, .-_halt 138 | #endif 139 | 140 | # _segmemcpy: copy memory from segmented pointers src to dest 141 | .globl _segmemcpy 142 | _segmemcpy: 143 | pushl %ebp # setup ebp and frame pointer 144 | movl %esp, %ebp 145 | pushl %esi # save used registers 146 | pushl %edi 147 | pushw %ds 148 | pushw %es 149 | 150 | lesw 8(%bp), %di # load es:di with dest 151 | xorl %eax, %eax # clear eax 152 | movw %es, %ax # get dest segment in ax 153 | shrl $4, %eax # multiply by 16 154 | andl $0xffff, %edi # clear highpart of edi 155 | addl %edi, %eax # add to get linear address 156 | 157 | ldsw 12(%bp), %si # load ds:si with src 158 | xorl %edx, %edx # clear edx 159 | movw %ds, %dx # get src segment in dx 160 | shrl $4, %edx # multiply by 16 161 | andl $0xffff, %esi # clear highpart of esi 162 | addl %esi, %edx # add to get linear address 163 | 164 | movl 16(%bp), %ecx # get size in ecx 165 | cld # default to forward copy 166 | cmpl %eax, %edx # if dest address is lower then 167 | jg 0f # src address, copy backwards 168 | std # set backward flag 169 | leaw -1(%esi,%ecx), %si # add size-1 to si 170 | leaw -1(%edi,%ecx), %di # add size-1 to di 171 | 0: rep movsb # do the actual copy 172 | movl 8(%bp), %eax # return dest address 173 | popw %es # restore used registers 174 | popw %ds 175 | popl %edi 176 | popl %esi 177 | popl %ebp # restore ebp 178 | ret 179 | #ifndef __MINGW32__ 180 | .type _segmemcpy, @function 181 | .size _segmemcpy, .-_segmemcpy 182 | #endif 183 | 184 | #ifndef MINIMAL 185 | # _segmemset: fill memory pointed to by segmented pointer 186 | .globl _segmemset 187 | _segmemset: 188 | pushl %ebp # setup ebp and frame pointer 189 | movl %esp, %ebp 190 | pushw %si # save used registers 191 | pushw %ds 192 | lesw 8(%bp), %di # load es:di with address 193 | movb 12(%bp), %al # load al with fill byte 194 | movw 16(%bp), %cx # load cx with count 195 | cld # fill forward 196 | rep stosb # do the actual fill 197 | movl 8(%bp), %eax # return memory address 198 | popw %ds # restore used registers 199 | popw %si 200 | popl %ebp # restore ebp 201 | ret 202 | #ifndef __MINGW32__ 203 | .type _segmemset, @function 204 | .size _segmemset, .-_segmemset 205 | #endif 206 | #endif 207 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | asm ( ".code16gcc" ); 22 | #ifndef _C_H 23 | # define _C_H 24 | 25 | # define MAXPACKETSIZE 1518 26 | # define SECTORSIZE 512 27 | # define PROMPTTIMEOUT (3 * 18.206) // in ticks (18.206 ticks / sec) 28 | # define RECEIVETIMEOUT 2 // in ticks 29 | 30 | # define PNP_SIGNATURE 0x506e5024 // PnP$ 31 | # define ROM_SIGNATURE 0xaa55 32 | 33 | # define AOE_PROTOCOL 0x88a2 34 | # define AOE_VERSION 1 35 | 36 | typedef struct s_abft 37 | { 38 | unsigned int signature; // 0x54464261 (aBFT) 39 | unsigned int length; 40 | unsigned char revision; 41 | unsigned char checksum; 42 | unsigned char oemid[6]; 43 | unsigned char oemtableid[8]; 44 | unsigned char reserved1[12]; 45 | unsigned short major; 46 | unsigned char minor; 47 | unsigned char reserved2; 48 | unsigned char clientmac[6]; 49 | unsigned char reserved3[15]; // for alignment on segment 50 | } __attribute__ ( ( __packed__ ) ) t_abft; 51 | 52 | typedef struct s_pnp 53 | { 54 | unsigned int signature; 55 | unsigned char version; 56 | unsigned char length; 57 | unsigned short control; 58 | unsigned char checksum; 59 | unsigned int flags; 60 | struct 61 | { 62 | unsigned short offset; 63 | unsigned short segment; 64 | } __attribute__ ( ( __packed__ ) ) RMentry; 65 | struct 66 | { 67 | unsigned short offset; 68 | unsigned int segment; 69 | } __attribute__ ( ( __packed__ ) ) PMentry; 70 | unsigned int identifier; 71 | unsigned short RMdatasegment; 72 | unsigned int PMdatasegment; 73 | } __attribute__ ( ( __packed__ ) ) t_pnp; 74 | 75 | typedef struct s_aoe 76 | { 77 | unsigned char dst[6]; 78 | unsigned char src[6]; 79 | unsigned short protocol; 80 | 81 | unsigned int flags:4; 82 | unsigned int ver:4; 83 | unsigned char error; 84 | unsigned short major; 85 | unsigned char minor; 86 | unsigned char command; 87 | unsigned int tag; 88 | 89 | unsigned char aflags; 90 | union 91 | { 92 | unsigned char err; 93 | unsigned char feature; 94 | }; 95 | unsigned char count; 96 | union 97 | { 98 | unsigned char cmd; 99 | unsigned char status; 100 | }; 101 | 102 | unsigned char lba0; 103 | unsigned char lba1; 104 | unsigned char lba2; 105 | unsigned char lba3; 106 | unsigned char lba4; 107 | unsigned char lba5; 108 | unsigned short reserved; 109 | 110 | unsigned char data[2 * SECTORSIZE]; 111 | } __attribute__ ( ( __packed__ ) ) t_aoe; 112 | 113 | typedef struct s_mbr 114 | { 115 | unsigned char reserved[446]; 116 | struct 117 | { 118 | unsigned char active; 119 | unsigned char starthead; 120 | unsigned startsector:6; 121 | unsigned startcylinderhigh:2; 122 | unsigned char startcylinderlow; 123 | unsigned char type; 124 | unsigned char endhead; 125 | unsigned endsector:6; 126 | unsigned endcylinderhigh:2; 127 | unsigned char endcylinderlow; 128 | unsigned int startlba; 129 | unsigned int size; 130 | } __attribute__ ( ( __packed__ ) ) partition[4]; 131 | unsigned short magic; 132 | } __attribute__ ( ( __packed__ ) ) t_mbr; 133 | 134 | typedef struct s_INT13_EXTENDED_READWRITE 135 | { 136 | unsigned char structsize; 137 | unsigned char reserved; 138 | unsigned short count; 139 | unsigned short bufferoffset; 140 | unsigned short buffersegment; 141 | unsigned long long lba; 142 | } __attribute__ ( ( __packed__ ) ) t_INT13_EXTENDED_READWRITE; 143 | 144 | typedef struct s_INT13_EXTENDED_GET_PARAMETERS 145 | { 146 | unsigned short structsize; 147 | unsigned short flags; 148 | unsigned int cylinders; 149 | unsigned int heads; 150 | unsigned int sectors; 151 | unsigned long long disksize; 152 | unsigned short sectorsize; 153 | } __attribute__ ( ( __packed__ ) ) t_INT13_EXTENDED_GET_PARAMETERS; 154 | 155 | typedef struct s_INT13_CDROM_EMULATION 156 | { 157 | unsigned char packetsize; 158 | unsigned char bootmediatype; 159 | unsigned char drivenumber; 160 | unsigned char controllernumber; 161 | unsigned int lbasize; 162 | unsigned short drivespecification; 163 | unsigned short cachesegment; 164 | unsigned short loadsegment; 165 | unsigned short sectorstoload; 166 | unsigned char cylinderslow; 167 | unsigned char sectors_cylindershigh; 168 | unsigned char heads; 169 | } __attribute__ ( ( __packed__ ) ) t_INT13_CDROM_EMULATION; 170 | #endif 171 | -------------------------------------------------------------------------------- /src/nbp/pxe.c/pxe.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2006-2008, V. 3 | For contact information, see http://winaoe.org/ 4 | 5 | This file is part of WinAoE. 6 | 7 | WinAoE is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | WinAoE is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with WinAoE. If not, see . 19 | */ 20 | 21 | asm ( ".code16gcc\n" ); 22 | #include "pxe.h" 23 | #include "asm.h" 24 | #include "lib.h" 25 | 26 | int apivector = 0; 27 | 28 | int 29 | pxeinit ( 30 | void 31 | ) 32 | { 33 | int v; 34 | asm ( "pushw %%es\n\t" "movw $0x5650, %%ax\n\t" "int $0x1a\n\t" "cmpw $0x564e, %%ax\n\t" "je 0f\n\t" "xorl %%eax, %%eax\n\t" "jmp 1f\n" "0: les %%es:0x28(%%bx), %%bx\n\t" "movl %%es:0x10(%%bx), %%eax\n" "1: popw %%es": "=a" ( v ): 35 | :"ebx", "cc" ); 36 | apivector = v; 37 | return v; 38 | } 39 | 40 | unsigned short 41 | api ( 42 | unsigned short command, 43 | void *commandstruct 44 | ) 45 | { 46 | unsigned short r; 47 | asm volatile ( 48 | // "pushfl\n\t" 49 | // "pushw %%ds\n\t" 50 | // "pushw %%es\n\t" 51 | // "pushw %%fs\n\t" 52 | // "pushw %%gs\n\t" 53 | // "pushal\n\t" 54 | "xorw %%ax, %%ax\n\t" "pushw %%cs\n\t" "pushw %%bx\n\t" "pushw %%cx\n" 55 | ".code16\n\t" "lcall *%%cs:_apivector\n" ".code16gcc\n\t" 56 | // "cli\n\t" 57 | "addw $6, %%sp\n\t" 58 | // "movw %%ax, %%gs\n\t" 59 | // "popal\n\t" 60 | // "movw %%gs, %%ax\n\t" 61 | // "popw %%gs\n\t" 62 | // "popw %%fs\n\t" 63 | // "popw %%es\n\t" 64 | // "popw %%ds\n\t" 65 | // "popfl" 66 | :"=a" ( r ):"b" ( commandstruct ), 67 | "c" ( command ):"cc", 68 | "memory" 69 | ); 70 | return r; 71 | } 72 | 73 | void 74 | apierror ( 75 | char *message, 76 | unsigned short status 77 | ) 78 | { 79 | printf ( "%s: 0x%04x\n", message, status ); 80 | halt ( ); 81 | } 82 | -------------------------------------------------------------------------------- /src/util/Wv.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/util/Wv.ico -------------------------------------------------------------------------------- /src/util/winvblock.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/util/winvblock.rc -------------------------------------------------------------------------------- /src/winvblock/device.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * 25 | * Device specifics. 26 | */ 27 | 28 | #include 29 | 30 | #include "portable.h" 31 | #include "winvblock.h" 32 | #include "wv_stdlib.h" 33 | #include "irp.h" 34 | #include "driver.h" 35 | #include "bus.h" 36 | #include "device.h" 37 | #include "debug.h" 38 | 39 | /* Forward declarations. */ 40 | static WV_F_DEV_FREE WvDevFreeDev_; 41 | static WV_F_DEV_CREATE_PDO WvDevMakePdo_; 42 | 43 | /** 44 | * Initialize device defaults. 45 | * 46 | * @v Dev Points to the device to initialize with defaults. 47 | */ 48 | WVL_M_LIB VOID WvDevInit(WV_SP_DEV_T Dev) { 49 | RtlZeroMemory(Dev, sizeof *Dev); 50 | /* Populate non-zero device defaults. */ 51 | Dev->DriverObject = WvDriverObj; 52 | Dev->Ops.CreatePdo = WvDevMakePdo_; 53 | Dev->Ops.Free = WvDevFreeDev_; 54 | } 55 | 56 | /** 57 | * Create a new device. 58 | * 59 | * @ret dev The address of a new device, or NULL for failure. 60 | * 61 | * This function should not be confused with a PDO creation routine, which is 62 | * actually implemented for each device type. This routine will allocate a 63 | * WV_DEV_T and populate the device with default values. 64 | */ 65 | WVL_M_LIB WV_SP_DEV_T WvDevCreate(void) { 66 | WV_SP_DEV_T dev; 67 | 68 | /* 69 | * Devices might be used for booting and should 70 | * not be allocated from a paged memory pool. 71 | */ 72 | dev = wv_malloc(sizeof *dev); 73 | if (dev == NULL) 74 | return NULL; 75 | 76 | WvDevInit(dev); 77 | return dev; 78 | } 79 | 80 | /** 81 | * Create a device PDO. 82 | * 83 | * @v Dev Points to the device that needs a PDO. 84 | */ 85 | WVL_M_LIB PDEVICE_OBJECT STDCALL WvDevCreatePdo(IN WV_SP_DEV_T Dev) { 86 | return Dev->Ops.CreatePdo ? Dev->Ops.CreatePdo(Dev) : NULL; 87 | } 88 | 89 | /** 90 | * Default PDO creation operation. 91 | * 92 | * @v dev Points to the device that needs a PDO. 93 | * @ret NULL Reports failure, no matter what. 94 | * 95 | * This function does nothing, since it doesn't make sense to create a PDO 96 | * for an unknown type of device. 97 | */ 98 | static PDEVICE_OBJECT STDCALL WvDevMakePdo_(IN WV_SP_DEV_T dev) { 99 | DBG("No specific PDO creation operation for this device!\n"); 100 | return NULL; 101 | } 102 | 103 | /** 104 | * Respond to a device PnP ID query. 105 | * 106 | * @v dev The device being queried for PnP IDs. 107 | * @v query_type The query type. 108 | * @v buf Wide character, 512-element buffer for the 109 | * ID response. 110 | * @ret UINT32 The number of wide characters in the response, 111 | * or 0 upon a failure. 112 | */ 113 | UINT32 STDCALL WvDevPnpId( 114 | IN WV_SP_DEV_T dev, 115 | IN BUS_QUERY_ID_TYPE query_type, 116 | IN OUT WCHAR (*buf)[512] 117 | ) { 118 | return dev->Ops.PnpId ? dev->Ops.PnpId(dev, query_type, buf) : 0; 119 | } 120 | 121 | /* An IRP handler for a PnP ID query. */ 122 | NTSTATUS STDCALL WvDevPnpQueryId(IN WV_SP_DEV_T dev, IN PIRP irp) { 123 | NTSTATUS status; 124 | WCHAR (*str)[512]; 125 | UINT32 str_len; 126 | PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp); 127 | 128 | /* Allocate the working buffer. */ 129 | str = wv_mallocz(sizeof *str); 130 | if (str == NULL) { 131 | DBG("wv_malloc IRP_MN_QUERY_ID\n"); 132 | status = STATUS_INSUFFICIENT_RESOURCES; 133 | goto alloc_str; 134 | } 135 | /* Invoke the specific device's ID query. */ 136 | str_len = WvDevPnpId( 137 | dev, 138 | io_stack_loc->Parameters.QueryId.IdType, 139 | str 140 | ); 141 | if (str_len == 0) { 142 | irp->IoStatus.Information = 0; 143 | status = STATUS_NOT_SUPPORTED; 144 | goto alloc_info; 145 | } 146 | /* Allocate the return buffer. */ 147 | irp->IoStatus.Information = (ULONG_PTR) wv_palloc(str_len * sizeof **str); 148 | if (irp->IoStatus.Information == 0) { 149 | DBG("wv_palloc failed.\n"); 150 | status = STATUS_INSUFFICIENT_RESOURCES; 151 | goto alloc_info; 152 | } 153 | /* Copy the working buffer to the return buffer. */ 154 | RtlCopyMemory( 155 | (PVOID) irp->IoStatus.Information, 156 | str, 157 | str_len * sizeof **str 158 | ); 159 | status = STATUS_SUCCESS; 160 | 161 | /* irp->IoStatus.Information not freed. */ 162 | alloc_info: 163 | 164 | wv_free(str); 165 | alloc_str: 166 | 167 | return WvlIrpComplete(irp, irp->IoStatus.Information, status); 168 | } 169 | 170 | /** 171 | * Close a device. 172 | * 173 | * @v Dev Points to the device to close. 174 | */ 175 | WVL_M_LIB VOID STDCALL WvDevClose(IN WV_SP_DEV_T Dev) { 176 | /* Call the device's close routine. */ 177 | if (Dev->Ops.Close) 178 | Dev->Ops.Close(Dev); 179 | return; 180 | } 181 | 182 | /** 183 | * Delete a device. 184 | * 185 | * @v Dev Points to the device to delete. 186 | */ 187 | WVL_M_LIB VOID STDCALL WvDevFree(IN WV_SP_DEV_T Dev) { 188 | /* Call the device's free routine. */ 189 | if (Dev->Ops.Free) 190 | Dev->Ops.Free(Dev); 191 | return; 192 | } 193 | 194 | /** 195 | * Default device deletion operation. 196 | * 197 | * @v dev Points to the device to delete. 198 | */ 199 | static VOID STDCALL WvDevFreeDev_(IN WV_SP_DEV_T dev) { 200 | wv_free(dev); 201 | } 202 | 203 | /** 204 | * Get a device from a DEVICE_OBJECT. 205 | * 206 | * @v dev_obj Points to the DEVICE_OBJECT to get the device from. 207 | * @ret Returns a pointer to the device on success, else NULL. 208 | */ 209 | WVL_M_LIB WV_SP_DEV_T WvDevFromDevObj(PDEVICE_OBJECT dev_obj) { 210 | WV_SP_DEV_EXT dev_ext; 211 | 212 | if (!dev_obj) 213 | return NULL; 214 | dev_ext = dev_obj->DeviceExtension; 215 | return dev_ext->device; 216 | } 217 | 218 | /** 219 | * Set the device for a DEVICE_OBJECT. 220 | * 221 | * @v dev_obj Points to the DEVICE_OBJECT to set the device for. 222 | * @v dev Points to the device to associate with. 223 | */ 224 | WVL_M_LIB VOID WvDevForDevObj(PDEVICE_OBJECT dev_obj, WV_SP_DEV_T dev) { 225 | WV_SP_DEV_EXT dev_ext = dev_obj->DeviceExtension; 226 | dev_ext->device = dev; 227 | return; 228 | } 229 | 230 | /** 231 | * Get a device's IRP handler routine. 232 | * 233 | * @v dev_obj Points to the DEVICE_OBJECT to get 234 | * the handler for. 235 | * @ret PDRIVER_DISPATCH Points to the IRP handler routine. 236 | */ 237 | WVL_M_LIB PDRIVER_DISPATCH STDCALL WvDevGetIrpHandler( 238 | IN PDEVICE_OBJECT dev_obj 239 | ) { 240 | WV_SP_DEV_EXT dev_ext = dev_obj->DeviceExtension; 241 | return dev_ext->IrpDispatch; 242 | } 243 | 244 | /** 245 | * Set a device's IRP handler routine. 246 | * 247 | * @v dev_obj Points to the DEVICE_OBJECT to set the handler for. 248 | * @v irp_dispatch Points to the IRP handler routine. 249 | */ 250 | WVL_M_LIB VOID STDCALL WvDevSetIrpHandler( 251 | IN PDEVICE_OBJECT dev_obj, 252 | IN PDRIVER_DISPATCH irp_dispatch 253 | ) { 254 | WV_SP_DEV_EXT dev_ext = dev_obj->DeviceExtension; 255 | dev_ext->IrpDispatch = irp_dispatch; 256 | return; 257 | } 258 | -------------------------------------------------------------------------------- /src/winvblock/disk.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * 25 | * WinVBlock driver disk specifics. 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | #include "portable.h" 32 | #include "winvblock.h" 33 | #include "wv_stdlib.h" 34 | #include "irp.h" 35 | #include "driver.h" 36 | #include "bus.h" 37 | #include "device.h" 38 | #include "disk.h" 39 | #include "debug.h" 40 | 41 | /** Exports. */ 42 | NTSTATUS STDCALL WvDiskPnpQueryDevText( 43 | IN PDEVICE_OBJECT dev_obj, 44 | IN PIRP irp, 45 | IN WVL_SP_DISK_T disk 46 | ) { 47 | IN WV_SP_DEV_T dev = WvDevFromDevObj(dev_obj); 48 | WCHAR (*str)[512]; 49 | PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp); 50 | NTSTATUS status; 51 | UINT32 str_len; 52 | 53 | /* Allocate a string buffer. */ 54 | str = wv_mallocz(sizeof *str); 55 | if (str == NULL) { 56 | DBG("wv_malloc IRP_MN_QUERY_DEVICE_TEXT\n"); 57 | status = STATUS_INSUFFICIENT_RESOURCES; 58 | goto alloc_str; 59 | } 60 | /* Determine the query type. */ 61 | switch (io_stack_loc->Parameters.QueryDeviceText.DeviceTextType) { 62 | case DeviceTextDescription: 63 | str_len = swprintf(*str, WVL_M_WLIT L" Disk") + 1; 64 | irp->IoStatus.Information = 65 | (ULONG_PTR) wv_palloc(str_len * sizeof **str); 66 | if (irp->IoStatus.Information == 0) { 67 | DBG("wv_palloc DeviceTextDescription\n"); 68 | status = STATUS_INSUFFICIENT_RESOURCES; 69 | goto alloc_info; 70 | } 71 | RtlCopyMemory( 72 | (PWCHAR) irp->IoStatus.Information, 73 | str, 74 | str_len * sizeof **str 75 | ); 76 | status = STATUS_SUCCESS; 77 | goto alloc_info; 78 | 79 | case DeviceTextLocationInformation: 80 | if (disk->disk_ops.PnpQueryId) { 81 | io_stack_loc->MinorFunction = IRP_MN_QUERY_ID; 82 | io_stack_loc->Parameters.QueryId.IdType = BusQueryInstanceID; 83 | return disk->disk_ops.PnpQueryId(dev_obj, irp, disk); 84 | } 85 | /* Else, fall through... */ 86 | 87 | default: 88 | irp->IoStatus.Information = 0; 89 | status = STATUS_NOT_SUPPORTED; 90 | } 91 | /* irp->IoStatus.Information not freed. */ 92 | alloc_info: 93 | 94 | wv_free(str); 95 | alloc_str: 96 | 97 | return WvlIrpComplete(irp, irp->IoStatus.Information, status); 98 | } 99 | -------------------------------------------------------------------------------- /src/winvblock/filedisk/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=filedisk 4 | 5 | set c=filedisk.c grub4dos.c security.c pnp.c scsi.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib -------------------------------------------------------------------------------- /src/winvblock/filedisk/security.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | /** 21 | * @file 22 | * 23 | * File-backed disk security impersonation. 24 | */ 25 | 26 | #include 27 | 28 | #include "portable.h" 29 | #include "wv_stdlib.h" 30 | 31 | NTSTATUS STDCALL WvFilediskImpersonate(IN PVOID Impersonation) { 32 | return SeImpersonateClientEx( 33 | Impersonation, 34 | NULL 35 | ); 36 | } 37 | 38 | VOID WvFilediskStopImpersonating(void) { 39 | PsRevertToSelf(); 40 | return; 41 | } 42 | 43 | NTSTATUS STDCALL WvFilediskCreateClientSecurity(OUT PVOID * Impersonation) { 44 | PSECURITY_CLIENT_CONTEXT sec_context; 45 | NTSTATUS status; 46 | SECURITY_QUALITY_OF_SERVICE sec_qos = {0}; 47 | 48 | /* Allocate the client security context. */ 49 | sec_context = wv_malloc(sizeof *sec_context); 50 | if (!sec_context) { 51 | status = STATUS_INSUFFICIENT_RESOURCES; 52 | goto err_context; 53 | } 54 | 55 | /* Build the impersonation context. Taken from Bo B.'s filedisk. */ 56 | sec_qos.Length = sizeof sec_qos; 57 | sec_qos.ImpersonationLevel = SecurityImpersonation; 58 | sec_qos.ContextTrackingMode = SECURITY_STATIC_TRACKING; 59 | sec_qos.EffectiveOnly = FALSE; 60 | status = SeCreateClientSecurity( 61 | PsGetCurrentThread(), 62 | &sec_qos, 63 | FALSE, 64 | sec_context 65 | ); 66 | if (!NT_SUCCESS(status)) { 67 | goto err_impersonation; 68 | } 69 | 70 | *Impersonation = sec_context; 71 | return status; 72 | 73 | err_impersonation: 74 | 75 | err_context: 76 | 77 | return status; 78 | } 79 | 80 | VOID STDCALL WvFilediskDeleteClientSecurity(IN OUT PVOID * Impersonation) { 81 | PSECURITY_CLIENT_CONTEXT sec_context; 82 | 83 | if (!*Impersonation) 84 | return; 85 | 86 | sec_context = *Impersonation; 87 | #if (NTDDI_VERSION >= NTDDI_WINXP) 88 | SeDeleteClientSecurity(sec_context); 89 | #endif 90 | wv_free(*Impersonation); 91 | *Impersonation = NULL; 92 | return; 93 | } 94 | -------------------------------------------------------------------------------- /src/winvblock/grub4dos/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=grub4dos 4 | 5 | set c=g4dbus.c fdo.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib 18 | -------------------------------------------------------------------------------- /src/winvblock/libbus/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=libbus 4 | 5 | set c=libbus.c pnp.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib -------------------------------------------------------------------------------- /src/winvblock/libdisk/dev_ctl.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * Copyright 2006-2008, V. 4 | * For WinAoE contact information, see http://winaoe.org/ 5 | * 6 | * This file is part of WinVBlock, derived from WinAoE. 7 | * 8 | * WinVBlock is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * WinVBlock is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with WinVBlock. If not, see . 20 | */ 21 | 22 | /** 23 | * @file 24 | * 25 | * Disk Device Control IRP handling. 26 | */ 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "portable.h" 38 | #include "winvblock.h" 39 | #include "irp.h" 40 | #include "driver.h" 41 | #include "bus.h" 42 | #include "device.h" 43 | #include "disk.h" 44 | #include "debug.h" 45 | 46 | static NTSTATUS STDCALL WvlDiskDevCtlStorageQueryProp_( 47 | IN WVL_SP_DISK_T disk, 48 | IN PIRP irp 49 | ) { 50 | PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp); 51 | NTSTATUS status = STATUS_INVALID_PARAMETER; 52 | PSTORAGE_PROPERTY_QUERY storage_prop_query = irp->AssociatedIrp.SystemBuffer; 53 | UINT32 copy_size; 54 | STORAGE_ADAPTER_DESCRIPTOR storage_adapter_desc; 55 | STORAGE_DEVICE_DESCRIPTOR storage_dev_desc; 56 | 57 | if ( 58 | storage_prop_query->PropertyId == StorageAdapterProperty && 59 | storage_prop_query->QueryType == PropertyStandardQuery 60 | ) { 61 | copy_size = ( 62 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength < 63 | sizeof (STORAGE_ADAPTER_DESCRIPTOR) ? 64 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength : 65 | sizeof (STORAGE_ADAPTER_DESCRIPTOR) 66 | ); 67 | storage_adapter_desc.Version = sizeof (STORAGE_ADAPTER_DESCRIPTOR); 68 | storage_adapter_desc.Size = sizeof (STORAGE_ADAPTER_DESCRIPTOR); 69 | storage_adapter_desc.MaximumTransferLength = 70 | WvlDiskMaxXferLen(disk); 71 | #if 0 72 | storage_adapter_desc.MaximumTransferLength = SECTORSIZE * POOLSIZE; 73 | #endif 74 | storage_adapter_desc.MaximumPhysicalPages = (UINT32) -1; 75 | storage_adapter_desc.AlignmentMask = 0; 76 | storage_adapter_desc.AdapterUsesPio = TRUE; 77 | storage_adapter_desc.AdapterScansDown = FALSE; 78 | storage_adapter_desc.CommandQueueing = FALSE; 79 | storage_adapter_desc.AcceleratedTransfer = FALSE; 80 | storage_adapter_desc.BusType = BusTypeScsi; 81 | RtlCopyMemory( 82 | irp->AssociatedIrp.SystemBuffer, 83 | &storage_adapter_desc, 84 | copy_size 85 | ); 86 | status = STATUS_SUCCESS; 87 | } 88 | 89 | if ( 90 | storage_prop_query->PropertyId == StorageDeviceProperty && 91 | storage_prop_query->QueryType == PropertyStandardQuery 92 | ) { 93 | copy_size = ( 94 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength < 95 | sizeof (STORAGE_DEVICE_DESCRIPTOR) ? 96 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength : 97 | sizeof (STORAGE_DEVICE_DESCRIPTOR) 98 | ); 99 | storage_dev_desc.Version = sizeof (STORAGE_DEVICE_DESCRIPTOR); 100 | storage_dev_desc.Size = sizeof (STORAGE_DEVICE_DESCRIPTOR); 101 | storage_dev_desc.DeviceType = DIRECT_ACCESS_DEVICE; 102 | storage_dev_desc.DeviceTypeModifier = 0; 103 | storage_dev_desc.RemovableMedia = WvlDiskIsRemovable[disk->Media]; 104 | storage_dev_desc.CommandQueueing = FALSE; 105 | storage_dev_desc.VendorIdOffset = 0; 106 | storage_dev_desc.ProductIdOffset = 0; 107 | storage_dev_desc.ProductRevisionOffset = 0; 108 | storage_dev_desc.SerialNumberOffset = 0; 109 | storage_dev_desc.BusType = BusTypeScsi; 110 | storage_dev_desc.RawPropertiesLength = 0; 111 | RtlCopyMemory( 112 | irp->AssociatedIrp.SystemBuffer, 113 | &storage_dev_desc, 114 | copy_size 115 | ); 116 | status = STATUS_SUCCESS; 117 | } 118 | 119 | if (status == STATUS_INVALID_PARAMETER) { 120 | DBG( 121 | "!!Invalid IOCTL_STORAGE_QUERY_PROPERTY " 122 | "(PropertyId: %08x / QueryType: %08x)!!\n", 123 | storage_prop_query->PropertyId, 124 | storage_prop_query->QueryType 125 | ); 126 | return WvlIrpComplete(irp, 0, status); 127 | } 128 | return WvlIrpComplete(irp, (ULONG_PTR) copy_size, status); 129 | } 130 | 131 | static NTSTATUS STDCALL WvlDiskDevCtlGetGeom_( 132 | IN WVL_SP_DISK_T disk, 133 | IN PIRP irp 134 | ) { 135 | PIO_STACK_LOCATION io_stack_loc = IoGetCurrentIrpStackLocation(irp); 136 | UINT32 copy_size; 137 | DISK_GEOMETRY disk_geom; 138 | 139 | copy_size = ( 140 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength < 141 | sizeof (DISK_GEOMETRY) ? 142 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength : 143 | sizeof (DISK_GEOMETRY) 144 | ); 145 | disk_geom.MediaType = FixedMedia; 146 | disk_geom.Cylinders.QuadPart = disk->Cylinders; 147 | disk_geom.TracksPerCylinder = disk->Heads; 148 | disk_geom.SectorsPerTrack = disk->Sectors; 149 | disk_geom.BytesPerSector = disk->SectorSize; 150 | RtlCopyMemory( 151 | irp->AssociatedIrp.SystemBuffer, 152 | &disk_geom, 153 | copy_size 154 | ); 155 | return WvlIrpComplete(irp, (ULONG_PTR) copy_size, STATUS_SUCCESS); 156 | } 157 | 158 | static NTSTATUS STDCALL WvlDiskDevCtlScsiGetAddr_( 159 | IN WVL_SP_DISK_T disk, 160 | IN PIRP irp 161 | ) { 162 | PIO_STACK_LOCATION io_stack_loc= IoGetCurrentIrpStackLocation(irp); 163 | UINT32 copy_size; 164 | SCSI_ADDRESS scsi_address; 165 | 166 | copy_size = ( 167 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength < 168 | sizeof (SCSI_ADDRESS) ? 169 | io_stack_loc->Parameters.DeviceIoControl.OutputBufferLength : 170 | sizeof (SCSI_ADDRESS) 171 | ); 172 | scsi_address.Length = sizeof (SCSI_ADDRESS); 173 | scsi_address.PortNumber = 0; 174 | scsi_address.PathId = 0; 175 | scsi_address.TargetId = WvlDiskUnitNum(disk); 176 | scsi_address.Lun = 0; 177 | RtlCopyMemory( 178 | irp->AssociatedIrp.SystemBuffer, 179 | &scsi_address, 180 | copy_size 181 | ); 182 | return WvlIrpComplete(irp, (ULONG_PTR) copy_size, STATUS_SUCCESS); 183 | } 184 | 185 | /** 186 | * Handle a disk IRP_MJ_DEVICE_CONTROL IRP. 187 | * 188 | * @v Disk The disk to process with the IRP. 189 | * @v Irp The IRP to process with the disk. 190 | * @v Code The device control code. 191 | * @ret NTSTATUS The status of the operation. 192 | */ 193 | WVL_M_LIB NTSTATUS STDCALL WvlDiskDevCtl( 194 | IN WVL_SP_DISK_T Disk, 195 | IN PIRP Irp, 196 | IN ULONG POINTER_ALIGNMENT Code 197 | ) { 198 | switch (Code) { 199 | case IOCTL_STORAGE_QUERY_PROPERTY: 200 | return WvlDiskDevCtlStorageQueryProp_(Disk, Irp); 201 | 202 | case IOCTL_DISK_GET_DRIVE_GEOMETRY: 203 | return WvlDiskDevCtlGetGeom_(Disk, Irp); 204 | 205 | case IOCTL_SCSI_GET_ADDRESS: 206 | return WvlDiskDevCtlScsiGetAddr_(Disk, Irp); 207 | 208 | /* Some cases that pop up on Windows Server 2003. */ 209 | #if 0 210 | case IOCTL_MOUNTDEV_UNIQUE_ID_CHANGE_NOTIFY: 211 | case IOCTL_MOUNTDEV_LINK_CREATED: 212 | case IOCTL_MOUNTDEV_QUERY_STABLE_GUID: 213 | case IOCTL_VOLUME_ONLINE: 214 | return WvlIrpComplete(Irp, 0, STATUS_SUCCESS); 215 | #endif 216 | } 217 | 218 | return WvlIrpComplete(Irp, 0, STATUS_INVALID_PARAMETER); 219 | } 220 | -------------------------------------------------------------------------------- /src/winvblock/libdisk/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=libdisk 4 | 5 | set c=libdisk.c dev_ctl.c scsi.c pnp.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib -------------------------------------------------------------------------------- /src/winvblock/mainbus/mainbus.h: -------------------------------------------------------------------------------- 1 | #ifndef M_WV_MAINBUS_H_ 2 | /** 3 | * Copyright (C) 2009-2012, Shao Miller . 4 | * Copyright 2006-2008, V. 5 | * For WinAoE contact information, see http://winaoe.org/ 6 | * 7 | * This file is part of WinVBlock, originally derived from WinAoE. 8 | * 9 | * WinVBlock is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * WinVBlock is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with WinVBlock. If not, see . 21 | */ 22 | 23 | /** 24 | * @file 25 | * 26 | * Main bus specifics 27 | */ 28 | 29 | /** Macros */ 30 | #define M_WV_MAINBUS_H_ 31 | 32 | /** Constants */ 33 | enum E_WV_MAIN_BUS_FLAG { 34 | CvWvMainBusFlagIrpsHeld_, 35 | CvWvMainBusFlagIrpsHeld = 1 << CvWvMainBusFlagIrpsHeld_, 36 | CvWvMainBusFlagZero = 0 37 | }; 38 | 39 | /** Object types */ 40 | typedef enum E_WV_MAIN_BUS_FLAG E_WV_MAIN_BUS_FLAG; 41 | typedef struct S_WV_MAIN_BUS S_WV_MAIN_BUS; 42 | 43 | /** Function declarations */ 44 | 45 | /* From mainbus.c */ 46 | extern NTSTATUS STDCALL WvBusRemoveDev(IN WV_S_DEV_T * Device); 47 | extern NTSTATUS WvMainBusInitialBusRelations(DEVICE_OBJECT * DeviceObject); 48 | 49 | /* From busirp.c */ 50 | extern VOID WvMainBusBuildMajorDispatchTable(void); 51 | extern DRIVER_DISPATCH WvMainBusIrpDispatch; 52 | 53 | /** Struct/union type definitions */ 54 | 55 | /** The bus extension type */ 56 | struct S_WV_MAIN_BUS { 57 | /** This must be the first member of all extension types */ 58 | WV_S_DEV_EXT DeviceExtension[1]; 59 | 60 | /** Flags for state that must be accessed atomically */ 61 | volatile LONG Flags; 62 | 63 | /** The main bus' PDO (bottom of the device stack) */ 64 | DEVICE_OBJECT * PhysicalDeviceObject; 65 | 66 | /** PnP bus information */ 67 | PNP_BUS_INFORMATION PnpBusInfo[1]; 68 | 69 | /** PnP bus relations */ 70 | DEVICE_RELATIONS * BusRelations; 71 | 72 | /** Registrations for the initial bus relations probe */ 73 | S_WVL_LOCKED_LIST InitialProbeRegistrations[1]; 74 | }; 75 | 76 | /** External objects */ 77 | 78 | /* From mainbus.c */ 79 | extern UNICODE_STRING WvBusDosName; 80 | extern WVL_S_BUS_T WvBus; 81 | extern WV_S_DEV_T WvBusDev; 82 | extern volatile LONG WvMainBusCreators; 83 | 84 | /** This mini-driver */ 85 | extern S_WVL_MINI_DRIVER * WvMainBusMiniDriver; 86 | 87 | #endif /* M_WV_MAINBUS_H_ */ 88 | -------------------------------------------------------------------------------- /src/winvblock/mainbus/makefile: -------------------------------------------------------------------------------- 1 | !INCLUDE $(NTMAKEENV)\makefile.def 2 | -------------------------------------------------------------------------------- /src/winvblock/mainbus/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=mainbus 4 | 5 | set c=mainbus.c busirp.c dummyirp.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib -------------------------------------------------------------------------------- /src/winvblock/makedriver.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set lib=libbus libdisk ramdisk filedisk wvlib grub4dos safehook mainbus memdisk 4 | 5 | set links= 6 | for /d %%a in (%lib%) do ( 7 | pushd . 8 | cd %%a 9 | call makelib.bat 10 | popd 11 | ) 12 | 13 | set c=debug.c driver.c registry.c winvblock.rc device.c wv_stdlib.c wv_string.c disk.c 14 | 15 | set name=WVBlk%bits% 16 | 17 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 18 | 19 | echo INCLUDES=..\include > sources 20 | echo TARGETNAME=%name% >> sources 21 | echo TARGETTYPE=EXPORT_DRIVER >> sources 22 | echo TARGETPATH=obj >> sources 23 | echo LINKLIBS=%links% >> sources 24 | echo TARGETLIBS=%links% >> sources 25 | echo SOURCES=%c% >> sources 26 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 27 | 28 | echo NAME %name%.sys > %name%.def 29 | 30 | build 31 | copy obj%obj%\%arch%\%name%.sys ..\..\bin >nul 32 | copy obj%obj%\%arch%\%name%.pdb ..\..\bin >nul 33 | copy obj%obj%\%arch%\%name%.lib ..\..\bin >nul 34 | -------------------------------------------------------------------------------- /src/winvblock/memdisk/makefile: -------------------------------------------------------------------------------- 1 | !INCLUDE $(NTMAKEENV)\makefile.def 2 | -------------------------------------------------------------------------------- /src/winvblock/memdisk/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=memdisk 4 | 5 | set c=memdisk.c fdo.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib 18 | -------------------------------------------------------------------------------- /src/winvblock/ramdisk/grub4dos.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | /** 21 | * @file 22 | * 23 | * GRUB4DOS RAM disk specifics. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include "portable.h" 30 | #include "winvblock.h" 31 | #include "wv_string.h" 32 | #include "driver.h" 33 | #include "bus.h" 34 | #include "device.h" 35 | #include "disk.h" 36 | #include "ramdisk.h" 37 | #include "debug.h" 38 | #include "x86.h" 39 | #include "safehook.h" 40 | #include "grub4dos.h" 41 | 42 | /** Create a GRUB4DOS RAM disk and set its parent bus */ 43 | DEVICE_OBJECT * WvRamdiskCreateG4dDisk( 44 | SP_WV_G4D_DRIVE_MAPPING slot, 45 | DEVICE_OBJECT * bus_dev_obj, 46 | WVL_E_DISK_MEDIA_TYPE media_type, 47 | UINT32 sector_size 48 | ) { 49 | WV_SP_RAMDISK_T ramdisk; 50 | 51 | ramdisk = WvRamdiskCreatePdo(media_type); 52 | if (!ramdisk) { 53 | DBG("Could not create GRUB4DOS disk!\n"); 54 | return NULL; 55 | } 56 | DBG("RAM Drive is type: %d\n", media_type); 57 | 58 | ramdisk->DiskBuf = (UINT32) (slot->SectorStart * 512); 59 | ramdisk->disk->LBADiskSize = ramdisk->DiskSize = 60 | (UINT32) slot->SectorCount; 61 | ramdisk->disk->Heads = slot->MaxHead + 1; 62 | ramdisk->disk->Sectors = slot->DestMaxSector; 63 | ramdisk->disk->Cylinders = ( 64 | ramdisk->disk->LBADiskSize / 65 | (ramdisk->disk->Heads * ramdisk->disk->Sectors) 66 | ); 67 | ramdisk->disk->Media = media_type; 68 | ramdisk->disk->SectorSize = sector_size; 69 | ramdisk->Dev->Boot = TRUE; 70 | /* Add the ramdisk to the bus. */ 71 | ramdisk->disk->ParentBus = bus_dev_obj; 72 | WvlBusInitNode(&ramdisk->Dev->BusNode, ramdisk->Dev->Self); 73 | ramdisk->Dev->BusNode.Linked = TRUE; 74 | ramdisk->Dev->Self->Flags &= ~DO_DEVICE_INITIALIZING; 75 | 76 | return ramdisk->Dev->Self; 77 | } 78 | -------------------------------------------------------------------------------- /src/winvblock/ramdisk/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=ramdisk 4 | 5 | set c=ramdisk.c memdisk.c grub4dos.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib -------------------------------------------------------------------------------- /src/winvblock/ramdisk/memdisk.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | /** 21 | * @file 22 | * 23 | * MEMDISK specifics. 24 | */ 25 | 26 | #include 27 | #include 28 | 29 | #include "portable.h" 30 | #include "winvblock.h" 31 | #include "wv_string.h" 32 | #include "driver.h" 33 | #include "bus.h" 34 | #include "device.h" 35 | #include "disk.h" 36 | #include "ramdisk.h" 37 | #include "debug.h" 38 | #include "mdi.h" 39 | #include "x86.h" 40 | #include "safehook.h" 41 | 42 | static BOOLEAN STDCALL WvMemdiskCheckMbft_( 43 | PUCHAR phys_mem, 44 | UINT32 offset, 45 | BOOLEAN walk 46 | ) { 47 | WV_SP_MDI_MBFT mbft = (WV_SP_MDI_MBFT) (phys_mem + offset); 48 | UINT32 i; 49 | UCHAR chksum = 0; 50 | WV_SP_PROBE_SAFE_MBR_HOOK assoc_hook; 51 | WVL_E_DISK_MEDIA_TYPE media_type; 52 | UINT32 sector_size; 53 | WV_SP_RAMDISK_T ramdisk; 54 | 55 | if (offset >= 0x100000) { 56 | DBG("mBFT physical pointer too high!\n"); 57 | return FALSE; 58 | } 59 | if (!wv_memcmpeq(mbft->Signature, "mBFT", sizeof "mBFT" - 1)) return FALSE; 60 | if (offset + mbft->Length >= 0x100000) { 61 | DBG("mBFT length out-of-bounds\n"); 62 | return FALSE; 63 | } 64 | for (i = 0; i < mbft->Length; i++) 65 | chksum += ((UCHAR *) mbft)[i]; 66 | if (chksum) { 67 | DBG("Invalid mBFT checksum\n"); 68 | return FALSE; 69 | } 70 | DBG("Found mBFT: 0x%08x\n", mbft); 71 | if (mbft->SafeHook >= 0x100000) { 72 | DBG("mBFT safe hook physical pointer too high!\n"); 73 | return FALSE; 74 | } 75 | assoc_hook = 76 | (WV_SP_PROBE_SAFE_MBR_HOOK) (phys_mem + mbft->SafeHook); 77 | if (assoc_hook->Flags) { 78 | DBG("This MEMDISK already processed\n"); 79 | return TRUE; 80 | } 81 | DBG("MEMDISK DiskBuf: 0x%08x\n", mbft->mdi.diskbuf); 82 | DBG("MEMDISK DiskSize: %d sectors\n", mbft->mdi.disksize); 83 | if (mbft->mdi.driveno == 0xE0) { 84 | media_type = WvlDiskMediaTypeOptical; 85 | sector_size = 2048; 86 | } else { 87 | if (mbft->mdi.driveno & 0x80) 88 | media_type = WvlDiskMediaTypeHard; 89 | else 90 | media_type = WvlDiskMediaTypeFloppy; 91 | sector_size = 512; 92 | } 93 | ramdisk = WvRamdiskCreatePdo(media_type); 94 | if (ramdisk == NULL) { 95 | DBG("Could not create MEMDISK disk!\n"); 96 | return FALSE; 97 | } 98 | ramdisk->DiskBuf = mbft->mdi.diskbuf; 99 | ramdisk->disk->LBADiskSize = ramdisk->DiskSize = mbft->mdi.disksize; 100 | DBG("RAM Drive is type: %d\n", media_type); 101 | ramdisk->disk->Cylinders = mbft->mdi.cylinders; 102 | ramdisk->disk->Heads = mbft->mdi.heads; 103 | ramdisk->disk->Sectors = mbft->mdi.sectors; 104 | ramdisk->disk->Media = media_type; 105 | ramdisk->disk->SectorSize = sector_size; 106 | ramdisk->Dev->Boot = TRUE; 107 | 108 | /* Add the ramdisk to the bus. */ 109 | ramdisk->disk->ParentBus = WvBus.Fdo; 110 | if (!WvBusAddDev(ramdisk->Dev)) { 111 | WvDevFree(ramdisk->Dev); 112 | return FALSE; 113 | } 114 | assoc_hook->Flags = 1; 115 | /* Should we try to walk the "safe hook" chain? */ 116 | if (walk) 117 | { DEVICE_OBJECT * TODO = NULL; 118 | WvlCreateSafeHookDevice(&assoc_hook->PrevHook, &TODO); 119 | } 120 | return TRUE; 121 | } 122 | 123 | VOID WvMemdiskFind(void) { 124 | PHYSICAL_ADDRESS phys_addr; 125 | PUCHAR phys_mem; 126 | UINT32 offset; 127 | BOOLEAN found = FALSE; 128 | 129 | /* Find a MEMDISK by scanning for mBFTs. Map the first MiB of memory. */ 130 | phys_addr.QuadPart = 0LL; 131 | phys_mem = MmMapIoSpace(phys_addr, 0x100000, MmNonCached); 132 | if (!phys_mem) { 133 | DBG("Could not map low memory\n"); 134 | goto err_map; 135 | } 136 | 137 | for (offset = 0; offset < 0xFFFF0; offset += 0x10) { 138 | found |= WvMemdiskCheckMbft_(phys_mem, offset, TRUE); 139 | } 140 | 141 | MmUnmapIoSpace(phys_mem, 0x100000); 142 | err_map: 143 | 144 | DBG("%smBFTs found\n", found ? "" : "No "); 145 | return; 146 | } 147 | 148 | BOOLEAN WvMemdiskProcessSafeHook( 149 | PUCHAR phys_mem, 150 | WV_SP_PROBE_SAFE_MBR_HOOK mbr_safe_hook 151 | ) { 152 | return WvMemdiskCheckMbft_(phys_mem, mbr_safe_hook->Mbft, FALSE); 153 | } 154 | -------------------------------------------------------------------------------- /src/winvblock/safehook/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=safehook 4 | 5 | set c=pdo.c probe.c fdo.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib 18 | -------------------------------------------------------------------------------- /src/winvblock/winvblock.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sha0/winvblock/7eed6ad5a72fb7d35e93031de36022816c00400f/src/winvblock/winvblock.rc -------------------------------------------------------------------------------- /src/winvblock/wv_stdlib.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2012, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | /** 21 | * @file 22 | * 23 | * Some C Standard Library work-alikes 24 | */ 25 | 26 | #include 27 | #include "wv_stdlib.h" 28 | 29 | PVOID wv_malloc(wv_size_t size) { 30 | return ExAllocatePoolWithTag(NonPagedPool, size, 'klBV'); 31 | } 32 | 33 | PVOID wv_palloc(wv_size_t size) { 34 | return ExAllocatePoolWithTag(PagedPool, size, 'klBV'); 35 | } 36 | 37 | PVOID wv_mallocz(wv_size_t size) { 38 | PVOID ptr = ExAllocatePoolWithTag(NonPagedPool, size, 'klBV'); 39 | return ptr ? RtlZeroMemory(ptr, size), ptr : ptr; 40 | } 41 | 42 | PVOID wv_pallocz(wv_size_t size) { 43 | PVOID ptr = ExAllocatePoolWithTag(PagedPool, size, 'klBV'); 44 | return ptr ? RtlZeroMemory(ptr, size), ptr : ptr; 45 | } 46 | 47 | VOID wv_free(VOID * ptr) { 48 | if (ptr) 49 | ExFreePool(ptr); 50 | return; 51 | } 52 | -------------------------------------------------------------------------------- /src/winvblock/wv_string.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | #include 21 | #include "wv_string.h" 22 | 23 | bool wv_memcmpeq(const VOID * s1, const VOID * s2, wv_size_t n) { 24 | return (RtlCompareMemory(s1, s2, n) == n) ? true : false; 25 | } 26 | -------------------------------------------------------------------------------- /src/winvblock/wvlib/irp.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (C) 2009-2011, Shao Miller . 3 | * 4 | * This file is part of WinVBlock, originally derived from WinAoE. 5 | * 6 | * WinVBlock is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * WinVBlock is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with WinVBlock. If not, see . 18 | */ 19 | 20 | /**** 21 | * @file 22 | * 23 | * IRP specifics. 24 | */ 25 | 26 | #include 27 | 28 | #include "portable.h" 29 | #include "winvblock.h" 30 | #include "debug.h" 31 | #include "irp.h" 32 | 33 | /*** Function definitions */ 34 | 35 | WVL_M_LIB NTSTATUS STDCALL WvlIrpComplete( 36 | IN PIRP Irp, 37 | IN ULONG_PTR Info, 38 | IN NTSTATUS Status 39 | ) { 40 | Irp->IoStatus.Information = Info; 41 | Irp->IoStatus.Status = Status; 42 | WVL_M_DEBUG_IRP_END(Irp, Status); 43 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 44 | return Status; 45 | } 46 | 47 | WVL_M_LIB NTSTATUS STDCALL WvlIrpPassToLower( 48 | IN PDEVICE_OBJECT Lower, 49 | IN PIRP Irp 50 | ) { 51 | /* Check that a lower device object was passed. */ 52 | if (Lower) { 53 | DBG("Passing IRP down\n"); 54 | IoSkipCurrentIrpStackLocation(Irp); 55 | return IoCallDriver(Lower, Irp); 56 | } 57 | 58 | Irp->IoStatus.Information = 0; 59 | Irp->IoStatus.Status = STATUS_SUCCESS; 60 | WVL_M_DEBUG_IRP_END(Irp, STATUS_SUCCESS); 61 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 62 | return STATUS_SUCCESS; 63 | } 64 | 65 | WVL_M_LIB NTSTATUS STDCALL WvlIrpPassPowerToLower( 66 | IN PDEVICE_OBJECT Lower, 67 | IN PIRP Irp 68 | ) { 69 | PoStartNextPowerIrp(Irp); 70 | 71 | /* Check that a lower device object was passed. */ 72 | if (Lower) { 73 | DBG("Passing power IRP down\n"); 74 | IoSkipCurrentIrpStackLocation(Irp); 75 | return PoCallDriver(Lower, Irp); 76 | } 77 | 78 | Irp->IoStatus.Information = 0; 79 | Irp->IoStatus.Status = STATUS_SUCCESS; 80 | WVL_M_DEBUG_IRP_END(Irp, STATUS_SUCCESS); 81 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 82 | return STATUS_SUCCESS; 83 | } 84 | 85 | WVL_M_LIB NTSTATUS STDCALL WvlIrpHandleWithTable( 86 | IN PDEVICE_OBJECT DevObj, 87 | IN PIRP Irp, 88 | IN SP_WVL_IRP_HANDLER_TABLE Table 89 | ) { 90 | PIO_STACK_LOCATION io_stack_loc; 91 | UCHAR code; 92 | SP_WVL_IRP_HANDLER end; 93 | SP_WVL_IRP_HANDLER handler; 94 | 95 | ASSERT(DevObj); 96 | ASSERT(Irp); 97 | ASSERT(Table); 98 | ASSERT(Table->Count); 99 | ASSERT(Table->Elements); 100 | 101 | io_stack_loc = IoGetCurrentIrpStackLocation(Irp); 102 | 103 | if (Table->IsMajor) 104 | code = io_stack_loc->MajorFunction; 105 | else 106 | code = io_stack_loc->MinorFunction; 107 | 108 | end = Table->Elements + Table->Count; 109 | 110 | for (handler = Table->Elements; handler < end; ++handler) { 111 | ASSERT(handler->Function); 112 | 113 | if (code == handler->Code) 114 | return handler->Function(DevObj, Irp); 115 | 116 | continue; 117 | } 118 | 119 | DBG("IRP not handled\n"); 120 | Irp->IoStatus.Information = 0; 121 | Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; 122 | WVL_M_DEBUG_IRP_END(Irp, STATUS_NOT_SUPPORTED); 123 | IoCompleteRequest(Irp, IO_NO_INCREMENT); 124 | return STATUS_NOT_SUPPORTED; 125 | } 126 | -------------------------------------------------------------------------------- /src/winvblock/wvlib/makelib.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set libname=wvlib 4 | 5 | set c=thread.c irp.c 6 | 7 | echo !INCLUDE $(NTMAKEENV)\makefile.def > makefile 8 | 9 | echo INCLUDES=..\..\include > sources 10 | echo TARGETNAME=%libname% >> sources 11 | echo TARGETTYPE=DRIVER_LIBRARY >> sources 12 | echo TARGETPATH=obj >> sources 13 | echo SOURCES=%c% >> sources 14 | echo C_DEFINES=-DPROJECT_WV=1 >> sources 15 | 16 | build 17 | set links=%links% %libname%\\obj%obj%\\%arch%\\%libname%.lib 18 | --------------------------------------------------------------------------------