process.cc (6701:4842482e1bd1) process.cc (6811:f130ea67e453)
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;

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

29 * Ali Saidi
30 * Korey Sewell
31 */
32
33#include "arch/mips/isa_traits.hh"
34#include "arch/mips/process.hh"
35
36#include "base/loader/object_file.hh"
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;

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

29 * Ali Saidi
30 * Korey Sewell
31 */
32
33#include "arch/mips/isa_traits.hh"
34#include "arch/mips/process.hh"
35
36#include "base/loader/object_file.hh"
37#include "base/loader/elf_object.hh"
37#include "base/misc.hh"
38#include "cpu/thread_context.hh"
39
40#include "mem/page_table.hh"
41
42#include "sim/process.hh"
43#include "sim/process_impl.hh"
44#include "sim/system.hh"

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

56
57 // Set pointer for next thread stack. Reserve 8M for main stack.
58 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
59
60 // Set up break point (Top of Heap)
61 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
62 brk_point = roundUp(brk_point, VMPageSize);
63
38#include "base/misc.hh"
39#include "cpu/thread_context.hh"
40
41#include "mem/page_table.hh"
42
43#include "sim/process.hh"
44#include "sim/process_impl.hh"
45#include "sim/system.hh"

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

57
58 // Set pointer for next thread stack. Reserve 8M for main stack.
59 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
60
61 // Set up break point (Top of Heap)
62 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize();
63 brk_point = roundUp(brk_point, VMPageSize);
64
64 // Set up region for mmaps. For now, start at bottom of kuseg space.
65 mmap_start = mmap_end = 0x10000;
65 // Set up region for mmaps. Start it 1GB above the top of the heap.
66 mmap_start = mmap_end = brk_point + 0x40000000L;
66}
67
68void
69MipsLiveProcess::startup()
70{
71 Process::startup();
72
67}
68
69void
70MipsLiveProcess::startup()
71{
72 Process::startup();
73
73 argsInit(MachineBytes, VMPageSize);
74 argsInit<uint32_t>(VMPageSize);
74}
75
75}
76
77template<class IntType>
76void
78void
77MipsLiveProcess::argsInit(int intSize, int pageSize)
79MipsLiveProcess::argsInit(int pageSize)
78{
80{
81 int intSize = sizeof(IntType);
82 Process::startup();
83
79 // load object file into target memory
80 objFile->loadSections(initVirtMem);
81
84 // load object file into target memory
85 objFile->loadSections(initVirtMem);
86
82 // Calculate how much space we need for arg & env arrays.
87 typedef AuxVector<IntType> auxv_t;
88 std::vector<auxv_t> auxv;
89
90 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile);
91 if (elfObject)
92 {
93 // Set the system page size
94 auxv.push_back(auxv_t(M5_AT_PAGESZ, MipsISA::VMPageSize));
95 // Set the frequency at which time() increments
96 auxv.push_back(auxv_t(M5_AT_CLKTCK, 100));
97 // For statically linked executables, this is the virtual
98 // address of the program header tables if they appear in the
99 // executable image.
100 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable()));
101 DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable());
102 // This is the size of a program header entry from the elf file.
103 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize()));
104 // This is the number of program headers from the original elf file.
105 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount()));
106 //The entry point to the program
107 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint()));
108 //Different user and group IDs
109 auxv.push_back(auxv_t(M5_AT_UID, uid()));
110 auxv.push_back(auxv_t(M5_AT_EUID, euid()));
111 auxv.push_back(auxv_t(M5_AT_GID, gid()));
112 auxv.push_back(auxv_t(M5_AT_EGID, egid()));
113 }
114
115 // Calculate how much space we need for arg & env & auxv arrays.
83 int argv_array_size = intSize * (argv.size() + 1);
84 int envp_array_size = intSize * (envp.size() + 1);
116 int argv_array_size = intSize * (argv.size() + 1);
117 int envp_array_size = intSize * (envp.size() + 1);
118 int auxv_array_size = intSize * 2 * (auxv.size() + 1);
119
85 int arg_data_size = 0;
86 for (vector<string>::size_type i = 0; i < argv.size(); ++i) {
87 arg_data_size += argv[i].size() + 1;
88 }
89 int env_data_size = 0;
90 for (vector<string>::size_type i = 0; i < envp.size(); ++i) {
91 env_data_size += envp[i].size() + 1;
92 }
93
94 int space_needed =
120 int arg_data_size = 0;
121 for (vector<string>::size_type i = 0; i < argv.size(); ++i) {
122 arg_data_size += argv[i].size() + 1;
123 }
124 int env_data_size = 0;
125 for (vector<string>::size_type i = 0; i < envp.size(); ++i) {
126 env_data_size += envp[i].size() + 1;
127 }
128
129 int space_needed =
95 argv_array_size + envp_array_size + arg_data_size + env_data_size;
96 if (space_needed < 32*1024)
97 space_needed = 32*1024;
130 argv_array_size +
131 envp_array_size +
132 auxv_array_size +
133 arg_data_size +
134 env_data_size;
98
99 // set bottom of stack
100 stack_min = stack_base - space_needed;
101 // align it
102 stack_min = roundDown(stack_min, pageSize);
103 stack_size = stack_base - stack_min;
104 // map memory
105 pTable->allocate(stack_min, roundUp(stack_size, pageSize));
106
107 // map out initial stack contents
135
136 // set bottom of stack
137 stack_min = stack_base - space_needed;
138 // align it
139 stack_min = roundDown(stack_min, pageSize);
140 stack_size = stack_base - stack_min;
141 // map memory
142 pTable->allocate(stack_min, roundUp(stack_size, pageSize));
143
144 // map out initial stack contents
108 // ========
109 // NOTE: Using uint32_t hardcodes MIPS32 and not MIPS64
110 // even if MIPS64 was intended. This is because the
111 // copyStringArray function templates on the parameters.
112 // Elegant way to check intSize and vary between 32/64?
113 // ========
114 uint32_t argv_array_base = stack_min + intSize; // room for argc
115 uint32_t envp_array_base = argv_array_base + argv_array_size;
116 uint32_t arg_data_base = envp_array_base + envp_array_size;
117 uint32_t env_data_base = arg_data_base + arg_data_size;
145 IntType argv_array_base = stack_min + intSize; // room for argc
146 IntType envp_array_base = argv_array_base + argv_array_size;
147 IntType auxv_array_base = envp_array_base + envp_array_size;
148 IntType arg_data_base = auxv_array_base + auxv_array_size;
149 IntType env_data_base = arg_data_base + arg_data_size;
118
119 // write contents to stack
150
151 // write contents to stack
120 uint32_t argc = argv.size();
152 IntType argc = argv.size();
121
153
122 if (intSize == 8)
123 argc = htog((uint64_t)argc);
124 else if (intSize == 4)
125 argc = htog((uint32_t)argc);
126 else
127 panic("Unknown int size");
154 argc = htog((IntType)argc);
128
155
129
130 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
131
132 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
133
134 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
135
156 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize);
157
158 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
159
160 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
161
162 // Copy the aux vector
163 for (typename vector<auxv_t>::size_type x = 0; x < auxv.size(); x++) {
164 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize,
165 (uint8_t*)&(auxv[x].a_type), intSize);
166 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
167 (uint8_t*)&(auxv[x].a_val), intSize);
168 }
169
170 // Write out the terminating zeroed auxilliary vector
171 for (unsigned i = 0; i < 2; i++) {
172 const IntType zero = 0;
173 const Addr addr = auxv_array_base + 2 * intSize * (auxv.size() + i);
174 initVirtMem->writeBlob(addr, (uint8_t*)&zero, intSize);
175 }
176
136 ThreadContext *tc = system->getThreadContext(contextIds[0]);
137
138 setSyscallArg(tc, 0, argc);
139 setSyscallArg(tc, 1, argv_array_base);
140 tc->setIntReg(StackPointerReg, stack_min);
141
142 Addr prog_entry = objFile->entryPoint();
143 tc->setPC(prog_entry);

--- 34 unchanged lines hidden ---
177 ThreadContext *tc = system->getThreadContext(contextIds[0]);
178
179 setSyscallArg(tc, 0, argc);
180 setSyscallArg(tc, 1, argv_array_base);
181 tc->setIntReg(StackPointerReg, stack_min);
182
183 Addr prog_entry = objFile->entryPoint();
184 tc->setPC(prog_entry);

--- 34 unchanged lines hidden ---