Finish VGA Buffer
This commit is contained in:
parent
16fc355843
commit
e4470bc04c
@ -1,2 +0,0 @@
|
|||||||
[build]
|
|
||||||
target = "thumbv7em-none-eabihf"
|
|
6
.cargo/config.toml
Normal file
6
.cargo/config.toml
Normal 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
9
Cargo.lock
generated
@ -5,3 +5,12 @@ version = 3
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "anos"
|
name = "anos"
|
||||||
version = "0.1.0"
|
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"
|
||||||
|
@ -9,3 +9,6 @@ panic = "abort" # 禁用 panic 时的栈展开
|
|||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
panic = "abort" # 禁用 panic 时的栈展开
|
panic = "abort" # 禁用 panic 时的栈展开
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bootloader = "0.9.8"
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly"
|
channel = "nightly"
|
||||||
components = [ "rust-analyzer-preview" ]
|
components = [ "llvm-tools-preview" ]
|
||||||
targets = [ "thumbv7em-none-eabihf" ]
|
|
||||||
profile = "minimal"
|
profile = "minimal"
|
||||||
|
|
||||||
|
14
src/main.rs
14
src/main.rs
@ -3,11 +3,25 @@
|
|||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
// 定义一个 byte string 类型的静态变量
|
||||||
|
static HELLO: &[u8] = b"Hello World!";
|
||||||
|
|
||||||
#[no_mangle] // 不重整函数名,否则编译器可能会生成名为 _ZN3blog_os4_start7hb173fedf945531caE 的函数
|
#[no_mangle] // 不重整函数名,否则编译器可能会生成名为 _ZN3blog_os4_start7hb173fedf945531caE 的函数
|
||||||
// extern "C" 告诉编译器这个函数应当使用 C 语言的调用约定
|
// extern "C" 告诉编译器这个函数应当使用 C 语言的调用约定
|
||||||
// 函数名为 _start 是因为大多数系统默认用这个名字作为入口点名称
|
// 函数名为 _start 是因为大多数系统默认用这个名字作为入口点名称
|
||||||
// -> ! 代表这是一个发散函数,不允许有任何返回值,因为它不会被任何函数调用,而是将直接被 bootloader 调用
|
// -> ! 代表这是一个发散函数,不允许有任何返回值,因为它不会被任何函数调用,而是将直接被 bootloader 调用
|
||||||
pub extern "C" fn _start() -> ! {
|
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 {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
15
x86_64-anos.json
Normal file
15
x86_64-anos.json
Normal 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"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user