40 #include "debug/Stack.hh" 42 #include "params/Process.hh" 62 fatal_if(params->useArchPT,
"Arch page tables not implemented.");
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;
306 int aligned_partial_size =
roundUp(frame_size, align);
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");
#define panic(...)
This implements a cprintf based panic() function.
virtual void setMiscReg(RegIndex misc_reg, RegVal val)=0
const std::string & name()
void flushWindows(ThreadContext *tc) override
virtual bool tryWriteBlob(Addr addr, const void *p, int size) const
Write size bytes from p to address.
virtual TheISA::PCState pcState() const =0
SparcProcess(ProcessParams *params, ::Loader::ObjectFile *objFile, Addr _StackBias)
virtual RegVal readIntReg(RegIndex reg_idx) const =0
std::unique_ptr< SETranslatingPortProxy > initVirtMem
std::vector< ContextID > contextIds
static const std::vector< int > ArgumentRegs
void argsInit(int pageSize)
virtual void setMiscRegNoEffect(RegIndex misc_reg, RegVal val)=0
const MachInst fillHandler64[numFillInsts]
virtual PortProxy & getVirtProxy()=0
Overload hash function for BasicBlockRange type.
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
T roundUp(const T &val, const U &align)
This function is used to align addresses in memory.
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
ThreadContext * getThreadContext(ContextID tid) const
void flushWindows(ThreadContext *tc) override
void align(const scfx_rep &lhs, const scfx_rep &rhs, int &new_wp, int &len_mant, scfx_mant_ref &lhs_mant, scfx_mant_ref &rhs_mant)
const int StackPointerReg
void copyStringArray(std::vector< std::string > &strings, AddrType array_ptr, AddrType data_ptr, const ByteOrder bo, PortProxy &memProxy)
virtual void flushWindows(ThreadContext *tc)=0
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
T roundDown(const T &val, const U &align)
This function is used to align addresses in memory.
std::vector< std::string > envp
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
virtual void setIntReg(RegIndex reg_idx, RegVal val)=0
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
const MachInst spillHandler32[numSpillInsts]
void argsInit(int intSize, int pageSize)
const MachInst fillHandler32[numFillInsts]
Ancillary State Registers.
Declarations of a non-full system Page Table.
virtual void handleTrap(int trapNum, ThreadContext *tc, Fault *fault)
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
void argsInit(int intSize, int pageSize)
const ByteOrder GuestByteOrder
std::vector< std::string > argv
virtual RegVal readMiscReg(RegIndex misc_reg)=0
std::shared_ptr< FaultBase > Fault
::Loader::ObjectFile * objFile
const MachInst spillHandler64[numSpillInsts]
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Floating Point Status Register.