Deleted Added
sdiff udiff text old ( 11854:0e94e16e26ea ) new ( 11886:43b882cada33 )
full compact
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;
60
61 // Set pointer for next thread stack. Reserve 8M for main stack.
62 next_thread_stack_base = stack_base - (8 * 1024 * 1024);
63
64 // Set up break point (Top of Heap)
65 brk_point = objFile->bssBase() + objFile->bssSize();
66
67 // Set up region for mmaps. Start it 1GB above the top of the heap.
68 mmap_end = brk_point + 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 stack_size = sizeof(IntType) + argv_array_size + 2 * sizeof(Addr) +
128 arg_data_size + 2 * sizeof(Addr);
129 if (!envp.empty()) {
130 stack_size += 2 * sizeof(Addr) + envp_array_size + 2 * sizeof(Addr) +
131 env_data_size;
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));
137
138 Addr argv_array_base = stack_min + 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
163 Addr sp = stack_min;
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]);
214 tc->setIntReg(StackPointerReg, stack_min);
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 ---