new release cleanup

svn path=/trunk/; revision=13
This commit is contained in:
Rex Jolliff 1998-08-25 04:37:43 +00:00
parent b5efc5cfc5
commit cdafa11dc1

View file

@ -1,291 +1,291 @@
; ;
; File: ; File:
; boot.asm ; boot.asm
; Description: ; Description:
; DOS-C boot ; DOS-C boot
; ;
; Copyright (c) 1997; ; Copyright (c) 1997;
; Svante Frey ; Svante Frey
; All Rights Reserved ; All Rights Reserved
; ;
; This file is part of DOS-C. ; This file is part of DOS-C.
; ;
; DOS-C is free software; you can redistribute it and/or ; DOS-C is free software; you can redistribute it and/or
; modify it under the terms of the GNU General Public License ; modify it under the terms of the GNU General Public License
; as published by the Free Software Foundation; either version ; as published by the Free Software Foundation; either version
; 2, or (at your option) any later version. ; 2, or (at your option) any later version.
; ;
; DOS-C is distributed in the hope that it will be useful, but ; DOS-C is distributed in the hope that it will be useful, but
; WITHOUT ANY WARRANTY; without even the implied warranty of ; WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
; the GNU General Public License for more details. ; the GNU General Public License for more details.
; ;
; You should have received a copy of the GNU General Public ; You should have received a copy of the GNU General Public
; License along with DOS-C; see the file COPYING. If not, ; License along with DOS-C; see the file COPYING. If not,
; write to the Free Software Foundation, 675 Mass Ave, ; write to the Free Software Foundation, 675 Mass Ave,
; Cambridge, MA 02139, USA. ; Cambridge, MA 02139, USA.
; ;
; $Logfile: C:/dos-c/src/boot/boot.asv $ ; $Logfile: C:/dos-c/src/boot/boot.asv $
; ;
; $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/loaders/boot/Attic/boot.asm,v 1.2 1998/08/12 22:43:38 rosmgr Exp $ ; $Header: /cygdrive/c/RCVS/CVS/ReactOS/reactos/loaders/boot/Attic/boot.asm,v 1.3 1998/08/25 04:37:43 rex Exp $
; ;
; $Log: boot.asm,v $ ; $Log: boot.asm,v $
; Revision 1.2 1998/08/12 22:43:38 rosmgr ; Revision 1.3 1998/08/25 04:37:43 rex
; Update from the kernel team ; new release cleanup
; ;
; ; Revision 1.1.1.2 1998/08/25 04:27:38 rex
; Rev 1.5 10 Jan 1997 4:58:06 patv ; A much Needed Update
; Corrected copyright ;
; ;
; Rev 1.4 10 Jan 1997 4:52:50 patv ; Rev 1.5 10 Jan 1997 4:58:06 patv
; Re-written to support C drive and eliminate restrictions on IPL.SYS ; Corrected copyright
; ;
; Rev 1.3 29 Aug 1996 13:06:50 patv ; Rev 1.4 10 Jan 1997 4:52:50 patv
; Bug fixes for v0.91b ; Re-written to support C drive and eliminate restrictions on IPL.SYS
; ;
; Rev 1.2 01 Sep 1995 17:56:44 patv ; Rev 1.3 29 Aug 1996 13:06:50 patv
; First GPL release. ; Bug fixes for v0.91b
; ;
; Rev 1.1 30 Jul 1995 20:37:38 patv ; Rev 1.2 01 Sep 1995 17:56:44 patv
; Initialized stack before use. ; First GPL release.
; ;
; Rev 1.0 02 Jul 1995 10:57:52 patv ; Rev 1.1 30 Jul 1995 20:37:38 patv
; Initial revision. ; Initialized stack before use.
; ;
; Rev 1.0 02 Jul 1995 10:57:52 patv
section .text ; Initial revision.
;
org 0
Entry: jmp real_start section .text
; bp is initialized to 7c00h org 0
%define oem [bp+3] Entry: jmp real_start
%define bytesPerSector [bp+0bh]
%define sectPerCluster [bp+0dh] ; bp is initialized to 7c00h
%define resSectors [bp+0eh] %define oem [bp+3]
%define nFats [bp+10h] %define bytesPerSector [bp+0bh]
%define nRootDir [bp+11h] %define sectPerCluster [bp+0dh]
%define nSectors [bp+13h] %define resSectors [bp+0eh]
%define MID [bp+15h] %define nFats [bp+10h]
%define sectPerFat [bp+16h] %define nRootDir [bp+11h]
%define sectPerTrack [bp+18h] %define nSectors [bp+13h]
%define nHeads [bp+1ah] %define MID [bp+15h]
%define nHidden [bp+1ch] %define sectPerFat [bp+16h]
%define nHidden_hi [bp+1eh] %define sectPerTrack [bp+18h]
%define nSectorHuge [bp+20h] %define nHeads [bp+1ah]
%define drive [bp+24h] %define nHidden [bp+1ch]
%define extBoot [bp+26h] %define nHidden_hi [bp+1eh]
%define volid [bp+27h] %define nSectorHuge [bp+20h]
%define vollabel [bp+2bh] %define drive [bp+24h]
%define filesys 36h %define extBoot [bp+26h]
%define volid [bp+27h]
LOADSEG equ 2000h %define vollabel [bp+2bh]
%define filesys 36h
FATBUF equ 4000h ; offset of temporary buffer for FAT
; chain LOADSEG equ 2000h
RETRYCOUNT equ 5 ; number of retries on disk errors
FATBUF equ 4000h ; offset of temporary buffer for FAT
; Some extra variables that are created on the stack frame ; chain
RETRYCOUNT equ 5 ; number of retries on disk errors
%define fat_start [bp-4] ; first FAT sector
%define fat_start_hi [bp-2] ; Some extra variables that are created on the stack frame
%define root_dir_start [bp-8] ; first root directory sector
%define root_dir_start_hi [bp-6] %define fat_start [bp-4] ; first FAT sector
%define data_start [bp-12] ; first data sector %define fat_start_hi [bp-2]
%define data_start_hi [bp-10] %define root_dir_start [bp-8] ; first root directory sector
%define root_dir_start_hi [bp-6]
; %define data_start [bp-12] ; first data sector
; Include macros for filesystem access %define data_start_hi [bp-10]
;
%include "boot.inc" ;
; Include macros for filesystem access
; ;
; %include "boot.inc"
;
TIMES 3eh-($-$$) DB 0 ;
;
%define tempbuf [bp+3eh] ;
load_seg dw LOADSEG TIMES 3eh-($-$$) DB 0
real_start: cli %define tempbuf [bp+3eh]
cld load_seg dw LOADSEG
mov ax, cs
mov ss, ax ; initialize stack real_start: cli
mov bp, 7c00h cld
lea sp, [bp-20h] mov ax, cs
sti mov ss, ax ; initialize stack
mov bp, 7c00h
mov es, ax lea sp, [bp-20h]
mov ds, ax sti
mov drive, dl ; BIOS passes drive number in DL
mov es, ax
GETDRIVEPARMS mov ds, ax
mov drive, dl ; BIOS passes drive number in DL
FINDFILE ; locate file in root directory
jc boot_error ; fail if not found GETDRIVEPARMS
GETFATCHAIN ; read FAT chain FINDFILE ; locate file in root directory
LOADFILE ; load file (jumps to boot_sucess if successful) jc boot_error ; fail if not found
boot_error: mov cx, ERRMSGLEN GETFATCHAIN ; read FAT chain
mov si, errmsg+7c00h LOADFILE ; load file (jumps to boot_sucess if successful)
next_char: lodsb ; print error message boot_error: mov cx, ERRMSGLEN
mov ah, 0eh mov si, errmsg+7c00h
xor bh, bh
int 10h next_char: lodsb ; print error message
loop next_char mov ah, 0eh
xor bh, bh
xor ah, ah int 10h
int 16h ; wait for keystroke loop next_char
int 19h ; invoke bootstrap loader
xor ah, ah
boot_success: mov dl, drive int 16h ; wait for keystroke
int 19h ; invoke bootstrap loader
db 0eah ; far jump to LOADSEG:0000
dw 0 boot_success: mov dl, drive
dw LOADSEG
db 0eah ; far jump to LOADSEG:0000
dw 0
; readDisk: Reads a number of sectors into memory. dw LOADSEG
;
; Call with: DX:AX = 32-bit DOS sector number
; DI = number of sectors to read ; readDisk: Reads a number of sectors into memory.
; ES:BX = destination buffer ;
; ES must be 64k aligned (1000h, 2000h etc). ; Call with: DX:AX = 32-bit DOS sector number
; ; DI = number of sectors to read
; Returns: CF set on error ; ES:BX = destination buffer
; ES:BX points one byte after the last byte read. ; ES must be 64k aligned (1000h, 2000h etc).
;
readDisk: ; Returns: CF set on error
push si ; ES:BX points one byte after the last byte read.
read_next: push dx
push ax readDisk:
push si
; read_next: push dx
; translate sector number to BIOS parameters push ax
;
;
; ; translate sector number to BIOS parameters
; abs = sector offset in track ;
; + head * sectPerTrack offset in cylinder
; + track * sectPerTrack * nHeads offset in platter ;
; ; abs = sector offset in track
; t1 = abs / sectPerTrack (ax has t1) ; + head * sectPerTrack offset in cylinder
; sector = abs mod sectPerTrack (cx has sector) ; + track * sectPerTrack * nHeads offset in platter
; ;
div word sectPerTrack ; t1 = abs / sectPerTrack (ax has t1)
mov cx, dx ; sector = abs mod sectPerTrack (cx has sector)
;
; div word sectPerTrack
; t1 = head + track * nHeads mov cx, dx
;
; track = t1 / nHeads (ax has track) ;
; head = t1 mod nHeads (dl has head) ; t1 = head + track * nHeads
; ;
xor dx, dx ; track = t1 / nHeads (ax has track)
div word nHeads ; head = t1 mod nHeads (dl has head)
;
; the following manipulations are necessary in order to xor dx, dx
; properly place parameters into registers. div word nHeads
; ch = cylinder number low 8 bits
; cl = 7-6: cylinder high two bits ; the following manipulations are necessary in order to
; 5-0: sector ; properly place parameters into registers.
mov dh, dl ; save head into dh for bios ; ch = cylinder number low 8 bits
ror ah, 1 ; move track high bits into ; cl = 7-6: cylinder high two bits
ror ah, 1 ; bits 7-6 (assumes top = 0) ; 5-0: sector
xchg al, ah ; swap for later mov dh, dl ; save head into dh for bios
mov dl, byte sectPerTrack ror ah, 1 ; move track high bits into
sub dl, cl ror ah, 1 ; bits 7-6 (assumes top = 0)
inc cl ; sector offset from 1 xchg al, ah ; swap for later
or cx, ax ; merge cylinder into sector mov dl, byte sectPerTrack
mov al, dl ; al has # of sectors left sub dl, cl
inc cl ; sector offset from 1
; Calculate how many sectors can be transfered in this read or cx, ax ; merge cylinder into sector
; due to dma boundary conditions. mov al, dl ; al has # of sectors left
push dx
; Calculate how many sectors can be transfered in this read
mov si, di ; temp register save ; due to dma boundary conditions.
; this computes remaining bytes because of modulo 65536 push dx
; nature of dma boundary condition
mov ax, bx ; get offset pointer mov si, di ; temp register save
neg ax ; and convert to bytes ; this computes remaining bytes because of modulo 65536
jz ax_min_1 ; started at seg:0, skip ahead ; nature of dma boundary condition
mov ax, bx ; get offset pointer
xor dx, dx ; convert to sectors neg ax ; and convert to bytes
div word bytesPerSector jz ax_min_1 ; started at seg:0, skip ahead
cmp ax, di ; check remainder vs. asked xor dx, dx ; convert to sectors
jb ax_min_1 ; less, skip ahead div word bytesPerSector
mov si, ax ; transfer only what we can
cmp ax, di ; check remainder vs. asked
ax_min_1: pop dx jb ax_min_1 ; less, skip ahead
mov si, ax ; transfer only what we can
; Check that request sectors do not exceed track boundary
mov si, sectPerTrack ax_min_1: pop dx
inc si
mov ax, cx ; get the sector/cyl byte ; Check that request sectors do not exceed track boundary
and ax, 03fh ; and mask out sector mov si, sectPerTrack
sub si, ax ; si has how many we can read inc si
mov ax, di mov ax, cx ; get the sector/cyl byte
cmp si, di ; see if asked <= available and ax, 03fh ; and mask out sector
jge ax_min_2 sub si, ax ; si has how many we can read
mov ax, si ; get what can be xfered mov ax, di
cmp si, di ; see if asked <= available
ax_min_2: mov si, RETRYCOUNT jge ax_min_2
mov ah, 2 mov ax, si ; get what can be xfered
mov dl, drive
ax_min_2: mov si, RETRYCOUNT
retry: push ax mov ah, 2
int 13h mov dl, drive
pop ax
jnc read_ok retry: push ax
push ax int 13h
xor ax, ax ; reset the drive pop ax
int 13h jnc read_ok
pop ax push ax
dec si xor ax, ax ; reset the drive
jnz retry int 13h
stc pop ax
pop ax dec si
pop dx jnz retry
pop si stc
ret pop ax
pop dx
read_next_jmp: jmp short read_next pop si
read_ok: xor ah, ah ret
mov si, ax ; AX = SI = number of sectors read
mul word bytesPerSector ; AX = number of bytes read read_next_jmp: jmp short read_next
add bx, ax ; add number of bytes read to BX read_ok: xor ah, ah
jnc no_incr_es ; if overflow... mov si, ax ; AX = SI = number of sectors read
mul word bytesPerSector ; AX = number of bytes read
mov ax, es add bx, ax ; add number of bytes read to BX
add ah, 10h ; ...add 1000h to ES jnc no_incr_es ; if overflow...
mov es, ax
mov ax, es
no_incr_es: pop ax add ah, 10h ; ...add 1000h to ES
pop dx ; DX:AX = last sector number mov es, ax
add ax, si no_incr_es: pop ax
adc dx, 0 ; DX:AX = next sector to read pop dx ; DX:AX = last sector number
sub di, si ; if there is anything left to read,
jg read_next_jmp ; continue add ax, si
adc dx, 0 ; DX:AX = next sector to read
clc sub di, si ; if there is anything left to read,
pop si jg read_next_jmp ; continue
ret
clc
errmsg db "Boot error" pop si
ERRMSGLEN equ $ - errmsg ret
errmsg db "Boot error"
;filename db "OSLDR BIN" ERRMSGLEN equ $ - errmsg
filename db "KERNEL BIN"
TIMES 510-($-$$) DB 0 ;filename db "OSLDR BIN"
sign dw 0aa55h filename db "KERNEL BIN"
TIMES 510-($-$$) DB 0
sign dw 0aa55h