From 6d8ddf91c2bf02ec916f4a5da4f3817d16d94d05 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 17 Oct 2021 13:04:45 +0200 Subject: [PATCH 01/13] Enable cursor after boot --- src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.rs b/src/main.rs index 4dc26680..14fae30d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ entry_point!(main); fn main(boot_info: &'static BootInfo) -> ! { moros::init(boot_info); + print!("\x1b[?25h"); // Enable cursor loop { let bootrc = "/ini/boot.sh"; if sys::fs::File::open(bootrc).is_some() { From f3b5e5c259b8e1ba2cf45107eb00e499748861e8 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 17 Oct 2021 18:58:09 +0200 Subject: [PATCH 02/13] Remove unused time attribute on file --- src/sys/fs/file.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/sys/fs/file.rs b/src/sys/fs/file.rs index cd17f9d9..f42d983c 100644 --- a/src/sys/fs/file.rs +++ b/src/sys/fs/file.rs @@ -18,7 +18,6 @@ pub struct File { name: String, addr: u32, size: u32, - time: u64, dir: Dir, // TODO: Replace with `parent: Some(Dir)` and also add it to `Dir` offset: u32, } @@ -29,7 +28,6 @@ impl From for File { name: entry.name(), addr: entry.addr(), size: entry.size(), - time: entry.time(), dir: entry.dir(), offset: 0, } From 4c2cc9969647c6a00c137c7091090fa223322c95 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 17 Oct 2021 18:58:36 +0200 Subject: [PATCH 03/13] Fix compilation warning --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 651969e7..247a685c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,6 @@ #![cfg_attr(test, no_main)] #![feature(abi_x86_interrupt)] #![feature(alloc_error_handler)] -#![feature(array_map)] #![feature(asm)] #![feature(naked_functions)] #![feature(custom_test_frameworks)] From 7fac3ff7e43476eb49c1ad84e66c43948cb3dfbd Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 19 Oct 2021 09:09:33 +0200 Subject: [PATCH 04/13] Clear screen after vga init --- src/sys/vga.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index 46fa446b..a2fa9836 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -192,6 +192,12 @@ impl Writer { } } + fn clear_screen(&mut self) { + for y in 0..BUFFER_HEIGHT { + self.clear_row_after(0, y); + } + } + pub fn set_color(&mut self, foreground: Color, background: Color) { self.color_code = ColorCode::new(foreground, background); } @@ -244,15 +250,20 @@ impl Writer { let code = color::from_index(i as usize).to_palette_code(); unsafe { addr.write(code); - data.write(r >> 2); // Convert 8-bit color to 6-bit color - data.write(g >> 2); - data.write(b >> 2); + data.write(vga_color(r)); + data.write(vga_color(g)); + data.write(vga_color(b)); } } } } } +// Convert 8-bit to 6-bit color +fn vga_color(color: u8) { + color >> 2 +} + /// See https://vt100.net/emu/dec_ansi_parser impl Perform for Writer { fn print(&mut self, c: char) { @@ -356,11 +367,7 @@ impl Perform for Writer { } match n { // TODO: 0 and 1, from cursor to begining or to end of screen - 2 => { - for y in 0..BUFFER_HEIGHT { - self.clear_row_after(0, y); - } - } + 2 => self.clear_screen(), _ => return, } self.set_writer_position(0, 0); @@ -474,4 +481,5 @@ pub fn init() { let value = adrr.read(); // Read attribute mode control register aadr.write(value & !0x08); // Use `value | 0x08` to enable and `value ^ 0x08` to toggle } + WRITER.lock().clear_screen(); } From b34ebd0ba4f7a227c3b2752f6c4fc812dccec73a Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Tue, 19 Oct 2021 09:13:25 +0200 Subject: [PATCH 05/13] Add disable_blinking function --- src/sys/vga.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index a2fa9836..f6bb9020 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -260,7 +260,7 @@ impl Writer { } // Convert 8-bit to 6-bit color -fn vga_color(color: u8) { +fn vga_color(color: u8) -> u8 { color >> 2 } @@ -469,17 +469,32 @@ pub fn set_palette(palette: Palette) { }) } -pub fn init() { +fn disable_blinking() { let mut isr: Port = Port::new(INPUT_STATUS_REG); let mut aadr: Port = Port::new(ATTR_ADDR_DATA_REG); let mut adrr: Port = Port::new(ATTR_DATA_READ_REG); - - // Disable blinking unsafe { isr.read(); // Reset to address mode aadr.write(0x30); // Select attribute mode control register let value = adrr.read(); // Read attribute mode control register aadr.write(value & !0x08); // Use `value | 0x08` to enable and `value ^ 0x08` to toggle } +} + +// 0x00 -> top +// 0x0F -> bottom +// 0x1F -> max (invisible) +fn set_underline_location(location: u8) { + let mut addr: Port = Port::new(CRTC_ADDR_REG); + let mut data: Port = Port::new(CRTC_DATA_REG); + unsafe { + addr.write(0x14); // Underline Location Register + data.write(location); + } +} + +pub fn init() { + disable_blinking(); + set_underline_location(0x1F); // Disable underline WRITER.lock().clear_screen(); } From 2f102a989984e9023c8f14933202593242909708 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Fri, 22 Oct 2021 19:01:25 +0200 Subject: [PATCH 06/13] Set palette registers at boot --- src/sys/vga.rs | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index f6bb9020..c3b6c496 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -15,9 +15,11 @@ use x86_64::instructions::port::Port; const ATTR_ADDR_DATA_REG: u16 = 0x3C0; const ATTR_DATA_READ_REG: u16 = 0x3C1; const SEQUENCER_ADDR_REG: u16 = 0x3C4; +const SEQUENCER_DATA_REG: u16 = 0x3C5; const DAC_ADDR_WRITE_MODE_REG: u16 = 0x3C8; const DAC_DATA_REG: u16 = 0x3C9; const GRAPHICS_ADDR_REG: u16 = 0x3CE; +const GRAPHICS_DATA_REG: u16 = 0x3CF; const CRTC_ADDR_REG: u16 = 0x3D4; const CRTC_DATA_REG: u16 = 0x3D5; const INPUT_STATUS_REG: u16 = 0x3DA; @@ -471,13 +473,15 @@ pub fn set_palette(palette: Palette) { fn disable_blinking() { let mut isr: Port = Port::new(INPUT_STATUS_REG); - let mut aadr: Port = Port::new(ATTR_ADDR_DATA_REG); - let mut adrr: Port = Port::new(ATTR_DATA_READ_REG); + let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); + let mut data: Port = Port::new(ATTR_DATA_READ_REG); + // The data register is read from the data port but must be written to the + // addr port. unsafe { isr.read(); // Reset to address mode - aadr.write(0x30); // Select attribute mode control register - let value = adrr.read(); // Read attribute mode control register - aadr.write(value & !0x08); // Use `value | 0x08` to enable and `value ^ 0x08` to toggle + addr.write(0x30); // Select attribute mode control register + let value = data.read(); // Read attribute mode control register + addr.write(value & !0x08); // Use `value | 0x08` to enable and `value ^ 0x08` to toggle } } @@ -493,7 +497,34 @@ fn set_underline_location(location: u8) { } } +fn set_palette_register(index: u8, value: u8) { + let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); + //let mut data: Port = Port::new(ATTR_DATA_READ_REG); + unsafe { + addr.write(index); + //log!("VGA Palette Register {:#x}: {:#x} -> {:#x}", index, data.read(), value); + addr.write(value); + } +} + pub fn init() { + set_palette_register(0x0, 0x00); + set_palette_register(0x1, 0x01); + set_palette_register(0x2, 0x02); + set_palette_register(0x3, 0x03); + set_palette_register(0x4, 0x04); + set_palette_register(0x5, 0x05); + set_palette_register(0x6, 0x14); + set_palette_register(0x7, 0x07); + set_palette_register(0x8, 0x38); + set_palette_register(0x9, 0x39); + set_palette_register(0xA, 0x3A); + set_palette_register(0xB, 0x3B); + set_palette_register(0xC, 0x3C); + set_palette_register(0xD, 0x3D); + set_palette_register(0xE, 0x3E); + set_palette_register(0xF, 0x3F); + disable_blinking(); set_underline_location(0x1F); // Disable underline WRITER.lock().clear_screen(); From aa243cb4f4fc17eca6f95c080f7d0dc82e1d98d2 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Fri, 22 Oct 2021 20:36:09 +0200 Subject: [PATCH 07/13] Set default palette --- src/api/vga/color.rs | 4 ++-- src/api/vga/palette.rs | 25 +++++++++++++++++++++++++ src/sys/allocator.rs | 2 +- src/sys/vga.rs | 9 +++++---- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/api/vga/color.rs b/src/api/vga/color.rs index d4509456..d92d01c8 100644 --- a/src/api/vga/color.rs +++ b/src/api/vga/color.rs @@ -71,7 +71,7 @@ pub fn from_ansi(code: u8) -> Color { } impl Color { - pub fn to_palette_code(&self) -> u8 { + pub fn to_vga_reg(&self) -> u8 { match self { Color::Black => 0x00, Color::Blue => 0x01, @@ -79,8 +79,8 @@ impl Color { Color::Cyan => 0x03, Color::Red => 0x04, Color::Magenta => 0x05, - Color::LightGray => 0x07, Color::Brown => 0x14, + Color::LightGray => 0x07, Color::DarkGray => 0x38, Color::LightBlue => 0x39, Color::LightGreen => 0x3A, diff --git a/src/api/vga/palette.rs b/src/api/vga/palette.rs index 36c94807..42c068bb 100644 --- a/src/api/vga/palette.rs +++ b/src/api/vga/palette.rs @@ -5,6 +5,31 @@ pub struct Palette { pub colors: [(u8, u8, u8, u8); 16] } +impl Palette { + pub fn default() -> Palette { + Palette { + colors: [ + (0x00, 0x00, 0x00, 0x00), // Black + (0x01, 0x00, 0x00, 0x80), // Blue + (0x02, 0x00, 0x80, 0x00), // Green + (0x03, 0x00, 0x80, 0x80), // Cyan + (0x04, 0x80, 0x00, 0x00), // Red + (0x05, 0x80, 0x00, 0x80), // Magenta + (0x06, 0x80, 0x80, 0x00), // Brown (Dark Yellow) + (0x07, 0xC0, 0xC0, 0xC0), // Light Gray + (0x08, 0x80, 0x80, 0x80), // Dark Gray (Gray) + (0x09, 0x00, 0x00, 0xFF), // Light Blue + (0x0A, 0x00, 0xFF, 0x00), // Light Green + (0x0B, 0x00, 0xFF, 0xFF), // Light Cyan + (0x0C, 0xFF, 0x00, 0x00), // Light Red + (0x0D, 0xFF, 0x00, 0xFF), // Pink (Light Magenta) + (0x0E, 0xFF, 0xFF, 0x00), // Yellow (Light Yellow) + (0x0F, 0xFF, 0xFF, 0xFF), // White + ] + } + } +} + pub fn from_csv(s: &str) -> Result { let colors: Vec<_> = s.split('\n').filter_map(|line| { let line = line.split('#').next().unwrap(); // Remove comments diff --git a/src/sys/allocator.rs b/src/sys/allocator.rs index f3b57a02..a3df1dd9 100644 --- a/src/sys/allocator.rs +++ b/src/sys/allocator.rs @@ -17,7 +17,7 @@ pub const HEAP_START: usize = 0x4444_4444_0000; static ALLOCATOR: LockedHeap = LockedHeap::empty(); pub fn init_heap(mapper: &mut impl Mapper, frame_allocator: &mut impl FrameAllocator) -> Result<(), MapToError> { - // Use half of the memory for the heap, caped to 16 GB because the allocator is too slow + // Use half of the memory for the heap, caped to 16 MB because the allocator is too slow let heap_size = cmp::min(sys::mem::memory_size() / 2, 16 << 20); let pages = { diff --git a/src/sys/vga.rs b/src/sys/vga.rs index c3b6c496..5a52cb7c 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -15,11 +15,11 @@ use x86_64::instructions::port::Port; const ATTR_ADDR_DATA_REG: u16 = 0x3C0; const ATTR_DATA_READ_REG: u16 = 0x3C1; const SEQUENCER_ADDR_REG: u16 = 0x3C4; -const SEQUENCER_DATA_REG: u16 = 0x3C5; +// const SEQUENCER_DATA_REG: u16 = 0x3C5; const DAC_ADDR_WRITE_MODE_REG: u16 = 0x3C8; const DAC_DATA_REG: u16 = 0x3C9; const GRAPHICS_ADDR_REG: u16 = 0x3CE; -const GRAPHICS_DATA_REG: u16 = 0x3CF; +// const GRAPHICS_DATA_REG: u16 = 0x3CF; const CRTC_ADDR_REG: u16 = 0x3D4; const CRTC_DATA_REG: u16 = 0x3D5; const INPUT_STATUS_REG: u16 = 0x3DA; @@ -249,9 +249,9 @@ impl Writer { let mut data: Port = Port::new(DAC_DATA_REG); for (i, r, g, b) in palette.colors { if i < 16 { - let code = color::from_index(i as usize).to_palette_code(); + let reg = color::from_index(i as usize).to_vga_reg(); unsafe { - addr.write(code); + addr.write(reg); data.write(vga_color(r)); data.write(vga_color(g)); data.write(vga_color(b)); @@ -526,6 +526,7 @@ pub fn init() { set_palette_register(0xF, 0x3F); disable_blinking(); + set_palette(Palette::default()); set_underline_location(0x1F); // Disable underline WRITER.lock().clear_screen(); } From 8db0a2063f80b92a750b8a1ca23331d8588b30e5 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Fri, 22 Oct 2021 20:37:02 +0200 Subject: [PATCH 08/13] Fix attribute control registers initialization --- src/sys/vga.rs | 113 +++++++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 46 deletions(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index 5a52cb7c..ea01007c 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -471,62 +471,83 @@ pub fn set_palette(palette: Palette) { }) } -fn disable_blinking() { - let mut isr: Port = Port::new(INPUT_STATUS_REG); - let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); - let mut data: Port = Port::new(ATTR_DATA_READ_REG); - // The data register is read from the data port but must be written to the - // addr port. - unsafe { - isr.read(); // Reset to address mode - addr.write(0x30); // Select attribute mode control register - let value = data.read(); // Read attribute mode control register - addr.write(value & !0x08); // Use `value | 0x08` to enable and `value ^ 0x08` to toggle - } -} - // 0x00 -> top // 0x0F -> bottom // 0x1F -> max (invisible) fn set_underline_location(location: u8) { - let mut addr: Port = Port::new(CRTC_ADDR_REG); - let mut data: Port = Port::new(CRTC_DATA_REG); - unsafe { - addr.write(0x14); // Underline Location Register - data.write(location); - } + interrupts::without_interrupts(|| { + let mut addr: Port = Port::new(CRTC_ADDR_REG); + let mut data: Port = Port::new(CRTC_DATA_REG); + unsafe { + addr.write(0x14); // Underline Location Register + data.write(location); + } + }) } -fn set_palette_register(index: u8, value: u8) { - let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); - //let mut data: Port = Port::new(ATTR_DATA_READ_REG); - unsafe { - addr.write(index); - //log!("VGA Palette Register {:#x}: {:#x} -> {:#x}", index, data.read(), value); - addr.write(value); - } +fn set_attr_ctrl_reg(index: u8, value: u8) { + interrupts::without_interrupts(|| { + // See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute + let mut isr: Port = Port::new(INPUT_STATUS_REG); + let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); + let index = index | 0x20; // Set "Palette Address Source" bit + unsafe { + isr.read(); // Reset to address mode + let tmp = addr.read(); + addr.write(index); + addr.write(value); + addr.write(tmp); + } + }) +} + +// TODO: Make this private when debug is done +pub fn get_attr_ctrl_reg(index: u8) -> u8 { + interrupts::without_interrupts(|| { + // See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute + let mut isr: Port = Port::new(INPUT_STATUS_REG); + let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); + let mut data: Port = Port::new(ATTR_DATA_READ_REG); + let index = index | 0x20; // Set "Palette Address Source" bit + unsafe { + isr.read(); // Reset to address mode + let tmp = addr.read(); + addr.write(index); + let res = data.read(); + addr.write(tmp); + res + } + }) } pub fn init() { - set_palette_register(0x0, 0x00); - set_palette_register(0x1, 0x01); - set_palette_register(0x2, 0x02); - set_palette_register(0x3, 0x03); - set_palette_register(0x4, 0x04); - set_palette_register(0x5, 0x05); - set_palette_register(0x6, 0x14); - set_palette_register(0x7, 0x07); - set_palette_register(0x8, 0x38); - set_palette_register(0x9, 0x39); - set_palette_register(0xA, 0x3A); - set_palette_register(0xB, 0x3B); - set_palette_register(0xC, 0x3C); - set_palette_register(0xD, 0x3D); - set_palette_register(0xE, 0x3E); - set_palette_register(0xF, 0x3F); - - disable_blinking(); + // Map palette register to color register + set_attr_ctrl_reg(0x0, 0x00); + set_attr_ctrl_reg(0x1, 0x01); + set_attr_ctrl_reg(0x2, 0x02); + set_attr_ctrl_reg(0x3, 0x03); + set_attr_ctrl_reg(0x4, 0x04); + set_attr_ctrl_reg(0x5, 0x05); + set_attr_ctrl_reg(0x6, 0x14); + set_attr_ctrl_reg(0x7, 0x07); + set_attr_ctrl_reg(0x8, 0x38); + set_attr_ctrl_reg(0x9, 0x39); + set_attr_ctrl_reg(0xA, 0x3A); + set_attr_ctrl_reg(0xB, 0x3B); + set_attr_ctrl_reg(0xC, 0x3C); + set_attr_ctrl_reg(0xD, 0x3D); + set_attr_ctrl_reg(0xE, 0x3E); + set_attr_ctrl_reg(0xF, 0x3F); + set_palette(Palette::default()); + + // Disable blinking + let reg = 0x10; // Attribute Mode Control Register + let mut attr = get_attr_ctrl_reg(reg); + attr.set_bit(3, false); // Clear "Blinking Enable" bit + set_attr_ctrl_reg(reg, attr); + set_underline_location(0x1F); // Disable underline + WRITER.lock().clear_screen(); } From 49d165f5fbf57937cc39890df54c4e33fbf3940d Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 24 Oct 2021 10:49:21 +0200 Subject: [PATCH 09/13] Clear palette address source bit when setting palette --- src/sys/vga.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index ea01007c..6d47a9cc 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -485,12 +485,15 @@ fn set_underline_location(location: u8) { }) } +const PALETTE_ADDRESS_SOURCE: u8 = 0x20; + +// See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute +// And https://01.org/sites/default/files/documentation/snb_ihd_os_vol3_part1_0.pdf + fn set_attr_ctrl_reg(index: u8, value: u8) { interrupts::without_interrupts(|| { - // See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute let mut isr: Port = Port::new(INPUT_STATUS_REG); let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); - let index = index | 0x20; // Set "Palette Address Source" bit unsafe { isr.read(); // Reset to address mode let tmp = addr.read(); @@ -504,11 +507,10 @@ fn set_attr_ctrl_reg(index: u8, value: u8) { // TODO: Make this private when debug is done pub fn get_attr_ctrl_reg(index: u8) -> u8 { interrupts::without_interrupts(|| { - // See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute let mut isr: Port = Port::new(INPUT_STATUS_REG); let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); let mut data: Port = Port::new(ATTR_DATA_READ_REG); - let index = index | 0x20; // Set "Palette Address Source" bit + let index = index | PALETTE_ADDRESS_SOURCE; unsafe { isr.read(); // Reset to address mode let tmp = addr.read(); From 7d7e186db73f87df1ed88b86aa2b486d8ae3a891 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 24 Oct 2021 10:50:40 +0200 Subject: [PATCH 10/13] Refactor code --- src/sys/vga.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/sys/vga.rs b/src/sys/vga.rs index 6d47a9cc..a1eaffe1 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -485,8 +485,6 @@ fn set_underline_location(location: u8) { }) } -const PALETTE_ADDRESS_SOURCE: u8 = 0x20; - // See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute // And https://01.org/sites/default/files/documentation/snb_ihd_os_vol3_part1_0.pdf @@ -504,13 +502,12 @@ fn set_attr_ctrl_reg(index: u8, value: u8) { }) } -// TODO: Make this private when debug is done -pub fn get_attr_ctrl_reg(index: u8) -> u8 { +fn get_attr_ctrl_reg(index: u8) -> u8 { interrupts::without_interrupts(|| { let mut isr: Port = Port::new(INPUT_STATUS_REG); let mut addr: Port = Port::new(ATTR_ADDR_DATA_REG); let mut data: Port = Port::new(ATTR_DATA_READ_REG); - let index = index | PALETTE_ADDRESS_SOURCE; + let index = index | 0x20; // Set "Palette Address Source" bit unsafe { isr.read(); // Reset to address mode let tmp = addr.read(); From b0794a72a81cd5e874fed4ca188740110321ec0c Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 24 Oct 2021 18:11:42 +0200 Subject: [PATCH 11/13] Remove index from palette --- dsk/ini/palette.csv | 32 ++++++++++++++++---------------- src/api/vga/palette.rs | 42 +++++++++++++++++++++--------------------- src/sys/vga.rs | 18 +++++++----------- 3 files changed, 44 insertions(+), 48 deletions(-) diff --git a/dsk/ini/palette.csv b/dsk/ini/palette.csv index 5aca9709..bb6781d6 100644 --- a/dsk/ini/palette.csv +++ b/dsk/ini/palette.csv @@ -1,18 +1,18 @@ # VGA Palette File (Index, Red, Green, Blue) # Dark Gruvbox color palette -0x00, 0x28, 0x28, 0x28 # Black -0x01, 0x45, 0x85, 0x88 # Blue -0x02, 0x98, 0x97, 0x1A # Green -0x03, 0x68, 0x9D, 0x6A # Cyan -0x04, 0xCC, 0x24, 0x1D # Red -0x05, 0xB1, 0x62, 0x86 # Magenta -0x06, 0xD7, 0x99, 0x21 # Brown (Dark Yellow) -0x07, 0xEB, 0xDB, 0xB2 # Light Gray -0x08, 0xA8, 0x99, 0x84 # Dark Gray (Gray) -0x09, 0x83, 0xa5, 0x98 # Light Blue -0x0A, 0xB8, 0xBB, 0x26 # Light Green -0x0B, 0x8E, 0xC0, 0x7C # Light Cyan -0x0C, 0xFB, 0x49, 0x34 # Light Red -0x0D, 0xD3, 0x86, 0x9B # Pink (Light Magenta) -0x0E, 0xFA, 0xBD, 0x2F # Yellow (Light Yellow) -0x0F, 0xFB, 0xF1, 0xF7 # White +0x28, 0x28, 0x28 # Black +0x45, 0x85, 0x88 # Blue +0x98, 0x97, 0x1A # Green +0x68, 0x9D, 0x6A # Cyan +0xCC, 0x24, 0x1D # Red +0xB1, 0x62, 0x86 # Magenta +0xD7, 0x99, 0x21 # Brown (Dark Yellow) +0xEB, 0xDB, 0xB2 # Light Gray +0xA8, 0x99, 0x84 # Dark Gray (Gray) +0x83, 0xa5, 0x98 # Light Blue +0xB8, 0xBB, 0x26 # Light Green +0x8E, 0xC0, 0x7C # Light Cyan +0xFB, 0x49, 0x34 # Light Red +0xD3, 0x86, 0x9B # Pink (Light Magenta) +0xFA, 0xBD, 0x2F # Yellow (Light Yellow) +0xFB, 0xF1, 0xF7 # White diff --git a/src/api/vga/palette.rs b/src/api/vga/palette.rs index 42c068bb..0bbff01f 100644 --- a/src/api/vga/palette.rs +++ b/src/api/vga/palette.rs @@ -2,29 +2,29 @@ use alloc::vec::Vec; use core::convert::TryInto; pub struct Palette { - pub colors: [(u8, u8, u8, u8); 16] + pub colors: [(u8, u8, u8); 16] } impl Palette { pub fn default() -> Palette { Palette { colors: [ - (0x00, 0x00, 0x00, 0x00), // Black - (0x01, 0x00, 0x00, 0x80), // Blue - (0x02, 0x00, 0x80, 0x00), // Green - (0x03, 0x00, 0x80, 0x80), // Cyan - (0x04, 0x80, 0x00, 0x00), // Red - (0x05, 0x80, 0x00, 0x80), // Magenta - (0x06, 0x80, 0x80, 0x00), // Brown (Dark Yellow) - (0x07, 0xC0, 0xC0, 0xC0), // Light Gray - (0x08, 0x80, 0x80, 0x80), // Dark Gray (Gray) - (0x09, 0x00, 0x00, 0xFF), // Light Blue - (0x0A, 0x00, 0xFF, 0x00), // Light Green - (0x0B, 0x00, 0xFF, 0xFF), // Light Cyan - (0x0C, 0xFF, 0x00, 0x00), // Light Red - (0x0D, 0xFF, 0x00, 0xFF), // Pink (Light Magenta) - (0x0E, 0xFF, 0xFF, 0x00), // Yellow (Light Yellow) - (0x0F, 0xFF, 0xFF, 0xFF), // White + (0x00, 0x00, 0x00), // Black + (0x00, 0x00, 0x80), // Blue + (0x00, 0x80, 0x00), // Green + (0x00, 0x80, 0x80), // Cyan + (0x80, 0x00, 0x00), // Red + (0x80, 0x00, 0x80), // Magenta + (0x80, 0x80, 0x00), // Brown (Dark Yellow) + (0xC0, 0xC0, 0xC0), // Light Gray + (0x80, 0x80, 0x80), // Dark Gray (Gray) + (0x00, 0x00, 0xFF), // Light Blue + (0x00, 0xFF, 0x00), // Light Green + (0x00, 0xFF, 0xFF), // Light Cyan + (0xFF, 0x00, 0x00), // Light Red + (0xFF, 0x00, 0xFF), // Pink (Light Magenta) + (0xFF, 0xFF, 0x00), // Yellow (Light Yellow) + (0xFF, 0xFF, 0xFF), // White ] } } @@ -38,8 +38,8 @@ pub fn from_csv(s: &str) -> Result { let value = value.trim().trim_start_matches("0x"); u8::from_str_radix(value, radix).ok() }).collect(); - if color.len() == 4 { // Color index + rgb values - Some((color[0], color[1], color[2], color[3])) + if color.len() == 3 { // RGB values + Some((color[0], color[1], color[2])) } else { None } @@ -58,6 +58,6 @@ fn parse_palette_csv() { let s = include_str!("../../../dsk/ini/palette.csv"); let palette = from_csv(s).unwrap(); - assert_eq!(palette.colors[0x03].0, 0x03); - assert_eq!(palette.colors[0x0D].2, 0x86); + assert_eq!(palette.colors[0x03].0, 0x68); + assert_eq!(palette.colors[0x0D].1, 0x86); } diff --git a/src/sys/vga.rs b/src/sys/vga.rs index a1eaffe1..2ddde781 100644 --- a/src/sys/vga.rs +++ b/src/sys/vga.rs @@ -10,16 +10,15 @@ use vte::{Params, Parser, Perform}; use x86_64::instructions::interrupts; use x86_64::instructions::port::Port; -// See: https://web.stanford.edu/class/cs140/projects/pintos/specs/freevga/vga/vga.htm +// See https://web.stanford.edu/class/cs140/projects/pintos/specs/freevga/vga/vga.htm +// And https://01.org/sites/default/files/documentation/snb_ihd_os_vol3_part1_0.pdf const ATTR_ADDR_DATA_REG: u16 = 0x3C0; const ATTR_DATA_READ_REG: u16 = 0x3C1; const SEQUENCER_ADDR_REG: u16 = 0x3C4; -// const SEQUENCER_DATA_REG: u16 = 0x3C5; const DAC_ADDR_WRITE_MODE_REG: u16 = 0x3C8; const DAC_DATA_REG: u16 = 0x3C9; const GRAPHICS_ADDR_REG: u16 = 0x3CE; -// const GRAPHICS_DATA_REG: u16 = 0x3CF; const CRTC_ADDR_REG: u16 = 0x3D4; const CRTC_DATA_REG: u16 = 0x3D5; const INPUT_STATUS_REG: u16 = 0x3DA; @@ -247,14 +246,14 @@ impl Writer { pub fn set_palette(&mut self, palette: Palette) { let mut addr: Port = Port::new(DAC_ADDR_WRITE_MODE_REG); let mut data: Port = Port::new(DAC_DATA_REG); - for (i, r, g, b) in palette.colors { + for (i, (r, g, b)) in palette.colors.iter().enumerate() { if i < 16 { let reg = color::from_index(i as usize).to_vga_reg(); unsafe { addr.write(reg); - data.write(vga_color(r)); - data.write(vga_color(g)); - data.write(vga_color(b)); + data.write(vga_color(*r)); + data.write(vga_color(*g)); + data.write(vga_color(*b)); } } } @@ -485,9 +484,6 @@ fn set_underline_location(location: u8) { }) } -// See http://www.osdever.net/FreeVGA/vga/vgareg.htm#attribute -// And https://01.org/sites/default/files/documentation/snb_ihd_os_vol3_part1_0.pdf - fn set_attr_ctrl_reg(index: u8, value: u8) { interrupts::without_interrupts(|| { let mut isr: Port = Port::new(INPUT_STATUS_REG); @@ -520,7 +516,7 @@ fn get_attr_ctrl_reg(index: u8) -> u8 { } pub fn init() { - // Map palette register to color register + // Map palette registers to color registers set_attr_ctrl_reg(0x0, 0x00); set_attr_ctrl_reg(0x1, 0x01); set_attr_ctrl_reg(0x2, 0x02); From 2e13082e6b180980523c8cc5425c063fe12e7f28 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 24 Oct 2021 18:12:26 +0200 Subject: [PATCH 12/13] Update comment --- dsk/ini/palette.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsk/ini/palette.csv b/dsk/ini/palette.csv index bb6781d6..0d172240 100644 --- a/dsk/ini/palette.csv +++ b/dsk/ini/palette.csv @@ -1,4 +1,4 @@ -# VGA Palette File (Index, Red, Green, Blue) +# VGA Palette File (Red, Green, Blue) # Dark Gruvbox color palette 0x28, 0x28, 0x28 # Black 0x45, 0x85, 0x88 # Blue From 1bf507c0af93d524241ff19dfaa615d5d7193b27 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Sun, 24 Oct 2021 18:17:14 +0200 Subject: [PATCH 13/13] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebef09d9..65fa5c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## Unreleased +- Fix VGA issues with real hardware (#258) - Add rust binaries support (#255) - Add dynamical disk information (#252) - Add spawn syscall (#251)