chapter 3 memory management. 3.1 from programs to address space 3 steps to run the programs of an...

Post on 15-Dec-2015

215 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Chapter 3 Memory Management

3.1 From Programs To Address Space

• 3 steps to run the programs of an application– A Compiler translates the source code of each

module to its object module, – A linker links all the object modules to form a

single binary executable also known as load module,

– A loader loads the load module in the memory of the computer

The Linker

• Each object module has its own sections of text, initialized data, symbol table and relocation information

• The task of the linker is to merge all the object modules into one load module

• This requires relocating the object modules

Loader

• Logical address spaces– The starting address of this space is 0

• This logical address to a physical address– CPU and OS

3.2 Memory Management Schemes

• Contiguous Allocation • Paging • Segmentation • Segmentation with Paging

3.3 Swapping

• 略

3.4 MIPS Simulator

• 3.4.1 Components of MIPS Machine

3.4.1 Components of MIPS Machine

• The major components of the machine – user registers: int registers[NumTotalRegs]; – main memory: char *mainMemory; – page table for the current user process:

TranslationEntry *pageTable; – tlb (table look-ahead buffer): TranslationEntry *tlb;

The machine operations

• 129 bool ReadMem(int addr, int size, int* value); • 130 bool WriteMem(int addr, int size, int value); • 116 int ReadRegister(int num); // read a register• 118 void WriteRegister(int num, int value); • 114 void Run(); // Run a user program ... • 124 void OneInstruction(Instruction *instr); • 142 void RaiseException(ExceptionType which, int

badVAddr); • 135 ExceptionType Translate(int virtAddr, int* physAddr, int

size,bool writing);

3.4.2 Instruction Interpretation

• OneInstruction(Instruction*) see P46

3.5 Nachos User Programs

• Use gcc MIPS cross compiler to produce the executable in the normal UNIXCOFF format

• Use program coff2noff made in directory ../bin/ to convert it to the Nachos NOFF format– NOFF format is the format of binary executables

used by Nachos. – It is similar to COFF format – See p48

NOFF format• #define NOFFMAGIC 0xbadfad• typedef struct segment {

– int virtualAddr; /* location of segment in virt addr space */ – int inFileAddr; /* location of segment in this file */ – int size; /* size of segment */ 16 }

• } Segment;• typedef struct noffHeader {

– int noffMagic; /* should be NOFFMAGIC */ – Segment code; /* executable code segment */ – Segment initData; /* initialized data segment */ – Segment uninitData; /* uninitialized data segment */

• } NoffHeader;

3.6 Address Space of User Process in Nachos

• Nachos uses paging• An address space is formed by calling the

constructor of AddrSpace• Nachos uses the a stub file system built on top

of the UNIX system, see p51.• Create address space– Page the table– Code – InitData

3.7 Memory Management in Nachos

• Address translation see p54• both page table and TLB• the alignment of the logical address is checked• The page number and the offset of the logical

address are calculated• The TLB can translation generates a pagefault• Physical address is also checked

3.8 From Thread to User Process

• After the thread constructs the address space and initializes the registers, it becomes a user process running on the simulated MIPS machine by calling machine->Run()

• If both the Nachos kernel and the user program were running on a real MIPS raw machine, a kernel thread becomes the user process by jumping to the first instruction of the code section of the address space

top related