xref: /netbsd-src/common/lib/libc/arch/arm/atomic/atomic_cas_up.S (revision 7680719e6befd3f40a9099d70c7da371e6aa6d9f)
1/*	$NetBSD: atomic_cas_up.S,v 1.8 2020/03/09 11:21:54 skrll Exp $	*/
2
3/*-
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Steve C. Woodford.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <sys/ras.h>
33#include <machine/asm.h>
34
35ENTRY(_atomic_cas_up)
36	.hidden	_C_LABEL(_atomic_cas_up)
37	mov	r3, r0
38	.align	0
39RAS_START_ASM_HIDDEN(_atomic_cas)
40	ldr	r0, [r3]
41	cmp	r0, r1
42#if defined(__thumb__)
43	beq	1f
44	str	r2, [r3]
45#else
46	streq	r2, [r3]
47#endif
48	.align	0
49RAS_END_ASM_HIDDEN(_atomic_cas)
501:	RET
51END(_atomic_cas_up)
52
53#if defined(__HAVE_ASM_ATOMIC_CAS_64_UP)
54ARM_ENTRY(_atomic_cas_64_up)
55	push	{r4-r5}
56	mov	ip, r0
57	ldrd	r4, r5, [sp, #8]
58	.align	0
59RAS_START_ASM_HIDDEN(_atomic_cas_64)
60	ldrd	r0, r1, [ip]
61	cmp	r0, r2
62	cmpeq	r1, r3
63	strdeq	r4, r5, [ip]
64	.align	0
65RAS_END_ASM_HIDDEN(_atomic_cas_64)
661:	pop	{r4-r5}
67	bx	lr
68END(_atomic_cas_64_up)
69#endif /* __HAVE_ASM_ATOMIC_64_UP */
70
71ENTRY(_atomic_cas_16_up)
72	mov	r3, r0
73	.align	0
74RAS_START_ASM_HIDDEN(_atomic_cas_16)
75	ldrh	r0, [r3]
76	cmp	r0, r1
77#if defined(__thumb__)
78	beq	1f
79	strh	r2, [r3]
80#else
81	strheq	r2, [r3]
82#endif
83	.align	0
84RAS_END_ASM_HIDDEN(_atomic_cas_16)
851:	RET
86END(_atomic_cas_16_up)
87
88ENTRY(_atomic_cas_8_up)
89	mov	r3, r0
90	.align	0
91RAS_START_ASM_HIDDEN(_atomic_cas_8)
92	ldrb	r0, [r3]
93	cmp	r0, r1
94#if defined(__thumb__)
95	beq	1f
96	strb	r2, [r3]
97#else
98	strbeq	r2, [r3]
99#endif
100	.align	0
101RAS_END_ASM_HIDDEN(_atomic_cas_8)
1021:	RET
103END(_atomic_cas_8_up)
104