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; --- 42 unchanged lines hidden (view full) --- 51{ 52 53 // XXX all the below need to be updated for SPARC - Ali 54 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 55 brk_point = roundUp(brk_point, VMPageSize); 56 57 // Set up stack. On SPARC Linux, stack goes from the top of memory 58 // downward, less the hole for the kernel address space. |
59 stack_base = (Addr)0x80000000000ULL; |
60 61 // Set up region for mmaps. Tru64 seems to start just above 0 and 62 // grow up from there. |
63 mmap_start = mmap_end = 0xfffff80000000000ULL; |
64 65 // Set pointer for next thread stack. Reserve 8M for main stack. 66 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 67} 68 69void 70SparcLiveProcess::startup() 71{ --- 33 unchanged lines hidden (view full) --- 105 return result; 106} 107 108void 109SparcLiveProcess::argsInit(int intSize, int pageSize) 110{ 111 Process::startup(); 112 |
113 string filename; 114 if(argv.size() < 1) 115 filename = ""; 116 else 117 filename = argv[0]; 118 |
119 Addr alignmentMask = ~(intSize - 1); 120 121 // load object file into target memory 122 objFile->loadSections(initVirtMem); 123 124 //These are the auxilliary vector types 125 enum auxTypes 126 { --- 68 unchanged lines hidden (view full) --- 195 auxv.push_back(buildAuxVect(SPARC_AT_GID, 100)); 196 auxv.push_back(buildAuxVect(SPARC_AT_EGID, 100)); 197 //Whether to enable "secure mode" in the executable 198 auxv.push_back(buildAuxVect(SPARC_AT_SECURE, 0)); 199 } 200 201 //Figure out how big the initial stack needs to be 202 |
203 // The unaccounted for 0 at the top of the stack 204 int mysterious_size = intSize; 205 206 //This is the name of the file which is present on the initial stack 207 //It's purpose is to let the user space linker examine the original file. 208 int file_name_size = filename.size() + 1; 209 |
210 int env_data_size = 0; 211 for (int i = 0; i < envp.size(); ++i) { 212 env_data_size += envp[i].size() + 1; 213 } 214 int arg_data_size = 0; 215 for (int i = 0; i < argv.size(); ++i) { 216 arg_data_size += argv[i].size() + 1; 217 } 218 |
219 //The info_block needs to be padded so it's size is a multiple of the 220 //alignment mask. Also, it appears that there needs to be at least some 221 //padding, so if the size is already a multiple, we need to increase it 222 //anyway. |
223 int info_block_size = |
224 (file_name_size + |
225 env_data_size + 226 arg_data_size + |
227 intSize) & alignmentMask; |
228 229 int info_block_padding = 230 info_block_size - |
231 file_name_size - |
232 env_data_size - 233 arg_data_size; 234 |
235 //Each auxilliary vector is two 8 byte words 236 int aux_array_size = intSize * 2 * (auxv.size() + 1); 237 238 int envp_array_size = intSize * (envp.size() + 1); 239 int argv_array_size = intSize * (argv.size() + 1); 240 241 int argc_size = intSize; 242 int window_save_size = intSize * 16; 243 |
244 int space_needed = |
245 mysterious_size + |
246 info_block_size + 247 aux_array_size + 248 envp_array_size + 249 argv_array_size + 250 argc_size + 251 window_save_size; 252 253 stack_min = stack_base - space_needed; 254 stack_min &= alignmentMask; 255 stack_size = stack_base - stack_min; 256 257 // map memory 258 pTable->allocate(roundDown(stack_min, pageSize), 259 roundUp(stack_size, pageSize)); 260 261 // map out initial stack contents |
262 Addr mysterious_base = stack_base - mysterious_size; 263 Addr file_name_base = mysterious_base - file_name_size; 264 Addr env_data_base = file_name_base - env_data_size; |
265 Addr arg_data_base = env_data_base - arg_data_size; |
266 Addr auxv_array_base = arg_data_base - aux_array_size - info_block_padding; |
267 Addr envp_array_base = auxv_array_base - envp_array_size; 268 Addr argv_array_base = envp_array_base - argv_array_size; 269 Addr argc_base = argv_array_base - argc_size; 270#ifndef NDEBUG 271 // only used in DPRINTF 272 Addr window_save_base = argc_base - window_save_size; 273#endif 274 275 DPRINTF(Sparc, "The addresses of items on the initial stack:\n"); |
276 DPRINTF(Sparc, "0x%x - file name\n", file_name_base); |
277 DPRINTF(Sparc, "0x%x - env data\n", env_data_base); 278 DPRINTF(Sparc, "0x%x - arg data\n", arg_data_base); 279 DPRINTF(Sparc, "0x%x - auxv array\n", auxv_array_base); 280 DPRINTF(Sparc, "0x%x - envp array\n", envp_array_base); 281 DPRINTF(Sparc, "0x%x - argv array\n", argv_array_base); 282 DPRINTF(Sparc, "0x%x - argc \n", argc_base); 283 DPRINTF(Sparc, "0x%x - window save\n", window_save_base); 284 DPRINTF(Sparc, "0x%x - stack min\n", stack_min); 285 286 // write contents to stack |
287 288 // figure out argc |
289 uint64_t argc = argv.size(); 290 uint64_t guestArgc = TheISA::htog(argc); 291 |
292 //Write out the mysterious 0 293 uint64_t mysterious_zero = 0; 294 initVirtMem->writeBlob(mysterious_base, 295 (uint8_t*)&mysterious_zero, mysterious_size); 296 297 //Write the file name 298 initVirtMem->writeString(file_name_base, filename.c_str()); 299 |
300 //Copy the aux stuff 301 for(int x = 0; x < auxv.size(); x++) 302 { 303 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, 304 (uint8_t*)&(auxv[x].a_type), intSize); 305 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 306 (uint8_t*)&(auxv[x].a_val), intSize); 307 } --- 21 unchanged lines hidden --- |