Home | History | Annotate | Line # | Download | only in gdb.base
      1 /* This testcase is part of GDB, the GNU debugger.
      2 
      3    Copyright 2017-2024 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 #include <stdint.h>
     19 #include <assert.h>
     20 
     21 static int again;
     22 
     23 static volatile struct
     24 {
     25   uint64_t alignment;
     26   union
     27     {
     28       uint64_t size8[1];
     29       uint32_t size4[2];
     30       uint16_t size2[4];
     31       uint8_t size1[8];
     32       uint64_t size8twice[3];
     33     }
     34   u;
     35 } data;
     36 
     37 static int size = 0;
     38 static int offset;
     39 
     40 static void
     41 write_size8twice (void)
     42 {
     43   static const uint64_t first = 1;
     44   static const uint64_t second = 2;
     45 
     46 #ifdef __aarch64__
     47   volatile void *p = &data.u.size8twice[offset];
     48   asm volatile ("stp %1, %2, [%0]"
     49 		: /* output */
     50 		: "r" (p), "r" (first), "r" (second) /* input */
     51 		: "memory" /* clobber */);
     52 #else
     53   data.u.size8twice[offset] = first;
     54   data.u.size8twice[offset + 1] = second;
     55 #endif
     56 }
     57 
     58 int
     59 main (void)
     60 {
     61   volatile uint64_t local;
     62 
     63   assert (sizeof (data) == 8 + 3 * 8);
     64 
     65   write_size8twice ();
     66 
     67   while (size)
     68     {
     69       switch (size)
     70 	{
     71 /* __s390x__ also defines __s390__ */
     72 #ifdef __s390__
     73 # define ACCESS(var) var = ~var
     74 #else
     75 # define ACCESS(var) local = var
     76 #endif
     77 	case 8:
     78 	  ACCESS (data.u.size8[offset]);
     79 	  break;
     80 	case 4:
     81 	  ACCESS (data.u.size4[offset]);
     82 	  break;
     83 	case 2:
     84 	  ACCESS (data.u.size2[offset]);
     85 	  break;
     86 	case 1:
     87 	  ACCESS (data.u.size1[offset]);
     88 	  break;
     89 #undef ACCESS
     90 	default:
     91 	  assert (0);
     92 	}
     93       size = 0;
     94       size = size; /* start_again */
     95     }
     96   return 0; /* final_return */
     97 }
     98