TIP: HARDWARE-BASED DYNAMIC RELOCATION
With dynamic relocation, a little hardware goes a long way. Namely, a
base register is used to transformvirtual addresses (generated by the program)
into physical addresses. A bounds (or limit) register ensures that
such addresses are within the confines of the address space. Together
they provide a simple and efficient virtualization of memory.
Now you might be asking: what happened to that bounds (limit) register?
After all, isn’t this the base and bounds approach? Indeed, it is. As
you might have guessed, the bounds register is there to help with protection.
Specifically, the processor will first check that the memory reference
is within bounds to make sure it is legal; in the simple example above, the
bounds register would always be set to 16 KB. If a process generates a virtual
address that is greater than the bounds, or one that is negative, the
CPU will raise an exception, and the process will likely be terminated.
The point of the bounds is thus to make sure that all addresses generated
by the process are legal and within the “bounds” of the process.
We should note that the base and bounds registers are hardware structures
kept on the chip (one pair per CPU). Sometimes people call the
part of the processor that helps with address translation the memory
management unit (MMU); as we develop more sophisticated memorymanagement
techniques, we will be adding more circuitry to the MMU.
A small aside about bound registers, which can be defined in one of
two ways. In one way (as above), it holds the size of the address space,
and thus the hardware checks the virtual address against it first before
adding the base. In the second way, it holds the physical address of the
end of the address space, and thus the hardware first adds the base and
thenmakes sure the address iswithin bounds. Bothmethods are logically
equivalent; for simplicity, we’ll usually assume the former method.
Example Translations
To understand address translation via base-and-bounds in more detail,
let’s take a look at an example. Imagine a processwith an address space of
size 4 KB (yes, unrealistically small) has been loaded at physical address
16 KB. Here are the results of a number of address translations:
Virtual Address Physical Address
0 ! => 16 KB
1 KB ! => 17 KB
3000 ! => 19384
4400 ! => Fault (out of bounds)
As you can see from the example, it is easy for you to simply add the
base address to the virtual address (which can rightly be viewed as an
offset into the address space) to get the resulting physical address. Only
if the virtual address is “too big” or negative will the result be a fault,
causing an exception to be raised.