[Qemu] Problem with MOV instruction

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
fiveayem
Member
Member
Posts: 51
Joined: Sun Aug 14, 2011 8:01 am

[Qemu] Problem with MOV instruction

Post 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 ?
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: [Qemu] Problem with MOV instruction

Post 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.
Last edited by DavidCooper on Mon Dec 26, 2011 2:34 pm, edited 2 times in total.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: [Qemu] Problem with MOV instruction

Post 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
fiveayem
Member
Member
Posts: 51
Joined: Sun Aug 14, 2011 8:01 am

Re: [Qemu] Problem with MOV instruction

Post by fiveayem »

Ok, I understand now. Thanks for your help. :)
Post Reply