Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / cris / arch-v32 / kernel / process.c
bloba02f276d0ed4205329168f3e3d5f630eba666e3e
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2000-2003 Axis Communications AB
5 * Authors: Bjorn Wesen (bjornw@axis.com)
6 * Mikael Starvik (starvik@axis.com)
7 * Tobias Anderberg (tobiasa@axis.com), CRISv32 port.
9 * This file handles the architecture-dependent parts of process handling..
12 #include <linux/sched.h>
13 #include <linux/sched/debug.h>
14 #include <linux/sched/task.h>
15 #include <linux/sched/task_stack.h>
16 #include <linux/slab.h>
17 #include <linux/err.h>
18 #include <linux/fs.h>
19 #include <hwregs/reg_rdwr.h>
20 #include <hwregs/reg_map.h>
21 #include <hwregs/timer_defs.h>
22 #include <hwregs/intr_vect_defs.h>
23 #include <linux/ptrace.h>
25 extern void stop_watchdog(void);
27 /* We use this if we don't have any better idle routine. */
28 void default_idle(void)
30 local_irq_enable();
31 /* Halt until exception. */
32 __asm__ volatile("halt");
36 * Free current thread data structures etc..
39 extern void deconfigure_bp(long pid);
40 void exit_thread(struct task_struct *tsk)
42 deconfigure_bp(tsk->pid);
46 * If the watchdog is enabled, disable interrupts and enter an infinite loop.
47 * The watchdog will reset the CPU after 0.1s. If the watchdog isn't enabled
48 * then enable it and wait.
50 extern void arch_enable_nmi(void);
52 void
53 hard_reset_now(void)
56 * Don't declare this variable elsewhere. We don't want any other
57 * code to know about it than the watchdog handler in entry.S and
58 * this code, implementing hard reset through the watchdog.
60 #if defined(CONFIG_ETRAX_WATCHDOG)
61 extern int cause_of_death;
62 #endif
64 printk("*** HARD RESET ***\n");
65 local_irq_disable();
67 #if defined(CONFIG_ETRAX_WATCHDOG)
68 cause_of_death = 0xbedead;
69 #else
71 reg_timer_rw_wd_ctrl wd_ctrl = {0};
73 stop_watchdog();
75 wd_ctrl.key = 16; /* Arbitrary key. */
76 wd_ctrl.cnt = 1; /* Minimum time. */
77 wd_ctrl.cmd = regk_timer_start;
79 arch_enable_nmi();
80 REG_WR(timer, regi_timer0, rw_wd_ctrl, wd_ctrl);
82 #endif
84 while (1)
85 ; /* Wait for reset. */
89 * Setup the child's kernel stack with a pt_regs and call switch_stack() on it.
90 * It will be unnested during _resume and _ret_from_sys_call when the new thread
91 * is scheduled.
93 * Also setup the thread switching structure which is used to keep
94 * thread-specific data during _resumes.
97 extern asmlinkage void ret_from_fork(void);
98 extern asmlinkage void ret_from_kernel_thread(void);
101 copy_thread(unsigned long clone_flags, unsigned long usp,
102 unsigned long arg, struct task_struct *p)
104 struct pt_regs *childregs = task_pt_regs(p);
105 struct switch_stack *swstack = ((struct switch_stack *) childregs) - 1;
108 * Put the pt_regs structure at the end of the new kernel stack page and
109 * fix it up. Note: the task_struct doubles as the kernel stack for the
110 * task.
112 if (unlikely(p->flags & PF_KTHREAD)) {
113 memset(swstack, 0,
114 sizeof(struct switch_stack) + sizeof(struct pt_regs));
115 swstack->r1 = usp;
116 swstack->r2 = arg;
117 childregs->ccs = 1 << (I_CCS_BITNR + CCS_SHIFT);
118 swstack->return_ip = (unsigned long) ret_from_kernel_thread;
119 p->thread.ksp = (unsigned long) swstack;
120 p->thread.usp = 0;
121 return 0;
123 *childregs = *current_pt_regs(); /* Struct copy of pt_regs. */
124 childregs->r10 = 0; /* Child returns 0 after a fork/clone. */
126 /* Set a new TLS ?
127 * The TLS is in $mof because it is the 5th argument to sys_clone.
129 if (p->mm && (clone_flags & CLONE_SETTLS)) {
130 task_thread_info(p)->tls = childregs->mof;
133 /* Put the switch stack right below the pt_regs. */
135 /* Parameter to ret_from_sys_call. 0 is don't restart the syscall. */
136 swstack->r9 = 0;
139 * We want to return into ret_from_sys_call after the _resume.
140 * ret_from_fork will call ret_from_sys_call.
142 swstack->return_ip = (unsigned long) ret_from_fork;
144 /* Fix the user-mode and kernel-mode stackpointer. */
145 p->thread.usp = usp ?: rdusp();
146 p->thread.ksp = (unsigned long) swstack;
148 return 0;
151 unsigned long
152 get_wchan(struct task_struct *p)
154 /* TODO */
155 return 0;
157 #undef last_sched
158 #undef first_sched
160 void show_regs(struct pt_regs * regs)
162 unsigned long usp = rdusp();
164 show_regs_print_info(KERN_DEFAULT);
166 printk("ERP: %08lx SRP: %08lx CCS: %08lx USP: %08lx MOF: %08lx\n",
167 regs->erp, regs->srp, regs->ccs, usp, regs->mof);
169 printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
170 regs->r0, regs->r1, regs->r2, regs->r3);
172 printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
173 regs->r4, regs->r5, regs->r6, regs->r7);
175 printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
176 regs->r8, regs->r9, regs->r10, regs->r11);
178 printk("r12: %08lx r13: %08lx oR10: %08lx\n",
179 regs->r12, regs->r13, regs->orig_r10);