the Kernel

Hey guys I'm not sure if this belongs in the Windows or Linux sub forums but since I'm talking about both OS's and many more I guess general is the best place for it,

anywho I have been doing a little bit of research,an operating system well parts of an OS can be written in C or C++ but ofcourse some critical parts of the OS have to be written in assembly like loading the kernel(this can only be done in assembly because you need to directly access the instuction pointer to point to the kernel code) anyway another thing is that when you load the kernel code(c or c++) when it first boots you do not have access to any libraries such as the stdio or iostream etc because these will be stored in the OS itself,

so how is this possible I mean how can you write a kernel or parts of a kernel with any libraries?

I know a code example would be way too long but could anyone give me a quick example of even a function that could possibly be used to do some easy and low level

thanks :)
when you load the kernel code(c or c++) when it first boots you do not have access to any libraries such as the stdio or iostream etc because these will be stored in the OS itself
Firstly, you can use C++ anywhere C is used. In this sense, C++ is a superset of C.

Just because you use a language, doesn't mean you have to use all features. Now, the language is separate from the runtime library. If you restrict the use of C++. like not using global objects, RTTI, not using the iostream library, or C or C++ runtime library, you can use a modified startup that is small as C and independent of the runtime environment, but has class and template features available.
Last edited on
thanks kbw :)
You'll also need to switch of C++ exceptions.
you need to directly access the instuction pointer to point to the kernel code

You can do that in C by calling longjmp(). http://www.cplusplus.com/reference/csetjmp/longjmp/?kw=longjmp

Here's how an operating system loads, more or less:
- When you turn on the power, the motherboard applies power (or maybe grounds) a "reset" pin on the CPU. This basically stops the CPU from doing anything.
- After a short period of time (milliseconds) during which the electrical circuits of the components all settle down, the motherboard changes the signal on the CPU's reset pin. This causes the CPU to start running.
- When starting from reset, the CPU will begin execution at a specific memory address. This is specified by the CPU manufacturer and can't be changed.
- The motherboard has a ROM program stored at that address. I believe that on a PC, this program has the smarts to find the hard drive(s), scan them for the active partition and boot from that partition.
- To boot from the active partition, the ROM program reads a specific sector (or sectors) from the partition into RAM and starts executing the code there. Note that up until now, the sequence is the same regardless of what operating system is installed. The contents of the sector(s) will cause the rest of the operating system to load. First it needs code to understand the file system on the disk, then it can read and execute whatever files are needed to boot the computer.
Topic archived. No new replies allowed.