/uspace/trunk/ns/ns.c |
---|
40,6 → 40,9 |
#include <assert.h> |
#include <libadt/list.h> |
#include <libadt/hash_table.h> |
#include <sysinfo.h> |
#include <ddi.h> |
#include <as.h> |
#define NAME "NS" |
73,6 → 76,28 |
int static ping_phone; |
static void get_realtime_as(ipc_callid_t callid, ipc_call_t *call) |
{ |
static void *addr = NULL; |
void *ph_addr; |
if (IPC_GET_ARG3(*call) != (AS_AREA_READ | AS_AREA_CACHEABLE)) { |
ipc_answer_fast(callid, EPERM, 0, 0); |
return; |
} |
if (!addr) { |
ph_addr = (void *)sysinfo_value("clock.faddr"); |
if (!ph_addr) { |
ipc_answer_fast(callid, ENOENT, 0, 0); |
return; |
} |
addr = (void *)(200*1024*1024); /* TODO: intelligent freemem space */ |
map_physmem(task_get_id(), ph_addr, addr, 1, |
AS_AREA_READ | AS_AREA_CACHEABLE); |
} |
ipc_answer_fast(callid, 0, (ipcarg_t)addr, 0); |
} |
int main(int argc, char **argv) |
{ |
ipc_call_t call; |
102,12 → 127,12 |
} else |
// printf("Failed answer: %d\n", retval); |
continue; |
break; |
case IPC_M_AS_AREA_RECV: |
get_realtime_as(callid, &call); |
continue; |
case IPC_M_INTERRUPT: |
// printf("GOT INTERRUPT: %c\n", IPC_GET_ARG2(call)); |
break; |
case IPC_M_PHONE_HUNGUP: |
// printf("Phone hung up.\n"); |
retval = 0; |
break; |
case IPC_M_CONNECT_TO_ME: |
/uspace/trunk/init/init.c |
---|
44,6 → 44,7 |
#include <kbd.h> |
#include <ipc/fb.h> |
#include <async.h> |
#include <time.h> |
int a; |
atomic_t ftx; |
401,7 → 402,19 |
ipc_hangup(phoneid); |
} |
static void test_time(void) |
{ |
int rc; |
struct timeval tv; |
struct timezone tz; |
while (1) { |
rc = gettimeofday(&tv, &tz); |
printf("Rc: %d, Secs: %d, Usecs: %d\n", rc, tv.tv_sec, |
tv.tv_usec); |
} |
} |
int main(int argc, char *argv[]) |
{ |
pstid_t ptid; |
420,7 → 433,8 |
// test_as_area_send(); |
// test_pci(); |
// test_kbd(); |
test_async_kbd(); |
test_time(); |
// test_async_kbd(); |
// test_fb(); |
printf("Hello\nThis is Init\n\nBye."); |
/uspace/trunk/libc/include/time.h |
---|
0,0 → 1,51 |
/* |
* Copyright (C) 2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __libc_TIME_H__ |
#define __libc_TIME_H__ |
#include <types.h> |
#define DST_NONE 0 |
typedef sysarg_t time_t; |
typedef sysarg_t suseconds_t; |
struct timeval { |
time_t tv_sec; /* seconds */ |
suseconds_t tv_usec; /* microseconds */ |
}; |
struct timezone { |
int tz_minuteswest; /* minutes W of Greenwich */ |
int tz_dsttime; /* type of dst correction */ |
}; |
int gettimeofday(struct timeval *tv, struct timezone *tz); |
#endif |
/uspace/trunk/libc/include/ipc/services.h |
---|
37,6 → 37,9 |
#define SERVICE_PCI 1 |
#define SERVICE_FRAME_BUFFER 2 |
#define SERVICE_KEYBOARD 3 |
#define SERVICE_VIDEO 4 |
#define SERVICE_VIDEO 4 |
/* Memory area to be received from NS */ |
#define SERVICE_MEM_REALTIME 1 |
#endif |
/uspace/trunk/libc/generic/time.c |
---|
0,0 → 1,96 |
/* |
* Copyright (C) 2006 Ondrej Palkovsky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#include <time.h> |
#include <unistd.h> |
#include <ipc/ipc.h> |
#include <stdio.h> |
#include <arch/barrier.h> |
#include <sysinfo.h> |
#include <as.h> |
#include <ddi.h> |
/* Pointers to public variables with time */ |
struct { |
volatile sysarg_t seconds; |
volatile sysarg_t useconds; |
volatile sysarg_t useconds2; |
} *ktime = NULL; |
/** POSIX gettimeofday |
* |
* The time variables are memory mapped(RO) from kernel, which updates |
* them periodically. As it is impossible to read 2 values atomically, we |
* use a trick: First read a seconds, then read microseconds, then |
* read seconds again. If a second elapsed in the meantime, read |
* useconds again. This provides assurance, that at least the |
* sequence of subsequent gettimeofday calls is ordered. |
*/ |
#define TMAREA (100*1024*1024) |
int gettimeofday(struct timeval *tv, struct timezone *tz) |
{ |
void *mapping; |
sysarg_t seconds,useconds; |
sysarg_t t1; |
int res; |
if (!ktime) { |
/* TODO: specify better, where to map the area */ |
/* Get the mapping of kernel clock */ |
res = ipc_call_sync_3(PHONE_NS, IPC_M_AS_AREA_RECV, |
TMAREA, |
PAGE_SIZE, |
AS_AREA_READ | AS_AREA_CACHEABLE, |
&t1,&t1,&t1); |
if (res) { |
printf("Failed to initialize timeofday memarea\n"); |
_exit(1); |
} |
ktime = (void *) (TMAREA); |
} |
tz->tz_minuteswest = 0; |
tz->tz_dsttime = DST_NONE; |
retry: |
seconds = ktime->seconds; |
read_barrier(); |
tv->tv_usec = ktime->useconds; |
read_barrier(); |
tv->tv_sec = ktime->seconds; |
if (tv->tv_usec == 0 && seconds == tv->tv_sec && |
ktime->useconds2 != 0) { |
read_barrier(); |
goto retry; |
} |
if (seconds != tv->tv_sec) |
tv->tv_usec = ktime->useconds; |
return 0; |
} |
/uspace/trunk/libc/generic/async.c |
---|
331,6 → 331,7 |
{ |
ipc_call_t call; |
ipc_callid_t callid; |
int timeout; |
while (1) { |
if (psthread_schedule_next_adv(PS_FROM_MANAGER)) { |
339,8 → 340,19 |
*/ |
continue; |
} |
callid = ipc_wait_cycle(&call,SYNCH_NO_TIMEOUT,SYNCH_BLOCKING); |
/* |
if (expires) |
timeout = .... ; |
else |
*/ |
timeout = SYNCH_NO_TIMEOUT; |
callid = ipc_wait_cycle(&call, timeout, SYNCH_BLOCKING); |
if (!callid) { |
// handle_expired_timeouts.......; |
continue; |
} |
if (callid & IPC_CALLID_ANSWERED) |
continue; |
404,7 → 416,8 |
*/ |
if (msg->dataptr) |
*msg->dataptr = *data; |
/* TODO: memory barrier?? */ |
msg->done = 1; |
if (! msg->active) { |
msg->active = 1; |
460,3 → 473,38 |
*retval = msg->retval; |
free(msg); |
} |
/* int async_wait_timeout(aid_t amsgid, ipcarg_t *retval, int timeout) */ |
/* { */ |
/* amsg_t *msg = (amsg_t *) amsgid; */ |
/* connection_t *conn; */ |
/* futex_down(&async_futex); */ |
/* if (msg->done) { */ |
/* futex_up(&async_futex); */ |
/* goto done; */ |
/* } */ |
/* msg->ptid = psthread_get_id(); */ |
/* msg->active = 0; */ |
/* msg->expires = gettime() + timeout; */ |
/* setup_timeouts_etc...(); */ |
/* /\* Leave locked async_futex when entering this function *\/ */ |
/* psthread_schedule_next_adv(PS_TO_MANAGER); */ |
/* /\* futex is up automatically after psthread_schedule_next...*\/ */ |
/* if (!msg->done) */ |
/* return casy-casy; */ |
/* /\* TODO: When memory barrier in reply_received, we can skip this *\/ */ |
/* futex_down(&async_futex); */ |
/* futex_up(&async_futex); */ |
/* done: */ |
/* if (retval) */ |
/* *retval = msg->retval; */ |
/* free(msg); */ |
/* } */ |
/uspace/trunk/libc/Makefile |
---|
65,7 → 65,8 |
generic/ipc.c \ |
generic/async.c \ |
generic/libadt/list.o \ |
generic/libadt/hash_table.o |
generic/libadt/hash_table.o \ |
generic/time.c |
ARCH_SOURCES += \ |
arch/$(ARCH)/src/entry.s \ |