OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 9:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Bug in bootloader
PostPosted: Mon Jan 10, 2005 12:00 am 
Offline
Member
Member

Joined: Mon Oct 25, 2004 11:00 pm
Posts: 43
Location: Poland
I've got this code:

Code:


[bits 16]
[org 0]


jmp BootCode

BPB_OEM               db 'ADDIX   '
BPB_BytesPerSector    dw 512
BPB_SectorsPerCluster db 1
BPB_ReservedSectors   dw 1
BPB_FatsNum           db 2
BPB_RootEntries       dw 224
BPB_TotalSectors      dw 2880
BPB_MediaType         db 0f0h
BPB_SectorsPerFat     dw 9
BPB_SectorsPerTrack   dw 18
BPB_HeadsNum          dw 2
BPB_HiddenSectors     dd 0
BPB_TotelSectors32    dd 0
BPB_DriveNum          db 0
BPB_Reserved          db 0
BPB_BootSignature     db 0
BPB_VolumeID          dd 0bbbbddddh
BPB_VolumeLabel       db 'ADDIX      '
BPB_FileSystem        db 'FAT 12  '


BootCode:
cli
mov ax, 7c00h
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

mov [BPB_DriveNum], dl

mov ax, 0000h
mov ss, ax
mov sp, 0ffffh
sti

xor cx, cx
xor dx, dx
mov ax, 32
mul word[BPB_RootEntries]
div word[BPB_BytesPerSector]
xchg ax, cx

mov al, byte[BPB_FatsNum]
mul word[BPB_SectorsPerFat]
add ax, [BPB_ReservedSectors]

mov word[DataSector], ax
add word[DataSector], cx

mov bx, 0200h
call ReadSector


mov cx, [BPB_RootEntries]
mov di, 0200h

FindLoop:
push cx

mov cx, 11
mov si, FileName
push di
rep cmpsb

pop di
je LoadFAT
pop cx
add di, 32

loop FindLoop

jmp Failure


LoadFAT:
mov dx, word[di+1ah]
mov word[Cluster], dx

xor ax, ax
mov al, byte[BPB_FatsNum]
mul word[BPB_SectorsPerFat]
mov cx, ax

mov ax, word[BPB_ReservedSectors]
mov bx, 0200h
call ReadSector


mov ax, 1000h
mov es, ax
mov bx, 0000h
push bx

LoadFile:
mov ax, word[Cluster]
pop bx
call ClusterLBA
xor cx, cx
mov cl, byte[BPB_SectorsPerCluster]
call ReadSector
push bx

mov ax, word[Cluster]
mov cx, ax
mov dx, ax
shr dx, 0x0001
add cx, dx
mov bx, 0x0200
add bx, cx
mov dx, word[bx]
test ax, 0001
jnz LoadFile2
 
LoadFile1:
and dx, 0000111111111111b
jmp LoadFileDone

LoadFile2:
shr dx, 4

LoadFileDone:
mov word[Cluster], dx
cmp dx, 0x0ff0
jb LoadFile

Done:
mov ax, 1000h
mov es, ax
mov ds, ax
mov ss, ax
xor ax, ax
xor bx, bx
xor cx, cx
xor dx, dx
xor si, si
xor di, di
xor sp, sp
xor bp, bp
jmp 1000h:0000h

Halt:
jmp Halt

Failure:
mov si, MSG_Failure
call PrintString

mov ax, 0
int 16h

int 19h

PrintString:
lodsb
cmp al, 0
je PrintStringEnd

mov ah, 0Eh
mov bh, 0
int 10h      
jmp PrintString
PrintStringEnd:
ret

LBA_to_CHS:
xor dx, dx
div word[BPB_SectorsPerTrack]
inc dl
mov byte[AbsSector], dl

xor dx, dx
div word[BPB_HeadsNum]
mov byte[AbsHead], dl
mov byte[AbsTrack], al
ret

ClusterLBA:
sub ax, 2
xor cx, cx
mov cl, byte[BPB_SectorsPerCluster]
mul cx
add ax, word[DataSector]

ReadSector:
push ax
push bx
push cx

call LBA_to_CHS

mov ah, 02h
mov al, 01h
mov ch, byte[AbsTrack]
mov cl, byte[AbsSector]
mov dh, byte[AbsHead]
mov dl, byte[BPB_DriveNum]
int 13h

pop cx
pop bx
pop ax

add bx, word[BPB_BytesPerSector]
inc ax
loop ReadSector
ret


AbsSector  db 0
AbsHead    db 0
AbsTrack   db 0
DataSector dw 0
Cluster    dw 0

FileName    db 'ADDIX   SYS'
MSG_Welcome db 'AddixOS loader by Adix', 13,10,0
MSG_Loading db 'Ladowanie AddixOS...', 13,10,0
MSG_Failure db 'Blad! Nacisnij jakis klawisz...', 0

times 510-($-$$) db 0
dw 0aa55h


i'm compiling it without any errors in NASM. Rawrating on floppy, copying kernel and trying to boot in bochs. I don't know why it's don't working :/


Top
 Profile  
 
 Post subject: Re: Bug in bootloader
PostPosted: Mon Jan 10, 2005 12:00 am 
Offline
Member
Member
User avatar

Joined: Sat Oct 23, 2004 11:00 pm
Posts: 154
don't u think the ORG should be to 0x7c00.... Just try


Top
 Profile  
 
 Post subject: Re: Bug in bootloader
PostPosted: Tue Jan 11, 2005 12:00 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 24, 2004 11:00 pm
Posts: 127
Location: In my cube, like a good leming. ;-)
I can not tell from your post the size of a couple of the BPB items. These all need to be specific to the requirements BPB in order to be used correctly as a FAT file system. Unfortunately I don't have a reference handy here at work, but recheck OEM, Volume, and FileSystem for the correct string length. Also verify that your kernel name is 11 characters long (sorry, I can not tell the stringlength since you placed it in the text area, perhaps use the code markers [ code ] code here [ / code ] [<- remove spaces]).

Also, can you be more specific? What error or lack of errors are you getting. Does the boot code print out a failure message?

_________________
-smiddy


Last edited by smiddy on Tue Jan 11, 2005 12:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Bug in bootloader
PostPosted: Tue Jan 11, 2005 12:00 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 27, 2004 11:00 pm
Posts: 874
Location: WA
yes it looks like your OEMID is too short
also looks like your fileName might be too short (use the code tag to make it clearer)
also if your CS is not default to 0x07c90 then your initial jmp over the bpb will be wrong(this could be your problem)

change the
Code:
jmp BootCode


into
Code:
jmp short BootCode
NOP

_________________
## ---- ----- ------ Intel Manuals
OSdev wiki


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 233 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group