Page 2 of 3
Re:STARTING A NEW OS (Operating System)
Posted: Wed Oct 16, 2002 3:01 pm
by Tom
I can %100 HAD TO MAKE my OWN boot secot

because everything EVERYTHING rebooted my computer. I also had probs with my bootsector to, because it's hard to make it. Frank helped, I have it working, and now I make mods to my bootsector and works fine everytime.
Bootsectors are hard, but if you make your own, with help, you can know all about your bootsector.
Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 12:34 am
by Berserk
Ok, here are some questions before i start learning assembler.
What does a bootsector contain??
It loads a kernel, what does a kernel do??
what file format is the bootsector in??
how does the BIOS know that that file is the bootsector??
how do i load the bootsector to boot off a floppy??
Please help me out:D
Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 2:06 am
by grey wolf
Berserk wrote:
Ok, here are some questions before i start learning assembler.
What does a bootsector contain??
it is the first code executed after BIOS finishes its boot-up. the bootsector is exactly 512 bytes long, with the last two bytes 0x55 and 0xAA, which leaves 510 bytes of code that loads the kernel from the disk (either by using the file system or by loading the next sector).
It loads a kernel, what does a kernel do??
the kernel does everything an OS is responsible for: memory management, process management, thread management, device management and communication, etc.
what file format is the bootsector in??
the bootsector is not a file. it is the first sector of the disk or partition and ends with the boot sector signature (0x55, 0xAA) as i said above.
how does the BIOS know that that file is the bootsector??
the signature.
how do i load the bootsector to boot off a floppy??
the BIOS does this for you.
Please help me out:D
any questions?
Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 2:23 am
by Berserk
how do i put the signature on a bootsector, and if a bootsector is not a file, what the hell is it??
i've seen bootsector files before, they just look like a normal file, but with no extension? how do i compile a boot sector ASM file with NASM?
and can the bootsector file be called anything i like??
or does it have a specific name like "boot"??
I have other questions, but first i want to learn the basics. I'll ask the questions later, so please if a moderator is reading this, please don't delete this topic, if i do not reply in a long time (a week or more) please don't think that i have given up or gone.....i will probably have gone to learn something or write some code before moving on and asking more questions ;D
ciao

Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 2:29 am
by grey wolf
Berserk wrote:
how do i put the signature on a bootsector, and if a bootsector is not a file, what the hell is it??
it is what the name implies: a sector.
i've seen bootsector files before, they just look like a normal file, but with no extension? how do i compile a boot sector ASM file with NASM?
you compile a boot sector just like you would any other assembly code. the output file must be a flat binary file and then must be written to the first sector of a floppy. one way is to use MS debug to write the file to the first sector, or you can create an image file with your bootsector code filling the first 512 bytes of the image
and can the bootsector file be called anything i like??
or does it have a specific name like "boot"??
it has no name, since it is the first sector of the disk.
I have other questions, but first i want to learn the basics. I'll ask the questions later, so please if a moderator is reading this, please don't delete this topic, if i do not reply in a long time (a week or more) please don't think that i have given up or gone.....i will probably have gone to learn something or write some code before moving on and asking more questions ;D
ciao
i'm willing to answer your questions one by one if i have to
to clarify on one point: when you write the boot sector, it's a good idea to put this at the very end of the code you write:
Code: Select all
padding times (510 - $) db 0
bootsig db 0x55, 0xAA
what this does is add null bytes to the end of your code until it reaches the end of the sector where it adds 0x55 and 0xAA, which act as the boot signature that the BIOS looks for. without it, BIOS will say that there is no boot sector on the disk.
Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 3:13 am
by Berserk
what is a simple frame for a boot sector??
i mean i need something to build on ;D
an example of a frame in C++ is:
Code: Select all
int main(int arg, char* args[])
{
return 0;
}
i know that a bootsector is not in C++ i am just using it to show what i mean by frame
i need something to build on.
please help, ciao

Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 8:06 pm
by Berserk
Hey,
Well.....Nobody has answered the questions i posted above.
I just got Something to add, i got somebody else's BootSector.....I am NOT going to use it.....what i want to learn is how to put the boot sector onto the first partion of a floppy disk. And i just want to see what a boot sector looks like. I AM NOT GOING TO USER THIS PERSONG BOOT SECTOR, i am going to make my own. So do not stop helping me on how to make a bootsector and things like that.
Please help if you can.....
Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 9:21 pm
by grey wolf
my boot code is still rather messy and hard to read, so i'm somewhat ashamed to show it to you
here is basically all you need (using NASM):
Code: Select all
[ORG 0]
entry:
cli
mov ax,0x7c0 ; set segments to boot code's location
mov es,ax
mov ds,ax
mov ax,0x9000 ; set stack segment and pointer
mov ss,ax
mov sp,ax
sti
; put your ASM boot code here
size equ $ - entry
%if size+2 > 512
%error "code is too large for boot sector"
%endif
padding times (510 - size) db 0
bootsig db 0x55, 0xAA
if you compiled this as-is, it would come out with a 512 byte file that contains 510 nulls and the boot signature.
the only restriction is that the BIOS loads the boot code to the flat memory location 0x7C00 (or as in the code above, 0x07C0:0x0000), and you need to set up the stack yourself. from then on, what happens is up to you.
after coding and compiling, you can use MS debug to copy it to the floppy:
Code: Select all
debug bootsector.bin
> w 0 0 0 1
> q
this will write bootsector.bin to the first sector of a floppy, where it belongs.
there are excellent examples of boot sectors compatible with FAT12 floppies on the web. here is a good tutorial:
http://www.nondot.org/sabre/os/files/Bo ... smBoot.txt
here is another tutorial that says basically what i've said 3 times already:
http://www.nondot.org/sabre/os/files/Bo ... ector.html
Re:STARTING A NEW OS (Operating System)
Posted: Fri Oct 18, 2002 10:39 pm
by Berserk
Ok,
Now i got a disk with a bootsector on it, it uses the RAW file system. I rebooted my PC with the disk in the drive, and surely it loads the bootsector (Somebody elses bootsector) and then it just stands there.....i didn't pu the kernel on the disk because i don't know how to.
The Disk is formatted in RAW so when i try and open it in Windows Explores Windows XP returns an error saying: 'This disk is not formatted, do you wish to fromat?'
I tryed writing the kernel in a similar way to the bootsector, using MS DEBUG, this is what i did:
Code: Select all
debug C:\os\kernel32.bin
-w 0 0 0 2
I figured that this might work, but it returns an error:
Disk in Drive A: is write protected (Which it isn't)
So.....how do i put other files on the disk??
You see, first i want to learn how to put someone else's bootsector onto a disk and someone else's kernel, before i start making my own.....I want to be able to test my bootsector and kernel as i go along.....But i can't do that since i haven't started making one, get the idea??
And one more question, i want to make my own kernel in C++. Is this possible. If it is can i use Visual C++ 6 to compile the code, or do i have to use GCC or DJPP (Which i also have) I understand that if i make C++ programs for my OS they can't use the WINDOWS API, can they use the Console functions and things??
And i don't get the thing about making my own library (Which is not a problem if i need to make one.....i'd actually love to make my own C/C++ library) but why do i have to make one??
If you understand what i am asking here.....please post a reply. I really need help with this. Everyday i learn something new. And thank you sooooo much greywolf and everybody else especially the guy with the picture of the star wars yoda character (Sorry i forgot your username), you do not know how much you have helped me.....Please help me further ;D
ciao

