Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions src/arch/i686/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod gdt;
pub mod port;

pub fn init()
{
gdt::init();
}
61 changes: 61 additions & 0 deletions src/arch/i686/port.rs
Original file line number Diff line number Diff line change
@@ -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));
}
}
9 changes: 9 additions & 0 deletions src/arch/initial.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[cfg(target_arch = "x86")]
use super::i686;

#[cfg(target_arch = "x86")]
#[inline(always)]
pub fn init()
{
i686::init();
}
7 changes: 7 additions & 0 deletions src/arch/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub mod initial;

#[cfg(target_arch = "x86")]
mod i686;

#[cfg(target_arch = "x86")]
pub use i686::port;
4 changes: 2 additions & 2 deletions src/elsos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
35 changes: 1 addition & 34 deletions src/ferramenta.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/keyboard/mod.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
{
Expand Down
14 changes: 7 additions & 7 deletions src/serial.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::fmt;
use crate::ferramenta::{inb, outb};
use crate::arch::port::{inb, outb};

#[macro_export]
macro_rules! serial_print
Expand All @@ -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
{
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions src/vga/cursor.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down