OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [linux-2.6/] [linux-2.6.24/] [arch/] [or32/] [kernel/] [process.c] - Blame information for rev 7

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 xianfeng
/*
2
 *  linux/arch/or32/kernel/process.c
3
 *
4
 *  or32 version
5
 *    author(s): Matjaz Breskvar (phoenix@bsemi.com)
6
 *
7
 *  derived from cris, i386, m68k, ppc, sh ports.
8
 *
9
 *  changes:
10
 *  18. 11. 2003: Matjaz Breskvar (phoenix@bsemi.com)
11
 *    initial port to or32 architecture
12
 *
13
 * This file handles the architecture-dependent parts of process handling..
14
 * Based on m86k.
15
 */
16
 
17
#define __KERNEL_SYSCALLS__
18
#include <stdarg.h>
19
 
20
#include <linux/errno.h>
21
#include <linux/sched.h>
22
#include <linux/kernel.h>
23
#include <linux/module.h>
24
#include <linux/mm.h>
25
#include <linux/stddef.h>
26
#include <linux/unistd.h>
27
#include <linux/ptrace.h>
28
#include <linux/slab.h>
29
#include <linux/user.h>
30
#include <linux/elfcore.h>
31
#include <linux/interrupt.h>
32
#include <linux/delay.h>
33
#include <linux/init_task.h>
34
#include <linux/mqueue.h>
35
#include <linux/fs.h>
36
 
37
#include <asm/uaccess.h>
38
#include <asm/pgtable.h>
39
#include <asm/system.h>
40
#include <asm/io.h>
41
#include <asm/processor.h>
42
#include <asm/spr_defs.h>
43
#include <asm/or32-hf.h>
44
 
45
 
46
#include <linux/smp.h>
47
 
48
/*
49
 * Initial task structure. Make this a per-architecture thing,
50
 * because different architectures tend to have different
51
 * alignment requirements and potentially different initial
52
 * setup.
53
 */
54
 
55
static struct fs_struct init_fs = INIT_FS;
56
static struct files_struct init_files = INIT_FILES;
57
static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
58
static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
59
struct mm_struct init_mm = INIT_MM(init_mm);
60
 
61
EXPORT_SYMBOL(init_mm);
62
 
63
/*
64
 * Initial thread structure.
65
 *
66
 * We need to make sure that this is 8192-byte aligned due to the
67
 * way process stacks are handled. This is done by having a special
68
 * "init_task" linker map entry..
69
 */
70
union thread_union init_thread_union
71
        __attribute__((__section__(".data.init_task"))) =
72
                { INIT_THREAD_INFO(init_task) };
73
 
74
/*
75
 * Pointer to Current thread info structure.
76
 *
77
 * Used at user space -> kernel transitions.
78
 */
79
struct thread_info *current_thread_info_set[NR_CPUS] = {&init_thread_info, };
80
 
81
/*
82
 * Initial task structure.
83
 *
84
 * All other task structs will be allocated on slabs in fork.c
85
 */
86
struct task_struct init_task = INIT_TASK(init_task);
87
 
88
EXPORT_SYMBOL(init_task);
89
 
90
/*
91
 * The hlt_counter, disable_hlt and enable_hlt is just here as a hook if
92
 * there would ever be a halt sequence (for power save when idle) with
93
 * some largish delay when halting or resuming *and* a driver that can't
94
 * afford that delay.  The hlt_counter would then be checked before
95
 * executing the halt sequence, and the driver marks the unhaltable
96
 * region by enable_hlt/disable_hlt.
97
 */
98
 
99
static int hlt_counter=0;
100
 
101
void disable_hlt(void)
102
{
103
        hlt_counter++;
104
}
105
 
106
EXPORT_SYMBOL(disable_hlt);
107
 
108
void enable_hlt(void)
109
{
110
        hlt_counter--;
111
}
112
 
113
EXPORT_SYMBOL(enable_hlt);
114
 
115
void machine_restart(void)
116
{
117
        printk("*** MACHINE RESTART ***\n");
118
        __asm__("l.nop 1");
119
}
120
 
