the jump form rmode to pmode

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
faway
Posts: 6
Joined: Mon Apr 13, 2009 9:28 pm

the jump form rmode to pmode

Post by faway »

Code: Select all

bits 16
org 0x7e00
jmp start
 	%include "stdio.inc"
	%include "gdt.inc"
	%include "A20.inc"

start:
	cli
	xor ax,ax
	mov ds,ax
	mov es,ax
	mov ax,0x9000
	mov ss,ax
	mov sp,0xffff

	call loadGDT
	
	call enableA20
	
	;cli
	
	mov eax,cr0
	or eax,1
	mov cr0,eax
	
	[color=#BF0000]jmp code_desc:protected_code[/color]
[bits 32]
protected_code:
	......

	times 1024-($-$$) db 0
This is the switch code about it.Before this code,i has done a lot of work in in the real mode.When bochs got the jmp,some error happend:
Error: (0) print_guard_results: guard_found ? (stop reason 0)
However,if i delete the job which in the real mode ,it ok.
faway
Posts: 6
Joined: Mon Apr 13, 2009 9:28 pm

Re: the jump form rmode to pmode

Post by faway »

Code: Select all

[bits 16]
loadGDT:
	cli
	pusha
	lgdt [gdt_desc]
	popa
	ret
gdt:
	dd 0
	dd 0
code_desc equ $-gdt
gdt_code:
	dw 0xffff
	dw 0
	db 0
	db 10011010b
	db 11001111b
	db 0
gdt_data:
	dw 0xffff
	dw 0
	db 0
	db 10010010b
	db 11001111b
	db 0
gdt_end:
gdt_desc:
	dw gdt_end - gdt  - 1
	dd gdt
this is the code about GDT.
Please help me.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: the jump form rmode to pmode

Post by Love4Boobies »

Your origin is 7E00h.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
faway
Posts: 6
Joined: Mon Apr 13, 2009 9:28 pm

Re: the jump form rmode to pmode

Post by faway »

I am sorry "Love4Boobies ",what's wrong about 0x7e00,this is the adress where I load the pmode code,and rmode is in the other place.
it's not the boot file.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: the jump form rmode to pmode

Post by Love4Boobies »

Ah, ok. So what is it that you do in real mode? Maybe you do something there that screwes up the rest (like writing over the EBDA or something).
EDIT: and are you sure this: jmp code_desc:protected_code is right?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
faway
Posts: 6
Joined: Mon Apr 13, 2009 9:28 pm

Re: the jump form rmode to pmode

Post by faway »

Love4Boobies wrote:Ah, ok. So what is it that you do in real mode? Maybe you do something there that screwes up the rest (like writing over the EBDA or something).
EDIT: and are you sure this: jmp code_desc:protected_code is right?
The "code_desc" has define in the second code about GDT.
Probably you are right,something may be writted,but I don't know how to check and amend.
I use bochs to debug,and I got the some info about registers just as follow.
before jmp:

Code: Select all

<bochs:9> info r
eax            0x60000011       1610612753
ecx            0x130000         1245184
edx            0x0              0
ebx            0x2              2
esp            0xffff           0xffff
ebp            0x0              0x0
esi            0x0              0
edi            0x10a            266
eip            0x1d3            0x1d3
eflags         0x46             70
cs             0x7e00           32256
ss             0x9000           36864
ds             0x40             64
es             0x0              0
fs             0x0              0
gs             0x0              0
after jmp

Code: Select all

<bochs:11> info r
eax            0x0              0
ecx            0x0              0
edx            0x300            768
ebx            0x0              0
esp            0x0              0x0
ebp            0x0              0x0
esi            0x0              0
edi            0x0              0
eip            0xfff0           0xfff0
eflags         0x2              2
cs             0xf000           61440
ss             0x0              0
ds             0x0              0
es             0x0              0
fs             0x0              0
gs             0x0              0
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: the jump form rmode to pmode

Post by Love4Boobies »

faway wrote:
Love4Boobies wrote:Ah, ok. So what is it that you do in real mode? Maybe you do something there that screwes up the rest (like writing over the EBDA or something).
EDIT: and are you sure this: jmp code_desc:protected_code is right?
The "code_desc" has define in the second code about GDT.
Yes. code_desc is a constant whose value is 8. Are you sure that's what you want? Are you sure you don't mean jmp protected_code instead? The code in you file is in the same segment so there's no need for a far jump.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
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: the jump form rmode to pmode

Post by Combuster »

um, the far jump is needed to change from 16 bit code to 32 bit code
"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
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: the jump form rmode to pmode

Post by Love4Boobies »

Combuster wrote:um, the far jump is needed to change from 16 bit code to 32 bit code
Ooops. Right, he was jumping to pmode. Still, be careful with the segment.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
faway
Posts: 6
Joined: Mon Apr 13, 2009 9:28 pm

Re: the jump form rmode to pmode

Post by faway »

Love4Boobies wrote:
Combuster wrote:um, the far jump is needed to change from 16 bit code to 32 bit code
Ooops. Right, he was jumping to pmode. Still, be careful with the segment.
If I code just as "jmp protected_code", it can jmp to the 32bit.However,when I init registers,the same error has happened. "mov es,ax" can't be executd.

Code: Select all

	jmp protected_code
[bits 32]
protected_code:
	  mov ax , data_desc  
    mov ds , ax
    [color=#FF0000]mov es , ax[/color]
    mov ss , ax 
    mov fs , ax 
    mov gs , ax
    mov esp , 0xffff 
faway
Posts: 6
Joined: Mon Apr 13, 2009 9:28 pm

Re: the jump form rmode to pmode

Post by faway »

The problem is I have no idea how to manage the space if it complicated. :x

Code: Select all

Error: (0) print_guard_results: guard_found ? (stop reason 0)
It is driving me crazy!
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: the jump form rmode to pmode

Post by Troy Martin »

One word: Google.

Another word: Wiki.

A final word: http://www.catb.org/~esr/faqs/smart-questions.html
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
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: the jump form rmode to pmode

Post by Combuster »

Troy Martin wrote:One word: Google.
Query text wanted. Plugging the error message yields no usable results.

EDIT: Have you fixed the ORG problem? could you post an updated register dump on the state before the far jump? From what I gathered the error message looks like a reset (in your case, triple fault).
"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 ]
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Re: the jump form rmode to pmode

Post by frank »

The problem is that CS isn't zero. The code goes from running at 0x7E00:something to 0:same something. The new GDT has a base of 0 and the old CS has a base of 0x7E00. I don't know how the NASM org instruction works exactly so I can't help you any further.

EDIT: Is the code running at 0x7E00 or 0x7E000? CS suggests the second and the ORG instruction the other.
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: the jump form rmode to pmode

Post by Troy Martin »

Combuster wrote:
Troy Martin wrote:One word: Google.
Query text wanted. Plugging the error message yields no usable results.
I'm putting my invisible tokens on the line by saying that I bet it's a problem with the GDT.
cs 0xf000 61440
Something here looks incorrectly set up. Probably either the GDT or the jump. Probably also causing a triple fault.

OP: try, instead of using your code_desc and data_desc things, use 0x08 and 0x10 respectively.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
Post Reply