链接到内核
请问,有人知道如何将启动与内核链接起来吗?例如,我有以下用于启动的代码:
[BITS 16]
[ORG 0x7C00]
[global start]
[extern _main]
start:
call _main
cli
hlt
以及用于我的 C++ 文件的代码:
#include <iostream>
#include <string>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
现在我将 .cpp 文件编译为 .o 文件,将 .asm 文件编译为 .o 文件。但我现在如何才能将该文件链接到 kernel.bin 呢?它有一些代码吗?这段代码可以工作吗?请帮我。
Please, does anybody know how to link boot with kernel? For example I have this code for boot:
[BITS 16]
[ORG 0x7C00]
[global start]
[extern _main]
start:
call _main
cli
hlt
and this for my C++ file:
#include <iostream>
#include <string>
int main()
{
std::cout << "Hello World" << std::endl;
return 0;
}
Now I'll compile .cpp file to .o file and .asm file to .o file. But how can I now link that files to kernel.bin? Its there some code for it? Will this code works? Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您不能使用 C/C++ 标准库,因为在业余爱好操作系统中,它不存在*。
其次,您的 C++ 代码似乎是 32 位格式,而您的汇编代码是 16 位格式。除非两者都是 16 或两者都是 32,否则无法链接它们。
我建议查看 OSDev Wiki(user786653 发布)也是如此)...它有许多有用的资源可以帮助您开始编写操作系统。
如果您确实想使用 16 位程序集从头开始,并且希望能够使用 32 位 C++ 代码,则必须执行以下步骤:
(注意,要执行此操作,您必须具有较高的 C/C++ 知识,并且至少具有一些汇编知识)
*如果您在自己的库中进行编程,则忽略第一条语句
希望这会有所帮助!
-阿德里安
Firstly, you cannot use the C/C++ Standard Library because, in a hobby OS, it doesn't exist*.
Secondly, your C++ code seems to be in 32Bit format while your Assembly code is in 16Bit format. These cannot be linked unless both are 16 or both are 32.
I recommend looking at the OSDev Wiki (user786653 posted that too)... It has many helpful resources to get you on your way to writing an Operating System.
If you really want to start from scratch using 16Bit Assembly, and you want to be able to use 32Bit C++ code, you will have to do the following steps:
(Note to do this you must have a high level of knowledge in C/C++ and at least some knowledge in Assembly)
*If you programmed in your own library then disregard the first statement.
Hope this helps!
-Adrian
请参阅 C++ Bare Bones。 org/Main_Page" rel="nofollow">OSDev 维基。但您的代码目前距离使用 iostream 还很远。
Look at C++ Bare Bones from the OSDev wiki. But your code is currently very far from being able to use
iostream
.