1c23b5764STaylor Simpson /*
2*0d57cd61STaylor Simpson * Copyright(c) 2021-2023 Qualcomm Innovation Center, Inc. All Rights Reserved.
3c23b5764STaylor Simpson *
4c23b5764STaylor Simpson * This program is free software; you can redistribute it and/or modify
5c23b5764STaylor Simpson * it under the terms of the GNU General Public License as published by
6c23b5764STaylor Simpson * the Free Software Foundation; either version 2 of the License, or
7c23b5764STaylor Simpson * (at your option) any later version.
8c23b5764STaylor Simpson *
9c23b5764STaylor Simpson * This program is distributed in the hope that it will be useful,
10c23b5764STaylor Simpson * but WITHOUT ANY WARRANTY; without even the implied warranty of
11c23b5764STaylor Simpson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12c23b5764STaylor Simpson * GNU General Public License for more details.
13c23b5764STaylor Simpson *
14c23b5764STaylor Simpson * You should have received a copy of the GNU General Public License
15c23b5764STaylor Simpson * along with this program; if not, see <http://www.gnu.org/licenses/>.
16c23b5764STaylor Simpson */
17c23b5764STaylor Simpson
18c23b5764STaylor Simpson /*
19c23b5764STaylor Simpson * Test the VLIW semantics of two stores in a packet
20c23b5764STaylor Simpson *
21c23b5764STaylor Simpson * When a packet has 2 stores, either both commit or neither commit.
22c23b5764STaylor Simpson * We test this with a packet that does stores to both NULL and a global
23c23b5764STaylor Simpson * variable, "should_not_change". After the SIGSEGV is caught, we check
24c23b5764STaylor Simpson * that the "should_not_change" value is the same.
25c23b5764STaylor Simpson */
26c23b5764STaylor Simpson
27c23b5764STaylor Simpson #include <stdlib.h>
28*0d57cd61STaylor Simpson #include <stdint.h>
29*0d57cd61STaylor Simpson #include <stdbool.h>
30c23b5764STaylor Simpson #include <stdio.h>
31c23b5764STaylor Simpson #include <unistd.h>
32c23b5764STaylor Simpson #include <sys/types.h>
33c23b5764STaylor Simpson #include <fcntl.h>
34c23b5764STaylor Simpson #include <setjmp.h>
35c23b5764STaylor Simpson #include <signal.h>
36c23b5764STaylor Simpson
37c23b5764STaylor Simpson int err;
38*0d57cd61STaylor Simpson
39*0d57cd61STaylor Simpson #include "hex_test.h"
40*0d57cd61STaylor Simpson
41*0d57cd61STaylor Simpson bool segv_caught;
42c23b5764STaylor Simpson
43c23b5764STaylor Simpson #define SHOULD_NOT_CHANGE_VAL 5
44*0d57cd61STaylor Simpson int32_t should_not_change = SHOULD_NOT_CHANGE_VAL;
45c23b5764STaylor Simpson
46c23b5764STaylor Simpson #define BUF_SIZE 300
47*0d57cd61STaylor Simpson uint8_t buf[BUF_SIZE];
48c23b5764STaylor Simpson jmp_buf jmp_env;
49c23b5764STaylor Simpson
sig_segv(int sig,siginfo_t * info,void * puc)50c23b5764STaylor Simpson static void sig_segv(int sig, siginfo_t *info, void *puc)
51c23b5764STaylor Simpson {
52*0d57cd61STaylor Simpson check32(sig, SIGSEGV);
53*0d57cd61STaylor Simpson segv_caught = true;
54c23b5764STaylor Simpson longjmp(jmp_env, 1);
55c23b5764STaylor Simpson }
56c23b5764STaylor Simpson
main()57c23b5764STaylor Simpson int main()
58c23b5764STaylor Simpson {
59c23b5764STaylor Simpson struct sigaction act;
60c23b5764STaylor Simpson
61c23b5764STaylor Simpson /* SIGSEGV test */
62c23b5764STaylor Simpson act.sa_sigaction = sig_segv;
63c23b5764STaylor Simpson sigemptyset(&act.sa_mask);
64c23b5764STaylor Simpson act.sa_flags = SA_SIGINFO;
65c23b5764STaylor Simpson chk_error(sigaction(SIGSEGV, &act, NULL));
66c23b5764STaylor Simpson if (setjmp(jmp_env) == 0) {
67c23b5764STaylor Simpson asm volatile("r18 = ##should_not_change\n\t"
68c23b5764STaylor Simpson "r19 = #0\n\t"
69c23b5764STaylor Simpson "{\n\t"
70c23b5764STaylor Simpson " memw(r18) = #7\n\t"
71c23b5764STaylor Simpson " memw(r19) = #0\n\t"
72c23b5764STaylor Simpson "}\n\t"
73c23b5764STaylor Simpson : : : "r18", "r19", "memory");
74c23b5764STaylor Simpson }
75c23b5764STaylor Simpson
76c23b5764STaylor Simpson act.sa_handler = SIG_DFL;
77c23b5764STaylor Simpson sigemptyset(&act.sa_mask);
78c23b5764STaylor Simpson act.sa_flags = 0;
79c23b5764STaylor Simpson chk_error(sigaction(SIGSEGV, &act, NULL));
80c23b5764STaylor Simpson
81*0d57cd61STaylor Simpson check32(segv_caught, true);
82*0d57cd61STaylor Simpson check32(should_not_change, SHOULD_NOT_CHANGE_VAL);
83c23b5764STaylor Simpson
84c23b5764STaylor Simpson puts(err ? "FAIL" : "PASS");
85c23b5764STaylor Simpson return err ? EXIT_FAILURE : EXIT_SUCCESS;
86c23b5764STaylor Simpson }
87