minos/common/console.c
Шурупов Илья Викторович 775a02cf3f Add D1/Lichee RV hardware boot and UART input
Bring up minos on the Allwinner D1 (Lichee RV) over FEL/xfel and add
bidirectional UART so the console can read keystrokes, not just print.

D1 / Lichee RV boot:
- riscv arch.c: select UART0 base by -DBOARD_D1 (0x02500000 vs QEMU
  0x10000000) and add a reg-shift abstraction (uart_rd/uart_wr): the D1's
  Synopsys DW-8250 uses 32-bit registers at 4-byte spacing, which is what
  made the first hardware boot silent.
- d1_uart0_init(): gate/deassert UART0 clock, mux PB8/PB9 to UART0, set
  115200 8N1, clear FIFOs, force non-loopback, drain stale RX.
- link-d1.ld: link for DRAM at 0x40000000 (xfel exec target, M-mode).
- Makefile: 'lichee' builds the flat binary; 'run-lichee' loads it via
  xfel (ddr d1 / write / exec).
- arch_name() reports the concrete board.

UART input (all archs):
- arch contract gains arch_uart_getc() and arch_uart_rx_ready(),
  implemented for riscv, x86 (COM1) and arm (Cadence UART).
- console gains getc() and drain_rx().
- kmain() runs an interactive echo loop (seed of the M3 console).

Verified: echo works under QEMU on x86/riscv/arm, and on real D1
hardware (banner once, then live keystroke echo over UART0 @115200).
2026-09-25 21:13:59 +03:00

42 lines
976 B
C

/* console.c — portable text output built on arch_uart_putc().
* No libc: we implement the tiny bit of formatting we need. */
#include "arch.h"
#include "console.h"
void putc(char c)
{
if (c == '\n')
arch_uart_putc('\r'); /* CRLF for dumb terminals */
arch_uart_putc(c);
}
void puts(const char *s)
{
while (*s)
putc(*s++);
}
/* Read one byte from the UART. Portable wrapper over arch_uart_getc(). */
char getc(void)
{
return arch_uart_getc();
}
/* Discard any bytes currently waiting in the RX FIFO. Used to drop the
* bytes our own TX echoes back on half-duplex-wired boards before we start
* reading real keystrokes. */
void drain_rx(void)
{
while (arch_uart_rx_ready())
(void)arch_uart_getc();
}
/* Minimal unsigned hex printer — enough to show addresses/registers. */
void puthex(unsigned long v)
{
static const char d[] = "0123456789abcdef";
int i;
puts("0x");
for (i = (int)(sizeof(v) * 2) - 1; i >= 0; i--)
putc(d[(v >> (i * 4)) & 0xf]);
}