216 lines
7.2 KiB
NASM
216 lines
7.2 KiB
NASM
%include "src/constants.asm"
|
|
|
|
extern strlen
|
|
|
|
section .rodata
|
|
errMsgs dq e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,\
|
|
e10,e11,e12,e13,e14,e15,e16,e17,e18,e19,\
|
|
e20,e21,e22,e23,e24,e25,e26,e27,e28,e29,\
|
|
e30,e31,e32,e33,e34,e35,e36,e37,e38,e39,\
|
|
e40,e41,e42,e43,e44,e45,e46,e47,e48,e49,\
|
|
e50,e51,e52,e53,e54,e55,e56,e57,e58,e59,\
|
|
e60,e61,e62,e63,e64,e65,e66,e67,e68,e69,\
|
|
e70,e71,e72,e73,e74,e75,e76,e77,e78,e79,\
|
|
e80,e81,e82,e83,e84,e85,e86,e87,e88,e89,\
|
|
e90,e91,e92,e93,e94,e95,e96,e97,e98,e99,\
|
|
e100,e101,e102,e103,e104,e105,e106,e107,e108,e109,\
|
|
e110,e111,e112,e113,e114,e115,e116,e117,e118,e119,\
|
|
e120,e121,e122,e123,e124,e125,e126,e127,e128,e129,\
|
|
e130,e131,e132,e133
|
|
e0 db "No error",NL,EOS
|
|
e1 db "Operation not permitted",NL,EOS
|
|
e2 db "No such file or directory",NL,EOS
|
|
e3 db "No such process",NL,EOS
|
|
e4 db "Interrupted system call",NL,EOS
|
|
e5 db "I/O error",NL,EOS
|
|
e6 db "No such device or address",NL,EOS
|
|
e7 db "Argument list too long",NL,EOS
|
|
e8 db "Exec format error",NL,EOS
|
|
e9 db "Bad file number",NL,EOS
|
|
e10 db "No child processes",NL,EOS
|
|
e11 db "Try again",NL,EOS
|
|
e12 db "Out of memory",NL,EOS
|
|
e13 db "Permission denied",NL,EOS
|
|
e14 db "Bad address",NL,EOS
|
|
e15 db "Block device required",NL,EOS
|
|
e16 db "Device or resource busy",NL,EOS
|
|
e17 db "File exists",NL,EOS
|
|
e18 db "Cross-device link",NL,EOS
|
|
e19 db "No such device",NL,EOS
|
|
e20 db "Not a directory",NL,EOS
|
|
e21 db "Is a directory",NL,EOS
|
|
e22 db "Invalid argument",NL,EOS
|
|
e23 db "File table overflow",NL,EOS
|
|
e24 db "Too many open files",NL,EOS
|
|
e25 db "Not a typewriter",NL,EOS
|
|
e26 db "Text file busy",NL,EOS
|
|
e27 db "File too large",NL,EOS
|
|
e28 db "No space left on device",NL,EOS
|
|
e29 db "Illegal seek",NL,EOS
|
|
e30 db "Read-only file system",NL,EOS
|
|
e31 db "Too many links",NL,EOS
|
|
e32 db "Broken pipe",NL,EOS
|
|
e33 db "Math argument out of domain func",NL,EOS
|
|
e34 db "Math result not representable",NL,EOS
|
|
e35 db "Resource deadlock would occur",NL,EOS
|
|
e36 db "File name too long",NL,EOS
|
|
e37 db "No record locks available",NL,EOS
|
|
e38 db "Invalid system call number",NL,EOS
|
|
e39 db "Directory not empty",NL,EOS
|
|
e40 db "Too many symbolic links encountered",NL,EOS
|
|
e41 equ e11
|
|
e42 db "No message of desired type",NL,EOS
|
|
e43 db "Identifier removed",NL,EOS
|
|
e44 db "Channel number out of range",NL,EOS
|
|
e45 db "Level 2 not synchronized",NL,EOS
|
|
e46 db "Level 3 halted",NL,EOS
|
|
e47 db "Level 3 reset",NL,EOS
|
|
e48 db "Link number out of range",NL,EOS
|
|
e49 db "Protocol driver not attached",NL,EOS
|
|
e50 db "No CSI structure available",NL,EOS
|
|
e51 db "Level 2 halted",NL,EOS
|
|
e52 db "Invalid exchange",NL,EOS
|
|
e53 db "Invalid request descriptor",NL,EOS
|
|
e54 db "Exchange full",NL,EOS
|
|
e55 db "No anode",NL,EOS
|
|
e56 db "Invalid request code",NL,EOS
|
|
e57 db "Invalid slot",NL,EOS
|
|
e58 equ e35
|
|
e59 db "Bad font file format",NL,EOS
|
|
e60 db "Device not a stream",NL,EOS
|
|
e61 db "No data available",NL,EOS
|
|
e62 db "Timer expired",NL,EOS
|
|
e63 db "Out of streams resources",NL,EOS
|
|
e64 db "Machine is not on the network",NL,EOS
|
|
e65 db "Package not installed",NL,EOS
|
|
e66 db "Object is remote",NL,EOS
|
|
e67 db "Link has been severed",NL,EOS
|
|
e68 db "Advertise error",NL,EOS
|
|
e69 db "Srmount error",NL,EOS
|
|
e70 db "Communication error on send",NL,EOS
|
|
e71 db "Protocol error",NL,EOS
|
|
e72 db "Multihop attempted",NL,EOS
|
|
e73 db "RFS specific error",NL,EOS
|
|
e74 db "Not a data message",NL,EOS
|
|
e75 db "Value too large for defined data type",NL,EOS
|
|
e76 db "Name not unique on network",NL,EOS
|
|
e77 db "File descriptor in bad state",NL,EOS
|
|
e78 db "Remote address changed",NL,EOS
|
|
e79 db "Can not acces a needed shared library",NL,EOS
|
|
e80 db "Accessing a corrupted shared library",NL,EOS
|
|
e81 db ".lib section in a.out corrupted",NL,EOS
|
|
e82 db "Attempting to link in too many shared libraries",NL,EOS
|
|
e83 db "Cannot exec a shared library directly",NL,EOS
|
|
e84 db "Illegal byte sequence",NL,EOS
|
|
e85 db "Interrupted system call should be restarted",NL,EOS
|
|
e86 db "Streams pip error",NL,EOS
|
|
e87 db "Too many users",NL,EOS
|
|
e88 db "Socket operation on non-socket",NL,EOS
|
|
e89 db "Destination address required",NL,EOS
|
|
e90 db "Message too long",NL,EOS
|
|
e91 db "Protocol wrong type for socket",NL,EOS
|
|
e92 db "Protocol not available",NL,EOS
|
|
e93 db "Protocol not supported",NL,EOS
|
|
e94 db "Socket type not supported",NL,EOS
|
|
e95 db "Operation not supported on transport endpoint",NL,EOS
|
|
e96 db "Protocol family not supported",NL,EOS
|
|
e97 db "Address family not supported by protocol",NL,EOS
|
|
e98 db "Address already in use",NL,EOS
|
|
e99 db "Cannot assign requested address",NL,EOS
|
|
e100 db "Network is down",NL,EOS
|
|
e101 db "Network is unreachable",NL,EOS
|
|
e102 db "Network dropped connection because of reset",NL,EOS
|
|
e103 db "Software caused connection abort",NL,EOS
|
|
e104 db "Connection reset by peer",NL,EOS
|
|
e105 db "No buffer space available",NL,EOS
|
|
e106 db "Transport endpoint is already connected",NL,EOS
|
|
e107 db "Transport endpoint is not connected",NL,EOS
|
|
e108 db "Cannot send after transport endpoint shutdown",NL,EOS
|
|
e109 db "Too many references: cannot splice",NL,EOS
|
|
e110 db "Connection timed out",NL,EOS
|
|
e111 db "Connection refused",NL,EOS
|
|
e112 db "Host is down",NL,EOS
|
|
e113 db "No route to host",NL,EOS
|
|
e114 db "Operation already in progress",NL,EOS
|
|
e115 db "Operation now in progress",NL,EOS
|
|
e116 db "Stale file handle",NL,EOS
|
|
e117 db "Structure needs cleaning",NL,EOS
|
|
e118 db "Not a XENIX named type file",NL,EOS
|
|
e119 db "No XENIX semaphores available",NL,EOS
|
|
e120 db "Is a named type file",NL,EOS
|
|
e121 db "Remote I/O error",NL,EOS
|
|
e122 db "Quota exceeded",NL,EOS
|
|
e123 db "No medium found",NL,EOS
|
|
e124 db "Wrong medium type",NL,EOS
|
|
e125 db "Operation Canceled",NL,EOS
|
|
e126 db "Required key not available",NL,EOS
|
|
e127 db "Key has expired",NL,EOS
|
|
e128 db "Key has been revoked",NL,EOS
|
|
e129 db "Key was rejected by service",NL,EOS
|
|
e130 db "Owner died",NL,EOS
|
|
e131 db "State not recoverable",NL,EOS
|
|
e132 db "Operation not possible due to RF-kill",NL,EOS
|
|
e133 db "Memory page has hardware error",NL,EOS
|
|
|
|
unknownError db "Unknown error",NL,EOS
|
|
errMsgUser db ": ",EOS
|
|
|
|
section .text
|
|
global perror
|
|
|
|
;----- perror(*str[]) -----;
|
|
; Prints a descriptive error to stderr.
|
|
; Return value: N/A (current error code untouched)
|
|
; Used registers:
|
|
; rax Current error code (may be both positive or negative)
|
|
; rdi* (arg) Pointer to str[] or 0 (no custom message)
|
|
; rdx* Used for syscall NR_write
|
|
; r8* (Re)stores pointer to str[]// Stores address of errMsgUser for cmov
|
|
; r9* (Re)stores error code
|
|
; r10* (Re)stores pointer to error msg
|
|
perror:
|
|
test rax, rax
|
|
jz .quit
|
|
js .negErr
|
|
jmp .cnt
|
|
.negErr:
|
|
neg rax
|
|
|
|
.cnt:
|
|
mov r9, rax
|
|
|
|
test rdi, rdi
|
|
jz .noUserMsg
|
|
mov r8, rdi
|
|
call strlen
|
|
mov rdx, rax
|
|
mov rax, NR_write
|
|
mov rdi, FD_stderr
|
|
mov rsi, r8
|
|
syscall
|
|
mov rax, NR_write
|
|
mov rdi, FD_stderr
|
|
lea rsi, [rel errMsgUser]
|
|
mov rdx, 2
|
|
syscall
|
|
mov rax, r8
|
|
.noUserMsg:
|
|
cmp r9, 133
|
|
ja .invalidErr
|
|
lea r10, [errMsgs + r9 * SIZE_QWORD]
|
|
mov r10, [r10]
|
|
jmp .printErrMsg
|
|
.invalidErr:
|
|
lea r10, [rel unknownError]
|
|
.printErrMsg:
|
|
mov rdi, r10
|
|
call strlen
|
|
mov rdx, rax
|
|
mov rax, NR_write
|
|
mov rdi, FD_stderr
|
|
mov rsi, r10
|
|
syscall
|
|
mov rax, r9
|
|
.quit:
|
|
ret
|