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

Last change on this file since 561 was 506, checked in by viala@…, 6 years ago

[syscalls] add interface in implementation.

Add const where possible, fix protoypes to follow interface.

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