pit and kernel ticks
This commit is contained in:
parent
37019a53ea
commit
57a6d51e68
1
Makefile
1
Makefile
|
@ -20,7 +20,6 @@ ISO := Hazel.iso
|
|||
CFLAGS := -ffreestanding -Wall -Wextra -Werror -I $(INCLUDEDIR) -I lib
|
||||
LDFLAGS := -ffreestanding -nostdlib -lgcc -T kernel/kernel.ld
|
||||
QEMUFLAGS := -cdrom $(BUILDDIR)/$(ISO) \
|
||||
-d int \
|
||||
-serial stdio
|
||||
|
||||
$(BUILDDIR)/$(KIMG): $(KOBJ) $(LOBJ)
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef struct {
|
|||
multiboot_memory_map_t *mem_map;
|
||||
uint32_t mem_map_len;
|
||||
log_method_t log_method;
|
||||
uint64_t ticks;
|
||||
} kernel_ctx_t;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
#define PIT_LOHIGH (3<<4)
|
||||
#define PIT_CHAN0 0
|
||||
|
||||
#define PIT_FREQUENCY 1193182
|
||||
#define DESIRED_FREQUENCY 100
|
||||
#define DIVISOR (PIT_FREQUENCY/DESIRED_FREQUENCY)
|
||||
|
||||
void pit_init(void);
|
||||
void pit_handler(void);
|
||||
|
||||
|
|
|
@ -19,6 +19,12 @@ void exception_handler(int_stack_frame_t r) {
|
|||
r.eip, r.cs, r.eflags);
|
||||
}
|
||||
|
||||
void sleep(int delay) {
|
||||
uint64_t end = ctx.ticks + delay;
|
||||
while (ctx.ticks < end)
|
||||
cpu_relax;
|
||||
}
|
||||
|
||||
void kernel(multiboot_info_t *info) {
|
||||
if (!CHECK_FLAG(info->flags, 6)) goto halt; // Memory map
|
||||
if (!CHECK_FLAG(info->flags, 12)) goto halt; // VBE data
|
||||
|
@ -41,8 +47,9 @@ void kernel(multiboot_info_t *info) {
|
|||
pic_remap(PIC_1_START, PIC_2_START);
|
||||
asm volatile ("sti" ::);
|
||||
|
||||
ctx.ticks = 0;
|
||||
pit_init();
|
||||
|
||||
halt:
|
||||
asm volatile ("cli" ::);
|
||||
for (;;) {}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,6 @@ void pic_remap(int pic1_start, int pic2_start) {
|
|||
outb(PIC_2_DATA, 0x01);
|
||||
|
||||
// Unmask
|
||||
//outb(PIC_1_DATA, 0b11111101);
|
||||
//outb(PIC_2_DATA, 0b11111101);
|
||||
outb(PIC_1_DATA, 0b11111110);
|
||||
outb(PIC_2_DATA, 0b11111110);
|
||||
}
|
||||
|
|
13
kernel/pit.c
13
kernel/pit.c
|
@ -1,14 +1,19 @@
|
|||
#include <kernel/kernel.h>
|
||||
#include <kernel/pit.h>
|
||||
#include <kernel/io.h>
|
||||
#include <kernel/pic.h>
|
||||
|
||||
void pit_init(void) {
|
||||
outb(PIT_MODE_CMD, PIT_CHAN0 | PIT_LOHIGH | PIT_MODE0);
|
||||
extern kernel_ctx_t ctx;
|
||||
|
||||
outb(PIT_CHAN0, 1);
|
||||
outb(PIT_CHAN0, 0);
|
||||
void pit_init(void) {
|
||||
outb(PIT_MODE_CMD, PIT_CHAN0 | PIT_LOBYTE | PIT_MODE0);
|
||||
|
||||
outb(PIT_CHAN0_DATA, (uint8_t)(DIVISOR & 0xff));
|
||||
}
|
||||
|
||||
void pit_handler(void) {
|
||||
ctx.ticks++;
|
||||
|
||||
outb(PIT_CHAN0_DATA, (uint8_t)(DIVISOR & 0xff));
|
||||
pic_send_eoi(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user