2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
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"
20 #include "user_util.h"
27 void *switch_to_skas(void *prev, void *next)
29 struct task_struct *from, *to;
34 /* XXX need to check runqueues[cpu].idle */
38 to->thread.prev_sched = from;
41 switch_threads(&from->thread.mode.skas.switch_buf,
42 to->thread.mode.skas.switch_buf);
47 return(current->thread.prev_sched);
50 extern void schedule_tail(struct task_struct *prev);
52 void new_thread_handler(int sig)
57 fn = current->thread.request.u.thread.proc;
58 arg = current->thread.request.u.thread.arg;
59 change_sig(SIGUSR1, 1);
60 thread_wait(¤t->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,
70 n = run_kernel_thread(fn, arg, ¤t->thread.exec_buf);
72 userspace(¤t->thread.regs.regs);
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 exit_thread_skas(void)
90 void fork_handler(int sig)
92 change_sig(SIGUSR1, 1);
93 thread_wait(¤t->thread.mode.skas.switch_buf,
94 current->thread.mode.skas.fork_buf);
97 if(current->thread.prev_sched == NULL)
100 schedule_tail(current->thread.prev_sched);
101 current->thread.prev_sched = NULL;
103 userspace(¤t->thread.regs.regs);
106 int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
107 unsigned long stack_top, struct task_struct * p,
108 struct pt_regs *regs)
110 void (*handler)(int);
112 if(current->thread.forking){
113 memcpy(&p->thread.regs.regs.skas,
114 ¤t->thread.regs.regs.skas,
115 sizeof(p->thread.regs.regs.skas));
116 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
117 if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
119 handler = fork_handler;
122 memcpy(p->thread.regs.regs.skas.regs, exec_regs,
123 sizeof(p->thread.regs.regs.skas.regs));
124 memcpy(p->thread.regs.regs.skas.fp, exec_fp_regs,
125 sizeof(p->thread.regs.regs.skas.fp));
126 memcpy(p->thread.regs.regs.skas.xfp, exec_fpx_regs,
127 sizeof(p->thread.regs.regs.skas.xfp));
128 p->thread.request.u.thread = current->thread.request.u.thread;
129 handler = new_thread_handler;
132 new_thread(p->thread_info, &p->thread.mode.skas.switch_buf,
133 &p->thread.mode.skas.fork_buf, handler);
139 struct proc_mm_op copy;
142 fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
147 copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
149 { .copy_segments = from } } );
150 n = os_write_file(fd, ©, sizeof(copy));
151 if(n != sizeof(copy))
152 printk("new_mm : /proc/mm copy_segments failed, "
159 void init_idle_skas(void)
161 cpu_tasks[current_thread->cpu].pid = os_getpid();
165 extern void start_kernel(void);
167 static int start_kernel_proc(void *unused)
174 cpu_tasks[0].pid = pid;
175 cpu_tasks[0].task = current;
177 cpu_online_map = cpumask_of_cpu(0);
183 int start_uml_skas(void)
186 capture_signal_stack();
188 init_new_thread_signals(1);
191 init_task.thread.request.u.thread.proc = start_kernel_proc;
192 init_task.thread.request.u.thread.arg = NULL;
193 return(start_idle_thread(init_task.thread_info,
194 &init_task.thread.mode.skas.switch_buf,
195 &init_task.thread.mode.skas.fork_buf));
198 int external_pid_skas(struct task_struct *task)
200 #warning Need to look up userspace_pid by cpu
201 return(userspace_pid[0]);
204 int thread_pid_skas(struct task_struct *task)
206 #warning Need to look up userspace_pid by cpu
207 return(userspace_pid[0]);
211 * Overrides for Emacs so that we follow Linus's tabbing style.
212 * Emacs will notice this stuff at the end of the file and automatically
213 * adjust the settings for this buffer only. This must remain at the end
215 * ---------------------------------------------------------------------------
217 * c-file-style: "linux"