From: Kenneth D. <per...@us...> - 2005-05-28 12:10:39
|
Update of /cvsroot/freedos/kernel/boot In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32512/boot Modified Files: Tag: UNSTABLE oemboot.asm Log Message: set backup boot sector on FAT32, add update option, fix oemboot to work with msdos 7+ Index: oemboot.asm =================================================================== RCS file: /cvsroot/freedos/kernel/boot/Attic/oemboot.asm,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- oemboot.asm 19 Dec 2004 19:33:27 -0000 1.1.2.2 +++ oemboot.asm 28 May 2005 12:10:28 -0000 1.1.2.3 @@ -5,17 +5,20 @@ ; Copyright (c) 200?, <add name here> ; Description: ; OEM boot sector for FreeDOS compatible with IBM's (R) PC-DOS, -; and Microsoft's (R) PC-DOS. It may work with OpenDOS/DR-DOS, -; although the standard FreeDOS boot sector works with later +; and Microsoft's (R) MS-DOS. It may work with older OpenDOS/DR-DOS, +; although the standard FreeDOS boot sector is needed with ver 7+ ; releases. May work with other versions of DOS that use ; IBMBIO.COM/IBMDOS.COM pair. This boot sector loads only up ; to 58 sectors (29KB) of the kernel (IBMBIO.COM) to 0x70:0 then -; jumps to it. As best I can tell, PC-DOS (and assuming MS-DOS -; behaves similar) expects on entry for: +; jumps to it. As best I can tell, PC-DOS (and MS-DOS up to version +; 6.xx behaves similar) expects on entry for: ; ch = media id byte in the boot sector ; dl = BIOS drive booted from (0x00=A:, 0x80=C:, ...) -; ax:bx = the LBA sector of 1st data sector 0x0000:0021 for FAT12 -; ?or? 1st sector of IBMBIO.COM (which is normally 1st data sector) +; ax:bx = the starting (LBA) sector of cluster 2 (ie the 1st +; data sector, which is 0x0000:0021 for FAT12) +; ?note? IBMBIO.COM/IO.SYS may use ax:bx and cluster # stored +; elsewhere (perhaps dir entry still at 0x50:0) to determine +; starting sector for full loading of kernel file. ; it also expects the boot sector (in particular the BPB) ; to still be at 0x0:7C00, the directory entry for IBMBIO.COM ; (generally first entry of first sector of the root directory) @@ -25,6 +28,26 @@ ; If the above conditions are not met, then IBMBIO.COM will ; print the not a bootable disk error message. ; +; For MS-DOS >= 7 (ie Win9x DOS) the following conditions +; must be met: +; bp = 0x7C00, ie offset boot sector loaded at +; [bp-4] = the starting (LBA) sector of cluster 2 (ie the 1st +; data sector [this is the same as ax:bx for earlier versions +; and dx:ax in Win9x boot sector] +; The starting cluster of the kernel file is stored in +; di for FAT 12/16 (where si is a don't care) and si:di +; for FAT 32. +; The values for ax,bx,cx,dx,ds and the stack do not +; seem to be important (used by IO.SYS) and so may be any value +; (though dx:ax=[data_start], cx=0, bx=0x0f00 on FAT12 or +; 0x0700 on FAT32, ds=0, ss:sp=0:7b??) + +; the boot time stack may store the original int1E floppy +; parameter table, otherwise nothing else important seems +; stored there and I am unsure if even this value is used +; beyond boot sector code. + +; ; This boot sector only supports FAT12/FAT16 as PC-DOS ; does not support FAT32 and newer FAT32 capable DOSes ; probably have different boot requirements; also do NOT @@ -78,29 +101,39 @@ ; |BOOT SEC| contains BPB ; |ORIGIN | ; |--------| 0000:7C00 (0:BP) +; |VARS | only known is 1st data sector (start of cluster 2) +; |--------| 0000:7BFC (DS:[BP-4]) ; |STACK | minimal 256 bytes (1/2 sector) ; |- - - - | ; |KERNEL | kernel loaded here (max 58 sectors, 29KB) ; |LOADED | also used as FAT buffer ; |--------| 0070:0000 (0:0700) ; |DOS DA/ | DOS Data Area, -; |ROOT DIR| during boot the 1st sector of root directory +; |ROOT DIR| during boot contains directory entries ; |--------| 0000:0500 ; |BDA | BIOS Data Area ; +--------+ 0000:0400 ; |IVT | Interrupt Vector Table ; +--------+ 0000:0000 +CPU 8086 ; enable assembler warnings to limit instruction set ;%define ISFAT12 1 ; only 1 of these should be set, ;%define ISFAT16 1 ; defines which FAT is supported %define TRYLBAREAD 1 ; undefine to use only CHS int 13h -;%define LOOPONERR 1 ; if defined on error simply loop forever -;%define SETROOTDIR 1 ; if defined dir entry copied to 0:500 +%define SETROOTDIR 1 ; if defined dir entry copied to 0:500 +%define LOOPONERR 1 ; if defined on error simply loop forever ;%define RETRYALWAYS 1 ; if defined retries read forever +;%define WINBOOT 1 ; use win9x kernel calling conventions (name & jmp addr) ;%define MSCOMPAT 1 ; sets default filename to MSDOS IO.SYS +%ifdef WINBOOT ; if set also change from PC-DOS to +%ifndef MSCOMPAT ; kernel name to MS-DOS kernel name +%define MSCOMPAT +%endif +%endif + segment .text %define BASE 0x7c00 ; boot sector originally at 0x0:BASE @@ -133,7 +166,8 @@ ;%define RootDirSecs PARAMS+0x0 ; # of sectors root dir uses %define fat_start PARAMS+0x2 ; first FAT sector ;%define root_dir_start PARAMS+0x6 ; first root directory sector -%define data_start PARAMS+0x0a ; first data sector +%define first_cluster PARAMS+0x0a ; starting cluster of kernel file +%define data_start bp-4 ; first data sector (win9x expects here) ;----------------------------------------------------------------------- @@ -203,20 +237,33 @@ mov es, ax mov ss, ax mov bp, BASE - lea sp, [bp-2] - - ; a reset should not be needed here -; int 0x13 ; reset drive + lea sp, [bp-4] ; for DOS <7 this may be [bp] ; For compatibility, diskette parameter vector updated. -; lea di [bp+0x3E] ; just use bp for DR-DOS? +; lea di [bp+0x3E] ; use 7c3e([bp+3e]) for PC-DOS, +; ;lea di [bp] ; but 7c00([bp]) for DR-DOS 7 bug ; mov bx, 4 * 1eh ; stored at int 1E's vector ; lds si, [bx] ; fetch current int 1eh pointer +; push ds ; store original 1eh pointer at stack top +; push si ; so can restore later if needed +; +; Copy table to new location ; mov cl, 11 ; the parameter table is 11 bytes ; rep movsb ; and copy the parameter block ; mov ds, ax ; restore DS +; +; Note: make desired changes to table here +; +; Update int1E to new location +; mov [bx+2], 0 ; set to 0:bp or 0:bp+3e as appropriate +; mov word [bx], 0x7c3e ; (use 0x7c00 for DR-DOS) sti ; enable interrupts + +; If updated floppy parameter table then must notify BIOS +; Otherwise a reset should not be needed here. +; int 0x13 ; reset drive (AX=0) + ; ; Note: some BIOS implementations may not correctly pass drive number ; in DL, however we work around this in SYS.COM by NOP'ing out the use of DL @@ -290,22 +337,21 @@ je ffDone add si, byte 0x20 ; go to next directory entry - jc near boot_error ; fail if not found and si wraps + jc boot_error ; fail if not found and si wraps cmp byte [si], 0 ; if the first byte of the name is 0, jnz next_entry ; there are no more files in the directory ffDone: - push ax ; store first cluster number + mov [first_cluster], ax ; store first cluster number %ifdef SETROOTDIR ; copy over this portion of root dir to 0x0:500 for PC-DOS ; (this may allow IBMBIO.COM to start in any directory entry) lea di, [ROOTDIR] ; es:di = 0:0500 - mov cx, 0x100 + mov cx, 32 ; limit to this 1 entry (rest don't matter) rep movsw %endif - ; GETFATCHAIN: ; ; Reads the FAT chain and stores it in a temporary buffer in the first @@ -334,7 +380,7 @@ mov ax, LOADSEG mov ds, ax ; ds:0 = 0x70:0 = 0:FATBUF - pop ax ; restore first cluster number + mov ax, [first_cluster] ; restore first cluster number push ds ; store LOADSEG next_clust: stosw ; store cluster number @@ -403,7 +449,30 @@ mov ch, [bsMedia] ; ch set to media id mov ax, [data_start+2] ; ax:bx set to 1st data sector mov bx, [data_start] ; + mov di, [first_cluster] ; set di (si:di on FAT32) to starting cluster # +%ifdef WINBOOT + jmp LOADSEG:0x0200 ; yes, pass control to kernel +%else jmp LOADSEG:0000 ; yes, pass control to kernel +%endif + + +; failed to boot +boot_error: +call show +; db "Error! Hit a key to reboot." + db "):." +%ifdef LOOPONERR +jmp $ +%else + + ; Note: should restore floppy paramater table address at int 0x1E + xor ah,ah + int 0x13 ; reset floppy + int 0x16 ; wait for a key + int 0x19 ; reboot the machine +%endif + load_next: dec ax ; cluster numbers start with 2 dec ax @@ -428,22 +497,6 @@ jne show ; until done ret -; failed to boot - -boot_error: -%ifdef LOOPONERR -jmp boot_error -%else -call show -; db "Error! Hit a key to reboot." - db "Err." - - xor ah,ah - int 0x13 ; reset floppy - int 0x16 ; wait for a key - int 0x19 ; reboot the machine -%endif - ; readDisk: Reads a number of sectors into memory. ; @@ -564,7 +617,8 @@ read_ok: mov ax, word [bsBytesPerSec] - shr ax, 4 ; adjust segment pointer by increasing + mov cl, 4 ; adjust segment pointer by increasing + shr ax, cl add word [LBA_SEG], ax ; by paragraphs read in (per sector) add LBA_SECTOR_0, byte 1 |