3b07478c3e885762c52415882f40b0cb21be1a49
[external/binutils.git] / gdb / testsuite / gdb.arch / aarch64-atomic-inst.c
1 /* This file is part of GDB, the GNU debugger.
2
3    Copyright 2008-2016 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 int main(void)
19 {
20   unsigned long tmp, cond;
21   unsigned long dword = 0;
22
23   /* Test that we can step over ldxr/stxr. This sequence should step from
24      ldxr to the following __asm __volatile.  */
25   __asm __volatile ("1:     ldxr    %0,%2\n"                             \
26                     "       cmp     %0,#1\n"                             \
27                     "       b.eq    out\n"                               \
28                     "       add     %0,%0,1\n"                           \
29                     "       stxr    %w1,%0,%2\n"                         \
30                     "       cbnz    %w1,1b"                              \
31                     : "=&r" (tmp), "=&r" (cond), "+Q" (dword)            \
32                     : : "memory");
33
34   /* This sequence should take the conditional branch and step from ldxr
35      to the return dword line.  */
36   __asm __volatile ("1:     ldxr    %0,%2\n"                             \
37                     "       cmp     %0,#1\n"                             \
38                     "       b.eq    out\n"                               \
39                     "       add     %0,%0,1\n"                           \
40                     "       stxr    %w1,%0,%2\n"                         \
41                     "       cbnz    %w1,1b\n"                            \
42                     : "=&r" (tmp), "=&r" (cond), "+Q" (dword)            \
43                     : : "memory");
44
45   dword = -1;
46 __asm __volatile ("out:\n");
47   return dword;
48 }