hazel/kernel/pit.c

33 lines
850 B
C
Raw Normal View History

2024-07-02 00:46:29 -04:00
#include <kernel/kernel.h>
2024-07-01 19:28:45 -04:00
#include <kernel/pit.h>
#include <kernel/io.h>
#include <kernel/pic.h>
2024-07-02 00:46:29 -04:00
extern kernel_ctx_t ctx;
2024-07-01 19:28:45 -04:00
void pit_init(void) {
2024-07-02 15:36:47 -04:00
outb(PIT_MODE_CMD, PIT_CHAN0 | PIT_LOHIGH | PIT_MODE2);
2024-07-01 19:28:45 -04:00
2024-07-02 00:46:29 -04:00
outb(PIT_CHAN0_DATA, (uint8_t)(DIVISOR & 0xff));
2024-07-02 15:36:47 -04:00
outb(PIT_CHAN0_DATA, (uint8_t)((DIVISOR & 0xff00) >> 8));
2024-07-01 19:28:45 -04:00
}
2024-07-06 18:00:06 -04:00
extern void task_switch(task_t *task);
2024-07-01 19:28:45 -04:00
void pit_handler(void) {
2024-07-02 00:46:29 -04:00
ctx.ticks++;
2024-07-06 18:00:06 -04:00
if (ctx.current_task->next) {
LOG("TASK SWITCH\n");
//task_t *old = ctx.current_task;
//task_t *new = (task_t *)ctx.current_task->next;
//new->next = (uint32_t *)old;
//old->next = (uint32_t *)new;
task_switch((task_t *)ctx.current_task->next);
}
2024-07-02 00:46:29 -04:00
outb(PIT_CHAN0_DATA, (uint8_t)(DIVISOR & 0xff));
2024-07-02 15:36:47 -04:00
outb(PIT_CHAN0_DATA, (uint8_t)((DIVISOR & 0xff00) >> 8));
2024-07-01 19:28:45 -04:00
pic_send_eoi(0);
}