diff --git a/Makefile b/Makefile index c3c73e2..66967d9 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ # Define the object files -OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o bin/utils.o bin/string.o bin/stdio.o bin/disk.o bin/pic.o +OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o bin/utils.o bin/string.o bin/stdio.o bin/disk.o bin/pic.o bin/pit.o # Define the compiler and assembler CC = gcc -D__is_katauos @@ -61,6 +61,9 @@ bin/disk.o: src/disk.c bin/pic.o: src/pic.c $(CC) $(CFLAGS) -c $< -o $@ +bin/pit.o: src/pit.c + $(CC) $(CFLAGS) -c $< -o $@ + clean: rm -rf bin/ rm -f $(OUTPUT) diff --git a/include/pit.h b/include/pit.h new file mode 100644 index 0000000..8d4cfb8 --- /dev/null +++ b/include/pit.h @@ -0,0 +1,8 @@ +#ifndef PIT_H +#define PIT_H + +#include "../include/utils.h" + +void pit_init(); + +#endif diff --git a/src/isr.c b/src/isr.c index 8e13800..a1afd60 100644 --- a/src/isr.c +++ b/src/isr.c @@ -3,6 +3,7 @@ #include "../include/types.h" #include "../include/screen.h" #include "../include/pic.h" +#include "../include/pit.h" typedef size_t uword_t; struct interrupt_frame @@ -14,6 +15,7 @@ struct interrupt_frame uword_t ss; }; +__attribute__((interrupt)) void isr_timer(struct interrupt_frame *frame); void isr_custom(); void default_handler(); @@ -54,6 +56,7 @@ void isr_install() { for(int i = 32; i < 255; i++) idt_set_descriptor(i, (uint32)default_handler, 0x8E); + idt_set_descriptor(0x20, (uint32)isr_timer, 0x8E); idt_set_descriptor(0x21, (uint32)isr_custom, 0x8E); @@ -66,6 +69,12 @@ void default_handler() } +__attribute__((interrupt)) void isr_timer(struct interrupt_frame *frame) +{ + pit_init(); + pic_end_int(0x0); +} + void handle_keyboard() { uint8_t scancode = inb(0x60); @@ -76,7 +85,7 @@ __attribute__((interrupt)) void isr_custom(struct interrupt_frame *frame) { //terminal_writestring("YOOOOO!!!!!! I LOVE KATYA!!!!"); handle_keyboard(); - pic_end_int(0x21); + pic_end_int(0x1); } void isr0() diff --git a/src/kernel.c b/src/kernel.c index 389ca56..8937b23 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -5,6 +5,7 @@ #include "../include/disk.h" #include "../include/string.h" #include "../include/pic.h" +#include "../include/pit.h" #include @@ -14,8 +15,9 @@ void kmain() printf("KatauOS booting up\n"); isr_install(); pic_remap(0x20, 0x28); + pit_init(); //only enable keyboard IRQs - outb(0x21,0xfd); + outb(0x21,0xfc); outb(0xa1,0xff); printf("Kernel init sequence completed\n"); diff --git a/src/pit.c b/src/pit.c new file mode 100644 index 0000000..592192a --- /dev/null +++ b/src/pit.c @@ -0,0 +1,37 @@ +#include "../include/pit.h" + +//https://wiki.osdev.org/Programmable_Interval_Timer + +/* +Bit/s Usage +7 Output pin state +6 Null count flags +5 and 4 Access mode : + 0 0 = Latch count value command + 0 1 = Access mode: lobyte only + 1 0 = Access mode: hibyte only + 1 1 = Access mode: lobyte/hibyte +3 to 1 Operating mode : + 0 0 0 = Mode 0 (interrupt on terminal count) + 0 0 1 = Mode 1 (hardware re-triggerable one-shot) + 0 1 0 = Mode 2 (rate generator) + 0 1 1 = Mode 3 (square wave generator) + 1 0 0 = Mode 4 (software triggered strobe) + 1 0 1 = Mode 5 (hardware triggered strobe) + 1 1 0 = Mode 2 (rate generator, same as 010b) + 1 1 1 = Mode 3 (square wave generator, same as 011b) +0 BCD/Binary mode: 0 = 16-bit binary, 1 = four-digit BCD +*/ + +#define PIT_COMMAND_PORT 0x43 +#define PIT_DATA_PORT 0x40 + +void pit_init() { + uint16_t frequency = 100; + uint8_t command = 0x36;//00110110 see above to get the idea wtf is this number + + outb(PIT_COMMAND_PORT, command); + + outb(PIT_DATA_PORT, (uint8_t)(frequency & 0xFF)); + outb(PIT_DATA_PORT, (uint8_t)((frequency >> 8) & 0xFF)); +}