我按照文档link写了内核,但是当我执行的时候
cargo bootimage
,我发送了这个错误
Building kernel
Compiling x86_64 v0.7.7
error: cannot find macro `asm` in this scope
--> /home/ubuntu/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/x86_64-0.7.7/src/registers/rflags.rs:96:18
|
96 | unsafe { asm!("pushq $0; popfq" :: "r"(val) : "memory" "flags") };
| ^^^
|
help: consider importing this macro
|
67 + use core::arch::asm;
|
error: cannot find macro `asm` in this scope
--> /home/ubuntu/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/x86_64-0.7.7/src/registers/rflags.rs:79:18
|
79 | unsafe { asm!("pushfq; popq $0" : "=r"(r) :: "memory") };
| ^^^
|
help: consider importing this macro
|
67 + use core::arch::asm;
|
当然这个错误只是一部分,类似的错误还有几十个就不一一重复了
如上所示,我是否应该回滚rust版本,应该回滚到什么版本,或者与我的版本错误无关的其他错误
我的 ubuntu:Ubuntu Server 18.04 LTS 64 位
我的锈迹
rustc 1.73.0-nightly (03a119b0b 2023-08-07)
作为补充: 在 src/main.rs 中
#![no_std] // 不链接Rust标准库
#![no_main] // 禁用所有Rust层级的入口点
use core::panic::PanicInfo;
static HELLO: &[u8] = b"Hello World!";
#[no_mangle] // 不重整函数名
pub extern "C" fn _start() -> ! {
// 因为编译器会寻找一个名为`_start`的函数,所以这个函数就是入口点
// 默认命名为`_start`
let vga_buffer = 0xb8000 as *mut u8;
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;
}
}
loop {}
}
/// 这个函数将在panic时被调用
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
在 Cargo.toml 中
[package]
name = "menghan_os"
version = "0.1.0"
# 使用`cargo build`编译时需要的配置
[profile.dev]
panic = "abort" # 禁用panic时栈展开
# 使用`cargo build --release`编译时需要的配置
[profile.release]
panic = "abort" # 禁用panic时栈展开
[dependencies]
bootloader = "0.6.0"
在 x86_64-menghan_os.json 中
{
"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"
}
在 Rust 工具链中
nightly
我太笨了。这是一个非常愚蠢的问题,我所需要做的就是更改一个数字 在 Cargo.toml 中
[dependencies]
bootloader = "0.6.0"