source: trunk/kernel/syscalls/sys_get_config.c @ 501

Last change on this file since 501 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: 3.4 KB
Line 
1/*
2 * sys_get_config.c - get hardware platform parameters.
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 <hal_special.h>
27#include <errno.h>
28#include <core.h>
29#include <thread.h>
30#include <process.h>
31#include <vmm.h>
32#include <printk.h>
33
34//////////////////////////////////////
35int sys_get_config( uint32_t * x_size,
36                    uint32_t * y_size,
37                    uint32_t * ncores )
38{
39        error_t    error;
40    vseg_t   * vseg;
41    uint32_t   k_x_size;
42    uint32_t   k_y_size;
43    uint32_t   k_ncores;
44
45    thread_t  * this    = CURRENT_THREAD;
46    process_t * process = this->process;
47
48#if DEBUG_SYS_GET_CONFIG
49uint64_t     tm_start;
50uint64_t     tm_end;
51tm_start = hal_get_cycles();
52if( DEBUG_SYS_GET_CONFIG < tm_start )
53printk("\n[DBG] %s : thread %x enter / process %x / cycle %d\n",
54__FUNCTION__, this, process->pid, (uint32_t)tm_start );
55#endif
56
57    // check x_size buffer in user space
58    error = vmm_get_vseg( process , (intptr_t)x_size  , &vseg );
59
60        if( error )
61        {
62
63#if DEBUG_SYSCALLS_ERROR
64printk("\n[ERROR] in %s : x_size buffer unmapped / thread %x / process %x\n",
65__FUNCTION__ , (intptr_t)x_size , this->trdid , process->pid );
66vmm_display( process , false );
67#endif
68        this->errno = EINVAL;
69                return -1;
70        }
71
72    // check y_size buffer in user space
73    error = vmm_get_vseg( process , (intptr_t)y_size  , &vseg );
74
75        if( error )
76        {
77
78#if DEBUG_SYSCALLS_ERROR
79printk("\n[ERROR] in %s : y_size buffer unmapped / thread %x / process %x\n",
80__FUNCTION__ , (intptr_t)y_size , this->trdid , process->pid );
81vmm_display( process , false );
82#endif
83        this->errno = EINVAL;
84                return -1;
85        }
86
87    // check ncores buffer in user space
88    error = vmm_get_vseg( process , (intptr_t)ncores  , &vseg );
89
90        if( error )
91        {
92
93#if DEBUG_SYSCALLS_ERROR
94printk("\n[ERROR] in %s : ncores buffer unmapped / thread %x / process %x\n",
95__FUNCTION__ , (intptr_t)ncores , this->trdid , process->pid );
96vmm_display( process , false );
97#endif
98        this->errno = EINVAL;
99                return -1;
100        }
101
102    // get parameters
103        k_x_size  = LOCAL_CLUSTER->x_size;
104        k_y_size  = LOCAL_CLUSTER->y_size;
105        k_ncores  = LOCAL_CLUSTER->cores_nr;
106
107    // copy to user space
108        hal_copy_to_uspace( x_size  , &k_x_size  , sizeof(uint32_t) );
109        hal_copy_to_uspace( y_size  , &k_y_size  , sizeof(uint32_t) );
110        hal_copy_to_uspace( ncores  , &k_ncores  , sizeof(uint32_t) );
111
112    hal_fence();
113
114#if DEBUG_SYS_GET_CONFIG
115tm_end = hal_get_cycles();
116if( DEBUG_SYS_GET_CONFIG < tm_end )
117printk("\n[DBG] %s : thread %x exit / process %x / cost %d / cycle %d\n",
118__FUNCTION__, this, process->pid, (uint32_t)(tm_end-tm_start), (uint32_t)tm_end );
119#endif
120
121        return 0; 
122
123}  // end sys_get_config()
Note: See TracBrowser for help on using the repository browser.