process.cc (5285:c9f212c32260) process.cc (5286:0ef359b4a1f2)
1/*
2 * Copyright (c) 2003-2004 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;

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

193 string filename;
194 if(argv.size() < 1)
195 filename = "";
196 else
197 filename = argv[0];
198
199 //Even for a 32 bit process, the ABI says we still need to
200 //maintain double word alignment of the stack pointer.
1/*
2 * Copyright (c) 2003-2004 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;

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

193 string filename;
194 if(argv.size() < 1)
195 filename = "";
196 else
197 filename = argv[0];
198
199 //Even for a 32 bit process, the ABI says we still need to
200 //maintain double word alignment of the stack pointer.
201 Addr alignmentMask = ~(sizeof(uint64_t) - 1);
201 uint64_t align = 16;
202
203 // load object file into target memory
204 objFile->loadSections(initVirtMem);
205
206 enum hardwareCaps
207 {
208 M5_HWCAP_SPARC_FLUSH = 1,
209 M5_HWCAP_SPARC_STBAR = 2,

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

258 auxv.push_back(auxv_t(M5_AT_EGID, egid()));
259 //Whether to enable "secure mode" in the executable
260 auxv.push_back(auxv_t(M5_AT_SECURE, 0));
261 }
262
263 //Figure out how big the initial stack needs to be
264
265 // The unaccounted for 8 byte 0 at the top of the stack
202
203 // load object file into target memory
204 objFile->loadSections(initVirtMem);
205
206 enum hardwareCaps
207 {
208 M5_HWCAP_SPARC_FLUSH = 1,
209 M5_HWCAP_SPARC_STBAR = 2,

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

258 auxv.push_back(auxv_t(M5_AT_EGID, egid()));
259 //Whether to enable "secure mode" in the executable
260 auxv.push_back(auxv_t(M5_AT_SECURE, 0));
261 }
262
263 //Figure out how big the initial stack needs to be
264
265 // The unaccounted for 8 byte 0 at the top of the stack
266 int mysterious_size = 8;
266 int sentry_size = 8;
267
268 //This is the name of the file which is present on the initial stack
269 //It's purpose is to let the user space linker examine the original file.
270 int file_name_size = filename.size() + 1;
271
272 int env_data_size = 0;
273 for (int i = 0; i < envp.size(); ++i) {
274 env_data_size += envp[i].size() + 1;
275 }
276 int arg_data_size = 0;
277 for (int i = 0; i < argv.size(); ++i) {
278 arg_data_size += argv[i].size() + 1;
279 }
280
267
268 //This is the name of the file which is present on the initial stack
269 //It's purpose is to let the user space linker examine the original file.
270 int file_name_size = filename.size() + 1;
271
272 int env_data_size = 0;
273 for (int i = 0; i < envp.size(); ++i) {
274 env_data_size += envp[i].size() + 1;
275 }
276 int arg_data_size = 0;
277 for (int i = 0; i < argv.size(); ++i) {
278 arg_data_size += argv[i].size() + 1;
279 }
280
281 //The info_block - This seems to need an pad for some reason.
282 int info_block_size =
283 (mysterious_size +
284 file_name_size +
285 env_data_size +
286 arg_data_size + intSize);
281 //The info_block.
282 int base_info_block_size =
283 sentry_size + file_name_size + env_data_size + arg_data_size;
287
284
285 int info_block_size = roundUp(base_info_block_size, align);
286
287 int info_block_padding = info_block_size - base_info_block_size;
288
288 //Each auxilliary vector is two words
289 int aux_array_size = intSize * 2 * (auxv.size() + 1);
290
291 int envp_array_size = intSize * (envp.size() + 1);
292 int argv_array_size = intSize * (argv.size() + 1);
293
294 int argc_size = intSize;
295 int window_save_size = intSize * 16;
296
289 //Each auxilliary vector is two words
290 int aux_array_size = intSize * 2 * (auxv.size() + 1);
291
292 int envp_array_size = intSize * (envp.size() + 1);
293 int argv_array_size = intSize * (argv.size() + 1);
294
295 int argc_size = intSize;
296 int window_save_size = intSize * 16;
297
297 int space_needed =
298 info_block_size +
298 //Figure out the size of the contents of the actual initial frame
299 int frame_size =
299 aux_array_size +
300 envp_array_size +
301 argv_array_size +
302 argc_size +
303 window_save_size;
304
300 aux_array_size +
301 envp_array_size +
302 argv_array_size +
303 argc_size +
304 window_save_size;
305
306 //There needs to be padding after the auxiliary vector data so that the
307 //very bottom of the stack is aligned properly.
308 int aligned_partial_size = roundUp(frame_size, align);
309 int aux_padding = aligned_partial_size - frame_size;
310
311 int space_needed =
312 info_block_size +
313 aux_padding +
314 frame_size;
315
305 stack_min = stack_base - space_needed;
316 stack_min = stack_base - space_needed;
306 stack_min &= alignmentMask;
317 stack_min = roundDown(stack_min, align);
307 stack_size = stack_base - stack_min;
308
309 // Allocate space for the stack
310 pTable->allocate(roundDown(stack_min, pageSize),
311 roundUp(stack_size, pageSize));
312
313 // map out initial stack contents
318 stack_size = stack_base - stack_min;
319
320 // Allocate space for the stack
321 pTable->allocate(roundDown(stack_min, pageSize),
322 roundUp(stack_size, pageSize));
323
324 // map out initial stack contents
314 IntType window_save_base = stack_min;
315 IntType argc_base = window_save_base + window_save_size;
316 IntType argv_array_base = argc_base + argc_size;
317 IntType envp_array_base = argv_array_base + argv_array_size;
318 IntType auxv_array_base = envp_array_base + envp_array_size;
319 //The info block is pushed up against the top of the stack, while
320 //the rest of the initial stack frame is aligned to an 8 byte boudary.
321 IntType arg_data_base = stack_base - info_block_size + intSize;
322 IntType env_data_base = arg_data_base + arg_data_size;
323 IntType file_name_base = env_data_base + env_data_size;
324 IntType mysterious_base = file_name_base + file_name_size;
325 IntType sentry_base = stack_base - sentry_size;
326 IntType file_name_base = sentry_base - file_name_size;
327 IntType env_data_base = file_name_base - env_data_size;
328 IntType arg_data_base = env_data_base - arg_data_size;
329 IntType auxv_array_base = arg_data_base -
330 info_block_padding - aux_array_size - aux_padding;
331 IntType envp_array_base = auxv_array_base - envp_array_size;
332 IntType argv_array_base = envp_array_base - argv_array_size;
333 IntType argc_base = argv_array_base - argc_size;
334#if TRACING_ON
335 IntType window_save_base = argc_base - window_save_size;
336#endif
325
326 DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
337
338 DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
339 DPRINTF(Sparc, "%#x - sentry NULL\n", sentry_base);
340 DPRINTF(Sparc, "filename = %s\n", filename);
327 DPRINTF(Sparc, "%#x - file name\n", file_name_base);
328 DPRINTF(Sparc, "%#x - env data\n", env_data_base);
329 DPRINTF(Sparc, "%#x - arg data\n", arg_data_base);
330 DPRINTF(Sparc, "%#x - auxv array\n", auxv_array_base);
331 DPRINTF(Sparc, "%#x - envp array\n", envp_array_base);
332 DPRINTF(Sparc, "%#x - argv array\n", argv_array_base);
333 DPRINTF(Sparc, "%#x - argc \n", argc_base);
334 DPRINTF(Sparc, "%#x - window save\n", window_save_base);
335 DPRINTF(Sparc, "%#x - stack min\n", stack_min);
336
341 DPRINTF(Sparc, "%#x - file name\n", file_name_base);
342 DPRINTF(Sparc, "%#x - env data\n", env_data_base);
343 DPRINTF(Sparc, "%#x - arg data\n", arg_data_base);
344 DPRINTF(Sparc, "%#x - auxv array\n", auxv_array_base);
345 DPRINTF(Sparc, "%#x - envp array\n", envp_array_base);
346 DPRINTF(Sparc, "%#x - argv array\n", argv_array_base);
347 DPRINTF(Sparc, "%#x - argc \n", argc_base);
348 DPRINTF(Sparc, "%#x - window save\n", window_save_base);
349 DPRINTF(Sparc, "%#x - stack min\n", stack_min);
350
351 assert(window_save_base == stack_min);
352
337 // write contents to stack
338
339 // figure out argc
340 IntType argc = argv.size();
341 IntType guestArgc = TheISA::htog(argc);
342
353 // write contents to stack
354
355 // figure out argc
356 IntType argc = argv.size();
357 IntType guestArgc = TheISA::htog(argc);
358
343 //Write out the mysterious 0
344 uint64_t mysterious_zero = 0;
345 initVirtMem->writeBlob(mysterious_base,
346 (uint8_t*)&mysterious_zero, mysterious_size);
359 //Write out the sentry void *
360 uint64_t sentry_NULL = 0;
361 initVirtMem->writeBlob(sentry_base,
362 (uint8_t*)&sentry_NULL, sentry_size);
347
348 //Write the file name
349 initVirtMem->writeString(file_name_base, filename.c_str());
350
351 //Copy the aux stuff
352 for(int x = 0; x < auxv.size(); x++)
353 {
354 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize,
355 (uint8_t*)&(auxv[x].a_type), intSize);
356 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
357 (uint8_t*)&(auxv[x].a_val), intSize);
358 }
359
360 //Write out the terminating zeroed auxilliary vector
361 const IntType zero = 0;
363
364 //Write the file name
365 initVirtMem->writeString(file_name_base, filename.c_str());
366
367 //Copy the aux stuff
368 for(int x = 0; x < auxv.size(); x++)
369 {
370 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize,
371 (uint8_t*)&(auxv[x].a_type), intSize);
372 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
373 (uint8_t*)&(auxv[x].a_val), intSize);
374 }
375
376 //Write out the terminating zeroed auxilliary vector
377 const IntType zero = 0;
362 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(),
363 (uint8_t*)&zero, 2 * intSize);
378 initVirtMem->writeBlob(auxv_array_base + intSize * 2 * auxv.size(),
379 (uint8_t*)&zero, intSize);
380 initVirtMem->writeBlob(auxv_array_base + intSize * (2 * auxv.size() + 1),
381 (uint8_t*)&zero, intSize);
364
365 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
366 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
367
368 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
369
370 //Set up space for the trap handlers into the processes address space.
371 //Since the stack grows down and there is reserved address space abov

--- 118 unchanged lines hidden ---
382
383 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem);
384 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem);
385
386 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
387
388 //Set up space for the trap handlers into the processes address space.
389 //Since the stack grows down and there is reserved address space abov

--- 118 unchanged lines hidden ---