Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to boot my simple hello world program? [closed]

Tags:

c++

c

assembly

boot

Suppose, I have a simple Hello world program which is built in C. Now How can I boot it during start my PC?

My wish is to make simple hello world Operating System. I've quite knowledge regarding C and C++, how can I boot it? Please let me know. Do I need to learn Assembly language for it?

If yes, then inside Assembly what do I need require to understand first? And where should I go for Assembly (NASM, MASM etc..)?

Help would be appreciated!

like image 410
Raj kumar Avatar asked Jan 08 '23 18:01

Raj kumar


1 Answers

You could do this by writing a simple bootloader. This OSdev article shows you one way to go about it.

Regarding languages: Any compiled language (C/C++) gets compiled into machine code, which again is 1-1 mappable to assembly instructions. So, in principle you could write most of the bootloader in C/C++.

Printing: The challenge with "booting your own code" is of course that you won't have any drivers or any standard library (so, no printf-function or cout). In x86, however, certain parts of low memory (starting at 0xa0000) is directly mapped to video memory when you boot, meaning that the bytes you write to this part of memory will atuomagically appear on the screen, as text.

Choice of assembler: This is really only a matter of taste. For a simple assembly-language bootloader, you'll want to avoid any particular formatting of the resulting binary. nasm -f bin myfile.asm -o myBootsector will just assemble the code into a raw binary.

This post has more details.

like image 141
Alfred Bratterud Avatar answered Jan 15 '23 09:01

Alfred Bratterud