Re: How does a processor generate an address?




Mary wrote:
> What do you mean by "with all programs linked as if they were loaded
> starting at address 0"? And why do we need to do this? Do programs
> always need to run at the start of the address region?

Programs can be written to load at any (virtual) address and start at
any address. Executables usually have a header at the start of the
file that specifies LOAD address, RUN address, etc.

> Are the "Starting addresses" from the diagram above all "virtual
> addresses"? In other words, they need to be translated to a phyical
> address when its their turn to run.

Yes.

Here's another example. Here's a physical memory diagram showing three
loaded processes, A, B and C:
.. .
| |
+--------+ 90000
| PROG A |
+--------+ 80000
| PROG B |
+--------+ 70000
| PROG A |
+--------+ 60000
| PROG B |
+--------+ 50000
| |
+ PROG C + 40000
| |
+--------+ 30000
| PROG A |
+--------+ 20000
| PROG C |
+--------+ 10000
| |
.. .

Notice that the programs are scattered throughout physical memory.

Now imagine PROG A is loaded into virtual address 40000. This is what
PROG A sees (virtual addresses):

.. .
| |
+--------+ 70000
| |
+ + 60000
| PROG A |
+ + 50000
| |
+--------+ 40000
| |
.. .

i.e. it sees a contiguous memory map. This is achieved using the maps
(or page tables) in the MMU.

PROG A MMU Table
Virtual -> Physical
40000 80000
50000 20000
60000 60000

See how there's no correlation to the order of pages in the virtual
address space and the order in the physical address space. Physical
pages are used in any order, with the MMU tables configured as
appropriate.



When the CPU decides to stop running PROG A and start running PROG B,
it sets up a new virtual -> physical map:

PROG B MMU Table
Virtual -> Physical
40000 50000
50000 70000

In this case PROG B, just like PROG A, is loaded at virtual address
40000.


This is, of course, heavily simplified.



Good luck.

Paul.

.