xref: /haiku/headers/private/kernel/arch/x86/arch_thread.h (revision 2b76973fa2401f7a5edf68e6470f3d3210cbcff3)
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
16 extern "C" {
17 #endif
18 
19 struct sigaction;
20 
21 
22 struct iframe* x86_get_user_iframe(void);
23 struct iframe* x86_get_current_iframe(void);
24 struct iframe* x86_get_thread_user_iframe(Thread* thread);
25 
26 phys_addr_t x86_next_page_directory(Thread* from, Thread* to);
27 void x86_initial_return_to_userland(Thread* thread, struct iframe* iframe);
28 
29 void x86_restart_syscall(struct iframe* frame);
30 void x86_set_tls_context(Thread* thread);
31 
32 
33 #ifdef __x86_64__
34 
35 
36 static inline Thread*
37 arch_thread_get_current_thread(void)
38 {
39 	addr_t addr;
40 	__asm__("mov %%gs:0, %0" : "=r"(addr));
41 	return (Thread*)addr;
42 }
43 
44 
45 static inline void
46 arch_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
59 void arch_syscall_64_bit_return_value(void);
60 
61 
62 static inline Thread*
63 arch_thread_get_current_thread(void)
64 {
65 	Thread* t = (Thread*)x86_read_dr3();
66 	return t;
67 }
68 
69 
70 static inline void
71 arch_thread_set_current_thread(Thread* t)
72 {
73 	x86_write_dr3(t);
74 }
75 
76 
77 #endif	// __x86_64__
78 
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* _KERNEL_ARCH_x86_THREAD_H */
85