summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2006-03-09 18:35:28 -0500
committerGabe Black <gblack@eecs.umich.edu>2006-03-09 18:35:28 -0500
commit872bbdfc33cb82bf32576db3a57d3055a04acbac (patch)
tree837dd214bd682ac7efa515b18857bec7d4d35bef /base
parent3adb45144aca819c9796168ecde7a263169d9d4d (diff)
parent7b283dbc090d1197593b00fd1279b92f7c2e693e (diff)
downloadgem5-872bbdfc33cb82bf32576db3a57d3055a04acbac.tar.xz
Hand merge. Stuff probably doesn't compile.
--HG-- rename : arch/alpha/isa_desc => arch/alpha/isa/main.isa rename : arch/alpha/alpha_linux_process.cc => arch/alpha/linux/process.cc rename : arch/alpha/alpha_linux_process.hh => arch/alpha/linux/process.hh rename : arch/alpha/alpha_tru64_process.cc => arch/alpha/tru64/process.cc rename : arch/alpha/alpha_tru64_process.hh => arch/alpha/tru64/process.hh rename : cpu/exec_context.cc => cpu/cpu_exec_context.cc rename : cpu/exec_context.hh => cpu/cpu_exec_context.hh extra : convert_revision : 7d1efcedd708815d985a951f6f010fbd83dc27e8
Diffstat (limited to 'base')
-rw-r--r--base/intmath.hh16
-rw-r--r--base/loader/elf_object.cc94
-rw-r--r--base/loader/exec_aout.h3
-rw-r--r--base/loader/exec_ecoff.h3
-rw-r--r--base/loader/object_file.hh11
-rw-r--r--base/loader/symtab.hh2
-rw-r--r--base/refcnt.hh2
-rw-r--r--base/remote_gdb.cc68
-rw-r--r--base/remote_gdb.hh2
-rw-r--r--base/sched_list.hh4
-rw-r--r--base/socket.cc3
11 files changed, 149 insertions, 59 deletions
diff --git a/base/intmath.hh b/base/intmath.hh
index 198278d6f..51baddb91 100644
--- a/base/intmath.hh
+++ b/base/intmath.hh
@@ -145,22 +145,6 @@ floorLog2(long long x)
return floorLog2((unsigned long long)x);
}
-#if defined(__APPLE__)
-inline int
-floorLog2(size_t x)
-{
- assert(x > 0);
- assert(sizeof(size_t) == 4 || sizeof(size_t) == 8);
-
- // It's my hope that this is optimized away?
- if (sizeof(size_t) == 4)
- return floorLog2((uint32_t)x);
- else if (sizeof(size_t) == 8)
- return floorLog2((uint64_t)x);
-
-}
-#endif
-
template <class T>
inline int
ceilLog2(T n)
diff --git a/base/loader/elf_object.cc b/base/loader/elf_object.cc
index 52f236fef..1136686f0 100644
--- a/base/loader/elf_object.cc
+++ b/base/loader/elf_object.cc
@@ -38,8 +38,8 @@
#define __LIBELF_NEED_LINK_H 0
#define __LIBELF_SYMBOL_VERSIONS 0
-#include <libelf/libelf.h>
-#include <libelf/gelf.h>
+#include "libelf/libelf.h"
+#include "libelf/gelf.h"
#include "base/loader/elf_object.hh"
@@ -55,6 +55,8 @@ ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
{
Elf *elf;
GElf_Ehdr ehdr;
+ Arch arch = UnknownArch;
+ OpSys opSys = UnknownOpSys;
// check that header matches library version
if (elf_version(EV_CURRENT) == EV_NONE)
@@ -72,17 +74,87 @@ ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
return NULL;
}
else {
- if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
- panic("32 bit ELF Binary, Not Supported");
- /* @todo this emachine value isn't offical yet.
- * so we probably shouldn't check it. */
-// if (ehdr.e_machine != EM_ALPHA)
-// panic("Non Alpha Binary, Not Supported");
+ //Detect the architecture
+ //Versioning issues in libelf need to be resolved to get the correct
+ //SPARC constants.
+ //If MIPS supports 32 bit executables, this may need to be changed.
+ //Also, there are other MIPS constants which may be used, like
+ //EM_MIPS_RS3_LE and EM_MIPS_X
+ //Since we don't know how to check for alpha right now, we'll
+ //just assume if it wasn't something else and it's 64 bit, that's
+ //what it must be.
+ if (ehdr.e_machine == EM_SPARC64 ||
+ ehdr.e_machine == EM_SPARC ||
+ ehdr.e_machine == EM_SPARCV9) {
+ arch = ObjectFile::SPARC;
+ } else if (ehdr.e_machine == EM_MIPS
+ && ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
+ arch = ObjectFile::MIPS;
+ } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) {
+ arch = ObjectFile::Alpha;
+ } else {
+ arch = ObjectFile::UnknownArch;
+ }
- elf_end(elf);
+ //Detect the operating system
+ switch (ehdr.e_ident[EI_OSABI])
+ {
+
+ case ELFOSABI_LINUX:
+ opSys = ObjectFile::Linux;
+ break;
+ case ELFOSABI_SOLARIS:
+ opSys = ObjectFile::Solaris;
+ break;
+ case ELFOSABI_TRU64:
+ opSys = ObjectFile::Tru64;
+ break;
+ default:
+ opSys = ObjectFile::UnknownOpSys;
+ }
- return new ElfObject(fname, fd, len, data,
- ObjectFile::Alpha, ObjectFile::Linux);
+ //take a look at the .note.ABI section
+ //It can let us know what's what.
+ if (opSys == ObjectFile::UnknownOpSys)
+ {
+ Elf_Scn *section;
+ GElf_Shdr shdr;
+ Elf_Data *data;
+ uint32_t osAbi;;
+ int secIdx = 1;
+
+ // Get the first section
+ section = elf_getscn(elf, secIdx);
+
+ // While there are no more sections
+ while (section != NULL) {
+ gelf_getshdr(section, &shdr);
+ if (shdr.sh_type == SHT_NOTE && !strcmp(".note.ABI-tag",
+ elf_strptr(elf, ehdr.e_shstrndx, shdr.sh_name))) {
+ // we have found a ABI note section
+ // Check the 5th 32bit word for OS 0 == linux, 1 == hurd,
+ // 2 == solaris, 3 == freebsd
+ data = elf_rawdata(section, NULL);
+ assert(data->d_buf);
+ if(ehdr.e_ident[EI_DATA] == ELFDATA2LSB)
+ osAbi = htole(((uint32_t*)data->d_buf)[4]);
+ else
+ osAbi = htobe(((uint32_t*)data->d_buf)[4]);
+
+ switch(osAbi) {
+ case 0:
+ opSys = ObjectFile::Linux;
+ break;
+ case 2:
+ opSys = ObjectFile::Solaris;
+ break;
+ }
+ } // if section found
+ section = elf_getscn(elf, ++secIdx);
+ } // while sections
+ }
+ elf_end(elf);
+ return new ElfObject(fname, fd, len, data, arch, opSys);
}
}
diff --git a/base/loader/exec_aout.h b/base/loader/exec_aout.h
index 76ebe9bb5..eed44baee 100644
--- a/base/loader/exec_aout.h
+++ b/base/loader/exec_aout.h
@@ -55,6 +55,7 @@
(N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
N_GETMAGIC(ex) != ZMAGIC)
-#include "targetarch/aout_machdep.h"
+//Only alpha will be able to load aout for now
+#include "arch/alpha/aout_machdep.h"
#endif /* !_SYS_EXEC_AOUT_H_ */
diff --git a/base/loader/exec_ecoff.h b/base/loader/exec_ecoff.h
index 4eece4318..555589806 100644
--- a/base/loader/exec_ecoff.h
+++ b/base/loader/exec_ecoff.h
@@ -37,7 +37,8 @@
#ifndef _SYS_EXEC_ECOFF_H_
#define _SYS_EXEC_ECOFF_H_
-#include "targetarch/ecoff_machdep.h"
+//Only alpha will be able to load ecoff files for now
+#include "arch/alpha/ecoff_machdep.h"
struct ecoff_filehdr {
coff_ushort f_magic; /* magic number */
diff --git a/base/loader/object_file.hh b/base/loader/object_file.hh
index 35ea11b54..08a51863e 100644
--- a/base/loader/object_file.hh
+++ b/base/loader/object_file.hh
@@ -29,7 +29,9 @@
#ifndef __OBJECT_FILE_HH__
#define __OBJECT_FILE_HH__
-#include "targetarch/isa_traits.hh" // for Addr
+#include <string>
+
+#include "sim/host.hh" // for Addr
class TranslatingPort;
class SymbolTable;
@@ -40,13 +42,16 @@ class ObjectFile
enum Arch {
UnknownArch,
- Alpha
+ Alpha,
+ SPARC,
+ MIPS
};
enum OpSys {
UnknownOpSys,
Tru64,
- Linux
+ Linux,
+ Solaris
};
protected:
diff --git a/base/loader/symtab.hh b/base/loader/symtab.hh
index 324fd8b45..ebcda1345 100644
--- a/base/loader/symtab.hh
+++ b/base/loader/symtab.hh
@@ -32,7 +32,7 @@
#include <iosfwd>
#include <map>
-#include "targetarch/isa_traits.hh" // for Addr
+#include "arch/isa_traits.hh" // for Addr
class Checkpoint;
class SymbolTable
diff --git a/base/refcnt.hh b/base/refcnt.hh
index 9d9ed4337..de589f7c5 100644
--- a/base/refcnt.hh
+++ b/base/refcnt.hh
@@ -29,6 +29,8 @@
#ifndef __REFCNT_HH__
#define __REFCNT_HH__
+#include <stddef.h> //For the NULL macro definition
+
class RefCounted
{
private:
diff --git a/base/remote_gdb.cc b/base/remote_gdb.cc
index 67d745d43..84093459c 100644
--- a/base/remote_gdb.cc
+++ b/base/remote_gdb.cc
@@ -129,9 +129,10 @@
#include "cpu/static_inst.hh"
#include "mem/functional/physical.hh"
#include "sim/system.hh"
-#include "targetarch/vtophys.hh"
+#include "arch/vtophys.hh"
using namespace std;
+using namespace TheISA;
#ifndef NDEBUG
vector<RemoteGDB *> debuggers;
@@ -370,7 +371,7 @@ RemoteGDB::acc(Addr va, size_t len)
if (AlphaISA::PcPAL(va) || va < 0x10000)
return true;
- Addr ptbr = context->regs.ipr[AlphaISA::IPR_PALtemp20];
+ Addr ptbr = context->readMiscReg(AlphaISA::IPR_PALtemp20);
TheISA::PageTableEntry pte = kernel_pte_lookup(pmem, ptbr, va);
if (!pte.valid()) {
DPRINTF(GDBAcc, "acc: %#x pte is invalid\n", va);
@@ -423,12 +424,25 @@ void
RemoteGDB::getregs()
{
memset(gdbregs, 0, sizeof(gdbregs));
- memcpy(&gdbregs[KGDB_REG_V0], context->regs.intRegFile, 32 * sizeof(uint64_t));
+
+ gdbregs[KGDB_REG_PC] = context->readPC();
+
+ // @todo: Currently this is very Alpha specific.
+ if (AlphaISA::PcPAL(gdbregs[KGDB_REG_PC])) {
+ for (int i = 0; i < TheISA::NumIntArchRegs; ++i) {
+ gdbregs[i] = context->readIntReg(AlphaISA::reg_redir[i]);
+ }
+ } else {
+ for (int i = 0; i < TheISA::NumIntArchRegs; ++i) {
+ gdbregs[i] = context->readIntReg(i);
+ }
+ }
+
#ifdef KGDB_FP_REGS
- memcpy(&gdbregs[KGDB_REG_F0], context->regs.floatRegFile.q,
- 32 * sizeof(uint64_t));
+ for (int i = 0; i < TheISA::NumFloatArchRegs; ++i) {
+ gdbregs[i + KGDB_REG_F0] = context->readFloatRegInt(i);
+ }
#endif
- gdbregs[KGDB_REG_PC] = context->regs.pc;
}
///////////////////////////////////////////////////////////
@@ -440,13 +454,23 @@ RemoteGDB::getregs()
void
RemoteGDB::setregs()
{
- memcpy(context->regs.intRegFile, &gdbregs[KGDB_REG_V0],
- 32 * sizeof(uint64_t));
+ // @todo: Currently this is very Alpha specific.
+ if (AlphaISA::PcPAL(gdbregs[KGDB_REG_PC])) {
+ for (int i = 0; i < TheISA::NumIntArchRegs; ++i) {
+ context->setIntReg(AlphaISA::reg_redir[i], gdbregs[i]);
+ }
+ } else {
+ for (int i = 0; i < TheISA::NumIntArchRegs; ++i) {
+ context->setIntReg(i, gdbregs[i]);
+ }
+ }
+
#ifdef KGDB_FP_REGS
- memcpy(context->regs.floatRegFile.q, &gdbregs[KGDB_REG_F0],
- 32 * sizeof(uint64_t));
+ for (int i = 0; i < TheISA::NumFloatArchRegs; ++i) {
+ context->setFloatRegInt(i, gdbregs[i + KGDB_REG_F0]);
+ }
#endif
- context->regs.pc = gdbregs[KGDB_REG_PC];
+ context->setPC(gdbregs[KGDB_REG_PC]);
}
void
@@ -485,7 +509,7 @@ RemoteGDB::clearSingleStep()
void
RemoteGDB::setSingleStep()
{
- Addr pc = context->regs.pc;
+ Addr pc = context->readPC();
Addr npc, bpc;
bool set_bt = false;
@@ -494,7 +518,7 @@ RemoteGDB::setSingleStep()
// User was stopped at pc, e.g. the instruction at pc was not
// executed.
MachInst inst = read<MachInst>(pc);
- StaticInstPtr<TheISA> si(inst);
+ StaticInstPtr si(inst);
if (si->hasBranchTarget(pc, context, bpc)) {
// Don't bother setting a breakpoint on the taken branch if it
// is the same as the next pc
@@ -834,7 +858,7 @@ RemoteGDB::trap(int type)
return false;
DPRINTF(GDBMisc, "trap: PC=%#x NPC=%#x\n",
- context->regs.pc, context->regs.npc);
+ context->readPC(), context->readNextPC());
clearSingleStep();
@@ -989,8 +1013,8 @@ RemoteGDB::trap(int type)
subcmd = hex2i(&p);
if (*p++ == ';') {
val = hex2i(&p);
- context->regs.pc = val;
- context->regs.npc = val + sizeof(MachInst);
+ context->setPC(val);
+ context->setNextPC(val + sizeof(MachInst));
}
clearSingleStep();
goto out;
@@ -998,8 +1022,8 @@ RemoteGDB::trap(int type)
case KGDB_CONT:
if (p - data < datalen) {
val = hex2i(&p);
- context->regs.pc = val;
- context->regs.npc = val + sizeof(MachInst);
+ context->setPC(val);
+ context->setNextPC(val + sizeof(MachInst));
}
clearSingleStep();
goto out;
@@ -1008,8 +1032,8 @@ RemoteGDB::trap(int type)
subcmd = hex2i(&p);
if (*p++ == ';') {
val = hex2i(&p);
- context->regs.pc = val;
- context->regs.npc = val + sizeof(MachInst);
+ context->setPC(val);
+ context->setNextPC(val + sizeof(MachInst));
}
setSingleStep();
goto out;
@@ -1017,8 +1041,8 @@ RemoteGDB::trap(int type)
case KGDB_STEP:
if (p - data < datalen) {
val = hex2i(&p);
- context->regs.pc = val;
- context->regs.npc = val + sizeof(MachInst);
+ context->setPC(val);
+ context->setNextPC(val + sizeof(MachInst));
}
setSingleStep();
goto out;
diff --git a/base/remote_gdb.hh b/base/remote_gdb.hh
index 652a58317..b7abf5116 100644
--- a/base/remote_gdb.hh
+++ b/base/remote_gdb.hh
@@ -43,6 +43,8 @@ class PhysicalMemory;
class GDBListener;
class RemoteGDB
{
+ protected:
+ typedef TheISA::MachInst MachInst;
private:
friend void debugger();
friend class GDBListener;
diff --git a/base/sched_list.hh b/base/sched_list.hh
index 0e2f3ddcb..f794e3514 100644
--- a/base/sched_list.hh
+++ b/base/sched_list.hh
@@ -30,8 +30,10 @@
#define SCHED_LIST_HH
#include <list>
+#include "base/intmath.hh"
#include "base/misc.hh"
+
// Any types you use this class for must be covered here...
namespace {
void ClearEntry(int &i) { i = 0; };
@@ -80,7 +82,7 @@ SchedList<T>::SchedList(unsigned _size)
size = _size;
// size must be a power of two
- if (size & (size-1)) {
+ if (!isPowerOf2(size)) {
panic("SchedList: size must be a power of two");
}
diff --git a/base/socket.cc b/base/socket.cc
index f33e79426..45a60e7e3 100644
--- a/base/socket.cc
+++ b/base/socket.cc
@@ -93,9 +93,6 @@ ListenSocket::listen(int port, bool reuse)
return true;
}
-#if defined(__APPLE__)
-typedef int socklen_t;
-#endif
// Open a connection. Accept will block, so if you don't want it to,
// make sure a connection is ready before you call accept.