My first bootsector
-
- Posts: 8
- Joined: Tue Nov 08, 2011 4:51 am
My first bootsector
.code16 # tell it is a 16 bit code
.org 0x0 # where to load in memory
.globl _start
_start:
jmp _start # infinite loop
.fill 507,1,0 # syntax: .fill repeat,size,value
.word 0x55AA # add the signature.
# as bootsector.s -o bootsector.o
# ld -Ttext 0x7C00 -o bootsector bootsector.o --oformat binary --entry=0
Is that correct?
I am using dd bs=512 count=1 if=bootsector of=/dev/sdb1 to write it in my pendrive for tests.
.org 0x0 # where to load in memory
.globl _start
_start:
jmp _start # infinite loop
.fill 507,1,0 # syntax: .fill repeat,size,value
.word 0x55AA # add the signature.
# as bootsector.s -o bootsector.o
# ld -Ttext 0x7C00 -o bootsector bootsector.o --oformat binary --entry=0
Is that correct?
I am using dd bs=512 count=1 if=bootsector of=/dev/sdb1 to write it in my pendrive for tests.
Re: My first bootsector
Well, the boot sector also includes partitioning information, so I'd be careful with all those zeroes you .fill'ed there...
Every good solution is obvious once you've found it.
-
- Posts: 8
- Joined: Tue Nov 08, 2011 4:51 am
Re: My first bootsector
Do you mean that FAT16's stuff:Solar wrote:Well, the boot sector also includes partitioning information, so I'd be careful with all those zeroes you .fill'ed there...
bootsector:
iOEM: .ascii "DevOS "
iSectSize: .word 0x200
iClustSize: .byte 1
iResSect: .word 1
iFatCnt: .byte 2
iRootSize: .word 224
iTotalSect: .word 2880
iMedia: .byte 0xF0
iFatSize: .word 9
iTrackSect: .word 9
iHeadCnt: .word 2
iHiddenSect: .int 0
iSect32: .int 0
iBootDrive: .byte 0
iReserved: .byte 0
iBootSign: .byte 0x29
iVolID: .ascii "seri"
acVolumeLabel:
root_strt: .byte 0,0
root_scts: .byte 0,0
file_strt: .byte 0,0
file_scts: .byte 0,0
.byte 0,0
rs_fail:
.byte 0
acFSType: .ascii "FAT16"
could you help me to fix my code (not to do it all, just to help me the way...please?)?
Re: My first bootsector
No, that is Bios Parameter Block. Partition table is a different thing.maurolarrat wrote:Do you mean that FAT16's stuff:
You need to mention your problem.maurolarrat wrote:Could you help me to fix my code (not to do it all, just to help me the way...please?)?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
-
- Posts: 8
- Joined: Tue Nov 08, 2011 4:51 am
Re: My first bootsector
Are BPB well defined or can i define my own parameters for using in my 4 GB HD ?Chandra wrote:No, that is Bios Parameter Block. Partition table is a different thing.maurolarrat wrote:Do you mean that FAT16's stuff:You need to mention your problem.maurolarrat wrote:Could you help me to fix my code (not to do it all, just to help me the way...please?)?
I read here http://homepage.ntlworld.com/jonathan.d ... block.html , and it seemed to me that it was developed by MS...
my aim is to write a simple bootsector using GAS to test it im my 4GB pendrive.
Re: My first bootsector
Flash drive usually has two kinds of boot loaders: MBR boot loader and one partition boot loader for every existing partition. What kind of boot loader do you want to write?
If you have seen bad English in my words, tell me what's wrong, please.
Re: My first bootsector
Won't work. BIOS loads your code at 0:7c00, not 0:0. You must set up stack too, and except dl holds the boot drive code, assume nothing.maurolarrat wrote: .org 0x0 # where to load in memory
That's good if you want to write a volume boot record. You're writing it on the first sector of the first partition. If you want master boot record, use /dev/sdb.maurolarrat wrote: I am using dd bs=512 count=1 if=bootsector of=/dev/sdb1 to write it in my pendrive for tests.
Read for example this (first google result...), it has a disassembled example too.
http://www.dewassoc.com/kbase/hard_driv ... record.htm
Re: My first bootsector
Actually, it could be correct: 7C0h:0.turdus wrote:Won't work. BIOS loads your code at 0:7c00, not 0:0.maurolarrat wrote: .org 0x0 # where to load in memory
If you have seen bad English in my words, tell me what's wrong, please.
Re: My first bootsector
Actually no. Since linear=offs+segbase<<4,egos wrote:Actually, it could be correct: 7C0h:0.
0+7C0h<<4=7C00h,
7C00h+0<<4=7C00h
So theoretically both correct, but there are reasons why the latter preferred. It's easier to use segbase 0, requires fewer bytes to code, easier to debug etc. Original DOS bootsector code, the last DOS bootsector code, win95/98/ME bootsector code, and even win7 bootsector code uses 0:7C00h hence you're wrong, and I suggest to change that org.
Re: My first bootsector
I use a far-jump at the start of the boot-sector to make sure I'm in segment 7C0 and not 0, or something else. I only think it can be garanteed that BIOS/chain-loaders passes control to linear address 7C00, but not the context of segment registers.
Re: My first bootsector
Why would the latter be prefered? I prefer the first alternative, since then the boot-sector code will start at the correct offset (0), and there is no need to manipulate with orgs in order for the assembler to generate correct offsets.turdus wrote:Actually no. Since linear=offs+segbase<<4,egos wrote:Actually, it could be correct: 7C0h:0.
0+7C0h<<4=7C00h,
7C00h+0<<4=7C00h
So theoretically both correct, but there are reasons why the latter preferred. It's easier to use segbase 0, requires fewer bytes to code, easier to debug etc. Original DOS bootsector code, the last DOS bootsector code, win95/98/ME bootsector code, and even win7 bootsector code uses 0:7C00h hence you're wrong, and I suggest to change that org.
Re: My first bootsector
Of course it does. If you use a jmp far 7C0:something before you reference labels. The alternative .org 0x7C00 will not work if BIOS passes control to 7C0:0.turdus wrote:Won't work. BIOS loads your code at 0:7c00, not 0:0. You must set up stack too, and except dl holds the boot drive code, assume nothing.maurolarrat wrote: .org 0x0 # where to load in memory
Code: Select all
BootSectInit:
jmp StartBoot
nop
db 'Rdos '
BootMedia boot_struc <> ; BPB
StartBoot:
db 0EAh
dw OFFSET JmpBootCode
dw 07C0h
JmpBootCode:
Last edited by rdos on Wed Nov 09, 2011 4:00 am, edited 1 time in total.
Re: My first bootsector
Because all mainstream OS does. Sorry, no offense, but your hobby os' boot sector code is not mainstream per definitionem.rdos wrote:Why would the latter be prefered?
So it's more likely that segment registers left with value of zero than any other value; and as you pointed out you'll need a jump to be correct, a jump that OP's code lacks.rdos wrote:I only think it can be garanteed that BIOS/chain-loaders passes control to linear address 7C00, but not the context of segment registers.
Re: My first bootsector
What is most likely is of no interest. If both alternatives are possible, a far jmp will ALWAYS be needed regardless of which segment is prefered in order for the boot-loader to always work.turdus wrote: So it's more likely that segment registers left with value of zero than any other value; and as you pointed out you'll need a jump to be correct, a jump that OP's code lacks.
Re: My first bootsector
I beg your pardon, can you read?rdos wrote: What is most likely is of no interest. If both alternatives are possible, a far jmp will ALWAYS be needed regardless of which segment is prefered in order for the boot-loader to always work.
And, just because you pissed me off, I have to ask, how many of these use cs=7C0h and how many use cs=0:turdus wrote:as you pointed out you'll need a jump to be correct
Code: Select all
---original mbr---
7C18 EA1D060000 JMP 0000:061D
---windows mbr---
7C00 33C0 XOR AX,AX
7C10 BF1B06 MOV DI,061B
7C13 50 PUSH AX
7C14 57 PUSH DI
7C1A CB RETF
---win7 mbr---
7C00 33C0 XOR AX,AX
7C17 50 PUSH AX
7C18 681C06 PUSH 061C
7C1B CB RETF
---grub---
7C4B EA507C0000 JMP 0000:7C50
---msdos vbr---
7C00 EB3C JMP 7C3E
---windows vbr (mswin4.1)---
7C00 EB58 JMP 7C5A
---windows ntfs vbr (ntldr)---
7C00 EB52 JMP 7C54
Cheers