home *** CD-ROM | disk | FTP | other *** search
- .MODEL SMALL
- .DATA
- ASSUME CS:DGROUP, DS:DGROUP, SS:DGROUP
- PUBLIC _IPL, _IPL_SELECTOR, _ENTRY_S, _ENTRY_V
- _IPL PROC
- ;
- ; BIOS loads MBR at 0000:7C00h
- ;
- ; Lets move code to 0000:0600h
- ;
- xor bp, bp
- mov ds, bp
- mov es, bp
- mov ss, bp ; CPU clears interrupt flag for next command
- mov sp, 7C00h
- cld
- mov si, sp
- mov di, 0600h
- mov cx, 0100h
- rep
- movsw
- ; jmp 0000:ENTRY_POINT
- DB 0EAh
- _IPL_SELECTOR DW 0000, 0000 ; Will be initialized during installation
- ;
- VIRUS EQU (M1-_IPL)
- BOOTNG EQU (M2-_IPL)
- IO_ERR EQU (M3-_IPL)
- WRITNG EQU (M4-_IPL)
- NL EQU (M5-_IPL)
- ;
- M1: DB "Virus in memory! ",0
- M2: DB "Booting from: ",0
- M3: DB ". I/O Error!",0Dh,0Ah,0
- M4: DB "Writing changes..."
- M5: DB 0Dh,0Ah,0
- ;
- ; Check interrupt vectors
- ;
- _ENTRY_V: ; Entry point for virus detection option
- V0:
- mov cl, 1Bh ; Check 26 interrupt vectors from 03h to 1Ch
- mov di, 0Bh
- V1:
- add di, 4
- dec cx
- jz V3
- cmp byte ptr [di], 0C0h ; They must be >= C000:0000
- jnb V1
-
- mov bl, VIRUS ; If any of interrupt vectors was changed
- call PRINT
- V2:
- mov ah, 0
- int 16h ; Get a key
- cmp al, 0Dh
- jne V2 ; Loop until ENTER is pressed
- mov bl, NL
- call PRINT
- V3:
- ;
- ; Check if HD number passed in DL is OK.
- ; Allowed values 80h (HD0) and 81h (HD1).
- ;
- _ENTRY_S: ; Entry point for select only option
- H0:
- cmp dl, 81h ; Are we on the second Hard Drive?
- je H1
- mov dl, 80h
- H1:
- mov bl, BOOTNG
- call PRINT
- ;
- ; Find active partition
- ;
- L0:
- mov al, '1'
- mov di, 07BEh ; Address of the first record in PT
- push dx
- L1:
- cmp Byte Ptr [di], 00
- jnz L2 ; Active partition found
- add di, 10h
- inc al
- cmp al, '4'
- jbe L1
- ;
- mov di, 07BAh ; No active partition found
- mov dl, [di]
- mov al, 'D' ; Booting from the next hard drive (D)
- cmp dl, 0
- jne L2
- mov al, 'A' ; Booting from the first floppy disk (A)
- xor bp, bp ; Don't save changes in this case
- L2:
- mov ah, 0Eh
- mov bh, 00h
- int 10h ; Print a character
- ;
- ; Load boot sector from disk
- ;
- mov si, 3 ; We will try at most three times
- L21:
- mov ax, 0201h ; Read (AH=02) 1 Sector (AL=01)
- mov bx, 7C00h ; Destination Address
- mov cx, [di+02] ; Cyl#, Sect#
- mov dx, [di+00] ; Head, Drive in DL
- int 13h
- jnc L23
- ; We get here if there was an error
- mov ah, 0 ; We will try to reset device
- int 13h
-
- dec si
- jnz L21
- stc ; We have tried three time and will give up
- L23:
- pop dx
- jc L4 ; I/O Error!
- call DOTS
- jnc L25 ; Time out or user hit ESC
- cmp al, ' '
- je L5
- cmp al, 'A'
- je L5
- cmp al, 'a'
- je L5
- cmp al, 'D'
- je L5
- cmp al, 'd'
- je L5
- sub al, '1'
- cmp al, 04h
- jbe L5
- ;
- ; Save changes to disk
- ;
- L25:
- push di
- or bp, bp ; Do we have to save (0=don't)
- je L3
- mov bl, WRITNG
- call PRINT
- mov ax, 0301h ; Write (AH=03) 1 Sector (AL=01)
- mov bx, 0600h ; Source located at address 600h
- mov cx, 0001h ; Cyl = 0, Sect = 1
- mov dh, 00h ; Head = 0, Drive in DL
- int 13h
- L3:
- pop si ; Boot sector expects Drive# in DL
- mov dl, [si] ; and pointer to its own params in SI
- ; jmp 0000:7C00h ; Transfer control to loaded BootSector
- DB 0EAh
- DW 7C00h, 0000h
- ;
- ; Print Error
- ;
- L4:
- mov bl, IO_ERR
- call PRINT
- ;
- ; Select new partition
- ;
- L5:
- mov bl, BOOTNG
- call PRINT
- L6:
- mov ah, 00h
- int 16h ; Read character
-
- mov ah, 00h
- mov [di], ah ; disabling old partition
- mov di, 07BAh
- cmp al, 'A'
- je L7
- cmp al, 'a'
- je L7
- mov ah, dl ; Next hard drive
- inc ah
- cmp al, 'D'
- je L7
- cmp al, 'd'
- je L7
- sub al, '1'
- cmp al, 04h
- jnb L6 ; if not a valid choice ask again
-
- mov di, 07BEh ; Address of first record in PT
- mov ah, 16
- mul ah
- add di, ax
- mov ah, dl
- L7:
- mov [di], ah
- inc bp ; indication that we need to save changes
- jmp L0
- _IPL ENDP
- ;
- ; PRINT
- ;
- PRINT PROC
- push ax
- mov ah, 0Eh
- mov bh, 00h
- lea si, [bx+0600h]
- P1:
- lodsb
- or al, al
- jz P2
- int 10h
- jmp P1
- P2:
- pop ax
- ret
- PRINT ENDP
- ;
- ; Print dots and check if key is pressed (key in al)
- ;
- DOTS PROC
- ; push bx
- ; push cx
- push dx
- mov ax, 092Eh ; Print '.'
- mov bx, 0007h
- mov cx, 0030h ; Here is how many dots will be printed
- int 10h
- W1:
- mov ah, 01h ; Check if key is pressed
- int 16h
- jz W3 ; There is no key waiting
-
- cmp al, 1Bh ; ESC
- je W2
- push ax
- stc
- jmp short W5
- W2:
- mov ah, 00 ; Remove ESC from keyboard buffer
- int 16h
- jmp short W4
- W3:
- mov ax, 0E20h
- int 10h ; Print a SPACE
-
- push bx
- push cx
- mov ah, 0
- int 1Ah ; Read System Timer
- mov bx, dx
- WT1: int 1Ah ; Wait one timer tick
- cmp bx, dx
- je WT1
- mov bx, dx
- WT2: int 1Ah ; Wait another timer tick
- cmp bx, dx
- je WT2
- pop cx
- pop bx
-
- loop W1
- W4:
- push ax
- clc
- W5:
- pushf
- mov ax, 0920h ; Print rest of SPACEs
- int 10h
- mov bl, NL
- call PRINT
- popf
- pop ax
- pop dx
- ; pop cx
- ; pop bx
- ret
- DOTS ENDP
-
- GAP PROC
- GAPLEN EQU (1BAh-(GAP-_IPL))
- DB GAPLEN DUP(0)
- GAP ENDP
-
- FD_PARM DB 00,00,01,00 ; Floppy disk boot sector parameters
- DB 40h DUP(0)
- DB 055h, 0AAh
- END
-