diff options
author | 2015-08-28 09:58:54 +0800 | |
---|---|---|
committer | 2015-09-01 12:44:00 +0800 | |
commit | e44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch) | |
tree | 66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/SLOF/clients/net-snk/kernel/systemcall.c | |
parent | 9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff) |
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5
Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/SLOF/clients/net-snk/kernel/systemcall.c')
-rw-r--r-- | qemu/roms/SLOF/clients/net-snk/kernel/systemcall.c | 176 |
1 files changed, 176 insertions, 0 deletions
diff --git a/qemu/roms/SLOF/clients/net-snk/kernel/systemcall.c b/qemu/roms/SLOF/clients/net-snk/kernel/systemcall.c new file mode 100644 index 000000000..52c45cad7 --- /dev/null +++ b/qemu/roms/SLOF/clients/net-snk/kernel/systemcall.c @@ -0,0 +1,176 @@ +/****************************************************************************** + * Copyright (c) 2004, 2008 IBM Corporation + * All rights reserved. + * This program and the accompanying materials + * are made available under the terms of the BSD License + * which accompanies this distribution, and is available at + * http://www.opensource.org/licenses/bsd-license.php + * + * Contributors: + * IBM Corporation - initial implementation + *****************************************************************************/ + +#include <stdint.h> +#include <stdarg.h> +#include <string.h> +#include <fileio.h> +#include <kernel.h> +#include <of.h> +#include <sys/socket.h> + +extern int vsprintf(char *, const char *, va_list); +extern void _exit(int status); + +void exit(int status); + +int open(const char* name, int flags) +{ + int fd; + + /* search free file descriptor */ + for (fd=0; fd<FILEIO_MAX; ++fd) { + if(fd_array[fd].type == FILEIO_TYPE_EMPTY) { + break; + } + } + if (fd == FILEIO_MAX) { + printf("Can not open \"%s\" because file descriptor list is full\n", name); + /* there is no free file descriptor available */ + return -2; + } + + fd_array[fd].ih = of_open(name); + if (fd_array[fd].ih == 0) + return -1; + + fd_array[fd].type = FILEIO_TYPE_FILE; + + return fd; +} + +int pre_open_ih(int fd, ihandle_t ih) +{ + if (fd_array[fd].type != FILEIO_TYPE_EMPTY) + return -2; + fd_array[fd].ih = ih; + fd_array[fd].type = FILEIO_TYPE_FILE; + + return fd; +} + +int socket(int domain, int type, int proto, char *mac_addr) +{ + uint8_t tmpbuf[8]; + int fd; + phandle_t ph; + + /* search free file descriptor */ + for (fd=0; fd<FILEIO_MAX; ++fd) { + if(fd_array[fd].type == FILEIO_TYPE_EMPTY) { + break; + } + } + if (fd == FILEIO_MAX) { + printf("Can not open socket, file descriptor list is full\n"); + /* there is no free file descriptor available */ + return -2; + } + + fd_array[fd].ih = of_interpret_1("my-parent", tmpbuf); + if (fd_array[fd].ih == 0) { + printf("Can not open socket, no parent instance\n"); + return -1; + } + ph = of_instance_to_package(fd_array[fd].ih); + if (ph == -1) { + printf("Can not open socket, no parent package\n"); + return -1; + } + if (of_get_mac(ph, mac_addr) < 0) { + printf("Can not open socket, no MAC address\n"); + return -1; + } + fd_array[fd].type = FILEIO_TYPE_SOCKET; + + return fd; +} + +int close(int fd) +{ + if (fd < 0 || fd >= FILEIO_MAX || + fd_array[fd].type == FILEIO_TYPE_EMPTY) + return -1; + if (fd_array[fd].type == FILEIO_TYPE_FILE) + of_close(fd_array[fd].ih); + fd_array[fd].type = FILEIO_TYPE_EMPTY; + return 0; +} + +ssize_t read(int fd, void *buf, size_t len) +{ + if (fd < 0 || fd >= FILEIO_MAX || + fd_array[fd].type == FILEIO_TYPE_EMPTY) + return -1; + + return of_read(fd_array[fd].ih, buf, len); +} + +ssize_t write (int fd, const void *buf, size_t len) +{ + char dest_buf[512]; + char *dest_buf_ptr; + const char *dbuf = buf; + int i; + + if (fd == 1 || fd == 2) { + dest_buf_ptr = &dest_buf[0]; + for (i = 0; i < len && i < 256; i++) + { + *dest_buf_ptr++ = *dbuf++; + if (dbuf[-1] == '\n') + *dest_buf_ptr++ = '\r'; + } + len = dest_buf_ptr - &dest_buf[0]; + buf = &dest_buf[0]; + } + + if(fd < 0 || fd >= FILEIO_MAX || + fd_array[fd].type == FILEIO_TYPE_EMPTY) + return -1; + + return of_write(fd_array[fd].ih, (void *)buf, len); +} + +ssize_t lseek (int fd, long offset, int whence) +{ + return 0; // this syscall is unused !!! +#if 0 + if (whence != 0) + return -1; + + of_seek (fd_array[fd], (unsigned int) (offset>>32), (unsigned int) (offset & 0xffffffffULL)); + + return offset; +#endif +} + +int recv(int fd, void *packet, int packet_len, int flags) +{ + return read(fd, packet, packet_len); +} + +int send(int fd, const void *packet, int packet_len, int flags) +{ + return write(fd, packet, packet_len); +} + +int sendto(int fd, const void *packet, int packet_len, int flags, + const void *sock_addr, int sock_addr_len) +{ + return send(fd, packet, packet_len, flags); +} + +void exit(int status) +{ + _exit(status); +} |