From 5563cc1c6bda21eb917f6bfd0c606e7f55f33eec Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Fri, 18 Apr 2008 01:03:39 +0100 Subject: [PATCH] Minor changes on sys_time A get/set flag determines whether to read or write time. --- src/generic/time.c | 41 ++++++++++++------- tasks/fs0/main.c | 10 +++++ tasks/libl4/include/l4lib/arch-arm/syscalls.h | 12 +++++- 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/generic/time.c b/src/generic/time.c index 46f1cdb..2e6db8d 100644 --- a/src/generic/time.c +++ b/src/generic/time.c @@ -76,28 +76,39 @@ void update_system_time(void) int sys_time(struct syscall_args *args) { struct time_info *ti = (struct time_info *)args->r0; + int set = (int)args->r1; int retries = 20; if (check_access((unsigned long)ti, sizeof(*ti), MAP_USR_RW_FLAGS) < 0) return -EINVAL; - while(retries > 0) { - systime.reader = 1; - memcpy(ti, &systime, sizeof(*ti)); - retries--; + /* Get time */ + if (!set) { + while(retries > 0) { + systime.reader = 1; + memcpy(ti, &systime, sizeof(*ti)); + retries--; - if (systime.reader) - break; + if (systime.reader) + break; + } + + /* + * No need to reset reader since it will be reset + * on next timer. If no retries return busy. + */ + if (!retries) + return -EBUSY; + else + return 0; + + /* Set */ + } else { + /* + * Setting the time not supported yet. + */ + return -ENOSYS; } - - /* - * No need to reset reader since it will be reset - * on next timer. If no retries return busy. - */ - if (!retries) - return -EBUSY; - else - return 0; } void update_process_times(void) diff --git a/tasks/fs0/main.c b/tasks/fs0/main.c index 155e858..bc087f3 100644 --- a/tasks/fs0/main.c +++ b/tasks/fs0/main.c @@ -99,12 +99,22 @@ void handle_fs_requests(void) void main(void) { + struct time_info ti; + printf("\n%s: Started with tid: %d\n", __TASKNAME__, self_tid()); initialise(); wait_pager(PAGER_TID); + if (l4_time(&ti, 0) < 0) { + printf("Reading the time has failed.\n"); + } else { + printf("Current time since system started: %u ticks, " + "%u seconds, %u minutes, %u hours, %llu days.\n", + ti.thz, ti.sec, ti.min, ti.hour, ti.day); + } + printf("%s: Listening requests.\n", __TASKNAME__); while (1) { handle_fs_requests(); diff --git a/tasks/libl4/include/l4lib/arch-arm/syscalls.h b/tasks/libl4/include/l4lib/arch-arm/syscalls.h index 05e645f..4155400 100644 --- a/tasks/libl4/include/l4lib/arch-arm/syscalls.h +++ b/tasks/libl4/include/l4lib/arch-arm/syscalls.h @@ -68,7 +68,17 @@ typedef int (*__l4_kmem_control_t)(unsigned long pfn, int npages, int grant); extern __l4_kmem_control_t __l4_kmem_control; int l4_kmem_control(unsigned long pfn, int npages, int grant); -typedef int (*__l4_time_t)(void *time_info, int set); +/* Represents time since epoch, a c0 specific structure. */ +struct time_info { + int reader; + u32 thz; /* Ticks in this hertz so far */ + u32 sec; + u32 min; + u32 hour; + u64 day; +}; + +typedef int (*__l4_time_t)(struct time_info *ti, int set); extern __l4_time_t __l4_time; int l4_time(void *time_info, int set);