process.cc (5713:993c7952b930) | process.cc (5759:6e65ac8a2c80) |
---|---|
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; --- 18 unchanged lines hidden (view full) --- 27 * 28 * Authors: Gabe Black 29 * Ali Saidi 30 */ 31 32#include "arch/alpha/isa_traits.hh" 33#include "arch/alpha/process.hh" 34#include "base/loader/object_file.hh" | 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; --- 18 unchanged lines hidden (view full) --- 27 * 28 * Authors: Gabe Black 29 * Ali Saidi 30 */ 31 32#include "arch/alpha/isa_traits.hh" 33#include "arch/alpha/process.hh" 34#include "base/loader/object_file.hh" |
35#include "base/loader/elf_object.hh" |
|
35#include "base/misc.hh" 36#include "cpu/thread_context.hh" | 36#include "base/misc.hh" 37#include "cpu/thread_context.hh" |
38#include "mem/page_table.hh" 39#include "sim/process_impl.hh" |
|
37#include "sim/system.hh" 38 39using namespace AlphaISA; 40using namespace std; 41 42AlphaLiveProcess::AlphaLiveProcess(LiveProcessParams *params, 43 ObjectFile *objFile) 44 : LiveProcess(params, objFile) --- 10 unchanged lines hidden (view full) --- 55 mmap_start = mmap_end = 0x10000; 56 57 // Set pointer for next thread stack. Reserve 8M for main stack. 58 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 59 60} 61 62void | 40#include "sim/system.hh" 41 42using namespace AlphaISA; 43using namespace std; 44 45AlphaLiveProcess::AlphaLiveProcess(LiveProcessParams *params, 46 ObjectFile *objFile) 47 : LiveProcess(params, objFile) --- 10 unchanged lines hidden (view full) --- 58 mmap_start = mmap_end = 0x10000; 59 60 // Set pointer for next thread stack. Reserve 8M for main stack. 61 next_thread_stack_base = stack_base - (8 * 1024 * 1024); 62 63} 64 65void |
66AlphaLiveProcess::argsInit(int intSize, int pageSize) 67{ 68 objFile->loadSections(initVirtMem); 69 70 typedef M5_auxv_t<uint64_t> auxv_t; 71 std::vector<auxv_t> auxv; 72 73 ElfObject * elfObject = dynamic_cast<ElfObject *>(objFile); 74 if(elfObject) 75 { 76 // modern glibc uses a bunch of auxiliary vectors to set up 77 // TLS as well as do a bunch of other stuff 78 // these vectors go on the bottom of the stack, below argc/argv/envp 79 // pointers but above actual arg strings 80 // I don't have all the ones glibc looks at here, but so far it doesn't 81 // seem to be a problem. 82 // check out _dl_aux_init() in glibc/elf/dl-support.c for details 83 // --Lisa 84 auxv.push_back(auxv_t(M5_AT_PAGESZ, AlphaISA::VMPageSize)); 85 auxv.push_back(auxv_t(M5_AT_CLKTCK, 100)); 86 auxv.push_back(auxv_t(M5_AT_PHDR, elfObject->programHeaderTable())); 87 DPRINTF(Loader, "auxv at PHDR %08p\n", elfObject->programHeaderTable()); 88 auxv.push_back(auxv_t(M5_AT_PHNUM, elfObject->programHeaderCount())); 89 auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint())); 90 auxv.push_back(auxv_t(M5_AT_UID, uid())); 91 auxv.push_back(auxv_t(M5_AT_EUID, euid())); 92 auxv.push_back(auxv_t(M5_AT_GID, gid())); 93 auxv.push_back(auxv_t(M5_AT_EGID, egid())); 94 95 } 96 97 // Calculate how much space we need for arg & env & auxv arrays. 98 int argv_array_size = intSize * (argv.size() + 1); 99 int envp_array_size = intSize * (envp.size() + 1); 100 int auxv_array_size = intSize * 2 * (auxv.size() + 1); 101 102 int arg_data_size = 0; 103 for (int i = 0; i < argv.size(); ++i) { 104 arg_data_size += argv[i].size() + 1; 105 } 106 int env_data_size = 0; 107 for (int i = 0; i < envp.size(); ++i) { 108 env_data_size += envp[i].size() + 1; 109 } 110 111 int space_needed = 112 argv_array_size + 113 envp_array_size + 114 auxv_array_size + 115 arg_data_size + 116 env_data_size; 117 118 if (space_needed < 32*1024) 119 space_needed = 32*1024; 120 121 // set bottom of stack 122 stack_min = stack_base - space_needed; 123 // align it 124 stack_min = roundDown(stack_min, pageSize); 125 stack_size = stack_base - stack_min; 126 // map memory 127 pTable->allocate(stack_min, roundUp(stack_size, pageSize)); 128 129 // map out initial stack contents 130 Addr argv_array_base = stack_min + intSize; // room for argc 131 Addr envp_array_base = argv_array_base + argv_array_size; 132 Addr auxv_array_base = envp_array_base + envp_array_size; 133 Addr arg_data_base = auxv_array_base + auxv_array_size; 134 Addr env_data_base = arg_data_base + arg_data_size; 135 136 // write contents to stack 137 uint64_t argc = argv.size(); 138 if (intSize == 8) 139 argc = htog((uint64_t)argc); 140 else if (intSize == 4) 141 argc = htog((uint32_t)argc); 142 else 143 panic("Unknown int size"); 144 145 initVirtMem->writeBlob(stack_min, (uint8_t*)&argc, intSize); 146 147 copyStringArray(argv, argv_array_base, arg_data_base, initVirtMem); 148 copyStringArray(envp, envp_array_base, env_data_base, initVirtMem); 149 150 //Copy the aux stuff 151 for(int x = 0; x < auxv.size(); x++) 152 { 153 initVirtMem->writeBlob(auxv_array_base + x * 2 * intSize, 154 (uint8_t*)&(auxv[x].a_type), intSize); 155 initVirtMem->writeBlob(auxv_array_base + (x * 2 + 1) * intSize, 156 (uint8_t*)&(auxv[x].a_val), intSize); 157 } 158 159 assert(NumArgumentRegs >= 2); 160 161 ThreadContext *tc = system->getThreadContext(contextIds[0]); 162 163 tc->setIntReg(ArgumentReg[0], argc); 164 tc->setIntReg(ArgumentReg[1], argv_array_base); 165 tc->setIntReg(StackPointerReg, stack_min); 166 167 Addr prog_entry = objFile->entryPoint(); 168 tc->setPC(prog_entry); 169 tc->setNextPC(prog_entry + sizeof(MachInst)); 170 171#if THE_ISA != ALPHA_ISA //e.g. MIPS or Sparc 172 tc->setNextNPC(prog_entry + (2 * sizeof(MachInst))); 173#endif 174 175 176} 177 178void |
|
63AlphaLiveProcess::startup() 64{ 65 if (checkpointRestored) 66 return; 67 | 179AlphaLiveProcess::startup() 180{ 181 if (checkpointRestored) 182 return; 183 |
184 Process::startup(); 185 |
|
68 argsInit(MachineBytes, VMPageSize); 69 70 ThreadContext *tc = system->getThreadContext(contextIds[0]); 71 tc->setIntReg(GlobalPointerReg, objFile->globalPointer()); 72 //Operate in user mode 73 tc->setMiscRegNoEffect(IPR_ICM, 0x18); 74 //No super page mapping 75 tc->setMiscRegNoEffect(IPR_MCSR, 0); 76 //Set this to 0 for now, but it should be unique for each process 77 tc->setMiscRegNoEffect(IPR_DTB_ASN, M5_pid << 57); 78} 79 | 186 argsInit(MachineBytes, VMPageSize); 187 188 ThreadContext *tc = system->getThreadContext(contextIds[0]); 189 tc->setIntReg(GlobalPointerReg, objFile->globalPointer()); 190 //Operate in user mode 191 tc->setMiscRegNoEffect(IPR_ICM, 0x18); 192 //No super page mapping 193 tc->setMiscRegNoEffect(IPR_MCSR, 0); 194 //Set this to 0 for now, but it should be unique for each process 195 tc->setMiscRegNoEffect(IPR_DTB_ASN, M5_pid << 57); 196} 197 |