60 #include "debug/Stack.hh"
70 using namespace X86ISA;
98 X86Process::X86Process(ProcessParams * params,
ObjectFile *objFile,
100 :
Process(params, objFile), syscallDescs(_syscallDescs),
101 numSyscallDescs(_numSyscallDescs)
115 :
X86Process(params, objFile, _syscallDescs, _numSyscallDescs)
125 Addr stack_base = 0x7FFFFFFFF000
ULL;
126 Addr max_stack_size = 8 * 1024 * 1024;
127 Addr next_thread_stack_base = stack_base - max_stack_size;
128 Addr mmap_end = 0x7FFFF7FFF000
ULL;
130 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
131 next_thread_stack_base, mmap_end);
150 :
X86Process(params, objFile, _syscallDescs, _numSyscallDescs)
163 Addr max_stack_size = 8 * 1024 * 1024;
164 Addr next_thread_stack_base = stack_base - max_stack_size;
167 memState = make_shared<MemState>(brk_point, stack_base, max_stack_size,
168 next_thread_stack_base, mmap_end);
188 uint8_t vtimeBlob[] = {
189 0x48,0xc7,0xc0,0xc9,0x00,0x00,0x00,
194 vtimeBlob,
sizeof(vtimeBlob));
196 uint8_t vgettimeofdayBlob[] = {
197 0x48,0xc7,0xc0,0x60,0x00,0x00,0x00,
202 vgettimeofdayBlob,
sizeof(vgettimeofdayBlob));
210 uint8_t numGDTEntries = 0;
211 uint64_t nullDescriptor = 0;
213 (uint8_t *)(&nullDescriptor), 8);
216 SegDescriptor initDesc = 0;
217 initDesc.type.codeOrData = 0;
226 initDesc.limitHigh = 0xFFFF;
227 initDesc.limitLow = 0xF;
228 initDesc.baseHigh = 0x0;
229 initDesc.baseLow = 0x0;
232 SegDescriptor csLowPLDesc = initDesc;
233 csLowPLDesc.type.codeOrData = 1;
235 uint64_t csLowPLDescVal = csLowPLDesc;
237 (uint8_t *)(&csLowPLDescVal), 8);
241 SegSelector csLowPL = 0;
242 csLowPL.si = numGDTEntries - 1;
246 SegDescriptor dsLowPLDesc = initDesc;
247 dsLowPLDesc.type.codeOrData = 0;
249 uint64_t dsLowPLDescVal = dsLowPLDesc;
251 (uint8_t *)(&dsLowPLDescVal), 8);
255 SegSelector dsLowPL = 0;
256 dsLowPL.si = numGDTEntries - 1;
260 SegDescriptor dsDesc = initDesc;
261 dsDesc.type.codeOrData = 0;
263 uint64_t dsDescVal = dsDesc;
265 (uint8_t *)(&dsDescVal), 8);
270 ds.si = numGDTEntries - 1;
274 SegDescriptor csDesc = initDesc;
275 csDesc.type.codeOrData = 1;
277 uint64_t csDescVal = csDesc;
279 (uint8_t *)(&csDescVal), 8);
284 cs.si = numGDTEntries - 1;
287 SegSelector scall = 0;
288 scall.si = csLowPL.si;
291 SegSelector sret = 0;
292 sret.si = dsLowPL.si;
296 TSSlow TSSDescLow = 0;
297 TSSDescLow.type = 0xB;
301 TSSDescLow.limitHigh = 0xF;
302 TSSDescLow.limitLow = 0xFFFF;
306 TSShigh TSSDescHigh = 0;
312 } tssDescVal = {TSSDescLow, TSSDescHigh};
315 (uint8_t *)(&tssDescVal),
sizeof(tssDescVal));
319 SegSelector tssSel = 0;
320 tssSel.si = numGDTEntries - 1;
322 uint64_t tss_base_addr = (TSSDescHigh.base << 32) |
323 (TSSDescLow.baseHigh << 24) |
325 uint64_t tss_limit = TSSDescLow.limitLow | (TSSDescLow.limitHigh << 16);
327 SegAttr tss_attr = 0;
329 tss_attr.type = TSSDescLow.type;
330 tss_attr.dpl = TSSDescLow.dpl;
331 tss_attr.present = TSSDescLow.p;
332 tss_attr.granularity = TSSDescLow.g;
333 tss_attr.unusable = 0;
440 MiscReg sfmask = (1 << 8) | (1 << 10);
478 tss.IST1_low = IST_start;
479 tss.IST1_high = IST_start >> 32;
480 tss.RSP0_low = tss.IST1_low;
481 tss.RSP0_high = tss.IST1_high;
482 tss.RSP1_low = tss.IST1_low;
483 tss.RSP1_high = tss.IST1_high;
484 tss.RSP2_low = tss.IST1_low;
485 tss.RSP2_high = tss.IST1_high;
489 GateDescriptorLow PFGateLow = 0;
492 PFGateLow.selector = csLowPL;
495 PFGateLow.type = 0xe;
498 GateDescriptorHigh PFGateHigh = 0;
504 } PFGate = {PFGateLow, PFGateHigh};
507 (uint8_t *)(&PFGate),
sizeof(PFGate));
510 uint8_t syscallBlob[] = {
512 0x48, 0xa3, 0x00, 0x60, 0x00,
513 0x00, 0x00, 0xc9, 0xff, 0xff,
519 syscallBlob,
sizeof(syscallBlob));
522 uint8_t faultBlob[] = {
524 0x48, 0xa3, 0x00, 0x61, 0x00,
525 0x00, 0x00, 0xc9, 0xff, 0xff,
527 0x48, 0x83, 0xc4, 0x08,
555 SegAttr dataAttr = 0;
557 dataAttr.unusable = 0;
558 dataAttr.defaultSize = 1;
559 dataAttr.longMode = 1;
561 dataAttr.granularity = 1;
562 dataAttr.present = 1;
564 dataAttr.writable = 1;
565 dataAttr.readable = 1;
566 dataAttr.expandDown = 0;
579 csAttr.defaultSize = 0;
582 csAttr.granularity = 1;
587 csAttr.expandDown = 0;
636 assert(
_gdtSize %
sizeof(zero) == 0);
644 uint8_t vsyscallBlob[] = {
652 vsyscallBlob,
sizeof(vsyscallBlob));
654 uint8_t vsysexitBlob[] = {
661 vsysexitBlob,
sizeof(vsysexitBlob));
666 SegAttr dataAttr = 0;
668 dataAttr.unusable = 0;
669 dataAttr.defaultSize = 1;
670 dataAttr.longMode = 0;
672 dataAttr.granularity = 1;
673 dataAttr.present = 1;
675 dataAttr.writable = 1;
676 dataAttr.readable = 1;
677 dataAttr.expandDown = 0;
692 csAttr.defaultSize = 1;
695 csAttr.granularity = 1;
700 csAttr.expandDown = 0;
742 template<
class IntType>
747 int intSize =
sizeof(IntType);
768 X86_OnboardFPU = 1 << 0,
769 X86_VirtualModeExtensions = 1 << 1,
770 X86_DebuggingExtensions = 1 << 2,
771 X86_PageSizeExtensions = 1 << 3,
773 X86_TimeStampCounter = 1 << 4,
774 X86_ModelSpecificRegisters = 1 << 5,
775 X86_PhysicalAddressExtensions = 1 << 6,
776 X86_MachineCheckExtensions = 1 << 7,
778 X86_CMPXCHG8Instruction = 1 << 8,
779 X86_OnboardAPIC = 1 << 9,
780 X86_SYSENTER_SYSEXIT = 1 << 11,
782 X86_MemoryTypeRangeRegisters = 1 << 12,
783 X86_PageGlobalEnable = 1 << 13,
784 X86_MachineCheckArchitecture = 1 << 14,
785 X86_CMOVInstruction = 1 << 15,
787 X86_PageAttributeTable = 1 << 16,
788 X86_36BitPSEs = 1 << 17,
789 X86_ProcessorSerialNumber = 1 << 18,
790 X86_CLFLUSHInstruction = 1 << 19,
792 X86_DebugTraceStore = 1 << 21,
793 X86_ACPIViaMSR = 1 << 22,
794 X86_MultimediaExtensions = 1 << 23,
796 X86_FXSAVE_FXRSTOR = 1 << 24,
797 X86_StreamingSIMDExtensions = 1 << 25,
798 X86_StreamingSIMDExtensions2 = 1 << 26,
799 X86_CPUSelfSnoop = 1 << 27,
801 X86_HyperThreading = 1 << 28,
802 X86_AutomaticClockControl = 1 << 29,
803 X86_IA64Processor = 1 << 30
814 X86_VirtualModeExtensions |
815 X86_DebuggingExtensions |
816 X86_PageSizeExtensions |
817 X86_TimeStampCounter |
818 X86_ModelSpecificRegisters |
819 X86_PhysicalAddressExtensions |
820 X86_MachineCheckExtensions |
821 X86_CMPXCHG8Instruction |
823 X86_SYSENTER_SYSEXIT |
824 X86_MemoryTypeRangeRegisters |
825 X86_PageGlobalEnable |
826 X86_MachineCheckArchitecture |
827 X86_CMOVInstruction |
828 X86_PageAttributeTable |
831 X86_CLFLUSHInstruction |
834 X86_MultimediaExtensions |
836 X86_StreamingSIMDExtensions |
837 X86_StreamingSIMDExtensions2 |
885 int sentry_size = intSize;
889 int file_name_size = filename.size() + 1;
891 const int numRandomBytes = 16;
892 int aux_data_size = numRandomBytes;
894 string platform =
"x86_64";
895 aux_data_size += platform.size() + 1;
897 int env_data_size = 0;
898 for (
int i = 0;
i <
envp.size(); ++
i)
900 int arg_data_size = 0;
901 for (
int i = 0;
i <
argv.size(); ++
i)
908 int base_info_block_size =
909 sentry_size + file_name_size + env_data_size + arg_data_size;
911 int info_block_size =
roundUp(base_info_block_size, align);
913 int info_block_padding = info_block_size - base_info_block_size;
916 int aux_array_size = intSize * 2 * (auxv.size() + 1);
918 int envp_array_size = intSize * (
envp.size() + 1);
919 int argv_array_size = intSize * (
argv.size() + 1);
921 int argc_size = intSize;
932 int partial_size = frame_size + aux_data_size;
933 int aligned_partial_size =
roundUp(partial_size, align);
934 int aux_padding = aligned_partial_size - partial_size;
944 Addr stack_min = stack_base - space_needed;
947 unsigned stack_size = stack_base - stack_min;
948 stack_size =
roundUp(stack_size, pageSize);
952 Addr stack_end =
roundDown(stack_base - stack_size, pageSize);
954 DPRINTF(Stack,
"Mapping the stack: 0x%x %dB\n", stack_end, stack_size);
958 IntType sentry_base = stack_base - sentry_size;
959 IntType file_name_base = sentry_base - file_name_size;
960 IntType env_data_base = file_name_base - env_data_size;
961 IntType arg_data_base = env_data_base - arg_data_size;
962 IntType aux_data_base = arg_data_base - info_block_padding - aux_data_size;
963 IntType auxv_array_base = aux_data_base - aux_array_size - aux_padding;
964 IntType envp_array_base = auxv_array_base - envp_array_size;
965 IntType argv_array_base = envp_array_base - argv_array_size;
966 IntType argc_base = argv_array_base - argc_size;
968 DPRINTF(Stack,
"The addresses of items on the initial stack:\n");
969 DPRINTF(Stack,
"0x%x - file name\n", file_name_base);
970 DPRINTF(Stack,
"0x%x - env data\n", env_data_base);
971 DPRINTF(Stack,
"0x%x - arg data\n", arg_data_base);
972 DPRINTF(Stack,
"0x%x - aux data\n", aux_data_base);
973 DPRINTF(Stack,
"0x%x - auxv array\n", auxv_array_base);
974 DPRINTF(Stack,
"0x%x - envp array\n", envp_array_base);
975 DPRINTF(Stack,
"0x%x - argv array\n", argv_array_base);
976 DPRINTF(Stack,
"0x%x - argc \n", argc_base);
977 DPRINTF(Stack,
"0x%x - stack min\n", stack_min);
982 IntType argc =
argv.size();
986 IntType sentry_NULL = 0;
994 auxv[auxv.size() - 3].a_val = aux_data_base;
996 auxv[auxv.size() - 2].a_val = argv_array_base;
998 auxv[auxv.size() - 1].a_val = aux_data_base + numRandomBytes;
1002 for (
int x = 0;
x < auxv.size();
x++) {
1004 (uint8_t*)&(auxv[
x].a_type), intSize);
1006 (uint8_t*)&(auxv[
x].a_val), intSize);
1009 const uint64_t zero = 0;
1011 (uint8_t*)&zero, intSize);
1013 (uint8_t*)&zero, intSize);
1040 X86Process::argsInit<uint64_t>(pageSize, extraAuxvs);
1052 X86Process::argsInit<uint32_t>(pageSize, extraAuxvs);
1086 assert(i < NumArgumentRegs32);
1093 assert(width == 32 || width == 64);
VSyscallPage vsyscallPage
void installSegDesc(ThreadContext *tc, SegmentRegIndex seg, SegDescriptor desc, bool longmode)
Addr programHeaderTable()
const uint64_t PFHandlerPhysAddr
void setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val)
void argsInit(int pageSize)
const uint64_t syscallCodeVirtAddr
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, TheISA::IntReg flags)
void syscall(int64_t callnum, ThreadContext *tc, Fault *fault) override
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, TheISA::IntReg flags)
void write(Addr address, T data) const
Write object T to address.
std::vector< ContextID > contextIds
void allocateMem(Addr vaddr, int64_t size, bool clobber=false)
SETranslatingPortProxy initVirtMem
void argsInit(int pageSize, std::vector< AuxVector< IntType > > extraAuxvs)
const uint64_t MMIORegionPhysAddr
virtual void setMiscReg(int misc_reg, const MiscReg &val)=0
void setSyscallArg(ThreadContext *tc, int i, X86ISA::IntReg val)
virtual void setIntReg(int reg_idx, uint64_t val)=0
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
virtual TheISA::PCState pcState()=0
Declaration of a multi-level page table.
T roundUp(const T &val, const U &align)
X86_64Process(ProcessParams *params, ObjectFile *objFile, SyscallDesc *_syscallDescs, int _numSyscallDescs)
std::shared_ptr< MemState > memState
const int numSyscallDescs
const uint64_t GDTPhysAddr
ThreadContext is the external interface to all thread state for anything outside of the CPU...
const int StackPointerReg
const uint64_t ISTVirtAddr
const uint64_t pageTablePhysAddr
const uint64_t TSSVirtAddr
void argsInit(int pageSize)
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i)
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
virtual uint64_t readIntReg(int reg_idx)=0
void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
static MiscRegIndex MISCREG_SEG_ATTR(int index)
static MiscRegIndex MISCREG_SEG_LIMIT(int index)
const uint64_t GDTVirtAddr
void setSyscallReturn(ThreadContext *tc, SyscallReturn return_value)
const uint64_t MMIORegionVirtAddr
void initState()
initState() is called on each SimObject when not restoring from a checkpoint.
const uint64_t syscallCodePhysAddr
static const int ArgumentReg32[]
static const int ArgumentReg[]
T roundDown(const T &val, const U &align)
const int NumArgumentRegs
std::vector< std::string > envp
ThreadContext * getThreadContext(ContextID tid)
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *process, TheISA::IntReg flags)
static MiscRegIndex MISCREG_SEG_SEL(int index)
const uint64_t PFHandlerVirtAddr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
#define ULL(N)
uint64_t constant
virtual bool loadSections(PortProxy &mem_proxy, Addr mask=maxAddr, Addr offset=0)
const uint64_t ISTPhysAddr
virtual void syscall(int64_t callnum, ThreadContext *tc, Fault *fault)
const uint64_t IDTVirtAddr
X86ISA::IntReg getSyscallArg(ThreadContext *tc, int &i)
VSyscallPage vsyscallPage
uint16_t programHeaderSize()
void copyStringArray(std::vector< std::string > &strings, AddrType array_ptr, AddrType data_ptr, SETranslatingPortProxy &memProxy)
This class provides the wrapper interface for the system call implementations which are defined in th...
void writeString(Addr addr, const char *str) const
static const int NumArgumentRegs M5_VAR_USED
void map(Addr vaddr, Addr paddr, int64_t size, uint64_t flags=0) override
Maps a virtual memory region to a physical memory region.
This object is a proxy for a structural port, to be used for debug accesses.
Declarations of a non-full system Page Table.
static MiscRegIndex MISCREG_SEG_BASE(int index)
This class implements an in-memory multi-level page table that can be configured to follow ISA specif...
uint16_t programHeaderCount()
const uint64_t IDTPhysAddr
GenericISA::SimplePCState< MachInst > PCState
SyscallDesc * syscallDescs
int64_t encodedValue() const
The encoded value (as described above)
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.
static MiscRegIndex MISCREG_SEG_EFF_BASE(int index)
SyscallDesc * getDesc(int callnum)
const uint64_t TSSPhysAddr
std::vector< std::string > argv
I386Process(ProcessParams *params, ObjectFile *objFile, SyscallDesc *_syscallDescs, int _numSyscallDescs)
This class represents the return value from an emulated system call, including any errno setting...
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
void clone(ThreadContext *old_tc, ThreadContext *new_tc, Process *new_p, TheISA::IntReg flags)
virtual void setMiscRegNoEffect(int misc_reg, const MiscReg &val)=0
std::shared_ptr< FaultBase > Fault
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.