引导加载程序和引导映像是否包含较新版本中的标准功能?

问题描述 投票:0回答:1

我正在尝试用 Rust 创建一个裸机操作系统,但遇到了许多与未找到类型相关的错误,例如

Vec
和其他标准库功能。我怀疑这些错误是由于依赖于
std
的依赖关系造成的,尽管我唯一的依赖关系是
bootimage
bootloader
,我认为它们不会使用
std

这是错误的一部分

error[E0463]: can't find crate for `std`
  |
  = note: the `x86_64-ferrite_os` target may not support the standard library
  = note: `std` is required by `semver_parser` because it does not declare `#![no_std]`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`


error: cannot find macro `try` in this scope
   --> /home/cosmin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/semver-parser-0.7.0/src/range.rs:184:22
    |
184 |     let predicates = try!(predicates);
    |                      ^^^

error: cannot find macro `vec` in this scope
   --> /home/cosmin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/semver-parser-0.7.0/src/range.rs:164:25
    |
164 |             predicates: vec![Predicate {
    |                         ^^^

范围错误仍在继续,而且还有更多

这是我的

Cargo.toml
文件的相关部分:

[package]
name = "ferriteos"
version = "0.1.0"
edition = "2021"

[dependencies]
bootimage = "0.10.3"
bootloader = "0.11.7"

[build-dependencies]
bootimage = "0.10.3"

[unstable]
build-std = ["core", "compiler_builtins"]
build-std-features = ["compiler-builtins-mem"]

[build]
target = "resources/x86_64-ferrite_os.json"

指定的目标看起来像这样,我遇到的唯一问题是数据布局问题,但我修复了它们:

{
    "llvm-target": "x86_64-unknown-none",
    "data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-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"
}

main.rs 文件包括

!#[no_std]
,我只是尝试将 hello world 打印到 vga 屏幕:

#![no_std]
#![no_main]

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

static HELLO: &[u8] = b"Hello World!";

#[no_mangle]
pub extern "C" fn _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 {}
}

但我想知道错误是否来自依赖项,我需要尝试降级,是否有人可以帮助我提供稳定的版本?

对于有关重现此示例的任何问题。大部分代码取自本教程
https://os.phil-opp.com/freestand-rust-binary/
https://os.phil-opp.com/minimal-rust-kernel/

rust operating-system rust-cargo
1个回答
0
投票

确实,两个板条箱都需要标准。

bootimage
板条箱从来不打算用作依赖项;它是一个可安装的(
cargo install
)工具。

bootloader
曾在0.9版本中用作依赖项,但此后发生了重大变化。 有针对 v.0.9 用户的迁移指南

© www.soinside.com 2019 - 2024. All rights reserved.