Error: operand type mismatch for `mov'

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
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Error: operand type mismatch for `mov'

Post by osdever »

I've encountered a problem with inline assembly. Maybe this is very nooby question, but why I'm getting this error:

Code: Select all

/tmp/ccgqP61A.s: Assembler messages:
/tmp/ccgqP61A.s:255: Error: operand type mismatch for `mov'
/tmp/ccgqP61A.s:255: Error: operand type mismatch for `mov'
in this code:

Code: Select all

void switch_task(struct task *task)
{
	asm("mov eax, %0;"
		"mov ebx, %1;"
		"mov ecx, %2;"
		"mov edx, %3;"
		"mov esi, %4;"
		"mov edi, %5;"
		"push %6;"
		"popf;"
		"mov esp, %7;"
		"mov cr0, %8;"
		"mov cr3, %9;"
		"jmp %10;" :
		"=g" (task->eax),
		"=g" (task->ebx),
		"=g" (task->ecx),
		"=g" (task->edx),
		"=g" (task->esi),
		"=g" (task->edi),
		"=g" (task->eflags),
		"=g" (task->stack),
		"=g" (task->cr0),
		"=g" (task->cr3),
		"=g" (task->eip));
}
? Tell me if you want some other info.
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
heat
Member
Member
Posts: 103
Joined: Sat Mar 28, 2015 11:23 am
Libera.chat IRC: heat

Re: Error: operand type mismatch for `mov'

Post by heat »

I'm afraid you wrote inline assembly using the Intel syntax, instead of the gcc-standard AT&T syntax.
If some of you people keep insisting on having backwards compatibitity with the stone age, we'll have stone tools forever.
My Hobby OS: https://github.com/heatd/Onyx
Octocontrabass
Member
Member
Posts: 5587
Joined: Mon Mar 25, 2013 7:01 pm

Re: Error: operand type mismatch for `mov'

Post by Octocontrabass »

Any tasks that use EBP will have some trouble.

Clobbering registers without telling GCC is a bad idea.

It's impossible for GCC to generate valid code here - you're clobbering all of the registers it needs in order to access your task struct.

GCC uses AT&T syntax by default. If you want Intel syntax, make sure you're using the right command-line options.

The "g" constraint allows memory and immediate operands, but MOV with a control register as the destination only allows general purpose registers as the source.
User avatar
osdever
Member
Member
Posts: 492
Joined: Fri Apr 03, 2015 9:41 am
Contact:

Re: Error: operand type mismatch for `mov'

Post by osdever »

Octocontrabass wrote:GCC uses AT&T syntax by default. If you want Intel syntax, make sure you're using the right command-line options.
I've used -masm=intel in CFLAGS.
Didn't known about EBP and control registers' behaivor. Maybe I will remove them fully?
Developing U365.
Source:
only testing: http://gitlab.com/bps-projs/U365/tree/testing

OSDev newbies can copy any code from my repositories, just leave a notice that this code was written by U365 development team, not by you.
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Error: operand type mismatch for `mov'

Post by Ch4ozz »

Push all values from the struct onto the stack and it should work just fine.
Set EBP last and thats it.

Since you have to change all registers this isnt as easy as it seems because the data has to be stored atleast into one register so you can work with it.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Error: operand type mismatch for `mov'

Post by iansjack »

Personally, I would write this as a separate function in assembler rather than using in-line assembler.
Post Reply