Page 1 of 1
About booting the kernel
Posted: Tue Feb 05, 2002 5:21 am
by Whatever5k
First of all, hi
I have a basic question on programming an Operating System:
Allright, I have programmed a kernel.c and I linked it to kernel.bin... .
Now I put it on a floppy disk and tell the BIOS to boot up from the floppy disk. But how can the program be executed, I always thought it needed the OS it was build on. For example, I compile and link my kernel on Linux, can the kernel only be executed in Linux, does the kernel need Linux for beeing executed?
Thanks and regards,
A. Blessing
Re: About booting the kernel
Posted: Tue Feb 05, 2002 7:30 am
by roswell
Hi,
In fact, the only thing you need is a bootloader.
This is a small app that is executed just after the BIOS.
It is located at the begining of the boot disc.
The bootloader just look for the kernel, load it in memory and jump to it.
Re: About booting the kernel
Posted: Tue Feb 05, 2002 1:16 pm
by K.J.
More accuratly, you will need to make a
bootsector that is copied to the first sector of a floppy(assuming that you want to boot from a floppy). The
bootsector that you write will need to written in assembly lanuage and compile it into a binary file. The
bootsector's job is to find your kernel.bin file on the floppy then and load it into memory and then jump to it. One thing that you need to be sure of is that your kernel and/or bootsector is written in assembly that you don't use
any int 21h calls as those are provided by DOS and DOS won't be availible to your kernel and/or bootsector. It appears that you have written your kernel in C so also be sure that there are
no printf's because these rely on Linux, DOS, or another OS. Also make sure that you don't link with the standard libc library that comes with Linux because most of the functions in it need Linux to work.
Basically, a boot off a floppy disk works like this:
1. pc is turned on
2. the pc's bios looks for a floppy in the floppy drive
3. if found the bios loads the first sector(the
bootsector) of the floppy into memory and jumps to it and runs it
4. the bootsector then loads the kernel into memory from the floppy
5. the bootsector jumps to the kernel and runs it
If you would like some well commented bootsectors then I suggest that you look at John Fine's:
http://www.execpc.com/~geezer/johnfine/index.htm
Hope that helps you
.
K.J.
Re: About booting the kernel
Posted: Wed Feb 06, 2002 1:15 am
by Whatever5k
> Hope that helps you
.
Oh yes, it does! Thanks very much.
Thanks to those people who created this board, I think it helps many people who want to build their own OS... .
Just one other question for now:
Did Linus Torvalds compile his kernel on Minix?
Thanks and regards,
A. Blessing
Re: About booting the kernel
Posted: Wed Feb 06, 2002 1:30 pm
by K.J.
Did Linus Torvalds compile his kernel on Minix?
I think that I read somewhere that he did originaly. Now the Linux kernel is compiled on Linux.
K.J.
Re: About booting the kernel
Posted: Thu Feb 07, 2002 3:01 am
by Whatever5k
Sorry, I still have a question... .
You said, I should not use any printf() functions, because they use functions that are specific to the OS on which it was compiled... .
So I have to compile my own printf(). But are there any printf() sources, I can use? How do these printf() functions differ from the printf() function in the libc? Do they use functions that are different in each OS?
Re: About booting the kernel
Posted: Thu Feb 07, 2002 4:11 pm
by Chris Giese
>You said, I should not use any printf() functions, because they use functions that are specific to the OS on which it was compiled...
Right. printf() and related functions call sub-functions to
do the actual printing, but there is no standard for these.
Maybe printf() calls putchar() to do the actual printing;
maybe not. Maybe fprintf() calls fputc() to print; maybe not.
>So I have to compile my own printf(). But are there any printf() sources, I can use?
You can use mine if you want:
http://www.execpc.com/~geezer/osd/libc/ ... tm#problem
It doesn't support floating point numbers, but it's pretty
complete otherwise.
Re: About booting the kernel
Posted: Fri Feb 08, 2002 3:41 am
by Whatever5k
Thanks for replying!
But if a printf() function calls putchar(), what's wrong with that? Gcc will include this function and so everything would be right, wouldn't it? The only problem I see would be, if the Library was dynamic... .
So, that's the first question... .
The second is: What's the difference between your printf() function and the putchar() function of gcc?
Pleeeeease help me, that's quite important to me... .
Re: About booting the kernel
Posted: Fri Feb 08, 2002 4:59 am
by df
:-X you cant include any functions in gcc! you can use the built in printf, or the builtin putchar. all yuor routines must be written to use your OS. if your using gcc on unix, or on windows, putchar is designed to use win32 api, or unix api.
you must write them all to use your own API. why do you think you cant run windows executables on unix? etc.
Re: About booting the kernel
Posted: Fri Feb 08, 2002 5:30 am
by Whatever5k
Allright, got that, but why are there some source codes for printf() functions I can use for my OS? Do these functions not use an API, but communicate directly with the hardware?
Thanks for replying
Re: About booting the kernel
Posted: Fri Feb 08, 2002 5:49 am
by df
becuase the authors have written them with their own api, often this is the hardware, 0xB80000
(which is exactly what mine does)
Re: About booting the kernel
Posted: Fri Feb 08, 2002 6:05 am
by Whatever5k
Allright, thanks, this answers my question (well, I hope so
)