mirror of
https://github.com/xcat2/xNBA.git
synced 2024-11-26 19:29:04 +00:00
[linux] Add most of the linux api
Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
parent
e743910cf9
commit
1812bfd5d0
114
src/arch/x86/core/linux/linux_api.c
Normal file
114
src/arch/x86/core/linux/linux_api.c
Normal file
@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
FILE_LICENCE(GPL2_OR_LATER);
|
||||
|
||||
/** @file
|
||||
*
|
||||
* Implementation of most of the linux API.
|
||||
*/
|
||||
|
||||
#include <linux_api.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <asm/unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
int linux_open(const char *pathname, int flags)
|
||||
{
|
||||
return linux_syscall(__NR_open, pathname, flags);
|
||||
}
|
||||
|
||||
int linux_close(int fd)
|
||||
{
|
||||
return linux_syscall(__NR_close, fd);
|
||||
}
|
||||
|
||||
ssize_t linux_read(int fd, void *buf, size_t count)
|
||||
{
|
||||
return linux_syscall(__NR_read, fd, buf, count);
|
||||
}
|
||||
|
||||
ssize_t linux_write(int fd, const void *buf, size_t count)
|
||||
{
|
||||
return linux_syscall(__NR_write, fd, buf, count);
|
||||
}
|
||||
|
||||
int linux_fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
long arg;
|
||||
va_list list;
|
||||
|
||||
va_start(list, cmd);
|
||||
arg = va_arg(list, long);
|
||||
va_end(list);
|
||||
|
||||
return linux_syscall(__NR_fcntl, fd, cmd, arg);
|
||||
}
|
||||
|
||||
int linux_ioctl(int fd, int request, ...)
|
||||
{
|
||||
void *arg;
|
||||
va_list list;
|
||||
|
||||
va_start(list, request);
|
||||
arg = va_arg(list, void *);
|
||||
va_end(list);
|
||||
|
||||
return linux_syscall(__NR_ioctl, fd, request, arg);
|
||||
}
|
||||
|
||||
int linux_poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
||||
{
|
||||
return linux_syscall(__NR_poll, fds, nfds, timeout);
|
||||
}
|
||||
|
||||
int linux_nanosleep(const struct timespec *req, struct timespec *rem)
|
||||
{
|
||||
return linux_syscall(__NR_nanosleep, req, rem);
|
||||
}
|
||||
|
||||
int linux_usleep(useconds_t usec)
|
||||
{
|
||||
struct timespec ts = {
|
||||
.tv_sec = (long) (usec / 1000000),
|
||||
.tv_nsec = (long) (usec % 1000000) * 1000ul
|
||||
};
|
||||
|
||||
return linux_nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
int linux_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
return linux_syscall(__NR_gettimeofday, tv, tz);
|
||||
}
|
||||
|
||||
void *linux_mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)
|
||||
{
|
||||
return (void *)linux_syscall(__SYSCALL_mmap, addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
void *linux_mremap(void *old_address, size_t old_size, size_t new_size, int flags)
|
||||
{
|
||||
return (void *)linux_syscall(__NR_mremap, old_address, old_size, new_size, flags);
|
||||
}
|
||||
|
||||
int linux_munmap(void *addr, size_t length)
|
||||
{
|
||||
return linux_syscall(__NR_munmap, addr, length);
|
||||
}
|
169
src/arch/x86/core/linux/linux_strerror.c
Normal file
169
src/arch/x86/core/linux/linux_strerror.c
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* Copyright (C) 2010 Piotr Jaroszyński <p.jaroszynski@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
FILE_LICENCE(GPL2_OR_LATER);
|
||||
|
||||
/** @file
|
||||
*
|
||||
* linux_strerror implementation
|
||||
*/
|
||||
|
||||
#include <linux_api.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/** Error names from glibc */
|
||||
static const char *errors[] = {
|
||||
"Success",
|
||||
"Operation not permitted",
|
||||
"No such file or directory",
|
||||
"No such process",
|
||||
"Interrupted system call",
|
||||
"Input/output error",
|
||||
"No such device or address",
|
||||
"Argument list too long",
|
||||
"Exec format error",
|
||||
"Bad file descriptor",
|
||||
"No child processes",
|
||||
"Resource temporarily unavailable",
|
||||
"Cannot allocate memory",
|
||||
"Permission denied",
|
||||
"Bad address",
|
||||
"Block device required",
|
||||
"Device or resource busy",
|
||||
"File exists",
|
||||
"Invalid cross-device link",
|
||||
"No such device",
|
||||
"Not a directory",
|
||||
"Is a directory",
|
||||
"Invalid argument",
|
||||
"Too many open files in system",
|
||||
"Too many open files",
|
||||
"Inappropriate ioctl for device",
|
||||
"Text file busy",
|
||||
"File too large",
|
||||
"No space left on device",
|
||||
"Illegal seek",
|
||||
"Read-only file system",
|
||||
"Too many links",
|
||||
"Broken pipe",
|
||||
"Numerical argument out of domain",
|
||||
"Numerical result out of range",
|
||||
"Resource deadlock avoided",
|
||||
"File name too long",
|
||||
"No locks available",
|
||||
"Function not implemented",
|
||||
"Directory not empty",
|
||||
"Too many levels of symbolic links",
|
||||
"",
|
||||
"No message of desired type",
|
||||
"Identifier removed",
|
||||
"Channel number out of range",
|
||||
"Level 2 not synchronized",
|
||||
"Level 3 halted",
|
||||
"Level 3 reset",
|
||||
"Link number out of range",
|
||||
"Protocol driver not attached",
|
||||
"No CSI structure available",
|
||||
"Level 2 halted",
|
||||
"Invalid exchange",
|
||||
"Invalid request descriptor",
|
||||
"Exchange full",
|
||||
"No anode",
|
||||
"Invalid request code",
|
||||
"Invalid slot",
|
||||
"",
|
||||
"Bad font file format",
|
||||
"Device not a stream",
|
||||
"No data available",
|
||||
"Timer expired",
|
||||
"Out of streams resources",
|
||||
"Machine is not on the network",
|
||||
"Package not installed",
|
||||
"Object is remote",
|
||||
"Link has been severed",
|
||||
"Advertise error",
|
||||
"Srmount error",
|
||||
"Communication error on send",
|
||||
"Protocol error",
|
||||
"Multihop attempted",
|
||||
"RFS specific error",
|
||||
"Bad message",
|
||||
"Value too large for defined data type",
|
||||
"Name not unique on network",
|
||||
"File descriptor in bad state",
|
||||
"Remote address changed",
|
||||
"Can not access a needed shared library",
|
||||
"Accessing a corrupted shared library",
|
||||
".lib section in a.out corrupted",
|
||||
"Attempting to link in too many shared libraries",
|
||||
"Cannot exec a shared library directly",
|
||||
"Invalid or incomplete multibyte or wide character",
|
||||
"Interrupted system call should be restarted",
|
||||
"Streams pipe error",
|
||||
"Too many users",
|
||||
"Socket operation on non-socket",
|
||||
"Destination address required",
|
||||
"Message too long",
|
||||
"Protocol wrong type for socket",
|
||||
"Protocol not available",
|
||||
"Protocol not supported",
|
||||
"Socket type not supported",
|
||||
"Operation not supported",
|
||||
"Protocol family not supported",
|
||||
"Address family not supported by protocol",
|
||||
"Address already in use",
|
||||
"Cannot assign requested address",
|
||||
"Network is down",
|
||||
"Network is unreachable",
|
||||
"Network dropped connection on reset",
|
||||
"Software caused connection abort",
|
||||
"Connection reset by peer",
|
||||
"No buffer space available",
|
||||
"Transport endpoint is already connected",
|
||||
"Transport endpoint is not connected",
|
||||
"Cannot send after transport endpoint shutdown",
|
||||
"Too many references: cannot splice",
|
||||
"Connection timed out",
|
||||
"Connection refused",
|
||||
"Host is down",
|
||||
"No route to host",
|
||||
"Operation already in progress",
|
||||
"Operation now in progress",
|
||||
"Stale NFS file handle",
|
||||
"Structure needs cleaning",
|
||||
"Not a XENIX named type file",
|
||||
"No XENIX semaphores available",
|
||||
"Is a named type file",
|
||||
"Remote I/O error",
|
||||
"Disk quota exceeded",
|
||||
"No medium found",
|
||||
"Wrong medium type",
|
||||
};
|
||||
|
||||
const char *linux_strerror(int errnum)
|
||||
{
|
||||
static char errbuf[64];
|
||||
static int errors_size = sizeof(errors) / sizeof(*errors);
|
||||
|
||||
if (errnum >= errors_size || errnum < 0) {
|
||||
snprintf(errbuf, sizeof(errbuf), "Error %#08x", errnum);
|
||||
return errbuf;
|
||||
} else {
|
||||
return errors[errnum];
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user