x86_64: add temporary serial driver for printk
This commit is contained in:
17
arch/x86_64/include/arch/serial.h
Normal file
17
arch/x86_64/include/arch/serial.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef ARCH_SERIAL_H_
|
||||||
|
#define ARCH_SERIAL_H_
|
||||||
|
|
||||||
|
#define SERIAL_PORT_A 0x3F8
|
||||||
|
#define SERIAL_PORT_B 0x2F8
|
||||||
|
#define SERIAL_PORT_C 0x3E8
|
||||||
|
#define SERIAL_PORT_D 0x2E8
|
||||||
|
|
||||||
|
extern void serial_putchar(int port, char ch);
|
||||||
|
|
||||||
|
extern void serial_wait(int device);
|
||||||
|
extern void serial_send_byte(int device, char out);
|
||||||
|
extern char serial_recv_byte(int device);
|
||||||
|
|
||||||
|
extern int serial_rcvd(int device);
|
||||||
|
|
||||||
|
#endif
|
||||||
30
arch/x86_64/serial.c
Normal file
30
arch/x86_64/serial.c
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#include <arch/serial.h>
|
||||||
|
#include <arch/ports.h>
|
||||||
|
|
||||||
|
static int transmit_empty(int device)
|
||||||
|
{
|
||||||
|
return inportb(device + 5) & 0x20;
|
||||||
|
}
|
||||||
|
|
||||||
|
void serial_send_byte(int device, char out)
|
||||||
|
{
|
||||||
|
unsigned int _count = 0;
|
||||||
|
while (!transmit_empty(device)) {
|
||||||
|
_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
outportb(device, out);
|
||||||
|
|
||||||
|
while (!transmit_empty(device)) {
|
||||||
|
_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void serial_putchar(int port, char ch)
|
||||||
|
{
|
||||||
|
if (ch == '\n') {
|
||||||
|
serial_send_byte(port, '\r');
|
||||||
|
}
|
||||||
|
|
||||||
|
serial_send_byte(port, ch);
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <arch/serial.h>
|
||||||
#include <socks/libc/string.h>
|
#include <socks/libc/string.h>
|
||||||
#include <socks/libc/ctype.h>
|
#include <socks/libc/ctype.h>
|
||||||
#include <arch/ports.h>
|
#include <arch/ports.h>
|
||||||
@@ -75,6 +76,8 @@ static void handle_ctrl(int c)
|
|||||||
|
|
||||||
static void vgacon_putchar(int c)
|
static void vgacon_putchar(int c)
|
||||||
{
|
{
|
||||||
|
serial_putchar(SERIAL_PORT_A, c);
|
||||||
|
|
||||||
if (iscntrl(c)) {
|
if (iscntrl(c)) {
|
||||||
handle_ctrl(c);
|
handle_ctrl(c);
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user