Boot loader

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

Boot loader

Post 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?
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Post 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
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post 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...
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Post 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?
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post by mathematician »

If you want to address memory above 1mb in real mode, you should go and type "unreal mode" into a search engine.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

why would you want to limit yourself by not enabling A20, anyway
well in a bootsector, space can get very tight...
madeofstaples
Member
Member
Posts: 204
Joined: Thu Apr 12, 2007 8:15 am
Location: Michigan

Post 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 :?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Post 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
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post by earlz »

can you use DMA for memory to memory moving!?
User avatar
d4n1l0d
Member
Member
Posts: 42
Joined: Sat Dec 02, 2006 4:12 pm

Post 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
---
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post 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...
User avatar
mathematician
Member
Member
Posts: 437
Joined: Fri Dec 15, 2006 5:26 pm
Location: Church Stretton Uk

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Post 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.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Post 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...
Aali
Member
Member
Posts: 58
Joined: Sat Apr 14, 2007 12:13 pm

Post 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
Post Reply