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, 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;
64 ent = create_proc_entry("sysemu", 00600, &proc_root);
65 ent->read_proc = proc_read_sysemu;
66 ent->write_proc = proc_write_sysemu;
70 printk("Failed to register /proc/sysemu\n");
77 late_initcall(make_proc_sysemu);
79 int singlestepping_skas(void)
81 int ret = current->ptrace & PT_DTRACE;
83 current->ptrace &= ~PT_DTRACE;
87 void *switch_to_skas(void *prev, void *next)
89 struct task_struct *from, *to;
94 /* XXX need to check runqueues[cpu].idle */
98 to->thread.prev_sched = from;
101 switch_threads(&from->thread.mode.skas.switch_buf,
102 to->thread.mode.skas.switch_buf);
104 if(current->pid == 0)
107 return(current->thread.prev_sched);
110 extern void schedule_tail(struct task_struct *prev);
112 void new_thread_handler(int sig)
114 int (*fn)(void *), n;
117 fn = current->thread.request.u.thread.proc;
118 arg = current->thread.request.u.thread.arg;
119 change_sig(SIGUSR1, 1);
120 thread_wait(¤t->thread.mode.skas.switch_buf,
121 current->thread.mode.skas.fork_buf);
123 if(current->thread.prev_sched != NULL)
124 schedule_tail(current->thread.prev_sched);
125 current->thread.prev_sched = NULL;
127 /* The return value is 1 if the kernel thread execs a process,
130 n = run_kernel_thread(fn, arg, ¤t->thread.exec_buf);
132 userspace(¤t->thread.regs.regs);
136 void new_thread_proc(void *stack, void (*handler)(int sig))
138 init_new_thread_stack(stack, handler);
139 os_usr1_process(os_getpid());
142 void release_thread_skas(struct task_struct *task)
146 void exit_thread_skas(void)
150 void fork_handler(int sig)
152 change_sig(SIGUSR1, 1);
153 thread_wait(¤t->thread.mode.skas.switch_buf,
154 current->thread.mode.skas.fork_buf);
157 if(current->thread.prev_sched == NULL)
160 schedule_tail(current->thread.prev_sched);
161 current->thread.prev_sched = NULL;
163 userspace(¤t->thread.regs.regs);
166 int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
167 unsigned long stack_top, struct task_struct * p,
168 struct pt_regs *regs)
170 void (*handler)(int);
172 if(current->thread.forking){
173 memcpy(&p->thread.regs.regs.skas,
174 ¤t->thread.regs.regs.skas,
175 sizeof(p->thread.regs.regs.skas));
176 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
177 if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
179 handler = fork_handler;
182 memcpy(p->thread.regs.regs.skas.regs, exec_regs,
183 sizeof(p->thread.regs.regs.skas.regs));
184 memcpy(p->thread.regs.regs.skas.fp, exec_fp_regs,
185 sizeof(p->thread.regs.regs.skas.fp));
186 memcpy(p->thread.regs.regs.skas.xfp, exec_fpx_regs,
187 sizeof(p->thread.regs.regs.skas.xfp));
188 p->thread.request.u.thread = current->thread.request.u.thread;
189 handler = new_thread_handler;
192 new_thread((void *) p->thread.kernel_stack,
193 &p->thread.mode.skas.switch_buf,
194 &p->thread.mode.skas.fork_buf, handler);
198 void init_idle_skas(void)
200 cpu_tasks[current_thread->cpu].pid = os_getpid();
204 extern void start_kernel(void);
206 static int start_kernel_proc(void *unused)
213 cpu_tasks[0].pid = pid;
214 cpu_tasks[0].task = current;
216 cpu_online_map = cpumask_of_cpu(0);
222 int start_uml_skas(void)
225 capture_signal_stack();
228 init_new_thread_signals(1);
230 init_task.thread.request.u.thread.proc = start_kernel_proc;
231 init_task.thread.request.u.thread.arg = NULL;
232 return(start_idle_thread((void *) init_task.thread.kernel_stack,
233 &init_task.thread.mode.skas.switch_buf,
234 &init_task.thread.mode.skas.fork_buf));
237 int external_pid_skas(struct task_struct *task)
239 #warning Need to look up userspace_pid by cpu
240 return(userspace_pid[0]);
243 int thread_pid_skas(struct task_struct *task)
245 #warning Need to look up userspace_pid by cpu
246 return(userspace_pid[0]);
250 * Overrides for Emacs so that we follow Linus's tabbing style.
251 * Emacs will notice this stuff at the end of the file and automatically
252 * adjust the settings for this buffer only. This must remain at the end
254 * ---------------------------------------------------------------------------
256 * c-file-style: "linux"