This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / arch / um / kernel / skas / process_kern.c
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #include "linux/sched.h"
7 #include "linux/slab.h"
8 #include "linux/ptrace.h"
9 #include "kern_util.h"
10 #include "time_user.h"
11 #include "signal_user.h"
12 #include "skas.h"
13 #include "os.h"
14 #include "user_util.h"
15 #include "tlb.h"
16 #include "frame.h"
17 #include "kern.h"
18 #include "mode.h"
19
20 int singlestepping_skas(void)
21 {
22         int ret = current->ptrace & PT_DTRACE;
23
24         current->ptrace &= ~PT_DTRACE;
25         return(ret);
26 }
27
28 void *switch_to_skas(void *prev, void *next)
29 {
30         struct task_struct *from, *to;
31
32         from = prev;
33         to = next;
34
35         /* XXX need to check runqueues[cpu].idle */
36         if(current->pid == 0)
37                 switch_timers(0);
38
39         to->thread.prev_sched = from;
40         set_current(to);
41
42         switch_threads(&from->thread.mode.skas.switch_buf, 
43                        to->thread.mode.skas.switch_buf);
44
45         if(current->pid == 0)
46                 switch_timers(1);
47
48         return(current->thread.prev_sched);
49 }
50
51 extern void schedule_tail(struct task_struct *prev);
52
53 void new_thread_handler(int sig)
54 {
55         int (*fn)(void *), n;
56         void *arg;
57
58         fn = current->thread.request.u.thread.proc;
59         arg = current->thread.request.u.thread.arg;
60         change_sig(SIGUSR1, 1);
61         thread_wait(&current->thread.mode.skas.switch_buf, 
62                     current->thread.mode.skas.fork_buf);
63
64         if(current->thread.prev_sched != NULL)
65                 schedule_tail(current->thread.prev_sched);
66         current->thread.prev_sched = NULL;
67
68         /* The return value is 1 if the kernel thread execs a process,
69          * 0 if it just exits
70          */
71         n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
72         if(n == 1)
73                 userspace(&current->thread.regs.regs);
74         else do_exit(0);
75 }
76
77 void new_thread_proc(void *stack, void (*handler)(int sig))
78 {
79         init_new_thread_stack(stack, handler);
80         os_usr1_process(os_getpid());
81 }
82
83 void release_thread_skas(struct task_struct *task)
84 {
85 }
86
87 void exit_thread_skas(void)
88 {
89 }
90
91 void fork_handler(int sig)
92 {
93         change_sig(SIGUSR1, 1);
94         thread_wait(&current->thread.mode.skas.switch_buf, 
95                     current->thread.mode.skas.fork_buf);
96         
97         force_flush_all();
98         if(current->thread.prev_sched == NULL)
99                 panic("blech");
100         
101         schedule_tail(current->thread.prev_sched);
102         current->thread.prev_sched = NULL;
103
104         userspace(&current->thread.regs.regs);
105 }
106
107 int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
108                      unsigned long stack_top, struct task_struct * p, 
109                      struct pt_regs *regs)
110 {
111         void (*handler)(int);
112
113         if(current->thread.forking){
114                 memcpy(&p->thread.regs.regs.skas, 
115                        &current->thread.regs.regs.skas, 
116                        sizeof(p->thread.regs.regs.skas));
117                 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
118                 if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
119
120                 handler = fork_handler;
121         }
122         else {
123                 memcpy(p->thread.regs.regs.skas.regs, exec_regs, 
124                        sizeof(p->thread.regs.regs.skas.regs));
125                 memcpy(p->thread.regs.regs.skas.fp, exec_fp_regs, 
126                        sizeof(p->thread.regs.regs.skas.fp));
127                 memcpy(p->thread.regs.regs.skas.xfp, exec_fpx_regs, 
128                        sizeof(p->thread.regs.regs.skas.xfp));
129                 p->thread.request.u.thread = current->thread.request.u.thread;
130                 handler = new_thread_handler;
131         }
132
133         new_thread((void *) p->thread.kernel_stack, 
134                    &p->thread.mode.skas.switch_buf, 
135                    &p->thread.mode.skas.fork_buf, handler);
136         return(0);
137 }
138
139 void init_idle_skas(void)
140 {
141         cpu_tasks[current_thread->cpu].pid = os_getpid();
142         default_idle();
143 }
144
145 extern void start_kernel(void);
146
147 static int start_kernel_proc(void *unused)
148 {
149         int pid;
150
151         block_signals();
152         pid = os_getpid();
153
154         cpu_tasks[0].pid = pid;
155         cpu_tasks[0].task = current;
156 #ifdef CONFIG_SMP
157         cpu_online_map = cpumask_of_cpu(0);
158 #endif
159         start_kernel();
160         return(0);
161 }
162
163 int start_uml_skas(void)
164 {
165         start_userspace(0);
166         capture_signal_stack();
167         uml_idle_timer();
168
169         init_new_thread_signals(1);
170
171         init_task.thread.request.u.thread.proc = start_kernel_proc;
172         init_task.thread.request.u.thread.arg = NULL;
173         return(start_idle_thread((void *) init_task.thread.kernel_stack,
174                                  &init_task.thread.mode.skas.switch_buf,
175                                  &init_task.thread.mode.skas.fork_buf));
176 }
177
178 int external_pid_skas(struct task_struct *task)
179 {
180 #warning Need to look up userspace_pid by cpu   
181         return(userspace_pid[0]);
182 }
183
184 int thread_pid_skas(struct task_struct *task)
185 {
186 #warning Need to look up userspace_pid by cpu   
187         return(userspace_pid[0]);
188 }
189
190 /*
191  * Overrides for Emacs so that we follow Linus's tabbing style.
192  * Emacs will notice this stuff at the end of the file and automatically
193  * adjust the settings for this buffer only.  This must remain at the end
194  * of the file.
195  * ---------------------------------------------------------------------------
196  * Local variables:
197  * c-file-style: "linux"
198  * End:
199  */