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.
-
As I recall it involves a half-suicide, kind of. A reset. You'll find the documentation at Intel. – Cheers and hth. - Alf Dec 09 '14 at 19:17
-
See the stuff at osdev.org. Note that you will probably enable protected mode and a20 from assembly and only go to your c++ kernel afterwards. Alternatively, use a multiboot loader which does it for you. – Jester Dec 09 '14 at 19:20
-
Do you have any links? Cheers and hth. - Alf – crank123 Dec 09 '14 at 19:20
-
A request for "any links" is inappropriate here. This is not a link locator service. – Ken White Dec 09 '14 at 19:33
1 Answers
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.

- 671
- 3
- 12
-
Thank you so much. This was really useful. I would vote up, but I only have two repetition. – crank123 Dec 09 '14 at 19:31