00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "copyright.h"
00019 #include "system.h"
00020 #include "addrspace.h"
00021 #include "noff.h"
00022
00023 extern "C" {
00024 int bzero(char *, int);
00025 };
00026
00027
00028
00029
00030
00031
00032
00033
00034 static void
00035 SwapHeader (NoffHeader *noffH)
00036 {
00037 noffH->noffMagic = WordToHost(noffH->noffMagic);
00038 noffH->code.size = WordToHost(noffH->code.size);
00039 noffH->code.virtualAddr = WordToHost(noffH->code.virtualAddr);
00040 noffH->code.inFileAddr = WordToHost(noffH->code.inFileAddr);
00041 noffH->initData.size = WordToHost(noffH->initData.size);
00042 noffH->initData.virtualAddr = WordToHost(noffH->initData.virtualAddr);
00043 noffH->initData.inFileAddr = WordToHost(noffH->initData.inFileAddr);
00044 noffH->uninitData.size = WordToHost(noffH->uninitData.size);
00045 noffH->uninitData.virtualAddr = WordToHost(noffH->uninitData.virtualAddr);
00046 noffH->uninitData.inFileAddr = WordToHost(noffH->uninitData.inFileAddr);
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 AddrSpace::AddrSpace(OpenFile *executable)
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
00076 size = noffH.code.size + noffH.initData.size + noffH.uninitData.size
00077 + UserStackSize;
00078
00079 numPages = divRoundUp(size, PageSize);
00080 size = numPages * PageSize;
00081
00082 ASSERT(numPages <= NumPhysPages);
00083
00084
00085
00086
00087 DEBUG('a', "Initializing address space, num pages %d, size %d\n",
00088 numPages, size);
00089
00090 pageTable = new TranslationEntry[numPages];
00091 for (i = 0; i < numPages; i++) {
00092 pageTable[i].virtualPage = i;
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;
00098
00099
00100 }
00101
00102
00103
00104 bzero(machine->mainMemory, size);
00105
00106
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 }
00121
00122
00123
00124
00125
00126
00127 AddrSpace::~AddrSpace()
00128 {
00129 delete pageTable;
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 void
00143 AddrSpace::InitRegisters()
00144 {
00145 int i;
00146
00147 for (i = 0; i < NumTotalRegs; i++)
00148 machine->WriteRegister(i, 0);
00149
00150
00151 machine->WriteRegister(PCReg, 0);
00152
00153
00154
00155 machine->WriteRegister(NextPCReg, 4);
00156
00157
00158
00159
00160 machine->WriteRegister(StackReg, numPages * PageSize - 16);
00161 DEBUG('a', "Initializing stack register to %d\n", numPages * PageSize - 16);
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 void AddrSpace::SaveState()
00173 {}
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 void AddrSpace::RestoreState()
00184 {
00185 machine->pageTable = pageTable;
00186 machine->pageTableSize = numPages;
00187 }
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees