Added ports/serial.h header for serial console stuff

This commit is contained in:
2024-10-09 16:50:56 +02:00
parent 95d32f025a
commit 4ee3940807
5 changed files with 80 additions and 4 deletions
+24
View File
@@ -0,0 +1,24 @@
#ifndef PORTS_SERIAL_H
#define PORTS_SERIAL_H
#include <stdint.h>
#define PORT_COM1 0x3f8
#define PORT_COM2 0x2f8
#define PORT_COM3 0x3e8
#define PORT_COM4 0x2e8
#define PORT_COM5 0x5f8
#define PORT_COM6 0x4f8
#define PORT_COM7 0x5e8
#define PORT_COM8 0x4e8
int setupSerial(uint32_t port);
int serialTransmitEmpty(uint32_t port);
int serialRecieved(uint32_t port);
void serialWrite(uint32_t port, char c);
void serialPrint(uint32_t port, char* s);
char serialRead(uint32_t port);
#endif
BIN
View File
Binary file not shown.
+46
View File
@@ -0,0 +1,46 @@
#include <ports/serial.h>
#include <ports/io.h>
#include <stdint.h>
int setupSerial(uint32_t port) {
outb(port + 1, 0x00); // Disable all interrupts
outb(port + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(port + 0, 0x03); // Set divisor to 3 (low byte) 38400 baud
outb(port + 1, 0x00); // (high byte)
outb(port + 3, 0x03); // 8 bits, no parity, one stop bit
outb(port + 2, 0xC7); // Enable FIFO, clear them, with 14 byte threshold
outb(port + 4, 0x0B); // IRQs enabled, RTS/DSR set
outb(port + 4, 0x1E); // Set in loopback mode, test the serial chip
outb(port + 0, 0xAE); // Test serial chip (send byte 0xAE and check if it returns)
if (inb(port + 0) != 0xAE) return 1;
outb(port + 4, 0x0F); // non-loopback, IRQs enabled, OUT#1 and OUT#2 bits enabled
return 0;
}
int serialTransmitEmpty(uint32_t port) {
return inb(port + 5) & 0x20;
}
int serialRecieved(uint32_t port) {
return inb(port + 5) & 0x01;
}
void serialWrite(uint32_t port, char c) {
while (serialTransmitEmpty(port) == 0);
outb(port, c);
}
void serialPrint(uint32_t port, char* s) {
while (*s != '\0') {
if (*s == '\n') serialWrite(port, '\r');
serialWrite(port, *s++);
}
}
char serialRead(uint32_t port) {
while (serialRecieved(port));
return inb(port);
}
+6
View File
@@ -19,6 +19,7 @@
#include <sound/pcspk.h>
#include <sound/notes.h>
#include <ports/io.h>
#include <ports/serial.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -56,6 +57,11 @@ void main() {
setupTimer();
setupRtc();
setupKeyboard();
if (setupSerial(PORT_COM1) != 0) { printf("\e[1MFailed to initialize serial interface\e[8M\n"); }
else {
serialPrint(PORT_COM1, "\x1b[H\x1b[J");
serialPrint(PORT_COM1, "kern. \x1b[36m(Serial console)\x1b[0m\n\n");
}
// Setup kernel malloc variables
mallocNode_t* kernelMallocListHead = 0;
+4 -4
View File
@@ -15,12 +15,12 @@ Legend:
- [ ] system root
- [ ] arch/
- [ ] lib/
- [ ] include/
- [x] include/
- [ ] cross compiler setup
- [ ] libc - User space
- [ ] libk - Kernel libc
- [x] libc - User space
- [x] libk - Kernel libc
- [ ] kernel
- [ ] use libk
- [x] use libk
- [ ] makefile
- [ ] probably a full rewrite
- [ ] userspace