Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VGA MMIO: does it really not need volatile writes? #1344

Open
meithecatte opened this issue Sep 15, 2024 · 1 comment
Open

VGA MMIO: does it really not need volatile writes? #1344

meithecatte opened this issue Sep 15, 2024 · 1 comment

Comments

@meithecatte
Copy link

Currently, the code used to access VGA does plain memory pokes:

    for (i, &byte) in HELLO.iter().enumerate() {
        unsafe {
            *vga_buffer.offset(i as isize * 2) = byte;
            *vga_buffer.offset(i as isize * 2 + 1) = 0xb;
        }
    }

This surprised me — I expected to see something like ptr::write_volatile here. Are you sure this code isn't working by accident?

I'm not too familiar with the exact semantics, but my guess would be that without volatile, these memory accesses are not considered side-effects, and therefore the compiler could, for example:

  • prove that our code won't read them (because of an upcoming infinite loop, for example), and decide remove them
  • move the write around some code that might not terminate, for example:
    print("doing the thing... ");
    some_mutex.lock().push(42);
    print("it worked!");
    could get optimised to
    some_mutex.lock().push(42);
    print("doing the thing... it worked!");
    This would suck big time if you're trying to track down a deadlock.

Is this something you've given some thought, or merely an oversight?

@xuanplus
Copy link

You will find it in next post: VGA Text Mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants