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

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

Introduce sys_fg() , sys_display() , sys_wait() syscalls.

File size: 3.7 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 <cluster.h>
28#include <thread.h>
29#include <process.h>
30
31
32/////////////////////////////
33int sys_display( reg_t  type,
34                 reg_t  arg0,
35                 reg_t  arg1 )
36{
37    if( type == DISPLAY_STRING )
38    {
39        paddr_t   paddr;
40        char      kbuf[256];
41
42        char    * string = (char *)arg0;
43 
44        // check string in user space
45        if( vmm_v2p_translate( false , string , &paddr ) ) return -1;
46
47        // ckeck string length
48        if( hal_strlen_from_uspace( string ) >= 256 ) return -1;
49
50        // copy string in kernel space
51        hal_strcpy_from_uspace( kbuf , string , 256 );
52
53        // get thread, process and core
54        thread_t  * this    = CURRENT_THREAD;
55        process_t * process = this->process;
56        core_t    * core    = this->core;
57
58        // print message on TXT0 kernel terminal
59        printk("\n[USER] thread %x / process %x / core[%x,%d] / cycle %d\n       %s",
60        this->trdid , process->pid , local_cxy, core->lid ,
61        (uint32_t)hal_get_cycles() , kbuf );
62
63            return 0; 
64    }
65    else if( type == DISPLAY_VMM )
66    {
67        pid_t pid = (pid_t)arg0;
68
69        // get extended pointer on reference process
70        xptr_t process_xp = cluster_get_reference_process_from_pid( pid );
71
72            if( process_xp == XPTR_NULL ) return -1;
73
74        // get cluster and local pointer on process
75        cxy_t       process_cxy = GET_CXY( process_xp );
76        process_t * process_ptr = (process_t *)GET_PTR( process_xp );
77
78        // call kernel function
79        if( process_cxy == local_cxy )
80        {
81                vmm_display( process_ptr , true );
82        }
83        else
84        {
85            rpc_vmm_display_client( process_cxy , process_ptr , true );
86        }
87
88            return 0; 
89    }
90    else if( type == DISPLAY_SCHED )
91    {
92        cxy_t cxy = (cxy_t)arg0;
93        lid_t lid = (lid_t)arg1;
94
95        // check cluster argument
96            if( cluster_is_undefined( cxy ) ) return -1;
97
98        // check core argument
99        if( lid >= LOCAL_CLUSTER->cores_nr ) return -1;
100
101        // call kernel function
102        if( cxy == local_cxy )
103        {
104                sched_display( lid );
105        }
106        else
107        {
108            rpc_sched_display_client( cxy , lid );
109        }
110
111            return 0; 
112    }
113    else if( type == DISPLAY_PROCESS )
114    {
115        cxy_t cxy = (cxy_t)arg0;
116
117        // check cluster argument
118            if( cluster_is_undefined( cxy ) ) return -1;
119
120        // call kernel function
121        cluster_processes_display( cxy );
122
123        return 0;
124    }
125    else if( type == DISPLAY_VFS )
126    {
127        // call kernel function
128        process_t * process = CURRENT_THREAD->process;
129        vfs_display( process->vfs_root_xp );
130
131        return 0;
132    }
133    else if( type == DISPLAY_CHDEV )
134    {
135        // call kernel function
136        chdev_dir_display();
137
138        return 0;
139    }
140    else return -1;
141
142}  // end sys_get_sched()
Note: See TracBrowser for help on using the repository browser.