Page 1 of 2

Boot loader

Posted: Sat May 19, 2007 9:08 am
by d4n1l0d
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?

Posted: Sat May 19, 2007 9:13 am
by madeofstaples
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

Posted: Sat May 19, 2007 9:33 am
by earlz
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...

Posted: Sat May 19, 2007 10:24 am
by madeofstaples
hckr83 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...
That's true, because it's only the 20h bit that is disabled

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?

Posted: Sat May 19, 2007 10:50 am
by mathematician
If you want to address memory above 1mb in real mode, you should go and type "unreal mode" into a search engine.

Posted: Sat May 19, 2007 10:54 am
by earlz
why would you want to limit yourself by not enabling A20, anyway
well in a bootsector, space can get very tight...

Posted: Sat May 19, 2007 11:02 am
by madeofstaples
hckr83 wrote:
why would you want to limit yourself by not enabling A20, anyway
well in a bootsector, space can get very tight...
so you're suggesting he wait until his kerenel starts to enable A20?

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 :?

Posted: Sat May 19, 2007 11:37 am
by Pype.Clicker
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 :P

Posted: Sat May 19, 2007 11:50 am
by earlz
can you use DMA for memory to memory moving!?

Posted: Sat May 19, 2007 12:47 pm
by d4n1l0d
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
---

Posted: Sat May 19, 2007 1:21 pm
by earlz
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...

Posted: Sun May 20, 2007 5:40 am
by mathematician
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

Posted: Sun May 20, 2007 5:53 am
by Pype.Clicker
hckr83 wrote:can you use DMA for memory to memory moving!?
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.

Posted: Sun May 20, 2007 8:25 am
by earlz
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.
well, I guess you could use it for background memory transfers...of course, I bet initialization loses any cpu cycles you'd save though...

Posted: Sun May 20, 2007 12:48 pm
by Aali
actually, DMA memory-to-memory transfers never worked
someone had grand plans for DMA back in the days, the actual chips support only a small fraction of those features