v / thirdparty / libatomic_ops / atomic_ops / sysdeps / gcc / m68k.h
68 lines · 58 sloc · 2.14 KB · f53b5d737fd636890520101e736ad29e20d3c322
Raw
1/*
2 * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
3 * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved.
4 * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved.
5 *
6 *
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
9 *
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
15 *
16 */
17
18/* The cas instruction causes an emulation trap for the */
19/* 060 with a misaligned pointer, so let's avoid this. */
20#undef AO_t
21typedef unsigned long AO_t __attribute__((__aligned__(4)));
22
23/* FIXME. Very incomplete. */
24#include "../all_aligned_atomic_load_store.h"
25
26/* Are there any m68k multiprocessors still around? */
27/* AFAIK, Alliants were sequentially consistent. */
28#include "../ordered.h"
29
30#include "../test_and_set_t_is_char.h"
31
32AO_INLINE AO_TS_VAL_t
33AO_test_and_set_full(volatile AO_TS_t *addr) {
34 AO_TS_t oldval;
35
36 /* The value at addr is semi-phony. */
37 /* 'tas' sets bit 7 while the return */
38 /* value pretends all bits were set, */
39 /* which at least matches AO_TS_SET. */
40 __asm__ __volatile__(
41 "tas %1; sne %0"
42 : "=d" (oldval), "=m" (*addr)
43 : "m" (*addr)
44 : "memory");
45 /* This cast works due to the above. */
46 return (AO_TS_VAL_t)oldval;
47}
48#define AO_HAVE_test_and_set_full
49
50/* Returns nonzero if the comparison succeeded. */
51AO_INLINE int
52AO_compare_and_swap_full(volatile AO_t *addr,
53 AO_t old, AO_t new_val)
54{
55 char result;
56
57 __asm__ __volatile__(
58 "cas.l %3,%4,%1; seq %0"
59 : "=d" (result), "=m" (*addr)
60 : "m" (*addr), "d" (old), "d" (new_val)
61 : "memory");
62 return -result;
63}
64#define AO_HAVE_compare_and_swap_full
65
66/* TODO: implement AO_fetch_compare_and_swap. */
67
68#define AO_T_IS_INT
69