gmod-lcpu/native/projects/riscv_test_harness/main.cpp

36 lines
812 B
C++
Raw Normal View History

2023-07-23 18:13:03 -04:00
//! A test harness for testing the riscv library.
#include <riscv/System.hpp>
/// simple 16550 UART implementation
struct SimpleUartDevice : public riscv::Bus::MmioDevice {
2023-07-23 18:13:03 -04:00
constexpr static riscv::Address BASE_ADDRESS = 0x10000000;
2023-07-23 18:13:03 -04:00
riscv::Address Base() const override { return BASE_ADDRESS; }
2023-07-23 18:13:03 -04:00
riscv::Address Size() const override { return 5; }
// TODO: emulate properly
2023-07-23 18:13:03 -04:00
u32 Peek(riscv::Address address) override {
switch(address) {
case BASE_ADDRESS:
break;
case BASE_ADDRESS + 5:
break;
}
return 0;
}
2023-07-23 18:13:03 -04:00
void Poke(riscv::Address address, u32 value) override {
if(address == BASE_ADDRESS) { // write to data buffer
printf("%c\n", value);
}
}
};
int main() {
2023-07-23 18:13:03 -04:00
auto system = riscv::System::WithMemory(128 * 1024);
system->AddDeviceToBus(new SimpleUartDevice);
return 0;
}