![]() |
How to Make an Operating System in C++ |
How to Make an operating system in C++ is asked by many people but developing an Operating System on your own is impossible Because, Windows XP had 40 million lines of code and Windows vista had 55 million line of code, by the way we can create our own Basic kernel by, Using C or C++, or any programming languages like Java, pascal,but we have to use assembly in some places.
Assembly Language
Assembly is a low-level programming language that you can use it to control everything like adding something to CPU registers, control BIOs memory and much more.
I am going to show you How to Make an Operating System in C++
Prerequisite:For creating an Basic kernel Operating System you have to know everything of your programming language like pointers, BUILTIN functions here I am gonna use C++, little code of Assembly Language so you must have some knowledge of the these languages too.
Tools I need to make an operating system
To develop an operating system you must have these:A cross-compiler
In order to Make an operating system, you must have a cross compiler because you must compile your kernel for it's executable format here, I am gonna use gcc(gnu compiler collection) you can download it from http://gcc.gnu.org/.
A linker
the linker take's your objects and link them to getter here i use gnu binutils you can download it from http://gnu.org/software/binutils
An Assembler
Assembler takes your assembly code and give you the low-level outputs like an object containing your controls on CPU registers the assembler here i want to use is nasm(netwide assembler) you can download it from http://nasm.us
A virtual machine
In order to test your operating system, you must have a vm(virtual machine) but it isn't necessary here i use Virtual box or other virtual machine you can download it from http://virtualbox.org/
Note!
When developing an operating system we couldn't use the built in directives or header file like <iostream>, <fstream>, <memory>, <cstdio>, <cstdlib>, <windows.h>, <unistd.h> and all the platform API's We should write our own header file.
When you are making your own Operating System,you have control of everything so, you can destroy one some or all of your hardware that why, I recommend to use a virtual machine to test your operating system instead of rebooting again and again when compiling your code.
Bootloader
An bootloader is a bunch of code that is written in assembly language and must be 512 byets(1 sector).It load's your operating system's kernel we skip writing code for the Bootloader because its very hard to write and the purpose of the every bootloader from DOS to Windows 10 is the Same just load your kernal so we will use grub as our bootloader. You can download grub source code from http://gnu.org/software/grub.
Now Start Writing kernel
We want to Make an operating system so, we have to create the functions ourselves first, we will create a file boot.asm an Assembly language file with these contents:
|
|
Now let just create a file named: kernel.cpp with these contents:
|
|
The linker script
create a file: linker.ld with these contents:
|
|
How to compile it
go to the shell (on windows cygwin is required):type these commands:
|
|
kingratulations!
your first operating system has been compiled successfully!
now you can create an image using grub-mkrescue:
create a directory: iso
in that directory, create another directory: boot then in the boot directory, create a directory: grub and then create a file: grub.cfg with these contents(do not add the braces in a new line) in the grub directory:
|
|
then copy your kernel (kern) to iso/boot directory and run your shell again:
switch to the main directory of your kernel and type:
|
|
now you can boot and enjoy from your first operating system:: this simple kernel without anything
U Copied this: http://www.cplusplus.com/articles/zv07M4Gy/
ردحذفWhat a waste of time
إرسال تعليق