Q&A: Initializing protected mode

Q&A: Initializing protected mode

This is a question received by Intel Software Network Support, along with the submitter's own solution:

Q. Just wondering why a piece of code such as the following is causing a reset when it's booted - it's (meant to be) based on the example in your manual.
Obviously I'm not understanding something. The following's in NASM syntax by the way.

bits 16

// setup temporary descriptor table at 0
mov ebx, 0x0

// null
mov dword [ebx], 0
mov dword [ebx+4], 0

// temporary data descriptor
mov dword [ebx+8], 0x0000ffff
mov dword [ebx+12], 0x00cf9200

// contents for the gdtr (limit 15 (16 bytes)) base 0
mov dword [ebx+32], 15
mov dword [ebx+34], 0

// load gdtr from the
lgdt [ebx+32]

// switch into protected mode using the PE bit
mov ebx, cr0
or ebx, 0x1
mov cr0, ebx

I've tested the code in various vms - blows up in each.

A. I suspect I've found the issue - I didn't perform a near jump down to the initial code segment base and (also) didn't use nops to fill the 16 bytes from 0xFFFFFFF0 in there.

1 post / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.