Bootloader Rebuild

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Bootloader Rebuild

Post by VolTeK »

I have gone through and fixed all i can, data errors dma errors (09h from what i recall) but it still cannot find my file. i have decided to show a dot for every time it loads a root directory sector i have it display a dot to make sure its loading correctly. and i have a screen shot.

Image

Every dot printed plus 1 is how many times it is loading a sector of the root directory to its destination (0x0200).

Any suggestions?


Fasm Assembly Code

Code: Select all

;vboot 1.0 build 0001
use16
org 0x0 
jmp start_boot

;;;;Bios Parameter Block;;;;
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 "VolTroXDisk"
bsFileSystem db "FAT12   "

filename db "VTXLDR  EXE"

startingcluster dw 0



fatoffset = (startingcluster + (startingcluster / 2))
locationof_rootdirectory = (2 * bpbSectorsPerFAT + bpbReservedSectors + 1)
sizeof_rootdirectory = (bpbRootEntries * 32 / bpbBytesPerSector)
sizeof_fats = (bpbNumberOfFATs * bpbSectorsPerFAT)
locationof_fats = (bpbReservedSectors + 1)
sectorlba = ( 33 + startingcluster - 2)
absoluteSector db 0
absoluteHead db 0
absoluteTrack db 0
fileloadaddress dw 0x1000
currentaddressofFAT dw 0
fcounter db 0


LBACHS:
          xor     dx, dx                              ; prepare dx:ax for operation
          div     WORD [bpbSectorsPerTrack]           ; divide by sectors per track
          inc     dl                                  ; add 1 (obsolute sector formula)
          mov     BYTE [absoluteSector], dl
 
; these forumlas are very simular...
 
          xor     dx, dx                              ; prepare dx:ax for operation
          div     WORD [bpbHeadsPerCylinder]          ; mod by number of heads (Absolue head formula)
          mov     BYTE [absoluteHead], dl             ; everything else was already done from the first formula
 
          mov     BYTE [absoluteTrack], al            ; not much else to do :)
          ret


print:
push ax
mov ah, 0eh
cont_print:
lodsb
cmp al, 0
je .done
int 10h
jmp cont_print
.done:
pop ax
ret

putletter:
mov ah, 0eh
int 10h
cli
hlt


read_sector: ;;ch cylinder number, dh head number,  [al number of sectors to read], cl sector number


mov al, 1
mov ah,0
mov dl,0
int 13h
cmp ah, 0
jne ferrorh
mov ah, 02h
int 13h
;cmp ah, 00h
;jne ferrorh
ret
ferrorh:
cmp [fcounter], 3
je ferror
add [fcounter], 1
jmp read_sector


ferror:
mov si, derr
call print
cli
hlt


derr db "HARDWARE FAILURE: |FLOPPY DRIVE|, PLEASE RESTART",0


file_not_found:
mov si, fnf
call print
cli
hlt
fnf db "LOADX WAS NOT FOUND, PLEASE RESTART",0

sord db 0
lord db 0
alrd dw 0







start_boot:
mov ax, 7c0h
mov es,ax
mov ds,ax
mov ss,ax
mov sp, 0


;;test
load_root:
mov al, [sizeof_rootdirectory]
mov cl, [locationof_rootdirectory]
mov bx, 0x0200
first_loadr:
mov [sord], al
mov [lord], cl
mov [alrd], bx
call read_sector
dec [sord]
cmp [sord], 0
je done_lrd
cont_ldrt:
push ax
mov al, '.'
mov ah, 0eh
int 10h
pop ax
inc [lord]
add [alrd], 512
mov cl, [lord] ;sector to load
mov bx, [alrd]
call read_sector
dec [sord]
cmp [sord], 0
je done_lrd
jmp cont_ldrt
done_lrd:

