diff --git a/devices/hmc.cpp b/devices/hmc.cpp new file mode 100644 index 0000000..52d54d7 --- /dev/null +++ b/devices/hmc.cpp @@ -0,0 +1,70 @@ +/* +DingusPPC - The Experimental PowerPC Macintosh emulator +Copyright (C) 2018-20 divingkatae and maximum + (theweirdo) spatium + +(Contact divingkatae#1017 or powermax#2286 on Discord for more info) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/** Highspeed Memory Controller emulation. + + Author: Max Poliakovski +*/ + +#include "hmc.h" + +HMC::HMC() : MemCtrlBase() +{ + this->name = "Highspeed Memory Controller"; + + /* add memory mapped I/O region for the HMC control register */ + add_mmio_region(0x50F40000, 0xFFFF, this); + + this->config_reg = 0ULL; + this->bit_pos = 0; +} + +bool HMC::supports_type(HWCompType type) { + if (type == HWCompType::MEM_CTRL || type == HWCompType::MMIO_DEV) { + return true; + } else { + return false; + } +} + +uint32_t HMC::read(uint32_t reg_start, uint32_t offset, int size) +{ + if (!offset) + return !!(this->config_reg & (1ULL << this->bit_pos++)); + else + return 0; /* FIXME: what should be returned for invalid offsets? */ +} + +void HMC::write(uint32_t reg_start, uint32_t offset, uint32_t value, int size) +{ + uint64_t bit; + + switch(offset) { + case 0: + bit = 1ULL << this->bit_pos++; + this->config_reg = (value & 1) ? this->config_reg | bit : + this->config_reg & ~bit; + break; + case 8: /* writing to HMCBase + 8 resets internal bit position */ + this->bit_pos = 0; + break; + } +} diff --git a/devices/hmc.h b/devices/hmc.h new file mode 100644 index 0000000..f996e04 --- /dev/null +++ b/devices/hmc.h @@ -0,0 +1,54 @@ +/* +DingusPPC - The Experimental PowerPC Macintosh emulator +Copyright (C) 2018-20 divingkatae and maximum + (theweirdo) spatium + +(Contact divingkatae#1017 or powermax#2286 on Discord for more info) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/** Highspeed Memory Controller emulation. + + Author: Max Poliakovski + + Highspeed Memory Controller (HMC) is a custom memory + and L2 cache controller designed especially for the + first generation of the PowerMacintosh computer. +*/ + +#ifndef HMC_H +#define HMC_H + +#include "hwcomponent.h" +#include "memctrlbase.h" +#include "mmiodevice.h" + +class HMC : public MemCtrlBase, public MMIODevice { +public: + HMC(); + ~HMC() = default; + + bool supports_type(HWCompType type); + + /* MMIODevice methods */ + uint32_t read(uint32_t reg_start, uint32_t offset, int size); + void write(uint32_t reg_start, uint32_t offset, uint32_t value, int size); + +private: + int bit_pos; + uint64_t config_reg; +}; + +#endif // HMC_H