Problem with bootloader
Moderator:Moderators
-
- Posts:18
- Joined:Tue Feb 01, 2011 6:25 pm
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
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
Re: Problem with bootloader
That completely depends on your definition of 'problem'
What it is not doing which you think it should be doing?
~Andrew
What it is not doing which you think it should be doing?
~Andrew

Re: Problem with bootloader
if your using NASM for your assembler this will be a problem:
also if im correct $ does not output a pure number and as such cant be used on its own
its obvious you copied the
line without fully understanding how it works in NASM
i suggest instead of using the TIMES directive you just place
or
and yes andrew is right, we need more information about what its doing currently and what its supposed to be doing ;P
Code: Select all
TIMES 0Bh-$+start DB 0
its obvious you copied the
Code: Select all
TIMES 510-($-$$) db 0
i suggest instead of using the TIMES directive you just place
Code: Select all
bpbOEMName db "MSWIN4.1"
Code: Select all
bpbOEMName db " "
-
- Posts:18
- Joined:Tue Feb 01, 2011 6:25 pm
Re: Problem with bootloader
The problem is that it doesn't load and execute stage 2 bootloader.
Re: Problem with bootloader
Hello,
Please add the bpbOEMName change as noted above. In addition replace start: jmp main with the following:Newer versions of NASM will assemble this instruction differently, which can cause the BPB to start at a wrong offset. The above fixes this.
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.
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
Code: Select all
filename db "KRNLDR SYS",0
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
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
-
- Posts:18
- Joined:Tue Feb 01, 2011 6:25 pm
Re: Problem with bootloader
Problem not fixed yet.
-
- Posts:4
- Joined:Mon Jun 21, 2010 12:23 am
Re: Problem with bootloader
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
Re: Problem with bootloader
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.
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
Website: http://www.brokenthorn.com
Email: webmaster@brokenthorn.com
-
- Posts:18
- Joined:Tue Feb 01, 2011 6:25 pm
Re: Problem with bootloader
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.