4 * Copyright (c) 2013 Stacey D. Son
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #ifndef _TARGET_ARCH_THREAD_H_
20 #define _TARGET_ARCH_THREAD_H_
22 /* Compare to arm/arm/vm_machdep.c cpu_set_upcall_kse() */
23 static inline void target_thread_set_upcall(CPUARMState
*env
, abi_ulong entry
,
24 abi_ulong arg
, abi_ulong stack_base
, abi_ulong stack_size
)
29 * Make sure the stack is properly aligned.
30 * arm/include/param.h (STACKLIGN() macro)
32 sp
= (u_int
)(stack_base
+ stack_size
) & ~0x7;
36 /* pc = start function entry */
37 env
->regs
[15] = entry
& 0xfffffffe;
40 env
->spsr
= ARM_CPU_MODE_USR
;
42 * Thumb mode is encoded by the low bit in the entry point (since ARM can't
43 * execute at odd addresses). When it's set, set the Thumb bit (T) in the
46 cpsr_write(env
, (entry
& 1) * CPSR_T
, CPSR_T
, CPSRWriteByInstr
);
49 static inline void target_thread_init(struct target_pt_regs
*regs
,
50 struct image_info
*infop
)
52 abi_long stack
= infop
->start_stack
;
53 memset(regs
, 0, sizeof(*regs
));
54 regs
->ARM_cpsr
= ARM_CPU_MODE_USR
;
56 * Thumb mode is encoded by the low bit in the entry point (since ARM can't
57 * execute at odd addresses). When it's set, set the Thumb bit (T) in the
60 if (infop
->entry
& 1) {
61 regs
->ARM_cpsr
|= CPSR_T
;
63 regs
->ARM_pc
= infop
->entry
& 0xfffffffe;
65 regs
->ARM_lr
= infop
->entry
& 0xfffffffe;
67 * FreeBSD kernel passes the ps_strings pointer in r0. This is used by some
68 * programs to set status messages that we see in ps. bsd-user doesn't
69 * support that functionality, so it's ignored. When set to 0, FreeBSD's csu
70 * code ignores it. For the static case, r1 and r2 are effectively ignored
71 * by the csu __startup() routine. For the dynamic case, rtld saves r0 but
72 * generates r1 and r2 and passes them into the csu _startup.
74 * r0 ps_strings 0 passed since ps arg setting not supported
75 * r1 obj_main ignored by _start(), so 0 passed
76 * r2 cleanup generated by rtld or ignored by _start(), so 0 passed
80 #endif /* !_TARGET_ARCH_THREAD_H_ */