开发者

Writing C/C++ Compiler to the MBR to execute source code before Booting up the OS [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I am trying to write the full OS independent program on C++. I want to load the program just before booting up the OS (i.e. Windows). I tried to replace the MBR with my simple “Hello World” program, but nothing happens and I lost Partition table of Virt开发者_JS百科ual Hard disk. I think I should write the C++ compiler to the MBR to directly execute the program or source code.

Q. The Compiler is in EXE format so should require Windows or DOS. Does it can be written on MBR?

Q. The C++ program require DOS platform. Does it can be run without any OS?

I am trying to write a Boot loader and some same sort of programs.


It is impossible to write such program in plain C/C++. There is no OS, and the compiler should work in "freestanding" mode. In this mode there is not "stdin.h" header, no files, no file access and no printf are available.

So, you program should call BIOS functions directly, e.g. using asm keyword.

Format of MBR binary is very close to COM file format of DOS. It is possible to convert short COM program into MBR boot code (by manipulating some parameters of compilation).

Also, you should know that MBR is one sector long and it contains a partition table. So, you have only ~450 bytes to store binary code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