diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-02-11 15:40:48 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-02-11 15:40:48 +0100 |
| commit | cd5c9e6a923878e797212d27476ee217eb844a14 (patch) | |
| tree | f5ea8605d0521cbfbf384b05567bf3d2155b0b45 /ft_read.s | |
| parent | 28424105e255f0a4c887b6e6a83afd6dce372709 (diff) | |
| download | libasm-cd5c9e6a923878e797212d27476ee217eb844a14.tar.gz libasm-cd5c9e6a923878e797212d27476ee217eb844a14.tar.bz2 libasm-cd5c9e6a923878e797212d27476ee217eb844a14.zip | |
Added Linux compatibility
Diffstat (limited to 'ft_read.s')
| -rw-r--r-- | ft_read.s | 56 |
1 files changed, 28 insertions, 28 deletions
@@ -10,38 +10,38 @@ ; ; ; **************************************************************************** ; -global _ft_read +%ifdef __LINUX__ + %define M_FT_READ ft_read + %define M_ERRNO_LOCATION __errno_location + %define M_SYSCALL_READ 0x0 +%else + %define M_FT_READ _ft_read + %define M_ERRNO_LOCATION ___error + %define M_SYSCALL_READ 0x2000003 +%endif -%define F_GETFD 1 -%define SYSCALL_READ 0x2000003 -%define SYSCALL_FCNTL 0x200005c +extern M_ERRNO_LOCATION -; int ft_read(int, void*, size_t); -_ft_read: - cmp rdx, 0 - je FT_READ_NO_SIZE - cmp rdi, 0 - jl FT_READ_ERROR - cmp rsi, 0 - je FT_READ_ERROR - - push rdx - push rsi - xor rsi, rsi - mov esi, F_GETFD - mov rax, SYSCALL_FCNTL - syscall - pop rsi - pop rdx - cmp eax, 0 - jne FT_READ_ERROR +global M_FT_READ - mov rax, SYSCALL_READ +section .text +; int ft_read(int, void*, size_t); +M_FT_READ: + mov rax, M_SYSCALL_READ syscall +%ifdef __LINUX__ + cmp rax, 0 + jl FT_READ_ERROR +%else + jc FT_READ_ERROR +%endif ret FT_READ_ERROR: - mov rax, -1 - ret -FT_READ_NO_SIZE: - xor rax, rax +%ifdef __LINUX__ + neg rax +%endif + push rax + call M_ERRNO_LOCATION wrt ..plt + pop qword [rax] + mov rax, -1 ret |
