OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 7:45 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 6:53 am 
Offline

Joined: Sun Feb 26, 2017 7:52 am
Posts: 9
Hello, i am debugging my code on bochs. at a point as you can see cs:ip is 0x0000:0x7eef and the next instruction is supposed to be at 0x0000:0x7ef2. but when i execute "s 1" command( which executes only one instruction), it executes "push ax" at address f000:e9df. do you have any idea why i get such a behaviour?
picture : http://i.imgur.com/H4vhB1g.jpg


Top
 Profile  
 
 Post subject: Re: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 7:28 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
I can't really read your screen shot, but I'm guessing you have triggered an exception and are seeing the first instruction of the exception handler.


Top
 Profile  
 
 Post subject: Re: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 7:34 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5137
It looks like Bochs is telling you exactly what's wrong.

Code:
00014176438e[CPU0 ] write_virtual_word_32(): segment limit violation


Top
 Profile  
 
 Post subject: Re: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 7:47 am 
Offline

Joined: Sun Feb 26, 2017 7:52 am
Posts: 9
I am in real mode, do you have any idea about the triggered exception by executing the following commands?
Code:
    7eef:   67 89 02                mov    WORD PTR [edx],ax
    7ef2:   66 a1 1c 00             mov    eax,ds:0x1c

(disassembly has generated by OBJDUMP command)


Last edited by atilali on Sat May 27, 2017 7:51 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 7:51 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

atilali wrote:
I am in real mode, do you have any idea about the triggered exception by executing the following commands?
Code:
    7eef:   67 89 02                mov    WORD PTR [edx],ax
    7ef2:   66 a1 1c 00             mov    eax,ds:0x1c


In real mode the segment limits are all 64 KiB, so if EDX contains a value that is larger than 0x0000FFFC (which is "0x00010000 - 4") when you execute "mov WORD PTR [edx],ax" you get a General Protection Fault (exception) because of a segment limit violation.


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.


Top
 Profile  
 
 Post subject: Re: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 8:00 am 
Offline

Joined: Sun Feb 26, 2017 7:52 am
Posts: 9
Thank you Brendan!

EDX had the value of 0xb8000. Is it allowed to use EDX register for addressing like that(MOV WORD PTR [edx],ax) in real mode? I didn't know that i am unable to address beyond 0xFFFC even though it's allowed to use edx(if it is allowed). i will use segment:offset addresing to fix the problem.


Top
 Profile  
 
 Post subject: Re: Bochs wrong instruction executed
PostPosted: Sat May 27, 2017 8:53 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

atilali wrote:
Is it allowed to use EDX register for addressing like that(MOV WORD PTR [edx],ax) in real mode?


Yes. In real mode (and in 16-bit code in general - e.g. including 16-bit protected mode code) the default is "16 bit", but that default can be overridden with instruction prefixes and nothing prevents you from using 32-bit registers/addresses/instructions (with appropriate size override prefixes) if the CPU supports it (80386 or later).

In 32-bit code it's the opposite - the default is "32 bit", but the same prefixes can be used to override that if you want to use 16-bit registers/addresses/instructions. For 64-bit code things get a little strange - the default is typically "32-bit", and prefixes can be used to get 16-bit or 64-bit.

Fortunately the assembler will handle the size override prefixes for you (you can just do whatever you like and let the assembler figure them out.


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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 150 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group