From de60bf2b2c6933b39cda7916978ac9bce8a40254 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 27 Jul 2021 10:05:34 +0200 Subject: [PATCH 1/3] Remove volatile crate --- Cargo.lock | 9 +-------- Cargo.toml | 1 - src/sys/vga.rs | 26 +++++++++++++++++--------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f137076f..fb0c39c8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -237,7 +237,6 @@ dependencies = [ "spin 0.9.2", "time", "uart_16550", - "volatile 0.2.7", "vte", "x86_64", ] @@ -503,12 +502,6 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -[[package]] -name = "volatile" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945" - [[package]] name = "volatile" version = "0.4.4" @@ -544,5 +537,5 @@ checksum = "d95947de37ad0d2d9a4a4dd22e0d042e034e5cbd7ab53edbca0d8035e0a6a64d" dependencies = [ "bit_field 0.9.0", "bitflags", - "volatile 0.4.4", + "volatile", ] diff --git a/Cargo.toml b/Cargo.toml index 70e1e9c53..c9b8d5a84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,7 +41,6 @@ smoltcp = { version = "0.7.5", default-features = false, features = ["alloc", "e spin = "0.9.2" time = { version = "0.2.27", default-features = false } uart_16550 = "0.2.15" -volatile = "0.2.6" vte = "0.10.1" x86_64 = "0.14.4" diff --git a/src/sys/vga.rs b/src/sys/vga.rs index acca5b2f5..1679d04c7 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -6,7 +6,6 @@ use core::fmt; use core::fmt::Write; use lazy_static::lazy_static; use spin::Mutex; -use volatile::Volatile; use vte::{Params, Parser, Perform}; use x86_64::instructions::interrupts; use x86_64::instructions::port::Port; @@ -49,7 +48,7 @@ const BUFFER_WIDTH: usize = 80; #[repr(transparent)] struct Buffer { - chars: [[Volatile; BUFFER_WIDTH]; BUFFER_HEIGHT], + chars: [[ScreenChar; BUFFER_WIDTH]; BUFFER_HEIGHT], } pub struct Writer { @@ -115,13 +114,15 @@ impl Writer { 0x08 => { // Backspace if self.writer[0] > 0 { self.writer[0] -= 1; - let blank = ScreenChar { + let c = ScreenChar { ascii_code: b' ', color_code: self.color_code, }; let x = self.writer[0]; let y = self.writer[1]; - self.buffer.chars[y][x].write(blank); + unsafe { + core::ptr::write_volatile(&mut self.buffer.chars[y][x], c); + } } }, byte => { @@ -133,7 +134,10 @@ impl Writer { let y = self.writer[1]; let ascii_code = if is_printable(byte) { byte } else { UNPRINTABLE }; let color_code = self.color_code; - self.buffer.chars[y][x].write(ScreenChar { ascii_code, color_code }); + let c = ScreenChar { ascii_code, color_code }; + unsafe { + core::ptr::write_volatile(&mut self.buffer.chars[y][x], c); + } self.writer[0] += 1; } } @@ -145,8 +149,10 @@ impl Writer { } else { for y in 1..BUFFER_HEIGHT { for x in 0..BUFFER_WIDTH { - let character = self.buffer.chars[y][x].read(); - self.buffer.chars[y - 1][x].write(character); + unsafe { + let c = core::ptr::read_volatile(&mut self.buffer.chars[y][x]); + core::ptr::write_volatile(&mut self.buffer.chars[y - 1][x], c); + } } } self.clear_row_after(0, BUFFER_HEIGHT - 1); @@ -155,12 +161,14 @@ impl Writer { } fn clear_row_after(&mut self, x: usize, y: usize) { - let blank = ScreenChar { + let c = ScreenChar { ascii_code: b' ', color_code: self.color_code, }; for i in x..BUFFER_WIDTH { - self.buffer.chars[y][i].write(blank); + unsafe { + core::ptr::write_volatile(&mut self.buffer.chars[y][i], c); + } } } From 49c78ddc0b3329fbf4d05bd752443e4bdb949b93 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 27 Jul 2021 10:08:33 +0200 Subject: [PATCH 2/3] Fix whitespace --- src/sys/vga.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index 1679d04c7..8a5580c50 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -150,7 +150,7 @@ impl Writer { for y in 1..BUFFER_HEIGHT { for x in 0..BUFFER_WIDTH { unsafe { - let c = core::ptr::read_volatile(&mut self.buffer.chars[y][x]); + let c = core::ptr::read_volatile(&mut self.buffer.chars[y][x]); core::ptr::write_volatile(&mut self.buffer.chars[y - 1][x], c); } } From 632a74954ea3590b2205d98f5ccf992253e6ac02 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 27 Jul 2021 10:16:03 +0200 Subject: [PATCH 3/3] Remove mut in read --- src/sys/vga.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index 8a5580c50..20bdbecff 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -150,7 +150,7 @@ impl Writer { for y in 1..BUFFER_HEIGHT { for x in 0..BUFFER_WIDTH { unsafe { - let c = core::ptr::read_volatile(&mut self.buffer.chars[y][x]); + let c = core::ptr::read_volatile(&self.buffer.chars[y][x]); core::ptr::write_volatile(&mut self.buffer.chars[y - 1][x], c); } }