; **********************
; * Error message *
; **********************
ErrMsg1 db 'Invalid partition table.',0
ErrMsg2 db 'Error loading operating system.',0
ErrMsg3 db 'Missing operating system.',0
PrintStr:
lodsb ;read a byte from [si]
cmp al,0 ;al=0?
je @exit ;if yes the jump to @exit
push si ;push si to stack
mov bx,7 ;
mov ah,0Eh ;display the char
int 10h
pop si
jmp short PrintStr ;print the next char
@exit:
retn
Tail: ;the Master Boot Record tail
FillNum equ 1BEh-(Tail-Head) ;count the fill number
db FillNum dup (0)
; *******************************************************************
; * The Parttition table data *
; * Notise: You must change the next parttition table data to your *
; * own Hard Disk parttition table data. *
; *******************************************************************
parttable db 80h,01h,01h,00h,06h,3Fh,7Fh,96h,3Fh,00h
db 00h,00h,01h,0Ah,19h,00h,00h,00h,41h,97h,0Fh,3Fh
db 0FFh,0FDh,40h,0Ah,19h,00h,00h,0E6h,25h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h
MagicID dw 0AA55h
end start
1. 主引导记录的安装程序
; *********************************************************************
; * Program:The Cmboot.exe MBR Sector loader.And read the cmos data *
; * and saved it to the harddisk hidden sector. *
; *===================================================================*
; * tasm Cmbootld1.asm *
; * tlink Cmbootld *
; *===================================================================*
; * Designer:Howard *
; * Creat Date:08/29/2000 *
; * Original place:Wuhan *
; * Modification date:08/29/2000 *
; * Now Version:1.0 *
; *===================================================================*
; * Modification History *
; *-------------------------------------------------------------------*
; * Version:1.0 1.Backup the old mbr to a file. *
; * 08/29/2000 2.Load the backup mbr file and saved it to the mbr *
; * sector(cylinder:0,head:0,sector:1). *
; * 3.Saved the cmos data to hard disk hidden sector. *
; * 4.Load the cmoscheckedmbr the mbr sector. *
; * 5.Reboot the computer. *
; *-------------------------------------------------------------------*
; *08/30/2000 6.Modify the psp and _data segment mistake. *
; *-------------------------------------------------------------------*
; * 09/01/2000 7.Modify some bug,and optimize some instructions. *
; *-------------------------------------------------------------------*
; * 09/07/2000 8.Modify the parameter error,ignore the space bet- *
; * ween the program name and parameter. *
; * 9.Modify the file creating problem,add zero to the *
; * end of filename string. *
; *********************************************************************
; * problem: 1.The _data and psp segment address is still a problem. *
; * 09/01/2000 Use a debug information.Maybe the buffer offset address*
; * is not correct,or the data segment is too large. *
; * I haved used two mem unit to save the psp and _data *
; * segment address.Do not use the stack to save psp and *
; * data segment address. *
; * 2.The file "creat/open/read/write" operating is still *
; * a problem. *
; *-------------------------------------------------------------------*
; * bugs: 1.Int 13h ah=02/03h es:bx point to the buffer,but *
; * modifying program executing,es=psp segment address,it must *
; * 09/01/2000 be make it equarl the real buffer segment address. *
; * 2.Push and pop operating must be make sure the *
; * operands is correct. *
; * 09/07/2000 3.The program can not creat a new file.error writing *
; * device AUX. *
; *********************************************************************
; dosseg
.model small
.486
.stack 200h
.data
;以下数据(SECTOR)是通过编译CMOSBOOT.ASM后用DEBUG得到CMOSBOOT.bin和并用BINTODAT.EXE转换CMOSBOOT.BIN得出来的
sector db 0FAh,33h,0C0h,8Eh,0D0h,0BCh,00h,7Ch,8Bh,0F4h,50h,07h
db 50h,1Fh,0FBh,0FCh,0BFh,00h,06h,0B9h,00h,01h,0F2h,0A5h
db 0EAh,1Dh,06h,00h,00h,0B8h,01h,02h,0BBh,00h,08h,0B9h
db 1Dh,00h,0BAh,80h,00h,0CDh,13h,0B8h,10h,00h,0B9h,70h
db 00h,0FCh,0E6h,70h,50h,8Ah,07h,0E6h,71h,58h,0FEh,0C0h
db 43h,0E2h,0F3h,0FDh,0BEh,0BEh,07h,0B3h,04h,80h,3Ch,80h
db 74h,0Eh,80h,3Ch,00h,75h,1Ch,83h,0C6h,10h,0FEh,0CBh
db 75h,0EFh,0CDh,18h,8Bh,14h,8Bh,4Ch,02h,8Bh,0EEh,83h
db 0C6h,10h,0FEh,0CBh,74h,0Dh,80h,3Ch,00h,74h,0F4h,0BEh
db 0A1h,06h,0E8h,83h,00h,0EBh,0FEh,0BFh,05h,00h,0BBh,00h
db 7Ch,0B8h,01h,02h,57h,0CDh,13h,5Fh,73h,0Ch,33h,0C0h
db 0CDh,13h,4Fh,75h,0EDh,0BEh,0BAh,06h,0EBh,0E0h,0BEh,0DAh
db 06h,0BFh,0FEh,7Dh,81h,3Dh,55h,0AAh,75h,0D4h,8Bh,0F5h
db 0EAh,00h,7Ch,00h,00h,49h,6Eh,76h,61h,6Ch,69h,64h
db 20h,70h,61h,72h,74h,69h,74h,69h,6Fh,6Eh,20h,74h
db 61h,62h,6Ch,65h,2Eh,00h,45h,72h,72h,6Fh,72h,20h
db 6Ch,6Fh,61h,64h,69h,6Eh,67h,20h,6Fh,70h,65h,72h
db 61h,74h,69h,6Eh,67h,20h,73h,79h,73h,74h,65h,6Dh
db 2Eh,00h,4Dh,69h,73h,73h,69h,6Eh,67h,20h,6Fh,70h
db 65h,72h,61h,74h,69h,6Eh,67h,20h,73h,79h,73h,74h
db 65h,6Dh,2Eh,00h,0ACh,3Ch,00h,74h,0Bh,56h,0BBh,07h
db 00h,0B4h,0Eh,0CDh,10h,5Eh,0EBh,0F0h,0C3h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,80h,01h,01h,00h,06h,3Fh,7Fh,96h,3Fh,00h
db 00h,00h,01h,0Ah,19h,00h,00h,00h,41h,97h,0Fh,3Fh
db 0FFh,0FDh,40h,0Ah,19h,00h,00h,0E6h,25h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h,00h
db 00h,00h,00h,00h,00h,00h,55h,0AAh
res dw 0072h,0040h
dat dw 0000h,0ffffh
buffer db 512 dup(0)
filename db 'hdpt.dat',0
parameter db 2 dup(?)
copyright db 0dh,0ah,'JiangBiFang,I love you!','$'
helpmsg db 0dh,0ah,'1.cmbootld /c'
db 0dh,0ah,' Saved the cmos data to hard disk hidden sector.'
db 0dh,0ah,'2.cmbootld /w'
db 0dh,0ah,' Load the old mbr data from a file and saved it to mbr sector.'
db 0dh,0ah,'3.cmbootld /s'
db 0dh,0ah,' Saved the mbr sector to a file.'
db 0dh,0ah,'4.cmbootld /l'
db 0dh,0ah,' Load the cmoschecked mbr sector to hard disk.'
db 0dh,0ah,'5.cmbootld /r'
db 0dh,0ah,' Reboot the computer.'
db 0dh,0ah,'6.cmbootld /?'
db 0dh,0ah,' Print the help message.','$'
noparamsg db 0dh,0ah,'Please use cmbootld /? for help.','$'
; debug db 0dh,0ah,'Debug message.','$'
hdbkokmsg db 0dh,0ah,'Harddisk mbr back ok.','$'
hdreaderrmsg db 0dh,0ah,'Harddisk reading error!','$'
hdwriteerrmsg db 0dh,0ah,'Harddisk writing error!','$'
filecreaterrmsg db 0dh,0ah,'File creating error!','$'
fileopenerrmsg db 0dh,0ah,'File opening error!','$'
filewriteerrmsg db 0dh,0ah,'File writing error!','$'
filewriteokmsg db 0dh,0ah,'File writing OK!','$'
filereaderrmsg db 0dh,0ah,'File reading error!','$'
mbrwriteokmsg db 0dh,0ah,'The cmoschecked mbr loading ok!','$'
cmossavedtohdokmsg db 0dh,0ah,'The cmos data haved to harddisk.','$'
mbrbkokmsg db 0dh,0ah,'The old mbr haved backup to the file hdpt.dat.','$'
cmoscheckedmbrldokmsg db 0dh,0ah,'The cmoscheckedmbr haved installed ok!','$'
wrongparamsg db 0dh,0ah,'The wrong parameter:"','$'
.code
start:
main proc far
assume cs:_text,ds:_data,es:_data,ss:stack
mov cs:pspseg,ds
; push ds
xor ax,ax
mov ax,_data
mov cs:dataseg1,ax
mov ds,ax ;ds=_data
mov es,ax ;int 13h es:bx point to buffer,es=seg _data
lea dx,copyright
call disp1
; push ds
; pop cx ;cx=_data
; pop ds ;ds=psg
mov ds,cs:pspseg ;ds=psp
cld
mov si,81h
lodsb
; push ds
; mov ds,cx ;ds=_data seg
mov ds,cs:dataseg1 ;ds=_data
cmp al,0dh
jz nopara
cmp al,' '
jz judgespace
; pop ds ;ds=psp
continue:
push si
dec si
mov ds,cs:pspseg
lodsb
; push ds
; mov ds,cx ;ds=_data
mov ds,cs:dataseg1 ;ds=_data
lea bx,parameter
cmp al,'/'
jz scanparaloop
; lea bx,parameter
; push ds
jmp error
scanparaloop:
mov [bx],al
; pop ds ;ds=psp
mov ds,cs:pspseg
lodsb
; push ds
; mov ds,cx ;ds=_data
mov ds,cs:dataseg1 ;ds=_data
cmp al,0dh
jz choise
inc bx
jnb scanparaloop ;instruction loop can not use rigister cx,
judgespace:
mov ds,cs:pspseg
lodsb
; call debug ;set break point
cmp al,0dh
je nopara
cmp al,' '
je judgespace
jne continue
nopara:
lea dx,noparamsg
jmp disp
; call disp
; call rettodos
help:
lea dx,helpmsg
jmp disp
; call disp
; call rettodos
choise:
; push cx
; mov ds,dataseg1
lea si,parameter
mov al,[si+1]
cmp al,'s'
jz savembr
cmp al,'S'
jz savembr
cmp al,'w'
jz writembr
cmp al,'W'
jz writembr
cmp al,'c'
jz savedcmosdatatohd
cmp al,'C'
jz savedcmosdatatohd
cmp al,'r'
jz reboot
cmp al,'R'
jz reboot
cmp al,'l'
jz cmoscheckedmbrld
cmp al,'L'
jz cmoscheckedmbrld
cmp al,'?'
jz help
jmp error
|