如何使用Assembly(NASM)引导程序编译Rust内核 [英] How to compile a Rust kernel with an Assembly (NASM) bootloader

查看:99
本文介绍了如何使用Assembly(NASM)引导程序编译Rust内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用NASM编写的简单的2阶段引导程序,我想使用Rust继续OS内核.

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

所以我用Cargo创建了一个每晚的Rust项目,并在src/main.rs文件中禁用了std.现在,我试图将Assembly文件与Cargo项目链接,但没有成功.

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.

我应该如何编译和链接NASM引导程序与Rust内核?

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

推荐答案

几个小时后,我编译了代码.

After a couple of hours I compiled the code.

解决方案是(如Michael Petch建议的那样),将汇编代码编译成静态的.o文件,然后使用xargo和自定义目标编译rust代码.我将Rust代码编译为静态库,而不是二进制库,因此输出是.a目标文件,而不是可执行文件.

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.

然后,我将gcc与链接描述文件一起使用来将目标文件链接在一起,并将结果输出为ELF文件.之后,我使用objcopy-O binary标志将ELF文件复制到.bin文件.最后,我使用dd创建了一个可以从中启动的图像文件.

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.

这篇关于如何使用Assembly(NASM)引导程序编译Rust内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