VGA Text Mode #999
Replies: 167 comments 56 replies
-
Excellent Tutorial series.. As a Rust newbie its a great resource to learn about new things. |
Beta Was this translation helpful? Give feedback.
-
Wow this was all sorts of fun... thanks for putting this together. I've both learned a lot about Rust (in a far gentler fashion than normal) and learned what's involved in building an OS. I look forward to future articles! By the way, for whatever reason, when I call my implementation of
|
Beta Was this translation helpful? Give feedback.
-
@Danrien I had the same problem - make sure your |
Beta Was this translation helpful? Give feedback.
-
Ah thanks, that did the trick!
|
Beta Was this translation helpful? Give feedback.
-
@gurpreetshanky @Danrien Thanks a lot! Glad that you find the posts informative :). @Danrien @edupc I just pushed #417 to avoid this confusion. Thanks for the feedback! |
Beta Was this translation helpful? Give feedback.
-
I think it should be useful to add an empty branch to println! macro. (Standard macro has this branch).
|
Beta Was this translation helpful? Give feedback.
-
I don't think printing strings byte by byte is good in this case. The characters on screen are encoded in Code Page 437, which is identical to UTF-8 (which Rust strings use) only for a certain range of characters. The
I added Unicode to Code Page 437 translation to my implementation, but that's a lot of code. |
Beta Was this translation helpful? Give feedback.
-
@fpsiorz Thanks for the suggestion! I opened #425 to add such a check in the |
Beta Was this translation helpful? Give feedback.
-
At first I got this error:
The reason is obvious: I forgot to add So I wonder: What are const functions exactly for and why do we need to use a const function here instead of a normal function? I found the (RFC)[https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md] on const functions, but that doesn't make me understand the concept behind const functions. |
Beta Was this translation helpful? Give feedback.
-
@arjanvaneersel A |
Beta Was this translation helpful? Give feedback.
-
@arjanvaneersel I removed the |
Beta Was this translation helpful? Give feedback.
-
Thank you! This is a lot of fun :). Typical beginner mistakes, that compile, but lead to blank screen:
Some notes from a beginner perspective:
Very kool stuff! If someone else likes to use cargo-make, like I do, here is a usable [tasks.build]
description = "Build no-std rust binary. Combine it with a preconfigured bootloader from rust-osdev."
command = "bootimage"
args = ["build"]
[tasks.boot]
description="Boot the kernel in a qemu virtual machine."
command="bootimage"
args=["run"] # build 'bootimage.bin' via the bootimage tool
$ cargo make build
# run 'bootimage.bin' in qemu
$ cargo make boot |
Beta Was this translation helpful? Give feedback.
-
@bugabinga Thanks for your comment!
You mean
Basically it's a way of transforming an integer to a memory reference. In C, the equivalent would be the cast
The problem is that the fmt::Write trait is defined that way that |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for this excellent blog series. I noticed while following along a small adjustment that could be made. Perhaps it was done like this for clarity, but I think the blog series assumes a familiarity with Rust. let color_code = self.color_code;
self.buffer.chars[row][col] = ScreenChar {
ascii_character: byte,
- color_code: color_code,
+ color_code,
};
self.column_position += 1; I was also prompted by the latest nightly compiler to add match byte {
0x20..0x7e | b'\n' => self.write_byte(byte),
_ => self.write_byte(0xfe),
} I recommend changing it to look like this, so that - 0x20..0x7e
+ 0x20..=0x7e |
Beta Was this translation helpful? Give feedback.
-
@c-edw Thanks, I agree with both suggestions! Could you open pull request that applies these changes to both src/vga_buffer.rs and blog/content/second-edition/posts/03-vga-text-buffer/index.md? |
Beta Was this translation helpful? Give feedback.
-
Coming from the bottom of this https://os.phil-opp.com/minimal-rust-kernel/ where:
either of the above 2 urls are listing both threads: So that was confusing until I noticed that one of them is for the next thread ie. https://os.phil-opp.com/vga-text-mode/ , so it must be a "bug". |
Beta Was this translation helpful? Give feedback.
-
I feel like |
Beta Was this translation helpful? Give feedback.
-
The article says that the VGA text buffer is "generally" 80x25, but is that something that can be configured in some way? |
Beta Was this translation helpful? Give feedback.
-
Thanks for writing these posts, they are incredibly informative. I just wanted to check if by the end of this article the volatile crate is still needed? When we introduced the dependency the justification was we weren't reading from the buffer so it was added to prevent the compiler optimising it away. However, that was before the implementation of new line was written which does read from the buffer. Is the new line function enough to mean that volatile isn't needed or is it still required? |
Beta Was this translation helpful? Give feedback.
-
Hello, thank you for this series, it was super informative. I was trying to find a good way to implement something that would move the vga buffer's cursor. I was wondering if you could point me in the right direction. |
Beta Was this translation helpful? Give feedback.
-
Can't lie, I'm really enjoying this. It's consolidating all that I have learned in the classroom... or computer laboratory in my case. Thank you! |
Beta Was this translation helpful? Give feedback.
This comment has been minimized.
This comment has been minimized.
-
There is a problem with running qemu-system-x86_64 -drive format=raw,file=bootimage.bin on wsl. QEMU runs but doesn't display the "Hello World!" text. My wsl version is Archlinux and it works when i use fedora. And i am willing to know the reason. |
Beta Was this translation helpful? Give feedback.
-
Thank you for the excellent tutorial. I have a safety-related question. The VGA buffer was initialized within an unsafe block. The Rust compiler seems not guarantee access safety to the variable initialized within the unsafe block, even when the accesses are outside of an unsafe block. Here is a minimized example: fn main() {
// block1
{
let buf1 = unsafe { &mut *(0xb8000 as *mut [[u8; 2]; 2]) };
let _should_not_be_compiled = &buf1[100][100];
}
// block2
{
let buf2: [[u8; 2]; 2] = [[1, 2], [3, 4]];
let _should_not_be_compiled = &buf2[100][100];
}
} The compiler correctly raised an issue for "block2" as expected. However, "block1" did not trigger any issues. Am I misunderstanding the safety concept highlighted in the tutorial? I would appreciate any comments on this matter. Thank you. |
Beta Was this translation helpful? Give feedback.
-
This blew my mind away... as someone that has followed the equivalent C VGA implementation documented on OSDev, it's incredible how easy it is to implement it in rust. And it doesn't only work on strings, but on all primitives and stuff that derives Great work on these guides, been enjoying them a lot so far! |
Beta Was this translation helpful? Give feedback.
-
i am getting this error and i have checked my code multiple times :: error: could not compile help please i have no idea what it is saying. |
Beta Was this translation helpful? Give feedback.
-
Small point, it might be simpler to implement fn new_line(&mut self) {
self.buffer.rotate_left(1);
*self.buffer.last_mut().unwrap_unchecked() = [Char::black_whitespace(); BUFFER_WIDTH];
self.cursor.reset()
} |
Beta Was this translation helpful? Give feedback.
-
I was using the latest volatile (0.5.1) and bootloader (0.11.4) and the compiler was reporting a bunch of errors, and then I found that the main error was on the bootloader, and I wondered if it was because of a version issue, or if the new version needed to do additional configuration |
Beta Was this translation helpful? Give feedback.
-
Thanks for the tutorial. I have been enjoy learning it so far. |
Beta Was this translation helpful? Give feedback.
-
Hi, it is an excellent tutorial. I have a question about writing to VGA buffer. I am trying to write the character to the VGA buffer at the position more than I suppose there is checking in runtime but I don't see any panic message in the runtime. Will buffer overflow happen?
Thanks! |
Beta Was this translation helpful? Give feedback.
-
This is a general purpose comment thread for the “VGA Text Mode” post.
Beta Was this translation helpful? Give feedback.
All reactions