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 "as-layout.h"
19 #include "user_util.h"
23 #include "registers.h"
25 void switch_to_skas(void *prev, void *next)
27 struct task_struct *from, *to;
32 /* XXX need to check runqueues[cpu].idle */
36 switch_threads(&from->thread.mode.skas.switch_buf,
37 &to->thread.mode.skas.switch_buf);
39 arch_switch_to_skas(current->thread.prev_sched, current);
45 extern void schedule_tail(struct task_struct *prev);
47 /* This is called magically, by its address being stuffed in a jmp_buf
48 * and being longjmp-d to.
50 void new_thread_handler(void)
55 if(current->thread.prev_sched != NULL)
56 schedule_tail(current->thread.prev_sched);
57 current->thread.prev_sched = NULL;
59 fn = current->thread.request.u.thread.proc;
60 arg = current->thread.request.u.thread.arg;
62 /* The return value is 1 if the kernel thread execs a process,
65 n = run_kernel_thread(fn, arg, ¤t->thread.exec_buf);
67 /* Handle any immediate reschedules or signals */
69 userspace(¤t->thread.regs.regs);
74 void release_thread_skas(struct task_struct *task)
78 /* Called magically, see new_thread_handler above */
79 void fork_handler(void)
82 if(current->thread.prev_sched == NULL)
85 schedule_tail(current->thread.prev_sched);
87 /* XXX: if interrupt_end() calls schedule, this call to
88 * arch_switch_to_skas isn't needed. We could want to apply this to
89 * improve performance. -bb */
90 arch_switch_to_skas(current->thread.prev_sched, current);
92 current->thread.prev_sched = NULL;
94 /* Handle any immediate reschedules or signals */
97 userspace(¤t->thread.regs.regs);
100 int copy_thread_skas(int nr, unsigned long clone_flags, unsigned long sp,
101 unsigned long stack_top, struct task_struct * p,
102 struct pt_regs *regs)
104 void (*handler)(void);
106 if(current->thread.forking){
107 memcpy(&p->thread.regs.regs.skas, ®s->regs.skas,
108 sizeof(p->thread.regs.regs.skas));
109 REGS_SET_SYSCALL_RETURN(p->thread.regs.regs.skas.regs, 0);
110 if(sp != 0) REGS_SP(p->thread.regs.regs.skas.regs) = sp;
112 handler = fork_handler;
114 arch_copy_thread(¤t->thread.arch, &p->thread.arch);
117 init_thread_registers(&p->thread.regs.regs);
118 p->thread.request.u.thread = current->thread.request.u.thread;
119 handler = new_thread_handler;
122 new_thread(task_stack_page(p), &p->thread.mode.skas.switch_buf,
127 int new_mm(unsigned long stack)
131 fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
136 map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);
141 void init_idle_skas(void)
143 cpu_tasks[current_thread->cpu].pid = os_getpid();
147 extern void start_kernel(void);
149 static int start_kernel_proc(void *unused)
156 cpu_tasks[0].pid = pid;
157 cpu_tasks[0].task = current;
159 cpu_online_map = cpumask_of_cpu(0);
165 extern int userspace_pid[];
167 int start_uml_skas(void)
170 userspace_pid[0] = start_userspace(0);
172 init_new_thread_signals();
174 init_task.thread.request.u.thread.proc = start_kernel_proc;
175 init_task.thread.request.u.thread.arg = NULL;
176 return(start_idle_thread(task_stack_page(&init_task),
177 &init_task.thread.mode.skas.switch_buf));
180 int external_pid_skas(struct task_struct *task)
182 #warning Need to look up userspace_pid by cpu
183 return(userspace_pid[0]);
186 int thread_pid_skas(struct task_struct *task)
188 #warning Need to look up userspace_pid by cpu
189 return(userspace_pid[0]);
192 void kill_off_processes_skas(void)
195 #warning need to loop over userspace_pids in kill_off_processes_skas
196 os_kill_ptraced_process(userspace_pid[0], 1);
198 struct task_struct *p;
206 pid = p->mm->context.skas.id.u.pid;
207 os_kill_ptraced_process(pid, 1);
212 unsigned long current_stub_stack(void)
214 if(current->mm == NULL)
217 return(current->mm->context.skas.id.stack);