Page 1 of 1
Writing above available RAM
Posted: Thu Apr 14, 2005 9:26 am
by Jubbens
If I try to write to 0x100000 in real mode, but they system doesn't have 1MB of RAM, will a flag be set or will the system just die? Since I'm in real mode, this could be my way of testing for enough memory.
I know this is a good page
http://www.osdev.org/osfaq2/index.php/H ... f%20RAM%3F
but I couldn't find the answer to this particular question.
Re:Writing above available RAM
Posted: Thu Apr 14, 2005 9:40 am
by smiddy
This depends if you have A20 (A is for Address) line is enabled or not. In real mode if you try to write at 0x100000 it will wrap around to 0x0, and you'd run into writing into the Interrupt Vector Table (IVT), if the A20 line isn't enabled. Enabling the A20 line allows you to see past 0x100000 to 0x10ffef (segment:offset = ffff:0010 to ffff:ffff). Now, from the page you list, it is possible to place the processor in flat-real mode and use the 32-bit offset in order to access the entire RAM. In this way (assuming again that A20 is enabled) you can write to and check that you wrote and determine if the RAM is there, counting the amount as you go. But, it is best to use what is available to you first, like BIOS calls to check the amount of installed memory. If the amount you wish the system to have isn't available, then you should resort to probing the memory directly.
Re:Writing above available RAM
Posted: Thu Apr 14, 2005 2:04 pm
by Jubbens
I know about the A20 line and unreal mode, but they're both off. Sorry for not being more specific.
So if I try to write a byte above available memory and try to read that byte, what will happen? Flag? Crash? Reboot? Nothing?
Re:Writing above available RAM
Posted: Thu Apr 14, 2005 4:18 pm
by AR
If you write beyond 1MB with A20 off it will wrap around so basically 0x100000 is exactly the same as 0x0 when A20 is off.
If you write beyond the end of available RAM nothing will happen, if you write to a memory mapped device then that could be potentially bad but that's it.
Re:Writing above available RAM
Posted: Fri Apr 15, 2005 2:10 am
by Pype.Clicker
no flag will ever tell you you're going out of the memory. No crash will occur (unless you're relying on getting back what you wrote or attempt to execute something somewhere no memory is present). No reboot will occur (unless it crashes)
Truth is, when you issue a memory reference, your CPU has no idea of whether the address is bound to some physical memory or not. It issues a "read cycle" on the bus and then, after proper timing, read the value that appears on the bus. If no chip has been enabled by the address issued, the bus line is simply 'floating' (usually, that means you read 0xff, but you shouldn't rely on that either).
If you're trying to write first, then read back, make sure
you have turned caching off first otherwise, what you read back is simply what the CPU reminds he wrote at that address last time (which of course defeats the whole purpose
)
Once again, there are things that are mapped in memory, notably the APIC registers (at 0xFEE00000) and there may be other memory-mapped device enabled ... so you're *really* better to ask the BIOS what is available if you wish to avoid *big* troubles later.