bootloader optimization

git-svn-id: svn://kolibrios.org@1940 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Artem Jerdev (art_zh) 2011-05-28 07:32:24 +00:00
parent 4781615a70
commit e37372cd01
6 changed files with 87 additions and 186 deletions

View File

@ -21,8 +21,6 @@ seg_read_kernel equ 01000h ;segment to kernel read
; Boot Sector and BPB Structure ; Boot Sector and BPB Structure
include 'floppy1440.inc' include 'floppy1440.inc'
;include 'floppy2880.inc' ;include 'floppy2880.inc'
;include 'floppy1680.inc'
;include 'floppy1743.inc'
start_program: start_program:
@ -47,30 +45,8 @@ read_root_directory:
push ss push ss
pop es pop es
; calculate some disk parameters
; - beginning sector of RootDir
mov ax,word [BPB_FATSz16+boot_program]
xor cx,cx
mov cl,byte [BPB_NumFATs+boot_program]
mul cx
add ax,word [BPB_RsvdSecCnt+boot_program]
mov word [FirstRootDirSecNum+boot_program],ax ; 19
mov si,ax
; - count of sectors in RootDir
mov bx,word [BPB_BytsPerSec+boot_program]
mov cl,5 ; divide ax by 32
shr bx,cl ; bx = directory entries per sector
mov ax,word [BPB_RootEntCnt+boot_program]
xor dx,dx
div bx
mov word [RootDirSecs+boot_program],ax ; 14
; - data start
add si,ax ; add beginning sector of RootDir and count sectors in RootDir
mov word [data_start+boot_program],si ; 33
; reading root directory ; reading root directory
; al=count root dir sectrors !!!! TODO: al, max 255 sectors !!!! ; al=count root dir sectors !!!! TODO: al, max 255 sectors !!!!
mov ah,2 ; read mov ah,2 ; read
push ax push ax
@ -96,21 +72,7 @@ loop_find_dir_entry:
add si,32 ; next dir. entry add si,32 ; next dir. entry
cmp si,ax ; end of directory cmp si,ax ; end of directory
jb loop_find_dir_entry jb loop_find_dir_entry
jmp $
file_error_message:
mov si,error_message+boot_program
loop_error_message:
lodsb
or al,al
jz freeze_pc
mov ah,0eh
mov bx,7
int 10h
jmp loop_error_message
freeze_pc:
jmp $ ; endless loop
; === KERNEL FOUND. LOADING... === ; === KERNEL FOUND. LOADING... ===
@ -127,29 +89,18 @@ found_kernel_file:
mov ah,2 ; ah=2 (read) mov ah,2 ; ah=2 (read)
mov al, byte [BPB_FATSz16+boot_program] ; FAT size in sectors (TODO: max 255 sectors) mov al, byte [BPB_FATSz16+boot_program] ; FAT size in sectors (TODO: max 255 sectors)
call read_sector call read_sector
jc file_error_message ; read error
mov ax,seg_read_kernel mov ax,seg_read_kernel
mov es,ax mov es,ax
xor bx,bx ; es:bx = 1000h:0000h xor bx,bx ; es:bx = 1000h:0000h
; reading kernel file ; reading kernel file
loop_obtains_kernel_data: loop_obtains_kernel_data:
; read one cluster of file call obtain_cluster ; read one cluster of file
call obtain_cluster
jc file_error_message ; read error
; add one cluster length to segment:offset mov ax,es
push bx add ax,seg_inc_per_cluster ; << =32(1.44M) or 64(2.88) >>
mov bx,es mov es,ax ; add one cluster length to segment:offset
mov ax,word [BPB_BytsPerSec+boot_program] ;\
movsx cx,byte [BPB_SecPerClus+boot_program] ; | !!! TODO: !!!
mul cx ; | out this from loop !!!
shr ax,4 ;/
add bx,ax
mov es,bx
pop bx
mov di,bp mov di,bp
shr di,1 shr di,1
@ -162,8 +113,7 @@ loop_obtains_kernel_data:
and ax,0fffh and ax,0fffh
jmp verify_end_sector jmp verify_end_sector
move_4_right: move_4_right:
mov cl,4 shr ax,4
shr ax,cl
verify_end_sector: verify_end_sector:
cmp ax,0ff8h ; last cluster cmp ax,0ff8h ; last cluster
jae execute_kernel jae execute_kernel
@ -194,87 +144,70 @@ obtain_cluster:
mov ax,0e2eh ; ah=0eh (teletype), al='.' mov ax,0e2eh ; ah=0eh (teletype), al='.'
xor bh,bh xor bh,bh
int 10h int 10h
; jc $ ; error
pop bx
writesec:
; convert cluster number to sector number ; convert cluster number to sector number
mov ax,bp ; data cluster to read mov ax,bp ; data cluster to read
sub ax,2 sub ax,2
xor bx,bx ;>> add ax,ax ; << only for 2.88M disks! >>
mov bl,byte [BPB_SecPerClus+boot_program]
mul bx
add ax,word [data_start+boot_program] add ax,word [data_start+boot_program]
pop bx
writesec:
call conv_abs_to_THS ; convert abs sector (AX) to BIOS T:H:S (track:head:sector) call conv_abs_to_THS ; convert abs sector (AX) to BIOS T:H:S (track:head:sector)
patchhere:
mov ah,2 ; ah=2 (read)
mov al,byte [BPB_SecPerClus+boot_program] ; al=(one cluster)
call read_sector
retn
;------------------------------------------
;------------------------------------------ patchhere:
mov ax,0x201 ; ah=2 (read)
;>> ; al=1(1.44) or 2(2.88)
; read sector from disk ; read sector from disk
read_sector: read_sector:
push bp
mov bp,20 ; try 20 times
newread:
dec bp
jz file_error_message
push ax bx cx dx push ax bx cx dx
int 13h int 13h
jc $ ; error: stop here
pop dx cx bx ax pop dx cx bx ax
jc newread
pop bp
retn retn
;------------------------------------------ ;------------------------------------------
; convert abs. sector number (AX) to BIOS T:H:S ; converts abs. sector number (AX) to BIOS T:H:S
; sector number = (abs.sector%BPB_SecPerTrk)+1 ; Returns: {pre.track number = (AX / BPB_SecPerTrk)}
; pre.track number = (abs.sector/BPB_SecPerTrk) ; ch - track number = pre.track number/2
; head number = pre.track number%BPB_NumHeads ; cl - sector number = (abs.sector%BPB_SecPerTrk)+1
; track number = pre.track number/BPB_NumHeads ; dh - head number = pre.track number%BPB_NumHeads
; Return: cl - sector number ; dl - drive number (0 = a:)
; ch - track number
; dl - drive number (0 = a:)
; dh - head number
conv_abs_to_THS: conv_abs_to_THS:
push bx mov cx,word [BPB_SecPerTrk+boot_program] ; << 18 or 36 >>
mov bx,word [BPB_SecPerTrk+boot_program]
xor dx,dx xor dx,dx
div bx div cx
inc dx inc dx
mov cl, dl ; cl = sector number mov cl, dl ; cl = sector number
mov bx,word [BPB_NumHeads+boot_program] xor dx, dx
xor dx,dx shr ax, 1
div bx rol dx, 1 ; dh = head number
; !!!!!!! ax = track number, dx = head number mov ch, al ; ch = track number
mov ch,al ; ch=track number
xchg dh,dl ; dh=head number
mov dl,0 ; dl=0 (drive 0 (a:))
pop bx
retn retn
;------------------------------------------ ;------------------------------------------
loading db cr,lf,'Starting system ',00h loading db cr,lf,'Starting system ',00h
error_message db 13,10 ;error_message db 13,10
kernel_name db 'KERNEL MNT ?',cr,lf,00h kernel_name db 'KERNEL MNT',00h
FirstRootDirSecNum dw ? FirstRootDirSecNum dw 19 ; 1st sector of the root dir
RootDirSecs dw ? RootDirSecs dw 14 ; << = 14(1.44M) or 15(2.88M) >>
data_start dw ? data_start dw 33 ; << = 33(1.44M) or 34(2.88M) >>
; <diamond> ; <diamond>
write1st: write1st:
push cs push cs
pop ds pop ds
mov byte [patchhere+1+boot_program], 3 ; change ah=2 to ah=3 mov byte [patchhere+1+boot_program], 3 ; change ah=2 to ah=3
mov ax,[cluster1st+boot_program] mov bp,[cluster1st+boot_program]
push 1000h push 1000h
pop es pop es
xor bx,bx xor bx,bx
call writesec call writesec
mov byte [patchhere+1+boot_program], 2 ; change back ah=3 to ah=2 mov byte [patchhere+1+boot_program], 2 ; change back ah=3 to ah=2
retf retf
cluster1st dw ?
cluster1st dw ? ; 1st cluster of kernel.mnt
loader_block: loader_block:
db 1 db 1
dw 0 dw 0

