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#else
52	struct farcall	current_stack;
53	struct farcall	interrupt_stack;
54#endif
55
56	// 512 byte floating point save point - this must be 16 byte aligned
57	uint8			fpu_state[512] _ALIGNED(16);
58
59	addr_t			GetFramePointer() const;
60} _ALIGNED(16);
61
62
63struct arch_team {
64	// gcc treats empty structures as zero-length in C, but as if they contain
65	// a char in C++. So we have to put a dummy in to be able to use the struct
66	// from both in a consistent way.
67	char			dummy;
68};
69
70
71struct arch_fork_arg {
72	struct iframe	iframe;
73};
74
75
76#ifdef __x86_64__
77
78
79inline addr_t
80arch_thread::GetFramePointer() const
81{
82	return current_stack[0];
83}
84
85
86#else
87
88
89inline addr_t
90arch_thread::GetFramePointer() const
91{
92	return current_stack.esp[2];
93}
94
95
96#endif	// __x86_64__
97
98#endif	// _KERNEL_ARCH_x86_THREAD_TYPES_H
99