Page 1 of 1

Error entering protected mode

Posted: Fri Oct 17, 2008 2:11 pm
by posman
Hi.

I've just modified my boot loader but now it doesn't enter protected mode. Debugging (with bochs), when the line "move cr0, eax" is executed, the next code that is executed is at address 0x0000

Maybe LGDT has an invalidad value? Does DS has to have a specified value? At the moment when I load GDT, DS = 0x8000

These are images of debug
Before loading GDT

Image
After

Image

This is the part of code for the gdt:

Code: Select all

	cli                  ; Inhabilitar interrupciones

	lgdt [gdt_desc]      ; leer GDT

	mov eax, cr0
	or eax, 1
	mov cr0, eax

	jmp 0x08:limpiarRegistros
...
use32
...
gdt:
gdt_null:
	dd 0
	dd 0

gdt_code:               ; segmento de codigo
	dw 0x0FFFF
	dw 0
	db 0
	db 10011010b
	db 11001111b
	db 0

gdt_data:               ; segmento de datos
	dw 0x0FFFF
	dw 0
	db 0
	db 10010010b
	db 11001111b
	db 0
gdt_end:                ; para calcular el tamano de la GDT
gdt_desc:
	dw gdt_end - gdt - 1  ; limite
	dd gdt                ; direccion de la GDT

Re: Error entering protected mode

Posted: Fri Oct 17, 2008 2:58 pm
by cr2
try adding this inside the function that enters protected mode(no "JMP 0x08:limpiarRegistros")

Code: Select all

mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:setCodeSeg
setCodeSeg:
P.S. Translate your code comments into english next time. :wink:

Re: Error entering protected mode

Posted: Fri Oct 17, 2008 3:16 pm
by kmtdk
well
if you send the compilede data, i could take a greater look at it ..

KMT dk

Re: Error entering protected mode

Posted: Fri Oct 17, 2008 10:22 pm
by egos
Your descriptors contain zero base, but you are using displacements relatively the address 0x80000.

Try this:

Code: Select all

gdt:
  dq 0
  desc 0x80000, (0x100000000-0x80000)/0x1000-1, DF_CODE or DF_DUALACTION or DF_USE32 or DF_PAGED
  desc 0x80000, (0x100000000-0x80000)/0x1000-1, DF_DATA or DF_DUALACTION or DF_USE32 or DF_PAGED
Or this:

Code: Select all

  ...
  jmp pword 8:startup32

  use32
  org 0x80000+$
startup32:
  ...

Re: Error entering protected mode

Posted: Sat Oct 18, 2008 12:44 am
by egos

Code: Select all

mov ax, 0x08
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
jmp 0x08:setCodeSeg
setCodeSeg:
cr2, cs must be initialized firstly!

This right:

Code: Select all

jmp 0x08:setCodeSeg
...
setCodeSeg:
mov eax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax

Re: Error entering protected mode

Posted: Sat Oct 18, 2008 3:41 am
by pcmattman
cr2, cs must be initialized firstly!
The segment registers are preserved over a far jump, so it should work either way. The value of 0x8 for DS, ES, FS and GS is incorrect, though.

EDIT: Also, that far jump is only to load the new CS (because you can't do mov cs,ax) - protected mode is technically already active at this point.

Re: Error entering protected mode

Posted: Sat Oct 18, 2008 4:35 am
by egos
The selector 8 is correct for data segment registers if the code segment (that it selects) is readable. Loading of data segment registers depends on CS.CPL, therefore to initialize cs firstly is more right.

Re: Error entering protected mode

Posted: Sat Oct 18, 2008 5:15 am
by Combuster
...and CS.CPL is zero in real mode so it doesn't matter anyway

Re: Error entering protected mode

Posted: Sat Oct 18, 2008 8:56 am
by cr2
Sorry for the 0x08(I promise I will not post on OSDEV.ORG when I should be sleeping).

Re: Error entering protected mode

Posted: Sat Oct 18, 2008 9:01 am
by cr2
Can we see limpiarRegistros?