modify for compile fasm 1.68 and add build.bat

git-svn-id: svn://kolibrios.org@1132 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Alexey Teplov ( 2009-08-18 18:15:03 +00:00
parent d165a4f143
commit 69eaca2fef
10 changed files with 2253 additions and 2227 deletions

View File

@ -0,0 +1,2 @@
@fasm -m 65535 kordldr.win.asm kordldr.win
@pause

View File

@ -0,0 +1,16 @@
echo off
cls
echo ** bulding after win loader **
@fasm -m 65535 after_win/kordldr.win.asm after_win/kordldr.win
echo ==============================
echo ** building first loader for cd/dvd **
@fasm -m 65535 cdfs/bootsect.asm cdfs/bootsect.bin
echo ==============================
echo ** building first loader for fat12/fat16 **
@fasm -m 65535 fat1x/bootsect.asm fat1x/bootsect.bin
@fasm -m 65535 fat1x/kordldr.f1x.asm fat1x/kordldr.f1x
echo ==============================
echo ** building firs loader for fat32 **
@fasm -m 65535 fat32/bootsect.asm fat32/bootsect.bin
@fasm -m 65535 fat32/kordldr.f1x.asm fat32/kordldr.f1x
@pause

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,2 @@
@fasm -m 65535 bootsect.asm bootsect.bin
@pause

View File

