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.