1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * Copyright (c) 2016 The University of Virginia 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51using namespace std; 52using namespace RiscvISA; 53 54RiscvProcess::RiscvProcess(ProcessParams * params, 55 ObjectFile *objFile) : Process(params, objFile) 56{ 57 // Set up stack. On RISC-V, stack starts at the top of kuseg 58 // user address space. RISC-V stack grows down from here |
59 memState->stackBase = (Addr)0x7FFFFFFF; |
60 61 // Set pointer for next thread stack. Reserve 8M for main stack. |
62 memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); |
63 64 // Set up break point (Top of Heap) |
65 memState->brkPoint = objFile->bssBase() + objFile->bssSize(); |
66 67 // Set up region for mmaps. Start it 1GB above the top of the heap. |
68 memState->mmapEnd = memState->brkPoint + 0x40000000L; |
69} 70 71void 72RiscvProcess::initState() 73{ 74 Process::initState(); 75 76 argsInit<uint64_t>(PageBytes); --- 42 unchanged lines hidden (view full) --- 119 for (string arg: argv) 120 arg_data_size += arg.size() + 1; 121 int envp_array_size = sizeof(Addr) * envp.size(); 122 int env_data_size = 0; 123 for (string env: envp) 124 env_data_size += env.size() + 1; 125 int auxv_array_size = 2 * sizeof(IntType)*auxv.size(); 126 |
127 memState->stackSize = sizeof(IntType) + argv_array_size + 2 * 128 sizeof(Addr) + arg_data_size + 2 * sizeof(Addr); |
129 if (!envp.empty()) { |
130 memState->stackSize += 2 * sizeof(Addr) + envp_array_size + 2 * 131 sizeof(Addr) + env_data_size; |
132 } 133 if (!auxv.empty()) |
134 memState->stackSize += 2 * sizeof(Addr) + auxv_array_size; 135 memState->stackMin = roundDown(memState->stackBase - memState->stackSize, 136 pageSize); 137 allocateMem(memState->stackMin, roundUp(memState->stackSize, pageSize)); |
138 |
139 Addr argv_array_base = memState->stackMin + sizeof(IntType); |
140 Addr arg_data_base = argv_array_base + argv_array_size + 2 * sizeof(Addr); 141 Addr envp_array_base = arg_data_base + arg_data_size; 142 if (!envp.empty()) 143 envp_array_base += 2 * sizeof(Addr); 144 Addr env_data_base = envp_array_base + envp_array_size; 145 if (!envp.empty()) 146 env_data_base += 2 * sizeof(Addr); 147 --- 8 unchanged lines hidden (view full) --- 156 vector<Addr> env_pointers; 157 if (!envp.empty()) { 158 env_pointers.push_back(env_data_base); 159 for (int i = 0; i < envp.size() - 1; i++) { 160 env_pointers.push_back(env_pointers[i] + envp[i].size() + 1); 161 } 162 } 163 |
164 Addr sp = memState->stackMin; |
165 initVirtMem.writeBlob(sp, (uint8_t *)&argc, sizeof(IntType)); 166 sp += sizeof(IntType); 167 for (Addr arg_pointer: arg_pointers) { 168 initVirtMem.writeBlob(sp, (uint8_t *)&arg_pointer, sizeof(Addr)); 169 sp += sizeof(Addr); 170 } 171 for (int i = 0; i < 2; i++) { 172 initVirtMem.writeBlob(sp, (uint8_t *)&zero, sizeof(Addr)); --- 34 unchanged lines hidden (view full) --- 207 sp += 2 * sizeof(IntType); 208 } 209 for (int i = 0; i < 2; i++) { 210 initVirtMem.writeBlob(sp, (uint8_t *)&zero, sizeof(Addr)); 211 sp += sizeof(Addr); 212 } 213 214 ThreadContext *tc = system->getThreadContext(contextIds[0]); |
215 tc->setIntReg(StackPointerReg, memState->stackMin); |
216 tc->pcState(getStartPC()); 217} 218 219RiscvISA::IntReg 220RiscvProcess::getSyscallArg(ThreadContext *tc, int &i) 221{ 222 // RISC-V only has four system call argument registers by convention, so 223 // if a larger index is requested return 0 --- 24 unchanged lines hidden --- |