[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 14/30] bsd-user/arm/target_arch_thread.h: Routines to create a
From: |
Warner Losh |
Subject: |
[PATCH v2 14/30] bsd-user/arm/target_arch_thread.h: Routines to create and switch to a thread |
Date: |
Tue, 2 Nov 2021 16:52:32 -0600 |
Implement target_thread_init (to create a thread) and target_set_upcall
(to switch to a thread) for arm.
Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Warner Losh <imp@bsdimp.com>
Reviewed-by: Kyle Evans <kevans@FreeBSD.org>
---
bsd-user/arm/target_arch_thread.h | 80 +++++++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
create mode 100644 bsd-user/arm/target_arch_thread.h
diff --git a/bsd-user/arm/target_arch_thread.h
b/bsd-user/arm/target_arch_thread.h
new file mode 100644
index 0000000000..ae5b0d6c38
--- /dev/null
+++ b/bsd-user/arm/target_arch_thread.h
@@ -0,0 +1,80 @@
+/*
+ * arm thread support
+ *
+ * Copyright (c) 2013 Stacey D. Son
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _TARGET_ARCH_THREAD_H_
+#define _TARGET_ARCH_THREAD_H_
+
+/* Compare to arm/arm/vm_machdep.c cpu_set_upcall_kse() */
+static inline void target_thread_set_upcall(CPUARMState *env, abi_ulong entry,
+ abi_ulong arg, abi_ulong stack_base, abi_ulong stack_size)
+{
+ abi_ulong sp;
+
+ /*
+ * Make sure the stack is properly aligned.
+ * arm/include/param.h (STACKLIGN() macro)
+ */
+ sp = (u_int)(stack_base + stack_size) & ~0x7;
+
+ /* sp = stack base */
+ env->regs[13] = sp;
+ /* pc = start function entry */
+ env->regs[15] = entry & 0xfffffffe;
+ /* r0 = arg */
+ env->regs[0] = arg;
+ env->spsr = ARM_CPU_MODE_USR;
+ /*
+ * Thumb mode is encoded by the low bit in the entry point (since ARM can't
+ * execute at odd addresses). When it's set, set the Thumb bit (T) in the
+ * CPSR.
+ */
+ if (entry & 0x1) {
+ cpsr_write(env, cpsr_read(env) | CPSR_T, CPSR_T, CPSRWriteByInstr);
+ }
+}
+
+static inline void target_thread_init(struct target_pt_regs *regs,
+ struct image_info *infop)
+{
+ abi_long stack = infop->start_stack;
+ memset(regs, 0, sizeof(*regs));
+ regs->ARM_cpsr = 0x10;
+ /*
+ * Thumb mode is encoded by the low bit in the entry point (since ARM can't
+ * execute at odd addresses). When it's set, set the Thumb bit (T) in the
+ * CPSR.
+ */
+ if (infop->entry & 1) {
+ regs->ARM_cpsr |= CPSR_T;
+ }
+ regs->ARM_pc = infop->entry & 0xfffffffe;
+ regs->ARM_sp = infop->start_stack;
+ if (bsd_type == target_freebsd) {
+ regs->ARM_lr = infop->entry & 0xfffffffe;
+ }
+ /* FIXME - what to for failure of get_user()? */
+ get_user_ual(regs->ARM_r2, stack + 8); /* envp */
+ get_user_ual(regs->ARM_r1, stack + 4); /* envp */
+ /* XXX: it seems that r0 is zeroed after ! */
+ regs->ARM_r0 = 0;
+ /* For uClinux PIC binaries. */
+ /* XXX: Linux does this only on ARM with no MMU (do we care ?) */
+ regs->ARM_r10 = infop->start_data;
+}
+
+#endif /* !_TARGET_ARCH_THREAD_H_ */
--
2.33.0
- [PATCH v2 06/30] bsd-user/arm/target_arch_cpu.h: Implement target_cpu_clone_regs, (continued)
- [PATCH v2 06/30] bsd-user/arm/target_arch_cpu.h: Implement target_cpu_clone_regs, Warner Losh, 2021/11/02
- [PATCH v2 11/30] bsd-user/arm/target_arch_reg.h: Implement core dump register copying, Warner Losh, 2021/11/02
- [PATCH v2 07/30] bsd-user/arm/target_arch_cpu.h: Dummy target_cpu_loop implementation, Warner Losh, 2021/11/02
- [PATCH v2 09/30] bsd-user/arm/target_arch_cpu.h: Implement data abort exceptions, Warner Losh, 2021/11/02
- [PATCH v2 08/30] bsd-user/arm/target_arch_cpu.h: Implement trivial EXCP exceptions, Warner Losh, 2021/11/02
- [PATCH v2 10/30] bsd-user/arm/target_arch_cpu.h: Implement system call dispatch, Warner Losh, 2021/11/02
- [PATCH v2 12/30] bsd-user/arm/target_arch_vmparam.h: Parameters for arm address space, Warner Losh, 2021/11/02
- [PATCH v2 13/30] bsd-user/arm/target_arch_sigtramp.h: Signal Trampoline for arm, Warner Losh, 2021/11/02
- [PATCH v2 14/30] bsd-user/arm/target_arch_thread.h: Routines to create and switch to a thread,
Warner Losh <=
- [PATCH v2 15/30] bsd-user/arm/target_arch_elf.h: arm defines for ELF, Warner Losh, 2021/11/02
- [PATCH v2 17/30] bsd-user/arm/target_arch_elf.h: arm get_hwcap2 impl, Warner Losh, 2021/11/02
- [PATCH v2 19/30] bsd-user/arm/target_arch_signal.h: arm specific signal registers and stack, Warner Losh, 2021/11/02
- [PATCH v2 18/30] bsd-user/freebsd: Create common target_os_ucontext.h file, Warner Losh, 2021/11/02
- [PATCH v2 22/30] bsd-user/arm/target_arch_signal.h: arm set_sigtramp_args, Warner Losh, 2021/11/02