Boot loader
Boot loader
I'm writing my own boot loader, that works in real mode, and I want to load my kernel over the 1 MB in memory, my question is if can I do it on real mode or do I have to enable protected mode for it?
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
You can do it in real mode.
Your bootloader needs to enable the A20 gate to access above 1MB of memory.
take a look at the following:
http://www.osdev.org/wiki/A20_Line
http://www.nondot.org/sabre/os/files/HCI/keyboard2.txt
http://www.nondot.org/sabre/os/files/HC ... ardFAQ.txt
http://osdever.net/tutorials/a20.php
Your bootloader needs to enable the A20 gate to access above 1MB of memory.
take a look at the following:
http://www.osdev.org/wiki/A20_Line
http://www.nondot.org/sabre/os/files/HCI/keyboard2.txt
http://www.nondot.org/sabre/os/files/HC ... ardFAQ.txt
http://osdever.net/tutorials/a20.php
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
That's true, because it's only the 20h bit that is disabledhckr83 wrote:that is a popular misconception...
If you set GDT properly...you don't have to enable A20...
The onyl limit is that you can only access even numbered MB, like 2MB, 4MB, 6MB, ect
I know this from John (somethihngs) bootloader..he doesn't enable A20, but loads the OS at 2MB...
at first I read that he wanted to load his kerenal at the 1 MB mark but now I see he said "above"
why would you want to limit yourself by not enabling A20, anyway?
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
-
- Member
- Posts: 204
- Joined: Thu Apr 12, 2007 8:15 am
- Location: Michigan
so you're suggesting he wait until his kerenel starts to enable A20?hckr83 wrote:well in a bootsector, space can get very tight...why would you want to limit yourself by not enabling A20, anyway
The problem I see with that, is what happens when his kernel grows to over one MB (granted, it's unlikely, at least anytime soon)?
He'd have to go back and write a second stage for his bootloader
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
It's been ages since i last read the DMA controller specs, but iirc, it was capable of addressing 16MB of space (regardless of the actual limitations of the CPU).
So i'd say that we could theoretically load stuff in high memory via a low-memory buffer even if one doesn't want to mess with CR0 in the bootloader proper ... not that it'd be of any use imho
So i'd say that we could theoretically load stuff in high memory via a low-memory buffer even if one doesn't want to mess with CR0 in the bootloader proper ... not that it'd be of any use imho
I'll enable a20 line for that, but, I want that my boot loader recognizes FAT12 system and I don't want to write a FAT12 driver totally in asm ( I prefer writing in C ), so which C compiler can I use for generating 16 Bits code??
---
My bootloader already has a second stage that is loaded by it's offset in the disk, so I don't have only 512 bytes for the FAT12 driver
---
---
My bootloader already has a second stage that is loaded by it's offset in the disk, so I don't have only 512 bytes for the FAT12 driver
---
for a bootloader, C just won't work well...unless of course, you make a second stage..but I recommend you do all of the first sector bootloader in ASM...
but turboC is the most commonly used 16bit C compiler..
there was some GCC variant that worked in 16bits also, though it didn't support inline ASM at all...
but turboC is the most commonly used 16bit C compiler..
there was some GCC variant that worked in 16bits also, though it didn't support inline ASM at all...
- mathematician
- Member
- Posts: 437
- Joined: Fri Dec 15, 2006 5:26 pm
- Location: Church Stretton Uk
Even with the A20 line enabled it is not normally possible to address more than 1mb of memory in real mode, because, when the processor is initialised, the hidden part of the segment registers are loaded with a maximum sector size of 64kb. It is only possible to change that by temporarily switching into protected mode:
http://www.osdev.org/wiki/Unreal_Mode
http://www.osdev.org/wiki/Unreal_Mode
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
well, I guess you could use it for background memory transfers...of course, I bet initialization loses any cpu cycles you'd save though...Iirc, yes. The DMA chip has a memory-to-memory mode too.
Now, that's far from being practical to use (ugly code) or efficient (outdated chip compatibility), but it's there.