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"
22 #include "registers.h"
24 void switch_to_skas(void *prev
, void *next
)
26 struct task_struct
*from
, *to
;
31 /* XXX need to check runqueues[cpu].idle */
35 switch_threads(&from
->thread
.mode
.skas
.switch_buf
,
36 &to
->thread
.mode
.skas
.switch_buf
);
38 arch_switch_to_skas(current
->thread
.prev_sched
, current
);
44 extern void schedule_tail(struct task_struct
*prev
);
46 /* This is called magically, by its address being stuffed in a jmp_buf
47 * and being longjmp-d to.
49 void new_thread_handler(void)
54 if(current
->thread
.prev_sched
!= NULL
)
55 schedule_tail(current
->thread
.prev_sched
);
56 current
->thread
.prev_sched
= NULL
;
58 fn
= current
->thread
.request
.u
.thread
.proc
;
59 arg
= current
->thread
.request
.u
.thread
.arg
;
61 /* The return value is 1 if the kernel thread execs a process,
64 n
= run_kernel_thread(fn
, arg
, ¤t
->thread
.exec_buf
);
66 /* Handle any immediate reschedules or signals */
68 userspace(¤t
->thread
.regs
.regs
);
73 void release_thread_skas(struct task_struct
*task
)
77 /* Called magically, see new_thread_handler above */
78 void fork_handler(void)
81 if(current
->thread
.prev_sched
== NULL
)
84 schedule_tail(current
->thread
.prev_sched
);
86 /* XXX: if interrupt_end() calls schedule, this call to
87 * arch_switch_to_skas isn't needed. We could want to apply this to
88 * improve performance. -bb */
89 arch_switch_to_skas(current
->thread
.prev_sched
, current
);
91 current
->thread
.prev_sched
= NULL
;
93 /* Handle any immediate reschedules or signals */
96 userspace(¤t
->thread
.regs
.regs
);
99 int copy_thread_skas(int nr
, unsigned long clone_flags
, unsigned long sp
,
100 unsigned long stack_top
, struct task_struct
* p
,
101 struct pt_regs
*regs
)
103 void (*handler
)(void);
105 if(current
->thread
.forking
){
106 memcpy(&p
->thread
.regs
.regs
.skas
, ®s
->regs
.skas
,
107 sizeof(p
->thread
.regs
.regs
.skas
));
108 REGS_SET_SYSCALL_RETURN(p
->thread
.regs
.regs
.skas
.regs
, 0);
109 if(sp
!= 0) REGS_SP(p
->thread
.regs
.regs
.skas
.regs
) = sp
;
111 handler
= fork_handler
;
113 arch_copy_thread(¤t
->thread
.arch
, &p
->thread
.arch
);
116 init_thread_registers(&p
->thread
.regs
.regs
);
117 p
->thread
.request
.u
.thread
= current
->thread
.request
.u
.thread
;
118 handler
= new_thread_handler
;
121 new_thread(task_stack_page(p
), &p
->thread
.mode
.skas
.switch_buf
,
126 int new_mm(unsigned long stack
)
130 fd
= os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
135 map_stub_pages(fd
, CONFIG_STUB_CODE
, CONFIG_STUB_DATA
, stack
);
140 void init_idle_skas(void)
142 cpu_tasks
[current_thread
->cpu
].pid
= os_getpid();
146 extern void start_kernel(void);
148 static int start_kernel_proc(void *unused
)
155 cpu_tasks
[0].pid
= pid
;
156 cpu_tasks
[0].task
= current
;
158 cpu_online_map
= cpumask_of_cpu(0);
164 extern int userspace_pid
[];
166 extern char cpu0_irqstack
[];
168 int start_uml_skas(void)
170 stack_protections((unsigned long) &cpu0_irqstack
);
171 set_sigstack(cpu0_irqstack
, THREAD_SIZE
);
173 userspace_pid
[0] = start_userspace(0);
175 init_new_thread_signals();
177 init_task
.thread
.request
.u
.thread
.proc
= start_kernel_proc
;
178 init_task
.thread
.request
.u
.thread
.arg
= NULL
;
179 return(start_idle_thread(task_stack_page(&init_task
),
180 &init_task
.thread
.mode
.skas
.switch_buf
));
183 int external_pid_skas(struct task_struct
*task
)
185 /* FIXME: Need to look up userspace_pid by cpu */
186 return(userspace_pid
[0]);
189 int thread_pid_skas(struct task_struct
*task
)
191 /* FIXME: Need to look up userspace_pid by cpu */
192 return(userspace_pid
[0]);
195 void kill_off_processes_skas(void)
199 * FIXME: need to loop over userspace_pids in
200 * kill_off_processes_skas
202 os_kill_ptraced_process(userspace_pid
[0], 1);
204 struct task_struct
*p
;
212 pid
= p
->mm
->context
.skas
.id
.u
.pid
;
213 os_kill_ptraced_process(pid
, 1);
218 unsigned long current_stub_stack(void)
220 if(current
->mm
== NULL
)
223 return(current
->mm
->context
.skas
.id
.stack
);