1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 39 unchanged lines hidden (view full) --- 48using namespace std; 49using namespace MipsISA; 50 51MipsProcess::MipsProcess(ProcessParams * params, ObjectFile *objFile) 52 : Process(params, objFile) 53{ 54 // Set up stack. On MIPS, stack starts at the top of kuseg 55 // user address space. MIPS stack grows down from here |
56 Addr stack_base = 0x7FFFFFFF; |
57 |
58 Addr max_stack_size = 8 * 1024 * 1024; 59 |
60 // Set pointer for next thread stack. Reserve 8M for main stack. |
61 Addr next_thread_stack_base = stack_base - max_stack_size; |
62 63 // Set up break point (Top of Heap) |
64 Addr brk_point = objFile->dataBase() + objFile->dataSize() + 65 objFile->bssSize(); 66 brk_point = roundUp(brk_point, PageBytes); |
67 68 // Set up region for mmaps. Start it 1GB above the top of the heap. |
69 Addr mmap_end = brk_point + 0x40000000L; 70 71 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size, 72 next_thread_stack_base, mmap_end); |
73} 74 75void 76MipsProcess::initState() 77{ 78 Process::initState(); 79 80 argsInit<uint32_t>(PageBytes); --- 60 unchanged lines hidden (view full) --- 141 int space_needed = 142 argv_array_size + 143 envp_array_size + 144 auxv_array_size + 145 arg_data_size + 146 env_data_size; 147 148 // set bottom of stack |
149 memState->setStackMin(memState->getStackBase() - space_needed); |
150 // align it |
151 memState->setStackMin(roundDown(memState->getStackMin(), pageSize)); 152 memState->setStackSize(memState->getStackBase() - memState->getStackMin()); |
153 // map memory |
154 allocateMem(memState->getStackMin(), roundUp(memState->getStackSize(), 155 pageSize)); |
156 |
157 // map out initial stack contents; leave room for argc 158 IntType argv_array_base = memState->getStackMin() + intSize; |
159 IntType envp_array_base = argv_array_base + argv_array_size; 160 IntType auxv_array_base = envp_array_base + envp_array_size; 161 IntType arg_data_base = auxv_array_base + auxv_array_size; 162 IntType env_data_base = arg_data_base + arg_data_size; 163 164 // write contents to stack 165 IntType argc = argv.size(); 166 167 argc = htog((IntType)argc); 168 |
169 initVirtMem.writeBlob(memState->getStackMin(), (uint8_t*)&argc, intSize); |
170 171 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 172 173 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 174 175 // Copy the aux vector 176 for (typename vector<auxv_t>::size_type x = 0; x < auxv.size(); x++) { 177 initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize, --- 8 unchanged lines hidden (view full) --- 186 const Addr addr = auxv_array_base + 2 * intSize * (auxv.size() + i); 187 initVirtMem.writeBlob(addr, (uint8_t*)&zero, intSize); 188 } 189 190 ThreadContext *tc = system->getThreadContext(contextIds[0]); 191 192 setSyscallArg(tc, 0, argc); 193 setSyscallArg(tc, 1, argv_array_base); |
194 tc->setIntReg(StackPointerReg, memState->getStackMin()); |
195 196 tc->pcState(getStartPC()); 197} 198 199 200MipsISA::IntReg 201MipsProcess::getSyscallArg(ThreadContext *tc, int &i) 202{ --- 24 unchanged lines hidden --- |