flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Loading Kernel? understanding the concepts...

Author
Thread Post new topic Reply to topic
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 03 Feb 2013, 08:15
Been away for a while...but I'm back....

I'm just looking for the concepts of how this thing works....

Let's say I've created a KERNEL formated as kernel.bin...

The bootloader is complete - 2 stages

In stage 2, I made a long jump to CODESEG:Pmode

now from PMode I want to jump to the kernel, and I'm wanting to "wash my hands of this floppy business"....

so am I right in assuming that to jump from pmode: to kernel:, I would first have to execute the bootloader, copy my kernel to the specified area of the hard disk, then jump to the kernel and then copy the boot loader to the MBR of the HD?


see.., I'm in protected mode, and I can write code all day long, but for some reason my kernel seems like it's still attached to the 2nd stage of the bootloader...very confusing I know...

I just basically want to know what steps to take after the bootloader completes execution to jump to the kernel and let it take over and run the OS. So that I can do away with floppy emulation....????

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 03 Feb 2013, 08:15
View user's profile Send private message Visit poster's website Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 03 Feb 2013, 17:17
To begin I think your a little confused on Protected Mode and using Disk..

I would sugest using a usb if your bios suport booting from it.. You can make a floppy image and write it to the USB.. Then you can pitch the floppies..

On a Floppy:
you have a MBR and then your kernel.. no need for stage 2 .. stage 2 of your boot is the kernel.. You could make a stage 2 but really no need.. Since floppies never have more than one portion..


On a HDD:
You have a MBR that lists if there is more than one portion.. the MBR boot code reads these and looks for the active portion to boot.. Once it reads and gets the active portion data it jumps to that address -the 2nd stage bootloader is located at that address will load the kernel located in the file system.. The MBR also holds the size of the porttion data so the OS knows how much of the disk it can use. Start sector - last..


As for protected mode.. can happen anywere in the boot proccess were the writer wants it to take place.. can be in the MBR or the kernel..
Post 03 Feb 2013, 17:17
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport 04 Feb 2013, 03:54
Thanks dosin for clearing that up....that helps a lot!

_________________
It's the desire to learn that leads to success...

http://www.webicomp.com
Post 04 Feb 2013, 03:54
View user's profile Send private message Visit poster's website Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 04 Feb 2013, 08:58
Your kernel can be loaded from hard disk directly as well. Usually I use stage 2 boot loader only If I have different kernels/different system folders on the same disk/partition. I use same stage 1 boot loaders to load kernel and to load stage 2 boot loader just by changing the file name. Anyway my kernel starts in RM except when it was loaded by Multiboot compliant boot loader. In this case I switch back to RM to make some first initialization steps. Kernel takes folowing parameters from boot loader:
- BIOS drive number of boot disk;
- number of boot partition or zero if booting occurs from whole boot device or from default boot partition;
- size of the one additional file, which was loaded, or zero;
- name of system folder (stored in kernel image, so stage 1 boot loaders can not give this parameter).

If your kernel starts in PM you should use stage 2 in any case because to switch in PM within stage 1 is bad practice.
Post 04 Feb 2013, 08:58
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 05 Feb 2013, 03:28
I would disagree there is nothing wrong with booting in protected mode..... Grub for example.. Smile

it realy depends on your overall goal.. you can always check in the start of the kernel to see if u need to enable it or not.

The only reason to switch back would be to enable vesa graphics.. or needing bios..
other than that.. no need to at all..
Post 05 Feb 2013, 03:28
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 05 Feb 2013, 08:59
Yes, I still need BIOS for many reasons. For example, to convert BIOS drive number into physical location of the disk. This also allows to have minimal size of routine at Multiboot entry point if the kernel usually starts in RM.
Post 05 Feb 2013, 08:59
View user's profile Send private message Reply with quote
dosin



Joined: 24 Aug 2007
Posts: 337
dosin 05 Feb 2013, 11:52
CHS (cylinder/head/sector) tuples can be mapped to LBA address

Virtual 8086 mode provides a handy way of running 16-bit real mode code under a 32-bit OS. It may seem a bit of a hack on top of normal protected mode, but it was designed to be easy and non-disruptive to add to an existing kernel

http://osdev.berlios.de/v86.html
Post 05 Feb 2013, 11:52
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 05 Feb 2013, 20:54
dosin wrote:
CHS (cylinder/head/sector) tuples can be mapped to LBA address
I cannot understand this, sorry.

It's more easy for me to switch into RM one time, than to make and to use VM.

_________________
If you have seen bad English in my words, tell me what's wrong, please.
Post 05 Feb 2013, 20:54
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 05 Feb 2013, 20:55
dosin wrote:
On a Floppy:
you have a MBR...
It's quite unusual to have MBR on a floppy. Wink

Mapping CHS to LBA can be sufficiently complex if BIOS-induced geometry is not the same as the real (i.e. that was used to format). That's why we have dosen of translation methods. Or probably because of them. Wink

Goddamn, most of MBs you'll encounter will support int13/4x. Stick with IBM/MS int13 extensions and you'll be fine (unless some rare MB stumbles upon you).
Post 05 Feb 2013, 20:55
View user's profile Send private message Reply with quote
egos



Joined: 10 Feb 2009
Posts: 144
egos 06 Feb 2013, 10:13
You are right. I think dosin meant boot sector/boot record when he told about MBR on floppy.

Usually I have support for both EDD service and legacy disk service in my boot loaders. Sometimes I have support only for EDD service. This depends on compilation key.

Excuse me for my bad English, but when I said about converting BIOS drive number into physical location of the disk, I meant disk bus/controller/device detection.
Post 06 Feb 2013, 10:13
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.