Detect Memory Size

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
User avatar
Tolga
Member
Member
Posts: 28
Joined: Thu Nov 16, 2006 12:08 am

Detect Memory Size

Post by Tolga »

Hi.

How can detect memory size in PROTECTED MODE? Please dont say that you can detect in "Virtual Mode". :cry: I need this for memory management.

Thanks.
User avatar
gaf
Member
Member
Posts: 349
Joined: Thu Oct 21, 2004 11:00 pm
Location: Munich, Germany

Post by gaf »

You're not the first to ask that question (Read the FAQ) ;)

cheers,
gaf
xsix
Member
Member
Posts: 59
Joined: Tue Oct 24, 2006 10:52 am

Post 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
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Post 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.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Post 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
Jabus
Member
Member
Posts: 39
Joined: Sun Jan 07, 2007 7:54 am

Post 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?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply