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

Last change on this file since 441 was 440, checked in by alain, 6 years ago

1/ Fix a bug in the Multithreaded "sort" applicationr:
The pthread_create() arguments must be declared as global variables.
2/ The exit syscall can be called by any thread of a process..

File size: 6.2 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
24#include <hal_types.h>
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>
[421]32
33
34/////////////////////////////
35int sys_display( reg_t  type,
36                 reg_t  arg0,
37                 reg_t  arg1 )
38{
[433]39
[440]40    error_t     error;
41    vseg_t    * vseg;
42
43    thread_t  * this    = CURRENT_THREAD;
44    process_t * process = this->process;
45
[438]46#if DEBUG_SYS_DISPLAY
[433]47uint64_t    tm_start;
48uint64_t    tm_end;
49tm_start = hal_get_cycles();
[438]50if( DEBUG_SYS_DISPLAY < tm_start )
[436]51printk("\n[DBG] %s : thread %d enter / process %x / type  %d / cycle = %d\n",
52__FUNCTION__, this, this->process->pid, type, (uint32_t)tm_start );
[433]53#endif
54
[440]55    ////////////////////////////
[421]56    if( type == DISPLAY_STRING )
57    {
58        char      kbuf[256];
[433]59        uint32_t  length;
[421]60
61        char    * string = (char *)arg0;
[440]62
[421]63        // check string in user space
[440]64        error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
65
66        if( error )
[433]67        {
[440]68
69#if DEBUG_SYSCALLS_ERROR
70printk("\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;
[433]74            return -1;
75        }
[421]76
77        // ckeck string length
[433]78        length = hal_strlen_from_uspace( string );
[440]79
[433]80        if( length >= 256 )
81        {
[440]82
83#if DEBUG_SYSCALLS_ERROR
84printk("\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;
[433]88            return -1;
89        }
[421]90
[440]91        // copy string to kernel space
[421]92        hal_strcpy_from_uspace( kbuf , string , 256 );
93
94        // print message on TXT0 kernel terminal
[440]95        printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
[421]96    }
[440]97    //////////////////////////////
[421]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
[433]105            if( process_xp == XPTR_NULL )
106        {
[440]107
108#if DEBUG_SYSCALLS_ERROR
109printk("\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;
[433]113            return -1;
114        }
[421]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    }
[440]130    ////////////////////////////////
[421]131    else if( type == DISPLAY_SCHED )
132    {
133        cxy_t cxy = (cxy_t)arg0;
134        lid_t lid = (lid_t)arg1;
135
[440]136        // check cxy argument
[433]137            if( cluster_is_undefined( cxy ) ) 
138        {
[440]139
140#if DEBUG_SYSCALLS_ERROR
141printk("\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;
[433]145            return -1;
146        }
[421]147
[440]148        // check lid argument
[433]149        if( lid >= LOCAL_CLUSTER->cores_nr )
150        {
[440]151
152#if DEBUG_SYSCALLS_ERROR
153printk("\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;
[433]157            return -1;
158        }
[421]159
160        if( cxy == local_cxy )
161        {
162                sched_display( lid );
163        }
164        else
165        {
166            rpc_sched_display_client( cxy , lid );
167        }
168    }
[440]169    ////////////////////////////////////////////
[435]170    else if( type == DISPLAY_CLUSTER_PROCESSES )
[421]171    {
172        cxy_t cxy = (cxy_t)arg0;
173
[440]174        // check cxy argument
[433]175            if( cluster_is_undefined( cxy ) )
176        {
[440]177
178#if DEBUG_SYSCALLS_ERROR
179printk("\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;
[433]183            return -1;
184        }
[421]185
186        cluster_processes_display( cxy );
187    }
[440]188    ////////////////////////////////////////
[435]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        {
[440]196
197#if DEBUG_SYSCALLS_ERROR
198printk("\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;
[435]202            return -1;
203        }
204
205        process_txt_display( txt_id );
206    }
[440]207    //////////////////////////////
[421]208    else if( type == DISPLAY_VFS )
209    {
210        vfs_display( process->vfs_root_xp );
211    }
[440]212    ////////////////////////////////
[421]213    else if( type == DISPLAY_CHDEV )
214    {
215        chdev_dir_display();
216    }
[440]217    ////
[433]218    else 
219    {
[440]220
221#if DEBUG_SYSCALLS_ERROR
222printk("\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;
[433]226        return -1;
227    }
[421]228
[438]229#if DEBUG_SYS_DISPLAY
[433]230tm_end = hal_get_cycles();
[438]231if( DEBUG_SYS_DISPLAY < tm_end )
[433]232printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
[436]233__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
[433]234#endif
235
236    return 0;
237
238}  // end sys_display()
Note: See TracBrowser for help on using the repository browser.