xref: /openbmc/qemu/tests/tcg/hexagon/dual_stores.c (revision 825d6eba)
1*825d6ebaSTaylor Simpson /*
2*825d6ebaSTaylor Simpson  *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
3*825d6ebaSTaylor Simpson  *
4*825d6ebaSTaylor Simpson  *  This program is free software; you can redistribute it and/or modify
5*825d6ebaSTaylor Simpson  *  it under the terms of the GNU General Public License as published by
6*825d6ebaSTaylor Simpson  *  the Free Software Foundation; either version 2 of the License, or
7*825d6ebaSTaylor Simpson  *  (at your option) any later version.
8*825d6ebaSTaylor Simpson  *
9*825d6ebaSTaylor Simpson  *  This program is distributed in the hope that it will be useful,
10*825d6ebaSTaylor Simpson  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11*825d6ebaSTaylor Simpson  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12*825d6ebaSTaylor Simpson  *  GNU General Public License for more details.
13*825d6ebaSTaylor Simpson  *
14*825d6ebaSTaylor Simpson  *  You should have received a copy of the GNU General Public License
15*825d6ebaSTaylor Simpson  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
16*825d6ebaSTaylor Simpson  */
17*825d6ebaSTaylor Simpson 
18*825d6ebaSTaylor Simpson #include <stdio.h>
19*825d6ebaSTaylor Simpson 
20*825d6ebaSTaylor Simpson /*
21*825d6ebaSTaylor Simpson  *  Make sure that two stores in the same packet honor proper
22*825d6ebaSTaylor Simpson  *  semantics: slot 1 executes first, then slot 0.
23*825d6ebaSTaylor Simpson  *  This is important when the addresses overlap.
24*825d6ebaSTaylor Simpson  */
25*825d6ebaSTaylor Simpson static inline void dual_stores(int *p, char *q, int x, char y)
26*825d6ebaSTaylor Simpson {
27*825d6ebaSTaylor Simpson   asm volatile("{\n\t"
28*825d6ebaSTaylor Simpson                "    memw(%0) = %2\n\t"
29*825d6ebaSTaylor Simpson                "    memb(%1) = %3\n\t"
30*825d6ebaSTaylor Simpson                "}\n"
31*825d6ebaSTaylor Simpson                :: "r"(p), "r"(q), "r"(x), "r"(y)
32*825d6ebaSTaylor Simpson                : "memory");
33*825d6ebaSTaylor Simpson }
34*825d6ebaSTaylor Simpson 
35*825d6ebaSTaylor Simpson typedef union {
36*825d6ebaSTaylor Simpson     int word;
37*825d6ebaSTaylor Simpson     char byte;
38*825d6ebaSTaylor Simpson } Dual;
39*825d6ebaSTaylor Simpson 
40*825d6ebaSTaylor Simpson int err;
41*825d6ebaSTaylor Simpson 
42*825d6ebaSTaylor Simpson static void check(Dual d, int expect)
43*825d6ebaSTaylor Simpson {
44*825d6ebaSTaylor Simpson     if (d.word != expect) {
45*825d6ebaSTaylor Simpson         printf("ERROR: 0x%08x != 0x%08x\n", d.word, expect);
46*825d6ebaSTaylor Simpson         err++;
47*825d6ebaSTaylor Simpson     }
48*825d6ebaSTaylor Simpson }
49*825d6ebaSTaylor Simpson 
50*825d6ebaSTaylor Simpson int main()
51*825d6ebaSTaylor Simpson {
52*825d6ebaSTaylor Simpson     Dual d;
53*825d6ebaSTaylor Simpson 
54*825d6ebaSTaylor Simpson     d.word = ~0;
55*825d6ebaSTaylor Simpson     dual_stores(&d.word, &d.byte, 0x12345678, 0xff);
56*825d6ebaSTaylor Simpson     check(d, 0x123456ff);
57*825d6ebaSTaylor Simpson 
58*825d6ebaSTaylor Simpson     puts(err ? "FAIL" : "PASS");
59*825d6ebaSTaylor Simpson     return err;
60*825d6ebaSTaylor Simpson }
61