43 #include "debug/Stack.hh"
51 using namespace SparcISA;
58 :
Process(params, objFile), StackBias(_StackBias)
71 warn(
"Software breakpoint encountered at pc %#x.\n", pc.
pc());
74 warn(
"Software signaled a division by zero at pc %#x.\n", pc.
pc());
80 warn(
"Ignoring process request for clean register "
81 "windows at pc %#x.\n", pc.
pc());
84 warn(
"Software signaled a range check at pc %#x.\n", pc.
pc());
87 warn(
"Ignoring process request for os assisted unaligned accesses "
88 "at pc %#x.\n", pc.
pc());
91 warn(
"Software signaled an integer overflow at pc %#x.\n", pc.
pc());
94 warn(
"Ignoring process request to get the integer condition codes "
95 "at pc %#x.\n", pc.
pc());
98 warn(
"Ignoring process request to set the integer condition codes "
99 "at pc %#x.\n", pc.
pc());
102 panic(
"Unimplemented trap to operating system: trap number %#x.\n", trapNum);
184 template<
class IntType>
188 int intSize =
sizeof(IntType);
212 M5_HWCAP_SPARC_FLUSH = 1,
213 M5_HWCAP_SPARC_STBAR = 2,
214 M5_HWCAP_SPARC_SWAP = 4,
215 M5_HWCAP_SPARC_MULDIV = 8,
216 M5_HWCAP_SPARC_V9 = 16,
220 M5_HWCAP_SPARC_ULTRA3 = 32
223 const int64_t hwcap =
224 M5_HWCAP_SPARC_FLUSH |
225 M5_HWCAP_SPARC_STBAR |
226 M5_HWCAP_SPARC_SWAP |
227 M5_HWCAP_SPARC_MULDIV |
229 M5_HWCAP_SPARC_ULTRA3;
273 int file_name_size = filename.size() + 1;
275 int env_data_size = 0;
276 for (
int i = 0;
i <
envp.size(); ++
i) {
277 env_data_size +=
envp[
i].size() + 1;
279 int arg_data_size = 0;
280 for (
int i = 0;
i <
argv.size(); ++
i) {
281 arg_data_size +=
argv[
i].size() + 1;
285 int base_info_block_size =
286 sentry_size + file_name_size + env_data_size + arg_data_size;
288 int info_block_size =
roundUp(base_info_block_size, align);
290 int info_block_padding = info_block_size - base_info_block_size;
293 int aux_array_size = intSize * 2 * (auxv.size() + 1);
295 int envp_array_size = intSize * (
envp.size() + 1);
296 int argv_array_size = intSize * (
argv.size() + 1);
298 int argc_size = intSize;
299 int window_save_size = intSize * 16;
311 int aligned_partial_size =
roundUp(frame_size, align);
312 int aux_padding = aligned_partial_size - frame_size;
328 IntType sentry_base =
memState->getStackBase() - sentry_size;
329 IntType file_name_base = sentry_base - file_name_size;
330 IntType env_data_base = file_name_base - env_data_size;
331 IntType arg_data_base = env_data_base - arg_data_size;
332 IntType auxv_array_base = arg_data_base -
333 info_block_padding - aux_array_size - aux_padding;
334 IntType envp_array_base = auxv_array_base - envp_array_size;
335 IntType argv_array_base = envp_array_base - argv_array_size;
336 IntType argc_base = argv_array_base - argc_size;
338 IntType window_save_base = argc_base - window_save_size;
341 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
342 DPRINTF(Stack,
"%#x - sentry NULL\n", sentry_base);
343 DPRINTF(Stack,
"filename = %s\n", filename);
344 DPRINTF(Stack,
"%#x - file name\n", file_name_base);
345 DPRINTF(Stack,
"%#x - env data\n", env_data_base);
346 DPRINTF(Stack,
"%#x - arg data\n", arg_data_base);
347 DPRINTF(Stack,
"%#x - auxv array\n", auxv_array_base);
348 DPRINTF(Stack,
"%#x - envp array\n", envp_array_base);
349 DPRINTF(Stack,
"%#x - argv array\n", argv_array_base);
350 DPRINTF(Stack,
"%#x - argc \n", argc_base);
351 DPRINTF(Stack,
"%#x - window save\n", window_save_base);
354 assert(window_save_base ==
memState->getStackMin());
359 IntType argc =
argv.size();
363 uint64_t sentry_NULL = 0;
365 (uint8_t*)&sentry_NULL, sentry_size);
371 for (
int x = 0;
x < auxv.size();
x++) {
373 (uint8_t*)&(auxv[
x].a_type), intSize);
375 (uint8_t*)&(auxv[
x].a_val), intSize);
379 const IntType zero = 0;
381 (uint8_t*)&zero, intSize);
383 (uint8_t*)&zero, 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 =
htog(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 =
htog(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");
547 val =
bits(val, 31, 0);
555 val =
bits(val, 31, 0);
void setSyscallArg(ThreadContext *tc, int i, SparcISA::IntReg val)
Addr programHeaderTable()
std::vector< ContextID > contextIds
void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
void argsInit(int pageSize)
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
SparcProcess(ProcessParams *params, ObjectFile *objFile, Addr _StackBias)
virtual MiscReg readMiscRegNoEffect(int misc_reg) const =0
SETranslatingPortProxy initVirtMem
void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
const MachInst fillHandler64[numFillInsts]
virtual void setMiscReg(int misc_reg, const MiscReg &val)=0
virtual void setIntReg(int reg_idx, uint64_t val)=0
SparcISA::IntReg getSyscallArg(ThreadContext *tc, int &i)
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
virtual TheISA::PCState pcState()=0
T roundUp(const T &val, const U &align)
std::shared_ptr< MemState > memState
ThreadContext is the external interface to all thread state for anything outside of the CPU...
void flushWindows(ThreadContext *tc)
virtual uint64_t readIntReg(int reg_idx)=0
int64_t returnValue() const
The return value.
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)
int errnoValue() const
The errno value.
virtual void flushWindows(ThreadContext *tc)=0
SparcISA::IntReg getSyscallArg(ThreadContext *tc, int &i)
const RegIndex StackPointerReg
T roundDown(const T &val, const U &align)
virtual SETranslatingPortProxy & getMemProxy()=0
std::vector< std::string > envp
ThreadContext * getThreadContext(ContextID tid)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
virtual bool loadSections(PortProxy &mem_proxy, Addr mask=maxAddr, Addr offset=0)
const MachInst spillHandler32[numSpillInsts]
void argsInit(int intSize, int pageSize)
const MachInst fillHandler32[numFillInsts]
Ancillary State Registers.
uint16_t programHeaderSize()
void copyStringArray(std::vector< std::string > &strings, AddrType array_ptr, AddrType data_ptr, SETranslatingPortProxy &memProxy)
virtual MiscReg readMiscReg(int misc_reg)=0
void writeString(Addr addr, const char *str) const
Declarations of a non-full system Page Table.
uint16_t programHeaderCount()
static const int FirstArgumentReg
void flushWindows(ThreadContext *tc)
virtual void handleTrap(int trapNum, ThreadContext *tc, Fault *fault)
void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
void argsInit(int intSize, int pageSize)
const RegIndex ReturnValueReg
std::vector< std::string > argv
This class represents the return value from an emulated system call, including any errno setting...
void setSyscallArg(ThreadContext *tc, int i, SparcISA::IntReg val)
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val)=0
bool successful() const
Was the system call successful?
std::shared_ptr< FaultBase > Fault
bool tryWriteBlob(Addr addr, const uint8_t *p, int size) const
const MachInst spillHandler64[numSpillInsts]
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.
Floating Point Status Register.