Page 1 of 1

[Qemu] Problem with MOV instruction

Posted: Mon Dec 26, 2011 11:45 am
by fiveayem
Hello,

I am currently testing my OS under qemu and it seems that there is a great problem with MOV emulation. Indeed, in the ELF I am launching under my OS, the instruction :

Code: Select all

8b 15 40 80 00 40       mov    0x40008040,%edx
is interpreted as follows :

Code: Select all

mov    0x8e0f0100,%edx
Indeed, I could see that the value 0x8e0f0100 (instead of 0x40008040) was put into EDX register by manually inserting breakpoints in the ELF code. After the ELF was loaded into memory by my loader, I printed some debug lines to make sure that the memory location where the instruction resided did contain valid data, and it was the case (it did contain these six bytes : 8b 15 40 80 00 40). I am also sure that the instruction is executed by the emulator (also used breakpoints to make sure of it). Moreover, it has probably nothing to do with my task scheduler, because interrupts are disabled during registers backup procedure.

Where does the problem come from, according to you ?

Re: [Qemu] Problem with MOV instruction

Posted: Mon Dec 26, 2011 2:24 pm
by DavidCooper
You've used the wrong instruction. 8b 15 loads edx with four bytes found at the location stated by an immediate address. You want to find a form of mov instruction that loads edx with an immediate value.

Edit: When you've found the right syntax for the instruction, it should translate to BA followed by the four bytes you want to appear in edx.

Re: [Qemu] Problem with MOV instruction

Posted: Mon Dec 26, 2011 2:27 pm
by JamesM
DavidCooper wrote:You've used the wrong instruction. 8b 15 loads edx with four bytes found at the location staded by an immediate address. You want to find a form of mov instruction that loads edx with an immediate value.
Specifically, AT&T syntax uses bare constant integers as indirect pointers - i.e.:

Code: Select all

mov 0x4, %eax
is equivalent to the intel syntax:

Code: Select all

mov eax, [0x4]
You want to prefix the constant with a dollar sign, to make it an immediate:

Code: Select all

mov $0x4, %eax
James

Re: [Qemu] Problem with MOV instruction

Posted: Mon Dec 26, 2011 2:45 pm
by fiveayem
Ok, I understand now. Thanks for your help. :)