source: trunk/kernel/syscalls/sys_display.c @ 467

Last change on this file since 467 was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 7.4 KB
RevLine 
[421]1/*
2 * sys_display.c - display the current state of a kernel structure on TXT0
3 *
[440]4 * Author    Alain Greiner (2016,2017,2018)
[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>
26#include <errno.h>
[433]27#include <vmm.h>
[421]28#include <cluster.h>
29#include <thread.h>
30#include <process.h>
[433]31#include <string.h>
[443]32#include <shared_syscalls.h>
[421]33
[443]34/////////////////////////////////////////////////////////////////////////////////
35// This static function returns a printable string for the type of display.
36/////////////////////////////////////////////////////////////////////////////////
[421]37
[443]38#if DEBUG_SYS_DISPLAY
39static char* display_type_str( uint32_t type )
40{
41    if     ( type == DISPLAY_STRING            ) return "STRING"; 
42    else if( type == DISPLAY_VMM               ) return "VMM"; 
43    else if( type == DISPLAY_SCHED             ) return "SCHED"; 
44    else if( type == DISPLAY_CLUSTER_PROCESSES ) return "CLUSTER_PROCESSES"; 
45    else if( type == DISPLAY_VFS               ) return "VFS"; 
46    else if( type == DISPLAY_CHDEV             ) return "CHDEV"; 
47    else if( type == DISPLAY_TXT_PROCESSES     ) return "TXT_PROCESSES"; 
48}
49#endif
50
[421]51/////////////////////////////
52int sys_display( reg_t  type,
53                 reg_t  arg0,
54                 reg_t  arg1 )
55{
[433]56
[440]57    error_t     error;
58    vseg_t    * vseg;
59
60    thread_t  * this    = CURRENT_THREAD;
61    process_t * process = this->process;
62
[438]63#if DEBUG_SYS_DISPLAY
[433]64uint64_t    tm_start;
65uint64_t    tm_end;
66tm_start = hal_get_cycles();
[438]67if( DEBUG_SYS_DISPLAY < tm_start )
[443]68printk("\n[DBG] %s : thread %d enter / process %x / type  %s / cycle = %d\n",
69__FUNCTION__, this, this->process->pid, display_type_str(type), (uint32_t)tm_start );
[433]70#endif
71
[440]72    ////////////////////////////
[421]73    if( type == DISPLAY_STRING )
74    {
75        char      kbuf[256];
[433]76        uint32_t  length;
[421]77
78        char    * string = (char *)arg0;
[440]79
[421]80        // check string in user space
[440]81        error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
82
83        if( error )
[433]84        {
[440]85
86#if DEBUG_SYSCALLS_ERROR
87printk("\n[ERROR] in %s : string buffer %x unmapped / thread %x / process %x\n",
88__FUNCTION__ , (intptr_t)arg0 , this->trdid , process->pid );
89#endif
90            this->errno = EINVAL;
[433]91            return -1;
92        }
[421]93
94        // ckeck string length
[433]95        length = hal_strlen_from_uspace( string );
[440]96
[433]97        if( length >= 256 )
98        {
[440]99
100#if DEBUG_SYSCALLS_ERROR
101printk("\n[ERROR] in %s : string length %d too large / thread %x / process %x\n",
102__FUNCTION__ , length , this->trdid , process->pid );
103#endif
104            this->errno = EINVAL;
[433]105            return -1;
106        }
[421]107
[440]108        // copy string to kernel space
[421]109        hal_strcpy_from_uspace( kbuf , string , 256 );
110
111        // print message on TXT0 kernel terminal
[440]112        printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
[421]113    }
[440]114    //////////////////////////////
[421]115    else if( type == DISPLAY_VMM )
116    {
[443]117        cxy_t cxy = (cxy_t)arg0;
118        pid_t pid = (pid_t)arg1;
[421]119
[443]120        // check cxy argument
121            if( cluster_is_undefined( cxy ) ) 
122        {
[421]123
[443]124#if DEBUG_SYSCALLS_ERROR
125printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
126__FUNCTION__ , cxy , this->trdid , process->pid );
127#endif
128            this->errno = EINVAL;
129            return -1;
130        }
131
132        // get extended pointer on process PID in cluster CXY
133        xptr_t process_xp = cluster_get_process_from_pid_in_cxy( cxy , pid );
134
[433]135            if( process_xp == XPTR_NULL )
136        {
[440]137
138#if DEBUG_SYSCALLS_ERROR
[443]139printk("\n[ERROR] in %s : process %x in cluster %x not found / thread %x / process %x\n",
140__FUNCTION__ , pid , cxy , this->trdid , process->pid );
[440]141#endif
142            this->errno = EINVAL;
[433]143            return -1;
144        }
[421]145
[443]146        // get local pointer on process
147        process_t * process = (process_t *)GET_PTR( process_xp );
[421]148
149        // call kernel function
[443]150        if( cxy == local_cxy )
[421]151        {
[443]152                vmm_display( process , true );
[421]153        }
154        else
155        {
[443]156            rpc_vmm_display_client( cxy , process , true );
[421]157        }
158    }
[440]159    ////////////////////////////////
[421]160    else if( type == DISPLAY_SCHED )
161    {
162        cxy_t cxy = (cxy_t)arg0;
163        lid_t lid = (lid_t)arg1;
164
[440]165        // check cxy argument
[433]166            if( cluster_is_undefined( cxy ) ) 
167        {
[440]168
169#if DEBUG_SYSCALLS_ERROR
170printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
171__FUNCTION__ , cxy , this->trdid , process->pid );
172#endif
173            this->errno = EINVAL;
[433]174            return -1;
175        }
[421]176
[440]177        // check lid argument
[433]178        if( lid >= LOCAL_CLUSTER->cores_nr )
179        {
[440]180
181#if DEBUG_SYSCALLS_ERROR
182printk("\n[ERROR] in %s : illegal lid argument %x / thread %x / process %x\n",
183__FUNCTION__ , lid , this->trdid , process->pid );
184#endif
185            this->errno = EINVAL;
[433]186            return -1;
187        }
[421]188
189        if( cxy == local_cxy )
190        {
191                sched_display( lid );
192        }
193        else
194        {
[450]195            sched_remote_display( cxy , lid );
[421]196        }
197    }
[440]198    ////////////////////////////////////////////
[435]199    else if( type == DISPLAY_CLUSTER_PROCESSES )
[421]200    {
201        cxy_t cxy = (cxy_t)arg0;
202
[440]203        // check cxy argument
[433]204            if( cluster_is_undefined( cxy ) )
205        {
[440]206
207#if DEBUG_SYSCALLS_ERROR
208printk("\n[ERROR] in %s : illegal cxy argument %x / thread %x / process %x\n",
209__FUNCTION__ , cxy , this->trdid , process->pid );
210#endif
211            this->errno = EINVAL;
[433]212            return -1;
213        }
[421]214
215        cluster_processes_display( cxy );
216    }
[440]217    ////////////////////////////////////////
[435]218    else if( type == DISPLAY_TXT_PROCESSES )
219    {
220        uint32_t txt_id = (uint32_t)arg0;
221
222        // check argument
223            if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
224        {
[440]225
226#if DEBUG_SYSCALLS_ERROR
227printk("\n[ERROR] in %s : illegal txt_id argument %d / thread %x / process %x\n",
228__FUNCTION__ , txt_id , this->trdid , process->pid );
229#endif
230            this->errno = EINVAL;
[435]231            return -1;
232        }
233
234        process_txt_display( txt_id );
235    }
[440]236    //////////////////////////////
[421]237    else if( type == DISPLAY_VFS )
238    {
239        vfs_display( process->vfs_root_xp );
240    }
[440]241    ////////////////////////////////
[421]242    else if( type == DISPLAY_CHDEV )
243    {
244        chdev_dir_display();
245    }
[445]246    ////////////////////////////////
247    else if( type == DISPLAY_DQDT )
248    {
249        dqdt_display();
250    }
[440]251    ////
[433]252    else 
253    {
[440]254
255#if DEBUG_SYSCALLS_ERROR
256printk("\n[ERROR] in %s : undefined display type %x / thread %x / process %x\n",
257        __FUNCTION__ , type , this->trdid , process->pid );
258#endif
259        this->errno = EINVAL;
[433]260        return -1;
261    }
[421]262
[438]263#if DEBUG_SYS_DISPLAY
[433]264tm_end = hal_get_cycles();
[438]265if( DEBUG_SYS_DISPLAY < tm_end )
[433]266printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
[436]267__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
[433]268#endif
269
270    return 0;
271
272}  // end sys_display()
Note: See TracBrowser for help on using the repository browser.