GetGS = 0x1004
};
- //First argument is the code, second is the address
+ // First argument is the code, second is the address
int index = 0;
int code = process->getSyscallArg(tc, index);
uint64_t addr = process->getSyscallArg(tc, index);
SETranslatingPortProxy &p = tc->getMemProxy();
switch(code)
{
- //Each of these valid options should actually check addr.
+ // Each of these valid options should actually check addr.
case SetFS:
tc->setMiscRegNoEffect(MISCREG_FS_BASE, addr);
tc->setMiscRegNoEffect(MISCREG_FS_EFF_BASE, addr);
INTREG_RDI,
INTREG_RSI,
INTREG_RDX,
- //This argument register is r10 for syscalls and rcx for C.
+ // This argument register is r10 for syscalls and rcx for C.
INTREG_R10W,
- //INTREG_RCX,
+ // INTREG_RCX,
INTREG_R8W,
INTREG_R9W
};
argsInit(PageBytes);
- // Set up the vsyscall page for this process.
+ // Set up the vsyscall page for this process.
allocateMem(vsyscallPage.base, vsyscallPage.size);
uint8_t vtimeBlob[] = {
0x48,0xc7,0xc0,0xc9,0x00,0x00,0x00, // mov $0xc9,%rax
dataAttr.expandDown = 0;
dataAttr.system = 1;
- //Initialize the segment registers.
+ // Initialize the segment registers.
for (int seg = 0; seg < NUM_SEGMENTREGS; seg++) {
tc->setMiscRegNoEffect(MISCREG_SEG_BASE(seg), 0);
tc->setMiscRegNoEffect(MISCREG_SEG_EFF_BASE(seg), 0);
efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
tc->setMiscReg(MISCREG_EFER, efer);
- //Set up the registers that describe the operating mode.
+ // Set up the registers that describe the operating mode.
CR0 cr0 = 0;
cr0.pg = 1; // Turn on paging.
cr0.cd = 0; // Don't disable caching.
dataAttr.expandDown = 0;
dataAttr.system = 1;
- //Initialize the segment registers.
+ // Initialize the segment registers.
for (int seg = 0; seg < NUM_SEGMENTREGS; seg++) {
tc->setMiscRegNoEffect(MISCREG_SEG_BASE(seg), 0);
tc->setMiscRegNoEffect(MISCREG_SEG_EFF_BASE(seg), 0);
efer.ffxsr = 1; // Turn on fast fxsave and fxrstor.
tc->setMiscReg(MISCREG_EFER, efer);
- //Set up the registers that describe the operating mode.
+ // Set up the registers that describe the operating mode.
CR0 cr0 = 0;
cr0.pg = 1; // Turn on paging.
cr0.cd = 0; // Don't disable caching.
else
filename = argv[0];
- //We want 16 byte alignment
+ // We want 16 byte alignment
uint64_t align = 16;
// Patch the ld_bias for dynamic executables.
// X86_IA64Processor |
0;
- //Bits which describe the system hardware capabilities
- //XXX Figure out what these should be
+ // Bits which describe the system hardware capabilities
+ // XXX Figure out what these should be
auxv.push_back(auxv_t(M5_AT_HWCAP, features));
- //The system page size
+ // The system page size
auxv.push_back(auxv_t(M5_AT_PAGESZ, X86ISA::PageBytes));
- //Frequency at which times() increments
- //Defined to be 100 in the kernel source.
+ // Frequency at which times() increments
+ // Defined to be 100 in the kernel source.
auxv.push_back(auxv_t(M5_AT_CLKTCK, 100));
// This is the virtual address of the program header tables if they
// appear in the executable image.
// zero for static executables or contain the base address for
// dynamic executables.
auxv.push_back(auxv_t(M5_AT_BASE, getBias()));
- //XXX Figure out what this should be.
+ // XXX Figure out what this should be.
auxv.push_back(auxv_t(M5_AT_FLAGS, 0));
- //The entry point to the program
+ // The entry point to the program
auxv.push_back(auxv_t(M5_AT_ENTRY, objFile->entryPoint()));
- //Different user and group IDs
+ // Different user and group IDs
auxv.push_back(auxv_t(M5_AT_UID, uid()));
auxv.push_back(auxv_t(M5_AT_EUID, euid()));
auxv.push_back(auxv_t(M5_AT_GID, gid()));
auxv.push_back(auxv_t(M5_AT_EGID, egid()));
- //Whether to enable "secure mode" in the executable
+ // Whether to enable "secure mode" in the executable
auxv.push_back(auxv_t(M5_AT_SECURE, 0));
- //The address of 16 "random" bytes.
+ // The address of 16 "random" bytes.
auxv.push_back(auxv_t(M5_AT_RANDOM, 0));
- //The name of the program
+ // The name of the program
auxv.push_back(auxv_t(M5_AT_EXECFN, 0));
- //The platform string
+ // The platform string
auxv.push_back(auxv_t(M5_AT_PLATFORM, 0));
}
- //Figure out how big the initial stack needs to be
+ // Figure out how big the initial stack needs to be
// A sentry NULL void pointer at the top of the stack.
int sentry_size = intSize;
- //This is the name of the file which is present on the initial stack
- //It's purpose is to let the user space linker examine the original file.
+ // This is the name of the file which is present on the initial stack
+ // It's purpose is to let the user space linker examine the original file.
int file_name_size = filename.size() + 1;
const int numRandomBytes = 16;
for (int i = 0; i < argv.size(); ++i)
arg_data_size += argv[i].size() + 1;
- //The info_block needs to be padded so it's size is a multiple of the
- //alignment mask. Also, it appears that there needs to be at least some
- //padding, so if the size is already a multiple, we need to increase it
- //anyway.
+ // The info_block needs to be padded so its size is a multiple of the
+ // alignment mask. Also, it appears that there needs to be at least some
+ // padding, so if the size is already a multiple, we need to increase it
+ // anyway.
int base_info_block_size =
sentry_size + file_name_size + env_data_size + arg_data_size;
int info_block_padding = info_block_size - base_info_block_size;
- //Each auxilliary vector is two 8 byte words
+ // Each auxiliary vector is two 8 byte words
int aux_array_size = intSize * 2 * (auxv.size() + 1);
int envp_array_size = intSize * (envp.size() + 1);
int argc_size = intSize;
- //Figure out the size of the contents of the actual initial frame
+ // Figure out the size of the contents of the actual initial frame
int frame_size =
aux_array_size +
envp_array_size +
argv_array_size +
argc_size;
- //There needs to be padding after the auxiliary vector data so that the
- //very bottom of the stack is aligned properly.
+ // There needs to be padding after the auxiliary vector data so that the
+ // very bottom of the stack is aligned properly.
int partial_size = frame_size + aux_data_size;
int aligned_partial_size = roundUp(partial_size, align);
int aux_padding = aligned_partial_size - partial_size;
IntType argc = argv.size();
IntType guestArgc = X86ISA::htog(argc);
- //Write out the sentry void *
+ // Write out the sentry void *
IntType sentry_NULL = 0;
- initVirtMem.writeBlob(sentry_base,
- (uint8_t*)&sentry_NULL, sentry_size);
+ initVirtMem.writeBlob(sentry_base, (uint8_t*)&sentry_NULL, sentry_size);
- //Write the file name
+ // Write the file name
initVirtMem.writeString(file_name_base, filename.c_str());
- //Fix up the aux vectors which point to data
+ // Fix up the aux vectors which point to data
assert(auxv[auxv.size() - 3].a_type == M5_AT_RANDOM);
auxv[auxv.size() - 3].a_val = aux_data_base;
assert(auxv[auxv.size() - 2].a_type == M5_AT_EXECFN);
assert(auxv[auxv.size() - 1].a_type == M5_AT_PLATFORM);
auxv[auxv.size() - 1].a_val = aux_data_base + numRandomBytes;
- //Copy the aux stuff
+
+ // Copy the aux stuff
for (int x = 0; x < auxv.size(); x++) {
initVirtMem.writeBlob(auxv_array_base + x * 2 * intSize,
(uint8_t*)&(auxv[x].a_type), intSize);
initVirtMem.writeBlob(auxv_array_base + (x * 2 + 1) * intSize,
(uint8_t*)&(auxv[x].a_val), intSize);
}
- //Write out the terminating zeroed auxilliary vector
+ // Write out the terminating zeroed auxiliary vector
const uint64_t zero = 0;
initVirtMem.writeBlob(auxv_array_base + auxv.size() * 2 * intSize,
(uint8_t*)&zero, intSize);
initVirtMem.writeBlob(argc_base, (uint8_t*)&guestArgc, intSize);
ThreadContext *tc = system->getThreadContext(contextIds[0]);
- //Set the stack pointer register
+ // Set the stack pointer register
tc->setIntReg(StackPointerReg, stack_min);
// There doesn't need to be any segment base added in since we're dealing
// with the flat segmentation model.
tc->pcState(getStartPC());
- //Align the "stack_min" to a page boundary.
+ // Align the "stack_min" to a page boundary.
memState->setStackMin(roundDown(stack_min, pageSize));
}
class ElfObject : public ObjectFile
{
protected:
-
- //The global definition of a "Section" is closest to elf's segments.
+ // The global definition of a gem5 "Section" is closest to ELF's segments.
typedef ObjectFile::Section Segment;
- //These values are provided to a linux process by the kernel, so we
- //need to keep them around.
+ // These values are provided to a linux process by the kernel, so we
+ // need to keep them around.
Addr _programHeaderTable;
uint16_t _programHeaderSize;
uint16_t _programHeaderCount;
uint8_t *fileData;
size_t len;
- Arch arch;
+ Arch arch;
OpSys opSys;
ObjectFile(const std::string &_filename, size_t _len, uint8_t *_data,
protected:
struct Section {
- Addr baseAddr;
+ Addr baseAddr;
uint8_t *fileImage;
- size_t size;
+ size_t size;
};
Addr entry;
fatal("Maximum stack size exceeded\n");
allocateMem(stack_min, TheISA::PageBytes);
inform("Increasing stack size by one page.");
- };
+ }
memState->setStackMin(stack_min);
return true;
}
tp.memsetBlob(gen.addr(), zero, size_needed);
if (gen.addr() + PageBytes > next_page &&
next_page < new_brk &&
- p->pTable->translate(next_page))
- {
+ p->pTable->translate(next_page)) {
size_needed = PageBytes - size_needed;
tp.memsetBlob(next_page, zero, size_needed);
}
{
int index = 0;
int tgt_fd = p->getSyscallArg(tc, index);
- Addr bufPtr = p->getSyscallArg(tc, index);
+ Addr buf_ptr = p->getSyscallArg(tc, index);
int nbytes = p->getSyscallArg(tc, index);
auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
return -EBADF;
int sim_fd = hbfdp->getSimFD();
- BufferArg bufArg(bufPtr, nbytes);
+ BufferArg bufArg(buf_ptr, nbytes);
int bytes_read = read(sim_fd, bufArg.bufferPtr(), nbytes);
if (bytes_read > 0)
{
int index = 0;
int tgt_fd = p->getSyscallArg(tc, index);
- Addr bufPtr = p->getSyscallArg(tc, index);
+ Addr buf_ptr = p->getSyscallArg(tc, index);
int nbytes = p->getSyscallArg(tc, index);
auto hbfdp = std::dynamic_pointer_cast<HBFDEntry>((*p->fds)[tgt_fd]);
return -EBADF;
int sim_fd = hbfdp->getSimFD();
- BufferArg bufArg(bufPtr, nbytes);
+ BufferArg bufArg(buf_ptr, nbytes);
bufArg.copyIn(tc->getMemProxy());
int bytes_written = write(sim_fd, bufArg.bufferPtr(), nbytes);
gethostnameFunc(SyscallDesc *desc, int num, Process *p, ThreadContext *tc)
{
int index = 0;
- Addr bufPtr = p->getSyscallArg(tc, index);
+ Addr buf_ptr = p->getSyscallArg(tc, index);
int name_len = p->getSyscallArg(tc, index);
- BufferArg name(bufPtr, name_len);
+ BufferArg name(buf_ptr, name_len);
strncpy((char *)name.bufferPtr(), hostname, name_len);
{
int result = 0;
int index = 0;
- Addr bufPtr = p->getSyscallArg(tc, index);
+ Addr buf_ptr = p->getSyscallArg(tc, index);
unsigned long size = p->getSyscallArg(tc, index);
- BufferArg buf(bufPtr, size);
+ BufferArg buf(buf_ptr, size);
// Is current working directory defined?
string cwd = p->getcwd();
// Adjust path for current working directory
path = p->fullPath(path);
- Addr bufPtr = p->getSyscallArg(tc, index);
+ Addr buf_ptr = p->getSyscallArg(tc, index);
size_t bufsiz = p->getSyscallArg(tc, index);
- BufferArg buf(bufPtr, bufsiz);
+ BufferArg buf(buf_ptr, bufsiz);
int result = -1;
if (path != "/proc/self/exe") {
string path;
if (!tc->getMemProxy().tryReadString(path, process->getSyscallArg(tc, index)))
- return -EFAULT;
+ return -EFAULT;
int64_t length = process->getSyscallArg(tc, index, 64);
// to the underlying OS
warn("fcntl64(%d, %d) passed through to host\n", tgt_fd, cmd);
return fcntl(sim_fd, cmd);
- // return 0;
}
}
// simulation to be deterministic.
// EUID goes in r20.
- tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID
- return process->uid(); // UID
+ tc->setIntReg(SyscallPseudoReturnReg, process->euid()); // EUID
+ return process->uid(); // UID
}
ThreadContext *tc)
{
// Get current group ID. EGID goes in r20.
- tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID
+ tc->setIntReg(SyscallPseudoReturnReg, process->egid()); // EGID
return process->gid();
}
int index);
/// Futex system call
-/// Implemented by Daniel Sanchez
-/// Used by printf's in multi-threaded apps
+/// Implemented by Daniel Sanchez
+/// Used by printf's in multi-threaded apps
template <class OS>
SyscallReturn
futexFunc(SyscallDesc *desc, int callnum, Process *process,
tgt->st_mtimeX = TheISA::htog(tgt->st_mtimeX);
tgt->st_ctimeX = host->st_ctime;
tgt->st_ctimeX = TheISA::htog(tgt->st_ctimeX);
- // Force the block size to be 8k. This helps to ensure buffered io works
+ // Force the block size to be 8KB. This helps to ensure buffered io works
// consistently across different hosts.
tgt->st_blksize = 0x2000;
tgt->st_blksize = TheISA::htog(tgt->st_blksize);
#endif
}
-//Here are a couple convenience functions
+// Here are a couple of convenience functions
template<class OS>
static void
copyOutStatBuf(SETranslatingPortProxy &mem, Addr addr,
- hst_stat *host, bool fakeTTY = false)
+ hst_stat *host, bool fakeTTY = false)
{
typedef TypedBufferArg<typename OS::tgt_stat> tgt_stat_buf;
tgt_stat_buf tgt(addr);
template<class OS>
static void
copyOutStat64Buf(SETranslatingPortProxy &mem, Addr addr,
- hst_stat64 *host, bool fakeTTY = false)
+ hst_stat64 *host, bool fakeTTY = false)
{
typedef TypedBufferArg<typename OS::tgt_stat64> tgt_stat_buf;
tgt_stat_buf tgt(addr);
TypedBufferArg<typename OS::rlimit> rlp(process->getSyscallArg(tc, index));
switch (resource) {
- case OS::TGT_RLIMIT_STACK:
- // max stack size in bytes: make up a number (8MB for now)
- rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
- rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
- rlp->rlim_max = TheISA::htog(rlp->rlim_max);
- break;
-
- case OS::TGT_RLIMIT_DATA:
- // max data segment size in bytes: make up a number
- rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
- rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
- rlp->rlim_max = TheISA::htog(rlp->rlim_max);
- break;
-
- default:
- warn("getrlimit: unimplemented resource %d", resource);
- return -EINVAL;
- break;
+ case OS::TGT_RLIMIT_STACK:
+ // max stack size in bytes: make up a number (8MB for now)
+ rlp->rlim_cur = rlp->rlim_max = 8 * 1024 * 1024;
+ rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
+ rlp->rlim_max = TheISA::htog(rlp->rlim_max);
+ break;
+
+ case OS::TGT_RLIMIT_DATA:
+ // max data segment size in bytes: make up a number
+ rlp->rlim_cur = rlp->rlim_max = 256 * 1024 * 1024;
+ rlp->rlim_cur = TheISA::htog(rlp->rlim_cur);
+ rlp->rlim_max = TheISA::htog(rlp->rlim_max);
+ break;
+
+ default:
+ warn("getrlimit: unimplemented resource %d", resource);
+ return -EINVAL;
+ break;
}
rlp.copyOut(tc->getMemProxy());
tp.copyIn(tc->getMemProxy());
struct timeval hostTimeval[2];
- for (int i = 0; i < 2; ++i)
- {
+ for (int i = 0; i < 2; ++i) {
hostTimeval[i].tv_sec = TheISA::gtoh((*tp)[i].tv_sec);
hostTimeval[i].tv_usec = TheISA::gtoh((*tp)[i].tv_usec);
}