xref: /minix3/common/lib/libc/arch/m68k/atomic/atomic_cas_68000.S (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc/*	$NetBSD: atomic_cas_68000.S,v 1.6 2014/01/29 10:20:11 martin Exp $	*/
2b6cbf720SGianluca Guida
3b6cbf720SGianluca Guida/*-
4b6cbf720SGianluca Guida * Copyright (c) 2008 The NetBSD Foundation, Inc.
5b6cbf720SGianluca Guida * All rights reserved.
6b6cbf720SGianluca Guida *
7b6cbf720SGianluca Guida * This code is derived from software contributed to The NetBSD Foundation
8b6cbf720SGianluca Guida * by Steve C. Woodford.
9b6cbf720SGianluca Guida *
10b6cbf720SGianluca Guida * Redistribution and use in source and binary forms, with or without
11b6cbf720SGianluca Guida * modification, are permitted provided that the following conditions
12b6cbf720SGianluca Guida * are met:
13b6cbf720SGianluca Guida * 1. Redistributions of source code must retain the above copyright
14b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer.
15b6cbf720SGianluca Guida * 2. Redistributions in binary form must reproduce the above copyright
16b6cbf720SGianluca Guida *    notice, this list of conditions and the following disclaimer in the
17b6cbf720SGianluca Guida *    documentation and/or other materials provided with the distribution.
18b6cbf720SGianluca Guida *
19b6cbf720SGianluca Guida * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20b6cbf720SGianluca Guida * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21b6cbf720SGianluca Guida * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22b6cbf720SGianluca Guida * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23b6cbf720SGianluca Guida * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b6cbf720SGianluca Guida * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b6cbf720SGianluca Guida * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b6cbf720SGianluca Guida * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b6cbf720SGianluca Guida * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b6cbf720SGianluca Guida * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29b6cbf720SGianluca Guida * POSSIBILITY OF SUCH DAMAGE.
30b6cbf720SGianluca Guida */
31b6cbf720SGianluca Guida
32b6cbf720SGianluca Guida#include <sys/ras.h>
33b6cbf720SGianluca Guida#include "atomic_op_asm.h"
34b6cbf720SGianluca Guida
35b6cbf720SGianluca Guida	.text
36b6cbf720SGianluca Guida
37b6cbf720SGianluca GuidaENTRY(_atomic_cas_up)
38b6cbf720SGianluca Guida	.hidden	_C_LABEL(_atomic_cas_up)
39b6cbf720SGianluca Guida
4084d9c625SLionel Sambuc	movl	4(%sp), %a0		/* Fetch ptr */
41b6cbf720SGianluca Guida
42b6cbf720SGianluca GuidaRAS_START_ASM_HIDDEN(_atomic_cas)
4384d9c625SLionel Sambuc	movl	(%a0), %d0		/* d0 = *ptr */
4484d9c625SLionel Sambuc	cmpl	8(%sp), %d0		/* Same as old? */
45b6cbf720SGianluca Guida	jne	1f			/* Nope */
4684d9c625SLionel Sambuc	movl	12(%sp), (%a0)		/* *ptr = new */
47b6cbf720SGianluca GuidaRAS_END_ASM_HIDDEN(_atomic_cas)
48b6cbf720SGianluca Guida1:	rts
4984d9c625SLionel SambucEND(_atomic_cas_up)
50*0a6a1f1dSLionel Sambuc
51*0a6a1f1dSLionel SambucENTRY(_atomic_cas_16_up)
52*0a6a1f1dSLionel Sambuc	.hidden	_C_LABEL(_atomic_cas_16_up)
53*0a6a1f1dSLionel Sambuc
54*0a6a1f1dSLionel Sambuc	movl	4(%sp), %a0		/* Fetch ptr */
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel SambucRAS_START_ASM_HIDDEN(_atomic_cas_16)
57*0a6a1f1dSLionel Sambuc	movw	(%a0), %d0		/* d0 = *ptr */
58*0a6a1f1dSLionel Sambuc	cmpw	8(%sp), %d0		/* Same as old? */
59*0a6a1f1dSLionel Sambuc	jne	1f			/* Nope */
60*0a6a1f1dSLionel Sambuc	movw	12(%sp), (%a0)		/* *ptr = new */
61*0a6a1f1dSLionel SambucRAS_END_ASM_HIDDEN(_atomic_cas_16)
62*0a6a1f1dSLionel Sambuc1:	rts
63*0a6a1f1dSLionel SambucEND(_atomic_cas_16_up)
64*0a6a1f1dSLionel Sambuc
65*0a6a1f1dSLionel Sambuc
66*0a6a1f1dSLionel SambucENTRY(_atomic_cas_8_up)
67*0a6a1f1dSLionel Sambuc	.hidden	_C_LABEL(_atomic_cas_8_up)
68*0a6a1f1dSLionel Sambuc
69*0a6a1f1dSLionel Sambuc	movl	4(%sp), %a0		/* Fetch ptr */
70*0a6a1f1dSLionel Sambuc
71*0a6a1f1dSLionel SambucRAS_START_ASM_HIDDEN(_atomic_cas_8)
72*0a6a1f1dSLionel Sambuc	movb	(%a0), %d0		/* d0 = *ptr */
73*0a6a1f1dSLionel Sambuc	cmpb	8(%sp), %d0		/* Same as old? */
74*0a6a1f1dSLionel Sambuc	jne	1f			/* Nope */
75*0a6a1f1dSLionel Sambuc	movb	12(%sp), (%a0)		/* *ptr = new */
76*0a6a1f1dSLionel SambucRAS_END_ASM_HIDDEN(_atomic_cas_8)
77*0a6a1f1dSLionel Sambuc1:	rts
78*0a6a1f1dSLionel SambucEND(_atomic_cas_8_up)
79