1 /*
2 * Copyright (c) 2015-2022 The strace developers.
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7
8 static unsigned int xtensa_probe_naregs(struct tcb *tcp)
9 {
10 struct user_pt_regs tmp = xtensa_regs;
11 unsigned int n = 8;
12
13 do {
14 n *= 2;
15 xtensa_regs.windowbase = n / 4;
16 } while (n < ARRAY_SIZE(xtensa_regs.a) &&
17 set_regs(tcp->pid) == 0);
18 xtensa_regs = tmp;
19 set_regs(tcp->pid);
20 return n;
21 }
22
23 /* Return -1 on error or 1 on success (never 0!). */
24 static int
25 arch_get_syscall_args(struct tcb *tcp)
26 {
27 static const unsigned int syscall_regs[MAX_ARGS] = { 6, 3, 4, 5, 8, 9 };
28 static unsigned int naregs_mask;
29
30 if (naregs_mask == 0)
31 naregs_mask = xtensa_probe_naregs(tcp) - 1;
32
33 for (unsigned int i = 0; i < n_args(tcp); ++i)
34 tcp->u_arg[i] = xtensa_regs.a[(xtensa_regs.windowbase * 4 +
35 syscall_regs[i]) & naregs_mask];
36 return 1;
37 }