summaryrefslogtreecommitdiff
path: root/kernel/src/devices
diff options
context:
space:
mode:
authorAleksa Vuckovic <aleksa@vuckovic.cc>2023-02-25 06:56:01 +0100
committerAleksa Vuckovic <aleksa@vuckovic.cc>2023-02-25 08:45:09 +0100
commit239900af293f192931391dc5579afab39a43e6c6 (patch)
tree72d7f87ee6adf5aa84b78436197e03e61fba8d97 /kernel/src/devices
parentaaa23fffd02fb49cdbc56a480dbb5a8fa95bff38 (diff)
clang-format
Diffstat (limited to 'kernel/src/devices')
-rw-r--r--kernel/src/devices/disc.c11
-rw-r--r--kernel/src/devices/keyboard.c36
-rw-r--r--kernel/src/devices/serial.c20
-rw-r--r--kernel/src/devices/timer.c9
4 files changed, 42 insertions, 34 deletions
diff --git a/kernel/src/devices/disc.c b/kernel/src/devices/disc.c
index b378fc1..75ed1ef 100644
--- a/kernel/src/devices/disc.c
+++ b/kernel/src/devices/disc.c
@@ -4,25 +4,24 @@
#include <paging.h>
#include <libk/math.h>
#include <kernel_vma.h>
+#include <libk/stdio.h>
-#include <libk/serial_stdio.h>
-
-disc_sector_t* disc;
+disc_sector_t *disc;
void disc_init()
{
- disc = (disc_sector_t*)((uint64_t)ext2_module->mod_start + KERNEL_VMA);
+ disc = (disc_sector_t *)((uint64_t)ext2_module->mod_start + KERNEL_VMA);
if (disc == NULL) {
printf("Error opening disc\n");
}
}
-void read_sector(size_t sector_num, disc_sector_t* disc_sector)
+void read_sector(size_t sector_num, disc_sector_t *disc_sector)
{
memcpy(disc_sector, disc + sector_num, SECTOR_SIZE);
}
-void write_sector(size_t sector_num, disc_sector_t* disc_sector)
+void write_sector(size_t sector_num, disc_sector_t *disc_sector)
{
memcpy(disc + sector_num, disc_sector, SECTOR_SIZE);
}
diff --git a/kernel/src/devices/keyboard.c b/kernel/src/devices/keyboard.c
index 549a0ca..67c2f19 100644
--- a/kernel/src/devices/keyboard.c
+++ b/kernel/src/devices/keyboard.c
@@ -7,23 +7,23 @@
#include <libk/stdio.h>
#include <libk/math.h>
#include <libk/string.h>
+#include <stdbuff.h>
+#include <heap.h>
bool is_pressed[128];
-#include <stdbuff.h>
-#include <heap.h>
#define BUFFER_SIZE 10000
-stdbuff* keyboard_buffer;
+stdbuff *keyboard_buffer;
void init_keyboard()
{
-// outb(KEYBOARD_CMD_PORT, 0xF3);
-// io_wait();
-// outb(KEYBOARD_DATA_PORT, 0x00);
-// io_wait();
-// while (!(inb(KEYBOARD_STATUS_PORT) & 1)) {}
-// if (inb(KEYBOARD_DATA_PORT) == 0xFA)
-// printf("[keyboard init]\n");
+ // outb(KEYBOARD_CMD_PORT, 0xF3);
+ // io_wait();
+ // outb(KEYBOARD_DATA_PORT, 0x00);
+ // io_wait();
+ // while (!(inb(KEYBOARD_STATUS_PORT) & 1)) {}
+ // if (inb(KEYBOARD_DATA_PORT) == 0xFA)
+ // printf("[keyboard init]\n");
}
void keyboard_handler()
@@ -48,13 +48,14 @@ void keyboard_handler()
if (main_fb.x != 0)
write_buff(keyboard_buffer, "\b \b", 3);
} else if (keycode == KEY_ENTER) {
- char* output = kalloc(sizeof(char) + 1);
+ char *output = kalloc(sizeof(char) + 1);
output[0] = keymap[keycode];
write_buff(keyboard_buffer, output, 1);
kfree(output);
} else {
- char* output = kalloc(sizeof(char) + 1);
- if (keymap[keycode] == ' ') return;
+ char *output = kalloc(sizeof(char) + 1);
+ if (keymap[keycode] == ' ')
+ return;
if (is_pressed[KEY_LSHIFT] || is_pressed[KEY_RSHIFT])
output[0] = shift_keymap[keycode];
else
@@ -66,8 +67,13 @@ void keyboard_handler()
is_pressed[keycode - 128] = false;
}
- uint32_t len = (uint32_t)(keyboard_buffer->head >= keyboard_buffer->tail ? keyboard_buffer->head - keyboard_buffer->tail : BUFFER_SIZE + keyboard_buffer->head - keyboard_buffer->tail);
- char* print_buff = kalloc(len + 1);
+ uint32_t len =
+ (uint32_t)(keyboard_buffer->head >= keyboard_buffer->tail ?
+ keyboard_buffer->head -
+ keyboard_buffer->tail :
+ BUFFER_SIZE + keyboard_buffer->head -
+ keyboard_buffer->tail);
+ char *print_buff = kalloc(len + 1);
read_buff(keyboard_buffer, print_buff, len);
printf("%s", print_buff);
kfree(print_buff);
diff --git a/kernel/src/devices/serial.c b/kernel/src/devices/serial.c
index 76bc71a..2d2da51 100644
--- a/kernel/src/devices/serial.c
+++ b/kernel/src/devices/serial.c
@@ -3,13 +3,13 @@
void init_serial()
{
- 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 (lo byte) 38400 baud
- outb(PORT + 1, 0x00); // (hi 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 + 1, 0x00); // Disable all interrupts
+ outb(PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
+ outb(PORT + 0, 0x03); // Set divisor to 3 (lo byte) 38400 baud
+ outb(PORT + 1, 0x00); // (hi 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
}
uint8_t serial_received()
@@ -19,7 +19,8 @@ uint8_t serial_received()
char read_serial()
{
- while (serial_received() == 0);
+ while (serial_received() == 0)
+ ;
return (char)inb(PORT);
}
@@ -31,7 +32,8 @@ uint8_t is_transmit_empty()
void write_serial(char c)
{
- while (is_transmit_empty() == 0);
+ while (is_transmit_empty() == 0)
+ ;
outb(PORT, (uint8_t)c);
}
diff --git a/kernel/src/devices/timer.c b/kernel/src/devices/timer.c
index c2fa887..f6463ab 100644
--- a/kernel/src/devices/timer.c
+++ b/kernel/src/devices/timer.c
@@ -18,7 +18,7 @@ wait_queue timer_queue;
void timer_handler()
{
- wait_queue* pos;
+ wait_queue *pos;
list_for_each_entry(pos, (&timer_queue.list), list) {
pos->ticks--;
}
@@ -33,12 +33,13 @@ void timer_handler()
void wait(uint64_t ms)
{
disable_interrupts();
- wait_queue* queue = (wait_queue*)kalloc(sizeof(wait_queue));
+ wait_queue *queue = (wait_queue *)kalloc(sizeof(wait_queue));
queue->ticks = (int64_t)ms;
add_to_list(&queue->list, &timer_queue.list, timer_queue.list.next);
enable_interrupts();
- while (queue->ticks > 0) ;
+ while (queue->ticks > 0)
+ ;
kfree(queue);
free_node(&queue->list);
@@ -52,7 +53,7 @@ void init_timer(uint32_t frequency)
outb(0x43, 0x36);
uint8_t l = (uint8_t)(divisor & 0xFF);
- uint8_t h = (uint8_t)((divisor>>8) & 0xFF);
+ uint8_t h = (uint8_t)((divisor >> 8) & 0xFF);
outb(0x40, l);
outb(0x40, h);