Page 1 of 1
debug using bochs
Posted: Wed Feb 04, 2009 9:56 pm
by david
Code: Select all
(0) [0x00007d16] 07c0:0116 (unk. ctxt): mov ds, ax ; 8ed8
<bochs:40> dump_cpu
......
ds:s=0x0010, dl=0x0000ffff, dh=0x00009200, valid=1
......
<bochs:41> s
Next at t=2082197
(0) [0x00007d18] 07c0:0118 (unk. ctxt): mov es, ax ; 8ec0
<bochs:42> dump_cpu
......
ds:s=0x07c0, dl=0x7c00ffff, dh=0x00009300, valid=1
......
source code:
Code: Select all
; set DS=ES=CS after jump from protect mode to real mode
mov ax, cs
mov ds, ax
mov es, ax
why dh's value changed after 'mov ds, ax' in real mode?
what's the meaning of 'valid'?
Re: debug using bochs
Posted: Wed Feb 04, 2009 10:03 pm
by Troy Martin
why dh's value changed after 'mov ds, ax' in real mode?
Umm, cause your code sets DS to AX.
Re: debug using bochs
Posted: Wed Feb 04, 2009 10:08 pm
by david
I remembered that it's impossible to change the value in real mode, but it changed, so i doubt.
it's allowed to edit the value in real mode?
Re: debug using bochs
Posted: Wed Feb 04, 2009 10:14 pm
by Troy Martin
Here's a breakdown of the code:
Code: Select all
mov ax, cs ; makes AX = CS
mov ds, ax ; makes DS = AX
mov es, ax ; makes ES = AX
Can't get any more simpler than that.
Re: debug using bochs
Posted: Wed Feb 04, 2009 10:25 pm
by david
Code: Select all
<bochs:26> u
00007cfa: ( ): mov ds, ax ; 8ed8
<bochs:27> dump_cpu
......
ds:s=0x07c0, dl=0x7c00ffff, dh=0x00009300, valid=1
......
<bochs:28> s
Next at t=2082187
(0) [0x00007cfc] 0008:00000000000000fc (unk. ctxt): mov es, ax
<bochs:29> dump_cpu
......
ds:s=0x0010, dl=0x0000ffff, dh=0x00009200, valid=1
......
source code:
Code: Select all
; DS=ES=SS=FS=GS
; GDT_Data_Sel is a selector
mov ax, GDT_Data_Sel
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov gs, ax
when i set ds to a selector, the A(bit0) should be 1, so dh should be 0x00009300, but its value is 0x00009200. i can't understand. the code in protect mode.
Re: debug using bochs
Posted: Thu Feb 05, 2009 12:49 am
by Helu
Hi,
david wrote:ds:s=0x07c0, dl=0x7c00ffff, dh=0x00009300, valid=1
...........................................
ds:s=0x0010, dl=0x0000ffff, dh=0x00009200, valid=1
Comparing the above two,not only dh has been changed from 0x00009300 to 0x00009200,but dl has been changed too.
I suggest you post more code ,so we can simulate and help you.
HeLU
Re: debug using bochs
Posted: Thu Feb 05, 2009 1:02 am
by Brendan
Hi,
Helu wrote:david wrote:ds:s=0x07c0, dl=0x7c00ffff, dh=0x00009300, valid=1
...........................................
ds:s=0x0010, dl=0x0000ffff, dh=0x00009200, valid=1
Comparing the above two,not only dh has been changed from 0x00009300 to 0x00009200,but dl has been changed too.
Sure - the base address of the segment changed from 0x7C00 to 0x0000 in dl, and the segment type changed from "read/write accessed" to "read/write" in dh. I'd assume that as soon as you use the DS segment for something it'll change back to "read/write accessed".
Note: The segment limit, DPL, granularity flag, default operand size flag and "available" flag didn't change.
It all looks perfectly normal (for real mode) to me...
Cheers,
Brendan
Re: debug using bochs
Posted: Thu Feb 05, 2009 1:19 am
by Helu
Hi,
Seems it is in PMode?
Troy Martin wrote:; GDT_Data_Sel is a selector
mov ax, GDT_Data_Sel
It mentions GDT... ,after all.
Re: debug using bochs
Posted: Thu Feb 05, 2009 1:36 am
by david
GDT:
Code: Select all
GDT label byte
GDT_Null s_RestoreDescriptor <>
GDT_Code s_RestoreDescriptor <0FFFFh, 7C00h, 0, 10011010b, 0, 0> ; Base=7C00h Limit=0FFFFh
GDT_Code_Sel = offset GDT_Code - offset GDT
GDT_Data s_RestoreDescriptor <0FFFFh, 0, 0, 10010010b, 0, 0> ; Base=0h Limit=0FFFFh
GDT_Data_Sel = offset GDT_Data - offset GDT
Code: Select all
s_RestoreDescriptor struc
LimitL dw 0 ; Segment Limit 0~15
BaseL dw 0 ; Segment Base 0~15
BaseM db 0 ; Segment Base 16~23
AttrL db 0 ; Low Attr
AttrLimitH db 0 ; High Attr and Limit 16~19
BaseH db 0 ; Base 24~31
s_RestoreDescriptor ends