start towards getting m5 endian compliant
authorAli Saidi <saidi@eecs.umich.edu>
Mon, 21 Jun 2004 04:58:30 +0000 (00:58 -0400)
committerAli Saidi <saidi@eecs.umich.edu>
Mon, 21 Jun 2004 04:58:30 +0000 (00:58 -0400)
base/inifile.cc:
    Added mac os support and fixed a bug, on error we need to exit the
    child process not return
base/intmath.hh:
    gcc on macos wanted a seperate function for the size_t type
base/loader/elf_object.cc:
    I'm not sure why this works under linux because it seems to return
    the wrong value.
base/stats/text.cc:
    added define/include for mac os x
cpu/exec_context.hh:
cpu/simple_cpu/simple_cpu.cc:
    added endian conversion code
dev/alpha_console.cc:
    rather than accessing a charecter array of varying size depending on
    the access, lets actually do this properly.
dev/alpha_console.hh:
    get rid of now nolonger used consoleData
dev/disk_image.cc:
    We have to byte swap the data is some cases, added function to do that
dev/ethertap.cc:
    added preproc directive for mac os

--HG--
extra : convert_revision : 2b5685765cfa2844926d7397f363d2788e3d640a

base/inifile.cc
base/intmath.hh
base/loader/elf_object.cc
base/stats/text.cc
cpu/exec_context.hh
cpu/simple_cpu/simple_cpu.cc
dev/alpha_console.cc
dev/alpha_console.hh
dev/disk_image.cc
dev/ethertap.cc

index 74d47204e0db10fb90df30d3e1dea18b795829e8..001e0a6f8000a035b1416832efcd1ec07c943c5d 100644 (file)
@@ -35,7 +35,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
-#if defined(__OpenBSD__)
+#if defined(__OpenBSD__) || defined(__APPLE__)
 #include <libgen.h>
 #endif
 #include <stdio.h>
@@ -142,11 +142,11 @@ IniFile::loadCPP(const string &file, vector<char *> &cppArgs)
 
         close(STDOUT_FILENO);
         if (dup2(fd[1], STDOUT_FILENO) == -1)
-            return 1;
+            exit(1);
 
         execvp("g++", args);
 
-        exit(1);
+        exit(0);
     }
 
     int retval;
index 77f63fe8d9c2bdc75173085bdffddefebfe8997f..28e9d5c68c98fb90e8ded94b0feb2c867aff22c5 100644 (file)
@@ -119,6 +119,20 @@ FloorLog2(int64_t x)
     return FloorLog2((uint64_t)x);
 }
 
+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);
+
+}
+
 template <class T>
 inline int
 CeilLog2(T n)
index a0c0c05514bf77d12f0d45d17ff404ee405cd1a3..5a8f937cc3379034be2f73a422e420ac2f2d0e28 100644 (file)
@@ -74,8 +74,9 @@ ElfObject::tryFile(const string &fname, int fd, size_t len, uint8_t *data)
     else {
         if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
             panic("32 bit ELF Binary, Not Supported");
-        if (ehdr.e_machine != EM_ALPHA)
-            panic("Non Alpha Binary, Not Supported");
+        printf("emachine = %x\n", ehdr.e_machine);
+//        if (ehdr.e_machine != EM_ALPHA)
+//            panic("Non Alpha Binary, Not Supported");
 
         elf_end(elf);
 
index 79a91e66112db07b76d703ec2c8d52fe7fb21138..ddd4286468d980b96648542587b643b3114a2b10 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if defined(__APPLE__)
+#define _GLIBCPP_USE_C99 1
+#endif
+
 #include <iostream>
 #include <fstream>
 #include <string>
index 7be83539a9a36b782eb418e0f924dda4e7b85171..4f62fa6fae6c2477d9a24f882b078763bee610cd 100644 (file)
@@ -32,6 +32,7 @@
 #include "sim/host.hh"
 #include "mem/mem_req.hh"
 #include "sim/serialize.hh"
+#include "targetarch/byte_swap.hh"
 
 // forward declaration: see functional_memory.hh
 class FunctionalMemory;
@@ -256,7 +257,11 @@ class ExecContext
             cregs->lock_flag = true;
         }
 #endif
-        return mem->read(req, data);
+
+        Fault error;
+        error = mem->read(req, data);
+        data = htoa(data);
+        return error;
     }
 
     template <class T>
@@ -305,7 +310,7 @@ class ExecContext
         }
 
 #endif
-        return mem->write(req, data);
+        return mem->write(req, (T)htoa(data));
     }
 
     virtual bool misspeculating();
index 617c91e6805c0385027a4abc4a2a96bcb12fd749..655a5b3ea1e9ddefa22700cf11ac89757382de68 100644 (file)
@@ -701,6 +701,7 @@ SimpleCPU::tick()
         comInstEventQueue[0]->serviceEvents(numInst);
 
         // decode the instruction
