main

Chapter 8 - Main Memory

The base register holds the smallest legal physcial memory address; The limit register specifies the size of the range.

E.g.

accessible process memory (inclusive)

  • base: 300040
  • limit: 120900
          ---------------------------|
        0 |                          |
          |  Operating System        |
          |                          |
   256000 |--------------------------|
          |                          |
          | process                  |
          |                          |
   300040 |--------------------------| <--- (300040) base
          |                          |
          | process                  |
          |                          |
   420940 |--------------------------| <--- (120900) limit
          |                          |
          | process                  |
          |                          |
   880000 |--------------------------|
          |                          |
          |                          |
          |                          |
  1024000 |--------------------------|

Protection of memory space is accomplished by having the CPU hardware compare every address generated in user mode with registers. Any attempt by a program executing in user mode to access OS memory or other users’ memory results in a trap to the operating system, which treats the attempt as fatal error.

This scheme prevents a user program from modifying code of data structures of either the operating system or other users.

The base and limit registers can only be loaded by the operating system which uses a special privileged instruction. Priviliged instructions can only be executed in kernel mode by the operating system.

An operating system that provides multiprocessing must store the process state and load the process state when context switching.

Address Binding

Usually, a program resides on a disk as a binary executable file. To be executed the program must be loaded into memory and placed within a process.

The processes on the disk that are waiting to be brought into memory for execution form the input queue. When a process terminates its memory space is marked as available.

Addresses in the source program are generally symbolic. A compiler typically binds these symbolic addresses to relocatable addresses (such as 14 bytes from the beginning of this module). The linkage editor or loader in turn binds the relocatable addresses to absolute addresses (such as 74014).

Each binding is a mapping from one address space to another.

  • Compile time binding: absolute code is generated to use hardcoded addresses.
    • MS-DOS COM format does this.
    • If location of address changes then the program is broken.
  • Load time binding: The compiler generates relocatable code where final binding is delayed until load time.
    • If the starting address changes, then we need to reload the user code to adjust.
  • Execution time binding: binding can be delayed until run time but special hardware must be available for this scheme to work.

Logical vs. Physical Address Space

CPU generated addresses are referred to as a logical address or virtual address. An address seen by the memory unit, i.e. loaded into the memory-address register, is called physcial address.

The compile-time and load-time address-binding methods generate identical logical and physical addresses. Execution-time addresses result in differing logical and physical addresses.

                                                                         ------------
                                                                         |          |
                                                                         |          |
                                |------------|                           |          |
                                | relocation |                           |          |
                                | register   |                           |          |
                                |            |                           |          |
                                | | 14000 |  |                           |          |
                                |            |                           |          |
-------                         |     _      |                           |          |
| CPU | --> logical address --> |    (+)     | ---> physical address --> |  memory  |
-------          346            |     -      |           14346           |          |
                                |            |                           |          |
                                |            |                           |          |
                                |------------|                           |          |
                                     MMU                                 |          |
                                                                         |          |
                                                                         |          |
                                                                         ------------

The memory-management unit (MMU) maps virtual to physical addresses.

The base register is referred to as the relocation register in the virtual address scheme.