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

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