mov cx, [bpbRootEntries] ;how many entries we will go through
mov di, 0x0200 ;di contains address of correct entry
browsefat:
push cx ;Save root entry number
mov cx, 11 ;Size of name
mov si, filename
push di ;Dont increment the correct addres
rep cmpsb ;Check every letter inc'ing di, but we saved the address of the entry
pop di ;di contains entry address
je load_fat ;Match
pop cx; cx contains number of entries left
cmp cx, 0
je file_not_found
add di, 32 ;root address plus 32 (next entry)
sub cx, 1
jmp browsefat

load_fat:
mov dx, [di + 26] ;di contains the address to the entry. plus 26 is the starting cluster number
;;dx contains starting cluster number
mov cl, [sizeof_fats]
mov al, [locationof_fats]
mov bx, 0x0200
call read_sector

mov WORD [startingcluster], dx


load_image:
mov ax, [startingcluster]
call LBACHS
mov ch, [absoluteTrack]
mov cl, [absoluteSector]
mov dh, [absoluteHead]
mov al, 1
mov bx, [fileloadaddress]
call read_sector

mov bx, 0x0200 ;location of fats atm
add bx, [fatoffset] ;now bx contains fatoffset
mov [currentaddressofFAT], bx

loop_read_image:
add [fileloadaddress], 512

mov ax, WORD [currentaddressofFAT]
mov cx, ax
mov dx, ax  ;DX and CX contain cluster
shr dx, 0x0001
add cx, dx ;Add modified dx, with current cx, cx is now modified
mov bx, 0x0200 ;moves word at location of fat's into 0x200
add bx, cx
mov dx, WORD [bx] ;Moves word into word register

test ax, 0x0001 ;Test bit tp check for odd, if not zero, its odd
jnz odd_cluster
and dx, 0000111111111111b
jmp done_cluster

odd_cluster:

shr dx, 0x0004

done_cluster:
mov WORD [currentaddressofFAT], dx
cmp dx, 0x0ff0
jb loop_read_image

jmp 0x1000 ;?



TIMES 510-($-$$) DB 0
DW 0xAA55























;;;;




Hopefully This may help ?


Ive made the size bigger to help any that may want to look at my code, Thank you

[Edit by quok] And I've fixed it so the size is normal. Please don't do that again.
Last edited by quok on Mon Sep 06, 2010 7:39 am, edited 1 time in total.
Reason: Got rid of stupid [size=150]...[/size] tags
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader Rebuild

Post by VolTeK »

Sorry if the code is messy, the bootloader is high in priority but low overall, since i may not be looking at it much i dont see a need to better organize. Tho from the kernel up there will be alot of organization
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bootloader Rebuild

Post by Combuster »

Ive made the size bigger to help any that may want to look at my code.
Apparently you never heard of CTRL-NUMPAD+. Don't be silly, all you achieved is that it looks like shouting now.
i have decided to show a dot for every time it loads a root directory sector i have it display a dot to make sure its loading correctly
And then you should have seen the number of dots is completely off (there are exactly 255 = 0xff of them!). Not 224 for the number of entries, let alone 7 for the actual number of sectors (which should be the correct number of dots to show).

I suggest you start with putting the BPB at the right offset if you want your tools to cooperate.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader Rebuild

Post by VolTeK »

Thank you for your smart @$$ help, ill be sure to look into it

Your so very selfish? I enlarged the text so it wouldnt be so bad on peoples eyes but i remember your the kind of person who complains about everything you can find, well you arent 'house' sorry.. As i say again and again, i will change it up this time, your attitude gets one everyones nerves.

But thanks anyway for a response, this should help much :)
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Bootloader Rebuild

Post by Solar »

@ GhostXoPCorp:

Factually he's right. Both on the netiquette thing and in his technical observation (AFAICT).

Putting something in boldface or larger font is generally considered equivalent to shouting. If somebody has problems with his eyesight, he can adjust font sizes locally.

As for how Combuster phrased it... well, he's short-tempered and a little bit pi**ed because things like post formatting shouldn't have to be addressed in a "professionals" board like this. Do you think giving him lip will make him calmer next time?
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bootloader Rebuild

