From 66289aa8ecfa07b20bad424eb9860b196641ef52 Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Fri, 19 Mar 2021 10:54:25 -0500 Subject: first commit --- src/kernel/libs/drivers/serial.c | 43 ++++++++++++++++++++++++++++++++++++++++ src/kernel/libs/drivers/video.c | 6 ++++++ 2 files changed, 49 insertions(+) create mode 100644 src/kernel/libs/drivers/serial.c create mode 100644 src/kernel/libs/drivers/video.c (limited to 'src/kernel/libs/drivers') diff --git a/src/kernel/libs/drivers/serial.c b/src/kernel/libs/drivers/serial.c new file mode 100644 index 0000000..665f06c --- /dev/null +++ b/src/kernel/libs/drivers/serial.c @@ -0,0 +1,43 @@ +#include +#include +//you can add more options if you need to later +// PORT + 3: values are from bit zero (right) to left +// dlab(1) | misteryyy bone(1) | paraty(3) | stop bits (1) | character length (2) +static inline void outb(uint16_t port, uint8_t value) { + //here "a" is the a register, and "Nd" is inteter (I think?) in the d register + asm volatile( + "outb %0, %1" :: "a"(value), "Nd"(port) + ); +} + +static inline uint8_t inb(uint16_t port) { + uint8_t ret; + asm volatile( + "inb %1, %0" : "=a"(ret) : "Nd"(port) + ); + return(ret); +} + +int init_serial(uint16_t port) { + outb(port + 1, 0x00); // disable them fuckin interupts + outb(port + 3, 0x80); // sets dlab, allowing custom serial speeds + outb(port + 0, 0x06); // speed is 115200/6 + outb(port + 1, 0x00); + outb(port + 3, 0x03); // disables dlab, as well as 8 bit char len, 1 stop bit, no paraty, no mystery + outb(port + 2, 0xc7); // I have no fucking clue what this means + outb(port + 4, 0x0b); // don't know what this means eather... delete if you can + outb(port + 4, 0x1e); // loopback mode (where the hell is this documented????) + + outb(port + 0, 0xae); // test char + + if(inb(port + 0) != 0xae) + return 1; + + outb(port + 4, 0x0f); // dissable interupts + return 0; +} + +void _putchar_serial(uint16_t port, char msg) { + while(!(inb(port + 5) & 0x20)); //wait for transmit to be doneroni + outb(port, msg); +} diff --git a/src/kernel/libs/drivers/video.c b/src/kernel/libs/drivers/video.c new file mode 100644 index 0000000..9bb4187 --- /dev/null +++ b/src/kernel/libs/drivers/video.c @@ -0,0 +1,6 @@ +#include +#include +void dump_video() { + struct mode_info *video = (struct mode_info *)0x600; + printf("Video info:\nx:\t%u\ny:\t%u\nbbp:\t%u\nloc:\t0x%p\n", video->width, video->height, video->bpp, video->framebuffer); +} -- cgit v1.2.3