AlgorithMan-de / wyoos

Source codes for the "Write your own Operating System" video-series on YouTube
http://wyoos.org
GNU General Public License v3.0
719 stars 222 forks source link

“lgdt” ASM code results in an error when compiler is optimised on level 2 #11

Open thehuzaifashaikh opened 5 years ago

thehuzaifashaikh commented 5 years ago

To load the Global Descriptor Table, the instruction “lgdt” when called from C code, gets discarded, and results in an error “Invalid asm operand: invalid expression”. This is only valid if the compiler is run in a level 2 optimised mode. If it’s not optimized, the compiler runs without any problem.

jlxip commented 5 years ago

You probably aren't using the volatile tag in the inline assembler. volatile tells the compiler explicitly not to remove or reorder the instructions.