From ed6b39346e09f6ba5d8a2102e93247bc0407b0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 11 May 2003 05:44:12 +0000 Subject: [PATCH] Added dumb implementations for system_time() and TLS: system_time() currently just returns the contents of the time base register, and the TLS implementation is only working correctly for single threaded applications. Enough for testing, at least. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3202 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/arch/ppc/Jamfile | 7 ++- src/kernel/libroot/os/arch/ppc/system_time.S | 26 ++++++++++ src/kernel/libroot/os/arch/ppc/tls.c | 53 ++++++++++++++++++++ 3 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 src/kernel/libroot/os/arch/ppc/system_time.S create mode 100644 src/kernel/libroot/os/arch/ppc/tls.c diff --git a/src/kernel/libroot/os/arch/ppc/Jamfile b/src/kernel/libroot/os/arch/ppc/Jamfile index 380fead788..22b8776be3 100644 --- a/src/kernel/libroot/os/arch/ppc/Jamfile +++ b/src/kernel/libroot/os/arch/ppc/Jamfile @@ -2,15 +2,14 @@ SubDir OBOS_TOP src kernel libroot os arch ppc ; KernelMergeObject os_arch_$(OBOS_ARCH).o : <$(SOURCE_GRIST)>atomic.S -# <$(SOURCE_GRIST)>cpuid.S # <$(SOURCE_GRIST)>systeminfo.c -# <$(SOURCE_GRIST)>thread.c -# <$(SOURCE_GRIST)>tls.c + <$(SOURCE_GRIST)>system_time.S + <$(SOURCE_GRIST)>tls.c : -fPIC -DPIC ; MergeObjectFromObjects kernel_os_arch_$(OBOS_ARCH).o : <$(SOURCE_GRIST)>atomic.o - #<$(SOURCE_GRIST)>cpuid.o + <$(SOURCE_GRIST)>system_time.S ; diff --git a/src/kernel/libroot/os/arch/ppc/system_time.S b/src/kernel/libroot/os/arch/ppc/system_time.S new file mode 100644 index 0000000000..16d0d80074 --- /dev/null +++ b/src/kernel/libroot/os/arch/ppc/system_time.S @@ -0,0 +1,26 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + +#define FUNCTION(x) .global x; .type x,@function; x + +.text + +// ToDo: note, this function absolutely doesn't do what it should do. +// It only reads out the time base register, but it doesn't compute +// the real system time from its value. +// To do so, the kernel has to provide the appropriate system dependent +// conversion factors. + +/* uint64 system_time(void) + * r3/r4 + */ +FUNCTION(system_time): +carry: mftbu %r3 + mftb %r4 + mftbu %r5 // read the upper half again + cmpw %r3, %r5 // and check if the values have changed + bne carry // try again, if they had + blr + diff --git a/src/kernel/libroot/os/arch/ppc/tls.c b/src/kernel/libroot/os/arch/ppc/tls.c new file mode 100644 index 0000000000..4ffd760532 --- /dev/null +++ b/src/kernel/libroot/os/arch/ppc/tls.c @@ -0,0 +1,53 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + +// ToDo: this is a dummy implementation - I've not yet gained enough knowledge +// to decide how this should be done, so it's just broken now (okay for single +// threaded apps, though). + +// we don't want to have the inline assembly included here +#ifndef _NO_INLINE_ASM +# define _NO_INLINE_ASM 1 +#endif + +#include "support/TLS.h" +#include "tls.h" + + +static int32 gNextSlot = TLS_FIRST_FREE_SLOT; +static void *gSlots[TLS_MAX_KEYS]; + + +int32 +tls_allocate(void) +{ + int32 next = atomic_add(&gNextSlot, 1); + if (next >= TLS_MAX_KEYS) + return B_NO_MEMORY; + + return next; +} + + +void * +tls_get(int32 index) +{ + return gSlots[index]; +} + + +void ** +tls_address(int32 index) +{ + return &gSlots[index]; +} + + +void +tls_set(int32 index, void *value) +{ + gSlots[index] = value; +} +