[449] | 1 | /* |
---|
| 2 | * unistd.c - User level <unistd> library implementation. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017,2018) |
---|
| 5 | * |
---|
| 6 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 7 | * |
---|
| 8 | * This file is part of ALMOS-MKH. |
---|
| 9 | * |
---|
| 10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 11 | * under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 13 | * |
---|
| 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 17 | * General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include <unistd.h> |
---|
[457] | 25 | #include <hal_shared_types.h> |
---|
[449] | 26 | #include <hal_user.h> |
---|
| 27 | #include <syscalls_numbers.h> |
---|
| 28 | |
---|
| 29 | ///////////////////////////// |
---|
| 30 | int getcwd( char * buf, |
---|
| 31 | unsigned int bytes ) |
---|
| 32 | { |
---|
| 33 | return hal_user_syscall( SYS_GETCWD, |
---|
| 34 | (reg_t)buf, |
---|
| 35 | (reg_t)bytes, 0, 0 ); |
---|
| 36 | } |
---|
| 37 | ////////////////////////// |
---|
| 38 | int read( int fd, |
---|
| 39 | void * buf, |
---|
| 40 | unsigned int count ) |
---|
| 41 | { |
---|
| 42 | return hal_user_syscall( SYS_READ, |
---|
| 43 | (reg_t)fd, |
---|
| 44 | (reg_t)buf, |
---|
| 45 | (reg_t)count, 0 ); |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | /////////////////////////// |
---|
| 49 | int write( int fd, |
---|
| 50 | const void * buf, |
---|
| 51 | unsigned int count ) |
---|
| 52 | { |
---|
| 53 | return hal_user_syscall( SYS_WRITE, |
---|
| 54 | (reg_t)fd, |
---|
| 55 | (reg_t)buf, |
---|
| 56 | (reg_t)count, 0 ); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /////////////////////////// |
---|
| 60 | int lseek( int fd, |
---|
| 61 | unsigned int offset, |
---|
| 62 | int whence ) |
---|
| 63 | { |
---|
| 64 | return hal_user_syscall( SYS_LSEEK, |
---|
| 65 | (reg_t)fd, |
---|
| 66 | (reg_t)offset, |
---|
| 67 | (reg_t)whence, 0 ); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | /////////////////// |
---|
| 71 | int close( int fd ) |
---|
| 72 | { |
---|
| 73 | return hal_user_syscall( SYS_CLOSE, |
---|
| 74 | (reg_t)fd, 0, 0, 0 ); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | ///////////////////// |
---|
| 78 | int pipe( int fd[2] ) |
---|
| 79 | { |
---|
| 80 | return -1; |
---|
| 81 | //return hal_user_syscall( SYS_PIPE, (reg_t)fd, 0, 0, 0 ); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | ////////////////////////////////// |
---|
| 85 | int chdir( const char * pathname ) |
---|
| 86 | { |
---|
| 87 | return hal_user_syscall( SYS_CHDIR, |
---|
| 88 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | //////////////////////////// |
---|
| 92 | int rmdir( char * pathname ) |
---|
| 93 | { |
---|
| 94 | return hal_user_syscall( SYS_RMDIR, |
---|
| 95 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | ////////// |
---|
| 99 | int fork() |
---|
| 100 | { |
---|
| 101 | return hal_user_syscall( SYS_FORK, 0, 0, 0, 0 ); |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | //////////// |
---|
| 105 | int getpid() |
---|
| 106 | { |
---|
| 107 | return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 ); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | /////////////////////////// |
---|
| 112 | int execve( char * pathname, |
---|
| 113 | char ** argv, |
---|
| 114 | char ** envp ) |
---|
| 115 | { |
---|
| 116 | return hal_user_syscall( SYS_EXEC, |
---|
| 117 | (reg_t)pathname, |
---|
| 118 | (reg_t)argv, |
---|
| 119 | (reg_t)envp, 0 ); |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | /////////////////////////////////// |
---|
| 124 | int unlink( const char * pathname ) |
---|
| 125 | { |
---|
| 126 | return hal_user_syscall( SYS_UNLINK, |
---|
| 127 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | /////////////////// |
---|
| 131 | int isatty(int fd ) |
---|
| 132 | { |
---|
| 133 | return hal_user_syscall( SYS_ISATTY, |
---|
| 134 | (reg_t)fd, 0, 0, 0 ); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | ////////////////////////////////// |
---|
| 138 | unsigned alarm( unsigned seconds ) |
---|
| 139 | { |
---|
| 140 | return hal_user_syscall( SYS_ALARM, |
---|
| 141 | (reg_t)seconds, 0, 0, 0 ); |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | |
---|