]>
Commit | Line | Data |
---|---|---|
cc310428 OM |
1 | // Implementation of synchronization functions for ARM architecture\r |
2 | //\r | |
3 | // Copyright (c) 2012-2015, ARM Limited. All rights reserved.\r | |
4 | //\r | |
5 | // This program and the accompanying materials\r | |
6 | // are licensed and made available under the terms and conditions of the BSD License\r | |
7 | // which accompanies this distribution. The full text of the license may be found at\r | |
8 | // http://opensource.org/licenses/bsd-license.php\r | |
9 | //\r | |
10 | // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | //\r | |
13 | //\r | |
14 | \r | |
15 | .text\r | |
16 | .align 3\r | |
17 | \r | |
18 | GCC_ASM_EXPORT(InternalSyncCompareExchange32)\r | |
19 | GCC_ASM_EXPORT(InternalSyncCompareExchange64)\r | |
20 | GCC_ASM_EXPORT(InternalSyncIncrement)\r | |
21 | GCC_ASM_EXPORT(InternalSyncDecrement)\r | |
22 | \r | |
23 | /**\r | |
24 | Performs an atomic compare exchange operation on a 32-bit unsigned integer.\r | |
25 | \r | |
26 | Performs an atomic compare exchange operation on the 32-bit unsigned integer\r | |
27 | specified by Value. If Value is equal to CompareValue, then Value is set to\r | |
28 | ExchangeValue and CompareValue is returned. If Value is not equal to CompareValue,\r | |
29 | then Value is returned. The compare exchange operation must be performed using\r | |
30 | MP safe mechanisms.\r | |
31 | \r | |
32 | @param Value A pointer to the 32-bit value for the compare exchange\r | |
33 | operation.\r | |
34 | @param CompareValue 32-bit value used in compare operation.\r | |
35 | @param ExchangeValue 32-bit value used in exchange operation.\r | |
36 | \r | |
37 | @return The original *Value before exchange.\r | |
38 | \r | |
39 | **/\r | |
40 | //UINT32\r | |
41 | //EFIAPI\r | |
42 | //InternalSyncCompareExchange32 (\r | |
43 | // IN volatile UINT32 *Value,\r | |
44 | // IN UINT32 CompareValue,\r | |
45 | // IN UINT32 ExchangeValue\r | |
46 | // )\r | |
47 | ASM_PFX(InternalSyncCompareExchange32):\r | |
48 | dmb\r | |
49 | \r | |
50 | InternalSyncCompareExchange32Again:\r | |
51 | ldrex r3, [r0]\r | |
52 | cmp r3, r1\r | |
53 | bne InternalSyncCompareExchange32Fail\r | |
54 | \r | |
55 | InternalSyncCompareExchange32Exchange:\r | |
56 | strex ip, r2, [r0]\r | |
57 | cmp ip, #0\r | |
58 | bne InternalSyncCompareExchange32Again\r | |
59 | \r | |
60 | InternalSyncCompareExchange32Fail:\r | |
61 | dmb\r | |
62 | mov r0, r3\r | |
63 | bx lr\r | |
64 | \r | |
65 | /**\r | |
66 | Performs an atomic compare exchange operation on a 64-bit unsigned integer.\r | |
67 | \r | |
68 | Performs an atomic compare exchange operation on the 64-bit unsigned integer specified\r | |
69 | by Value. If Value is equal to CompareValue, then Value is set to ExchangeValue and\r | |
70 | CompareValue is returned. If Value is not equal to CompareValue, then Value is returned.\r | |
71 | The compare exchange operation must be performed using MP safe mechanisms.\r | |
72 | \r | |
73 | @param Value A pointer to the 64-bit value for the compare exchange\r | |
74 | operation.\r | |
75 | @param CompareValue 64-bit value used in compare operation.\r | |
76 | @param ExchangeValue 64-bit value used in exchange operation.\r | |
77 | \r | |
78 | @return The original *Value before exchange.\r | |
79 | \r | |
80 | **/\r | |
81 | //UINT64\r | |
82 | //EFIAPI\r | |
83 | //InternalSyncCompareExchange64 (\r | |
84 | // IN volatile UINT64 *Value, // r0\r | |
85 | // IN UINT64 CompareValue, // r2-r3\r | |
86 | // IN UINT64 ExchangeValue // stack\r | |
87 | // )\r | |
88 | ASM_PFX(InternalSyncCompareExchange64):\r | |
89 | push { r4-r7 }\r | |
90 | ldrd r4, r5, [sp, #16]\r | |
91 | dmb\r | |
92 | \r | |
93 | InternalSyncCompareExchange64Again:\r | |
94 | ldrexd r6, r7, [r0]\r | |
95 | cmp r6, r2\r | |
96 | cmpeq r7, r3\r | |
97 | bne InternalSyncCompareExchange64Fail\r | |
98 | \r | |
99 | InternalSyncCompareExchange64Exchange:\r | |
100 | strexd ip, r4, r5, [r0]\r | |
101 | cmp ip, #0\r | |
102 | bne InternalSyncCompareExchange64Again\r | |
103 | \r | |
104 | InternalSyncCompareExchange64Fail:\r | |
105 | dmb\r | |
106 | mov r0, r6\r | |
107 | mov r1, r7\r | |
108 | pop { r4-r7 }\r | |
109 | bx lr\r | |
110 | \r | |
111 | /**\r | |
112 | Performs an atomic increment of an 32-bit unsigned integer.\r | |
113 | \r | |
114 | Performs an atomic increment of the 32-bit unsigned integer specified by\r | |
115 | Value and returns the incremented value. The increment operation must be\r | |
116 | performed using MP safe mechanisms. The state of the return value is not\r | |
117 | guaranteed to be MP safe.\r | |
118 | \r | |
119 | @param Value A pointer to the 32-bit value to increment.\r | |
120 | \r | |
121 | @return The incremented value.\r | |
122 | \r | |
123 | **/\r | |
124 | //UINT32\r | |
125 | //EFIAPI\r | |
126 | //InternalSyncIncrement (\r | |
127 | // IN volatile UINT32 *Value\r | |
128 | // )\r | |
129 | ASM_PFX(InternalSyncIncrement):\r | |
130 | dmb\r | |
131 | TryInternalSyncIncrement:\r | |
132 | ldrex r1, [r0]\r | |
133 | add r1, r1, #1\r | |
134 | strex r2, r1, [r0]\r | |
135 | cmp r2, #0\r | |
136 | bne TryInternalSyncIncrement\r | |
137 | dmb\r | |
138 | bx lr\r | |
139 | \r | |
140 | /**\r | |
141 | Performs an atomic decrement of an 32-bit unsigned integer.\r | |
142 | \r | |
143 | Performs an atomic decrement of the 32-bit unsigned integer specified by\r | |
144 | Value and returns the decrement value. The decrement operation must be\r | |
145 | performed using MP safe mechanisms. The state of the return value is not\r | |
146 | guaranteed to be MP safe.\r | |
147 | \r | |
148 | @param Value A pointer to the 32-bit value to decrement.\r | |
149 | \r | |
150 | @return The decrement value.\r | |
151 | \r | |
152 | **/\r | |
153 | //UINT32\r | |
154 | //EFIAPI\r | |
155 | //InternalSyncDecrement (\r | |
156 | // IN volatile UINT32 *Value\r | |
157 | // )\r | |
158 | ASM_PFX(InternalSyncDecrement):\r | |
159 | dmb\r | |
160 | TryInternalSyncDecrement:\r | |
161 | ldrex r1, [r0]\r | |
162 | sub r1, r1, #1\r | |
163 | strex r2, r1, [r0]\r | |
164 | cmp r2, #0\r | |
165 | bne TryInternalSyncDecrement\r | |
166 | dmb\r | |
167 | bx lr\r |