[PATCH] Driver Core: pm diagnostics update, check for errors
[linux-2.6/verdex.git] / arch / um / kernel / skas / process_kern.c
blobab5d3271da0b08229a01964428a4d033fdd0604c
1 /*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include "linux/sched.h"
7 #include "linux/slab.h"
8 #include "linux/ptrace.h"
9 #include "linux/proc_fs.h"
10 #include "linux/file.h"
11 #include "linux/errno.h"
12 #include "linux/init.h"
13 #include "asm/uaccess.h"
14 #include "asm/atomic.h"
15 #include "kern_util.h"
16 #include "time_user.h"
17 #include "signal_user.h"
18 #include "skas.h"
19 #include "os.h"
20 #include "user_util.h"
21 #include "tlb.h"
22 #include "kern.h"
23 #include "mode.h"
24 #include "proc_mm.h"
25 #include "registers.h"
27 void *switch_to_skas(void *prev, void *next)
29 struct task_struct *from, *to;
31 from = prev;
32 to = next;
34 /* XXX need to check runqueues[cpu].idle */
35 if(current->pid == 0)
36 switch_timers(0);
38 to->thread.prev_sched = from;
39 set_current(to);
41 switch_threads(&from->thread.mode.skas.switch_buf,
42 to->thread.mode.skas.switch_buf);
44 if(current->pid == 0)
45 switch_timers(1);
47 return(current->thread.prev_sched);
50 extern void schedule_tail(struct task_struct *prev);
52 void new_thread_handler(int sig)
54 int (*fn)(void *), n;
55 void *arg;
57 fn = current->thread.request.u.thread.proc;
58 arg = current->thread.request.u.thread.arg;
59 change_sig(SIGUSR1, 1);
60 thread_wait(&current->thread.mode.skas.switch_buf,
61 current->thread.mode.skas.fork_buf);
63 if(current->thread.prev_sched != NULL)
64 schedule_tail(current->thread.prev_sched);
65 current->thread.prev_sched = NULL;
67 /* The return value is 1 if the kernel thread execs a process,
68 * 0 if it just exits
70 n = run_kernel_thread(fn, arg, &current->thread.exec_buf);
71 if(n == 1)
72 userspace(&current->thread.regs.regs);
73 else do_exit(0);
76 void new_thread_proc(void *stack, void (*handler)(int sig))
78 init_new_thread_stack(stack, handler);
79 os_usr1_process(os_getpid());
82 void release_thread_skas(struct task_struct *task)
86 void fork_handler(int sig)
88 change_sig(SIGUSR1, 1);
89 thread_wait(&current->thread.mode.skas.switch_buf,
90 current->thread.mode.skas.fork_buf);
92 force_flush_all();
93 if(current->thread.prev_sched == NULL)
94 panic("blech");
96 schedule_tail(current->thread.prev_sched);
97 current->thread.prev_sched = NULL;
99 userspace(&current->thread.regs.regs);
102 int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
103 unsigned long stack_top, struct task_struct * p,
104 struct pt_regs *regs)
106 void (*handler)(int);
108 if(current->thread.forking){
109 memcpy(&p->thread.regs.regs.skas,
110 &current->thread.regs.regs.skas,
111 sizeof(p->thread.regs.regs.skas));
112 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
113 if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
115 handler = fork_handler;
117 else {
118 init_thread_registers(&p->thread.regs.regs);
119 p->thread.request.u.thread = current->thread.request.u.thread;
120 handler = new_thread_handler;
123 new_thread(p->thread_info, &p->thread.mode.skas.switch_buf,
124 &p->thread.mode.skas.fork_buf, handler);
125 return(0);
128 int new_mm(int from)
130 struct proc_mm_op copy;
131 int n, fd;
133 fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
134 if(fd < 0)
135 return(fd);
137 if(from != -1){
138 copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
139 .u =
140 { .copy_segments = from } } );
141 n = os_write_file(fd, &copy, sizeof(copy));
142 if(n != sizeof(copy))
143 printk("new_mm : /proc/mm copy_segments failed, "
144 "err = %d\n", -n);
147 return(fd);
150 void init_idle_skas(void)
152 cpu_tasks[current_thread->cpu].pid = os_getpid();
153 default_idle();
156 extern void start_kernel(void);
158 static int start_kernel_proc(void *unused)
160 int pid;
162 block_signals();
163 pid = os_getpid();
165 cpu_tasks[0].pid = pid;
166 cpu_tasks[0].task = current;
167 #ifdef CONFIG_SMP
168 cpu_online_map = cpumask_of_cpu(0);
169 #endif
170 start_kernel();
171 return(0);
174 int start_uml_skas(void)
176 start_userspace(0);
178 init_new_thread_signals(1);
179 uml_idle_timer();
181 init_task.thread.request.u.thread.proc = start_kernel_proc;
182 init_task.thread.request.u.thread.arg = NULL;
183 return(start_idle_thread(init_task.thread_info,
184 &init_task.thread.mode.skas.switch_buf,
185 &init_task.thread.mode.skas.fork_buf));
188 int external_pid_skas(struct task_struct *task)
190 #warning Need to look up userspace_pid by cpu
191 return(userspace_pid[0]);
194 int thread_pid_skas(struct task_struct *task)
196 #warning Need to look up userspace_pid by cpu
197 return(userspace_pid[0]);
201 * Overrides for Emacs so that we follow Linus's tabbing style.
202 * Emacs will notice this stuff at the end of the file and automatically
203 * adjust the settings for this buffer only. This must remain at the end
204 * of the file.
205 * ---------------------------------------------------------------------------
206 * Local variables:
207 * c-file-style: "linux"
208 * End: