Page 1 of 1

Memory

Posted: Mon Jun 28, 2004 11:00 pm
by Ares
Could someone tell me how can I get the amount of memory avaible after enabling the A20 line ? I must find a quick method of geting this value without using any bios or other procedures.

Please help.

RE:Memory

Posted: Mon Jun 28, 2004 11:00 pm
by GT

RE:Memory

Posted: Tue Jun 29, 2004 11:00 pm
by Ares
Well ok, I'll use BIOS's INT 15H but can you give me an example of INT 15H usage ?

RE:Memory

Posted: Tue Jun 29, 2004 11:00 pm
by Fitz
I don't know if you are using GRUB or not as the boot loader, but it will return a memory map.  GRUB is probably using BIOS routines to create that memory map.

RE:Memory

Posted: Tue Jun 29, 2004 11:00 pm
by Ares
But thats the problem it returns nothing in the specified buffer. Just plain old 00000000.

RE:Memory

Posted: Tue Jun 29, 2004 11:00 pm
by Fitz
Hmmm, I would double check and make sure bit 1 in the flags is set for the multiboot header.

I can't imagine GRUB not providing one if you requested one.

RE:Memory

Posted: Tue Jun 29, 2004 11:00 pm
by Ares
Im not using GRUB boot loader. Its my one.

RE:Memory

Posted: Wed Jun 30, 2004 11:00 pm
by Moose
uurr hu,
obviously, you need grub to get the memory map. Grub provides the memory map and unless you do the same in your own bootloader, then you wont get that map.

Grub does use the bios ints to create that memory map. In fact, it does no more than any of us developers would do in real mode to find out about memory.

There are three methods that i am aware of that can get information about memory.

1. CMOS memory. This will tell you how much memory you have. Problem is, it only knows upto 64mb of memory, thus if you have 128mb, it will still say 64mb. This means its unreliable if you query it and find it containing 64mb. It also only knows how much memory you have, gives no info on memory holes, which is what matters.

2. bios ints. Only available in real mode. Problem is different bioses use different ints and older bioses on older boards have lesser functionality for gaining information about the memory than newer boards. So this method is some what a grey area of how much info you can get.

3. Memory probing. Directly writing to every say megabyte of memory, then reading that value back. If its the same, then its available, if its reset to its original state, its not. Problem is, memory holes can be devices, so in effect you could be sending messages to devices, which is not good.

There is not a reliable method to query memory. The grub memory map is not even garunteed but most of the time, accurate. This is because its methods of calculating the memory map is the same as ours.
It has however always given me the correct information before so i have no reason to question its integrity.

Moose

RE:Memory

Posted: Wed Jun 30, 2004 11:00 pm
by Ares
Ok. So lets say that Im going to prob the memory directly. Writing to every megabyte of memory ok. But what if I try to write a megabite of memory that is above the availble memory ? The memory wont wrap around ? For example if I would have 128 MB of memory and if I try to read the 129'th MB of memory I wont read the first one ?

RE:Memory

Posted: Wed Jun 30, 2004 11:00 pm
by Moose
No

The memory you write to just won't exist. As far as i am aware, the processor will send the write message for 129thmb to the address bus for your memory to handle. Since that location does not exist, the message is lost. When you read the location you will get all 0's. So if you write all 1's, then read and its 0's, you have no memory at that point. You should read up on direct probing though, i think it can be dangerous to your hardware if you do not do it correctly.
Some coders say it works, others do not. Its a matter of opinion. All i know is i tried it and the next thing i knew, my test machine (old compaq) was screwed. Giving an error with some code i can't remember.

Moose

RE:Memory

Posted: Fri Jul 02, 2004 11:00 pm
by GT
"The memory wont wrap around ? For example if I would have 128 MB of memory and if I try to read the 129'th MB of memory I wont read the first one ?"

Actually, it very well might.  It does in some systems, doesn't in others.  In order to handle this, every time your probing writes to memory at some location, it should store a value there that's unique to that location.  Then, go back and check what you've previously written -- if any of your previous writes have been overwritten with the new value, you know you've wrapped around.

If you do this every time you move on to the next meg, checking all previous megs, you'll be rather slow.  You can optimize this a bit by noting that wrap-around usually only occurs when you add a new bit to your addresses (i.e. you previous address fit in 22 bits but the new address requires 23), and the location it wraps to is usually that address with the new bit stripped (so, after probing 0x00F08012, you write to 0x01008012 and find you've clobbered what you previous wrote to 0x00008012, because the hardware only uses 24 bits from the processor address lines).  You can use the BSR instruction to easily see if you've added a new significant bit, and rescan for clobbers when the BSR result changes.  That'll speed things up and still catch wrap-around situations most of the time...

RE:Memory

Posted: Fri Jul 02, 2004 11:00 pm
by GT
"No

The memory you write to just won't exist. As far as i am aware, the processor will send the write message for 129thmb to the address bus for your memory to handle. Since that location does not exist, the message is lost."

Not necessarily.  If the machine in question is built to support more memory than it has installed, this is often true.  But if the machine was only expandable to 128MB of memory to begin with, it may be they (the hardware designers) never connected more address lines than necessary to support that.  In that case, when you write to the 129th MB, the RAM doesn't see the high bit in the address (as it's not even connected in the hardware) -- what it sees is a write to the FIRST MB of memory, and responds accordingly.  Due to the unconnected address lines, the RAM sees a different message than the CPU is sending.

This problem is particularly rampant in machines that were built to support a maximum of 16MB of RAM, but is can really occur anywhere, with any motherboard that has a maximum on its expandable RAM less than the maximum the processor can support.

RE:Memory

Posted: Sun Jul 04, 2004 11:00 pm
by Ares
Is probing memory safe ? What can I do ? I can only have problems with the graphics card buffer and the bios. Can I damage some hardwere with probing memory ? Plz help.

RE:Memory

Posted: Sun Jul 04, 2004 11:00 pm
by GT
Depends on the hardware in the machine.  I'm assuming this is not for a standard PC, otherwise you could just use the BIOS.  If you don't know what kind of hardware might be in the machine, probing is probably not safe...