Transition the code to Rust 2018

This commit is contained in:
Philipp Oppermann
2018-11-18 13:44:21 +01:00
parent 5091491a1f
commit 6e5ebc4bd9
10 changed files with 16 additions and 48 deletions

View File

@@ -2,6 +2,7 @@
authors = ["Philipp Oppermann <dev@phil-opp.com>"] authors = ["Philipp Oppermann <dev@phil-opp.com>"]
name = "blog_os" name = "blog_os"
version = "0.2.0" version = "0.2.0"
edition = "2018"
[dependencies] [dependencies]
bootloader = "0.3.4" bootloader = "0.3.4"

View File

@@ -2,11 +2,7 @@
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
// add the library as dependency (same crate name as executable) use blog_os::{exit_qemu, serial_println};
#[macro_use]
extern crate blog_os;
use blog_os::exit_qemu;
use core::panic::PanicInfo; use core::panic::PanicInfo;
/// This function is the entry point, since the linker looks for a function /// This function is the entry point, since the linker looks for a function

View File

@@ -3,12 +3,7 @@
#![cfg_attr(not(test), no_main)] #![cfg_attr(not(test), no_main)]
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
#[macro_use] use blog_os::{exit_qemu, serial_println};
extern crate blog_os;
extern crate x86_64;
extern crate lazy_static;
use blog_os::exit_qemu;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use core::sync::atomic::{AtomicUsize, Ordering}; use core::sync::atomic::{AtomicUsize, Ordering};
use lazy_static::lazy_static; use lazy_static::lazy_static;

View File

@@ -3,12 +3,7 @@
#![cfg_attr(not(test), no_main)] #![cfg_attr(not(test), no_main)]
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
#[macro_use] use blog_os::{exit_qemu, serial_println};
extern crate blog_os;
extern crate x86_64;
extern crate lazy_static;
use blog_os::exit_qemu;
use core::panic::PanicInfo; use core::panic::PanicInfo;
use lazy_static::lazy_static; use lazy_static::lazy_static;

View File

@@ -2,10 +2,7 @@
#![cfg_attr(not(test), no_main)] #![cfg_attr(not(test), no_main)]
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
#[macro_use] use blog_os::{exit_qemu, serial_println};
extern crate blog_os;
use blog_os::exit_qemu;
use core::panic::PanicInfo; use core::panic::PanicInfo;
#[cfg(not(test))] #[cfg(not(test))]

View File

@@ -4,7 +4,7 @@
// problem we skip compilation of this module on Windows. // problem we skip compilation of this module on Windows.
#![cfg(not(windows))] #![cfg(not(windows))]
use gdt; use crate::gdt;
use pic8259_simple::ChainedPics; use pic8259_simple::ChainedPics;
use spin; use spin;
use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable}; use x86_64::structures::idt::{ExceptionStackFrame, InterruptDescriptorTable};
@@ -48,7 +48,7 @@ extern "x86-interrupt" fn double_fault_handler(
stack_frame: &mut ExceptionStackFrame, stack_frame: &mut ExceptionStackFrame,
_error_code: u64, _error_code: u64,
) { ) {
use hlt_loop; use crate::hlt_loop;
println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame); println!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
hlt_loop(); hlt_loop();

View File

@@ -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)] #![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] #[macro_use]
pub mod vga_buffer; pub mod vga_buffer;
pub mod gdt; pub mod gdt;

View File

@@ -2,12 +2,10 @@
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] #![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 core::panic::PanicInfo;
use blog_os::println;
/// This function is the entry point, since the linker looks for a function /// This function is the entry point, since the linker looks for a function
/// named `_start` by default. /// named `_start` by default.
#[cfg(not(test))] #[cfg(not(test))]

View File

@@ -33,7 +33,7 @@ macro_rules! serial_print {
/// Prints to the host through the serial interface, appending a newline. /// Prints to the host through the serial interface, appending a newline.
#[macro_export] #[macro_export]
macro_rules! serial_println { macro_rules! serial_println {
() => (serial_print!("\n")); () => ($crate::serial_print!("\n"));
($fmt:expr) => (serial_print!(concat!($fmt, "\n"))); ($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (serial_print!(concat!($fmt, "\n"), $($arg)*)); ($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(concat!($fmt, "\n"), $($arg)*));
} }

View File

@@ -157,9 +157,9 @@ macro_rules! print {
/// Like the `print!` macro in the standard library, but prints to the VGA text buffer. /// Like the `print!` macro in the standard library, but prints to the VGA text buffer.
#[macro_export] #[macro_export]
macro_rules! println { macro_rules! println {
() => (print!("\n")); () => ($crate::print!("\n"));
($fmt:expr) => (print!(concat!($fmt, "\n"))); ($fmt:expr) => ($crate::print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); ($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. /// Prints the given formatted string to the VGA text buffer through the global `WRITER` instance.