@ -25,254 +25,254 @@
;***************************************************************************** ;*****************************************************************************
use_lba = 0 use_lba = 0
org 0x7C00 org 0x7C00
jmp start jmp start
nop nop
; FAT parameters, BPB ; FAT parameters, BPB
; note: they can be changed at install, replaced with real values ; note: they can be changed at install, replaced with real values
; these settings are for most typical 1.44M floppies ; these settings are for most typical 1.44M floppies
db 'KOLIBRI ' ; BS_OEMName, ignored db 'KOLIBRI ' ; BS_OEMName, ignored
dw 200h ; BPB_BytsPerSec dw 200h ; BPB_BytsPerSec
BPB_SecsPerClus db 1 BPB_SecsPerClus db 1
BPB_RsvdSecCnt dw 1 BPB_RsvdSecCnt dw 1
BPB_NumFATs db 2 BPB_NumFATs db 2
BPB_RootEntCnt dw 0xE0 BPB_RootEntCnt dw 0xE0
dw 2880 ; BPB_TotSec16 dw 2880 ; BPB_TotSec16
db 0xF0 ; BPB_Media db 0xF0 ; BPB_Media
BPB_FATSz16 dw 9 BPB_FATSz16 dw 9
BPB_SecPerTrk dw 18 BPB_SecPerTrk dw 18
BPB_NumHeads dw 2 BPB_NumHeads dw 2
BPB_HiddSec dd 0 BPB_HiddSec dd 0
dd 0 ; BPB_TotSec32 dd 0 ; BPB_TotSec32
BS_DrvNum db 0 BS_DrvNum db 0
db 0 ; BS_Reserved1 db 0 ; BS_Reserved1
db ')' ; BS_BootSig db ')' ; BS_BootSig
dd 12344321h ; BS_VolID dd 12344321h ; BS_VolID
filename: filename:
db 'KORD.OS ' ; BS_VolLab db 'KORD.OS ' ; BS_VolLab
db 'FAT12 ' ; BS_FilSysType db 'FAT12 ' ; BS_FilSysType
; Used memory map: ; Used memory map:
; 8000:0000 - current directory ; 8000:0000 - current directory
; 9000:0000 - root directory data [cached] ; 9000:0000 - root directory data [cached]
start: start:
xor ax, ax xor ax, ax
mov ss, ax mov ss, ax
mov sp, 0x7C00 mov sp, 0x7C00
mov ds, ax mov ds, ax
mov bp, sp mov bp, sp
cld cld
sti sti
mov [bp+BS_DrvNum-0x7C00], dl mov [bp+BS_DrvNum-0x7C00], dl
if use_lba if use_lba
mov ah, 41h mov ah, 41h
mov bx, 55AAh mov bx, 55AAh
int 13h int 13h
mov si, aNoLBA mov si, aNoLBA
jc err jc err_
cmp bx, 0AA55h cmp bx, 0AA55h
jnz err jnz err_
test cx, 1 test cx, 1
jz err jz err_
else else
mov ah, 8 mov ah, 8
int 13h int 13h
jc @f ; on error, assume that BPB geometry is valid jc @f ; on error, assume that BPB geometry is valid
mov al, dh mov al, dh
mov ah, 0 mov ah, 0
inc ax inc ax
mov [bp+BPB_NumHeads-0x7C00], ax mov [bp+BPB_NumHeads-0x7C00], ax
and cx, 3Fh and cx, 3Fh
mov [bp+BPB_SecPerTrk-0x7C00], cx mov [bp+BPB_SecPerTrk-0x7C00], cx
@@: @@:
end if end if
; get FAT parameters ; get FAT parameters
xor bx, bx xor bx, bx
mov al, [bp+BPB_NumFATs-0x7C00] mov al, [bp+BPB_NumFATs-0x7C00]
mov ah, 0 mov ah, 0
mul [bp+BPB_FATSz16-0x7C00] mul [bp+BPB_FATSz16-0x7C00]
add ax, [bp+BPB_RsvdSecCnt-0x7C00] add ax, [bp+BPB_RsvdSecCnt-0x7C00]
adc dx, bx adc dx, bx
push dx push dx
push ax ; root directory start = dword [bp-4] push ax ; root directory start = dword [bp-4]
mov cx, [bp+BPB_RootEntCnt-0x7C00] mov cx, [bp+BPB_RootEntCnt-0x7C00]
add cx, 0xF add cx, 0xF
rcr cx, 1 rcr cx, 1
shr cx, 3 ; cx = size of root directory in sectors shr cx, 3 ; cx = size of root directory in sectors
add ax, cx add ax, cx
adc dx, bx adc dx, bx
push dx push dx
push ax ; data start = dword [bp-8] push ax ; data start = dword [bp-8]
; load start of root directory (no more than 0x2000 bytes = 0x10 sectors) ; load start of root directory (no more than 0x2000 bytes = 0x10 sectors)
cmp cx, 0x10 cmp cx, 0x10
jb @f jb @f
mov cx, 0x10 mov cx, 0x10
@@: @@:
mov ax, [bp-4] mov ax, [bp-4]
mov dx, [bp-2] mov dx, [bp-2]
push 0x9000 push 0x9000
pop es pop es
call read_sectors call read_sectors
add word [bp-4], cx ; dword [bp-4] = start of non-cached root data add word [bp-4], cx ; dword [bp-4] = start of non-cached root data
adc word [bp-2], bx adc word [bp-2], bx
; load kordldr.f12 ; load kordldr.f12
mov si, main_loader mov si, main_loader
call lookup_in_root_dir call lookup_in_root_dir
jc noloader jc noloader
test byte [es:di+11], 10h ; directory? test byte [es:di+11], 10h ; directory?
jz kordldr_ok jz kordldr_ok
noloader: noloader:
mov si, aLoaderNotFound mov si, aLoaderNotFound
err: err_:
call out_string call out_string
mov si, aPressAnyKey mov si, aPressAnyKey
call out_string call out_string
xor ax, ax xor ax, ax
int 16h int 16h
int 18h int 18h
jmp $ jmp $
kordldr_ok: kordldr_ok:
mov ax, [es:di+26] ; get file cluster mov ax, [es:di+26] ; get file cluster
mov bx, 0x7E00 mov bx, 0x7E00
xor cx, cx xor cx, cx
mov es, cx mov es, cx
sub ax, 2 sub ax, 2
jc noloader jc noloader
push bx ; save return address: bx = 7E00 push bx ; save return address: bx = 7E00
mov cl, [bp+BPB_SecsPerClus-0x7C00] mov cl, [bp+BPB_SecsPerClus-0x7C00]
mul cx mul cx
; fall through - 'ret' in read_sectors will return to 7E00 ; fall through - 'ret' in read_sectors will return to 7E00
read_sectors2: read_sectors2:
; same as read_sectors, but dx:ax is relative to start of data ; same as read_sectors, but dx:ax is relative to start of data
add ax, [bp-8] add ax, [bp-8]
adc dx, [bp-6] adc dx, [bp-6]
read_sectors: read_sectors:
; ss:bp = 0:7C00 ; ss:bp = 0:7C00
; es:bx = pointer to data ; es:bx = pointer to data
; dx:ax = first sector ; dx:ax = first sector
; cx = number of sectors ; cx = number of sectors
pusha pusha
add ax, word [bp+BPB_HiddSec-0x7C00] add ax, word [bp+BPB_HiddSec-0x7C00]
adc dx, word [bp+BPB_HiddSec+2-0x7C00] adc dx, word [bp+BPB_HiddSec+2-0x7C00]
if use_lba if use_lba
push ds push ds
do_read_sectors: do_read_sectors:
push ax push ax
push cx push cx
push dx push dx
cmp cx, 0x7F cmp cx, 0x7F
jbe @f jbe @f
mov cx, 0x7F mov cx, 0x7F
@@: @@:
; create disk address packet on the stack ; create disk address packet on the stack
; dq starting LBA ; dq starting LBA
push 0 push 0
push 0 push 0
push dx push dx
push ax push ax
; dd buffer ; dd buffer
push es push es
push bx push bx
; dw number of blocks to transfer (no more than 0x7F) ; dw number of blocks to transfer (no more than 0x7F)
push cx push cx
; dw packet size in bytes ; dw packet size in bytes
push 10h push 10h
; issue BIOS call ; issue BIOS call
push ss push ss
pop ds pop ds
mov si, sp mov si, sp
mov dl, [bp+BS_DrvNum-0x7C00] mov dl, [bp+BS_DrvNum-0x7C00]
mov ah, 42h mov ah, 42h
int 13h int 13h
mov si, aReadError mov si, aReadError
jc err jc err_
; restore stack ; restore stack
add sp, 10h add sp, 10h
; increase current sector & buffer; decrease number of sectors ; increase current sector & buffer; decrease number of sectors
mov si, cx mov si, cx
mov ax, es mov ax, es
shl cx, 5 shl cx, 5
add ax, cx add ax, cx
mov es, ax mov es, ax
pop dx pop dx
pop cx pop cx
pop ax pop ax
add ax, si add ax, si
adc dx, 0 adc dx, 0
sub cx, si sub cx, si
jnz do_read_sectors jnz do_read_sectors
pop ds pop ds
popa popa
ret ret
else else
do_read_sectors: do_read_sectors:
pusha pusha
pop di pop di
push bx push bx
; (dword in dx:ax) / (SectorsPerTrack) -> (dword in dx:ax), remainder bx ; (dword in dx:ax) / (SectorsPerTrack) -> (dword in dx:ax), remainder bx
mov si, ax mov si, ax
xchg ax, dx xchg ax, dx
xor dx, dx xor dx, dx
div [bp+BPB_SecPerTrk-0x7C00] div [bp+BPB_SecPerTrk-0x7C00]
push ax push ax
mov ax, si mov ax, si
div [bp+BPB_SecPerTrk-0x7C00] div [bp+BPB_SecPerTrk-0x7C00]
mov bx, dx ; bx=sector-1 mov bx, dx ; bx=sector-1
pop dx pop dx
; (dword in dx:ax) / (NumHeads) -> (word in ax), remainder dx ; (dword in dx:ax) / (NumHeads) -> (word in ax), remainder dx
div [bp+BPB_NumHeads-0x7C00] div [bp+BPB_NumHeads-0x7C00]
; number of sectors: read no more than to end of track ; number of sectors: read no more than to end of track
push bx push bx
sub bx, [bp+BPB_SecPerTrk-0x7C00] sub bx, [bp+BPB_SecPerTrk-0x7C00]
neg bx neg bx
cmp cx, bx cmp cx, bx
jbe @f jbe @f
mov cx, bx mov cx, bx
@@: @@:
pop bx pop bx
inc bx inc bx
; now ax=track, dl=head, dh=0, cl=number of sectors, ch=0, bl=sector; convert to int13 format ; now ax=track, dl=head, dh=0, cl=number of sectors, ch=0, bl=sector; convert to int13 format
mov di, cx mov di, cx
mov dh, dl mov dh, dl
mov dl, [bp+BS_DrvNum-0x7C00] mov dl, [bp+BS_DrvNum-0x7C00]
shl ah, 6 shl ah, 6
mov ch, al mov ch, al
mov al, cl mov al, cl
mov cl, bl mov cl, bl
or cl, ah or cl, ah
pop bx pop bx
mov si, 3 mov si, 3
mov ah, 2 mov ah, 2
@@: @@:
push ax push ax
int 13h int 13h
jnc @f jnc @f
xor ax, ax xor ax, ax
int 13h ; reset drive int 13h ; reset drive
pop ax pop ax
dec si dec si
jnz @b jnz @b
mov si, aReadError mov si, aReadError
jmp err jmp err_
@@: @@:
pop ax pop ax
mov ax, es mov ax, es
mov cx, di mov cx, di
shl cx, 5 shl cx, 5
add ax, cx add ax, cx
mov es, ax mov es, ax
push di push di
popa popa
add ax, di add ax, di
adc dx, 0 adc dx, 0
sub cx, di sub cx, di
jnz do_read_sectors jnz do_read_sectors
popa popa
ret ret
end if end if
scan_for_filename: scan_for_filename:
@ -282,111 +282,111 @@ scan_for_filename:
; out: if found: CF=0, ZF=1, es:di -> directory entry ; out: if found: CF=0, ZF=1, es:di -> directory entry
; out: if not found, but continue required: CF=1 and ZF=0 ; out: if not found, but continue required: CF=1 and ZF=0
; out: if not found and zero item reached: CF=1 and ZF=1 ; out: if not found and zero item reached: CF=1 and ZF=1
xor di, di xor di, di
push cx push cx
sloop: sloop:
cmp byte [es:di], 0 cmp byte [es:di], 0
jz snotfound jz snotfound
test byte [es:di+11], 8 ; volume label? test byte [es:di+11], 8 ; volume label?
jnz scont ; ignore volume labels jnz scont ; ignore volume labels
pusha pusha
mov cx, 11 mov cx, 11
repz cmpsb repz cmpsb
popa popa
jz sdone jz sdone
scont: scont:
add di, 0x20 add di, 0x20
loop sloop loop sloop
inc cx ; clear ZF flag inc cx ; clear ZF flag
snotfound: snotfound:
stc stc
sdone: sdone:
pop cx pop cx
lrdret: lrdret:
ret ret
lookup_in_root_dir: lookup_in_root_dir:
; ss:bp = 0:7C00 ; ss:bp = 0:7C00
; in: ds:si -> 11-bytes FAT name ; in: ds:si -> 11-bytes FAT name
; out: if found: CF=0, es:di -> directory entry ; out: if found: CF=0, es:di -> directory entry
; out: if not found: CF=1 ; out: if not found: CF=1
mov cx, [bp+BPB_RootEntCnt-0x7C00] mov cx, [bp+BPB_RootEntCnt-0x7C00]
push cx push cx
; first, look in root directory cache ; first, look in root directory cache
push 0x9000 push 0x9000
pop es pop es
test ch, ch test ch, ch
jz @f jz @f
mov cx, 0x100 mov cx, 0x100
@@: @@:
mov ax, [bp-4] mov ax, [bp-4]
mov dx, [bp-2] ; dx:ax = starting sector of not cached data of root directory mov dx, [bp-2] ; dx:ax = starting sector of not cached data of root directory
lrdloop: lrdloop:
call scan_for_filename call scan_for_filename
pop bx pop bx
jz lrdret jz lrdret
sub bx, cx sub bx, cx
mov cx, bx mov cx, bx
stc stc
jz lrdret jz lrdret
; read no more than 0x10000 bytes, or 0x10000/0x20 = 0x800 entries ; read no more than 0x10000 bytes, or 0x10000/0x20 = 0x800 entries
push cx push cx
cmp ch, 0x8 cmp ch, 0x8
jb @f jb @f
mov cx, 0x800 mov cx, 0x800
@@: @@:
push 0x8000 push 0x8000
pop es pop es
push cx push cx
push es push es
xor bx, bx xor bx, bx
add cx, 0xF add cx, 0xF
shr cx, 4 shr cx, 4
call read_sectors call read_sectors
pop es pop es
add ax, cx add ax, cx
adc dx, bx adc dx, bx
pop cx pop cx
jmp lrdloop jmp lrdloop
out_string: out_string:
; in: ds:si -> ASCIIZ string ; in: ds:si -> ASCIIZ string
lodsb lodsb
test al, al test al, al
jz lrdret jz lrdret
mov ah, 0Eh mov ah, 0Eh
mov bx, 7 mov bx, 7
int 10h int 10h
jmp out_string jmp out_string
aReadError db 'Read error',0 aReadError db 'Read error',0
if use_lba if use_lba
aNoLBA db 'The drive does not support LBA!',0 aNoLBA db 'The drive does not support LBA!',0
end if end if
aLoaderNotFound db 'Loader not found',0 aLoaderNotFound db 'Loader not found',0
aPressAnyKey db 13,10,'Press any key...',13,10,0 aPressAnyKey db 13,10,'Press any key...',13,10,0
main_loader db 'KORDLDR F1X' main_loader db 'KORDLDR F1X'
if use_lba if use_lba
db 0 ; make bootsector 512 bytes in length db 0 ; make bootsector 512 bytes in length
end if end if
; bootsector signature ; bootsector signature
dw 0xAA55 dw 0xAA55
; display offsets of all procedures used by kordldr.f12.asm ; display offsets of all procedures used by kordldr.f12.asm
macro show [procedure] macro show [procedure]
{ {
bits = 16 bits = 16
display `procedure,' = ' display `procedure,' = '
repeat bits/4 repeat bits/4
d = '0' + procedure shr (bits - %*4) and 0Fh d = '0' + procedure shr (bits - %*4) and 0Fh
if d > '9' if d > '9'
d = d + 'A'-'9'-1 d = d + 'A'-'9'-1
end if end if
display d display d
end repeat end repeat
display 13,10 display 13,10
} }
show read_sectors, read_sectors2, lookup_in_root_dir, scan_for_filename, err, noloader show read_sectors, read_sectors2, lookup_in_root_dir, scan_for_filename, err_, noloader

