How to compile a Rust kernel with an Assembly (NASM) bootloader

旧城冷巷雨未停 提交于 2019-12-08 12:50:59

问题


I have a simple 2-stage bootloader written in NASM, and I want to continue the OS kernel using Rust.

So I created a nightly Rust project with Cargo, and disabled std in the src/main.rs file. Now I am trying to link the Assembly files with the Cargo project, but without any success.

How should I compile and link the NASM bootloader with the Rust kernel?


回答1:


After a couple of hours I compiled the code.

The solution was (like Michael Petch suggested), to compile the assembly code into static .o files, then compile the rust code using xargo and a custom target. I compiled the Rust code as a static library, not a binary, so the output was a .a object file, and not an executable.

Then I used gcc with a linker script to link together the object files and output the result as an ELF file. After that I used objcopy to with the -O binary flag to copy the ELF file to a .bin file. And finally I used dd to create an image file, that I could boot from.



来源:https://stackoverflow.com/questions/55542407/how-to-compile-a-rust-kernel-with-an-assembly-nasm-bootloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!