2022-10-06 06:29:13 +03:00
|
|
|
#if defined (BIOS)
|
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <drivers/serial.h>
|
|
|
|
#include <sys/cpu.h>
|
2022-08-27 00:44:47 +03:00
|
|
|
#include <lib/misc.h>
|
2022-03-01 19:53:46 +03:00
|
|
|
|
|
|
|
static bool serial_initialised = false;
|
|
|
|
|
|
|
|
static void serial_initialise(void) {
|
|
|
|
if (serial_initialised) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init com1
|
2022-03-11 07:11:09 +03:00
|
|
|
outb(0x3f8 + 3, 0x00);
|
2022-03-01 19:53:46 +03:00
|
|
|
outb(0x3f8 + 1, 0x00);
|
|
|
|
outb(0x3f8 + 3, 0x80);
|
|
|
|
outb(0x3f8 + 0, 0x0c); // 9600 baud
|
|
|
|
outb(0x3f8 + 1, 0x00);
|
|
|
|
outb(0x3f8 + 3, 0x03);
|
|
|
|
outb(0x3f8 + 2, 0xc7);
|
|
|
|
outb(0x3f8 + 4, 0x0b);
|
|
|
|
|
|
|
|
serial_initialised = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void serial_out(uint8_t b) {
|
|
|
|
serial_initialise();
|
|
|
|
|
|
|
|
while ((inb(0x3f8 + 5) & 0x20) == 0);
|
|
|
|
outb(0x3f8, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
int serial_in(void) {
|
|
|
|
serial_initialise();
|
|
|
|
|
|
|
|
if ((inb(0x3f8 + 5) & 0x01) == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return inb(0x3f8);
|
|
|
|
}
|
2022-10-06 06:29:13 +03:00
|
|
|
|
2022-03-01 19:53:46 +03:00
|
|
|
#endif
|