source: trunk/libs/newlib/src/libgloss/moxie/sim-time.c @ 520

Last change on this file since 520 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.6 KB
Line 
1/* sim-time.c -- stubs so clock can be linked in.
2 *
3 * Copyright (c) 2008 Anthony Green
4 *
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
13 * they apply.
14 */
15#include <errno.h>
16#include <sys/time.h>
17#include <sys/times.h>
18#include "glue.h"
19
20/*
21 * time -- simulator interface to return current time in seconds.
22 */
23__asm__ ("\
24        .text\n\
25        .globl  _sim_time\n\
26        .type   _sim_time,@function\n\
27_sim_time:\n\
28        jmpa _sim_time\n\
29        ret\n\
30.Lsim:\n\
31        .size   _sim_time,.Lsim-_sim_time");
32
33extern time_t _sim_time (void) __asm__("_sim_time");
34
35
36/*
37 * time -- return current time in seconds.
38 */
39time_t
40time (time_t *t)
41{
42  time_t ret = _sim_time ();
43
44  if (t)
45    *t = ret;
46
47  return ret;
48}
49
50/*
51 * _times -- no clock, so return an error.
52 */
53int
54_times (struct tms *buf)
55{
56  errno = EINVAL;
57  return (-1);
58}
59
60/*
61 * _gettimeofday -- implement in terms of time, which means we can't return the
62 * microseconds.
63 */
64int
65_gettimeofday (struct timeval *tv,
66        void *tzvp)
67{
68  struct timezone *tz = tzvp;
69  if (tz)
70    tz->tz_minuteswest = tz->tz_dsttime = 0;
71
72  tv->tv_usec = 0;
73  tv->tv_sec = _sim_time ();
74  return 0;
75}
Note: See TracBrowser for help on using the repository browser.