121
EXPORT_SYMBOL(machine_restart);
122
 
123
/*
124
 * Similar to machine_power_off, but don't shut off power.  Add code
125
 * here to freeze the system for e.g. post-mortem debug purpose when
126
 * possible.  This halt has nothing to do with the idle halt.
127
 */
128
 
129
void machine_halt(void)
130
{
131
        printk("*** MACHINE HALT ***\n");
132
        __asm__("l.nop 1");
133
}
134
 
135
EXPORT_SYMBOL(machine_halt);
136
 
137
/* If or when software power-off is implemented, add code here.  */
138
 
139
void machine_power_off(void)
140
{
141
        printk("*** MACHINE POWER OFF ***\n");
142
        __asm__("l.nop 1");
143
}
144
 
145
EXPORT_SYMBOL(machine_power_off);
146
 
147
void (*pm_power_off)(void) = machine_power_off;
148
EXPORT_SYMBOL(pm_power_off);
149
 
150
/*
151
 * When a process does an "exec", machine state like FPU and debug
152
 * registers need to be reset.  This is a hook function for that.
153
 * Currently we don't have any such state to reset, so this is empty.
154
 */
155
 
156
void flush_thread(void)
157
{
158
}
159
 
160
void show_regs(struct pt_regs *regs)
161
{
162
        extern void show_registers(struct pt_regs *regs);
163
 
164
        /* __PHX__ cleanup this mess */
165
        show_registers(regs);
166
}
167
 
168
asmlinkage int sys_fork(int r3, int r4, int r5, int r6, int r7, struct pt_regs *regs)
169
{
170
        return do_fork(SIGCHLD, regs->sp, regs, 0, NULL, NULL);
171
}
172
 
173
asmlinkage int sys_clone(int r3, int r4, int r5, int r6, int r7, struct pt_regs *regs)
174
{
175
        unsigned long clone_flags = (unsigned long)r3;
176
        return do_fork(clone_flags, regs->sp, regs, 0, NULL, NULL);
177
}
178
 
179
asmlinkage int sys_vfork(int r3, int r4, int r5, int r6, int r7, struct pt_regs *regs)
180
{
181
        return do_fork(CLONE_VFORK | CLONE_VM | SIGCHLD, regs->gprs[1], regs, 0, NULL, NULL);
182
}
183
 
184
unsigned long thread_saved_pc(struct task_struct *t)
185
{
186
        return (unsigned long)user_regs(t->stack)->pc;
187
}
188
 
189
void release_thread(struct task_struct *dead_task)
190
{
191
}
192
 
193
int copy_thread(int nr, unsigned long clone_flags, unsigned long usp,
194
                unsigned long unused, struct task_struct *p, struct pt_regs *regs)
195
{
196
        struct pt_regs *childregs, *kregs;
197
        extern void ret_from_fork(void);
198
        unsigned long sp = (unsigned long)p->stack + THREAD_SIZE;
199
        unsigned long childframe;
200
        struct thread_info *tmp;
201
        p->set_child_tid = p->clear_child_tid = NULL;
202
 
203
        /* Copy registers */
204
        sp -= sizeof(struct pt_regs);
205
        childregs = (struct pt_regs *) sp;
206
 
207
        *childregs = *regs;
208
 
209
        if ((childregs->sr & SPR_SR_SM) == 1) {
210
                /* for kernel thread, set `current' and stackptr in new task */
211
                childregs->sp = sp + sizeof(struct pt_regs);
212
                childregs->gprs[8] = (unsigned long)p->stack;
213
                /* __PHX__ :: i think this thread.regs is not needed */
214
                p->thread.regs = NULL;  /* no user register state */
215
        } else
216
                p->thread.regs = childregs;
217
 
218
        childregs->gprs[9] = 0;  /* Result from fork() */
219
//      sp -= STACK_FRAME_OVERHEAD;
220
        childframe = sp;
221
 
222
        /*
223
         * The way this works is that at some point in the future
224
         * some task will call _switch to switch to the new task.
225
         * That will pop off the stack frame created below and start
226
         * the new task running at ret_from_fork.  The new task will
227
         * do some house keeping and then return from the fork or clone
228
         * system call, using the stack frame created above.
229
         */
230
        sp -= sizeof(struct pt_regs);
231
        kregs = (struct pt_regs *) sp;
232
 
233
//      sp -= STACK_FRAME_OVERHEAD;
234
        tmp = (struct thread_info*)p->stack;
235
        tmp->ksp = sp;
236
 
237
        kregs->sr = regs->sr | SPR_SR_SM;
238
        kregs->sp = sp + sizeof(struct pt_regs);
239
        kregs->gprs[1] = (unsigned long)p;              /* for schedule_tail */
240
        kregs->gprs[8] = (unsigned long)p->stack; /* current           */
241
        kregs->pc = (unsigned long)ret_from_fork;
242
        p->thread.last_syscall = -1;
243
        return 0;
244
}
245
 
