Can the original img processed with the old version be directly processed with the new version? Or can it only be processed if the img has not been processed?
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
; ==========================================================================
; This is a program used to boot the startup floppy disk of my system backup/restore CD. It will be placed in the first sector of the floppy disk. When this program boots the system, a prompt will appear. The user can choose to press any key to boot the tool floppy disk, or boot the operating system on the hard disk after waiting for 8 seconds. After choosing to boot DOS from the tool floppy disk, the hidden FAT32 primary partition (0B/0C) in the MBR will be assigned a drive letter and become visible, so that conventional tools can be used for backup - backup in the hidden partition, see who can delete it!
; Final version: 2005/9/5
; ==========================================================================
; Programming records:
; The version on June 29 only processed the traditional INT13 function 2, so it worked normally when debugging in a virtual machine with a small hard disk (1B-FAT32), but it failed when it came to a partition (1C-FAT32LBA, 1E-FAT16LBA) that uses LBA mode to read. But now there are no hard disks below 8GB, and reading is almost all in LBA mode.
;
; July 23:
; Added the takeover of the extended INT3 read (function 42), and realized the reading of the hidden LBA partition. Since there are almost no FAT16 partitions on hard disks now, only FAT32 is processed.
; Due to the addition of new code, my original prompt information had to be cut down a bit.
;
; August 22:
; Added a partition flag code list (FlagTable), and judged and processed one by one.
; In FlagTable DW xxyy, xx in each word represents the original partition flag code, and yy represents the hidden partition flag code
; For example, 0414h means that the original partition is 04h (FAT12), and the hidden partition flag code is 14h
; Now, it can be expanded infinitely.
;
; August 28:
; Experimentally added the function of booting from the hidden partition.
; 1. After booting, use your own INT13 to change the original partition activation flag to 00, and change the activation flag of the original hidden partition that can be changed to a normal partition to 80.
; 2. Before installation, judge the key, use DX register as a flag, no key DX=0XFFFF, press F7 when DX=1, CH=1 in INT13, press other keys when DX=0, CH=0 in INT13.
; 3. In INT13, use CH as the judgment flag for whether to activate the hidden partition, and when it is 1, boot from the hidden partition.
; 3. Since the BOCHS virtual machine uses the F11 and F12 keys, the F7 key is set to boot from the hidden partition.
;
; August 31:
; crshen found several BUGs, which are solved one by one. The function of booting from the hidden partition.
; 1. Cannot read F11 because the 0 function of INT10H does not support the extended keyboard, now changed to the 10H function. But in QEMU, the 10 function cannot read F11, and VPC can, maybe because the BIOS of the two is different or QEMU intercepts F11/F12.
; 2. Before installation, judge the key. If you press the ESC key, directly enter the hard disk boot.
; 3. There is a wrong judgment jump, which causes the INT13H 42H function processing to be invalid. I was careless. When adding the processing 42H function code, I forgot to change the previous code.
; 4. Cannot boot from the hidden partition after 8G is because there is a serious error in my INT13 process. This error was introduced due to wrong information in the reference materials. In the INT13H extended function, DS:SI points to DAP, not DS
I as said in that material. This is really...
; In most programs such as MS-FDISK, FREE-FDISK, AEFDISK, PQMAGIC, Acronis Disk Editor, the hidden partition will be displayed as a normal partition, but GDISK can see that this partition is a hidden partition, and GDISK must have a unique access method to the hard disk beyond the BIOS interrupt.
; September 1:
; At present, at 0:47 on September 2, I have eliminated all possible BUGs I can think of, and the length of the program is close to the limit of 512 bytes.
; 1. I found that there was a dead code in the original program. After calling the original INT13 interrupt, AH has been used as the return value, but it is still using AH to judge the extended INT13, so the code for processing the extended INT13 function will not run. Changed to push AX to save, but the code is more chaotic, so I rewrote the previous code.
; 2. After tracking and thinking for two days, I found that the reason why I couldn't boot the OS on the hidden partition on the P4 in the computer room was actually a trick I used to play before. It's really clever but backfires!
; 3. Changed the initial judgment method. In DX, DH=0 installs INT13, DH=FFH does not install; DL=0 loads the floppy disk boot record to start, DL=80H loads the hard disk MBR to start
; 4. Newly added a function ESC key: you can not load this program, and start from the hard disk normally, for general situations.
; 5. Newly added a function F5 key: you can not load this program, and start from the floppy disk normally, for general situations.
; ==========================================================================
;GoodFlag1 equ 0bh
;HideFlag1 equ 1bh
;GoodFlag2 equ 0ch
;HideFlag2 equ 1ch
;GoodFlag3 equ 0eh
;HideFlag3 equ 1eh
ORIGIN EQU 7C00H; Origin of bootstrap LOADER
BIO_MEMEQU 0413H; BIOS Memory size =640(KB)
BIO_CLKEQU 046CH; BIOS Clock (1/18.2 seconds)
DSK_PARMSEQU 1EH*4;POINTER TO DRIVE PARAMETERS
KEY_BOOTHIDDENEQU 41H;Scancode: F7=41H, F11=85H, F12=86H
KEY_BOOTFLOPPYEQU 3FH;Scancode: F5=3FH
KEY_ESCAPEEQU 01H;Scancode: ESC=01H
BOOTHIDDENFLAGEQU 80h
ORG0000h
START:
; WARNING -- Don change this to a short jmp
jmp short main; Jump to start of code
nop
; ==========================================================================
; Start of BPB area of the boot record
OemName DB "MSDOS"
OsVersion DB "5.0"; DOS version number
BPB:
BytesPerSector DW 512; Size of a physical sector
SecsPerClust DB 1; Sectors per allocation unit
ReservedSecs DW 1; Number of reserved sectors
NumFatsDB 2; Number of fats
NumDirEntries DW 00E0h; Number of direc entries
TotalSectors DW 0B40H; Number of sectors - number of hidden
; sectors (0 when 32 bit sector number)
MediaByte DB 0F0H; MediaByte byte
NumFatSecs DW 9; Number of fat sectors
SecPerTrack DW 18; Sectors per track
NumHeads DW 2; Number of drive heads
HiddenSecs DD 0; Number of hidden sectors
BigTotalSecs DD 0; 32 bit version of number of sectors
BootDrv DB 0h
CurrentHead DB 0h; Current Head
ExtBootSig DB 41
SerialNum DD 20050628h
VolumeLabel DB "YISIR_LOADER"
FatId DB "FAT12"
; =========================================================================
; First thing is to reset the stack to a better and more known
; place. The ROM may change, but wed like to get the stack
; in the correct place.
main:
cli;Stop interrupts till stack ok
xor AX,AX
mov ds,ax
mov es,ax
mov SS,AX;Work in stack just below this routine
mov ax,ORIGIN
mov sp,ax
sti
PUSH AX
;Show message
mov ax,1301h
mov bx,000ah
mov cx,MyMsgLen
mov dx,1500h
mov bp,MyMsg+ORIGIN
int 10h
;Hide the cursor
mov ah,1
mov cx,2000h
int 10h
;Wait 10 seconds
mov si, BIO_CLK
mov edx, dword
mov ecx, edx
add edx, 159;18.2*10 seconds
ReadKB:
;Change 5 bytes with install option
;Case Option:/f Boot from floppy disk directly, do not waiting 8 seconds
;31H D2Hxor dx,dx
;E9H xxH 00Hjmp BiosMemory
;
;Case Option:/b Boot from HIDDEN parition derectly (activate it and load it)
;31H D2Hxor dx,dx
;E9H xxH 00Hjmp Key_F7
;
;Case Default: Show message and wait 8 second
mov ah, 11h;Get keyboard status
int 16h
jz NoKeyPress
mov ah,10h;Read a key (In old code, AH=0, can not read F11/F12...)
int 16h
xor dx,dx
cmp ah, KEY_ESCAPE
jz DX_HD;Press ESC to BOOT from Harddisk
cmp ah, KEY_BOOTFLOPPY
jnz RKB_1
mov dh, 0ffh;dh=0 Install INT13, else do not Install. Now DX=FF00H
jmp BiosMemory
RKB_1:
cmp ah, KEY_BOOTHIDDEN
jnz BiosMemory
Key_F7:
;If press Hot key, Boot From Hidden Partition. Now DX=0001H
;modify CH=80h in Int13 procedure
mov byte, BOOTHIDDENFLAG
jmp DX_HD
NoKeyPress:
cmp ecx, dword
jae L_0
test cl,1
jz L_0
mov ax,0e3eh; write ">" to show progressing
mov bx,0004h
int 10h
L_0:
mov ecx, dword
cmp edx,ecx
jae ReadKB
mov dh,0ffh;Do not install INT13. Now DX=FF00
DX_HD:
mov dl,080h;Boot from HD.
;DH=0 Install INT13, DH=FFH do not Install
;DL=0 Boot Floppy, DL=80H Boot HD
;Now:
; ESC DX=FF80, F5 DX=FF00H, F7 DX=0080H, ANYKEY DX=0000H, TIMEOUT DX=FF80H
BiosMemory:
;Show the cursor
mov ah,1
mov cx,0d0eh
int 10h
;BIOS MEMORY - 2KB
mov bx,BIO_MEM;bx=280H (KB)
mov ax,word
dec ax
cmp dh,0
jnz L_1
mov word ,ax;If DH=FF, Do not install
L_1:
;Move to High Memory. ex. 9fc0:0000
shl ax,6;ax=9fc0h SEG of top memory
mov es,ax;es=9fc0h
pop si;si=7c00h
push es;ready to RETF
xor di,di;di=0
cld
mov cx,100h
repnz movsw;move code to 9fc0:0000
cmp dh,0
jnz L_2;If DH=0ffh, Do not install
;modify Int13
mov si,4ch;Int13 13h*4
mov di,OLDINT13
;Save Old
mov eax,
mov ,eax
;cmp dh,0
;jnz L_2;If DH=0ffh, Do not install
push es
pop ax
shl eax,16
mov ax, MyInt13
mov ,eax
L_2:;Jump to high address, 9fc0:00xx
push ds
pop es
mov bx,word Entre2
push bx;push 9fc0:Entre2
retf;跳到高端执行
Entre2:
cmp dl,0;If DX <> 0, Load HD-MBR
jnz L_3
ReadFD:;Read old boot sector from Floppy H1 T79 S18
mov cx,4f12h
mov dx,0100h
jmp RunInt13
L_3:;Read from Harddisk H0 T0 S1 MBR
mov cx,1
mov dx,80h
RunInt13:
mov ax,0201h
mov bx,ORIGIN
push ds
push bx
int 13h
retf
; 2005-9-1
; 这里是原来用的花哨技巧代码,就是它们导致使用F7启动不了隐藏分区。因为这里读到的是原始的MBR
; pushf ;int 13h
; push ds
; push bx
; ------------------------------------------
;Jump to Old INT 13H
JmpFarInt13:
DB 0eah ;JMP far OLDINT13
OLDINT13 DW 0,0
;End of Install-code
;Partition Flag Table normal and hidden
FlagTable:
dw 0111h, 0414h, 0616h, 0717h, 0b1bh, 0c1ch, 0e1eh
FlagTableEnd:
;My INT13h code
MyInt13:
cmp ah,2 ;Is Read?
jz Func2
cmp ah,42h ;Is ExtRead?
jz Func42
JmpOldInt13:
jmp JmpFarInt13
Func2:
CMP DX,0080H;Is Harddisk and Head 0?
jnz JmpOldInt13
cmp cx,0001H;Is Track 0 Sector 1?
jnz JmpOldInt13
pushf;Simulate INT operator
push cs
CALL JmpFarInt13;Call old INT13
jc exit;Flase then Exit
push bx
push es
jmp EditFlag
Func42:
cmp dl,80h;Is Harddisk
jnz JmpOldInt13
push eax
xor eax,eax
cmp dword ,eax;Is Sector 0, Low 32bit
jnz ExitFunc42
cmp dword ,eax;Is Sector 0, Hight 32bit
jnz ExitFunc42
pop eax
pushf;Simulate INT operator
push cs
CALL JmpFarInt13;Call old INT13
jc exit;If flase then Exit
push bx
push es
mov bx, ; Fix BX,ES like Int13h Func02
mov es,
jmp EditFlag
ExitFunc42:
pop eax
jmp JmpOldInt13
EditFlag:
push ax
push cx
push si; DS:SI -> DAP
push ds
push cs
pop ds
add bx, 01c2h; ES:BX -> Partition Flag
BootHiddenCode:
mov cx, 4; CL=4, CH will can be change by Makeimg.c with 1 to Modify the ActiveFlag
cmp1:
mov si, FlagTable
cmp ch, BOOTHIDDENFLAG;If CH=BOOTHIDDENFLAG, Boot from hidden Partition
jnz nextFlag
mov byte , 0;Clear Active Flag for boot from hidden partition
nextFlag:
cld
lodsw
cmp si, FlagTableEnd
jae nextPart
cmp byte , al
jnz nextFlag
mov byte , ah
cmp ch,BOOTHIDDENFLAG;If CH=BOOTHIDDENFLAG, Boot from hidden Partition
jnz JmpNextFlag
mov byte , 80h
xor ch, ch;Set CH=0h, Don't modify the next.
JmpNextFlag:
jmp nextFlag
nextPart:
add bx,10h
dec cl
ja cmp1
pop ds
pop si
pop cx
pop ax
pop es
pop bx
exit:
iret
; End of INT13H code
MyMsg db "PartUnhide Loader, yisir.9126.com, 2005-9-5",13,10
; db "Press any key to load RESTORE FLOPPY DISK...",13,10
MyMsgLen equ $-MyMsg
times 510 -($-$$) db 0
BOOTFLAG db 55h,0aah