aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-12-25 01:37:06 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-12-25 01:56:42 +0100
commitd52dcd1de717d6a38c004814c340c9e1187aa481 (patch)
tree88e4931eeed017e226d87863ca4a440fc1b28a78
parent29062e6c441f1bf34a9105b775cbde8955646388 (diff)
downloadbfc-d52dcd1de717d6a38c004814c340c9e1187aa481.tar.gz
bfc-d52dcd1de717d6a38c004814c340c9e1187aa481.tar.xz
bfc-d52dcd1de717d6a38c004814c340c9e1187aa481.zip
Shorter epilog once again
Even though it's more cryptic now.
-rw-r--r--bfc-amd64.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/bfc-amd64.c b/bfc-amd64.c
index 9cb5b98..cf34b84 100644
--- a/bfc-amd64.c
+++ b/bfc-amd64.c
@@ -588,7 +588,7 @@ main (int argc, char *argv[])
#error Target not supported
#endif
- CODE ("\xB8") DD (SYS_EXIT) // mov eax, 0x3c
+ CODE ("\xB8") DD (SYS_EXIT) // mov eax, "SYS_EXIT"
CODE ("\x48\x31\xFF") // xor rdi, rdi
CODE ("\x0F\x05") // syscall
@@ -608,22 +608,27 @@ main (int argc, char *argv[])
CODE ("\xBF") DD (1) // mov edi, "EXIT_FAILURE"
CODE ("\x0F\x05") // syscall
- size_t read_offset = buffer.len;
- CODE ("\x50") // push rax -- save tape position
- CODE ("\xB8") DD (SYS_READ) // mov eax, "SYS_READ"
- CODE ("\xBF") DD (0) // mov edi, "STDIN_FILENO"
- CODE ("\x66\x6A\x00") // push word 0 -- the default value for EOF
+ size_t io_offset = buffer.len;
CODE ("\x48\x89\xE6") // mov rsi, rsp -- the char starts at rsp
CODE ("\xBA") DD (1) // mov edx, 1 -- count
CODE ("\x0F\x05") // syscall
- CODE ("\x66\x5B") // pop bx
CODE ("\x48\x83\xF8\x00") // cmp rax, 0
- CODE ("\x48\x8D\x35") DD (8) // lea rsi, [rel read_message]
- CODE ("\x0F\x8C") // jl "fatal_offset" -- write failure message
- DD ((intptr_t) fatal_offset - (intptr_t) (buffer.len + 4))
+ CODE ("\x4C\x89\xE6") // mov rsi, r12
+ CODE ("\x7C") // jl "fatal_offset" -- write failure message
+ DB ((intptr_t) fatal_offset - (intptr_t) (buffer.len + 1))
+ CODE ("\x66\x5B") // pop bx
CODE ("\x58") // pop rax -- restore tape position
CODE ("\xC3") // ret
+
+ size_t read_offset = buffer.len;
+ CODE ("\x50") // push rax -- save tape position
+ CODE ("\xB8") DD (SYS_READ) // mov eax, "SYS_READ"
+ CODE ("\xBF") DD (0) // mov edi, "STDIN_FILENO"
+ CODE ("\x66\x6A\x00") // push word 0 -- the default value for EOF
+ CODE ("\x4C\x8D\x25") DD (2) // lea r12, [rel read_message]
+ CODE ("\xEB") // jmp "io_offset"
+ DB ((intptr_t) io_offset - (intptr_t) (buffer.len + 1))
CODE ("fatal: read failed\n\0")
size_t write_offset = buffer.len;
@@ -631,17 +636,9 @@ main (int argc, char *argv[])
CODE ("\xB8") DD (SYS_WRITE) // mov eax, "SYS_WRITE"
CODE ("\xBF") DD (1) // mov edi, "STDOUT_FILENO"
CODE ("\x66\x53") // push bx
- CODE ("\x48\x89\xE6") // mov rsi, rsp -- the char starts at rsp
- CODE ("\xBA") DD (1) // mov edx, 1 -- count
- CODE ("\x0F\x05") // syscall
- CODE ("\x66\x5B") // pop bx
-
- CODE ("\x48\x83\xF8\x00") // cmp rax, 0
- CODE ("\x48\x8D\x35") DD (8) // lea rsi, [rel write_message]
- CODE ("\x0F\x8C") // jl "fatal_offset" -- write failure message
- DD ((intptr_t) fatal_offset - (intptr_t) (buffer.len + 4))
- CODE ("\x58") // pop rax -- restore tape position
- CODE ("\xC3") // ret
+ CODE ("\x4C\x8D\x25") DD (2) // lea r12, [rel write_message]
+ CODE ("\xEB") // jmp "io_offset"
+ DB ((intptr_t) io_offset - (intptr_t) (buffer.len + 1))
CODE ("fatal: write failed\n\0")
// Now that we know where each instruction is, fill in relative jumps