summaryrefslogtreecommitdiff
path: root/sim
diff options
context:
space:
mode:
Diffstat (limited to 'sim')
-rw-r--r--sim/faults.hh19
-rw-r--r--sim/host.hh8
-rw-r--r--sim/process.cc16
-rw-r--r--sim/process.hh9
-rw-r--r--sim/pseudo_inst.cc1
-rw-r--r--sim/syscall_emul.cc49
-rw-r--r--sim/syscall_emul.hh6
-rw-r--r--sim/system.cc9
8 files changed, 102 insertions, 15 deletions
diff --git a/sim/faults.hh b/sim/faults.hh
index d9c742b90..dbec399af 100644
--- a/sim/faults.hh
+++ b/sim/faults.hh
@@ -29,30 +29,33 @@
#ifndef __FAULTS_HH__
#define __FAULTS_HH__
-class Fault
+class FaultBase;
+typedef FaultBase * Fault;
+
+class FaultBase
{
public:
- Fault(char * newName, int newId = 0) : name(newName), id(newId) {;}
+ FaultBase(char * newName, int newId = 0) : name(newName), id(newId) {;}
const char * name;
int id;
};
-extern class NoFaultType : public Fault
+extern class NoFaultType : public FaultBase
{
public:
- NoFaultType(char * newName) : Fault(newName) {;}
+ NoFaultType(char * newName) : FaultBase(newName) {;}
} * const NoFault;
-extern class MachineCheckFaultType : public Fault
+extern class MachineCheckFaultType : public FaultBase
{
public:
- MachineCheckFaultType(char * newName) : Fault(newName) {;}
+ MachineCheckFaultType(char * newName) : FaultBase(newName) {;}
} * const MachineCheckFault;
-extern class AlignmentFaultType : public Fault
+extern class AlignmentFaultType : public FaultBase
{
public:
- AlignmentFaultType(char * newName) : Fault(newName) {;}
+ AlignmentFaultType(char * newName) : FaultBase(newName) {;}
} * const AlignmentFault;
diff --git a/sim/host.hh b/sim/host.hh
index ef7008042..f7e64f23c 100644
--- a/sim/host.hh
+++ b/sim/host.hh
@@ -54,4 +54,12 @@ typedef int64_t Counter;
*/
typedef int64_t Tick;
+/**
+ * Address type
+ * This will probably be moved somewhere else in the near future.
+ * This should be at least as big as the biggest address width in use
+ * in the system, which will probably be 64 bits.
+ */
+typedef uint64_t Addr;
+
#endif // __HOST_H__
diff --git a/sim/process.cc b/sim/process.cc
index 59d122b48..0a7e46082 100644
--- a/sim/process.cc
+++ b/sim/process.cc
@@ -46,6 +46,7 @@
#include "sim/fake_syscall.hh"
#include "sim/process.hh"
#include "sim/stats.hh"
+#include "sim/syscall_emul.hh"
#ifdef TARGET_ALPHA
#include "arch/alpha/alpha_tru64_process.hh"
@@ -53,6 +54,7 @@
#endif
using namespace std;
+using namespace TheISA;
//
// The purpose of this code is to fake the loader & syscall mechanism
@@ -350,6 +352,19 @@ LiveProcess::LiveProcess(const string &nm, ObjectFile *objFile,
init_regs->npc = prog_entry + sizeof(MachInst);
}
+void
+LiveProcess::syscall(ExecContext *xc)
+{
+ num_syscalls++;
+
+ int64_t callnum = xc->regs.intRegFile[ReturnValueReg];
+
+ SyscallDesc *desc = getDesc(callnum);
+ if (desc == NULL)
+ fatal("Syscall %d out of range", callnum);
+
+ desc->doSyscall(callnum, this, xc);
+}
LiveProcess *
LiveProcess::create(const string &nm,
@@ -394,6 +409,7 @@ LiveProcess::create(const string &nm,
}
+
BEGIN_DECLARE_SIM_OBJECT_PARAMS(LiveProcess)
VectorParam<string> cmd;
diff --git a/sim/process.hh b/sim/process.hh
index 43fafd9d7..71b7d02b3 100644
--- a/sim/process.hh
+++ b/sim/process.hh
@@ -48,8 +48,12 @@
class ExecContext;
class FunctionalMemory;
+class SyscallDesc;
class Process : public SimObject
{
+ protected:
+ typedef TheISA::RegFile RegFile;
+ typedef TheISA::MachInst MachInst;
public:
// have we initialized an execution context from this process? If
@@ -200,6 +204,11 @@ class LiveProcess : public Process
std::string executable,
std::vector<std::string> &argv,
std::vector<std::string> &envp);
+
+ virtual void syscall(ExecContext *xc);
+
+ virtual SyscallDesc* getDesc(int callnum) { panic("Must be implemented."); }
+
};
diff --git a/sim/pseudo_inst.cc b/sim/pseudo_inst.cc
index 11ab55f53..58ea8266f 100644
--- a/sim/pseudo_inst.cc
+++ b/sim/pseudo_inst.cc
@@ -53,6 +53,7 @@ using namespace std;
extern Sampler *SampCPU;
using namespace Stats;
+using namespace TheISA;
namespace AlphaPseudo
{
diff --git a/sim/syscall_emul.cc b/sim/syscall_emul.cc
index 0fac43fc5..d22dde3b8 100644
--- a/sim/syscall_emul.cc
+++ b/sim/syscall_emul.cc
@@ -26,6 +26,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <fcntl.h>
#include <unistd.h>
#include <string>
@@ -40,6 +41,7 @@
#include "sim/sim_events.hh"
using namespace std;
+using namespace TheISA;
void
SyscallDesc::doSyscall(int callnum, Process *process, ExecContext *xc)
@@ -89,7 +91,7 @@ exitFunc(SyscallDesc *desc, int callnum, Process *process,
SyscallReturn
getpagesizeFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
{
- return VMPageSize;
+ return (int)VMPageSize;
}
@@ -278,3 +280,48 @@ fchownFunc(SyscallDesc *desc, int num, Process *process, ExecContext *xc)
int result = fchown(fd, hostOwner, hostGroup);
return (result == -1) ? -errno : result;
}
+
+
+SyscallReturn
+fcntlFunc(SyscallDesc *desc, int num, Process *process,
+ ExecContext *xc)
+{
+ int fd = xc->getSyscallArg(0);
+
+ if (fd < 0 || process->sim_fd(fd) < 0)
+ return -EBADF;
+
+ int cmd = xc->getSyscallArg(1);
+ switch (cmd) {
+ case 0: // F_DUPFD
+ // if we really wanted to support this, we'd need to do it
+ // in the target fd space.
+ warn("fcntl(%d, F_DUPFD) not supported, error returned\n", fd);
+ return -EMFILE;
+
+ case 1: // F_GETFD (get close-on-exec flag)
+ case 2: // F_SETFD (set close-on-exec flag)
+ return 0;
+
+ case 3: // F_GETFL (get file flags)
+ case 4: // F_SETFL (set file flags)
+ // not sure if this is totally valid, but we'll pass it through
+ // to the underlying OS
+ warn("fcntl(%d, %d) passed through to host\n", fd, cmd);
+ return fcntl(process->sim_fd(fd), cmd);
+ // return 0;
+
+ case 7: // F_GETLK (get lock)
+ case 8: // F_SETLK (set lock)
+ case 9: // F_SETLKW (set lock and wait)
+ // don't mess with file locking... just act like it's OK
+ warn("File lock call (fcntl(%d, %d)) ignored.\n", fd, cmd);
+ return 0;
+
+ default:
+ warn("Unknown fcntl command %d\n", cmd);
+ return 0;
+ }
+}
+
+
diff --git a/sim/syscall_emul.hh b/sim/syscall_emul.hh
index 739cd20e5..f49248dea 100644
--- a/sim/syscall_emul.hh
+++ b/sim/syscall_emul.hh
@@ -239,6 +239,10 @@ SyscallReturn chownFunc(SyscallDesc *desc, int num,
SyscallReturn fchownFunc(SyscallDesc *desc, int num,
Process *p, ExecContext *xc);
+/// Target fnctl() handler.
+SyscallReturn fcntlFunc(SyscallDesc *desc, int num,
+ Process *process, ExecContext *xc);
+
/// This struct is used to build an target-OS-dependent table that
/// maps the target's open() flags to the host open() flags.
struct OpenFlagTransTable {
@@ -646,7 +650,7 @@ mmapFunc(SyscallDesc *desc, int num, Process *p, ExecContext *xc)
if (start == 0) {
// user didn't give an address... pick one from our "mmap region"
start = p->mmap_end;
- p->mmap_end += roundUp(length, VMPageSize);
+ p->mmap_end += roundUp(length, TheISA::VMPageSize);
if (p->nxm_start != 0) {
//If we have an nxm space, make sure we haven't colided
assert(p->mmap_end < p->nxm_start);
diff --git a/sim/system.cc b/sim/system.cc
index 990145826..41de8cee4 100644
--- a/sim/system.cc
+++ b/sim/system.cc
@@ -41,6 +41,7 @@
#include "base/trace.hh"
using namespace std;
+using namespace TheISA;
vector<System *> System::systemList;
@@ -306,11 +307,9 @@ System::registerExecContext(ExecContext *xc, int id)
void
System::startup()
{
- if (!execContexts.empty()) {
- // activate with zero delay so that we start ticking right
- // away on cycle 0
- execContexts[0]->activate(0);
- }
+ int i;
+ for (i = 0; i < execContexts.size(); i++)
+ execContexts[i]->activate(0);
}
void