concept screen in category rust

appears as: screen, screen
Rust in Action

This is an excerpt from Manning's book Rust in Action.

From this point onwards, the commands for all operating systems should be the same. If you have installed Rust correctly, the following three commands will produce "Hello, world!" on the screen (as well as a bunch of other output).

Listing 11. 5. Creating an operating system kernel that paints a block of color on the screen. (ch11/ch11-fledgeos-0/src/main.rs)
#![feature(core_intrinsics)]       #1
#![no_std]                          #2
#![no_main]                         #3

use core::intrinsics;
use core::panic::PanicInfo;         #4

#[panic_handler]                    #5
#[no_mangle]
fn panic(_info: &PanicInfo) -> ! {  #6
  unsafe {
    intrinsics::abort();            #7
  }
}

#[no_mangle]                        #8
pub extern "C" fn _start() -> ! {   #9
  let framebuffer = 0xb8000 as *mut u8;  #10
  unsafe {
      framebuffer.offset(1).write_volatile(0x30);  #11
  }
  loop {}
}

11.1.5. Writing to the screen with VGA-compatible text mode

The bootloader sets some magic bytes with raw assembly code at boot mode. At startup, the bytes are interpreted by hardware. The hardware switches its display to a 80x25 grid. It also sets up some fixed memory buffer that is interpreted by the hardware for printing to the screen.

Mutating the frame buffer instructs the hardware to change what’s presented on screen. The snippet used in Listing 11. 5 and repeated here is how one writes to memory:

let mut framebuffer = 0xb8000 as *mut u8;
  unsafe {
      framebuffer.offset(1).write_volatile(0x30);  #1
  }

This initialization at boot time makes it very easy to display things on screen. Each of the points in the 80x25 grid are mapped to locations in memory. This area of memory is called the "framebuffer". Our bootloader designates 0xb8000 as the start of a 4,000 byte framebuffer.