This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
forked from riscv-software-src/riscv-isa-sim
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I tested the block against coreboot's driver for memory-mapped 8250-compatible UARTs, but most features are missing: - Any writes to other registers than the first one are silently discarded. This includes the scratch register and the interrupt-enable register. - Non-byte sized accesses are not supported - The FIFO isn't emulated. Instead every written byte is immediately printed on stdout, and the line status register always indicates that new bytes can be sent. - Input doesn't work, either.
- Loading branch information
1 parent
f5ecf65
commit 6641189
Showing
6 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "devices.h" | ||
#include <stdio.h> | ||
|
||
void bus_t::add_device(reg_t addr, abstract_device_t* dev) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* This file implements a minimal 8250 UART block. */ | ||
#include "devices.h" | ||
#include "processor.h" | ||
#include <unistd.h> | ||
|
||
enum { | ||
UART_DATA = 0, /* Data RX/TX */ | ||
UART_INTR_EN, /* Interrupt enable */ | ||
UART_INTR_ID, /* Interrupt identification */ | ||
UART_LINE_CTL, /* Line control */ | ||
UART_MODEM_CTL, /* Modem control */ | ||
UART_LINE_STAT, /* Line status */ | ||
UART_MODEM_STAT, /* Modem status */ | ||
UART_SCRATCH /* Scratch register */ | ||
}; | ||
|
||
enum { | ||
UART_LINE_STAT_THRE = (1 << 5), /* Transmitter holding register empty */ | ||
UART_LINE_STAT_TEMT = (1 << 6), /* Transmitter completely empty */ | ||
}; | ||
|
||
bool uart_t::load(reg_t addr, size_t len, uint8_t* bytes) | ||
{ | ||
/* For simplicity on our side, only support byte-sized accesses for now. */ | ||
if (len > 1) | ||
return false; | ||
|
||
switch (addr) | ||
{ | ||
case UART_LINE_STAT: | ||
*bytes = UART_LINE_STAT_TEMT | UART_LINE_STAT_THRE; | ||
break; | ||
default: | ||
*bytes = 0; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
bool uart_t::store(reg_t addr, size_t len, const uint8_t* bytes) | ||
{ | ||
if (len > 1) | ||
return false; | ||
|
||
switch (addr) | ||
{ | ||
case UART_DATA: | ||
putchar(*bytes); | ||
fflush(stdout); | ||
break; | ||
} | ||
|
||
return true; | ||
} |