diff options
author | Aurelien Jacquiot <a-jacquiot@ti.com> | 2011-10-04 11:03:44 -0400 |
---|---|---|
committer | Mark Salter <msalter@redhat.com> | 2011-10-06 19:47:40 -0400 |
commit | 687b12baecae2aa3af9df05c12b90d8e9ef21fa7 (patch) | |
tree | 0d73b753a7dd541d987a06fd7b69d7958170a5dd /arch/c6x/kernel | |
parent | 14aa7e8bf6d84c9a42c48e7f93472d830f694b1e (diff) |
C6X: process management
Original port to early 2.6 kernel using TI COFF toolchain.
Brought up to date by Mark Salter <msalter@redhat.com>
Signed-off-by: Aurelien Jacquiot <a-jacquiot@ti.com>
Signed-off-by: Mark Salter <msalter@redhat.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/c6x/kernel')
-rw-r--r-- | arch/c6x/kernel/process.c | 263 | ||||
-rw-r--r-- | arch/c6x/kernel/switch_to.S | 74 |
2 files changed, 337 insertions, 0 deletions
diff --git a/arch/c6x/kernel/process.c b/arch/c6x/kernel/process.c new file mode 100644 index 000000000000..aa65c879323b --- /dev/null +++ b/arch/c6x/kernel/process.c | |||
@@ -0,0 +1,263 @@ | |||
1 | /* | ||
2 | * Port on Texas Instruments TMS320C6x architecture | ||
3 | * | ||
4 | * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated | ||
5 | * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com) | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | */ | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/unistd.h> | ||
14 | #include <linux/ptrace.h> | ||
15 | #include <linux/init_task.h> | ||
16 | #include <linux/tick.h> | ||
17 | #include <linux/mqueue.h> | ||
18 | #include <linux/syscalls.h> | ||
19 | #include <linux/reboot.h> | ||
20 | |||
21 | #include <asm/syscalls.h> | ||
22 | |||
23 | /* hooks for board specific support */ | ||
24 | void (*c6x_restart)(void); | ||
25 | void (*c6x_halt)(void); | ||
26 | |||
27 | extern asmlinkage void ret_from_fork(void); | ||
28 | |||
29 | static struct signal_struct init_signals = INIT_SIGNALS(init_signals); | ||
30 | static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand); | ||
31 | |||
32 | /* | ||
33 | * Initial thread structure. | ||
34 | */ | ||
35 | union thread_union init_thread_union __init_task_data = { | ||
36 | INIT_THREAD_INFO(init_task) | ||
37 | }; | ||
38 | |||
39 | /* | ||
40 | * Initial task structure. | ||
41 | */ | ||
42 | struct task_struct init_task = INIT_TASK(init_task); | ||
43 | EXPORT_SYMBOL(init_task); | ||
44 | |||
45 | /* | ||
46 | * power off function, if any | ||
47 | */ | ||
48 | void (*pm_power_off)(void); | ||
49 | EXPORT_SYMBOL(pm_power_off); | ||
50 | |||
51 | static void c6x_idle(void) | ||
52 | { | ||
53 | unsigned long tmp; | ||
54 | |||
55 | /* | ||
56 | * Put local_irq_enable and idle in same execute packet | ||
57 | * to make them atomic and avoid race to idle with | ||
58 | * interrupts enabled. | ||
59 | */ | ||
60 | asm volatile (" mvc .s2 CSR,%0\n" | ||
61 | " or .d2 1,%0,%0\n" | ||
62 | " mvc .s2 %0,CSR\n" | ||
63 | "|| idle\n" | ||
64 | : "=b"(tmp)); | ||
65 | } | ||
66 | |||
67 | /* | ||
68 | * The idle loop for C64x | ||
69 | */ | ||
70 | void cpu_idle(void) | ||
71 | { | ||
72 | /* endless idle loop with no priority at all */ | ||
73 | while (1) { | ||
74 | tick_nohz_stop_sched_tick(1); | ||
75 | while (1) { | ||
76 | local_irq_disable(); | ||
77 | if (need_resched()) { | ||
78 | local_irq_enable(); | ||
79 | break; | ||
80 | } | ||
81 | c6x_idle(); /* enables local irqs */ | ||
82 | } | ||
83 | tick_nohz_restart_sched_tick(); | ||
84 | |||
85 | preempt_enable_no_resched(); | ||
86 | schedule(); | ||
87 | preempt_disable(); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | static void halt_loop(void) | ||
92 | { | ||
93 | printk(KERN_EMERG "System Halted, OK to turn off power\n"); | ||
94 | local_irq_disable(); | ||
95 | while (1) | ||
96 | asm volatile("idle\n"); | ||
97 | } | ||
98 | |||
99 | void machine_restart(char *__unused) | ||
100 | { | ||
101 | if (c6x_restart) | ||
102 | c6x_restart(); | ||
103 | halt_loop(); | ||
104 | } | ||
105 | |||
106 | void machine_halt(void) | ||
107 | { | ||
108 | if (c6x_halt) | ||
109 | c6x_halt(); | ||
110 | halt_loop(); | ||
111 | } | ||
112 | |||
113 | void machine_power_off(void) | ||
114 | { | ||
115 | if (pm_power_off) | ||
116 | pm_power_off(); | ||
117 | halt_loop(); | ||
118 | } | ||
119 | |||
120 | static void kernel_thread_helper(int dummy, void *arg, int (*fn)(void *)) | ||
121 | { | ||
122 | do_exit(fn(arg)); | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * Create a kernel thread | ||
127 | */ | ||
128 | int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags) | ||
129 | { | ||
130 | struct pt_regs regs; | ||
131 | |||
132 | /* | ||
133 | * copy_thread sets a4 to zero (child return from fork) | ||
134 | * so we can't just set things up to directly return to | ||
135 | * fn. | ||
136 | */ | ||
137 | memset(®s, 0, sizeof(regs)); | ||
138 | regs.b4 = (unsigned long) arg; | ||
139 | regs.a6 = (unsigned long) fn; | ||
140 | regs.pc = (unsigned long) kernel_thread_helper; | ||
141 | local_save_flags(regs.csr); | ||
142 | regs.csr |= 1; | ||
143 | regs.tsr = 5; /* Set GEE and GIE in TSR */ | ||
144 | |||
145 | /* Ok, create the new process.. */ | ||
146 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, -1, ®s, | ||
147 | 0, NULL, NULL); | ||
148 | } | ||
149 | EXPORT_SYMBOL(kernel_thread); | ||
150 | |||
151 | void flush_thread(void) | ||
152 | { | ||
153 | } | ||
154 | |||
155 | void exit_thread(void) | ||
156 | { | ||
157 | } | ||
158 | |||
159 | SYSCALL_DEFINE1(c6x_clone, struct pt_regs *, regs) | ||
160 | { | ||
161 | unsigned long clone_flags; | ||
162 | unsigned long newsp; | ||
163 | |||
164 | /* syscall puts clone_flags in A4 and usp in B4 */ | ||
165 | clone_flags = regs->orig_a4; | ||
166 | if (regs->b4) | ||
167 | newsp = regs->b4; | ||
168 | else | ||
169 | newsp = regs->sp; | ||
170 | |||
171 | return do_fork(clone_flags, newsp, regs, 0, (int __user *)regs->a6, | ||
172 | (int __user *)regs->b6); | ||
173 | } | ||
174 | |||
175 | /* | ||
176 | * Do necessary setup to start up a newly executed thread. | ||
177 | */ | ||
178 | void start_thread(struct pt_regs *regs, unsigned int pc, unsigned long usp) | ||
179 | { | ||
180 | /* | ||
181 | * The binfmt loader will setup a "full" stack, but the C6X | ||
182 | * operates an "empty" stack. So we adjust the usp so that | ||
183 | * argc doesn't get destroyed if an interrupt is taken before | ||
184 | * it is read from the stack. | ||
185 | * | ||
186 | * NB: Library startup code needs to match this. | ||
187 | */ | ||
188 | usp -= 8; | ||
189 | |||
190 | set_fs(USER_DS); | ||
191 | regs->pc = pc; | ||
192 | regs->sp = usp; | ||
193 | regs->tsr |= 0x40; /* set user mode */ | ||
194 | current->thread.usp = usp; | ||
195 | } | ||
196 | |||
197 | /* | ||
198 | * Copy a new thread context in its stack. | ||
199 | */ | ||
200 | int copy_thread(unsigned long clone_flags, unsigned long usp, | ||
201 | unsigned long ustk_size, | ||
202 | struct task_struct *p, struct pt_regs *regs) | ||
203 | { | ||
204 | struct pt_regs *childregs; | ||
205 | |||
206 | childregs = task_pt_regs(p); | ||
207 | |||
208 | *childregs = *regs; | ||
209 | childregs->a4 = 0; | ||
210 | |||
211 | if (usp == -1) | ||
212 | /* case of __kernel_thread: we return to supervisor space */ | ||
213 | childregs->sp = (unsigned long)(childregs + 1); | ||
214 | else | ||
215 | /* Otherwise use the given stack */ | ||
216 | childregs->sp = usp; | ||
217 | |||
218 | /* Set usp/ksp */ | ||
219 | p->thread.usp = childregs->sp; | ||
220 | /* switch_to uses stack to save/restore 14 callee-saved regs */ | ||
221 | thread_saved_ksp(p) = (unsigned long)childregs - 8; | ||
222 | p->thread.pc = (unsigned int) ret_from_fork; | ||
223 | p->thread.wchan = (unsigned long) ret_from_fork; | ||
224 | #ifdef __DSBT__ | ||
225 | { | ||
226 | unsigned long dp; | ||
227 | |||
228 | asm volatile ("mv .S2 b14,%0\n" : "=b"(dp)); | ||
229 | |||
230 | thread_saved_dp(p) = dp; | ||
231 | if (usp == -1) | ||
232 | childregs->dp = dp; | ||
233 | } | ||
234 | #endif | ||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | /* | ||
239 | * c6x_execve() executes a new program. | ||
240 | */ | ||
241 | SYSCALL_DEFINE4(c6x_execve, const char __user *, name, | ||
242 | const char __user *const __user *, argv, | ||
243 | const char __user *const __user *, envp, | ||
244 | struct pt_regs *, regs) | ||
245 | { | ||
246 | int error; | ||
247 | char *filename; | ||
248 | |||
249 | filename = getname(name); | ||
250 | error = PTR_ERR(filename); | ||
251 | if (IS_ERR(filename)) | ||
252 | goto out; | ||
253 | |||
254 | error = do_execve(filename, argv, envp, regs); | ||
255 | putname(filename); | ||
256 | out: | ||
257 | return error; | ||
258 | } | ||
259 | |||
260 | unsigned long get_wchan(struct task_struct *p) | ||
261 | { | ||
262 | return p->thread.wchan; | ||
263 | } | ||
diff --git a/arch/c6x/kernel/switch_to.S b/arch/c6x/kernel/switch_to.S new file mode 100644 index 000000000000..09177ed0fa5c --- /dev/null +++ b/arch/c6x/kernel/switch_to.S | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2011 Texas Instruments Incorporated | ||
3 | * Author: Mark Salter (msalter@redhat.com) | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | */ | ||
9 | |||
10 | #include <linux/linkage.h> | ||
11 | #include <asm/asm-offsets.h> | ||
12 | |||
13 | #define SP B15 | ||
14 | |||
15 | /* | ||
16 | * void __switch_to(struct thread_info *prev, | ||
17 | * struct thread_info *next, | ||
18 | * struct task_struct *tsk) ; | ||
19 | */ | ||
20 | ENTRY(__switch_to) | ||
21 | LDDW .D2T2 *+B4(THREAD_B15_14),B7:B6 | ||
22 | || MV .L2X A4,B5 ; prev | ||
23 | || MV .L1X B4,A5 ; next | ||
24 | || MVC .S2 RILC,B1 | ||
25 | |||
26 | STW .D2T2 B3,*+B5(THREAD_PC) | ||
27 | || STDW .D1T1 A13:A12,*+A4(THREAD_A13_12) | ||
28 | || MVC .S2 ILC,B0 | ||
29 | |||
30 | LDW .D2T2 *+B4(THREAD_PC),B3 | ||
31 | || LDDW .D1T1 *+A5(THREAD_A13_12),A13:A12 | ||
32 | |||
33 | STDW .D1T1 A11:A10,*+A4(THREAD_A11_10) | ||
34 | || STDW .D2T2 B1:B0,*+B5(THREAD_RICL_ICL) | ||
35 | #ifndef __DSBT__ | ||
36 | || MVKL .S2 current_ksp,B1 | ||
37 | #endif | ||
38 | |||
39 | STDW .D2T2 B15:B14,*+B5(THREAD_B15_14) | ||
40 | || STDW .D1T1 A15:A14,*+A4(THREAD_A15_14) | ||
41 | #ifndef __DSBT__ | ||
42 | || MVKH .S2 current_ksp,B1 | ||
43 | #endif | ||
44 | |||
45 | ;; Switch to next SP | ||
46 | MV .S2 B7,SP | ||
47 | #ifdef __DSBT__ | ||
48 | || STW .D2T2 B7,*+B14(current_ksp) | ||
49 | #else | ||
50 | || STW .D2T2 B7,*B1 | ||
51 | || MV .L2 B6,B14 | ||
52 | #endif | ||
53 | || LDDW .D1T1 *+A5(THREAD_RICL_ICL),A1:A0 | ||
54 | |||
55 | STDW .D2T2 B11:B10,*+B5(THREAD_B11_10) | ||
56 | || LDDW .D1T1 *+A5(THREAD_A15_14),A15:A14 | ||
57 | |||
58 | STDW .D2T2 B13:B12,*+B5(THREAD_B13_12) | ||
59 | || LDDW .D1T1 *+A5(THREAD_A11_10),A11:A10 | ||
60 | |||
61 | B .S2 B3 ; return in next E1 | ||
62 | || LDDW .D2T2 *+B4(THREAD_B13_12),B13:B12 | ||
63 | |||
64 | LDDW .D2T2 *+B4(THREAD_B11_10),B11:B10 | ||
65 | NOP | ||
66 | |||
67 | MV .L2X A0,B0 | ||
68 | || MV .S1 A6,A4 | ||
69 | |||
70 | MVC .S2 B0,ILC | ||
71 | || MV .L2X A1,B1 | ||
72 | |||
73 | MVC .S2 B1,RILC | ||
74 | ENDPROC(__switch_to) | ||