Deleted Added
sdiff udiff text old ( 5285:c9f212c32260 ) new ( 5286:0ef359b4a1f2 )
full compact
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);
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;
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);
287
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
297 int space_needed =
298 info_block_size +
299 aux_array_size +
300 envp_array_size +
301 argv_array_size +
302 argc_size +
303 window_save_size;
304
305 stack_min = stack_base - space_needed;
306 stack_min &= alignmentMask;
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
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
326 DPRINTF(Sparc, "The addresses of items on the initial stack:\n");
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
337 // write contents to stack
338
339 // figure out argc
340 IntType argc = argv.size();
341 IntType guestArgc = TheISA::htog(argc);
342
343 //Write out the mysterious 0
344 uint64_t mysterious_zero = 0;
345 initVirtMem->writeBlob(mysterious_base,
346 (uint8_t*)&mysterious_zero, mysterious_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;
362 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(),
363 (uint8_t*)&zero, 2 * 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 ---