LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2011, 11:22 AM   #1
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
[assembler] Operand type mismatch for 'and'


I'm trying to compile grub-legacy using gcc-4.5.3/binutils-2.21.53.0.2 am getting this error during compilation:
Error: Operand type mismatch for 'and'
The offending lines are like this:
Code:
    and $0xffffffff    %rsi
Searching for "Operand type mismatch for 'and'" hasn't helped. Does anyone have any idea what is wrong here?
 
Old 10-08-2011, 03:27 AM   #2
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by gnashley View Post
I'm trying to compile grub-legacy using gcc-4.5.3/binutils-2.21.53.0.2 am getting this error during compilation:
Error: Operand type mismatch for 'and'
The offending lines are like this:
Code:
    and $0xffffffff    %rsi
Searching for "Operand type mismatch for 'and'" hasn't helped. Does anyone have any idea what is wrong here?
first of all, that seems a strange syntax to me. Totally different to what I'm used to. I guess that instruction would "normally" be

and si,0xFFFFFFFF

And as you can see, that tries to involve a 16bit register and a 32bit constant. That can't be right.

Besides, hexadecimal numbers are prefixed with 0x or, less frequently, a dollar sign - but not both at the same time. Another common way to indicate hexadecimal numbers, especially in Assembler, is a trailing 'h'.

[X] Doc CPU
 
Old 10-08-2011, 06:01 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
Quote:
... using gcc-4.5.3/binutils-2.21.53.0.2 ...
Must be the 32bits Slackware-current ? The 64bits OS would say :
C compiler cannot create executables.

Issues are expected, I guess : The grub-0.97 code is from year 2003.
Most OS' use older grub packages for the latest OS version.
Example: "slackware-current/extra/grub/grub-0.97-i486-9.txz" : 14-May-2010.
And : Debian (Wheezy) has "gcc-4.3" as a dependency for building grub-legacy.

Fedora 16 has patches, that will fix the issues for 32bits Slackware-current :
1) 0001-Fall-back-to-old-efi-GOP-detection-behavior.patch
2) 0001-Fix-strange-compilation-problem.patch
3) grub-fedora-16.patch : 1.7 MB / 47,000 lines.
→ → gcc-4.5.3 will do OK.
http://download.fedora.redhat.com/pu...9.fc16.src.rpm
> > grub-0.97-79.fc16.src.rpm

.

Last edited by knudfl; 10-08-2011 at 06:36 AM.
 
Old 10-08-2011, 10:45 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by Doc CPU View Post
first of all, that seems a strange syntax to me. Totally different to what I'm used to. I guess that instruction would "normally" be

and si,0xFFFFFFFF
What you call "normal" is Intel syntax, the "strange" syntax is AT&T which is what (g)as uses. See AT&T Syntax versus Intel Syntax.

Quote:
And as you can see, that tries to involve a 16bit register and a 32bit constant. That can't be right.
16bit registers!? esi is the 32bit version of si, and rsi is the 64bit one.
 
Old 10-08-2011, 11:19 AM   #5
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Original Poster
Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
"Must be the 32bits Slackware-current ?" No, but I expect they would have the same problem if they tried to re-compile grub-0.97 right now. It turns out to be the binutils version causing the problem. Thanks knudfl for the link to the latest fedora rpm -I had already found a couple for ~fc13 to look for corrective patches to the source itself.

"gcc-4.3 as a dependency" I keep 4.2.1 around for anything pretty old. In fact I keep 3.4.6 around for one favorite 'oldy'.

Meanwhile, I'll look for another binutils version which matches well with gcc-4.5.3/glibc-2.13. I'd like to find a single combination which works well for both ix86 and ARM arches. I'm upgrading from glibc-2.11.1/gcc-4.4.3/binutils-2.19.
I'm consulting crosstool-ng's 'status' table for clues regarding arm. ANyone have a better idea?
 
