Error entering protected mode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
posman
Posts: 19
Joined: Fri Sep 05, 2008 12:55 pm

Error entering protected mode

Post 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
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: Error entering protected mode

Post 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:
Last edited by cr2 on Sat Oct 18, 2008 8:55 am, edited 1 time in total.
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: Error entering protected mode

Post by kmtdk »

well
if you send the compilede data, i could take a greater look at it ..

KMT dk
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Error entering protected mode

Post 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:
  ...
If you have seen bad English in my words, tell me what's wrong, please.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Error entering protected mode

Post 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
If you have seen bad English in my words, tell me what's wrong, please.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: Error entering protected mode

Post 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.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Error entering protected mode

Post 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.
If you have seen bad English in my words, tell me what's wrong, please.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Error entering protected mode

Post by Combuster »

...and CS.CPL is zero in real mode so it doesn't matter anyway
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: Error entering protected mode

Post by cr2 »

Sorry for the 0x08(I promise I will not post on OSDEV.ORG when I should be sleeping).
OS-LUX V0.0
Working on...
Memory management: the Pool
User avatar
cr2
Member
Member
Posts: 162
Joined: Fri Jun 27, 2008 8:05 pm
Location: ND, USA

Re: Error entering protected mode

Post by cr2 »

Can we see limpiarRegistros?
OS-LUX V0.0
Working on...
Memory management: the Pool
Post Reply