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

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

blip

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