Changeset 426
- Timestamp:
- Jan 29, 2018, 6:00:54 PM (7 years ago)
- Location:
- trunk/libs
- Files:
-
- 2 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/libs/malloc.c
r416 r426 22 22 */ 23 23 24 #include <nostdio.h>25 24 #include <stdlib.h> 26 25 #include <stdio.h> -
trunk/libs/pthread.c
r412 r426 24 24 #include <shared_syscalls.h> 25 25 #include <hal_user.h> 26 #include <nostdio.h>27 26 #include <stdio.h> 28 27 #include <stdlib.h> -
trunk/libs/stdio.c
r412 r426 29 29 #define reg_t int 30 30 31 ///////////// POSIX standard system calls //////////////////////////////////// 32 31 33 /////////////////////// 32 34 void exit( int status ) … … 36 38 } 37 39 38 // 11///////////////////////////40 ///////////////////////////////// 39 41 int munmap( void * addr, 40 42 unsigned int size ) … … 45 47 } 46 48 47 // 12//////////////////////////49 //////////////////////////////// 48 50 int open( const char * pathname, 49 51 int flags, … … 56 58 } 57 59 58 // 13/////////////////////////60 /////////////////////////////// 59 61 void * mmap( void * addr, 60 62 unsigned int length, … … 77 79 } 78 80 79 // 14////////////////////81 ////////////////////////// 80 82 int read( int fd, 81 83 void * buf, … … 88 90 } 89 91 90 // 15/////////////////////92 /////////////////////////// 91 93 int write( int fd, 92 94 const void * buf, … … 99 101 } 100 102 101 // 16/////////////////////103 /////////////////////////// 102 104 int lseek( int fd, 103 105 unsigned int offset, … … 110 112 } 111 113 112 // 17/////////////114 /////////////////// 113 115 int close( int fd ) 114 116 { … … 117 119 } 118 120 119 // 18/////////////////////////////121 /////////////////////////////////// 120 122 int unlink( const char * pathname ) 121 123 { … … 124 126 } 125 127 126 // 19///////////////128 ///////////////////// 127 129 int pipe( int fd[2] ) 128 130 { … … 130 132 } 131 133 132 // 20////////////////////////////134 ////////////////////////////////// 133 135 int chdir( const char * pathname ) 134 136 { … … 137 139 } 138 140 139 // 21///////////////////////////141 ///////////////////////////////// 140 142 int mkdir( const char * pathname, 141 143 int mode ) … … 146 148 } 147 149 148 // 22////////////////////////////150 ////////////////////////////////// 149 151 int mkfifo( const char * pathname, 150 152 int mode ) … … 155 157 } 156 158 157 // 23////////////////////////////////159 ////////////////////////////////////// 158 160 DIR * opendir( const char * pathname ) 159 161 { … … 167 169 } 168 170 169 // 24///////////////////////////////171 ///////////////////////////////////// 170 172 struct dirent * readdir( DIR * dirp ) 171 173 { … … 179 181 } 180 182 181 // 25////////////////////183 ////////////////////////// 182 184 int closedir( DIR * dirp ) 183 185 { … … 186 188 } 187 189 188 // 26///////////////////////190 ///////////////////////////// 189 191 int getcwd( char * buf, 190 192 unsigned int bytes ) … … 195 197 } 196 198 197 // 29//////////////////////199 //////////////////////////// 198 200 int rmdir( char * pathname ) 199 201 { … … 202 204 } 203 205 204 // 30///////////////////////////206 ///////////////////////////////// 205 207 int utls( unsigned int operation, 206 208 unsigned int value ) … … 211 213 } 212 214 213 // 31/////////////////////////215 /////////////////////////////// 214 216 int chmod( char * pathname, 215 217 unsigned int rights ) … … 220 222 } 221 223 222 // 32///////////////////////////224 ///////////////////////////////// 223 225 int signal( unsigned int sigid, 224 226 void * handler ) … … 229 231 } 230 232 231 // 33/////////////////////////////////233 /////////////////////////////////////// 232 234 int gettimeofday( struct timeval * tv, 233 235 struct timezone * tz ) … … 238 240 } 239 241 240 // 34/////////////////////242 /////////////////////////// 241 243 int kill( unsigned int pid, 242 244 unsigned int sig_id ) … … 247 249 } 248 250 249 // 35//////251 //////////// 250 252 int getpid() 251 253 { … … 253 255 } 254 256 255 // 36////257 ////////// 256 258 int fork() 257 259 { … … 259 261 } 260 262 261 // 37/////////////////////263 /////////////////////////// 262 264 int exec( char * pathname, 263 265 char ** argv, … … 270 272 } 271 273 272 // 38///////////////////////////274 ///////////////////////////////// 273 275 int stat( const char * pathname, 274 276 struct stat * stat ) 275 277 { 276 return hal_user_syscall( SYS_ EXEC,278 return hal_user_syscall( SYS_STAT, 277 279 (reg_t)pathname, 278 280 (reg_t)stat, 0, 0 ); 279 281 } 280 282 281 // 39 //////////////////////////// 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 ////////////////////////////////// 282 377 int trace( unsigned int operation, 283 378 unsigned int pid, -
trunk/libs/stdio.h
r412 r426 29 29 #define NULL (void *)0 30 30 31 /****************** Standard (POSIX) system calls **************************************/ 32 31 33 /***************************************************************************************** 32 34 * This function terminates a process. … … 277 279 * This function implements the POSIX "getpid" system call. 278 280 ***************************************************************************************** 279 * @ returns the process PID for the calling thread .281 * @ returns the process PID for the calling thread process. 280 282 ****************************************************************************************/ 281 283 int getpid(); … … 329 331 330 332 /***************************************************************************************** 331 * This function is used to activate / desactivate the trace for a thread 333 * This blocking function returns only when one child process of the calling process 334 * changes state (from RUNNING to STOPPED / EXITED / KILLED). It returns the terminating 335 * child process PID, and set in the <status> buffer the new child process state. 336 ***************************************************************************************** 337 * @ status : [out] terminating child process state. 338 * @ returns terminating child process pid. 339 ****************************************************************************************/ 340 int wait( int * status ); 341 342 /****************** Non standard (ALMOS_MKH specific) system calls **********************/ 343 344 345 /***************************************************************************************** 346 * This function is used to give the process identified by the <pid> argument the 347 * exclusive ownership of the attached TXT_RX terminal. 348 ***************************************************************************************** 349 * @ pid : process identifier. 350 * @ returns O if success / returns -1 if process not found. 351 ****************************************************************************************/ 352 int fg( unsigned int pid ); 353 354 /*************************************************************************************** 355 * This function returns the hardware platform parameters. 356 *************************************************************************************** 357 * @ x_size : [out] number of clusters in a row. 358 * @ y_size : [out] number of clusters in a column. 359 * @ ncores : [out] number of cores per cluster. 360 * @ return always 0. 361 **************************************************************************************/ 362 int get_config( unsigned int * x_size, 363 unsigned int * y_size, 364 unsigned int * ncores ); 365 366 /*************************************************************************************** 367 * This function returns the cluster an local index for the calling core. 368 *************************************************************************************** 369 * @ cxy : [out] cluster identifier. 370 * @ lid : [out] core local index in cluster. 371 * @ return always 0. 372 **************************************************************************************/ 373 int get_core( unsigned int * cxy, 374 unsigned int * lid ); 375 376 /*************************************************************************************** 377 * This function returns the calling core cycles counter, 378 * taking into account a possible overflow on 32 bits architectures. 379 *************************************************************************************** 380 * @ cycle : [out] current cycle value. 381 * @ return always 0. 382 **************************************************************************************/ 383 int get_cycle( unsigned long long * cycle ); 384 385 /*************************************************************************************** 386 * This debug function displays on the kernel terminal TXT0 387 * the thread / process / core identifiers, the current cycle, plus a user defined 388 * message as specified by the <string> argument. 389 *************************************************************************************** 390 * @ string : [in] user defined message. 391 **************************************************************************************/ 392 void display_string( char * string ); 393 394 /*************************************************************************************** 395 * This debug function displays on the kernel terminal TXT0 396 * the state of the process VMM identified by the <pid> argument. 397 * It can be called by any thread running in any cluster. 398 *************************************************************************************** 399 * @ pid : [in] process identifier. 400 * @ return 0 if success / return -1 if illegal argument. 401 **************************************************************************************/ 402 int display_vmm( unsigned int pid ); 403 404 /*************************************************************************************** 405 * This debug function displays on the kernel terminal TXT0 406 * the state of the core scheduler identified by the <cxy> and <lid> arguments. 407 * It can be called by any thread running in any cluster. 408 *************************************************************************************** 409 * @ cxy : [in] target cluster identifier. 410 * @ lid : [in] target core local index. 411 * @ return 0 if success / return -1 if illegal arguments. 412 **************************************************************************************/ 413 int display_sched( unsigned int cxy, 414 unsigned int lid ); 415 416 /*************************************************************************************** 417 * This debug function displays on the kernel terminal TXT0 418 * the list of process registered in a given cluster identified by the <cxy> argument. 419 * It can be called by any thread running in any cluster. 420 *************************************************************************************** 421 * @ cxy : [in] target cluster identifier. 422 * @ return 0 if success / return -1 if illegal argument. 423 **************************************************************************************/ 424 int display_process( unsigned int cxy ); 425 426 /*************************************************************************************** 427 * This debug function displays on the kernel terminal TXT0 428 * the list of channel devices available in the architecture. 429 * It can be called by any thread running in any cluster. 430 *************************************************************************************** 431 * @ return always 0. 432 **************************************************************************************/ 433 int display_chdev(); 434 435 /*************************************************************************************** 436 * This debug function displays on the kernel terminal TXT0 437 * the list of channel device or pseudo-files registered in the VFS cache. 438 * It can be called by any thread running in any cluster. 439 *************************************************************************************** 440 * @ return always 0. 441 **************************************************************************************/ 442 int display_vfs(); 443 444 /***************************************************************************************** 445 * This debug function is used to activate / desactivate the trace for a thread 332 446 * identified by the <trdid> and <pid> arguments. 333 447 * It can be called by any other thread in the same process. … … 336 450 * @ pid : process identifier. 337 451 * @ trdid : thread identifier. 338 * @ returns O if success / returns -1 if failure.452 * @ returns O if success / returns -1 if illegal arguments. 339 453 ****************************************************************************************/ 340 454 int trace( unsigned int operation, -
trunk/libs/stdlib.c
r416 r426 22 22 */ 23 23 24 #include <nostdio.h>25 24 #include <stdio.h> 26 25 #include <stdarg.h> … … 40 39 } 41 40 42 ///////////////////////// 43 int atoi(const char *str) 44 { 45 int res = 0; // Initialize result 46 int sign = 1; // Initialize sign as positive 47 int i = 0; // Initialize index of first digit 48 49 if (str[0] == '-') //If number is negative, then update sign 50 { 51 sign = -1; 52 i++; // Also update index of first digit 53 } 54 55 for (; str[i] != '\0'; ++i) // Iterate through all digits and update the result 56 { 57 res = res*10 + str[i] - '0'; 41 ////////////////////////// 42 int atoi(const char * str) 43 { 44 int res = 0; // Initialize result 45 int sign = 1; // Initialize sign as positive 46 int i = 0; // Initialize index of first digit 47 48 if( (str[0] == '0') && ((str[1] == 'x') || (str[1] == 'X')) ) // hexa 49 { 50 i = 2; 51 52 while( str[i] != 0 ) 53 { 54 if ( (str[i] >= '0') && (str[i] <= '9') ) res = (res<<4) + (str[i] - '0'); 55 else if( (str[i] >= 'A') && (str[i] <= 'F') ) res = (res<<4) + (str[i] - 'A'); 56 else if( (str[i] >= 'a') && (str[i] <= 'f') ) res = (res<<4) + (str[i] - 'a'); 57 else return 0; 58 i++; 59 } 60 } 61 else // decimal 62 { 63 if (str[0] == '-') // number is negative, update sign 64 { 65 sign = -1; 66 i++; // Also update index of first digit 67 } 68 69 while( str[i] != 0 ) 70 { 71 if( (str[i] >= '0') && (str[i] <= '9') ) res = (res*10) + (str[i] - '0'); 72 else return 0; 73 i++; 74 } 58 75 } 59 76 … … 382 399 if ( count == -1 ) 383 400 { 384 panic( "stdlibxprintf failure" );401 display_string( "stdlib : xprintf failure" ); 385 402 return -1; 386 403 } … … 495 512 } // end getint() 496 513 497 /////////////////////////////////////// ////498 int snprintf( char * string,514 /////////////////////////////////////// 515 int snprintf( char * string, 499 516 unsigned int length, 500 const char * format, ... )517 const char * format, ... ) 501 518 { 502 519 va_list args;
Note: See TracChangeset
for help on using the changeset viewer.