├── .github └── workflows │ └── release.yml ├── .gitignore ├── g4dext ├── ChangeLog.txt ├── Makefile ├── Makefile-old ├── ProgressBar.c ├── bios.c ├── chkpci.c ├── cpuid.c ├── date.c ├── defs.h ├── diskid.c ├── echo.c ├── fat │ ├── fat.c │ ├── fat.h │ ├── fat_config.h │ ├── ff.c │ ├── ff.h │ ├── ffconf.h │ ├── integer.h │ └── option │ │ ├── 00readme.txt │ │ ├── cc932.c │ │ ├── cc936.c │ │ ├── cc949.c │ │ ├── cc950.c │ │ ├── ccsbcs.c │ │ ├── diskio.c │ │ ├── diskio.h │ │ └── syscall.c ├── font │ ├── Mbcs │ │ ├── Mbcs.c │ │ └── Mbcs.h │ ├── Unicode │ │ ├── unicode.c │ │ └── unicode.h │ ├── font.c │ └── font.h ├── fontfile.c ├── g4d_off.c ├── hotkey.c ├── inifile.c ├── main.h ├── mbrcheck.c ├── memcheck.c ├── menuset.c ├── snake.c ├── time.c ├── umbr.c ├── unifont.c ├── unitest.c ├── vbe.c ├── vbmp.c ├── vfont.c ├── wenv-readme.txt └── wenv.c ├── g4eext ├── ChangeLog.txt ├── Makefile ├── ProgressBar.c ├── WIMname.c ├── chkpci.c ├── cmdline.c ├── cpuid.c ├── date.c ├── diskid.c ├── echo.c ├── efidiskinfo.c ├── fat │ ├── fat.c │ ├── fat.h │ ├── fat_config.h │ ├── ff.c │ ├── ff.h │ ├── ffconf.h │ ├── integer.h │ └── option │ │ ├── 00readme.txt │ │ ├── cc932.c │ │ ├── cc936.c │ │ ├── cc949.c │ │ ├── cc950.c │ │ ├── ccsbcs.c │ │ ├── diskio.c │ │ ├── diskio.h │ │ └── syscall.c ├── fwsetup.c ├── g4d_off.c ├── getenv.c ├── hotkey.c ├── include │ ├── bcd.h │ ├── grub4dos.h │ ├── grubprog.h │ ├── pc_slice.h │ ├── reg.h │ └── uefi.h ├── inifile.c ├── mbrcheck.c ├── ntboot.c ├── ntboot │ ├── gbk2uni │ └── ntboot ├── slic.c ├── time.c ├── ver.c └── wenv.c ├── grubutils ├── common │ ├── COPYING │ ├── bin2h.c │ ├── bin2h.pl │ ├── common.mk │ ├── genrev.sh │ ├── keytab.c │ ├── keytab.h │ ├── ldscript │ ├── symbol.h │ ├── utils.c │ ├── utils.h │ ├── ver2h.c │ ├── ver2h.pl │ ├── xd16.asm │ ├── xdio.c │ └── xdio.h ├── fbinst │ ├── Makefile │ ├── fbinst.c │ ├── fbinst.h │ ├── fbmbr.S │ └── version ├── grubinst │ ├── Makefile │ ├── Makefile.dos │ ├── Makefile.vc6 │ ├── README_grubinst.txt │ ├── changelog.txt │ ├── g2hdr.S │ ├── grldrstart.S │ ├── grubinst-1.3.zip │ ├── grubinst.c │ ├── grubinst.ico │ ├── grubinst_gui.c │ ├── grubinst_gui.chs │ ├── grubinst_gui.rc │ ├── grubmenu.c │ ├── ntfsbs.S │ ├── ntfsbs.S.old │ ├── readme.txt │ ├── resource.h │ └── version ├── loadbin │ ├── Makefile │ ├── header.S │ ├── ldgrub.S │ ├── ldgrub2.S │ ├── ldntldr.S │ ├── mkimage.c │ └── version ├── makemod │ ├── Makefile │ └── makemod.c ├── makerom │ ├── LzmaDecode.c │ ├── LzmaDecode.h │ ├── LzmaDecode.s │ ├── LzmaTypes.h │ ├── Makefile │ ├── makerom.c │ ├── mkrom.mk │ ├── rom.S │ └── version ├── wee │ ├── COPYING │ ├── ChangeLog.txt │ ├── Makefile │ ├── README.txt │ ├── a20.inc │ ├── asm.S │ ├── builtins.c │ ├── disk_io.c │ ├── fsys_ext2fs.c │ ├── fsys_fat.c │ ├── fsys_ntfs.c │ ├── preset_menu_used │ ├── shared.h │ ├── utils │ │ └── weemouse.asm │ └── wee63start.S └── weesetup │ ├── Makefile │ ├── doc │ ├── WEE_ChangeLog.txt │ ├── WEE_README.txt │ └── readme.txt │ ├── menu.wee │ ├── mkmbr │ ├── nt6mbr.bin │ └── weesetup.c ├── include ├── grub4dos.h ├── grubprog.h ├── pc_slice.h └── typedef.h ├── umbr ├── Makefile ├── bin2c.c └── umbr.S └── wimboot ├── 0001_Add-EFI-LoadFile2-and-InitrdMedia-headers.patch ├── 0002_Fix-optinal-header-in-wimboot-2.8.0.patch ├── 0003_Provide-common-vdisk_read_mem_file-cpio-handler.patch ├── 0004_Support-EFI-linux-initrd-media-loading.patch └── build.sh /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-22.04 11 | steps: 12 | - name: 下载源码 13 | uses: actions/checkout@v3 14 | - name: 初始化 15 | run: | 16 | sudo apt update 17 | sudo apt -y install gcc gcc-multilib nasm p7zip-full autoconf automake make patch binutils-dev liblzma-dev gcc-mingw-w64-i686 libiberty-dev pesign gcab 18 | - name: 编译 19 | run: | 20 | make -C umbr 21 | make -j -C g4dext 22 | make -j -C g4eext 23 | cd wimboot && ./build.sh && cd .. 24 | zip -j g4dext-*.zip wimboot/wimboot 25 | zip -j g4eext-*.zip wimboot/wimboot 26 | # make -C grubutils/fbinst OSTYPE=MINGW CC=i686-w64-mingw32-gcc 27 | # make -C grubutils/loadbin 28 | # make -C grubutils/makemod OSTYPE=MINGW CC=i686-w64-mingw32-gcc 29 | # make -C grubutils/makerom OSTYPE=MINGW CC=i686-w64-mingw32-gcc 30 | # make -C grubutils/wee 31 | # make -C grubutils/weesetup OSTYPE=MINGW CC=i686-w64-mingw32-gcc 32 | # 7z a grubutils.7z grubutils/fbinst/fbinst.exe grubutils/loadbin/*.bin grubutils/makemod/makemod.exe grubutils/makerom/makerom.exe grubutils/makerom/*.bin grubutils/weesetup/weesetup.exe 33 | 34 | - name: 上传 35 | continue-on-error: true 36 | working-directory: ${{env.GITHUB_WORKSPACE}} 37 | run: | 38 | gh release delete latest --cleanup-tag --yes 39 | gh release create latest -t "Development Build" g4dext-*.zip g4eext-*.zip 40 | env: 41 | GH_TOKEN: "${{ secrets.GITHUB_TOKEN }}" 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.tmp 3 | *.mod 4 | *.zip 5 | *.mbr 6 | *.exe 7 | umbr/bin2c 8 | umbr/umbr.h 9 | umbr/umbr 10 | g4dext/bin 11 | g4dext/zip 12 | grubutils/wee/stage2_size.h 13 | grubutils/wee/wee127/stage2_size.h 14 | g4eext/bin 15 | wimboot/build 16 | wimboot/wimboot 17 | -------------------------------------------------------------------------------- /g4dext/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 更新说明: 2 | 2023-03-28 (yaya) 3 | 增加外部定时器应用:进度条(ProgressBar)。 4 | 使用方式:ProgressBar [--no-box] 左上角x 左上角y x尺寸 y尺寸 颜色 模式 5 | 颜色:24位色 0x红红绿绿蓝蓝 6 | 模式(0-3):1.水平从左到右 2.水平从右到左 3.垂直从上到下 4.垂直从下到上 7 | 模式(4-7):0.递增 1.递减 8 | x与y采用像素表示 9 | --no-box: 在递增模式不显示边框 10 | 11 | ============================================ 12 | hotkey 13 | 热键 14 | 15 | 可选参数 16 | -nb 按键热后只选择对应菜单项,不启动. 17 | -nc 除了方向键和回车键之外,如果按下的不是热键则丢弃。用于安全性比较高的场合,比如可以禁用’c’,’e’等GRUB4DOS默认的菜单热键。防止用户进入GRUB4DOS命令行或修改菜单。 18 | -u 卸载热键 19 | -A 使用菜单首字母选择菜单 20 | 注: 使用该参数会占用菜单的控制按键(像c,b,e,p),需要使用这些功能请按住Shift.比如Shift+C进入命令行 21 | 22 | hotkey [HOTKEY] "COMMAND" 注册新热键HOTKEY,执行COMMAND 23 | hotkey [HOTKEY] 禁用热键HOTKEY 24 | 25 | 例子: 26 | hotkey -A [F3] "reboot" 27 | hotkey [Ctrl+d] "commandline" 28 | title [F4] Boot Win 8 29 | title Boot ^Win 10 30 | setmenu --hotkey-color=[COLOR] #设置热键颜色 31 | 32 | ============================================ 33 | bios 34 | 可以在GRUB4DOS下调用BIOS中断的外部命令 35 | 36 | 参数 37 | 写数据到指定端口 38 | bios outb/outw/outl PORT VALUE 39 | 从指定端口读数据 40 | bios inb/inw/inl 41 | 中断调用 42 | bios int=INT eax=EAX ebx=EBX […] 43 | 44 | 可使用的所以参数在下面的列表中 45 | unsigned long edi; // as input and output 46 | unsigned long esi; // as input and output 47 | unsigned long ebp; // as input and output 48 | unsigned long esp; // stack pointer, as input 49 | unsigned long ebx; // as input and output 50 | unsigned long edx; // as input and output 51 | unsigned long ecx; // as input and output 52 | unsigned long eax;// as input and output 53 | unsigned long gs; // as input and output 54 | unsigned long fs; // as input and output 55 | unsigned long es; // as input and output 56 | unsigned long ds; // as input and output 57 | unsigned long ss; // stack segment, as input 58 | unsigned long eip; // instruction pointer, as input, 59 | unsigned long cs; // code segment, as input 60 | unsigned long eflags; // as input and output 61 | 62 | =========================================== 63 | chkpci 64 | 在GRUB4DOS下直接检测PCI设备信息 65 | 66 | =========================================== 67 | fat 68 | 在FAT分区上复制创建文件 69 | 70 | FAT命令的目标对象必须是FAT12/16/32分区的目录和文件,目前只支持8.3格式 71 | 72 | FAT mkdir 73 | 创建一个目录,只能一级一级建立目录,不可以同时建立多级目录; 74 | 例子:FAT mkdir (hd1,0)/SRS 75 | FAT copy [/o] 76 | 从源文件拷贝到目标文件,/o 参数用于覆盖操作。 77 | 来源文件可以是任意GRUB4DOS可以访问的路径; 78 | 目标文件必须是FAT分区;并且目标目录必须存在否则会提示错误; 79 | 如果不指定目标文件名,自动使用源文件名; 80 | 例子: fat copy (hd0,0)/file.ext (hd1,0)/file.ext 81 | 82 | FAT ren 83 | 文件或目录更名/移动 84 | 例子: 85 | 1、修改当前ROOT分区下的abc.txt文件为abc.ini 86 | fat ren /abc.txt abc.ini 87 | 88 | 2、移动文件,把abc.txt移到test目录下(test目录必须已经存在) 89 | fat ren /abc.txt /test/abc.txt 90 | 91 | FAT del 92 | 删除文件或目录(只能删除空目录同DOS) 93 | 例子: 94 | 删除一个文件 95 | fat del /abc.txt 96 | 删除一个目录同删除文件一样,但要求这个目录是空目录,你必须先删除这个目录下的文件才能删除这个目录 97 | 注意:不要删除根目录 98 | 99 | FAT mkfile size=SIZE|* file 100 | 创建新文件 101 | SIZE是文件大小,可以直接用*代替,大小等于上一个cat —length=0命令的结果。 102 | 注:cat --length=0 file命令在GRUB4DOS中用于获取指定文件的大小。 103 | 104 | FAT mkfs [/A:unit-size] 105 | 格式化磁盘 106 | 107 | FAT dir [/a*] 108 | 列出路径下所有文件及目录。 109 | dir加了按属性显示的参数(同DOS的dir) 110 | d 目录 111 | s 系统属性 112 | r 只性属性 113 | h 隐藏属性 114 | - 表示否的前辍 115 | 例子: 116 | dir /ad #只显示目录 117 | dir /as #只显示有带系统属性的文件或目录 118 | dir /ads #只显示带系统属性的目录 119 | dir /a-d #不显示目录。 120 | 121 | ================================================ 122 | wenv 123 | GRUB4DOS菜单脚本命令增强. 124 | 125 | 两个内置变量: 126 | ?_WENV 保存上一次wenv call运行的返回值 127 | ?_GET 保存上一次wenv get variable变量的长度 128 | 129 | FOR 类拟于CMD的for 130 | 比较强大的一个命令,可以分析字符串,文本文件。 131 | 语法: 132 | FOR /L %variable IN (start,step,end) DO wenv-command 133 | 该集表示以增量形式从开始到结束的一个数字序列。因此,(1,1,5)将产生序列 134 | 1 2 3 4 5,(5,-1,1)将产生序列(5 4 3 2 1) 135 | 136 | FOR /F ["options"] %variable IN ( file ) DO wenv-command 137 | FOR /F ["options"] %variable IN ("string") DO wenv-command 138 | 如果有 usebackq 选项: 139 | FOR /F ["options"] %variable IN (`string`) DO wenv-command 140 | options 141 | eol=c - 指一个行注释字符的结尾(就一个) 142 | delims=xxx - 指分隔符集。这个替换了空格和跳格键的 143 | 默认分隔符集。 144 | tokens=x,y,m-n - 指每行的哪一个符号被传递到每个迭代 145 | 的 for 本身。这会导致额外变量名称的分配。m-n 146 | 格式为一个范围。通过 nth 符号指定 mth。 147 | usebackq - 反向引号 148 | 149 | 几个例子 分析myfile.txt的每一行,使用";"作为注释符,使用","分隔字符串,显示每行的第二和第三个字符串 150 | FOR /F "eol=; tokens=2,3 delims=," %i in ( myfile.txt ) do echo %i %j 151 | 152 | 显示从1-10的数字 153 | FOR /L %i in (1,1,10) do echo %i 154 | 155 | 以下语句会显示 1 2 3 6 156 | FOR /f "tokens=1-3,6" %i in ("1 2 3 4 5 6 7 8 9 0") do echo %i %j %k %l 157 | 158 | 可以参考CMD的for命令帮助说明. 159 | 160 | 161 | -------------------------------------------------------------------------------- /g4dext/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(CC),cc) 2 | CC := gcc 3 | endif 4 | OBJCOPY := objcopy 5 | RM := rm 6 | MV := mv 7 | MKDIR := mkdir 8 | 9 | DATE = $(shell date -u +%Y-%m-%d) 10 | 11 | GCCVERSIONGTEQ5 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 5) 12 | GCCVERSIONGTEQ8 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 8) 13 | GCCVERSIONGTEQ10 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \< 10) 14 | 15 | CFLAGS := -Wl,--build-id=none -m32 -mno-sse -nostdlib \ 16 | -fno-zero-initialized-in-bss -fno-function-cse \ 17 | -fshort-wchar -fno-jump-tables -Wl,-N 18 | 19 | ifeq "$(GCCVERSIONGTEQ5)" "1" 20 | CFLAGS += -no-pie 21 | else 22 | CFLAGS += -fPIE 23 | endif 24 | 25 | OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c)) fat/fat.o 26 | MODULES := $(patsubst %.c,%.mod,$(wildcard *.c)) fat/fat.mod 27 | 28 | .PHONY: all 29 | all: prepare $(MODULES) bin/fatmini 30 | cp -f ChangeLog.txt bin/ 31 | zip -9 -j ../g4dext-$(DATE).zip bin/* 32 | 33 | %.o: %.c 34 | $(CC) $(CFLAGS) -I../include/ $< -o $@ 35 | 36 | %.mod: %.o 37 | $(OBJCOPY) -O binary $< $@ 38 | 39 | #ifneq ($(A)$(B), 00),) # 'A || B' = (NOT)(NOT)'A || B' =(NOT)'(NOT)A && (NOT)B 40 | ifeq ($(GCCVERSIONGTEQ8)$(GCCVERSIONGTEQ10), 11) # $(GCCVERSIONGTEQ8) && $(GCCVERSIONGTEQ10) 41 | # echo eq 42 | dd bs=1 skip=28 if=$@ of=$@new 43 | $(MV) $@new bin/$$(basename $@new .modnew) 44 | $(RM) -f $@ 45 | else 46 | # echo neq 47 | $(MV) $@ bin/$$(basename $@ .mod) 48 | endif 49 | 50 | bin/fatmini: 51 | $(CC) $(CFLAGS) -I../include/ -DFAT_MINI fat/fat.c -o fat/fatmini.o 52 | $(OBJCOPY) -O binary fat/fatmini.o fat/fatmini.mod 53 | ifeq ($(GCCVERSIONGTEQ8)$(GCCVERSIONGTEQ10), 11) # $(GCCVERSIONGTEQ8) && $(GCCVERSIONGTEQ10) 54 | # echo eq 55 | dd bs=1 skip=28 if=fat/fatmini.mod of=fat/fatmini.modnew 56 | $(MV) fat/fatmini.modnew bin/fatmini 57 | $(RM) -f fat/fatmini.mod 58 | else 59 | # echo neq 60 | $(MV) fat/fatmini.mod bin/fatmini 61 | endif 62 | 63 | .PHONY: prepare 64 | prepare: 65 | $(MKDIR) -p bin 66 | 67 | .PHONY: clean 68 | clean: 69 | ifeq ($(GCCVERSIONGTEQ8)$(GCCVERSIONGTEQ10), 1) 70 | $(RM) -f *.o *.mod *.modnew fat/*.o fat/*.mod fat/*.modnew bin/* ../*.zip 71 | else 72 | $(RM) -f *.o *.mod fat/*.o fat/*.mod bin/* ../*.zip 73 | endif 74 | 75 | -------------------------------------------------------------------------------- /g4dext/Makefile-old: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | OBJCOPY := objcopy 3 | SED := sed 4 | RM := rm 5 | MV := mv 6 | MKDIR := mkdir 7 | 8 | _TIME_Y = `date +%-Y` 9 | _TIME_m = `date +%-m` 10 | _TIME_d = `date +%-d` 11 | _TIME_H = `date +%-H` 12 | _TIME_M = `date +%-M` 13 | _TIME_S = `date +%-S` 14 | DATE = $(shell date -u +%Y-%m-%d) 15 | ASMDATE = $(shell date -u +".long "%Y%m%d) 16 | GCCVERSIONGTEQ5 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 5) 17 | 18 | CFLAGS = -nostdlib -DASM_BUILD_DATE=\""$(ASMDATE)"\" -fno-reorder-functions \ 19 | -fno-strict-aliasing -fno-exceptions -fno-asynchronous-unwind-tables \ 20 | -fno-unwind-tables -fno-zero-initialized-in-bss -fno-function-cse \ 21 | -fno-jump-tables --entry main -Wl,-N -Wl,--build-id=none \ 22 | -m32 -mno-sse -Wl,-Ttext -Wl,0 23 | 24 | ifeq "$(GCCVERSIONGTEQ5)" "1" 25 | CFLAGS += -no-pie 26 | else 27 | CFLAGS += -fPIE 28 | endif 29 | 30 | OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c)) fat/fat.o 31 | TMPFILES := $(patsubst %.c,%.tmp,$(wildcard *.c)) fat/fat.tmp 32 | MODULES := $(patsubst %.c,%.mod,$(wildcard *.c)) fat/fat.mod 33 | 34 | .PHONY: all 35 | all: prepare $(MODULES) bin/fatmini 36 | zip -9 -j ../g4dext-$(DATE).zip bin/* 37 | 38 | %.o: %.c 39 | $(CC) $(CFLAGS) -I../include/ $< -o $@ 40 | 41 | %.tmp: %.o 42 | $(OBJCOPY) -O binary $< $@ 43 | #SED在gcc-8、gcc-9失效 44 | %.mod: %.tmp 45 | $(SED) -e '$$s/\x00*$$//' $< > $@ 46 | $(MV) $@ bin/$$(basename $@ .mod) 47 | 48 | bin/fatmini: 49 | $(CC) $(CFLAGS) -I../include/ -DFAT_MINI fat/fat.c -o fat/fatmini.o 50 | $(OBJCOPY) -O binary fat/fatmini.o fat/fatmini.tmp 51 | $(SED) -e '$$s/\x00*$$//' fat/fatmini.tmp > bin/fatmini 52 | 53 | .PHONY: prepare 54 | prepare: 55 | $(MKDIR) -p bin 56 | 57 | .PHONY: clean 58 | clean: 59 | $(RM) -f *.o *.tmp *.mod fat/*.o fat/*.tmp bin/* 60 | -------------------------------------------------------------------------------- /g4dext/bios.c: -------------------------------------------------------------------------------- 1 | #include "grub4dos.h" 2 | 3 | struct realmode_regs { 4 | unsigned long edi; // as input and output 5 | unsigned long esi; // as input and output 6 | unsigned long ebp; // as input and output 7 | unsigned long esp; // stack pointer, as input 8 | unsigned long ebx; // as input and output 9 | unsigned long edx; // as input and output 10 | unsigned long ecx; // as input and output 11 | unsigned long eax;// as input and output 12 | unsigned long gs; // as input and output 13 | unsigned long fs; // as input and output 14 | unsigned long es; // as input and output 15 | unsigned long ds; // as input and output 16 | unsigned long ss; // stack segment, as input 17 | unsigned long eip; // instruction pointer, as input, 18 | unsigned long cs; // code segment, as input 19 | unsigned long eflags; // as input and output 20 | }; 21 | static unsigned int inl(unsigned short port); 22 | static unsigned char inb(unsigned short port); 23 | static void outb(unsigned short port, char val); 24 | static unsigned short inw(unsigned short port); 25 | static void outw(unsigned short port, unsigned short val); 26 | static void outl(unsigned short port, int val); 27 | 28 | /* this is needed, see the comment in grubprog.h */ 29 | #include "grubprog.h" 30 | /* Do not insert any other asm lines here. */ 31 | 32 | int main(char *arg,int flags) 33 | { 34 | struct realmode_regs int_regs = {0,0,0,-1,0,0,0,0,-1,-1,-1,-1,-1,0,-1,-1}; 35 | unsigned long long ll; 36 | char *p; 37 | if (memcmp(arg,"int=",4) == 0) 38 | { 39 | arg += 4; 40 | if (!safe_parse_maxint(&arg,&ll)) 41 | return 0; 42 | int_regs.eip= 0xFFFF00CD | ((char)ll << 8); 43 | arg = skip_to(0,arg); 44 | while (*arg) 45 | { 46 | p = arg; 47 | arg = skip_to(1,arg); 48 | if (!safe_parse_maxint(&arg,&ll)) 49 | return 0; 50 | if (memcmp(p,"edi",3) == 0) 51 | int_regs.edi = (unsigned long)ll; 52 | else if (memcmp(p,"esi",3) == 0) 53 | int_regs.esi = (unsigned long)ll; 54 | else if (memcmp(p,"ebp",3) == 0) 55 | int_regs.ebp = (unsigned long)ll; 56 | else if (memcmp(p,"esp",3) == 0) 57 | int_regs.esp = (unsigned long)ll; 58 | else if (memcmp(p,"ebx",3) == 0) 59 | int_regs.ebx = (unsigned long)ll; 60 | else if (memcmp(p,"edx",3) == 0) 61 | int_regs.edx = (unsigned long)ll; 62 | else if (memcmp(p,"ecx",3) == 0) 63 | int_regs.ecx = (unsigned long)ll; 64 | else if (memcmp(p,"eax",3) == 0) 65 | int_regs.eax = (unsigned long)ll; 66 | else if (memcmp(p,"gs",2) == 0) 67 | int_regs.gs = (unsigned long)ll; 68 | else if (memcmp(p,"fs",2) == 0) 69 | int_regs.fs = (unsigned long)ll; 70 | else if (memcmp(p,"es",2) == 0) 71 | int_regs.es = (unsigned long)ll; 72 | else if (memcmp(p,"ds",2) == 0) 73 | int_regs.ds = (unsigned long)ll; 74 | else if (memcmp(p,"ss",2) == 0) 75 | int_regs.ss = (unsigned long)ll; 76 | else if (memcmp(p,"eip",3) == 0) 77 | int_regs.eip = (unsigned long)ll; 78 | else if (memcmp(p,"cs",2) == 0) 79 | int_regs.cs = (unsigned long)ll; 80 | else if (memcmp(p,"eflags",2) == 0) 81 | int_regs.eflags = (unsigned long)ll; 82 | else 83 | return 0; 84 | arg = skip_to(0,arg); 85 | } 86 | ll = realmode_run((long)&int_regs); 87 | flags = int_regs.eflags; 88 | printf(" EAX=%08X EBX=%08X ECX=%08X EDX=%08X ESI=%08X" 89 | "\n EDI=%08X EBP=%08X ESP=%08X EIP=%08X eFLAG=%08X" 90 | "\n DS=%04X ES=%04X FS=%04X GS=%04X SS=%04X CS=%04X %s %s %s %s %s %s %s %s", 91 | int_regs.eax,int_regs.ebx,int_regs.ecx,int_regs.edx,int_regs.esi, 92 | int_regs.edi,int_regs.ebp,int_regs.esp,int_regs.eip,flags, 93 | (short)int_regs.ds,(short)int_regs.es,(short)int_regs.fs,(short)int_regs.gs,(short)int_regs.ss,(short)int_regs.cs, 94 | (flags&(1<<11))?"OV":"NV",flags&(1<<10)?"DN":"UP",flags&(1<<9)?"EI":"DI",flags&(1<<7)?"NG":"PL", 95 | flags&(1<<6)?"ZR":"NZ",flags&(1<<4)?"AC":"NA",flags&4?"PE":"PO",flags&1?"CY":"NC" 96 | ); 97 | return int_regs.eax; 98 | } 99 | else 100 | { 101 | unsigned short port; 102 | int val; 103 | p = skip_to(1,arg); 104 | if (!safe_parse_maxint(&p,&ll)) 105 | { 106 | return 0; 107 | } 108 | port = (unsigned short)ll; 109 | if (*(unsigned short *)arg == 0x756F) 110 | { 111 | p = skip_to(0,p); 112 | if (!safe_parse_maxint(&p,&ll)) 113 | return 0; 114 | switch(arg[3]) 115 | { 116 | case 'b': 117 | outb(port,(char)ll); 118 | break; 119 | case 'w': 120 | outw(port,(unsigned short)ll); 121 | break; 122 | case 'l': 123 | outl(port,(unsigned int)ll); 124 | break; 125 | default: 126 | return 0; 127 | } 128 | return 1; 129 | } 130 | else if (*(unsigned short *)arg == 0x6E69) 131 | { 132 | switch(arg[2]) 133 | { 134 | case 'b': 135 | ll=inb(port); 136 | break; 137 | case 'w': 138 | ll=inw(port); 139 | break; 140 | case 'l': 141 | ll=inl(port); 142 | break; 143 | default: 144 | return 0; 145 | } 146 | printf("0x%X",(unsigned int)ll); 147 | return ll; 148 | } 149 | } 150 | return 0; 151 | } 152 | 153 | static unsigned int inl(unsigned short port) 154 | { 155 | int ret_val; 156 | __asm__ volatile ("inl %%dx,%%eax" : "=a" (ret_val) : "d"(port)); 157 | return (int)ret_val; 158 | } 159 | 160 | static unsigned char inb(unsigned short port) 161 | { 162 | char ret_val; 163 | __asm__ volatile ("inb %%dx,%%al" : "=a" (ret_val) : "d"(port)); 164 | return ret_val; 165 | } 166 | 167 | static unsigned short inw(unsigned short port) 168 | { 169 | unsigned short ret_val; 170 | __asm__ volatile ("inw %%dx,%%ax" : "=a" (ret_val) : "d"(port)); 171 | return ret_val; 172 | } 173 | 174 | static void outw(unsigned short port, unsigned short val) 175 | { 176 | __asm__ volatile ("outw %%ax,%%dx"::"a" (val), "d"(port)); 177 | } 178 | 179 | static void outb(unsigned short port, char val) 180 | { 181 | __asm__ volatile ("outb %%al,%%dx"::"a" (val), "d"(port)); 182 | } 183 | 184 | static void outl(unsigned short port, int val) 185 | { 186 | __asm__ volatile ("outl %%eax,%%dx" : : "a"(val), "d"(port)); 187 | } -------------------------------------------------------------------------------- /g4dext/cpuid.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define grub_cpuid(num,a,b,c,d) \ 4 | asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1" \ 5 | : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \ 6 | : "0" (num)) 7 | 8 | #include 9 | 10 | int main (char *arg,int key) 11 | { 12 | unsigned int eax, ebx, ecx, edx, leaf; 13 | unsigned long long num; 14 | if (strcmp (arg, "--pae") == 0) 15 | { 16 | grub_cpuid (1, eax, ebx, ecx, edx); 17 | return printf ("%s\n", (edx & (1 << 6))? "true" : "false"); 18 | } 19 | if (strcmp (arg, "--vendor") == 0) 20 | { 21 | char vendor[13]; 22 | grub_cpuid (0, eax, ebx, ecx, edx); 23 | memmove (&vendor[0], &ebx, 4); 24 | memmove (&vendor[4], &edx, 4); 25 | memmove (&vendor[8], &ecx, 4); 26 | vendor[12] = '\0'; 27 | return printf ("%s\n", vendor); 28 | } 29 | if (strcmp (arg, "--vmx") == 0) 30 | { 31 | grub_cpuid (1, eax, ebx, ecx, edx); 32 | return printf ("%s\n", (ecx & (1 << 5))? "true" : "false"); 33 | } 34 | if (strcmp (arg, "--hyperv") == 0) 35 | { 36 | grub_cpuid (1, eax, ebx, ecx, edx); 37 | return printf ("%s\n", (ecx & (1 << 31))? "true" : "false"); 38 | } 39 | if (strcmp (arg, "--vmsign") == 0) 40 | { 41 | char vmsign[13]; 42 | grub_cpuid (0x40000000, eax, ebx, ecx, edx); 43 | memmove (&vmsign[0], &ebx, 4); 44 | memmove (&vmsign[4], &ecx, 4); 45 | memmove (&vmsign[8], &edx, 4); 46 | vmsign[12] = '\0'; 47 | return printf ("%s\n", vmsign); 48 | } 49 | if (strcmp (arg, "--brand") == 0) 50 | { 51 | char brand[50]; 52 | memset (brand, 0, 50); 53 | grub_cpuid (0x80000002, eax, ebx, ecx, edx); 54 | memmove (&brand[0], &eax, 4); 55 | memmove (&brand[4], &ebx, 4); 56 | memmove (&brand[8], &ecx, 4); 57 | memmove (&brand[12], &edx, 4); 58 | grub_cpuid (0x80000003, eax, ebx, ecx, edx); 59 | memmove (&brand[16], &eax, 4); 60 | memmove (&brand[20], &ebx, 4); 61 | memmove (&brand[24], &ecx, 4); 62 | memmove (&brand[28], &edx, 4); 63 | grub_cpuid (0x80000004, eax, ebx, ecx, edx); 64 | memmove (&brand[32], &eax, 4); 65 | memmove (&brand[36], &ebx, 4); 66 | memmove (&brand[40], &ecx, 4); 67 | memmove (&brand[44], &edx, 4); 68 | return printf ("%s\n", brand); 69 | } 70 | if (memcmp (arg, "--eax=", 6) == 0) 71 | { 72 | char *p = arg + 6; 73 | if (safe_parse_maxint (&p, &num)) 74 | { 75 | leaf = (unsigned int) num; 76 | grub_cpuid (leaf, eax, ebx, ecx, edx); 77 | return printf ("EAX=0x%08X EBX=0x%08X ECX=0x%08X EDX=0x%08X\n", 78 | eax, ebx, ecx, edx); 79 | } 80 | return 0; 81 | } 82 | printf ("Usage: cpuid [OPTION]\nOptions:\n"); 83 | printf (" --pae Check if CPU supports PAE.\n"); 84 | printf (" --vendor Get CPU's manufacturer ID string.\n"); 85 | printf (" --vmx Check if CPU supports Virtual Machine eXtensions.\n"); 86 | printf (" --hyperv Check if hypervisor presents.\n"); 87 | printf (" --vmsign Get hypervisor signature.\n"); 88 | printf (" --brand Get CPU's processor brand string.\n"); 89 | printf (" --eax=NUM Specify value of EAX register.\n"); 90 | return 1; 91 | } 92 | -------------------------------------------------------------------------------- /g4dext/date.c: -------------------------------------------------------------------------------- 1 | #include "grub4dos.h" 2 | 3 | struct realmode_regs { 4 | unsigned long edi; // as input and output 5 | unsigned long esi; // as input and output 6 | unsigned long ebp; // as input and output 7 | unsigned long esp; // stack pointer, as input 8 | unsigned long ebx; // as input and output 9 | unsigned long edx; // as input and output 10 | unsigned long ecx; // as input and output 11 | unsigned long eax;// as input and output 12 | unsigned long gs; // as input and output 13 | unsigned long fs; // as input and output 14 | unsigned long es; // as input and output 15 | unsigned long ds; // as input and output 16 | unsigned long ss; // stack segment, as input 17 | unsigned long eip; // instruction pointer, as input, 18 | unsigned long cs; // code segment, as input 19 | unsigned long eflags; // as input and output 20 | }; 21 | static unsigned long BCD2DEC(const char *bcd,int len); 22 | 23 | /* this is needed, see the comment in grubprog.h */ 24 | #include "grubprog.h" 25 | /* Do not insert any other asm lines here. */ 26 | 27 | int main (char *arg,int flags) 28 | { 29 | struct realmode_regs int_regs = {0,0,0,-1,0,0,0,0x400,-1,-1,-1,-1,-1,0xFFFF1ACD,-1,-1}; 30 | if (!*arg) 31 | { 32 | realmode_run((long)&int_regs); 33 | return printf("%04X-%02X-%02X\n",int_regs.ecx,(char)(int_regs.edx>>8),(char)int_regs.edx); 34 | } 35 | char tmp[8]; 36 | int_regs.ecx = BCD2DEC(arg,4); 37 | int_regs.edx = (BCD2DEC(arg+5,2)<<8)+BCD2DEC(arg+8,2); 38 | int_regs.eax = 0x500; 39 | return realmode_run((long)&int_regs);; 40 | } 41 | 42 | static unsigned long BCD2DEC(const char *bcd,int len) 43 | { 44 | unsigned long dec = 0; 45 | while (len--) 46 | { 47 | dec <<= 4; 48 | dec += (*bcd++ - '0'); 49 | } 50 | return dec; 51 | } -------------------------------------------------------------------------------- /g4dext/defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Mach Operating System 3 | * Copyright (c) 1991,1990 Carnegie Mellon University 4 | * All Rights Reserved. 5 | * 6 | * Permission to use, copy, modify and distribute this software and its 7 | * documentation is hereby granted, provided that both the copyright 8 | * notice and this permission notice appear in all copies of the 9 | * software, derivative works or modified versions, and any portions 10 | * thereof, and that both notices appear in supporting documentation. 11 | * 12 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 13 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 14 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 15 | * 16 | * Carnegie Mellon requests users of this software to return to 17 | * 18 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 | * School of Computer Science 20 | * Carnegie Mellon University 21 | * Pittsburgh PA 15213-3890 22 | * 23 | * any improvements or extensions that they make and grant Carnegie Mellon 24 | * the rights to redistribute these changes. 25 | */ 26 | /* 27 | * Common definitions for Berkeley Fast File System. 28 | */ 29 | 30 | /* 31 | * Compatibility definitions for disk IO. 32 | */ 33 | 34 | /* 35 | * Disk devices do all IO in 512-byte blocks. 36 | */ 37 | #define DEV_BSIZE 512 38 | 39 | /* 40 | * Conversion between bytes and disk blocks. 41 | */ 42 | #define btodb(byte_offset) ((byte_offset) >> 9) 43 | #define dbtob(block_number) ((block_number) << 9) 44 | 45 | /* 46 | * Compatibility definitions for old type names. 47 | */ 48 | 49 | typedef unsigned char u_char; /* unsigned char */ 50 | typedef unsigned short u_short; /* unsigned short */ 51 | typedef unsigned int u_int; /* unsigned int */ 52 | 53 | typedef struct _quad_ 54 | { 55 | unsigned int val[2]; /* 2 int values make... */ 56 | } 57 | quad; /* an 8-byte item */ 58 | 59 | typedef unsigned int mach_time_t; /* an unsigned int */ 60 | typedef unsigned int mach_daddr_t; /* an unsigned int */ 61 | typedef unsigned int mach_off_t; /* another unsigned int */ 62 | 63 | typedef unsigned short mach_uid_t; 64 | typedef unsigned short mach_gid_t; 65 | typedef unsigned int mach_ino_t; 66 | 67 | #define NBBY 8 68 | 69 | /* 70 | * The file system is made out of blocks of at most MAXBSIZE units, 71 | * with smaller units (fragments) only in the last direct block. 72 | * MAXBSIZE primarily determines the size of buffers in the buffer 73 | * pool. It may be made larger without any effect on existing 74 | * file systems; however, making it smaller may make some file 75 | * systems unmountable. 76 | * 77 | * Note that the disk devices are assumed to have DEV_BSIZE "sectors" 78 | * and that fragments must be some multiple of this size. 79 | */ 80 | #define MAXBSIZE 8192 81 | #define MAXFRAG 8 82 | 83 | /* 84 | * MAXPATHLEN defines the longest permissible path length 85 | * after expanding symbolic links. 86 | * 87 | * MAXSYMLINKS defines the maximum number of symbolic links 88 | * that may be expanded in a path name. It should be set 89 | * high enough to allow all legitimate uses, but halt infinite 90 | * loops reasonably quickly. 91 | */ 92 | 93 | #define MAXPATHLEN 1024 94 | #define MAXSYMLINKS 8 95 | -------------------------------------------------------------------------------- /g4dext/diskid.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/diskid.c -------------------------------------------------------------------------------- /g4dext/echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB -- GRand Unified Bootloader 3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | /* 22 | * compile: 23 | 24 | gcc -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE echo.c 25 | 26 | * disassemble: objdump -d a.out 27 | * confirm no relocation: readelf -r a.out 28 | * generate executable: objcopy -O binary a.out echo 29 | * 30 | */ 31 | /* 32 | * to get this source code & binary: http://grub4dos-chenall.google.com 33 | * For more information.Please visit web-site at http://chenall.net 34 | * 2010-02-25 35 | */ 36 | #include "grub4dos.h" 37 | 38 | /* this is needed, see the comment in grubprog.h */ 39 | #include "grubprog.h" 40 | /* Do not insert any other asm lines here. */ 41 | 42 | int main(char *arg,int flags) 43 | { 44 | return printf ("%s\n",arg); 45 | } 46 | -------------------------------------------------------------------------------- /g4dext/fat/fat.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/fat/fat.c -------------------------------------------------------------------------------- /g4dext/fat/fat.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file R0.07 (C)ChaN, 2009 3 | /-----------------------------------------------------------------------*/ 4 | #include "ff.h" 5 | #ifndef _DISKIO 6 | 7 | #define _READONLY 0 /* 1: Read-only mode */ 8 | #define _USE_IOCTL 1 9 | 10 | #include "integer.h" 11 | #include "grub4dos.h" 12 | #define _SS_BIT 9 /* sector size bit */ 13 | /* Status of Disk Functions */ 14 | typedef BYTE DSTATUS; 15 | 16 | /* Results of Disk Functions */ 17 | typedef enum { 18 | RES_OK = 0, /* 0: Successful */ 19 | RES_ERROR, /* 1: R/W Error */ 20 | RES_WRPRT, /* 2: Write Protected */ 21 | RES_NOTRDY, /* 3: Not Ready */ 22 | RES_PARERR /* 4: Invalid Parameter */ 23 | } DRESULT; 24 | 25 | /*---------------------------------------*/ 26 | /* Prototypes for disk control functions */ 27 | 28 | DSTATUS disk_initialize (BYTE); 29 | 30 | DSTATUS disk_status(BYTE); 31 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 32 | #if _READONLY == 0 33 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 34 | #endif 35 | DRESULT disk_ioctl (BYTE, BYTE, void*); 36 | 37 | 38 | 39 | /* Disk Status Bits (DSTATUS) */ 40 | 41 | #define STA_NOINIT 0x01 /* Drive not initialized */ 42 | #define STA_NODISK 0x02 /* No medium in the drive */ 43 | #define STA_PROTECT 0x04 /* Write protected */ 44 | 45 | 46 | /* Command code for disk_ioctrl() */ 47 | 48 | /* Generic command */ 49 | #define CTRL_SYNC 0 /* Mandatory for write functions */ 50 | #define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ 51 | #define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */ 52 | #define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */ 53 | #define CTRL_POWER 4 54 | #define CTRL_LOCK 5 55 | #define CTRL_EJECT 6 56 | /* MMC/SDC command */ 57 | #define MMC_GET_TYPE 10 58 | #define MMC_GET_CSD 11 59 | #define MMC_GET_CID 12 60 | #define MMC_GET_OCR 13 61 | #define MMC_GET_SDSTAT 14 62 | /* ATA/CF command */ 63 | #define ATA_GET_REV 20 64 | #define ATA_GET_MODEL 21 65 | #define ATA_GET_SN 22 66 | //#define FAT_MINI 67 | #ifndef FAT_MINI 68 | #define DEBUG 69 | #define F_GETFREE 1 70 | #define F_DIR 1 71 | #define F_REN 1 72 | #define F_CHMOD 1 73 | #define F_MKDIR 1 74 | #define FAT_INFO 1 75 | #endif 76 | #define FAT_MKFILE 1 77 | #define F_DEL 1 78 | #define _DISKIO 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /g4dext/fat/fat_config.h: -------------------------------------------------------------------------------- 1 | #define _TIME_Y 2015 2 | #define _TIME_m 2 3 | #define _TIME_d 15 4 | #define _TIME_H 10 5 | #define _TIME_M 27 6 | #define _TIME_S 20 7 | #define GET_FATTIME 8 | -------------------------------------------------------------------------------- /g4dext/fat/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /g4dext/fat/option/00readme.txt: -------------------------------------------------------------------------------- 1 | FatFs Module Source Files R0.08 (C)ChaN, 2010 2 | 3 | 4 | FILES 5 | 6 | ffconf.h Configuration file for FatFs module. 7 | ff.h Common include file for FatFs and application module. 8 | ff.c FatFs module. 9 | diskio.h Common include file for FatFs and disk I/O module. 10 | diskio.c Skeleton of low level disk I/O module. 11 | integer.h Alternative type definitions for integer variables. 12 | option Optional external functions. 13 | 14 | Low level disk I/O module is not included in this archive because the FatFs 15 | module is only a generic file system layer and not depend on any specific 16 | storage device. You have to provide a low level disk I/O module that written 17 | to control your storage device. 18 | 19 | 20 | 21 | AGREEMENTS 22 | 23 | FatFs module is an open source software to implement FAT file system to 24 | small embedded systems. This is a free software and is opened for education, 25 | research and commercial developments under license policy of following trems. 26 | 27 | Copyright (C) 2010, ChaN, all right reserved. 28 | 29 | * The FatFs module is a free software and there is NO WARRANTY. 30 | * No restriction on use. You can use, modify and redistribute it for 31 | personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. 32 | * Redistributions of source code must retain the above copyright notice. 33 | 34 | 35 | 36 | REVISION HISTORY 37 | 38 | Feb 26, 2006 R0.00 Prototype 39 | 40 | Apr 29, 2006 R0.01 First release. 41 | 42 | Jun 01, 2006 R0.02 Added FAT12. 43 | Removed unbuffered mode. 44 | Fixed a problem on small (<32M) patition. 45 | 46 | Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM. 47 | 48 | Sep 22, 2006 R0.03 Added f_rename. 49 | Changed option _FS_MINIMUM to _FS_MINIMIZE. 50 | 51 | Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast. 52 | Fixed f_mkdir creates incorrect directory on FAT32. 53 | 54 | Feb 04, 2007 R0.04 Supported multiple drive system. (FatFs) 55 | Changed some APIs for multiple drive system. 56 | Added f_mkfs. (FatFs) 57 | Added _USE_FAT32 option. (Tiny-FatFs) 58 | 59 | Apr 01, 2007 R0.04a Supported multiple partitions on a plysical drive. (FatFs) 60 | Fixed an endian sensitive code in f_mkfs. (FatFs) 61 | Added a capability of extending the file size to f_lseek. 62 | Added minimization level 3. 63 | Fixed a problem that can collapse a sector when recreate an 64 | existing file in any sub-directory at non FAT32 cfg. (Tiny-FatFs) 65 | 66 | May 05, 2007 R0.04b Added _USE_NTFLAG option. 67 | Added FSInfo support. 68 | Fixed some problems corresponds to FAT32. (Tiny-FatFs) 69 | Fixed DBCS name can result FR_INVALID_NAME. 70 | Fixed short seek (0 < ofs <= csize) collapses the file object. 71 | 72 | Aug 25, 2007 R0.05 Changed arguments of f_read, f_write. 73 | Changed arguments of f_mkfs. (FatFs) 74 | Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs) 75 | Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs) 76 | 77 | Feb 03, 2008 R0.05a Added f_truncate(). 78 | Added f_utime(). 79 | Fixed off by one error at FAT sub-type determination. 80 | Fixed btr in f_read() can be mistruncated. 81 | Fixed cached sector is not flushed when create and close without write. 82 | 83 | Apr 01, 2008 R0.06 Added f_forward(). (Tiny-FatFs) 84 | Added string functions: fputc(), fputs(), fprintf() and fgets(). 85 | Improved performance of f_lseek() on move to the same or following cluster. 86 | 87 | Apr 01, 2009, R0.07 Merged Tiny-FatFs as a buffer configuration option. 88 | Added long file name support. 89 | Added multiple code page support. 90 | Added re-entrancy for multitask operation. 91 | Added auto cluster size selection to f_mkfs(). 92 | Added rewind option to f_readdir(). 93 | Changed result code of critical errors. 94 | Renamed string functions to avoid name collision. 95 | 96 | Apr 14, 2009, R0.07a Separated out OS dependent code on reentrant cfg. 97 | Added multiple sector size support. 98 | 99 | Jun 21, 2009, R0.07c Fixed f_unlink() may return FR_OK on error. 100 | Fixed wrong cache control in f_lseek(). 101 | Added relative path feature. 102 | Added f_chdir(). 103 | Added f_chdrive(). 104 | Added proper case conversion for extended characters. 105 | 106 | Nov 03, 2009 R0.07e Separated out configuration options from ff.h to ffconf.h. 107 | Added a configuration option, _LFN_UNICODE. 108 | Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH. 109 | Fixed name matching error on the 13 char boundary. 110 | Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. 111 | 112 | May 15, 2010, R0.08 Added a memory configuration option. (_USE_LFN) 113 | Added file lock feature. (_FS_SHARE) 114 | Added fast seek feature. (_USE_FASTSEEK) 115 | Changed some types on the API, XCHAR->TCHAR. 116 | Changed fname member in the FILINFO structure on Unicode cfg. 117 | String functions support UTF-8 encoding files on Unicode cfg. 118 | -------------------------------------------------------------------------------- /g4dext/fat/option/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ 3 | /*-----------------------------------------------------------------------*/ 4 | /* This is a stub disk I/O module that acts as front end of the existing */ 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ 6 | /*-----------------------------------------------------------------------*/ 7 | 8 | #include "diskio.h" 9 | /*-----------------------------------------------------------------------*/ 10 | /* Correspondence between physical drive number and physical drive. */ 11 | /*-----------------------------------------------------------------------*/ 12 | 13 | #define ATA 0 14 | #define MMC 1 15 | #define USB 2 16 | 17 | 18 | 19 | /*-----------------------------------------------------------------------*/ 20 | /* Inidialize a Drive */ 21 | /*-----------------------------------------------------------------------*/ 22 | 23 | DSTATUS disk_initialize ( 24 | BYTE drv /* Physical drive nmuber (0..) */ 25 | ) 26 | { 27 | if (! real_open_partition(0)) 28 | return STA_NOINIT; 29 | return 0; 30 | } 31 | 32 | 33 | 34 | /*-----------------------------------------------------------------------*/ 35 | /* Return Disk Status */ 36 | /*-----------------------------------------------------------------------*/ 37 | 38 | DSTATUS disk_status ( 39 | BYTE drv /* Physical drive nmuber (0..) */ 40 | ) 41 | { 42 | if (! real_open_partition(0)) 43 | return STA_NOINIT; 44 | return 0; 45 | } 46 | 47 | 48 | 49 | /*-----------------------------------------------------------------------*/ 50 | /* Read Sector(s) */ 51 | /*-----------------------------------------------------------------------*/ 52 | 53 | DRESULT disk_read ( 54 | BYTE drv, /* Physical drive nmuber (0..) */ 55 | BYTE *buff, /* Data buffer to store read data */ 56 | DWORD sector, /* Sector address (LBA) */ 57 | BYTE count /* Number of sectors to read (1..255) */ 58 | ) 59 | { 60 | if (! devread ((unsigned long long)sector, 0L, (unsigned long long)count << _SS_BIT ,(unsigned long long)(unsigned int)buff, GRUB_READ)) 61 | { 62 | return RES_PARERR; 63 | } 64 | return RES_OK; 65 | } 66 | 67 | 68 | 69 | /*-----------------------------------------------------------------------*/ 70 | /* Write Sector(s) */ 71 | /*-----------------------------------------------------------------------*/ 72 | /* The FatFs module will issue multiple sector transfer request 73 | / (count > 1) to the disk I/O layer. The disk function should process 74 | / the multiple sector transfer properly Do. not translate it into 75 | / multiple single sector transfers to the media, or the data read/write 76 | / performance may be drasticaly decreased. */ 77 | 78 | #if _READONLY == 0 79 | DRESULT disk_write ( 80 | BYTE drv, /* Physical drive nmuber (0..) */ 81 | const BYTE *buff, /* Data to be written */ 82 | DWORD sector, /* Sector address (LBA) */ 83 | BYTE count /* Number of sectors to write (1..255) */ 84 | ) 85 | { 86 | if (! devread ((unsigned long)sector, 0L,(unsigned long long)count << _SS_BIT ,(unsigned long long)(unsigned int)buff, GRUB_WRITE)) 87 | { 88 | return RES_PARERR; 89 | } 90 | return RES_OK; 91 | } 92 | #endif /* _READONLY */ 93 | 94 | 95 | 96 | /*-----------------------------------------------------------------------*/ 97 | /* Miscellaneous Functions */ 98 | /*-----------------------------------------------------------------------*/ 99 | 100 | DRESULT disk_ioctl ( 101 | BYTE drv, /* Physical drive nmuber (0..) */ 102 | BYTE ctrl, /* Control code */ 103 | void *buff /* Buffer to send/receive control data */ 104 | ) 105 | { 106 | return 0; 107 | //return RES_PARERR; 108 | } 109 | 110 | DWORD get_fattime (void) 111 | { 112 | return 0; 113 | }; 114 | 115 | -------------------------------------------------------------------------------- /g4dext/fat/option/diskio.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file R0.07 (C)ChaN, 2009 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO 6 | 7 | #define _READONLY 0 /* 1: Read-only mode */ 8 | #define _USE_IOCTL 1 9 | 10 | #include "integer.h" 11 | #include "grub4dos.h" 12 | #define _SS_BIT 9 /* sector size bit */ 13 | /* Status of Disk Functions */ 14 | typedef BYTE DSTATUS; 15 | 16 | /* Results of Disk Functions */ 17 | typedef enum { 18 | RES_OK = 0, /* 0: Successful */ 19 | RES_ERROR, /* 1: R/W Error */ 20 | RES_WRPRT, /* 2: Write Protected */ 21 | RES_NOTRDY, /* 3: Not Ready */ 22 | RES_PARERR /* 4: Invalid Parameter */ 23 | } DRESULT; 24 | 25 | /*---------------------------------------*/ 26 | /* Prototypes for disk control functions */ 27 | 28 | DSTATUS disk_initialize (BYTE); 29 | DSTATUS disk_status (BYTE); 30 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 31 | #if _READONLY == 0 32 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 33 | #endif 34 | DRESULT disk_ioctl (BYTE, BYTE, void*); 35 | 36 | 37 | 38 | /* Disk Status Bits (DSTATUS) */ 39 | 40 | #define STA_NOINIT 0x01 /* Drive not initialized */ 41 | #define STA_NODISK 0x02 /* No medium in the drive */ 42 | #define STA_PROTECT 0x04 /* Write protected */ 43 | 44 | 45 | /* Command code for disk_ioctrl() */ 46 | 47 | /* Generic command */ 48 | #define CTRL_SYNC 0 /* Mandatory for write functions */ 49 | #define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ 50 | #define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */ 51 | #define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */ 52 | #define CTRL_POWER 4 53 | #define CTRL_LOCK 5 54 | #define CTRL_EJECT 6 55 | /* MMC/SDC command */ 56 | #define MMC_GET_TYPE 10 57 | #define MMC_GET_CSD 11 58 | #define MMC_GET_CID 12 59 | #define MMC_GET_OCR 13 60 | #define MMC_GET_SDSTAT 14 61 | /* ATA/CF command */ 62 | #define ATA_GET_REV 20 63 | #define ATA_GET_MODEL 21 64 | #define ATA_GET_SN 22 65 | 66 | 67 | #define _DISKIO 68 | #endif 69 | -------------------------------------------------------------------------------- /g4dext/fat/option/syscall.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample code of OS dependent controls for FatFs R0.08 */ 3 | /* (C)ChaN, 2010 */ 4 | /*------------------------------------------------------------------------*/ 5 | 6 | #include /* ANSI memory controls */ 7 | #include /* ANSI memory controls */ 8 | 9 | #include "../ff.h" 10 | 11 | 12 | #if _FS_REENTRANT 13 | /*------------------------------------------------------------------------*/ 14 | /* Create a Synchronization Object 15 | /*------------------------------------------------------------------------*/ 16 | /* This function is called in f_mount function to create a new 17 | / synchronization object, such as semaphore and mutex. When a FALSE is 18 | / returned, the f_mount function fails with FR_INT_ERR. 19 | */ 20 | 21 | BOOL ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */ 22 | BYTE vol, /* Corresponding logical drive being processed */ 23 | _SYNC_t *sobj /* Pointer to return the created sync object */ 24 | ) 25 | { 26 | BOOL ret; 27 | 28 | *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */ 29 | ret = (*sobj != INVALID_HANDLE_VALUE) ? TRUE : FALSE; 30 | 31 | // *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */ 32 | // ret = TRUE; /* The initial value of the semaphore must be 1. */ 33 | 34 | // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */ 35 | // ret = (err == OS_NO_ERR) ? TRUE : FALSE; 36 | 37 | // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */ 38 | // ret = (*sobj != NULL) ? TRUE : FALSE; 39 | 40 | return ret; 41 | } 42 | 43 | 44 | 45 | /*------------------------------------------------------------------------*/ 46 | /* Delete a Synchronization Object */ 47 | /*------------------------------------------------------------------------*/ 48 | /* This function is called in f_mount function to delete a synchronization 49 | / object that created with ff_cre_syncobj function. When a FALSE is 50 | / returned, the f_mount function fails with FR_INT_ERR. 51 | */ 52 | 53 | BOOL ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */ 54 | _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ 55 | ) 56 | { 57 | BOOL ret; 58 | 59 | ret = CloseHandle(sobj); /* Win32 * 60 | 61 | // ret = TRUE; /* uITRON (nothing to do) * 62 | 63 | // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */ 64 | // ret = (err == OS_NO_ERR) ? TRUE : FALSE; 65 | 66 | // ret = TRUE; /* FreeRTOS (nothing to do) */ 67 | 68 | return ret; 69 | } 70 | 71 | 72 | 73 | /*------------------------------------------------------------------------*/ 74 | /* Request Grant to Access the Volume */ 75 | /*------------------------------------------------------------------------*/ 76 | /* This function is called on entering file functions to lock the volume. 77 | / When a FALSE is returned, the file function fails with FR_TIMEOUT. 78 | */ 79 | 80 | BOOL ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */ 81 | _SYNC_t sobj /* Sync object to wait */ 82 | ) 83 | { 84 | BOOL ret; 85 | 86 | ret = (WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0) ? TRUE : FALSE; /* Win32 */ 87 | 88 | // ret = (wai_sem(sobj) == E_OK) ? TRUE : FALSE; /* uITRON */ 89 | 90 | // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */ 91 | // ret = (err == OS_NO_ERR) ? TRUE : FALSE; 92 | 93 | // ret = (xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE) ? TRUE : FALSE; /* FreeRTOS */ 94 | 95 | return ret; 96 | } 97 | 98 | 99 | 100 | /*------------------------------------------------------------------------*/ 101 | /* Release Grant to Access the Volume */ 102 | /*------------------------------------------------------------------------*/ 103 | /* This function is called on leaving file functions to unlock the volume. 104 | */ 105 | 106 | void ff_rel_grant ( 107 | _SYNC_t sobj /* Sync object to be signaled */ 108 | ) 109 | { 110 | ReleaseMutex(sobj); /* Win32 */ 111 | 112 | // sig_sem(sobj); /* uITRON */ 113 | 114 | // OSMutexPost(sobj); /* uC/OS-II */ 115 | 116 | // xSemaphoreGive(sobj); /* FreeRTOS */ 117 | 118 | } 119 | 120 | #endif 121 | 122 | 123 | 124 | 125 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ 126 | /*------------------------------------------------------------------------*/ 127 | /* Allocate a memory block */ 128 | /*------------------------------------------------------------------------*/ 129 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. 130 | */ 131 | 132 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ 133 | UINT size /* Number of bytes to allocate */ 134 | ) 135 | { 136 | return malloc(size); 137 | } 138 | 139 | 140 | /*------------------------------------------------------------------------*/ 141 | /* Free a memory block */ 142 | /*------------------------------------------------------------------------*/ 143 | 144 | void ff_memfree( 145 | void* mblock /* Pointer to the memory block to free */ 146 | ) 147 | { 148 | free(mblock); 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /g4dext/font/Mbcs/Mbcs.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/font/Mbcs/Mbcs.c -------------------------------------------------------------------------------- /g4dext/font/Mbcs/Mbcs.h: -------------------------------------------------------------------------------- 1 | // Mbcs.h 2 | // 3 | 4 | #if !defined(AFX_MBCS_H__6E6D67A4_78AE_410B_B728_2464EF2E40C7__INCLUDED_) 5 | #define AFX_MBCS_H__6E6D67A4_78AE_410B_B728_2464EF2E40C7__INCLUDED_ 6 | 7 | #include "../../include/typedef.h" 8 | 9 | DWORD ReadCharDistX_M(WORD wCode); 10 | 11 | 12 | #endif // !defined(AFX_MBCS_H__6E6D67A4_78AE_410B_B728_2464EF2E40C7__INCLUDED_) 13 | -------------------------------------------------------------------------------- /g4dext/font/Unicode/unicode.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/font/Unicode/unicode.c -------------------------------------------------------------------------------- /g4dext/font/Unicode/unicode.h: -------------------------------------------------------------------------------- 1 | // unicode.h 2 | // 3 | 4 | #if !defined(AFX_FONT_UNICODE_H__6E6D67A4_78AE_410B_B728_2464EF2E40C7__INCLUDED_) 5 | #define AFX_FONT_UNICODE_H__6E6D67A4_78AE_410B_B728_2464EF2E40C7__INCLUDED_ 6 | 7 | #include "../../include/typedef.h" 8 | 9 | int ReadFontSection(); 10 | void ReleaseSection(); 11 | DWORD ReadCharDistX_U(WORD wCode); 12 | 13 | 14 | #endif // !defined(AFX_FONT_UNICODE_H__6E6D67A4_78AE_410B_B728_2464EF2E40C7__INCLUDED_) 15 | -------------------------------------------------------------------------------- /g4dext/font/font.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/font/font.c -------------------------------------------------------------------------------- /g4dext/font/font.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/font/font.h -------------------------------------------------------------------------------- /g4dext/inifile.c: -------------------------------------------------------------------------------- 1 | #include "grub4dos.h" 2 | static int inifile(char *section,char *item,char *value); 3 | static unsigned long long pos; 4 | static char *buff; 5 | static int setenvi = 0; 6 | static char *trim(char *string); 7 | 8 | /* this is needed, see the comment in grubprog.h */ 9 | #include "grubprog.h" 10 | /* Do not insert any other asm lines here. */ 11 | 12 | int main (char *arg,int flags) 13 | { 14 | char *section = NULL; 15 | char *item = NULL; 16 | char *value = NULL; 17 | int ret = 0; 18 | if (!(buff = malloc(32<<10))) 19 | return 0; 20 | if (!open(arg)) 21 | goto quit; 22 | section = skip_to(0,arg); 23 | item = strstr(++section,"]"); 24 | if (!item) 25 | goto quit; 26 | *item++ = 0; 27 | item = skip_to(0x200,item); 28 | if (substring("/B",item,1) != 1) 29 | { 30 | setenvi = 1; 31 | item = skip_to(0x200,item); 32 | } 33 | if (value = strstr(item,"=")) 34 | { 35 | *value++ = 0; 36 | value = trim(value); 37 | } 38 | else 39 | { 40 | value=skip_to(0x201,item); 41 | if (!*value) 42 | value = NULL; 43 | } 44 | ret = inifile(section,item,value); 45 | quit: 46 | close(); 47 | free(buff); 48 | return ret; 49 | } 50 | 51 | static char *trim(char *string) 52 | { 53 | char *s; 54 | while (*string == ' ' || *string == '\t') 55 | ++string; 56 | s = string; 57 | string += strlen(string)-1; 58 | while (*string == ' ' || *string == '\t') 59 | { 60 | --string; 61 | } 62 | string[1] = 0; 63 | return s; 64 | } 65 | 66 | static char *check_eof(char *line) 67 | { 68 | if (line == NULL) 69 | return NULL; 70 | char *s1 = line; 71 | while (*line) 72 | { 73 | if (*line == ';') 74 | { 75 | *line = 0; 76 | break; 77 | } 78 | if (*line == '\"') 79 | { 80 | while (*++line && *line != '\"') 81 | ; 82 | } 83 | if (*line) 84 | ++line; 85 | } 86 | s1 = trim(s1); 87 | return *s1?s1:NULL; 88 | } 89 | 90 | static int read_line(char *buf) 91 | { 92 | char *s1 = buf; 93 | pos = filepos; 94 | while (read((unsigned long long)(int)buf,1,GRUB_READ) == 1) 95 | { 96 | if (*buf == '\r' || *buf == '\n') 97 | { 98 | if (s1 == buf) 99 | { 100 | pos = filepos; 101 | continue; 102 | } 103 | break; 104 | } 105 | else if (!*buf) 106 | { 107 | filepos = filemax; 108 | break; 109 | } 110 | ++buf; 111 | } 112 | *buf = 0; 113 | return buf - s1; 114 | } 115 | 116 | static int find_section(char *section) 117 | { 118 | static char *s; 119 | int ret = 0; 120 | if (!*section) 121 | return 1; 122 | while ((read_line(buff))) 123 | { 124 | if (*buff != '[') 125 | continue; 126 | s = strstr(buff,"]"); 127 | *s = 0; 128 | s = buff + 1; 129 | s = trim(s); 130 | if (substring(section,s,1) == 0) 131 | { 132 | ret = 1; 133 | break; 134 | } 135 | } 136 | return ret; 137 | } 138 | 139 | static int inifile(char *section,char *item,char *value) 140 | { 141 | char *s1,*s2; 142 | int ret = 0; 143 | int len; 144 | int remove_section = (substring(item,"/remove",1) == 0); 145 | section = trim(section); 146 | item = trim(item); 147 | if (remove_section && !*section) 148 | return 0; 149 | while (find_section(section)) 150 | { 151 | if (remove_section) 152 | { 153 | filepos = pos; 154 | ret = read((unsigned long long)(unsigned int)"[*",2,GRUB_WRITE); 155 | continue; 156 | } 157 | while (len = (read_line(buff))) 158 | { 159 | if (*buff == '[') 160 | { 161 | filepos = pos; 162 | break; 163 | } 164 | s1 = check_eof(buff); 165 | if (s1) 166 | { 167 | s2 = skip_to(0x201,s1); 168 | if (!*item) 169 | { 170 | if (setenvi) 171 | { 172 | ret = envi_cmd(s1,s2,0); 173 | } 174 | else 175 | ret = printf("%s=%s\r\n",s1,s2); 176 | } 177 | else if (substring(item,s1,1) == 0) 178 | { 179 | if (value) 180 | { 181 | filepos = pos; 182 | if (substring(value,"/d",1) == 0) 183 | ret = read((unsigned long long)(unsigned int)";",1,GRUB_WRITE); 184 | else 185 | { 186 | ret = sprintf(buff,"%s=%s",item,value); 187 | if (ret > len) 188 | return 0; 189 | ret = read((unsigned long long)(unsigned int)buff,ret,GRUB_WRITE); 190 | if (ret < len) 191 | read((unsigned long long)(unsigned int)";",1,GRUB_WRITE); 192 | } 193 | } 194 | else if (setenvi) 195 | { 196 | ret = envi_cmd(s1,s2,0); 197 | } 198 | else 199 | return printf("%s",s2); 200 | } 201 | } 202 | } 203 | if (!*section) 204 | return ret; 205 | } 206 | return ret; 207 | } 208 | 209 | 210 | 211 | 212 | -------------------------------------------------------------------------------- /g4dext/main.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB -- GRand Unified Bootloader 3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | /* 22 | * compile: 23 | 24 | gcc -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE wenv.c 25 | 26 | * disassemble: objdump -d a.out 27 | * confirm no relocation: readelf -r a.out 28 | * generate executable: objcopy -O binary a.out wenv 29 | * 30 | */ 31 | /* 32 | * to get this source code & binary: http://grub4dos-chenall.google.com 33 | * For more information.Please visit web-site at http://www.chenall.com 34 | * 2010-02-25 35 | */ 36 | #include "grub4dos.h" 37 | 38 | int GRUB = 0x42555247;/* this is needed, see the following comment. */ 39 | /* gcc treat the following as data only if a global initialization like the 40 | * above line occurs. 41 | */ 42 | 43 | asm(".long 0x534F4434"); 44 | 45 | /* a valid executable file for grub4dos must end with these 8 bytes */ 46 | asm(".long 0x03051805"); 47 | asm(".long 0xBCBAA7BA"); 48 | 49 | /* thank goodness gcc will place the above 8 bytes at the end of the b.out 50 | * file. Do not insert any other asm lines here. 51 | */ 52 | 53 | int 54 | main () 55 | { 56 | void *p = &main; 57 | char *arg = p - (*(int *)(p - 8)); 58 | int flags = (*(int *)(p - 12)); 59 | return wenv_func (arg , flags); 60 | } 61 | -------------------------------------------------------------------------------- /g4dext/menuset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB -- GRand Unified Bootloader 3 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | 21 | /* 22 | * compile: 23 | 24 | gcc -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE menuset.c 25 | 26 | * disassemble: objdump -d a.out 27 | * confirm no relocation: readelf -r a.out 28 | * generate executable: objcopy -O binary a.out menuset 29 | * 30 | */ 31 | /* 32 | * to get this source code & binary: http://grub4dos-chenall.google.com 33 | * For more information.Please visit web-site at http://chenall.net 34 | * 2010-05-20 35 | */ 36 | #include "grub4dos.h" 37 | 38 | struct broder { 39 | unsigned char disp_ul; 40 | unsigned char disp_ur; 41 | unsigned char disp_ll; 42 | unsigned char disp_lr; 43 | unsigned char disp_horiz; 44 | unsigned char disp_vert; 45 | unsigned char menu_box_x; /* line start */ 46 | unsigned char menu_box_w; /* line width */ 47 | unsigned char menu_box_y; /* first line number */ 48 | unsigned char menu_box_h; 49 | unsigned char menu_box_b; 50 | } __attribute__ ((packed)); 51 | 52 | /* this is needed, see the comment in grubprog.h */ 53 | #include "grubprog.h" 54 | /* Do not insert any other asm lines here. */ 55 | 56 | int main (char *arg, int flags) 57 | { 58 | struct broder tmp_broder = {218,191,192,217,196,179,2,76,2,0,0}; 59 | char *p=(char *)&tmp_broder; 60 | int i; 61 | unsigned long long val; 62 | 63 | if (*arg) 64 | { 65 | memmove ((char *)&tmp_broder,menu_border,sizeof(tmp_broder)); 66 | } 67 | 68 | for (i=0;i< 11 && *arg;i++) 69 | { 70 | if (safe_parse_maxint(&arg, &val)) 71 | { 72 | val &= 0xff; 73 | if (val) 74 | { 75 | *p = (unsigned char)val ; 76 | } 77 | } 78 | else 79 | { 80 | (*p = *arg); 81 | } 82 | p++; 83 | arg = skip_to (0, arg); 84 | } 85 | if (tmp_broder.menu_box_h > current_term->max_lines - tmp_broder.menu_box_y) 86 | { 87 | tmp_broder.menu_box_h = 0; 88 | } 89 | if (tmp_broder.menu_box_w > current_term->chars_per_line-2) tmp_broder.menu_box_w = current_term->chars_per_line-2; 90 | if (tmp_broder.menu_box_x > current_term->chars_per_line-2) tmp_broder.menu_box_x = 2; 91 | if (tmp_broder.menu_box_x + tmp_broder.menu_box_w > current_term->chars_per_line-2) tmp_broder.menu_box_x = current_term->chars_per_line-2 - tmp_broder.menu_box_w; 92 | 93 | memmove (menu_border,(char *)&tmp_broder,sizeof(tmp_broder)); 94 | return 1; 95 | } 96 | -------------------------------------------------------------------------------- /g4dext/snake.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/snake.c -------------------------------------------------------------------------------- /g4dext/time.c: -------------------------------------------------------------------------------- 1 | #include "grub4dos.h" 2 | 3 | struct realmode_regs { 4 | unsigned long edi; // as input and output 5 | unsigned long esi; // as input and output 6 | unsigned long ebp; // as input and output 7 | unsigned long esp; // stack pointer, as input 8 | unsigned long ebx; // as input and output 9 | unsigned long edx; // as input and output 10 | unsigned long ecx; // as input and output 11 | unsigned long eax;// as input and output 12 | unsigned long gs; // as input and output 13 | unsigned long fs; // as input and output 14 | unsigned long es; // as input and output 15 | unsigned long ds; // as input and output 16 | unsigned long ss; // stack segment, as input 17 | unsigned long eip; // instruction pointer, as input, 18 | unsigned long cs; // code segment, as input 19 | unsigned long eflags; // as input and output 20 | }; 21 | static unsigned long BCD2DEC(const char *bcd,int len); 22 | 23 | /* this is needed, see the comment in grubprog.h */ 24 | #include "grubprog.h" 25 | /* Do not insert any other asm lines here. */ 26 | 27 | /* 28 | INT 1aH 03H: Set Time on Real-Time Clock 29 | Expects: AH 03H 30 | 31 | CH hours, in BCD^ 32 | 33 | CL minutes, in BCD 34 | 35 | DH seconds, in BCD 36 | 37 | DL 00h = no Daylight Savings Time option 38 | 39 | 01h = Daylight Savings Time option 40 | 41 | Returns: AH 0 42 | 43 | AL value written to CMOS 0bH register 44 | 45 | CF NC (0) clock operating 46 | 47 | CY (1) clock not operating or busy being updated 48 | */ 49 | 50 | int main (char *arg,int flags) 51 | { 52 | struct realmode_regs int_regs = {0,0,0,-1,0,0,0,0x200,-1,-1,-1,-1,-1,0xFFFF1ACD,-1,-1}; 53 | if (!*arg) 54 | { 55 | realmode_run((long)&int_regs); 56 | return printf("%02X:%02X:%02X\n",(unsigned char)(int_regs.ecx>>8),(unsigned char)(int_regs.ecx),(unsigned char)(int_regs.edx>>8)); 57 | } 58 | char tmp[8]; 59 | int_regs.ecx = (BCD2DEC(arg,2)<<8)|BCD2DEC(arg+3,2); 60 | int_regs.edx = BCD2DEC(arg+6,2)<<8; 61 | int_regs.eax = 0x300; 62 | return realmode_run((long)&int_regs);; 63 | } 64 | 65 | static unsigned long BCD2DEC(const char *bcd,int len) 66 | { 67 | unsigned long dec = 0; 68 | while (len--) 69 | { 70 | dec <<= 4; 71 | dec += (*bcd++&0xF); 72 | } 73 | return dec; 74 | } -------------------------------------------------------------------------------- /g4dext/unifont.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/unifont.c -------------------------------------------------------------------------------- /g4dext/unitest.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/unitest.c -------------------------------------------------------------------------------- /g4dext/vbmp.c: -------------------------------------------------------------------------------- 1 | #include "grub4dos.h" 2 | 3 | struct realmode_regs { 4 | unsigned long edi; // as input and output 5 | unsigned long esi; // as input and output 6 | unsigned long ebp; // as input and output 7 | unsigned long esp; // stack pointer, as input 8 | unsigned long ebx; // as input and output 9 | unsigned long edx; // as input and output 10 | unsigned long ecx; // as input and output 11 | unsigned long eax;// as input and output 12 | unsigned long gs; // as input and output 13 | unsigned long fs; // as input and output 14 | unsigned long es; // as input and output 15 | unsigned long ds; // as input and output 16 | unsigned long ss; // stack segment, as input 17 | unsigned long eip; // instruction pointer, as input, 18 | unsigned long cs; // code segment, as input 19 | unsigned long eflags; // as input and output 20 | }; 21 | 22 | /* this is needed, see the comment in grubprog.h */ 23 | #include "grubprog.h" 24 | /* Do not insert any other asm lines here. */ 25 | 26 | int 27 | main (char *arg,int flags) 28 | { 29 | /* 30 | 通过调用BIOS 10h替换系统字模来显示汉字 31 | 入口: ax=1100h 32 | bh=字模的高度(有效值:0~20h,默认值:10h) 33 | bl=被替换的字模集代号(有效值:0~7) 34 | cx=要替换的字模数 35 | dx=被替换的第一个字模所对应的字符的ASCII 36 | es:bp=新字模起始地址 37 | int 10h 38 | 恢复系统原字符集: 39 | ax=1104h 40 | bl=字模集代号(有效值:0~7) 41 | int 10h 42 | */ 43 | struct realmode_regs int_regs = {0,0,0,-1,0,0,0,0x1104,-1,-1,-1,-1,-1,0xFFFF10CD,-1,-1}; 44 | /* 45 | 详请请查看以下贴子。 46 | http://bbs.znpc.net/viewthread.php?tid=5838&page=12&fromuid=29#pid46781 47 | 只是希望运行一条简单的 int 软中断指令,则用户应该设置 CS=0xFFFFFFFF, EIP=0xFFFFXXCD。其中 XX 表示中断号。 48 | */ 49 | if (*arg == 0)//如果没有任何参数,则恢复字模 50 | { 51 | return realmode_run((long)&int_regs); 52 | } 53 | 54 | if (!open(arg)) 55 | { 56 | unsigned long long addr = 0LL; 57 | if (safe_parse_maxint(&arg,&addr))//这一部份只供测试代码使用。 58 | { 59 | errnum = 0; 60 | int_regs.eip = addr & 0xFFFFFFFF; 61 | int_regs.cs = int_regs.es = int_regs.ds = addr >> 32; 62 | int_regs.esp = -1; 63 | return realmode_run((long)&int_regs); 64 | } 65 | errnum = 0; 66 | return !printf("Error: open_file\n"); 67 | } 68 | 69 | typedef unsigned long DWORD; 70 | typedef unsigned long LONG; 71 | typedef unsigned short WORD; 72 | struct { /* bmfh */ 73 | WORD bfType; 74 | DWORD bfSize; 75 | DWORD bfReserved1; 76 | DWORD bfOffBits; 77 | } __attribute__ ((packed)) bmfh; 78 | struct { /* bmih */ 79 | DWORD biSize; 80 | LONG biWidth; 81 | LONG biHeight; 82 | WORD biPlanes; 83 | WORD biBitCount; 84 | DWORD biCompression; 85 | DWORD biSizeImage; 86 | LONG biXPelsPerMeter; 87 | LONG biYPelsPerMeter; 88 | DWORD biClrUsed; 89 | DWORD biClrImportant; 90 | } __attribute__ ((packed)) bmih; 91 | 92 | if (! read((unsigned long long)(unsigned int)&bmfh,sizeof(bmfh),GRUB_READ) || bmfh.bfType != 0x4d42) 93 | { 94 | close(); 95 | return !printf("Err: fil"); 96 | } 97 | if (! read((unsigned long long)(unsigned int)&bmih,sizeof(bmih),GRUB_READ)) 98 | { 99 | close(); 100 | return !printf("Error:read1\n"); 101 | } 102 | 103 | /* 104 | 入口: ax=1100h 105 | bh=字模的高度(有效值:0~20h,默认值:10h) 106 | bl=被替换的字模集代号(有效值:0~7) 107 | cx=要替换的字模数 108 | dx=被替换的第一个字模所对应的字符的ASCII 109 | es:bp=新字模起始地 110 | */ 111 | int perline_char = (bmih.biWidth + 31)>>5<<2; 112 | int i,j; 113 | char s1[perline_char+4]; 114 | unsigned int size = (bmih.biHeight + 15) >> 4; 115 | char ch = 0xb0; 116 | if (size * perline_char > 79) 117 | { 118 | close(); 119 | return 0; 120 | } 121 | filepos = bmfh.bfOffBits; 122 | while (size--) 123 | { 124 | char *chars = (char *)0x40000 + size * perline_char * 16; 125 | for (i=15;i>=0;--i) 126 | { 127 | read((unsigned long long)(unsigned int)s1,perline_char,GRUB_READ); 128 | char *s = s1; 129 | for (j=0;j> 4) * perline_char; 140 | int_regs.eax = 0x1100; 141 | int_regs.ebx = 0x1000; 142 | int_regs.ecx = size; 143 | int_regs.edx = 0xb0; 144 | int_regs.es = 0x4000; 145 | int_regs.ebp = 0; 146 | realmode_run((long)&int_regs); 147 | return 1; 148 | } 149 | -------------------------------------------------------------------------------- /g4dext/vfont.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4dext/vfont.c -------------------------------------------------------------------------------- /g4eext/ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 更新说明: 2 | 2025-05-10 (yaya) 3 | 增加ntboot命令行选项:设置具体图形分辨率。 4 | 如:gfxmode=800x600 5 | 6 | 2025-03-24 (yaya) 7 | 增加 gbk2uni,用于支持网起文件名含有中文及空格。例如:set gbk2uni=/efi/grub/ext/gbk2uni 8 | 9 | 2024-12-16 (yaya) 10 | 1. fat 支持长文件名(只限英文)。支持将镜象格式化为卷或者磁盘。 11 | 2. ntboot 支持网起 wim。例:/efi/grub/ext/ntboot (http)/boot/imgs/boot.wim 12 | 13 | 2023-11-27 (yaya) 14 | 1. ntboot增加 --test 参数,用于产生一个启动 wim 的 bcd 实例。 15 | 可以在虚拟机网起环境执行。其他情况要在实机执行,因为一般虚拟机是只读的。 16 | 示例:ntboot --test /boot/imgs/pe64.wim 17 | 18 | 2. 增加函数 WIMname。用于 pxe 网起 wim 时,修改 bcd 文件内的 wim 文件名称。 19 | 示例:/efi/grub/ext/wimname /boot/imgs/pe64.wim 20 | 21 | 2023-07-15 (yaya) 22 | ntboot 支持外部命令尾续。 23 | 使用方法有所改变。 24 | 1. 启动 Windows WIM/VHD 25 | title Boot Windows NT6+ vhd(PE) 26 | find /efi/grub/ext/ntboot | set bd= 27 | find --set-root /boot/imgs/winpe.vhd 28 | %bd%/efi/grub/ext/ntboot /boot/imgs/winpe.vhd winload=/Windows/System32/boot/winload.efi minint=1 29 | boot 30 | 31 | title Boot Windows NT6+ wim 32 | find /efi/grub/ext/ntboot | set bd= 33 | find --set-root /boot/imgs/winpe.wim 34 | %bd%/efi/grub/ext/ntboot /boot/imgs/winpe.wim 35 | boot 36 | 37 | 2. 启动 Windows 系统 38 | 假设系统文件夹位于 (hdx,y) 39 | title Boot Windows 40 | /efi/grub/ext/ntboot (hdx,y)/win 41 | boot 42 | 43 | 2023-07-01 (yaya) 44 | 增加 ntboot,用于在 x64 UEFI 启动 WIM/VHD 45 | 支持 MBR 主分区及逻辑分区、GPT 任意分区 46 | 支持 FAT, NTFS, exFAT 文件系统 (VHD 不能位于 FAT 分区,老版本 Windows VHD 只能位于 NTFS 分区) 47 | 文件路径最好是不带空格的英文字母/数字。带空格的话传递参数时用符号"\ "代替空格。 48 | 命令行长度不得超过255。 49 | 50 | 命令行选项: 51 | 1、设置 Windows PE 加载选项。 52 | winload=/Windows/System32/boot/winload.efi 53 | 54 | 2、指定 winload.exe/winload.efi 的路径。 55 | sysroot=/Windows 56 | 57 | 3、指定 Windows 系统根目录。 58 | secureboot=off 59 | 60 | 4、启动到 WinPE 模式。 61 | minint=1 62 | 63 | 5、指定最大分辨率 64 | hires=1 65 | 66 | 2023-03-28 (yaya) 67 | 增加外部定时器应用:进度条(ProgressBar)。 68 | 使用方式:ProgressBar [--no-box] 左上角x 左上角y x尺寸 y尺寸 颜色 模式 69 | 颜色:24位色 0x红红绿绿蓝蓝 70 | 模式(0-3):1.水平从左到右 2.水平从右到左 3.垂直从上到下 4.垂直从下到上 71 | 模式(4-7):0.递增 1.递减 72 | x与y采用像素表示 73 | --no-box: 在递增模式不显示边框 74 | 75 | ================================================== 76 | hotkey 77 | 热键 78 | 79 | 可选参数 80 | -nb 按键热后只选择对应菜单项,不启动. 81 | -nc 除了方向键和回车键之外,如果按下的不是热键则丢弃。用于安全性比较高的场合,比如可以禁用’c’,’e’等GRUB4DOS默认的菜单热键。防止用户进入GRUB4DOS命令行或修改菜单。 82 | -u 卸载热键 83 | -A 使用菜单首字母选择菜单 84 | 注: 使用该参数会占用菜单的控制按键(像c,b,e,p),需要使用这些功能请按住Shift.比如Shift+C进入命令行 85 | 86 | hotkey [HOTKEY] "COMMAND" 注册新热键HOTKEY,执行COMMAND 87 | hotkey [HOTKEY] 禁用热键HOTKEY 88 | 89 | 例子: 90 | hotkey -A [F3] "reboot" 91 | hotkey [Ctrl+d] "commandline" 92 | title [F4] Boot Win 8 93 | title Boot ^Win 10 94 | setmenu --hotkey-color=[COLOR] #设置热键颜色 95 | 96 | ============================================ 97 | chkpci 98 | 在GRUB4DOS下直接检测PCI设备信息 99 | 100 | =========================================== 101 | fat 102 | 在FAT分区上复制创建文件 103 | 104 | FAT命令的目标对象必须是FAT12/16/32分区的目录和文件 105 | 106 | FAT mkdir 107 | 创建一个目录,只能一级一级建立目录,不可以同时建立多级目录; 108 | 例子:FAT mkdir (hd1,0)/SRS 109 | FAT copy [/o] 110 | 从源文件拷贝到目标文件,/o 参数用于覆盖操作。 111 | 来源文件可以是任意GRUB4DOS可以访问的路径; 112 | 目标文件必须是FAT分区;并且目标目录必须存在否则会提示错误; 113 | 如果不指定目标文件名,自动使用源文件名; 114 | 例子: fat copy (hd0,0)/file.ext (hd1,0)/file.ext 115 | 116 | FAT ren 117 | 文件或目录更名/移动 118 | 例子: 119 | 1、修改当前ROOT分区下的abc.txt文件为abc.ini 120 | fat ren /abc.txt abc.ini 121 | 122 | 2、移动文件,把abc.txt移到test目录下(test目录必须已经存在) 123 | fat ren /abc.txt /test/abc.txt 124 | 125 | FAT del 126 | 删除文件或目录(只能删除空目录同DOS) 127 | 例子: 128 | 删除一个文件 129 | fat del /abc.txt 130 | 删除一个目录同删除文件一样,但要求这个目录是空目录,你必须先删除这个目录下的文件才能删除这个目录 131 | 注意:不要删除根目录 132 | 133 | FAT mkfile size=SIZE|* file 134 | 创建新文件 135 | SIZE是文件大小,可以直接用*代替,大小等于上一个cat —length=0命令的结果。 136 | 注:cat --length=0 file命令在GRUB4DOS中用于获取指定文件的大小。 137 | 138 | FAT mkfs [/A:unit-size] [mbr] 驱动器 139 | 格式化磁盘 140 | /A:unit-size:指定一簇的字节尺寸,如 /A:4096。可以变相设置 FAT16/FAT32。 141 | mbr:硬盘格式,即有主分区。 142 | 驱动器:如(0),(rd),(hd),(hd1,2)等等 143 | 144 | FAT dir [/a*] 145 | 列出路径下所有文件及目录。 146 | dir加了按属性显示的参数(同DOS的dir) 147 | d 目录 148 | s 系统属性 149 | r 只性属性 150 | h 隐藏属性 151 | - 表示否的前辍 152 | 例子: 153 | dir /ad #只显示目录 154 | dir /as #只显示有带系统属性的文件或目录 155 | dir /ads #只显示带系统属性的目录 156 | dir /a-d #不显示目录。 157 | 158 | ================================================ 159 | wenv 160 | GRUB4DOS菜单脚本命令增强. 161 | 162 | 两个内置变量: 163 | ?_WENV 保存上一次wenv call运行的返回值 164 | ?_GET 保存上一次wenv get variable变量的长度 165 | 166 | FOR 类拟于CMD的for 167 | 比较强大的一个命令,可以分析字符串,文本文件。 168 | 语法: 169 | FOR /L %variable IN (start,step,end) DO wenv-command 170 | 该集表示以增量形式从开始到结束的一个数字序列。因此,(1,1,5)将产生序列 171 | 1 2 3 4 5,(5,-1,1)将产生序列(5 4 3 2 1) 172 | 173 | FOR /F ["options"] %variable IN ( file ) DO wenv-command 174 | FOR /F ["options"] %variable IN ("string") DO wenv-command 175 | 如果有 usebackq 选项: 176 | FOR /F ["options"] %variable IN (`string`) DO wenv-command 177 | options 178 | eol=c - 指一个行注释字符的结尾(就一个) 179 | delims=xxx - 指分隔符集。这个替换了空格和跳格键的 180 | 默认分隔符集。 181 | tokens=x,y,m-n - 指每行的哪一个符号被传递到每个迭代 182 | 的 for 本身。这会导致额外变量名称的分配。m-n 183 | 格式为一个范围。通过 nth 符号指定 mth。 184 | usebackq - 反向引号 185 | 186 | 几个例子 分析myfile.txt的每一行,使用";"作为注释符,使用","分隔字符串,显示每行的第二和第三个字符串 187 | FOR /F "eol=; tokens=2,3 delims=," %i in ( myfile.txt ) do echo %i %j 188 | 189 | 显示从1-10的数字 190 | FOR /L %i in (1,1,10) do echo %i 191 | 192 | 以下语句会显示 1 2 3 6 193 | FOR /f "tokens=1-3,6" %i in ("1 2 3 4 5 6 7 8 9 0") do echo %i %j %k %l 194 | 195 | 可以参考CMD的for命令帮助说明. 196 | 197 | 198 | -------------------------------------------------------------------------------- /g4eext/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(CC),cc) 2 | CC := gcc 3 | endif 4 | OBJCOPY := objcopy 5 | RM := rm 6 | MV := mv 7 | MKDIR := mkdir 8 | 9 | DATE = $(shell date -u +%Y-%m-%d) 10 | 11 | GCCVERSIONGTEQ5 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 5) 12 | GCCVERSIONGTEQ8 := $(shell expr `$(CC) -dumpversion | cut -f1 -d.` \>= 8) 13 | 14 | CFLAGS := -Wl,--build-id=none -m64 -mno-sse -nostdlib \ 15 | -fno-zero-initialized-in-bss -fno-function-cse \ 16 | -fshort-wchar -fno-jump-tables -Wl,-N 17 | 18 | ifeq "$(GCCVERSIONGTEQ5)" "1" 19 | CFLAGS += -no-pie 20 | else 21 | CFLAGS += -fPIE 22 | endif 23 | 24 | OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c)) fat/fat.o 25 | MODULES := $(patsubst %.c,%.mod,$(wildcard *.c)) fat/fat.mod 26 | 27 | .PHONY: all 28 | all: prepare $(MODULES) 29 | 30 | cat ntboot/ntboot >> bin/ntboot 31 | cp -f ChangeLog.txt bin/ 32 | cp -f ntboot/gbk2uni bin/ 33 | zip -9 -j ../g4eext-$(DATE).zip bin/* 34 | 35 | %.o: %.c 36 | $(CC) $(CFLAGS) -Iinclude/ $< -o $@ 37 | 38 | %.mod: %.o 39 | $(OBJCOPY) -O binary $< $@ 40 | 41 | ifeq ($(GCCVERSIONGTEQ8),1) 42 | # echo eq 43 | dd bs=1 skip=32 if=$@ of=$@new 44 | $(MV) $@new bin/$$(basename $@new .modnew) 45 | $(RM) -f $@ 46 | else 47 | # echo neq 48 | $(MV) $@ bin/$$(basename $@ .mod) 49 | endif 50 | 51 | .PHONY: prepare 52 | prepare: 53 | $(MKDIR) -p bin 54 | 55 | .PHONY: clean 56 | clean: 57 | ifeq ($(GCCVERSIONGTEQ8),1) 58 | $(RM) -f *.o *.mod *.modnew bin/* 59 | else 60 | $(RM) -f *.o *.mod fat/*.o fat/*.mod bin/* ../*.zip 61 | endif 62 | 63 | -------------------------------------------------------------------------------- /g4eext/cmdline.c: -------------------------------------------------------------------------------- 1 | /* 2 | * G4E external commands 3 | * Copyright (C) 2021 a1ive 4 | * 5 | * G4EEXT is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * G4EEXT is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with G4EEXT. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | static efi_system_table_t *st = 0; 23 | static efi_handle_t *ih = 0; 24 | static efi_boot_services_t *bs = 0; 25 | static efi_guid_t loaded_image_guid = EFI_LOADED_IMAGE_GUID; 26 | static efi_loaded_image_t *loaded_image = 0; 27 | 28 | static grub_size_t g4e_data = 0; 29 | 30 | static grub_uint8_t *utf16_to_utf8 (grub_uint8_t *dest, 31 | const grub_uint16_t *src, grub_size_t size); 32 | static void get_G4E_image (void); 33 | 34 | #include 35 | 36 | static int main (char *arg,int key); 37 | static int main (char *arg,int key) 38 | { 39 | efi_status_t status; 40 | grub_size_t cmdline_len = 0; 41 | efi_char16_t *wcmdline = 0; 42 | unsigned char *cmdline = 0; 43 | 44 | get_G4E_image (); 45 | if (! g4e_data) 46 | return 0; 47 | st = grub_efi_system_table; 48 | ih = grub_efi_image_handle; 49 | bs = st->boot_services; 50 | 51 | /* get loaded image */ 52 | status = bs->open_protocol (ih, &loaded_image_guid, 53 | (void **)&loaded_image, ih, 54 | 0, EFI_OPEN_PROTOCOL_GET_PROTOCOL); 55 | if (status != EFI_SUCCESS) 56 | return printf_errinfo ("loaded image protocol not found.\n"); 57 | /* UTF-8 U+0000 ~ U+007F 1 byte UTF-16 U+0000 ~ U+D7FF 2 bytes 58 | * U+0080 ~ U+07FF 2 bytes U+E000 ~ U+FFFF 2 bytes 59 | * U+0800 ~ U+FFFF 3 bytes U+010000 ~ U+10FFFF 4 bytes 60 | */ 61 | cmdline_len = (loaded_image->load_options_size / 2) * 3 + 1; 62 | cmdline = zalloc (cmdline_len); 63 | if (!cmdline) 64 | printf_errinfo ("out of memory\n"); 65 | 66 | wcmdline = loaded_image->load_options; 67 | utf16_to_utf8 (cmdline, wcmdline, cmdline_len); 68 | printf ("%s\n", cmdline); 69 | sprintf (ADDR_RET_STR, "%s", cmdline); 70 | free (cmdline); 71 | return 1; 72 | } 73 | 74 | static grub_uint8_t * 75 | utf16_to_utf8 (grub_uint8_t *dest, const grub_uint16_t *src, grub_size_t size) 76 | { 77 | grub_uint32_t code_high = 0; 78 | 79 | while (size--) 80 | { 81 | grub_uint32_t code = *src++; 82 | 83 | if (code_high) 84 | { 85 | if (code >= 0xDC00 && code <= 0xDFFF) 86 | { 87 | /* Surrogate pair. */ 88 | code = ((code_high - 0xD800) << 10) + (code - 0xDC00) + 0x10000; 89 | 90 | *dest++ = (code >> 18) | 0xF0; 91 | *dest++ = ((code >> 12) & 0x3F) | 0x80; 92 | *dest++ = ((code >> 6) & 0x3F) | 0x80; 93 | *dest++ = (code & 0x3F) | 0x80; 94 | } 95 | else 96 | { 97 | /* Error... */ 98 | *dest++ = '?'; 99 | /* *src may be valid. Don't eat it. */ 100 | src--; 101 | } 102 | code_high = 0; 103 | } 104 | else 105 | { 106 | if (code <= 0x007F) 107 | *dest++ = code; 108 | else if (code <= 0x07FF) 109 | { 110 | *dest++ = (code >> 6) | 0xC0; 111 | *dest++ = (code & 0x3F) | 0x80; 112 | } 113 | else if (code >= 0xD800 && code <= 0xDBFF) 114 | { 115 | code_high = code; 116 | continue; 117 | } 118 | else if (code >= 0xDC00 && code <= 0xDFFF) 119 | { 120 | /* Error... */ 121 | *dest++ = '?'; 122 | } 123 | else if (code < 0x10000) 124 | { 125 | *dest++ = (code >> 12) | 0xE0; 126 | *dest++ = ((code >> 6) & 0x3F) | 0x80; 127 | *dest++ = (code & 0x3F) | 0x80; 128 | } 129 | else 130 | { 131 | *dest++ = (code >> 18) | 0xF0; 132 | *dest++ = ((code >> 12) & 0x3F) | 0x80; 133 | *dest++ = ((code >> 6) & 0x3F) | 0x80; 134 | *dest++ = (code & 0x3F) | 0x80; 135 | } 136 | } 137 | } 138 | return dest; 139 | } 140 | 141 | static void get_G4E_image (void) 142 | { 143 | grub_size_t i; 144 | 145 | /* search "GRUB4EFI" in 0-0x9ffff */ 146 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 147 | { 148 | if (*(unsigned long long *)i == 0x4946453442555247) 149 | { 150 | g4e_data = *(grub_size_t *)(i+16); 151 | return; 152 | } 153 | } 154 | return; 155 | } 156 | -------------------------------------------------------------------------------- /g4eext/cpuid.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * compile: 5 | * gcc -Wl,--build-id=none -m64 -mno-sse -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE g4e_wb.c -o g4e_wb.o 2>&1|tee build.log 6 | * objcopy -O binary g4e_wb.o g4e_wb 7 | * 8 | * analysis: 9 | * objdump -d g4e_wb.o > g4e_wb.s 10 | * readelf -a g4e_wb.o > a.s 11 | */ 12 | // 13 | 14 | #include 15 | 16 | #define grub_cpuid(num,a,b,c,d) \ 17 | asm volatile ("cpuid" \ 18 | : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ 19 | : "0" (num)) 20 | 21 | //在此定义静态变量、结构。不能包含全局变量,否则编译可以通过,但是不能正确执行。 22 | //不能在main前定义子程序,在main后可以定义子程序。 23 | static grub_size_t g4e_data = 0; 24 | static void get_G4E_image(void); 25 | 26 | /* 这是必需的,请参阅grubprog.h中的注释 */ 27 | #include 28 | /* 请勿在此处插入任何其他asm行 */ 29 | //不能包含子程序,不能包含全局变量,否则编译可以通过,但是不能正确执行。 30 | static int main(char *arg,int key); 31 | static int main(char *arg,int key) 32 | { 33 | unsigned int eax, ebx, ecx, edx, leaf; 34 | unsigned long long num; 35 | get_G4E_image(); 36 | if (! g4e_data) 37 | return 0; 38 | if (strcmp (arg, "--pae") == 0) 39 | { 40 | grub_cpuid (1, eax, ebx, ecx, edx); 41 | printf ("%s\n", (edx & (1 << 6))? "true" : "false"); 42 | return sprintf (ADDR_RET_STR, "%u", (edx & (1 << 6))? 1 : 0); 43 | } 44 | if (strcmp (arg, "--vendor") == 0) 45 | { 46 | char vendor[13]; 47 | grub_cpuid (0, eax, ebx, ecx, edx); 48 | memmove (&vendor[0], &ebx, 4); 49 | memmove (&vendor[4], &edx, 4); 50 | memmove (&vendor[8], &ecx, 4); 51 | vendor[12] = '\0'; 52 | printf ("%s\n", vendor); 53 | return sprintf (ADDR_RET_STR, "%s", vendor); 54 | } 55 | if (strcmp (arg, "--vmx") == 0) 56 | { 57 | grub_cpuid (1, eax, ebx, ecx, edx); 58 | printf ("%s\n", (ecx & (1 << 5))? "true" : "false"); 59 | return sprintf (ADDR_RET_STR, "%u", (ecx & (1 << 5))? 1 : 0); 60 | } 61 | if (strcmp (arg, "--hyperv") == 0) 62 | { 63 | grub_cpuid (1, eax, ebx, ecx, edx); 64 | printf ("%s\n", (ecx & (1 << 31))? "true" : "false"); 65 | return sprintf (ADDR_RET_STR, "%u", (ecx & (1 << 31))? 1 : 0); 66 | } 67 | if (strcmp (arg, "--vmsign") == 0) 68 | { 69 | char vmsign[13]; 70 | grub_cpuid (0x40000000, eax, ebx, ecx, edx); 71 | memmove (&vmsign[0], &ebx, 4); 72 | memmove (&vmsign[4], &ecx, 4); 73 | memmove (&vmsign[8], &edx, 4); 74 | vmsign[12] = '\0'; 75 | printf ("%s\n", vmsign); 76 | return sprintf (ADDR_RET_STR, "%s", vmsign); 77 | } 78 | if (strcmp (arg, "--brand") == 0) 79 | { 80 | char brand[50]; 81 | memset (brand, 0, 50); 82 | grub_cpuid (0x80000002, eax, ebx, ecx, edx); 83 | memmove (&brand[0], &eax, 4); 84 | memmove (&brand[4], &ebx, 4); 85 | memmove (&brand[8], &ecx, 4); 86 | memmove (&brand[12], &edx, 4); 87 | grub_cpuid (0x80000003, eax, ebx, ecx, edx); 88 | memmove (&brand[16], &eax, 4); 89 | memmove (&brand[20], &ebx, 4); 90 | memmove (&brand[24], &ecx, 4); 91 | memmove (&brand[28], &edx, 4); 92 | grub_cpuid (0x80000004, eax, ebx, ecx, edx); 93 | memmove (&brand[32], &eax, 4); 94 | memmove (&brand[36], &ebx, 4); 95 | memmove (&brand[40], &ecx, 4); 96 | memmove (&brand[44], &edx, 4); 97 | printf ("%s\n", brand); 98 | return sprintf (ADDR_RET_STR, "%s", brand); 99 | } 100 | if (memcmp (arg, "--eax=", 6) == 0) 101 | { 102 | char *p = arg + 6; 103 | if (safe_parse_maxint (&p, &num)) 104 | { 105 | leaf = (unsigned int) num; 106 | grub_cpuid (leaf, eax, ebx, ecx, edx); 107 | return printf ("EAX=0x%08X EBX=0x%08X ECX=0x%08X EDX=0x%08X\n", 108 | eax, ebx, ecx, edx); 109 | } 110 | return 0; 111 | } 112 | printf ("Usage: cpuid [OPTION]\nOptions:\n"); 113 | printf (" --pae Check if CPU supports PAE.\n"); 114 | printf (" --vendor Get CPU's manufacturer ID string.\n"); 115 | printf (" --vmx Check if CPU supports Virtual Machine eXtensions.\n"); 116 | printf (" --hyperv Check if hypervisor presents.\n"); 117 | printf (" --vmsign Get hypervisor signature.\n"); 118 | printf (" --brand Get CPU's processor brand string.\n"); 119 | printf (" --eax=NUM Specify value of EAX register.\n"); 120 | return 1; 121 | } 122 | 123 | static void get_G4E_image(void) 124 | { 125 | grub_size_t i; 126 | 127 | //在内存0-0x9ffff, 搜索特定字符串"GRUB4EFI",获得GRUB_IMGE 128 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 129 | { 130 | if (*(unsigned long long *)i == 0x4946453442555247) //比较数据 131 | { 132 | g4e_data = *(grub_size_t *)(i+16); //GRUB4DOS_for_UEFI入口 133 | return; 134 | } 135 | } 136 | return; 137 | } 138 | -------------------------------------------------------------------------------- /g4eext/date.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * compile: 5 | * gcc -Wl,--build-id=none -m64 -mno-sse -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE g4e_wb.c -o g4e_wb.o 2>&1|tee build.log 6 | * objcopy -O binary g4e_wb.o g4e_wb 7 | * 8 | * analysis: 9 | * objdump -d g4e_wb.o > g4e_wb.s 10 | * readelf -a g4e_wb.o > a.s 11 | */ 12 | // 13 | 14 | #include 15 | #include 16 | 17 | //在此定义静态变量、结构。不能包含全局变量,否则编译可以通过,但是不能正确执行。 18 | //不能在main前定义子程序,在main后可以定义子程序。 19 | static grub_size_t g4e_data = 0; 20 | static void get_G4E_image(void); 21 | 22 | /* 这是必需的,请参阅grubprog.h中的注释 */ 23 | #include 24 | /* 请勿在此处插入任何其他asm行 */ 25 | //不能包含子程序,不能包含全局变量,否则编译可以通过,但是不能正确执行。 26 | static int main(char *arg,int key); 27 | static int main(char *arg,int key) 28 | { 29 | get_G4E_image(); 30 | if (! g4e_data) 31 | return 0; 32 | efi_status_t status; 33 | struct efi_time tm; 34 | efi_system_table_t *st = grub_efi_system_table; 35 | 36 | status = st->runtime_services->get_time (&tm, 0); 37 | 38 | if (status) 39 | return 0; 40 | else 41 | return printf ("%04u-%02u-%02u\n", tm.year, tm.month, tm.day); 42 | 43 | } 44 | 45 | static void get_G4E_image(void) 46 | { 47 | grub_size_t i; 48 | 49 | //在内存0-0x9ffff, 搜索特定字符串"GRUB4EFI",获得GRUB_IMGE 50 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 51 | { 52 | if (*(unsigned long long *)i == 0x4946453442555247) //比较数据 53 | { 54 | g4e_data = *(grub_size_t *)(i+16); //GRUB4DOS_for_UEFI入口 55 | return; 56 | } 57 | } 58 | return; 59 | } 60 | -------------------------------------------------------------------------------- /g4eext/diskid.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4eext/diskid.c -------------------------------------------------------------------------------- /g4eext/echo.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * compile: 5 | * gcc -Wl,--build-id=none -m64 -mno-sse -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE g4e_wb.c -o g4e_wb.o 2>&1|tee build.log 6 | * objcopy -O binary g4e_wb.o g4e_wb 7 | * 8 | * analysis: 9 | * objdump -d g4e_wb.o > g4e_wb.s 10 | * readelf -a g4e_wb.o > a.s 11 | */ 12 | // 13 | 14 | #include 15 | 16 | //在此定义静态变量、结构。不能包含全局变量,否则编译可以通过,但是不能正确执行。 17 | //不能在main前定义子程序,在main后可以定义子程序。 18 | static grub_size_t g4e_data = 0; 19 | static void get_G4E_image(void); 20 | 21 | /* 这是必需的,请参阅grubprog.h中的注释 */ 22 | #include 23 | /* 请勿在此处插入任何其他asm行 */ 24 | //不能包含子程序,不能包含全局变量,否则编译可以通过,但是不能正确执行。 25 | static int main(char *arg,int key); 26 | static int main(char *arg,int key) 27 | { 28 | get_G4E_image(); 29 | if (! g4e_data) 30 | return 0; 31 | 32 | return printf ("%s\n",arg); 33 | } 34 | 35 | static void get_G4E_image(void) 36 | { 37 | grub_size_t i; 38 | 39 | //在内存0-0x9ffff, 搜索特定字符串"GRUB4EFI",获得GRUB_IMGE 40 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 41 | { 42 | if (*(unsigned long long *)i == 0x4946453442555247) //比较数据 43 | { 44 | g4e_data = *(grub_size_t *)(i+16); //GRUB4DOS_for_UEFI入口 45 | return; 46 | } 47 | } 48 | return; 49 | } 50 | -------------------------------------------------------------------------------- /g4eext/fat/fat.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file R0.07 (C)ChaN, 2009 3 | /-----------------------------------------------------------------------*/ 4 | #include "ff.h" 5 | #ifndef _DISKIO 6 | 7 | #define _READONLY 0 /* 1: Read-only mode */ 8 | #define _USE_IOCTL 1 9 | 10 | #include "integer.h" 11 | #include "grub4dos.h" 12 | #define _SS_BIT 9 /* sector size bit */ 13 | /* Status of Disk Functions */ 14 | typedef BYTE DSTATUS; 15 | 16 | /* Results of Disk Functions */ 17 | typedef enum { 18 | RES_OK = 0, /* 0: Successful */ 19 | RES_ERROR, /* 1: R/W Error */ 20 | RES_WRPRT, /* 2: Write Protected */ 21 | RES_NOTRDY, /* 3: Not Ready */ 22 | RES_PARERR /* 4: Invalid Parameter */ 23 | } DRESULT; 24 | 25 | /*---------------------------------------*/ 26 | /* Prototypes for disk control functions */ 27 | 28 | //DSTATUS disk_initialize (BYTE); 29 | 30 | //DSTATUS disk_status(BYTE); 31 | //DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 32 | #if _READONLY == 0 33 | //DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 34 | #endif 35 | //DRESULT disk_ioctl (BYTE, BYTE, void*); 36 | 37 | 38 | 39 | /* Disk Status Bits (DSTATUS) */ 40 | 41 | #define STA_NOINIT 0x01 /* Drive not initialized */ 42 | #define STA_NODISK 0x02 /* No medium in the drive */ 43 | #define STA_PROTECT 0x04 /* Write protected */ 44 | 45 | 46 | /* Command code for disk_ioctrl() */ 47 | 48 | /* Generic command */ 49 | #define CTRL_SYNC 0 /* Mandatory for write functions */ 50 | #define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ 51 | #define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */ 52 | #define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */ 53 | #define CTRL_POWER 4 54 | #define CTRL_LOCK 5 55 | #define CTRL_EJECT 6 56 | /* MMC/SDC command */ 57 | #define MMC_GET_TYPE 10 58 | #define MMC_GET_CSD 11 59 | #define MMC_GET_CID 12 60 | #define MMC_GET_OCR 13 61 | #define MMC_GET_SDSTAT 14 62 | /* ATA/CF command */ 63 | #define ATA_GET_REV 20 64 | #define ATA_GET_MODEL 21 65 | #define ATA_GET_SN 22 66 | //#define FAT_MINI 67 | #ifndef FAT_MINI 68 | #define DEBUG 69 | #define F_GETFREE 1 70 | #define F_DIR 1 71 | #define F_REN 1 72 | #define F_CHMOD 1 73 | #define F_MKDIR 1 74 | #define FAT_INFO 1 75 | #endif 76 | #define FAT_MKFILE 1 77 | #define F_DEL 1 78 | #define _DISKIO 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /g4eext/fat/fat_config.h: -------------------------------------------------------------------------------- 1 | #define _TIME_Y 2021 2 | #define _TIME_m 1 3 | #define _TIME_d 31 4 | #define _TIME_H 10 5 | #define _TIME_M 30 6 | #define _TIME_S 24 7 | #define GET_FATTIME 8 | -------------------------------------------------------------------------------- /g4eext/fat/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef int LONG; 32 | typedef unsigned int ULONG; 33 | typedef unsigned int DWORD; 34 | typedef unsigned long long QWORD; 35 | 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /g4eext/fat/option/00readme.txt: -------------------------------------------------------------------------------- 1 | FatFs Module Source Files R0.08 (C)ChaN, 2010 2 | 3 | 4 | FILES 5 | 6 | ffconf.h Configuration file for FatFs module. 7 | ff.h Common include file for FatFs and application module. 8 | ff.c FatFs module. 9 | diskio.h Common include file for FatFs and disk I/O module. 10 | diskio.c Skeleton of low level disk I/O module. 11 | integer.h Alternative type definitions for integer variables. 12 | option Optional external functions. 13 | 14 | Low level disk I/O module is not included in this archive because the FatFs 15 | module is only a generic file system layer and not depend on any specific 16 | storage device. You have to provide a low level disk I/O module that written 17 | to control your storage device. 18 | 19 | 20 | 21 | AGREEMENTS 22 | 23 | FatFs module is an open source software to implement FAT file system to 24 | small embedded systems. This is a free software and is opened for education, 25 | research and commercial developments under license policy of following trems. 26 | 27 | Copyright (C) 2010, ChaN, all right reserved. 28 | 29 | * The FatFs module is a free software and there is NO WARRANTY. 30 | * No restriction on use. You can use, modify and redistribute it for 31 | personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY. 32 | * Redistributions of source code must retain the above copyright notice. 33 | 34 | 35 | 36 | REVISION HISTORY 37 | 38 | Feb 26, 2006 R0.00 Prototype 39 | 40 | Apr 29, 2006 R0.01 First release. 41 | 42 | Jun 01, 2006 R0.02 Added FAT12. 43 | Removed unbuffered mode. 44 | Fixed a problem on small (<32M) patition. 45 | 46 | Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM. 47 | 48 | Sep 22, 2006 R0.03 Added f_rename. 49 | Changed option _FS_MINIMUM to _FS_MINIMIZE. 50 | 51 | Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast. 52 | Fixed f_mkdir creates incorrect directory on FAT32. 53 | 54 | Feb 04, 2007 R0.04 Supported multiple drive system. (FatFs) 55 | Changed some APIs for multiple drive system. 56 | Added f_mkfs. (FatFs) 57 | Added _USE_FAT32 option. (Tiny-FatFs) 58 | 59 | Apr 01, 2007 R0.04a Supported multiple partitions on a plysical drive. (FatFs) 60 | Fixed an endian sensitive code in f_mkfs. (FatFs) 61 | Added a capability of extending the file size to f_lseek. 62 | Added minimization level 3. 63 | Fixed a problem that can collapse a sector when recreate an 64 | existing file in any sub-directory at non FAT32 cfg. (Tiny-FatFs) 65 | 66 | May 05, 2007 R0.04b Added _USE_NTFLAG option. 67 | Added FSInfo support. 68 | Fixed some problems corresponds to FAT32. (Tiny-FatFs) 69 | Fixed DBCS name can result FR_INVALID_NAME. 70 | Fixed short seek (0 < ofs <= csize) collapses the file object. 71 | 72 | Aug 25, 2007 R0.05 Changed arguments of f_read, f_write. 73 | Changed arguments of f_mkfs. (FatFs) 74 | Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs) 75 | Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs) 76 | 77 | Feb 03, 2008 R0.05a Added f_truncate(). 78 | Added f_utime(). 79 | Fixed off by one error at FAT sub-type determination. 80 | Fixed btr in f_read() can be mistruncated. 81 | Fixed cached sector is not flushed when create and close without write. 82 | 83 | Apr 01, 2008 R0.06 Added f_forward(). (Tiny-FatFs) 84 | Added string functions: fputc(), fputs(), fprintf() and fgets(). 85 | Improved performance of f_lseek() on move to the same or following cluster. 86 | 87 | Apr 01, 2009, R0.07 Merged Tiny-FatFs as a buffer configuration option. 88 | Added long file name support. 89 | Added multiple code page support. 90 | Added re-entrancy for multitask operation. 91 | Added auto cluster size selection to f_mkfs(). 92 | Added rewind option to f_readdir(). 93 | Changed result code of critical errors. 94 | Renamed string functions to avoid name collision. 95 | 96 | Apr 14, 2009, R0.07a Separated out OS dependent code on reentrant cfg. 97 | Added multiple sector size support. 98 | 99 | Jun 21, 2009, R0.07c Fixed f_unlink() may return FR_OK on error. 100 | Fixed wrong cache control in f_lseek(). 101 | Added relative path feature. 102 | Added f_chdir(). 103 | Added f_chdrive(). 104 | Added proper case conversion for extended characters. 105 | 106 | Nov 03, 2009 R0.07e Separated out configuration options from ff.h to ffconf.h. 107 | Added a configuration option, _LFN_UNICODE. 108 | Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH. 109 | Fixed name matching error on the 13 char boundary. 110 | Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. 111 | 112 | May 15, 2010, R0.08 Added a memory configuration option. (_USE_LFN) 113 | Added file lock feature. (_FS_SHARE) 114 | Added fast seek feature. (_USE_FASTSEEK) 115 | Changed some types on the API, XCHAR->TCHAR. 116 | Changed fname member in the FILINFO structure on Unicode cfg. 117 | String functions support UTF-8 encoding files on Unicode cfg. 118 | -------------------------------------------------------------------------------- /g4eext/fat/option/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */ 3 | /*-----------------------------------------------------------------------*/ 4 | /* This is a stub disk I/O module that acts as front end of the existing */ 5 | /* disk I/O modules and attach it to FatFs module with common interface. */ 6 | /*-----------------------------------------------------------------------*/ 7 | 8 | #include "diskio.h" 9 | /*-----------------------------------------------------------------------*/ 10 | /* Correspondence between physical drive number and physical drive. */ 11 | /*-----------------------------------------------------------------------*/ 12 | 13 | #define ATA 0 14 | #define MMC 1 15 | #define USB 2 16 | 17 | 18 | 19 | /*-----------------------------------------------------------------------*/ 20 | /* Inidialize a Drive */ 21 | /*-----------------------------------------------------------------------*/ 22 | 23 | DSTATUS disk_initialize ( 24 | BYTE drv /* Physical drive nmuber (0..) */ 25 | ) 26 | { 27 | if (! real_open_partition(0)) 28 | return STA_NOINIT; 29 | return 0; 30 | } 31 | 32 | 33 | 34 | /*-----------------------------------------------------------------------*/ 35 | /* Return Disk Status */ 36 | /*-----------------------------------------------------------------------*/ 37 | 38 | DSTATUS disk_status ( 39 | BYTE drv /* Physical drive nmuber (0..) */ 40 | ) 41 | { 42 | if (! real_open_partition(0)) 43 | return STA_NOINIT; 44 | return 0; 45 | } 46 | 47 | 48 | 49 | /*-----------------------------------------------------------------------*/ 50 | /* Read Sector(s) */ 51 | /*-----------------------------------------------------------------------*/ 52 | 53 | DRESULT disk_read ( 54 | BYTE drv, /* Physical drive nmuber (0..) */ 55 | BYTE *buff, /* Data buffer to store read data */ 56 | DWORD sector, /* Sector address (LBA) */ 57 | BYTE count /* Number of sectors to read (1..255) */ 58 | ) 59 | { 60 | if (! devread ((unsigned long long)sector, 0L, (unsigned long long)count << _SS_BIT ,(unsigned long long)(unsigned int)buff, GRUB_READ)) 61 | { 62 | return RES_PARERR; 63 | } 64 | return RES_OK; 65 | } 66 | 67 | 68 | 69 | /*-----------------------------------------------------------------------*/ 70 | /* Write Sector(s) */ 71 | /*-----------------------------------------------------------------------*/ 72 | /* The FatFs module will issue multiple sector transfer request 73 | / (count > 1) to the disk I/O layer. The disk function should process 74 | / the multiple sector transfer properly Do. not translate it into 75 | / multiple single sector transfers to the media, or the data read/write 76 | / performance may be drasticaly decreased. */ 77 | 78 | #if _READONLY == 0 79 | DRESULT disk_write ( 80 | BYTE drv, /* Physical drive nmuber (0..) */ 81 | const BYTE *buff, /* Data to be written */ 82 | DWORD sector, /* Sector address (LBA) */ 83 | BYTE count /* Number of sectors to write (1..255) */ 84 | ) 85 | { 86 | if (! devread ((unsigned long long)sector, 0L,(unsigned long long)count << _SS_BIT ,(unsigned long long)(unsigned int)buff, GRUB_WRITE)) 87 | { 88 | return RES_PARERR; 89 | } 90 | return RES_OK; 91 | } 92 | #endif /* _READONLY */ 93 | 94 | 95 | 96 | /*-----------------------------------------------------------------------*/ 97 | /* Miscellaneous Functions */ 98 | /*-----------------------------------------------------------------------*/ 99 | 100 | DRESULT disk_ioctl ( 101 | BYTE drv, /* Physical drive nmuber (0..) */ 102 | BYTE ctrl, /* Control code */ 103 | void *buff /* Buffer to send/receive control data */ 104 | ) 105 | { 106 | return 0; 107 | //return RES_PARERR; 108 | } 109 | 110 | DWORD get_fattime (void) 111 | { 112 | return 0; 113 | }; 114 | 115 | -------------------------------------------------------------------------------- /g4eext/fat/option/diskio.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | / Low level disk interface modlue include file R0.07 (C)ChaN, 2009 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO 6 | 7 | #define _READONLY 0 /* 1: Read-only mode */ 8 | #define _USE_IOCTL 1 9 | 10 | #include "integer.h" 11 | #include "grub4dos.h" 12 | #define _SS_BIT 9 /* sector size bit */ 13 | /* Status of Disk Functions */ 14 | typedef BYTE DSTATUS; 15 | 16 | /* Results of Disk Functions */ 17 | typedef enum { 18 | RES_OK = 0, /* 0: Successful */ 19 | RES_ERROR, /* 1: R/W Error */ 20 | RES_WRPRT, /* 2: Write Protected */ 21 | RES_NOTRDY, /* 3: Not Ready */ 22 | RES_PARERR /* 4: Invalid Parameter */ 23 | } DRESULT; 24 | 25 | /*---------------------------------------*/ 26 | /* Prototypes for disk control functions */ 27 | 28 | DSTATUS disk_initialize (BYTE); 29 | DSTATUS disk_status (BYTE); 30 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE); 31 | #if _READONLY == 0 32 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE); 33 | #endif 34 | DRESULT disk_ioctl (BYTE, BYTE, void*); 35 | 36 | 37 | 38 | /* Disk Status Bits (DSTATUS) */ 39 | 40 | #define STA_NOINIT 0x01 /* Drive not initialized */ 41 | #define STA_NODISK 0x02 /* No medium in the drive */ 42 | #define STA_PROTECT 0x04 /* Write protected */ 43 | 44 | 45 | /* Command code for disk_ioctrl() */ 46 | 47 | /* Generic command */ 48 | #define CTRL_SYNC 0 /* Mandatory for write functions */ 49 | #define GET_SECTOR_COUNT 1 /* Mandatory for only f_mkfs() */ 50 | #define GET_SECTOR_SIZE 2 /* Mandatory for multiple sector size cfg */ 51 | #define GET_BLOCK_SIZE 3 /* Mandatory for only f_mkfs() */ 52 | #define CTRL_POWER 4 53 | #define CTRL_LOCK 5 54 | #define CTRL_EJECT 6 55 | /* MMC/SDC command */ 56 | #define MMC_GET_TYPE 10 57 | #define MMC_GET_CSD 11 58 | #define MMC_GET_CID 12 59 | #define MMC_GET_OCR 13 60 | #define MMC_GET_SDSTAT 14 61 | /* ATA/CF command */ 62 | #define ATA_GET_REV 20 63 | #define ATA_GET_MODEL 21 64 | #define ATA_GET_SN 22 65 | 66 | 67 | #define _DISKIO 68 | #endif 69 | -------------------------------------------------------------------------------- /g4eext/fat/option/syscall.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* Sample code of OS dependent controls for FatFs R0.08 */ 3 | /* (C)ChaN, 2010 */ 4 | /*------------------------------------------------------------------------*/ 5 | 6 | #include /* ANSI memory controls */ 7 | #include /* ANSI memory controls */ 8 | 9 | #include "../ff.h" 10 | 11 | 12 | #if _FS_REENTRANT 13 | /*------------------------------------------------------------------------*/ 14 | /* Create a Synchronization Object 15 | /*------------------------------------------------------------------------*/ 16 | /* This function is called in f_mount function to create a new 17 | / synchronization object, such as semaphore and mutex. When a FALSE is 18 | / returned, the f_mount function fails with FR_INT_ERR. 19 | */ 20 | 21 | BOOL ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */ 22 | BYTE vol, /* Corresponding logical drive being processed */ 23 | _SYNC_t *sobj /* Pointer to return the created sync object */ 24 | ) 25 | { 26 | BOOL ret; 27 | 28 | *sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */ 29 | ret = (*sobj != INVALID_HANDLE_VALUE) ? TRUE : FALSE; 30 | 31 | // *sobj = SyncObjects[vol]; /* uITRON (give a static created sync object) */ 32 | // ret = TRUE; /* The initial value of the semaphore must be 1. */ 33 | 34 | // *sobj = OSMutexCreate(0, &err); /* uC/OS-II */ 35 | // ret = (err == OS_NO_ERR) ? TRUE : FALSE; 36 | 37 | // *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */ 38 | // ret = (*sobj != NULL) ? TRUE : FALSE; 39 | 40 | return ret; 41 | } 42 | 43 | 44 | 45 | /*------------------------------------------------------------------------*/ 46 | /* Delete a Synchronization Object */ 47 | /*------------------------------------------------------------------------*/ 48 | /* This function is called in f_mount function to delete a synchronization 49 | / object that created with ff_cre_syncobj function. When a FALSE is 50 | / returned, the f_mount function fails with FR_INT_ERR. 51 | */ 52 | 53 | BOOL ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */ 54 | _SYNC_t sobj /* Sync object tied to the logical drive to be deleted */ 55 | ) 56 | { 57 | BOOL ret; 58 | 59 | ret = CloseHandle(sobj); /* Win32 * 60 | 61 | // ret = TRUE; /* uITRON (nothing to do) * 62 | 63 | // OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */ 64 | // ret = (err == OS_NO_ERR) ? TRUE : FALSE; 65 | 66 | // ret = TRUE; /* FreeRTOS (nothing to do) */ 67 | 68 | return ret; 69 | } 70 | 71 | 72 | 73 | /*------------------------------------------------------------------------*/ 74 | /* Request Grant to Access the Volume */ 75 | /*------------------------------------------------------------------------*/ 76 | /* This function is called on entering file functions to lock the volume. 77 | / When a FALSE is returned, the file function fails with FR_TIMEOUT. 78 | */ 79 | 80 | BOOL ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */ 81 | _SYNC_t sobj /* Sync object to wait */ 82 | ) 83 | { 84 | BOOL ret; 85 | 86 | ret = (WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0) ? TRUE : FALSE; /* Win32 */ 87 | 88 | // ret = (wai_sem(sobj) == E_OK) ? TRUE : FALSE; /* uITRON */ 89 | 90 | // OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */ 91 | // ret = (err == OS_NO_ERR) ? TRUE : FALSE; 92 | 93 | // ret = (xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE) ? TRUE : FALSE; /* FreeRTOS */ 94 | 95 | return ret; 96 | } 97 | 98 | 99 | 100 | /*------------------------------------------------------------------------*/ 101 | /* Release Grant to Access the Volume */ 102 | /*------------------------------------------------------------------------*/ 103 | /* This function is called on leaving file functions to unlock the volume. 104 | */ 105 | 106 | void ff_rel_grant ( 107 | _SYNC_t sobj /* Sync object to be signaled */ 108 | ) 109 | { 110 | ReleaseMutex(sobj); /* Win32 */ 111 | 112 | // sig_sem(sobj); /* uITRON */ 113 | 114 | // OSMutexPost(sobj); /* uC/OS-II */ 115 | 116 | // xSemaphoreGive(sobj); /* FreeRTOS */ 117 | 118 | } 119 | 120 | #endif 121 | 122 | 123 | 124 | 125 | #if _USE_LFN == 3 /* LFN with a working buffer on the heap */ 126 | /*------------------------------------------------------------------------*/ 127 | /* Allocate a memory block */ 128 | /*------------------------------------------------------------------------*/ 129 | /* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE. 130 | */ 131 | 132 | void* ff_memalloc ( /* Returns pointer to the allocated memory block */ 133 | UINT size /* Number of bytes to allocate */ 134 | ) 135 | { 136 | return malloc(size); 137 | } 138 | 139 | 140 | /*------------------------------------------------------------------------*/ 141 | /* Free a memory block */ 142 | /*------------------------------------------------------------------------*/ 143 | 144 | void ff_memfree( 145 | void* mblock /* Pointer to the memory block to free */ 146 | ) 147 | { 148 | free(mblock); 149 | } 150 | 151 | #endif 152 | -------------------------------------------------------------------------------- /g4eext/fwsetup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * G4E external commands 3 | * Copyright (C) 2021 a1ive 4 | * 5 | * G4EEXT is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * G4EEXT is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with G4EEXT. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | static efi_system_table_t *st = 0; 23 | static efi_runtime_services_t *rt = 0; 24 | 25 | static grub_size_t g4e_data = 0; 26 | static void get_G4E_image (void); 27 | 28 | #include 29 | 30 | static int main (char *arg,int key); 31 | static int main (char *arg,int key) 32 | { 33 | efi_uint64_t osis = 0; 34 | efi_uint64_t osi = 0; 35 | efi_uintn_t size = sizeof (efi_uint64_t); 36 | efi_guid_t global = EFI_GLOBAL_VARIABLE_GUID; 37 | efi_status_t status; 38 | 39 | get_G4E_image (); 40 | if (! g4e_data) 41 | return 0; 42 | st = grub_efi_system_table; 43 | rt = st->runtime_services; 44 | 45 | /* check whether fwsetup is supported */ 46 | status = rt->get_variable (L"OsIndicationsSupported", &global, NULL, &size, &osis); 47 | if (status != EFI_SUCCESS) 48 | { 49 | printf ("failed to get variable OsIndicationsSupported.\n"); 50 | return 0; 51 | } 52 | if (! (osis & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) 53 | { 54 | printf ("fwsetup is not supported.\n"); 55 | return 0; 56 | } 57 | /* save old OsIndications variable */ 58 | status = rt->get_variable (L"OsIndications", &global, NULL, &size, &osi); 59 | if (status != EFI_SUCCESS) 60 | printf ("failed to get variable OsIndications.\n"); 61 | osi |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI; 62 | /* set OsIndications variable */ 63 | status = rt->set_variable (L"OsIndications", &global, 64 | EFI_VARIABLE_NON_VOLATILE | 65 | EFI_VARIABLE_BOOTSERVICE_ACCESS | 66 | EFI_VARIABLE_RUNTIME_ACCESS, size, &osi); 67 | if (status != EFI_SUCCESS) 68 | { 69 | printf ("failed to set variable OsIndications.\n"); 70 | return 0; 71 | } 72 | /* perform cold reset */ 73 | // rt->reset_system (EFI_RESET_WARM, EFI_SUCCESS, 0, NULL); 74 | //无忧启动论坛 gues1688 反馈,热重启进入休眠,需按电源键后才能进入 fwsetup 固件设置。 75 | //这个实体机主板很奇怪,按 ctrl+alt+del 也是进入休眠状态,必须再次按电源键才正常进入重启状态。 76 | rt->reset_system (EFI_RESET_COLD, EFI_SUCCESS, 0, NULL); 77 | 78 | return 1; 79 | } 80 | 81 | static void get_G4E_image (void) 82 | { 83 | grub_size_t i; 84 | 85 | //在内存0-0x9ffff, 搜索特定字符串"GRUB4EFI",获得GRUB_IMGE 86 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 87 | { 88 | if (*(unsigned long long *)i == 0x4946453442555247) //比较数据 89 | { 90 | g4e_data = *(grub_size_t *)(i+16); //GRUB4DOS_for_UEFI入口 91 | return; 92 | } 93 | } 94 | return; 95 | } 96 | -------------------------------------------------------------------------------- /g4eext/include/grubprog.h: -------------------------------------------------------------------------------- 1 | /* thank goodness gcc will place the above 8 bytes at the end of the b.out 谢天谢地,gcc将上述8个字节放在b.out文件的末尾。请勿在此处插入任何其他asm管路。 2 | * file. Do not insert any other asm lines here. 3 | */ 4 | /* it seems gcc use end and/or _end for __bss_end 似乎gcc使用end和/或end表示bss end */ 5 | #if 1 6 | #define __BSS_END end 7 | #else 8 | #define __BSS_END _end 9 | #endif 10 | 11 | #if 1 12 | #define __BSS_START __bss_start 13 | #elif 1 14 | #define __BSS_START edata 15 | #else 16 | #define __BSS_START _edata 17 | #endif 18 | 19 | #define PROG_PSP (char*)(((int)&__BSS_END + 16) & ~0x0F) 20 | extern int __BSS_END; 21 | extern int __BSS_START; 22 | 23 | unsigned long long GRUB = 0x534f443442555247LL;/* this is needed, see the following comment. 'GRUB4DOS'这是必需的,请参阅以下命令 */ 24 | /* gcc treat the following as data only if a global initialization like the gcc仅在发生与上述行类似的全局初始化时才将以下内容视为数据。 25 | * above line occurs. 26 | */ 27 | 28 | /* The 40-byte space is structured. 40字节空间是结构化的 */ 29 | asm(".long main"); //程序入口 4000e8 30 | asm(".long .text"); //程序段起始 4000e8 31 | asm(".long etext"); //扩展程序段起始 402da4 32 | asm(".long .data"); //数据段起始 403890 33 | asm(".long edata"); //扩展数据段起始 4038e8 34 | asm(".long __bss_start"); //bss段起始 4038e8 __bss_start - .text = 代码尺寸 35 | asm(".long .bss"); // 403900 36 | asm(".long end"); //进程结束 4039b8 end - .text = 程序实际需求空间尺寸 37 | asm(".ascii \"uefi_end\""); //uefi版本签名 38 | 39 | /* Don't insert any code/data here! 不要在这里插入任何代码/数据!*/ 40 | /* these 16 bytes can be used for any purpose. 这16个字节可以用于任何目的*/ 41 | asm(".long 0"); 42 | asm(".long 0"); 43 | asm(".long 0"); 44 | asm(".long 0"); 45 | 46 | /* Don't insert any code/data here! 不要在这里插入任何代码/数据*/ 47 | 48 | /* a valid executable file for grub4dos must end with these 8 bytes grub4dos的有效可执行文件必须以这8字节结尾 */ 49 | //grub4dos外部命令结束签名 50 | asm(".long 0x03051805"); 51 | asm(".long 0xBCBAA7BA"); 52 | 53 | asm(".globl _start"); 54 | asm("_start:"); 55 | /* thank goodness gcc will place the above 8 bytes at the end of the program 谢天谢地,gcc会把上面的8个字节放在程序文件的末尾。请勿在此处插入任何其他asm管路。 56 | * file. Do not insert any other asm lines here. 57 | */ 58 | 59 | -------------------------------------------------------------------------------- /g4eext/inifile.c: -------------------------------------------------------------------------------- 1 | #include 2 | static int inifile(char *section,char *item,char *value); 3 | static unsigned long long pos; 4 | static char *buff; 5 | static int setenvi = 0; 6 | static char *trim(char *string); 7 | 8 | static grub_size_t g4e_data = 0; 9 | static void get_G4E_image(void); 10 | 11 | /* this is needed, see the comment in grubprog.h */ 12 | #include 13 | /* Do not insert any other asm lines here. */ 14 | static int main (char *arg, int key); 15 | static int main (char *arg, int key) 16 | { 17 | get_G4E_image(); 18 | if (! g4e_data) 19 | return 0; 20 | char *section = NULL; 21 | char *item = NULL; 22 | char *value = NULL; 23 | int ret = 0; 24 | if (!(buff = malloc(32<<10))) 25 | return 0; 26 | if (!open(arg)) 27 | goto quit; 28 | section = skip_to(0,arg); 29 | item = strstr(++section,"]"); 30 | if (!item) 31 | goto quit; 32 | *item++ = 0; 33 | item = skip_to(0x200,item); 34 | if (substring("/B",item,1) != 1) 35 | { 36 | setenvi = 1; 37 | item = skip_to(0x200,item); 38 | } 39 | if (value = strstr(item,"=")) 40 | { 41 | *value++ = 0; 42 | value = trim(value); 43 | } 44 | else 45 | { 46 | value=skip_to(0x201,item); 47 | if (!*value) 48 | value = NULL; 49 | } 50 | ret = inifile(section,item,value); 51 | quit: 52 | close(); 53 | free(buff); 54 | return ret; 55 | } 56 | 57 | static char *trim(char *string) 58 | { 59 | char *s; 60 | while (*string == ' ' || *string == '\t') 61 | ++string; 62 | s = string; 63 | string += strlen(string)-1; 64 | while (*string == ' ' || *string == '\t') 65 | { 66 | --string; 67 | } 68 | string[1] = 0; 69 | return s; 70 | } 71 | 72 | static char *check_eof(char *line) 73 | { 74 | if (line == NULL) 75 | return NULL; 76 | char *s1 = line; 77 | while (*line) 78 | { 79 | if (*line == ';') 80 | { 81 | *line = 0; 82 | break; 83 | } 84 | if (*line == '\"') 85 | { 86 | while (*++line && *line != '\"') 87 | ; 88 | } 89 | if (*line) 90 | ++line; 91 | } 92 | s1 = trim(s1); 93 | return *s1?s1:NULL; 94 | } 95 | 96 | static int read_line(char *buf) 97 | { 98 | char *s1 = buf; 99 | pos = filepos; 100 | while (read((unsigned long long)(grub_addr_t)buf,1,GRUB_READ) == 1) 101 | { 102 | if (*buf == '\r' || *buf == '\n') 103 | { 104 | if (s1 == buf) 105 | { 106 | pos = filepos; 107 | continue; 108 | } 109 | break; 110 | } 111 | else if (!*buf) 112 | { 113 | filepos = filemax; 114 | break; 115 | } 116 | ++buf; 117 | } 118 | *buf = 0; 119 | return buf - s1; 120 | } 121 | 122 | static int find_section(char *section) 123 | { 124 | static char *s; 125 | int ret = 0; 126 | if (!*section) 127 | return 1; 128 | while ((read_line(buff))) 129 | { 130 | if (*buff != '[') 131 | continue; 132 | s = strstr(buff,"]"); 133 | *s = 0; 134 | s = buff + 1; 135 | s = trim(s); 136 | if (substring(section,s,1) == 0) 137 | { 138 | ret = 1; 139 | break; 140 | } 141 | } 142 | return ret; 143 | } 144 | 145 | static int inifile(char *section,char *item,char *value) 146 | { 147 | char *s1,*s2; 148 | int ret = 0; 149 | int len; 150 | int remove_section = (substring(item,"/remove",1) == 0); 151 | section = trim(section); 152 | item = trim(item); 153 | if (remove_section && !*section) 154 | return 0; 155 | while (find_section(section)) 156 | { 157 | if (remove_section) 158 | { 159 | filepos = pos; 160 | ret = read((unsigned long long)(grub_addr_t)"[*",2,GRUB_WRITE); 161 | continue; 162 | } 163 | while (len = (read_line(buff))) 164 | { 165 | if (*buff == '[') 166 | { 167 | filepos = pos; 168 | break; 169 | } 170 | s1 = check_eof(buff); 171 | if (s1) 172 | { 173 | s2 = skip_to(0x201,s1); 174 | if (!*item) 175 | { 176 | if (setenvi) 177 | { 178 | ret = envi_cmd(s1,s2,0); 179 | } 180 | else 181 | ret = printf("%s=%s\r\n",s1,s2); 182 | } 183 | else if (substring(item,s1,1) == 0) 184 | { 185 | if (value) 186 | { 187 | filepos = pos; 188 | if (substring(value,"/d",1) == 0) 189 | ret = read((unsigned long long)(grub_addr_t)";",1,GRUB_WRITE); 190 | else 191 | { 192 | ret = sprintf(buff,"%s=%s",item,value); 193 | if (ret > len) 194 | return 0; 195 | ret = read((unsigned long long)(grub_addr_t)buff,ret,GRUB_WRITE); 196 | if (ret < len) 197 | read((unsigned long long)(grub_addr_t)";",1,GRUB_WRITE); 198 | } 199 | } 200 | else if (setenvi) 201 | { 202 | ret = envi_cmd(s1,s2,0); 203 | } 204 | else 205 | return printf("%s",s2); 206 | } 207 | } 208 | } 209 | if (!*section) 210 | return ret; 211 | } 212 | return ret; 213 | } 214 | 215 | static void get_G4E_image(void) 216 | { 217 | grub_size_t i; 218 | 219 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 220 | { 221 | if (*(unsigned long long *)i == 0x4946453442555247) 222 | { 223 | g4e_data = *(grub_size_t *)(i+16); 224 | return; 225 | } 226 | } 227 | return; 228 | } 229 | -------------------------------------------------------------------------------- /g4eext/ntboot/gbk2uni: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4eext/ntboot/gbk2uni -------------------------------------------------------------------------------- /g4eext/ntboot/ntboot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/g4eext/ntboot/ntboot -------------------------------------------------------------------------------- /g4eext/time.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * compile: 5 | * gcc -Wl,--build-id=none -m64 -mno-sse -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE g4e_wb.c -o g4e_wb.o 2>&1|tee build.log 6 | * objcopy -O binary g4e_wb.o g4e_wb 7 | * 8 | * analysis: 9 | * objdump -d g4e_wb.o > g4e_wb.s 10 | * readelf -a g4e_wb.o > a.s 11 | */ 12 | // 13 | 14 | #include 15 | #include 16 | 17 | //在此定义静态变量、结构。不能包含全局变量,否则编译可以通过,但是不能正确执行。 18 | //不能在main前定义子程序,在main后可以定义子程序。 19 | static grub_size_t g4e_data = 0; 20 | static void get_G4E_image(void); 21 | 22 | /* 这是必需的,请参阅grubprog.h中的注释 */ 23 | #include 24 | /* 请勿在此处插入任何其他asm行 */ 25 | //不能包含子程序,不能包含全局变量,否则编译可以通过,但是不能正确执行。 26 | static int main(char *arg,int key); 27 | static int main(char *arg,int key) 28 | { 29 | get_G4E_image(); 30 | if (! g4e_data) 31 | return 0; 32 | efi_status_t status; 33 | struct efi_time tm; 34 | efi_system_table_t *st = grub_efi_system_table; 35 | 36 | status = st->runtime_services->get_time (&tm, 0); 37 | 38 | if (status) 39 | return 0; 40 | else 41 | return printf ("%02u:%02u:%02u\n", tm.hour, tm.minute, tm.second); 42 | 43 | } 44 | 45 | static void get_G4E_image(void) 46 | { 47 | grub_size_t i; 48 | 49 | //在内存0-0x9ffff, 搜索特定字符串"GRUB4EFI",获得GRUB_IMGE 50 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 51 | { 52 | if (*(unsigned long long *)i == 0x4946453442555247) //比较数据 53 | { 54 | g4e_data = *(grub_size_t *)(i+16); //GRUB4DOS_for_UEFI入口 55 | return; 56 | } 57 | } 58 | return; 59 | } 60 | -------------------------------------------------------------------------------- /g4eext/ver.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * compile: 5 | * gcc -Wl,--build-id=none -m64 -mno-sse -nostdlib -fno-zero-initialized-in-bss -fno-function-cse -fno-jump-tables -Wl,-N -fPIE g4e_wb.c -o g4e_wb.o 2>&1|tee build.log 6 | * objcopy -O binary g4e_wb.o g4e_wb 7 | * 8 | * analysis: 9 | * objdump -d g4e_wb.o > g4e_wb.s 10 | * readelf -a g4e_wb.o > a.s 11 | */ 12 | // 13 | 14 | #include 15 | #include 16 | 17 | //在此定义静态变量、结构。不能包含全局变量,否则编译可以通过,但是不能正确执行。 18 | //不能在main前定义子程序,在main后可以定义子程序。 19 | static grub_size_t g4e_data = 0; 20 | static void get_G4E_image(void); 21 | 22 | /* 这是必需的,请参阅grubprog.h中的注释 */ 23 | #include 24 | /* 请勿在此处插入任何其他asm行 */ 25 | //不能包含子程序,不能包含全局变量,否则编译可以通过,但是不能正确执行。 26 | static int main(char *arg,int key); 27 | static int main(char *arg,int key) 28 | { 29 | get_G4E_image(); 30 | if (! g4e_data) 31 | return 0; 32 | char uefi_ver[11]; 33 | efi_system_table_t *st = grub_efi_system_table; 34 | grub_uint16_t uefi_major_rev = st->hdr.revision >> 16; 35 | grub_uint16_t uefi_minor_rev = st->hdr.revision & 0xffff; 36 | grub_uint8_t uefi_minor_1 = uefi_minor_rev / 10; 37 | grub_uint8_t uefi_minor_2 = uefi_minor_rev % 10; 38 | sprintf (uefi_ver, "%u.%u", uefi_major_rev, uefi_minor_1); 39 | if (uefi_minor_2) 40 | sprintf (uefi_ver, "%s.%u", uefi_ver, uefi_minor_2); 41 | printf ("%s\n", uefi_ver); 42 | return sprintf (ADDR_RET_STR, "%s", uefi_ver); 43 | } 44 | 45 | static void get_G4E_image(void) 46 | { 47 | grub_size_t i; 48 | 49 | //在内存0-0x9ffff, 搜索特定字符串"GRUB4EFI",获得GRUB_IMGE 50 | for (i = 0x40100; i <= 0x9f100 ; i += 0x1000) 51 | { 52 | if (*(unsigned long long *)i == 0x4946453442555247) //比较数据 53 | { 54 | g4e_data = *(grub_size_t *)(i+16); //GRUB4DOS_for_UEFI入口 55 | return; 56 | } 57 | } 58 | return; 59 | } 60 | -------------------------------------------------------------------------------- /grubutils/common/bin2h.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | int 23 | main (int argc, char *argv[]) 24 | { 25 | FILE *in, *out; 26 | unsigned char *data; 27 | int length, i; 28 | 29 | if (argc != 4) 30 | { 31 | fprintf (stderr, "Usage: bin2h file.dat outfile.h token_name\n"); 32 | return 1; 33 | } 34 | 35 | in = fopen (argv[1], "rb"); 36 | 37 | if (!in) 38 | { 39 | fprintf (stderr, "bin2h: open %s fail\n", argv[1]); 40 | return 1; 41 | } 42 | 43 | fseek (in, 0, SEEK_END); 44 | length = ftell (in); 45 | fseek (in, 0, SEEK_SET); 46 | 47 | if (length == 0) 48 | { 49 | fprintf (stderr, "bin2h: %s is empty\n", argv[1]); 50 | return 1; 51 | } 52 | 53 | if ((data = malloc (length)) == NULL) 54 | { 55 | fclose (in); 56 | fprintf (stderr, "bin2h: can\'t allocate memory\n"); 57 | return 1; 58 | } 59 | 60 | if ((fread (data, 1, length, in)) != length) 61 | { 62 | fclose (in); 63 | fprintf (stderr, "bin2h: read %s fail\n", argv[1]); 64 | return 1; 65 | } 66 | 67 | fclose (in); 68 | 69 | out = fopen (argv[2], "wt"); 70 | 71 | if (!out) 72 | { 73 | fclose (in); 74 | fprintf (stderr, "bin2h: open %s fail\n", argv[2]); 75 | return 1; 76 | } 77 | 78 | fprintf (out, "unsigned char %s[%d] = {", argv[3], length); 79 | 80 | for (i = 0; i < length; i++) 81 | { 82 | if (i % 20 == 0) 83 | { 84 | fprintf (out, "\n "); 85 | } 86 | fprintf (out, "%d", data[i]); 87 | if (i != length - 1) 88 | fprintf (out, ","); 89 | } 90 | 91 | fprintf (out, "};\n"); 92 | fclose (out); 93 | free (data); 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /grubutils/common/bin2h.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 5 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Affero General Public License as 9 | # published by the Free Software Foundation, either version 3 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # This program 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 Affero General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Affero General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | $delim = $/; 22 | undef $/; # undef input record separator - read file as a whole 23 | 24 | $ifile = shift; 25 | $ofile = shift; 26 | $token = shift; 27 | 28 | if (! $token) { 29 | die "Usage: bin2h file.dat outfile.h token_name\n"; 30 | } 31 | 32 | # open ifile 33 | open(INFILE,$ifile) || die "bin2h: open $ifile fail\n"; 34 | binmode(INFILE); 35 | 36 | # check file size 37 | @st = stat($ifile); 38 | if (1 && $st[7] <= 0) { 39 | die "bin2h: $ifile is empty\n"; 40 | } 41 | 42 | # read whole file 43 | $data = ; 44 | close(INFILE); 45 | 46 | $n = length($data); 47 | die "bin2h: read $ifile fail" if ($n != $st[7]); 48 | 49 | # open ofile 50 | open(OUTFILE,">$ofile") || die "bin2h: open $ofile fail\n"; 51 | binmode(OUTFILE); 52 | select(OUTFILE); 53 | 54 | $if = $ifile; 55 | $if =~ s/.*[\/\\]//; 56 | $of = $ofile; 57 | $of =~ s/.*[\/\\]//; 58 | 59 | printf("unsigned char %s[%d] = {",$token,$n); 60 | for ($i = 0; $i < $n; $i++) { 61 | if ($i % 20 == 0) { 62 | printf("\n "); 63 | } 64 | printf("%d", ord(substr($data, $i, 1))); 65 | print "," if ($i != $n - 1); 66 | } 67 | 68 | print "};\n"; 69 | 70 | close(OUTFILE); 71 | select(STDOUT); 72 | 73 | undef $delim; 74 | exit(0); 75 | -------------------------------------------------------------------------------- /grubutils/common/common.mk: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(_COMMON_),) 20 | 21 | _COMMON_ = 1 22 | 23 | CMNDIR := $(dir $(lastword $(MAKEFILE_LIST))) 24 | 25 | OSTYPE = $(shell uname -s) 26 | #REV = $(shell sh $(SRCDIR)genrev.sh $(SRCDIR) ${rev}) 27 | REV = $(shell date --utc --iso-8601) 28 | _NONE := 29 | _SPACE := $(_NONE) $(_NONE) 30 | VERSION = $(subst $(_SPACE),-,$(shell cat $(SRCDIR)version)) 31 | 32 | CC = gcc 33 | OC = objcopy 34 | LD = ld 35 | 36 | CFLAGS += -I$(CMNDIR) -I. -Wall 37 | AFLAGS += -I$(CMNDIR) -I. -Wall 38 | 39 | SYSSTR = lnx 40 | 41 | ifneq ($(findstring MINGW,$(OSTYPE)),) 42 | IS_WIN32 = 1 43 | CFLAGS += -DWIN32 44 | AFLAGS += -DWIN32 45 | EXEEXT = .exe 46 | SYSSTR = w32 47 | endif 48 | 49 | ifneq ($(findstring CYGWIN,$(OSTYPE)),) 50 | IS_WIN32 = 1 51 | CFLAGS += -DWIN32 -mno-cygwin 52 | AFLAGS += -DWIN32 -mno-cygwin 53 | EXEEXT = .exe 54 | SYSSTR = w32 55 | endif 56 | 57 | ifneq ($(findstring Linux,$(OSTYPE)),) 58 | CFLAGS += -DLINUX 59 | AFLAGS += -DLINUX 60 | endif 61 | 62 | USE_ZIP ?= y 63 | 64 | ifeq ($(USE_ZIP),y) 65 | HAVE_ZIP = $(shell which zip) 66 | endif 67 | 68 | USE_PERL ?= y 69 | 70 | ifeq ($(USE_PERL),y) 71 | HAVE_PERL= $(shell which perl) 72 | endif 73 | 74 | VPATH = $(SRCDIR) $(CMNDIR) 75 | 76 | .PHONY: all clean pkg_src pkg_bin 77 | 78 | all_EXES += $(all_EXES_$(SYSSTR)) 79 | all_OBJS += $(all_OBJS_$(SYSSTR)) 80 | all_DIST += $(all_DIST_$(SYSSTR)) 81 | 82 | all: $(CURDIR)/Makefile $(all_EXES) $(all_BINS) 83 | 84 | pkg_bin: all 85 | ifneq ($(HAVE_ZIP),) 86 | zip -j -q -r $(PACKAGE)-$(VERSION)-bin-$(SYSSTR)-$(REV).zip $(all_EXES) $(all_BINS) $(addprefix $(SRCDIR),$(all_DIST)) $(CMNDIR)COPYING 87 | else 88 | tar czf $(PACKAGE)-$(VERSION)-bin-$(SYSSTR)-$(REV).tar.gz $(all_EXES) $(all_BINS) $(addprefix $(SRCDIR),$(all_DIST)) $(CMNDIR)COPYING 89 | endif 90 | 91 | pkg_src: 92 | ifneq ($(HAVE_ZIP),) 93 | zip -j -q -r $(PACKAGE)-$(VERSION)-src-$(REV).zip $(addprefix $(SRCDIR),$(all_SRCS) $(all_DIST)) $(addprefix $(CMNDIR),$(cmn_SRCS) COPYING) 94 | else 95 | tar czf $(PACKAGE)-$(VERSION)-src-$(REV).tar.gz $(addprefix $(SRCDIR),$(all_SRCS) $(all_DIST)) $(addprefix $(CMNDIR),$(cmn_SRCS) COPYING) 96 | endif 97 | 98 | clean: 99 | rm -f $(all_EXES) $(all_BINS) $(extra_CLEAN) *.o *.d # Cleanup 100 | 101 | $(CURDIR)/Makefile: 102 | echo "SRCDIR:=$(SRCDIR)\ninclude $(SRCDIR)$(notdir $(firstword $(MAKEFILE_LIST)))" > $@ # Create Makefile 103 | 104 | %$(EXEEXT): %.c 105 | $(CC) $(CFLAGS) -MMD -o $@ $< 106 | 107 | %.o: %.c 108 | $(CC) $(CFLAGS) -c -MMD -o $@ $< 109 | 110 | %.o: %.S 111 | $(CC) $(AFLAGS) -c -MMD -o $@ $< 112 | 113 | %.bin: %.pre 114 | $(OC) $(OCFLAGS) -O binary $< $@ 115 | 116 | %.pre: %.S 117 | $(CC) $(AFLAGS) -nostdlib -MMD -Wl,-T -Wl,$(CMNDIR)ldscript -o $@ $< 118 | 119 | ifneq ($(HAVE_PERL),) 120 | 121 | version.h: version ver2h.pl 122 | perl $(CMNDIR)ver2h.pl $< $@ 123 | 124 | BIN2H_EXEC = perl $(CMNDIR)bin2h.pl 125 | BIN2H_DEPS = bin2h.pl 126 | 127 | else 128 | 129 | version.h: version ver2h$(EXEEXT) 130 | ./ver2h$(EXEEXT) $< $@ 131 | 132 | BIN2H_EXEC = bin2h$(EXEEXT) 133 | BIN2H_DEPS = bin2h$(EXEEXT) 134 | 135 | extra_CLEAN += ver2h$(EXEEXT) bin2h$(EXEEXT) 136 | endif 137 | 138 | ifeq ($(EXEEXT),) 139 | all_DEPS := $(addsuffix .d, $(all_EXES)) 140 | else 141 | all_DEPS := $(subst $(EXEEXT),.d,$(all_EXES)) 142 | endif 143 | 144 | all_DEPS += $(subst .bin,.d,$(all_BINS)) 145 | all_DEPS += $(subst .o,.d,$(all_OBJS)) 146 | 147 | -include $(all_DEPS) 148 | 149 | endif 150 | -------------------------------------------------------------------------------- /grubutils/common/genrev.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # 4 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 5 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Affero General Public License as 9 | # published by the Free Software Foundation, either version 3 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # This program 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 Affero General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Affero General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | cd $1 22 | 23 | if [ -n "$2" ]; then 24 | if [ "a$2" != "adate" ]; then 25 | echo $2 26 | exit 27 | fi 28 | else 29 | if [ -d .svn ]; then 30 | svn info | sed -n "s/Revision:\ //p" 31 | exit 32 | fi 33 | fi 34 | 35 | date --utc --iso-8601 36 | -------------------------------------------------------------------------------- /grubutils/common/keytab.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __KEYTAB_H 20 | #define __KEYTAB_H 21 | 22 | #if defined(__cplusplus) || defined(c_plusplus) 23 | extern "C" { 24 | #endif 25 | 26 | int get_keycode (char* key); 27 | char *get_keyname (unsigned short code); 28 | char *str_upcase (char *str); 29 | 30 | #if defined(__cplusplus) || defined(c_plusplus) 31 | } 32 | #endif 33 | #endif /* __KEYTAB_H */ 34 | -------------------------------------------------------------------------------- /grubutils/common/ldscript: -------------------------------------------------------------------------------- 1 | SECTIONS 2 | { 3 | .text : { *(.text) } 4 | /DISCARD/ : { *(*) } 5 | } 6 | -------------------------------------------------------------------------------- /grubutils/common/symbol.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007,2008 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __SYMBOL_H 20 | #define __SYMBOL_H 21 | 22 | #ifdef WIN32 23 | #define EXT_FUNC(x) x + 2 24 | #else 25 | #define EXT_FUNC(x) x 26 | #endif 27 | 28 | #define DEF_FUNC(x) .global x ; x: 29 | 30 | #endif /* __SYMBOL_H */ 31 | -------------------------------------------------------------------------------- /grubutils/common/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __UTILS_H 20 | #define __UTILS_H 21 | 22 | #if defined(__cplusplus) || defined(c_plusplus) 23 | extern "C" { 24 | #endif 25 | 26 | #define FST_OTHER 0 27 | #define FST_MBR 1 28 | #define FST_MBR_FORCE_LBA 2 29 | #define FST_MBR_BAD 4 30 | #define FST_GPT 5 31 | #define FST_FAT16 6 32 | #define FST_FAT32 7 33 | #define FST_NTFS 8 34 | #define FST_EXT2 9 35 | #define FST_EXT3 10 36 | #define FST_EXT4 11 37 | #define FST_EXFAT 12 38 | 39 | extern int mbr_nhd, mbr_spt; 40 | int get_fstype (unsigned char*); 41 | char* fst2str (int); 42 | char* dfs2str (int); 43 | 44 | #if defined(__cplusplus) || defined(c_plusplus) 45 | } 46 | #endif 47 | #endif /* __UTILS_H */ 48 | -------------------------------------------------------------------------------- /grubutils/common/ver2h.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | int 24 | main (int argc, char *argv[]) 25 | { 26 | FILE *in, *out; 27 | int major, minor, len; 28 | char ver[40]; 29 | 30 | if (argc != 3) 31 | { 32 | fprintf (stderr, "Usage: ver2h version version.h\n"); 33 | return 1; 34 | } 35 | 36 | in = fopen (argv[1], "rt"); 37 | 38 | if (!in) 39 | { 40 | fprintf (stderr, "ver2h: open %s fail\n", argv[1]); 41 | return 1; 42 | } 43 | 44 | ver[0] = 0; 45 | fgets (ver, sizeof (ver), in); 46 | len = strlen (ver) - 1; 47 | while ((len >= 0) && ((ver[len] == '\r') || (ver[len] == '\n'))) 48 | len--; 49 | ver[len + 1] = 0; 50 | sscanf (ver, "%d.%d", &major, &minor); 51 | 52 | fclose (in); 53 | 54 | out = fopen (argv[2], "wt"); 55 | 56 | if (!out) 57 | { 58 | fclose (in); 59 | fprintf (stderr, "ver2h: open %s fail\n", argv[2]); 60 | return 1; 61 | } 62 | 63 | fprintf (out, "#define VERSION \"%s\"\n", ver); 64 | fprintf (out, "#define VER_MAJOR %d\n", major); 65 | fprintf (out, "#define VER_MINOR %d\n", minor); 66 | fclose (out); 67 | 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /grubutils/common/ver2h.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 5 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Affero General Public License as 9 | # published by the Free Software Foundation, either version 3 of the 10 | # License, or (at your option) any later version. 11 | # 12 | # This program 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 Affero General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Affero General Public License 18 | # along with this program. If not, see . 19 | # 20 | 21 | # 22 | # Read the "version" file and produce some macro declarations 23 | # 24 | 25 | use Fcntl; 26 | 27 | ($vfile, $vout) = @ARGV; 28 | sysopen(VERSION, $vfile, O_RDONLY) or die "$0: Cannot open $vfile\n"; 29 | $version = ; 30 | chomp $version; 31 | close(VERSION); 32 | 33 | unless ( $version =~ /^([0-9]+)\.([0-9]+) *([A-Za-z0-9 ]*)$/ ) { 34 | die "$0: Cannot parse version format\n"; 35 | } 36 | $vma = $1+0; $vmi = $2+0; 37 | 38 | sysopen(VI, $vout, O_WRONLY|O_CREAT|O_TRUNC) 39 | or die "$0: Cannot create $vout: $!\n"; 40 | print VI "#define VERSION \"$version\"\n"; 41 | print VI "#define VER_MAJOR $vma\n"; 42 | print VI "#define VER_MINOR $vmi\n"; 43 | close(VI); 44 | -------------------------------------------------------------------------------- /grubutils/common/xd16.asm: -------------------------------------------------------------------------------- 1 | ; 2 | ; GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | ; Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | ; 5 | ; This program is free software: you can redistribute it and/or modify 6 | ; it under the terms of the GNU Affero General Public License as 7 | ; published by the Free Software Foundation, either version 3 of the 8 | ; License, or (at your option) any later version. 9 | ; 10 | ; This program is distributed in the hope that it will be useful, 11 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ; GNU Affero General Public License for more details. 14 | ; 15 | ; You should have received a copy of the GNU Affero General Public License 16 | ; along with this program. If not, see . 17 | ; 18 | 19 | .386 20 | locals 21 | 22 | xd_t struc 23 | flg dw 0 24 | num dw 0 25 | ofs dd 0 26 | prm dw 0 27 | xd_t ends 28 | 29 | global _xd16_init:near 30 | global _xd16_read:near 31 | global _xd16_write:near 32 | 33 | _TEXT segment byte use16 public 'CODE' 34 | assume cs:_TEXT 35 | 36 | ; void xd16_init(xd_t*); 37 | _xd16_init proc near 38 | push bp 39 | mov bp, sp 40 | mov bx, [bp+4] 41 | mov dl, byte ptr [bx].num 42 | mov ah, 41h 43 | mov bx, 55aah 44 | int 13h 45 | jc short @@chs 46 | cmp bx, 0aa55h 47 | jnz short @@chs 48 | test cx, 1 49 | jz short @@chs 50 | @@lba: 51 | mov [bx].prm, 0 52 | @@quit: 53 | pop bp 54 | ret 55 | @@chs: 56 | mov ah, 8 57 | mov bx, [bp+4] 58 | mov dl, byte ptr [bx].num 59 | push es 60 | push di 61 | push si 62 | push bx 63 | int 13h 64 | pop bx 65 | pop si 66 | pop di 67 | pop es 68 | jc @@lba 69 | mov al, cl 70 | and al, 3Fh 71 | mov byte ptr [bx].prm, al 72 | inc dh 73 | mov byte ptr [bx+1].prm, dh 74 | jmp @@quit 75 | _xd16_init endp 76 | 77 | ; xd16_read(xd_t*,char*,int); 78 | _xd16_read proc near 79 | mov dh,0 80 | jmp short _xd16_rdwr 81 | _xd16_read endp 82 | 83 | _xd16_write proc near 84 | mov dh,1 85 | _xd16_write endp 86 | 87 | _xd16_rdwr proc near 88 | push bp 89 | mov bp, sp 90 | push si 91 | mov bx, [bp+4] 92 | mov dl, byte ptr [bx].num 93 | cmp [bx].prm, 0 94 | jnz short @@chs 95 | xor eax, eax 96 | push eax 97 | push [bx].ofs 98 | push ds 99 | push word ptr [bp+6] 100 | push word ptr [bp+8] 101 | push 10h 102 | mov si, sp 103 | mov ah, dh 104 | add ah, 42h 105 | int 13h 106 | jc short @@fail 107 | mov ax, [si+2] 108 | cmp [bp+8], ax 109 | jnz short @@fail 110 | @@done: 111 | add word ptr [bx].ofs, ax 112 | adc word ptr [bx+2].ofs, 0 113 | xor ax, ax 114 | @@quit: 115 | mov si, [bp-2] 116 | leave 117 | ret 118 | @@fail: 119 | mov ax, 1 120 | jmp @@quit 121 | @@chs: 122 | mov cx, [bp+8] 123 | 124 | @@back: 125 | push cx 126 | push dx 127 | 128 | push dx 129 | mov ax, [bx].prm 130 | mul ah 131 | mov cx, ax 132 | mov ax, word ptr [bx].ofs 133 | mov dx, word ptr [bx+2].ofs 134 | div cx 135 | cmp ax, 1024 136 | jae @@fail 137 | xchg dx, ax 138 | div byte ptr [bx].prm 139 | inc ah 140 | mov ch, dl 141 | mov cl, dh 142 | shl cl, 6 143 | or cl, ah 144 | pop dx 145 | mov ah, dh 146 | add ah, 2 147 | mov dh, al 148 | mov al, 1 149 | mov bx, [bp+6] 150 | push es 151 | push ds 152 | pop es 153 | int 13h 154 | pop es 155 | jc short @@fail 156 | 157 | add word ptr [bp+6], 200h 158 | mov bx, [bp+4] 159 | add word ptr [bx].ofs, 1 160 | adc word ptr [bx+2].ofs, 0 161 | 162 | pop dx 163 | pop cx 164 | loop @@back 165 | 166 | xor ax, ax 167 | jmp @@quit 168 | _xd16_rdwr endp 169 | 170 | _TEXT ends 171 | 172 | end 173 | -------------------------------------------------------------------------------- /grubutils/common/xdio.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __XDIO_H 20 | #define __XDIO_H 21 | 22 | #if defined(__cplusplus) || defined(c_plusplus) 23 | extern "C" { 24 | #endif 25 | 26 | #ifdef DOS 27 | #include 28 | #endif 29 | 30 | #define MAX_DISKS 20 31 | #define MAX_PARTS 30 32 | 33 | #define XDF_FILE 1 34 | #define XDF_DISK 2 35 | 36 | #define XD_INVALID_SIZE 0xffffffff 37 | 38 | #if (! defined(WIN32)) && (! defined(DOS)) 39 | 40 | #define O_BINARY 0 41 | 42 | #endif 43 | 44 | typedef struct { 45 | int flg; 46 | int num; 47 | unsigned long ofs; 48 | #ifdef DOS 49 | unsigned short prm; 50 | #endif 51 | } xd_t; 52 | 53 | typedef struct { 54 | unsigned char cur; // Current partition number 55 | unsigned char nxt; // Next partition number 56 | unsigned char dfs; // File system flag 57 | unsigned char btf; // Bootable flag 58 | unsigned char pad; // Padding 59 | unsigned long bse; // Partition start address 60 | unsigned long len; // Partition length 61 | unsigned long ebs; // Base address for the extended partition 62 | } xde_t; 63 | 64 | #define valueat(buf,ofs,type) *((type *) (((char*) &buf) + ofs)) 65 | 66 | #ifdef DOS 67 | void xd16_init (xd_t*); 68 | int xd16_read (xd_t*, char*, int); 69 | int xd16_write (xd_t*, char*, int); 70 | #endif 71 | 72 | xd_t* xd_open (char*, int, int); 73 | int xd_seek (xd_t*, unsigned long); 74 | int xd_enum (xd_t*, xde_t*); 75 | int xd_read (xd_t*, char*, int); 76 | int xd_write (xd_t*, char*, int); 77 | void xd_close (xd_t*); 78 | unsigned long xd_size (xd_t* xd); 79 | int xd_lock (xd_t * xd); 80 | void xd_unlock (void); 81 | 82 | #if defined(__cplusplus) || defined(c_plusplus) 83 | } 84 | #endif 85 | #endif /* __XDIO_H */ 86 | -------------------------------------------------------------------------------- /grubutils/fbinst/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(SRCDIR),) 20 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 21 | endif 22 | 23 | PACKAGE = fbinst 24 | 25 | extra_SRCS = Makefile version fbmbr.S fbinst.h 26 | 27 | all_DIST = 28 | 29 | cmn_SRCS = common.mk ldscript keytab.c keytab.h bin2h.c bin2h.pl ver2h.c ver2h.pl utils.c utils.h xdio.c xdio.h xd16.asm 30 | 31 | all_SRCS := fbinst.c $(extra_SRCS) 32 | all_OBJS = fbinst.o 33 | all_EXES = fbinst$(EXEEXT) 34 | 35 | extra_CLEAN = fb.mbr version.h fb_*.* 36 | 37 | -include common.mk $(SRCDIR)../common/common.mk 38 | 39 | fbinst$(EXEEXT): fbinst.o xdio.o keytab.o 40 | $(CC) $(CFLAGS) -o$@ $^ 41 | 42 | fbinst.o: version.h fbinst.h fb_mbr_rel.h fb_mbr_dbg.h 43 | 44 | fb_rel.mbr: fbmbr.S version.h fbinst.h 45 | $(CC) -nostdlib -I. -I$(SRCDIR) -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o fb$(EXEEXT) $< 46 | $(OC) -O binary fb$(EXEEXT) $@ 47 | rm fb$(EXEEXT) 48 | 49 | fb_mbr_rel.h: fb_rel.mbr $(BIN2H_DEPS) 50 | $(BIN2H_EXEC) $< $@ fb_mbr_rel 51 | 52 | fb_dbg.mbr: fbmbr.S version.h fbinst.h 53 | $(CC) -nostdlib -I. -I$(SRCDIR) -DDEBUG -DDEBUG_INT13 -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o fb$(EXEEXT) $< 54 | $(OC) -O binary fb$(EXEEXT) $@ 55 | rm fb$(EXEEXT) 56 | 57 | fb_mbr_dbg.h: fb_dbg.mbr $(BIN2H_DEPS) 58 | $(BIN2H_EXEC) $< $@ fb_mbr_dbg 59 | -------------------------------------------------------------------------------- /grubutils/fbinst/fbinst.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2009 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef __FBINST_H 20 | #define __FBINST_H 21 | 22 | #define FB_MAGIC "FBBF" 23 | #define FB_MAGIC_LONG 0x46424246 24 | #define FB_MAGIC_WORD (FB_MAGIC_LONG & 0xffff) 25 | 26 | 27 | #define FB_AR_MAGIC "FBAR" 28 | #define FB_AR_MAGIC_LONG 0x52414246 29 | #define FB_AR_MAGIC_WORD (FB_AR_MAGIC_LONG & 0xffff) 30 | #define FB_AR_MAX_SIZE 0x7fffffff 31 | 32 | #define FB_MENU_FILE "fb.cfg" 33 | 34 | #define FBM_TYPE_MENU 1 35 | #define FBM_TYPE_TEXT 2 36 | #define FBM_TYPE_TIMEOUT 3 37 | #define FBM_TYPE_DEFAULT 4 38 | #define FBM_TYPE_COLOR 5 39 | 40 | #define FBS_TYPE_MENU 1 41 | #define FBS_TYPE_BULDR 2 42 | #define FBS_TYPE_SYSLINUX 3 43 | #define FBS_TYPE_LINUX 4 44 | #define FBS_TYPE_MSDOS 5 45 | #define FBS_TYPE_FREEDOS 6 46 | #define FBS_TYPE_CHAIN 7 47 | #define FBS_TYPE_GRLDR 8 48 | 49 | #define FBF_FLAG_EXTENDED 1 50 | #define FBF_FLAG_SYSLINUX 2 51 | 52 | #define OFS_max_sec 0x1ad 53 | #define OFS_lba 0x1ae 54 | #define OFS_bootdrv 0x1af 55 | #define OFS_spt 0x1b0 56 | #define OFS_heads 0x1b1 57 | #define OFS_boot_base 0x1b2 58 | #define OFS_fb_magic 0x1b4 59 | #define OFS_mbr_table 0x1b8 60 | 61 | #define OFS_boot_size 0x200 62 | #define OFS_flags 0x202 63 | #define OFS_ver_major 0x204 64 | #define OFS_ver_minor 0x205 65 | #define OFS_list_used 0x206 66 | #define OFS_list_size 0x208 67 | #define OFS_pri_size 0x20a 68 | #define OFS_ext_size 0x20c 69 | 70 | 71 | #define COLOR_NORMAL 7 72 | 73 | #endif /* __FBINST_H */ 74 | -------------------------------------------------------------------------------- /grubutils/fbinst/version: -------------------------------------------------------------------------------- 1 | 1.6 2 | -------------------------------------------------------------------------------- /grubutils/grubinst/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(SRCDIR),) 20 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 21 | endif 22 | 23 | PACKAGE = grubinst 24 | 25 | # To build the standalone NTFS boot sector, uncomment the following line 26 | # BUILD_NTFSBS ?= y 27 | 28 | # To build the grub2 header, uncomment the following line 29 | # BUILD_G2HDR ?= y 30 | 31 | # USE_RC ?=y 32 | 33 | extra_SRCS = Makefile Makefile.vc6 Makefile.dos version resource.h ntfsbs.S g2hdr.S grldrstart45cp.S grldrstart45cnp.S grldrstart46ap.S grldrstart46anp.S grubinst.ico 34 | 35 | all_DIST = readme.txt changelog.txt grubinst_gui.chs 36 | 37 | cmn_SRCS = common.mk ldscript keytab.c keytab.h bin2h.c bin2h.pl ver2h.c ver2h.pl utils.c utils.h xdio.c xdio.h xd16.asm 38 | 39 | all_SRCS := grubinst.c grubinst_gui.c grubinst_gui.rc grubmenu.c $(extra_SRCS) 40 | all_OBJS = grubinst.o grubmenu.o grubinst_gui.o 41 | all_EXES = grubinst$(EXEEXT) grubmenu$(EXEEXT) grubinst_gui$(EXEEXT) 42 | 43 | 44 | ifeq ($(BUILD_NTFSBS),y) 45 | all_BINS += ntfsbs.bin 46 | endif 47 | 48 | ifeq ($(BUILD_G2HDR),y) 49 | all_BINS += g2hdr.bin 50 | endif 51 | 52 | extra_CLEAN = grldr45cp.mbr grldr46ap.mbr grldr45cnp.mbr grldr46anp.mbr version.h grub_mbr45cp.h grub_mbr46ap.h grub_mbr45cnp.h grub_mbr46anp.h grub_pbr46al.h *.ro 53 | 54 | -include common.mk $(SRCDIR)../common/common.mk 55 | 56 | grubinst$(EXEEXT): grubinst.o utils.o xdio.o keytab.o 57 | $(CC) $(CFLAGS) -o$@ $^ 58 | 59 | grubinst.o: version.h grub_mbr45cp.h grub_mbr46ap.h grub_pbr46al.h 60 | 61 | grubinst_gui.o: version.h grub_mbr45cp.h grub_mbr46ap.h grub_mbr45cnp.h grub_mbr46anp.h grub_pbr46al.h 62 | 63 | grldr45cp.mbr: grldrstart45cp.S ntfsbs.S 64 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 65 | $(OC) -O binary grldr$(EXEEXT) $@ 66 | rm grldr$(EXEEXT) 67 | 68 | grldr45cnp.mbr: grldrstart45cnp.S ntfsbs.S 69 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 70 | $(OC) -O binary grldr$(EXEEXT) $@ 71 | rm grldr$(EXEEXT) 72 | grldr46ap.mbr: grldrstart46ap.S ntfsbs.S 73 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 74 | $(OC) -O binary grldr$(EXEEXT) $@ 75 | rm grldr$(EXEEXT) 76 | grldr46anp.mbr: grldrstart46anp.S ntfsbs.S 77 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 78 | $(OC) -O binary grldr$(EXEEXT) $@ 79 | rm grldr$(EXEEXT) 80 | 81 | ifneq ($(IS_WIN32),) 82 | 83 | ifeq ($(USE_RC),y) 84 | HAVE_RC = $(shell which rc.exe) 85 | endif 86 | 87 | ifneq ($(HAVE_RC),) 88 | 89 | grubinst_gui.ro: grubinst_gui.rc resource.h grubinst.ico 90 | rc -fo grubinst_gui.res $< 91 | cvtres -nologo -machine:ix86 -out:$@ grubinst_gui.res 92 | rm -f grubinst_gui.res 93 | 94 | else 95 | 96 | grubinst_gui.ro: grubinst_gui.rc resource.h grubinst.ico 97 | windres -I$(SRCDIR) $< $@ 98 | 99 | endif 100 | 101 | grubinst_gui$(EXEEXT): grubinst_gui.o utils.o keytab.o xdio.o grubinst_gui.ro 102 | $(CC) $(CFLAGS) -o$@ $^ -mwindows 103 | 104 | else 105 | grubinst$(EXEEXT): grubinst.o utils.o xdio.o keytab.o 106 | $(CC) $(CFLAGS) -o$@ $^ 107 | grubinst_gui$(EXEEXT): grubinst_gui.o utils.o keytab.o xdio.o 108 | $(CC) $(CFLAGS) -o$@ $^ 109 | endif 110 | 111 | grub_mbr45cp.h: grldr45cp.mbr $(BIN2H_DEPS) 112 | ./$(BIN2H_EXEC) $< $@ grub_mbr45cp 113 | grub_mbr45cnp.h: grldr45cnp.mbr $(BIN2H_DEPS) 114 | ./$(BIN2H_EXEC) $< $@ grub_mbr45cnp 115 | grub_mbr46ap.h: grldr46ap.mbr $(BIN2H_DEPS) 116 | ./$(BIN2H_EXEC) $< $@ grub_mbr46ap 117 | grub_mbr46anp.h: grldr46anp.mbr $(BIN2H_DEPS) 118 | ./$(BIN2H_EXEC) $< $@ grub_mbr46anp 119 | grub_pbr46al.h: grldr46al.pbr $(BIN2H_DEPS) 120 | ./$(BIN2H_EXEC) $< $@ grub_pbr46al 121 | -------------------------------------------------------------------------------- /grubutils/grubinst/Makefile.dos: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(SRCDIR),) 20 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 21 | endif 22 | 23 | PACKAGE = grubinst 24 | 25 | extra_SRCS = Makefile.dos version grldrstart45cp.S grldrstart45cnp.S grldrstart46ap.S grldrstart46anp.S 26 | 27 | all_DIST = readme.txt changelog.txt 28 | 29 | cmn_SRCS = common.mk ldscript keytab.c keytab.h bin2h.c bin2h.pl ver2h.c ver2h.pl utils.c utils.h xdio.c xdio.h xd16.asm 30 | 31 | all_SRCS = grubinst.c 32 | all_EXES = grbins16.exe 33 | 34 | extra_CLEAN = grldr45cp.mbr grldr45cnp.mbr grldr46ap.mbr grldr46anp.mbr version.h grub_mbr45cp.h grub_mbr45cnp.h grub_mbr46ap.h grub_mbr46anp.h grub_pbr46al.h grubinst.obj utils.obj xdio.obj keytab.obj xd16.obj 35 | 36 | -include common.mk $(SRCDIR)../common/common.mk 37 | 38 | CFLAGS = -DDOS -I$(CMNDIR) -I. 39 | SYSSTR = dos 40 | 41 | grbins16.exe: grubinst.obj utils.obj xdio.obj keytab.obj xd16.obj 42 | bcc $(CFLAGS) -e$@ $^ 43 | 44 | grubinst.obj: version.h grub_mbr45cp.h grub_mbr46ap.h grub_mbr45cnp.h grub_mbr46anp.h grub_pbr46al.h 45 | 46 | %.obj: %.c 47 | bcc $(CFLAGS) -c -o$@ $< 48 | 49 | %.obj: %.asm 50 | tasm $(subst /,\\,$<),$(subst /,\\,$@) 51 | 52 | grldr46anp.mbr: grldrstart46anp.S ntfsbs.S 53 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 54 | $(OC) -O binary grldr$(EXEEXT) $@ 55 | rm grldr$(EXEEXT) 56 | grldr45cp.mbr: grldrstart45cp.S ntfsbs.S 57 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 58 | $(OC) -O binary grldr$(EXEEXT) $@ 59 | rm grldr$(EXEEXT) 60 | 61 | grldr45cnp.mbr: grldrstart45cnp.S ntfsbs.S 62 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 63 | $(OC) -O binary grldr$(EXEEXT) $@ 64 | rm grldr$(EXEEXT) 65 | grldr46ap.mbr: grldrstart46ap.S ntfsbs.S 66 | $(CC) -nostdlib -DGRLDR_MBR -Wl,-N -Wl,-T -Wl,$(CMNDIR)ldscript -o grldr$(EXEEXT) $< 67 | $(OC) -O binary grldr$(EXEEXT) $@ 68 | rm grldr$(EXEEXT) 69 | grub_mbr45cp.h: grldr45cp.mbr $(BIN2H_DEPS) 70 | $(BIN2H_EXEC) $< $@ grub_mbr45cp 71 | grub_mbr45cnp.h: grldr45cnp.mbr $(BIN2H_DEPS) 72 | $(BIN2H_EXEC) $< $@ grub_mbr45cnp 73 | grub_mbr46anp.h: grldr46anp.mbr $(BIN2H_DEPS) 74 | $(BIN2H_EXEC) $< $@ grub_mbr46anp 75 | grub_mbr46ap.h: grldr46ap.mbr $(BIN2H_DEPS) 76 | $(BIN2H_EXEC) $< $@ grub_mbr46ap 77 | grub_pbr46al.h: grldr46al.pbr $(BIN2H_DEPS) 78 | $(BIN2H_EXEC) $< $@ grub_pbr46al 79 | -------------------------------------------------------------------------------- /grubutils/grubinst/Makefile.vc6: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123@126.com) 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | # 19 | 20 | CC=cl 21 | CFLAGS=-DWIN32 22 | 23 | all: grubinst.exe grubinst_gui.exe 24 | 25 | grubinst.exe: grubinst.c grub_mbr45cp.h grub_mbr46ap.h grub_pbr46al.h utils.obj utils.h key_tab.h version.h 26 | $(CC) $(CFLAGS) grubinst.c utils.obj 27 | 28 | utils.obj: utils.c 29 | $(CC) $(CFLAGS) -c utils.c 30 | 31 | grub_mbr45cp.h: grldr45cp.mbr bin2h.exe 32 | bin2h grldr45cp.mbr grub_mbr45cp.h grub_mbr45cp 33 | 34 | grub_mbr45cnp.h: grldr45cnp.mbr bin2h.exe 35 | bin2h grldr45cnp.mbr grub_mbr45cnp.h grub_mbr45cnp 36 | 37 | grub_mbr46ap.h: grldr46ap.mbr bin2h.exe 38 | bin2h grldr46ap.mbr grub_mbr46ap.h grub_mbr46ap 39 | 40 | grub_mbr46anp.h: grldr46anp.mbr bin2h.exe 41 | bin2h grldr46anp.mbr grub_mbr46anp.h grub_mbr46anp 42 | 43 | grub_pbr46al.h: grldr46al.pbr bin2h.exe 44 | bin2h grldr46al.pbr grub_pbr46al.h grub_pbr46al 45 | 46 | version.h: version ver2h.exe 47 | ver2h version version.h 48 | 49 | bin2h.exe: bin2h.c 50 | $(CC) $(CFLAGS) bin2h.c 51 | 52 | ver2h.exe: ver2h.c 53 | $(CC) $(CFLAGS) ver2h.c 54 | 55 | grubinst_gui.exe: grubinst_gui.c resource.h keytab.h grub_mbr45cp.h grub_mbr45cnp.h grub_mbr46ap.h grub_mbr46anp.h grub_pbr46al.h grubinst_gui.res utils.obj 56 | $(CC) $(CFLAGS) grubinst_gui.c utils.obj grubinst_gui.res user32.lib comdlg32.lib 57 | 58 | grubinst_gui.res: grubinst_gui.rc resource.h grubinst.ico 59 | rc -fo grubinst_gui.res grubinst_gui.rc 60 | 61 | clean: 62 | del grubinst.exe 63 | del grubinst.obj 64 | del grubinst_gui.exe 65 | del grubinst_gui.obj 66 | del grubinst_gui.res 67 | del utils.obj 68 | del bin2h.exe 69 | del bin2h.obj 70 | del ver2h.exe 71 | del ver2h.obj 72 | 73 | dist-clean: clean 74 | del grub_mbr45cp.h 75 | del grub_mbr46ap.h 76 | del grub_mbr45cnp.h 77 | del grub_mbr46anp.h 78 | del grub_pbr46al.h 79 | del version.h 80 | -------------------------------------------------------------------------------- /grubutils/grubinst/changelog.txt: -------------------------------------------------------------------------------- 1 | 2015-01 2 | * implemented Grub4Dos 0.4.6a 3 | * many improvements to the GUI 4 | 5 | 2012-02-15 6 | * 更新GRLDR.MBR代码。 7 | * 修正GUI不能显示超过10个磁盘的BUG。 8 | 9 | 2008-12-30 10 | * 使用了最新版的GRLDR.MBR代码. 11 | * 修改了对应新版的GRLDR.MBR热键写入位置. 12 | 13 | 2008-12-15 14 | * 添加一个新的参数 --chs-no-tune同bootlace.com一样. 15 | 16 | 2008-12-13 version 1.1 (by chenall) 17 | * 使用了GRUB4DOS源码里面新的GRLDR.MBR代码. 18 | * 修正改名 (只能用于最新版GRLDR). 19 | * MBR热键显示 20 | 21 | 2007-08-29 version 1.1 (revision 19) 22 | * Run mbr test to detect chs problem 23 | * New option --no-copy-bpb and --skip-mbr-test 24 | * NTFS boot sector update: get number of heads and sectors per track at runtime 25 | * Support 8.3 boot file name (max length 7 in previous versions) 26 | 27 | 2007-07-16 version 1.1 (revision 17) 28 | * Display timeout counter 29 | * New NTFS boot code (4 sector) 30 | * NTFS driver update: support non-resident $BITMAP 31 | * New option -k, -r for grubmenu 32 | * New option -e for grubinst 33 | * Copy FAT16/FAT32 BPB to MBR 34 | 35 | 2007-05-10 version 1.1 (revision 13) 36 | * Display hot key name, change --force-backup-mbr handling 37 | * F11/F12 hotkey handling 38 | 39 | 2007-04-22 version 1.1 (revision 10) 40 | * Convert menu file in grubmenu 41 | * Check if there is enough space to install GRLDR.MBR 42 | 43 | 2007-04-07 version 1.1 (revision 9) 44 | * Fix bugs in the NTFS boot sector 45 | * Add tool grubmenu 46 | 47 | 2007-02-23 version 1.1 beta7 48 | * Support compressed and sparse file in NTFS partition 49 | 50 | 2007-02-22 version 1.1 beta6 51 | * Move language specific text to external file 52 | * Add --load-seg and --boot-file option 53 | * Add --output option which is used to extract the embeded grldr.mbr 54 | * Support loading Grub2 kernel as well as grldr 55 | * Fix bugs in the NTFS boot sector 56 | 57 | 2007-02-05 version 1.1 beta5 58 | * Add native NTFS support 59 | 60 | 2007-01-22 version 1.1 beta4 61 | * Fix a bug that cause --time-out option to have no effect 62 | * Make "Restore from file" and "Restore from PrevMBR" exclusive 63 | 64 | 2007-01-20 version 1.1 beta3 65 | * Fix a bug when installing GRLDR to floppy image 66 | 67 | 2007-01-19 version 1.1 beta2 68 | * Fix a bug in the partition enumerator xd_enum 69 | * Fix Linux 64-bit off_t bug 70 | 71 | 2007-01-18 version 1.1 beta1 72 | * Merge platform specific makefiles 73 | * Support key code translation in grubinst 74 | * Add --list-part option to grubinst 75 | * Add floppy support to grubinst 76 | * Add partition support to grubinst 77 | * Major change in the layout of grubinst_gui 78 | * Support Chinese language in grubinst_gui 79 | 80 | 2006-12-30 version 1.0.1 81 | * Minor change 82 | 83 | 2006-12-28 version 1.0.0 84 | * First release -------------------------------------------------------------------------------- /grubutils/grubinst/g2hdr.S: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #define CODE_ADDR 0x700 20 | #define CODE_LENG 0x200 // 1 sector 21 | #define DATA_ADDR 0x820 22 | 23 | #define BLCK_LENG 0x8000 24 | 25 | .file "g2hdr.S" 26 | 27 | .text 28 | 29 | .code16 30 | 31 | .globl start, _start 32 | 33 | start: 34 | _start: 35 | 36 | // Move itself to CODE_ADDR:0 37 | // Don't modify dx 38 | 39 | cld 40 | movw %cs, %ax 41 | movw %ax, %ds 42 | movw $CODE_ADDR, %ax 43 | movw %ax, %es 44 | xorw %si, %si 45 | movw %si, %di 46 | movw $(CODE_LENG >> 2), %cx 47 | 48 | rep 49 | movsl 50 | 51 | ljmp $0, $(jump_start-start+(CODE_ADDR << 4)) 52 | 53 | jump_start: 54 | // Move core.img to 0x820:0 55 | 56 | movw %ds, %ax 57 | addw $((CODE_LENG >> 4)+0x20), %ax 58 | movw %ax, %ds 59 | movw $(DATA_ADDR), %ax 60 | movw %ax, %es 61 | xorl %eax, %eax 62 | movb %dh, %al 63 | movl %eax, 0x14 // GRUB_KERNEL_MACHINE_INSTALL_DOS_PART 64 | movl 0x10, %eax // GRUB_KERNEL_MACHINE_COMPRESSED_SIZE 65 | addl $0x4A0, %eax // GRUB_KERNEL_MACHINE_RAW_SIZE 66 | xorl %ecx, %ecx 67 | 68 | 1: 69 | xorw %si, %si 70 | movw %si, %di 71 | 72 | movw $(BLCK_LENG), %cx 73 | cmpl %ecx, %eax 74 | jae 2f 75 | movw %ax, %cx 76 | 2: 77 | 78 | pushw %cx 79 | addw $3, %cx 80 | shrw $2, %cx 81 | 82 | rep 83 | movsl 84 | 85 | popw %cx 86 | 87 | movw %ds, %si 88 | addw $(BLCK_LENG >> 4), %si 89 | movw %si, %ds 90 | 91 | movw %es, %si 92 | addw $(BLCK_LENG >> 4), %si 93 | movw %si, %es 94 | 95 | subl %ecx, %eax 96 | jnz 1b 97 | 98 | movb $0xFF, %dh 99 | 100 | ljmp $0, $(DATA_ADDR << 4) 101 | 102 | . = _start + 0x200 - 2 103 | 104 | .word 0xAA55 105 | 106 | -------------------------------------------------------------------------------- /grubutils/grubinst/grubinst-1.3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/grubutils/grubinst/grubinst-1.3.zip -------------------------------------------------------------------------------- /grubutils/grubinst/grubinst.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/grubutils/grubinst/grubinst.c -------------------------------------------------------------------------------- /grubutils/grubinst/grubinst.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/grubutils/grubinst/grubinst.ico -------------------------------------------------------------------------------- /grubutils/grubinst/grubinst_gui.chs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/grubutils/grubinst/grubinst_gui.chs -------------------------------------------------------------------------------- /grubutils/grubinst/readme.txt: -------------------------------------------------------------------------------- 1 | 1. Introdution 2 | 3 | This utility is used to install GRUB4DOS boot code to the MBR or partition 4 | boot sector of hard disk or image file. 5 | 6 | grubinst.exe is a console mode program. It mimics the behavior of the DOS/Linux 7 | utility bootlace.com from TinyBit's GRUB4DOS package. But unlike bootlace.com, 8 | grubinst is writen completely in C and can be compiled to run in OSs like 9 | Windows NT/2K/XP, Linux and FreeBSD. 10 | 11 | grubinst_gui.exe is a GUI frontend to grubinst.exe. It provides a friendly 12 | interface to users who are not familiar whith the command line environment. 13 | Currently, grubinst_gui.exe only runs in Windows OSs. 14 | 15 | Please note that these utilities only install MBR, it DOES NOT copy GRLDR to 16 | your partition or configure menu.lst, neither does it modify boot.ini to enable 17 | booting from the NT boot manager. To know more about such things, please refers 18 | to readme file from the GRUB4DOS package. 19 | 20 | Also note that the current version of grubinst doesn't support modify the MBR 21 | of hard disk in Windows 95/98/ME. For those OSs, bootlace.com should be used 22 | instead. 23 | 24 | 2. Documents 25 | 26 | Documents have been moved to the grub4dos homepage at sourceforge.net: 27 | 28 | http://grub4dos.sourceforge.net 29 | 30 | 3. Useful links 31 | 32 | http://grub4dos.sourceforge.net/ 33 | grubinst and wingrub homepage 34 | 35 | http://grub4dos.jot.com/ 36 | Latest GRUB4DOS package by TinyBit 37 | 38 | http://www.znpc.net/bbs 39 | Chinese forum on GRUB4DOS 40 | 41 | http://grub.linuxeden.com/ 42 | Misc information by TinyBit, also in chinese 43 | -------------------------------------------------------------------------------- /grubutils/grubinst/resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123@126.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 | */ 19 | 20 | #define DLG_MAIN 1 21 | #define DLG_OUTPUT 2 22 | 23 | #define ICO_MAIN 10 24 | 25 | #define IDC_GROUPBOX1 100 26 | #define IDC_ISDISK 101 27 | #define IDC_DISKS 102 28 | #define IDC_REFRESH_DISK 103 29 | #define IDC_ISFILE 104 30 | #define IDC_FILENAME 105 31 | #define IDC_BROWSE 106 32 | #define IDC_LFILESYSTEM 107 33 | #define IDC_FILESYSTEM 108 34 | #define IDC_LPART 109 35 | #define IDC_PARTS 110 36 | #define IDC_ORDER_PART 111 37 | #define IDC_LSTATUS 112 38 | #define IDC_STATUS 113 39 | #define IDC_CHOOSEVER 114 40 | 41 | #define IDC_GROUPBOX2 120 42 | #define IDC_VERBOSE 121 43 | #define IDC_NO_BACKUP_MBR 122 44 | #define IDC_DISABLE_FLOPPY 123 45 | #define IDC_DISABLE_OSBR 124 46 | #define IDC_PREVMBR_FIRST 125 47 | #define IDC_SILENT 126 48 | #define IDC_COPY_BPB 127 49 | #define IDC_SKIP 128 50 | #define IDC_CHS_NO_TUNE 129 51 | #define IDC_LOCK 130 52 | #define IDC_UNMOUNT 131 53 | #define IDC_LTIMEOUT 132 54 | #define IDC_TIMEOUT 133 55 | #define IDC_LHOTKEY 134 56 | #define IDC_HOTKEY 135 57 | #define IDC_LBOOTFILE 136 58 | #define IDC_BOOTFILE 137 59 | #define IDC_LEXTRA 138 60 | #define IDC_EXTRA 139 61 | 62 | #define IDC_GROUPBOX3 141 63 | #define IDC_LSAVEFILE 142 64 | #define IDC_SAVEFILE 143 65 | #define IDC_BROWSE_SAVE 144 66 | #define IDC_SAVEMBR 145 67 | #define IDC_RESTOREMBR 146 68 | #define IDC_RESTORE_PREVMBR 147 69 | #define IDC_OUTPUT 148 70 | 71 | #define IDC_TEST 160 72 | #define IDC_INSTALL 161 73 | #define IDC_QUIT 162 74 | 75 | #define IDC_COUNT_MAIN 300 76 | 77 | #define IDC_RICHEDIT 300 78 | #define IDC_COPY 301 79 | #define IDC_SELALL 302 80 | #define IDC_CLOSE 303 81 | 82 | #define IDC_COUNT_OUTPUT 10 83 | 84 | #define IDS_BEGIN 500 85 | 86 | #define IDS_MAIN 500 87 | #define IDS_OUTPUT 501 88 | #define IDS_NO_SAVEFILE 502 89 | #define IDS_NO_RESTOREFILE 503 90 | #define IDS_NO_DISKNAME 504 91 | #define IDS_NO_FILENAME 505 92 | #define IDS_NO_DEVICETYPE 506 93 | #define IDS_EXEC_ERROR 507 94 | #define IDS_INVALID_FILE 508 95 | #define IDS_WHOLE_DISK 509 96 | #define IDS_NO_DEVICE 510 97 | #define IDS_INVALID_MBR 511 98 | #define IDS_OSDRIVE 512 99 | #define IDS_NO_GRUBINST 513 100 | #define IDS_INSTALL 514 101 | #define IDS_UPDATE 515 102 | #define IDS_UNKNOWN 516 103 | #define IDS_ENHANCED 517 104 | #define IDS_INSTALLED 518 105 | #define IDS_UNSUPPORTED 519 106 | #define IDS_NOT_INSTALLED 520 107 | #define IDS_INSTALL_MODE 521 108 | #define IDS_EDIT_MODE 522 109 | #define IDS_OPTIONS 523 110 | #define IDS_BR_TO_FILE 524 111 | #define IDS_COPY_TO_FILE 525 112 | #define IDS_BR_FROM_FILE 526 113 | #define IDS_SAVE 527 114 | #define IDS_COPY 528 115 | #define IDS_RESTORE 529 116 | #define IDS_ENHANCED_VERSION 530 117 | #define IDS_NORMAL_VERSION 531 118 | #define IDS_UNSUPPORTED_VERSION 532 119 | #define IDS_STARTING 533 120 | #define IDS_ERROR_CODE 534 121 | #define IDS_NO_RICHED20 535 122 | #define IDS_RAW_DISK 536 123 | #define IDS_ALL_FILES 537 124 | #define IDS_BIN_FILES 538 125 | #define IDS_PBR_FILES 539 126 | #define IDS_MBR_FILES 540 127 | #define IDS_G4D_LOADER 541 128 | #define IDS_G2_LOADER 542 129 | #define IDS_AUTODETECT 543 130 | #define IDS_OBSOLETE_VERSION 544 131 | 132 | #define IDS_END 550 133 | #define IDS_COUNT (IDS_END-IDS_BEGIN+1) 134 | -------------------------------------------------------------------------------- /grubutils/grubinst/version: -------------------------------------------------------------------------------- 1 | 1.4 2 | -------------------------------------------------------------------------------- /grubutils/loadbin/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(SRCDIR),) 20 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 21 | endif 22 | 23 | PACKAGE = loadbin 24 | 25 | loadbin_ASRC = ldgrub2.S ldgrub.S ldntldr.S 26 | loadbin_AEXT = header.S 27 | loadbin_CSRC = mkimage.c 28 | loadbin_SRCS = $(loadbin_ASRC) $(loadbin_AEXT) $(loadbin_CSRC) 29 | loadbin_EXES = $(subst .c,$(EXEEXT),$(loadbin_CSRC)) 30 | loadbin_BINS = $(subst .S,.bin,$(loadbin_ASRC)) 31 | 32 | extra_SRCS = Makefile version 33 | 34 | all_SRCS = $(loadbin_SRCS) $(extra_SRCS) 35 | all_EXES = $(loadbin_EXES) 36 | all_BINS = $(loadbin_BINS) 37 | 38 | cmn_DIST = COPYING 39 | cmn_SRCS = common.mk ldscript 40 | 41 | extra_CLEAN = *.pre 42 | 43 | -include common.mk $(SRCDIR)../common/common.mk 44 | 45 | .PRECIOUS: %.o 46 | 47 | %.bin: %.pre 48 | $(OC) $(OCFLAGS) -O binary $< $@ 49 | ./mkimage$(EXEEXT) $@ $@ 50 | 51 | $(subst .S,.bin,$(loadbin_ASRC)): mkimage$(EXEEXT) 52 | 53 | ldgrub2.pre: ldscript header.o ldgrub2.o 54 | $(LD) $(LDFLAGS) -T $^ -o $@ 55 | 56 | ldgrub.pre: ldscript header.o ldgrub.o 57 | $(LD) $(LDFLAGS) -T $^ -o $@ 58 | 59 | ldntldr.pre: ldscript header.o ldntldr.o 60 | $(LD) $(LDFLAGS) -T $^ -o $@ 61 | -------------------------------------------------------------------------------- /grubutils/loadbin/ldgrub.S: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007,2008 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | .file "ldgrub.S" 20 | 21 | #include 22 | 23 | #define DATA_ADDR 0x8000 24 | 25 | .text 26 | 27 | .code16 28 | 29 | DEF_FUNC(main) 30 | movl $DATA_ADDR, %edi 31 | 32 | call EXT_FUNC(move_memory) 33 | 34 | pushw %ss 35 | popw %ds 36 | 37 | movsbl %dh, %eax 38 | 39 | /* install_partition. */ 40 | movl %eax, (DATA_ADDR + 0x208) 41 | 42 | ljmp $((DATA_ADDR >> 4) + 0x20), $0 43 | -------------------------------------------------------------------------------- /grubutils/loadbin/ldgrub2.S: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007,2008 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | .file "ldgrub2.S" 20 | 21 | #include 22 | 23 | #define DATA_ADDR 0x8000 24 | 25 | .text 26 | 27 | .code16 28 | 29 | DEF_FUNC(main) 30 | movl $DATA_ADDR, %edi 31 | 32 | call EXT_FUNC(move_memory) 33 | 34 | pushw %ss 35 | popw %ds 36 | 37 | movsbl %dh, %eax 38 | 39 | /* GRUB_KERNEL_MACHINE_INSTALL_DOS_PART. */ 40 | movl %eax, (DATA_ADDR + 0x214) 41 | 42 | movb $0xFF, %dh 43 | 44 | ljmp $((DATA_ADDR >> 4) + 0x20), $0 45 | -------------------------------------------------------------------------------- /grubutils/loadbin/ldntldr.S: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007,2008 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | .file "ldntldr.S" 20 | 21 | #include 22 | 23 | #define DATA_ADDR 0x20000 24 | 25 | .text 26 | 27 | .code16 28 | 29 | DEF_FUNC(main) 30 | movl $DATA_ADDR, %edi 31 | 32 | call EXT_FUNC(move_memory) 33 | 34 | ljmp $(DATA_ADDR >> 4), $0 35 | -------------------------------------------------------------------------------- /grubutils/loadbin/mkimage.c: -------------------------------------------------------------------------------- 1 | /* 2 | * GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | * Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define BUF_SIZE 16384 27 | 28 | #define OFS_HLEN 0x1F1 29 | #define OFS_REDX 0x260 30 | #define OFS_DLEN 0x264 31 | 32 | #define APP_NAME "mkimage" 33 | 34 | #define valueat(buf,ofs,type) *((type*)(((char*)&buf)+ofs)) 35 | 36 | void usage(int status) 37 | { 38 | fprintf(stderr, 39 | "Usage:\n" 40 | " mkimage [OPTIONS] header [image] output\n\n" 41 | "Options:\n" 42 | " -d\t\tdrive[,part]\tSet default drive and partition\n"); 43 | exit(status); 44 | } 45 | 46 | void quit(int syserr,char *fmt, ...) 47 | { 48 | va_list argptr; 49 | 50 | va_start(argptr, fmt); 51 | 52 | fprintf(stderr, APP_NAME ": "); 53 | vfprintf(stderr, fmt, argptr); 54 | if (syserr) 55 | fprintf(stderr,": %s\n", strerror(errno)); 56 | else 57 | fprintf(stderr,"\n"); 58 | 59 | va_end(argptr); 60 | 61 | exit(1); 62 | } 63 | 64 | unsigned char buf[BUF_SIZE]; 65 | 66 | int main(int argc, char **argv) 67 | { 68 | char ch,*pout; 69 | FILE *fin,*fout; 70 | long ofs,len,i; 71 | unsigned long edx; 72 | 73 | edx=0xFFFFFFFF; 74 | while ((ch=getopt(argc,argv, "hd:"))!= -1) 75 | switch (ch) { 76 | case 'd': 77 | { 78 | unsigned long drive,part; 79 | char *pp; 80 | 81 | drive=(strtoul(optarg,&pp,0) & 0xFF); 82 | if (*pp==',') 83 | part=(strtoul(pp+1,NULL,0) & 0xFF); 84 | else 85 | part=0xFF; 86 | edx=drive + (part << 16) + 0xFFFF0000; 87 | break; 88 | } 89 | case 'h': 90 | default: 91 | usage(0); 92 | } 93 | 94 | if ((optind + 2 != argc) && (optind + 3 !=argc)) 95 | usage(1); 96 | 97 | fin=fopen(argv[optind], "rb"); 98 | if (fin == NULL) 99 | quit(1, "Unable to open %s", argv[optind]); 100 | 101 | fseek(fin,0,SEEK_END); 102 | len = ftell(fin); 103 | if (len >= BUF_SIZE) 104 | { 105 | fclose(fin); 106 | quit(0, "%s too long", argv[optind]); 107 | } 108 | 109 | fseek(fin, 0, SEEK_SET); 110 | if (fread(buf, len, 1, fin)!=1) 111 | { 112 | fclose(fin); 113 | quit(0, "%s read error", argv[optind]); 114 | } 115 | 116 | fclose(fin); 117 | fin = NULL; 118 | 119 | len = (len + 511) & (~0x1FF); 120 | buf[OFS_HLEN] = (len >> 9) - 1; 121 | if (edx != 0xFFFFFFFF) 122 | valueat(buf, OFS_REDX, unsigned long) = edx; 123 | 124 | if (optind + 2 == argc) 125 | pout=argv[optind + 1]; 126 | else 127 | { 128 | long len1; 129 | 130 | fin=fopen(argv[optind+1], "rb"); 131 | if (fin == NULL) 132 | quit(1, "Unable to open %s", argv[optind+1]); 133 | 134 | fseek(fin,0,SEEK_END); 135 | len1 = ftell(fin); 136 | 137 | if (len1 <= 0) 138 | { 139 | fclose(fin); 140 | quit(0, "%s invalid length", argv[optind+1]); 141 | } 142 | 143 | fseek(fin, 0, SEEK_SET); 144 | 145 | valueat(buf, OFS_DLEN, unsigned long) = len1; 146 | pout = argv[optind + 2]; 147 | } 148 | 149 | fout=fopen(pout, "wb"); 150 | if (fout == NULL) 151 | quit(1, "Unable to open %s", pout); 152 | 153 | if (fwrite(buf, len, 1, fout)!=1) 154 | { 155 | fclose(fout); 156 | quit(0, "%s read error", pout); 157 | } 158 | 159 | if (fin) 160 | { 161 | while (1) 162 | { 163 | len = fread(buf, 1, BUF_SIZE, fin); 164 | if (len < 0) 165 | { 166 | fclose(fin); 167 | fclose(fout); 168 | quit(1, "%s read error", argv[optind+1]); 169 | } 170 | if (len == 0) 171 | break; 172 | if (fwrite(buf, len, 1, fout)!=1) 173 | { 174 | fclose(fin); 175 | fclose(fout); 176 | quit(1, "%s write error", pout); 177 | } 178 | } 179 | fclose(fin); 180 | } 181 | fclose(fout); 182 | 183 | return 0; 184 | } 185 | -------------------------------------------------------------------------------- /grubutils/loadbin/version: -------------------------------------------------------------------------------- 1 | 0.1 2 | -------------------------------------------------------------------------------- /grubutils/makemod/Makefile: -------------------------------------------------------------------------------- 1 | ifeq ($(SRCDIR),) 2 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 3 | endif 4 | 5 | PACKAGE = makemod 6 | 7 | makemod_CSRC = makemod.c 8 | makemod_SRCS = $(makemod_CSRC) 9 | makemod_EXES = $(subst .c,$(EXEEXT),$(makemod_CSRC)) 10 | 11 | extra_SRCS = Makefile 12 | 13 | all_SRCS = $(makemod_SRCS) $(extra_SRCS) 14 | all_EXES = $(makemod_EXES) 15 | 16 | -include common.mk $(SRCDIR)../common/common.mk 17 | 18 | makemod$(EXEEXT): makemod.o 19 | $(CC) $(CFLAGS) -o $@ $^ 20 | -------------------------------------------------------------------------------- /grubutils/makemod/makemod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc,char *argv[]) 6 | { 7 | int i; 8 | FILE *fp; 9 | FILE *f_mod = fopen("grub4dos.mod","wb"); 10 | 11 | struct 12 | { 13 | char filename[12]; 14 | unsigned long size; 15 | } grub_mod = {"\x05\x18\x05\x03\xBA\xA7\xBA\xBC",0}; 16 | fwrite(&grub_mod,1,16,f_mod); 17 | char *buff=malloc(0xa000); 18 | unsigned long n; 19 | for(i = 1; i < argc; i++) 20 | { 21 | if ((fp=fopen(argv[i],"rb"))==NULL) 22 | { 23 | printf("Err open file %s\n",argv[i]); 24 | continue; 25 | } 26 | memset(&grub_mod,0,16); 27 | strncpy(grub_mod.filename,argv[i],11); 28 | n = fread(buff,1,0xa000,fp); 29 | fgetc(fp); 30 | if (feof(fp)) 31 | { 32 | grub_mod.size=n; 33 | fwrite(&grub_mod,1,16,f_mod); 34 | fwrite(buff,1,n,f_mod); 35 | } 36 | else 37 | printf("Err read file %s,%lx\n",argv[i],n); 38 | 39 | fclose(fp); 40 | } 41 | fclose(f_mod); 42 | free(buff); 43 | return 1; 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /grubutils/makerom/LzmaDecode.h: -------------------------------------------------------------------------------- 1 | /* 2 | LzmaDecode.h 3 | LZMA Decoder interface 4 | 5 | LZMA SDK 4.40 Copyright (c) 1999-2006 Igor Pavlov (2006-05-01) 6 | http://www.7-zip.org/ 7 | 8 | LZMA SDK is licensed under two licenses: 9 | 1) GNU Lesser General Public License (GNU LGPL) 10 | 2) Common Public License (CPL) 11 | It means that you can select one of these two licenses and 12 | follow rules of that license. 13 | 14 | SPECIAL EXCEPTION: 15 | Igor Pavlov, as the author of this code, expressly permits you to 16 | statically or dynamically link your code (or bind by name) to the 17 | interfaces of this file without subjecting your linked code to the 18 | terms of the CPL or GNU LGPL. Any modifications or additions 19 | to this file, however, are subject to the LGPL or CPL terms. 20 | */ 21 | 22 | #ifndef __LZMADECODE_H 23 | #define __LZMADECODE_H 24 | 25 | #include "LzmaTypes.h" 26 | 27 | /* #define _LZMA_IN_CB */ 28 | /* Use callback for input data */ 29 | 30 | /* #define _LZMA_OUT_READ */ 31 | /* Use read function for output data */ 32 | 33 | /* #define _LZMA_PROB32 */ 34 | /* It can increase speed on some 32-bit CPUs, 35 | but memory usage will be doubled in that case */ 36 | 37 | /* #define _LZMA_LOC_OPT */ 38 | /* Enable local speed optimizations inside code */ 39 | 40 | #ifdef _LZMA_PROB32 41 | #define CProb UInt32 42 | #else 43 | #define CProb UInt16 44 | #endif 45 | 46 | #define LZMA_RESULT_OK 0 47 | #define LZMA_RESULT_DATA_ERROR 1 48 | 49 | #ifdef _LZMA_IN_CB 50 | typedef struct _ILzmaInCallback 51 | { 52 | int (*Read)(void *object, const unsigned char **buffer, SizeT *bufferSize); 53 | } ILzmaInCallback; 54 | #endif 55 | 56 | #define LZMA_BASE_SIZE 1846 57 | #define LZMA_LIT_SIZE 768 58 | 59 | #define LZMA_PROPERTIES_SIZE 5 60 | 61 | typedef struct _CLzmaProperties 62 | { 63 | int lc; 64 | int lp; 65 | int pb; 66 | #ifdef _LZMA_OUT_READ 67 | UInt32 DictionarySize; 68 | #endif 69 | }CLzmaProperties; 70 | 71 | int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size); 72 | 73 | #define LzmaGetNumProbs(Properties) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((Properties)->lc + (Properties)->lp))) 74 | 75 | #define kLzmaNeedInitId (-2) 76 | 77 | typedef struct _CLzmaDecoderState 78 | { 79 | CLzmaProperties Properties; 80 | CProb *Probs; 81 | 82 | #ifdef _LZMA_IN_CB 83 | const unsigned char *Buffer; 84 | const unsigned char *BufferLim; 85 | #endif 86 | 87 | #ifdef _LZMA_OUT_READ 88 | unsigned char *Dictionary; 89 | UInt32 Range; 90 | UInt32 Code; 91 | UInt32 DictionaryPos; 92 | UInt32 GlobalPos; 93 | UInt32 DistanceLimit; 94 | UInt32 Reps[4]; 95 | int State; 96 | int RemainLen; 97 | unsigned char TempDictionary[4]; 98 | #endif 99 | } CLzmaDecoderState; 100 | 101 | #ifdef _LZMA_OUT_READ 102 | #define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; } 103 | #endif 104 | 105 | int LzmaDecode(CLzmaDecoderState *vs, 106 | #ifdef _LZMA_IN_CB 107 | ILzmaInCallback *inCallback, 108 | #else 109 | const unsigned char *inStream, SizeT inSize, SizeT *inSizeProcessed, 110 | #endif 111 | unsigned char *outStream, SizeT outSize, SizeT *outSizeProcessed); 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /grubutils/makerom/LzmaTypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | LzmaTypes.h 3 | 4 | Types for LZMA Decoder 5 | 6 | This file written and distributed to public domain by Igor Pavlov. 7 | This file is part of LZMA SDK 4.40 (2006-05-01) 8 | */ 9 | 10 | #ifndef __LZMATYPES_H 11 | #define __LZMATYPES_H 12 | 13 | #ifndef _7ZIP_BYTE_DEFINED 14 | #define _7ZIP_BYTE_DEFINED 15 | typedef unsigned char Byte; 16 | #endif 17 | 18 | #ifndef _7ZIP_UINT16_DEFINED 19 | #define _7ZIP_UINT16_DEFINED 20 | typedef unsigned short UInt16; 21 | #endif 22 | 23 | #ifndef _7ZIP_UINT32_DEFINED 24 | #define _7ZIP_UINT32_DEFINED 25 | #ifdef _LZMA_UINT32_IS_ULONG 26 | typedef unsigned long UInt32; 27 | #else 28 | typedef unsigned int UInt32; 29 | #endif 30 | #endif 31 | 32 | /* #define _LZMA_NO_SYSTEM_SIZE_T */ 33 | /* You can use it, if you don't want */ 34 | 35 | #ifndef _7ZIP_SIZET_DEFINED 36 | #define _7ZIP_SIZET_DEFINED 37 | #ifdef _LZMA_NO_SYSTEM_SIZE_T 38 | typedef UInt32 SizeT; 39 | #else 40 | #include 41 | typedef size_t SizeT; 42 | #endif 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /grubutils/makerom/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(SRCDIR),) 20 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 21 | endif 22 | 23 | PACKAGE = makerom 24 | 25 | makerom_ASRC = rom.S 26 | makerom_CSRC = makerom.c 27 | makerom_SRCS = $(makerom_ASRC) $(makerom_CSRC) 28 | makerom_EXES = $(subst .c,$(EXEEXT),$(makerom_CSRC)) 29 | makerom_BINS = rom_isa.bin rom_pci.bin rom_zisa.bin rom_zpci.bin 30 | 31 | extra_SRCS = Makefile version LzmaDecode.c LzmaDecode.s LzmaDecode.h LzmaTypes.h 32 | 33 | all_SRCS = $(makerom_SRCS) $(extra_SRCS) 34 | all_EXES = $(makerom_EXES) 35 | all_BINS = $(makerom_BINS) 36 | all_OBJS = keytab.o 37 | 38 | cmn_SRCS = common.mk ldscript keytab.c keytab.h 39 | 40 | extra_CLEAN = *.pre 41 | 42 | -include common.mk $(SRCDIR)../common/common.mk 43 | 44 | #LzmaDecode.s: LzmaDecode.c LzmaDecode.h LzmaTypes.h 45 | # gcc -Os -S -o $@ $< 46 | 47 | rom_isa.pre: rom.S 48 | $(CC) -nostdlib -MMD -Wl,-T -Wl,$(CMNDIR)ldscript -o $@ $< 49 | 50 | rom_pci.pre: rom.S 51 | $(CC) -nostdlib -MMD -DPCI -Wl,-T -Wl,$(CMNDIR)ldscript -o $@ $< 52 | 53 | rom_zisa.pre: rom.S 54 | $(CC) -nostdlib -MMD -DLZMA -Wl,-T -Wl,$(CMNDIR)ldscript -o $@ $< 55 | 56 | rom_zpci.pre: rom.S 57 | $(CC) -nostdlib -MMD -DPCI -DLZMA -Wl,-T -Wl,$(CMNDIR)ldscript -o $@ $< 58 | 59 | makerom$(EXEEXT): makerom.o keytab.o 60 | $(CC) $(CFLAGS) -o $@ $^ 61 | -------------------------------------------------------------------------------- /grubutils/makerom/mkrom.mk: -------------------------------------------------------------------------------- 1 | EXEEXT=.exe 2 | 3 | all: rom_isa.img rom_pci.img rom_isa_lzma.img rom_pci_lzma.img makerom$(EXEEXT) 4 | 5 | rom_isa.img: romboot.S 6 | gcc -nostdlib -Wl,-T -Wl,ldscript -o rom_isa$(EXEEXT) $< 7 | objcopy -O binary rom_isa$(EXEEXT) $@ 8 | rm rom_isa$(EXEEXT) 9 | 10 | rom_pci.img: romboot.S 11 | gcc -nostdlib -Wl,-T -DPCI -Wl,ldscript -o rom_pci$(EXEEXT) $< 12 | objcopy -O binary rom_pci$(EXEEXT) $@ 13 | rm rom_pci$(EXEEXT) 14 | 15 | rom_isa_lzma.img: romboot.S 16 | gcc -nostdlib -Wl,-T -DLZMA -Wl,ldscript -o rom_isa_lzma$(EXEEXT) $< 17 | objcopy -O binary rom_isa_lzma$(EXEEXT) $@ 18 | rm rom_isa_lzma$(EXEEXT) 19 | 20 | rom_pci_lzma.img: romboot.S 21 | gcc -nostdlib -Wl,-T -DLZMA -DPCI -Wl,ldscript -o rom_pci_lzma$(EXEEXT) $< 22 | objcopy -O binary rom_pci_lzma$(EXEEXT) $@ 23 | rm rom_pci_lzma$(EXEEXT) 24 | 25 | makerom$(EXEEXT): makerom.c 26 | gcc -mno-cygwin -o $@ $< -------------------------------------------------------------------------------- /grubutils/makerom/version: -------------------------------------------------------------------------------- 1 | 0.1 2 | -------------------------------------------------------------------------------- /grubutils/wee/Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | SRC_C := builtins.c disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c 3 | SRC_S := asm.S wee63start.S 4 | BUILDROOT := . 5 | LDFLAGS := 6 | 7 | ifneq ($(WEE127),1) 8 | OBJDIR := . 9 | DEFINES := 10 | else 11 | OBJDIR := wee127 12 | DEFINES := -DMBRSECTORS127 13 | endif 14 | 15 | ifneq ($(BUILDIDUNSUPPORTTED),1) 16 | LDFLAGS += -Wl,--build-id=none 17 | BUILDIDUNSUPPORTTED := 0 18 | endif 19 | 20 | OBJS := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(SRC_C))) $(addprefix $(OBJDIR)/,$(subst .S,.o,$(SRC_S))) 21 | 22 | 23 | #all: PRE $(OBJDIR)/wee63.mbr $(OBJDIR)/wee127.mbr POST 24 | all: wee63 wee127 25 | 26 | wee63: $(OBJDIR)/wee63.mbr 27 | 28 | wee127: wee127.mbr 29 | 30 | .SUFFIXES: .exec .S .c .o 31 | 32 | #PRE: 33 | # @mkdir -p wee127 34 | # -rm -f $(BUILDROOT)/wee127.mbr 35 | 36 | #POST: 37 | # -cp wee127/wee63.mbr $(BUILDROOT)/wee127.mbr 38 | 39 | clean: 40 | rm -f $(OBJDIR)/*.o $(OBJDIR)/wee63start $(OBJDIR)/pre_stage2 41 | ifneq ($(WEE127),1) 42 | $(MAKE) WEE127=1 clean 43 | else 44 | rm -f $(OBJDIR)/wee63.mbr 45 | endif 46 | 47 | distclean: 48 | rm -rf *~ *.o wee63start pre_stage2 wee127 49 | 50 | ifneq ($(WEE127),1) 51 | wee127.mbr: wee127/wee63.mbr 52 | cp wee127/wee63.mbr wee127.mbr 53 | 54 | wee127/wee63.mbr: $(SRC_C) $(SRC_S) shared.h preset_menu_used 55 | $(MAKE) WEE127=1 BUILDIDUNSUPPORTTED=$(BUILDIDUNSUPPORTTED) wee127/wee63.mbr 56 | endif 57 | 58 | .PHONY: all clean distclean wee63 wee127 59 | 60 | $(OBJDIR)/%.o: %.c $(BUILDROOT)/shared.h 61 | @mkdir -p $(OBJDIR) 62 | gcc -m32 -mno-sse -g -Os -fno-stack-protector -fno-builtin -mpreferred-stack-boundary=2 -fno-strict-aliasing -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -nostdinc -Wall -Wmissing-prototypes -Wunused -Wshadow -Wpointer-arith -Wundef $(DEFINES) -c $*.c -o $(OBJDIR)/$*.o 63 | 64 | $(OBJDIR)/%.o: %.S $(BUILDROOT)/shared.h 65 | @mkdir -p $(OBJDIR) 66 | gcc -m32 -mno-sse -g $(DEFINES) -c $*.S -o $(OBJDIR)/$*.o 67 | 68 | $(OBJDIR)/wee63start: $(OBJDIR)/wee63start.o 69 | objcopy -O binary $< $@ 70 | 71 | $(OBJDIR)/pre_stage2: $(OBJDIR)/asm.o $(OBJDIR)/builtins.o $(OBJDIR)/disk_io.o $(OBJDIR)/fsys_ext2fs.o $(OBJDIR)/fsys_fat.o $(OBJDIR)/fsys_ntfs.o 72 | gcc -m32 -mno-sse -g -o $@ -nostdlib -Wl,-N -Wl,-Ttext -Wl,308200 -Wl,-N $(LDFLAGS) $(OBJDIR)/asm.o $(OBJDIR)/builtins.o $(OBJDIR)/disk_io.o $(OBJDIR)/fsys_ext2fs.o $(OBJDIR)/fsys_fat.o $(OBJDIR)/fsys_ntfs.o 73 | objcopy -O binary $@ 74 | echo -n -e "\0260\002\032\0316" >> $@ 75 | 76 | $(OBJDIR)/wee63start.o: $(BUILDROOT)/wee63start.S $(OBJDIR)/stage2_size.h 77 | 78 | $(OBJDIR)/asm.o: $(BUILDROOT)/asm.S $(BUILDROOT)/a20.inc 79 | 80 | $(OBJDIR)/stage2_size.h: $(OBJDIR)/pre_stage2 81 | -rm -f $(OBJDIR)/stage2_size.h 82 | set dummy `ls -l $(OBJDIR)/pre_stage2`; \ 83 | echo "#define STAGE2_SIZE $$6" > $(OBJDIR)/stage2_size.h 84 | 85 | $(OBJDIR)/wee63.mbr: $(OBJDIR)/pre_stage2 $(OBJDIR)/wee63start $(BUILDROOT)/preset_menu_used 86 | -rm -f $(OBJDIR)/wee63.mbr 87 | echo -n -e "\000\000\000\000\000\000\000\000\000\000\000\000" | cat $(OBJDIR)/wee63start $(OBJDIR)/pre_stage2 - > $(OBJDIR)/wee63.mbr 88 | if [ -f $(BUILDROOT)/preset_menu_used ]; then echo -n -e "\000" | cat $(BUILDROOT)/preset_menu_used - >> $(OBJDIR)/wee63.mbr ;fi 89 | 90 | $(BUILDROOT)/preset_menu_used: 91 | echo File not found: preset_menu_used 92 | exit 1 93 | -------------------------------------------------------------------------------- /grubutils/wee/preset_menu_used: -------------------------------------------------------------------------------- 1 | find --set-root /boot/grub/grldr 2 | /boot/grub/grldr 3 | timeout 1 4 | default 0 5 | 6 | title 1. DOS/Windows 7 | find --set-root --active /boot/BCD /bootmgr 8 | find --set-root --active /boot.ini /ntldr 9 | find --set-root --active /command.com /io.sys 10 | find --set-root --active /command.com /kernel.sys 11 | find --set-root /boot/BCD /bootmgr 12 | find --set-root /boot.ini /ntldr 13 | find --set-root /command.com /io.sys 14 | find --set-root /command.com /kernel.sys 15 | 16 | title 2. GRUB4DOS 17 | find --set-root /boot/grub/grldr /boot/grub/grldr 18 | find --set-root /boot/grub.exe /boot/grub.exe 19 | find --set-root /boot/grldr /boot/grldr 20 | find --set-root /grldr /grldr 21 | 22 | title 3. Plop Boot Manager 23 | find --set-root /boot/grub/plpbt.bin /boot/grub/plpbt.bin 24 | 25 | title 4. Vboot 26 | find --set-root /vbootldr /vbootldr 27 | 28 | title 5. Burg 29 | find --set-root /buldr /buldr 30 | 31 | title 6. Previous MBR 32 | (hd0)1+1 33 | 34 | title 7. Command Line 35 | exit 36 | 37 | -------------------------------------------------------------------------------- /grubutils/weesetup/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # GRUB Utilities -- Utilities for GRUB Legacy, GRUB2 and GRUB for DOS 3 | # Copyright (C) 2007 Bean (bean123ch@gmail.com) 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU Affero General Public License as 7 | # published by the Free Software Foundation, either version 3 of the 8 | # License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | ifeq ($(SRCDIR),) 20 | SRCDIR := $(dir $(firstword $(MAKEFILE_LIST))) 21 | endif 22 | 23 | PACKAGE = weesetup 24 | 25 | extra_SRCS = Makefile weesetup.c mbr.h 26 | 27 | all_DIST = 28 | 29 | cmn_SRCS = common.mk ldscript bin2h.c bin2h.pl utils.c utils.h xdio.c xdio.h xd16.asm 30 | 31 | all_SRCS := weesetup.c $(extra_SRCS) 32 | all_OBJS = 33 | all_EXES = weesetup$(EXEEXT) 34 | 35 | extra_CLEAN = mbr.h 36 | 37 | -include common.mk $(SRCDIR)../common/common.mk 38 | 39 | weesetup.o: mbr.h 40 | weesetup$(EXEEXT): weesetup.o xdio.o utils.o 41 | $(CC) $(CFLAGS) -s -o$@ $^ 42 | rm *.o *.d mbr.h 43 | mbr.h: wee63.mbr $(BIN2H_DEPS) 44 | $(BIN2H_EXEC) $< $@ wee63_mbr 45 | wee63.mbr: nt6mbr.bin ../wee/wee63.mbr 46 | ./mkmbr -------------------------------------------------------------------------------- /grubutils/weesetup/doc/WEE_ChangeLog.txt: -------------------------------------------------------------------------------- 1 | 2 | 2011-02-17 fixed a bug of "0xEA not properly restored" in realmode_run(asm.S). 3 | 2011-02-16 fixed a bug on stack checking in realmode_run(asm.S). 4 | 2011-02-01 prevent IO.SYS from wiping out int32-int3F. 5 | 2011-01-31 realmode .com style program support. 6 | 2011-01-14 add comments on how to alter the leading 0xEB for buggy Acer. 7 | 2011-01-07 (Roy)supported drbio.sys that is packed with pack101. 8 | 9 | ------------------------------------------------------------------------ 10 | r14 | Roy | 2010-12-26 09:03:13 +0800 (Sun, 26 Dec 2010) | 3 lines 11 | 12 | wee-2010-12-25 import. 13 | - makefile patch from http://bbs.znpc.net/viewthread.php?tid=5838&page=16&fromuid=14598#pid46984 14 | - changed prototype of rawread to match Grub4DOS 15 | ------------------------------------------------------------------------ 16 | r13 | Roy | 2010-12-23 19:07:09 +0800 (Thu, 23 Dec 2010) | 1 line 17 | 18 | remove intermediate file. 19 | ------------------------------------------------------------------------ 20 | r12 | Roy | 2010-12-19 18:37:09 +0800 (Sun, 19 Dec 2010) | 3 lines 21 | 22 | wee-2010-12-19 import. 23 | - support loading ROM-DOS 7.10 rom-dos.sys/ibmbio.com 24 | - fix loading memdisk initrd low issue 25 | ------------------------------------------------------------------------ 26 | r11 | Roy | 2010-12-19 18:34:29 +0800 (Sun, 19 Dec 2010) | 2 lines 27 | 28 | wee-2010-12-18 import. 29 | - support loading DR DOS 7.01.08 WIP drbio.sys 30 | ------------------------------------------------------------------------ 31 | r10 | Roy | 2010-12-19 18:33:22 +0800 (Sun, 19 Dec 2010) | 3 lines 32 | 33 | wee-2010-12-17 import. 34 | - make the last of contiguous "title" command available and others in contiguous "title" disabled. 35 | - fix command line CF/LF display 36 | ------------------------------------------------------------------------ 37 | r9 | Roy | 2010-12-19 18:31:00 +0800 (Sun, 19 Dec 2010) | 4 lines 38 | 39 | wee-2010-12-16 import. 40 | - fix menu struct corrupting interrupt vector table issue 41 | - adjust menu position 42 | - add "rootnoverify" command 43 | ------------------------------------------------------------------------ 44 | r8 | Roy | 2010-12-19 18:26:25 +0800 (Sun, 19 Dec 2010) | 5 lines 45 | 46 | wee-2010-12-12 (bad) import. 47 | - adding "title" command based menu system. 48 | - adding realmode_run function support. 49 | - this version of menu struct corrupts interrupt vector table. 50 | - *DO NOT USE THIS VERSION* 51 | ------------------------------------------------------------------------ 52 | r7 | Roy | 2010-12-19 18:25:23 +0800 (Sun, 19 Dec 2010) | 3 lines 53 | 54 | wee-2010-06-26 import. 55 | - rename variables 56 | - remove next_partition_partnum 57 | ------------------------------------------------------------------------ 58 | r6 | Roy | 2010-12-19 18:22:54 +0800 (Sun, 19 Dec 2010) | 4 lines 59 | 60 | wee-2010-06-25 import. 61 | - cleanup file systems: 62 | * don't put current_partition into hibyte of boot_drive, use install_partition instead. 63 | * cleanup BSD slice codes. 64 | ------------------------------------------------------------------------ 65 | r5 | Roy | 2010-12-19 18:00:39 +0800 (Sun, 19 Dec 2010) | 2 lines 66 | 67 | wee-2010-06-24 import. 68 | - cleanup "find" command. 69 | ------------------------------------------------------------------------ 70 | r4 | Roy | 2010-12-19 17:57:56 +0800 (Sun, 19 Dec 2010) | 2 lines 71 | 72 | wee-2010-06-23 import. 73 | - adding command line history function. 74 | ------------------------------------------------------------------------ 75 | r3 | Roy | 2010-12-19 17:56:23 +0800 (Sun, 19 Dec 2010) | 3 lines 76 | 77 | wee-2010-06-22 import. 78 | - add "exit" command. 79 | - add more defines. 80 | ------------------------------------------------------------------------ 81 | r2 | Roy | 2010-12-19 17:49:31 +0800 (Sun, 19 Dec 2010) | 2 lines 82 | 83 | wee-2010-06-20 import. 84 | - adding copyright message, license, and readme. 85 | ------------------------------------------------------------------------ 86 | r1 | Roy | 2010-12-19 17:47:18 +0800 (Sun, 19 Dec 2010) | 1 line 87 | 88 | wee-2010-06-19 initial import. 89 | ------------------------------------------------------------------------ 90 | 91 | -------------------------------------------------------------------------------- /grubutils/weesetup/doc/readme.txt: -------------------------------------------------------------------------------- 1 | wee 是一个微型的grub4dos用于安装到硬盘mbr上,可以用来代替之前的grldr.mbr方案。 2 | 3 | 支持的文件系统: FAT12/16/32/NTFS EXT2/3/4 4 | 5 | weesetup是为了方便安装wee63.mbr而写的程序。支持自定义脚本。 6 | 7 | 注意: 如果你的bios不支持EBIOS请不要安装(一般情况下较新的电脑都会支持),具体原因请看下面的WEE说明。 8 | 9 | WEE access disk sectors only using EBIOS(int13/AH=42h), and never using 10 | CHS mode BIOS call(int13/AH=02h). So, if the BIOS does not support EBIOS 11 | on a drive, then WEE will not be able to access that drive. 12 | 13 | WEE supports FAT12/16/32, NTFS and ext2/3/4, and no other file systems are 14 | supported. 15 | 16 | WEE can boot up IO.SYS(Win9x), KERNEL.SYS(FreeDOS), VMLINUZ(Linux), NTLDR/ 17 | BOOTMGR(Windows), GRLDR(grub4dos). And GRUB.EXE(grub4dos) is also bootable 18 | because it is of a valid Linux kernel format. 19 | 20 | Any single sector boot record file(with 55 AA at offset 0x1FE) can boot 21 | as well. 22 | 23 | Besides, WEE can run 32-bit programs written for it. 24 | 2011-03-07 25 | 1.升级内置wee63.mbr到最新版。 26 | 2.修改默认的内置脚本菜单。 27 | 28 | 2011-02-28 29 | 1.升级内置wee63.mbr到最新版. 30 | 31 | 2011-02-17 32 | 1.升级内置wee63.mbr到最新版 33 | 2.添加-l参数,显示磁盘列表。 34 | 3.阻止在使用了fbinst的磁盘上使用该程序。 35 | 36 | 37 | weesetup v1.2. 38 | Usage: 39 | weesetup [OPTIONS] DEVICE 40 | 41 | OPTIONS: 42 | -i wee63.mbr Use a custom wee63.mbr file. 43 | 44 | -o outfile Export new wee63.mbr to outfile. 45 | 46 | -s scriptfile Import script from scriptfile. 47 | 48 | -m mbrfile Read mbr from mbrfile(must use with option -o). 49 | 50 | -f Force install. 51 | -u Update. 52 | -b Backup mbr to second sector(default is nt6mbr). 53 | -l List all disks in system and exit. 54 | 55 | Report bugs to website: 56 | http://code.google.com/p/grubutils/issues 57 | 58 | Thanks: 59 | wee63.mbr (minigrub for mbr by tinybit) 60 | http://bbs.znpc.net/viewthread.php?tid=5838 61 | wee63setup.c by SvOlli,xdio.c by bean 62 | 63 | 64 | wee 安装程序v1.2 65 | 用法: 66 | weesetup [参数] 磁盘 67 | 参数: 68 | -i wee63.mbr 使用外置的wee63.mbr。 69 | 70 | -o outfile 导出新的WEE63.MBR文件到outfile. 71 | 72 | -s scriptfile 导入wee脚本文件. 73 | 74 | -m mbrfile 从mbrfile获取mbr信息(必须配合参数-o使用). 75 | 76 | -f 强制安装. 77 | -u 更新wee. 78 | -b 备份旧的mbr到第二扇区(默认不备份,而是直接使用内置的nt6mbr). 79 | -l 显示所在硬盘列表 80 | 81 | 请到以下网址报告BUG: 82 | http://code.google.com/p/grubutils/issues 83 | 84 | 感谢: 85 | wee63.mbr (minigrub for mbr by tinybit) 86 | http://bbs.znpc.net/viewthread.php?tid=5838 87 | wee63setup.c by SvOlli,xdio.c by bean 88 | 89 | 更多资料请访问我的搏客: 90 | http://chenall.net/post/weesetup/ 91 | 92 | 编译方法: 93 | 94 | 1.首先从SVN下载GRUBUTILS源码 95 | svn co svn://svn.gna.org/svn/grubutil grubutil 96 | 97 | 2.在grubutil目录下新建一个子目录weesetup,然后把weesetup的源码复制过去. 98 | 99 | 在weesetup目录下执行make,就可以在bin目录中生成一个weesetup.exe 100 | 101 | 或直接从googlecode上下载。 102 | svn co http://grubutils.googlecode.com/svn/grubutils grubutils 103 | 104 | cd grubutils 105 | cd weesetup 106 | make 107 | 108 | 109 | 附:内置的wee63.mbr默认脚本内容 110 | find --set-root /boot/grub/grldr 111 | /boot/grub/grldr 112 | timeout 1 113 | default 0 114 | 115 | title 1. Windows 116 | find --set-root --active 117 | +1 118 | find --set-root /bootmgr 119 | /bootmgr 120 | find --set-root /ntldr 121 | /ntldr 122 | 123 | title 2. GRUB4DOS 124 | find --set-root /BOOT/GRUB/GRLDR 125 | /BOOT/GRUB/GRLDR 126 | find --set-root /BOOT/GRUB.EXE 127 | /BOOT/GRUB.EXE 128 | find --set-root /BOOT/GRLDR 129 | /BOOT/GRLDR 130 | find --set-root /grldr 131 | /grldr 132 | 133 | title 3. Plop Boot Manager 134 | find --set-root /BOOT/GRUB/PLPBT.BIN 135 | /BOOT/GRUB/PLPBT.BIN 136 | 137 | title 4. Vboot 138 | find --set-root /vbootldr 139 | /vbootldr 140 | 141 | title 5. Burg 142 | find --set-root /buldr 143 | /buldr -------------------------------------------------------------------------------- /grubutils/weesetup/menu.wee: -------------------------------------------------------------------------------- 1 | find --set-root /boot/grub/grldr 2 | /boot/grub/grldr 3 | timeout 1 4 | default 0 5 | 6 | title 1. Windows 7 | find --set-root --active 8 | +1 9 | find --set-root /bootmgr 10 | /bootmgr 11 | find --set-root /ntldr 12 | /ntldr 13 | 14 | title 2. GRUB4DOS 15 | find --set-root /BOOT/GRUB/GRLDR 16 | /BOOT/GRUB/GRLDR 17 | find --set-root /BOOT/GRUB.EXE 18 | /BOOT/GRUB.EXE 19 | find --set-root /BOOT/GRLDR 20 | /BOOT/GRLDR 21 | find --set-root /grldr 22 | /grldr 23 | 24 | title 3. Plop Boot Manager 25 | find --set-root /BOOT/GRUB/PLPBT.BIN 26 | /BOOT/GRUB/PLPBT.BIN 27 | 28 | title 4. Vboot 29 | find --set-root /vbootldr 30 | /vbootldr 31 | 32 | title 5. Burg 33 | find --set-root /buldr 34 | /buldr -------------------------------------------------------------------------------- /grubutils/weesetup/mkmbr: -------------------------------------------------------------------------------- 1 | dd if=/dev/zero of=./wee63.mbr count=63 2 | ####seek=`cat ../wee/stage2_size.h` 3 | ####seek=`echo $((${seek##* }+0x40C))` 4 | dd conv=notrunc if=../wee/wee63.mbr of=./wee63.mbr bs=1 5 | dd conv=notrunc if=./nt6mbr.bin of=./wee63.mbr seek=1 count=1 6 | ####dd conv=notrunc if=./menu.wee of=./wee63.mbr bs=1 seek=${seek} 7 | -------------------------------------------------------------------------------- /grubutils/weesetup/nt6mbr.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenall/grubutils/267f3902376cc1e4a439c94f2dff9501710a7e94/grubutils/weesetup/nt6mbr.bin -------------------------------------------------------------------------------- /include/grubprog.h: -------------------------------------------------------------------------------- 1 | /* thank goodness gcc will place the above 8 bytes at the end of the b.out 2 | * file. Do not insert any other asm lines here. 3 | */ 4 | /* it seems gcc use end and/or _end for __bss_end */ 5 | #if 1 6 | #define __BSS_END end 7 | #else 8 | #define __BSS_END _end 9 | #endif 10 | 11 | #if 1 12 | #define __BSS_START __bss_start 13 | #elif 1 14 | #define __BSS_START edata 15 | #else 16 | #define __BSS_START _edata 17 | #endif 18 | #define PROG_PSP (char*)(((int)&__BSS_END + 16) & ~0x0F) 19 | extern int __BSS_END; 20 | extern int __BSS_START; 21 | 22 | unsigned long long GRUB = 0x534f443442555247LL;/* this is needed, see the following comment. */ 23 | /* gcc treat the following as data only if a global initialization like the 24 | * above line occurs. 25 | */ 26 | 27 | /* The 40-byte space is structured. */ 28 | asm(".long main"); /* actually not used for now */ 29 | asm(".long .text"); /* actually not used for now */ 30 | asm(".long etext"); /* actually not used for now */ 31 | asm(".long .data"); /* actually not used for now */ 32 | asm(".long edata"); /* actually not used for now */ 33 | asm(".long __bss_start"); /* actually not used for now */ 34 | asm(".long .bss"); /* actually not used for now */ 35 | asm(".long end"); /* this is the process length */ 36 | asm(".ascii \"main\""); 37 | asm(".ascii \"_end\""); 38 | 39 | /* Don't insert any code/data here! */ 40 | 41 | /* these 16 bytes can be used for any purpose. */ 42 | asm(".long 0"); 43 | asm(".long 0"); 44 | asm(".long 0"); 45 | //asm(ASM_BUILD_DATE); //asm(".long 0"); 46 | asm(".long 0"); 47 | /* Don't insert any code/data here! */ 48 | 49 | /* a valid executable file for grub4dos must end with these 8 bytes */ 50 | asm(".long 0x03051805"); 51 | asm(".long 0xBCBAA7BA"); 52 | 53 | asm(".globl _start"); 54 | asm("_start:"); 55 | /* thank goodness gcc will place the above 8 bytes at the end of the program 56 | * file. Do not insert any other asm lines here. 57 | */ 58 | -------------------------------------------------------------------------------- /include/typedef.h: -------------------------------------------------------------------------------- 1 | #ifndef __TYPEDEF__ 2 | #define __TYPEDEF__ 3 | typedef unsigned long DWORD; 4 | typedef int BOOL; 5 | typedef unsigned char BYTE; 6 | typedef unsigned short WORD; 7 | typedef unsigned long long UINT64; 8 | typedef unsigned long UINT32; 9 | typedef unsigned int UINT; 10 | typedef unsigned char* PBYTE; 11 | #endif 12 | -------------------------------------------------------------------------------- /umbr/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | OBJCOPY := objcopy 3 | RM := rm 4 | 5 | CFLAGS := -m32 -mno-sse 6 | 7 | all: bin2c umbr umbr.h 8 | 9 | bin2c: bin2c.c 10 | $(CC) $< -o $@ 11 | 12 | umbr.o: umbr.S 13 | $(CC) $(CFLAGS) -c $< -o $@ 14 | 15 | umbr: umbr.o 16 | $(OBJCOPY) -O binary $< $@ 17 | 18 | umbr.h: umbr 19 | ./bin2c $< $@ umbr 20 | 21 | clean: 22 | $(RM) -f bin2c *.o umbr umbr.h 23 | -------------------------------------------------------------------------------- /umbr/bin2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This is bin2c program, which allows you to convert binary file to 3 | * C language array, for use as embedded resource, for instance you can 4 | * embed graphics or audio file directly into your program. 5 | * This is public domain software, use it on your own risk. 6 | * Contact Serge Fukanchik at fuxx@mail.ru if you have any questions. 7 | * 8 | * Some modifications were made by Gwilym Kuiper (kuiper.gwilym@gmail.com) 9 | * I have decided not to change the licence. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | int 18 | main(int argc, char *argv[]) 19 | { 20 | char *buf; 21 | char *ident; 22 | unsigned int i, file_size, need_comma; 23 | 24 | FILE *f_input, *f_output; 25 | 26 | if (argc < 4) { 27 | fprintf(stderr, "Usage: %s binary_file output_file array_name\n", 28 | argv[0]); 29 | return -1; 30 | } 31 | 32 | f_input = fopen(argv[1], "rb"); 33 | if (f_input == NULL) { 34 | fprintf(stderr, "%s: can't open %s for reading\n", argv[0], argv[1]); 35 | return -1; 36 | } 37 | 38 | // Get the file length 39 | fseek(f_input, 0, SEEK_END); 40 | file_size = ftell(f_input); 41 | fseek(f_input, 0, SEEK_SET); 42 | 43 | buf = (char *) malloc(file_size); 44 | assert(buf); 45 | 46 | fread(buf, file_size, 1, f_input); 47 | fclose(f_input); 48 | 49 | f_output = fopen(argv[2], "w"); 50 | if (f_output == NULL) { 51 | fprintf(stderr, "%s: can't open %s for writing\n", argv[0], argv[2]); 52 | return -1; 53 | } 54 | 55 | ident = argv[3]; 56 | 57 | need_comma = 0; 58 | 59 | fprintf(f_output, "unsigned char %s[] = {", ident); 60 | for (i = 0; i < file_size; ++i) { 61 | if (need_comma) 62 | fprintf(f_output, ", "); 63 | else 64 | need_comma = 1; 65 | if ((i % 11) == 0) 66 | fprintf(f_output, "\n "); 67 | fprintf(f_output, "0x%.2x", buf[i] & 0xff); 68 | } 69 | fprintf(f_output, "\n};\n\n"); 70 | 71 | fprintf(f_output, "unsigned int %s_len = %i;\n", ident, file_size); 72 | 73 | fclose(f_output); 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /wimboot/0002_Fix-optinal-header-in-wimboot-2.8.0.patch: -------------------------------------------------------------------------------- 1 | From 0890cc86c970659dcbefdf5c09c80d975f7184e2 Mon Sep 17 00:00:00 2001 2 | From: MexIT 3 | Date: Tue, 29 Oct 2024 01:24:47 +0000 4 | Subject: [PATCH] Fix optinal header in wimboot 2.8.0 5 | 6 | Thanks @Melanie.Malachite (#1) 7 | --- 8 | src/elf2efi.c | 1 + 9 | 1 file changed, 1 insertion(+) 10 | 11 | diff --git a/src/elf2efi.c b/src/elf2efi.c 12 | index 3109486..39c8d66 100644 13 | --- a/src/elf2efi.c 14 | +++ b/src/elf2efi.c 15 | @@ -249,6 +249,7 @@ static struct pe_header efi_pe_header = { 16 | .MinorLinkerVersion = 42, 17 | .SectionAlignment = EFI_IMAGE_ALIGN, 18 | .FileAlignment = EFI_FILE_ALIGN, 19 | + .MajorImageVersion = 1, 20 | .SizeOfImage = EFI_IMAGE_ALIGN, 21 | .SizeOfHeaders = 22 | ( sizeof ( efi_pe_header ) - 23 | -------------------------------------------------------------------------------- /wimboot/0003_Provide-common-vdisk_read_mem_file-cpio-handler.patch: -------------------------------------------------------------------------------- 1 | From 395f15bb10d35e9f48381898ea3807032e5f8585 Mon Sep 17 00:00:00 2001 2 | From: a1ive 3 | Date: Sat, 4 Nov 2023 10:51:24 +0800 4 | Subject: [PATCH] Provide common vdisk_read_mem_file cpio handler 5 | 6 | https://lists.ipxe.org/pipermail/ipxe-devel/2018-November/006339.html 7 | 8 | Signed-off-by: a1ive 9 | --- 10 | src/main.c | 20 +++----------------- 11 | src/vdisk.c | 13 +++++++++++++ 12 | src/vdisk.h | 2 ++ 13 | 3 files changed, 18 insertions(+), 17 deletions(-) 14 | 15 | diff --git a/src/main.c b/src/main.c 16 | index 371c822..7274344 100644 17 | --- a/src/main.c 18 | +++ b/src/main.c 19 | @@ -226,20 +226,6 @@ static int is_empty_pgh ( const void *pgh ) { 20 | return ( ( dwords[0] | dwords[1] | dwords[2] | dwords[3] ) == 0 ); 21 | } 22 | 23 | -/** 24 | - * Read from file 25 | - * 26 | - * @v file Virtual file 27 | - * @v data Data buffer 28 | - * @v offset Offset 29 | - * @v len Length 30 | - */ 31 | -static void read_file ( struct vdisk_file *file, void *data, size_t offset, 32 | - size_t len ) { 33 | - 34 | - memcpy ( data, ( file->opaque + offset ), len ); 35 | -} 36 | - 37 | /** 38 | * Add embedded bootmgr.exe extracted from bootmgr 39 | * 40 | @@ -337,7 +323,7 @@ static struct vdisk_file * add_bootmgr ( const void *data, size_t len ) { 41 | 42 | /* Add decompressed image */ 43 | return vdisk_add_file ( "bootmgr.exe", initrd, 44 | - decompressed_len, read_file ); 45 | + decompressed_len, vdisk_read_mem_file ); 46 | } 47 | 48 | DBG ( "...no embedded bootmgr.exe found\n" ); 49 | @@ -356,7 +342,7 @@ static int add_file ( const char *name, void *data, size_t len ) { 50 | struct vdisk_file *file; 51 | 52 | /* Store file */ 53 | - file = vdisk_add_file ( name, data, len, read_file ); 54 | + file = vdisk_add_file ( name, data, len, vdisk_read_mem_file ); 55 | 56 | /* Check for special-case files */ 57 | if ( strcasecmp ( name, "bootmgr.exe" ) == 0 ) { 58 | @@ -467,7 +453,7 @@ int main ( void ) { 59 | /* Read bootmgr.exe into memory */ 60 | if ( ! bootmgr ) 61 | die ( "FATAL: no bootmgr.exe\n" ); 62 | - if ( bootmgr->read == read_file ) { 63 | + if ( bootmgr->read == vdisk_read_mem_file ) { 64 | raw_pe = bootmgr->opaque; 65 | } else { 66 | padded_len = ( ( bootmgr->len + PAGE_SIZE - 1 ) & 67 | diff --git a/src/vdisk.c b/src/vdisk.c 68 | index 7885a5b..6685b14 100644 69 | --- a/src/vdisk.c 70 | +++ b/src/vdisk.c 71 | @@ -613,6 +613,19 @@ void vdisk_read ( uint64_t lba, unsigned int count, void *data ) { 72 | DBG2 ( "\n" ); 73 | } 74 | 75 | +/** 76 | + * Read virtual file from memory 77 | + * 78 | + * @v file Virtual file 79 | + * @v data Data buffer 80 | + * @v offset Offset 81 | + * @v len Length 82 | + */ 83 | +void vdisk_read_mem_file ( struct vdisk_file *file, void *data, 84 | + size_t offset, size_t len ) { 85 | + memcpy ( data, ( file->opaque + offset ), len ); 86 | +} 87 | + 88 | /** 89 | * Add file to virtual disk 90 | * 91 | diff --git a/src/vdisk.h b/src/vdisk.h 92 | index 7cae51c..b3b526b 100644 93 | --- a/src/vdisk.h 94 | +++ b/src/vdisk.h 95 | @@ -611,6 +611,8 @@ struct vdisk_file { 96 | extern struct vdisk_file vdisk_files[VDISK_MAX_FILES]; 97 | 98 | extern void vdisk_read ( uint64_t lba, unsigned int count, void *data ); 99 | +extern void vdisk_read_mem_file ( struct vdisk_file *file, void *data, 100 | + size_t offset, size_t len ); 101 | extern struct vdisk_file * 102 | vdisk_add_file ( const char *name, void *opaque, size_t len, 103 | void ( * read ) ( struct vdisk_file *file, void *data, 104 | -------------------------------------------------------------------------------- /wimboot/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rm -rf build 4 | 5 | git clone https://github.com/ipxe/wimboot.git build && cd build 6 | git checkout v2.8.0 7 | 8 | git apply ../0001_Add-EFI-LoadFile2-and-InitrdMedia-headers.patch 9 | git apply ../0002_Fix-optinal-header-in-wimboot-2.8.0.patch 10 | git apply ../0003_Provide-common-vdisk_read_mem_file-cpio-handler.patch 11 | git apply ../0004_Support-EFI-linux-initrd-media-loading.patch 12 | 13 | make -C src wimboot.x86_64 14 | 15 | mv src/wimboot.x86_64 ../wimboot 16 | --------------------------------------------------------------------------------