View File

@ -1,3 +1,5 @@
seg_inc_per_cluster equ 32 ; = cluster_size shr 4
BS_OEMName db 'KOLIBRI ' ; db 8 BS_OEMName db 'KOLIBRI ' ; db 8
BPB_BytsPerSec dw 512 ; bytes per sector BPB_BytsPerSec dw 512 ; bytes per sector
BPB_SecPerClus db 1 ; sectors per cluster BPB_SecPerClus db 1 ; sectors per cluster

View File

@ -1,19 +0,0 @@
BS_OEMName db 'KOLIBRI ' ; db 8
BPB_BytsPerSec dw 512 ; bytes per sector
BPB_SecPerClus db 1 ; sectors per cluster
BPB_RsvdSecCnt dw 1 ; number of reserver sectors
BPB_NumFATs db 2 ; count of FAT data structures
BPB_RootEntCnt dw 112 ; count of 32-byte dir. entries (112*32 = 7 sectors)
BPB_TotSec16 dw 3360 ; count of sectors on the volume (3360 for 1.68 mbytes disk)
BPB_Media db 0f0h ; f0 - used for removable media
BPB_FATSz16 dw 10 ; count of sectors by one copy of FAT
BPB_SecPerTrk dw 21 ; sectors per track
BPB_NumHeads dw 2 ; number of heads
BPB_HiddSec dd 0 ; count of hidden sectors
BPB_TotSec32 dd 0 ; count of sectors on the volume (if > 65535)
BS_DrvNum db 0 ; int 13h drive number
BS_Reserved db 0 ; reserved
BS_BootSig db 29h ; Extended boot signature
BS_VolID dd 0 ; Volume serial number
BS_VolLab db 'KOLIBRI ' ; Volume label (db 11)
BS_FilSysType db 'FAT12 ' ; file system type (db 8)

