process.cc (11854:0e94e16e26ea) | process.cc (11886:43b882cada33) |
---|---|
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 | 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 stack_base = 0x7FFFFFFF; | 59 memState->stackBase = (Addr)0x7FFFFFFF; |
60 61 // Set pointer for next thread stack. Reserve 8M for main stack. | 60 61 // Set pointer for next thread stack. Reserve 8M for main stack. |
62 next_thread_stack_base = stack_base - (8 * 1024 * 1024); | 62 memState->nextThreadStackBase = memState->stackBase - (8 * 1024 * 1024); |
63 64 // Set up break point (Top of Heap) | 63 64 // Set up break point (Top of Heap) |
65 brk_point = objFile->bssBase() + objFile->bssSize(); | 65 memState->brkPoint = objFile->bssBase() + objFile->bssSize(); |
66 67 // Set up region for mmaps. Start it 1GB above the top of the heap. | 66 67 // Set up region for mmaps. Start it 1GB above the top of the heap. |
68 mmap_end = brk_point + 0x40000000L; | 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 | 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 stack_size = sizeof(IntType) + argv_array_size + 2 * sizeof(Addr) + 128 arg_data_size + 2 * sizeof(Addr); | 127 memState->stackSize = sizeof(IntType) + argv_array_size + 2 * 128 sizeof(Addr) + arg_data_size + 2 * sizeof(Addr); |
129 if (!envp.empty()) { | 129 if (!envp.empty()) { |
130 stack_size += 2 * sizeof(Addr) + envp_array_size + 2 * sizeof(Addr) + 131 env_data_size; | 130 memState->stackSize += 2 * sizeof(Addr) + envp_array_size + 2 * 131 sizeof(Addr) + env_data_size; |
132 } 133 if (!auxv.empty()) | 132 } 133 if (!auxv.empty()) |
134 stack_size += 2 * sizeof(Addr) + auxv_array_size; 135 stack_min = roundDown(stack_base - stack_size, pageSize); 136 allocateMem(stack_min, roundUp(stack_size, pageSize)); | 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)); |
137 | 138 |
138 Addr argv_array_base = stack_min + sizeof(IntType); | 139 Addr argv_array_base = memState->stackMin + sizeof(IntType); |
139 Addr arg_data_base = argv_array_base + argv_array_size + 2 * sizeof(Addr); 140 Addr envp_array_base = arg_data_base + arg_data_size; 141 if (!envp.empty()) 142 envp_array_base += 2 * sizeof(Addr); 143 Addr env_data_base = envp_array_base + envp_array_size; 144 if (!envp.empty()) 145 env_data_base += 2 * sizeof(Addr); 146 --- 8 unchanged lines hidden (view full) --- 155 vector<Addr> env_pointers; 156 if (!envp.empty()) { 157 env_pointers.push_back(env_data_base); 158 for (int i = 0; i < envp.size() - 1; i++) { 159 env_pointers.push_back(env_pointers[i] + envp[i].size() + 1); 160 } 161 } 162 | 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 |
163 Addr sp = stack_min; | 164 Addr sp = memState->stackMin; |
164 initVirtMem.writeBlob(sp, (uint8_t *)&argc, sizeof(IntType)); 165 sp += sizeof(IntType); 166 for (Addr arg_pointer: arg_pointers) { 167 initVirtMem.writeBlob(sp, (uint8_t *)&arg_pointer, sizeof(Addr)); 168 sp += sizeof(Addr); 169 } 170 for (int i = 0; i < 2; i++) { 171 initVirtMem.writeBlob(sp, (uint8_t *)&zero, sizeof(Addr)); --- 34 unchanged lines hidden (view full) --- 206 sp += 2 * sizeof(IntType); 207 } 208 for (int i = 0; i < 2; i++) { 209 initVirtMem.writeBlob(sp, (uint8_t *)&zero, sizeof(Addr)); 210 sp += sizeof(Addr); 211 } 212 213 ThreadContext *tc = system->getThreadContext(contextIds[0]); | 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]); |
214 tc->setIntReg(StackPointerReg, stack_min); | 215 tc->setIntReg(StackPointerReg, memState->stackMin); |
215 tc->pcState(getStartPC()); 216} 217 218RiscvISA::IntReg 219RiscvProcess::getSyscallArg(ThreadContext *tc, int &i) 220{ 221 // RISC-V only has four system call argument registers by convention, so 222 // if a larger index is requested return 0 --- 24 unchanged lines hidden --- | 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 --- |