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