📄 boot.asm
字号:
;
; File:
; boot.asm
; Description:
; DOS-C boot
;
; Copyright (c) 1997;
; Svante Frey
; All Rights Reserved
;
; This file is part of DOS-C.
;
; DOS-C is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version
; 2, or (at your option) any later version.
;
; DOS-C is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
; the GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public
; License along with DOS-C; see the file COPYING. If not,
; write to the Free Software Foundation, 675 Mass Ave,
; Cambridge, MA 02139, USA.
;
; $Logfile: C:/dos-c/src/boot/boot.asv $
;
; $Header: C:/dos-c/src/boot/boot.asv 1.5 10 Jan 1997 4:58:06 patv $
;
; $Log: C:/dos-c/src/boot/boot.asv $
;
; Rev 1.5 10 Jan 1997 4:58:06 patv
; Corrected copyright
;
; Rev 1.4 10 Jan 1997 4:52:50 patv
; Re-written to support C drive and eliminate restrictions on IPL.SYS
;
; Rev 1.3 29 Aug 1996 13:06:50 patv
; Bug fixes for v0.91b
;
; Rev 1.2 01 Sep 1995 17:56:44 patv
; First GPL release.
;
; Rev 1.1 30 Jul 1995 20:37:38 patv
; Initialized stack before use.
;
; Rev 1.0 02 Jul 1995 10:57:52 patv
; Initial revision.
;
page 60,132
title DOS-C boot
IFDEF DEBUG
TEXT SEGMENT WORD PUBLIC 'TEXT'
TEXT ENDS
LOAD SEGMENT PARA PUBLIC 'LOAD'
LOAD ENDS
TEXT SEGMENT WORD PUBLIC 'TEXT'
ASSUME CS:TEXT, DS:TEXT
LOAD SEGMENT PARA PUBLIC 'LOAD'
org 0
loadBuffer dw 32767 dup (?)
LOAD ENDS
ELSE
TEXT SEGMENT WORD PUBLIC 'TEXT'
ASSUME CS:TEXT, DS:TEXT
ENDIF
IFDEF DEBUG
mov dl, BOOTDRIVE
jmp Entry
BASE equ 7c00h
ELSE
BASE equ 0
ENDIF
org BASE
Entry: jmp real_start
; bp is initialized to 7c00h
oem equ [bp+3]
bytesPerSector equ [bp+0bh]
sectPerCluster equ [bp+0dh]
resSectors equ [bp+0eh]
nFats equ [bp+10h]
nRootDir equ [bp+11h]
nSectors equ [bp+13h]
MID equ [bp+15h]
sectPerFat equ [bp+16h]
sectPerTrack equ [bp+18h]
nHeads equ [bp+1ah]
nHidden equ [bp+1ch]
nSectorHuge equ [bp+20h]
drive equ [bp+24h]
extBoot equ [bp+26h]
volid equ [bp+27h]
vollabel equ [bp+2bh]
filesys equ [bp+36h]
IFDEF DEBUG
db 'FreeDOS '
dw 512 ; bytes/sector
db 2 ; sectors/allocation unit
dw 1 ; # reserved sectors
db 2 ; # of fats
dw 112 ; # of root directories
dw 720 ; # sectors total in image
db 0fdh ; media descrip: fd=2side9sec, etc...
dw 2 ; # sectors in a fat
dw 9 ; # sectors/track
dw 2 ; # heads
dd 0 ; # hidden sectors
dd 0 ; # sectors if > 65536
db 00h ; drive number
db 00h
db 29h ; extended boot signature
dd 0
db 'DOS-C BOOT '
db 'FAT12 '
LOADSEG equ seg LOAD
ELSE
LOADSEG equ 2000h
ENDIF
FATBUF equ 4000h ; offset of temporary buffer for FAT
; chain
RETRYCOUNT equ 5 ; number of retries on disk errors
; Some extra variables that are created on the stack frame
fat_start equ [bp-4] ; first FAT sector
root_dir_start equ [bp-8] ; first root directory sector
data_start equ [bp-12] ; first data sector
; To save space, functions that are just called once are
; implemented as macros instead. Four bytes are saved by
; avoiding the call / ret instructions.
; FINDFILE: Searches for the file in the root directory.
;
; Returns:
;
; If file not found: CF set
;
; If file found: CF clear
; AX = first cluster of file
FINDFILE MACRO
; First, read the whole root directory
; into the temporary buffer.
mov ax, word ptr root_dir_start
mov dx, word ptr root_dir_start+2
mov di, nRootDir
xor bx, bx
mov es, tempbuf
call readDisk
jc ffDone
xor di, di
next_entry: mov cx, 11
mov si, offset filename+7c00h
push di
repe cmpsb
pop di
mov ax, es:[di][1ah] ; get cluster number from directory entry
clc
je ffDone
add di, 20h ; go to next directory entry
cmp byte ptr es:[di], 0 ; if the first byte of the name is 0,
jnz next_entry ; there is no more files in the directory
stc
ffDone:
ENDM
; GETDRIVEPARMS: Calculate start of some disk areas.
GETDRIVEPARMS MACRO
mov si, word ptr nHidden
mov di, word ptr nHidden+2
add si, word ptr resSectors
adc di, 0 ; DI:SI = first FAT sector
mov word ptr fat_start, si
mov word ptr fat_start+2, di
mov al, nFats
xor ah, ah
mul word ptr sectPerFat ; DX:AX = total number of FAT sectors
add si, ax
adc di, dx ; DI:SI = first root directory sector
mov word ptr root_dir_start, si
mov word ptr root_dir_start+2, di
; Calculate how many sectors the root directory occupies.
mov bx, bytesPerSector
mov cl, 5 ; divide BX by 32
shr bx, cl ; BX = directory entries per sector
mov ax, nRootDir
xor dx, dx
div bx
mov nRootDir, ax ; AX = sectors per root directory
add si, ax
adc di, 0 ; DI:SI = first data sector
mov data_start, si
mov data_start+2, di
ENDM
; GETFATCHAIN:
;
; Reads the FAT chain and stores it in a temporary buffer in the first
; 64 kb. The FAT chain is stored an array of 16-bit cluster numbers,
; ending with 0.
;
; The file must fit in conventional memory, so it can't be larger than
; 640 kb. The sector size must be at least 512 bytes, so the FAT chain
; can't be larger than around 3 kb.
;
; Call with: AX = first cluster in chain
;
; Returns: CF clear on success, set on error
GETFATCHAIN MACRO
push ax ; store first cluster number
; Load the complete FAT into memory. The FAT can't be larger
; than 128 kb, so it should fit in the temporary buffer.
mov es, tempbuf
xor bx, bx
mov di, sectPerFat
mov ax, word ptr fat_start
mov dx, word ptr fat_start+2
call readDisk
pop ax ; restore first cluster number
jc boot_error
; Set ES:DI to the temporary storage for the FAT chain.
push ds
push es
pop ds
pop es
mov di, FATBUF
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -