AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
16
static
uintptr_t
uart
=
VIRT_REG
(
VIRT_UART
);
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
*/
23
int
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
*/
38
int
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
*/
52
int
earlycon_on_screen
(
void
)
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. */
59
void
earlycon_init
(
void
)
60
{
61
}
62
63
/* Sets up the early console again, once the command line is read:
64
* nothing to do. */
65
void
earlycon_reinit
(
void
)
66
{
67
}
earlycon_putc
int earlycon_putc(char c)
Writes a character on the early console.
Definition
earlycon.c:23
earlycon_reinit
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
UART_FR_TXFF
#define UART_FR_TXFF
Definition
earlycon.c:14
earlycon_puts
int earlycon_puts(char *s)
Writes a string on the early console.
Definition
earlycon.c:38
UART_FR
#define UART_FR
Definition
earlycon.c:13
earlycon_init
void earlycon_init(void)
Sets up the early console at boot, before anything else.
Definition
earlycon.c:59
earlycon_on_screen
int earlycon_on_screen(void)
Says whether the early console writes on the screen, rather than on a serial port.
Definition
earlycon.c:52
UART_DR
#define UART_DR
Definition
earlycon.c:12
earlycon.h
system.h
io.h
uintptr_t
__SIZE_TYPE__ uintptr_t
Definition
stddef.h:12
uint8_t
unsigned char uint8_t
Definition
stddef.h:20
uart
A serial port.
Definition
uart.h:17
virt.h
VIRT_UART
#define VIRT_UART
Definition
virt.h:15
VIRT_REG
#define VIRT_REG(base)
Definition
virt.h:30
kernel
arch
aarch64
earlycon
earlycon.c
Generated by
1.18.0