source: trunk/kernel/syscalls/sys_timeofday.c @ 65

Last change on this file since 65 was 50, checked in by alain, 7 years ago

bloup

File size: 2.2 KB
Line 
1/*
2 * sys_timeofday.c - Get current time
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 <thread.h>
27#include <printk.h>
28#include <errno.h>
29#include <process.h>
30#include <vmm.h>
31#include <core.h>
32#include <time.h>
33
34////////////////////////////////////////
35int sys_timeofday( struct timeval  * tv,
36                   struct timezone * tz )
37{
38        error_t        error;
39    paddr_t        paddr;
40
41        uint32_t       tm_s;
42    uint32_t       tm_us;
43
44        struct timeval k_tv;
45
46        thread_t  *    this    = CURRENT_THREAD;
47        process_t *    process = this->process;
48
49    // check tz (non supported / must be null)
50    if( tz )
51    {
52        printk("\n[ERROR] in %s for thread %x in process %x : tz argument must be NULL\n",
53               __FUNCTION__ , this->trdid , process->pid );
54        this->errno = EINVAL;
55        return -1;
56    }
57 
58    // check tv
59    error = vmm_v2p_translate( false , tv , &paddr );
60
61    if( error )
62    {
63        printk("\n[ERROR] in %s for thread %x in process %x : tv argument unmapped\n",
64        __FUNCTION__ , this->trdid , process->pid );
65        this->errno = EINVAL;
66        return -1;
67    }
68
69    // get time from calling core descriptor
70    core_get_time( this->core , &tm_s , &tm_us );
71        k_tv.tv_sec  = tm_s;
72        k_tv.tv_usec = tm_us;
73
74    // copy values to user space
75        hal_copy_to_uspace( tv , &k_tv , sizeof(struct timeval) );
76
77    hal_wbflush();
78
79        return 0; 
80
81}  // end sys_timeofday()
Note: See TracBrowser for help on using the repository browser.