Merge pull request #43 from cookie545445/machdep
Move x86_64-specific code to arch/x86_64
This commit is contained in:
5
src/arch/mod.rs
Normal file
5
src/arch/mod.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[macro_use]
|
||||
pub mod x86_64;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub use self::x86_64::*;
|
||||
11
src/arch/x86_64/device/serial.rs
Normal file
11
src/arch/x86_64/device/serial.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
use devices::uart_16550::SerialPort;
|
||||
use syscall::io::Pio;
|
||||
use spin::Mutex;
|
||||
|
||||
pub static COM1: Mutex<SerialPort<Pio<u8>>> = Mutex::new(SerialPort::<Pio<u8>>::new(0x3F8));
|
||||
pub static COM2: Mutex<SerialPort<Pio<u8>>> = Mutex::new(SerialPort::<Pio<u8>>::new(0x2F8));
|
||||
|
||||
pub unsafe fn init() {
|
||||
COM1.lock().init();
|
||||
COM2.lock().init();
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => ({
|
||||
use core::fmt::Write;
|
||||
let _ = write!($crate::device::serial::COM1.lock(), $($arg)*);
|
||||
let _ = write!($crate::arch::device::serial::COM1.lock(), $($arg)*);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ macro_rules! interrupt_stack {
|
||||
#[naked]
|
||||
pub unsafe extern fn $name () {
|
||||
#[inline(never)]
|
||||
unsafe fn inner($stack: &mut $crate::macros::InterruptStack) {
|
||||
unsafe fn inner($stack: &mut $crate::arch::x86_64::macros::InterruptStack) {
|
||||
$func
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ macro_rules! interrupt_stack {
|
||||
asm!("" : "={rsp}"(rsp) : : : "intel", "volatile");
|
||||
|
||||
// Call inner rust function
|
||||
inner(&mut *(rsp as *mut $crate::macros::InterruptStack));
|
||||
inner(&mut *(rsp as *mut $crate::arch::x86_64::macros::InterruptStack));
|
||||
|
||||
// Pop scratch registers and return
|
||||
asm!("pop fs
|
||||
@@ -153,7 +153,7 @@ macro_rules! interrupt_error {
|
||||
#[naked]
|
||||
pub unsafe extern fn $name () {
|
||||
#[inline(never)]
|
||||
unsafe fn inner($stack: &$crate::macros::InterruptErrorStack) {
|
||||
unsafe fn inner($stack: &$crate::arch::x86_64::macros::InterruptErrorStack) {
|
||||
$func
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ macro_rules! interrupt_error {
|
||||
asm!("" : "={rsp}"(rsp) : : : "intel", "volatile");
|
||||
|
||||
// Call inner rust function
|
||||
inner(&*(rsp as *const $crate::macros::InterruptErrorStack));
|
||||
inner(&*(rsp as *const $crate::arch::x86_64::macros::InterruptErrorStack));
|
||||
|
||||
// Pop scratch registers, error code, and return
|
||||
asm!("pop fs
|
||||
23
src/arch/x86_64/mod.rs
Normal file
23
src/arch/x86_64/mod.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
|
||||
/// Devices
|
||||
pub mod device;
|
||||
|
||||
/// Global descriptor table
|
||||
pub mod gdt;
|
||||
|
||||
/// Interrupt descriptor table
|
||||
pub mod idt;
|
||||
|
||||
/// Interrupt instructions
|
||||
pub mod interrupt;
|
||||
|
||||
/// Paging
|
||||
pub mod paging;
|
||||
|
||||
/// Initialization and start function
|
||||
pub mod start;
|
||||
|
||||
/// Stop function
|
||||
pub mod stop;
|
||||
1
src/devices/mod.rs
Normal file
1
src/devices/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod uart_16550;
|
||||
@@ -1,16 +1,7 @@
|
||||
use core::fmt::{self, Write};
|
||||
use spin::Mutex;
|
||||
|
||||
use scheme::debug::debug_input;
|
||||
use syscall::io::{Io, Pio, ReadOnly};
|
||||
|
||||
pub static COM1: Mutex<SerialPort> = Mutex::new(SerialPort::new(0x3F8));
|
||||
pub static COM2: Mutex<SerialPort> = Mutex::new(SerialPort::new(0x2F8));
|
||||
|
||||
pub unsafe fn init() {
|
||||
COM1.lock().init();
|
||||
COM2.lock().init();
|
||||
}
|
||||
use syscall::io::{Io, Pio, Mmio, ReadOnly};
|
||||
|
||||
bitflags! {
|
||||
/// Interrupt enable flags
|
||||
@@ -34,25 +25,25 @@ bitflags! {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct SerialPort {
|
||||
pub struct SerialPort<T: Io<Value = u8>> {
|
||||
/// Data register, read to receive, write to send
|
||||
data: Pio<u8>,
|
||||
data: T,
|
||||
/// Interrupt enable
|
||||
int_en: Pio<u8>,
|
||||
int_en: T,
|
||||
/// FIFO control
|
||||
fifo_ctrl: Pio<u8>,
|
||||
fifo_ctrl: T,
|
||||
/// Line control
|
||||
line_ctrl: Pio<u8>,
|
||||
line_ctrl: T,
|
||||
/// Modem control
|
||||
modem_ctrl: Pio<u8>,
|
||||
modem_ctrl: T,
|
||||
/// Line status
|
||||
line_sts: ReadOnly<Pio<u8>>,
|
||||
line_sts: ReadOnly<T>,
|
||||
/// Modem status
|
||||
modem_sts: ReadOnly<Pio<u8>>,
|
||||
modem_sts: ReadOnly<T>,
|
||||
}
|
||||
|
||||
impl SerialPort {
|
||||
const fn new(base: u16) -> SerialPort {
|
||||
impl SerialPort<Pio<u8>> {
|
||||
pub const fn new(base: u16) -> SerialPort<Pio<u8>> {
|
||||
SerialPort {
|
||||
data: Pio::new(base),
|
||||
int_en: Pio::new(base + 1),
|
||||
@@ -63,8 +54,24 @@ impl SerialPort {
|
||||
modem_sts: ReadOnly::new(Pio::new(base + 6))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn init(&mut self) {
|
||||
impl SerialPort<Mmio<u8>> {
|
||||
pub fn new(base: usize) -> SerialPort<Mmio<u8>> {
|
||||
SerialPort {
|
||||
data: Mmio::new(),
|
||||
int_en: Mmio::new(),
|
||||
fifo_ctrl: Mmio::new(),
|
||||
line_ctrl: Mmio::new(),
|
||||
modem_ctrl: Mmio::new(),
|
||||
line_sts: ReadOnly::new(Mmio::new()),
|
||||
modem_sts: ReadOnly::new(Mmio::new())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Io<Value = u8>> SerialPort<T> {
|
||||
pub fn init(&mut self) {
|
||||
//TODO: Cleanup
|
||||
self.int_en.write(0x00);
|
||||
self.line_ctrl.write(0x80);
|
||||
@@ -104,7 +111,7 @@ impl SerialPort {
|
||||
}
|
||||
}
|
||||
|
||||
impl Write for SerialPort {
|
||||
impl<T: Io<Value = u8>> Write for SerialPort<T> {
|
||||
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
|
||||
for byte in s.bytes() {
|
||||
self.send(byte);
|
||||
27
src/lib.rs
27
src/lib.rs
@@ -42,9 +42,10 @@ pub use consts::*;
|
||||
/// Shared data structures
|
||||
pub mod common;
|
||||
|
||||
/// Macros like print, println, and interrupt
|
||||
/// Architecture-dependent stuff
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
pub mod arch;
|
||||
pub use arch::*;
|
||||
|
||||
/// Constants like memory locations
|
||||
pub mod consts;
|
||||
@@ -55,8 +56,8 @@ mod acpi;
|
||||
/// Context management
|
||||
pub mod context;
|
||||
|
||||
/// Devices
|
||||
pub mod device;
|
||||
/// Architecture-independent devices
|
||||
pub mod devices;
|
||||
|
||||
/// ELF file parsing
|
||||
pub mod elf;
|
||||
@@ -64,33 +65,15 @@ pub mod elf;
|
||||
/// External functions
|
||||
pub mod externs;
|
||||
|
||||
/// Global descriptor table
|
||||
pub mod gdt;
|
||||
|
||||
/// Interrupt descriptor table
|
||||
mod idt;
|
||||
|
||||
/// Interrupt instructions
|
||||
pub mod interrupt;
|
||||
|
||||
/// Memory management
|
||||
pub mod memory;
|
||||
|
||||
/// Paging
|
||||
pub mod paging;
|
||||
|
||||
/// Panic
|
||||
pub mod panic;
|
||||
|
||||
/// Schemes, filesystem handlers
|
||||
pub mod scheme;
|
||||
|
||||
/// Initialization and start function
|
||||
pub mod start;
|
||||
|
||||
/// Shutdown function
|
||||
pub mod stop;
|
||||
|
||||
/// Synchronization primitives
|
||||
pub mod sync;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user