1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#ifdef ENABLE_PORTIO_UART
#include "jove.h"
#include "device/portio_uart.h"
#include "device/portio.h"
static void
s_set_int(ioport_t dev, uint8_t enable)
{
port_outb(PORTIO_UART_COM_IER(dev), enable);
}
static void
s_set_baud(ioport_t dev, uint16_t baud)
{
/* Enable DLAB */
port_outb(PORTIO_UART_COM_LCR(dev), PORTIO_UART_COM_LCR(dev) | 0x80);
/* Write low & high. */
port_outb(PORTIO_UART_COM_DLAB_DLL(dev), (uint8_t)(baud & 0xFF));
port_outb(PORTIO_UART_COM_DLAB_DLH(dev), (uint8_t)((baud >> 8) & 0xFF));
/* Disable DLAB */
port_outb(PORTIO_UART_COM_LCR(dev), PORTIO_UART_COM_LCR(dev) & 0x7F);
}
static void
s_set_fcr(ioport_t dev, uint8_t flg)
{
port_outb(PORTIO_UART_COM_FCR(dev), flg);
}
static void
s_set_lcr(ioport_t dev, uint8_t flg)
{
port_outb(PORTIO_UART_COM_LCR(dev), flg);
}
static void
s_set_mcr(ioport_t dev, uint8_t flg)
{
port_outb(PORTIO_UART_COM_MCR(dev), flg);
}
void
portio_uart_setup(void)
{
s_set_int(PORTIO_UART_COM1, 0);
s_set_baud(PORTIO_UART_COM1, 3);
s_set_lcr(PORTIO_UART_COM1, 1 | 2);
s_set_fcr(PORTIO_UART_COM1, 1 | 2 | 4 | 0xC0);
s_set_fcr(PORTIO_UART_COM1, 1 | 2 | 8);
s_set_mcr(PORTIO_UART_COM1, 1 | 2 | 4 | 8);
uint64_t serial_i = _initDirectory.self.data++;
_initDirectory.entries[serial_i] = (struct jove_ObjectDirectoryEntry) {
.type = KO_DEV_UART,
.data = PORTIO_UART_COM1
};
_initData.log_object = serial_i;
}
void
portio_uart_write(uint64_t dev, const char *s, int n)
{
for(int i = 0; i < n; i++) {
port_outb(dev, s[i]);
}
}
#endif
|