memory probing such a difficult thing?
Posted: Tue Dec 19, 2006 11:35 pm
In spite good-thinking-peoples's worst wishes, I decided to probe memory directly... It works perfecty! Else, it worked perfectly when I had coded something similar in ASM some weeks ago...
Note that the code that executes it is a boot loader and is loaded below 1M... and... it assumes that there are 640KB of usable memory below 1MB and that there *is* some memory available above 1MB (at least 1 byte!)...
It will have unpredictable results is this two conditions are not guaranteed (like overwriting BIOS code or so)...
I've not explicitly disabled interrupts, however: (1) in my case the function will really *assume* they are disabled, (2) I don't see how correclty setup interrupts could affect this... If they aren't correctly setup the code would triple fault, anyway!
Anyway, can someone do a simple evaluation about my code, please? Memory allocation is still a sensible area for me and I don't risk relying very much on my own skills! And... it was very easy for my taste!
JJ
Note that the code that executes it is a boot loader and is loaded below 1M... and... it assumes that there are 640KB of usable memory below 1MB and that there *is* some memory available above 1MB (at least 1 byte!)...
It will have unpredictable results is this two conditions are not guaranteed (like overwriting BIOS code or so)...
I've not explicitly disabled interrupts, however: (1) in my case the function will really *assume* they are disabled, (2) I don't see how correclty setup interrupts could affect this... If they aren't correctly setup the code would triple fault, anyway!
Anyway, can someone do a simple evaluation about my code, please? Memory allocation is still a sensible area for me and I don't risk relying very much on my own skills! And... it was very easy for my taste!
JJ
Code: Select all
void* probe_memory (void)
{
register unsigned char* memptr;
for( memptr = (char*) (4 * 1024 * 1024); //We start at 4MB
*memptr = 0x55, *memptr = ~*memptr, *memptr == 0xAA;
memptr += 4 * 1024 * 1024 ) //Using a granularity of 4MB...
; //The loop is empty...
for( ;
*memptr = 0x55, *memptr = ~*memptr, *memptr != 0xAA ;
memptr-- )
; //The loop is empty... remember?!
return (void*) memptr;
}