diff --git a/src/devices/uart/uart.c b/src/devices/uart/uart.c new file mode 100644 index 0000000..c5e6dc8 --- /dev/null +++ b/src/devices/uart/uart.c @@ -0,0 +1,26 @@ +#include "uart.h" +#include "memory/memory.h" +#include + +#define UART_ADDRESS 0x3000000 +#define UART_REGISTER_SIZE 4 +#define UART_REGISTER_COUNT 1 +#define UART_REG_TXFIFO 0x0 + +void uart_handle_mmio_write(uint32_t address, uint8_t value); +uint32_t uart_handle_mmio_read(uint32_t address); + +void uart_init() +{ + mem_register_mmio(UART_ADDRESS, UART_REGISTER_SIZE, UART_REGISTER_COUNT, uart_handle_mmio_write, uart_handle_mmio_read); +} + +void uart_handle_mmio_write(uint32_t address, uint8_t value) +{ + printf("%c", value); +} + +uint32_t uart_handle_mmio_read(uint32_t address) +{ + return 0; +} diff --git a/src/devices/uart/uart.h b/src/devices/uart/uart.h new file mode 100644 index 0000000..f232703 --- /dev/null +++ b/src/devices/uart/uart.h @@ -0,0 +1,6 @@ +#ifndef UART_H +#define UART_H + +void uart_init(); + +#endif diff --git a/src/main.c b/src/main.c index 1aa8008..3ac7c9d 100644 --- a/src/main.c +++ b/src/main.c @@ -3,6 +3,7 @@ #include "bootloader/bootloader.h" #include "cpu/rv32cpu.h" #include "gdbstub/gdbstub.h" +#include "devices/uart/uart.h" char* CURRENT_NAME; @@ -14,6 +15,9 @@ int main(int argc, char** argv) // Initialize the memory mem_init(); + // Initialize UART (memory-mapped) + uart_init(); + // Bootload the file passed as argument uint32_t entry_point = bootload(file_path);