How can RAM contain a "memory map" if RAM is unaware of the overall system?

3

3

This question concerns hardware more than software. Basically, citing from this article on memory maps, it says that:

In computer science, a memory map is a structure of data (which usually resides in memory itself) that indicates how memory is laid out.

Source: http://en.wikipedia.org/wiki/Memory_map

There is extreme ambiguity in regards to that very opening sentence. First off, how can RAM know how to lay memory out for the CPU's address space if the purpose of RAM depends on the system?

Second, RAM can be changed. If the data resides in the RAM, all RAM chips are hardwired to have a structure describing memory? That doesn't make sense, because from the scope of the CPU it's vague, and makes even less sense when you look at it from the scope of the RAM(a system can have different memory at any time, different hardware, different addresses, different architecture, etc.).

Third, the article claims that the memory map is passed to the firmware for an OS. That would only make sense if the RAM is hardwired, or the map is synchronous with the CPU's address space.

Basically, I am 100% clueless and lost on this. I do not understand in any way how this makes clear sense. RAM can not map addresses out for a system if it has no knowledge of the system's structure.

user274686

Posted 2013-11-16T22:26:34.327

Reputation:

First of, the Wikipedia article is somewhat vague (they indicate the lack of good sources). A little more research might give you more info. Second, it is not desirable to access every byte inside the RAM, hence it is "partitioned" and accessed through addresses, that usually are 4 byte or 8 or 16 or 32 byte long (can't remember the details though). – Doktoro Reichard – 2013-11-16T22:35:11.120

Answers

4

In computer science, a memory map is a structure of data (which usually resides in memory itself) that indicates how memory is laid out.

Source: http://en.wikipedia.org/wiki/Memory_map

There is extreme ambiguity in regards to that very opening sentence. First off, how can RAM know how to lay memory out for the CPU's address space if the purpose of RAM depends on the system?

Normally the memory map itself is saved into some kind of non-volatile memory on the device, which loads the memory map into the processor/MMU when the system boots up. As someone using the device, you can change the memory map yourself, although the layout is less relevant in systems running operating systems, since it then becomes the OS's job to control memory access. The DIY approach is usually only required in embedded systems where you yourself are physically connecting RAM/ROM IC's to an existing circuit.

Moving on to modern-day computer systems...

Second, RAM can be changed. If the data resides in the RAM, all RAM chips are hardwired to have a structure describing memory? That doesn't make sense, because from the scope of the CPU it's vague, and makes even less sense when you look at it from the scope of the RAM(a system can have different memory at any time, different hardware, different addresses, different architecture, etc.).

Third, the article claims that the memory map is passed to the firmware for an OS. That would only make sense if the RAM is hardwired, or the map is synchronous with the CPU's address space.

Exactly - this is why RAM itself provides serial presence detect (SPD) so the BIOS/UEFI can determine what RAM is in your system (and if it has changed since the last time the computer was started!).

Also, x86 memory management units come with virtual-memory support made for use with operating systems. The MMU itself bridges the physica hardwired RAM layout (which is just a large number of data/address lines connected to all the DIMMs on the motherboard), so this is abstracted away from the CPU itself (even if the MMU and CPU are on the same die, they are logically two different "units").

RAM can not map addresses out for a system if it has no knowledge of the system's structure.

You're correct, the RAM itself cannot (which is why they have SPD/XMP profiles) - the CPU/MMU will identify what resources are available in the system each and every time you start your computer. Furthermore, this process is abstracted away from anything under the operating system since most OS'es use virtual memory now, which completely separates the concept of system memory from physical RAM (most people are familiar with this concept through paging, where the OS can place part of a processes' memory on-disk to free up RAM for other applications).

Breakthrough

Posted 2013-11-16T22:26:34.327

Reputation: 32 927

2

The article says

In the boot process, a memory map is passed on from the firmware in order to instruct an operating system kernel about memory layout. It contains the information regarding the size of total memory, any reserved regions and may also provide other details specific to the architecture.

And then it says

The PC BIOS provides a set of routines that can be used by operating system to get memory layout. Some of the available routines are: BIOS Function: INT 0x15, AX=0xE801 This BIOS interrupt call is used by the running OS to get the memory size for 64MB+ configurations

To answer your first question then. The article mentions nothing of cpu address space, and it's not easy to even find that term used on the internet! 'cos CPUs have some registers(cpu memory locations), but not like a big space that needs a map or some kind of index to find things! And the term CPU doesn't even occur anywhere in that article you linked to. The article says RAM GETS the info from elsewhere in the system, not from the RAM. It gets it from the BIOS (the BIOS uses CMOS memory.. which is memory that has a battery to power it... and is set in the BIOS setup manually.. but can find some things automatically). And possibly the memory map has a flexible aspect and new things are loaded in. But RAM starts without any memory map put in.

That answers your second question.

And in your third question you got it wrong, the article doesn't say memory map is passed to the firmware - NO!! It says the opposite In the boot process, a memory map is passed on from the firmware (the firmware is not RAM, there is no RAM firmware).

The basic program of the BIOS would be firmware. But it can store data which can be changed.

And as an additional note, There is something called SPD.. which DDR RAM uses to send data to the BIOS on request (as mentioned by this rather advanced article) http://www.simmtester.com/page/news/showpubnews.asp?num=153 SPD is mentioned in the BIOS.. I've configured a BIOS on a system where it said get RAM details from SPD, of enter them manually. (so one could overclock the RAM). No memory map of course.. just something basic like what speed it is meant to run at and other stuff SPD gets that is mentioned in that article. Other things in the BIOS are manually entered data.

And to view the or a memory map

enter image description here

barlop

Posted 2013-11-16T22:26:34.327

Reputation: 18 677

0

Quick answer: The RAM doesn't "know" anything. Whatever structures are stored in RAM that help determine the semantics of other contents of RAM, are built by the operating system.

Jamie Hanrahan

Posted 2013-11-16T22:26:34.327

Reputation: 19 777

0

Really old Apple II computers had a minimum of 4k RAM and DIP switches to set if more was added. During start-up the position of the switches are read and the memory map setup accordingly. Early IBM PC systems also had DIP switches and 64k minimum RAM. The memory map listed where various things like the contents of the display, disk buffers etc were located in memory and what address ranges have RAM.

So at least some of the memory map is know - a minimum amount of RAM at a known location. Some of that memory is used to store the memory map and other information used by the code that detects the rest and builds the full memory map.

Modern systems do a lot more auto-configuration (no more DIP switches) using things like SPD chips on RAM modules to find out it's size and layout but the basics are the same. Some minmum amount of memory has to be at a know location.

Brian

Posted 2013-11-16T22:26:34.327

Reputation: 8 439

0

There is definitely some confusion happening here, mostly due to the fact that the article is trying to pack in various different, but related things into one place.

There are two primary types of “memory-map” which are completely different things, using the same name.

  • Memory Layout

    What you are seeing in regards to the BIOS and hardware, should really be called more of a memory-layout. This is a design of how memory is laid out and used. In this context, certain parts of memory are assigned to be used for different things.

    This map doesn’t usually exist in any tangible way in the hardware, it is more of a napkin or whiteboard diagram which the designers come up with and implement in hardware/software using arrays and indices.

  • Memory Allocation

    Another usage of the term memory-map is in regards to memory allocation. In this case, a memory-allocation map is a list that the memory-manager of the OS uses to keep track of what parts of memory have been assigned to programs, and what parts of memory are free. Because different programs allocate and free variously-sized chunks of memory in indeterminate patterns, memory gets fragmented just like a disk-drive does when files of various sizes are created and deleted.

    Since memory gets fragmented, the OS cannot simply hand out a chunk of memory of any requested size to every program that comes along. There will be free blocks of different sizes surrounded by used blocks. To know how big each free block is, the memory-manager will keep a “map” of memory which it marks used or free whenever it allocates or releases memory to/from programs. This map is just like a disk-map (figure 1), and you can even see it with tools like VMMap (figure 2). (The specific layout used in the visualization may vary, for example, most disk-maps will show the drive as two-dimensional while most memory-tools will show memory as one-dimensional, but that’s just a design choice.)

    This allocation map is a literal map that is actually an array that is stored in memory.

  • (Memory mapping)

    (When it comes to the BIOS and hardware, there is also the term memory-mapping which refers to mapping parts of hardware devices on to memory so that you can read and write to the device by simply reading and writing to memory addresses just like you would access normal memory. However, this is an even more different usage of the term, and thus adds to the confusion. In this context, “map” doesn’t mean a layout, but rather more like a mathematical mapping where one thing is assigned an analog/alias to something else.)


Figure 1: Vopt’s disk-map

Figure 2: VMMap

Synetech

Posted 2013-11-16T22:26:34.327

Reputation: 63 242