How to develop an operating system using C++?
how operating systems are developed? using C(or actually) C++, assembly and any programming languages like ada, fortran, pascal you can develop your own operating system
but you have to use assembly in some places
secondly, you must have some knowledge of the assembly language
1. an assembler
assembler takes your assembly code and give's 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
2. a cross-compiler
in order to develop an operating system, you must have a cross compiler because you must compile your kernel for it's executable format
here i use gcc(gnu compiler collection)
you can download it from http://gcc.gnu.org/
3. 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
4. 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 virtualbox
you can download it from http://virtualbox.org/
you must create all of them yourself
2. you must very very be careful
when you are developing, you have control of everything
so, you can destroy one or some or all of your hardwares
in this case, i recommend to use a virtual machine to test your operating system instead of rebooting more and more times
it load's your operating system's kernel
we skip this section and use grub as are bootloader
you can download grub source code from http://gnu.org/software/grub
or actually you maybe want a compiled for floppy: searching in google will help you
so, we have to create the functions ourselves
firstly, we create a file boot.asm with these contents:
now create a file: kernel.cpp with these contents:
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
an intruduction to assembly language
assembly is a low-level programming language that you can use it to control everything like adding something to CPU registers, control the memory and much morehow can i start to develop an operating system?
firstly, you have to know everything of your programming language like pointers, functions (here i want to use C++)secondly, you must have some knowledge of the assembly language
what tools i need to develop an operating system?
to develop an operating system you must have these:1. an assembler
assembler takes your assembly code and give's 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
2. a cross-compiler
in order to develop an operating system, you must have a cross compiler because you must compile your kernel for it's executable format
here i use gcc(gnu compiler collection)
you can download it from http://gcc.gnu.org/
3. 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
4. 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 virtualbox
you can download it from http://virtualbox.org/
notes before you get started
1. in developing an operating system, you cannot and cannot and cannot use <iostream>, <fstream>, <memory>, <cstdio>, <cstdlib>, <windows.h>, <unistd.h> and all the platform API'syou must create all of them yourself
2. you must very very be careful
when you are developing, you have control of everything
so, you can destroy one or some or all of your hardwares
in this case, i recommend to use a virtual machine to test your operating system instead of rebooting more and more times
the bootloader
a 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 this section and use grub as are bootloader
you can download grub source code from http://gnu.org/software/grub
or actually you maybe want a compiled for floppy: searching in google will help you
a simple kernel
we want to develop an operating systemso, we have to create the functions ourselves
firstly, we create a file boot.asm with these contents:
|
|
now create a file: 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
Comments
Post a Comment