Post by Combuster »

GhostXoPCorp wrote:Well you arent 'house' sorry..
Of course not, I don't go over (nearly) dead bodies.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader Rebuild

Post by VolTeK »

Bytes from bits? your kidding right.



I know my computer science, Ive read Intel manuals, and lots over protected mode development, and yes, ive used a debugger before.

How in the hell do you make that assumption from a bootloader. Thats why i dont show respect. I give it to all who deserve it, this isnt one of my fighting classes where your a grand master. You coded something. and your making an @$$ of both of us with your short minded assumptions, maybe your thinking i was like you in your earlier times? Well i can tell you that i have done everything you said i havent. Im not like you when you first started
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

Re: Bootloader Rebuild

Post by fronty »

GhostXoPCorp wrote:How in the hell do you make that assumption from a bootloader. -- Im not like you when you first started
How in the hell do you make that assumption from ... err ... nothing?

I don't understand where you suddenly got this thing going. He just told you that your action is against netiquette (man I hate that word) and noted you about technical shortcomings of your code in a way I think is completelu appropriate.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader Rebuild

Post by VolTeK »

true, i am over reacting. Not to combuster, but to all others
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Bootloader Rebuild

Post by Candy »

GhostXoPCorp wrote:Thank you for your smart @$$ help, ill be sure to look into it

Your so very selfish? I enlarged the text so it wouldnt be so bad on peoples eyes but i remember your the kind of person who complains about everything you can find, well you arent 'house' sorry.. As i say again and again, i will change it up this time, your attitude gets one everyones nerves.
He's right. You may assume that the default font on the forum is right for everybody. If you think otherwise, tell Chase and (if he agrees) he'll fix it. Given that some 5000 forum members before you didn't complain, it's unlikely.

Using a bigger font, colors and capitals are all ways of attracting attention in the way that annoys lots of people. The general idea on the internet, and especially on this forum, is to not annoy other people. Don't be surprised if people react annoyed when you do use one (or more) of those options. I recall fixing up a post of yours that was barely readable due to use of colors.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader Rebuild

Post by VolTeK »

Im sorry, i have eye trouble sometimes trying to read or focus and it starts to hurt my eyes, and i know it would be better without havign to hit any keys, to be in a bigger font and less eye straining to read, but i will know better for the future
User avatar
Candy
Member
Member
Posts: 3883
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re: Bootloader Rebuild

Post by Candy »

GhostXoPCorp wrote:Im sorry, i have eye trouble sometimes trying to read or focus and it starts to hurt my eyes, and i know it would be better without havign to hit any keys, to be in a bigger font and less eye straining to read, but i will know better for the future
You can (and should!) fix that in your OS settings. Making your text larger isn't going to help with any other text typed; making everything bigger will.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Bootloader Rebuild

Post by gerryg400 »

Code: Select all

locationof_rootdirectory = (2 * bpbSectorsPerFAT + bpbReservedSectors + 1)
The root directory starts after the reaserved sectors and FAT sectors. So shouldn't it be

Code: Select all

locationof_rootdirectory = (bpbNumberOfFATs * bpbSectorsPerFAT + bpbReservedSectors)
I think you're off by one sector. Or have I forgotten something ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Bootloader Rebuild

Post by VolTeK »

Theres a good chance your correct, atm ive determined all of the equations return 0 (idk why fasm does this) so i have to hard code them all, and am done. That maybe the problem but if this doesnt work il experiment with your equation
User avatar
Solar
Member
Member
Posts: 7635
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Bootloader Rebuild

Post by Solar »

GhostXoPCorp wrote:...atm ive determined all of the equations return 0 (idk why fasm does this) so i have to hard code them all...
That's a workaround, not a solution. And if you don't know why the tool of your choice reacts in the way you expected, find out why.
Every good solution is obvious once you've found it.
Post Reply