master
h 69 lines 2.27 KB
Raw
1 /*
2 * arm thread support
3 *
4 * Copyright (c) 2013 Stacey D. Son
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8 #ifndef TARGET_ARCH_THREAD_H
9 #define TARGET_ARCH_THREAD_H
10
11 /* Compare to arm/arm/vm_machdep.c cpu_set_upcall_kse() */
12 static inline void target_thread_set_upcall(CPUARMState *env, abi_ulong entry,
13 abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
14 {
15 abi_ulong sp;
16
17 /*
18 * Make sure the stack is properly aligned.
19 * arm/include/param.h (STACKLIGN() macro)
20 */
21 sp = (u_int)(stack_base + stack_size) & ~0x7;
22
23 /* sp = stack base */
24 env->regs[13] = sp;
25 /* pc = start function entry */
26 env->regs[15] = entry & 0xfffffffe;
27 /* r0 = arg */
28 env->regs[0] = arg;
29 env->spsr = ARM_CPU_MODE_USR;
30 /*
31 * Thumb mode is encoded by the low bit in the entry point (since ARM can't
32 * execute at odd addresses). When it's set, set the Thumb bit (T) in the
33 * CPSR.
34 */
35 cpsr_write(env, (entry & 1) * CPSR_T, CPSR_T, CPSRWriteByInstr);
36 }
37
38 static inline void target_thread_init(struct target_pt_regs *regs,
39 struct image_info *infop)
40 {
41 abi_long stack = infop->start_stack;
42 memset(regs, 0, sizeof(*regs));
43 regs->ARM_cpsr = ARM_CPU_MODE_USR;
44 /*
45 * Thumb mode is encoded by the low bit in the entry point (since ARM can't
46 * execute at odd addresses). When it's set, set the Thumb bit (T) in the
47 * CPSR.
48 */
49 if (infop->entry & 1) {
50 regs->ARM_cpsr |= CPSR_T;
51 }
52 regs->ARM_pc = infop->entry & 0xfffffffe;
53 regs->ARM_sp = stack;
54 regs->ARM_lr = infop->entry & 0xfffffffe;
55 /*
56 * FreeBSD kernel passes the ps_strings pointer in r0. This is used by some
57 * programs to set status messages that we see in ps. bsd-user doesn't
58 * support that functionality, so it's ignored. When set to 0, FreeBSD's csu
59 * code ignores it. For the static case, r1 and r2 are effectively ignored
60 * by the csu __startup() routine. For the dynamic case, rtld saves r0 but
61 * generates r1 and r2 and passes them into the csu _startup.
62 *
63 * r0 ps_strings 0 passed since ps arg setting not supported
64 * r1 obj_main ignored by _start(), so 0 passed
65 * r2 cleanup generated by rtld or ignored by _start(), so 0 passed
66 */
67 }
68
69 #endif /* TARGET_ARCH_THREAD_H */