summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2021-11-27 19:07:11 -0500
committerJon Santmyer <jon@jonsantmyer.com>2021-11-27 19:07:11 -0500
commit255e2d57b08236051b659323865b6ce2772071f6 (patch)
treeba2396618b133b64bd1f6bd9e6eae7f672cacc1b
parentc070667252e6db6bde6cb6b1d96a0c5bbb52b435 (diff)
downloadmodit-kernel-255e2d57b08236051b659323865b6ce2772071f6.tar.gz
modit-kernel-255e2d57b08236051b659323865b6ce2772071f6.tar.bz2
modit-kernel-255e2d57b08236051b659323865b6ce2772071f6.zip
strip timer module; fix issue with page contexts overwriting; add debug print to heap; add register print to panic
-rw-r--r--include/arch_x86/common/syscall.h7
-rw-r--r--include/arch_x86/common/task.h2
-rw-r--r--src/arch_common/klibc/strcpy.c2
-rw-r--r--src/arch_common/klibc/vsnprintf.c1
-rw-r--r--src/arch_x86/64/apic/ioapic.c2
-rw-r--r--src/arch_x86/64/syscall/syscall.c1
-rw-r--r--src/arch_x86/64/task/context.c43
-rw-r--r--src/arch_x86/64/task/load.c34
-rw-r--r--src/arch_x86/64/tlb/clone.c7
-rw-r--r--src/arch_x86/64/tlb/main.c2
-rw-r--r--src/arch_x86/64/user/jump.s2
-rw-r--r--src/arch_x86/common/acpi/madt.c8
-rw-r--r--src/arch_x86/common/heap/main.c53
-rw-r--r--src/arch_x86/common/main.c2
-rw-r--r--src/arch_x86/common/panic/main.c4
-rw-r--r--src/arch_x86/common/syscall/syscall.c24
-rw-r--r--src/arch_x86/common/timer/main.c63
17 files changed, 139 insertions, 118 deletions
diff --git a/include/arch_x86/common/syscall.h b/include/arch_x86/common/syscall.h
index 7eb84c9..406664e 100644
--- a/include/arch_x86/common/syscall.h
+++ b/include/arch_x86/common/syscall.h
@@ -113,4 +113,11 @@ struct syscall_initrd_data {
uintptr_t *len;
};
+struct syscall_exec_data {
+ const uint8_t *program;
+ size_t programsz;
+ const uint8_t *stack;
+ size_t stacksz;
+};
+
#endif
diff --git a/include/arch_x86/common/task.h b/include/arch_x86/common/task.h
index eac5cc2..df2035a 100644
--- a/include/arch_x86/common/task.h
+++ b/include/arch_x86/common/task.h
@@ -32,6 +32,8 @@ struct execution_context
extern struct execution_context *execution_contexts;
extern struct execution_context *current_excontext;
+struct execution_context *excontext_find(size_t id);
+
struct execution_context *excontext_fork(void);
struct execution_context *excontext_spawn(const uint8_t *bin, size_t binsz, const uint8_t *stack, size_t stacksz);
diff --git a/src/arch_common/klibc/strcpy.c b/src/arch_common/klibc/strcpy.c
index 7ab4782..056491b 100644
--- a/src/arch_common/klibc/strcpy.c
+++ b/src/arch_common/klibc/strcpy.c
@@ -3,7 +3,7 @@
char *
strcpy(char *restrict dest, const char *src)
{
- for(size_t i = 0; src[i]; i++){
+ for(size_t i = 0; i < strlen(src) + 1; i++){
dest[i] = src[i];
}
diff --git a/src/arch_common/klibc/vsnprintf.c b/src/arch_common/klibc/vsnprintf.c
index d6b8b52..abc6338 100644
--- a/src/arch_common/klibc/vsnprintf.c
+++ b/src/arch_common/klibc/vsnprintf.c
@@ -104,6 +104,7 @@ vsnprintf(char *restrict str, size_t size, const char *restrict format, va_list
break;
}
}
+ *str = 0;
return osize - size;
}
/* vim: set ts=4 sw=4 tw=0 et :*/
diff --git a/src/arch_x86/64/apic/ioapic.c b/src/arch_x86/64/apic/ioapic.c
index 83ae2d4..57fc4dd 100644
--- a/src/arch_x86/64/apic/ioapic.c
+++ b/src/arch_x86/64/apic/ioapic.c
@@ -107,7 +107,7 @@ apic_ioapic_setup(void)
ioapic_entries = madt_get_ioapic_ents(&nioapic);
ioapic_isos = madt_get_iso_ents(&niso);
- ioapics = kmalloc(sizeof(struct ioapic) * nioapic, "ioapic entries");
+ ioapics = kmalloc(sizeof(struct ioapic) * nioapic, "ioapices");
for(size_t i = 0; i < nioapic; i++){
struct madt_ioapic *entry = ioapic_entries[i];
diff --git a/src/arch_x86/64/syscall/syscall.c b/src/arch_x86/64/syscall/syscall.c
index 0873890..183e402 100644
--- a/src/arch_x86/64/syscall/syscall.c
+++ b/src/arch_x86/64/syscall/syscall.c
@@ -18,4 +18,5 @@ syscall_constructor(void)
{
uintptr_t handler = (uintptr_t)_syscall_handler;
cpu_msr_set(0xC0000082, handler, handler >> 32);
+ cpu_msr_set(0xC0000084, 0, 0);
}
diff --git a/src/arch_x86/64/task/context.c b/src/arch_x86/64/task/context.c
index d7d57b8..27f6e55 100644
--- a/src/arch_x86/64/task/context.c
+++ b/src/arch_x86/64/task/context.c
@@ -5,6 +5,7 @@
#include "heap.h"
#include "vmm.h"
#include "gdt.h"
+#include "apic.h"
//Current execution context
THREAD struct execution_context *current_excontext;
@@ -18,22 +19,30 @@ static size_t nextid = 0;
static struct execution_context *timer_context = NULL;
static int timer_context_ticks = 0;
static int timer_context_ticks_trigger = 0;
+static bool in_timer = false;
static void
-excontext_timer_hook(void)
+excontext_timer_handler(struct intregs *regs)
{
- if(timer_context == NULL) return;
- timer_context_ticks--;
- if(timer_context_ticks <= 0) {
- timer_context_ticks = timer_context_ticks_trigger;
- excontext_switch(timer_context);
+ if(timer_context == NULL) {
+ apic_write(APIC_REG_TIMER_IC, 10 * timer_gettpms());
+ apic_write(0xB0, 0);
+ return;
}
+
+ in_timer = true;
+ excontext_switch(timer_context);
}
void
excontext_set_timer(size_t ms) {
timer_context_ticks_trigger = timer_context_ticks = ms;
timer_context = current_excontext;
+ apic_write(APIC_REG_TIMER_IC, ms * timer_gettpms());
+ if(in_timer) {
+ apic_write(0xB0, 0);
+ in_timer = false;
+ }
}
struct execution_context *
@@ -50,14 +59,17 @@ excontext_find(size_t id)
struct execution_context *
excontext_append(uintptr_t cr3, uintptr_t ip, uintptr_t sp, uintptr_t bp)
{
- struct execution_context *ctx = kmalloc(sizeof(struct execution_context), "ex context");
+ char reasonstr[32];
+ sprintf(reasonstr, "context %i", nextid);
+ struct execution_context *ctx = kmalloc(sizeof(struct execution_context), reasonstr);
memset(ctx, 0, sizeof(struct execution_context));
if(execution_contexts == 0) {
- execution_contexts = ctx;
+ ctx->privs = ~0;
current_excontext = ctx;
- ctx->privs = (~0);
- } else sll_appbeg(execution_contexts, ctx);
+ }
+ ctx->listhead.next = execution_contexts;
+ execution_contexts = ctx;
ctx->id = nextid++;
ctx->vcr3 = cr3;
@@ -85,10 +97,19 @@ excontext_switch(struct execution_context *target)
//Begin swap
+ /*printk(KERNEL_INFO, "SWAP %i %lX -> %i %lX\n",
+ current_excontext->id,
+ vmm_getphys(current_excontext->vcr3),
+ target->id,
+ vmm_getphys(target->vcr3));*/
+
current_excontext = target;
uintptr_t cr3 = current_excontext->vcr3;
cr3 = vmm_getphys(cr3);
+ extern uintptr_t vcr3;
+ vcr3 = current_excontext->vcr3;
+
ip = current_excontext->ip;
sp = current_excontext->sp;
bp = current_excontext->bp;
@@ -113,5 +134,5 @@ task_constructor(void)
excontext_switch(current_excontext);
tss_setstackpl(0, MODIT_KERNEL_STAST);
- timer_hook_register(10, excontext_timer_hook);
+ int_set_handler(32, excontext_timer_handler);
}
diff --git a/src/arch_x86/64/task/load.c b/src/arch_x86/64/task/load.c
index c1b65d6..094530b 100644
--- a/src/arch_x86/64/task/load.c
+++ b/src/arch_x86/64/task/load.c
@@ -35,7 +35,6 @@ excontext_spawn_firsthalf(void);
void
excontext_spawn_secondhalf(const uint8_t *bin, size_t binsz, const uint8_t *stack, size_t stacksz)
{
- asm volatile("cli");
vmptr_t start = MODIT_USER_MIN;
vmptr_t ustk = MODIT_USER_STACK;
@@ -47,22 +46,21 @@ excontext_spawn_secondhalf(const uint8_t *bin, size_t binsz, const uint8_t *stac
vmm_alloc_force(start, binsz, true, false);
memcpy((void*)start, bin, binsz);
-
- asm volatile("xchg %bx, %bx");
+
+ vmm_alloc_force(MODIT_KERNEL_STAST - 0x2000, 0x2000, false, false);
+ kfree((void*)((uintptr_t)&stacksz - 0xFE0));
user_enter(start, ustk);
}
struct execution_context *
excontext_spawn(const uint8_t *bin, size_t binsz, const uint8_t *stack, size_t stacksz)
{
- pmptr_t cr3 = tlb_spawncr3();
- pmptr_t ocr3 = 0;
+ pmptr_t pcr3 = tlb_spawncr3();
vmptr_t ip = (uintptr_t)excontext_spawn_firsthalf;
- vmptr_t sp = MODIT_KERNEL_STAST;
-
- //Temporarily enter context
- asm volatile("mov %%cr3, %0": "=r"(ocr3));
- asm volatile("mov %0, %%cr3":: "r"(cr3));
+
+ size_t kstacksz = binsz + stacksz + (sizeof(uintptr_t) * 4) + PAGE_SIZE;
+ vmptr_t kstack = (vmptr_t)kmalloc(kstacksz, "spawnkstk");
+ vmptr_t sp = kstack + kstacksz;
//Push data to stack
PUSH(sp, bin, binsz)
@@ -77,15 +75,11 @@ excontext_spawn(const uint8_t *bin, size_t binsz, const uint8_t *stack, size_t s
PUSHV(sp, stkat);
PUSHV(sp, stacksz);
- //Page of leeway
- vmm_alloc_force(sp - PAGE_SIZE, PAGE_SIZE, 0, 0);
-
- asm volatile("mov %0, %%cr3":: "r"(ocr3));
-
//Spawn context
- vmptr_t ncr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "pgctx");
- pmm_freepage(vmm_mappg(cr3, ncr3, 0, 3).value);
- return excontext_append(ncr3, ip, sp, 0);
+ char reasonstr[32];
+ vmptr_t newcr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "spawn cr3");
+ vmm_mappg(pcr3, newcr3, 0, 3);
+ return excontext_append(newcr3, ip, sp, 0);
}
struct execution_context *
@@ -102,11 +96,11 @@ excontext_fork(void)
return current_excontext;
}
- cr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "cr3");
+ cr3 = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "fork cr3");
pcr3 = tlb_copycr3();
stkf = tlb_clonepml(4, 255);
- vmm_mappg(tlb_copycr3(), cr3, 0, 3);
+ vmm_mappg(pcr3, cr3, 0, 3);
((uintptr_t*)cr3)[255] = stkf;
return excontext_append(cr3, ip, sp, bp);
diff --git a/src/arch_x86/64/tlb/clone.c b/src/arch_x86/64/tlb/clone.c
index dd2acb1..125a9c5 100644
--- a/src/arch_x86/64/tlb/clone.c
+++ b/src/arch_x86/64/tlb/clone.c
@@ -65,8 +65,11 @@ tlb_spawncr3(void)
//Allocate cr3
pmptr_t new = pmm_getpage();
vmm_mappg(new, (vmptr_t)pmlbuffer, 0, 3);
-
- memcpy(pmlbuffer, pmls[3], PAGE_SIZE);
+
+ memset(pmlbuffer, 0, 4096);
+ for(uint64_t i = 256; i < 512; i++) {
+ pmlbuffer[i] = pmls[3][i];
+ }
pmlbuffer[510] = new | 3;
pmlbuffer[511] = pmls[3][511];
diff --git a/src/arch_x86/64/tlb/main.c b/src/arch_x86/64/tlb/main.c
index c597942..71c46f1 100644
--- a/src/arch_x86/64/tlb/main.c
+++ b/src/arch_x86/64/tlb/main.c
@@ -4,6 +4,7 @@
#include "interrupt.h"
#include "panic.h"
#include "modit.h"
+#include "task.h"
#include "stdio.h"
#include "stdlib.h"
@@ -34,6 +35,7 @@ _interrupt_handler_pagefault(struct intregs *regs)
uint64_t pa;
asm volatile("movq %%cr2, %0": "=a"(pa));
+ //printk(KERNEL_INFO, "%X PF %X @ %X (%i)\n", vcr3, pa, regs->rip, regs->err);
uintptr_t l1 = VMM_PML1_INDEX(pa);
uint64_t pg = pml1[l1];
if(pg & (PAGE_OS_LAZY << 9)) {
diff --git a/src/arch_x86/64/user/jump.s b/src/arch_x86/64/user/jump.s
index 1d7c953..2f6ce62 100644
--- a/src/arch_x86/64/user/jump.s
+++ b/src/arch_x86/64/user/jump.s
@@ -14,5 +14,5 @@ user_enablesce:
user_enter:
mov %rdi, %rcx #Entry
mov %rsi, %rsp #Stack
- mov $0x0202, %r11
+ mov $0x202, %r11
sysretq
diff --git a/src/arch_x86/common/acpi/madt.c b/src/arch_x86/common/acpi/madt.c
index dcebdec..bdf3a3f 100644
--- a/src/arch_x86/common/acpi/madt.c
+++ b/src/arch_x86/common/acpi/madt.c
@@ -82,13 +82,13 @@ madt_parse(struct acpisdthdr *madthdr)
}
//Allocate memory for lists
- lapicids = kmalloc(ncores, "acpi core ids");
+ lapicids = kmalloc(ncores, "acpids");
ncores = 0;
- ioapics = kmalloc(nioapic * sizeof(uintptr_t), "acpi ioapics");
+ ioapics = kmalloc(nioapic * sizeof(uintptr_t), "ioapics");
nioapic = 0;
- isos = kmalloc(niso * sizeof(uintptr_t), "acpi isos");
+ isos = kmalloc(niso * sizeof(uintptr_t), "isos");
niso = 0;
//Second pass, add IDs to list, lapic_addr
@@ -106,7 +106,7 @@ madt_parse(struct acpisdthdr *madthdr)
}
}
- lapic_registers = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "lapic regs");
+ lapic_registers = (uintptr_t)kmalloc_a(PAGE_SIZE, PAGE_SIZE, "lapicrs");
vmm_mappg(lapic_addr, lapic_registers, 0, 3);
lapic_registers += (lapic_addr % 0x1000);
}
diff --git a/src/arch_x86/common/heap/main.c b/src/arch_x86/common/heap/main.c
index c91ddcf..9601946 100644
--- a/src/arch_x86/common/heap/main.c
+++ b/src/arch_x86/common/heap/main.c
@@ -7,7 +7,7 @@
#include "mutex.h"
#include "modit.h"
-#define BUCKET_SIZE 36
+#define BUCKET_SIZE 64
#define BUCKET_DATA_SIZE (sizeof(uintptr_t) * 3)
#define BUCKET_REASON_SIZE (BUCKET_SIZE - BUCKET_DATA_SIZE)
@@ -168,13 +168,14 @@ heap_mergebucket(struct bucket *bucket)
}
static struct bucket*
-heap_getbest(size_t size)
+heap_getbest(size_t size, size_t align)
{
struct bucket *best = NULL;
for(struct bucket *bucket = heap_head; bucket != 0; bucket = bucket->next)
{
if(BUCKET_GETTAKEN(bucket)) continue;
if(BUCKET_GETLEN(bucket) < size) continue;
+ if(bucket->addr % align != 0) continue;
if(best == NULL) {
best = bucket;
continue;
@@ -185,10 +186,9 @@ heap_getbest(size_t size)
best = bucket;
}
- if(best == NULL) {
+ if(best == NULL && align == 1) {
best = heap_makebest(size);
}
-
return best;
}
@@ -201,7 +201,7 @@ kmalloc(size_t size, const char *reason)
size = ((size / 2) + (size % 2)) * 2;
LOCK(heap)
- struct bucket *bestfit = heap_getbest(size);
+ struct bucket *bestfit = heap_getbest(size, 1);
bestfit = heap_splitbucket(bestfit, size);
bestfit->len |= 1;
@@ -215,27 +215,31 @@ void*
kmalloc_a(size_t size, uintptr_t alignto, const char *reason)
{
if(size == 0) return NULL;
- if(alignto == 0) return kmalloc(size, reason);
if(reason == 0) reason = "unknown";
size = ((size / 2) + (size % 2)) * 2;
LOCK(heap)
- uintptr_t ht_addr = BUCKET_GETADDR(heap_tail);
- uintptr_t ht_size = BUCKET_GETLEN(heap_tail);
- uintptr_t ht_lim = ht_addr + ht_size;
-
- uintptr_t buffersize = alignto - (ht_lim % alignto);
- if(BUCKET_GETTAKEN(heap_tail)){
- heap_makebest(buffersize);
- }
- heap_tail->len = buffersize;
- struct bucket *buffer = heap_tail;
+ struct bucket *best = heap_getbest(size, alignto);
+ if(best == NULL) {
+ uintptr_t ht_addr = BUCKET_GETADDR(heap_tail);
+ uintptr_t ht_size = BUCKET_GETLEN(heap_tail);
+ uintptr_t ht_lim = ht_addr + ht_size;
- buffer->len |= 1;
- struct bucket *best = heap_makebest(size);
+ uintptr_t buffersize = alignto - (ht_lim % alignto);
+ if(BUCKET_GETTAKEN(heap_tail)){
+ heap_makebest(buffersize);
+ }
- buffer->len &= ~1;
+ struct bucket *buffer = heap_tail;
+ best = buffer;
+ best->len = size;
+ if(heap_tail->addr % alignto != 0) {
+ buffer->len = buffersize | 1;
+ best = heap_makebest(size);
+ buffer->len &= ~1;
+ }
+ }
best->len |= 1;
strcpy(best->reason, reason);
@@ -266,6 +270,17 @@ kfree_unlock_return:
UNLOCK(heap)
}
+void
+heap_print(void)
+{
+ printk(KERNEL_INFO, "Printing block debug info\n");
+ int i = 0;
+ for(struct bucket *bucket = heap_head; bucket; bucket = bucket->next) {
+ printk(KERNEL_INFO, "%i : [%s] %X bytes %X (%s)\n", i++, bucket->len & 1 ? "TAKEN" : "FREE", bucket->len, bucket->addr, bucket->reason);
+ }
+ printk(KERNEL_INFO, "End debug info\n");
+}
+
MODULE static void
heap_constructor(void)
{
diff --git a/src/arch_x86/common/main.c b/src/arch_x86/common/main.c
index 1e9ede1..f1b7249 100644
--- a/src/arch_x86/common/main.c
+++ b/src/arch_x86/common/main.c
@@ -25,13 +25,11 @@ kernel_main(void)
void
mutex_lock(struct mutex *mutex)
{
- asm volatile("cli");
while(!__sync_bool_compare_and_swap(&mutex->lock, 0, 1)) asm("pause");
}
void
mutex_unlock(struct mutex *mutex)
{
- asm volatile("sti");
mutex->lock = 0;
}
diff --git a/src/arch_x86/common/panic/main.c b/src/arch_x86/common/panic/main.c
index 3384989..de804b6 100644
--- a/src/arch_x86/common/panic/main.c
+++ b/src/arch_x86/common/panic/main.c
@@ -56,10 +56,12 @@ panic_except(struct intregs *regs, const char *exceptstr)
if(regs != NULL) {
printf("ERR %i\n", regs->err);
printf("IP %l016X CTX %i\n", regs->rip, current_excontext->id);
+ printf("RAX %l016X RBX %l016X RCX %l016X\nRDX %l016X", regs->rax, regs->rbx, regs->rcx, regs->rdx);
+ printf("RSI %l016X RDI %l016X\nRSP %l016X RBP %l016X", regs->rsi, regs->rdi, regs->sp, regs->rbp);
}
#else
#endif
-
+ heap_print();
panic_end();
}
diff --git a/src/arch_x86/common/syscall/syscall.c b/src/arch_x86/common/syscall/syscall.c
index ee13205..50bb49b 100644
--- a/src/arch_x86/common/syscall/syscall.c
+++ b/src/arch_x86/common/syscall/syscall.c
@@ -4,6 +4,7 @@
#include "boot.h"
#include "vmm.h"
#include "pmm.h"
+#include "heap.h"
#include "ipc.h"
#define POINTER_BOUND_CHECK(ptr) \
@@ -195,6 +196,24 @@ syscall_detach(void *unused)
current_excontext->vcr3 = cr3;
excontext_switch(current_excontext);
+ return 0;
+}
+
+int
+syscall_exec(struct syscall_exec_data *data)
+{
+ printk(KERNEL_WARN, "TODO: SYSCALL_EXEC is stub!\n");
+ return -1;
+}
+
+int
+syscall_spawn(struct syscall_exec_data *data)
+{
+ POINTER_CHECK(data)
+ POINTER_CHECK(data->program);
+ POINTER_CHECK(data->stack);
+
+ return excontext_spawn(data->program, data->programsz, data->stack, data->stacksz)->id;
}
syscall_t syscalls[SYSCALL_MAX] =
@@ -215,5 +234,8 @@ syscall_t syscalls[SYSCALL_MAX] =
syscall_port_write,
syscall_message_send,
syscall_message_recv,
- syscall_initrd_get
+ syscall_initrd_get,
+ syscall_detach,
+ syscall_exec,
+ syscall_spawn
};
diff --git a/src/arch_x86/common/timer/main.c b/src/arch_x86/common/timer/main.c
index f1d643a..b166277 100644
--- a/src/arch_x86/common/timer/main.c
+++ b/src/arch_x86/common/timer/main.c
@@ -12,8 +12,6 @@
static bool started = false;
static int pit_ms;
static int apic_tpms;
-static uint32_t timer_lcd;
-static uint32_t timer_wait_ticks;
static struct timer_quantum *quantum_tail = NULL;
static struct timer_quantum *quantum_head = NULL;
@@ -28,25 +26,11 @@ _interrupt_pit(struct intframe *frame)
}
static void
-apic_refresh(void)
-{
- apic_write(APIC_REG_TIMER_IC, apic_tpms * timer_lcd);
-}
-
-static void
_interrupt_timer(struct intregs *regs)
{
(void)regs;
- apic_refresh();
+ printk(KERNEL_INFO, "Timer tick\n");
apic_write(0xB0, 0);
-
- for(struct timer_quantum *q = quantum_head; q; q = q->next) {
- q->cc -= timer_lcd;
- if(q->cc == 0) {
- q->cc = q->ms;
- q->hook();
- }
- }
}
static void
@@ -70,40 +54,8 @@ pit_wait(void)
ioapic_mask(0);
}
-static void
-timer_hook(void)
-{
- if(timer_wait_ticks > 0) timer_wait_ticks--;
-}
-
-void
-timer_hook_register(uint32_t ms, void (*hook)(void))
-{
- struct timer_quantum *q = kmalloc(sizeof(struct timer_quantum), "timer quantum");
- q->ms = ms;
- q->cc = ms;
- q->hook = hook;
-
- if(quantum_tail == NULL) quantum_tail = quantum_head = q;
- uint32_t gcd = ms * timer_lcd;
- gcd = timer_lcd > ms ? gcd / timer_lcd : gcd / ms;
- timer_lcd = gcd;
-
- apic_refresh();
-
- if(quantum_tail) quantum_tail->next = q;
- q->next = NULL;
-}
-
-void
-wait(uint32_t ms)
-{
- timer_wait_ticks = ms;
- apic_refresh();
- while(timer_wait_ticks > 0) {
- asm("pause");
- }
-}
+int
+timer_gettpms(void) { return apic_tpms; }
MODULE static void
timer_constructor(void)
@@ -117,10 +69,11 @@ timer_constructor(void)
printk(KERNEL_INFO, "Clocked timer at %lX clocks per ms\n", apic_tpms);
int_set_handler(32, _interrupt_timer);
- apic_write(APIC_REG_LVTTMR, 32);
+ apic_write(APIC_REG_LVTTMR, 0x20);
apic_write(APIC_REG_TIMER_DC, 0x3);
- ioapic_umask(0);
- timer_lcd = 10;
- timer_hook_register(10, timer_hook);
+ pit_command(PIT_OM_TERMINAL, PIT_AM_LOHI, PIT_SC_CHANNEL0);
+ pit_write(PIT_SC_CHANNEL0, 0);
+
+ ioapic_umask(0);
}