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 <arch_cpu.h>
13
14
15namespace BKernel {
16    struct Thread;
17}
18
19
20#define _ALIGNED(bytes) __attribute__((aligned(bytes)))
21	// move this to somewhere else, maybe BeBuild.h?
22
23
24#ifndef __x86_64__
25struct farcall {
26	uint32* esp;
27	uint32* ss;
28};
29#endif
30
31
32// architecture specific thread info
33struct arch_thread {
34#ifdef __x86_64__
35	// Back pointer to the containing Thread structure. The GS segment base is
36	// pointed here, used to get the current thread.
37	BKernel::Thread* thread;
38
39	// RSP for kernel entry used by SYSCALL, and temporary scratch space.
40	uint64*			syscall_rsp;
41	uint64*			user_rsp;
42
43	uint64*			current_stack;
44#else
45	struct farcall	current_stack;
46	struct farcall	interrupt_stack;
47#endif
48
49	// 512 byte floating point save point - this must be 16 byte aligned
50	uint8			fpu_state[512] _ALIGNED(16);
51
52	addr_t			GetFramePointer() const;
53} _ALIGNED(16);
54
55
56struct arch_team {
57	// gcc treats empty structures as zero-length in C, but as if they contain
58	// a char in C++. So we have to put a dummy in to be able to use the struct
59	// from both in a consistent way.
60	char			dummy;
61};
62
63
64struct arch_fork_arg {
65	struct iframe	iframe;
66};
67
68
69#ifdef __x86_64__
70
71
72inline addr_t
73arch_thread::GetFramePointer() const
74{
75	return current_stack[1];
76}
77
78
79#else
80
81
82inline addr_t
83arch_thread::GetFramePointer() const
84{
85	return current_stack.esp[2];
86}
87
88
89#endif	// __x86_64__
90
91#endif	// _KERNEL_ARCH_x86_THREAD_TYPES_H
92