summaryrefslogtreecommitdiff
path: root/dev
diff options
context:
space:
mode:
Diffstat (limited to 'dev')
-rw-r--r--dev/alpha_console.cc103
-rw-r--r--dev/alpha_console.hh3
-rw-r--r--dev/disk_image.cc40
-rw-r--r--dev/ethertap.cc2
4 files changed, 106 insertions, 42 deletions
diff --git a/dev/alpha_console.cc b/dev/alpha_console.cc
index ee20511e1..f8870496f 100644
--- a/dev/alpha_console.cc
+++ b/dev/alpha_console.cc
@@ -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();
@@ -88,36 +86,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;
}
diff --git a/dev/alpha_console.hh b/dev/alpha_console.hh
index 39d0a0a6b..47afa8f4a 100644
--- a/dev/alpha_console.hh
+++ b/dev/alpha_console.hh
@@ -73,10 +73,7 @@ class SimpleDisk;
class AlphaConsole : public PioDevice
{
protected:
- union {
AlphaAccess *alphaAccess;
- uint8_t *consoleData;
- };
/** the disk must be accessed from the console */
SimpleDisk *disk;
diff --git a/dev/disk_image.cc b/dev/disk_image.cc
index 7779cd79f..d990d7078 100644
--- a/dev/disk_image.cc
+++ b/dev/disk_image.cc
@@ -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;
}
diff --git a/dev/ethertap.cc b/dev/ethertap.cc
index a0d2eda8d..edc400760 100644
--- a/dev/ethertap.cc
+++ b/dev/ethertap.cc
@@ -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>