diff --git a/Makefile b/Makefile index aca3654..3153634 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ VERSION=0 PATCHLEVEL=0 -SUBLEVEL=3 +SUBLEVEL=4 EXTRAVERSION=-$(shell git rev-parse HEAD | head -c 7) export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION diff --git a/src/gdt.rs b/src/arch/i686/gdt.rs similarity index 100% rename from src/gdt.rs rename to src/arch/i686/gdt.rs diff --git a/src/arch/i686/mod.rs b/src/arch/i686/mod.rs new file mode 100644 index 0000000..429c8f3 --- /dev/null +++ b/src/arch/i686/mod.rs @@ -0,0 +1,7 @@ +pub mod gdt; +pub mod port; + +pub fn init() +{ + gdt::init(); +} diff --git a/src/arch/i686/port.rs b/src/arch/i686/port.rs new file mode 100644 index 0000000..1f6f091 --- /dev/null +++ b/src/arch/i686/port.rs @@ -0,0 +1,61 @@ +use core::arch::asm; + +#[inline(always)] +pub fn inb(port: u16) -> u8 +{ + let ret: u8; + unsafe + { + asm!("in al, dx", out("al") ret, in("dx") port, options(nomem, nostack, preserves_flags)); + } + ret +} + +#[inline(always)] +pub fn inw(port: u16) -> u16 +{ + let ret: u16; + unsafe + { + asm!("in ax, dx", out("ax") ret, in("dx") port, options(nomem, nostack, preserves_flags)); + } + ret +} + +#[inline(always)] +pub fn ind(port: u16) -> u32 +{ + let ret: u32; + unsafe + { + asm!("in eax, dx", out("eax") ret, in("dx") port, options(nomem, nostack, preserves_flags)); + } + ret +} + +#[inline(always)] +pub fn outb(port: u16, value: u8) +{ + unsafe + { + asm!("out dx, al", in("dx") port, in("al") value, options(nomem, nostack, preserves_flags)); + } +} + +#[inline(always)] +pub fn outw(port: u16, value: u16) +{ + unsafe + { + asm!("out dx, ax", in("dx") port, in("ax") value, options(nomem, nostack, preserves_flags)); + } +} + +#[inline(always)] +pub fn outd(port: u16, value: u32) +{ + unsafe + { + asm!("out dx, eax", in("dx") port, in("eax") value, options(nomem, nostack, preserves_flags)); + } +} diff --git a/src/arch/initial.rs b/src/arch/initial.rs new file mode 100644 index 0000000..13d36c0 --- /dev/null +++ b/src/arch/initial.rs @@ -0,0 +1,9 @@ +#[cfg(target_arch = "x86")] +use super::i686; + +#[cfg(target_arch = "x86")] +#[inline(always)] +pub fn init() +{ + i686::init(); +} diff --git a/src/arch/mod.rs b/src/arch/mod.rs new file mode 100644 index 0000000..3860f24 --- /dev/null +++ b/src/arch/mod.rs @@ -0,0 +1,7 @@ +pub mod initial; + +#[cfg(target_arch = "x86")] +mod i686; + +#[cfg(target_arch = "x86")] +pub use i686::port; diff --git a/src/elsos.rs b/src/elsos.rs index ea16e6f..d0e7d63 100644 --- a/src/elsos.rs +++ b/src/elsos.rs @@ -8,13 +8,13 @@ use core::panic::PanicInfo; use crate::multiboot::{MULTIBOOT_MMAP, MULTIBOOT_MMAP_ENTRIES}; +mod arch; mod ferramenta; mod vga; mod keyboard; mod tty; mod multiboot; mod serial; -mod gdt; mod memory; mod libc; @@ -38,7 +38,7 @@ pub static mut SETTINGS: Settings = Settings #[no_mangle] pub extern "C" fn kernel_main(magic: u32, address: u32) { - gdt::init(); + arch::initial::init(); init_vga(); vga::cursor::Cursor::init(0, 15); if multiboot::check_magic(magic) && multiboot::parse(address) diff --git a/src/ferramenta.rs b/src/ferramenta.rs index 86b7ccc..dd7efcf 100644 --- a/src/ferramenta.rs +++ b/src/ferramenta.rs @@ -1,42 +1,9 @@ use core::slice; -use core::arch::asm; use crate::memory; pub fn shutdown_qemu() { - outw(0x604, 0x2000); -} - -#[inline(always)] -pub fn outw(port: u32, value: u16) -{ - unsafe - { - asm!("out dx, ax", in("dx") port, in("ax") value, - options(nomem, nostack, preserves_flags)); - } -} - -#[inline(always)] -pub fn inb(port: u32) -> u8 -{ - let ret: u8; - unsafe - { - asm!("in al, dx", out("al") ret, in("dx") port, - options(nomem, nostack, preserves_flags)); - } - ret -} - -#[inline(always)] -pub fn outb(port: u32, value: u8) -{ - unsafe - { - asm!("out dx, al", in("dx") port, in("al") value, - options(nomem, nostack, preserves_flags)); - } + crate::arch::port::outw(0x604, 0x2000); } pub fn get_bit_at(input: u32, n: u8) -> bool diff --git a/src/keyboard/mod.rs b/src/keyboard/mod.rs index 0913d89..7e55b1f 100644 --- a/src/keyboard/mod.rs +++ b/src/keyboard/mod.rs @@ -1,10 +1,10 @@ -use crate::ferramenta; +use crate::arch; use crate::tty; mod azerty; mod qwerty; -const KEYBOARD_DATA: u32 = 0x60; +const KEYBOARD_DATA: u16 = 0x60; const KEYBOARD_READ_STATUS: u32 = 0x64; const KEYBOARD_WRITE_COMMAND: u32 = 0x64; @@ -54,7 +54,7 @@ pub fn get_scancodes() let mut scancode: u8 = 0; loop { - let new_scancode = ferramenta::inb(KEYBOARD_DATA); + let new_scancode = arch::port::inb(KEYBOARD_DATA); if new_scancode == scancode { diff --git a/src/serial.rs b/src/serial.rs index 79558b5..e0b2287 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -1,5 +1,5 @@ use core::fmt; -use crate::ferramenta::{inb, outb}; +use crate::arch::port::{inb, outb}; #[macro_export] macro_rules! serial_print @@ -14,15 +14,15 @@ macro_rules! serial_println ($($arg:tt)*) => ($crate::serial_print!("{}\n", format_args!($($arg)*))); } -pub const COM1: u32 = 0x3f8; +pub const COM1: u16 = 0x3f8; -fn check_serial_chip(port: u32) -> bool +fn check_serial_chip(port: u16) -> bool { outb(port, 0xAE); inb(port) == 0xAE } -pub fn init(port: u32) -> bool +pub fn init(port: u16) -> bool { unsafe { @@ -50,18 +50,18 @@ pub fn init(port: u32) -> bool return true; } -fn is_transmit_empty(port: u32) -> u8 { +fn is_transmit_empty(port: u16) -> u8 { return inb(port + 5) & 0x20; } -pub fn write(a: u8, port: u32) { +pub fn write(a: u8, port: u16) { while is_transmit_empty(port) == 0 { } outb(port, a); } struct Serial { - port: u32, + port: u16, pos_x: usize } diff --git a/src/vga/cursor.rs b/src/vga/cursor.rs index 0768387..cf710a6 100644 --- a/src/vga/cursor.rs +++ b/src/vga/cursor.rs @@ -1,8 +1,8 @@ -use crate::ferramenta::{inb, outb}; +use crate::arch::port::{inb, outb}; use crate::vga::BUFFER_WIDTH; -const CRT_ADDR_REG: u32 = 0x3D4; -const CRT_DATA_REG: u32 = 0x3D5; +const CRT_ADDR_REG: u16 = 0x3D4; +const CRT_DATA_REG: u16 = 0x3D5; const CURSOR_START_REG: u8 = 0x0A; const CURSOR_END_REG: u8 = 0x0B;