#include <addrspace.h>
Public Methods | |
| AddrSpace (OpenFile *executable) | |
| ~AddrSpace () | |
| void | InitRegisters () |
| void | SaveState () |
| void | RestoreState () |
Private Attributes | |
| TranslationEntry * | pageTable |
| unsigned int | numPages |
|
|
Definition at line 64 of file addrspace.cc. References ASSERT, bzero, noffHeader::code, DEBUG, TranslationEntry::dirty, divRoundUp, FALSE, segment::inFileAddr, noffHeader::initData, NOFFMAGIC, noffHeader::noffMagic, numPages, NumPhysPages, PageSize, pageTable, TranslationEntry::physicalPage, OpenFile::ReadAt, TranslationEntry::readOnly, segment::size, SwapHeader, TRUE, noffHeader::uninitData, TranslationEntry::use, UserStackSize, TranslationEntry::valid, segment::virtualAddr, TranslationEntry::virtualPage, and WordToHost.
00065 {
00066 NoffHeader noffH;
00067 unsigned int i, size;
00068
00069 executable->ReadAt((char *)&noffH, sizeof(noffH), 0);
00070 if ((noffH.noffMagic != NOFFMAGIC) &&
00071 (WordToHost(noffH.noffMagic) == NOFFMAGIC))
00072 SwapHeader(&noffH);
00073 ASSERT(noffH.noffMagic == NOFFMAGIC);
00074
00075 // how big is address space?
00076 size = noffH.code.size + noffH.initData.size + noffH.uninitData.size
00077 + UserStackSize; // we need to increase the size
00078 // to leave room for the stack
00079 numPages = divRoundUp(size, PageSize);
00080 size = numPages * PageSize;
00081
00082 ASSERT(numPages <= NumPhysPages); // check we're not trying
00083 // to run anything too big --
00084 // at least until we have
00085 // virtual memory
00086
00087 DEBUG('a', "Initializing address space, num pages %d, size %d\n",
00088 numPages, size);
00089 // first, set up the translation
00090 pageTable = new TranslationEntry[numPages];
00091 for (i = 0; i < numPages; i++) {
00092 pageTable[i].virtualPage = i; // for now, virtual page # = phys page #
00093 pageTable[i].physicalPage = i;
00094 pageTable[i].valid = TRUE;
00095 pageTable[i].use = FALSE;
00096 pageTable[i].dirty = FALSE;
00097 pageTable[i].readOnly = FALSE; // if the code segment was entirely on
00098 // a separate page, we could set its
00099 // pages to be read-only
00100 }
00101
00102 // zero out the entire address space, to zero the unitialized data segment
00103 // and the stack segment
00104 bzero(machine->mainMemory, size);
00105
00106 // then, copy in the code and data segments into memory
00107 if (noffH.code.size > 0) {
00108 DEBUG('a', "Initializing code segment, at 0x%x, size %d\n",
00109 noffH.code.virtualAddr, noffH.code.size);
00110 executable->ReadAt(&(machine->mainMemory[noffH.code.virtualAddr]),
00111 noffH.code.size, noffH.code.inFileAddr);
00112 }
00113 if (noffH.initData.size > 0) {
00114 DEBUG('a', "Initializing data segment, at 0x%x, size %d\n",
00115 noffH.initData.virtualAddr, noffH.initData.size);
00116 executable->ReadAt(&(machine->mainMemory[noffH.initData.virtualAddr]),
00117 noffH.initData.size, noffH.initData.inFileAddr);
00118 }
00119
00120 }
|
|
|
Definition at line 127 of file addrspace.cc. References pageTable.
00128 {
00129 delete pageTable;
00130 }
|
|
|
Definition at line 143 of file addrspace.cc. References DEBUG, NextPCReg, numPages, NumTotalRegs, PageSize, PCReg, and StackReg. Referenced by StartProcess.
00144 {
00145 int i;
00146
00147 for (i = 0; i < NumTotalRegs; i++)
00148 machine->WriteRegister(i, 0);
00149
00150 // Initial program counter -- must be location of "Start"
00151 machine->WriteRegister(PCReg, 0);
00152
00153 // Need to also tell MIPS where next instruction is, because
00154 // of branch delay possibility
00155 machine->WriteRegister(NextPCReg, 4);
00156
00157 // Set the stack register to the end of the address space, where we
00158 // allocated the stack; but subtract off a bit, to make sure we don't
00159 // accidentally reference off the end!
00160 machine->WriteRegister(StackReg, numPages * PageSize - 16);
00161 DEBUG('a', "Initializing stack register to %d\n", numPages * PageSize - 16);
00162 }
|
|
|
Definition at line 183 of file addrspace.cc. References numPages, and pageTable. Referenced by StartProcess.
|
|
|
Definition at line 172 of file addrspace.cc.
00173 {}
|
|
|
Definition at line 37 of file addrspace.h. Referenced by AddrSpace, InitRegisters, and RestoreState. |
|
|
Definition at line 35 of file addrspace.h. Referenced by AddrSpace, RestoreState, and ~AddrSpace. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002