Courses/Computer Science/CPSC 457.F2013/Lecture Notes/MemAddr

From wiki.ucalgary.ca
< Courses‎ | Computer Science‎ | CPSC 457.F2013‎ | Lecture Notes
Revision as of 21:20, 13 October 2013 by Vrvardeleon (talk | contribs) (Scribe Notes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Addressing Memory

This will be an overview of basic concepts in addressing memory on the IA-32 architecture. We will revisit some basic hardware support (i.e., segments, segment selectors, segment registers, segment descriptors) and more closely examine the support available for paging (MMU, page directories, page tables, TLBs).

The OS cooperates with the MMU via a set of mappings called page tables to provide independent physical locations for the contents of every process's address space.

Terminology

  • logical address
  • linear address
  • virtual address
  • physical address
  • segmentation
  • paging
  • pages
  • page tables
  • TLB
  • MMU

Class Notes and Code

Here is our "one.c" program from last session:

[cpsc@cpsc457 procaddr]$ cat one.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define DEFAULT_SECONDS  10
int x_michael = 0xAbad1dea;
int seconds = DEFAULT_SECONDS;
int main(int argc,
 	  char* argv[])
{
  if(2!=argc)
  {
    fprintf(stderr, "bad args.\n\t%s [seconds]\n", argv[0]);
    return -1;
  }
  seconds = strtol(argv[1], NULL, 10);
  fprintf(stdout, 
          "process-%d sleeping for %d seconds...\n", 
          getpid(), 
          seconds);
  sleep(seconds);
  x_michael = 0xDEADBEEF;
  fprintf(stdout, 
 	   "process-%d value of x_michael=0x%x...\n", 
          getpid(),
          x_michael);
  return 0;
}
[cpsc@cpsc457 procaddr]$

We can see what the virtual address of the global variable x_michael is by examining the ELF. The compiler has assigned address 0x08049858

[cpsc@cpsc457 procaddr]$ objdump -t one | grep michael
08049858 g     O .data	00000004              x_michael
[cpsc@cpsc457 procaddr]$

This session is about how the MMU assists the OS in mapping that virtual address to a specific physical location.

Example

This example will use the basic two-level scheme on x86.

Our task is to translate the address 0x08049858 to a physical one. Since Linux uses a flat segment model, the logical address is ds:0x08049858, which reduces to 0x08049858 (the virtual or linear address).

We take the virtual address (i.e., linear address) 0x08049858 and treat it as a series of indexes into data structures maintained by the operating system and of which the MMU is aware exist.

0x08049858
 08          04          98          58           //original address
[0000 1000] [0000 0100] [1001 1000] [0101 1000]   //translate to binary notation
[0000100000] [0001001001] [100001011000]          //gather into groups of 10, 10, 12 bits
[2^5]        [2^6+2^3+2^0] [2048+64+16+8]
[32]         [73]          [2136]

Notes

Scribe Notes

Reading

  • MOS: 3.2.3
  • LKD: Chapter 15, pages 320-322