From: darcagn <da...@us...> - 2024-08-28 01:05:11
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 698c12cc65d16dee55ed5b6106767bdea2e1056c (commit) via bedf52662a10f267a422d1227d178e8972cd38e4 (commit) from 715eb80e6e0ca1edf343b0fecee3275a67a5fab3 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 698c12cc65d16dee55ed5b6106767bdea2e1056c Author: Andy Barajas <and...@gm...> Date: Tue Aug 27 18:04:21 2024 -0700 Fix incorrect file handle checks (#730) commit bedf52662a10f267a422d1227d178e8972cd38e4 Author: Falco Girgis <gyr...@gm...> Date: Tue Aug 27 11:43:10 2024 -0500 Added POSIX settimeofday() (#661) * Added settimeofday() POSIX funtion from sys/time.h - Newlib declares this function for us but never bothers to defined it for our target. - It can be defined trivially by just forwarding the call to clock_settime() and converting usecs to nsecs. - Made rtc_set_unix_sets() return standard POSIX codes, so that clock_settime() and settimeofday() can simply forward the call and have errno set automatically from the RTC driver (which now has errno support) * updated documentation. ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/libdream/cdfs/cdfs.c | 4 ++-- kernel/arch/dreamcast/include/arch/rtc.h | 34 +++++++++++++++++++------------- kernel/arch/dreamcast/kernel/rtc.c | 10 ++++++++-- kernel/libc/posix/Makefile | 2 +- kernel/libc/posix/settimeofday.c | 24 ++++++++++++++++++++++ 5 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 kernel/libc/posix/settimeofday.c diff --git a/examples/dreamcast/libdream/cdfs/cdfs.c b/examples/dreamcast/libdream/cdfs/cdfs.c index a482a286..33e3b43c 100644 --- a/examples/dreamcast/libdream/cdfs/cdfs.c +++ b/examples/dreamcast/libdream/cdfs/cdfs.c @@ -16,7 +16,7 @@ void cdfs_test(void) { /* Read and print the root directory */ d = fs_open("/cd", O_RDONLY | O_DIR); - if(d == 0) { + if(d < 0) { printf("Can't open root!\r\n"); return; } @@ -37,7 +37,7 @@ void cdfs_test(void) { /* Read and print a file called README.TXT (if any) */ fd = fs_open("/cd/readme.txt", O_RDONLY); - if(fd == 0) { + if(fd < 0) { printf("Can't open file README.TXT for reading.\r\n"); return; } diff --git a/kernel/arch/dreamcast/include/arch/rtc.h b/kernel/arch/dreamcast/include/arch/rtc.h index 4042a08a..ccbe294d 100644 --- a/kernel/arch/dreamcast/include/arch/rtc.h +++ b/kernel/arch/dreamcast/include/arch/rtc.h @@ -1,8 +1,8 @@ /* KallistiOS ##version## arch/dreamcast/include/rtc.h - Copyright (C) 2000-2001 Megan Potter - Copyright (C) 2023 Falco Girgis + Copyright (C) 2000, 2001 Megan Potter + Copyright (C) 2023, 2024 Falco Girgis */ @@ -57,11 +57,12 @@ __BEGIN_DECLS Y2K and the last timestamp it can represent before rolling over is February 06 2086 06:28:15. - \sa wdt + \sa wdt, timers, perf_counters + + @{ */ /** \brief Get the current date/time. - \ingroup rtc This function retrieves the current RTC value as a standard UNIX timestamp (with an epoch of January 1, 1970 00:00). This is assumed to be in the @@ -69,12 +70,11 @@ __BEGIN_DECLS \return The current UNIX-style timestamp (local time). - \sa rtc_set_unix_secs(), rtc_boot_time() + \sa rtc_set_unix_secs() */ time_t rtc_unix_secs(void); /** \brief Set the current date/time. - \ingroup rtc This function sets the current RTC value as a standard UNIX timestamp (with an epoch of January 1, 1970 00:00). This is assumed to be in the @@ -85,32 +85,38 @@ time_t rtc_unix_secs(void); uses a 32-bit timestamp (which also has a different epoch), not all `time_t` values can be represented within the RTC! - \param time Unix timestamp to set the current time to + \param time Unix timestamp to set the current time to + + \return 0 for success or -1 for failure (with errno set + appropriately). - \return 0 for success or -1 for failure + \exception EINVAL \p time was an invalid timestamp or could not be + represented on the AICA's RTC. + \exception EPERM Failed to set and successfully read back \p time + from the RTC. \sa rtc_unix_secs() */ int rtc_set_unix_secs(time_t time); /** \brief Get the time since the system was booted. - \ingroup rtc - This function retrieves the cached RTC value from when KallistiOS was started. As - with rtc_unix_secs(), this is a UNIX-style timestamp in local time. + This function retrieves the cached RTC value from when KallistiOS was + started. As with rtc_unix_secs(), this is a UNIX-style timestamp in + local time. \return The boot time as a UNIX-style timestamp. - - \sa rtc_unix_secs() */ time_t rtc_boot_time(void); -/* \cond */ +/* \cond INTERNAL */ /* Internally called Init / Shutdown */ int rtc_init(void); void rtc_shutdown(void); /* \endcond */ +/** @} */ + __END_DECLS #endif /* __ARCH_RTC_H */ diff --git a/kernel/arch/dreamcast/kernel/rtc.c b/kernel/arch/dreamcast/kernel/rtc.c index d18c8f18..d6d71d18 100644 --- a/kernel/arch/dreamcast/kernel/rtc.c +++ b/kernel/arch/dreamcast/kernel/rtc.c @@ -28,8 +28,10 @@ #include <arch/rtc.h> #include <arch/timer.h> #include <dc/g2bus.h> + #include <stdint.h> #include <assert.h> +#include <errno.h> /* High 16-bit Timestamp Value @@ -125,8 +127,10 @@ int rtc_set_unix_secs(time_t secs) { const uint32_t adjusted = (const uint32_t)adjusted_time; /* Protect against underflowing or overflowing our 32-bit timestamp. */ - if(adjusted_time < 0 || adjusted_time > UINT32_MAX) + if(adjusted_time < 0 || adjusted_time > UINT32_MAX) { + errno = EINVAL; return -1; + } /* Enable writing by setting LSB of control */ g2_write_32(RTC_CTRL_ADDR, RTC_CTRL_WRITE_EN); @@ -151,8 +155,10 @@ int rtc_set_unix_secs(time_t secs) { /* Signify failure if the fetched time never matched the time we attempted to set. */ - if(i == RTC_RETRY_COUNT) + if(i == RTC_RETRY_COUNT) { + errno = EPERM; result = -1; + } /* We have to update the boot time now as well, subtracting the amount of time that has elapsed since boot from the diff --git a/kernel/libc/posix/Makefile b/kernel/libc/posix/Makefile index b38f6502..3b495f6a 100644 --- a/kernel/libc/posix/Makefile +++ b/kernel/libc/posix/Makefile @@ -11,6 +11,6 @@ # CFLAGS += -std=gnu11 -OBJS = posix_memalign.o clock_gettime.o sysconf.o +OBJS = posix_memalign.o clock_gettime.o settimeofday.o sysconf.o include $(KOS_BASE)/Makefile.prefab diff --git a/kernel/libc/posix/settimeofday.c b/kernel/libc/posix/settimeofday.c new file mode 100644 index 00000000..da4f5aa9 --- /dev/null +++ b/kernel/libc/posix/settimeofday.c @@ -0,0 +1,24 @@ +/* KallistiOS ##version## + + settimeofday.c + Copyright (C) 2024 Falco Girgis +*/ + +#include <time.h> +#include <sys/time.h> +#include <errno.h> + +int settimeofday(const struct timeval *tv, const struct timezone *tz) { + struct timespec tspec; + (void)tz; + + if(!tv) { + errno = EFAULT; + return -1; + } + + tspec.tv_sec = tv->tv_sec; + tspec.tv_nsec = tv->tv_usec * 1000; + + return clock_settime(CLOCK_REALTIME, &tspec); +} hooks/post-receive -- A pseudo Operating System for the Dreamcast. |