64-bit long mode compatability with 32-bit instructions-GAS (Developers)
> Hi,
Hopefully marcov (amd64 expert) can chime in more here.
> in my multiplatform C code (I use GCC) I have a few lines of inline
> assembler. I tried it to recompile under 64-bit Linux and I got an error
> from gcc/gas that some instructions has invalid suffix, e.g.:
> " pushfl ; "
> " popl %%eax ; "
> I searched for solution and found that I have to use 64-bit extended
> instructions instead so I used:
> #ifdef __x86_64__
> " pushfq ; "
> " popq %%rax ; "
> Now it seems to work.
Presumably this is to avoid misaligning the stack since SSE is mandatory.
> Do I really need to make branching for 32-bit and
> 64-bit platform?
Compatibility is rarely as simple as just recompiling.
> Does it mean that if CPU is in long mode it is not
> compatible with 32b (and 16b) instructions?
Not 100%, no, you have to avoid some instructions (e.g. AAM, SAHF) and keep in mind that "xor eax,eax" will clear rax (etc. etc.) among other things.
> Then how does 64-bit windows run older 32-bit apps without recompiling?
It's not 100% transparent. You can't mix drivers or plugins or libraries. All of that has to be duplicated / redone. Windows server editions (I think) even make the 32-bit compatibility optional.
> I know that it use some WoW64
> layer but I don't know what it is exactly doing. If I would use long mode
> under DOS then do I need to write all in 64-bit asm (otherwise will I got
> invalid opcode exception)?
No idea, probably can't use long mode + DOS at all. It wasn't really designed for that (although VT-X maybe allows a way, indirectly). In other words, you're probably expected to host a 16-bit VM atop a 64-bit OS rather than trying the opposite.
P.S. Don't forget that some people don't want to be compatible, they want you to "upgrade" to them, exclusively! It's not a given that they want to help you at all.
Complete thread:
- 64-bit long mode compatability with 32-bit instructions-GAS - RayeR, 22.01.2014, 23:44
![Open in board view [Board]](img/board_d.gif)
![Open in mix view [Mix]](img/mix_d.gif)
- 64-bit long mode compatability with 32-bit instructions-GAS - Rugxulo, 23.01.2014, 01:10
- 64-bit long mode compatability with 32-bit instructions-GAS - Oso2k, 23.01.2014, 01:34
- 64-bit long mode compatability with 32-bit instructions-GAS - RayeR, 23.01.2014, 03:03
- 64-bit long mode compatability with 32-bit instructions-GAS - alexfru, 23.01.2014, 08:34
- 64-bit long mode compatability with 32-bit instructions-GAS - georgpotthast, 23.01.2014, 20:16
- 64-bit long mode compatability with 32-bit instructions-GAS - alexfru, 23.01.2014, 08:34
- 64-bit long mode compatability with 32-bit instructions-GAS - marcov, 23.01.2014, 21:57
Mix view