xref: /haiku/headers/private/kernel/arch/sparc/arch_atomic.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
1 /*
2  * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Alexander von Gluck IV <kallisti5@unixzen.com>
7  */
8 #ifndef _KERNEL_ARCH_SPARC_ATOMIC_H
9 #define _KERNEL_ARCH_SPARC_ATOMIC_H
10 
11 
12 static inline void
13 memory_read_barrier_inline(void)
14 {
15 	// TODO
16 }
17 
18 
19 static inline void
20 memory_write_barrier_inline(void)
21 {
22 	// TODO
23 }
24 
25 
26 static inline void
27 memory_full_barrier_inline(void)
28 {
29 	// TODO
30 }
31 
32 
33 #define memory_read_barrier		memory_read_barrier_inline
34 #define memory_write_barrier	memory_write_barrier_inline
35 #define memory_full_barrier		memory_full_barrier_inline
36 
37 
38 static inline void
39 atomic_set_inline(int32* value, int32 newValue)
40 {
41 	memory_write_barrier();
42 	*(volatile int32*)value = newValue;
43 }
44 
45 
46 static inline int32
47 atomic_get_and_set_inline(int32* value, int32 newValue)
48 {
49 	// BIG TODO: PowerPC Atomic get and set
50 //	asm volatile("xchgl %0, (%1)"
51 //		: "+r" (newValue)
52 //		: "r" (value)
53 //		: "memory");
54 	return newValue;
55 }
56 
57 
58 static inline int32
59 atomic_test_and_set_inline(int32* value, int32 newValue, int32 testAgainst)
60 {
61 	// BIG TODO: PowerPC Atomic test and set inline
62 //	asm volatile("lock; cmpxchgl %2, (%3)"
63 //		: "=a" (newValue)
64 //		: "0" (testAgainst), "r" (newValue), "r" (value)
65 //		: "memory");
66 	return newValue;
67 }
68 
69 
70 static inline int32
71 atomic_add_inline(int32* value, int32 newValue)
72 {
73 	// BIG TODO: PowerPC Atomic add inline
74 //	asm volatile("lock; xaddl %0, (%1)"
75 //		: "+r" (newValue)
76 //		: "r" (value)
77 //		: "memory");
78 	return newValue;
79 }
80 
81 
82 static inline int32
83 atomic_get_inline(int32* value)
84 {
85 	int32 newValue = *(volatile int32*)value;
86 	memory_read_barrier();
87 	return newValue;
88 }
89 
90 
91 #define atomic_set				atomic_set_inline
92 #define atomic_get_and_set		atomic_get_and_set_inline
93 #ifndef atomic_test_and_set
94 #	define atomic_test_and_set	atomic_test_and_set_inline
95 #endif
96 #ifndef atomic_add
97 #	define atomic_add			atomic_add_inline
98 #endif
99 #define atomic_get				atomic_get_inline
100 
101 
102 #endif	// _KERNEL_ARCH_PPC_ATOMIC_H
103 
104