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 static atomic_t using_sysemu;
30 void set_using_sysemu(int value)
32 atomic_set(&using_sysemu, sysemu_supported && value);
35 int get_using_sysemu(void)
37 return atomic_read(&using_sysemu);
40 int proc_read_sysemu(char *buf, char **start, off_t offset, int size,int *eof, void *data)
42 if (snprintf(buf, size, "%d\n", get_using_sysemu()) < size) /*No overflow*/
48 int proc_write_sysemu(struct file *file,const char *buf, unsigned long count,void *data)
52 if (copy_from_user(tmp, buf, 1))
55 if (tmp[0] == '0' || tmp[0] == '1')
56 set_using_sysemu(tmp[0] - '0');
57 return count; /*We use the first char, but pretend to write everything*/
60 int __init make_proc_sysemu(void)
62 struct proc_dir_entry *ent;
63 if (mode_tt || !sysemu_supported)
66 ent = create_proc_entry("sysemu", 0600, &proc_root);
70 printk("Failed to register /proc/sysemu\n");
74 ent->read_proc = proc_read_sysemu;
75 ent->write_proc = proc_write_sysemu;
80 late_initcall(make_proc_sysemu);
82 int singlestepping_skas(void)
84 int ret = current->ptrace & PT_DTRACE;
86 current->ptrace &= ~PT_DTRACE;
90 void *switch_to_skas(void *prev, void *next)
92 struct task_struct *from, *to;
97 /* XXX need to check runqueues[cpu].idle */
101 to->thread.prev_sched = from;
104 switch_threads(&from->thread.mode.skas.switch_buf,
105 to->thread.mode.skas.switch_buf);
107 if(current->pid == 0)
110 return(current->thread.prev_sched);
113 extern void schedule_tail(struct task_struct *prev);
115 void new_thread_handler(int sig)
117 int (*fn)(void *), n;
120 fn = current->thread.request.u.thread.proc;
121 arg = current->thread.request.u.thread.arg;
122 change_sig(SIGUSR1, 1);
123 thread_wait(¤t->thread.mode.skas.switch_buf,
124 current->thread.mode.skas.fork_buf);
126 if(current->thread.prev_sched != NULL)
127 schedule_tail(current->thread.prev_sched);
128 current->thread.prev_sched = NULL;
130 /* The return value is 1 if the kernel thread execs a process,
133 n = run_kernel_thread(fn, arg, ¤t->thread.exec_buf);
135 userspace(¤t->thread.regs.regs);
139 void new_thread_proc(void *stack, void (*handler)(int sig))
141 init_new_thread_stack(stack, handler);
142 os_usr1_process(os_getpid());
145 void release_thread_skas(struct task_struct *task)
149 void exit_thread_skas(void)
153 void fork_handler(int sig)
155 change_sig(SIGUSR1, 1);
156 thread_wait(¤t->thread.mode.skas.switch_buf,
157 current->thread.mode.skas.fork_buf);
160 if(current->thread.prev_sched == NULL)
163 schedule_tail(current->thread.prev_sched);
164 current->thread.prev_sched = NULL;
166 userspace(¤t->thread.regs.regs);
169 int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
170 unsigned long stack_top, struct task_struct * p,
171 struct pt_regs *regs)
173 void (*handler)(int);
175 if(current->thread.forking){
176 memcpy(&p->thread.regs.regs.skas,
177 ¤t->thread.regs.regs.skas,
178 sizeof(p->thread.regs.regs.skas));
179 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
180 if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
182 handler = fork_handler;
185 memcpy(p->thread.regs.regs.skas.regs, exec_regs,
186 sizeof(p->thread.regs.regs.skas.regs));
187 memcpy(p->thread.regs.regs.skas.fp, exec_fp_regs,
188 sizeof(p->thread.regs.regs.skas.fp));
189 memcpy(p->thread.regs.regs.skas.xfp, exec_fpx_regs,
190 sizeof(p->thread.regs.regs.skas.xfp));
191 p->thread.request.u.thread = current->thread.request.u.thread;
192 handler = new_thread_handler;
195 new_thread(p->thread_info, &p->thread.mode.skas.switch_buf,
196 &p->thread.mode.skas.fork_buf, handler);
202 struct proc_mm_op copy;
205 fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
210 copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
212 { .copy_segments = from } } );
213 n = os_write_file(fd, ©, sizeof(copy));
214 if(n != sizeof(copy))
215 printk("new_mm : /proc/mm copy_segments failed, "
222 void init_idle_skas(void)
224 cpu_tasks[current_thread->cpu].pid = os_getpid();
228 extern void start_kernel(void);
230 static int start_kernel_proc(void *unused)
237 cpu_tasks[0].pid = pid;
238 cpu_tasks[0].task = current;
240 cpu_online_map = cpumask_of_cpu(0);
246 int start_uml_skas(void)
249 capture_signal_stack();
251 init_new_thread_signals(1);
254 init_task.thread.request.u.thread.proc = start_kernel_proc;
255 init_task.thread.request.u.thread.arg = NULL;
256 return(start_idle_thread(init_task.thread_info,
257 &init_task.thread.mode.skas.switch_buf,
258 &init_task.thread.mode.skas.fork_buf));
261 int external_pid_skas(struct task_struct *task)
263 #warning Need to look up userspace_pid by cpu
264 return(userspace_pid[0]);
267 int thread_pid_skas(struct task_struct *task)
269 #warning Need to look up userspace_pid by cpu
270 return(userspace_pid[0]);
274 * Overrides for Emacs so that we follow Linus's tabbing style.
275 * Emacs will notice this stuff at the end of the file and automatically
276 * adjust the settings for this buffer only. This must remain at the end
278 * ---------------------------------------------------------------------------
280 * c-file-style: "linux"