AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
uart.c File Reference

x86: the early console on the first serial port (COM1, port 0x3F8), polled: each character waits until the UART can take it. More...

#include <core/system.h>
#include <core/string.h>
#include <console/earlycon.h>
#include <cpu/io.h>
#include <mm/mm.h>

Go to the source code of this file.

Macros

#define UART_IER   1
#define UART_FCR   2
#define UART_LCR   3
#define UART_MCR   4
#define UART_DLL   0
#define UART_DLH   1
#define UART_LCR_DLAB   0x80

Functions

static void serial_init (void)
 Sets the UART up: no interrupts, no FIFO, 38400 baud, 8 bits, no parity, one stop bit.
static int serial_tx_empty (void)
 Returns whether the UART's transmit holding register is empty.
static int serial_chr (char chr)
 Writes a character, a newline as CR LF.
static int serial_str (char *str)
 Writes a string, and returns how many characters it wrote.
static int earlycon_uart_puts (char *s)
static int earlycon_uart_putc (char c)
static void earlycon_uart_init (void)

Variables

static struct ioaddr earlycon_uart_ioaddr
struct earlycon earlycon_uart

Detailed Description

x86: the early console on the first serial port (COM1, port 0x3F8), polled: each character waits until the UART can take it.

Definition in file uart.c.

Macro Definition Documentation

◆ UART_DLH

#define UART_DLH   1

Definition at line 22 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

◆ UART_DLL

#define UART_DLL   0

Definition at line 21 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

◆ UART_FCR

#define UART_FCR   2

Definition at line 18 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

◆ UART_IER

#define UART_IER   1

Definition at line 17 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

◆ UART_LCR

#define UART_LCR   3

Definition at line 19 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

◆ UART_LCR_DLAB

#define UART_LCR_DLAB   0x80

Definition at line 23 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

◆ UART_MCR

#define UART_MCR   4

Definition at line 20 of file uart.c.

Referenced by serial_init(), and uart_8250_comm_init().

Function Documentation

◆ earlycon_uart_init()

void earlycon_uart_init ( void )
static

Definition at line 84 of file uart.c.

References earlycon_uart_init(), serial_init(), and serial_str().

Referenced by earlycon_uart_init().

◆ earlycon_uart_putc()

int earlycon_uart_putc ( char c)
static

Definition at line 79 of file uart.c.

References earlycon_uart_putc(), and serial_chr().

Referenced by earlycon_uart_putc().

◆ earlycon_uart_puts()

int earlycon_uart_puts ( char * s)
static

Definition at line 74 of file uart.c.

References earlycon_uart_puts(), and serial_str().

Referenced by earlycon_uart_puts().

◆ serial_chr()

int serial_chr ( char chr)
static

Writes a character, a newline as CR LF.

Returns 1. The wait for the UART is bounded, so that a UART that never empties doesn't hang the kernel.

Definition at line 50 of file uart.c.

References earlycon_uart_ioaddr, io_out8(), serial_chr(), and serial_tx_empty().

Referenced by earlycon_uart_putc(), serial_chr(), and serial_str().

◆ serial_init()

void serial_init ( void )
static

Sets the UART up: no interrupts, no FIFO, 38400 baud, 8 bits, no parity, one stop bit.

Definition at line 27 of file uart.c.

References earlycon_uart_ioaddr, io_in8(), io_out8(), serial_init(), UART_DLH, UART_DLL, UART_FCR, UART_IER, UART_LCR, UART_LCR_DLAB, and UART_MCR.

Referenced by earlycon_uart_init(), and serial_init().

◆ serial_str()

int serial_str ( char * str)
static

Writes a string, and returns how many characters it wrote.

Definition at line 64 of file uart.c.

References serial_chr(), and serial_str().

Referenced by earlycon_uart_init(), earlycon_uart_puts(), and serial_str().

◆ serial_tx_empty()

int serial_tx_empty ( void )
static

Returns whether the UART's transmit holding register is empty.

Definition at line 42 of file uart.c.

References earlycon_uart_ioaddr, io_in8(), and serial_tx_empty().

Referenced by serial_chr(), and serial_tx_empty().

Variable Documentation

◆ earlycon_uart

struct earlycon earlycon_uart
Initial value:
= {
}
static int earlycon_uart_puts(char *s)
Definition uart.c:74
static int earlycon_uart_putc(char c)
Definition uart.c:79
static void earlycon_uart_init(void)
Definition uart.c:84

Definition at line 92 of file uart.c.

Referenced by earlycon_init(), earlycon_on_screen(), and earlycon_reinit().

◆ earlycon_uart_ioaddr

struct ioaddr earlycon_uart_ioaddr
static
Initial value:
= {
.addr = 0x3F8,
.type = IOADDR_PORT,
}
#define IOADDR_PORT
Definition io.h:89

Definition at line 12 of file uart.c.

Referenced by serial_chr(), serial_init(), and serial_tx_empty().