Driver section separation
This commit is contained in:
65
src/drivers/serial.c
Normal file
65
src/drivers/serial.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include "../kernel/io.h"
|
||||
#include "serial.h"
|
||||
|
||||
int init_serial()
|
||||
{
|
||||
outb(PORT+1, 0x00);
|
||||
outb(PORT+3, 0x80);
|
||||
outb(PORT+0, 0x03);
|
||||
outb(PORT+1, 0x00);
|
||||
|
||||
outb(PORT+3, 0x03);
|
||||
outb(PORT+2, 0xC7);
|
||||
outb(PORT+4, 0x0B);
|
||||
outb(PORT+4, 0x1E);
|
||||
outb(PORT+0, 0xAE);
|
||||
|
||||
if (inb(PORT+0) != 0xAE) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
outb(PORT+4, 0x0F);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int is_transmit_empty()
|
||||
{
|
||||
return inb(PORT+5) & 0x20;
|
||||
}
|
||||
|
||||
void write_serial(const char a)
|
||||
{
|
||||
while (is_transmit_empty() == 0);
|
||||
outb(PORT, a);
|
||||
}
|
||||
|
||||
void serial_puts(const char* str)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
write_serial(str[0]); // Transmit first byte 2 times
|
||||
while (*str++)
|
||||
{
|
||||
write_serial(str[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void log(const char* str, const int errlevel)
|
||||
{
|
||||
switch (errlevel)
|
||||
{
|
||||
case 0:
|
||||
serial_puts("[ERROR] ");
|
||||
break;
|
||||
case 1:
|
||||
serial_puts("[WARNING] ");
|
||||
break;
|
||||
case 2:
|
||||
serial_puts("[INFO] ");
|
||||
break;
|
||||
case 3:
|
||||
serial_puts("[DEBUG] ");
|
||||
break;
|
||||
}
|
||||
serial_puts(str);
|
||||
serial_puts("\n");
|
||||
}
|
||||
Reference in New Issue
Block a user