00001 // addrspace.h 00002 // Data structures to keep track of executing user programs 00003 // (address spaces). 00004 // 00005 // For now, we don't keep any information about address spaces. 00006 // The user level CPU state is saved and restored in the thread 00007 // executing the user program (see thread.h). 00008 // 00009 // Copyright (c) 1992-1996 The Regents of the University of California. 00010 // All rights reserved. See copyright.h for copyright notice and limitation 00011 // of liability and disclaimer of warranty provisions. 00012 00013 #ifndef ADDRSPACE_H 00014 #define ADDRSPACE_H 00015 00016 #include "copyright.h" 00017 #include "filesys.h" 00018 00019 #define UserStackSize 1024 // increase this as necessary! 00020 00021 class AddrSpace { 00022 public: 00023 AddrSpace(); // Create an address space. 00024 ~AddrSpace(); // De-allocate an address space 00025 00026 bool Load(char *fileName); // Load a program into addr space from 00027 // a file 00028 // return false if not found 00029 00030 void Execute(); // Run a program 00031 // assumes the program has already 00032 // been loaded 00033 00034 void SaveState(); // Save/restore address space-specific 00035 void RestoreState(); // info on a context switch 00036 00037 // Translate virtual address _vaddr_ 00038 // to physical address _paddr_. _mode_ 00039 // is 0 for Read, 1 for Write. 00040 ExceptionType Translate(unsigned int vaddr, unsigned int *paddr, int mode); 00041 00042 private: 00043 TranslationEntry *pageTable; // Assume linear page table translation 00044 // for now! 00045 unsigned int numPages; // Number of pages in the virtual 00046 // address space 00047 00048 void InitRegisters(); // Initialize user-level CPU registers, 00049 // before jumping to user code 00050 00051 }; 00052 00053 #endif // ADDRSPACE_H