From 6e5ebc4bd9837f9300bb565cd60b330bc5c0bba8 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 18 Nov 2018 13:44:21 +0100 Subject: [PATCH] Transition the code to Rust 2018 --- Cargo.toml | 1 + src/bin/test-basic-boot.rs | 6 +----- src/bin/test-exception-breakpoint.rs | 7 +------ ...test-exception-double-fault-stack-overflow.rs | 7 +------ src/bin/test-panic.rs | 5 +---- src/interrupts.rs | 4 ++-- src/lib.rs | 16 +--------------- src/main.rs | 6 ++---- src/serial.rs | 6 +++--- src/vga_buffer.rs | 6 +++--- 10 files changed, 16 insertions(+), 48 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 730970f8..14c71a44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ authors = ["Philipp Oppermann "] name = "blog_os" version = "0.2.0" +edition = "2018" [dependencies] bootloader = "0.3.4" diff --git a/src/bin/test-basic-boot.rs b/src/bin/test-basic-boot.rs index 9b891aad..f4acda07 100644 --- a/src/bin/test-basic-boot.rs +++ b/src/bin/test-basic-boot.rs @@ -2,11 +2,7 @@ #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -// add the library as dependency (same crate name as executable) -#[macro_use] -extern crate blog_os; - -use blog_os::exit_qemu; +use blog_os::{exit_qemu, serial_println}; use core::panic::PanicInfo; /// This function is the entry point, since the linker looks for a function diff --git a/src/bin/test-exception-breakpoint.rs b/src/bin/test-exception-breakpoint.rs index 5f6db24c..fc3091e4 100644 --- a/src/bin/test-exception-breakpoint.rs +++ b/src/bin/test-exception-breakpoint.rs @@ -3,12 +3,7 @@ #![cfg_attr(not(test), no_main)] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -#[macro_use] -extern crate blog_os; -extern crate x86_64; -extern crate lazy_static; - -use blog_os::exit_qemu; +use blog_os::{exit_qemu, serial_println}; use core::panic::PanicInfo; use core::sync::atomic::{AtomicUsize, Ordering}; use lazy_static::lazy_static; diff --git a/src/bin/test-exception-double-fault-stack-overflow.rs b/src/bin/test-exception-double-fault-stack-overflow.rs index 673a8037..3d934a4c 100644 --- a/src/bin/test-exception-double-fault-stack-overflow.rs +++ b/src/bin/test-exception-double-fault-stack-overflow.rs @@ -3,12 +3,7 @@ #![cfg_attr(not(test), no_main)] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -#[macro_use] -extern crate blog_os; -extern crate x86_64; -extern crate lazy_static; - -use blog_os::exit_qemu; +use blog_os::{exit_qemu, serial_println}; use core::panic::PanicInfo; use lazy_static::lazy_static; diff --git a/src/bin/test-panic.rs b/src/bin/test-panic.rs index 64131b86..62ed7d7f 100644 --- a/src/bin/test-panic.rs +++ b/src/bin/test-panic.rs @@ -2,10 +2,7 @@ #![cfg_attr(not(test), no_main)] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -#[macro_use] -extern crate blog_os; - -use blog_os::exit_qemu; +use blog_os::{exit_qemu, serial_println}; use core::panic::PanicInfo; #[cfg(not(test))] diff --git a/src/interrupts.rs b/src/interrupts.rs index 728e6853..eec59ab6 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -4,7 +4,7 @@ // problem we skip compilation of this module on Windows. #![cfg(not(windows))] -use gdt; +use crate::gdt; use pic8259_simple::ChainedPics; use spin; use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable}; @@ -48,7 +48,7 @@ extern "x86-interrupt" fn double_fault_handler( stack_frame: &mut ExceptionStackFrame, _error_code: u64, ) { - use hlt_loop; + use crate::hlt_loop; println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); hlt_loop(); diff --git a/src/lib.rs b/src/lib.rs index 31a702a6..e806c7c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,6 @@ -#![no_std] // don't link the Rust standard library +#![cfg_attr(not(test), no_std)] // don't link the Rust standard library #![feature(abi_x86_interrupt)] -extern crate bootloader; -extern crate spin; -extern crate volatile; -extern crate lazy_static; -extern crate pic8259_simple; -extern crate uart_16550; -extern crate x86_64; -extern crate pc_keyboard; - -#[cfg(test)] -extern crate array_init; -#[cfg(test)] -extern crate std; - #[macro_use] pub mod vga_buffer; pub mod gdt; diff --git a/src/main.rs b/src/main.rs index c9890b1b..004c9dc5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,12 +2,10 @@ #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -#[macro_use] -extern crate blog_os; -extern crate x86_64; - use core::panic::PanicInfo; +use blog_os::println; + /// This function is the entry point, since the linker looks for a function /// named `_start` by default. #[cfg(not(test))] diff --git a/src/serial.rs b/src/serial.rs index 494273c9..b89b843a 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -33,7 +33,7 @@ macro_rules! serial_print { /// Prints to the host through the serial interface, appending a newline. #[macro_export] macro_rules! serial_println { - () => (serial_print!("\n")); - ($fmt:expr) => (serial_print!(concat!($fmt, "\n"))); - ($fmt:expr, $($arg:tt)*) => (serial_print!(concat!($fmt, "\n"), $($arg)*)); + () => ($crate::serial_print!("\n")); + ($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(concat!($fmt, "\n"), $($arg)*)); } diff --git a/src/vga_buffer.rs b/src/vga_buffer.rs index 9c245190..e63c4077 100644 --- a/src/vga_buffer.rs +++ b/src/vga_buffer.rs @@ -157,9 +157,9 @@ macro_rules! print { /// Like the `print!` macro in the standard library, but prints to the VGA text buffer. #[macro_export] macro_rules! println { - () => (print!("\n")); - ($fmt:expr) => (print!(concat!($fmt, "\n"))); - ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); + () => ($crate::print!("\n")); + ($fmt:expr) => ($crate::print!(concat!($fmt, "\n"))); + ($fmt:expr, $($arg:tt)*) => ($crate::print!(concat!($fmt, "\n"), $($arg)*)); } /// Prints the given formatted string to the VGA text buffer through the global `WRITER` instance.