Yeah, your not doing things properly. Cargo should be the sole tool you use to generate binaries; you shouldn't need makefiles (that's what Cargo is for). Its very possible to write a 32-bit kernel that uses multiboot
without makefiles. To do so, you need a target definition file; this looks something like:
Code:
{
"llvm-target": "x86_64-kernel-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"
}
Another target definition for a custom pure rust bootloader looks like this:
Code:
{
"llvm-target": "x86_64-unknown-none-gnu",
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"pre-link-args": {
"ld.lld": [
"--script=linker.ld"
]
},
"target-endian": "little",
"target-pointer-width": "64",
"target-c-int-width": "32",
"arch": "x86_64",
"os": "none",
"features": "-mmx,-sse,+soft-float",
"disable-redzone": true,
"panic-strategy": "abort",
"executables": true,
"relocation_model": "static"
}
Information on custom target definitions can be found over
here and some extra info is over
here.
Then, you need to create a .cargo directory with a config.toml file inside that looks something like:
Code:
[unstable]
build-std = ["core", "compiler_builtins", "alloc"]
[build]
# Replace this target string with your custom JSON file
target = "x86_64-kernel-none.json"
Then you can include custom asm to prepare your kernel for protected mode and all that jaz. You include that in your main.rs file with the
global_asm! macro. The setup might seem a bit convoluted but once you get it working you (typically) never have to touch it again.
Edit: also, you *need* to do this on nightly. Beta or stable channels won't let you do this stuff.