process.cc (3039:9cec9533b941) | process.cc (3044:66cc2a38662e) |
---|---|
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. | 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); | 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. | 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 = 0x800000; | 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 | 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 |
|
113 Addr alignmentMask = ~(intSize - 1); 114 115 // load object file into target memory 116 objFile->loadSections(initVirtMem); 117 118 //These are the auxilliary vector types 119 enum auxTypes 120 { --- 68 unchanged lines hidden (view full) --- 189 auxv.push_back(buildAuxVect(SPARC_AT_GID, 100)); 190 auxv.push_back(buildAuxVect(SPARC_AT_EGID, 100)); 191 //Whether to enable "secure mode" in the executable 192 auxv.push_back(buildAuxVect(SPARC_AT_SECURE, 0)); 193 } 194 195 //Figure out how big the initial stack needs to be 196 | 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 |
197 //Each auxilliary vector is two 8 byte words 198 int aux_data_size = 2 * intSize * auxv.size(); | 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 |
199 int env_data_size = 0; 200 for (int i = 0; i < envp.size(); ++i) { 201 env_data_size += envp[i].size() + 1; 202 } 203 int arg_data_size = 0; 204 for (int i = 0; i < argv.size(); ++i) { 205 arg_data_size += argv[i].size() + 1; 206 } 207 | 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 |
208 int aux_array_size = intSize * 2 * (auxv.size() + 1); 209 210 int argv_array_size = intSize * (argv.size() + 1); 211 int envp_array_size = intSize * (envp.size() + 1); 212 213 int argc_size = intSize; 214 int window_save_size = intSize * 16; 215 | 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. |
216 int info_block_size = | 223 int info_block_size = |
217 (aux_data_size + | 224 (file_name_size + |
218 env_data_size + 219 arg_data_size + | 225 env_data_size + 226 arg_data_size + |
220 ~alignmentMask) & alignmentMask; | 227 intSize) & alignmentMask; |
221 222 int info_block_padding = 223 info_block_size - | 228 229 int info_block_padding = 230 info_block_size - |
224 aux_data_size - | 231 file_name_size - |
225 env_data_size - 226 arg_data_size; 227 | 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 |
|
228 int space_needed = | 244 int space_needed = |
245 mysterious_size + |
|
229 info_block_size + 230 aux_array_size + 231 envp_array_size + 232 argv_array_size + 233 argc_size + 234 window_save_size; 235 236 stack_min = stack_base - space_needed; 237 stack_min &= alignmentMask; 238 stack_size = stack_base - stack_min; 239 240 // map memory 241 pTable->allocate(roundDown(stack_min, pageSize), 242 roundUp(stack_size, pageSize)); 243 244 // map out initial stack contents | 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 |
245 Addr aux_data_base = stack_base - aux_data_size - info_block_padding; 246 Addr env_data_base = aux_data_base - env_data_size; | 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; |
247 Addr arg_data_base = env_data_base - arg_data_size; | 265 Addr arg_data_base = env_data_base - arg_data_size; |
248 Addr auxv_array_base = arg_data_base - aux_array_size; | 266 Addr auxv_array_base = arg_data_base - aux_array_size - info_block_padding; |
249 Addr envp_array_base = auxv_array_base - envp_array_size; 250 Addr argv_array_base = envp_array_base - argv_array_size; 251 Addr argc_base = argv_array_base - argc_size; 252#ifndef NDEBUG 253 // only used in DPRINTF 254 Addr window_save_base = argc_base - window_save_size; 255#endif 256 257 DPRINTF(Sparc, "The addresses of items on the initial stack:\n"); | 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"); |
258 DPRINTF(Sparc, "0x%x - aux data\n", aux_data_base); | 276 DPRINTF(Sparc, "0x%x - file name\n", file_name_base); |
259 DPRINTF(Sparc, "0x%x - env data\n", env_data_base); 260 DPRINTF(Sparc, "0x%x - arg data\n", arg_data_base); 261 DPRINTF(Sparc, "0x%x - auxv array\n", auxv_array_base); 262 DPRINTF(Sparc, "0x%x - envp array\n", envp_array_base); 263 DPRINTF(Sparc, "0x%x - argv array\n", argv_array_base); 264 DPRINTF(Sparc, "0x%x - argc \n", argc_base); 265 DPRINTF(Sparc, "0x%x - window save\n", window_save_base); 266 DPRINTF(Sparc, "0x%x - stack min\n", stack_min); 267 268 // write contents to stack | 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 |
|
269 uint64_t argc = argv.size(); 270 uint64_t guestArgc = TheISA::htog(argc); 271 | 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 |
|
272 //Copy the aux stuff 273 for(int x = 0; x < auxv.size(); x++) 274 { 275 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, 276 (uint8_t*)&(auxv[x].a_type), intSize); 277 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 278 (uint8_t*)&(auxv[x].a_val), intSize); 279 } --- 21 unchanged lines hidden --- | 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 --- |