1/* $NetBSD: lock_stubs.s,v 1.11 2022/04/06 22:47:57 riastradh Exp $ */ 2 3/*- 4 * Copyright (c) 2007 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran and Michael Hitch. 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 "opt_lockdebug.h" 33 34#include <machine/asm.h> 35 36#include "assym.h" 37 38 .file "lock_stubs.s" 39 .text 40 41#if defined(__mc68010__) 42/* 43 * int _atomic_cas_32(volatile uint32_t *val, uint32_t old, uint32_t new); 44 * 45 * The 68010 does not have a cas instruction, so we implement this as 46 * a restartable atomic sequence. For an example of how this is used, 47 * see sun68k/sun68k/isr.c 48 */ 49ENTRY(_atomic_cas_32) 50 movl 4(%sp),%a0 51 52 .globl _C_LABEL(_atomic_cas_ras_start) 53_C_LABEL(_atomic_cas_ras_start): 54 movl (%a0),%d0 55 cmpl 8(%sp),%d0 56 jne 1f 57 movl 12(%sp),(%a0) 58 .globl _C_LABEL(_atomic_cas_ras_end) 59_C_LABEL(_atomic_cas_ras_end): 60 611: 62 movl %d0, %a0 /* pointers return also in %a0 */ 63 rts 64 65STRONG_ALIAS(atomic_cas_ptr,_atomic_cas_32) 66STRONG_ALIAS(_atomic_cas_ptr,_atomic_cas_32) 67STRONG_ALIAS(atomic_cas_uint,_atomic_cas_32) 68STRONG_ALIAS(_atomic_cas_uint,_atomic_cas_32) 69STRONG_ALIAS(atomic_cas_ulong,_atomic_cas_32) 70STRONG_ALIAS(_atomic_cas_ulong,_atomic_cas_32) 71STRONG_ALIAS(atomic_cas_32,_atomic_cas_32) 72 73STRONG_ALIAS(atomic_cas_32_ni,_atomic_cas_32) 74STRONG_ALIAS(_atomic_cas_32_ni,_atomic_cas_32) 75 76STRONG_ALIAS(atomic_cas_ptr_ni,_atomic_cas_32) 77STRONG_ALIAS(_atomic_cas_ptr_ni,_atomic_cas_32) 78STRONG_ALIAS(atomic_cas_uint_ni,_atomic_cas_32) 79STRONG_ALIAS(_atomic_cas_uint_ni,_atomic_cas_32) 80STRONG_ALIAS(atomic_cas_ulong_ni,_atomic_cas_32) 81STRONG_ALIAS(_atomic_cas_ulong_ni,_atomic_cas_32) 82#endif /* __mc68010__ */ 83 84#if !defined(LOCKDEBUG) 85 86#if !defined(__mc68010__) 87/* 88 * void mutex_enter(kmutex_t *mtx); 89 */ 90ENTRY(mutex_enter) 91 movq #0,%d0 92 movl _C_LABEL(curlwp),%d1 93 movl 4(%sp),%a0 94 casl %d0,%d1,(%a0) 95 bnes 1f 96 rts 971: jra _C_LABEL(mutex_vector_enter) 98 99/* 100 * void mutex_exit(kmutex_t *mtx); 101 */ 102ENTRY(mutex_exit) 103 movl _C_LABEL(curlwp),%d0 104 movq #0,%d1 105 movl 4(%sp),%a0 106 casl %d0,%d1,(%a0) 107 bnes 1f 108 rts 1091: jra _C_LABEL(mutex_vector_exit) 110#endif /* !__mc68010__ */ 111 112#endif /* !LOCKDEBUG */ 113