Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Amit Bhor, Kanika Nema: Codito Technologies 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/syscalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/tick.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/fpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) SYSCALL_DEFINE1(arc_settls, void *, user_tls_data_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	task_thread_info(current)->thr_ptr = (unsigned int)user_tls_data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * We return the user space TLS data ptr as sys-call return code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Ideally it should be copy to user.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * However we can cheat by the fact that some sys-calls do return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * absurdly high values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * Since the tls dat aptr is not going to be in range of 0xFFFF_xxxx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * it won't be considered a sys-call error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * and it will be loads better than copy-to-user, which is a definite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * D-TLB Miss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) SYSCALL_DEFINE0(arc_gettls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	return task_thread_info(current)->thr_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) SYSCALL_DEFINE3(arc_usr_cmpxchg, int __user *, uaddr, int, expected, int, new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	u32 uval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	 * This is only for old cores lacking LLOCK/SCOND, which by defintion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	 * can't possibly be SMP. Thus doesn't need to be SMP safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	 * And this also helps reduce the overhead for serializing in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * the UP case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	WARN_ON_ONCE(IS_ENABLED(CONFIG_SMP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	/* Z indicates to userspace if operation succeded */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	regs->status32 &= ~STATUS_Z_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	ret = access_ok(uaddr, sizeof(*uaddr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	preempt_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	ret = __get_user(uval, uaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		 goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (uval != expected)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		 goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ret = __put_user(new, uaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		 goto fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	regs->status32 |= STATUS_Z_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return uval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) fault:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	preempt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (unlikely(ret != -EFAULT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		 goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	mmap_read_lock(current->mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	ret = fixup_user_fault(current->mm, (unsigned long) uaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			       FAULT_FLAG_WRITE, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	mmap_read_unlock(current->mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (likely(!ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	force_sig(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #ifdef CONFIG_ISA_ARCV2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	/* Re-enable interrupts <= default irq priority before commiting SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	const unsigned int arg = 0x10 | ARCV2_IRQ_DEF_PRIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	__asm__ __volatile__(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		"sleep %0	\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		:"I"(arg)); /* can't be "r" has to be embedded const */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) #else	/* ARC700 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	/* sleep, but enable both set E1/E2 (levels of interrutps) before committing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	__asm__ __volatile__("sleep 0x3	\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) asmlinkage void ret_from_fork(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)  * Copy architecture-specific thread state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * Layout of Child kernel mode stack as setup at the end of this function is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * |     ...        |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * |     ...        |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * |    unused      |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * |                |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  * ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * |     r25        |   <==== top of Stack (thread.ksp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  * ~                ~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)  * |    --to--      |   (CALLEE Regs of kernel mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)  * |     r13        |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * |     fp         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * |    blink       |   @ret_from_fork
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * |                |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * ~                ~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  * ~                ~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * |                |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * |     r12        |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  * ~                ~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * |    --to--      |   (scratch Regs of user mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  * |     r0         |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)  * ------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)  * |      SP        |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)  * |    orig_r0     |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)  * |    event/ECR   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)  * |    user_r25    |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)  * ------------------  <===== END of PAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int copy_thread(unsigned long clone_flags, unsigned long usp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		unsigned long kthread_arg, struct task_struct *p,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct pt_regs *c_regs;        /* child's pt_regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	unsigned long *childksp;       /* to unwind out of __switch_to() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct callee_regs *c_callee;  /* child's callee regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct callee_regs *parent_callee;  /* paren't callee */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	/* Mark the specific anchors to begin with (see pic above) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	c_regs = task_pt_regs(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	childksp = (unsigned long *)c_regs - 2;  /* 2 words for FP/BLINK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	c_callee = ((struct callee_regs *)childksp) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	 * __switch_to() uses thread.ksp to start unwinding stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	 * For kernel threads we don't need to create callee regs, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	 * stack layout nevertheless needs to remain the same.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	 * Also, since __switch_to anyways unwinds callee regs, we use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	 * this to populate kernel thread entry-pt/args into callee regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	 * so that ret_from_kernel_thread() becomes simpler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	p->thread.ksp = (unsigned long)c_callee;	/* THREAD_KSP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	/* __switch_to expects FP(0), BLINK(return addr) at top */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	childksp[0] = 0;			/* fp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	childksp[1] = (unsigned long)ret_from_fork; /* blink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (unlikely(p->flags & PF_KTHREAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		memset(c_regs, 0, sizeof(struct pt_regs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		c_callee->r13 = kthread_arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		c_callee->r14 = usp;  /* function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	/*--------- User Task Only --------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	/* __switch_to expects FP(0), BLINK(return addr) at top of stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	childksp[0] = 0;				/* for POP fp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	childksp[1] = (unsigned long)ret_from_fork;	/* for POP blink */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	/* Copy parents pt regs on child's kernel mode stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	*c_regs = *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (usp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		c_regs->sp = usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	c_regs->r0 = 0;		/* fork returns 0 in child */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	parent_callee = ((struct callee_regs *)regs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	*c_callee = *parent_callee;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (unlikely(clone_flags & CLONE_SETTLS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		 * set task's userland tls data ptr from 4th arg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		 * clone C-lib call is difft from clone sys-call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		task_thread_info(p)->thr_ptr = tls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		/* Normal fork case: set parent's TLS ptr in child */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		task_thread_info(p)->thr_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		task_thread_info(current)->thr_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	 * setup usermode thread pointer #1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 * when child is picked by scheduler, __switch_to() uses @c_callee to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	 * populate usermode callee regs: this works (despite being in a kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	 * function) since special return path for child @ret_from_fork()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	 * ensures those regs are not clobbered all the way to RTIE to usermode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	c_callee->r25 = task_thread_info(p)->thr_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #ifdef CONFIG_ARC_CURR_IN_REG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	 * setup usermode thread pointer #2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	 * however for this special use of r25 in kernel, __switch_to() sets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * r25 for kernel needs and only in the final return path is usermode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * r25 setup, from pt_regs->user_r25. So set that up as well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	c_regs->user_r25 = c_callee->r25;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  * Do necessary setup to start up a new user task
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long usp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	regs->sp = usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	regs->ret = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 * [U]ser Mode bit set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 * [L] ZOL loop inhibited to begin with - cleared by a LP insn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	 * Interrupts enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	regs->status32 = STATUS_U_MASK | STATUS_L_MASK | ISA_INIT_STATUS_BITS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	fpu_init_task(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	/* bogus seed values for debugging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	regs->lp_start = 0x10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	regs->lp_end = 0x80;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * Some archs flush debug and FPU info here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) void flush_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) int elf_check_arch(const struct elf32_hdr *x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	unsigned int eflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (x->e_machine != EM_ARC_INUSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		pr_err("ELF not built for %s ISA\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			is_isa_arcompact() ? "ARCompact":"ARCv2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	eflags = x->e_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if ((eflags & EF_ARC_OSABI_MSK) != EF_ARC_OSABI_CURRENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		pr_err("ABI mismatch - you need newer toolchain\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		force_sigsegv(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) EXPORT_SYMBOL(elf_check_arch);