	.include	"features.inc"
	.section	.rodata
	.global	sys_nerr
	.type	sys_nerr, %object
sys_nerr:
	.word	36
NONE:
	.ascii	"\010No error\000"
EPERM:
	.ascii	"\027Operation not permitted\000"
ENOENT:
	.ascii	"\031No such file or directory\000"
ESRCH:
	.ascii	"\017No such process\000"
EINTR:
	.ascii	"\027Interrupted system call\000"
EIO:
	.ascii	"\011I/O error\000"
ENXIO:
	.ascii	"\031No such device or address\000"
E2BIG:
	.ascii	"\026Argument list too long\000"
ENOEXEC:
	.ascii	"\021Exec format error\000"
EBADF:
	.ascii	"\017Bad file number\000"
ECHILD:
	.ascii	"\022No child processes\000"
EAGAIN:
	.ascii	"\011Try again\000"
ENOMEM:
	.ascii	"\015Out of memory\000"
EACCES:
	.ascii	"\021Permission denied\000"
EFAULT:
	.ascii	"\013Bad address\000"
ENOTBLK:
	.ascii	"\026Block device required \000"
EBUSY:
	.ascii	"\027Device or resource busy\000"
EEXIST:
	.ascii	"\013File exists\000"
EXDEV:
	.ascii	"\021Cross-device link\000"
ENODEV:
	.ascii	"\016No such device\000"
ENOTDIR:
	.ascii	"\017Not a directory\000"
EISDIR:
	.ascii	"\016Is a directory\000"
EINVAL:
	.ascii	"\020Invalid argument\000"
ENFILE:
	.ascii	"\023File table overflow\000"
EMFILE:
	.ascii	"\023Too many open files\000"
ENOTTY:
	.ascii	"\020Not a typewriter\000"
ETXTBSY:
	.ascii	"\016Text file busy\000"
EFBIG:
	.ascii	"\016File too large\000"
ENOSPC:
	.ascii	"\027No space left on device\000"
ESPIPE:
	.ascii	"\014Illegal seek\000"
EROFS:
	.ascii	"\025Read-only file system\000"
EMLINK:
	.ascii	"\016Too many links\000"
EPIPE:
	.ascii	"\013Broken pipe\000"
EDOM:
	.ascii	"\043Math argument out of domain of func\000"
ERANGE:
	.ascii	"\035Math result not representable\000"
	.long	15
ESOVFL:
	.ascii	"String overflow\000"
	.long	18
ESINDEX:
	.ascii	"String index error\000"

	.global	sys_errlist
	.type	sys_errlist, %object
sys_errlist:
	.word	NONE
	.word	EPERM
	.word	ENOENT
	.word	ESRCH
	.word	EINTR
	.word	EIO
	.word	ENXIO
	.word	E2BIG
	.word	ENOEXEC
	.word	EBADF
	.word	ECHILD
	.word	EAGAIN
	.word	ENOMEM
	.word	EACCES
	.word	EFAULT
	.word	ENOTBLK
	.word	EBUSY
	.word	EEXIST
	.word	EXDEV
	.word	ENODEV
	.word	ENOTDIR
	.word	EISDIR
	.word	EINVAL
	.word	ENFILE
	.word	EMFILE
	.word	ENOTTY
	.word	ETXTBSY
	.word	EFBIG
	.word	ENOSPC
	.word	ESPIPE
	.word	EROFS
	.word	EMLINK
	.word	EPIPE
	.word	EDOM
	.word	ERANGE
	.word	ESOVFL
	.word	ESINDEX

	.section	.text
	.global	strerror
	.type	strerror, %function
strerror:
	sub	sp, sp, #12
	str	r0, [sp, #4]
	ldr	r0, sys_nerr_adr
	ldr	r0, [r0]
	ldr	r1, [sp, #4]
	cmp	r1, r0
	bls	keep_value
	movs	r0, #0
	str	r0, [sp, #4]
keep_value:
	ldr	r0, sys_errlist_adr
	ldr	r1, [sp, #4]
	ldr	r0, [r0, r1, lsl #2]
	add	sp, sp, #12
	RET
sys_nerr_adr:
	.long	sys_nerr
sys_errlist_adr:
	.long	sys_errlist