+    inst = htoa(inst);
         StaticInstPtr<TheISA> si(inst);
 
         traceData = Trace::getInstRecord(curTick, xc, this, si,
index 111b23c816dcae23f8396e724a6c05677c885b54..e9780b2d03b676e517a00a78a7db09444cde2437 100644 (file)
@@ -51,6 +51,7 @@
 #include "sim/system.hh"
 #include "dev/tsunami_io.hh"
 #include "sim/sim_object.hh"
+#include "targetarch/byte_swap.hh"
 
 using namespace std;
 
@@ -68,9 +69,6 @@ AlphaConsole::AlphaConsole(const string &name, SimConsole *cons, SimpleDisk *d,
         pioInterface->addAddrRange(addr, addr + size);
     }
 
-    consoleData = new uint8_t[size];
-    memset(consoleData, 0, size);
-
     alphaAccess->last_offset = size - 1;
     alphaAccess->kernStart = system->getKernelStart();
     alphaAccess->kernEnd = system->getKernelEnd();
@@ -95,36 +93,85 @@ Fault
 AlphaConsole::read(MemReqPtr &req, uint8_t *data)
 {
     memset(data, 0, req->size);
-    uint64_t val;
 
     Addr daddr = req->paddr - (addr & PA_IMPL_MASK);
 
-    switch (daddr) {
-      case offsetof(AlphaAccess, inputChar):
-        val = console->console_in();
-        break;
-
-      default:
-        val = *(uint64_t *)(consoleData + daddr);
-        break;
-    }
-
-    DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n", daddr, val);
-
-    switch (req->size) {
-      case sizeof(uint32_t):
-        *(uint32_t *)data = (uint32_t)val;
-        break;
-
-      case sizeof(uint64_t):
-        *(uint64_t *)data = val;
-        break;
-
-      default:
-        return Machine_Check_Fault;
+    switch (req->size)
+    {
+        case sizeof(uint32_t):
+            DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n", daddr, *(uint32_t*)data);
+            switch (daddr)
+            {
+                case offsetof(AlphaAccess, last_offset):
+                    *(uint32_t*)data = alphaAccess->last_offset;
+                    break;
+                case offsetof(AlphaAccess, version):
+                    *(uint32_t*)data = alphaAccess->version;
+                    break;
+                case offsetof(AlphaAccess, numCPUs):
+                    *(uint32_t*)data = alphaAccess->numCPUs;
+                    break;
+                case offsetof(AlphaAccess, bootStrapCPU):
+                    *(uint32_t*)data = alphaAccess->bootStrapCPU;
+                    break;
+                case offsetof(AlphaAccess, intrClockFrequency):
+                    *(uint32_t*)data = alphaAccess->intrClockFrequency;
+                    break;
+                default:
+                    panic("Unknown 32bit access, %#x\n", daddr);
+            }
+            break;
+        case sizeof(uint64_t):
+            DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n", daddr, *(uint64_t*)data);
+            switch (daddr)
+            {
+                case offsetof(AlphaAccess, inputChar):
+                    *(uint64_t*)data = console->console_in();
+                    break;
+                case offsetof(AlphaAccess, cpuClock):
+                    *(uint64_t*)data = alphaAccess->cpuClock;
+                    break;
+                case offsetof(AlphaAccess, mem_size):
+                    *(uint64_t*)data = alphaAccess->mem_size;
+                    break;
+                case offsetof(AlphaAccess, kernStart):
+                    *(uint64_t*)data = alphaAccess->kernStart;
+                    break;
+                case offsetof(AlphaAccess, kernEnd):
+                    *(uint64_t*)data = alphaAccess->kernEnd;
+                    break;
+                case offsetof(AlphaAccess, entryPoint):
+                    *(uint64_t*)data = alphaAccess->entryPoint;
+                    break;
+                case offsetof(AlphaAccess, diskUnit):
+                    *(uint64_t*)data = alphaAccess->diskUnit;
+                    break;
+                case offsetof(AlphaAccess, diskCount):
+                    *(uint64_t*)data = alphaAccess->diskCount;
+                    break;
+                case offsetof(AlphaAccess, diskPAddr):
+                    *(uint64_t*)data = alphaAccess->diskPAddr;
+                    break;
+                case offsetof(AlphaAccess, diskBlock):
+                    *(uint64_t*)data = alphaAccess->diskBlock;
+                    break;
+                case offsetof(AlphaAccess, diskOperation):
+                    *(uint64_t*)data = alphaAccess->diskOperation;
+                    break;
+                case offsetof(AlphaAccess, outputChar):
+                    *(uint64_t*)data = alphaAccess->outputChar;
+                    break;
+                case offsetof(AlphaAccess, bootStrapImpure):
+                    *(uint64_t*)data = alphaAccess->bootStrapImpure;
+                    break;
+                default:
+                    panic("Unknown 64bit access, %#x\n", daddr);
+            }
+            break;
+        default:
+            return Machine_Check_Fault;
     }
 
-
     return No_Fault;
 }
 
index 4986d0e5f0702bf039f461903180b0b2b6793e84..a5cc51c5e3f520e0a8efd9c0732adcb51a2e330e 100644 (file)
@@ -74,10 +74,7 @@ class SimpleDisk;
 class AlphaConsole : public PioDevice
 {
   protected:
-    union {
         AlphaAccess *alphaAccess;
-        uint8_t *consoleData;
-    };
 
     /** the disk must be accessed from the console */
     SimpleDisk *disk;
index 142fb60a5c624909a4281a67e6ea70e35498b608..4df196e64d84014dcf27d31ce19f30e4ab2249c2 100644 (file)
@@ -46,6 +46,7 @@
 #include "dev/disk_image.hh"
 #include "sim/builder.hh"
 #include "sim/sim_exit.hh"
+#include "targetarch/byte_swap.hh"
 
 using namespace std;
 
@@ -227,7 +228,17 @@ SafeRead(ifstream &stream, void *data, int count)
 template<class T>
 void
 SafeRead(ifstream &stream, T &data)
-{ SafeRead(stream, &data, sizeof(data)); }
+{
+    SafeRead(stream, &data, sizeof(data));
+}
+
+template<class T>
+void
+SafeReadSwap(ifstream &stream, T &data)
+{
+    SafeRead(stream, &data, sizeof(data));
+    data = htoa(data);
+}
 
 bool
 CowDiskImage::open(const string &file)
@@ -246,21 +257,21 @@ CowDiskImage::open(const string &file)
         panic("Could not open %s: Invalid magic", file);
 
     uint32_t major, minor;
-    SafeRead(stream, major);
-    SafeRead(stream, minor);
+    SafeReadSwap(stream, major);
+    SafeReadSwap(stream, minor);
 
     if (major != VersionMajor && minor != VersionMinor)
         panic("Could not open %s: invalid version %d.%d != %d.%d",
               file, major, minor, VersionMajor, VersionMinor);
 
     uint64_t sector_count;
-    SafeRead(stream, sector_count);
+    SafeReadSwap(stream, sector_count);
     table = new SectorTable(sector_count);
 
 
     for (uint64_t i = 0; i < sector_count; i++) {
         uint64_t offset;
-        SafeRead(stream, offset);
+        SafeReadSwap(stream, offset);
 
         Sector *sector = new Sector;
         SafeRead(stream, sector, sizeof(Sector));
@@ -300,8 +311,17 @@ SafeWrite(ofstream &stream, const void *data, int count)
 template<class T>
 void
 SafeWrite(ofstream &stream, const T &data)
-{ SafeWrite(stream, &data, sizeof(data)); }
+{
+    SafeWrite(stream, &data, sizeof(data));
+}
 
+template<class T>
+void
+SafeWriteSwap(ofstream &stream, const T &data)
+{
+    T swappeddata = htoa(data);
+    SafeWrite(stream, &swappeddata, sizeof(data));
+}
 void
 CowDiskImage::save()
 {
@@ -322,9 +342,9 @@ CowDiskImage::save(const string &file)
     memcpy(&magic, "COWDISK!", sizeof(magic));
     SafeWrite(stream, magic);
 
-    SafeWrite(stream, (uint32_t)VersionMajor);
-    SafeWrite(stream, (uint32_t)VersionMinor);
-    SafeWrite(stream, (uint64_t)table->size());
+    SafeWriteSwap(stream, (uint32_t)VersionMajor);
+    SafeWriteSwap(stream, (uint32_t)VersionMinor);
+    SafeWriteSwap(stream, (uint64_t)table->size());
 
     uint64_t size = table->size();
     SectorTable::iterator iter = table->begin();
@@ -334,7 +354,7 @@ CowDiskImage::save(const string &file)
         if (iter == end)
             panic("Incorrect Table Size during save of COW disk image");
 
-        SafeWrite(stream, (uint64_t)(*iter).first);
+        SafeWriteSwap(stream, (uint64_t)(*iter).first);
         SafeWrite(stream, (*iter).second->data, sizeof(Sector));
         ++iter;
     }
index db1b3660f0c7e107f8d20d5d56f92a43f46726b7..297053e1e10d0ceeee02c096453290c127a10472 100644 (file)
@@ -30,7 +30,7 @@
  * Interface to connect a simulated ethernet device to the real world
  */
 
-#if defined(__OpenBSD__)
+#if defined(__OpenBSD__) || defined(__APPLE__)
 #include <sys/param.h>
 #endif
 #include <netinet/in.h>