Call C ++ from assembly loader

I have a small build loader that I got from this Tutorial . The code for the bootloader can be found here . I want to know if C ++ can be run from this bootloader. 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 see it, this causes 2 problems. First, somehow the C ++ file must be included in the compiled bin file. Also #include <iostream>... Is the included iostream included in the compiled C ++ file or its dose, which should be included in some kind of library in the bootloader?

Thanks for any help as it really puzzles me.

+3
source share
3

C , . g++ gcc ++. , "++" , , . , ++!

cboot.c

void bootcode(void) {
 /* code */
}

boot.asm

# some where you have this line
call bootcode
# more code to follow

, .

nasm -f boot.o boot.asm

gcc -c cboot.c

gcc -o prog cboot.o boot.o
+2

- . , - (C stdio, iostreams),

  • , , , .
  • (, libc, libstd++), .

, .

+3

First of all, you cannot use iostream or cout unless you implement it or statically link the STL to your bootloader. Probably the STL should be booloader specific.

As for calling your main function from Assembly, here is what you would do:

extern _main
;...
call _main
0
source

Source: https://habr.com/ru/post/1755155/


All Articles