Skip to content

Commit 29defd7

Browse files
committed
back to AT&T syntax for assembly
this reverts 5c04730. 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.
1 parent cbfe4b4 commit 29defd7

File tree

6 files changed

+17
-37
lines changed

6 files changed

+17
-37
lines changed

src/codegen.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,10 +2088,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru
20882088
}
20892089
LLVMTypeRef function_type = LLVMFunctionType(ret_type, param_types, (unsigned)input_and_output_count, false);
20902090

2091-
bool is_x86 = (g->zig_target.arch.arch == ZigLLVM_x86 || g->zig_target.arch.arch == ZigLLVM_x86_64);
20922091
bool is_volatile = asm_expr->is_volatile || (asm_expr->output_list.length == 0);
2093-
LLVMValueRef asm_fn = ZigLLVMConstInlineAsm(function_type, buf_ptr(&llvm_template),
2094-
buf_ptr(&constraint_buf), is_volatile, false, is_x86);
2092+
LLVMValueRef asm_fn = LLVMConstInlineAsm(function_type, buf_ptr(&llvm_template),
2093+
buf_ptr(&constraint_buf), is_volatile, false);
20952094

20962095
return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, "");
20972096
}
@@ -4805,9 +4804,6 @@ static void gen_global_asm(CodeGen *g) {
48054804
if ((err = os_fetch_file_path(asm_file, &contents))) {
48064805
zig_panic("Unable to read %s: %s", buf_ptr(asm_file), err_str(err));
48074806
}
4808-
if (g->zig_target.arch.arch == ZigLLVM_x86 || g->zig_target.arch.arch == ZigLLVM_x86_64) {
4809-
buf_append_str(&g->global_asm, ".intel_syntax noprefix\n");
4810-
}
48114807
buf_append_buf(&g->global_asm, &contents);
48124808
}
48134809
}

src/zig_llvm.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,6 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
186186
return wrap(unwrap(B)->Insert(call_inst));
187187
}
188188

189-
LLVMValueRef ZigLLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
190-
const char *Constraints, bool HasSideEffects, bool IsAlignStack, bool is_x86)
191-
{
192-
if (is_x86) {
193-
return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
194-
Constraints, HasSideEffects, IsAlignStack, InlineAsm::AD_Intel));
195-
} else {
196-
return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
197-
Constraints, HasSideEffects, IsAlignStack));
198-
}
199-
}
200-
201189
void ZigLLVMFnSetSubprogram(LLVMValueRef fn, ZigLLVMDISubprogram *subprogram) {
202190
assert( isa<Function>(unwrap(fn)) );
203191
Function *unwrapped_function = reinterpret_cast<Function*>(unwrap(fn));

src/zig_llvm.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
4040
LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args,
4141
unsigned NumArgs, unsigned CC, bool always_inline, const char *Name);
4242

43-
LLVMValueRef ZigLLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
44-
const char *Constraints, bool HasSideEffects, bool IsAlignStack, bool is_x86);
45-
4643
LLVMValueRef ZigLLVMBuildCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr, LLVMValueRef cmp,
4744
LLVMValueRef new_val, LLVMAtomicOrdering success_ordering,
4845
LLVMAtomicOrdering failure_ordering);

std/os/linux_i386.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,28 +420,28 @@ pub const F_GETOWN_EX = 16;
420420
pub const F_GETOWNER_UIDS = 17;
421421

422422
pub inline fn syscall0(number: usize) -> usize {
423-
asm volatile ("int 80h"
423+
asm volatile ("int $0x80"
424424
: [ret] "={eax}" (-> usize)
425425
: [number] "{eax}" (number))
426426
}
427427

428428
pub inline fn syscall1(number: usize, arg1: usize) -> usize {
429-
asm volatile ("int 80h"
429+
asm volatile ("int $0x80"
430430
: [ret] "={eax}" (-> usize)
431431
: [number] "{eax}" (number),
432432
[arg1] "{ebx}" (arg1))
433433
}
434434

435435
pub inline fn syscall2(number: usize, arg1: usize, arg2: usize) -> usize {
436-
asm volatile ("int 80h"
436+
asm volatile ("int $0x80"
437437
: [ret] "={eax}" (-> usize)
438438
: [number] "{eax}" (number),
439439
[arg1] "{ebx}" (arg1),
440440
[arg2] "{ecx}" (arg2))
441441
}
442442

443443
pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) -> usize {
444-
asm volatile ("int 80h"
444+
asm volatile ("int $0x80"
445445
: [ret] "={eax}" (-> usize)
446446
: [number] "{eax}" (number),
447447
[arg1] "{ebx}" (arg1),
@@ -450,7 +450,7 @@ pub inline fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) ->
450450
}
451451

452452
pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) -> usize {
453-
asm volatile ("int 80h"
453+
asm volatile ("int $0x80"
454454
: [ret] "={eax}" (-> usize)
455455
: [number] "{eax}" (number),
456456
[arg1] "{ebx}" (arg1),
@@ -462,7 +462,7 @@ pub inline fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg
462462
pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
463463
arg4: usize, arg5: usize) -> usize
464464
{
465-
asm volatile ("int 80h"
465+
asm volatile ("int $0x80"
466466
: [ret] "={eax}" (-> usize)
467467
: [number] "{eax}" (number),
468468
[arg1] "{ebx}" (arg1),
@@ -475,7 +475,7 @@ pub inline fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize,
475475
pub inline fn syscall6(number: usize, arg1: usize, arg2: usize, arg3: usize,
476476
arg4: usize, arg5: usize, arg6: usize) -> usize
477477
{
478-
asm volatile ("int 80h"
478+
asm volatile ("int $0x80"
479479
: [ret] "={eax}" (-> usize)
480480
: [number] "{eax}" (number),
481481
[arg1] "{ebx}" (arg1),

std/special/bootstrap.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export nakedcc fn _start() -> noreturn {
1919

2020
switch (@compileVar("arch")) {
2121
Arch.x86_64 => {
22-
argc_ptr = asm("lea %[argc], [rsp]": [argc] "=r" (-> &usize));
22+
argc_ptr = asm("lea (%%rsp), %[argc]": [argc] "=r" (-> &usize));
2323
},
2424
Arch.i386 => {
25-
argc_ptr = asm("lea %[argc], [esp]": [argc] "=r" (-> &usize));
25+
argc_ptr = asm("lea (%%esp), %[argc]": [argc] "=r" (-> &usize));
2626
},
2727
else => @compileError("unsupported arch"),
2828
}

test/assemble_and_link.zig

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
77
\\.globl _start
88
\\
99
\\_start:
10-
\\ mov rax, 1
11-
\\ mov rdi, 1
12-
\\ lea rsi, msg
13-
\\ mov rdx, 14
10+
\\ mov $1, %rax
11+
\\ mov $1, %rdi
12+
\\ mov $msg, %rsi
13+
\\ mov $14, %rdx
1414
\\ syscall
1515
\\
16-
\\ mov rax, 60
17-
\\ mov rdi, 0
16+
\\ mov $60, %rax
17+
\\ mov $0, %rdi
1818
\\ syscall
1919
\\
2020
\\.data
21-
\\
2221
\\msg:
2322
\\ .ascii "Hello, world!\n"
2423
, "Hello, world!\n");

0 commit comments

Comments
 (0)