blob: dabae62d52bed566890b8d22125cd2155290a742 [file] [log] [blame]
Jeff Dike995473a2006-09-27 01:50:40 -07001/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
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"
Jeff Dike4ff83ce2007-05-06 14:51:08 -070016#include "as-layout.h"
Jeff Dike995473a2006-09-27 01:50:40 -070017#include "skas.h"
18#include "os.h"
Jeff Dike995473a2006-09-27 01:50:40 -070019#include "tlb.h"
20#include "kern.h"
Jeff Dike995473a2006-09-27 01:50:40 -070021#include "registers.h"
22
Jeff Dike995473a2006-09-27 01:50:40 -070023extern void schedule_tail(struct task_struct *prev);
24
Jeff Dike995473a2006-09-27 01:50:40 -070025int new_mm(unsigned long stack)
26{
27 int fd;
28
29 fd = os_open_file("/proc/mm", of_cloexec(of_write(OPENFLAGS())), 0);
30 if(fd < 0)
Jeff Dike77bf4402007-10-16 01:26:58 -070031 return fd;
Jeff Dike995473a2006-09-27 01:50:40 -070032
33 if(skas_needs_stub)
34 map_stub_pages(fd, CONFIG_STUB_CODE, CONFIG_STUB_DATA, stack);
35
Jeff Dike77bf4402007-10-16 01:26:58 -070036 return fd;
Jeff Dike995473a2006-09-27 01:50:40 -070037}
38
39extern void start_kernel(void);
40
Jeff Dike97a1fcb2007-07-23 18:43:48 -070041static int __init start_kernel_proc(void *unused)
Jeff Dike995473a2006-09-27 01:50:40 -070042{
43 int pid;
44
45 block_signals();
46 pid = os_getpid();
47
48 cpu_tasks[0].pid = pid;
49 cpu_tasks[0].task = current;
50#ifdef CONFIG_SMP
51 cpu_online_map = cpumask_of_cpu(0);
52#endif
53 start_kernel();
Jeff Dike77bf4402007-10-16 01:26:58 -070054 return 0;
Jeff Dike995473a2006-09-27 01:50:40 -070055}
56
57extern int userspace_pid[];
58
Jeff Dikec14b8492007-05-10 22:22:34 -070059extern char cpu0_irqstack[];
60
Jeff Dike77bf4402007-10-16 01:26:58 -070061int __init start_uml(void)
Jeff Dike995473a2006-09-27 01:50:40 -070062{
Jeff Dikec14b8492007-05-10 22:22:34 -070063 stack_protections((unsigned long) &cpu0_irqstack);
64 set_sigstack(cpu0_irqstack, THREAD_SIZE);
Jeff Dike995473a2006-09-27 01:50:40 -070065 if(proc_mm)
66 userspace_pid[0] = start_userspace(0);
67
68 init_new_thread_signals();
69
70 init_task.thread.request.u.thread.proc = start_kernel_proc;
71 init_task.thread.request.u.thread.arg = NULL;
Jeff Dike77bf4402007-10-16 01:26:58 -070072 return start_idle_thread(task_stack_page(&init_task),
73 &init_task.thread.switch_buf);
Jeff Dike995473a2006-09-27 01:50:40 -070074}
75
76unsigned long current_stub_stack(void)
77{
78 if(current->mm == NULL)
Jeff Dike77bf4402007-10-16 01:26:58 -070079 return 0;
Jeff Dike995473a2006-09-27 01:50:40 -070080
Jeff Dike77bf4402007-10-16 01:26:58 -070081 return current->mm->context.skas.id.stack;
Jeff Dike995473a2006-09-27 01:50:40 -070082}