Re:STARTING A NEW OS (Operating System)
Posted: Sat Oct 19, 2002 9:57 am
by TheMuso
In order to get the kernel to be loaded by the boot sector, you need to add code to the boot sector to read from the disk, (Preferably a floppy at this stage,) and then jump to the memory location of the kernel.
If you wanted to write a kernel in real mode, there would be no great drama in doing this. However, since protected mode is the best mode for advanced operating systems, you need to do a lot more before you jump to the kernel.
As for the location of the kernel, it would usually go on the next sector on the disk, so in your code you would instruct the BIOS to read from sector 1, of the floppy drive, and read so many sectors. (You need to tell the boot sector how big your kernel is as well.)
Hope this helps.
Re:STARTING A NEW OS (Operating System)
Posted: Sat Oct 19, 2002 9:32 pm
by Berserk
hi,
I already have a BootSector and Kernel from the FritzOS (NOTE: I AM NOT GOING TO USE IT) First i want to learn how to put a bootsector and kernel onto a disk, then i will start programming my own OS.
So all i need to know is how to make this OS Load??
After i learn how to load the FritzOS, i will start programming my own OS. I need to learn how to put the bootsector and kernel onto a disk first!!
Please help.....Then i will start asking questions on BootSector Programming ;D
ciao

Re:STARTING A NEW OS (Operating System)
Posted: Sun Oct 20, 2002 4:27 am
by -Haik-
I?m never programmed anything big such as an OS, but I?m pretty sure that you have to learn languages & stuff before starting a project like that, not while making it.
Listing all you can do with assembler here would be insane.
Re:STARTING A NEW OS (Operating System)
Posted: Sun Oct 20, 2002 6:49 am
by Tom
just do this to put FritzOS's boot.bin on a floppy
Download & extract this
http://my.execpc.com/~geezer/johnfine/pcopy02.zip
after extracting partcopy, go to your source code's dir and copy partcopy there.
type in
PARTCOPY boot.bin 0 3 -f0 0
and you have FritzOS's bootloader on your floppy!!!
Now for the C code:
type in ( for pre-compiled binarys )
PARTCOPY kernel32.bin 3E 1C2 -f0 3E
Note: your version of FritzOS might have kernel32 or kernel
Tell me if that works,
Re:STARTING A NEW OS (Operating System)
Posted: Tue Oct 22, 2002 7:24 am
by Ben
Hi, i've never posted here before but i really need to say something about this 'Berserk' person, how can you even think about creating an OS when you know nothing about Asm coding, you need to know it when learning ASM you also learn about how the x86 architecture works how memory management works everything you cannot just say Oh i want to write an OS today and use tools u've never seen before it's stupid. If you want my advice to creating a good os here are the five things you need to learn.
1) PC Architecture(or what ever arch ure using) how the pc works.
2) Asmbelly this is a *MUST* you learn so much get a good book i learnt from Asmbelly Step-By-Step it takes you through Real Mode, Segemented mode & 32bit programming under linux.
3) Learn a high level language like C or C++, do all the nitty bits in asm, and all the rest like consoles, programs n guis in a high level language.
4) Patience. It will take you alot of time you cannot expect to be competing with Linux & windows within a couple of hours. It takes months even years.
5) Research, if you get really stuck ask questions but you will learn alot more by trying to work things out yourself.
I hope this helps i do believe in writing my own code rather than using other peoples you get a greated sense of achivement out of it.
Hope this Helps
Ben
Re:STARTING A NEW OS (Operating System)
Posted: Tue Oct 22, 2002 8:12 am
by Pype.Clicker
Ben wrote:
Hi, i've never posted here before but i really need to say something about this 'Berserk' person, how can you even think about creating an OS when you know nothing about Asm coding, y
this does not seems quite correct to me ... virtually 1% of your code will be written in assembly, rest will be higher language ... of course you'll need a good understanding of the machine internals (i.e. why "hello"+"world" result in a compilation error in C should be obvious to you as well as why you cannot do { int x=2; return &x}), but assembly programming ... sorry, it is absolutely not mandatory except if you believe you have to start with a bootsector to do an OS ...
knowing what scheduling, file management, process, threads, etc. are, how a semaphore works and when to use it, what is dynamic allocation, linked list, etc. seems to be *really* more important in OS programming that any knowledge on the x86 opcodes ...