process.cc (11886:43b882cada33) process.cc (11905:4a771f8756ad)
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
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 memState->stackBase = 0x7FFFFFFF;
56 Addr stack_base = 0x7FFFFFFF;
57
57
58 Addr max_stack_size = 8 * 1024 * 1024;
59
58 // Set pointer for next thread stack. Reserve 8M for main stack.
60 // Set pointer for next thread stack. Reserve 8M for main stack.
59 memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024);
61 Addr next_thread_stack_base = stack_base - max_stack_size;
60
61 // Set up break point (Top of Heap)
62
63 // Set up break point (Top of Heap)
62 memState->brkPoint = objFile->dataBase() + objFile->dataSize() +
63 objFile->bssSize();
64 memState->brkPoint = roundUp(memState->brkPoint, PageBytes);
64 Addr brk_point = objFile->dataBase() + objFile->dataSize() +
65 objFile->bssSize();
66 brk_point = roundUp(brk_point, PageBytes);
65
66 // Set up region for mmaps. Start it 1GB above the top of the heap.
67
68 // Set up region for mmaps. Start it 1GB above the top of the heap.
67 memState->mmapEnd = memState->brkPoint + 0x40000000L;
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);
68}
69
70void
71MipsProcess::initState()
72{
73 Process::initState();
74
75 argsInit<uint32_t>(PageBytes);

--- 60 unchanged lines hidden (view full) ---

136 int space_needed =
137 argv_array_size +
138 envp_array_size +
139 auxv_array_size +
140 arg_data_size +
141 env_data_size;
142
143 // set bottom of stack
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
144 memState->stackMin = memState->stackBase - space_needed;
149 memState->setStackMin(memState->getStackBase() - space_needed);
145 // align it
150 // align it
146 memState->stackMin = roundDown(memState->stackMin, pageSize);
147 memState->stackSize = memState->stackBase - memState->stackMin;
151 memState->setStackMin(roundDown(memState->getStackMin(), pageSize));
152 memState->setStackSize(memState->getStackBase() - memState->getStackMin());
148 // map memory
153 // map memory
149 allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize));
154 allocateMem(memState->getStackMin(), roundUp(memState->getStackSize(),
155 pageSize));
150
156
151 // map out initial stack contents
152 IntType argv_array_base = memState->stackMin + intSize; // room for argc
157 // map out initial stack contents; leave room for argc
158 IntType argv_array_base = memState->getStackMin() + intSize;
153 IntType envp_array_base = argv_array_base + argv_array_size;
154 IntType auxv_array_base = envp_array_base + envp_array_size;
155 IntType arg_data_base = auxv_array_base + auxv_array_size;
156 IntType env_data_base = arg_data_base + arg_data_size;
157
158 // write contents to stack
159 IntType argc = argv.size();
160
161 argc = htog((IntType)argc);
162
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
163 initVirtMem.writeBlob(memState->stackMin, (uint8_t*)&argc, intSize);
169 initVirtMem.writeBlob(memState->getStackMin(), (uint8_t*)&argc, intSize);
164
165 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
166
167 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
168
169 // Copy the aux vector
170 for (typename vector<auxv_t>::size_type x = 0; x < auxv.size(); x++) {
171 initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize,

--- 8 unchanged lines hidden (view full) ---

180 const Addr addr = auxv_array_base + 2 * intSize * (auxv.size() + i);
181 initVirtMem.writeBlob(addr, (uint8_t*)&zero, intSize);
182 }
183
184 ThreadContext *tc = system->getThreadContext(contextIds[0]);
185
186 setSyscallArg(tc, 0, argc);
187 setSyscallArg(tc, 1, argv_array_base);
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);
188 tc->setIntReg(StackPointerReg, memState->stackMin);
194 tc->setIntReg(StackPointerReg, memState->getStackMin());
189
190 tc->pcState(getStartPC());
191}
192
193
194MipsISA::IntReg
195MipsProcess::getSyscallArg(ThreadContext *tc, int &i)
196{

--- 24 unchanged lines hidden ---
195
196 tc->pcState(getStartPC());
197}
198
199
200MipsISA::IntReg
201MipsProcess::getSyscallArg(ThreadContext *tc, int &i)
202{

--- 24 unchanged lines hidden ---