From 0652ff24200cbf4e06b6a4135351d9add419776a Mon Sep 17 00:00:00 2001 From: Suleyman Farajli Date: Thu, 2 Jan 2025 00:13:34 +0400 Subject: parameter order on the stack reversed for syscalls --- src/main.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main.go b/src/main.go index 68db099..e4dfbff 100644 --- a/src/main.go +++ b/src/main.go @@ -246,26 +246,42 @@ func X86_64map(op Operation) string{ case "number": return fmt.Sprintf("\tpush %d\n", op.intData) case "syscall": + /* FIXME: make it more consise */ buf := "" switch op.intData { case 7: + buf += "\tpop rax\n" + buf += "\tpop rdi\n" + buf += "\tpop rsi\n" + buf += "\tpop rdx\n" + buf += "\tpop r10\n" + buf +="\tpop r8\n" buf +="\tpop r9\n" - fallthrough case 6: + buf += "\tpop rax\n" + buf += "\tpop rdi\n" + buf += "\tpop rsi\n" + buf += "\tpop rdx\n" + buf += "\tpop r10\n" buf +="\tpop r8\n" - fallthrough case 5: + buf += "\tpop rax\n" + buf += "\tpop rdi\n" + buf += "\tpop rsi\n" + buf += "\tpop rdx\n" buf += "\tpop r10\n" - fallthrough case 4: + buf += "\tpop rax\n" + buf += "\tpop rdi\n" + buf += "\tpop rsi\n" buf += "\tpop rdx\n" - fallthrough case 3: + buf += "\tpop rax\n" + buf += "\tpop rdi\n" buf += "\tpop rsi\n" - fallthrough case 2: + buf += "\tpop rax\n" buf += "\tpop rdi\n" - fallthrough case 1: buf += "\tpop rax\n" } -- cgit v1.2.3