Driver section separation

This commit is contained in:
xamidev
2024-08-05 19:33:16 +02:00
parent 4b6beb5ba9
commit f05347f73b
7 changed files with 10 additions and 9 deletions

View File

@@ -1,142 +0,0 @@
#include "io.h"
#include "../libc/stdio.h"
#include "system.h"
#define KEYBOARD_BUFFER_SIZE 256
#define LEFT_SHIFT_PRESSED 0x2A
#define RIGHT_SHIFT_PRESSED 0x36
#define LEFT_SHIFT_RELEASED 0xAA
#define RIGHT_SHIFT_RELEASED 0xB6
unsigned char kbdus[128] =
{
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
'q', 'w', 'e', 'r', /* 19 */
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
0, /* 29 - Control */
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
'\'', '`', 0, /* Left shift */
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
'm', ',', '.', '/', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
unsigned char kbdus_shift[128] =
{
0, 27, '!', '@', '#', '$', '%', '^', '&', '*', /* 9 */
'(', ')', '_', '+', '\b', /* Backspace */
'\t', /* Tab */
'Q', 'W', 'E', 'R', /* 19 */
'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', /* Enter key */
0, /* 29 - Control */
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* 39 */
'"', '~', 0, /* Left shift */
'|', 'Z', 'X', 'C', 'V', 'B', 'N', /* 49 */
'M', '<', '>', '?', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
static char keyboard_buffer[KEYBOARD_BUFFER_SIZE];
static unsigned int keyboard_buffer_start = 0;
static unsigned int keyboard_buffer_end = 0;
static int shift_pressed = 0;
void keyboard_handler()
{
unsigned char scancode;
scancode = inb(0x60);
if (scancode & 0x80)
{
if (scancode == LEFT_SHIFT_RELEASED || scancode == RIGHT_SHIFT_RELEASED) {
shift_pressed = 0;
}
}
else
{
if (scancode == LEFT_SHIFT_PRESSED || scancode == RIGHT_SHIFT_PRESSED) {
shift_pressed = 1;
} else {
char c;
if (shift_pressed) {
c = kbdus_shift[scancode];
} else {
c = kbdus[scancode];
}
if (c)
{
keyboard_buffer[keyboard_buffer_end] = c;
keyboard_buffer_end = (keyboard_buffer_end+1) % KEYBOARD_BUFFER_SIZE;
}
}
}
}
void keyboard_install()
{
irq_install_handler(1, keyboard_handler);
}
char keyboard_getchar()
{
while (keyboard_buffer_start == keyboard_buffer_end);
char c = keyboard_buffer[keyboard_buffer_start];
keyboard_buffer_start = (keyboard_buffer_start+1) % KEYBOARD_BUFFER_SIZE;
return c;
}

View File

@@ -1,5 +1,5 @@
#include "../libc/stdio.h"
#include "serial.h"
#include "../drivers/serial.h"
#include "gdt.h"
#include "idt.h"
#include "system.h"
@@ -33,7 +33,7 @@ int kmain(int retvalue)
clear();
colorputs(ascii_title, 10);
colorputs(" by @xamidev - star the repo for a cookie!\n\n", 11);
colorputs(" by @xamidev - star the repo for a cookie!\n\n", 14);
// TODO: Grub modules to load programs

View File

@@ -1,65 +0,0 @@
#include "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");
}

View File

@@ -1,12 +0,0 @@
#ifndef INCLUDE_SERIAL_H
#define INCLUDE_SERIAL_H
#define PORT 0x3f8 //COM1
int init_serial();
int is_transmit_empty();
void write_serial(const char a);
void serial_puts(const char* str);
void log(const char* str, const int errlevel);
#endif

View File

@@ -1,21 +0,0 @@
#include "system.h"
#include "../libc/stdio.h"
volatile unsigned long global_ticks = 0;
void timer_handler()
{
global_ticks++;
}
void timer_install()
{
irq_install_handler(0, timer_handler);
}
void delay(int ticks)
{
unsigned long eticks;
eticks = global_ticks + ticks;
while (global_ticks < eticks);
}