StudioMenghan
StudioMenghan

Reputation: 11

How can I solve a problem with my rust when I compile the kernel

I wrote the kernel according to the document link but when I executed cargo bootimage , I sent this error

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;
   |

Of course, this error is only a part, and there are dozens of other similar errors that won't be repeated one by one

As shown above, should I roll back the rust version, and to what version should I roll back, or Other errors unrelated to my version error

my ubuntu : Ubuntu Server 18.04 LTS 64bit

My rust

rustc 1.73.0-nightly (03a119b0b 2023-08-07)

As a supplement: in 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 {}
}

in 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"

in 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"
}

in rust-toolchain

nightly

Upvotes: 0

Views: 257

Answers (1)

StudioMenghan
StudioMenghan

Reputation: 11

I'm too stupid. This is a very foolish question, all I need to do is change one number in Cargo.toml

[dependencies]
bootloader = "0.6.0"

Upvotes: 0

Related Questions