From 5e47b08dc80281e27f0cd7c15d0d91a2e1c0a636 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 9 May 2016 21:38:01 +0200 Subject: [x86] Fix some asm problems A bag of assembler fixes, to be either compatible with GAS (e.g. order of 'test' operands), accept more instructions, count correct foo{bwlq} variants on x86_64, fix modrm/sib bytes on x86_64 to not use %rip relative addressing mode, to not use invalid insns in tests/asmtest.S for x86_64. Result is that now output of GAS and of tcc on tests/asmtest.S is mostly the same. --- tests/asmtest.S | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 8 deletions(-) (limited to 'tests/asmtest.S') diff --git a/tests/asmtest.S b/tests/asmtest.S index e235c80..0876aa8 100644 --- a/tests/asmtest.S +++ b/tests/asmtest.S @@ -38,7 +38,7 @@ mov %al, 0x10000 mov $1, %edx mov $1, %dx -mov $1, %dl +mov $1, %cl movb $2, 0x100(%ebx,%edx,2) movw $2, 0x100(%ebx,%edx,2) movl $2, 0x100(%ebx,%edx,2) @@ -48,12 +48,20 @@ movw %ax, 0x100(%ebx,%edx,2) mov %eax, 0x12(,%edx,2) +#ifdef __i386__ mov %cr3, %edx mov %ecx, %cr3 movl %cr3, %eax movl %tr3, %eax movl %db3, %ebx movl %dr6, %eax +#else +mov %cr3, %rdx +mov %rcx, %cr3 +movq %cr3, %rax +movq %db3, %rbx +movq %dr6, %rax +#endif movl %fs, %ecx movl %ebx, %fs @@ -69,18 +77,28 @@ movl %ebx, %fs movzb 0x1000, %ax +#ifdef __i386__ pushl %eax - pushw %ax push %eax push %cs +#else + pushq %rax + push %rax +#endif + pushw %ax push %gs push $1 push $100 +#ifdef __i386__ popl %eax - popw %ax pop %eax pop %ds +#else + popq %rax + pop %rax +#endif + popw %ax pop %fs xchg %eax, %ecx @@ -111,11 +129,13 @@ movl %ebx, %fs leal 0x1000(%ebx), %ecx lea 0x1000(%ebx), %ecx +#ifdef __i386__ les 0x2000, %eax lds 0x2000, %ebx + lss 0x2000, %edx +#endif lfs 0x2000, %ecx lgs 0x2000, %edx - lss 0x2000, %edx addl $0x123, %eax add $0x123, %ebx @@ -195,7 +215,11 @@ shrd %eax, %edx L4: call 0x1000 call L4 +#ifdef __i386__ call *%eax +#else +call *%rax +#endif call *0x1000 call func1 @@ -204,19 +228,37 @@ call func1 L5: L6: +#ifdef __i386__ lcall $0x100, $0x1000 +#else +lcall *0x100 +lcall *(%rax) +#endif jmp 0x1000 +#ifdef __i386__ jmp *%eax +#else +jmp *%rax +#endif jmp *0x1000 +#ifdef __i386__ ljmp $0x100, $0x1000 +#else +ljmp *0x100 +ljmp *(%rdi) +#endif ret -retl - ret $10 +#ifdef __i386__ +retl retl $10 +#else +retq +retq $10 +#endif lret @@ -436,8 +478,10 @@ fucomip %st(5), %st int $3 int $0x10 +#ifdef __i386__ pusha popa +#endif clc cld cli @@ -445,19 +489,27 @@ int $0x10 cmc lahf sahf +#ifdef __i386__ pushfl popfl +#else + pushfq + popfq +#endif pushf popf stc std sti +#ifdef __i386__ aaa aas daa das aad aam + into +#endif cbw cwd cwde @@ -468,7 +520,6 @@ int $0x10 cltd leave int3 - into iret rsm hlt @@ -558,10 +609,12 @@ int $0x10 +#ifdef __i386__ boundl %edx, 0x10000 boundw %bx, 0x1000 - + arpl %bx, 0x1000 +#endif lar 0x1000, %eax lgdt 0x1000 lidt 0x1000 @@ -579,15 +632,21 @@ int $0x10 verr 0x1000 verw 0x1000 +#ifdef __i386__ push %ds pushw %ds pushl %ds pop %ds popw %ds popl %ds +#endif fxsave 1(%ebx) fxrstor 1(%ecx) +#ifdef __i386__ pushl $1 +#else + pushq $1 +#endif pushw $1 push $1 -- cgit v1.3.1