View File

@ -0,0 +1,3 @@
@fasm -m 65535 bootsect.asm bootsect.bin
@fasm -m 65535 kordldr.f1x.asm kordldr.f1x
@pause

File diff suppressed because it is too large Load Diff

View File

@ -25,232 +25,232 @@
;***************************************************************************** ;*****************************************************************************
use_lba = 0 use_lba = 0
org 0x7C00 org 0x7C00
jmp start jmp start
nop nop
; FAT parameters, BPB ; FAT parameters, BPB
; they must be changed at install, replaced with real values ; they must be changed at install, replaced with real values
rb 8 ; BS_OEMName, ignored rb 8 ; BS_OEMName, ignored
dw 200h ; BPB_BytsPerSec dw 200h ; BPB_BytsPerSec
BPB_SecsPerClus db ? BPB_SecsPerClus db ?
BPB_RsvdSecCnt dw ? BPB_RsvdSecCnt dw ?
BPB_NumFATs db ? BPB_NumFATs db ?
BPB_RootEntCnt dw ? BPB_RootEntCnt dw ?
dw ? ; BPB_TotSec16 dw ? ; BPB_TotSec16
db ? ; BPB_Media db ? ; BPB_Media
dw ? ; BPB_FATSz16 = 0 for FAT32 dw ? ; BPB_FATSz16 = 0 for FAT32
BPB_SecPerTrk dw ? BPB_SecPerTrk dw ?
BPB_NumHeads dw ? BPB_NumHeads dw ?
BPB_HiddSec dd ? BPB_HiddSec dd ?
dd ? ; BPB_TotSec32 dd ? ; BPB_TotSec32
BPB_FATSz32 dd ? BPB_FATSz32 dd ?
BPB_ExtFlags dw ? BPB_ExtFlags dw ?
dw ? ; BPB_FSVer dw ? ; BPB_FSVer
BPB_RootClus dd ? BPB_RootClus dd ?
dw ? ; BPB_FSInfo dw ? ; BPB_FSInfo
BPB_BkBootSec dw ? BPB_BkBootSec dw ?
rb 12 ; BPB_Reserved rb 12 ; BPB_Reserved
BS_DrvNum db ? BS_DrvNum db ?
db ? ; BS_Reserved1 db ? ; BS_Reserved1
db ? ; BS_BootSig db ? ; BS_BootSig
dd ? ; BS_VolID dd ? ; BS_VolID
rb 11 ; BS_VolLab rb 11 ; BS_VolLab
rb 8 ; rb 8 ;
curseg dw 0x8000 curseg dw 0x8000
start: start:
xor ax, ax xor ax, ax
mov ss, ax mov ss, ax
mov sp, 0x7C00 mov sp, 0x7C00
mov ds, ax mov ds, ax
mov bp, sp mov bp, sp
cld cld
sti sti
push dx ; byte [bp-2] = boot drive push dx ; byte [bp-2] = boot drive
if use_lba if use_lba
mov ah, 41h mov ah, 41h
mov bx, 55AAh mov bx, 55AAh
int 13h int 13h
mov si, aNoLBA mov si, aNoLBA
jc err jc err_
cmp bx, 0AA55h cmp bx, 0AA55h
jnz err jnz err_
test cl, 1 test cl, 1
jz err jz err_
else else
mov ah, 8 mov ah, 8
int 13h int 13h
jc @f jc @f
movzx ax, dh movzx ax, dh
inc ax inc ax
mov [bp+BPB_NumHeads-0x7C00], ax mov [bp+BPB_NumHeads-0x7C00], ax
and cx, 3Fh and cx, 3Fh
mov [bp+BPB_SecPerTrk-0x7C00], cx mov [bp+BPB_SecPerTrk-0x7C00], cx
@@: @@:
end if end if
; get FAT parameters ; get FAT parameters
xor bx, bx xor bx, bx
movzx eax, [bp+BPB_NumFATs-0x7C00] movzx eax, [bp+BPB_NumFATs-0x7C00]
mul [bp+BPB_FATSz32-0x7C00] mul [bp+BPB_FATSz32-0x7C00]
movzx ecx, [bp+BPB_RsvdSecCnt-0x7C00] movzx ecx, [bp+BPB_RsvdSecCnt-0x7C00]
push ecx ; FAT start = dword [bp-6] push ecx ; FAT start = dword [bp-6]
add eax, ecx add eax, ecx
push eax ; data start = dword [bp-10] push eax ; data start = dword [bp-10]
;push dword -1 ; dword [bp-14] = current sector for FAT cache ;push dword -1 ; dword [bp-14] = current sector for FAT cache
db 66h db 66h
push -1 ; dword [bp-14] = current sector for FAT cache push -1 ; dword [bp-14] = current sector for FAT cache
mov eax, [bp+BPB_RootClus-0x7C00] mov eax, [bp+BPB_RootClus-0x7C00]
mov si, main_loader mov si, main_loader
call lookup_in_dir call lookup_in_dir
jnc kordldr_ok jnc kordldr_ok
noloader: noloader:
mov si, aLoaderNotFound mov si, aLoaderNotFound
err: err_:
call out_string call out_string
mov si, aPressAnyKey mov si, aPressAnyKey
call out_string call out_string
xor ax, ax xor ax, ax
int 16h int 16h
int 18h int 18h
jmp $ jmp $
kordldr_ok: kordldr_ok:
mov eax, [es:di+20-2] ; hiword(eax) = hiword(cluster) mov eax, [es:di+20-2] ; hiword(eax) = hiword(cluster)
mov ax, [es:di+26] ; loword(eax) = loword(cluster) mov ax, [es:di+26] ; loword(eax) = loword(cluster)
mov es, bx ; es = 0 mov es, bx ; es = 0
mov bx, 0x7E00 mov bx, 0x7E00
push bx ; save return address: bx = 7E00 push bx ; save return address: bx = 7E00
; fall through - 'ret' in read_cluster will return to 7E00 ; fall through - 'ret' in read_cluster will return to 7E00
read_cluster: read_cluster:
; ss:bp = 0:7C00 ; ss:bp = 0:7C00
; es:bx = pointer to data ; es:bx = pointer to data
; eax = cluster ; eax = cluster
sub eax, 2 sub eax, 2
movzx ecx, [bp+BPB_SecsPerClus-0x7C00] movzx ecx, [bp+BPB_SecsPerClus-0x7C00]
mul ecx mul ecx
read_sectors2: read_sectors2:
; same as read_sectors32, but eax is relative to start of data ; same as read_sectors32, but eax is relative to start of data
add eax, [bp-10] add eax, [bp-10]
read_sectors32: read_sectors32:
; ss:bp = 0:7C00 ; ss:bp = 0:7C00
; es:bx = pointer to data ; es:bx = pointer to data
; eax = first sector ; eax = first sector
; cx = number of sectors ; cx = number of sectors
; some high words of 32-bit registers are destroyed! ; some high words of 32-bit registers are destroyed!
pusha pusha
add eax, [bp+BPB_HiddSec-0x7C00] add eax, [bp+BPB_HiddSec-0x7C00]
if use_lba if use_lba
push ds push ds
do_read_sectors: do_read_sectors:
push ax push ax
push cx push cx
cmp cx, 0x7F cmp cx, 0x7F
jbe @f jbe @f
mov cx, 0x7F mov cx, 0x7F
@@: @@:
; create disk address packet on the stack ; create disk address packet on the stack
; dq starting LBA ; dq starting LBA
push 0 push 0
push 0 push 0
push eax push eax
; dd buffer ; dd buffer
push es push es
push bx push bx
; dw number of blocks to transfer (no more than 0x7F) ; dw number of blocks to transfer (no more than 0x7F)
push cx push cx
; dw packet size in bytes ; dw packet size in bytes
push 10h push 10h
; issue BIOS call ; issue BIOS call
push ss push ss
pop ds pop ds
mov si, sp mov si, sp
mov dl, [bp-2] mov dl, [bp-2]
mov ah, 42h mov ah, 42h
int 13h int 13h
mov si, aReadError mov si, aReadError
jc err jc err_
; restore stack ; restore stack
add sp, 10h add sp, 10h
; increase current sector & buffer; decrease number of sectors ; increase current sector & buffer; decrease number of sectors
movzx esi, cx movzx esi, cx
mov ax, es mov ax, es
shl cx, 5 shl cx, 5
add ax, cx add ax, cx
mov es, ax mov es, ax
pop cx pop cx
pop ax pop ax
add eax, esi add eax, esi
sub cx, si sub cx, si
jnz do_read_sectors jnz do_read_sectors
pop ds pop ds
popa popa
ret ret
else else
do_read_sectors: do_read_sectors:
pusha pusha
pop edi ; loword(edi) = di, hiword(edi) = si pop edi ; loword(edi) = di, hiword(edi) = si
push bx push bx
; eax / (SectorsPerTrack) -> eax, remainder bx ; eax / (SectorsPerTrack) -> eax, remainder bx
movzx esi, [bp+BPB_SecPerTrk-0x7C00] movzx esi, [bp+BPB_SecPerTrk-0x7C00]
xor edx, edx xor edx, edx
div esi div esi
mov bx, dx ; bx=sector-1 mov bx, dx ; bx=sector-1
; eax -> dx:ax ; eax -> dx:ax
push eax push eax
pop ax pop ax
pop dx pop dx
; (dword in dx:ax) / (NumHeads) -> (word in ax), remainder dx ; (dword in dx:ax) / (NumHeads) -> (word in ax), remainder dx
div [bp+BPB_NumHeads-0x7C00] div [bp+BPB_NumHeads-0x7C00]
; number of sectors: read no more than to end of track ; number of sectors: read no more than to end of track
sub si, bx sub si, bx
cmp cx, si cmp cx, si
jbe @f jbe @f
mov cx, si mov cx, si
@@: @@:
inc bx inc bx
; now ax=track, dl=head, dh=0, cl=number of sectors, ch=0, bl=sector; convert to int13 format ; now ax=track, dl=head, dh=0, cl=number of sectors, ch=0, bl=sector; convert to int13 format
movzx edi, cx movzx edi, cx
mov dh, dl mov dh, dl
mov dl, [bp-2] mov dl, [bp-2]
shl ah, 6 shl ah, 6
mov ch, al mov ch, al
mov al, cl mov al, cl
mov cl, bl mov cl, bl
or cl, ah or cl, ah
pop bx pop bx
mov si, 3 mov si, 3
mov ah, 2 mov ah, 2
@@: @@:
push ax push ax
int 13h int 13h
jnc @f jnc @f
xor ax, ax xor ax, ax
int 13h ; reset drive int 13h ; reset drive
pop ax pop ax
dec si dec si
jnz @b jnz @b
mov si, aReadError mov si, aReadError
jmp err jmp err_
@@: @@:
pop ax pop ax
mov ax, es mov ax, es
mov cx, di mov cx, di
shl cx, 5 shl cx, 5
add ax, cx add ax, cx
mov es, ax mov es, ax
push edi push edi
popa popa
add eax, edi add eax, edi
sub cx, di sub cx, di
jnz do_read_sectors jnz do_read_sectors
popa popa
ret ret
end if end if
lookup_in_dir: lookup_in_dir:
@ -259,100 +259,100 @@ lookup_in_dir:
; in: bx = 0 ; in: bx = 0
; out: if found: CF=0, es:di -> directory entry ; out: if found: CF=0, es:di -> directory entry
; out: if not found: CF=1 ; out: if not found: CF=1
; push 0x8000 ; push 0x8000
; pop es ; pop es
; read current cluster: first cluster goes to 8000:0000, others - to 8200:0000 ; read current cluster: first cluster goes to 8000:0000, others - to 8200:0000
mov es, [bp-7C00h + curseg] mov es, [bp-7C00h + curseg]
push es push es
push eax push eax
call read_cluster call read_cluster
mov ax, es mov ax, es
cmp ah, 82h cmp ah, 82h
jb @f jb @f
mov ax, 8200h mov ax, 8200h
@@: @@:
mov [bp-7C00h + curseg], ax mov [bp-7C00h + curseg], ax
pop eax pop eax
pop es pop es
; scan for filename ; scan for filename
shl cx, 4 shl cx, 4
xor di, di xor di, di
sloop: sloop:
cmp byte [es:di], bl cmp byte [es:di], bl
jz snotfound jz snotfound
test byte [es:di+11], 8 ; volume label? test byte [es:di+11], 8 ; volume label?
jnz scont ; ignore volume labels jnz scont ; ignore volume labels
pusha pusha
mov cx, 11 mov cx, 11
repz cmpsb repz cmpsb
popa popa
jz sdone jz sdone
scont: scont:
add di, 0x20 add di, 0x20
loop sloop loop sloop
; next cluster ; next cluster
push 0x6000 push 0x6000
pop es pop es
push es ax push es ax
shr eax, 7 shr eax, 7
cmp eax, [bp-14] cmp eax, [bp-14]
mov [bp-14], eax mov [bp-14], eax
jz @f jz @f
add eax, [bp-6] add eax, [bp-6]
mov cx, 1 mov cx, 1
call read_sectors32 call read_sectors32
@@: @@:
pop di es pop di es
and di, 0x7F and di, 0x7F
shl di, 2 shl di, 2
and byte [es:di+3], 0x0F and byte [es:di+3], 0x0F
mov eax, [es:di] mov eax, [es:di]
;and eax, 0x0FFFFFFF ;and eax, 0x0FFFFFFF
cmp eax, 0x0FFFFFF7 cmp eax, 0x0FFFFFF7
jb lookup_in_dir jb lookup_in_dir
snotfound: snotfound:
stc stc
sdone: sdone:
ret ret
out_string: out_string:
; in: ds:si -> ASCIIZ string ; in: ds:si -> ASCIIZ string
lodsb lodsb
test al, al test al, al
jz sdone jz sdone
mov ah, 0Eh mov ah, 0Eh
mov bx, 7 mov bx, 7
int 10h int 10h
jmp out_string jmp out_string
aReadError db 'Read error',0 aReadError db 'Read error',0
if use_lba if use_lba
aNoLBA db 'The drive does not support LBA!',0 aNoLBA db 'The drive does not support LBA!',0
end if end if
aLoaderNotFound db 'Loader not found',0 aLoaderNotFound db 'Loader not found',0
aPressAnyKey db 13,10,'Press any key...',13,10,0 aPressAnyKey db 13,10,'Press any key...',13,10,0
main_loader db 'KORDLDR F32' main_loader db 'KORDLDR F32'
db 56h db 56h
; just to make file 512 bytes long :) ; just to make file 512 bytes long :)
db 'd' xor 'i' xor 'a' xor 'm' xor 'o' xor 'n' xor 'd' db 'd' xor 'i' xor 'a' xor 'm' xor 'o' xor 'n' xor 'd'
; bootsector signature ; bootsector signature
dw 0xAA55 dw 0xAA55
; display offsets of all procedures used by kordldr.f12.asm ; display offsets of all procedures used by kordldr.f12.asm
macro show [procedure] macro show [procedure]
{ {
bits = 16 bits = 16
display `procedure,' = ' display `procedure,' = '
repeat bits/4 repeat bits/4
d = '0' + procedure shr (bits - %*4) and 0Fh d = '0' + procedure shr (bits - %*4) and 0Fh
if d > '9' if d > '9'
d = d + 'A'-'9'-1 d = d + 'A'-'9'-1
end if end if
display d display d
end repeat end repeat
display 13,10 display 13,10
} }
show read_sectors32, read_sectors2, err, noloader show read_sectors32, read_sectors2, err_, noloader

View File

@ -0,0 +1,3 @@
@fasm -m 65535 bootsect.asm bootsect.bin
@fasm -m 65535 kordldr.f32.asm kordldr.f32
@pause

File diff suppressed because it is too large Load Diff