致电 C++从程序集引导加载程序
我有一个从教程获得的小型程序集引导加载程序。引导加载程序的代码可以在此处找到。我想知道是否可以从这个引导加载程序运行 c++。我想运行一个像这样的简单的事情:
#include <iostream>
using namespace std;
int main () {
cout << "Hello World!\n";
return 0;
}
但正如我所看到的,它带来了两个问题。首先,C++ 文件必须包含在编译后的 bin 文件中。另外#include
... iostream 是否包含在已编译的 C++ 文件中,或者是否需要包含在引导加载程序中的某种库中?
感谢您的帮助,因为这真的让我很困惑。
I have a small assembly bootloader that I got from this Tutorial. The code for the boot loader can be found here. I want to know if its possible to run c++ from this boot loader. I want to run a simple thing like this:
#include <iostream>
using namespace std;
int main () {
cout << "Hello World!\n";
return 0;
}
But as I can see it brings up 2 issues. First somehow the C++ file has to be included in the compiled bin file. Also #include <iostream>
... Is iostream included included in a compiled C++ file or dose it need to be included in some sort of library in the boot loader?
Thanks for any help as this is really puzzling me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要从汇编代码调用 C 函数,下面是一个示意图。使用 g++ 代替 gcc 应该允许您使用 C++ 代码。但我想知道你能写多少“C++”,因为你不能使用库函数,正如之前对你的问题的一些答复明确指出的那样。您最终可能会在 C++ 代码中编写汇编!
cboot.c
boot.asm
您可以通过这种方式编译和链接它们以创建可执行文件prog。
To call a C function from your assembly code, here's a schematic. Using g++ in place of gcc should allow you to use C++ code. But I wonder how much of 'C++' you'd be able to write since you cannot use the library functions, as some of the earlier replies to your question clearly point out. You may end up writing assembly in your C++ code finally!
cboot.c
boot.asm
You compile and link them this way to create the executable prog.
您将无法运行任何具有任何外部依赖项或系统调用的代码。这限制了很多标准库函数,即所有 IO 函数(C stdio、iostreams),因为
您必须推出自己的标准库,该库可以在特定硬件上的内核空间中运行。
You will not be able to run any code that has any external dependencies or system calls. This bars a lot of standard library functions, namely all IO functions (C stdio, iostreams), because
You will have to roll your own standard library that works in kernel space on your particular hardware.
首先,除非您实现它或将 STL 静态链接到引导加载程序,否则您将无法使用 iostream 或 cout。 STL 可能必须是特定于 booloader 的。
至于从 Assembly 调用 main 函数,您需要执行以下操作:
First of all, you won't be able to use iostream nor cout unless you implement it or statically link a STL to your bootloader. The STL will probably have to be booloader-specific.
As for calling your main function from Assembly, here's what you'd do: