Squash commits for public release
This commit is contained in:
61
boot/x86_64/prekernel/drivers/port.h
Normal file
61
boot/x86_64/prekernel/drivers/port.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef _BOOT_DRIVERS_PORT_H
|
||||
#define _BOOT_DRIVERS_PORT_H
|
||||
|
||||
#include <libboot/types.h>
|
||||
|
||||
static inline uint8_t port_read8(uint16_t port)
|
||||
{
|
||||
uint8_t result_data;
|
||||
asm volatile("inb %%dx, %%al"
|
||||
: "=a"(result_data)
|
||||
: "d"(port));
|
||||
return result_data;
|
||||
}
|
||||
|
||||
static inline void port_write8(uint16_t port, uint8_t data)
|
||||
{
|
||||
asm volatile("outb %%al, %%dx"
|
||||
:
|
||||
: "a"(data), "d"(port));
|
||||
}
|
||||
|
||||
static inline uint16_t port_read16(uint16_t port)
|
||||
{
|
||||
uint16_t result_data;
|
||||
asm volatile("inw %%dx, %%ax"
|
||||
: "=a"(result_data)
|
||||
: "d"(port));
|
||||
return result_data;
|
||||
}
|
||||
|
||||
static inline void port_write16(uint16_t port, uint16_t data)
|
||||
{
|
||||
asm volatile("outw %%ax, %%dx"
|
||||
:
|
||||
: "a"(data), "d"(port));
|
||||
}
|
||||
|
||||
static inline uint32_t port_read32(uint16_t port)
|
||||
{
|
||||
uint32_t result_data;
|
||||
asm volatile("inl %%dx, %%eax"
|
||||
: "=a"(result_data)
|
||||
: "d"(port));
|
||||
return result_data;
|
||||
}
|
||||
|
||||
static inline void port_write32(uint16_t port, uint32_t data)
|
||||
{
|
||||
asm volatile("outl %%eax, %%dx"
|
||||
:
|
||||
: "a"(data), "d"(port));
|
||||
}
|
||||
|
||||
static inline void port_wait_io()
|
||||
{
|
||||
asm volatile("out %%al, $0x80"
|
||||
:
|
||||
: "a"(0));
|
||||
}
|
||||
|
||||
#endif // _BOOT_DRIVERS_PORT_H
|
||||
43
boot/x86_64/prekernel/drivers/uart.c
Normal file
43
boot/x86_64/prekernel/drivers/uart.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "uart.h"
|
||||
#include "port.h"
|
||||
|
||||
static int _uart_setup_impl(int port)
|
||||
{
|
||||
port_write8(port + 1, 0x00);
|
||||
port_write8(port + 3, 0x80);
|
||||
port_write8(port + 0, 0x03);
|
||||
port_write8(port + 1, 0x00);
|
||||
port_write8(port + 3, 0x03);
|
||||
port_write8(port + 2, 0xC7);
|
||||
port_write8(port + 4, 0x0B);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void uart_init()
|
||||
{
|
||||
_uart_setup_impl(COM1);
|
||||
}
|
||||
|
||||
static inline bool _uart_is_free_in(int port)
|
||||
{
|
||||
return port_read8(port + 5) & 0x01;
|
||||
}
|
||||
|
||||
static inline bool _uart_is_free_out(int port)
|
||||
{
|
||||
return port_read8(port + 5) & 0x20;
|
||||
}
|
||||
|
||||
int uart_write(uint8_t data)
|
||||
{
|
||||
while (!_uart_is_free_out(COM1)) { }
|
||||
port_write8(COM1, data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uart_read(uint8_t* data)
|
||||
{
|
||||
while (!_uart_is_free_out(COM1)) { }
|
||||
*data = port_read8(COM1);
|
||||
return 0;
|
||||
}
|
||||
15
boot/x86_64/prekernel/drivers/uart.h
Normal file
15
boot/x86_64/prekernel/drivers/uart.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _BOOT_DRIVERS_UART_H
|
||||
#define _BOOT_DRIVERS_UART_H
|
||||
|
||||
#include <libboot/types.h>
|
||||
|
||||
#define COM1 0x3F8
|
||||
#define COM2 0x2F8
|
||||
#define COM3 0x3E8
|
||||
#define COM4 0x2E8
|
||||
|
||||
void uart_init();
|
||||
int uart_write(uint8_t data);
|
||||
int uart_read(uint8_t* data);
|
||||
|
||||
#endif //_BOOT_DRIVERS_UART_H
|
||||
Reference in New Issue
Block a user