| 1 | /*
|
|---|
| 2 | * sys_display.c - display the current state of a kernel structure on TXT0
|
|---|
| 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 <hal_types.h>
|
|---|
| 25 | #include <hal_uspace.h>
|
|---|
| 26 | #include <errno.h>
|
|---|
| 27 | #include <vmm.h>
|
|---|
| 28 | #include <cluster.h>
|
|---|
| 29 | #include <thread.h>
|
|---|
| 30 | #include <process.h>
|
|---|
| 31 | #include <string.h>
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | /////////////////////////////
|
|---|
| 35 | int sys_display( reg_t type,
|
|---|
| 36 | reg_t arg0,
|
|---|
| 37 | reg_t arg1 )
|
|---|
| 38 | {
|
|---|
| 39 |
|
|---|
| 40 | error_t error;
|
|---|
| 41 | vseg_t * vseg;
|
|---|
| 42 |
|
|---|
| 43 | thread_t * this = CURRENT_THREAD;
|
|---|
| 44 | process_t * process = this->process;
|
|---|
| 45 |
|
|---|
| 46 | #if DEBUG_SYS_DISPLAY
|
|---|
| 47 | uint64_t tm_start;
|
|---|
| 48 | uint64_t tm_end;
|
|---|
| 49 | tm_start = hal_get_cycles();
|
|---|
| 50 | if( DEBUG_SYS_DISPLAY < tm_start )
|
|---|
| 51 | printk("\n[DBG] %s : thread %d enter / process %x / type %d / cycle = %d\n",
|
|---|
| 52 | __FUNCTION__, this, this->process->pid, type, (uint32_t)tm_start );
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| 55 | ////////////////////////////
|
|---|
| 56 | if( type == DISPLAY_STRING )
|
|---|
| 57 | {
|
|---|
| 58 | char kbuf[256];
|
|---|
| 59 | uint32_t length;
|
|---|
| 60 |
|
|---|
| 61 | char * string = (char *)arg0;
|
|---|
| 62 |
|
|---|
| 63 | // check string in user space
|
|---|
| 64 | error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
|
|---|
| 65 |
|
|---|
| 66 | if( error )
|
|---|
| 67 | {
|
|---|
| 68 |
|
|---|
| 69 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 70 | printk("\n[ERROR] in %s : string buffer %x unmapped / thread %x / process %x\n",
|
|---|
| 71 | __FUNCTION__ , (intptr_t)arg0 , this->trdid , process->pid );
|
|---|
| 72 | #endif
|
|---|
| 73 | this->errno = EINVAL;
|
|---|
| 74 | return -1;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | // ckeck string length
|
|---|
| 78 | length = hal_strlen_from_uspace( string );
|
|---|
| 79 |
|
|---|
| 80 | if( length >= 256 )
|
|---|
| 81 | {
|
|---|
| 82 |
|
|---|
| 83 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 84 | printk("\n[ERROR] in %s : string length %d too large / thread %x / process %x\n",
|
|---|
| 85 | __FUNCTION__ , length , this->trdid , process->pid );
|
|---|
| 86 | #endif
|
|---|
| 87 | this->errno = EINVAL;
|
|---|
| 88 | return -1;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // copy string to kernel space
|
|---|
| 92 | hal_strcpy_from_uspace( kbuf , string , 256 );
|
|---|
| 93 |
|
|---|
| 94 | // print message on TXT0 kernel terminal
|
|---|
| 95 | printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
|
|---|
| 96 | }
|
|---|
| 97 | //////////////////////////////
|
|---|
| 98 | else if( type == DISPLAY_VMM )
|
|---|
| 99 | {
|
|---|
| 100 | pid_t pid = (pid_t)arg0;
|
|---|
| 101 |
|
|---|
| 102 | // get extended pointer on reference process
|
|---|
| 103 | xptr_t process_xp = cluster_get_reference_process_from_pid( pid );
|
|---|
| 104 |
|
|---|
| 105 | if( process_xp == XPTR_NULL )
|
|---|
| 106 | {
|
|---|
| 107 |
|
|---|
| 108 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 109 | printk("\n[ERROR] in %s : undefined pid argument %d / thread %x / process %x\n",
|
|---|
| 110 | __FUNCTION__ , pid , this->trdid , process->pid );
|
|---|
| 111 | #endif
|
|---|
| 112 | this->errno = EINVAL;
|
|---|
| 113 | return -1;
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | // get cluster and local pointer on process
|
|---|
| 117 | cxy_t process_cxy = GET_CXY( process_xp );
|
|---|
| 118 | process_t * process_ptr = (process_t *)GET_PTR( process_xp );
|
|---|
| 119 |
|
|---|
| 120 | // call kernel function
|
|---|
| 121 | if( process_cxy == local_cxy )
|
|---|
| 122 | {
|
|---|
| 123 | vmm_display( process_ptr , true );
|
|---|
| 124 | }
|
|---|
| 125 | else
|
|---|
| 126 | {
|
|---|
| 127 | rpc_vmm_display_client( process_cxy , process_ptr , true );
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | ////////////////////////////////
|
|---|
| 131 | else if( type == DISPLAY_SCHED )
|
|---|
| 132 | {
|
|---|
| 133 | cxy_t cxy = (cxy_t)arg0;
|
|---|
| 134 | lid_t lid = (lid_t)arg1;
|
|---|
| 135 |
|
|---|
| 136 | // check cxy argument
|
|---|
| 137 | if( cluster_is_undefined( cxy ) )
|
|---|
| 138 | {
|
|---|
| 139 |
|
|---|
| 140 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 141 | printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
|
|---|
| 142 | __FUNCTION__ , cxy , this->trdid , process->pid );
|
|---|
| 143 | #endif
|
|---|
| 144 | this->errno = EINVAL;
|
|---|
| 145 | return -1;
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | // check lid argument
|
|---|
| 149 | if( lid >= LOCAL_CLUSTER->cores_nr )
|
|---|
| 150 | {
|
|---|
| 151 |
|
|---|
| 152 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 153 | printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n",
|
|---|
| 154 | __FUNCTION__ , lid , this->trdid , process->pid );
|
|---|
| 155 | #endif
|
|---|
| 156 | this->errno = EINVAL;
|
|---|
| 157 | return -1;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | if( cxy == local_cxy )
|
|---|
| 161 | {
|
|---|
| 162 | sched_display( lid );
|
|---|
| 163 | }
|
|---|
| 164 | else
|
|---|
| 165 | {
|
|---|
| 166 | rpc_sched_display_client( cxy , lid );
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 | ////////////////////////////////////////////
|
|---|
| 170 | else if( type == DISPLAY_CLUSTER_PROCESSES )
|
|---|
| 171 | {
|
|---|
| 172 | cxy_t cxy = (cxy_t)arg0;
|
|---|
| 173 |
|
|---|
| 174 | // check cxy argument
|
|---|
| 175 | if( cluster_is_undefined( cxy ) )
|
|---|
| 176 | {
|
|---|
| 177 |
|
|---|
| 178 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 179 | printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
|
|---|
| 180 | __FUNCTION__ , cxy , this->trdid , process->pid );
|
|---|
| 181 | #endif
|
|---|
| 182 | this->errno = EINVAL;
|
|---|
| 183 | return -1;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | cluster_processes_display( cxy );
|
|---|
| 187 | }
|
|---|
| 188 | ////////////////////////////////////////
|
|---|
| 189 | else if( type == DISPLAY_TXT_PROCESSES )
|
|---|
| 190 | {
|
|---|
| 191 | uint32_t txt_id = (uint32_t)arg0;
|
|---|
| 192 |
|
|---|
| 193 | // check argument
|
|---|
| 194 | if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
|
|---|
| 195 | {
|
|---|
| 196 |
|
|---|
| 197 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 198 | printk("\n[ERROR] in %s : illegal txt_id argument %d / thread %x / process %x\n",
|
|---|
| 199 | __FUNCTION__ , txt_id , this->trdid , process->pid );
|
|---|
| 200 | #endif
|
|---|
| 201 | this->errno = EINVAL;
|
|---|
| 202 | return -1;
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | process_txt_display( txt_id );
|
|---|
| 206 | }
|
|---|
| 207 | //////////////////////////////
|
|---|
| 208 | else if( type == DISPLAY_VFS )
|
|---|
| 209 | {
|
|---|
| 210 | vfs_display( process->vfs_root_xp );
|
|---|
| 211 | }
|
|---|
| 212 | ////////////////////////////////
|
|---|
| 213 | else if( type == DISPLAY_CHDEV )
|
|---|
| 214 | {
|
|---|
| 215 | chdev_dir_display();
|
|---|
| 216 | }
|
|---|
| 217 | ////
|
|---|
| 218 | else
|
|---|
| 219 | {
|
|---|
| 220 |
|
|---|
| 221 | #if DEBUG_SYSCALLS_ERROR
|
|---|
| 222 | printk("\n[ERROR] in %s : undefined display type %x / thread %x / process %x\n",
|
|---|
| 223 | __FUNCTION__ , type , this->trdid , process->pid );
|
|---|
| 224 | #endif
|
|---|
| 225 | this->errno = EINVAL;
|
|---|
| 226 | return -1;
|
|---|
| 227 | }
|
|---|
| 228 |
|
|---|
| 229 | #if DEBUG_SYS_DISPLAY
|
|---|
| 230 | tm_end = hal_get_cycles();
|
|---|
| 231 | if( DEBUG_SYS_DISPLAY < tm_end )
|
|---|
| 232 | printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
|
|---|
| 233 | __FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
|
|---|
| 234 | #endif
|
|---|
| 235 |
|
|---|
| 236 | return 0;
|
|---|
| 237 |
|
|---|
| 238 | } // end sys_display()
|
|---|