Finish VGA Buffer

This commit is contained in:
Sainnhe Park 2021-12-01 16:47:28 +08:00
parent 16fc355843
commit e4470bc04c
7 changed files with 48 additions and 5 deletions

View File

@ -1,2 +0,0 @@
[build]
target = "thumbv7em-none-eabihf"

6
.cargo/config.toml Normal file
View File

@ -0,0 +1,6 @@
[build]
target = "x86_64-anos.json"
[unstable]
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins"]

9
Cargo.lock generated
View File

@ -5,3 +5,12 @@ version = 3
[[package]]
name = "anos"
version = "0.1.0"
dependencies = [
"bootloader",
]
[[package]]
name = "bootloader"
version = "0.9.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c452074efc3c0bfb241fb7bc87df04741c7c85e926f6a07c05f8fbd6008240"

View File

@ -9,3 +9,6 @@ panic = "abort" # 禁用 panic 时的栈展开
[profile.release]
panic = "abort" # 禁用 panic 时的栈展开
[dependencies]
bootloader = "0.9.8"

View File

@ -1,6 +1,4 @@
[toolchain]
channel = "nightly"
components = [ "rust-analyzer-preview" ]
targets = [ "thumbv7em-none-eabihf" ]
components = [ "llvm-tools-preview" ]
profile = "minimal"

View File

@ -3,11 +3,25 @@
use core::panic::PanicInfo;
// 定义一个 byte string 类型的静态变量
static HELLO: &[u8] = b"Hello World!";
#[no_mangle] // 不重整函数名,否则编译器可能会生成名为 _ZN3blog_os4_start7hb173fedf945531caE 的函数
// extern "C" 告诉编译器这个函数应当使用 C 语言的调用约定
// 函数名为 _start 是因为大多数系统默认用这个名字作为入口点名称
// -> ! 代表这是一个发散函数,不允许有任何返回值,因为它不会被任何函数调用,而是将直接被 bootloader 调用
pub extern "C" fn _start() -> ! {
// VGA Buffer 从 0xb8000 开始
let vga_buffer = 0xb8000 as *mut u8;
// 迭代 HELLO, 通过裸指针 vga_buffer 来定位待写入的缓冲区地址
for (i, &byte) in HELLO.iter().enumerate() {
unsafe {
*vga_buffer.offset(i as isize * 2) = byte; // ASCII 码字节
*vga_buffer.offset(i as isize * 2 + 1) = 0xb; // 颜色字节, 0xb 代表青色
}
}
loop {}
}

15
x86_64-anos.json Normal file
View File

@ -0,0 +1,15 @@
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float"
}