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
an开发者_如何学God 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.
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:
- Create a Bootloader's First Stage (A Small file that loads the rest of the bootloader.. It has to be exactly 512 Bytes...
- Create a Bootloader's Second Stage (This one sets up a GDT, enables the A20 Line, and switches to 32Bit Protected Mode.. - It can also set up a video mode, get RAM info, and pass that onto the 32Bit Kernel..).
- Create a 32Bit Kernel Stub (In C/C++.. Preferrably C). This Will create the main environment for the operating system's kernel.
- Write some C/C++ Standard Library Routines. String.h is your main priority (CString on C++). Also, a Stdio.h file would be useful (CStdio on C++)
- In the Kernel Stub's main function, call your print routine.
(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
Look at C++ Bare Bones from the OSDev wiki. But your code is currently very far from being able to use iostream
.
精彩评论