arch_thread.h revision 4f7b9506
1/*
2 * Copyright 2002-2011, The Haiku Team. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Copyright 2002, Travis Geiselbrecht. All rights reserved.
6 * Distributed under the terms of the NewOS License.
7 */
8#ifndef _KERNEL_ARCH_x86_THREAD_H
9#define _KERNEL_ARCH_x86_THREAD_H
10
11
12#include <arch/cpu.h>
13
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct sigaction;
20
21
22struct iframe* x86_get_user_iframe(void);
23struct iframe* x86_get_current_iframe(void);
24struct iframe* x86_get_thread_user_iframe(Thread* thread);
25
26phys_addr_t x86_next_page_directory(Thread* from, Thread* to);
27void x86_initial_return_to_userland(Thread* thread, struct iframe* iframe);
28
29void x86_restart_syscall(struct iframe* frame);
30void x86_set_tls_context(Thread* thread);
31
32
33static inline Thread*
34arch_thread_get_current_thread(void)
35{
36	addr_t addr;
37	__asm__("mov %%gs:0, %0" : "=r"(addr));
38	return (Thread*)addr;
39}
40
41
42#ifdef __x86_64__
43
44
45static inline void
46arch_thread_set_current_thread(Thread* t)
47{
48	// Point GS segment base at thread architecture data.
49	t->arch_info.thread = t;
50	x86_write_msr(IA32_MSR_GS_BASE, (addr_t)&t->arch_info);
51}
52
53
54#else	// __x86_64__
55
56
57// override empty macro
58#undef arch_syscall_64_bit_return_value
59void arch_syscall_64_bit_return_value(void);
60
61
62static inline void
63arch_thread_set_current_thread(Thread* t)
64{
65	asm volatile("mov %0, %%gs:0" : : "r" (t) : "memory");
66}
67
68
69#endif	// __x86_64__
70
71
72#ifdef __cplusplus
73}
74#endif
75
76#endif /* _KERNEL_ARCH_x86_THREAD_H */
77
78