process.cc (5941:e8a1f956d76c) process.cc (5956:a49d9413a9e8)
1/*
2 * Copyright (c) 2003-2006 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;

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

93#include "base/loader/object_file.hh"
94#include "base/loader/elf_object.hh"
95#include "base/misc.hh"
96#include "base/trace.hh"
97#include "cpu/thread_context.hh"
98#include "mem/page_table.hh"
99#include "mem/translating_port.hh"
100#include "sim/process_impl.hh"
1/*
2 * Copyright (c) 2003-2006 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;

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

93#include "base/loader/object_file.hh"
94#include "base/loader/elf_object.hh"
95#include "base/misc.hh"
96#include "base/trace.hh"
97#include "cpu/thread_context.hh"
98#include "mem/page_table.hh"
99#include "mem/translating_port.hh"
100#include "sim/process_impl.hh"
101#include "sim/syscall_emul.hh"
101#include "sim/system.hh"
102
103using namespace std;
104using namespace X86ISA;
105
106
102#include "sim/system.hh"
103
104using namespace std;
105using namespace X86ISA;
106
107
107X86LiveProcess::X86LiveProcess(LiveProcessParams * params,
108 ObjectFile *objFile)
109 : LiveProcess(params, objFile)
108X86LiveProcess::X86LiveProcess(LiveProcessParams * params, ObjectFile *objFile,
109 SyscallDesc *_syscallDescs, int _numSyscallDescs) :
110 LiveProcess(params, objFile), syscallDescs(_syscallDescs),
111 numSyscallDescs(_numSyscallDescs)
110{
111 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
112 brk_point = roundUp(brk_point, VMPageSize);
112{
113 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
114 brk_point = roundUp(brk_point, VMPageSize);
115}
113
116
114 // Set pointer for next thread stack. Reserve 8M for main stack.
115 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
116
117X86_64LiveProcess::X86_64LiveProcess(LiveProcessParams *params,
118 ObjectFile *objFile, SyscallDesc *_syscallDescs,
119 int _numSyscallDescs) :
120 X86LiveProcess(params, objFile, _syscallDescs, _numSyscallDescs)
121{
117 // Set up stack. On X86_64 Linux, stack goes from the top of memory
118 // downward, less the hole for the kernel address space plus one page
119 // for undertermined purposes.
120 stack_base = (Addr)0x7FFFFFFFF000ULL;
121
122 // Set up stack. On X86_64 Linux, stack goes from the top of memory
123 // downward, less the hole for the kernel address space plus one page
124 // for undertermined purposes.
125 stack_base = (Addr)0x7FFFFFFFF000ULL;
126
127 // Set pointer for next thread stack. Reserve 8M for main stack.
128 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
129
122 // Set up region for mmaps. This was determined empirically and may not
123 // always be correct.
124 mmap_start = mmap_end = (Addr)0x2aaaaaaab000ULL;
125}
126
130 // Set up region for mmaps. This was determined empirically and may not
131 // always be correct.
132 mmap_start = mmap_end = (Addr)0x2aaaaaaab000ULL;
133}
134
127void X86LiveProcess::handleTrap(int trapNum, ThreadContext *tc)
135I386LiveProcess::I386LiveProcess(LiveProcessParams *params,
136 ObjectFile *objFile, SyscallDesc *_syscallDescs,
137 int _numSyscallDescs) :
138 X86LiveProcess(params, objFile, _syscallDescs, _numSyscallDescs)
128{
139{
129 switch(trapNum)
130 {
131 default:
132 panic("Unimplemented trap to operating system: trap number %#x.\n", trapNum);
133 }
140 stack_base = (Addr)0xffffe000ULL;
141
142 // Set pointer for next thread stack. Reserve 8M for main stack.
143 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
144
145 // Set up region for mmaps. This was determined empirically and may not
146 // always be correct.
147 mmap_start = mmap_end = (Addr)0xf7ffd000ULL;
134}
135
148}
149
150SyscallDesc*
151X86LiveProcess::getDesc(int callnum)
152{
153 if (callnum < 0 || callnum >= numSyscallDescs)
154 return NULL;
155 return &syscallDescs[callnum];
156}
157
136void
158void
137X86LiveProcess::startup()
159X86_64LiveProcess::startup()
138{
160{
161 LiveProcess::startup();
162
139 if (checkpointRestored)
140 return;
141
163 if (checkpointRestored)
164 return;
165
142 argsInit(sizeof(IntReg), VMPageSize);
166 argsInit(sizeof(uint64_t), VMPageSize);
143
144 for (int i = 0; i < contextIds.size(); i++) {
145 ThreadContext * tc = system->getThreadContext(contextIds[i]);
146
147 SegAttr dataAttr = 0;
148 dataAttr.writable = 1;
149 dataAttr.readable = 1;
150 dataAttr.expandDown = 0;

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

193 efer.nxe = 1; // Enable nx support.
194 efer.svme = 0; // Disable svm support for now. It isn't implemented.
195 efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
196 tc->setMiscReg(MISCREG_EFER, efer);
197 }
198}
199
200void
167
168 for (int i = 0; i < contextIds.size(); i++) {
169 ThreadContext * tc = system->getThreadContext(contextIds[i]);
170
171 SegAttr dataAttr = 0;
172 dataAttr.writable = 1;
173 dataAttr.readable = 1;
174 dataAttr.expandDown = 0;

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

217 efer.nxe = 1; // Enable nx support.
218 efer.svme = 0; // Disable svm support for now. It isn't implemented.
219 efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
220 tc->setMiscReg(MISCREG_EFER, efer);
221 }
222}
223
224void
201X86LiveProcess::argsInit(int intSize, int pageSize)
225I386LiveProcess::startup()
202{
226{
203 typedef AuxVector<uint64_t> auxv_t;
204 std::vector<auxv_t> auxv;
227 LiveProcess::startup();
205
228
206 Process::startup();
229 if (checkpointRestored)
230 return;
207
231
232 argsInit(sizeof(uint32_t), VMPageSize);
233
234 for (int i = 0; i < contextIds.size(); i++) {
235 ThreadContext * tc = system->getThreadContext(contextIds[i]);
236
237 SegAttr dataAttr = 0;
238 dataAttr.writable = 1;
239 dataAttr.readable = 1;
240 dataAttr.expandDown = 0;
241 dataAttr.dpl = 3;
242 dataAttr.defaultSize = 1;
243 dataAttr.longMode = 0;
244
245 //Initialize the segment registers.
246 for(int seg = 0; seg < NUM_SEGMENTREGS; seg++) {
247 tc->setMiscRegNoEffect(MISCREG_SEG_BASE(seg), 0);
248 tc->setMiscRegNoEffect(MISCREG_SEG_EFF_BASE(seg), 0);
249 tc->setMiscRegNoEffect(MISCREG_SEG_ATTR(seg), dataAttr);
250 tc->setMiscRegNoEffect(MISCREG_SEG_SEL(seg), 0xB);
251 }
252
253 SegAttr csAttr = 0;
254 csAttr.writable = 0;
255 csAttr.readable = 1;
256 csAttr.expandDown = 0;
257 csAttr.dpl = 3;
258 csAttr.defaultSize = 1;
259 csAttr.longMode = 0;
260
261 tc->setMiscRegNoEffect(MISCREG_CS_ATTR, csAttr);
262
263 //Set up the registers that describe the operating mode.
264 CR0 cr0 = 0;
265 cr0.pg = 1; // Turn on paging.
266 cr0.cd = 0; // Don't disable caching.
267 cr0.nw = 0; // This is bit is defined to be ignored.
268 cr0.am = 0; // No alignment checking
269 cr0.wp = 0; // Supervisor mode can write read only pages
270 cr0.ne = 1;
271 cr0.et = 1; // This should always be 1
272 cr0.ts = 0; // We don't do task switching, so causing fp exceptions
273 // would be pointless.
274 cr0.em = 0; // Allow x87 instructions to execute natively.
275 cr0.mp = 1; // This doesn't really matter, but the manual suggests
276 // setting it to one.
277 cr0.pe = 1; // We're definitely in protected mode.
278 tc->setMiscReg(MISCREG_CR0, cr0);
279
280 Efer efer = 0;
281 efer.sce = 1; // Enable system call extensions.
282 efer.lme = 1; // Enable long mode.
283 efer.lma = 0; // Deactivate long mode.
284 efer.nxe = 1; // Enable nx support.
285 efer.svme = 0; // Disable svm support for now. It isn't implemented.
286 efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
287 tc->setMiscReg(MISCREG_EFER, efer);
288 }
289}
290
291template<class IntType>
292void
293X86LiveProcess::argsInit(int pageSize)
294{
295 int intSize = sizeof(IntType);
296
297 typedef AuxVector<IntType> auxv_t;
298 std::vector<auxv_t> auxv;
299
208 string filename;
209 if(argv.size() < 1)
210 filename = "";
211 else
212 filename = argv[0];
213
214 //We want 16 byte alignment
215 uint64_t align = 16;

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

391 stack_min = roundDown(stack_min, align);
392 stack_size = stack_base - stack_min;
393
394 // map memory
395 pTable->allocate(roundDown(stack_min, pageSize),
396 roundUp(stack_size, pageSize));
397
398 // map out initial stack contents
300 string filename;
301 if(argv.size() < 1)
302 filename = "";
303 else
304 filename = argv[0];
305
306 //We want 16 byte alignment
307 uint64_t align = 16;

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

483 stack_min = roundDown(stack_min, align);
484 stack_size = stack_base - stack_min;
485
486 // map memory
487 pTable->allocate(roundDown(stack_min, pageSize),
488 roundUp(stack_size, pageSize));
489
490 // map out initial stack contents
399 Addr sentry_base = stack_base - sentry_size;
400 Addr file_name_base = sentry_base - file_name_size;
401 Addr env_data_base = file_name_base - env_data_size;
402 Addr arg_data_base = env_data_base - arg_data_size;
403 Addr aux_data_base = arg_data_base - info_block_padding - aux_data_size;
404 Addr auxv_array_base = aux_data_base - aux_array_size - aux_padding;
405 Addr envp_array_base = auxv_array_base - envp_array_size;
406 Addr argv_array_base = envp_array_base - argv_array_size;
407 Addr argc_base = argv_array_base - argc_size;
491 IntType sentry_base = stack_base - sentry_size;
492 IntType file_name_base = sentry_base - file_name_size;
493 IntType env_data_base = file_name_base - env_data_size;
494 IntType arg_data_base = env_data_base - arg_data_size;
495 IntType aux_data_base = arg_data_base - info_block_padding - aux_data_size;
496 IntType auxv_array_base = aux_data_base - aux_array_size - aux_padding;
497 IntType envp_array_base = auxv_array_base - envp_array_size;
498 IntType argv_array_base = envp_array_base - argv_array_size;
499 IntType argc_base = argv_array_base - argc_size;
408
409 DPRINTF(Stack, "The addresses of items on the initial stack:\n");
410 DPRINTF(Stack, "0x%x - file name\n", file_name_base);
411 DPRINTF(Stack, "0x%x - env data\n", env_data_base);
412 DPRINTF(Stack, "0x%x - arg data\n", arg_data_base);
413 DPRINTF(Stack, "0x%x - aux data\n", aux_data_base);
414 DPRINTF(Stack, "0x%x - auxv array\n", auxv_array_base);
415 DPRINTF(Stack, "0x%x - envp array\n", envp_array_base);
416 DPRINTF(Stack, "0x%x - argv array\n", argv_array_base);
417 DPRINTF(Stack, "0x%x - argc \n", argc_base);
418 DPRINTF(Stack, "0x%x - stack min\n", stack_min);
419
420 // write contents to stack
421
422 // figure out argc
500
501 DPRINTF(Stack, "The addresses of items on the initial stack:\n");
502 DPRINTF(Stack, "0x%x - file name\n", file_name_base);
503 DPRINTF(Stack, "0x%x - env data\n", env_data_base);
504 DPRINTF(Stack, "0x%x - arg data\n", arg_data_base);
505 DPRINTF(Stack, "0x%x - aux data\n", aux_data_base);
506 DPRINTF(Stack, "0x%x - auxv array\n", auxv_array_base);
507 DPRINTF(Stack, "0x%x - envp array\n", envp_array_base);
508 DPRINTF(Stack, "0x%x - argv array\n", argv_array_base);
509 DPRINTF(Stack, "0x%x - argc \n", argc_base);
510 DPRINTF(Stack, "0x%x - stack min\n", stack_min);
511
512 // write contents to stack
513
514 // figure out argc
423 uint64_t argc = argv.size();
424 uint64_t guestArgc = X86ISA::htog(argc);
515 IntType argc = argv.size();
516 IntType guestArgc = X86ISA::htog(argc);
425
426 //Write out the sentry void *
517
518 //Write out the sentry void *
427 uint64_t sentry_NULL = 0;
519 IntType sentry_NULL = 0;
428 initVirtMem->writeBlob(sentry_base,
429 (uint8_t*)&sentry_NULL, sentry_size);
430
431 //Write the file name
432 initVirtMem->writeString(file_name_base, filename.c_str());
433
434 //Fix up the aux vector which points to the "platform" string
435 assert(auxv[auxv.size() - 1].a_type = M5_AT_PLATFORM);

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

465 tc->setPC(prog_entry);
466 tc->setNextPC(prog_entry + sizeof(MachInst));
467
468 //Align the "stack_min" to a page boundary.
469 stack_min = roundDown(stack_min, pageSize);
470
471// num_processes++;
472}
520 initVirtMem->writeBlob(sentry_base,
521 (uint8_t*)&sentry_NULL, sentry_size);
522
523 //Write the file name
524 initVirtMem->writeString(file_name_base, filename.c_str());
525
526 //Fix up the aux vector which points to the "platform" string
527 assert(auxv[auxv.size() - 1].a_type = M5_AT_PLATFORM);

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

557 tc->setPC(prog_entry);
558 tc->setNextPC(prog_entry + sizeof(MachInst));
559
560 //Align the "stack_min" to a page boundary.
561 stack_min = roundDown(stack_min, pageSize);
562
563// num_processes++;
564}
565
566void
567X86_64LiveProcess::argsInit(int intSize, int pageSize)
568{
569 X86LiveProcess::argsInit<uint64_t>(pageSize);
570}
571
572void
573I386LiveProcess::argsInit(int intSize, int pageSize)
574{
575 X86LiveProcess::argsInit<uint32_t>(pageSize);
576}