40 #include "debug/Stack.hh"
42 #include "params/Process.hh"
74 warn(
"Software breakpoint encountered at pc %#x.\n",
pc.pc());
77 warn(
"Software signaled a division by zero at pc %#x.\n",
pc.pc());
83 warn(
"Ignoring process request for clean register "
84 "windows at pc %#x.\n",
pc.pc());
87 warn(
"Software signaled a range check at pc %#x.\n",
pc.pc());
90 warn(
"Ignoring process request for os assisted unaligned accesses "
91 "at pc %#x.\n",
pc.pc());
94 warn(
"Software signaled an integer overflow at pc %#x.\n",
pc.pc());
97 warn(
"Ignoring process request to get the integer condition codes "
98 "at pc %#x.\n",
pc.pc());
101 warn(
"Ignoring process request to set the integer condition codes "
102 "at pc %#x.\n",
pc.pc());
105 panic(
"Unimplemented trap to operating system: trap number %#x.\n", trapNum);
182 template<
class IntType>
186 int intSize =
sizeof(IntType);
202 M5_HWCAP_SPARC_FLUSH = 1,
203 M5_HWCAP_SPARC_STBAR = 2,
204 M5_HWCAP_SPARC_SWAP = 4,
205 M5_HWCAP_SPARC_MULDIV = 8,
206 M5_HWCAP_SPARC_V9 = 16,
210 M5_HWCAP_SPARC_ULTRA3 = 32
213 const int64_t hwcap =
214 M5_HWCAP_SPARC_FLUSH |
215 M5_HWCAP_SPARC_STBAR |
216 M5_HWCAP_SPARC_SWAP |
217 M5_HWCAP_SPARC_MULDIV |
219 M5_HWCAP_SPARC_ULTRA3;
234 auxv.emplace_back(
M5_AT_PHDR, elfObject->programHeaderTable());
236 auxv.emplace_back(
M5_AT_PHENT, elfObject->programHeaderSize());
238 auxv.emplace_back(
M5_AT_PHNUM, elfObject->programHeaderCount());
265 int file_name_size = filename.size() + 1;
267 const int numRandomBytes = 16;
268 int aux_data_size = numRandomBytes;
270 int env_data_size = 0;
271 for (
int i = 0;
i <
envp.size(); ++
i) {
272 env_data_size +=
envp[
i].size() + 1;
274 int arg_data_size = 0;
275 for (
int i = 0;
i <
argv.size(); ++
i) {
276 arg_data_size +=
argv[
i].size() + 1;
280 int base_info_block_size =
281 sentry_size + file_name_size + env_data_size + arg_data_size;
283 int info_block_size =
roundUp(base_info_block_size,
align);
285 int info_block_padding = info_block_size - base_info_block_size;
288 int aux_array_size = intSize * 2 * (auxv.size() + 1);
290 int envp_array_size = intSize * (
envp.size() + 1);
291 int argv_array_size = intSize * (
argv.size() + 1);
293 int argc_size = intSize;
294 int window_save_size = intSize * 16;
307 int aux_padding = aligned_partial_size - frame_size;
324 IntType sentry_base =
memState->getStackBase() - sentry_size;
325 IntType file_name_base = sentry_base - file_name_size;
326 IntType env_data_base = file_name_base - env_data_size;
327 IntType arg_data_base = env_data_base - arg_data_size;
328 IntType aux_data_base = arg_data_base - info_block_padding - aux_data_size;
329 IntType auxv_array_base = aux_data_base - aux_array_size - aux_padding;
330 IntType envp_array_base = auxv_array_base - envp_array_size;
331 IntType argv_array_base = envp_array_base - argv_array_size;
332 IntType argc_base = argv_array_base - argc_size;
334 IntType window_save_base = argc_base - window_save_size;
337 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
338 DPRINTF(Stack,
"%#x - sentry NULL\n", sentry_base);
339 DPRINTF(Stack,
"filename = %s\n", filename);
340 DPRINTF(Stack,
"%#x - file name\n", file_name_base);
341 DPRINTF(Stack,
"%#x - env data\n", env_data_base);
342 DPRINTF(Stack,
"%#x - arg data\n", arg_data_base);
343 DPRINTF(Stack,
"%#x - auxv array\n", auxv_array_base);
344 DPRINTF(Stack,
"%#x - envp array\n", envp_array_base);
345 DPRINTF(Stack,
"%#x - argv array\n", argv_array_base);
346 DPRINTF(Stack,
"%#x - argc \n", argc_base);
347 DPRINTF(Stack,
"%#x - window save\n", window_save_base);
350 assert(window_save_base ==
memState->getStackMin());
355 IntType argc =
argv.size();
356 IntType guestArgc =
htobe(argc);
359 uint64_t sentry_NULL = 0;
360 initVirtMem->writeBlob(sentry_base, &sentry_NULL, sentry_size);
363 initVirtMem->writeString(file_name_base, filename.c_str());
366 for (
auto &aux: auxv) {
368 aux.val = aux_data_base;
372 Addr auxv_array_end = auxv_array_base;
373 for (
const auto &aux: auxv) {
375 auxv_array_end +=
sizeof(aux);
381 auxv_array_end +=
sizeof(zero);
388 initVirtMem->writeBlob(argc_base, &guestArgc, intSize);
416 SparcProcess::argsInit<uint64_t>(pageSize);
428 SparcProcess::argsInit<uint32_t>(pageSize);
444 CWP = (CWP + Cansave + 2) %
NWindows;
445 while (
NWindows - 2 - Cansave != 0) {
447 panic(
"Otherwin non-zero.\n");
454 regVal =
htobe(regVal);
456 sp + (
index - 16) * 4, (uint8_t *)®Val, 4)) {
457 warn(
"Failed to save register to the stack when "
458 "flushing windows.\n");
479 CWP = (CWP + Cansave + 2) %
NWindows;
480 while (
NWindows - 2 - Cansave != 0) {
482 panic(
"Otherwin non-zero.\n");
489 regVal =
htobe(regVal);
491 sp + 2047 + (
index - 16) * 8, (uint8_t *)®Val, 8)) {
492 warn(
"Failed to save register to the stack when "
493 "flushing windows.\n");