Search code examples
c++operating-system32-bitprotected-mode

C++ - 32 bit Protected Mode


I am working on an OS kernel which will be written in 32 bit C++. I need to figure out how I can enable 32 bit protected mode/enable the a20 gate in C++. So, may you tell me if that is possible and if so how? Thank you.


Solution

  • C and C++ have no idea what an "a20 gate" is and how to enable it. Same for "32 bit protected mode". This will need to be done through specific machine code. Now, the right question would be how to call this code from your C++ program. Depending on the C++ compiler, there could be several different way to do that:

    1) The simplest way is to use embedded assembly code using an asm, __asm or __asm__ block. Read carefully your C++ compiler documentation on how to use that. I am not sure that all compilers support that.

    2) Use an assembler to write the code using assembly code so that it can be called from your C++ application. Use extern "C" to declare the function in C++ program so you can call it.

    3) Even more nasty: put your assembly code into a byte array, convert the address to the array to a pointer to function and call it. Heavy knowledge of machine code and C/C++ calling convention necessary for that to work.