diff options
author | Steve Reinhardt <stever@eecs.umich.edu> | 2006-03-12 00:40:29 -0500 |
---|---|---|
committer | Steve Reinhardt <stever@eecs.umich.edu> | 2006-03-12 00:40:29 -0500 |
commit | 38dd86ce7297b1ebecc5996c0c158990e14b1f02 (patch) | |
tree | 9185434074c988701deb766d93553a535f1c17f4 /mem | |
parent | 1f5266e79d86fd6b82982c3f43dc2e5ef83a18ee (diff) | |
download | gem5-38dd86ce7297b1ebecc5996c0c158990e14b1f02.tar.xz |
Fix TranslatingPort access functions to:
- know nothing about Fault objects (as it should be)
- call fatal() by default on accesses to unmapped addrs
- provide "try" versions for callers that are prepared to handle failure
mem/translating_port.cc:
mem/translating_port.hh:
Memory system objects should not return Fault objects, just errors.
Half the time we don't check the return code anyway, so make
default version of the access functions call fatal().
Provide "try*" versions that return a bool for places where we
really are going to check the return code.
sim/syscall_emul.cc:
sim/syscall_emul.hh:
Need to use new "tryReadString" here since we actually check the return code.
--HG--
extra : convert_revision : 039737398ef183904dc382c05912ab96cd1d4a51
Diffstat (limited to 'mem')
-rw-r--r-- | mem/translating_port.cc | 84 | ||||
-rw-r--r-- | mem/translating_port.hh | 21 |
2 files changed, 75 insertions, 30 deletions
diff --git a/mem/translating_port.cc b/mem/translating_port.cc index 42101dad0..a3bf1baa7 100644 --- a/mem/translating_port.cc +++ b/mem/translating_port.cc @@ -27,7 +27,6 @@ */ #include <string> -#include "arch/faults.hh" #include "base/chunk_generator.hh" #include "mem/port.hh" #include "mem/translating_port.hh" @@ -42,8 +41,8 @@ TranslatingPort::TranslatingPort(Port *_port, PageTable *p_table) TranslatingPort::~TranslatingPort() { } -Fault -TranslatingPort::readBlobFunctional(Addr addr, uint8_t *p, int size) +bool +TranslatingPort::tryReadBlobFunctional(Addr addr, uint8_t *p, int size) { Addr paddr; int prevSize = 0; @@ -51,19 +50,28 @@ TranslatingPort::readBlobFunctional(Addr addr, uint8_t *p, int size) for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) { if (!pTable->translate(gen.addr(),paddr)) - return genMachineCheckFault(); + return false; port->readBlobFunctional(paddr, p + prevSize, gen.size()); prevSize += gen.size(); } - return NoFault; + return true; } -Fault -TranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size, - bool alloc) +void +TranslatingPort::readBlobFunctional(Addr addr, uint8_t *p, int size) +{ + if (!tryReadBlobFunctional(addr, p, size)) + fatal("readBlobFunctional(0x%x, ...) failed", addr); +} + + +bool +TranslatingPort::tryWriteBlobFunctional(Addr addr, uint8_t *p, int size, + bool alloc) { + Addr paddr; int prevSize = 0; @@ -75,7 +83,7 @@ TranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size, VMPageSize); pTable->translate(gen.addr(), paddr); } else { - return genMachineCheckFault(); + return false; } } @@ -83,13 +91,21 @@ TranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size, prevSize += gen.size(); } - return NoFault; + return true; } -Fault -TranslatingPort::memsetBlobFunctional(Addr addr, uint8_t val, int size, - bool alloc) +void +TranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size, + bool alloc) +{ + if (!tryWriteBlobFunctional(addr, p, size, alloc)) + fatal("writeBlobFunctional(0x%x, ...) failed", addr); +} + +bool +TranslatingPort::tryMemsetBlobFunctional(Addr addr, uint8_t val, int size, + bool alloc) { Addr paddr; @@ -101,19 +117,27 @@ TranslatingPort::memsetBlobFunctional(Addr addr, uint8_t val, int size, VMPageSize); pTable->translate(gen.addr(), paddr); } else { - return genMachineCheckFault(); + return false; } } port->memsetBlobFunctional(paddr, val, gen.size()); } - return NoFault; + return true; } +void +TranslatingPort::memsetBlobFunctional(Addr addr, uint8_t val, int size, + bool alloc) +{ + if (!tryMemsetBlobFunctional(addr, val, size, alloc)) + fatal("memsetBlobFunctional(0x%x, ...) failed", addr); +} -Fault -TranslatingPort::writeStringFunctional(Addr addr, const char *str) + +bool +TranslatingPort::tryWriteStringFunctional(Addr addr, const char *str) { Addr paddr,vaddr; uint8_t c; @@ -123,16 +147,23 @@ TranslatingPort::writeStringFunctional(Addr addr, const char *str) do { c = *str++; if (!pTable->translate(vaddr++,paddr)) - return genMachineCheckFault(); + return false; port->writeBlobFunctional(paddr, &c, 1); } while (c); - return NoFault; + return true; } -Fault -TranslatingPort::readStringFunctional(std::string &str, Addr addr) +void +TranslatingPort::writeStringFunctional(Addr addr, const char *str) +{ + if (!tryWriteStringFunctional(addr, str)) + fatal("writeStringFunctional(0x%x, ...) failed", addr); +} + +bool +TranslatingPort::tryReadStringFunctional(std::string &str, Addr addr) { Addr paddr,vaddr; uint8_t c; @@ -141,12 +172,19 @@ TranslatingPort::readStringFunctional(std::string &str, Addr addr) do { if (!pTable->translate(vaddr++,paddr)) - return genMachineCheckFault(); + return false; port->readBlobFunctional(paddr, &c, 1); str += c; } while (c); - return NoFault; + return true; +} + +void +TranslatingPort::readStringFunctional(std::string &str, Addr addr) +{ + if (!tryReadStringFunctional(str, addr)) + fatal("readStringFunctional(0x%x, ...) failed", addr); } diff --git a/mem/translating_port.hh b/mem/translating_port.hh index 1a334c103..eaecff35a 100644 --- a/mem/translating_port.hh +++ b/mem/translating_port.hh @@ -48,14 +48,21 @@ class TranslatingPort virtual ~TranslatingPort(); public: - Fault readBlobFunctional(Addr addr, uint8_t *p, int size); - Fault writeBlobFunctional(Addr addr, uint8_t *p, int size, - bool alloc = false); - Fault memsetBlobFunctional(Addr addr, uint8_t val, int size, - bool alloc = false); - Fault writeStringFunctional(Addr addr, const char *str); - Fault readStringFunctional(std::string &str, Addr addr); + bool tryReadBlobFunctional(Addr addr, uint8_t *p, int size); + bool tryWriteBlobFunctional(Addr addr, uint8_t *p, int size, + bool alloc = false); + bool tryMemsetBlobFunctional(Addr addr, uint8_t val, int size, + bool alloc = false); + bool tryWriteStringFunctional(Addr addr, const char *str); + bool tryReadStringFunctional(std::string &str, Addr addr); + void readBlobFunctional(Addr addr, uint8_t *p, int size); + void writeBlobFunctional(Addr addr, uint8_t *p, int size, + bool alloc = false); + void memsetBlobFunctional(Addr addr, uint8_t val, int size, + bool alloc = false); + void writeStringFunctional(Addr addr, const char *str); + void readStringFunctional(std::string &str, Addr addr); }; #endif |