2023-07-23 18:13:03 -04:00
|
|
|
//! A test harness for testing the riscv library.
|
|
|
|
#include <riscv/System.hpp>
|
2023-07-21 06:32:04 -04:00
|
|
|
|
|
|
|
/// 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-21 06:32:04 -04:00
|
|
|
|
2023-07-23 18:13:03 -04:00
|
|
|
riscv::Address Base() const override { return BASE_ADDRESS; }
|
2023-07-21 06:32:04 -04:00
|
|
|
|
2023-07-23 18:13:03 -04:00
|
|
|
riscv::Address Size() const override { return 5; }
|
2023-07-21 06:32:04 -04:00
|
|
|
|
|
|
|
// TODO: emulate properly
|
2023-07-23 18:13:03 -04:00
|
|
|
u32 Peek(riscv::Address address) override {
|
2023-07-21 06:32:04 -04:00
|
|
|
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 {
|
2023-07-21 06:32:04 -04:00
|
|
|
if(address == BASE_ADDRESS) { // write to data buffer
|
|
|
|
printf("%c\n", value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2023-07-22 22:46:36 -04:00
|
|
|
|
|
|
|
int main() {
|
2023-07-23 18:13:03 -04:00
|
|
|
auto system = riscv::System::WithMemory(128 * 1024);
|
|
|
|
system->AddDeviceToBus(new SimpleUartDevice);
|
2023-07-22 22:46:36 -04:00
|
|
|
return 0;
|
|
|
|
}
|