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.
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
void bootcode(void) {
/* code */
}
boot.asm
# some where you have this line
call bootcode
# more code to follow
You compile and link them this way to create the executable prog.
nasm -f boot.o boot.asm
gcc -c cboot.c
gcc -o prog cboot.o boot.o
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With