]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
51533b61 MS |
2 | /* |
3 | * Copyright (C) 2000-2003 Axis Communications AB | |
4 | * | |
5 | * Authors: Bjorn Wesen (bjornw@axis.com) | |
6 | * Mikael Starvik (starvik@axis.com) | |
7 | * Tobias Anderberg (tobiasa@axis.com), CRISv32 port. | |
8 | * | |
9 | * This file handles the architecture-dependent parts of process handling.. | |
10 | */ | |
11 | ||
51533b61 | 12 | #include <linux/sched.h> |
b17b0153 | 13 | #include <linux/sched/debug.h> |
29930025 | 14 | #include <linux/sched/task.h> |
68db0cf1 | 15 | #include <linux/sched/task_stack.h> |
5a0e3ad6 | 16 | #include <linux/slab.h> |
51533b61 MS |
17 | #include <linux/err.h> |
18 | #include <linux/fs.h> | |
8cca29b7 JN |
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> | |
27d892fb | 23 | #include <linux/ptrace.h> |
51533b61 MS |
24 | |
25 | extern void stop_watchdog(void); | |
26 | ||
51533b61 MS |
27 | /* We use this if we don't have any better idle routine. */ |
28 | void default_idle(void) | |
29 | { | |
3fffa23e | 30 | local_irq_enable(); |
8dc7c5ec | 31 | /* Halt until exception. */ |
3fffa23e | 32 | __asm__ volatile("halt"); |
51533b61 MS |
33 | } |
34 | ||
35 | /* | |
36 | * Free current thread data structures etc.. | |
37 | */ | |
38 | ||
39 | extern void deconfigure_bp(long pid); | |
e6464694 | 40 | void exit_thread(struct task_struct *tsk) |
51533b61 | 41 | { |
e6464694 | 42 | deconfigure_bp(tsk->pid); |
51533b61 MS |
43 | } |
44 | ||
45 | /* | |
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. | |
49 | */ | |
50 | extern void arch_enable_nmi(void); | |
51 | ||
52 | void | |
53 | hard_reset_now(void) | |
54 | { | |
55 | /* | |
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. | |
59 | */ | |
60 | #if defined(CONFIG_ETRAX_WATCHDOG) | |
61 | extern int cause_of_death; | |
62 | #endif | |
63 | ||
64 | printk("*** HARD RESET ***\n"); | |
65 | local_irq_disable(); | |
66 | ||
67 | #if defined(CONFIG_ETRAX_WATCHDOG) | |
68 | cause_of_death = 0xbedead; | |
69 | #else | |
70 | { | |
71 | reg_timer_rw_wd_ctrl wd_ctrl = {0}; | |
72 | ||
73 | stop_watchdog(); | |
74 | ||
75 | wd_ctrl.key = 16; /* Arbitrary key. */ | |
76 | wd_ctrl.cnt = 1; /* Minimum time. */ | |
77 | wd_ctrl.cmd = regk_timer_start; | |
78 | ||
79 | arch_enable_nmi(); | |
8cca29b7 | 80 | REG_WR(timer, regi_timer0, rw_wd_ctrl, wd_ctrl); |
51533b61 MS |
81 | } |
82 | #endif | |
83 | ||
84 | while (1) | |
85 | ; /* Wait for reset. */ | |
86 | } | |
87 | ||
51533b61 MS |
88 | /* |
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. | |
92 | * | |
93 | * Also setup the thread switching structure which is used to keep | |
94 | * thread-specific data during _resumes. | |
95 | */ | |
96 | ||
97 | extern asmlinkage void ret_from_fork(void); | |
69b58a67 | 98 | extern asmlinkage void ret_from_kernel_thread(void); |
51533b61 MS |
99 | |
100 | int | |
6f2c55b8 | 101 | copy_thread(unsigned long clone_flags, unsigned long usp, |
afa86fc4 | 102 | unsigned long arg, struct task_struct *p) |
51533b61 | 103 | { |
69b58a67 AV |
104 | struct pt_regs *childregs = task_pt_regs(p); |
105 | struct switch_stack *swstack = ((struct switch_stack *) childregs) - 1; | |
51533b61 MS |
106 | |
107 | /* | |
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. | |
111 | */ | |
69b58a67 AV |
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; | |
122 | } | |
27d892fb | 123 | *childregs = *current_pt_regs(); /* Struct copy of pt_regs. */ |
51533b61 MS |
124 | childregs->r10 = 0; /* Child returns 0 after a fork/clone. */ |
125 | ||
126 | /* Set a new TLS ? | |
25985edc | 127 | * The TLS is in $mof because it is the 5th argument to sys_clone. |
51533b61 MS |
128 | */ |
129 | if (p->mm && (clone_flags & CLONE_SETTLS)) { | |
27d892fb | 130 | task_thread_info(p)->tls = childregs->mof; |
51533b61 MS |
131 | } |
132 | ||
133 | /* Put the switch stack right below the pt_regs. */ | |
51533b61 | 134 | |
49b4ff33 | 135 | /* Parameter to ret_from_sys_call. 0 is don't restart the syscall. */ |
51533b61 MS |
136 | swstack->r9 = 0; |
137 | ||
138 | /* | |
139 | * We want to return into ret_from_sys_call after the _resume. | |
140 | * ret_from_fork will call ret_from_sys_call. | |
141 | */ | |
142 | swstack->return_ip = (unsigned long) ret_from_fork; | |
143 | ||
144 | /* Fix the user-mode and kernel-mode stackpointer. */ | |
27d892fb | 145 | p->thread.usp = usp ?: rdusp(); |
51533b61 MS |
146 | p->thread.ksp = (unsigned long) swstack; |
147 | ||
148 | return 0; | |
149 | } | |
150 | ||
51533b61 MS |
151 | unsigned long |
152 | get_wchan(struct task_struct *p) | |
153 | { | |
154 | /* TODO */ | |
155 | return 0; | |
156 | } | |
157 | #undef last_sched | |
158 | #undef first_sched | |
159 | ||
160 | void show_regs(struct pt_regs * regs) | |
161 | { | |
162 | unsigned long usp = rdusp(); | |
a43cb95d TH |
163 | |
164 | show_regs_print_info(KERN_DEFAULT); | |
165 | ||
51533b61 MS |
166 | printk("ERP: %08lx SRP: %08lx CCS: %08lx USP: %08lx MOF: %08lx\n", |
167 | regs->erp, regs->srp, regs->ccs, usp, regs->mof); | |
168 | ||
169 | printk(" r0: %08lx r1: %08lx r2: %08lx r3: %08lx\n", | |
170 | regs->r0, regs->r1, regs->r2, regs->r3); | |
171 | ||
172 | printk(" r4: %08lx r5: %08lx r6: %08lx r7: %08lx\n", | |
173 | regs->r4, regs->r5, regs->r6, regs->r7); | |
174 | ||
175 | printk(" r8: %08lx r9: %08lx r10: %08lx r11: %08lx\n", | |
176 | regs->r8, regs->r9, regs->r10, regs->r11); | |
177 | ||
178 | printk("r12: %08lx r13: %08lx oR10: %08lx\n", | |
179 | regs->r12, regs->r13, regs->orig_r10); | |
180 | } |