meos32 >>Kernel >>Booting from a primary FAT16 partition
vhanla- 04-10-2006
Booting from a primary FAT16 partition ; MenuetOS Boot Loader for FAT16
; .................................
; originally by John S. Fine johnfine@erols.com
;
; Adapted by vhanla for MenuetOS or Kolibri
;
; Notice that !!!
;.................
; I put the KERNEL.MNT into the FAT16 partition just for loading
; the kernel... but the kernel BOOTCODE needs to have the entire
; MenuetOS floppy image loaded into memory and that's where this
; bootloader fails... because this bootloader only gives control
; to the kernel.mnt. So, you need to have MENUET.IMG in the first
; primary FAT32 partition that has this file ("c:\menuet.img") or
; MSETUP.EXE ("c:\msetup.exe") it depends on KERNEL.MNT
; if you use KOLIBRI OS, MENUET.IMG is needed and if you're using
; official MENUET OS distro you need MSETUP.EXE in root directory
;
; WARNING!!!
; -----------
; Since bootsector of a partition must be treated carefully, I
; recommend NOT TO OVERWRITE BYTES BEFORE! OFFSET 62 (3Eh)IN BOOTSECTOR
; NOTICE ALSO THAT IF THE FIRST 3 BYTES OF BOOTSECTOR DON'T MATCH
; THIS BOOTLOADER'S FIRST 3 BYTES, YOU NEED TO MODIFY THEM TO MATCH.
; THEN AFTER OFFSET 61 (3Dh), i.e., STARTING FROM OFFSET 62 (3Eh) YOU MUST
; REPLACE ALL BYTES INTO ALL BOOT SECTOR (512 BYTES SECTOR IS NEEDED)
; UNTIL OFFSET 512 ;)
;
; Do it carefully with your favorite hex editor
;
; PS: I TESTED THIS BOOTLOADER ONLY WITH MY 4GB SIZE HARD DISK
; I DON'T KNOW ABOUT LARGER HARD DISKs
;
; PS2: IT'S RECOMMENDED TO HAVE A BACKUP OF THE PARTITION BOOT SECTOR
; AND ALSO THE OFFSET NUMBER WHERE IT LOCATES IN THE PHYSICAL HARD DISK
; JUST TO KNOW WHERE TO RESTORE THE BOOT SECTOR IF SOMETHING WEIRD HAPPENED
;
;,,,,,,,,,,,,,,,,,,
; ... BE CAREFUL... THIS IS ONLY FOR FAT16, FAT32 HAS MORE SPACE FOR
; PARTITION INFO, SO REPLACING AFTER OFFSET 62 (3Eh) IN A FAT32, WILL CAUSE
; DAMAGES TO YOUR PARTITION STRUCTURE...
; I REPEAT !!!!! ONLY FAT16 --- SO TAKE CARE
; Features:
; ----------
; CPU: Supports any 8088+ CPU
;
; Volume Format: Supports Only FAT16
;
; Sector Size: Supports Only 512 bytes per sector.
;
; release date 04/02/2006
; IV) Customization
;
; The memory usage can be customized by changing the _SEG variables (see
; directly below).
;
; The file name to be loaded and the message displayed in case of error
; may be customized (see end of this file).
;
; The ouput values may be customized.
;_____________________________________________________________________________
ROOT_SEG =0x800
FAT_SEG =0x800
IMG_SEG =0x1000
; The following defined directives declare the parts of the FAT16 "DOS BOOT
; RECORD" that are used by this code, based on BP being set to 7C00.
;
sc_p_clu equ bp+0Dh ;byte Sectors per cluster
sc_b4_fat equ bp+0Eh ;word Sectors (in partition) before FAT
fats equ bp+10h ;byte Number of FATs
dir_ent equ bp+11h ;word Number of root directory entries
sc_p_fat equ bp+16h ;word Sectors per FAT
sc_p_trk equ bp+18h ;word Sectors per track
heads equ bp+1Ah ;word Number of heads
sc_b4_prt equ bp+1Ch ;dword Sectors before partition
drive equ bp+24h ;byte Drive number
org 0x7C00
entrada:
jmp begin
nop
; Skip over the data portion of the "DOS BOOT RECORD". The install method
; must merge the code from this ASM with the data put in the boot record
; by the FAT16 formatter.
;
times 0x3B db 0 ; THIS PART IS THE PARTITION INFO AREA THAT YOU NEED
; TO CHANGE WITH YOUR PARTITION INFO
begin:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 0x7C00
mov bp, sp
mov [drive], dl ;Drive number
mov al, [fats] ;Number of FATs
mul word [sc_p_fat] ; * Sectors per FAT
add ax, [sc_b4_fat] ; + Sectors before FAT
xchg ax, di ;DI = Sector of Root directory
mov bx, [dir_ent] ;Max root directory entries
dec bx
shr bx, 4
inc bx ;BX = Length of root in sectors
mov ax, ROOT_SEG ;Segment for root directory
mov es, ax
call read_16 ;Read root directory
push di ;Sector of cluster two
sc_clu2 equ bp-2 ;Later access to the word just pushed is via bp
mov dx, [dir_ent] ;Number of directory entries
xor di, di ;Point at first directory entry
search:
dec dx ;Any more directory entries?
js error ;No
mov si, filename ;Name we are searching for
mov cx, 11 ;11 characters long
lea ax, [di+0x20] ;Precompute next entry address
push ax
repe cmpsb ;Compare
pop di
jnz search ;Repeat until match
mov si, IMG_SEG ;Segment for image
push si ; segment for retf
push bx ; zero offset for retf
push word [es:di-6] ;Starting cluster number
if FAT_SEG-ROOT_SEG
mov ax, FAT_SEG ;Segment for FAT
mov es, ax
end if
mov di, [sc_b4_fat] ;Sector number of FAT
mov bl, [sc_p_fat] ;Length of FAT (or zero if FAT is 256)
cmp bl, 0x81 ;If it is 1 through 0x80
js .1 ; then read it in one chunk
push bx ; but for 0, or 0x81 through 0xFF
mov bl, 0x80 ; read 0x80 sectors first.
call read_16
pop bx
sub bl, 0x80 ;Remainder after first 0x80 sectors
mov ax, FAT_SEG+0x1000 ;Segment for second part of FAT
mov es, ax
.1:
call read_16
next: ;Loop for all clusters
pop ax ;Cluster number
; cmp ax, byte -0x12 ;End of file?
cmp al, -0x12
jae eof ; Yes
mov di, ax
shl di, 1 ;A two-byte entry per cluster
mov dx, FAT_SEG ;Assume first half of FAT
jnc .1 ; It is first
mov dh, (FAT_SEG/256)+8 ;Second half of FAT
.1: mov ds, dx
push word [di] ;Cluster number for next time
dec ax
dec ax ;Current cluster minus two
mov bl, [sc_p_clu]
mul bx ; * sectors per cluster
add ax, [sc_clu2] ; + sector number of cluster two
adc dl, dh ;Allow 24-bit result
xchg ax, di ;DX:DI = sector number
mov es, si ;ES = destination segment
mov ax, bx ;AX = cluster size in sectors
mov cl, 5
shl ax, cl ;AX = cluster size in paragraphs
add si, ax ;Precompute next segment
call read_32 ;Read one cluster
jmp next
eof: retf
error: mov si, errmsg ;Same message for all detected errors
mov ax, 0xE0D ;Start message with CR
mov bx, 7
.1: int 10h
ss lodsb
test al, al
jnz .1
xor ah, ah
int 16h ;Wait for a key
int 19h ;Try to reboot
read_16:
xor dx, dx
read_32:
;
; Input:
; dx:di = sector within partition
; bl = sector count (max 0x80)
; es = destination segment
;
; The sector number is converted from a partition-relative to a whole-disk
; (LBN) value, and then converted to CHS form, and then the sectors are read
; into ES:0.
;
; Output:
; di = input di + input bx
; bx = 0
; dl = drive
; si, bp and seg regs unchanged
; other registers modified
lea ax, [di+bx] ;Compute di+bx (needed by two caller's
push ax ; of read_16)
add di, [sc_b4_prt] ;Convert to LBN
adc dx, [sc_b4_prt+2]
xchg ax, dx ;AX = (high) LBN
cwd
div word [sc_p_trk] ; / Sectors per track
xchg ax, di ;AX = (low) LBN ;DI = (high) track
div word [sc_p_trk] ;AX = (low) track ;DX = sector-1
inc dx
mov cl, dl ;CL = sector
mov dx, di ;DX = (high) track
div word [heads] ; / Number of heads
mov dh, dl ;DH = head
mov ch, al ;CH = (low) cylinder
ror ah, 1 ;rotate (high) cylinder
ror ah, 1
add cl, ah ;CL = combine sector, (high) cylinder
mov dl, [drive] ;DL = Drive number
xchg ax, bx ;AL = Sector count
mov ah, 2 ;AH = Read command
xor bx, bx ;ES:BX = address
int 13h ;Do it
jc error
pop di ;DI = Input DI + Input BX
ret
errmsg db 10,"KERNEL.MNT NOT FOUND",13
db 10,"Press any key to reboot...",13,10,0
filename db "KERNEL MNT" ;11 byte name
times 0x7c00+510-$ db 0
db 0x55, 0xAA ;2 byte boot signature
hidnplayr- 04-11-2006
The future! nice nice...
we have so many bootloaders now,
but shouldnt we start thinking of getting rid of the ramdisk?
And read files directly from a folder on a fat32 partition ?
I dont think this would be that hard :)
PS: since we have a full floppy driver now in kolibri, we can do the same for booting from floppy..
Dex- 04-11-2006
This to me as always been menuet biggest asset, but also its biggest draw back.
When you first try menuet the ramdisk works great to show you what menuet can do in the fastest way.
But if you want to use menuet as a OS than the ramdisk slows loading of OS and makes it harder to work on programs.
So keep ramdisk as a demo OS ver and make a users ver without ramdisk, but with floppy driver etc.
hidnplayr- 04-11-2006
So keep ramdisk as a demo OS ver and make a users ver without ramdisk, but with floppy driver etc.
Or just ask the user at load if he want's to create a ramdisk.. (only when booting from removable media)
Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.