How to load the kernel after entering pmode
How to load the kernel after entering pmode
So I wrote a boot sector, then I had it jump to a second stage boot loader which enables protected mode, a20 etc... But now I am faced with the problem of how to load the kernel. I cant use the BIOS interrupt so I would have to write a floppy driver within my second stage boot loader. This seems like a bad idea because (1)The OS may not always boot from a floppy and (2)I would like to not have to write a floppy driver twice.
So first I tried to link the boot loader and the kernel, but there was some problem linking the 16 bit loader code. Then I tried to load the boot sector into memory before jumping to protected mode. I was planning on jumping to the kernel in memory after entering protected mode . The problem was that I ended up overwriting the boot loader with the kernel code, causing a crash. Then when I tried to put the kernel at a higher address I get this error from bochs:
00351951398p[FDD ] >>PANIC<< io: norm r/w parms out of range: sec#0bh cyl#fbh eot#00h head#01h
Although this error seems to suggest an error with FAT traversal, it does not occur when I have a lower address that overwrites the loader code. Now thinking about it, I guess that makes sense, because the code would be overwritten before the FAT error occurs.
How do most people load the kernel in a situation like this? It seems like I'm going about this the wrong way.
So first I tried to link the boot loader and the kernel, but there was some problem linking the 16 bit loader code. Then I tried to load the boot sector into memory before jumping to protected mode. I was planning on jumping to the kernel in memory after entering protected mode . The problem was that I ended up overwriting the boot loader with the kernel code, causing a crash. Then when I tried to put the kernel at a higher address I get this error from bochs:
00351951398p[FDD ] >>PANIC<< io: norm r/w parms out of range: sec#0bh cyl#fbh eot#00h head#01h
Although this error seems to suggest an error with FAT traversal, it does not occur when I have a lower address that overwrites the loader code. Now thinking about it, I guess that makes sense, because the code would be overwritten before the FAT error occurs.
How do most people load the kernel in a situation like this? It seems like I'm going about this the wrong way.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to load the kernel after entering pmode
The second stage bootloader is still 16 bit, and can thus still access the bios interrupts, load the kernel and only then jump to protected mode.
Re: How to load the kernel after entering pmode
My setup:
Start bootloader,
Enter UnReal mode (for loading kernel into higher memory),
Depending on the boot device, load kernel from floppy (using INT's) or load from HDD (using IO).
After loading kernel, load second stage bootloader into low mem for later use.
Jump to second stage bootloader to setup PMode and then LMode, and jump to kernel.
Start bootloader,
Enter UnReal mode (for loading kernel into higher memory),
Depending on the boot device, load kernel from floppy (using INT's) or load from HDD (using IO).
After loading kernel, load second stage bootloader into low mem for later use.
Jump to second stage bootloader to setup PMode and then LMode, and jump to kernel.
Website: https://joscor.com
Re: How to load the kernel after entering pmode
Oh. I completely forgot that it was still in real mode until you jump. That makes things easier. Thank you.Combuster wrote:The second stage bootloader is still 16 bit, and can thus still access the bios interrupts, load the kernel and only then jump to protected mode.
Does your program detect whether its on a floppy or the HDD or do you have two versions?01000101 wrote:My setup:
Start bootloader,
Enter UnReal mode (for loading kernel into higher memory),
Depending on the boot device, load kernel from floppy (using INT's) or load from HDD (using IO).
After loading kernel, load second stage bootloader into low mem for later use.
Jump to second stage bootloader to setup PMode and then LMode, and jump to kernel.
How high in memory do people usually put the kernel?
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: How to load the kernel after entering pmode
The de-facto standard seems to be at 1M (for protected- and longmode OSes)
Re: How to load the kernel after entering pmode
My first-stage bootloader detects the boot medium (dl on boot) and the floppy and hdd read code is small enough to fit in the first stage. I used to use two separate files for each type of boot, but I found it unnecessary.
Oh btw, I just reviewed my newer version of DiNS and found out that I no longer use a second stage. The first-stage sets up pmode and lmode itself and jumps to the kernel, the 'second-stage' i was thinking of is just the AP trampoline code.
I load my kernel at 0x1000400 [16MB] (I copy the BSP and AP boot-sectors as well). But as already said, the de-facto is at 0x100000 [1MB].
Oh btw, I just reviewed my newer version of DiNS and found out that I no longer use a second stage. The first-stage sets up pmode and lmode itself and jumps to the kernel, the 'second-stage' i was thinking of is just the AP trampoline code.
I load my kernel at 0x1000400 [16MB] (I copy the BSP and AP boot-sectors as well). But as already said, the de-facto is at 0x100000 [1MB].
Website: https://joscor.com
Re: How to load the kernel after entering pmode
01000101 wrote:I load my kernel at 0x1000400 [16MB]
Re: How to load the kernel after entering pmode
oops typo: supposed to be 0x2000400 [32MB + 0x400 (for bsp+ap bootsect)]
[edit]Also, why is that worthy of a [/edit]
[edit]Also, why is that worthy of a [/edit]
Website: https://joscor.com
Re: How to load the kernel after entering pmode
Ignore me. It's been a long day today
I didn't see your proviso about the 2 boot sectors and thought you were saying 0x1000400 was 16MB - apologies.
Cheers,
Adam
I didn't see your proviso about the 2 boot sectors and thought you were saying 0x1000400 was 16MB - apologies.
Cheers,
Adam
Re: How to load the kernel after entering pmode
I put 0x1000000 as that is where I mirror the kernel before I copy it to the hdd.
And no worries, I was just concerned that maybe there was something I didn't know about occupying that space lol.
And no worries, I was just concerned that maybe there was something I didn't know about occupying that space lol.
Website: https://joscor.com
Re: How to load the kernel after entering pmode
My bootloader enters protected mode asap and uses its services routine that switches between real and protected modes to call bios interrupts during its execution. Its a little slower with this method do to the processor mode switches but works very well as everything is done through the BIOS but from protected mode. Its basically a <dos.h> int86() like routine that I can use within protected mode.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
Re: How to load the kernel after entering pmode
Hi,
So, if the BIOS says the boot device was the "first floppy" (dl = 0x00), then you use enhanced disk services to find out if it really is the first floppy, or if it's the second floppy (with the "swap a: and b:" BIOS option), or if it's a flash drive or CD-ROM emulating a floppy; and if the BIOS says the boot device was the "first hard drive" (dl = 0x80) then you find out if it's the first IDE/ATA/SATA hard drive or if it's a SCSI drive, or if it's a flash drive or CD-ROM emulating a hard drive. Then, you've got device drivers for floppies, IDE/ATA/SATA (and ATAPI) and every kind of SCSI controller, plus code for each type of USB controller and code to handle several USB devices (USB flash, USB floppy, USB hard disk and USB CD-ROM). And, all of this fits in your first stage boot loader? I'm impressed....
Cheers,
Brendan
Umm...01000101 wrote:My first-stage bootloader detects the boot medium (dl on boot) and the floppy and hdd read code is small enough to fit in the first stage.
So, if the BIOS says the boot device was the "first floppy" (dl = 0x00), then you use enhanced disk services to find out if it really is the first floppy, or if it's the second floppy (with the "swap a: and b:" BIOS option), or if it's a flash drive or CD-ROM emulating a floppy; and if the BIOS says the boot device was the "first hard drive" (dl = 0x80) then you find out if it's the first IDE/ATA/SATA hard drive or if it's a SCSI drive, or if it's a flash drive or CD-ROM emulating a hard drive. Then, you've got device drivers for floppies, IDE/ATA/SATA (and ATAPI) and every kind of SCSI controller, plus code for each type of USB controller and code to handle several USB devices (USB flash, USB floppy, USB hard disk and USB CD-ROM). And, all of this fits in your first stage boot loader? I'm impressed....
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.
Re: How to load the kernel after entering pmode
Remember, I'm programming for an incredibly narrow hardware range. Also, that small hardware range is specified when assembled and thus the configuration does not vary.
I don't need to check for half of those things listed as they will be disabled in the BIOS and will not have any sort of implementation in any non-debug mode. Basically the goal is to only program what needs to be programmed for, and leave the rest without any handling at all (unless that is more of a security issue itself). Also, the future method will involve BIOS locking so that the startup cannot vary, thus ruling out things such as floppy drives (of any fashion).
I don't need to check for half of those things listed as they will be disabled in the BIOS and will not have any sort of implementation in any non-debug mode. Basically the goal is to only program what needs to be programmed for, and leave the rest without any handling at all (unless that is more of a security issue itself). Also, the future method will involve BIOS locking so that the startup cannot vary, thus ruling out things such as floppy drives (of any fashion).
Website: https://joscor.com
-
- Member
- Posts: 195
- Joined: Tue Aug 26, 2008 11:24 am
- GitHub: https://github.com/sebihepp
Re: How to load the kernel after entering pmode
I had this problem, too. But I am solving it this way:
My 2nd stage boot loader contains 16Bit Code and 32 BitCode.
After jump to PMode everytime I want to read from floppy I jump to
UnrealMode, use the BIOS, jump back to PMode and copy the readed
sector to the destination.
Cheers Sebihepp
My 2nd stage boot loader contains 16Bit Code and 32 BitCode.
After jump to PMode everytime I want to read from floppy I jump to
UnrealMode, use the BIOS, jump back to PMode and copy the readed
sector to the destination.
Cheers Sebihepp
Re: How to load the kernel after entering pmode
HI!
So, If I know right, int13 can load not more than 64Kb file? If it is so, then how can I load more than 64Kb and not to 1Mb? For example i'd like to load at 0xC0000000? (3GB)
Thanks!
So, If I know right, int13 can load not more than 64Kb file? If it is so, then how can I load more than 64Kb and not to 1Mb? For example i'd like to load at 0xC0000000? (3GB)
Thanks!
Don't think a ****, but in ukrainian schools English is TOO BAD!