OS in Rust
| Bit(s) | Value |
|---|---|
| 0-7 | ASCII code point |
| 8-11 | Foreground color |
| 12-14 | Background color |
| 15 | Blink |
qemu thing I’m not sure.| Number | Color | Bright | Bright Color |
|---|---|---|---|
| 0o00 | Black | 0o10 | Dark Gray |
| 0o01 | Blue | 0o11 | Light Blue |
| 0o02 | Green | 0o12 | Light Green |
| 0o03 | Cyan | 0o13 | Light Cyan |
| 0o04 | Red | 0o14 | Light Red |
| 0o05 | Magenta | 0o15 | Pink |
| 0o06 | Brown | 0o16 | Yellow |
| 0o07 | Light Gray | 0o17 | White |
0x64 memory location and also 0x64 device.0x00x10x20x30x40xb8000.
u64 is read.
src/vga.rs file.const for color and not worry about.&strsrc/vga.rssrc/vga.rs
\n.\\ to show a single backslash.\n10 (I think?)0xau8 within the loop (since we as_bytes first)consts and write a helper.memmove
scroll to str_to_vgaLATEST in scroll0x20 or 32)for loops and “single-equals-assignment”
memmove (a C function) when we have the humble for loop.memmove.src/vga.rs
const ROWS: usize = 80;
const COLS: usize = 25;
const MAX: usize = ROWS * COLS;
fn scroll() {
unsafe {
for i in 80..MAX {
let src: *mut u8 = (MMIO + i * 2) as *mut u8;
let dst: *mut u8 = (MMIO + (i - 80) * 2)) as *mut u8;
*dst = *src;
*((dst as usize + 1) as *mut u8) = COLOR;
}
for i in (MAX-80)..MAX {
let dst: *mut u8 = (MMIO + i * 2) as *mut u8;
*dst = 32;
*((dst as usize + 1) as *mut u8) = COLOR;
}
LATEST = LATEST - 80;
}
}
pub fn str_to_vga(s: &str) {
let v = s.as_bytes();
unsafe {
for i in 0..v.len() {
if LATEST > MAX {
scroll();
}
match v[i] {
10 => LATEST = ((LATEST / 80) + 1) * 80,
_ => char_to_vga(v[i]),
}
}
}
}rustc is a bit too smart.
The problem is that we only write to the buffer and never read from it again.
read_volatile and write_volatile in std::ptr and another in core::ptr, we might be able to use those.