From e9ebba2c893f5091a7e01df618d4eb5517d02af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Fri, 20 Dec 2024 18:38:55 +0100 Subject: [PATCH] refactor(pit): migrate to `x86_64` crate --- src/arch/x86_64/kernel/pit.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/arch/x86_64/kernel/pit.rs b/src/arch/x86_64/kernel/pit.rs index 3863ca930a..9209be9b45 100644 --- a/src/arch/x86_64/kernel/pit.rs +++ b/src/arch/x86_64/kernel/pit.rs @@ -1,16 +1,27 @@ #![allow(dead_code)] -use x86::io::*; +use x86_64::instructions::port::Port; use crate::arch::x86_64::kernel::pic; const PIT_CLOCK: u64 = 1_193_182; pub const PIT_INTERRUPT_NUMBER: u8 = pic::PIC1_INTERRUPT_OFFSET; -const PIT_CHANNEL0_DATA_PORT: u16 = 0x40; -const PIT_CHANNEL1_DATA_PORT: u16 = 0x41; -const PIT_CHANNEL2_DATA_PORT: u16 = 0x42; -const PIT_COMMAND_PORT: u16 = 0x43; +const fn pit_channel0_data() -> Port { + Port::new(0x40) +} + +const fn pit_channel1_data() -> Port { + Port::new(0x41) +} + +const fn pit_channel2_data() -> Port { + Port::new(0x42) +} + +const fn pit_command() -> Port { + Port::new(0x43) +} const PIT_BINARY_OUTPUT: u8 = 0b0000_0000; const PIT_BCD_OUTPUT: u8 = 0b0000_0001; @@ -34,8 +45,7 @@ pub fn init(frequency_in_hz: u64) { unsafe { // Reset the Programmable Interval Timer (PIT). - outb( - PIT_COMMAND_PORT, + pit_command().write( PIT_BINARY_OUTPUT | PIT_RATE_GENERATOR_MODE | PIT_LOBYTE_ACCESS @@ -46,8 +56,8 @@ pub fn init(frequency_in_hz: u64) { // Calculate the reload value to count down (round it to the closest integer). // Then transmit it as two individual bytes to the PIT. let count = (PIT_CLOCK + frequency_in_hz / 2) / frequency_in_hz; - outb(PIT_CHANNEL0_DATA_PORT, count as u8); - outb(PIT_CHANNEL0_DATA_PORT, (count >> 8) as u8); + pit_channel0_data().write(count as u8); + pit_channel0_data().write((count >> 8) as u8); } }