This is what I've got on hand for a 32-bit version. Writes to stdout - probably should write to stderr... and other potential improvements... It is what it is.
Best,
Frank
; nasm -f elf32 rpterror.asm
global report_error
%define NL 10
;---------------
report_error:
push eax
push ebx
push ecx
push edx
neg eax
mov ecx, [error_table + eax * 4]
xor edx, edx
.getlen:
cmp byte [ecx + edx], 0
jz .gotlen
inc edx
jmp .getlen
.gotlen:
mov ebx, 1 ; stdout
mov eax, 4 ; write
int 80h
pop edx
pop ecx
pop ebx
pop eax
ret
;--------------
section .data
msg_EPERM db "EPERM - Operation not permitted ", NL, 0
msg_ENOENT db "ENOENT - No such file or directory ", NL, 0
msg_ESRCH db "ESRCH - No such process ", NL, 0
msg_EINTR db "EINTR - Interrupted system call ", NL, 0
msg_EIO db "EIO - I/O error ", NL, 0
msg_ENXIO db "ENXIO - No such device or address ", NL, 0
msg_E2BIG db "E2BIG - Argument list too long ", NL, 0
msg_ENOEXEC db "ENOEXEC - Exec format error ", NL, 0
msg_EBADF db "EBADF - Bad file number ", NL, 0
msg_ECHILD db "ECHILD - No child processes ", NL, 0
msg_EAGAIN db "EAGAIN - Try again, or EWOULDBLOCK - Operation would block ", NL, 0
msg_ENOMEM db "ENOMEM - Out of memory ", NL, 0
msg_EACCES db "EACCES - Permission denied ", NL, 0
msg_EFAULT db "EFAULT - Bad address ", NL, 0
msg_ENOTBLK db "ENOTBLK - Block device required ", NL, 0
msg_EBUSY db "EBUSY - Device or resource busy ", NL, 0
msg_EEXIST db "EEXIST - File exists ", NL, 0
msg_EXDEV db "EXDEV - Cross-device link ", NL, 0
msg_ENODEV db "ENODEV - No such device ", NL, 0
msg_ENOTDIR db "ENOTDIR - Not a directory ", NL, 0
msg_EISDIR db "EISDIR - Is a directory ", NL, 0
msg_EINVAL db "EINVAL - Invalid argument ", NL, 0
msg_ENFILE db "ENFILE - File table overflow ", NL, 0
msg_EMFILE db "EMFILE - Too many open files ", NL, 0
msg_ENOTTY db "ENOTTY - Not a typewriter ", NL, 0
msg_ETXTBSY db "ETXTBSY - Text file busy ", NL, 0
msg_EFBIG db "EFBIG - File too large ", NL, 0
msg_ENOSPC db "ENOSPC - No space left on device ", NL, 0
msg_ESPIPE db "ESPIPE - Illegal seek ", NL, 0
msg_EROFS db "EROFS - Read-only file system ", NL, 0
msg_EMLINK db "EMLINK - Too many links ", NL, 0
msg_EPIPE db "EPIPE - Broken pipe ", NL, 0
msg_EDOM db "EDOM - Math argument out of domain of func ", NL, 0
msg_ERANGE db "ERANGE - Math result not representable ", NL, 0
msg_EDEADLK db "EDEADLK - Resource deadlock would occur ", NL, 0
msg_ENAMETOOLONG db "ENAMETOOLONG - File name too long ", NL, 0
msg_ENOLCK db "ENOLCK - No record locks available ", NL, 0
msg_ENOSYS db "ENOSYS - Function not implemented ", NL, 0
msg_ENOTEMPTY db "ENOTEMPTY - Directory not empty ", NL, 0
msg_ELOOP db "ELOOP - Too many symbolic links encountered ", NL, 0
msg_EWOULDBLOCK db "EWOULDBLOCK Operation would block ", NL, 0
msg_ENOMSG db "ENOMSG - No message of desired type ", NL, 0
msg_EIDRM db "EIDRM - Identifier removed ", NL, 0
msg_ECHRNG db "ECHRNG - Channel number out of range ", NL, 0
msg_EL2NSYNC db "EL2NSYNC - Level 2 not synchronized ", NL, 0
msg_EL3HLT db "EL3HLT - Level 3 halted ", NL, 0
msg_EL3RST db "EL3RST - Level 3 reset ", NL, 0
msg_ELNRNG db "ELNRNG - Link number out of range ", NL, 0
msg_EUNATCH db "EUNATCH - Protocol driver not attached ", NL, 0
msg_ENOCSI db "ENOCSI - No CSI structure available ", NL, 0
msg_EL2HLT db "EL2HLT - Level 2 halted ", NL, 0
msg_EBADE db "EBADE - Invalid exchange ", NL, 0
msg_EBADR db "EBADR - Invalid request descriptor ", NL, 0
msg_EXFULL db "EXFULL - Exchange full ", NL, 0
msg_ENOANO db "ENOANO - No anode ", NL, 0
msg_EBADRQC db "EBADRQC - Invalid request code ", NL, 0
msg_EBADSLT db "EBADSLT - Invalid slot ", NL, 0
msg_EDEADLOCK db "EDEADLOCK - EDEADLK"
msg_EBFONT db "EBFONT - Bad font file format ", NL, 0
msg_ENOSTR db "ENOSTR - Device not a stream ", NL, 0
msg_ENODATA db "ENODATA - No data available ", NL, 0
msg_ETIME db "ETIME - Timer expired ", NL, 0
msg_ENOSR db "ENOSR - Out of streams resources ", NL, 0
msg_ENONET db "ENONET - Machine is not on the network ", NL, 0
msg_ENOPKG db "ENOPKG - Package not installed ", NL, 0
msg_EREMOTE db "EREMOTE - Object is remote ", NL, 0
msg_ENOLINK db "ENOLINK - Link has been severed ", NL, 0
msg_EADV db "EADV - Advertise error ", NL, 0
msg_ESRMNT db "ESRMNT - Srmount error ", NL, 0
msg_ECOMM db "ECOMM - Communication error on send ", NL, 0
msg_EPROTO db "EPROTO - Protocol error ", NL, 0
msg_EMULTIHOP db "EMULTIHOP - Multihop attempted ", NL, 0
msg_EDOTDOT db "EDOTDOT - RFS specific error ", NL, 0
msg_EBADMSG db "EBADMSG - Not a data message ", NL, 0
msg_EOVERFLOW db "EOVERFLOW - Value too large for defined data type ", NL, 0
msg_ENOTUNIQ db "ENOTUNIQ - Name not unique on network ", NL, 0
msg_EBADFD db "EBADFD - File descriptor in bad state ", NL, 0
msg_EREMCHG db "EREMCHG - Remote address changed ", NL, 0
msg_ELIBACC db "ELIBACC - Can not access a needed shared library ", NL, 0
msg_ELIBBAD db "ELIBBAD - Accessing a corrupted shared library ", NL, 0
msg_ELIBSCN db "ELIBSCN - .lib section in a.out corrupted ", NL, 0
msg_ELIBMAX db "ELIBMAX - Attempting to link in too many shared libraries ", NL, 0
msg_ELIBEXEC db "ELIBEXEC - Cannot exec a shared library directly ", NL, 0
msg_EILSEQ db "EILSEQ - Illegal byte sequence ", NL, 0
msg_ERESTART db "ERESTART - Interrupted system call should be restarted ", NL, 0
msg_ESTRPIPE db "ESTRPIPE - Streams pipe error ", NL, 0
msg_EUSERS db "EUSERS - Too many users ", NL, 0
msg_ENOTSOCK db "ENOTSOCK - Socket operation on non-socket ", NL, 0
msg_EDESTADDRREQ db "EDESTADDRREQ - Destination address required ", NL, 0
msg_EMSGSIZE db "EMSGSIZE - Message too long ", NL, 0
msg_EPROTOTYPE db "EPROTOTYPE - Protocol wrong type for socket ", NL, 0
msg_ENOPROTOOPT db "ENOPROTOOPT - Protocol not available ", NL, 0
msg_EPROTONOSUPPORT db "EPROTONOSUPPORT - Protocol not supported ", NL, 0
msg_ESOCKTNOSUPPORT db "ESOCKTNOSUPPORT - Socket type not supported ", NL, 0
msg_EOPNOTSUPP db "EOPNOTSUPP - Operation not supported on transport endpoint ", NL, 0
msg_EPFNOSUPPORT db "EPFNOSUPPORT - Protocol family not supported ", NL, 0
msg_EAFNOSUPPORT db "EAFNOSUPPORT - Address family not supported by protocol ", NL, 0
msg_EADDRINUSE db "EADDRINUSE - Address already in use ", NL, 0
msg_EADDRNOTAVAIL db "EADDRNOTAVAIL - Cannot assign requested address ", NL, 0
msg_ENETDOWN db "ENETDOWN - Network is down ", NL, 0
msg_ENETUNREACH db "ENETUNREACH - Network is unreachable ", NL, 0
msg_ENETRESET db "ENETRESET - Network dropped connection because of reset ", NL, 0
msg_ECONNABORTED db "ECONNABORTED - Software caused connection abort ", NL, 0
msg_ECONNRESET db "ECONNRESET - Connection reset by peer ", NL, 0
msg_ENOBUFS db "ENOBUFS - No buffer space available ", NL, 0
msg_EISCONN db "EISCONN - Transport endpoint is already connected ", NL, 0
msg_ENOTCONN db "ENOTCONN - Transport endpoint is not connected ", NL, 0
msg_ESHUTDOWN db "ESHUTDOWN - Cannot send after transport endpoint shutdown ", NL, 0
msg_ETOOMANYREFS db "ETOOMANYREFS - Too many references: cannot splice ", NL, 0
msg_ETIMEDOUT db "ETIMEDOUT - Connection timed out ", NL, 0
msg_ECONNREFUSED db "ECONNREFUSED - Connection refused ", NL, 0
msg_EHOSTDOWN db "EHOSTDOWN - Host is down ", NL, 0
msg_EHOSTUNREACH db "EHOSTUNREACH - No route to host ", NL, 0
msg_EALREADY db "EALREADY - Operation already in progress ", NL, 0
msg_EINPROGRESS db "EINPROGRESS - Operation now in progress ", NL, 0
msg_ESTALE db "ESTALE - Stale NFS file handle ", NL, 0
msg_EUCLEAN db "EUCLEAN - Structure needs cleaning ", NL, 0
msg_ENOTNAM db "ENOTNAM - Not a XENIX named type file ", NL, 0
msg_ENAVAIL db "ENAVAIL - No XENIX semaphores available ", NL, 0
msg_EISNAM db "EISNAM - Is a named type file ", NL, 0
msg_EREMOTEIO db "EREMOTEIO - Remote I/O error ", NL, 0
msg_EDQUOT db "EDQUOT - Quota exceeded ", NL, 0
msg_ENOMEDIUM db "ENOMEDIUM - No medium found ", NL, 0
msg_EMEDIUMTYPE db "EMEDIUMTYPE - Wrong medium type ", NL, 0
msg_WTF db 'WTF???', NL, 0
MAX_ERROR equ 124
error_table:
dd msg_WTF
dd msg_EPERM , msg_ENOENT , msg_ESRCH , msg_EINTR
dd msg_EIO , msg_ENXIO , msg_E2BIG , msg_ENOEXEC
dd msg_EBADF , msg_ECHILD , msg_EAGAIN , msg_ENOMEM
dd msg_EACCES , msg_EFAULT , msg_ENOTBLK , msg_EBUSY
dd msg_EEXIST , msg_EXDEV , msg_ENODEV , msg_ENOTDIR
dd msg_EISDIR , msg_EINVAL , msg_ENFILE , msg_EMFILE
dd msg_ENOTTY , msg_ETXTBSY , msg_EFBIG , msg_ENOSPC
dd msg_ESPIPE , msg_EROFS , msg_EMLINK , msg_EPIPE
dd msg_EDOM , msg_ERANGE , msg_EDEADLK , msg_ENAMETOOLONG
dd msg_ENOLCK , msg_ENOSYS , msg_ENOTEMPTY , msg_ELOOP
dd msg_EWOULDBLOCK , msg_ENOMSG , msg_EIDRM , msg_ECHRNG
dd msg_EL2NSYNC , msg_EL3HLT , msg_EL3RST , msg_ELNRNG
dd msg_EUNATCH , msg_ENOCSI , msg_EL2HLT , msg_EBADE
dd msg_EBADR , msg_EXFULL , msg_ENOANO , msg_EBADRQC
dd msg_EBADSLT , msg_EDEADLOCK , msg_EBFONT , msg_ENOSTR
dd msg_ENODATA , msg_ETIME , msg_ENOSR , msg_ENONET
dd msg_ENOPKG , msg_EREMOTE , msg_ENOLINK , msg_EADV
dd msg_ESRMNT , msg_ECOMM , msg_EPROTO , msg_EMULTIHOP
dd msg_EDOTDOT , msg_EBADMSG , msg_EOVERFLOW , msg_ENOTUNIQ
dd msg_EBADFD , msg_EREMCHG , msg_ELIBACC , msg_ELIBBAD
dd msg_ELIBSCN , msg_ELIBMAX , msg_ELIBEXEC , msg_EILSEQ
dd msg_ERESTART , msg_ESTRPIPE , msg_EUSERS , msg_ENOTSOCK
dd msg_EDESTADDRREQ , msg_EMSGSIZE , msg_EPROTOTYPE
dd msg_ENOPROTOOPT , msg_EPROTONOSUPPORT , msg_ESOCKTNOSUPPORT
dd msg_EOPNOTSUPP , msg_EPFNOSUPPORT , msg_EAFNOSUPPORT
dd msg_EADDRINUSE , msg_EADDRNOTAVAIL , msg_ENETDOWN
dd msg_ENETUNREACH , msg_ENETRESET , msg_ECONNABORTED
dd msg_ECONNRESET , msg_ENOBUFS , msg_EISCONN , msg_ENOTCONN
dd msg_ESHUTDOWN , msg_ETOOMANYREFS , msg_ETIMEDOUT
dd msg_ECONNREFUSED , msg_EHOSTDOWN , msg_EHOSTUNREACH
dd msg_EALREADY , msg_EINPROGRESS , msg_ESTALE , msg_EUCLEAN
dd msg_ENOTNAM , msg_ENAVAIL , msg_EISNAM , msg_EREMOTEIO
dd msg_EDQUOT , msg_ENOMEDIUM , msg_EMEDIUMTYPE