AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
earlycon.c
Go to the documentation of this file.
1
5
6#include <core/system.h>
7#include <console/earlycon.h>
8#include <cpu/io.h>
9#include <platform/virt.h>
10
11/* The PL011's registers: data, and flags. */
12#define UART_DR 0x00 /* data */
13#define UART_FR 0x18 /* flags */
14#define UART_FR_TXFF (1 << 5) /* the transmit FIFO is full */
15
17
18/*
19 * Writes a character to the UART, waiting while its FIFO is full; a
20 * newline is sent as CR LF. The wait is bounded, so that a UART that
21 * never takes the character doesn't hang the kernel.
22 */
23int earlycon_putc(char c)
24{
25 if (c == '\n')
26 earlycon_putc('\r');
27
28 for (int i = 0; i < 100000 && (mmio_read32(uart + UART_FR) & UART_FR_TXFF); ++i)
29 ;
30
31 mmio_write32(uart + UART_DR, (uint8_t) c);
32 return 1;
33}
34
35/*
36 * Writes a string to the UART.
37 */
38int earlycon_puts(char *s)
39{
40 int n = 0;
41
42 while (*s)
43 n += earlycon_putc(*s++);
44
45 return n;
46}
47
48/*
49 * Says whether the early console is on the screen: it isn't, it's the
50 * serial port.
51 */
53{
54 return 0;
55}
56
57/* Sets up the early console. QEMU's PL011 needs no setup: it's on, at
58 * any speed. */
59void earlycon_init(void)
60{
61}
62
63/* Sets up the early console again, once the command line is read:
64 * nothing to do. */
66{
67}
int earlycon_putc(char c)
Writes a character on the early console.
Definition earlycon.c:23
void earlycon_reinit(void)
Sets up the early console again, once the kernel's command line has been read, since it may choose an...
Definition earlycon.c:65
#define UART_FR_TXFF
Definition earlycon.c:14
int earlycon_puts(char *s)
Writes a string on the early console.
Definition earlycon.c:38
#define UART_FR
Definition earlycon.c:13
void earlycon_init(void)
Sets up the early console at boot, before anything else.
Definition earlycon.c:59
int earlycon_on_screen(void)
Says whether the early console writes on the screen, rather than on a serial port.
Definition earlycon.c:52
#define UART_DR
Definition earlycon.c:12
__SIZE_TYPE__ uintptr_t
Definition stddef.h:12
unsigned char uint8_t
Definition stddef.h:20
A serial port.
Definition uart.h:17
#define VIRT_UART
Definition virt.h:15
#define VIRT_REG(base)
Definition virt.h:30