commit ab9d42a485be23e1f3ee3d9c1488157ffcd28f76
parent b8f04aa6fc6abab81fb8af1f0a0b58994fe2df25
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Mon, 9 Dec 2024 08:42:14 +0000
Switch to Intel syntax
Diffstat:
3 files changed, 22 insertions(+), 18 deletions(-)
diff --git a/Tupfile b/Tupfile
@@ -1,5 +1,5 @@
-CFLAGS = -Os -fno-asynchronous-unwind-tables
-LDFLAGS = -static -nostartfiles -nostdlib -Xlinker --gc-sections
+CFLAGS = -Os -fno-asynchronous-unwind-tables -no-pie -g
+LDFLAGS = -static -nostartfiles -nostdlib -no-pie -Xlinker --gc-sections
: foreach *.c *.s |> cc $(CFLAGS) -c -o %o %f |> x86_64/%B.o {objs.x86_64}
: {objs.x86_64} |> cc $(LDFLAGS) -o %o %f |> echo.x86_64
diff --git a/crt0.s b/crt0.s
@@ -1,12 +1,14 @@
+.intel_syntax noprefix
+
.global _start
.text
_start: # _start is the entry point known to the linker
- xor %ebp, %ebp # effectively RBP := 0, mark the end of stack frames
- mov (%rsp), %edi # get argc from the stack (implicitly zero-extended to 64-bit)
- lea 8(%rsp), %rsi # take the address of argv from the stack
- lea 16(%rsp,%rdi,8), %rdx # take the address of envp from the stack
- xor %eax, %eax # per ABI and compatibility with icc
- jmp start # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main
+ xor ebp, ebp # effectively RBP := 0, mark the end of stack frames
+ mov edi, [rsp] # get argc from the stack (implicitly zero-extended to 64-bit)
+ lea rsi, [rsp+8] # take the address of argv from the stack
+ lea rdx, [rsp+16] # take the address of envp from the stack
+ xor eax, eax # per ABI and compatibility with icc
+ jmp start # %edi, %rsi, %rdx are the three args (of which first two are C standard) to main
diff --git a/syscall.s b/syscall.s
@@ -1,13 +1,15 @@
+.intel_syntax noprefix
+
.macro syscall3, num, name
.global \name
.section .text.\name
\name:
- push %r11
- push %rcx
- mov $\num, %rax
+ push r11
+ push rcx
+ mov rax, \num
syscall
- pop %rcx
- pop %r11
+ pop rcx
+ pop r11
ret
.endm
@@ -15,11 +17,11 @@
.global \name
.section .text.\name
\name:
- push %r11
- mov $\num, %rax
- mov %rcx, %r10
+ push r11
+ mov rax, \num
+ mov r10, rcx
syscall
- pop %r11
+ pop r11
ret
.endm
@@ -88,7 +90,7 @@ syscall3 58 vfork
syscall3 59 execve
.section .text.exit
-exit: mov $60, %rax
+exit: mov rax, 60
syscall
syscall6 61 wait4