Download presentation
Presentation is loading. Please wait.
Published bySterling Burkett Modified over 9 years ago
1
Chapter 3 Memory Management
2
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
3
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
4
Loader Logical address spaces – The starting address of this space is 0 This logical address to a physical address – CPU and OS
5
3.2 Memory Management Schemes Contiguous Allocation Paging Segmentation Segmentation with Paging
6
3.3 Swapping 略
7
3.4 MIPS Simulator 3.4.1 Components of MIPS Machine
8
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;
9
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);
10
3.4.2 Instruction Interpretation OneInstruction(Instruction*) see P46
11
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
12
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;
13
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
14
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
15
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
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.