[1] | 1 | /* |
---|
[23] | 2 | * sys_gettimeofday.c - Get current time |
---|
[1] | 3 | * |
---|
[23] | 4 | * Author Alain Greiner (2016,2017) |
---|
[1] | 5 | * |
---|
[23] | 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 |
---|
[1] | 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 | * |
---|
[23] | 14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
[1] | 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 |
---|
[23] | 20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
[1] | 21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 22 | */ |
---|
| 23 | |
---|
[23] | 24 | #include <hal_types.h> |
---|
| 25 | #include <hal_uspace.h> |
---|
[1] | 26 | #include <thread.h> |
---|
[23] | 27 | #include <printk.h> |
---|
| 28 | #include <errno.h> |
---|
| 29 | #include <process.h> |
---|
| 30 | #include <vmm.h> |
---|
| 31 | #include <core.h> |
---|
[1] | 32 | #include <time.h> |
---|
| 33 | |
---|
[23] | 34 | /////////////////////////////////////////// |
---|
| 35 | int sys_gettimeofday( struct timeval * tv, |
---|
| 36 | struct timezone * tz ) |
---|
[1] | 37 | { |
---|
[23] | 38 | error_t error; |
---|
| 39 | paddr_t paddr; |
---|
[1] | 40 | |
---|
[23] | 41 | uint32_t tm_s; |
---|
| 42 | uint32_t tm_us; |
---|
[1] | 43 | |
---|
[23] | 44 | struct timeval k_tv; |
---|
[1] | 45 | |
---|
[23] | 46 | thread_t * this = CURRENT_THREAD; |
---|
| 47 | process_t * process = this->process; |
---|
[1] | 48 | |
---|
[23] | 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 ); |
---|
[1] | 60 | |
---|
[23] | 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 | } |
---|
[1] | 68 | |
---|
[23] | 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() |
---|