[haiku-commits] BRANCH xyzzy-github.x86_64 - in src/system/libroot: os/arch/x86_64 posix/string/arch/x86_64 posix/arch/x86_64

  • From: xyzzy-github.x86_64 <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 22 Jul 2012 16:49:13 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/xyzzy-github/x86_64'
old head: aef19e3c95ba3047d6d95b2731c6ea66dbbfddab
new head: fd9f32c0db56a5cebdda79c329b479355bdde87c

----------------------------------------------------------------------------

fd9f32c: Added some libroot bits for x86_64.
  
  Still some parts missing (the glibc bits + fenv.c), plus the TLS
  functions are only stubs.

                                      [ Alex Smith <alex@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Commit:      fd9f32c0db56a5cebdda79c329b479355bdde87c

Author:      Alex Smith <alex@xxxxxxxxxxxxxxxx>
Date:        Sun Jul 22 13:59:42 2012 UTC

----------------------------------------------------------------------------

11 files changed, 260 insertions(+)
src/system/libroot/os/arch/x86_64/Jamfile          |   17 ++++++
.../libroot/os/arch/x86_64/get_stack_frame.S       |   22 +++++++
src/system/libroot/os/arch/x86_64/syscalls.inc     |   46 ++++++++++++++
src/system/libroot/os/arch/x86_64/system_info.cpp  |   16 +++++
src/system/libroot/os/arch/x86_64/thread.cpp       |   18 ++++++
src/system/libroot/os/arch/x86_64/time.cpp         |   44 ++++++++++++++
src/system/libroot/os/arch/x86_64/tls.cpp          |   50 ++++++++++++++++
src/system/libroot/os/syscalls.S                   |    3 +
src/system/libroot/posix/arch/x86_64/Jamfile       |   19 ++++++
.../libroot/posix/string/arch/x86_64/Jamfile       |    8 +++
.../libroot/posix/string/arch/x86_64/arch_string.S |   17 ++++++

----------------------------------------------------------------------------

diff --git a/src/system/libroot/os/arch/x86_64/Jamfile 
b/src/system/libroot/os/arch/x86_64/Jamfile
new file mode 100644
index 0000000..72a195e
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/Jamfile
@@ -0,0 +1,17 @@
+SubDir HAIKU_TOP src system libroot os arch x86_64 ;
+
+UsePrivateKernelHeaders ;
+       # TODO: Replace by "UsePrivateHeaders libroot" after resolving the TODO 
in
+       # time.c!
+UsePrivateSystemHeaders ;
+
+MergeObject os_arch_$(TARGET_ARCH).o :
+       atomic.S
+       byteorder.S
+       get_stack_frame.S
+       system_info.cpp
+       system_time_asm.S
+       thread.cpp
+       time.cpp
+       tls.cpp
+;
diff --git a/src/system/libroot/os/arch/x86_64/get_stack_frame.S 
b/src/system/libroot/os/arch/x86_64/get_stack_frame.S
new file mode 100644
index 0000000..0eaee36
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/get_stack_frame.S
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+*/
+
+
+#include <asm_defs.h>
+
+
+/* void* get_stack_frame(void) */
+FUNCTION(get_stack_frame):
+       movq    %rbp, %rax
+       ret
+FUNCTION_END(get_stack_frame)
+
+
+/* void* __arch_get_caller(void); */
+FUNCTION(__arch_get_caller):
+       movq    8(%rbp), %rax
+       ret
+FUNCTION_END(__arch_get_caller)
+
diff --git a/src/system/libroot/os/arch/x86_64/syscalls.inc 
b/src/system/libroot/os/arch/x86_64/syscalls.inc
new file mode 100644
index 0000000..f318d59
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/syscalls.inc
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <asm_defs.h>
+
+
+// The kernel follows the AMD64 ABI for parameter passing (first 6 arguments in
+// registers and the remaining ones in on the stack), except that RCX is used
+// by SYSCALL so it is moved to R10. Syscall number goes in RAX.
+
+
+#define _SYSCALL(name, n)              \
+       .align 8;                                       \
+       FUNCTION(name):                         \
+               movq    %rcx, %r10;             \
+               movq    $n, %rax;               \
+               syscall;                                \
+               ret;                                    \
+       FUNCTION_END(name)
+
+
+#define SYSCALL0(name, n)      _SYSCALL(name, n)
+#define SYSCALL1(name, n)      _SYSCALL(name, n)
+#define SYSCALL2(name, n)      _SYSCALL(name, n)
+#define SYSCALL3(name, n)      _SYSCALL(name, n)
+#define SYSCALL4(name, n)      _SYSCALL(name, n)
+#define SYSCALL5(name, n)      _SYSCALL(name, n)
+#define SYSCALL6(name, n)      _SYSCALL(name, n)
+#define SYSCALL7(name, n)      _SYSCALL(name, n)
+#define SYSCALL8(name, n)      _SYSCALL(name, n)
+#define SYSCALL9(name, n)      _SYSCALL(name, n)
+#define SYSCALL10(name, n)     _SYSCALL(name, n)
+#define SYSCALL11(name, n)     _SYSCALL(name, n)
+#define SYSCALL12(name, n)     _SYSCALL(name, n)
+#define SYSCALL13(name, n)     _SYSCALL(name, n)
+#define SYSCALL14(name, n)     _SYSCALL(name, n)
+#define SYSCALL15(name, n)     _SYSCALL(name, n)
+#define SYSCALL16(name, n)     _SYSCALL(name, n)
+#define SYSCALL17(name, n)     _SYSCALL(name, n)
+#define SYSCALL18(name, n)     _SYSCALL(name, n)
+#define SYSCALL19(name, n)     _SYSCALL(name, n)
+#define SYSCALL20(name, n)     _SYSCALL(name, n)
+
diff --git a/src/system/libroot/os/arch/x86_64/system_info.cpp 
b/src/system/libroot/os/arch/x86_64/system_info.cpp
new file mode 100644
index 0000000..03a3e4c
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/system_info.cpp
@@ -0,0 +1,16 @@
+/* 
+ * Copyright 2003-2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <OS.h>
+#include <syscalls.h>
+
+
+status_t
+get_cpuid(cpuid_info* info, uint32 eaxRegister, uint32 cpuNum)
+{
+       return _kern_get_cpuid(info, eaxRegister, cpuNum);
+}
+
diff --git a/src/system/libroot/os/arch/x86_64/thread.cpp 
b/src/system/libroot/os/arch/x86_64/thread.cpp
new file mode 100644
index 0000000..7b12f02
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/thread.cpp
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <OS.h>
+#include "syscalls.h"
+
+
+thread_id
+find_thread(const char* name)
+{
+       // TODO x86_64: x86 is doing some TLS thing here. Should that be done 
here
+       // too?
+       return _kern_find_thread(name);
+}
+
diff --git a/src/system/libroot/os/arch/x86_64/time.cpp 
b/src/system/libroot/os/arch/x86_64/time.cpp
new file mode 100644
index 0000000..8b95ed1
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/time.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
+ * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+
+#include <libroot_private.h>
+#include <real_time_data.h>
+#include <arch_cpu.h>
+
+
+void
+__arch_init_time(real_time_data* data, bool setDefaults)
+{
+       uint32 conversionFactor;
+       uint64 conversionFactorNsecs;
+
+       if (setDefaults) {
+               data->arch_data.system_time_offset = 0;
+               data->arch_data.system_time_conversion_factor = 100000;
+       }
+
+       // TODO: this should only store a pointer to that value
+       // When resolving this TODO, also resolve the one in the Jamfile.
+
+       conversionFactor = data->arch_data.system_time_conversion_factor;
+       conversionFactorNsecs = (uint64)conversionFactor * 1000;
+
+       // The x86_64 system_time() implementation uses 64-bit multiplication 
and
+       // therefore shifting is not necessary for low frequencies (it's also 
not
+       // too likely that there'll be any x86_64 CPUs clocked under 1GHz).
+       __x86_setup_system_time((uint64)conversionFactor << 32,
+               conversionFactorNsecs);
+}
+
+
+bigtime_t
+__arch_get_system_time_offset(struct real_time_data *data)
+{
+       //we don't use atomic_get64 because memory is read-only, maybe find 
another way to lock
+       return data->arch_data.system_time_offset;
+}
+
diff --git a/src/system/libroot/os/arch/x86_64/tls.cpp 
b/src/system/libroot/os/arch/x86_64/tls.cpp
new file mode 100644
index 0000000..794c422
--- /dev/null
+++ b/src/system/libroot/os/arch/x86_64/tls.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+
+// TODO x86_64.
+// Also want to add inline versions to support/TLS.h.
+
+
+#ifndef _NO_INLINE_ASM
+#      define _NO_INLINE_ASM 1
+#endif
+
+#include <support/TLS.h>
+#include <tls.h>
+
+#include <assert.h>
+
+
+int32
+tls_allocate(void)
+{
+       assert(0 && "tls_allocate: not implemented");
+       return 0;
+}
+
+
+void*
+tls_get(int32 index)
+{
+       assert(0 && "tls_get: not implemented");
+       return NULL;
+}
+
+
+void**
+tls_address(int32 index)
+{
+       assert(0 && "tls_address: not implemented");
+       return NULL;
+}
+
+
+void
+tls_set(int32 index, void* value)
+{
+       assert(0 && "tls_set: not implemented");
+}
+
diff --git a/src/system/libroot/os/syscalls.S b/src/system/libroot/os/syscalls.S
index 770da14..b7b3e87 100644
--- a/src/system/libroot/os/syscalls.S
+++ b/src/system/libroot/os/syscalls.S
@@ -1,6 +1,9 @@
 #ifdef ARCH_x86
 #      include "arch/x86/syscalls.inc"
 #endif
+#ifdef ARCH_x86_64
+#      include "arch/x86_64/syscalls.inc"
+#endif
 #ifdef ARCH_alpha
 #      include "arch/alpha/syscalls.inc"
 #endif
diff --git a/src/system/libroot/posix/arch/x86_64/Jamfile 
b/src/system/libroot/posix/arch/x86_64/Jamfile
new file mode 100644
index 0000000..cbbe851
--- /dev/null
+++ b/src/system/libroot/posix/arch/x86_64/Jamfile
@@ -0,0 +1,19 @@
+SubDir HAIKU_TOP src system libroot posix arch x86_64 ;
+
+UsePrivateSystemHeaders ;
+
+local genericSources =
+       setjmp_save_sigs.c
+       longjmp_return.c
+;
+
+MergeObject posix_arch_$(TARGET_ARCH).o :
+       #fenv.c
+       sigsetjmp.S
+       siglongjmp.S
+
+       $(genericSources)
+;
+
+SEARCH on [ FGristFiles $(genericSources) ]
+       = [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
diff --git a/src/system/libroot/posix/string/arch/x86_64/Jamfile 
b/src/system/libroot/posix/string/arch/x86_64/Jamfile
new file mode 100644
index 0000000..1c3ac21
--- /dev/null
+++ b/src/system/libroot/posix/string/arch/x86_64/Jamfile
@@ -0,0 +1,8 @@
+SubDir HAIKU_TOP src system libroot posix string arch x86_64 ;
+
+UsePrivateSystemHeaders ;
+
+MergeObject posix_string_arch_$(TARGET_ARCH).o :
+       arch_string.S
+;
+
diff --git a/src/system/libroot/posix/string/arch/x86_64/arch_string.S 
b/src/system/libroot/posix/string/arch/x86_64/arch_string.S
new file mode 100644
index 0000000..8bbadb3
--- /dev/null
+++ b/src/system/libroot/posix/string/arch/x86_64/arch_string.S
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2008, Ingo Weinhold, ingo_weinhold@xxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+
+#include <asm_defs.h>
+#include <commpage_defs.h>
+
+
+FUNCTION(memcpy):
+       jmp     *(USER_COMMPAGE_ADDR + COMMPAGE_ENTRY_X86_MEMCPY * 8)
+FUNCTION_END(memcpy)
+
+
+FUNCTION(memset):
+       jmp     *(USER_COMMPAGE_ADDR + COMMPAGE_ENTRY_X86_MEMSET * 8)
+FUNCTION_END(memset)


Other related posts: