From 2d6ab447f95df0f3e235a6a570db8d6c0c2cf093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 7 Jan 2003 09:05:27 +0000 Subject: [PATCH] Moved arch-dependent stuff to the correct location, no more #if __INTEL__ anymore. Adapted tls.c to honour the reserved slots. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2375 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/Jamfile | 1 - src/kernel/libroot/os/arch/x86/Jamfile | 4 +- src/kernel/libroot/os/arch/x86/systeminfo.c | 60 +++++++++++++++++++++ src/kernel/libroot/os/arch/x86/thread.c | 22 ++++++++ src/kernel/libroot/os/{ => arch/x86}/tls.c | 18 ++----- src/kernel/libroot/os/systeminfo.c | 56 ------------------- src/kernel/libroot/os/thread.c | 14 ----- 7 files changed, 88 insertions(+), 87 deletions(-) create mode 100644 src/kernel/libroot/os/arch/x86/systeminfo.c create mode 100644 src/kernel/libroot/os/arch/x86/thread.c rename src/kernel/libroot/os/{ => arch/x86}/tls.c (52%) diff --git a/src/kernel/libroot/os/Jamfile b/src/kernel/libroot/os/Jamfile index ad9c01fb3f..e6595b7b6a 100644 --- a/src/kernel/libroot/os/Jamfile +++ b/src/kernel/libroot/os/Jamfile @@ -11,7 +11,6 @@ KernelMergeObject os_main.o : <$(SOURCE_GRIST)>team.c <$(SOURCE_GRIST)>thread.c <$(SOURCE_GRIST)>time.c - <$(SOURCE_GRIST)>tls.c <$(SOURCE_GRIST)>syscalls.S : -fPIC -DPIC diff --git a/src/kernel/libroot/os/arch/x86/Jamfile b/src/kernel/libroot/os/arch/x86/Jamfile index 68c1b547b1..4933df4036 100644 --- a/src/kernel/libroot/os/arch/x86/Jamfile +++ b/src/kernel/libroot/os/arch/x86/Jamfile @@ -3,6 +3,9 @@ SubDir OBOS_TOP src kernel libroot os arch x86 ; 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 : -fPIC -DPIC ; @@ -12,4 +15,3 @@ MergeObjectFromObjects kernel_os_arch_$(OBOS_ARCH).o : #<$(SOURCE_GRIST)>atomic.o <$(SOURCE_GRIST)>cpuid.o ; - diff --git a/src/kernel/libroot/os/arch/x86/systeminfo.c b/src/kernel/libroot/os/arch/x86/systeminfo.c new file mode 100644 index 0000000000..6b53bbf86d --- /dev/null +++ b/src/kernel/libroot/os/arch/x86/systeminfo.c @@ -0,0 +1,60 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include + + +// this declaration could be placed in a header file somewhere, but it doesn't +// appear likely that any user functions besides 'get_cpuid()' would need it... +void cpuid(unsigned int selector, unsigned int *data); + + +/* + * get_cpuid() -- uses the 'cpuid' instruction to retrieve information + * about the computer make & model and the capabilities of the cpu(s) + * ...this means the function is strictly INTEL PLATFORM ONLY!!! + * + * parameters: + * info: out - the structure to hold the cpuid information + * eax_register: in - the value to place in eax before invoking 'cpuid' + * cpu_num: in - the number of the cpu to gather information about + * (currently not used) + * + * Note: the stage2 bootloader already verifies at startup time that the + * 'cpuid' instruction can be called by the host computer, so no checking + * for this is done here. + */ + +status_t +get_cpuid(cpuid_info *info, uint32 eax_register, uint32 cpu_num) +{ + unsigned int data[4]; + + // call the instruction + cpuid(eax_register, data); + + // fill the info struct with the return values + info->regs.eax = data[0]; + info->regs.ebx = data[1]; + info->regs.ecx = data[2]; + info->regs.edx = data[3]; + + if (eax_register == 0) { + // fixups for this special case + char *vendor = info->eax_0.vendorid; + + // the high-order word is non-zero on some Cyrix CPUs + info->eax_0.max_eax = data[0] & 0xffff; + + // the vendor string bytes need a little re-ordering + *((unsigned int *) &vendor[0]) = data[1]; + *((unsigned int *) &vendor[4]) = data[3]; + *((unsigned int *) &vendor[8]) = data[2]; + } + + return B_OK; +} + diff --git a/src/kernel/libroot/os/arch/x86/thread.c b/src/kernel/libroot/os/arch/x86/thread.c new file mode 100644 index 0000000000..9a31c65638 --- /dev/null +++ b/src/kernel/libroot/os/arch/x86/thread.c @@ -0,0 +1,22 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include +#include +#include "syscalls.h" + + +// see OS.h for the reason why we need this +thread_id _kfind_thread_(const char *name); + +thread_id +_kfind_thread_(const char *name) +{ + // ToDo: _kfind_thread_() + printf("find_thread(): Not yet implemented!!\n"); + return B_ERROR; +} + diff --git a/src/kernel/libroot/os/tls.c b/src/kernel/libroot/os/arch/x86/tls.c similarity index 52% rename from src/kernel/libroot/os/tls.c rename to src/kernel/libroot/os/arch/x86/tls.c index 59f91be833..0cb1f26cc7 100644 --- a/src/kernel/libroot/os/tls.c +++ b/src/kernel/libroot/os/arch/x86/tls.c @@ -1,5 +1,5 @@ /* -** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. ** Distributed under the terms of the OpenBeOS License. */ @@ -10,17 +10,10 @@ #endif #include "support/TLS.h" +#include "tls.h" -// ToDo: we probably need to set some standard slots (like it's done in BeOS)! -// Slot 1 is obviously the thread ID, but there are 8 pre-allocated slots in BeOS. -// I have no idea what the other slots are used for; they are all NULL when the -// thread has just started, but slots 0 & 1. -// Slot 0 seems to be an address somewhere on the stack. Another slot is most probably -// reserved for "errno", the others could have been used to make some POSIX calls -// thread-safe - but we also have to find out which supposely non-thread-safe POSIX -// calls are thread-safe in BeOS. -static int32 gNextSlot = 0; +static int32 gNextSlot = TLS_FIRST_FREE_SLOT; int32 @@ -34,8 +27,6 @@ tls_allocate(void) } -#if __INTEL__ && __GNUC__ - void * tls_get(int32 index) { @@ -67,6 +58,3 @@ tls_set(int32 index, void *value) : : "d"(index), "a"(value) ); } -#else -# error "TLS has not been implemented for this platform" -#endif diff --git a/src/kernel/libroot/os/systeminfo.c b/src/kernel/libroot/os/systeminfo.c index 982ea55ac0..af4c55f504 100644 --- a/src/kernel/libroot/os/systeminfo.c +++ b/src/kernel/libroot/os/systeminfo.c @@ -8,62 +8,6 @@ #include "syscalls.h" -#ifdef __INTEL__ - -// this declaration could be placed in a header file somewhere, but it doesn't -// appear likely that any user functions besides 'get_cpuid()' would need it... -void cpuid(unsigned int selector, unsigned int *data); - - -/* - * get_cpuid() -- uses the 'cpuid' instruction to retrieve information - * about the computer make & model and the capabilities of the cpu(s) - * ...this means the function is strictly INTEL PLATFORM ONLY!!! - * - * parameters: - * info: out - the structure to hold the cpuid information - * eax_register: in - the value to place in eax before invoking 'cpuid' - * cpu_num: in - the number of the cpu to gather information about - * (currently not used) - * - * Note: the stage2 bootloader already verifies at startup time that the - * 'cpuid' instruction can be called by the host computer, so no checking - * for this is done here. - */ - -status_t -get_cpuid(cpuid_info *info, uint32 eax_register, uint32 cpu_num) -{ - unsigned int data[4]; - - // call the instruction - cpuid(eax_register, data); - - // fill the info struct with the return values - info->regs.eax = data[0]; - info->regs.ebx = data[1]; - info->regs.ecx = data[2]; - info->regs.edx = data[3]; - - if (eax_register == 0) { - // fixups for this special case - char *vendor = info->eax_0.vendorid; - - // the high-order word is non-zero on some Cyrix CPUs - info->eax_0.max_eax = data[0] & 0xffff; - - // the vendor string bytes need a little re-ordering - *((unsigned int *) &vendor[0]) = data[1]; - *((unsigned int *) &vendor[4]) = data[3]; - *((unsigned int *) &vendor[8]) = data[2]; - } - - return B_OK; -} - -#endif - - status_t _get_system_info(system_info *returned_info, size_t size) { diff --git a/src/kernel/libroot/os/thread.c b/src/kernel/libroot/os/thread.c index ad0379d7bb..58db0a2cb1 100644 --- a/src/kernel/libroot/os/thread.c +++ b/src/kernel/libroot/os/thread.c @@ -50,20 +50,6 @@ find_thread(const char *name) } -#ifdef __INTEL__ -// see OS.h for the reason why we need this -thread_id _kfind_thread_(const char *name); - -thread_id -_kfind_thread_(const char *name) -{ - // ToDo: _kfind_thread_() - printf("find_thread(): Not yet implemented!!\n"); - return B_ERROR; -} -#endif - - status_t rename_thread(thread_id thread, const char *name) {