Page 1 of 2

HELP!!! My bootsector is WAY to big!!!

Posted: Mon Apr 05, 2004 11:00 pm
by Berry
Hello,

I've made a pretty bootsector. It does:

check if whe have a > 386
enable A20
load the kernel from the FAT
enter PMode
jump to the kernel code

but it's way to big: it gives me

D:\Program Files\OS\Berry's OS\boot>nasm boot.asm
boot.asm:466: error: TIMES value -145 is negative

so its 145 bytes TO BIG!!!

how can I make the bootsector smaller? I have only a minimal BPB and a few bytes strings... Is the only way to fix this a second stage????? I rather do it with 1 bootloader and the kernel...

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Mon Apr 05, 2004 11:00 pm
by ASHLEY4
You can do alot of the things you have done in your bootloader in your kernel .

ASHLEY4.

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Mon Apr 05, 2004 11:00 pm
by Berry
hmmm... Like? You mean entering PMode and anbeling A20? But I don't think that does slogg op 145 bytes... Anyways, I can try :) When I make a C kernel, where to do that things then? In the part (sort off glue, really) between the bootloader and the C code, I mean that bit assembly code that does something like this

[bits 32]

extern _main
call _main

cli
hlt

built it therein?

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Mon Apr 05, 2004 11:00 pm
by Chase
Most people go with a 2 stage bootload.
Basically your bootsector knows just enough to read another asm program and jump to it. The second stage is everything you wish you could fit in your boot sector.
Depending on your filesystem some people do the second stage as just a bunch of sectors after the boot sector while other people make it a file in the file system.

-Chase

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Mon Apr 05, 2004 11:00 pm
by ASHLEY4
Most people go for the 2d stage loader, I have gone for the put it in , what you would call the kernel, But my os is not like any other, it works on a kernel less OS.

PS: My os will be made in100% asm and the kernel is part of the program.
ASHLEY4.

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Mon Apr 05, 2004 11:00 pm
by Karig
The only things your boot sector really HAS to do are (1) set up stack and segment registers (so you can call BIOS routines without a problem) and (2) load the next part of your OS (usually the bootloader). Usually a boot sector will load a bootloader by loading a number of sectors, and the bootloader will have code that understands a file system and can load the rest of the OS by loading files.

If you just want to keep it simple for now, have your boot sector load a number of other sectors (usually the sectors immediately following the boot sector on the disk), and make sure the rest of your system is stored into those sectors.

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Tue Apr 06, 2004 11:00 pm
by common
That's an exokernel :)

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Tue Apr 06, 2004 11:00 pm
by Berry
But if I put my second stage in the sectors IMIDIADLY after the bootsector, it will overwrite the FAT's... Then the problem is my second stage can't load the kernel... So would it be better to let the bootloader load the second stage from the FAT? That's what I think...

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Tue Apr 06, 2004 11:00 pm
by DruG5t0r3
just remove the pmode part of the code...and once you load your file from the FAT...let that program do the pmode work

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Tue Apr 06, 2004 11:00 pm
by JAAman
IMHO you should always load your next  stage through a proper file FAT12 is really easy to implement within the bootsector and you only need enough to find the file in the root dir and follow its FAT chain but I would wait on  the Pmode&A20 and that will prob save you enough space but you may have to remove your386detect code

you could  also hard code some values like sectors/cluster(always one on FDD) or disk geometry calculations this takes less code space than loading these values from the BPB since you can just be sure its loaded only on 1.44FDDs and create a different boot sector if you want to support older disk types later

RE:HELP!!! My bootsector is WAY to big!!!

Posted: Tue Apr 06, 2004 11:00 pm
by Chase
Your second stage can be right after your boot sector without overwritting the FAT. In a FAT boot sector you can specify a reserved sector count. If you want an example of a boot sector that reads from fat12 all in under 512 bytes take a look at mine, http://www.osdev.org/drywell/snapshot/s ... 12boot.asm

-Chase

RE:HELP!!! My bootsector is WAY to big!!! Now have a second

Posted: Tue Apr 06, 2004 11:00 pm
by Berry
when I try to print something in my new bootsector, which only sets up ds like this:

mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax

and the stack, and then tries to load something from the fat, it just won't print... I use this:

print:
mov ah, 0x0e
mov bh, 0x00
mov bl, 0x07

.nextchar
lodsb

or al, al
jz .done

int 0x10
jmp .nextchar

.done
ret

I use the same thing, I only deleted the pmode and a20 enabler + 386 check...

RE:HELP!!! My bootsector is WAY to big!!! Now have a second

Posted: Tue Apr 06, 2004 11:00 pm
by JAAman
make sure SI is set correctly: and its not a good idea to set DS=CS unless you already set CS: CS is NOT always the same and one some systems it starts at 0 and others start at 7C00 and in theory some could start at other addresses(but I'm not  sure any do) so either set CS(with a full sector:offset JMP) or set DS=7C00(or 0000 just make sure your offset is corrected)

Oops:7C00=07C0

Posted: Tue Apr 06, 2004 11:00 pm
by JAAman
that should be "...others start at 07C0..."    and "...set DS=07C0..."
sorry
forgeting segment vs. linear addressing

thats what I get for typeing to fast!!!

RE:Oops:7C00=07C0

Posted: Wed Apr 07, 2004 11:00 pm
by Berry
could somebody please give an example of that? when I do this

mov ax, 0x7C0 ;zet ds op
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

it won't do anything (like printing text)
when I delete that part, it works fine... What's wrong with it?