[412] | 1 | /* |
---|
| 2 | * stdio.c - User side system calls implementation. |
---|
| 3 | * |
---|
| 4 | * Author Alain Greiner (2016,2017) |
---|
| 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 <shared_syscalls.h> |
---|
| 25 | #include <hal_user.h> |
---|
| 26 | #include <stdio.h> |
---|
| 27 | #include <stdlib.h> |
---|
| 28 | |
---|
| 29 | #define reg_t int |
---|
| 30 | |
---|
[426] | 31 | ///////////// POSIX standard system calls //////////////////////////////////// |
---|
| 32 | |
---|
[412] | 33 | /////////////////////// |
---|
| 34 | void exit( int status ) |
---|
| 35 | { |
---|
| 36 | hal_user_syscall( SYS_EXIT, |
---|
| 37 | (reg_t)status, 0, 0, 0 ); |
---|
| 38 | } |
---|
| 39 | |
---|
[426] | 40 | ///////////////////////////////// |
---|
[412] | 41 | int munmap( void * addr, |
---|
| 42 | unsigned int size ) |
---|
| 43 | { |
---|
| 44 | return hal_user_syscall( SYS_MUNMAP, |
---|
| 45 | (reg_t)addr, |
---|
| 46 | (reg_t)size, 0, 0 ); |
---|
| 47 | } |
---|
| 48 | |
---|
[426] | 49 | //////////////////////////////// |
---|
[412] | 50 | int open( const char * pathname, |
---|
| 51 | int flags, |
---|
| 52 | int mode ) |
---|
| 53 | { |
---|
| 54 | return hal_user_syscall( SYS_OPEN, |
---|
| 55 | (reg_t)pathname, |
---|
| 56 | (reg_t)flags, |
---|
| 57 | (reg_t)mode, 0 ); |
---|
| 58 | } |
---|
| 59 | |
---|
[426] | 60 | /////////////////////////////// |
---|
[412] | 61 | void * mmap( void * addr, |
---|
| 62 | unsigned int length, |
---|
| 63 | int prot, |
---|
| 64 | int flags, |
---|
| 65 | int fd, |
---|
| 66 | unsigned int offset ) |
---|
| 67 | { |
---|
| 68 | mmap_attr_t attr; |
---|
| 69 | attr.addr = addr; |
---|
| 70 | attr.length = length; |
---|
| 71 | attr.prot = prot; |
---|
| 72 | attr.flags = flags; |
---|
| 73 | attr.fdid = fd; |
---|
| 74 | attr.offset = offset; |
---|
| 75 | |
---|
| 76 | if( hal_user_syscall( SYS_MMAP, |
---|
| 77 | (reg_t)&attr, 0, 0, 0 ) ) return NULL; |
---|
| 78 | else return attr.addr; |
---|
| 79 | } |
---|
| 80 | |
---|
[426] | 81 | ////////////////////////// |
---|
[412] | 82 | int read( int fd, |
---|
| 83 | void * buf, |
---|
| 84 | unsigned int count ) |
---|
| 85 | { |
---|
| 86 | return hal_user_syscall( SYS_READ, |
---|
| 87 | (reg_t)fd, |
---|
| 88 | (reg_t)buf, |
---|
| 89 | (reg_t)count, 0 ); |
---|
| 90 | } |
---|
| 91 | |
---|
[426] | 92 | /////////////////////////// |
---|
[412] | 93 | int write( int fd, |
---|
| 94 | const void * buf, |
---|
| 95 | unsigned int count ) |
---|
| 96 | { |
---|
| 97 | return hal_user_syscall( SYS_WRITE, |
---|
| 98 | (reg_t)fd, |
---|
| 99 | (reg_t)buf, |
---|
| 100 | (reg_t)count, 0 ); |
---|
| 101 | } |
---|
| 102 | |
---|
[426] | 103 | /////////////////////////// |
---|
[412] | 104 | int lseek( int fd, |
---|
| 105 | unsigned int offset, |
---|
| 106 | int whence ) |
---|
| 107 | { |
---|
| 108 | return hal_user_syscall( SYS_LSEEK, |
---|
| 109 | (reg_t)fd, |
---|
| 110 | (reg_t)offset, |
---|
| 111 | (reg_t)whence, 0 ); |
---|
| 112 | } |
---|
| 113 | |
---|
[426] | 114 | /////////////////// |
---|
[412] | 115 | int close( int fd ) |
---|
| 116 | { |
---|
| 117 | return hal_user_syscall( SYS_CLOSE, |
---|
| 118 | (reg_t)fd, 0, 0, 0 ); |
---|
| 119 | } |
---|
| 120 | |
---|
[426] | 121 | /////////////////////////////////// |
---|
[412] | 122 | int unlink( const char * pathname ) |
---|
| 123 | { |
---|
| 124 | return hal_user_syscall( SYS_UNLINK, |
---|
| 125 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 126 | } |
---|
| 127 | |
---|
[426] | 128 | ///////////////////// |
---|
[412] | 129 | int pipe( int fd[2] ) |
---|
| 130 | { |
---|
| 131 | return -1; |
---|
| 132 | } |
---|
| 133 | |
---|
[426] | 134 | ////////////////////////////////// |
---|
[412] | 135 | int chdir( const char * pathname ) |
---|
| 136 | { |
---|
| 137 | return hal_user_syscall( SYS_CHDIR, |
---|
| 138 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 139 | } |
---|
| 140 | |
---|
[426] | 141 | ///////////////////////////////// |
---|
[412] | 142 | int mkdir( const char * pathname, |
---|
| 143 | int mode ) |
---|
| 144 | { |
---|
| 145 | return hal_user_syscall( SYS_MKDIR, |
---|
| 146 | (reg_t)pathname, |
---|
| 147 | (reg_t)mode, 0, 0 ); |
---|
| 148 | } |
---|
| 149 | |
---|
[426] | 150 | ////////////////////////////////// |
---|
[412] | 151 | int mkfifo( const char * pathname, |
---|
| 152 | int mode ) |
---|
| 153 | { |
---|
| 154 | return hal_user_syscall( SYS_MKFIFO, |
---|
| 155 | (reg_t)pathname, |
---|
| 156 | (reg_t)mode, 0, 0 ); |
---|
| 157 | } |
---|
| 158 | |
---|
[426] | 159 | ////////////////////////////////////// |
---|
[412] | 160 | DIR * opendir( const char * pathname ) |
---|
| 161 | { |
---|
| 162 | DIR * dirp; |
---|
| 163 | int error; |
---|
| 164 | error = hal_user_syscall( SYS_OPENDIR, |
---|
| 165 | (reg_t)pathname, |
---|
| 166 | (reg_t)&dirp, 0, 0 ); |
---|
| 167 | if( error ) return NULL; |
---|
| 168 | else return dirp; |
---|
| 169 | } |
---|
| 170 | |
---|
[426] | 171 | ///////////////////////////////////// |
---|
[412] | 172 | struct dirent * readdir( DIR * dirp ) |
---|
| 173 | { |
---|
| 174 | struct dirent * dentp; |
---|
| 175 | int error; |
---|
| 176 | error = hal_user_syscall( SYS_READDIR, |
---|
| 177 | (reg_t)dirp, |
---|
| 178 | (reg_t)&dentp, 0, 0 ); |
---|
| 179 | if( error ) return NULL; |
---|
| 180 | else return dentp; |
---|
| 181 | } |
---|
| 182 | |
---|
[426] | 183 | ////////////////////////// |
---|
[412] | 184 | int closedir( DIR * dirp ) |
---|
| 185 | { |
---|
| 186 | return hal_user_syscall( SYS_CLOSEDIR, |
---|
| 187 | (reg_t)dirp, 0, 0, 0 ); |
---|
| 188 | } |
---|
| 189 | |
---|
[426] | 190 | ///////////////////////////// |
---|
[412] | 191 | int getcwd( char * buf, |
---|
| 192 | unsigned int bytes ) |
---|
| 193 | { |
---|
| 194 | return hal_user_syscall( SYS_GETCWD, |
---|
| 195 | (reg_t)buf, |
---|
| 196 | (reg_t)bytes, 0, 0 ); |
---|
| 197 | } |
---|
| 198 | |
---|
[426] | 199 | //////////////////////////// |
---|
[412] | 200 | int rmdir( char * pathname ) |
---|
| 201 | { |
---|
| 202 | return hal_user_syscall( SYS_RMDIR, |
---|
| 203 | (reg_t)pathname, 0, 0, 0 ); |
---|
| 204 | } |
---|
| 205 | |
---|
[426] | 206 | ///////////////////////////////// |
---|
[412] | 207 | int utls( unsigned int operation, |
---|
| 208 | unsigned int value ) |
---|
| 209 | { |
---|
| 210 | return hal_user_syscall( SYS_UTLS, |
---|
| 211 | (reg_t)operation, |
---|
| 212 | (reg_t)value, 0, 0 ); |
---|
| 213 | } |
---|
| 214 | |
---|
[426] | 215 | /////////////////////////////// |
---|
[412] | 216 | int chmod( char * pathname, |
---|
| 217 | unsigned int rights ) |
---|
| 218 | { |
---|
| 219 | return hal_user_syscall( SYS_CHMOD, |
---|
| 220 | (reg_t)pathname, |
---|
| 221 | (reg_t)rights, 0, 0 ); |
---|
| 222 | } |
---|
| 223 | |
---|
[426] | 224 | ///////////////////////////////// |
---|
[412] | 225 | int signal( unsigned int sigid, |
---|
| 226 | void * handler ) |
---|
| 227 | { |
---|
| 228 | return hal_user_syscall( SYS_SIGNAL, |
---|
| 229 | (reg_t)sigid, |
---|
| 230 | (reg_t)handler, 0, 0 ); |
---|
| 231 | } |
---|
| 232 | |
---|
[426] | 233 | /////////////////////////////////////// |
---|
[412] | 234 | int gettimeofday( struct timeval * tv, |
---|
| 235 | struct timezone * tz ) |
---|
| 236 | { |
---|
| 237 | return hal_user_syscall( SYS_SIGNAL, |
---|
| 238 | (reg_t)tv, |
---|
| 239 | (reg_t)tz, 0, 0 ); |
---|
| 240 | } |
---|
| 241 | |
---|
[426] | 242 | /////////////////////////// |
---|
[412] | 243 | int kill( unsigned int pid, |
---|
| 244 | unsigned int sig_id ) |
---|
| 245 | { |
---|
| 246 | return hal_user_syscall( SYS_KILL, |
---|
| 247 | (reg_t)pid, |
---|
| 248 | (reg_t)sig_id, 0, 0 ); |
---|
| 249 | } |
---|
| 250 | |
---|
[426] | 251 | //////////// |
---|
[412] | 252 | int getpid() |
---|
| 253 | { |
---|
| 254 | return hal_user_syscall( SYS_GETPID, 0, 0, 0, 0 ); |
---|
| 255 | } |
---|
| 256 | |
---|
[426] | 257 | ////////// |
---|
[412] | 258 | int fork() |
---|
| 259 | { |
---|
| 260 | return hal_user_syscall( SYS_FORK, 0, 0, 0, 0 ); |
---|
| 261 | } |
---|
| 262 | |
---|
[426] | 263 | /////////////////////////// |
---|
[412] | 264 | int exec( char * pathname, |
---|
| 265 | char ** argv, |
---|
| 266 | char ** envp ) |
---|
| 267 | { |
---|
| 268 | return hal_user_syscall( SYS_EXEC, |
---|
| 269 | (reg_t)pathname, |
---|
| 270 | (reg_t)argv, |
---|
| 271 | (reg_t)envp, 0 ); |
---|
| 272 | } |
---|
| 273 | |
---|
[426] | 274 | ///////////////////////////////// |
---|
[412] | 275 | int stat( const char * pathname, |
---|
| 276 | struct stat * stat ) |
---|
| 277 | { |
---|
[426] | 278 | return hal_user_syscall( SYS_STAT, |
---|
[412] | 279 | (reg_t)pathname, |
---|
| 280 | (reg_t)stat, 0, 0 ); |
---|
| 281 | } |
---|
| 282 | |
---|
[426] | 283 | //////////////////////// |
---|
| 284 | int wait( int * status ) |
---|
| 285 | { |
---|
| 286 | return hal_user_syscall( SYS_WAIT, |
---|
| 287 | (reg_t)status, 0, 0, 0 ); |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | ///////////// Non standard system calls //////////////////////////////////// |
---|
| 293 | |
---|
| 294 | ////////////////////////// |
---|
| 295 | int fg( unsigned int pid ) |
---|
| 296 | { |
---|
| 297 | return hal_user_syscall( SYS_FG, |
---|
| 298 | (reg_t)pid, 0, 0, 0 ); |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | ////////////////////////////////////// |
---|
| 302 | int get_config( unsigned int * x_size, |
---|
| 303 | unsigned int * y_size, |
---|
| 304 | unsigned int * ncores ) |
---|
| 305 | { |
---|
| 306 | return hal_user_syscall( SYS_GET_CONFIG, |
---|
| 307 | (reg_t)x_size, |
---|
| 308 | (reg_t)y_size, |
---|
| 309 | (reg_t)ncores, 0 ); |
---|
| 310 | } |
---|
| 311 | |
---|
| 312 | ///////////////////////////////// |
---|
| 313 | int get_core( unsigned int * cxy, |
---|
| 314 | unsigned int * lid ) |
---|
| 315 | { |
---|
| 316 | return hal_user_syscall( SYS_GET_CORE, |
---|
| 317 | (reg_t)cxy, |
---|
| 318 | (reg_t)lid, 0, 0 ); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | //////////////////////////////////// |
---|
| 322 | void display_string( char * string ) |
---|
| 323 | { |
---|
| 324 | hal_user_syscall( SYS_DISPLAY, |
---|
| 325 | DISPLAY_STRING, |
---|
| 326 | (reg_t)string, 0, 0 ); |
---|
| 327 | } |
---|
| 328 | |
---|
| 329 | /////////////////////////////////// |
---|
| 330 | int display_vmm( unsigned int pid ) |
---|
| 331 | { |
---|
| 332 | return hal_user_syscall( SYS_DISPLAY, |
---|
| 333 | DISPLAY_VMM, |
---|
| 334 | (reg_t)pid, 0, 0 ); |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | //////////////////////////////// |
---|
| 338 | int display_sched( unsigned int cxy, |
---|
| 339 | unsigned int lid ) |
---|
| 340 | { |
---|
| 341 | return hal_user_syscall( SYS_DISPLAY, |
---|
| 342 | DISPLAY_SCHED, |
---|
| 343 | (reg_t)cxy, |
---|
| 344 | (reg_t)lid, 0 ); |
---|
| 345 | } |
---|
| 346 | |
---|
| 347 | /////////////////////////////////////// |
---|
| 348 | int display_process( unsigned int cxy ) |
---|
| 349 | { |
---|
| 350 | return hal_user_syscall( SYS_DISPLAY, |
---|
| 351 | DISPLAY_PROCESS, |
---|
| 352 | (reg_t)cxy, 0, 0 ); |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | /////////////////// |
---|
| 356 | int display_chdev() |
---|
| 357 | { |
---|
| 358 | return hal_user_syscall( SYS_DISPLAY, |
---|
| 359 | DISPLAY_CHDEV, 0, 0, 0 ); |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | ///////////////// |
---|
| 363 | int display_vfs() |
---|
| 364 | { |
---|
| 365 | return hal_user_syscall( SYS_DISPLAY, |
---|
| 366 | DISPLAY_VFS, 0, 0, 0 ); |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | /////////////////////////////////////////// |
---|
| 370 | int get_cycle( unsigned long long * cycle ) |
---|
| 371 | { |
---|
| 372 | return hal_user_syscall( SYS_GET_CYCLE, |
---|
| 373 | (reg_t)cycle, 0, 0, 0 ); |
---|
| 374 | } |
---|
| 375 | |
---|
| 376 | ////////////////////////////////// |
---|
[412] | 377 | int trace( unsigned int operation, |
---|
| 378 | unsigned int pid, |
---|
| 379 | unsigned int trdid ) |
---|
| 380 | { |
---|
| 381 | return hal_user_syscall( SYS_TRACE, |
---|
| 382 | (reg_t)pid, |
---|
| 383 | (reg_t)trdid, 0, 0 ); |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | |
---|