I am writing a second stage bootloader, a part of whose responsibility will be to enter 32 bit protected mode from 16 bit real mode.
My code has some initializing real mode code, a few real mode functions, protected mode code and a few protected mode ones. Here's what I had done (the actual code is in the same order):
Added
BITS 16
before the starting of first real mode function.Added
BITS 32
before the first protected mode functionAdded
BITS 16
before the initializing real mode codeAdded
BITS 32
before the initializing protected mode code (basically beforemov cr0, eax
afterOR
ingeax
with 1.
This didn't work, so I read NASM's manual which said its not necessary to use this directive. I removed all of them and the code worked!
So what was the mistake in my approach ? Also, am I somehow mixing up bitness and the processor mode ?