1*00c07344SRichard Henderson #include "../multiarch/noexec.c.inc"
2*00c07344SRichard Henderson
arch_mcontext_pc(const mcontext_t * ctx)3*00c07344SRichard Henderson static void *arch_mcontext_pc(const mcontext_t *ctx)
4*00c07344SRichard Henderson {
5*00c07344SRichard Henderson return (void *)ctx->__gregs[REG_PC];
6*00c07344SRichard Henderson }
7*00c07344SRichard Henderson
arch_mcontext_arg(const mcontext_t * ctx)8*00c07344SRichard Henderson static int arch_mcontext_arg(const mcontext_t *ctx)
9*00c07344SRichard Henderson {
10*00c07344SRichard Henderson return ctx->__gregs[REG_A0];
11*00c07344SRichard Henderson }
12*00c07344SRichard Henderson
arch_flush(void * p,int len)13*00c07344SRichard Henderson static void arch_flush(void *p, int len)
14*00c07344SRichard Henderson {
15*00c07344SRichard Henderson __builtin___clear_cache(p, p + len);
16*00c07344SRichard Henderson }
17*00c07344SRichard Henderson
18*00c07344SRichard Henderson extern char noexec_1[];
19*00c07344SRichard Henderson extern char noexec_2[];
20*00c07344SRichard Henderson extern char noexec_end[];
21*00c07344SRichard Henderson
22*00c07344SRichard Henderson asm(".option push\n"
23*00c07344SRichard Henderson ".option norvc\n"
24*00c07344SRichard Henderson "noexec_1:\n"
25*00c07344SRichard Henderson " li a0,1\n" /* a0 is 0 on entry, set 1. */
26*00c07344SRichard Henderson "noexec_2:\n"
27*00c07344SRichard Henderson " li a0,2\n" /* a0 is 0/1; set 2. */
28*00c07344SRichard Henderson " ret\n"
29*00c07344SRichard Henderson "noexec_end:\n"
30*00c07344SRichard Henderson ".option pop");
31*00c07344SRichard Henderson
main(void)32*00c07344SRichard Henderson int main(void)
33*00c07344SRichard Henderson {
34*00c07344SRichard Henderson struct noexec_test noexec_tests[] = {
35*00c07344SRichard Henderson {
36*00c07344SRichard Henderson .name = "fallthrough",
37*00c07344SRichard Henderson .test_code = noexec_1,
38*00c07344SRichard Henderson .test_len = noexec_end - noexec_1,
39*00c07344SRichard Henderson .page_ofs = noexec_1 - noexec_2,
40*00c07344SRichard Henderson .entry_ofs = noexec_1 - noexec_2,
41*00c07344SRichard Henderson .expected_si_ofs = 0,
42*00c07344SRichard Henderson .expected_pc_ofs = 0,
43*00c07344SRichard Henderson .expected_arg = 1,
44*00c07344SRichard Henderson },
45*00c07344SRichard Henderson {
46*00c07344SRichard Henderson .name = "jump",
47*00c07344SRichard Henderson .test_code = noexec_1,
48*00c07344SRichard Henderson .test_len = noexec_end - noexec_1,
49*00c07344SRichard Henderson .page_ofs = noexec_1 - noexec_2,
50*00c07344SRichard Henderson .entry_ofs = 0,
51*00c07344SRichard Henderson .expected_si_ofs = 0,
52*00c07344SRichard Henderson .expected_pc_ofs = 0,
53*00c07344SRichard Henderson .expected_arg = 0,
54*00c07344SRichard Henderson },
55*00c07344SRichard Henderson {
56*00c07344SRichard Henderson .name = "fallthrough [cross]",
57*00c07344SRichard Henderson .test_code = noexec_1,
58*00c07344SRichard Henderson .test_len = noexec_end - noexec_1,
59*00c07344SRichard Henderson .page_ofs = noexec_1 - noexec_2 - 2,
60*00c07344SRichard Henderson .entry_ofs = noexec_1 - noexec_2 - 2,
61*00c07344SRichard Henderson .expected_si_ofs = 0,
62*00c07344SRichard Henderson .expected_pc_ofs = -2,
63*00c07344SRichard Henderson .expected_arg = 1,
64*00c07344SRichard Henderson },
65*00c07344SRichard Henderson {
66*00c07344SRichard Henderson .name = "jump [cross]",
67*00c07344SRichard Henderson .test_code = noexec_1,
68*00c07344SRichard Henderson .test_len = noexec_end - noexec_1,
69*00c07344SRichard Henderson .page_ofs = noexec_1 - noexec_2 - 2,
70*00c07344SRichard Henderson .entry_ofs = -2,
71*00c07344SRichard Henderson .expected_si_ofs = 0,
72*00c07344SRichard Henderson .expected_pc_ofs = -2,
73*00c07344SRichard Henderson .expected_arg = 0,
74*00c07344SRichard Henderson },
75*00c07344SRichard Henderson };
76*00c07344SRichard Henderson
77*00c07344SRichard Henderson return test_noexec(noexec_tests,
78*00c07344SRichard Henderson sizeof(noexec_tests) / sizeof(noexec_tests[0]));
79*00c07344SRichard Henderson }
80