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

Last change on this file since 436 was 436, checked in by alain, 4 years ago

1) improve the threads and process destruction mechanism.
2) introduce FIFOs in the soclib_tty driver.

File size: 5.2 KB
Line 
1/*
2 * sys_display.c - display the current state of a kernel structure on TXT0
3 *
4 * Author    Alain Greiner (2016,2017)
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>
27#include <vmm.h>
28#include <cluster.h>
29#include <thread.h>
30#include <process.h>
31#include <string.h>
32
33
34/////////////////////////////
35int sys_display( reg_t  type,
36                 reg_t  arg0,
37                 reg_t  arg1 )
38{
39
40#if CONFIG_DEBUG_SYS_DISPLAY
41uint64_t    tm_start;
42uint64_t    tm_end;
43thread_t  * this;
44this     = CURRENT_THREAD;
45tm_start = hal_get_cycles();
46if( CONFIG_DEBUG_SYS_DISPLAY < tm_start )
47printk("\n[DBG] %s : thread %d enter / process %x / type  %d / cycle = %d\n",
48__FUNCTION__, this, this->process->pid, type, (uint32_t)tm_start );
49#endif
50
51    if( type == DISPLAY_STRING )
52    {
53        paddr_t   paddr;
54        char      kbuf[256];
55        uint32_t  length;
56
57        char    * string = (char *)arg0;
58 
59        // check string in user space
60        if( vmm_v2p_translate( false , string , &paddr ) )
61        {
62            printk("\n[ERROR] in %s : string buffer %x unmapped\n",
63            __FUNCTION__ , string );
64            return -1;
65        }
66
67        // ckeck string length
68        length = hal_strlen_from_uspace( string );
69        if( length >= 256 )
70        {
71            printk("\n[ERROR] in %s : string length %d too large\n",
72            __FUNCTION__ , length );
73            return -1;
74        }
75
76        // copy string in kernel space
77        hal_strcpy_from_uspace( kbuf , string , 256 );
78
79        // print message on TXT0 kernel terminal
80        printk("\n[USER] %s / cycle %d\n", kbuf, (uint32_t)hal_get_cycles() );
81    }
82    else if( type == DISPLAY_VMM )
83    {
84        pid_t pid = (pid_t)arg0;
85
86        // get extended pointer on reference process
87        xptr_t process_xp = cluster_get_reference_process_from_pid( pid );
88
89            if( process_xp == XPTR_NULL )
90        {
91            printk("\n[ERROR] in %s : undefined PID %x\n",
92            __FUNCTION__ , pid );
93            return -1;
94        }
95
96        // get cluster and local pointer on process
97        cxy_t       process_cxy = GET_CXY( process_xp );
98        process_t * process_ptr = (process_t *)GET_PTR( process_xp );
99
100        // call kernel function
101        if( process_cxy == local_cxy )
102        {
103                vmm_display( process_ptr , true );
104        }
105        else
106        {
107            rpc_vmm_display_client( process_cxy , process_ptr , true );
108        }
109    }
110    else if( type == DISPLAY_SCHED )
111    {
112        cxy_t cxy = (cxy_t)arg0;
113        lid_t lid = (lid_t)arg1;
114
115        // check cluster argument
116            if( cluster_is_undefined( cxy ) ) 
117        {
118            printk("\n[ERROR] in %s : undefined cluster identifier %x\n",
119            __FUNCTION__ , cxy );
120            return -1;
121        }
122
123        // check core argument
124        if( lid >= LOCAL_CLUSTER->cores_nr )
125        {
126            printk("\n[ERROR] in %s : undefined local index %d\n",
127            __FUNCTION__ , lid );
128            return -1;
129        }
130
131        if( cxy == local_cxy )
132        {
133                sched_display( lid );
134        }
135        else
136        {
137            rpc_sched_display_client( cxy , lid );
138        }
139    }
140    else if( type == DISPLAY_CLUSTER_PROCESSES )
141    {
142        cxy_t cxy = (cxy_t)arg0;
143
144        // check cluster argument
145            if( cluster_is_undefined( cxy ) )
146        {
147            printk("\n[ERROR] in %s : undefined cluster identifier %x\n",
148            __FUNCTION__ , cxy );
149            return -1;
150        }
151
152        cluster_processes_display( cxy );
153    }
154    else if( type == DISPLAY_TXT_PROCESSES )
155    {
156        uint32_t txt_id = (uint32_t)arg0;
157
158        // check argument
159            if( txt_id >= LOCAL_CLUSTER->nb_txt_channels )
160        {
161            printk("\n[ERROR] in %s : undefined TXT channel %x\n",
162            __FUNCTION__ , txt_id );
163            return -1;
164        }
165
166        process_txt_display( txt_id );
167    }
168    else if( type == DISPLAY_VFS )
169    {
170        // call kernel function
171        process_t * process = CURRENT_THREAD->process;
172        vfs_display( process->vfs_root_xp );
173    }
174    else if( type == DISPLAY_CHDEV )
175    {
176        chdev_dir_display();
177    }
178    else 
179    {
180        printk("\n[ERROR] in %s : undefined display type %x\n",
181        __FUNCTION__ , type );
182        return -1;
183    }
184
185#if CONFIG_DEBUG_SYS_DISPLAY
186tm_end = hal_get_cycles();
187if( CONFIG_DEBUG_SYS_DISPLAY < tm_end )
188printk("\n[DBG] %s : thread %x exit / process %x / cost = %d / cycle %d\n",
189__FUNCTION__, this, this->process->pid, (uint32_t)(tm_end - tm_start) , (uint32_t)tm_end );
190#endif
191
192    return 0;
193
194}  // end sys_display()
Note: See TracBrowser for help on using the repository browser.