Shorter epilog once again
Even though it's more cryptic now.
This commit is contained in:
parent
29062e6c44
commit
d52dcd1de7
43
bfc-amd64.c
43
bfc-amd64.c
|
@ -588,7 +588,7 @@ main (int argc, char *argv[])
|
||||||
#error Target not supported
|
#error Target not supported
|
||||||
#endif
|
#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 ("\x48\x31\xFF") // xor rdi, rdi
|
||||||
CODE ("\x0F\x05") // syscall
|
CODE ("\x0F\x05") // syscall
|
||||||
|
|
||||||
|
@ -608,22 +608,27 @@ main (int argc, char *argv[])
|
||||||
CODE ("\xBF") DD (1) // mov edi, "EXIT_FAILURE"
|
CODE ("\xBF") DD (1) // mov edi, "EXIT_FAILURE"
|
||||||
CODE ("\x0F\x05") // syscall
|
CODE ("\x0F\x05") // syscall
|
||||||
|
|
||||||
|
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 ("\x48\x83\xF8\x00") // cmp rax, 0
|
||||||
|
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;
|
size_t read_offset = buffer.len;
|
||||||
CODE ("\x50") // push rax -- save tape position
|
CODE ("\x50") // push rax -- save tape position
|
||||||
CODE ("\xB8") DD (SYS_READ) // mov eax, "SYS_READ"
|
CODE ("\xB8") DD (SYS_READ) // mov eax, "SYS_READ"
|
||||||
CODE ("\xBF") DD (0) // mov edi, "STDIN_FILENO"
|
CODE ("\xBF") DD (0) // mov edi, "STDIN_FILENO"
|
||||||
CODE ("\x66\x6A\x00") // push word 0 -- the default value for EOF
|
CODE ("\x66\x6A\x00") // push word 0 -- the default value for EOF
|
||||||
CODE ("\x48\x89\xE6") // mov rsi, rsp -- the char starts at rsp
|
CODE ("\x4C\x8D\x25") DD (2) // lea r12, [rel read_message]
|
||||||
CODE ("\xBA") DD (1) // mov edx, 1 -- count
|
CODE ("\xEB") // jmp "io_offset"
|
||||||
CODE ("\x0F\x05") // syscall
|
DB ((intptr_t) io_offset - (intptr_t) (buffer.len + 1))
|
||||||
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 ("\x58") // pop rax -- restore tape position
|
|
||||||
CODE ("\xC3") // ret
|
|
||||||
CODE ("fatal: read failed\n\0")
|
CODE ("fatal: read failed\n\0")
|
||||||
|
|
||||||
size_t write_offset = buffer.len;
|
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 ("\xB8") DD (SYS_WRITE) // mov eax, "SYS_WRITE"
|
||||||
CODE ("\xBF") DD (1) // mov edi, "STDOUT_FILENO"
|
CODE ("\xBF") DD (1) // mov edi, "STDOUT_FILENO"
|
||||||
CODE ("\x66\x53") // push bx
|
CODE ("\x66\x53") // push bx
|
||||||
CODE ("\x48\x89\xE6") // mov rsi, rsp -- the char starts at rsp
|
CODE ("\x4C\x8D\x25") DD (2) // lea r12, [rel write_message]
|
||||||
CODE ("\xBA") DD (1) // mov edx, 1 -- count
|
CODE ("\xEB") // jmp "io_offset"
|
||||||
CODE ("\x0F\x05") // syscall
|
DB ((intptr_t) io_offset - (intptr_t) (buffer.len + 1))
|
||||||
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 ("fatal: write failed\n\0")
|
CODE ("fatal: write failed\n\0")
|
||||||
|
|
||||||
// Now that we know where each instruction is, fill in relative jumps
|
// Now that we know where each instruction is, fill in relative jumps
|
||||||
|
|
Loading…
Reference in New Issue