1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <stdio.h>
19#include <stdbool.h>
20#include <stdint.h>
21
22
23
24
25
26int err;
27
28static void __check32(int line, uint32_t result, uint32_t expect)
29{
30 if (result != expect) {
31 printf("ERROR at line %d: 0x%08x != 0x%08x\n",
32 line, result, expect);
33 err++;
34 }
35}
36
37#define check32(RES, EXP) __check32(__LINE__, RES, EXP)
38
39static void __check64(int line, uint64_t result, uint64_t expect)
40{
41 if (result != expect) {
42 printf("ERROR at line %d: 0x%016llx != 0x%016llx\n",
43 line, result, expect);
44 err++;
45 }
46}
47
48#define check64(RES, EXP) __check64(__LINE__, RES, EXP)
49
50static bool my_func_called;
51
52static void my_func(void)
53{
54 my_func_called = true;
55}
56
57static inline void callrh(void *func)
58{
59 asm volatile("callrh %0\n\t"
60 : : "r"(func)
61
62 : "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
63 "r10", "r11", "r12", "r13", "r14", "r15", "r28",
64 "p0", "p1", "p2", "p3");
65}
66
67static void test_callrh(void)
68{
69 my_func_called = false;
70 callrh(&my_func);
71 check32(my_func_called, true);
72}
73
74static void test_jumprh(void)
75{
76 uint32_t res;
77 asm ("%0 = #5\n\t"
78 "r0 = ##1f\n\t"
79 "jumprh r0\n\t"
80 "%0 = #3\n\t"
81 "jump 2f\n\t"
82 "1:\n\t"
83 "%0 = #1\n\t"
84 "2:\n\t"
85 : "=r"(res) : : "r0");
86 check32(res, 1);
87}
88
89int main()
90{
91 test_callrh();
92 test_jumprh();
93
94 puts(err ? "FAIL" : "PASS");
95 return err ? 1 : 0;
96}
97