Bochs wrong instruction executed

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
atilali
Posts: 9
Joined: Sun Feb 26, 2017 7:52 am

Bochs wrong instruction executed

Post by atilali »

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
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Bochs wrong instruction executed

Post by iansjack »

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.
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Bochs wrong instruction executed

Post by Octocontrabass »

It looks like Bochs is telling you exactly what's wrong.

Code: Select all

00014176438e[CPU0 ] write_virtual_word_32(): segment limit violation
atilali
Posts: 9
Joined: Sun Feb 26, 2017 7:52 am

Re: Bochs wrong instruction executed

Post by atilali »

I am in real mode, do you have any idea about the triggered exception by executing the following commands?

Code: Select all

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

Re: Bochs wrong instruction executed

Post by Brendan »

Hi,
atilali wrote:I am in real mode, do you have any idea about the triggered exception by executing the following commands?

Code: Select all

    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.
atilali
Posts: 9
Joined: Sun Feb 26, 2017 7:52 am

Re: Bochs wrong instruction executed

Post by atilali »

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

Re: Bochs wrong instruction executed

Post by Brendan »

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.
Post Reply