Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / x86 / core / linux / linux_api.c
1 /*
2  * Copyright (C) 2010 Piotr JaroszyƄski <p.jaroszynski@gmail.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 FILE_LICENCE ( GPL2_OR_LATER );
20
21 /** @file
22  *
23  * Implementation of most of the linux API.
24  */
25
26 #include <linux_api.h>
27
28 #include <stdarg.h>
29 #include <asm/unistd.h>
30 #include <string.h>
31
32 int linux_open ( const char *pathname, int flags ) {
33         return linux_syscall ( __NR_open, pathname, flags );
34 }
35
36 int linux_close ( int fd ) {
37         return linux_syscall ( __NR_close, fd );
38 }
39
40 off_t linux_lseek ( int fd, off_t offset, int whence ) {
41         return linux_syscall ( __NR_lseek, fd, offset, whence );
42 }
43
44 __kernel_ssize_t linux_read ( int fd, void *buf, __kernel_size_t count ) {
45         return linux_syscall ( __NR_read, fd, buf, count );
46 }
47
48 __kernel_ssize_t linux_write ( int fd, const void *buf,
49                                __kernel_size_t count ) {
50         return linux_syscall  (  __NR_write, fd, buf, count );
51 }
52
53 int linux_fcntl ( int fd, int cmd, ... ) {
54         long arg;
55         va_list list;
56
57         va_start ( list, cmd );
58         arg = va_arg ( list, long );
59         va_end ( list );
60
61         return linux_syscall ( __NR_fcntl, fd, cmd, arg );
62 }
63
64 int linux_ioctl ( int fd, int request, ... ) {
65         void *arg;
66         va_list list;
67
68         va_start ( list, request );
69         arg = va_arg ( list, void * );
70         va_end ( list );
71
72         return linux_syscall ( __NR_ioctl, fd, request, arg );
73 }
74
75 int linux_poll ( struct pollfd *fds, nfds_t nfds, int timeout ) {
76         return linux_syscall ( __NR_poll, fds, nfds, timeout );
77 }
78
79 int linux_nanosleep ( const struct timespec *req, struct timespec *rem ) {
80         return linux_syscall ( __NR_nanosleep, req, rem );
81 }
82
83 int linux_usleep ( useconds_t usec ) {
84         struct timespec ts = {
85                 .tv_sec = ( ( long ) ( usec / 1000000 ) ),
86                 .tv_nsec = ( ( long ) ( usec % 1000000 ) * 1000UL ),
87         };
88
89         return linux_nanosleep ( &ts, NULL );
90 }
91
92 int linux_gettimeofday ( struct timeval *tv, struct timezone *tz ) {
93         return linux_syscall ( __NR_gettimeofday, tv, tz );
94 }
95
96 void * linux_mmap ( void *addr, __kernel_size_t length, int prot, int flags,
97                     int fd, __kernel_off_t offset ) {
98         return ( void * ) linux_syscall ( __SYSCALL_mmap, addr, length, prot,
99                                           flags, fd, offset );
100 }
101
102 void * linux_mremap ( void *old_address, __kernel_size_t old_size,
103                       __kernel_size_t new_size, int flags ) {
104         return ( void * ) linux_syscall ( __NR_mremap, old_address, old_size,
105                                           new_size, flags );
106 }
107
108 int linux_munmap ( void *addr, __kernel_size_t length ) {
109         return linux_syscall ( __NR_munmap, addr, length );
110 }