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

Last change on this file since 483 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
Line 
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_kernel_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#include <shared_syscalls.h>
33
34/////////////////////////////////////////////////////////////////////////////////
35// This static function returns a printable string for the type of display.
36/////////////////////////////////////////////////////////////////////////////////
37
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
51/////////////////////////////
52int sys_display( reg_t  type,
53                 reg_t  arg0,
54                 reg_t  arg1 )
55{
56
57    error_t     error;
58    vseg_t    * vseg;
59
60    thread_t  * this    = CURRENT_THREAD;
61    process_t * process = this->process;
62
63#if DEBUG_SYS_DISPLAY
64uint64_t    tm_start;
65uint64_t    tm_end;
66tm_start = hal_get_cycles();
67if( DEBUG_SYS_DISPLAY < tm_start )
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 );
70#endif
71
72    ////////////////////////////
73    if( type == DISPLAY_STRING )
74    {
75        char      kbuf[256];
76        uint32_t  length;
77
78        char    * string = (char *)arg0;
79
80        // check string in user space
81        error = vmm_get_vseg( process , (intptr_t)arg0 , &vseg );
82
83        if( error )
84        {
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;
91            return -1;
92        }
93
94        // ckeck string length
95        length = hal_strlen_from_uspace( string );
96
97        if( length >= 256 )
98        {
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;
105            return -1;
106        }
107
108        // copy string to kernel space
109        hal_strcpy_from_uspace( kbuf , string , 256 );
110
111        // print message on TXT0 kernel terminal
112        printk("\n%s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
113    }
114    //////////////////////////////
115    else if( type == DISPLAY_VMM )
116    {
117        cxy_t cxy = (cxy_t)arg0;
118        pid_t pid = (pid_t)arg1;
119
120        // check cxy argument
121            if( cluster_is_undefined( cxy ) ) 
122        {
123
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
135            if( process_xp == XPTR_NULL )
136        {
137
138#if DEBUG_SYSCALLS_ERROR
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 );
141#endif
142            this->errno = EINVAL;
143            return -1;
144        }
145
146        // get local pointer on process
147        process_t * process = (process_t *)GET_PTR( process_xp );
148
149        // call kernel function
150        if( cxy == local_cxy )
151        {
152                vmm_display( process , true );
153        }
154        else
155        {
156            rpc_vmm_display_client( cxy , process , true );
157        }
158    }
159    ////////////////////////////////
160    else if( type == DISPLAY_SCHED )
161    {
162        cxy_t cxy = (cxy_t)arg0;
163        lid_t lid = (lid_t)arg1;
164
165        // check cxy argument
166            if( cluster_is_undefined( cxy ) ) 
167        {
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;
174            return -1;
175        }
176
177        // check lid argument
178        if( lid >= LOCAL_CLUSTER->cores_nr )
179        {
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;
186            return -1;
187        }
188
189        if( cxy == local_cxy )
190        {
191                sched_display( lid );
192        }
193        else
194        {
195            sched_remote_display( cxy , lid );
196        }
197    }
198    ////////////////////////////////////////////
199    else if( type == DISPLAY_CLUSTER_PROCESSES )
200    {
201        cxy_t cxy = (cxy_t)arg0;
202
203        // check cxy argument
204            if( cluster_is_undefined( cxy ) )
205        {
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;
212            return -1;
213        }
214
215        cluster_processes_display( cxy );
216    }
217    ////////////////////////////////////////
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        {
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;
231            return -1;
232        }
233
234        process_txt_display( txt_id );
235    }
236    //////////////////////////////
237    else if( type == DISPLAY_VFS )
238    {
239        vfs_display( process->vfs_root_xp );
240    }
241    ////////////////////////////////
242    else if( type == DISPLAY_CHDEV )
243    {
244        chdev_dir_display();
245    }
246    ////////////////////////////////
247    else if( type == DISPLAY_DQDT )
248    {
249        dqdt_display();
250    }
251    ////
252    else 
253    {
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;
260        return -1;
261    }
262
263#if DEBUG_SYS_DISPLAY
264tm_end = hal_get_cycles();
265if( DEBUG_SYS_DISPLAY < tm_end )
266printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
267__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
268#endif
269
270    return 0;
271
272}  // end sys_display()
Note: See TracBrowser for help on using the repository browser.