process.cc (6020:0647c8b31a99) | process.cc (6400:b7fd31c84c99) |
---|---|
1/* 2 * Copyright (c) 2007-2008 The Florida State University 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; --- 32 unchanged lines hidden (view full) --- 41#include "sim/system.hh" 42 43using namespace std; 44using namespace ArmISA; 45 46ArmLiveProcess::ArmLiveProcess(LiveProcessParams *params, ObjectFile *objFile) 47 : LiveProcess(params, objFile) 48{ | 1/* 2 * Copyright (c) 2007-2008 The Florida State University 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; --- 32 unchanged lines hidden (view full) --- 41#include "sim/system.hh" 42 43using namespace std; 44using namespace ArmISA; 45 46ArmLiveProcess::ArmLiveProcess(LiveProcessParams *params, ObjectFile *objFile) 47 : LiveProcess(params, objFile) 48{ |
49 stack_base = 0xc0000000L; | 49 stack_base = 0xbf000000L; |
50 51 // Set pointer for next thread stack. Reserve 8M for main stack. 52 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 53 54 // Set up break point (Top of Heap) 55 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 56 brk_point = roundUp(brk_point, VMPageSize); 57 --- 25 unchanged lines hidden (view full) --- 83 data_ptr = 0; 84 85 memPort->writeBlob(array_ptr, (uint8_t*)&data_ptr, sizeof(uint32_t)); 86} 87 88void 89ArmLiveProcess::argsInit(int intSize, int pageSize) 90{ | 50 51 // Set pointer for next thread stack. Reserve 8M for main stack. 52 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 53 54 // Set up break point (Top of Heap) 55 brk_point = objFile->dataBase() + objFile->dataSize() + objFile->bssSize(); 56 brk_point = roundUp(brk_point, VMPageSize); 57 --- 25 unchanged lines hidden (view full) --- 83 data_ptr = 0; 84 85 memPort->writeBlob(array_ptr, (uint8_t*)&data_ptr, sizeof(uint32_t)); 86} 87 88void 89ArmLiveProcess::argsInit(int intSize, int pageSize) 90{ |
91 typedef AuxVector<uint32_t> auxv_t; 92 std::vector<auxv_t> auxv; 93 94 string filename; 95 if (argv.size() < 1) 96 filename = ""; 97 else 98 filename = argv[0]; 99 100 //We want 16 byte alignment 101 uint64_t align = 16; 102 |
|
91 // Overloaded argsInit so that we can fine-tune for ARM architecture 92 Process::startup(); 93 94 // load object file into target memory 95 objFile->loadSections(initVirtMem); 96 | 103 // Overloaded argsInit so that we can fine-tune for ARM architecture 104 Process::startup(); 105 106 // load object file into target memory 107 objFile->loadSections(initVirtMem); 108 |
97 // Calculate how much space we need for arg & env arrays. 98 int argv_array_size = intSize * (argv.size() + 1); 99 int envp_array_size = intSize * (envp.size() + 1); 100 int arg_data_size = 0; 101 for (int i = 0; i < argv.size(); ++i) { 102 arg_data_size += argv[i].size() + 1; | 109 enum ArmCpuFeature { 110 Arm_Swp = 1 << 0, 111 Arm_Half = 1 << 1, 112 Arm_Thumb = 1 << 2, 113 Arm_26Bit = 1 << 3, 114 Arm_FastMult = 1 << 4, 115 Arm_Fpa = 1 << 5, 116 Arm_Vfp = 1 << 6, 117 Arm_Edsp = 1 << 7, 118 Arm_Java = 1 << 8, 119 Arm_Iwmmxt = 1 << 9, 120 Arm_Crunch = 1 << 10 121 }; 122 123 //Setup the auxilliary vectors. These will already have endian conversion. 124 //Auxilliary vectors are loaded only for elf formatted executables. 125 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); 126 if (elfObject) { 127 uint32_t features = 128 Arm_Swp | 129 Arm_Half | 130 Arm_Thumb | 131// Arm_26Bit | 132 Arm_FastMult | 133// Arm_Fpa | 134 Arm_Vfp | 135 Arm_Edsp | 136 Arm_Java | 137// Arm_Iwmmxt | 138// Arm_Crunch | 139 0; 140 141 //Bits which describe the system hardware capabilities 142 //XXX Figure out what these should be 143 auxv.push_back(auxv_t(M5_AT_HWCAP, features)); 144 //The system page size 145 auxv.push_back(auxv_t(M5_AT_PAGESZ, ArmISA::VMPageSize)); 146 //Frequency at which times() increments 147 auxv.push_back(auxv_t(M5_AT_CLKTCK, 0x64)); 148 // For statically linked executables, this is the virtual address of the 149 // program header tables if they appear in the executable image 150 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); 151 // This is the size of a program header entry from the elf file. 152 auxv.push_back(auxv_t(M5_AT_PHENT, elfObject->programHeaderSize())); 153 // This is the number of program headers from the original elf file. 154 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); 155 //This is the address of the elf "interpreter", It should be set 156 //to 0 for regular executables. It should be something else 157 //(not sure what) for dynamic libraries. 158 auxv.push_back(auxv_t(M5_AT_BASE, 0)); 159 160 //XXX Figure out what this should be. 161 auxv.push_back(auxv_t(M5_AT_FLAGS, 0)); 162 //The entry point to the program 163 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); 164 //Different user and group IDs 165 auxv.push_back(auxv_t(M5_AT_UID, uid())); 166 auxv.push_back(auxv_t(M5_AT_EUID, euid())); 167 auxv.push_back(auxv_t(M5_AT_GID, gid())); 168 auxv.push_back(auxv_t(M5_AT_EGID, egid())); 169 //Whether to enable "secure mode" in the executable 170 auxv.push_back(auxv_t(M5_AT_SECURE, 0)); 171 //The filename of the program 172 auxv.push_back(auxv_t(M5_AT_EXECFN, 0)); 173 //The string "v51" with unknown meaning 174 auxv.push_back(auxv_t(M5_AT_PLATFORM, 0)); |
103 } | 175 } |
176 177 //Figure out how big the initial stack nedes to be 178 179 // A sentry NULL void pointer at the top of the stack. 180 int sentry_size = intSize; 181 182 string platform = "v51"; 183 int platform_size = platform.size() + 1; 184 185 // The aux vectors are put on the stack in two groups. The first group are 186 // the vectors that are generated as the elf is loaded. The second group 187 // are the ones that were computed ahead of time and include the platform 188 // string. 189 int aux_data_size = filename.size() + 1; 190 |
|
104 int env_data_size = 0; 105 for (int i = 0; i < envp.size(); ++i) { 106 env_data_size += envp[i].size() + 1; 107 } | 191 int env_data_size = 0; 192 for (int i = 0; i < envp.size(); ++i) { 193 env_data_size += envp[i].size() + 1; 194 } |
195 int arg_data_size = 0; 196 for (int i = 0; i < argv.size(); ++i) { 197 arg_data_size += argv[i].size() + 1; 198 } |
|
108 | 199 |
109 int space_needed = 110 argv_array_size + envp_array_size + arg_data_size + env_data_size; 111 if (space_needed < 16*1024) 112 space_needed = 16*1024; | 200 int info_block_size = 201 sentry_size + env_data_size + arg_data_size + 202 aux_data_size + platform_size; |
113 | 203 |
114 // set bottom of stack | 204 //Each auxilliary vector is two 4 byte words 205 int aux_array_size = intSize * 2 * (auxv.size() + 1); 206 207 int envp_array_size = intSize * (envp.size() + 1); 208 int argv_array_size = intSize * (argv.size() + 1); 209 210 int argc_size = intSize; 211 212 //Figure out the size of the contents of the actual initial frame 213 int frame_size = 214 info_block_size + 215 aux_array_size + 216 envp_array_size + 217 argv_array_size + 218 argc_size; 219 220 //There needs to be padding after the auxiliary vector data so that the 221 //very bottom of the stack is aligned properly. 222 int partial_size = frame_size; 223 int aligned_partial_size = roundUp(partial_size, align); 224 int aux_padding = aligned_partial_size - partial_size; 225 226 int space_needed = frame_size + aux_padding; 227 |
115 stack_min = stack_base - space_needed; | 228 stack_min = stack_base - space_needed; |
116 // align it 117 stack_min = roundDown(stack_min, pageSize); | 229 stack_min = roundDown(stack_min, align); |
118 stack_size = stack_base - stack_min; | 230 stack_size = stack_base - stack_min; |
231 |
|
119 // map memory | 232 // map memory |
120 pTable->allocate(stack_min, roundUp(stack_size, pageSize)); | 233 pTable->allocate(roundDown(stack_min, pageSize), 234 roundUp(stack_size, pageSize)); |
121 122 // map out initial stack contents | 235 236 // map out initial stack contents |
123 Addr argv_array_base = stack_min + intSize; // room for argc 124 Addr envp_array_base = argv_array_base + argv_array_size; 125 Addr arg_data_base = envp_array_base + envp_array_size; 126 Addr env_data_base = arg_data_base + arg_data_size; | 237 uint32_t sentry_base = stack_base - sentry_size; 238 uint32_t aux_data_base = sentry_base - aux_data_size; 239 uint32_t env_data_base = aux_data_base - env_data_size; 240 uint32_t arg_data_base = env_data_base - arg_data_size; 241 uint32_t platform_base = arg_data_base - platform_size; 242 uint32_t auxv_array_base = platform_base - aux_array_size - aux_padding; 243 uint32_t envp_array_base = auxv_array_base - envp_array_size; 244 uint32_t argv_array_base = envp_array_base - argv_array_size; 245 uint32_t argc_base = argv_array_base - argc_size; |
127 | 246 |
247 DPRINTF(Stack, "The addresses of items on the initial stack:\n"); 248 DPRINTF(Stack, "0x%x - aux data\n", aux_data_base); 249 DPRINTF(Stack, "0x%x - env data\n", env_data_base); 250 DPRINTF(Stack, "0x%x - arg data\n", arg_data_base); 251 DPRINTF(Stack, "0x%x - platform base\n", platform_base); 252 DPRINTF(Stack, "0x%x - auxv array\n", auxv_array_base); 253 DPRINTF(Stack, "0x%x - envp array\n", envp_array_base); 254 DPRINTF(Stack, "0x%x - argv array\n", argv_array_base); 255 DPRINTF(Stack, "0x%x - argc \n", argc_base); 256 DPRINTF(Stack, "0x%x - stack min\n", stack_min); 257 |
|
128 // write contents to stack | 258 // write contents to stack |
129 uint64_t argc = argv.size(); 130 if (intSize == 8) 131 argc = htog((uint64_t)argc); 132 else if (intSize == 4) 133 argc = htog((uint32_t)argc); 134 else 135 panic("Unknown int size"); | |
136 | 259 |
137 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize); | 260 // figure out argc 261 uint32_t argc = argv.size(); 262 uint32_t guestArgc = ArmISA::htog(argc); |
138 | 263 |
139 copyStringArray32(argv, argv_array_base, arg_data_base, initVirtMem); 140 copyStringArray32(envp, envp_array_base, env_data_base, initVirtMem); | 264 //Write out the sentry void * 265 uint32_t sentry_NULL = 0; 266 initVirtMem->writeBlob(sentry_base, 267 (uint8_t*)&sentry_NULL, sentry_size); |
141 | 268 |
142 /* 143 //uint8_t insns[] = {0xe5, 0x9f, 0x00, 0x08, 0xe1, 0xa0, 0xf0, 0x0e}; 144 uint8_t insns[] = {0x08, 0x00, 0x9f, 0xe5, 0x0e, 0xf0, 0xa0, 0xe1}; | 269 //Fix up the aux vectors which point to other data 270 for (int i = auxv.size() - 1; i >= 0; i--) { 271 if (auxv[i].a_type == M5_AT_PLATFORM) { 272 auxv[i].a_val = platform_base; 273 initVirtMem->writeString(platform_base, platform.c_str()); 274 } else if (auxv[i].a_type == M5_AT_EXECFN) { 275 auxv[i].a_val = aux_data_base; 276 initVirtMem->writeString(aux_data_base, filename.c_str()); 277 } 278 } |
145 | 279 |
146 initVirtMem->writeBlob(0xffff0fe0, insns, 8); 147 */ | 280 //Copy the aux stuff 281 for(int x = 0; x < auxv.size(); x++) 282 { 283 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, 284 (uint8_t*)&(auxv[x].a_type), intSize); 285 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 286 (uint8_t*)&(auxv[x].a_val), intSize); 287 } 288 //Write out the terminating zeroed auxilliary vector 289 const uint64_t zero = 0; 290 initVirtMem->writeBlob(auxv_array_base + 2 * intSize * auxv.size(), 291 (uint8_t*)&zero, 2 * intSize); |
148 | 292 |
149 ThreadContext *tc = system->getThreadContext(contextIds[0]); | 293 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 294 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); |
150 | 295 |
151 tc->setIntReg(ArgumentReg1, argc); 152 tc->setIntReg(ArgumentReg2, argv_array_base); | 296 initVirtMem->writeBlob(argc_base, (uint8_t*)&guestArgc, intSize); 297 298 ThreadContext *tc = system->getThreadContext(contextIds[0]); 299 //Set the stack pointer register |
153 tc->setIntReg(StackPointerReg, stack_min); | 300 tc->setIntReg(StackPointerReg, stack_min); |
301 //A pointer to a function to run when the program exits. We'll set this 302 //to zero explicitly to make sure this isn't used. 303 tc->setIntReg(ArgumentReg0, 0); 304 //Set argument regs 1 and 2 to argv[0] and envp[0] respectively 305 if (argv.size() > 0) { 306 tc->setIntReg(ArgumentReg1, arg_data_base + arg_data_size - 307 argv[argv.size() - 1].size() - 1); 308 } else { 309 tc->setIntReg(ArgumentReg1, 0); 310 } 311 if (envp.size() > 0) { 312 tc->setIntReg(ArgumentReg2, env_data_base + env_data_size - 313 envp[envp.size() - 1].size() - 1); 314 } else { 315 tc->setIntReg(ArgumentReg2, 0); 316 } |
|
154 155 Addr prog_entry = objFile->entryPoint(); 156 tc->setPC(prog_entry); 157 tc->setNextPC(prog_entry + sizeof(MachInst)); | 317 318 Addr prog_entry = objFile->entryPoint(); 319 tc->setPC(prog_entry); 320 tc->setNextPC(prog_entry + sizeof(MachInst)); |
321 322 //Align the "stack_min" to a page boundary. 323 stack_min = roundDown(stack_min, pageSize); |
|
158} 159 160ArmISA::IntReg 161ArmLiveProcess::getSyscallArg(ThreadContext *tc, int i) 162{ 163 assert(i < 4); 164 return tc->readIntReg(ArgumentReg0 + i); 165} --- 15 unchanged lines hidden --- | 324} 325 326ArmISA::IntReg 327ArmLiveProcess::getSyscallArg(ThreadContext *tc, int i) 328{ 329 assert(i < 4); 330 return tc->readIntReg(ArgumentReg0 + i); 331} --- 15 unchanged lines hidden --- |