Page 2 of 3
Re: My first bootsector
Posted: Wed Nov 09, 2011 4:38 am
by Chandra
Turdus, will you please stop spreading the misconception? To remind you, the original code the OP posted doesn't do anything at all. There's only short jmp. So even without setting up proper CS that code would just work fine
(given that the whole code is intended as a loop).
turdus wrote:egos wrote:Actually, it could be correct: 7C0h:0.
Actually no. Since linear=offs+segbase<<4,
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.
You're surprisingly mistaken. If you setup CS:IP to point to the beginning of your code, your code works just fine. Even if you use something like ORG 0x9FFF where your code is not intended to run, your code works just fine as long as you subtract the correct offset from all relative addressing. This includes tweaking the far jmp too.
RDOS is correct. I'd suggest you to try some
real mode Postition Independent Code.
Re: My first bootsector
Posted: Wed Nov 09, 2011 5:05 am
by turdus
Dear Chandra,
I'm not mistaken, I know what I'm saying, and yes, I agree with rdos that you'll need a far jump to be correct even on buggy bioses. The discussion was about which cs base is preferred, and rdos is wrong about that. You can use any org you want, that's for sure, but it does not make it a preferred one. Hope it's clear, since I do not want to spend more time on this, it hardly helps the OP.
Re: My first bootsector
Posted: Wed Nov 09, 2011 5:11 am
by Chandra
turdus wrote:Dear Chandra,
I'm not mistaken, I know what I'm saying, and yes, I agree with rdos that you'll need a far jump to be correct even on buggy bioses. The discussion was about which cs base is preferred, and rdos is wrong about that. You can use any org you want, that's for sure, but it does not make it a preferred one. Hope it's clear, since I do not want to spend more time on this, it hardly helps the OP.
Yeah, lets end it here.
Re: My first bootsector
Posted: Wed Nov 09, 2011 11:05 am
by rdos
When I talked about preference, I meant which preference the boot-sector itself would want to have. As long as there is a far jmp in the beginning, it doesn't matter if the code uses segment 7c0 or 0. It's only a preference of the coder.
Re: My first bootsector
Posted: Wed Nov 09, 2011 5:08 pm
by egos
turdus wrote:Because all mainstream OS does. Sorry, no offense, but your hobby os' boot sector code is not mainstream per definitionem.
You found very serious theme for discussion
Who did say about what way is right and why? "Can you read?" I spoke only about possibility to use
org 0 because you took attention on this thing around empty space. I use
org 7C00h in all my bootloaders including ISO bootloader where we have CS:IP=7C0h:0 in entry point in most cases. Moreover I use far jump to 0:@f (though in general it is not required; setting for data segment registers is enough in most cases) because I use ip register to transfer some parameter to specific subroutines. But as I said I know about possibility to use
org 0. And what about you?
Re: My first bootsector
Posted: Thu Nov 10, 2011 1:33 am
by bitshifter
In certain cases i will use seg=0 so i can screw with the RM-IVT without any extra fuss.
Since the BS code is small we never need the full offset anyway.
I would use whichever gives the smallest result for the goal at hand.
Also i would do short jump over the BPB then far jump to purge CS reg.
Re: My first bootsector
Posted: Fri Nov 11, 2011 5:16 am
by maurolarrat
ok,
i have formated my USB FLASH drive (4GB) as FAT16 and i wrote (and compiled normaly) this code below in it, using dd in Windows 7.
command: dd bs=512 if=boot.bin of=\\.\F:
Code: Select all
org 0x7c00
bits 16
start: jmp loader
;*************************************************;
; OEM Parameter block
;*************************************************;
bpbOEM db "MYOS123 " ;
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 "FAT16 "
msg db "Welcome to My Operating System!", 0 ; the string to print
Print:
lodsb
or al, al ; al=current character
jz PrintDone ; null terminator found
mov ah, 0eh ; get next character
int 10h
jmp Print
PrintDone:
ret
loader:
xor ax, ax
mov ds, ax
mov es, ax
mov si, msg
call Print
cli ; Clear all Interrupts
hlt ; halt the system
times 510 - ($-$$) db 0 ; .Clear the rest of the bytes with 0
dw 0xAA55 ; Boot Signiture
my PENDRIVE turned to 1,30MB (like a FLOPPY disk) in a FAT16 format (lol). When i reboot from this pendrive, it seems to appear that "msg" faster and after (i am not sure), the message like "could not load a OS".
some hint about how could i fill the parameter block to fit those informations it in my 4GB FAT32 (not fat16)?
why the hlt command dont halt the system with "msg"?
thanks.
Re: My first bootsector
Posted: Fri Nov 11, 2011 7:45 am
by egos
maurolarrat wrote:my PENDRIVE turned to 1,30MB (like a FLOPPY disk) in a FAT16 format (lol).
Well, that's exactly what we expected. Why do you rewrite bpb* fields?
When i reboot from this pendrive, it seems to appear that "msg" faster and after (i am not sure), the message like "could not load a OS".
Take some example boot loader and learn it. The hint:
Code: Select all
org 7C00h
jmp SHORT @f
NOP
rb BS_SIZE-3
@@:
xor ax,ax
cli
mov ss,ax
mov sp,$$
sti
mov ds,ax
cld ; for lods
; and so on
And you didn't answer for my question.
some hint about how could i fill the parameter block to fit those informations it in my 4GB FAT32 (not fat16)?
Don't fill it at all. Keep the original values. Look at "FAT32 File System Specification" for FAT32 BS format.
Re: My first bootsector
Posted: Fri Nov 11, 2011 7:57 am
by maurolarrat
egos wrote: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?
Answer|: MBR bootloader .
Why cant I rewrite the Partition Table? Is it sufficient to do a bootloader using the pre formated FAT32 information? I thought i need to create a Partition table from the ground up.
thanks.
Re: My first bootsector
Posted: Fri Nov 11, 2011 8:11 am
by egos
MBR doesn't have FS structures such as BPB. You can rewrite only MBR boot code (first 440 bytes) keeping disk signature, partition table and boot signature.
Re: My first bootsector
Posted: Fri Nov 11, 2011 8:17 am
by maurolarrat
egos wrote:MBR doesn't have FS structures such as BPB. You can rewrite only MBR boot code (first 440 bytes) keeping disk signature, partition table and boot signature.
ok, what about i want to do another one (not MBR)?
if i have a new FS structure developed, is it possible to include it in BPT?
Re: My first bootsector
Posted: Fri Nov 11, 2011 9:42 am
by Solar
maurolarrat wrote:if i have a new FS structure developed...
Generic advice: Be sure you can walk safely before you try to run.
Re: My first bootsector
Posted: Sat Nov 12, 2011 6:41 am
by maurolarrat
I do not want advices, I want solutions.
Re: My first bootsector
Posted: Sat Nov 12, 2011 7:08 am
by Chandra
In your case, Advice is the Solution.
Re: My first bootsector
Posted: Sat Nov 12, 2011 8:15 pm
by Kazinsal
maurolarrat wrote:I do not want advices, I want solutions.
I think that's probably the root of your problem. We're not here to write your code for you - we're here to help you on your way to creating your own solutions to problems.
(This probably sounds weird to everyone who's been here forever compared to this relative newbie.)