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 0000000000..72a195ed84 --- /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 0000000000..0eaee36523 --- /dev/null +++ b/src/system/libroot/os/arch/x86_64/get_stack_frame.S @@ -0,0 +1,22 @@ +/* + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. +*/ + + +#include + + +/* 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 0000000000..f318d59c39 --- /dev/null +++ b/src/system/libroot/os/arch/x86_64/syscalls.inc @@ -0,0 +1,46 @@ +/* + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + */ + + +#include + + +// 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 0000000000..03a3e4c440 --- /dev/null +++ b/src/system/libroot/os/arch/x86_64/system_info.cpp @@ -0,0 +1,16 @@ +/* + * Copyright 2003-2004, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ + + +#include +#include + + +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 0000000000..7b12f02e39 --- /dev/null +++ b/src/system/libroot/os/arch/x86_64/thread.cpp @@ -0,0 +1,18 @@ +/* + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + */ + + +#include +#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 0000000000..8b95ed1c62 --- /dev/null +++ b/src/system/libroot/os/arch/x86_64/time.cpp @@ -0,0 +1,44 @@ +/* + * Copyright 2004, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * Distributed under the terms of the MIT License. + */ + + +#include +#include +#include + + +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 0000000000..794c422090 --- /dev/null +++ b/src/system/libroot/os/arch/x86_64/tls.cpp @@ -0,0 +1,50 @@ +/* + * Copyright 2012, Alex Smith, alex@alex-smith.me.uk. + * 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 +#include + +#include + + +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 770da146bc..b7b3e87b02 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 0000000000..cbbe85108d --- /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 0000000000..1c3ac217c0 --- /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 0000000000..8bbadb31ca --- /dev/null +++ b/src/system/libroot/posix/string/arch/x86_64/arch_string.S @@ -0,0 +1,17 @@ +/* + * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. + * Distributed under the terms of the MIT License. + */ + +#include +#include + + +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)