Old 10-08-2011, 12:24 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by ntubski View Post
16bit registers!? esi is the 32bit version of si, and rsi is the 64bit one.
Since your immediate data operand only specifies 32 bits, and the MSB is a 'one', I would hazard a guess that the assembler cannot decide whether the operand should be extended to '00000000FFFFFFFF' or 'FFFFFFFFFFFFFFFF', or something else altogether.
--- rod.
 
Old 10-08-2011, 01:43 PM   #7
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by theNbomr View Post
Since your immediate data operand only specifies 32 bits, and the MSB is a 'one', I would hazard a guess that the assembler cannot decide whether the operand should be extended to '00000000FFFFFFFF' or 'FFFFFFFFFFFFFFFF', or something else altogether.
In the x86_64 machine language, an immediate data operand to a 64 bit AND instruction can only be an 8-bit or 32-bit value sign extended to 64-bit.

0x00000000FFFFFFFF is not a possible operand for that instruction.

So my guess is this instruction is incorrect and the assembler is correct to reject it. I don't know for sure. Maybe the rules of the assembler are the same as the rules of the machine language that writing a 32 bit constant in a 64 bit AND instruction inherently means the 64 bit sign extend of that 32 bit constant. That would be a stupid choice for an assembler designer. An assembler constant does not inherently have a size. So 0xFFFFFFFF in 64 bit assembler ought to mean 4294967295 and ought not to mean -1.

Whatever that instruction does or should mean, it seems to be a rotten way to accomplish whatever it is supposed to accomplish. But I don't understand enough of the OP's posts or knudfl's plausible looking reply to put any of that in real context.

Quote:
Originally Posted by gnashley View Post
It turns out to be the binutils version causing the problem.
Can you explain that? Is the "bad" assembler instruction generated by some part of binutils (maybe from C code in the grub sources)? I would have guessed that instruction was more directly from the grub sources.

Or do you mean you think that assembler line isn't bad and/or some version of as will interpret it as meaning
AND $-1, %rsi

I'm also confused by your and knudfl's mention of "32bits Slackware" when discussing an assembler instruction that uses a 64 bit general register.

Are we talking about a 32 bit assembler in which %rsi is not valid as any operand of any instruction? Or are we talking about a 64 bit assembler in which 0xFFFFFFFF should not be valid as the source operand of an AND instruction?

Last edited by johnsfine; 10-08-2011 at 02:31 PM.
 
Old 10-08-2011, 02:28 PM   #8
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Hi there,

Quote:
Originally Posted by ntubski View Post
What you call "normal" is Intel syntax, the "strange" syntax is AT&T which is what (g)as uses. See AT&T Syntax versus Intel Syntax.
thanks for the information - up to now I only knew the Intel syntax (I grew up with TASM & MASM).

Quote:
Originally Posted by ntubski View Post
16bit registers!? esi is the 32bit version of si, and rsi is the 64bit one.
Since I didn't know what %RSI was supposed to mean, I guessed it was the "strange" form for "register SI". And I've never programmed 64bit code, so I didn't know about the special meaning of RSI. By the way, what does the 'R' literally stand for?

[X] Doc CPU
 
Old 10-08-2011, 05:08 PM   #9
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by Doc CPU View Post
By the way, what does the 'R' literally stand for?
I think it stands for... register .
Quote:
X86-64 defines eight new integer registers named r8-r15.
From http://www.x86-64.org/documentation/assembly.html. So the r is just to match the new registers.
 
  


Reply

Tags
%rsi



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java - "Type mismatch: cannot convert from element type Object to int[]" Infasoft Programming 2 07-09-2010 01:06 PM
Error: operand out of range anhvuitinh Red Hat 1 04-02-2010 08:12 AM
mtrr type mismatch Z038 Linux - General 6 08-03-2009 12:01 AM
mtrr type mismatch? Vgui Linux - General 1 08-13-2005 05:53 PM
invalid operand 0000 x2000koh Linux - General 3 07-03-2003 08:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration