From 29defd705dcaf25d4a080f7db8f76e8787fca146 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 30 Apr 2017 11:28:11 -0400 Subject: [PATCH] back to AT&T syntax for assembly this reverts 5c04730534ea7933855429c5fc5dc7b22eba7bc2. sadly the quality of the intel dialect in llvm's assembly parser has many frustrating bugs, and generally has unfortunate syntax. the plan is to use AT&T for now since it at least works, and eventually zig will have its own assembly parser for x86 and it will be as close to NASM as possible. --- src/codegen.cpp | 8 ++------ src/zig_llvm.cpp | 12 ------------ src/zig_llvm.hpp | 3 --- std/os/linux_i386.zig | 14 +++++++------- std/special/bootstrap.zig | 4 ++-- test/assemble_and_link.zig | 13 ++++++------- 6 files changed, 17 insertions(+), 37 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index a57ff40be3..63a03fc496 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2088,10 +2088,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru } LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false); - bool is_x86 = (g->zig_target.arch.arch == ZigLLVM_x86 || g->zig_target.arch.arch == ZigLLVM_x86_64); bool is_volatile = asm_expr->is_volatile || (asm_expr->output_list.length == 0); - LLVMValueRef asm_fn = ZigLLVMConstInlineAsm(function_type, buf_ptr(&llvm_template), - buf_ptr(&constraint_buf), is_volatile, false, is_x86); + LLVMValueRef asm_fn = LLVMConstInlineAsm(function_type, buf_ptr(&llvm_template), + buf_ptr(&constraint_buf), is_volatile, false); return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, ""); } @@ -4805,9 +4804,6 @@ static void gen_global_asm(CodeGen *g) { if ((err = os_fetch_file_path(asm_file, &contents))) { zig_panic("Unable to read %s: %s", buf_ptr(asm_file), err_str(err)); } - if (g->zig_target.arch.arch == ZigLLVM_x86 || g->zig_target.arch.arch == ZigLLVM_x86_64) { - buf_append_str(&g->global_asm, ".intel_syntax noprefix\n"); - } buf_append_buf(&g->global_asm, &contents); } } diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 5256af1b09..29accd59cc 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -186,18 +186,6 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A return wrap(unwrap(B)->Insert(call_inst)); } -LLVMValueRef ZigLLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, - const char *Constraints, bool HasSideEffects, bool IsAlignStack, bool is_x86) -{ - if (is_x86) { - return wrap(InlineAsm::get(dyn_cast(unwrap(Ty)), AsmString, - Constraints, HasSideEffects, IsAlignStack, InlineAsm::AD_Intel)); - } else { - return wrap(InlineAsm::get(dyn_cast(unwrap(Ty)), AsmString, - Constraints, HasSideEffects, IsAlignStack)); - } -} - void ZigLLVMFnSetSubprogram(LLVMValueRef fn, ZigLLVMDISubprogram *subprogram) { assert( isa(unwrap(fn)) ); Function *unwrapped_function = reinterpret_cast(unwrap(fn)); diff --git a/src/zig_llvm.hpp b/src/zig_llvm.hpp index 5d19e2ad59..2acffeaba6 100644 --- a/src/zig_llvm.hpp +++ b/src/zig_llvm.hpp @@ -40,9 +40,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs, unsigned CC, bool always_inline, const char *Name); -LLVMValueRef ZigLLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, - const char *Constraints, bool HasSideEffects, bool IsAlignStack, bool is_x86); - LLVMValueRef ZigLLVMBuildCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr, LLVMValueRef cmp, LLVMValueRef new_val, LLVMAtomicOrdering success_ordering, LLVMAtomicOrdering failure_ordering); diff --git a/std/os/linux_i386.zig b/std/os/linux_i386.zig index 218043307e..d76d614a36 100644 --- a/std/os/linux_i386.zig +++ b/std/os/linux_i386.zig @@ -420,20 +420,20 @@ pub const F_GETOWN_EX = 16; pub const F_GETOWNER_UIDS = 17; pub inline fn syscall0(number: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number)) } pub inline fn syscall1(number: usize, arg1: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1)) } pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1), @@ -441,7 +441,7 @@ pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize { } pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1), @@ -450,7 +450,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> } pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1), @@ -462,7 +462,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1), @@ -475,7 +475,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize, arg6: usize) -> usize { - asm volatile ("int 80h" + asm volatile ("int $0x80" : [ret] "={eax}" (-> usize) : [number] "{eax}" (number), [arg1] "{ebx}" (arg1), diff --git a/std/special/bootstrap.zig b/std/special/bootstrap.zig index f7e6a35c88..00010bf0c9 100644 --- a/std/special/bootstrap.zig +++ b/std/special/bootstrap.zig @@ -19,10 +19,10 @@ export nakedcc fn _start() -> noreturn { switch (@compileVar("arch")) { Arch.x86_64 => { - argc_ptr = asm("lea %[argc], [rsp]": [argc] "=r" (-> &usize)); + argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize)); }, Arch.i386 => { - argc_ptr = asm("lea %[argc], [esp]": [argc] "=r" (-> &usize)); + argc_ptr = asm("lea (%%esp), %[argc]": [argc] "=r" (-> &usize)); }, else => @compileError("unsupported arch"), } diff --git a/test/assemble_and_link.zig b/test/assemble_and_link.zig index 89b0195fe6..6205d6a91c 100644 --- a/test/assemble_and_link.zig +++ b/test/assemble_and_link.zig @@ -7,18 +7,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) { \\.globl _start \\ \\_start: - \\ mov rax, 1 - \\ mov rdi, 1 - \\ lea rsi, msg - \\ mov rdx, 14 + \\ mov $1, %rax + \\ mov $1, %rdi + \\ mov $msg, %rsi + \\ mov $14, %rdx \\ syscall \\ - \\ mov rax, 60 - \\ mov rdi, 0 + \\ mov $60, %rax + \\ mov $0, %rdi \\ syscall \\ \\.data - \\ \\msg: \\ .ascii "Hello, world!\n" , "Hello, world!\n");