40 #include "debug/Stack.hh"
42 #include "params/Process.hh"
136 template<
class IntType>
140 int intSize =
sizeof(IntType);
144 std::string filename;
156 M5_HWCAP_SPARC_FLUSH = 1,
157 M5_HWCAP_SPARC_STBAR = 2,
158 M5_HWCAP_SPARC_SWAP = 4,
159 M5_HWCAP_SPARC_MULDIV = 8,
160 M5_HWCAP_SPARC_V9 = 16,
164 M5_HWCAP_SPARC_ULTRA3 = 32
167 const int64_t hwcap =
168 M5_HWCAP_SPARC_FLUSH |
169 M5_HWCAP_SPARC_STBAR |
170 M5_HWCAP_SPARC_SWAP |
171 M5_HWCAP_SPARC_MULDIV |
173 M5_HWCAP_SPARC_ULTRA3;
188 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
190 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
192 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
219 int file_name_size = filename.size() + 1;
221 const int numRandomBytes = 16;
222 int aux_data_size = numRandomBytes;
224 int env_data_size = 0;
225 for (
int i = 0;
i <
envp.size(); ++
i) {
226 env_data_size +=
envp[
i].size() + 1;
228 int arg_data_size = 0;
229 for (
int i = 0;
i <
argv.size(); ++
i) {
230 arg_data_size +=
argv[
i].size() + 1;
234 int base_info_block_size =
235 sentry_size + file_name_size + env_data_size + arg_data_size;
237 int info_block_size =
roundUp(base_info_block_size,
align);
239 int info_block_padding = info_block_size - base_info_block_size;
242 int aux_array_size = intSize * 2 * (auxv.size() + 1);
244 int envp_array_size = intSize * (
envp.size() + 1);
245 int argv_array_size = intSize * (
argv.size() + 1);
247 int argc_size = intSize;
248 int window_save_size = intSize * 16;
261 int aux_padding = aligned_partial_size - frame_size;
278 IntType sentry_base =
memState->getStackBase() - sentry_size;
279 IntType file_name_base = sentry_base - file_name_size;
280 IntType env_data_base = file_name_base - env_data_size;
281 IntType arg_data_base = env_data_base - arg_data_size;
282 IntType aux_data_base = arg_data_base - info_block_padding - aux_data_size;
283 IntType auxv_array_base = aux_data_base - aux_array_size - aux_padding;
284 IntType envp_array_base = auxv_array_base - envp_array_size;
285 IntType argv_array_base = envp_array_base - argv_array_size;
286 IntType argc_base = argv_array_base - argc_size;
288 IntType window_save_base = argc_base - window_save_size;
291 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
292 DPRINTF(Stack,
"%#x - sentry NULL\n", sentry_base);
293 DPRINTF(Stack,
"filename = %s\n", filename);
294 DPRINTF(Stack,
"%#x - file name\n", file_name_base);
295 DPRINTF(Stack,
"%#x - env data\n", env_data_base);
296 DPRINTF(Stack,
"%#x - arg data\n", arg_data_base);
297 DPRINTF(Stack,
"%#x - auxv array\n", auxv_array_base);
298 DPRINTF(Stack,
"%#x - envp array\n", envp_array_base);
299 DPRINTF(Stack,
"%#x - argv array\n", argv_array_base);
300 DPRINTF(Stack,
"%#x - argc \n", argc_base);
301 DPRINTF(Stack,
"%#x - window save\n", window_save_base);
304 assert(window_save_base ==
memState->getStackMin());
309 IntType argc =
argv.size();
310 IntType guestArgc =
htobe(argc);
313 uint64_t sentry_NULL = 0;
314 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
317 initVirtMem->writeString(file_name_base, filename.c_str());
320 for (
auto &aux: auxv) {
322 aux.val = aux_data_base;
326 Addr auxv_array_end = auxv_array_base;
327 for (
const auto &aux: auxv) {
329 auxv_array_end +=
sizeof(aux);
335 auxv_array_end +=
sizeof(zero);
342 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);
370 SparcProcess::argsInit<uint64_t>(pageSize);
382 SparcProcess::argsInit<uint32_t>(pageSize);