x86_64: more local and i/o apic configuration

This commit is contained in:
2023-03-20 20:21:44 +00:00
parent 8e9127cd6a
commit a4d850cc03
6 changed files with 71 additions and 11 deletions

View File

@@ -1,9 +1,13 @@
#include <socks/printk.h>
#include <socks/cpu.h>
#include <arch/ports.h>
#include <arch/irq.h>
static unsigned long long tick_counter = 0;
static int pit_callback(void)
{
tick_counter++;
printk("tick");
return 0;
}
@@ -12,7 +16,7 @@ static irq_hook_t pit_irq_hook = {
.irq_callback = pit_callback
};
void pit_init(unsigned int hz)
void pit_start(unsigned int hz)
{
unsigned int divisor = 1193180 / hz;
@@ -24,6 +28,28 @@ void pit_init(unsigned int hz)
outportb(0x40, hi);
hook_irq(IRQ0, &pit_irq_hook);
printk("clock: 8253 PIT initialised at %uHz", hz);
}
void pit_stop(void)
{
/* lowest possible frequency */
unsigned int divisor = 1193180;
outportb(0x43, 0x36);
uint8_t lo = (uint8_t)(divisor & 0xFF);
uint8_t hi = (uint8_t)((divisor >> 8) & 0xFF);
outportb(0x40, lo);
outportb(0x40, hi);
unhook_irq(IRQ0, &pit_irq_hook);
}
void pit_wait(unsigned int ticks)
{
unsigned long long end = tick_counter + ticks;
while (tick_counter < end) {
ml_cpu_pause();
}
}