Commit | Line | Data |
---|---|---|
ea2ba7dc | 1 | /* |
1da177e4 LT |
2 | * Copyright (C) 2000, 2002 Jeff Dike (jdike@karaya.com) |
3 | * Licensed under the GPL | |
4 | */ | |
5 | ||
1da177e4 LT |
6 | #include "linux/kernel.h" |
7 | #include "linux/sched.h" | |
8 | #include "linux/notifier.h" | |
9 | #include "linux/mm.h" | |
10 | #include "linux/types.h" | |
11 | #include "linux/tty.h" | |
12 | #include "linux/init.h" | |
13 | #include "linux/bootmem.h" | |
14 | #include "linux/spinlock.h" | |
15 | #include "linux/utsname.h" | |
16 | #include "linux/sysrq.h" | |
17 | #include "linux/seq_file.h" | |
18 | #include "linux/delay.h" | |
19 | #include "linux/module.h" | |
b4ffb6ad | 20 | #include "linux/utsname.h" |
1da177e4 LT |
21 | #include "asm/page.h" |
22 | #include "asm/pgtable.h" | |
23 | #include "asm/ptrace.h" | |
24 | #include "asm/elf.h" | |
25 | #include "asm/user.h" | |
16c11163 | 26 | #include "asm/setup.h" |
1da177e4 LT |
27 | #include "ubd_user.h" |
28 | #include "asm/current.h" | |
1da177e4 | 29 | #include "kern_util.h" |
4ff83ce1 | 30 | #include "as-layout.h" |
eb830759 | 31 | #include "arch.h" |
1da177e4 LT |
32 | #include "kern.h" |
33 | #include "mem_user.h" | |
34 | #include "mem.h" | |
1da177e4 LT |
35 | #include "initrd.h" |
36 | #include "init.h" | |
37 | #include "os.h" | |
1da177e4 LT |
38 | #include "mode_kern.h" |
39 | #include "mode.h" | |
cb66504d | 40 | #include "skas.h" |
1da177e4 LT |
41 | |
42 | #define DEFAULT_COMMAND_LINE "root=98:0" | |
43 | ||
1d1497e1 | 44 | /* Changed in add_arg and setup_arch, which run before SMP is started */ |
7a3a06d0 | 45 | static char __initdata command_line[COMMAND_LINE_SIZE] = { 0 }; |
1da177e4 | 46 | |
7a3a06d0 | 47 | static void __init add_arg(char *arg) |
1da177e4 LT |
48 | { |
49 | if (strlen(command_line) + strlen(arg) + 1 > COMMAND_LINE_SIZE) { | |
50 | printf("add_arg: Too many command line arguments!\n"); | |
51 | exit(1); | |
52 | } | |
53 | if(strlen(command_line) > 0) | |
54 | strcat(command_line, " "); | |
55 | strcat(command_line, arg); | |
56 | } | |
57 | ||
1d1497e1 JD |
58 | /* |
59 | * These fields are initialized at boot time and not changed. | |
60 | * XXX This structure is used only in the non-SMP case. Maybe this | |
61 | * should be moved to smp.c. | |
62 | */ | |
63 | struct cpuinfo_um boot_cpu_data = { | |
1da177e4 LT |
64 | .loops_per_jiffy = 0, |
65 | .ipi_pipe = { -1, -1 } | |
66 | }; | |
67 | ||
68 | unsigned long thread_saved_pc(struct task_struct *task) | |
69 | { | |
6aa802ce | 70 | return os_process_pc(thread_pid_skas(task)); |
1da177e4 LT |
71 | } |
72 | ||
b4ffb6ad JD |
73 | /* Changed in setup_arch, which is called in early boot */ |
74 | static char host_info[(__NEW_UTS_LEN + 1) * 5]; | |
75 | ||
1da177e4 LT |
76 | static int show_cpuinfo(struct seq_file *m, void *v) |
77 | { | |
78 | int index = 0; | |
79 | ||
80 | #ifdef CONFIG_SMP | |
81 | index = (struct cpuinfo_um *) v - cpu_data; | |
82 | if (!cpu_online(index)) | |
83 | return 0; | |
84 | #endif | |
85 | ||
86 | seq_printf(m, "processor\t: %d\n", index); | |
87 | seq_printf(m, "vendor_id\t: User Mode Linux\n"); | |
88 | seq_printf(m, "model name\t: UML\n"); | |
6aa802ce | 89 | seq_printf(m, "mode\t\t: skas\n"); |
1da177e4 LT |
90 | seq_printf(m, "host\t\t: %s\n", host_info); |
91 | seq_printf(m, "bogomips\t: %lu.%02lu\n\n", | |
92 | loops_per_jiffy/(500000/HZ), | |
93 | (loops_per_jiffy/(5000/HZ)) % 100); | |
94 | ||
a5ed1ffa | 95 | return 0; |
1da177e4 LT |
96 | } |
97 | ||
98 | static void *c_start(struct seq_file *m, loff_t *pos) | |
99 | { | |
100 | return *pos < NR_CPUS ? cpu_data + *pos : NULL; | |
101 | } | |
102 | ||
103 | static void *c_next(struct seq_file *m, void *v, loff_t *pos) | |
104 | { | |
105 | ++*pos; | |
106 | return c_start(m, pos); | |
107 | } | |
108 | ||
109 | static void c_stop(struct seq_file *m, void *v) | |
110 | { | |
111 | } | |
112 | ||
5e7672ec | 113 | const struct seq_operations cpuinfo_op = { |
1da177e4 LT |
114 | .start = c_start, |
115 | .next = c_next, | |
116 | .stop = c_stop, | |
117 | .show = show_cpuinfo, | |
118 | }; | |
119 | ||
1da177e4 LT |
120 | /* Set in linux_main */ |
121 | unsigned long host_task_size; | |
122 | unsigned long task_size; | |
1da177e4 | 123 | unsigned long uml_physmem; |
1d1497e1 | 124 | unsigned long uml_reserved; /* Also modified in mem_init */ |
1da177e4 LT |
125 | unsigned long start_vm; |
126 | unsigned long end_vm; | |
1d1497e1 JD |
127 | |
128 | /* Set in uml_ncpus_setup */ | |
1da177e4 LT |
129 | int ncpus = 1; |
130 | ||
1da177e4 LT |
131 | /* Set in early boot */ |
132 | static int have_root __initdata = 0; | |
1d1497e1 JD |
133 | |
134 | /* Set in uml_mem_setup and modified in linux_main */ | |
ae173816 | 135 | long long physmem_size = 32 * 1024 * 1024; |
1da177e4 | 136 | |
1da177e4 LT |
137 | static char *usage_string = |
138 | "User Mode Linux v%s\n" | |
139 | " available at http://user-mode-linux.sourceforge.net/\n\n"; | |
140 | ||
141 | static int __init uml_version_setup(char *line, int *add) | |
142 | { | |
96b644bd | 143 | printf("%s\n", init_utsname()->release); |
1da177e4 LT |
144 | exit(0); |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | __uml_setup("--version", uml_version_setup, | |
150 | "--version\n" | |
151 | " Prints the version number of the kernel.\n\n" | |
152 | ); | |
153 | ||
154 | static int __init uml_root_setup(char *line, int *add) | |
155 | { | |
156 | have_root = 1; | |
157 | return 0; | |
158 | } | |
159 | ||
160 | __uml_setup("root=", uml_root_setup, | |
161 | "root=<file containing the root fs>\n" | |
162 | " This is actually used by the generic kernel in exactly the same\n" | |
163 | " way as in any other kernel. If you configure a number of block\n" | |
164 | " devices and want to boot off something other than ubd0, you \n" | |
165 | " would use something like:\n" | |
166 | " root=/dev/ubd5\n\n" | |
167 | ); | |
168 | ||
fbd55779 JD |
169 | static int __init no_skas_debug_setup(char *line, int *add) |
170 | { | |
171 | printf("'debug' is not necessary to gdb UML in skas mode - run \n"); | |
42fda663 | 172 | printf("'gdb linux'"); |
fbd55779 JD |
173 | |
174 | return 0; | |
175 | } | |
176 | ||
177 | __uml_setup("debug", no_skas_debug_setup, | |
178 | "debug\n" | |
179 | " this flag is not needed to run gdb on UML in skas mode\n\n" | |
180 | ); | |
181 | ||
1da177e4 LT |
182 | #ifdef CONFIG_SMP |
183 | static int __init uml_ncpus_setup(char *line, int *add) | |
184 | { | |
a5ed1ffa JD |
185 | if (!sscanf(line, "%d", &ncpus)) { |
186 | printf("Couldn't parse [%s]\n", line); | |
187 | return -1; | |
188 | } | |
1da177e4 | 189 | |
a5ed1ffa | 190 | return 0; |
1da177e4 LT |
191 | } |
192 | ||
193 | __uml_setup("ncpus=", uml_ncpus_setup, | |
194 | "ncpus=<# of desired CPUs>\n" | |
195 | " This tells an SMP kernel how many virtual processors to start.\n\n" | |
196 | ); | |
197 | #endif | |
198 | ||
1da177e4 LT |
199 | static int __init Usage(char *line, int *add) |
200 | { | |
a5ed1ffa | 201 | const char **p; |
1da177e4 | 202 | |
96b644bd | 203 | printf(usage_string, init_utsname()->release); |
a5ed1ffa JD |
204 | p = &__uml_help_start; |
205 | while (p < &__uml_help_end) { | |
206 | printf("%s", *p); | |
207 | p++; | |
208 | } | |
1da177e4 | 209 | exit(0); |
1da177e4 LT |
210 | return 0; |
211 | } | |
212 | ||
213 | __uml_setup("--help", Usage, | |
214 | "--help\n" | |
215 | " Prints this message.\n\n" | |
216 | ); | |
217 | ||
218 | static int __init uml_checksetup(char *line, int *add) | |
219 | { | |
220 | struct uml_param *p; | |
221 | ||
222 | p = &__uml_setup_start; | |
223 | while(p < &__uml_setup_end) { | |
224 | int n; | |
225 | ||
226 | n = strlen(p->str); | |
227 | if(!strncmp(line, p->str, n)){ | |
228 | if (p->setup_func(line + n, add)) return 1; | |
229 | } | |
230 | p++; | |
231 | } | |
232 | return 0; | |
233 | } | |
234 | ||
235 | static void __init uml_postsetup(void) | |
236 | { | |
237 | initcall_t *p; | |
238 | ||
239 | p = &__uml_postsetup_start; | |
240 | while(p < &__uml_postsetup_end){ | |
241 | (*p)(); | |
242 | p++; | |
243 | } | |
244 | return; | |
245 | } | |
246 | ||
247 | /* Set during early boot */ | |
248 | unsigned long brk_start; | |
249 | unsigned long end_iomem; | |
250 | EXPORT_SYMBOL(end_iomem); | |
251 | ||
252 | #define MIN_VMALLOC (32 * 1024 * 1024) | |
253 | ||
23bbd586 JD |
254 | extern char __binary_start; |
255 | ||
7a3a06d0 | 256 | int __init linux_main(int argc, char **argv) |
1da177e4 LT |
257 | { |
258 | unsigned long avail, diff; | |
259 | unsigned long virtmem_size, max_physmem; | |
260 | unsigned int i, add; | |
cb66504d | 261 | char * mode; |
1da177e4 LT |
262 | |
263 | for (i = 1; i < argc; i++){ | |
264 | if((i == 1) && (argv[i][0] == ' ')) continue; | |
265 | add = 1; | |
266 | uml_checksetup(argv[i], &add); | |
267 | if (add) | |
268 | add_arg(argv[i]); | |
269 | } | |
270 | if(have_root == 0) | |
271 | add_arg(DEFAULT_COMMAND_LINE); | |
272 | ||
60d339f6 | 273 | os_early_checks(); |
cb66504d | 274 | |
42fda663 JD |
275 | can_do_skas(); |
276 | ||
277 | if (proc_mm && ptrace_faultinfo) | |
cb66504d PBG |
278 | mode = "SKAS3"; |
279 | else | |
280 | mode = "SKAS0"; | |
cb66504d PBG |
281 | |
282 | printf("UML running in %s mode\n", mode); | |
283 | ||
6aa802ce | 284 | host_task_size = set_task_sizes_skas(&task_size); |
1da177e4 | 285 | |
ea2ba7dc | 286 | /* |
a5ed1ffa JD |
287 | * Setting up handlers to 'sig_info' struct |
288 | */ | |
ea2ba7dc GS |
289 | os_fill_handlinfo(handlinfo_kern); |
290 | ||
1da177e4 | 291 | brk_start = (unsigned long) sbrk(0); |
6aa802ce | 292 | before_mem_skas(brk_start); |
1da177e4 LT |
293 | /* Increase physical memory size for exec-shield users |
294 | so they actually get what they asked for. This should | |
295 | add zero for non-exec shield users */ | |
296 | ||
297 | diff = UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end); | |
298 | if(diff > 1024 * 1024){ | |
299 | printf("Adding %ld bytes to physical memory to account for " | |
300 | "exec-shield gap\n", diff); | |
301 | physmem_size += UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end); | |
302 | } | |
303 | ||
1d1497e1 | 304 | uml_physmem = (unsigned long) &__binary_start & PAGE_MASK; |
1da177e4 LT |
305 | |
306 | /* Reserve up to 4M after the current brk */ | |
307 | uml_reserved = ROUND_4M(brk_start) + (1 << 22); | |
308 | ||
96b644bd | 309 | setup_machinename(init_utsname()->machine); |
1da177e4 | 310 | |
1da177e4 LT |
311 | highmem = 0; |
312 | iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK; | |
313 | max_physmem = get_kmem_end() - uml_physmem - iomem_size - MIN_VMALLOC; | |
314 | ||
315 | /* Zones have to begin on a 1 << MAX_ORDER page boundary, | |
316 | * so this makes sure that's true for highmem | |
317 | */ | |
318 | max_physmem &= ~((1 << (PAGE_SHIFT + MAX_ORDER)) - 1); | |
319 | if(physmem_size + iomem_size > max_physmem){ | |
320 | highmem = physmem_size + iomem_size - max_physmem; | |
321 | physmem_size -= highmem; | |
322 | #ifndef CONFIG_HIGHMEM | |
323 | highmem = 0; | |
324 | printf("CONFIG_HIGHMEM not enabled - physical memory shrunk " | |
d9f8b62a | 325 | "to %Lu bytes\n", physmem_size); |
1da177e4 LT |
326 | #endif |
327 | } | |
328 | ||
329 | high_physmem = uml_physmem + physmem_size; | |
330 | end_iomem = high_physmem + iomem_size; | |
331 | high_memory = (void *) end_iomem; | |
332 | ||
333 | start_vm = VMALLOC_START; | |
334 | ||
335 | setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem); | |
336 | if(init_maps(physmem_size, iomem_size, highmem)){ | |
d9f8b62a JD |
337 | printf("Failed to allocate mem_map for %Lu bytes of physical " |
338 | "memory and %Lu bytes of highmem\n", physmem_size, | |
1da177e4 LT |
339 | highmem); |
340 | exit(1); | |
341 | } | |
342 | ||
343 | virtmem_size = physmem_size; | |
344 | avail = get_kmem_end() - start_vm; | |
345 | if(physmem_size > avail) virtmem_size = avail; | |
346 | end_vm = start_vm + virtmem_size; | |
347 | ||
348 | if(virtmem_size < physmem_size) | |
ae173816 | 349 | printf("Kernel virtual memory size shrunk to %lu bytes\n", |
1da177e4 LT |
350 | virtmem_size); |
351 | ||
a5ed1ffa | 352 | uml_postsetup(); |
1da177e4 | 353 | |
57598fd7 | 354 | stack_protections((unsigned long) &init_thread_info); |
1da177e4 LT |
355 | os_flush_stdout(); |
356 | ||
6aa802ce | 357 | return start_uml_skas(); |
1da177e4 LT |
358 | } |
359 | ||
360 | extern int uml_exitcode; | |
361 | ||
362 | static int panic_exit(struct notifier_block *self, unsigned long unused1, | |
363 | void *unused2) | |
364 | { | |
365 | bust_spinlocks(1); | |
366 | show_regs(&(current->thread.regs)); | |
367 | bust_spinlocks(0); | |
368 | uml_exitcode = 1; | |
63843c26 | 369 | os_dump_core(); |
a5ed1ffa | 370 | return 0; |
1da177e4 LT |
371 | } |
372 | ||
373 | static struct notifier_block panic_exit_notifier = { | |
374 | .notifier_call = panic_exit, | |
375 | .next = NULL, | |
376 | .priority = 0 | |
377 | }; | |
378 | ||
379 | void __init setup_arch(char **cmdline_p) | |
380 | { | |
e041c683 AS |
381 | atomic_notifier_chain_register(&panic_notifier_list, |
382 | &panic_exit_notifier); | |
1da177e4 | 383 | paging_init(); |
19bf7e7a | 384 | strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); |
a5ed1ffa | 385 | *cmdline_p = command_line; |
b4ffb6ad | 386 | setup_hostinfo(host_info, sizeof host_info); |
1da177e4 LT |
387 | } |
388 | ||
389 | void __init check_bugs(void) | |
390 | { | |
391 | arch_check_bugs(); | |
a5ed1ffa | 392 | os_check_bugs(); |
1da177e4 LT |
393 | } |
394 | ||
9a0b5817 GH |
395 | void apply_alternatives(struct alt_instr *start, struct alt_instr *end) |
396 | { | |
397 | } | |
398 | ||
c61a8416 | 399 | #ifdef CONFIG_SMP |
9a0b5817 GH |
400 | void alternatives_smp_module_add(struct module *mod, char *name, |
401 | void *locks, void *locks_end, | |
402 | void *text, void *text_end) | |
403 | { | |
404 | } | |
405 | ||
406 | void alternatives_smp_module_del(struct module *mod) | |
1da177e4 LT |
407 | { |
408 | } | |
c61a8416 | 409 | #endif |