Hello and welcome in this lecture, and we will check to see if the cpu support long mode.
The modern processors should support long mode. Since checking it is really simple, we will see how to do it
.
Another check we need to perform is 1g page support.
Our memory module allocates pages using this feature. So our kernel requires the processor support 1g page
.
The first thing we are going to do is we are going to save the drive id for later use.
Remember we have saved the drive id in dl register before we jump to the loader.
we define the variable
drive id
Just like we did in the boot file
and save the value of dl to the variable.
Ok let�s check long mode.
There is a special instruction called cpuid
which returns processor identification and feature information. We pass the input value
80000001 to eax
and execute cpuid. By passing different number to eax, we will get different information about processor returned by cpuid.
Passing 80000001 to eax will return processor features.
The information about long mode support is saved in edx.
We test bit 29 in edx.
If it is set, it means that long mode is supported.
Otherwise long mode is not available and we jump to the label not support.
So we use test instruction to test.
the bit 29 in edx
We use jz instruction.
If zero flag is set, it means that the bit we checked is not set and we jump to not support.
Also, we check 1g page support which is at bit 26, so we test edx
and the bit 26.
If it is set, this feature is supported.
If zero flag is set, it means that this feature is not supported and we jump to not support.
There is one thing left to do. Before we use value 80000001,
we need to check whether it supports this input value. In order to check that, we pass value
80000000 to eax
and execute cpuid instruction. If the return value in eax
is less than
80000001, we know that it does not support input value
So we use jb instruction, which means jump if below and we simply jump to not support.
Because our operating system is designed for running on long mode, we place not support at the end of the code
,
and stop here if the processor does not support it. Otherwise, we print message long mode is supported.
so we change the message
to long mode is supported.
OK, let's build the project and test it out in virtual machine.
We open the terminal.
and to navigate to the boot folder.
and run the build script.
OK, let's open the bochs, we double click it.
As you see long mode is supported is printed on screen?
OK, this is what it's showing in real machine.
That's it for this lecture.
See you in the next video.