]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - arch/cris/arch-v10/kernel/process.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-hirsute-kernel.git] / arch / cris / arch-v10 / kernel / process.c
CommitLineData
10f9f9c8 1/*
1da177e4
LT
2 * linux/arch/cris/kernel/process.c
3 *
4 * Copyright (C) 1995 Linus Torvalds
5 * Copyright (C) 2000-2002 Axis Communications AB
6 *
7 * Authors: Bjorn Wesen (bjornw@axis.com)
8 * Mikael Starvik (starvik@axis.com)
9 *
10 * This file handles the architecture-dependent parts of process handling..
11 */
12
1da177e4 13#include <linux/sched.h>
b17b0153 14#include <linux/sched/debug.h>
29930025 15#include <linux/sched/task.h>
5a0e3ad6 16#include <linux/slab.h>
1da177e4
LT
17#include <linux/err.h>
18#include <linux/fs.h>
cd065a01 19#include <arch/svinto.h>
1da177e4 20#include <linux/init.h>
b1a154db 21#include <arch/system.h>
27d892fb 22#include <linux/ptrace.h>
1da177e4
LT
23
24#ifdef CONFIG_ETRAX_GPIO
25void etrax_gpio_wake_up_check(void); /* drivers/gpio.c */
26#endif
27
28/*
29 * We use this if we don't have any better
30 * idle routine..
31 */
32void default_idle(void)
33{
34#ifdef CONFIG_ETRAX_GPIO
8dc7c5ec 35 etrax_gpio_wake_up_check();
1da177e4 36#endif
8dc7c5ec 37 local_irq_enable();
1da177e4
LT
38}
39
1da177e4
LT
40/* if the watchdog is enabled, we can simply disable interrupts and go
41 * into an eternal loop, and the watchdog will reset the CPU after 0.1s
42 * if on the other hand the watchdog wasn't enabled, we just enable it and wait
43 */
44
45void hard_reset_now (void)
46{
47 /*
48 * Don't declare this variable elsewhere. We don't want any other
49 * code to know about it than the watchdog handler in entry.S and
50 * this code, implementing hard reset through the watchdog.
51 */
e269a869 52#if defined(CONFIG_ETRAX_WATCHDOG)
1da177e4
LT
53 extern int cause_of_death;
54#endif
55
56 printk("*** HARD RESET ***\n");
57 local_irq_disable();
58
e269a869 59#if defined(CONFIG_ETRAX_WATCHDOG)
1da177e4
LT
60 cause_of_death = 0xbedead;
61#else
49b4ff33 62 /* Since we dont plan to keep on resetting the watchdog,
1da177e4
LT
63 the key can be arbitrary hence three */
64 *R_WATCHDOG = IO_FIELD(R_WATCHDOG, key, 3) |
65 IO_STATE(R_WATCHDOG, enable, start);
66#endif
67
68 while(1) /* waiting for RETRIBUTION! */ ;
69}
70
71/*
72 * Return saved PC of a blocked thread.
73 */
74unsigned long thread_saved_pc(struct task_struct *t)
75{
95ca0dc6 76 return task_pt_regs(t)->irp;
1da177e4
LT
77}
78
1da177e4
LT
79/* setup the child's kernel stack with a pt_regs and switch_stack on it.
80 * it will be un-nested during _resume and _ret_from_sys_call when the
81 * new thread is scheduled.
82 *
83 * also setup the thread switching structure which is used to keep
84 * thread-specific data during _resumes.
85 *
86 */
87asmlinkage void ret_from_fork(void);
69b58a67 88asmlinkage void ret_from_kernel_thread(void);
1da177e4 89
6f2c55b8 90int copy_thread(unsigned long clone_flags, unsigned long usp,
afa86fc4 91 unsigned long arg, struct task_struct *p)
1da177e4 92{
69b58a67
AV
93 struct pt_regs *childregs = task_pt_regs(p);
94 struct switch_stack *swstack = ((struct switch_stack *)childregs) - 1;
1da177e4
LT
95
96 /* put the pt_regs structure at the end of the new kernel stack page and fix it up
97 * remember that the task_struct doubles as the kernel stack for the task
98 */
99
69b58a67
AV
100 if (unlikely(p->flags & PF_KTHREAD)) {
101 memset(swstack, 0,
102 sizeof(struct switch_stack) + sizeof(struct pt_regs));
103 swstack->r1 = usp;
104 swstack->r2 = arg;
105 childregs->dccr = 1 << I_DCCR_BITNR;
106 swstack->return_ip = (unsigned long) ret_from_kernel_thread;
107 p->thread.ksp = (unsigned long) swstack;
108 p->thread.usp = 0;
109 return 0;
110 }
27d892fb 111 *childregs = *current_pt_regs(); /* struct copy of pt_regs */
1da177e4
LT
112
113 childregs->r10 = 0; /* child returns 0 after a fork/clone */
1da177e4 114
69b58a67 115 /* put the switch stack right below the pt_regs */
1da177e4
LT
116
117 swstack->r9 = 0; /* parameter to ret_from_sys_call, 0 == dont restart the syscall */
118
119 /* we want to return into ret_from_sys_call after the _resume */
120
121 swstack->return_ip = (unsigned long) ret_from_fork; /* Will call ret_from_sys_call */
122
123 /* fix the user-mode stackpointer */
124
27d892fb 125 p->thread.usp = usp ?: rdusp();
1da177e4
LT
126
127 /* and the kernel-mode one */
128
129 p->thread.ksp = (unsigned long) swstack;
130
131#ifdef DEBUG
132 printk("copy_thread: new regs at 0x%p, as shown below:\n", childregs);
133 show_registers(childregs);
134#endif
135
136 return 0;
137}
138
1da177e4
LT
139unsigned long get_wchan(struct task_struct *p)
140{
141#if 0
142 /* YURGH. TODO. */
143
144 unsigned long ebp, esp, eip;
145 unsigned long stack_page;
146 int count = 0;
147 if (!p || p == current || p->state == TASK_RUNNING)
148 return 0;
149 stack_page = (unsigned long)p;
150 esp = p->thread.esp;
151 if (!stack_page || esp < stack_page || esp > 8188+stack_page)
152 return 0;
153 /* include/asm-i386/system.h:switch_to() pushes ebp last. */
154 ebp = *(unsigned long *) esp;
155 do {
156 if (ebp < stack_page || ebp > 8184+stack_page)
157 return 0;
158 eip = *(unsigned long *) (ebp+4);
159 if (!in_sched_functions(eip))
160 return eip;
161 ebp = *(unsigned long *) ebp;
162 } while (count++ < 16);
163#endif
164 return 0;
165}
166#undef last_sched
167#undef first_sched
168
169void show_regs(struct pt_regs * regs)
170{
171 unsigned long usp = rdusp();
a43cb95d
TH
172
173 show_regs_print_info(KERN_DEFAULT);
174
1da177e4
LT
175 printk("IRP: %08lx SRP: %08lx DCCR: %08lx USP: %08lx MOF: %08lx\n",
176 regs->irp, regs->srp, regs->dccr, usp, regs->mof );
177 printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n",
178 regs->r0, regs->r1, regs->r2, regs->r3);
179 printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n",
180 regs->r4, regs->r5, regs->r6, regs->r7);
181 printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n",
182 regs->r8, regs->r9, regs->r10, regs->r11);
183 printk("r12: %08lx r13: %08lx oR10: %08lx\n",
184 regs->r12, regs->r13, regs->orig_r10);
185}
186