Page 1 of 1
the jump form rmode to pmode
Posted: Tue Apr 14, 2009 4:07 am
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.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 4:11 am
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.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 4:14 am
by Love4Boobies
Your origin is 7E00h.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 4:26 am
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.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 4:31 am
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?
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 5:05 am
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
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 5:14 am
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.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 5:22 am
by Combuster
um, the far jump is needed to change from 16 bit code to 32 bit code
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 5:31 am
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.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 5:56 am
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
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 6:00 am
by faway
The problem is I have no idea how to manage the space if it complicated.
Code: Select all
Error: (0) print_guard_results: guard_found ? (stop reason 0)
It is driving me crazy!
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 8:42 am
by Troy Martin
One word: Google.
Another word: Wiki.
A final word:
http://www.catb.org/~esr/faqs/smart-questions.html
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 8:50 am
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).
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 9:30 am
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.
Re: the jump form rmode to pmode
Posted: Tue Apr 14, 2009 4:01 pm
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.