If anybody can help, please do it, so:
that is my stage1 code:
Code: Select all
segment .text
org 0x7c00
Entry: jmp short real_start
nop
%define bsBytesPerSec bp+0x0b
%define bsSecPerClust bp+0x0d
%define bsResSectors bp+0x0e
%define bsFATs bp+0x10
%define sectPerTrack bp+0x18
%define xsectPerFat bp+0x24
%define xrootClst bp+0x2c
%define drive bp+0x40
%define data_start bp+0x4c
times 0x5a-$+$$ db 0
real_start: cld
cli
sub ax, ax
mov ds, ax
mov bp, 0x7c00
mov ax, 0x1FE0
mov es, ax
mov si, bp
mov di, bp
mov cx, 0x0100
rep movsw
jmp word 0x1FE0:cont
cont: mov ds, ax
mov ss, ax
lea sp, [bp-0x20]
sti
mov [drive], dl
mov si, msg_1
call print
mov ah, 0x41
mov bx, 0x55AA
mov dl, 0x80
int 0x13
jc short .err
mov eax, [xsectPerFat]
imul dword [bsFATs]
add ax, word [bsResSectors]
add ax, word 0x003F
mov [data_start], eax
mov eax, [data_start]
mov bx, 0x7E00
call readDisk
mov ax, 0x7E00
.nent:
mov cx, 11
mov si, filename
mov di, ax
repe cmpsb
jz .done
add ax, 0x20
jmp .nent
.done:
add ax, 0x1A
mov bx, word [eax]
xor eax, eax
mov ax, bx
mov [cur_cl], ax
call read_file
push dword 0x00000500
retf
cli
hlt
.err:
mov si, msg_2
call print
cli
hlt
;eax - cluster number (in)
;eax - sector number (out)
convert_cl:
cmp eax, 0x0ffffff8
jnb end_of_chain
dec eax
dec eax
imul byte [bsSecPerClust]
add eax, [data_start]
ret
end_of_chain: stc
ret
cur_cl dd 0
next_cl dd 0
read_file:
; load FAT sector (just one)
mov bx, 0x300
xor eax, eax
mov ax, [bsResSectors]
add ax, 0x3F
call readDisk
mov bx, 0x500
.read:
mov eax, [cur_cl]
call convert_cl
jc .succ
call readCluster
mov eax, dword 4
imul dword [cur_cl]
add eax, 0x300
xor edx, edx
mov edx, [eax]
mov [cur_cl], edx
call .read
.succ:
ret
;eax - sector number
;bx - address
readCluster:
mov cl, byte [bsSecPerClust]
.read:
call readDisk
dec cl
cmp cl, 0
jne .read
ret
readDisk: push dx
push si
push di
read_next: push eax
mov di, sp
push byte 0
push byte 0
push eax
push es
push bx
push byte 1
push byte 16
mov si, sp
mov dl, [drive]
mov ah, 42h
int 0x13
mov sp, di
pop eax
jnc read_ok
push ax
xor ah, ah
int 0x13
pop ax
jmp read_next
read_ok: inc eax
add bx, word [bsBytesPerSec]
jnc no_incr_es
mov dx, es
add dh, 0x10
mov es, dx
no_incr_es: pop di
pop si
pop dx
ret
printchar: xor bx, bx
mov ah, 0x0e
int 0x10
print: lodsb
cmp al, 0
jne printchar
ret
msg_1 db "SYOS is starting...",0
msg_2 db "Error while loading stage 2 bootloader", 0x0D, 0x0A
times 0x01F1-$+$$ db 0
filename db "KRNLDR SYS"
sign dw 0, 0xAA55
My second stage for this moment looks like this:
Code: Select all
org 0x500
bits 16
jmp entry
msg_1 db "Stage 2 started...", 0x0d, 0x0a, 0x00
entry:
cli
xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0xFFFF
sti
mov si, msg_1
call print
cli
hlt
printchar: xor bx, bx
mov ah, 0x0e
int 0x10
print: lodsb
cmp al, 0
jne printchar
ret
Thanks great, Daniel.