Serial comm kernel process
This commit is contained in:
@ -2,17 +2,12 @@
|
||||
#include <stdbool.h>
|
||||
#include "hal/hal.h"
|
||||
#include "kprintf.h"
|
||||
#include "serial.h"
|
||||
#include "gdt.h"
|
||||
#include "intr.h"
|
||||
#include "pic.h"
|
||||
#include "pit.h"
|
||||
|
||||
void hal_init(void) {
|
||||
if (!serial_init()) {
|
||||
hal_hang(); // going further makes no sense
|
||||
}
|
||||
LOG("hal", "serial init\n");
|
||||
gdt_init();
|
||||
intr_init();
|
||||
pic_init();
|
||||
|
@ -1,51 +0,0 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "io.h"
|
||||
#include "putchar.h"
|
||||
|
||||
#define SERIAL_PORT 0x3f8
|
||||
|
||||
static int serial_received(void) {
|
||||
return io_in8(SERIAL_PORT + 5) & 1;
|
||||
}
|
||||
|
||||
static uint8_t serial_read(void) {
|
||||
while (serial_received() == 0);
|
||||
return io_in8(SERIAL_PORT);
|
||||
}
|
||||
|
||||
static int serial_trans_empty(void) {
|
||||
return io_in8(SERIAL_PORT + 5) & 0x20;
|
||||
}
|
||||
|
||||
static void serial_write(uint8_t value) {
|
||||
while (!serial_trans_empty());
|
||||
io_out8(SERIAL_PORT, value);
|
||||
}
|
||||
|
||||
// REFERENCE: https://wiki.osdev.org/Serial_Ports
|
||||
bool serial_init(void) {
|
||||
io_out8(SERIAL_PORT + 1, 0x00);
|
||||
io_out8(SERIAL_PORT + 3, 0x80);
|
||||
io_out8(SERIAL_PORT + 0, 0x03);
|
||||
io_out8(SERIAL_PORT + 1, 0x00);
|
||||
io_out8(SERIAL_PORT + 3, 0x03);
|
||||
io_out8(SERIAL_PORT + 2, 0xc7);
|
||||
io_out8(SERIAL_PORT + 4, 0x0b);
|
||||
io_out8(SERIAL_PORT + 4, 0x1e);
|
||||
io_out8(SERIAL_PORT + 0, 0xae);
|
||||
|
||||
if (io_in8(SERIAL_PORT + 0) != 0xae) {
|
||||
return false;
|
||||
}
|
||||
|
||||
io_out8(SERIAL_PORT + 4, 0x0f);
|
||||
return true;
|
||||
}
|
||||
|
||||
#if PUTCHAR_ == PUTCHAR_SERIAL
|
||||
// For printf library
|
||||
void putchar_(char c) {
|
||||
serial_write(c);
|
||||
}
|
||||
#endif
|
@ -1,8 +0,0 @@
|
||||
#ifndef HAL_SERIAL_H_
|
||||
#define HAL_SERIAL_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool serial_init(void);
|
||||
|
||||
#endif // HAL_SERIAL_H_
|
Reference in New Issue
Block a user