How to Load kernal

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

How to Load kernal

Post by crazygray1 »

I'm using Qemu to run the bootloadr. Ok, I have a 1.44m floppy image and on it is a stage1 bootloader. If I just have the kernal pasted right below the bootloader will somebody outline a function that will load and execute the kernel. :wink:
Last edited by crazygray1 on Sat Nov 24, 2007 12:31 am, edited 1 time in total.
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

This depends on the file system that you are using, and the file format of the kernel.

Unless, you mean the bootloader (at sector 0) loads and executes a "kernel" at sector 1? (Please please not this.)

Need more details, please ;)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Post by crazygray1 »

Yes,the kernal starts at the 2nd sector.What's the problem.
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

You can use it to load extra sectors for booting as needed (Some systems do this for some reason.), I highly recommend it not being a Kernel ,though.

It is very hackish, and does not use any file system of any type. It is much more better to treat the kernel as its own task/program for design purposes for cohesion. There is no possible way to do this by reading/writing random sectors off disk.

Also, some/most/mabey all filesystems use certain sectors for specific purposes. For example, FAT12's first FAT table is located directly after the number of reserved sectors after the bootsector, or directly after the bootsector. Reading/Writing random sectors may make a file system impossible to design and develop on that system.

A system without a filesystem has almost no nice way to treat "files" and "programs", as there is no standard structure for their storage on disk. Hence, say goodbye to Program Management - A core function in any OS.

I am sure many members here can come up with countless of reasons why this would be very bad for a kernel.

If you still wish to continue, This might help you.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
maverick777
Member
Member
Posts: 65
Joined: Wed Nov 14, 2007 3:19 pm

Post by maverick777 »

lol had I not read some of the guides thats probably what I would have done :-) , yeah Im guessing if you went that route you would want to be thinking about making your own filesystem and a way to keep track of where files are?

Must admit the whole sectors 1 to x thing seems nice and simple but Im guessing it would be a knightmare to know what was where on disk?
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Not to mention the fact that your kernel would be very difficult to install on a hard drive (you'd need a "kernel partition") and next to impossible to update.

In my OS, the kernel is a binary just like any other, except it's always executed at startup. Because I use GRUB I don't need to write FAT code, or any ELF code, but all that can easily be put into a second-stage loader, which should not be ELF.

1st stage loader loads the second stage (which is a pure binary), second stage loader has FAT and ELF code, loads up the kernel (if the kernel is a higher-half kernel in the second stage loader you could also set that up), and then jumps to the entry point (which the ELF header provides).

If any of this is confusing, just ask :D
User avatar
crazygray1
Member
Member
Posts: 168
Joined: Thu Nov 22, 2007 7:18 pm
Location: USA,Hawaii,Honolulu(Seriously)

Post by crazygray1 »

Actually now that you tell me about the problems I'm going ahead and writing my own disk image tool that will have the features that I want so I can not have to do that.
Codname: Cipher
Working On: Design Doc(CFFS file system)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,

@crazygray1: I want you to look at things from a different perspective...

All boot loaders need to put the computer into some sort of state that the next stage can rely on. The details for this "transition state" are important, but what any specific boot loader does is mostly irrelevant (as long as it sets up this "transition state"). For the latest version of my OS this transition state goes something like this:
  • - A20 must be enabled
    - the boot image must be at 0x00100000
    - the "boot script" must be at 0x00070000
    - a correct "pre-boot data structure" must be at 0x00060000, and must include a map of areas in the physical address space and other information (see the file "inc/boot/peds.inc" for exact requirements and details for this data structure).
    - an (optional) list of faulty RAM areas must be at 0x00050000 (if present)
    - the boot loader is responsible for selecting and setting up a default video mode (where maximum resolution and maximum colour depth allowed is determined by the "boot script")
    - the second stage code must be at 0x00030000
    - the boot loader must be in 32-bit protected mode (with "flat" segments) when it jumps to the second stage
    - all AP CPUs shall be left in their default "wait-for-SIPI" state
    - the state of all other hardware is undefined
@Neon: My "1440 KB floppy boot loader" doesn't use any file format and data is stored in contiguous sectors following the boot loader, and I don't see any problem with this at all. I haven't decided what a native "hard disk boot loader" will do yet. To be honest I really do like the idea of having a seperate boot partition, as it keeps the data needed during boot isolated from (potentially buggy and/or insecure and/or non-fault tolerant) file system code.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Post by neon »

@Neon: My "1440 KB floppy boot loader" doesn't use any file format and data is stored in contiguous sectors following the boot loader, and I don't see any problem with this at all.
There is no problem with that ;)

The bootloader does not need to have any file format. The Kernel should, though.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Post Reply