Problem with bootloader

If you are new to OS Development, plan on spending some time here first before going into the other forums.

Moderator:Moderators

Post Reply
afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm
Problem with bootloader

Post by afdgdhfrtewdszs » Tue Feb 08, 2011 11:57 am

What is the problem with the following bootloader?


bits 16
org 0x7C00

start: jmp main


TIMES 0Bh-$+start DB 0

bpbBytesPerSector: DW 512
bpbSectorsPerCluster: DB 1
bpbReservedSectors: DW 1
bpbNumberOfFATs: DB 2
bpbRootEntries: DW 224
bpbTotalSectors: DW 2880
bpbMedia: DB 0xF0
bpbSectorsPerFAT: DW 9
bpbSectorsPerTrack: DW 18
bpbHeadsPerCylinder: DW 2
bpbHiddenSectors: DD 0
bpbTotalSectorsBig: DD 0
bsDriveNumber: DB 0
bsUnused: DB 0
bsExtBootSignature: DB 0x29
bsSerialNumber: DD 0xa0a1a2a3
bsVolumeLabel: DB "MOS FLOPPY "
bsFileSystem: DB "FAT12 "


main:

push cs
pop ds
push cs
pop es

xor ax,ax
xor bx,bx
xor cx,cx


; reset floppy
mov ah,0
mov dl,0
int 0x13

;------------------------------------------
; load root directory at 7c00:0200
;------------------------------------------
mov bx,0x0200
mov ah,0x02
mov al,14 ; (224 * 32) / 512
mov ch,0 ; track = (((9+9+1) / 18) / 2)
mov cl,2 ; sector = 19 % 18 + 1
mov dh,1 ; head = (19 / 18) % 2
mov dl,0
int 0x13

;-----------------------------------
; find file
;-----------------------------------
findfl_start:
mov di,0x0200
mov si,filename
mov cx,224
.LOOP:
push cx
mov cx,11
rep cmpsb
je LOAD_FAT
pop cx
add di,32
loop .LOOP

;--------------------------------------
;Load FAT
;--------------------------------------
LOAD_FAT:
mov ax, WORD [di + 26]
mov WORD [cluster],ax

mov bx,0x0200
mov ah,0x02
mov al,9
mov ch,0 ; track = ((1 / 18) / 2)
mov cl,2 ; sector = 1 % 18 + 1
mov dh,1 ; head = (1 / 18) % 2
mov dl,0
int 0x13

;------------------------------------
;Load file
;------------------------------------
mov ax,0x0050
mov es,ax
xor bx,bx

LOAD_FILE:
mov ax, WORD [cluster]
add ax,31

xor dx,dx
mov di,18
div di
mov cl,dl
add cl,1 ; cl = sector = (logical % 18 + 1)
mov dx,0
mov di,2
div di
mov ch, al ; ch = track = ((logical / 18) / 2)
mov dh, dl ; dh = head = ((logical / 18) % 2)

mov ah,0x02
mov al,1
mov dl,0
int 0x13

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,0x0001
jnz .ODD_CLUSTER

.EVEN_CLUSTER:
and dx, 0000111111111111b
jmp .DONE

.ODD_CLUSTER:
shr dx,0x0004

.DONE:
mov WORD [cluster],dx
cmp dx,0x0FF0
jb LOAD_FILE


filename db "KRNLDR SYS",0
cluster dw 0x0000


times 510-($-$$) db 0

dw 0XAA55

Andyhhp
Moderator
Posts:387
Joined:Tue Oct 23, 2007 10:05 am
Location:127.0.0.1
Contact:

Re: Problem with bootloader

Post by Andyhhp » Tue Feb 08, 2011 6:55 pm

That completely depends on your definition of 'problem'

What it is not doing which you think it should be doing?

~Andrew
Image

accelleon
Posts:15
Joined:Mon Dec 07, 2009 3:41 am

Re: Problem with bootloader

Post by accelleon » Tue Feb 08, 2011 9:36 pm

if your using NASM for your assembler this will be a problem:

Code: Select all

TIMES 0Bh-$+start DB 0
also if im correct $ does not output a pure number and as such cant be used on its own

its obvious you copied the

Code: Select all

TIMES 510-($-$$) db 0
line without fully understanding how it works in NASM

i suggest instead of using the TIMES directive you just place

Code: Select all

bpbOEMName db "MSWIN4.1"
or

Code: Select all

bpbOEMName db "        "
and yes andrew is right, we need more information about what its doing currently and what its supposed to be doing ;P

afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm

Re: Problem with bootloader

Post by afdgdhfrtewdszs » Wed Feb 09, 2011 11:38 am

The problem is that it doesn't load and execute stage 2 bootloader.

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Problem with bootloader

Post by Mike » Wed Feb 09, 2011 7:40 pm

Hello,

Please add the bpbOEMName change as noted above. In addition replace start: jmp main with the following:

Code: Select all

start: jmp short main
nop
Newer versions of NASM will assemble this instruction differently, which can cause the BPB to start at a wrong offset. The above fixes this.

Code: Select all

filename db "KRNLDR SYS",0
This is incorrect. Filenames are padded to 11 bytes (8.3) not null terminated, so should be "KRNLDR SYS". In a similar way, bsFileSystem is wrong - it should be padded to 8 bytes (with spaces at the end). If your original code has this, please disregard.

If problems persists, please provide more detail. Also note the bochs debugger and crash log can help with resolving the issue.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm

Re: Problem with bootloader

Post by afdgdhfrtewdszs » Wed Feb 09, 2011 10:13 pm

Problem not fixed yet.

GhostXoP_Development
Posts:4
Joined:Mon Jun 21, 2010 12:23 am

Re: Problem with bootloader

Post by GhostXoP_Development » Thu Feb 10, 2011 2:43 am

Image

Post in following format:

Is problem still persisting IF so {
Post details on program failure
};

If constant_spoon_Feeding_request {
Post_Format_Invaild_Message(http://t0.gstatic.com/images?q=tbn:ANd9 ... O1aI-Q&t=1);
};
GhostXoP Head Software Engineer of the VolTroX Concept Engine Project

User avatar
Mike
Site Admin
Posts:465
Joined:Sat Oct 20, 2007 7:58 pm
Contact:

Re: Problem with bootloader

Post by Mike » Thu Feb 10, 2011 2:55 am

Hello,

You really need to start providing information - this has been requested three times (now four).

What debugging steps have you already performed? If none, why not?
Does the file ever get found?
How do you assemble and copy the programs to disk?

Your bochs crash log (if using bochs) can also help provide some information that might isolate any possible issues.

*Edit: I have tested the software. It appears to be finding the file correctly but failing with calculating the correct CHS. Due to a lack of time however I will not be able to look more into the issue until tomorrow. Please note that I have made the above modifications prior to testing.
Lead Programmer for BrokenThorn Entertainment, Co.
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com

afdgdhfrtewdszs
Posts:18
Joined:Tue Feb 01, 2011 6:25 pm

Re: Problem with bootloader

Post by afdgdhfrtewdszs » Thu Feb 10, 2011 3:43 pm

Thank you very much for your time.I didn't provide more information because i didn't use Bochs (instead i 'm using VirtualBox).I installed it and boot from the floppy (the one where the boot loader and and second stage file are locatedn) but Bochs just hung up without even printing any info in the log file or the console window.

Post Reply