2003-12-02 04:34:38 +01:00
|
|
|
/*
|
2005-03-10 20:20:12 +01:00
|
|
|
* Copyright (c) 2003-2005 The Regents of The University of Michigan
|
2003-12-02 04:34:38 +01:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Steve Reinhardt
|
|
|
|
* Ali Saidi
|
2003-12-02 04:34:38 +01:00
|
|
|
*/
|
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
#include <fcntl.h>
|
2003-12-02 04:34:38 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-11-05 01:57:01 +01:00
|
|
|
#include <cstdio>
|
2003-12-02 04:34:38 +01:00
|
|
|
#include <iostream>
|
2009-11-05 01:57:01 +01:00
|
|
|
#include <string>
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2010-09-14 09:29:38 +02:00
|
|
|
#include "arch/utility.hh"
|
2006-03-15 23:04:50 +01:00
|
|
|
#include "base/chunk_generator.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
#include "base/trace.hh"
|
2009-09-23 17:34:21 +02:00
|
|
|
#include "config/the_isa.hh"
|
2005-06-05 02:50:10 +02:00
|
|
|
#include "cpu/base.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "cpu/thread_context.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/SyscallVerbose.hh"
|
2006-03-15 23:04:50 +01:00
|
|
|
#include "mem/page_table.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
#include "sim/process.hh"
|
2006-06-10 05:01:31 +02:00
|
|
|
#include "sim/sim_exit.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "sim/syscall_emul.hh"
|
|
|
|
#include "sim/system.hh"
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
using namespace std;
|
Changes to untemplate StaticInst and StaticInstPtr, change the isa to a namespace instead of a class, an improvement to the architecture specific header file selection system, and fixed up a few include paths.
arch/alpha/alpha_linux_process.cc:
Added using directive for AlphaISA namespace
arch/alpha/alpha_memory.hh:
arch/alpha/isa/branch.isa:
cpu/pc_event.hh:
Added typedefs for Addr
arch/alpha/alpha_tru64_process.cc:
arch/alpha/arguments.cc:
Added using directive for AlphaISA
arch/alpha/ev5.hh:
Added an include of arch/alpha/isa_traits.hh, and a using directive for the AlphaISA namespace.
arch/alpha/faults.hh:
Added a typedef for the Addr type, and changed the formatting of the faults slightly.
arch/alpha/isa/main.isa:
Untemplatized StaticInst, added a using for namespace AlphaISA to show up in decoder.cc and the exec.ccs, relocated makeNop to decoder.hh
arch/alpha/isa/mem.isa:
Untemplatized StaticInst and StaticInstPtr
arch/alpha/isa/pal.isa:
cpu/base_dyn_inst.cc:
Untemplatized StaticInstPtr
arch/alpha/isa_traits.hh:
Changed variables to be externs instead of static since they are part of a namespace and not a class.
arch/alpha/stacktrace.cc:
Untemplatized StaticInstPtr, and added a using directive for AlphaISA.
arch/alpha/stacktrace.hh:
Added some typedefs for Addr and MachInst, and untemplatized StaticInstPtr
arch/alpha/vtophys.cc:
Added a using directive for AlphaISA
arch/alpha/vtophys.hh:
Added the AlphaISA namespace specifier where needed
arch/isa_parser.py:
Changed the placement of the definition of the decodeInst function to be outside the namespaceInst namespace.
base/loader/object_file.hh:
cpu/o3/bpred_unit.hh:
Added a typedef for Addr
base/loader/symtab.hh:
Added a typedef for Addr, and added a TheISA to Addr in another typedef
base/remote_gdb.cc:
Added a using namespace TheISA, and untemplatized StaticInstPtr
base/remote_gdb.hh:
Added typedefs for Addr and MachInst
cpu/base.cc:
Added TheISA specifier to some variables exported from the isa.
cpu/base.hh:
Added a typedef for Addr, and TheISA to some variables from the ISA
cpu/base_dyn_inst.hh:
Untemplatized StaticInstPtr, and added TheISA specifier to some variables from the ISA.
cpu/exec_context.hh:
Added some typedefs for types from the isa, and added TheISA specifier to some variables from the isa
cpu/exetrace.hh:
Added typedefs for some types from the ISA, and untemplatized StaticInstPtr
cpu/memtest/memtest.cc:
cpu/o3/btb.cc:
dev/baddev.cc:
dev/ide_ctrl.cc:
dev/ide_disk.cc:
dev/isa_fake.cc:
dev/ns_gige.cc:
dev/pciconfigall.cc:
dev/platform.cc:
dev/sinic.cc:
dev/uart8250.cc:
kern/freebsd/freebsd_system.cc:
kern/linux/linux_system.cc:
kern/system_events.cc:
kern/tru64/dump_mbuf.cc:
kern/tru64/tru64_events.cc:
sim/process.cc:
sim/pseudo_inst.cc:
sim/system.cc:
Added using namespace TheISA
cpu/memtest/memtest.hh:
cpu/trace/opt_cpu.hh:
cpu/trace/reader/itx_reader.hh:
dev/ide_disk.hh:
dev/pcidev.hh:
dev/platform.hh:
dev/tsunami.hh:
sim/system.hh:
sim/vptr.hh:
Added typedef for Addr
cpu/o3/2bit_local_pred.hh:
Changed the include to use arch/isa_traits.hh instead of arch/alpha/isa_traits.hh. Added typedef for Addr
cpu/o3/alpha_cpu.hh:
Added typedefs for Addr and IntReg
cpu/o3/alpha_cpu_impl.hh:
Added this-> to setNextPC to fix a problem since it didn't depend on template parameters any more. Removed "typename" where it was no longer needed.
cpu/o3/alpha_dyn_inst.hh:
Cleaned up some typedefs, and untemplatized StaticInst
cpu/o3/alpha_dyn_inst_impl.hh:
untemplatized StaticInstPtr
cpu/o3/alpha_impl.hh:
Fixed up a typedef of MachInst
cpu/o3/bpred_unit_impl.hh:
Added a using TheISA::MachInst to a function
cpu/o3/btb.hh:
Changed an include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr
cpu/o3/commit.hh:
Removed a typedef of Impl::ISA as ISA, since TheISA takes care of this now.
cpu/o3/cpu.cc:
Cleaned up namespace issues
cpu/o3/cpu.hh:
Cleaned up namespace usage
cpu/o3/decode.hh:
Removed typedef of ISA, and changed it to TheISA
cpu/o3/fetch.hh:
Fized up typedefs, and changed ISA to TheISA
cpu/o3/free_list.hh:
Changed include of arch/alpha/isa_traits.hh to arch/isa_traits.hh
cpu/o3/iew.hh:
Removed typedef of ISA
cpu/o3/iew_impl.hh:
Added TheISA namespace specifier to MachInst
cpu/o3/ras.hh:
Changed include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr.
cpu/o3/regfile.hh:
Changed ISA to TheISA, and added some typedefs for Addr, IntReg, FloatReg, and MiscRegFile
cpu/o3/rename.hh:
Changed ISA to TheISA, and added a typedef for RegIndex
cpu/o3/rename_map.hh:
Added an include for arch/isa_traits.hh, and a typedef for RegIndex
cpu/o3/rob.hh:
Added a typedef for RegIndex
cpu/o3/store_set.hh:
cpu/o3/tournament_pred.hh:
Changed an include of arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef of Addr
cpu/ozone/cpu.hh:
Changed ISA into TheISA, and untemplatized StaticInst
cpu/pc_event.cc:
Added namespace specifier TheISA to Addr types
cpu/profile.hh:
kern/kernel_stats.hh:
Added typedef for Addr, and untemplatized StaticInstPtr
cpu/simple/cpu.cc:
Changed using directive from LittleEndianGuest to AlphaISA, which will contain both namespaces. Added TheISA where needed, and untemplatized StaticInst
cpu/simple/cpu.hh:
Added a typedef for MachInst, and untemplatized StaticInst
cpu/static_inst.cc:
Untemplatized StaticInst
cpu/static_inst.hh:
Untemplatized StaticInst by using the TheISA namespace
dev/alpha_console.cc:
Added using namespace AlphaISA
dev/simple_disk.hh:
Added typedef for Addr and fixed up some formatting
dev/sinicreg.hh:
Added TheISA namespace specifier where needed
dev/tsunami.cc:
dev/tsunami_io.cc:
dev/tsunami_pchip.cc:
Added using namespace TheISA. It might be better for it to be AlphaISA
dev/tsunami_cchip.cc:
Added typedef for TheISA. It might be better for it to be AlphaISA
kern/linux/aligned.hh:
sim/pseudo_inst.hh:
Added TheISA namespace specifier to Addr
kern/linux/linux_threadinfo.hh:
Added typedef for Addr, and TheISA namespace specifier to StackPointerReg
kern/tru64/mbuf.hh:
Added TheISA to Addr type in structs
sim/process.hh:
Added typedefs of Addr, RegFile, and MachInst
sim/syscall_emul.cc:
Added using namespace TheISA, and a cast of VMPageSize to the int type
sim/syscall_emul.hh:
Added typecast for Addr, and TheISA namespace specifier for where needed
--HG--
extra : convert_revision : 91d4f6ca33a73b21c1f1771d74bfdea3b80eff45
2006-02-19 08:34:37 +01:00
|
|
|
using namespace TheISA;
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
void
|
2006-09-17 09:00:55 +02:00
|
|
|
SyscallDesc::doSyscall(int callnum, LiveProcess *process, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-31 21:20:22 +01:00
|
|
|
#if TRACING_ON
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2009-10-31 21:20:22 +01:00
|
|
|
#endif
|
2009-04-21 17:17:36 +02:00
|
|
|
DPRINTFR(SyscallVerbose,
|
|
|
|
"%d: %s: syscall %s called w/arguments %d,%d,%d,%d\n",
|
2011-01-08 06:50:29 +01:00
|
|
|
curTick(), tc->getCpuPtr()->name(), name,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index),
|
|
|
|
process->getSyscallArg(tc, index),
|
|
|
|
process->getSyscallArg(tc, index),
|
|
|
|
process->getSyscallArg(tc, index));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-06-06 23:32:21 +02:00
|
|
|
SyscallReturn retval = (*funcPtr)(this, callnum, process, tc);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2006-04-10 18:23:17 +02:00
|
|
|
DPRINTFR(SyscallVerbose, "%d: %s: syscall %s returns %d\n",
|
2011-01-08 06:50:29 +01:00
|
|
|
curTick(),tc->getCpuPtr()->name(), name, retval.value());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
if (!(flags & SyscallDesc::SuppressReturnValue))
|
2009-02-27 18:22:14 +01:00
|
|
|
process->setSyscallReturn(tc, retval);
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
unimplementedFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2005-11-11 03:05:31 +01:00
|
|
|
fatal("syscall %s (#%d) unimplemented.", desc->name, callnum);
|
2006-03-18 16:51:28 +01:00
|
|
|
|
|
|
|
return 1;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
ignoreFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2005-11-11 03:05:31 +01:00
|
|
|
warn("ignoring syscall %s(%d, %d, ...)", desc->name,
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index), process->getSyscallArg(tc, index));
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-18 01:20:20 +01:00
|
|
|
SyscallReturn
|
|
|
|
ignoreWarnOnceFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
warn_once("ignoring syscall %s(%d, %d, ...)", desc->name,
|
|
|
|
process->getSyscallArg(tc, index), process->getSyscallArg(tc, index));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-04-15 22:13:47 +02:00
|
|
|
if (process->system->numRunningContexts() == 1) {
|
|
|
|
// Last running context... exit simulator
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2009-02-27 18:22:14 +01:00
|
|
|
exitSimLoop("target called exit()",
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index) & 0xff);
|
2009-04-15 22:13:47 +02:00
|
|
|
} else {
|
|
|
|
// other running threads... just halt this one
|
|
|
|
tc->halt();
|
2006-07-03 18:19:35 +02:00
|
|
|
}
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 1;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
SyscallReturn
|
|
|
|
exitGroupFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
|
|
|
// really should just halt all thread contexts belonging to this
|
|
|
|
// process in case there's another process running...
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2009-04-21 17:17:36 +02:00
|
|
|
exitSimLoop("target called exit()",
|
2009-10-30 08:44:55 +01:00
|
|
|
process->getSyscallArg(tc, index) & 0xff);
|
2009-04-21 17:17:36 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getpagesizeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
Changes to untemplate StaticInst and StaticInstPtr, change the isa to a namespace instead of a class, an improvement to the architecture specific header file selection system, and fixed up a few include paths.
arch/alpha/alpha_linux_process.cc:
Added using directive for AlphaISA namespace
arch/alpha/alpha_memory.hh:
arch/alpha/isa/branch.isa:
cpu/pc_event.hh:
Added typedefs for Addr
arch/alpha/alpha_tru64_process.cc:
arch/alpha/arguments.cc:
Added using directive for AlphaISA
arch/alpha/ev5.hh:
Added an include of arch/alpha/isa_traits.hh, and a using directive for the AlphaISA namespace.
arch/alpha/faults.hh:
Added a typedef for the Addr type, and changed the formatting of the faults slightly.
arch/alpha/isa/main.isa:
Untemplatized StaticInst, added a using for namespace AlphaISA to show up in decoder.cc and the exec.ccs, relocated makeNop to decoder.hh
arch/alpha/isa/mem.isa:
Untemplatized StaticInst and StaticInstPtr
arch/alpha/isa/pal.isa:
cpu/base_dyn_inst.cc:
Untemplatized StaticInstPtr
arch/alpha/isa_traits.hh:
Changed variables to be externs instead of static since they are part of a namespace and not a class.
arch/alpha/stacktrace.cc:
Untemplatized StaticInstPtr, and added a using directive for AlphaISA.
arch/alpha/stacktrace.hh:
Added some typedefs for Addr and MachInst, and untemplatized StaticInstPtr
arch/alpha/vtophys.cc:
Added a using directive for AlphaISA
arch/alpha/vtophys.hh:
Added the AlphaISA namespace specifier where needed
arch/isa_parser.py:
Changed the placement of the definition of the decodeInst function to be outside the namespaceInst namespace.
base/loader/object_file.hh:
cpu/o3/bpred_unit.hh:
Added a typedef for Addr
base/loader/symtab.hh:
Added a typedef for Addr, and added a TheISA to Addr in another typedef
base/remote_gdb.cc:
Added a using namespace TheISA, and untemplatized StaticInstPtr
base/remote_gdb.hh:
Added typedefs for Addr and MachInst
cpu/base.cc:
Added TheISA specifier to some variables exported from the isa.
cpu/base.hh:
Added a typedef for Addr, and TheISA to some variables from the ISA
cpu/base_dyn_inst.hh:
Untemplatized StaticInstPtr, and added TheISA specifier to some variables from the ISA.
cpu/exec_context.hh:
Added some typedefs for types from the isa, and added TheISA specifier to some variables from the isa
cpu/exetrace.hh:
Added typedefs for some types from the ISA, and untemplatized StaticInstPtr
cpu/memtest/memtest.cc:
cpu/o3/btb.cc:
dev/baddev.cc:
dev/ide_ctrl.cc:
dev/ide_disk.cc:
dev/isa_fake.cc:
dev/ns_gige.cc:
dev/pciconfigall.cc:
dev/platform.cc:
dev/sinic.cc:
dev/uart8250.cc:
kern/freebsd/freebsd_system.cc:
kern/linux/linux_system.cc:
kern/system_events.cc:
kern/tru64/dump_mbuf.cc:
kern/tru64/tru64_events.cc:
sim/process.cc:
sim/pseudo_inst.cc:
sim/system.cc:
Added using namespace TheISA
cpu/memtest/memtest.hh:
cpu/trace/opt_cpu.hh:
cpu/trace/reader/itx_reader.hh:
dev/ide_disk.hh:
dev/pcidev.hh:
dev/platform.hh:
dev/tsunami.hh:
sim/system.hh:
sim/vptr.hh:
Added typedef for Addr
cpu/o3/2bit_local_pred.hh:
Changed the include to use arch/isa_traits.hh instead of arch/alpha/isa_traits.hh. Added typedef for Addr
cpu/o3/alpha_cpu.hh:
Added typedefs for Addr and IntReg
cpu/o3/alpha_cpu_impl.hh:
Added this-> to setNextPC to fix a problem since it didn't depend on template parameters any more. Removed "typename" where it was no longer needed.
cpu/o3/alpha_dyn_inst.hh:
Cleaned up some typedefs, and untemplatized StaticInst
cpu/o3/alpha_dyn_inst_impl.hh:
untemplatized StaticInstPtr
cpu/o3/alpha_impl.hh:
Fixed up a typedef of MachInst
cpu/o3/bpred_unit_impl.hh:
Added a using TheISA::MachInst to a function
cpu/o3/btb.hh:
Changed an include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr
cpu/o3/commit.hh:
Removed a typedef of Impl::ISA as ISA, since TheISA takes care of this now.
cpu/o3/cpu.cc:
Cleaned up namespace issues
cpu/o3/cpu.hh:
Cleaned up namespace usage
cpu/o3/decode.hh:
Removed typedef of ISA, and changed it to TheISA
cpu/o3/fetch.hh:
Fized up typedefs, and changed ISA to TheISA
cpu/o3/free_list.hh:
Changed include of arch/alpha/isa_traits.hh to arch/isa_traits.hh
cpu/o3/iew.hh:
Removed typedef of ISA
cpu/o3/iew_impl.hh:
Added TheISA namespace specifier to MachInst
cpu/o3/ras.hh:
Changed include from arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef for Addr.
cpu/o3/regfile.hh:
Changed ISA to TheISA, and added some typedefs for Addr, IntReg, FloatReg, and MiscRegFile
cpu/o3/rename.hh:
Changed ISA to TheISA, and added a typedef for RegIndex
cpu/o3/rename_map.hh:
Added an include for arch/isa_traits.hh, and a typedef for RegIndex
cpu/o3/rob.hh:
Added a typedef for RegIndex
cpu/o3/store_set.hh:
cpu/o3/tournament_pred.hh:
Changed an include of arch/alpha/isa_traits.hh to arch/isa_traits.hh, and added a typedef of Addr
cpu/ozone/cpu.hh:
Changed ISA into TheISA, and untemplatized StaticInst
cpu/pc_event.cc:
Added namespace specifier TheISA to Addr types
cpu/profile.hh:
kern/kernel_stats.hh:
Added typedef for Addr, and untemplatized StaticInstPtr
cpu/simple/cpu.cc:
Changed using directive from LittleEndianGuest to AlphaISA, which will contain both namespaces. Added TheISA where needed, and untemplatized StaticInst
cpu/simple/cpu.hh:
Added a typedef for MachInst, and untemplatized StaticInst
cpu/static_inst.cc:
Untemplatized StaticInst
cpu/static_inst.hh:
Untemplatized StaticInst by using the TheISA namespace
dev/alpha_console.cc:
Added using namespace AlphaISA
dev/simple_disk.hh:
Added typedef for Addr and fixed up some formatting
dev/sinicreg.hh:
Added TheISA namespace specifier where needed
dev/tsunami.cc:
dev/tsunami_io.cc:
dev/tsunami_pchip.cc:
Added using namespace TheISA. It might be better for it to be AlphaISA
dev/tsunami_cchip.cc:
Added typedef for TheISA. It might be better for it to be AlphaISA
kern/linux/aligned.hh:
sim/pseudo_inst.hh:
Added TheISA namespace specifier to Addr
kern/linux/linux_threadinfo.hh:
Added typedef for Addr, and TheISA namespace specifier to StackPointerReg
kern/tru64/mbuf.hh:
Added TheISA to Addr type in structs
sim/process.hh:
Added typedefs of Addr, RegFile, and MachInst
sim/syscall_emul.cc:
Added using namespace TheISA, and a cast of VMPageSize to the int type
sim/syscall_emul.hh:
Added typecast for Addr, and TheISA namespace specifier for where needed
--HG--
extra : convert_revision : 91d4f6ca33a73b21c1f1771d74bfdea3b80eff45
2006-02-19 08:34:37 +01:00
|
|
|
return (int)VMPageSize;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2008-11-15 18:30:10 +01:00
|
|
|
brkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
// change brk addr to first arg
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
Addr new_brk = p->getSyscallArg(tc, index);
|
2008-11-15 18:30:10 +01:00
|
|
|
|
|
|
|
// in Linux at least, brk(0) returns the current break value
|
|
|
|
// (note that the syscall and the glibc function have different behavior)
|
|
|
|
if (new_brk == 0)
|
|
|
|
return p->brk_point;
|
|
|
|
|
|
|
|
if (new_brk > p->brk_point) {
|
|
|
|
// might need to allocate some new pages
|
2006-03-15 23:04:50 +01:00
|
|
|
for (ChunkGenerator gen(p->brk_point, new_brk - p->brk_point,
|
|
|
|
VMPageSize); !gen.done(); gen.next()) {
|
2008-11-15 18:30:10 +01:00
|
|
|
if (!p->pTable->translate(gen.addr()))
|
2011-10-23 07:30:08 +02:00
|
|
|
p->allocateMem(roundDown(gen.addr(), VMPageSize), VMPageSize);
|
2009-10-24 19:53:58 +02:00
|
|
|
|
|
|
|
// if the address is already there, zero it out
|
|
|
|
else {
|
|
|
|
uint8_t zero = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
SETranslatingPortProxy *tp = tc->getMemProxy();
|
2009-10-24 19:53:58 +02:00
|
|
|
|
|
|
|
// split non-page aligned accesses
|
|
|
|
Addr next_page = roundUp(gen.addr(), VMPageSize);
|
|
|
|
uint32_t size_needed = next_page - gen.addr();
|
|
|
|
tp->memsetBlob(gen.addr(), zero, size_needed);
|
|
|
|
if (gen.addr() + VMPageSize > next_page &&
|
|
|
|
next_page < new_brk &&
|
|
|
|
p->pTable->translate(next_page))
|
|
|
|
{
|
|
|
|
size_needed = VMPageSize - size_needed;
|
|
|
|
tp->memsetBlob(next_page, zero, size_needed);
|
|
|
|
}
|
|
|
|
}
|
2006-03-15 23:04:50 +01:00
|
|
|
}
|
2005-03-09 21:52:10 +01:00
|
|
|
}
|
2008-11-15 18:30:10 +01:00
|
|
|
|
|
|
|
p->brk_point = new_brk;
|
2005-03-10 20:20:12 +01:00
|
|
|
DPRINTF(SyscallVerbose, "Break Point changed to: %#X\n", p->brk_point);
|
|
|
|
return p->brk_point;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
closeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int target_fd = p->getSyscallArg(tc, index);
|
2010-07-22 19:47:52 +02:00
|
|
|
int sim_fd = p->sim_fd(target_fd);
|
|
|
|
int status = 0;
|
|
|
|
if (sim_fd > 2)
|
|
|
|
status = close(sim_fd);
|
2005-11-11 03:08:33 +01:00
|
|
|
if (status >= 0)
|
|
|
|
p->free_fd(target_fd);
|
|
|
|
return status;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
readFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, index));
|
|
|
|
Addr bufPtr = p->getSyscallArg(tc, index);
|
|
|
|
int nbytes = p->getSyscallArg(tc, index);
|
|
|
|
BufferArg bufArg(bufPtr, nbytes);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
int bytes_read = read(fd, bufArg.bufferPtr(), nbytes);
|
|
|
|
|
|
|
|
if (bytes_read != -1)
|
2012-01-17 19:55:08 +01:00
|
|
|
bufArg.copyOut(tc->getMemProxy());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return bytes_read;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
writeFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, index));
|
|
|
|
Addr bufPtr = p->getSyscallArg(tc, index);
|
|
|
|
int nbytes = p->getSyscallArg(tc, index);
|
|
|
|
BufferArg bufArg(bufPtr, nbytes);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
bufArg.copyIn(tc->getMemProxy());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
int bytes_written = write(fd, bufArg.bufferPtr(), nbytes);
|
|
|
|
|
|
|
|
fsync(fd);
|
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return bytes_written;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
lseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, index));
|
|
|
|
uint64_t offs = p->getSyscallArg(tc, index);
|
|
|
|
int whence = p->getSyscallArg(tc, index);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
off_t result = lseek(fd, offs, whence);
|
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return (result == (off_t)-1) ? -errno : result;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-03 04:34:55 +01:00
|
|
|
SyscallReturn
|
|
|
|
_llseekFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = p->sim_fd(p->getSyscallArg(tc, index));
|
|
|
|
uint64_t offset_high = p->getSyscallArg(tc, index);
|
|
|
|
uint32_t offset_low = p->getSyscallArg(tc, index);
|
|
|
|
Addr result_ptr = p->getSyscallArg(tc, index);
|
|
|
|
int whence = p->getSyscallArg(tc, index);
|
2007-03-03 04:34:55 +01:00
|
|
|
|
|
|
|
uint64_t offset = (offset_high << 32) | offset_low;
|
|
|
|
|
|
|
|
uint64_t result = lseek(fd, offset, whence);
|
|
|
|
result = TheISA::htog(result);
|
|
|
|
|
|
|
|
if (result == (off_t)-1) {
|
|
|
|
//The seek failed.
|
|
|
|
return -errno;
|
|
|
|
} else {
|
2009-04-21 17:17:36 +02:00
|
|
|
// The seek succeeded.
|
|
|
|
// Copy "result" to "result_ptr"
|
|
|
|
// XXX We'll assume that the size of loff_t is 64 bits on the
|
|
|
|
// target platform
|
2007-03-03 04:34:55 +01:00
|
|
|
BufferArg result_buf(result_ptr, sizeof(result));
|
|
|
|
memcpy(result_buf.bufferPtr(), &result, sizeof(result));
|
2012-01-17 19:55:08 +01:00
|
|
|
result_buf.copyOut(tc->getMemProxy());
|
2007-03-03 04:34:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (result == (off_t)-1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
munmapFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
|
|
|
// given that we don't really implement mmap, munmap is really easy
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *hostname = "m5.eecs.umich.edu";
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
gethostnameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2003-12-02 04:34:38 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
Addr bufPtr = p->getSyscallArg(tc, index);
|
|
|
|
int name_len = p->getSyscallArg(tc, index);
|
|
|
|
BufferArg name(bufPtr, name_len);
|
2003-12-02 04:34:38 +01:00
|
|
|
|
|
|
|
strncpy((char *)name.bufferPtr(), hostname, name_len);
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
name.copyOut(tc->getMemProxy());
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-03-10 20:20:12 +01:00
|
|
|
return 0;
|
2003-12-02 04:34:38 +01:00
|
|
|
}
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
SyscallReturn
|
|
|
|
getcwdFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
int result = 0;
|
2009-11-09 16:02:55 +01:00
|
|
|
int index = 0;
|
2009-10-30 08:44:55 +01:00
|
|
|
Addr bufPtr = p->getSyscallArg(tc, index);
|
|
|
|
unsigned long size = p->getSyscallArg(tc, index);
|
|
|
|
BufferArg buf(bufPtr, size);
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
// Is current working directory defined?
|
|
|
|
string cwd = p->getcwd();
|
|
|
|
if (!cwd.empty()) {
|
|
|
|
if (cwd.length() >= size) {
|
|
|
|
// Buffer too small
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
strncpy((char *)buf.bufferPtr(), cwd.c_str(), size);
|
|
|
|
result = cwd.length();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (getcwd((char *)buf.bufferPtr(), size) != NULL) {
|
|
|
|
result = strlen((char *)buf.bufferPtr());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
buf.copyOut(tc->getMemProxy());
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
|
|
|
readlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
|
2008-07-23 23:41:33 +02:00
|
|
|
return (TheISA::IntReg)-EFAULT;
|
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
Addr bufPtr = p->getSyscallArg(tc, index);
|
|
|
|
size_t bufsiz = p->getSyscallArg(tc, index);
|
|
|
|
|
|
|
|
BufferArg buf(bufPtr, bufsiz);
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
int result = readlink(path.c_str(), (char *)buf.bufferPtr(), bufsiz);
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
buf.copyOut(tc->getMemProxy());
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
unlinkFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2004-02-05 18:16:17 +01:00
|
|
|
{
|
2005-06-03 22:19:34 +02:00
|
|
|
string path;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
|
2005-03-09 21:52:10 +01:00
|
|
|
return (TheISA::IntReg)-EFAULT;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2004-02-05 18:16:17 +01:00
|
|
|
int result = unlink(path.c_str());
|
2005-03-10 20:20:12 +01:00
|
|
|
return (result == -1) ? -errno : result;
|
2004-02-05 18:16:17 +01:00
|
|
|
}
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
SyscallReturn
|
|
|
|
mkdirFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
|
2008-07-23 23:41:33 +02:00
|
|
|
return (TheISA::IntReg)-EFAULT;
|
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
mode_t mode = p->getSyscallArg(tc, index);
|
2008-07-23 23:41:33 +02:00
|
|
|
|
|
|
|
int result = mkdir(path.c_str(), mode);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2005-03-09 21:52:10 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
renameFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2004-02-05 18:16:17 +01:00
|
|
|
{
|
2005-06-03 22:19:34 +02:00
|
|
|
string old_name;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(old_name, p->getSyscallArg(tc, index)))
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EFAULT;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
string new_name;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(new_name, p->getSyscallArg(tc, index)))
|
2005-03-10 20:20:12 +01:00
|
|
|
return -EFAULT;
|
2004-02-05 18:16:17 +01:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
old_name = p->fullPath(old_name);
|
|
|
|
new_name = p->fullPath(new_name);
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
int64_t result = rename(old_name.c_str(), new_name.c_str());
|
2005-03-10 20:20:12 +01:00
|
|
|
return (result == -1) ? -errno : result;
|
2004-02-05 18:16:17 +01:00
|
|
|
}
|
2003-12-02 04:34:38 +01:00
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
truncateFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2005-06-03 22:19:34 +02:00
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
|
2005-06-03 22:19:34 +02:00
|
|
|
return -EFAULT;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
off_t length = p->getSyscallArg(tc, index);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2005-06-03 22:19:34 +02:00
|
|
|
int result = truncate(path.c_str(), length);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2009-04-21 17:17:36 +02:00
|
|
|
ftruncateFunc(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *process, ThreadContext *tc)
|
2005-06-03 22:19:34 +02:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, index));
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
off_t length = process->getSyscallArg(tc, index);
|
2005-06-03 22:19:34 +02:00
|
|
|
|
|
|
|
int result = ftruncate(fd, length);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
2005-11-22 18:08:08 +01:00
|
|
|
|
2009-10-30 17:31:55 +01:00
|
|
|
SyscallReturn
|
|
|
|
truncate64Func(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *process, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
string path;
|
|
|
|
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path, process->getSyscallArg(tc, index)))
|
2009-10-30 17:31:55 +01:00
|
|
|
return -EFAULT;
|
|
|
|
|
2009-11-14 18:49:01 +01:00
|
|
|
int64_t length = process->getSyscallArg(tc, index, 64);
|
2009-10-30 17:31:55 +01:00
|
|
|
|
|
|
|
// Adjust path for current working directory
|
|
|
|
path = process->fullPath(path);
|
|
|
|
|
2009-11-14 18:49:01 +01:00
|
|
|
#if NO_STAT64
|
|
|
|
int result = truncate(path.c_str(), length);
|
|
|
|
#else
|
2009-10-30 17:31:55 +01:00
|
|
|
int result = truncate64(path.c_str(), length);
|
2009-11-14 18:49:01 +01:00
|
|
|
#endif
|
2009-10-30 17:31:55 +01:00
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2009-10-24 19:53:58 +02:00
|
|
|
SyscallReturn
|
|
|
|
ftruncate64Func(SyscallDesc *desc, int num,
|
|
|
|
LiveProcess *process, ThreadContext *tc)
|
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, index));
|
2009-10-24 19:53:58 +02:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-11-14 18:49:01 +01:00
|
|
|
int64_t length = process->getSyscallArg(tc, index, 64);
|
2009-10-24 19:53:58 +02:00
|
|
|
|
2009-11-14 18:49:01 +01:00
|
|
|
#if NO_STAT64
|
|
|
|
int result = ftruncate(fd, length);
|
|
|
|
#else
|
2009-10-24 19:53:58 +02:00
|
|
|
int result = ftruncate64(fd, length);
|
2009-11-14 18:49:01 +01:00
|
|
|
#endif
|
2009-10-24 19:53:58 +02:00
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
2008-07-23 23:41:33 +02:00
|
|
|
SyscallReturn
|
|
|
|
umaskFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
|
|
|
|
{
|
|
|
|
// Letting the simulated program change the simulator's umask seems like
|
|
|
|
// a bad idea. Compromise by just returning the current umask but not
|
|
|
|
// changing anything.
|
|
|
|
mode_t oldMask = umask(0);
|
|
|
|
umask(oldMask);
|
2008-08-04 03:19:53 +02:00
|
|
|
return (int)oldMask;
|
2008-07-23 23:41:33 +02:00
|
|
|
}
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
chownFunc(SyscallDesc *desc, int num, LiveProcess *p, ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
|
|
|
string path;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
2012-01-17 19:55:08 +01:00
|
|
|
if (!tc->getMemProxy()->tryReadString(path, p->getSyscallArg(tc, index)))
|
2005-11-22 18:08:08 +01:00
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* XXX endianess */
|
2009-10-30 08:44:55 +01:00
|
|
|
uint32_t owner = p->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
uid_t hostOwner = owner;
|
2009-10-30 08:44:55 +01:00
|
|
|
uint32_t group = p->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
gid_t hostGroup = group;
|
|
|
|
|
2006-11-16 21:43:11 +01:00
|
|
|
// Adjust path for current working directory
|
|
|
|
path = p->fullPath(path);
|
|
|
|
|
2005-11-22 18:08:08 +01:00
|
|
|
int result = chown(path.c_str(), hostOwner, hostGroup);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fchownFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
|
2005-11-22 18:08:08 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, index));
|
2005-11-22 18:08:08 +01:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
|
|
|
/* XXX endianess */
|
2009-10-30 08:44:55 +01:00
|
|
|
uint32_t owner = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
uid_t hostOwner = owner;
|
2009-10-30 08:44:55 +01:00
|
|
|
uint32_t group = process->getSyscallArg(tc, index);
|
2005-11-22 18:08:08 +01:00
|
|
|
gid_t hostGroup = group;
|
|
|
|
|
|
|
|
int result = fchown(fd, hostOwner, hostGroup);
|
|
|
|
return (result == -1) ? -errno : result;
|
|
|
|
}
|
2006-02-19 05:44:22 +01:00
|
|
|
|
|
|
|
|
2006-08-28 16:39:56 +02:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
dupFunc(SyscallDesc *desc, int num, LiveProcess *process, ThreadContext *tc)
|
2006-08-28 16:39:56 +02:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->sim_fd(process->getSyscallArg(tc, index));
|
2006-08-28 16:39:56 +02:00
|
|
|
if (fd < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
Process::FdMap *fdo = process->sim_fd_obj(fd);
|
2007-11-29 06:22:46 +01:00
|
|
|
|
2006-08-28 16:39:56 +02:00
|
|
|
int result = dup(fd);
|
2009-04-21 17:17:36 +02:00
|
|
|
return (result == -1) ? -errno :
|
|
|
|
process->alloc_fd(result, fdo->filename, fdo->flags, fdo->mode, false);
|
2006-08-28 16:39:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fcntlFunc(SyscallDesc *desc, int num, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-02-19 05:44:22 +01:00
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->getSyscallArg(tc, index);
|
2006-02-19 05:44:22 +01:00
|
|
|
|
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int cmd = process->getSyscallArg(tc, index);
|
2006-02-19 05:44:22 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-09 23:07:13 +02:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
fcntl64Func(SyscallDesc *desc, int num, LiveProcess *process,
|
2006-06-09 23:07:13 +02:00
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
int fd = process->getSyscallArg(tc, index);
|
2006-06-09 23:07:13 +02:00
|
|
|
|
|
|
|
if (fd < 0 || process->sim_fd(fd) < 0)
|
|
|
|
return -EBADF;
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
int cmd = process->getSyscallArg(tc, index);
|
2006-06-09 23:07:13 +02:00
|
|
|
switch (cmd) {
|
|
|
|
case 33: //F_GETLK64
|
|
|
|
warn("fcntl64(%d, F_GETLK64) not supported, error returned\n", fd);
|
|
|
|
return -EMFILE;
|
|
|
|
|
|
|
|
case 34: // F_SETLK64
|
|
|
|
case 35: // F_SETLKW64
|
|
|
|
warn("fcntl64(%d, F_SETLK(W)64) not supported, error returned\n", fd);
|
|
|
|
return -EMFILE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// not sure if this is totally valid, but we'll pass it through
|
|
|
|
// to the underlying OS
|
|
|
|
warn("fcntl64(%d, %d) passed through to host\n", fd, cmd);
|
|
|
|
return fcntl(process->sim_fd(fd), cmd);
|
|
|
|
// return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-09 21:42:09 +01:00
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
pipePseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
int fds[2], sim_fds[2];
|
|
|
|
int pipe_retval = pipe(fds);
|
|
|
|
|
|
|
|
if (pipe_retval < 0) {
|
|
|
|
// error
|
|
|
|
return pipe_retval;
|
|
|
|
}
|
|
|
|
|
2007-11-29 06:22:46 +01:00
|
|
|
sim_fds[0] = process->alloc_fd(fds[0], "PIPE-READ", O_WRONLY, -1, true);
|
|
|
|
sim_fds[1] = process->alloc_fd(fds[1], "PIPE-WRITE", O_RDONLY, -1, true);
|
2006-03-09 21:42:09 +01:00
|
|
|
|
2007-11-29 06:22:46 +01:00
|
|
|
process->setReadPipeSource(sim_fds[0], sim_fds[1]);
|
2006-03-09 21:42:09 +01:00
|
|
|
// Alpha Linux convention for pipe() is that fd[0] is returned as
|
|
|
|
// the return value of the function, and fd[1] is returned in r20.
|
2006-06-06 23:32:21 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, sim_fds[1]);
|
2006-03-09 21:42:09 +01:00
|
|
|
return sim_fds[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getpidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Make up a PID. There's no interprocess communication in
|
|
|
|
// fake_syscall mode, so there's no way for a process to know it's
|
|
|
|
// not getting a unique value.
|
|
|
|
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->ppid());
|
|
|
|
return process->pid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getuidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Make up a UID and EUID... it shouldn't matter, and we want the
|
|
|
|
// simulation to be deterministic.
|
|
|
|
|
|
|
|
// EUID goes in r20.
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->euid()); //EUID
|
2008-09-10 20:26:15 +02:00
|
|
|
return process->uid(); // UID
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getgidPseudoFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Get current group ID. EGID goes in r20.
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->egid()); //EGID
|
|
|
|
return process->gid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
setuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// can't fathom why a benchmark would call this.
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
warn("Ignoring call to setuid(%d)\n", process->getSyscallArg(tc, index));
|
2006-03-09 21:42:09 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getpidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
|
|
|
// Make up a PID. There's no interprocess communication in
|
|
|
|
// fake_syscall mode, so there's no way for a process to know it's
|
|
|
|
// not getting a unique value.
|
|
|
|
|
2006-09-17 09:00:55 +02:00
|
|
|
tc->setIntReg(SyscallPseudoReturnReg, process->ppid()); //PID
|
|
|
|
return process->pid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getppidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2006-09-17 09:00:55 +02:00
|
|
|
return process->ppid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2008-09-10 20:26:15 +02:00
|
|
|
return process->uid(); // UID
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
geteuidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2008-09-10 20:26:15 +02:00
|
|
|
return process->euid(); // UID
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getgidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2006-09-17 09:00:55 +02:00
|
|
|
return process->gid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SyscallReturn
|
2006-09-17 09:00:55 +02:00
|
|
|
getegidFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
2006-06-06 23:32:21 +02:00
|
|
|
ThreadContext *tc)
|
2006-03-09 21:42:09 +01:00
|
|
|
{
|
2006-09-17 09:00:55 +02:00
|
|
|
return process->egid();
|
2006-03-09 21:42:09 +01:00
|
|
|
}
|
|
|
|
|
2006-02-19 05:44:22 +01:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
SyscallReturn
|
|
|
|
cloneFunc(SyscallDesc *desc, int callnum, LiveProcess *process,
|
|
|
|
ThreadContext *tc)
|
|
|
|
{
|
2009-10-30 08:44:55 +01:00
|
|
|
int index = 0;
|
|
|
|
IntReg flags = process->getSyscallArg(tc, index);
|
|
|
|
IntReg newStack = process->getSyscallArg(tc, index);
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
DPRINTF(SyscallVerbose, "In sys_clone:\n");
|
2009-10-30 08:44:55 +01:00
|
|
|
DPRINTF(SyscallVerbose, " Flags=%llx\n", flags);
|
|
|
|
DPRINTF(SyscallVerbose, " Child stack=%llx\n", newStack);
|
2009-04-21 17:17:36 +02:00
|
|
|
|
|
|
|
|
2009-10-30 08:44:55 +01:00
|
|
|
if (flags != 0x10f00) {
|
2009-04-21 17:17:36 +02:00
|
|
|
warn("This sys_clone implementation assumes flags "
|
|
|
|
"CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD "
|
|
|
|
"(0x10f00), and may not work correctly with given flags "
|
2009-10-30 08:44:55 +01:00
|
|
|
"0x%llx\n", flags);
|
2009-04-21 17:17:36 +02:00
|
|
|
}
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
ThreadContext* ctc; // child thread context
|
2009-04-21 17:17:36 +02:00
|
|
|
if ( ( ctc = process->findFreeContext() ) != NULL ) {
|
|
|
|
DPRINTF(SyscallVerbose, " Found unallocated thread context\n");
|
|
|
|
|
|
|
|
ctc->clearArchRegs();
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Arch-specific cloning code
|
2009-04-21 17:17:36 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA or THE_ISA == X86_ISA
|
2009-04-21 17:17:36 +02:00
|
|
|
// Cloning the misc. regs for these archs is enough
|
2009-04-21 17:17:36 +02:00
|
|
|
TheISA::copyMiscRegs(tc, ctc);
|
|
|
|
#elif THE_ISA == SPARC_ISA
|
|
|
|
TheISA::copyRegs(tc, ctc);
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// TODO: Explain what this code actually does :-)
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(NumIntArchRegs + 6, 0);
|
|
|
|
ctc->setIntReg(NumIntArchRegs + 4, 0);
|
|
|
|
ctc->setIntReg(NumIntArchRegs + 3, NWindows - 2);
|
|
|
|
ctc->setIntReg(NumIntArchRegs + 5, NWindows);
|
2009-07-10 10:01:47 +02:00
|
|
|
ctc->setMiscReg(MISCREG_CWP, 0);
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(NumIntArchRegs + 7, 0);
|
|
|
|
ctc->setMiscRegNoEffect(MISCREG_TL, 0);
|
|
|
|
ctc->setMiscRegNoEffect(MISCREG_ASI, ASI_PRIMARY);
|
|
|
|
|
|
|
|
for (int y = 8; y < 32; y++)
|
|
|
|
ctc->setIntReg(y, tc->readIntReg(y));
|
2011-03-18 01:20:20 +01:00
|
|
|
#elif THE_ISA == ARM_ISA
|
|
|
|
TheISA::copyRegs(tc, ctc);
|
2009-04-21 17:17:36 +02:00
|
|
|
#else
|
|
|
|
fatal("sys_clone is not implemented for this ISA\n");
|
|
|
|
#endif
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Set up stack register
|
2009-10-30 08:44:55 +01:00
|
|
|
ctc->setIntReg(TheISA::StackPointerReg, newStack);
|
2009-04-21 17:17:36 +02:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Set up syscall return values in parent and child
|
|
|
|
ctc->setIntReg(ReturnValueReg, 0); // return value, child
|
2009-04-21 17:17:36 +02:00
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// Alpha needs SyscallSuccessReg=0 in child
|
2009-04-21 17:17:36 +02:00
|
|
|
#if THE_ISA == ALPHA_ISA
|
2009-04-21 17:17:36 +02:00
|
|
|
ctc->setIntReg(TheISA::SyscallSuccessReg, 0);
|
2009-04-21 17:17:36 +02:00
|
|
|
#endif
|
|
|
|
|
2009-04-21 17:17:36 +02:00
|
|
|
// In SPARC/Linux, clone returns 0 on pseudo-return register if
|
|
|
|
// parent, non-zero if child
|
2009-04-21 17:17:36 +02:00
|
|
|
#if THE_ISA == SPARC_ISA
|
|
|
|
tc->setIntReg(TheISA::SyscallPseudoReturnReg, 0);
|
|
|
|
ctc->setIntReg(TheISA::SyscallPseudoReturnReg, 1);
|
|
|
|
#endif
|
|
|
|
|
ISA,CPU,etc: Create an ISA defined PC type that abstracts out ISA behaviors.
This change is a low level and pervasive reorganization of how PCs are managed
in M5. Back when Alpha was the only ISA, there were only 2 PCs to worry about,
the PC and the NPC, and the lsb of the PC signaled whether or not you were in
PAL mode. As other ISAs were added, we had to add an NNPC, micro PC and next
micropc, x86 and ARM introduced variable length instruction sets, and ARM
started to keep track of mode bits in the PC. Each CPU model handled PCs in
its own custom way that needed to be updated individually to handle the new
dimensions of variability, or, in the case of ARMs mode-bit-in-the-pc hack,
the complexity could be hidden in the ISA at the ISA implementation's expense.
Areas like the branch predictor hadn't been updated to handle branch delay
slots or micropcs, and it turns out that had introduced a significant (10s of
percent) performance bug in SPARC and to a lesser extend MIPS. Rather than
perpetuate the problem by reworking O3 again to handle the PC features needed
by x86, this change was introduced to rework PC handling in a more modular,
transparent, and hopefully efficient way.
PC type:
Rather than having the superset of all possible elements of PC state declared
in each of the CPU models, each ISA defines its own PCState type which has
exactly the elements it needs. A cross product of canned PCState classes are
defined in the new "generic" ISA directory for ISAs with/without delay slots
and microcode. These are either typedef-ed or subclassed by each ISA. To read
or write this structure through a *Context, you use the new pcState() accessor
which reads or writes depending on whether it has an argument. If you just
want the address of the current or next instruction or the current micro PC,
you can get those through read-only accessors on either the PCState type or
the *Contexts. These are instAddr(), nextInstAddr(), and microPC(). Note the
move away from readPC. That name is ambiguous since it's not clear whether or
not it should be the actual address to fetch from, or if it should have extra
bits in it like the PAL mode bit. Each class is free to define its own
functions to get at whatever values it needs however it needs to to be used in
ISA specific code. Eventually Alpha's PAL mode bit could be moved out of the
PC and into a separate field like ARM.
These types can be reset to a particular pc (where npc = pc +
sizeof(MachInst), nnpc = npc + sizeof(MachInst), upc = 0, nupc = 1 as
appropriate), printed, serialized, and compared. There is a branching()
function which encapsulates code in the CPU models that checked if an
instruction branched or not. Exactly what that means in the context of branch
delay slots which can skip an instruction when not taken is ambiguous, and
ideally this function and its uses can be eliminated. PCStates also generally
know how to advance themselves in various ways depending on if they point at
an instruction, a microop, or the last microop of a macroop. More on that
later.
Ideally, accessing all the PCs at once when setting them will improve
performance of M5 even though more data needs to be moved around. This is
because often all the PCs need to be manipulated together, and by getting them
all at once you avoid multiple function calls. Also, the PCs of a particular
thread will have spatial locality in the cache. Previously they were grouped
by element in arrays which spread out accesses.
Advancing the PC:
The PCs were previously managed entirely by the CPU which had to know about PC
semantics, try to figure out which dimension to increment the PC in, what to
set NPC/NNPC, etc. These decisions are best left to the ISA in conjunction
with the PC type itself. Because most of the information about how to
increment the PC (mainly what type of instruction it refers to) is contained
in the instruction object, a new advancePC virtual function was added to the
StaticInst class. Subclasses provide an implementation that moves around the
right element of the PC with a minimal amount of decision making. In ISAs like
Alpha, the instructions always simply assign NPC to PC without having to worry
about micropcs, nnpcs, etc. The added cost of a virtual function call should
be outweighed by not having to figure out as much about what to do with the
PCs and mucking around with the extra elements.
One drawback of making the StaticInsts advance the PC is that you have to
actually have one to advance the PC. This would, superficially, seem to
require decoding an instruction before fetch could advance. This is, as far as
I can tell, realistic. fetch would advance through memory addresses, not PCs,
perhaps predicting new memory addresses using existing ones. More
sophisticated decisions about control flow would be made later on, after the
instruction was decoded, and handed back to fetch. If branching needs to
happen, some amount of decoding needs to happen to see that it's a branch,
what the target is, etc. This could get a little more complicated if that gets
done by the predecoder, but I'm choosing to ignore that for now.
Variable length instructions:
To handle variable length instructions in x86 and ARM, the predecoder now
takes in the current PC by reference to the getExtMachInst function. It can
modify the PC however it needs to (by setting NPC to be the PC + instruction
length, for instance). This could be improved since the CPU doesn't know if
the PC was modified and always has to write it back.
ISA parser:
To support the new API, all PC related operand types were removed from the
parser and replaced with a PCState type. There are two warts on this
implementation. First, as with all the other operand types, the PCState still
has to have a valid operand type even though it doesn't use it. Second, using
syntax like PCS.npc(target) doesn't work for two reasons, this looks like the
syntax for operand type overriding, and the parser can't figure out if you're
reading or writing. Instructions that use the PCS operand (which I've
consistently called it) need to first read it into a local variable,
manipulate it, and then write it back out.
Return address stack:
The return address stack needed a little extra help because, in the presence
of branch delay slots, it has to merge together elements of the return PC and
the call PC. To handle that, a buildRetPC utility function was added. There
are basically only two versions in all the ISAs, but it didn't seem short
enough to put into the generic ISA directory. Also, the branch predictor code
in O3 and InOrder were adjusted so that they always store the PC of the actual
call instruction in the RAS, not the next PC. If the call instruction is a
microop, the next PC refers to the next microop in the same macroop which is
probably not desirable. The buildRetPC function advances the PC intelligently
to the next macroop (in an ISA specific way) so that that case works.
Change in stats:
There were no change in stats except in MIPS and SPARC in the O3 model. MIPS
runs in about 9% fewer ticks. SPARC runs with 30%-50% fewer ticks, which could
likely be improved further by setting call/return instruction flags and taking
advantage of the RAS.
TODO:
Add != operators to the PCState classes, defined trivially to be !(a==b).
Smooth out places where PCs are split apart, passed around, and put back
together later. I think this might happen in SPARC's fault code. Add ISA
specific constructors that allow setting PC elements without calling a bunch
of accessors. Try to eliminate the need for the branching() function. Factor
out Alpha's PAL mode pc bit into a separate flag field, and eliminate places
where it's blindly masked out or tested in the PC.
2010-10-31 08:07:20 +01:00
|
|
|
ctc->pcState(tc->nextInstAddr());
|
2009-04-21 17:17:36 +02:00
|
|
|
|
|
|
|
ctc->activate();
|
|
|
|
|
|
|
|
// Should return nonzero child TID in parent's syscall return register,
|
|
|
|
// but for our pthread library any non-zero value will work
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
fatal("Called sys_clone, but no unallocated thread contexts found!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|