diff --git a/source/kernel/idt.c b/source/kernel/idt.c index d5651ec..2b5f04a 100644 --- a/source/kernel/idt.c +++ b/source/kernel/idt.c @@ -19,39 +19,6 @@ __attribute__((aligned(0x10))) static idt_entry_t idt[NUM_IDTS]; // define the idtr static idtr_t idtr; -static uint32_t has_triggered = 0; -static uint32_t hits = 0; -static uint32_t oopsie_woopsie = 0; - -uint32_t get_hits(void) { return oopsie_woopsie; } - -// we no-inline because I don't want it inlined :lemonthink: -// also i want the actual isr to only have save register, call, then iret -__attribute__((noinline)) static void actual_exception_handler(void) -{ - oopsie_woopsie++; -} - -// this currently will triple-fault on pressing a keyboard -__attribute__((noinline)) static void actualirq1Handler(void) -{ - // seems to triple fault before reaching here, idk pls can we get serial - // driver - hits++; - if (terminal_driver_loaded() && !has_triggered) { - terminal_putchar('U'); - terminal_update_cursor(); - // inb(0x60) is the port containing the key pressed - terminal_put64(inb(0x60)); - terminal_update_cursor(); - - // send eoi to the master PIC - // this is needed in the PIC remapping, don't question it - outb(0x20, 0x20); - __asm__ volatile("cli"); - } -} - void idt_set_entry(int idx, uint32_t handler_ptr, uint16_t code_selector, uint8_t attributes) { @@ -109,7 +76,7 @@ void setup_pic(void) // // remember that ^ toggles bits, so bits 1 and 2 will be toggled to 0 // (which will enable them in hw) - mask1 = 0xff ^ (1 << 1 | 1 << 2); + mask1 = 0xff ^ (1 << 0 | 1 << 1 | 1 << 2); mask2 = 0xff; outb(0x21, mask1); io_wait(); diff --git a/source/kernel/include/timer.h b/source/kernel/include/timer.h index 765542f..4321d2f 100644 --- a/source/kernel/include/timer.h +++ b/source/kernel/include/timer.h @@ -1,4 +1,6 @@ #pragma once #include +#include "idt.h" -unsigned long long get_cpu_time(); \ No newline at end of file +void timer_init(uint32_t hz); +void timer_irq(registers_t *frame); diff --git a/source/kernel/isr.c b/source/kernel/isr.c index c9addbf..23a07a0 100644 --- a/source/kernel/isr.c +++ b/source/kernel/isr.c @@ -3,6 +3,7 @@ #include "io.h" #include "keyboard_driver.h" #include "terminal_driver.h" +#include "timer.h" isr_t interrupt_handlers[256]; @@ -21,6 +22,8 @@ void breakpoint(registers_t *frame) { printf("breakpoint\n"); } void overflow(registers_t *frame) { printf("overflow trap\n"); } +void pagefault(registers_t *frame) { printf("page fault\n"); } + void init_isr() { for (int i = 0; i < 256; i++) @@ -31,11 +34,13 @@ void init_isr() register_interrupt_handler(3, &breakpoint); register_interrupt_handler(4, &overflow); - // irq handlers - register_interrupt_handler(33, &keyboard_irq); + register_interrupt_handler(14, &pagefault); - // handler initializations + // irq handlers IRQ# + 32 + timer_init(100); + register_interrupt_handler(32, &timer_irq); keyboard_init(); + register_interrupt_handler(33, &keyboard_irq); } void isr_handler(registers_t *frame) diff --git a/source/kernel/kernel.c b/source/kernel/kernel.c index f1fe5bd..3a72fe1 100644 --- a/source/kernel/kernel.c +++ b/source/kernel/kernel.c @@ -12,32 +12,10 @@ void main() { init_drivers(); terminal_clear(); - init_paging(); terminal_update_cursor(); init_idt(); - asm volatile("int $0x3"); - asm volatile("int $0x4"); + init_paging(); + printf("Hello"); write_serial(COM1, "Hello From SecureOS!"); - // printf(s.data); - - // init_paging(); - // string s; - // s.data = - // "HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLLLLLLL" - // "LLOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"; - // s.len = 96; - // printf(&s); - // uint32_t* wow = (uint32_t*) 0x12340000; - // palloc(wow, PAGE_PRESENT | PAGE_RW); - // *wow = 0x42042069; - // terminal_put64(*wow); - // for (int i = 0; i < 30; i ++) { - // uint32_t* smol = kalloc(200); - // *smol = 0x12345678; - // terminal_put64(smol); - // terminal_putchar(' '); - // terminal_put64(*smol); - // terminal_putchar('\n'); - // } } diff --git a/source/kernel/kernel_entry.asm b/source/kernel/kernel_entry.asm index a54116b..200878d 100644 --- a/source/kernel/kernel_entry.asm +++ b/source/kernel/kernel_entry.asm @@ -6,7 +6,7 @@ global kernel_entry ; flags for a megapage MEGAPAGE_FLAGS equ (1 << 7) | (1 << 1) | (1 << 0) -L2_PAGE_BASE equ l2_page_table - (1 << 31) +L2_PAGE_BASE equ l2_page_table - (0x80100000) kernel_entry: ; enable page size extensions diff --git a/source/kernel/memory.c b/source/kernel/memory.c index 978d696..6d6321b 100644 --- a/source/kernel/memory.c +++ b/source/kernel/memory.c @@ -1,7 +1,7 @@ #include "memory.h" #include "terminal_driver.h" +#include "io.h" #include -#include uint32_t l2_page_table[1024] __attribute__((aligned(4096))); diff --git a/source/kernel/timer.c b/source/kernel/timer.c index 178ebac..f563691 100644 --- a/source/kernel/timer.c +++ b/source/kernel/timer.c @@ -1,12 +1,49 @@ #include "timer.h" +#include "io.h" -unsigned long long get_cpu_time() -{ - unsigned long long time_stamp; - // get time_stamp from cpu register - asm volatile("rdtsc" : "=A"(time_stamp)); +#define PORT_CHANNEL_0 0x40 +#define PORT_CHANNEL_1 0x41 +#define PORT_CHANNEL_2 0x42 +#define PORT_CMD 0x43 - return time_stamp; +// Channel options +#define CHANNEL_0 (0b00 << 6) +#define CHANNEL_1 (0b01 << 6) +#define CHANNEL_2 (0b10 << 6) +#define READ_BACK (0b11 << 6) + +// Access mode options +#define LATCH_COUNT (0b00 << 4) +#define LOBYTE_ONLY (0b01 << 4) +#define HIBYTE_ONLY (0b10 << 4) +#define LOBYTE_HIBYTE (0b11 << 4) + +// Operating mode options +#define MODE_0 (0b000 << 1) //interrupt on terminal count +#define MODE_1 (0b001 << 1) //hardware retriggerable one-shot +#define MODE_2 (0b010 << 1) //rate generator +#define MODE_3 (0b011 << 1) //square wave generator +#define MODE_4 (0b100 << 1) //software strobe +#define MODE_5 (0b101 << 1) //hardware strobe + +// BCD/Binary mode options +#define BINARY_MODE 0 +#define BCD_MODE 1 + +uint32_t divisor; +uint32_t tick; + +void timer_init(uint32_t hz) { + tick = 0; + divisor = 1193180 / hz; + outb(PORT_CMD, CHANNEL_0 | LOBYTE_HIBYTE | MODE_3 | BINARY_MODE); + uint8_t lowbyte = (uint8_t) (divisor & 0xFF); + uint8_t highbyte = (uint8_t) ((divisor >> 8) & 0xFF); + outb(PORT_CHANNEL_0, lowbyte); + outb(PORT_CHANNEL_0, highbyte); } -unsigned long long get_cpu_frequency() {} \ No newline at end of file +void timer_irq(registers_t *frame) { + tick++; + // printf("%x\n", tick); +}