redox/arch/x86_64/src/lib.rs

173 lines
3.6 KiB
Rust
Raw Normal View History

2016-08-14 19:45:47 +02:00
//! Architecture support for x86_64
#![feature(asm)]
#![feature(concat_idents)]
2016-08-14 19:45:47 +02:00
#![feature(const_fn)]
#![feature(core_intrinsics)]
2016-09-01 19:51:33 +02:00
#![feature(drop_types_in_const)]
#![feature(lang_items)]
2016-08-14 19:45:47 +02:00
#![feature(naked_functions)]
#![feature(thread_local)]
#![feature(unique)]
2016-08-14 19:45:47 +02:00
#![no_std]
2016-08-15 23:27:32 +02:00
extern crate hole_list_allocator as allocator;
2016-09-01 22:39:45 +02:00
2016-08-14 19:45:47 +02:00
#[macro_use]
extern crate bitflags;
2016-09-01 19:51:33 +02:00
extern crate ransid;
extern crate spin;
pub extern crate x86;
2016-08-14 19:45:47 +02:00
/// Print to console
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
2016-08-18 01:24:10 +02:00
use core::fmt::Write;
2016-09-02 01:08:43 +02:00
let mut console = $crate::console::CONSOLE.lock();
let _ = write!(console, $($arg)*);
2016-08-14 19:45:47 +02:00
});
}
/// Print with new line to console
#[macro_export]
macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}
/// Create an interrupt function that can safely run rust code
#[macro_export]
macro_rules! interrupt {
($name:ident, $func:block) => {
#[naked]
pub unsafe extern fn $name () {
#[inline(never)]
unsafe fn inner() {
$func
}
// Push scratch registers
asm!("xchg bx, bx
push rax
push rcx
push rdx
push rdi
push rsi
push r8
push r9
push r10
push r11
push fs
mov rax, 0x18
mov fs, ax"
: : : : "intel", "volatile");
// Call inner rust function
inner();
// Pop scratch registers and return
asm!("xchg bx, bx
pop fs
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rdi
pop rdx
pop rcx
pop rax
iretq"
: : : : "intel", "volatile");
}
};
}
#[macro_export]
macro_rules! interrupt_error {
($name:ident, $func:block) => {
#[naked]
pub unsafe extern fn $name () {
#[inline(never)]
unsafe fn inner() {
$func
}
// Push scratch registers
asm!("xchg bx, bx
push rax
push rcx
push rdx
push rdi
push rsi
push r8
push r9
push r10
push r11
push fs
mov rax, 0x18
mov fs, ax"
: : : : "intel", "volatile");
// Call inner rust function
inner();
// Pop scratch registers, error code, and return
asm!("xchg bx, bx
pop fs
pop r11
pop r10
pop r9
pop r8
pop rsi
pop rdi
pop rdx
pop rcx
pop rax
add rsp, 8
iretq"
: : : : "intel", "volatile");
}
};
}
/// ACPI table parsing
pub mod acpi;
2016-09-01 19:51:33 +02:00
/// Console handling
pub mod console;
2016-08-23 03:56:35 +02:00
/// Context switching
pub mod context;
/// Devices
pub mod device;
2016-08-25 04:10:55 +02:00
/// Memcpy, memmove, etc.
pub mod externs;
2016-08-14 19:45:47 +02:00
/// Global descriptor table
pub mod gdt;
/// Interrupt descriptor table
pub mod idt;
/// IO Handling
pub mod io;
/// Interrupt instructions
pub mod interrupt;
/// Memory management
pub mod memory;
/// Paging
pub mod paging;
2016-08-14 19:45:47 +02:00
/// Panic
pub mod panic;
2016-08-15 23:32:33 +02:00
/// Initialization and start function
pub mod start;