Page 1 of 1
Detect Memory Size
Posted: Sun Jan 21, 2007 3:59 pm
by Tolga
Hi.
How can detect memory size in PROTECTED MODE? Please dont say that you can detect in "Virtual Mode".
I need this for memory management.
Thanks.
Posted: Sun Jan 21, 2007 4:15 pm
by gaf
You're not the first to ask that question (Read the
FAQ)
cheers,
gaf
Posted: Mon Jan 22, 2007 10:31 am
by xsix
Detect memory via BIOS in real mode and place information somewhere in memory, so from protected mode you can see it. I've done some real mode detections in this way. I've loaded my kernel @ 1st megabyte of ram, and palced all information in 640kbytes below the 1st megabyte and i'm happy. What's wrong? or in another way, you can write and read values to and from memory, but reading non-existing memory address will cause an exception so you'll get more job on your own
Posted: Mon Jan 22, 2007 12:03 pm
by Candy
xsix wrote:Detect memory via BIOS in real mode and place information somewhere in memory, so from protected mode you can see it. I've done some real mode detections in this way. I've loaded my kernel @ 1st megabyte of ram, and palced all information in 640kbytes below the 1st megabyte and i'm happy. What's wrong? or in another way, you can write and read values to and from memory, but reading non-existing memory address will cause an exception so you'll get more job on your own
Reading non-existing memory will not cause any exception, it'll cause you to read random stuff. The locations also won't remember anything. Worst that can happen is that they DO function like memory, but aren't intended to be used as such - say, the registers your video card uses or its framebuffer.
Posted: Tue Jan 23, 2007 11:11 am
by JAAman
Worst that can happen is that they DO function like memory, but aren't intended to be used as such - say, the registers your video card uses or its framebuffer.
and in some cases, (admittedly rare), writing to non-existent 'memory' can permanently destroy your computer
just a warning
there is, however, a way to detect memory in PMode, by querying the memory controller -- but this will require you to first write a driver for each memory controller you support -- meaning each north-bridge for Intel and older AMD systems, and each revision of each newer AMD CPU, will require its own memory detection code -- not recommended
Posted: Tue Jan 23, 2007 11:49 am
by Jabus
This is just a side question. At what stage do you need to know the memory size. Is it only useful to know when you have a large kernel?
Posted: Tue Jan 23, 2007 6:25 pm
by Brendan
Hi,
Jabus wrote:This is just a side question. At what stage do you need to know the memory size. Is it only useful to know when you have a large kernel?
In general, you need to know which areas are usable RAM when your OS stops using statically allocated RAM in "safe" areas and starts using dynamically allocated RAM.
When this happens may be different for different OSs. For a monolithic kernel that always loads at 1 MB it could happen when the virtual memory manager is initialised (and could be after a lot of other things happen). For my OS the boot code dynamically allocates pages for "kernel modules", so it needs to happen before the kernel started.
Cheers,
Brendan