memory: remove unused functions

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2023-09-23 21:58:41 +05:30
parent 91a82eec7c
commit 9cdfa90acc
3 changed files with 22 additions and 47 deletions

View File

@@ -17,12 +17,6 @@ class Memory {
uint8_t read(size_t address) const;
void write(size_t address, uint8_t byte);
uint16_t read_halfword(size_t address) const;
void write_halfword(size_t address, uint16_t halfword);
uint32_t read_word(size_t address) const;
void write_word(size_t address, uint32_t word);
private:
#define MEMORY_REGION(name, start, end) \
static constexpr size_t name##_START = start; \

View File

@@ -1,4 +1,5 @@
#include "bus.hh"
#include "util/log.hh"
#include <memory>
namespace matar {
@@ -17,21 +18,38 @@ Bus::write_byte(size_t address, uint8_t byte) {
uint16_t
Bus::read_halfword(size_t address) {
return memory->read_halfword(address);
if (address & 0b01)
glogger.warn("Reading a non aligned halfword address");
return memory->read(address) | memory->read(address + 1) << 8;
}
void
Bus::write_halfword(size_t address, uint16_t halfword) {
memory->write_halfword(address, halfword);
if (address & 0b01)
glogger.warn("Writing to a non aligned halfword address");
memory->write(address, halfword & 0xFF);
memory->write(address + 1, halfword >> 8 & 0xFF);
}
uint32_t
Bus::read_word(size_t address) {
return memory->read_word(address);
if (address & 0b11)
glogger.warn("Reading a non aligned word address");
return memory->read(address) | memory->read(address + 1) << 8 |
memory->read(address + 2) << 16 | memory->read(address + 3) << 24;
}
void
Bus::write_word(size_t address, uint32_t word) {
memory->write_word(address, word);
if (address & 0b11)
glogger.warn("Writing to a non aligned word address");
memory->write(address, word & 0xFF);
memory->write(address + 1, word >> 8 & 0xFF);
memory->write(address + 2, word >> 16 & 0xFF);
memory->write(address + 3, word >> 24 & 0xFF);
}
}

View File

@@ -89,43 +89,6 @@ Memory::write(size_t address, uint8_t byte) {
#undef MATCHES
uint16_t
Memory::read_halfword(size_t address) const {
if (address & 0b01)
glogger.warn("Reading a non aligned halfword address");
return read(address) | read(address + 1) << 8;
}
void
Memory::write_halfword(size_t address, uint16_t halfword) {
if (address & 0b01)
glogger.warn("Writing to a non aligned halfword address");
write(address, halfword & 0xFF);
write(address + 1, halfword >> 8 & 0xFF);
}
uint32_t
Memory::read_word(size_t address) const {
if (address & 0b11)
glogger.warn("Reading a non aligned word address");
return read(address) | read(address + 1) << 8 | read(address + 2) << 16 |
read(address + 3) << 24;
}
void
Memory::write_word(size_t address, uint32_t word) {
if (address & 0b11)
glogger.warn("Writing to a non aligned word address");
write(address, word & 0xFF);
write(address + 1, word >> 8 & 0xFF);
write(address + 2, word >> 16 & 0xFF);
write(address + 3, word >> 24 & 0xFF);
}
void
Memory::parse_header() {