Hi all,
I have written a boot sector which loads a stage 2 loader into memory, and now I am working on making the stage 2 loader pull the rest of the kernel into off the disk and into memory. I am curious as to the different methods to do this.
My concerns:
1. I want my kernel to start at 0x100000, but can't load it there in real mode (that I know of).
2. I want to be able to load a kernel larger than 64k, but am not sure how to do this in real mode.
3. I would like to make the stage 2 loader set the a20 and jump to pmode before attempting to load the kernel (so I can put it where I want and also avoid the 64k segment issue) but without access to int 13h in pmode, i'm not sure how to do this. I really don't want to have to incorperate a disk driver in the stage2 loader.
Basically the only thing I can think of doing right now is to load the kernel in real mode to a location in memory, jump to pmode and then copy it to 0x100000 and then jump there. But then I still have an issue trying to pull a kernel bigger than 64k (I just don't know how to do it). Any suggestions or ideas that I havn't considered?
Many thanks in advance.
Load kernel in pmode or real mode?
Re:Load kernel in pmode or real mode?
My advice..
Use GRUB...it will solve all your problems. You can always create your own bootloader later.
Daryl.
Use GRUB...it will solve all your problems. You can always create your own bootloader later.
Daryl.
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:Load kernel in pmode or real mode?
Well, one can load the kernel to 0x100000 in real mode. Just the adressing is somewhat odd.
this is the block in the boot code, which loads my kernelthing to 0x100000:
read;
mov ax,0xffff
mov es,ax
mov bx,0x10
after these three commands, int 13 h knows to load the kernal at 0x100000
the rest of this routine is as usual: the settings of int 13 to get some sectors off the disk into memory.
I think, Mr. Perica Senjak has written a tutorial about this real mode adressing, which is to be found at http://osdev.neopages.net/ - K.J.'s site.
concerning the 64 K limit ... well, as Mr. Dudey here says, take GRUB. It will ease your life.
this is the block in the boot code, which loads my kernelthing to 0x100000:
read;
mov ax,0xffff
mov es,ax
mov bx,0x10
after these three commands, int 13 h knows to load the kernal at 0x100000
the rest of this routine is as usual: the settings of int 13 to get some sectors off the disk into memory.
I think, Mr. Perica Senjak has written a tutorial about this real mode adressing, which is to be found at http://osdev.neopages.net/ - K.J.'s site.
concerning the 64 K limit ... well, as Mr. Dudey here says, take GRUB. It will ease your life.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:Load kernel in pmode or real mode?
You're not limited to 64k.
eg.
Make ES:BX 0x1000:0000
Copy 128 sectors with int 13h
Make ES:BX 0x2000:0000
Copy 128 sectors with int 13h
.
.
.
Switch to pmode and copy the whole thing to wherever you want it to wind up.
Of course this limits you to a kernel of 1mb if you only want to do 1 pmode switch (There is a sneaky way to avoid the pmode switch on newer BIOS by using one of the int 15h functions to move the data higher than 1mb).
Other options include using the ports/dma from within pmode, V86 mode with the BIOS or (As has been mentioned) GRUB.
Ports are the best way to go if you insist on doing everything yourself. However general opinion on the board is to not get stuck on the bootsector, use GRUB to start with, and do some of the more interesting things instead of struggling with a bootloader.
eg.
Make ES:BX 0x1000:0000
Copy 128 sectors with int 13h
Make ES:BX 0x2000:0000
Copy 128 sectors with int 13h
.
.
.
Switch to pmode and copy the whole thing to wherever you want it to wind up.
Of course this limits you to a kernel of 1mb if you only want to do 1 pmode switch (There is a sneaky way to avoid the pmode switch on newer BIOS by using one of the int 15h functions to move the data higher than 1mb).
Other options include using the ports/dma from within pmode, V86 mode with the BIOS or (As has been mentioned) GRUB.
Ports are the best way to go if you insist on doing everything yourself. However general opinion on the board is to not get stuck on the bootsector, use GRUB to start with, and do some of the more interesting things instead of struggling with a bootloader.
Re:Load kernel in pmode or real mode?
Grub is not the HOLY GRAIL OF OS LOADERS,PLEASE!!!
I used my own boot loader, and must say its was a VERY valuable learning experience!
It will help you later on when writing the kernel, you will learn a lot about how pmode works if you can successfully write one. and it less that 2pages of code!
I used my own boot loader, and must say its was a VERY valuable learning experience!
It will help you later on when writing the kernel, you will learn a lot about how pmode works if you can successfully write one. and it less that 2pages of code!
Re:Load kernel in pmode or real mode?
I originally looked at GRUB when I first started my project, but decided against it since I really wanted to learn about setting the A20 line, setting up a proper GDT and setting pmode, etc.
My first pass of the project was a simple boot loader and kernel that did all of this. It was basically a pmode "hello world", and I guess I really have learned what I wanted from that exercise and now that I want to get into a real kernel implementation, GRUB may be the best thing to use rather than trying to make my first pass bootloader useful for a real kernel.
Thanks for the quick and learned responses. I've found this site quite useful already!
My first pass of the project was a simple boot loader and kernel that did all of this. It was basically a pmode "hello world", and I guess I really have learned what I wanted from that exercise and now that I want to get into a real kernel implementation, GRUB may be the best thing to use rather than trying to make my first pass bootloader useful for a real kernel.
Thanks for the quick and learned responses. I've found this site quite useful already!
Re:Load kernel in pmode or real mode?
Errrh,..... you do know that boot loaders just have to setup the pmode environment - a20,pic reprogram etc (stuff you say you have done!) So what else do you need? The last thing needed is loading kernel from disk and jump to it! Also bootloader are not re-entrantie you run only once at start up < 1% of entire OS!
Re:Load kernel in pmode or real mode?
My previous "bootloader" consisted of reading a single sector (my "kernel") off the disk to 0x8000 setting the a20, a GDT, and then pmode and then jumping to my "kernel" which printed "Kernel loaded" and then halted.
Both programs were assembly, so my kernel was easily under 512 bytes and didn't have to be anywhere special in memory
My real kernel that I am now going to work on, I want to start at 0x100000 and will be in C. Quite a different task than my previous "kernel" which was merely a few assembly lines and was just a learning exercise.
Both programs were assembly, so my kernel was easily under 512 bytes and didn't have to be anywhere special in memory
My real kernel that I am now going to work on, I want to start at 0x100000 and will be in C. Quite a different task than my previous "kernel" which was merely a few assembly lines and was just a learning exercise.
Re:Load kernel in pmode or real mode?
Yes but what Code Slasher meant, was not that you should use the first bootsector that you ever had done. He meant that you should write a boot sector that does the thing GRUB does instead of relying on GRUB to boot your system.Parabola1 wrote: My previous "bootloader" consisted of reading a single sector (my "kernel") off the disk to 0x8000 setting the a20, a GDT, and then pmode and then jumping to my "kernel" which printed "Kernel loaded" and then halted.
Both programs were assembly, so my kernel was easily under 512 bytes and didn't have to be anywhere special in memory
My real kernel that I am now going to work on, I want to start at 0x100000 and will be in C. Quite a different task than my previous "kernel" which was merely a few assembly lines and was just a learning exercise.
I don't rely on GRUB since I, just as Code Slasher, think that the best excercise is to code it by yourself and by doing so I get knowledge how the bootsector will load a file from a FAT12 floppy for example.