phil-opp / blog_os

Writing an OS in Rust
http://os.phil-opp.com
Apache License 2.0
14.35k stars 1.01k forks source link

cargo bootimage fails with "cannot find macro `asm` in this scope" #1066

Closed HLevering closed 2 years ago

HLevering commented 2 years ago

I tried to build the boot image (macOs Big Sur Arm Architecture).I used the source from branch part-02 and followed the instructions in the readme. When I run "cargo bootimage", I get the following error:

cargo bootimage
WARNING: `CARGO_MANIFEST_DIR` env variable not set
Building kernel
    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Building bootloader
   Compiling x86_64 v0.13.2
warning: target json file contains unused fields: panic, relocation_model

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/rflags.rs:125:13
    |
125 |             asm!("push {}; popf", in(reg) val, options(preserves_flags))
    |             ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/rflags.rs:83:13
   |
83 |             asm!("pushf; pop {}", out(reg) r)
   |             ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/model_specific.rs:144:17
    |
144 |                 asm!("wrmsr", in("ecx") self.0, in("eax") low, in("edx") high, options(nostack))
    |                 ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/tlb.rs:10:9
   |
10 |         asm!("invlpg [{}]", in(reg) addr.as_u64(), options(nostack))
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:211:9
    |
211 |         asm!("wrgsbase {}", in(reg) val, options(nomem, nostack))
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:137:18
    |
137 |         unsafe { asm!("mov {0:x}, cs", out(reg) segment, options(nostack, nomem)) };
    |                  ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/model_specific.rs:124:17
    |
124 |                 asm!("rdmsr", out("eax") low, out("edx") high, in("ecx") self.0, options(nostack));
    |                 ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:363:13
    |
363 |             asm!("mov cr4, {}", in(reg) value, options(nostack));
    |             ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:322:17
    |
322 |                 asm!("mov {}, cr4", out(reg) value, options(nostack));
    |                 ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:301:13
    |
301 |             asm!("mov cr3, {}", in(reg) value, options(nostack));
    |             ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:247:17
    |
247 |                 asm!("mov {}, cr3", out(reg) value, options(nomem));
    |                 ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:219:17
    |
219 |                 asm!("mov {}, cr2", out(reg) value, options(nomem));
    |                 ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:186:13
    |
186 |             asm!("mov cr0, {}", in(reg) value, options(nostack));
    |             ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/registers/control.rs:147:17
    |
147 |                 asm!("mov {}, cr0", out(reg) value, options(nomem));
    |                 ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/mod.rs:64:9
   |
64 |         asm!(
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/mod.rs:53:9
   |
53 |         asm!("xchg bx, bx", options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/mod.rs:38:9
   |
38 |         asm!("nop", options(nomem, nostack, preserves_flags));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/mod.rs:19:9
   |
19 |         asm!("hlt", options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/tlb.rs:103:9
    |
103 |         asm!("invpcid {1}, [{0}]", in(reg) desc_value, in(reg) kind);
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/tables.rs:57:5
   |
57 |     asm!("ltr {0:x}", in(reg) sel.0, options(nostack, nomem));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/tables.rs:41:5
   |
41 |     asm!("lidt [{}]", in(reg) idt, options(nostack));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/tables.rs:21:5
   |
21 |     asm!("lgdt [{}]", in(reg) gdt, options(nostack));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:234:9
    |
234 |         asm!("rdgsbase {}", out(reg) val, options(nomem, nostack));
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:185:9
    |
185 |         asm!("rdfsbase {}", out(reg) val, options(nomem, nostack));
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:162:9
    |
162 |         asm!("wrfsbase {}", in(reg) val, options(nomem, nostack));
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:125:5
    |
125 |     asm!("swapgs", options(nostack));
    |     ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:110:5
    |
110 |     asm!("mov gs, {0:x}", in(reg) sel.0, options(nostack));
    |     ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:95:5
   |
95 |     asm!("mov fs, {0:x}", in(reg) sel.0, options(nostack));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:80:5
   |
80 |     asm!("mov es, {0:x}", in(reg) sel.0, options(nostack));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:65:5
   |
65 |     asm!("mov ds, {0:x}", in(reg) sel.0, options(nostack));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:50:5
   |
50 |     asm!("mov ss, {0:x}", in(reg) sel.0, options(nostack));
   |     ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/segmentation.rs:21:9
   |
21 |         asm!(
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/port.rs:87:9
   |
87 |         asm!("out dx, eax", in("dx") port, in("eax") value, options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/port.rs:73:9
   |
73 |         asm!("out dx, ax", in("dx") port, in("ax") value, options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/port.rs:59:9
   |
59 |         asm!("out dx, al", in("dx") port, in("al") value, options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/port.rs:44:9
   |
44 |         asm!("in eax, dx", out("eax") value, in("dx") port, options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/port.rs:28:9
   |
28 |         asm!("in ax, dx", out("ax") value, in("dx") port, options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/port.rs:12:9
   |
12 |         asm!("in al, dx", out("al") value, in("dx") port, options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/interrupts.rs:147:9
    |
147 |         asm!("int3", options(nomem, nostack));
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
   --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/interrupts.rs:134:9
    |
134 |         asm!("sti; hlt", options(nomem, nostack));
    |         ^^^
    |
    = note: consider importing this macro:
            core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/interrupts.rs:33:9
   |
33 |         asm!("cli", options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

error: cannot find macro `asm` in this scope
  --> /Users/hendrik/.cargo/registry/src/github.com-1ecc6299db9ec823/x86_64-0.13.2/src/instructions/interrupts.rs:18:9
   |
18 |         asm!("sti", options(nomem, nostack));
   |         ^^^
   |
   = note: consider importing this macro:
           core::arch::asm

warning: `x86_64` (lib) generated 1 warning
error: could not compile `x86_64` due to 42 previous errors; 1 warning emitted
Error: Bootloader build failed.
Stderr:

How can I solve this error?

bjorn3 commented 2 years ago

This is fixed with x86_64 version 0.14.7. Bootloader 0.9 will need to update to it. Opened https://github.com/rust-osdev/bootloader/issues/207 for this. For now you can switch to rustc nightly-2021-12-13 using rustup override set nightly-2021-12-13.

HLevering commented 2 years ago

Thank you very much.

jmcph4 commented 2 years ago

Confirming that this is fixed due to @phil-opp publishing 0.9.20 of bootloader here.

phil-opp commented 2 years ago

@jmcph4 Thanks for checking!