[421] | 1 | /* |
---|
| 2 | * sys_display.c - display the current state of a kernel structure on TXT0 |
---|
| 3 | * |
---|
[657] | 4 | * Author Alain Greiner (2016,2017,2018,2019,2020) |
---|
[421] | 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 | |
---|
[457] | 24 | #include <hal_kernel_types.h> |
---|
[421] | 25 | #include <hal_uspace.h> |
---|
[624] | 26 | #include <hal_vmm.h> |
---|
[421] | 27 | #include <errno.h> |
---|
[433] | 28 | #include <vmm.h> |
---|
[421] | 29 | #include <cluster.h> |
---|
| 30 | #include <thread.h> |
---|
| 31 | #include <process.h> |
---|
[433] | 32 | #include <string.h> |
---|
[443] | 33 | #include <shared_syscalls.h> |
---|
[623] | 34 | #include <remote_barrier.h> |
---|
[611] | 35 | #include <vfs.h> |
---|
| 36 | #include <mapper.h> |
---|
[664] | 37 | #include <ksocket.h> |
---|
[506] | 38 | #include <syscalls.h> |
---|
| 39 | |
---|
[443] | 40 | ///////////////////////////////////////////////////////////////////////////////// |
---|
| 41 | // This static function returns a printable string for the type of display. |
---|
| 42 | ///////////////////////////////////////////////////////////////////////////////// |
---|
[421] | 43 | |
---|
[443] | 44 | #if DEBUG_SYS_DISPLAY |
---|
| 45 | static char* display_type_str( uint32_t type ) |
---|
| 46 | { |
---|
| 47 | if ( type == DISPLAY_STRING ) return "STRING"; |
---|
| 48 | else if( type == DISPLAY_VMM ) return "VMM"; |
---|
| 49 | else if( type == DISPLAY_SCHED ) return "SCHED"; |
---|
| 50 | else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES"; |
---|
| 51 | else if( type == DISPLAY_VFS ) return "VFS"; |
---|
| 52 | else if( type == DISPLAY_CHDEV ) return "CHDEV"; |
---|
| 53 | else if( type == DISPLAY_TXT_PROCESSES ) return "TXT_PROCESSES"; |
---|
[580] | 54 | else if( type == DISPLAY_DQDT ) return "DQDT"; |
---|
| 55 | else if( type == DISPLAY_BUSYLOCKS ) return "BUSYLOCKS"; |
---|
[612] | 56 | else if( type == DISPLAY_MAPPER ) return "MAPPER"; |
---|
[623] | 57 | else if( type == DISPLAY_BARRIER ) return "BARRIER"; |
---|
[626] | 58 | else if( type == DISPLAY_FAT ) return "FAT"; |
---|
[664] | 59 | else if( type == DISPLAY_SOCKET ) return "SOCKET"; |
---|
[670] | 60 | else if( type == DISPLAY_FD ) return "FD"; |
---|
| 61 | else if( type == DISPLAY_WINDOWS ) return "WINDOWS"; |
---|
[612] | 62 | else return "undefined"; |
---|
[443] | 63 | } |
---|
| 64 | #endif |
---|
| 65 | |
---|
[421] | 66 | ///////////////////////////// |
---|
| 67 | int sys_display( reg_t type, |
---|
| 68 | reg_t arg0, |
---|
[611] | 69 | reg_t arg1, |
---|
| 70 | reg_t arg2 ) |
---|
[421] | 71 | { |
---|
[433] | 72 | |
---|
[440] | 73 | error_t error; |
---|
| 74 | vseg_t * vseg; |
---|
| 75 | |
---|
| 76 | thread_t * this = CURRENT_THREAD; |
---|
| 77 | process_t * process = this->process; |
---|
| 78 | |
---|
[594] | 79 | #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 80 | uint64_t tm_start = hal_get_cycles(); |
---|
| 81 | #endif |
---|
| 82 | |
---|
[438] | 83 | #if DEBUG_SYS_DISPLAY |
---|
[433] | 84 | tm_start = hal_get_cycles(); |
---|
[438] | 85 | if( DEBUG_SYS_DISPLAY < tm_start ) |
---|
[664] | 86 | printk("\n[%s] thread[%x,%x] enter / type %s / arg0 %x / arg1 %x / arg2 %x / cycle = %d\n", |
---|
| 87 | __FUNCTION__, process->pid, this->trdid, display_type_str(type), |
---|
| 88 | (uint32_t)arg0, (uint32_t)arg1, (uint32_t)arg2, (uint32_t)tm_start ); |
---|
[433] | 89 | #endif |
---|
| 90 | |
---|
[623] | 91 | switch( type ) |
---|
[421] | 92 | { |
---|
[623] | 93 | //////////////////// |
---|
| 94 | case DISPLAY_STRING: |
---|
| 95 | { |
---|
| 96 | char kbuf[512]; |
---|
| 97 | uint32_t length; |
---|
[421] | 98 | |
---|
[623] | 99 | char * string = (char *)arg0; |
---|
[440] | 100 | |
---|
[623] | 101 | // check string in user space |
---|
| 102 | error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg ); |
---|
| 103 | if( error ) |
---|
| 104 | { |
---|
[440] | 105 | |
---|
| 106 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 107 | printk("\n[ERROR] in %s for STRING : string buffer %x unmapped\n", |
---|
| 108 | __FUNCTION__ , (intptr_t)arg0 ); |
---|
[440] | 109 | #endif |
---|
[623] | 110 | this->errno = EINVAL; |
---|
| 111 | return -1; |
---|
| 112 | } |
---|
[421] | 113 | |
---|
[623] | 114 | // ckeck string length |
---|
| 115 | length = hal_strlen_from_uspace( string ); |
---|
| 116 | if( length >= 512 ) |
---|
| 117 | { |
---|
[440] | 118 | |
---|
| 119 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 120 | printk("\n[ERROR] in %s STRING : string length %d too large\n", |
---|
[580] | 121 | __FUNCTION__ , length ); |
---|
[440] | 122 | #endif |
---|
[623] | 123 | this->errno = EINVAL; |
---|
| 124 | return -1; |
---|
| 125 | } |
---|
[421] | 126 | |
---|
[623] | 127 | // copy string to kernel space |
---|
[637] | 128 | hal_strcpy_from_uspace( XPTR( local_cxy , kbuf ), |
---|
| 129 | string, |
---|
| 130 | 512 ); |
---|
[421] | 131 | |
---|
[623] | 132 | // print message on TXT0 kernel terminal |
---|
| 133 | printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() ); |
---|
[421] | 134 | |
---|
[623] | 135 | break; |
---|
| 136 | } |
---|
| 137 | ///////////////// |
---|
| 138 | case DISPLAY_VMM: |
---|
[443] | 139 | { |
---|
[640] | 140 | cxy_t cxy = (cxy_t)arg0; |
---|
| 141 | pid_t pid = (pid_t)arg1; |
---|
| 142 | bool_t mapping = (arg2 != 0); |
---|
[421] | 143 | |
---|
[623] | 144 | // check cxy argument |
---|
[637] | 145 | if( cluster_is_active( cxy ) == false ) |
---|
[623] | 146 | { |
---|
| 147 | |
---|
[443] | 148 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 149 | printk("\n[ERROR] in %s VMM : process %x in cluster %x not found\n", |
---|
[580] | 150 | __FUNCTION__ , pid , cxy ); |
---|
[443] | 151 | #endif |
---|
[623] | 152 | this->errno = EINVAL; |
---|
| 153 | return -1; |
---|
| 154 | } |
---|
[443] | 155 | |
---|
[623] | 156 | // get extended pointer on process PID in cluster CXY |
---|
| 157 | xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid ); |
---|
| 158 | if( process_xp == XPTR_NULL ) |
---|
| 159 | { |
---|
[440] | 160 | |
---|
| 161 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 162 | printk("\n[ERROR] in %s VMM : process %x in cluster %x not found\n", |
---|
[580] | 163 | __FUNCTION__ , pid , cxy ); |
---|
[440] | 164 | #endif |
---|
[623] | 165 | this->errno = EINVAL; |
---|
| 166 | return -1; |
---|
| 167 | } |
---|
[421] | 168 | |
---|
[623] | 169 | // call kernel function |
---|
[640] | 170 | hal_vmm_display( process_xp , mapping ); |
---|
[623] | 171 | |
---|
| 172 | break; |
---|
[421] | 173 | } |
---|
[623] | 174 | /////////////////// |
---|
| 175 | case DISPLAY_SCHED: |
---|
[421] | 176 | { |
---|
[623] | 177 | cxy_t cxy = (cxy_t)arg0; |
---|
| 178 | lid_t lid = (lid_t)arg1; |
---|
[421] | 179 | |
---|
[623] | 180 | // check cxy argument |
---|
[637] | 181 | if( cluster_is_active( cxy ) == false ) |
---|
[623] | 182 | { |
---|
[440] | 183 | |
---|
| 184 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 185 | printk("\n[ERROR] in %s SCHED : illegal cxy argument %x\n", |
---|
[580] | 186 | __FUNCTION__ , cxy ); |
---|
[440] | 187 | #endif |
---|
[623] | 188 | this->errno = EINVAL; |
---|
| 189 | return -1; |
---|
| 190 | } |
---|
[421] | 191 | |
---|
[623] | 192 | // check lid argument |
---|
| 193 | if( lid >= LOCAL_CLUSTER->cores_nr ) |
---|
| 194 | { |
---|
[440] | 195 | |
---|
| 196 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 197 | printk("\n[ERROR] in %s SCHED : illegal lid argument %x\n", |
---|
[580] | 198 | __FUNCTION__ , lid ); |
---|
[440] | 199 | #endif |
---|
[623] | 200 | this->errno = EINVAL; |
---|
| 201 | return -1; |
---|
| 202 | } |
---|
[421] | 203 | |
---|
[640] | 204 | // call kernel function |
---|
| 205 | sched_remote_display( cxy , lid ); |
---|
[623] | 206 | |
---|
| 207 | break; |
---|
[421] | 208 | } |
---|
[623] | 209 | /////////////////////////////// |
---|
| 210 | case DISPLAY_CLUSTER_PROCESSES: |
---|
[421] | 211 | { |
---|
[623] | 212 | cxy_t cxy = (cxy_t)arg0; |
---|
| 213 | bool_t owned = (bool_t)arg1; |
---|
[421] | 214 | |
---|
[623] | 215 | // check cxy argument |
---|
[637] | 216 | if( cluster_is_active( cxy ) == false ) |
---|
[623] | 217 | { |
---|
[440] | 218 | |
---|
| 219 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 220 | printk("\n[ERROR] in %s CLUSTER_PROCESSES : illegal cxy argument %x\n", |
---|
[580] | 221 | __FUNCTION__ , cxy ); |
---|
[440] | 222 | #endif |
---|
[623] | 223 | this->errno = EINVAL; |
---|
| 224 | return -1; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | cluster_processes_display( cxy , owned ); |
---|
| 228 | |
---|
| 229 | break; |
---|
[433] | 230 | } |
---|
[623] | 231 | ///////////////// |
---|
| 232 | case DISPLAY_VFS: |
---|
| 233 | { |
---|
| 234 | vfs_display( process->vfs_root_xp ); |
---|
[421] | 235 | |
---|
[623] | 236 | break; |
---|
| 237 | } |
---|
| 238 | /////////////////// |
---|
| 239 | case DISPLAY_CHDEV: |
---|
| 240 | { |
---|
| 241 | chdev_dir_display(); |
---|
[435] | 242 | |
---|
[623] | 243 | break; |
---|
| 244 | } |
---|
| 245 | /////////////////////////// |
---|
| 246 | case DISPLAY_TXT_PROCESSES: |
---|
[435] | 247 | { |
---|
[623] | 248 | uint32_t txt_id = (uint32_t)arg0; |
---|
[440] | 249 | |
---|
[623] | 250 | // check argument |
---|
| 251 | if( txt_id >= LOCAL_CLUSTER->nb_txt_channels ) |
---|
| 252 | { |
---|
| 253 | |
---|
[440] | 254 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 255 | printk("\n[ERROR] in %s TXT_PROCESSES : illegal txt_id argument %d\n", |
---|
[580] | 256 | __FUNCTION__ , txt_id ); |
---|
[440] | 257 | #endif |
---|
[623] | 258 | this->errno = EINVAL; |
---|
| 259 | return -1; |
---|
| 260 | } |
---|
[435] | 261 | |
---|
[623] | 262 | process_txt_display( txt_id ); |
---|
[580] | 263 | |
---|
[623] | 264 | break; |
---|
| 265 | } |
---|
| 266 | ////////////////// |
---|
| 267 | case DISPLAY_DQDT: |
---|
| 268 | { |
---|
| 269 | dqdt_display(); |
---|
[580] | 270 | |
---|
[623] | 271 | break; |
---|
| 272 | } |
---|
| 273 | /////////////////////// |
---|
| 274 | case DISPLAY_BUSYLOCKS: |
---|
[580] | 275 | { |
---|
[623] | 276 | pid_t pid = (pid_t)arg0; |
---|
| 277 | trdid_t trdid = (trdid_t)arg1; |
---|
[580] | 278 | |
---|
[623] | 279 | // get extended pointer on target thread |
---|
| 280 | xptr_t thread_xp = thread_get_xptr( pid , trdid ); |
---|
| 281 | |
---|
| 282 | if( thread_xp == XPTR_NULL ) |
---|
| 283 | { |
---|
| 284 | |
---|
[580] | 285 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 286 | printk("\n[ERROR] in %s BUSYLOCKS : thread[%x,%x] not found\n", |
---|
[594] | 287 | __FUNCTION__ , pid, trdid ); |
---|
[580] | 288 | #endif |
---|
[623] | 289 | this->errno = EINVAL; |
---|
| 290 | return -1; |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | thread_display_busylocks( thread_xp , __FUNCTION__ ); |
---|
| 294 | |
---|
| 295 | break; |
---|
[580] | 296 | } |
---|
[623] | 297 | //////////////////// |
---|
| 298 | case DISPLAY_MAPPER: |
---|
| 299 | { |
---|
| 300 | xptr_t root_inode_xp; |
---|
| 301 | xptr_t inode_xp; |
---|
| 302 | cxy_t inode_cxy; |
---|
| 303 | vfs_inode_t * inode_ptr; |
---|
| 304 | xptr_t mapper_xp; |
---|
| 305 | mapper_t * mapper_ptr; |
---|
[656] | 306 | xptr_t page_xp; |
---|
[580] | 307 | |
---|
[623] | 308 | char kbuf[CONFIG_VFS_MAX_PATH_LENGTH]; |
---|
[611] | 309 | |
---|
[623] | 310 | char * path = (char *)arg0; |
---|
| 311 | uint32_t page_id = (uint32_t)arg1; |
---|
| 312 | uint32_t nbytes = (uint32_t)arg2; |
---|
[611] | 313 | |
---|
[623] | 314 | // check pathname length |
---|
| 315 | if( hal_strlen_from_uspace( path ) >= CONFIG_VFS_MAX_PATH_LENGTH ) |
---|
| 316 | { |
---|
[611] | 317 | |
---|
| 318 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 319 | printk("\n[ERROR] in %s MAPPER : pathname too long\n", |
---|
[611] | 320 | __FUNCTION__ ); |
---|
| 321 | #endif |
---|
[656] | 322 | this->errno = EINVAL; |
---|
[623] | 323 | return -1; |
---|
| 324 | } |
---|
[611] | 325 | |
---|
[656] | 326 | // check nbytes |
---|
| 327 | if( nbytes >= 4096 ) |
---|
| 328 | { |
---|
| 329 | |
---|
| 330 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 331 | printk("\n[ERROR] in %s MAPPER : nbytes cannot be larger than 4096\n", |
---|
[656] | 332 | __FUNCTION__ ); |
---|
| 333 | #endif |
---|
| 334 | this->errno = EINVAL; |
---|
| 335 | return -1; |
---|
| 336 | } |
---|
| 337 | |
---|
[623] | 338 | // copy pathname in kernel space |
---|
[637] | 339 | hal_strcpy_from_uspace( XPTR( local_cxy , kbuf ), |
---|
| 340 | path, |
---|
| 341 | CONFIG_VFS_MAX_PATH_LENGTH ); |
---|
[611] | 342 | |
---|
[623] | 343 | // compute root inode for pathname |
---|
| 344 | if( kbuf[0] == '/' ) // absolute path |
---|
| 345 | { |
---|
| 346 | // use extended pointer on VFS root inode |
---|
| 347 | root_inode_xp = process->vfs_root_xp; |
---|
| 348 | } |
---|
| 349 | else // relative path |
---|
| 350 | { |
---|
| 351 | // get cluster and local pointer on reference process |
---|
| 352 | xptr_t ref_xp = process->ref_xp; |
---|
| 353 | process_t * ref_ptr = (process_t *)GET_PTR( ref_xp ); |
---|
| 354 | cxy_t ref_cxy = GET_CXY( ref_xp ); |
---|
[611] | 355 | |
---|
[623] | 356 | // get extended pointer on CWD inode |
---|
| 357 | root_inode_xp = hal_remote_l64( XPTR( ref_cxy , &ref_ptr->cwd_xp ) ); |
---|
| 358 | } |
---|
[611] | 359 | |
---|
[623] | 360 | // get extended pointer on target inode |
---|
| 361 | error = vfs_lookup( root_inode_xp, |
---|
| 362 | kbuf, |
---|
| 363 | 0, |
---|
| 364 | &inode_xp, |
---|
| 365 | NULL ); |
---|
| 366 | if( error ) |
---|
| 367 | { |
---|
[611] | 368 | |
---|
| 369 | #if DEBUG_SYSCALLS_ERROR |
---|
| 370 | printk("\n[ERROR] in %s for MAPPER : cannot found inode <%s>\n", |
---|
| 371 | __FUNCTION__ , kbuf ); |
---|
| 372 | #endif |
---|
[623] | 373 | this->errno = ENFILE; |
---|
| 374 | return -1; |
---|
| 375 | } |
---|
[611] | 376 | |
---|
[623] | 377 | // get target inode cluster and local pointer |
---|
| 378 | inode_cxy = GET_CXY( inode_xp ); |
---|
| 379 | inode_ptr = GET_PTR( inode_xp ); |
---|
[611] | 380 | |
---|
[623] | 381 | // get extended pointer on target mapper |
---|
| 382 | mapper_ptr = hal_remote_lpt( XPTR( inode_cxy , &inode_ptr->mapper ) ); |
---|
| 383 | mapper_xp = XPTR( inode_cxy , mapper_ptr ); |
---|
[611] | 384 | |
---|
[656] | 385 | // get extended pointer on target page |
---|
[657] | 386 | page_xp = mapper_get_page( mapper_xp , page_id ); |
---|
[611] | 387 | |
---|
[656] | 388 | if( page_xp == XPTR_NULL ) |
---|
[623] | 389 | { |
---|
[611] | 390 | |
---|
| 391 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 392 | printk("\n[ERROR] in %s MAPPER : cannot get page %d\n", |
---|
[611] | 393 | __FUNCTION__ , page_id ); |
---|
| 394 | #endif |
---|
[623] | 395 | this->errno = ENFILE; |
---|
| 396 | return -1; |
---|
| 397 | } |
---|
[440] | 398 | |
---|
[656] | 399 | // display mapper |
---|
| 400 | mapper_display_page( mapper_xp , page_xp , nbytes ); |
---|
| 401 | |
---|
| 402 | |
---|
[623] | 403 | break; |
---|
| 404 | } |
---|
| 405 | ///////////////////// |
---|
| 406 | case DISPLAY_BARRIER: |
---|
| 407 | { |
---|
| 408 | // get target process PID |
---|
| 409 | pid_t pid = (pid_t)arg0; |
---|
| 410 | |
---|
| 411 | // get pointers on owner process |
---|
| 412 | xptr_t process_xp = cluster_get_reference_process_from_pid( pid ); |
---|
| 413 | process_t * process_ptr = GET_PTR( process_xp ); |
---|
| 414 | cxy_t process_cxy = GET_CXY( process_xp ); |
---|
| 415 | |
---|
| 416 | if( process_xp == XPTR_NULL ) |
---|
| 417 | { |
---|
| 418 | |
---|
[440] | 419 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 420 | printk("\n[ERROR] in %s BARRIER : process %x not found\n", |
---|
[623] | 421 | __FUNCTION__ , pid ); |
---|
| 422 | #endif |
---|
| 423 | this->errno = EINVAL; |
---|
| 424 | return -1; |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | // get extended pointer on root of list of barriers |
---|
| 428 | xptr_t root_xp = XPTR( process_cxy , &process_ptr->barrier_root ); |
---|
| 429 | |
---|
| 430 | if( xlist_is_empty( root_xp ) ) |
---|
| 431 | { |
---|
| 432 | |
---|
| 433 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 434 | printk("\n[ERROR] in %s BARRIER : no registered barrier in process %x\n", |
---|
[623] | 435 | __FUNCTION__ , pid ); |
---|
| 436 | #endif |
---|
| 437 | this->errno = EINVAL; |
---|
| 438 | return -1; |
---|
| 439 | } |
---|
| 440 | |
---|
| 441 | // get extended pointer on first registered generic barrier descriptor |
---|
| 442 | xptr_t gen_barrier_xp = XLIST_FIRST( root_xp , generic_barrier_t , list ); |
---|
| 443 | |
---|
| 444 | // display barrier state |
---|
| 445 | generic_barrier_display( gen_barrier_xp ); |
---|
| 446 | |
---|
| 447 | break; |
---|
| 448 | } |
---|
[626] | 449 | ///////////////// |
---|
| 450 | case DISPLAY_FAT: |
---|
| 451 | { |
---|
[657] | 452 | uint32_t slots = (uint32_t)arg1; |
---|
[626] | 453 | |
---|
[657] | 454 | if( slots > 1024 ) |
---|
[626] | 455 | { |
---|
| 456 | |
---|
| 457 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 458 | printk("\n[ERROR] in %s FAT : nb_slots larger than 1024\n", |
---|
[626] | 459 | __FUNCTION__ ); |
---|
| 460 | #endif |
---|
| 461 | this->errno = EINVAL; |
---|
| 462 | return -1; |
---|
| 463 | } |
---|
| 464 | |
---|
[657] | 465 | if( slots == 0 ) // display fat context in cluster cxy |
---|
[626] | 466 | { |
---|
| 467 | uint32_t cxy = (uint32_t)arg0; |
---|
| 468 | |
---|
[637] | 469 | if( cluster_is_active( cxy ) == false ) |
---|
[626] | 470 | { |
---|
| 471 | |
---|
| 472 | #if DEBUG_SYSCALLS_ERROR |
---|
[664] | 473 | printk("\n[ERROR] in %s FAT : illegal cxy argument %x\n", |
---|
[626] | 474 | __FUNCTION__ , cxy ); |
---|
| 475 | #endif |
---|
| 476 | this->errno = EINVAL; |
---|
| 477 | return -1; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | fatfs_display_ctx( cxy ); |
---|
| 481 | } |
---|
[657] | 482 | else // display nb_slots in page |
---|
[626] | 483 | { |
---|
[657] | 484 | uint32_t min = (uint32_t)arg0; |
---|
[626] | 485 | |
---|
[657] | 486 | fatfs_display_fat( min , slots ); |
---|
[626] | 487 | } |
---|
| 488 | |
---|
| 489 | break; |
---|
| 490 | } |
---|
[664] | 491 | //////////////////// |
---|
| 492 | case DISPLAY_SOCKET: |
---|
| 493 | { |
---|
| 494 | pid_t pid = (pid_t)arg0; |
---|
| 495 | trdid_t fdid = (trdid_t)arg1; |
---|
| 496 | |
---|
| 497 | // get extended pointer on owner process descriptor |
---|
| 498 | xptr_t owner_xp = cluster_get_owner_process_from_pid( pid ); |
---|
| 499 | |
---|
| 500 | if( owner_xp == XPTR_NULL ) |
---|
| 501 | { |
---|
| 502 | |
---|
| 503 | #if DEBUG_SYSCALLS_ERROR |
---|
[670] | 504 | printk("\n[ERROR] in %s for SOCKET : pid %x not found\n", __FUNCTION__ , pid ); |
---|
[664] | 505 | #endif |
---|
| 506 | this->errno = EINVAL; |
---|
| 507 | return -1; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | // get extended pointer on file descriptor |
---|
| 511 | xptr_t file_xp = process_fd_get_xptr_from_owner( owner_xp , fdid ); |
---|
| 512 | |
---|
| 513 | if( file_xp == XPTR_NULL ) |
---|
| 514 | { |
---|
| 515 | |
---|
| 516 | #if DEBUG_SYSCALLS_ERROR |
---|
[670] | 517 | printk("\n[ERROR] in %s for SOCKET : fdid %d not found\n", __FUNCTION__ , fdid ); |
---|
[664] | 518 | #endif |
---|
| 519 | this->errno = EINVAL; |
---|
| 520 | return -1; |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | // get local pointer and cluster for file |
---|
| 524 | vfs_file_t * file_ptr = GET_PTR( file_xp ); |
---|
| 525 | cxy_t file_cxy = GET_CXY( file_xp ); |
---|
| 526 | |
---|
| 527 | // get local pointer on socket descriptor |
---|
| 528 | socket_t * socket = hal_remote_lpt( XPTR( file_cxy , &file_ptr->socket ) ); |
---|
| 529 | |
---|
| 530 | // display socket descriptor on TXT0 |
---|
| 531 | socket_display( XPTR( file_cxy , socket ), NULL ); |
---|
| 532 | |
---|
| 533 | break; |
---|
| 534 | } |
---|
[670] | 535 | //////////////// |
---|
| 536 | case DISPLAY_FD: |
---|
| 537 | { |
---|
| 538 | pid_t pid = (pid_t)arg0; |
---|
| 539 | |
---|
| 540 | // get extended pointer on owner process descriptor |
---|
| 541 | xptr_t owner_xp = cluster_get_owner_process_from_pid( pid ); |
---|
| 542 | |
---|
| 543 | if( owner_xp == XPTR_NULL ) |
---|
| 544 | { |
---|
| 545 | |
---|
| 546 | #if DEBUG_SYSCALLS_ERROR |
---|
| 547 | printk("\n[ERROR] in %s for FD : pid %x not found\n", __FUNCTION__ , pid ); |
---|
| 548 | #endif |
---|
| 549 | this->errno = EINVAL; |
---|
| 550 | return -1; |
---|
| 551 | } |
---|
| 552 | |
---|
| 553 | // display fd_array on TXT0 |
---|
| 554 | process_fd_display( owner_xp ); |
---|
| 555 | |
---|
| 556 | break; |
---|
| 557 | } |
---|
| 558 | ///////////////////// |
---|
| 559 | case DISPLAY_WINDOWS: |
---|
| 560 | { |
---|
| 561 | pid_t pid = (pid_t)arg0; |
---|
| 562 | |
---|
| 563 | if( pid != 0 ) // only one target process |
---|
| 564 | { |
---|
| 565 | // get extended pointer on owner process descriptor |
---|
| 566 | xptr_t owner_xp = cluster_get_owner_process_from_pid( pid ); |
---|
| 567 | |
---|
| 568 | if( owner_xp == XPTR_NULL ) |
---|
| 569 | { |
---|
| 570 | |
---|
| 571 | #if DEBUG_SYSCALLS_ERROR |
---|
| 572 | printk("\n[ERROR] in %s for FD : pid %x not found\n", __FUNCTION__ , pid ); |
---|
| 573 | #endif |
---|
| 574 | this->errno = EINVAL; |
---|
| 575 | return -1; |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | // display windows state for one, or for all processes |
---|
| 580 | dev_fbf_display_windows( pid ); |
---|
| 581 | |
---|
| 582 | break; |
---|
| 583 | } |
---|
[623] | 584 | //////// |
---|
| 585 | default: |
---|
| 586 | { |
---|
| 587 | |
---|
| 588 | #if DEBUG_SYSCALLS_ERROR |
---|
[580] | 589 | printk("\n[ERROR] in %s : undefined display type %d\n", |
---|
| 590 | __FUNCTION__ , type ); |
---|
[440] | 591 | #endif |
---|
[623] | 592 | this->errno = EINVAL; |
---|
| 593 | return -1; |
---|
| 594 | } |
---|
| 595 | } // end switch on type |
---|
[421] | 596 | |
---|
[594] | 597 | #if (DEBUG_SYS_DISPLAY || CONFIG_INSTRUMENTATION_SYSCALLS) |
---|
| 598 | uint64_t tm_end = hal_get_cycles(); |
---|
| 599 | #endif |
---|
| 600 | |
---|
[438] | 601 | #if DEBUG_SYS_DISPLAY |
---|
| 602 | if( DEBUG_SYS_DISPLAY < tm_end ) |
---|
[619] | 603 | printk("\n[%s] thread[%x,%x] exit / cycle %d\n", |
---|
[594] | 604 | __FUNCTION__, process->pid, this->trdid, (uint32_t)tm_end ); |
---|
[433] | 605 | #endif |
---|
| 606 | |
---|
[594] | 607 | #if CONFIG_INSTRUMENTATION_SYSCALLS |
---|
| 608 | hal_atomic_add( &syscalls_cumul_cost[SYS_DISPLAY] , tm_end - tm_start ); |
---|
| 609 | hal_atomic_add( &syscalls_occurences[SYS_DISPLAY] , 1 ); |
---|
| 610 | #endif |
---|
| 611 | |
---|
[433] | 612 | return 0; |
---|
| 613 | |
---|
| 614 | } // end sys_display() |
---|