diff options
| author | Ada Christine <adachristine18@gmail.com> | 2022-02-14 00:33:18 +0000 |
|---|---|---|
| committer | Ada Christine <adachristine18@gmail.com> | 2022-02-14 00:33:18 +0000 |
| commit | 86de700207fb0114ec52fafc36f84e1cbe508fd8 (patch) | |
| tree | 830649e3b7081e4c43d579a6ded67f7ee18add92 /kc/core | |
| parent | e8a76b2f6b53d99640ceb2850bf4e45118b923f1 (diff) | |
entering idle loop works with timer
Diffstat (limited to 'kc/core')
| -rw-r--r-- | kc/core/kc_main.c | 7 | ||||
| -rw-r--r-- | kc/core/pic8259.c | 13 | ||||
| -rw-r--r-- | kc/core/pic8259.h | 3 | ||||
| -rw-r--r-- | kc/core/pit8253.c | 17 | ||||
| -rw-r--r-- | kc/core/task.c | 11 |
5 files changed, 44 insertions, 7 deletions
diff --git a/kc/core/kc_main.c b/kc/core/kc_main.c index cfbc564..6d73cea 100644 --- a/kc/core/kc_main.c +++ b/kc/core/kc_main.c @@ -4,6 +4,8 @@ #include "memory.h" #include "panic.h" #include "task.h" +#include "pic8259.h" +#include "pit8253.h" #include <kernel/entry.h> @@ -22,8 +24,11 @@ unsigned long kc_main(struct kc_boot_data *data) cpu_init(); serial_init(); - kputs("<hacker voice> i'm in 3333\r\n"); + kprintf("sophia starting, boot data %#lx\n", boot_data); + kprintf("integer test %d %u\n", 3, 3); memory_init(); + pic8259_init(); + pit8253_init(); task_init(); return 0; diff --git a/kc/core/pic8259.c b/kc/core/pic8259.c index f449e38..b1de903 100644 --- a/kc/core/pic8259.c +++ b/kc/core/pic8259.c @@ -21,11 +21,18 @@ #define OCW3_READ_ISR 0xb #define OCW3_EOI 0x20 -typedef int (*pic8259_handler_func)(uint8_t irq); - pic8259_handler_func irq_handlers[PIC_ISR_COUNT]; -__attribute__((optimize("O3"))) +void pic8259_irq_install(uint8_t irq, pic8259_handler_func h) +{ + if (irq_handlers[irq]) + { + kprintf("attempt to overwrite irq handler for %u\n", irq); + return; + } + irq_handlers[irq] = h; +} + static void wait(void) { // stall for a few cycles diff --git a/kc/core/pic8259.h b/kc/core/pic8259.h index 13aaaaa..1913573 100644 --- a/kc/core/pic8259.h +++ b/kc/core/pic8259.h @@ -14,7 +14,10 @@ #include <stdint.h> +typedef int (*pic8259_handler_func)(uint8_t irq); + void pic8259_init(void); +void pic8259_irq_install(uint8_t irq, pic8259_handler_func f); void pic8259_irq_begin(uint8_t irq); void pic8259_irq_end(uint8_t irq); void pic8259_irq_mask(uint8_t irq); diff --git a/kc/core/pit8253.c b/kc/core/pit8253.c index 75e0467..8be2872 100644 --- a/kc/core/pit8253.c +++ b/kc/core/pit8253.c @@ -1,6 +1,7 @@ #include "pit8253.h" #include "pic8259.h" #include "port.h" +#include "kprint.h" #define PIT8253_DATA0 0x40 #define PIT8253_CMD 0x43 @@ -12,12 +13,28 @@ #define CONFIG_CHANNEL_0 (SEL_CHANNEL0|ACC_LOHI|MODE_RATE|BIN_COUNT) +static uint64_t count = 0; + +int pit8253_callback(uint8_t irq) +{ + (void)irq; + count++; + + if (!(count % (185))) + { + kprintf("it's been about %lu seconds\n", count / 18); + } + + return 0; +} + void pit8253_init(void) { outb(PIT8253_CMD, CONFIG_CHANNEL_0); outb(PIT8253_DATA0, 0xff); outb(PIT8253_DATA0, 0xff); + pic8259_irq_install(0, pit8253_callback); pic8259_irq_unmask(0); } diff --git a/kc/core/task.c b/kc/core/task.c index b825f01..b381793 100644 --- a/kc/core/task.c +++ b/kc/core/task.c @@ -42,10 +42,13 @@ static void lock_scheduler(void) static void unlock_scheduler(void) { - if (1 == schedule_lock_cnt) + if (schedule_lock_cnt >= 1) { schedule_lock_cnt--; - __asm__ volatile("sti;"); + } + if (schedule_lock_cnt == 0) + { + __asm__ volatile ("sti;"); } } @@ -86,6 +89,7 @@ static void idle_task_thread(void) noreturn void task_init(void) { + lock_scheduler(); char *kernel_rsp0 = vm_alloc(4096); // TODO: make it so this isn't demand-allocated. kernel_rsp0[1] = 0; @@ -95,12 +99,13 @@ noreturn void task_init(void) (struct kc_thread *)(first_task + 16384 - sizeof(*idle_thread)); idle_thread->state.stack = (uintptr_t)idle_thread; idle_thread->state.stack_top = (uintptr_t)kernel_rsp0; - + __asm__ volatile ( "mov %%cr3, %%rax\n\t" "mov %%rax, 0(%%rsi)\n\t" "mov %%rcx, %%rsp\n\t" + "call unlock_scheduler\n\t" "jmp idle_task_thread\n\t" : "=m"(idle_thread->state.page_map) : "S"(&idle_thread->state.page_map), |
