debug using bochs

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
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

debug using bochs

Post 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'?
Just For Fun
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: debug using bochs

Post by Troy Martin »

why dh's value changed after 'mov ds, ax' in real mode?
Umm, cause your code sets DS to AX. #-o
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
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: debug using bochs

Post 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?
Just For Fun
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: debug using bochs

Post by Troy Martin »

#-o #-o #-o #-o
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.
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
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: debug using bochs

Post 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.
Just For Fun
User avatar
Helu
Posts: 10
Joined: Mon Feb 11, 2008 8:10 pm
Location: An Hui China

Re: debug using bochs

Post 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
Love HeLU
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: debug using bochs

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Helu
Posts: 10
Joined: Mon Feb 11, 2008 8:10 pm
Location: An Hui China

Re: debug using bochs

Post 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.
Love HeLU
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: debug using bochs

Post 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
Just For Fun
Post Reply