Memory?

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

Memory?

Post by BrandonChris »

I written a small kernel (input/output functions) but whats next? paging? memory mangment? a filesystem? Dont really know what I gonna write next..

By the way, what memory can I use for applications and stuff, and what memory is already used or reserved? I got my kernel at 0x1000 and I suppose I can use all the memory from 0x1000 to 0x9FFFF but thats only 651.263 kbytes, where is the "rest" of the memory that I can use?
Schol-R-LEA

Re:Memory?

Post by Schol-R-LEA »

The rest of the memory is above the original 1M of real-mode memory. In order to access that, you need to do two things.

First, you need to activate the A20 address line, which allows you to access the 21st addressing line. This allows you, in real mode, to access the High Memory Area, an area of 48K between 0x1000 and 0x1FFEF, or to access the whole 4G address space in protected mode. The reason you need to do this is an artifact of the segment:offset memory model in real mode and the design of the 8086 chip. You see, base:offset values greater than FFFF:000F are actually greater than 1M. However, the original 8086/8088 had only 20 physical address lines, enough to address 1M exactly, so on those chips, the memory above FFFF:000F would actually wrap around back to 0000:0000 through 0000:FFEF. When the IBM AT designed (using the 80286, which had 24 address lines), they didn't want programs that relied on this to break, so the redirected the 21st address line to a line in the jeyboard controller, in order to disable it. It as later determined that it could be re-enabled again by certain calls to the keyboard controller, allowing the system to access it's full memory.

However, in real mode, the software can still only access the memory which can be addressed through the base:offset pairs, meaning anything above 0x10FFEF is ureachable. To access the rest of memory, you have to switch the system into 32-bit protected mode (there is a 16-bit protected mode as well, which was first used in the 80286, but the 32-bit p-mode is much more useful). This uses a completely different mechanism for accessing and addressing memory, and allows for 32-bit (or 36-bit with PAE) segment offsets, which means that a single segment can address the whole of the physical memory. Note that real mode programs - such as the majority of the BIOS - wil not run in p-mode, so you will probably want to run certain BIOS dependent functions (e.g., memory checking) first. There is a sort of hybrid mode called 'unreal' mode which allows you to use the whole memory while still running real mode software, but it has serious limitations which make it less useful than you would hope, and it lacks the memory protection that gives protected mode it's name. You can also run real mode software in a V86 ("virtual 8086") task under p-mode, but it requires a good amount of work and has certain limits on what it can do.

You can do these two things in whatever order you choose, but it is better to do the A-20 line first, as you can try using the BIOS INT 0x15 functions to activate it while in real-mode (though not all motherboards support it). Doing it this way also means that you will have the whole memory available to you as soon as you switch modes.

See the .:Quicklinks:. thread for pointers to tutorials explaining the a20 line and protected mode.
BrandonChris

Re:Memory?

Post by BrandonChris »

Thanks but I?ve already done that (entered PM and enabled the A20 line)... I just meant that some of the memory is reserved for special stuff, System BIOS and so on...
Curufir

Re:Memory?

Post by Curufir »

Rest of the memory is above 1mb, figure out what is available by using the bios interrupts.
BrandonChris

Re:Memory?

Post by BrandonChris »

What bios interrupt? :)
Curufir

Re:Memory?

Post by Curufir »

Take your pick

int 15h, e820h - Gives a full map
int 15h, e802h - Only gives information about available memory
int 15h, e801h - Only gives information about available memory
int 15h, 88h - Only reports a maximum of 64Mb of memory

I won't tell you what form they report back in because it's been discussed MANY times on the board and is in fact in the FAQ!!!

http://www.osdev.org/osfaq2/index.php/How%20do%20I%20determine%20the%20amount%20of%20RAM%3F
BrandonChris

Re:Memory?

Post by BrandonChris »

Alright :) thank you very much!
Post Reply