forked from CHatingPython/towos
feat: add interrupts handling, PIC and PIT
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#ifndef ARCH_X86_64_PIT_HPP
|
||||
#define ARCH_X86_64_PIT_HPP
|
||||
|
||||
#include "arch/x86_64/int.hpp"
|
||||
#include "arch/x86_64/io.hpp"
|
||||
#include "types.hpp"
|
||||
#include "vga.hpp"
|
||||
|
||||
namespace x86_64 {
|
||||
|
||||
struct pit {
|
||||
pit(u32 targetHz = 100) {
|
||||
constexpr u32 PIT_INPUT_HZ = 1193182;
|
||||
|
||||
const u16 divisor = static_cast<u16>(PIT_INPUT_HZ / targetHz);
|
||||
|
||||
io::outb(0x43, 0x36);
|
||||
|
||||
io::outb(0x40, static_cast<u8>(divisor & 0xFF));
|
||||
io::outb(0x40, static_cast<u8>(divisor >> 8));
|
||||
}
|
||||
|
||||
static void handler(interrupt_frame& frame, void* data) {
|
||||
(void)frame;
|
||||
|
||||
pit* pit = reinterpret_cast<decltype(pit)>(data);
|
||||
++pit->ticks;
|
||||
|
||||
vga::puts("PIT called!", 0, 5);
|
||||
}
|
||||
|
||||
volatile u64 ticks = 0;
|
||||
};
|
||||
|
||||
} // namespace x86_64
|
||||
|
||||
#endif // ARCH_X86_64_PIT_HPP
|
||||
Reference in New Issue
Block a user