246
 
247
/*
248
 * Set up a thread for executing a new program
249
 */
250
void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
251
{
252
        phx_warn("NIP: %lx, SP: %lx", pc, sp);
253
 
254
        set_fs(USER_DS);
255
        memset(regs->gprs, 0, sizeof(regs->gprs));
256
 
257
        regs->pc = pc;
258
        regs->sr = regs->sr & ~ SPR_SR_SM;
259
        regs->sp = sp;
260
}
261
 
262
/* Fill in the fpu structure for a core dump.  */
263
int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
264
{
265
        phx_warn("FPU :: TODO");
266
        return 0;
267
}
268
 
269
void _switch_to(struct task_struct *old,
270
                struct task_struct *new,
271
                struct task_struct **last)
272
{
273
        extern struct thread_info *_switch(struct thread_info *old_ti,
274
                                           struct thread_info *new_ti);
275
        struct thread_info *new_ti, *old_ti;
276
        long flags;
277
 
278
        local_irq_save(flags);
279
        check_stack(NULL, __FILE__, __FUNCTION__, __LINE__);
280
 
281
        /* current_set is an array of saved current pointers
282
         * (one for each cpu). we need them at user->kernel transition,
283
         * while we save them at kernel->user transition
284
         */
285
        new_ti = new->stack;
286
        old_ti = old->stack;
287
 
288
        current_thread_info_set[smp_processor_id()] = new_ti;
289
        *last = (_switch(old_ti, new_ti))->task;
290
 
291
        check_stack(NULL, __FILE__, __FUNCTION__, __LINE__);
292
        local_irq_restore(flags);
293
}
294
 
295
/*
296
 * fill in the user structure for a core dump..
297
 */
298
void dump_thread(struct pt_regs *regs, struct user *dump)
299
{
300
        phx_warn("TODO");
301
}
302
 
303
/*
304
 * sys_execve() executes a new program.
305
 */
306
asmlinkage int sys_execve(char *name, char **argv, char **envp,
307
                          int r6, int r7, struct pt_regs *regs)
308
{
309
        int error;
310
        char * filename;
311
 
312
        filename = getname(name);
313
        error = PTR_ERR(filename);
314
 
315
        if (IS_ERR(filename))
316
          goto out;
317
 
318
        error = do_execve(filename, argv, envp, regs);
319
        putname(filename);
320
 
321
out:
322
        return error;
323
}
324
 
325
unsigned long get_wchan(struct task_struct *p)
326
{
327
        phx_warn("TODO");
328
 
329
        return 0;
330
}
331
 
332
int kernel_execve(const char *filename, char *const argv[], char *const
333
envp[])
334
{
335
  register long __res asm("r11") = __NR_execve;
336
  register long __a asm("r3") = (long)(filename);
337
  register long __b asm("r4") = (long)(argv);
338
  register long __c asm("r5") = (long)(envp);
339
  __asm__ volatile ("l.sys 1" : "=r" (__res)
340
           : "r" (__res), "r" (__a), "r" (__b), "r" (__c));
341
  __asm__ volatile("l.nop");
342
  return __res;
343
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.