1/* 2 * Copyright 2002-2006, The Haiku Team. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. 6 * Distributed under the terms of the NewOS License. 7 */ 8#ifndef _KERNEL_ARCH_x86_THREAD_TYPES_H 9#define _KERNEL_ARCH_x86_THREAD_TYPES_H 10 11 12#include <SupportDefs.h> 13 14#ifdef __x86_64__ 15# include <arch/x86/64/iframe.h> 16#else 17# include <arch/x86/32/iframe.h> 18#endif 19 20 21namespace BKernel { 22 struct Thread; 23} 24 25 26#define _ALIGNED(bytes) __attribute__((aligned(bytes))) 27 // move this to somewhere else, maybe BeBuild.h? 28 29 30#ifndef __x86_64__ 31struct farcall { 32 uint32* esp; 33 uint32* ss; 34}; 35#endif 36 37 38// architecture specific thread info 39struct arch_thread { 40#ifdef __x86_64__ 41 // Back pointer to the containing Thread structure. The GS segment base is 42 // pointed here, used to get the current thread. 43 BKernel::Thread* thread; 44 45 // RSP for kernel entry used by SYSCALL, and temporary scratch space. 46 uint64* syscall_rsp; 47 uint64* user_rsp; 48 49 uintptr_t* current_stack; 50 uintptr_t instruction_pointer; 51 52 uint64 user_gs_base; 53#else 54 struct farcall current_stack; 55 struct farcall interrupt_stack; 56#endif 57 58#ifndef __x86_64__ 59 // 512 byte floating point save point - this must be 16 byte aligned 60 uint8 fpu_state[512] _ALIGNED(16); 61#else 62 // floating point save point - this must be 64 byte aligned for xsave and 63 // have enough space for all the registers, at least 2560 bytes according 64 // to Intel Architecture Instruction Set Extensions Programming Reference, 65 // Section 3.2.4, table 3-8 66 uint8 fpu_state[2560] _ALIGNED(64); 67#endif 68 69 addr_t GetFramePointer() const; 70} _ALIGNED(16); 71 72 73struct arch_team { 74 // gcc treats empty structures as zero-length in C, but as if they contain 75 // a char in C++. So we have to put a dummy in to be able to use the struct 76 // from both in a consistent way. 77 char dummy; 78}; 79 80 81struct arch_fork_arg { 82 struct iframe iframe; 83}; 84 85 86#ifdef __x86_64__ 87 88 89inline addr_t 90arch_thread::GetFramePointer() const 91{ 92 return current_stack[0]; 93} 94 95 96#else 97 98 99inline addr_t 100arch_thread::GetFramePointer() const 101{ 102 return current_stack.esp[2]; 103} 104 105 106#endif // __x86_64__ 107 108#endif // _KERNEL_ARCH_x86_THREAD_TYPES_H 109