a general mechanism: limited direct execution (LDE)
:
the idea is simple, for the most part, let program run directly on hardware.
let’s see one example
1 | 128: movl 0x0(%ebx), %eax ;load 0+ebx into eax |
When these instructions run, from the perspective of the process, the following memory accesses take place.
- Fetch instruction at address 128
- Execute this instruction (load from address 15 KB)
- Fetch instruction at address 132
- Execute this instruction (no memory reference)
- Fetch the instruction at address 135
- Execute this instruction (store to address 15 KB)
how can we relocate this process in memory in a way that is transparent
to the process? How can we provide the illusion of a virtual address space starting at 0, when in reality the address space is located at some other physical address?
An example of what physical memory might look like once this process’s address space has been placed in memory is found in Figure
the OS using the first slot of physical memory for itself, and that it has relocated the process from the example above into the slot starting at physical memory address 32 KB. The other two slots are free (16 KB-32 KB and 48 KB-64 KB).
Dynamic (Hardware-based) Relocation
we’ll need two hardware registers within each CPU: one is called the base register
, and the other the bounds
(sometimes called a limitregister). This base-and-bounds pair is going to allow us to place the address space anywhere we’d like in physical memory, and do so while ensuring that the process can only access its own address space.
Each memory reference generated by the process is avirtual address
; the hardware in turn adds the contents of the base register to this address and the result is a physical address that can be issued to the memory system
Transforming a virtual address into a physical address is exactly the technique we refer to as address translation
; that is, the hardware takes a virtual address the process thinks it is referencing and transforms it into a physical address which is where the data actually resides. Because this relocation of the address happens at runtime, and because we can move address spaces even after the process has started running, the technique is often referred to asdynamic relocation.