View File

@ -1,19 +0,0 @@
BS_OEMName db 'KOLIBRI ' ; db 8
BPB_BytsPerSec dw 512 ; bytes per sector
BPB_SecPerClus db 1 ; sectors per cluster
BPB_RsvdSecCnt dw 1 ; number of reserver sectors
BPB_NumFATs db 2 ; count of FAT data structures
BPB_RootEntCnt dw 224 ; count of 32-byte dir. entries (224*32 = 14 sectors)
BPB_TotSec16 dw 3486 ; count of sectors on the volume (3486 for 1.74 mbytes disk)
BPB_Media db 0f0h ; f0 - used for removable media
BPB_FATSz16 dw 11 ; count of sectors by one copy of FAT
BPB_SecPerTrk dw 21 ; sectors per track
BPB_NumHeads dw 2 ; number of heads
BPB_HiddSec dd 0 ; count of hidden sectors
BPB_TotSec32 dd 0 ; count of sectors on the volume (if > 65535)
BS_DrvNum db 0 ; int 13h drive number
BS_Reserved db 0 ; reserved
BS_BootSig db 29h ; Extended boot signature
BS_VolID dd 0 ; Volume serial number
BS_VolLab db 'KOLIBRI ' ; Volume label (db 11)
BS_FilSysType db 'FAT12 ' ; file system type (db 8)

View File

@ -1,3 +1,5 @@
seg_inc_per_cluster equ 64 ; = cluster_size shr 4
BS_OEMName db 'KOLIBRI ' ; db 8 BS_OEMName db 'KOLIBRI ' ; db 8
BPB_BytsPerSec dw 512 ; bytes per sector BPB_BytsPerSec dw 512 ; bytes per sector
BPB_SecPerClus db 2 ; sectors per cluster BPB_SecPerClus db 2 ; sectors per cluster

View File

@ -3,6 +3,8 @@
; ;
; Boot: ; Boot:
; ;
; 0:7C00->7CFF boot_code
;
; 0:9000 byte bits per pixel ; 0:9000 byte bits per pixel
; 0:9001 word scanline length ; 0:9001 word scanline length
; 0:9008 word vesa video mode ; 0:9008 word vesa video mode