process.cc (4786:47d848a9ccd9) | process.cc (4793:315e1db6bd39) |
---|---|
1/* 2 * Copyright (c) 2003-2006 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; --- 111 unchanged lines hidden (view full) --- 120 brk_point = roundUp(brk_point, VMPageSize); 121 122 // Set pointer for next thread stack. Reserve 8M for main stack. 123 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 124 125 // Set up stack. On X86_64 Linux, stack goes from the top of memory 126 // downward, less the hole for the kernel address space plus one page 127 // for undertermined purposes. | 1/* 2 * Copyright (c) 2003-2006 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; --- 111 unchanged lines hidden (view full) --- 120 brk_point = roundUp(brk_point, VMPageSize); 121 122 // Set pointer for next thread stack. Reserve 8M for main stack. 123 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 124 125 // Set up stack. On X86_64 Linux, stack goes from the top of memory 126 // downward, less the hole for the kernel address space plus one page 127 // for undertermined purposes. |
128 stack_base = (Addr)0x7FFFFFFF000ULL; | 128 stack_base = (Addr)0x7FFFFFFFF000ULL; |
129 130 // Set up region for mmaps. Tru64 seems to start just above 0 and 131 // grow up from there. 132 mmap_start = mmap_end = 0xfffff80000000000ULL; 133} 134 135void X86LiveProcess::handleTrap(int trapNum, ThreadContext *tc) 136{ --- 24 unchanged lines hidden (view full) --- 161 Process::startup(); 162 163 string filename; 164 if(argv.size() < 1) 165 filename = ""; 166 else 167 filename = argv[0]; 168 | 129 130 // Set up region for mmaps. Tru64 seems to start just above 0 and 131 // grow up from there. 132 mmap_start = mmap_end = 0xfffff80000000000ULL; 133} 134 135void X86LiveProcess::handleTrap(int trapNum, ThreadContext *tc) 136{ --- 24 unchanged lines hidden (view full) --- 161 Process::startup(); 162 163 string filename; 164 if(argv.size() < 1) 165 filename = ""; 166 else 167 filename = argv[0]; 168 |
169 Addr alignmentMask = ~(intSize - 1); | 169 //We want 16 byte alignment 170 Addr alignmentMask = ~mask(4); |
170 171 // load object file into target memory 172 objFile->loadSections(initVirtMem); 173 | 171 172 // load object file into target memory 173 objFile->loadSections(initVirtMem); 174 |
174 //These are the auxilliary vector types 175 enum auxTypes 176 { 177 X86_AT_NULL = 0, 178 X86_AT_IGNORE = 1, 179 X86_AT_EXECFD = 2, 180 X86_AT_PHDR = 3, 181 X86_AT_PHENT = 4, 182 X86_AT_PHNUM = 5, 183 X86_AT_PAGESZ = 6, 184 X86_AT_BASE = 7, 185 X86_AT_FLAGS = 8, 186 X86_AT_ENTRY = 9, 187 X86_AT_NOTELF = 10, 188 X86_AT_UID = 11, 189 X86_AT_EUID = 12, 190 X86_AT_GID = 13, 191 X86_AT_EGID = 14, 192 X86_AT_PLATFORM = 15, 193 X86_AT_HWCAP = 16, 194 X86_AT_CLKTCK = 17, | 175 enum X86CpuFeature { 176 X86_OnboardFPU = 1 << 0, 177 X86_VirtualModeExtensions = 1 << 1, 178 X86_DebuggingExtensions = 1 << 2, 179 X86_PageSizeExtensions = 1 << 3, |
195 | 180 |
196 X86_AT_SECURE = 13, | 181 X86_TimeStampCounter = 1 << 4, 182 X86_ModelSpecificRegisters = 1 << 5, 183 X86_PhysicalAddressExtensions = 1 << 6, 184 X86_MachineCheckExtensions = 1 << 7, |
197 | 185 |
198 X86_AT_VECTOR_SIZE = 44 | 186 X86_CMPXCHG8Instruction = 1 << 8, 187 X86_OnboardAPIC = 1 << 9, 188 X86_SYSENTER_SYSEXIT = 1 << 11, 189 190 X86_MemoryTypeRangeRegisters = 1 << 12, 191 X86_PageGlobalEnable = 1 << 13, 192 X86_MachineCheckArchitecture = 1 << 14, 193 X86_CMOVInstruction = 1 << 15, 194 195 X86_PageAttributeTable = 1 << 16, 196 X86_36BitPSEs = 1 << 17, 197 X86_ProcessorSerialNumber = 1 << 18, 198 X86_CLFLUSHInstruction = 1 << 19, 199 200 X86_DebugTraceStore = 1 << 21, 201 X86_ACPIViaMSR = 1 << 22, 202 X86_MultimediaExtensions = 1 << 23, 203 204 X86_FXSAVE_FXRSTOR = 1 << 24, 205 X86_StreamingSIMDExtensions = 1 << 25, 206 X86_StreamingSIMDExtensions2 = 1 << 26, 207 X86_CPUSelfSnoop = 1 << 27, 208 209 X86_HyperThreading = 1 << 28, 210 X86_AutomaticClockControl = 1 << 29, 211 X86_IA64Processor = 1 << 30 |
199 }; 200 201 //Setup the auxilliary vectors. These will already have endian conversion. 202 //Auxilliary vectors are loaded only for elf formatted executables. 203 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); 204 if(elfObject) 205 { | 212 }; 213 214 //Setup the auxilliary vectors. These will already have endian conversion. 215 //Auxilliary vectors are loaded only for elf formatted executables. 216 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); 217 if(elfObject) 218 { |
219 uint64_t features = 220 X86_OnboardFPU | 221 X86_VirtualModeExtensions | 222 X86_DebuggingExtensions | 223 X86_PageSizeExtensions | 224 X86_TimeStampCounter | 225 X86_ModelSpecificRegisters | 226 X86_PhysicalAddressExtensions | 227 X86_MachineCheckExtensions | 228 X86_CMPXCHG8Instruction | 229 X86_OnboardAPIC | 230 X86_SYSENTER_SYSEXIT | 231 X86_MemoryTypeRangeRegisters | 232 X86_PageGlobalEnable | 233 X86_MachineCheckArchitecture | 234 X86_CMOVInstruction | 235 X86_PageAttributeTable | 236 X86_36BitPSEs | 237// X86_ProcessorSerialNumber | 238 X86_CLFLUSHInstruction | 239// X86_DebugTraceStore | 240// X86_ACPIViaMSR | 241 X86_MultimediaExtensions | 242 X86_FXSAVE_FXRSTOR | 243 X86_StreamingSIMDExtensions | 244 X86_StreamingSIMDExtensions2 | 245// X86_CPUSelfSnoop | 246// X86_HyperThreading | 247// X86_AutomaticClockControl | 248// X86_IA64Processor | 249 0; 250 |
|
206 //Bits which describe the system hardware capabilities 207 //XXX Figure out what these should be | 251 //Bits which describe the system hardware capabilities 252 //XXX Figure out what these should be |
208 auxv.push_back(auxv_t(X86_AT_HWCAP, 0)); | 253 auxv.push_back(auxv_t(M5_AT_HWCAP, features)); |
209 //The system page size | 254 //The system page size |
210 auxv.push_back(auxv_t(X86_AT_PAGESZ, X86ISA::VMPageSize)); | 255 auxv.push_back(auxv_t(M5_AT_PAGESZ, X86ISA::VMPageSize)); |
211 //Frequency at which times() increments | 256 //Frequency at which times() increments |
212 auxv.push_back(auxv_t(X86_AT_CLKTCK, 100)); | 257 auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); |
213 // For statically linked executables, this is the virtual address of the 214 // program header tables if they appear in the executable image | 258 // For statically linked executables, this is the virtual address of the 259 // program header tables if they appear in the executable image |
215 auxv.push_back(auxv_t(X86_AT_PHDR, elfObject->programHeaderTable())); | 260 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); |
216 // This is the size of a program header entry from the elf file. | 261 // This is the size of a program header entry from the elf file. |
217 auxv.push_back(auxv_t(X86_AT_PHENT, elfObject->programHeaderSize())); | 262 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); |
218 // This is the number of program headers from the original elf file. | 263 // This is the number of program headers from the original elf file. |
219 auxv.push_back(auxv_t(X86_AT_PHNUM, elfObject->programHeaderCount())); | 264 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); |
220 //Defined to be 100 in the kernel source. 221 //This is the address of the elf "interpreter", It should be set 222 //to 0 for regular executables. It should be something else 223 //(not sure what) for dynamic libraries. | 265 //Defined to be 100 in the kernel source. 266 //This is the address of the elf "interpreter", It should be set 267 //to 0 for regular executables. It should be something else 268 //(not sure what) for dynamic libraries. |
224 auxv.push_back(auxv_t(X86_AT_BASE, 0)); | 269 auxv.push_back(auxv_t(M5_AT_BASE, 0)); |
225 226 //XXX Figure out what this should be. | 270 271 //XXX Figure out what this should be. |
227 auxv.push_back(auxv_t(X86_AT_FLAGS, 0)); | 272 auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); |
228 //The entry point to the program | 273 //The entry point to the program |
229 auxv.push_back(auxv_t(X86_AT_ENTRY, objFile->entryPoint())); | 274 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); |
230 //Different user and group IDs | 275 //Different user and group IDs |
231 auxv.push_back(auxv_t(X86_AT_UID, uid())); 232 auxv.push_back(auxv_t(X86_AT_EUID, euid())); 233 auxv.push_back(auxv_t(X86_AT_GID, gid())); 234 auxv.push_back(auxv_t(X86_AT_EGID, egid())); | 276 auxv.push_back(auxv_t(M5_AT_UID, uid())); 277 auxv.push_back(auxv_t(M5_AT_EUID, euid())); 278 auxv.push_back(auxv_t(M5_AT_GID, gid())); 279 auxv.push_back(auxv_t(M5_AT_EGID, egid())); |
235 //Whether to enable "secure mode" in the executable | 280 //Whether to enable "secure mode" in the executable |
236 auxv.push_back(auxv_t(X86_AT_SECURE, 0)); | 281 auxv.push_back(auxv_t(M5_AT_SECURE, 0)); |
237 //The string "x86_64" with unknown meaning | 282 //The string "x86_64" with unknown meaning |
238 auxv.push_back(auxv_t(X86_AT_PLATFORM, 0)); | 283 auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); |
239 } 240 241 //Figure out how big the initial stack needs to be 242 243 // The unaccounted for 0 at the top of the stack 244 int mysterious_size = intSize; 245 246 //This is the name of the file which is present on the initial stack 247 //It's purpose is to let the user space linker examine the original file. | 284 } 285 286 //Figure out how big the initial stack needs to be 287 288 // The unaccounted for 0 at the top of the stack 289 int mysterious_size = intSize; 290 291 //This is the name of the file which is present on the initial stack 292 //It's purpose is to let the user space linker examine the original file. |
248 int file_name_size = filename.size() + 1; | 293 int file_name_size = filename.size(); |
249 | 294 |
295 string platform = "x86_64"; 296 int aux_data_size = platform.size() + 1; 297 |
|
250 int env_data_size = 0; 251 for (int i = 0; i < envp.size(); ++i) { | 298 int env_data_size = 0; 299 for (int i = 0; i < envp.size(); ++i) { |
252 env_data_size += envp[i].size() + 1; | 300 env_data_size += envp[i].size(); |
253 } 254 int arg_data_size = 0; 255 for (int i = 0; i < argv.size(); ++i) { | 301 } 302 int arg_data_size = 0; 303 for (int i = 0; i < argv.size(); ++i) { |
256 arg_data_size += argv[i].size() + 1; | 304 arg_data_size += argv[i].size(); |
257 } 258 | 305 } 306 |
307 //The auxiliary vector data needs to be padded so it's size is a multiple 308 //of the alignment mask. 309 int aux_padding = 310 ((aux_data_size + ~alignmentMask) & alignmentMask) - aux_data_size; 311 |
|
259 //The info_block needs to be padded so it's size is a multiple of the 260 //alignment mask. Also, it appears that there needs to be at least some 261 //padding, so if the size is already a multiple, we need to increase it 262 //anyway. 263 int info_block_size = | 312 //The info_block needs to be padded so it's size is a multiple of the 313 //alignment mask. Also, it appears that there needs to be at least some 314 //padding, so if the size is already a multiple, we need to increase it 315 //anyway. 316 int info_block_size = |
264 (file_name_size + | 317 (mysterious_size + 318 file_name_size + |
265 env_data_size + 266 arg_data_size + | 319 env_data_size + 320 arg_data_size + |
267 intSize) & alignmentMask; | 321 ~alignmentMask) & alignmentMask; |
268 269 int info_block_padding = 270 info_block_size - | 322 323 int info_block_padding = 324 info_block_size - |
325 mysterious_size - |
|
271 file_name_size - 272 env_data_size - 273 arg_data_size; 274 275 //Each auxilliary vector is two 8 byte words 276 int aux_array_size = intSize * 2 * (auxv.size() + 1); 277 278 int envp_array_size = intSize * (envp.size() + 1); 279 int argv_array_size = intSize * (argv.size() + 1); 280 281 int argc_size = intSize; 282 283 int space_needed = | 326 file_name_size - 327 env_data_size - 328 arg_data_size; 329 330 //Each auxilliary vector is two 8 byte words 331 int aux_array_size = intSize * 2 * (auxv.size() + 1); 332 333 int envp_array_size = intSize * (envp.size() + 1); 334 int argv_array_size = intSize * (argv.size() + 1); 335 336 int argc_size = intSize; 337 338 int space_needed = |
284 mysterious_size + | |
285 info_block_size + | 339 info_block_size + |
340 aux_data_size + 341 aux_padding + |
|
286 aux_array_size + 287 envp_array_size + 288 argv_array_size + 289 argc_size; 290 291 stack_min = stack_base - space_needed; 292 stack_min &= alignmentMask; 293 stack_size = stack_base - stack_min; 294 295 // map memory 296 pTable->allocate(roundDown(stack_min, pageSize), 297 roundUp(stack_size, pageSize)); 298 299 // map out initial stack contents 300 Addr mysterious_base = stack_base - mysterious_size; 301 Addr file_name_base = mysterious_base - file_name_size; 302 Addr env_data_base = file_name_base - env_data_size; 303 Addr arg_data_base = env_data_base - arg_data_size; | 342 aux_array_size + 343 envp_array_size + 344 argv_array_size + 345 argc_size; 346 347 stack_min = stack_base - space_needed; 348 stack_min &= alignmentMask; 349 stack_size = stack_base - stack_min; 350 351 // map memory 352 pTable->allocate(roundDown(stack_min, pageSize), 353 roundUp(stack_size, pageSize)); 354 355 // map out initial stack contents 356 Addr mysterious_base = stack_base - mysterious_size; 357 Addr file_name_base = mysterious_base - file_name_size; 358 Addr env_data_base = file_name_base - env_data_size; 359 Addr arg_data_base = env_data_base - arg_data_size; |
304 Addr auxv_array_base = arg_data_base - aux_array_size - info_block_padding; | 360 Addr aux_data_base = arg_data_base - aux_data_size - info_block_padding; 361 Addr auxv_array_base = aux_data_base - aux_array_size - aux_padding; |
305 Addr envp_array_base = auxv_array_base - envp_array_size; 306 Addr argv_array_base = envp_array_base - argv_array_size; 307 Addr argc_base = argv_array_base - argc_size; 308 309 DPRINTF(X86, "The addresses of items on the initial stack:\n"); 310 DPRINTF(X86, "0x%x - file name\n", file_name_base); 311 DPRINTF(X86, "0x%x - env data\n", env_data_base); 312 DPRINTF(X86, "0x%x - arg data\n", arg_data_base); | 362 Addr envp_array_base = auxv_array_base - envp_array_size; 363 Addr argv_array_base = envp_array_base - argv_array_size; 364 Addr argc_base = argv_array_base - argc_size; 365 366 DPRINTF(X86, "The addresses of items on the initial stack:\n"); 367 DPRINTF(X86, "0x%x - file name\n", file_name_base); 368 DPRINTF(X86, "0x%x - env data\n", env_data_base); 369 DPRINTF(X86, "0x%x - arg data\n", arg_data_base); |
370 DPRINTF(X86, "0x%x - aux data\n", aux_data_base); |
|
313 DPRINTF(X86, "0x%x - auxv array\n", auxv_array_base); 314 DPRINTF(X86, "0x%x - envp array\n", envp_array_base); 315 DPRINTF(X86, "0x%x - argv array\n", argv_array_base); 316 DPRINTF(X86, "0x%x - argc \n", argc_base); 317 DPRINTF(X86, "0x%x - stack min\n", stack_min); 318 319 // write contents to stack 320 --- 4 unchanged lines hidden (view full) --- 325 //Write out the mysterious 0 326 uint64_t mysterious_zero = 0; 327 initVirtMem->writeBlob(mysterious_base, 328 (uint8_t*)&mysterious_zero, mysterious_size); 329 330 //Write the file name 331 initVirtMem->writeString(file_name_base, filename.c_str()); 332 | 371 DPRINTF(X86, "0x%x - auxv array\n", auxv_array_base); 372 DPRINTF(X86, "0x%x - envp array\n", envp_array_base); 373 DPRINTF(X86, "0x%x - argv array\n", argv_array_base); 374 DPRINTF(X86, "0x%x - argc \n", argc_base); 375 DPRINTF(X86, "0x%x - stack min\n", stack_min); 376 377 // write contents to stack 378 --- 4 unchanged lines hidden (view full) --- 383 //Write out the mysterious 0 384 uint64_t mysterious_zero = 0; 385 initVirtMem->writeBlob(mysterious_base, 386 (uint8_t*)&mysterious_zero, mysterious_size); 387 388 //Write the file name 389 initVirtMem->writeString(file_name_base, filename.c_str()); 390 |
391 //Fix up the aux vector which points to the "platform" string 392 assert(auxv[auxv.size() - 1].a_type = M5_AT_PLATFORM); 393 auxv[auxv.size() - 1].a_val = aux_data_base; 394 |
|
333 //Copy the aux stuff 334 for(int x = 0; x < auxv.size(); x++) 335 { 336 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, 337 (uint8_t*)&(auxv[x].a_type), intSize); 338 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 339 (uint8_t*)&(auxv[x].a_val), intSize); 340 } 341 //Write out the terminating zeroed auxilliary vector 342 const uint64_t zero = 0; 343 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(), 344 (uint8_t*)&zero, 2 * intSize); 345 | 395 //Copy the aux stuff 396 for(int x = 0; x < auxv.size(); x++) 397 { 398 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, 399 (uint8_t*)&(auxv[x].a_type), intSize); 400 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 401 (uint8_t*)&(auxv[x].a_val), intSize); 402 } 403 //Write out the terminating zeroed auxilliary vector 404 const uint64_t zero = 0; 405 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(), 406 (uint8_t*)&zero, 2 * intSize); 407 |
408 initVirtMem->writeString(aux_data_base, platform.c_str()); 409 |
|
346 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 347 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 348 349 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 350 351 //Set up the thread context to start running the process | 410 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 411 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 412 413 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 414 415 //Set up the thread context to start running the process |
416 //Because of the peculiarities of how syscall works, I believe 417 //a process starts with r11 containing the value of eflags or maybe r11 418 //from before the call to execve. Empirically this value is 0x200. 419 threadContexts[0]->setIntReg(INTREG_R11, 0x200); 420 //Set the stack pointer register |
|
352 threadContexts[0]->setIntReg(StackPointerReg, stack_min); 353 354 Addr prog_entry = objFile->entryPoint(); 355 threadContexts[0]->setPC(prog_entry); 356 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst)); 357 358 //Align the "stack_min" to a page boundary. 359 stack_min = roundDown(stack_min, pageSize); 360 361// num_processes++; 362} | 421 threadContexts[0]->setIntReg(StackPointerReg, stack_min); 422 423 Addr prog_entry = objFile->entryPoint(); 424 threadContexts[0]->setPC(prog_entry); 425 threadContexts[0]->setNextPC(prog_entry + sizeof(MachInst)); 426 427 //Align the "stack_min" to a page boundary. 428 stack_min = roundDown(stack_min, pageSize); 429 430// num_processes++; 431} |