;================================================= ======================
; HDBOOT version 1.0
; (c) Computer Magazine þ BlackMedia 41 þ
;-----------------------------------------------------------------------
; This program alters the boot record on a floppy disk so that it loads
; the primary boot record from your first physical hard disk (usually
; C:). If you then boot your PC with the altered floppy in drive A:,
; it will boot from the HD, bypassing that "Non-System disk" message.
; Reformat or SYSing the floppy restores its original boot record.
;
; Syntax: HDBOOT a:
;
; where a: must be a floppy drive
;-----------------------------------------------------------------------
; This program is designed to be assemled with TASM, OPTASM, or
; MASM 5.x. Create using the following commands:
;
; MASM HDBOOT;
; LINK HDBOOT;
; EXE2BIN HDBOOT.EXE HDBOOT.COM
; DEL HDBOOT.OBJ
; DEL HDBOOT.EXE
;-----------------------------------------------------------------------
CSEG SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG
ORG 100H ;COM file format
ENTPT: JMP MAIN
;================================================= ======================
; Program data.
;-----------------------------------------------------------------------
COPYRIGHT$ DB "HDBOOT 1.0 (c)First Published in"
DB " BlackMedia 41 þ Computer Magazine"
CRLF$ DB 13,10,"$"
USAGE$ DB "Usage: HDBOOT a:$"
INVDRIVE$ DB "Drive is invalid$"
DRIVEERR$ DB "Can't access drive$"
NOTFLOPPY$ DB "Drive is not a floppy$"
RDERR$ DB "Read error$"
WRERR$ DB "Write error$"
MEMERR$ DB "Not Enough Memory$"
SUCCESS$ DB "Success!$"
TARGET DB 0 ;Destination floppy
;-----------------------------------------------------------------------
; This is the new bootstrap code to boot from the hard disk.
;-----------------------------------------------------------------------
JMP_TARGET LABEL NEAR
BOOTSTRAP LABEL BYTE
CLI ;Disable interrupts
MOV BX,7C00H ;Load code here
SUB AX,AX ;AX=0
MOV SS,AX ;Set stack to
MOV SP,BX ; 0:7C00h
MOV ES,AX ;Dest is ES:BX
MOV AX,13CDH ;Int 13 instruction
PUSH AX ;Below our code
MOV AX,201H ;Read one sector
MOV CX,0001H ;Cyl 0, SECT 1
MOV DX,0080H ;head 0, drive 80h
DB 0EAH ;JMP to INT 13
DW 7BFEH,0 ; instruction
BOOT_LEN EQU $-BOOTSTRAP
;================================================= ======================
; MAIN procedure
;-----------------------------------------------------------------------
MAIN PROC NEAR
ASSUME CS:CSEG,DS:CSEG,ES:CSEG,SS:CSEG
;-----------------------------------------------------------------------
; Initialize and display the programm title.
;-----------------------------------------------------------------------
CLD ;String moves forward
MOV CX,AX ;Save drive status
MOV AH,9 ;Display string fn
MOV DX,OFFSET COPYRIGHT$ ; located here
INT 21H ; Thru DOS
;-----------------------------------------------------------------------
; If the first command line argument contained an invalid drive spec,
; AL = FFh. If so, report an error to the user.
;-----------------------------------------------------------------------
CMP CL,0FFH ;Check for invalid drv
JNE M_2
MOV AH,9 ;Display string
MOV DX,OFFSET INVDRIVE$ ; in DX
INT 21H ; Thru DOS
;-----------------------------------------------------------------------
; Terminate the program.
;-----------------------------------------------------------------------
MOV DX,OFFSET CRLF$ ; located here
M_EXIT:
MOV AH,9 ;Display string
INT 21H ; Thru DOS
RET ;Exit
;-----------------------------------------------------------------------
; The first FCB will contain the parsed drive spec. (0=none, 1=A, etc).
; If none specified, display usage message.
;-----------------------------------------------------------------------
M_2:
MOV DX,OFFSET USAGE$ ;Usage message
MOV BL,DS:[5CH] ;Get specified drive
OR BL,BL ;0=none specified
JZ M_EXIT
MOV [TARGET],BL ;Target drive 1-BASED
;-----------------------------------------------------------------------
; The target disk must be a floppy and must be in the drive.
;-----------------------------------------------------------------------
MOV AX,4408H ;Ckeck removable media
; Drive in BL
INT 21H ; Thru DOS
M_3:
MOV DX,OFFSET DRIVEERR$ ;Assume drve error
JC M_EXIT
MOV DX,OFFSET NOTFLOPPY$ ;Assume not a floppy
OR AX,AX ;0=REMOVABLE
JNZ M_EXIT
;-----------------------------------------------------------------------
; Read the boot sector from the floppy.
;-----------------------------------------------------------------------
MOV AL,[TARGET] ;1-based
DEC AL ;0-based
MOV BX,OFFSET BOOTBUF ;Destination DS:BX
MOV CX,1 ;Read 1 sector
SUB DX,DX ;At sector 0
INT 25H ;Absolute disk read
POP DX ;Discard old flags
JNC M_4
MOV DX,OFFSET RDERR$
JMP M_EXIT
M_4:
CMP WORD PTR [BX+1FEH],0AA55H ;Verify signature
JNE M_EXIT
;-----------------------------------------------------------------------
; Determine the location of the current bootstrap code by examining the
; type and relative offset of the jump at the start of the code.
;-----------------------------------------------------------------------
MOV BX,OFFSET BOOTBUF
MOV CL,[BX] ;Get jump type
MOV AX,[BX+1] ;Get relative offset
ADD AX,3 ;Assume 3-byte jump
CMP CL,0E9H ;16-bit disp?
JE M_5
DEC AX ;2-byte jump
SUB AH,AH ;Clear top byte
M_5:
ADD AX,BX ;Add buffer start adr
MOV DI,AX ;Destination for move
MOV SI,OFFSET BOOTSTRAP ;Source
MOV CX,BOOT_LEN ;Length
REP MOVSB ;Move them
;-----------------------------------------------------------------------
; Write the code to perform the HD boot to the floppy.
;-----------------------------------------------------------------------
MOV AL,[TARGET] ;1-based
DEC AL ;0-based
MOV BX,OFFSET BOOTBUF ;Source is DX:BX
MOV CX,1 ;Write 1 sector
SUB DX,DX ;At sector 0
INT 26H ;Absolute disk write
POP DX ;Discard old flags
JNC M_6
MOV DX,OFFSET WRERR$
JMP M_EXIT
M_6:
MOV DX,OFFSET SUCCESS$
JMP M_EXIT
MAIN ENDP
;================================================= ======================
BOOTBUF EQU $
CSEG ENDS
END ENTPT