3 Copyright (c) 2004 - 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Since the SEC is the only program in our emulation we
19 must use a Tiano mechanism to export APIs to other modules.
20 This is the role of the EFI_UNIX_THUNK_PROTOCOL.
22 The mUnixThunkTable exists so that a change to EFI_UNIX_THUNK_PROTOCOL
23 will cause an error in initializing the array if all the member functions
24 are not added. It looks like adding a element to end and not initializing
25 it may cause the table to be initaliized with the members at the end being
26 set to zero. This is bad as jumping to zero will crash.
29 gUnix is a a public exported global that contains the initialized
35 #include "Library/UnixLib.h"
42 #include <sys/ioctl.h>
43 static int settimer_initialized
;
44 static struct timeval settimer_timeval
;
45 static void (*settimer_callback
)(UINT64 delta
);
48 settimer_handler (int sig
)
50 struct timeval timeval
;
53 gettimeofday (&timeval
, NULL
);
54 delta
= ((UINT64
)timeval
.tv_sec
* 1000) + (timeval
.tv_usec
/ 1000)
55 - ((UINT64
)settimer_timeval
.tv_sec
* 1000)
56 - (settimer_timeval
.tv_usec
/ 1000);
57 settimer_timeval
= timeval
;
58 if (settimer_callback
)
59 (*settimer_callback
)(delta
);
64 SetTimer (UINT64 PeriodMs
, VOID (*CallBack
)(UINT64 DeltaMs
))
66 struct itimerval timerval
;
68 if (!settimer_initialized
) {
71 settimer_initialized
= 1;
72 act
.sa_handler
= settimer_handler
;
74 sigemptyset (&act
.sa_mask
);
75 if (sigaction (SIGALRM
, &act
, NULL
) != 0) {
76 printf ("SetTimer: sigaction error %s\n", strerror (errno
));
78 if (gettimeofday (&settimer_timeval
, NULL
) != 0) {
79 printf ("SetTimer: gettimeofday error %s\n", strerror (errno
));
82 timerval
.it_value
.tv_sec
= PeriodMs
/ 1000;
83 timerval
.it_value
.tv_usec
= (PeriodMs
% 1000) * 1000;
84 timerval
.it_value
.tv_sec
= PeriodMs
/ 1000;
85 timerval
.it_interval
= timerval
.it_value
;
87 if (setitimer (ITIMER_REAL
, &timerval
, NULL
) != 0) {
88 printf ("SetTimer: setitimer error %s\n", strerror (errno
));
90 settimer_callback
= CallBack
;
94 msSleep (unsigned long Milliseconds
)
98 ts
.tv_sec
= Milliseconds
/ 1000;
99 ts
.tv_nsec
= (Milliseconds
% 1000) * 1000000;
101 while (nanosleep (&ts
, &ts
) != 0 && errno
== EINTR
)
106 GetLocalTime (EFI_TIME
*Time
)
114 Time
->Year
= 1900 + tm
->tm_year
;
115 Time
->Month
= tm
->tm_mon
;
116 Time
->Day
= tm
->tm_mday
;
117 Time
->Hour
= tm
->tm_hour
;
118 Time
->Minute
= tm
->tm_min
;
119 Time
->Second
= tm
->tm_sec
;
120 Time
->Nanosecond
= 0;
121 Time
->TimeZone
= timezone
;
122 Time
->Daylight
= (daylight
? EFI_TIME_ADJUST_DAYLIGHT
: 0)
123 | (tm
->tm_isdst
> 0 ? EFI_TIME_IN_DAYLIGHT
: 0);
157 UgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL
**UgaIo
, CONST CHAR16
*Title
);
159 EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable
= {
160 EFI_UNIX_THUNK_PROTOCOL_SIGNATURE
,
203 EFI_UNIX_THUNK_PROTOCOL
*gUnix
= &mUnixThunkTable
;