From e3134a64242351bf64458862fd6fd3a5d614dbc3 Mon Sep 17 00:00:00 2001 From: Cody Brocious Date: Sat, 21 May 2016 11:45:28 -0600 Subject: [PATCH] Added LPC and SMBus stub devices. Moved boost headers out of Zookeeper to speed up compiles. --- Box.cpp | 2 ++ Box.hpp | 5 ++++- Debugger.cpp | 3 +++ Gpu.cpp | 5 ++++- IOManager.cpp | 2 ++ Lpc.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ Lpc.hpp | 16 ++++++++++++++++ Smbus.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ Smbus.hpp | 16 ++++++++++++++++ Zookeeper.hpp | 9 +++++---- 10 files changed, 138 insertions(+), 6 deletions(-) create mode 100644 Lpc.cpp create mode 100644 Lpc.hpp create mode 100644 Smbus.cpp create mode 100644 Smbus.hpp diff --git a/Box.cpp b/Box.cpp index b0906f3..7e1b020 100644 --- a/Box.cpp +++ b/Box.cpp @@ -20,6 +20,8 @@ Box::Box() { debugger = new Debugger(); gpu = new Gpu(); + lpc = new Lpc(); + smbus = new Smbus(); } void Box::add_mmio(uint32_t base, uint32_t pages, Device *dev) { diff --git a/Box.hpp b/Box.hpp index ffb8902..73cd7af 100644 --- a/Box.hpp +++ b/Box.hpp @@ -10,7 +10,6 @@ public: void add_pci(uint16_t bus, uint16_t slot, Device *dev); Cpu *cpu; - Gpu *gpu; Hypercall *hypercall; HandleManager *hm; PageManager *pm; @@ -18,6 +17,10 @@ public: IOManager *io; Debugger *debugger; + Gpu *gpu; + Lpc *lpc; + Smbus *smbus; + map mmio; map ports; map pci; diff --git a/Debugger.cpp b/Debugger.cpp index c758f09..b7b3960 100644 --- a/Debugger.cpp +++ b/Debugger.cpp @@ -1,4 +1,7 @@ #include "Zookeeper.hpp" +#include +#include +using namespace boost::algorithm; void break_in(bool fatal) { if(fatal) diff --git a/Gpu.cpp b/Gpu.cpp index dc6a80e..437f046 100644 --- a/Gpu.cpp +++ b/Gpu.cpp @@ -1,7 +1,9 @@ #include "Zookeeper.hpp" +// Comment to enable break_in()s for this file +#define break_in() do { } while(0) + Gpu::Gpu() { - box->add_pci(1, 0, this); box->add_mmio(0xFD000000, 4096, this); // 4096 pages * 4KB == 16MB address space box->add_port(0x80c0, this); } @@ -12,6 +14,7 @@ uint32_t Gpu::readMmio(uint32_t addr) { return 3; default: cout << format("Gpu::readMmio(0x%08x)") % addr << endl; + break_in(); return 0; } } diff --git a/IOManager.cpp b/IOManager.cpp index 6676868..2f4ce13 100644 --- a/IOManager.cpp +++ b/IOManager.cpp @@ -1,4 +1,6 @@ #include "Zookeeper.hpp" +#include +using namespace boost::algorithm; list parse_path(string path) { list vec; diff --git a/Lpc.cpp b/Lpc.cpp new file mode 100644 index 0000000..2e8345c --- /dev/null +++ b/Lpc.cpp @@ -0,0 +1,43 @@ +#include "Zookeeper.hpp" + +// Comment to enable break_in()s for this file +#define break_in() do { } while(0) + +Lpc::Lpc() { + box->add_pci(1, 0, this); +} + +uint32_t Lpc::readMmio(uint32_t addr) { + switch(addr) { + default: + cout << format("Lpc::readMmio(0x%08x)") % addr << endl; + break_in(); + return 0; + } +} + +void Lpc::writeMmio(uint32_t addr, uint32_t value) { + cout << format("Lpc::writeMmio(0x%08x, 0x%08x)") % addr % value << endl; + break_in(); +} + +void Lpc::readPci(uint32_t reg, void *buffer, uint32_t length) { + cout << format("Lpc::readPci(0x%08x, %i)") % reg % length << endl; + break_in(); +} + +void Lpc::writePci(uint32_t reg, void *buffer, uint32_t length) { + cout << format("Lpc::writePci(0x%08x, %i)") % reg % length << endl; + break_in(); +} + +uint32_t Lpc::readPort(uint32_t port, uint32_t size) { + cout << format("Lpc::readPort(0x%04x, %i)") % port % size << endl; + break_in(); + return 0; +} + +void Lpc::writePort(uint32_t port, uint32_t size, uint32_t value) { + cout << format("Lpc::writePort(0x%04x, %i, 0x%x)") % port % size % value << endl; + break_in(); +} diff --git a/Lpc.hpp b/Lpc.hpp new file mode 100644 index 0000000..4119516 --- /dev/null +++ b/Lpc.hpp @@ -0,0 +1,16 @@ +#pragma once +#include "Zookeeper.hpp" + +class Lpc : public Device { +public: + Lpc(); + + uint32_t readMmio(uint32_t addr); + void writeMmio(uint32_t addr, uint32_t value); + + void readPci(uint32_t reg, void *buffer, uint32_t length); + void writePci(uint32_t reg, void *buffer, uint32_t length); + + uint32_t readPort(uint32_t port, uint32_t size); + void writePort(uint32_t port, uint32_t size, uint32_t value); +}; diff --git a/Smbus.cpp b/Smbus.cpp new file mode 100644 index 0000000..941c0d3 --- /dev/null +++ b/Smbus.cpp @@ -0,0 +1,43 @@ +#include "Zookeeper.hpp" + +// Comment to enable break_in()s for this file +#define break_in() do { } while(0) + +Smbus::Smbus() { + box->add_pci(1, 1, this); +} + +uint32_t Smbus::readMmio(uint32_t addr) { + switch(addr) { + default: + cout << format("Smbus::readMmio(0x%08x)") % addr << endl; + break_in(); + return 0; + } +} + +void Smbus::writeMmio(uint32_t addr, uint32_t value) { + cout << format("Smbus::writeMmio(0x%08x, 0x%08x)") % addr % value << endl; + break_in(); +} + +void Smbus::readPci(uint32_t reg, void *buffer, uint32_t length) { + cout << format("Smbus::readPci(0x%08x, %i)") % reg % length << endl; + break_in(); +} + +void Smbus::writePci(uint32_t reg, void *buffer, uint32_t length) { + cout << format("Smbus::writePci(0x%08x, %i)") % reg % length << endl; + break_in(); +} + +uint32_t Smbus::readPort(uint32_t port, uint32_t size) { + cout << format("Smbus::readPort(0x%04x, %i)") % port % size << endl; + break_in(); + return 0; +} + +void Smbus::writePort(uint32_t port, uint32_t size, uint32_t value) { + cout << format("Smbus::writePort(0x%04x, %i, 0x%x)") % port % size % value << endl; + break_in(); +} diff --git a/Smbus.hpp b/Smbus.hpp new file mode 100644 index 0000000..3001958 --- /dev/null +++ b/Smbus.hpp @@ -0,0 +1,16 @@ +#pragma once +#include "Zookeeper.hpp" + +class Smbus : public Device { +public: + Smbus(); + + uint32_t readMmio(uint32_t addr); + void writeMmio(uint32_t addr, uint32_t value); + + void readPci(uint32_t reg, void *buffer, uint32_t length); + void writePci(uint32_t reg, void *buffer, uint32_t length); + + uint32_t readPort(uint32_t port, uint32_t size); + void writePort(uint32_t port, uint32_t size, uint32_t value); +}; diff --git a/Zookeeper.hpp b/Zookeeper.hpp index 613455e..d0a8abd 100644 --- a/Zookeeper.hpp +++ b/Zookeeper.hpp @@ -1,9 +1,6 @@ #pragma once #include -#include -#include -#include #include #include #include @@ -11,9 +8,9 @@ #include #include #include +#include using namespace std; using boost::format; -using namespace boost::algorithm; #define bailout(expr) do { if(expr) { cout << "Bailout: " << #expr << " @ " << __FILE__ << " (" << dec << __LINE__ << ")" << endl; exit(1); } } while(0) @@ -34,9 +31,13 @@ using namespace boost::algorithm; #include "Hypercall.hpp" #include "xbetypes.hpp" #include "Xbe.hpp" + #include "Device.hpp" #include "Cpu.hpp" #include "Gpu.hpp" +#include "Lpc.hpp" +#include "Smbus.hpp" + #include "HandleManager.hpp" #include "PageManager.hpp" #include "ThreadManager.hpp"