GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / um / kernel / um_arch.c
blobda82f12f3439a0caf9d9d687545f13ccb2635db5
1 /*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
6 #include <linux/delay.h>
7 #include <linux/init.h>
8 #include <linux/mm.h>
9 #include <linux/module.h>
10 #include <linux/seq_file.h>
11 #include <linux/string.h>
12 #include <linux/utsname.h>
13 #include <asm/pgtable.h>
14 #include <asm/processor.h>
15 #include <asm/setup.h>
16 #include "as-layout.h"
17 #include "arch.h"
18 #include "init.h"
19 #include "kern.h"
20 #include "kern_util.h"
21 #include "mem_user.h"
22 #include "os.h"
24 #define DEFAULT_COMMAND_LINE "root=98:0"
26 /* Changed in add_arg and setup_arch, which run before SMP is started */
27 static char __initdata command_line[COMMAND_LINE_SIZE] = { 0 };
29 static void __init add_arg(char *arg)
31 if (strlen(command_line) + strlen(arg) + 1 > COMMAND_LINE_SIZE) {
32 printf("add_arg: Too many command line arguments!\n");
33 exit(1);
35 if (strlen(command_line) > 0)
36 strcat(command_line, " ");
37 strcat(command_line, arg);
40 struct cpuinfo_um boot_cpu_data = {
41 .loops_per_jiffy = 0,
42 .ipi_pipe = { -1, -1 }
45 unsigned long thread_saved_pc(struct task_struct *task)
47 return os_process_pc(userspace_pid[0]);
50 /* Changed in setup_arch, which is called in early boot */
51 static char host_info[(__NEW_UTS_LEN + 1) * 5];
53 static int show_cpuinfo(struct seq_file *m, void *v)
55 int index = 0;
57 #ifdef CONFIG_SMP
58 index = (struct cpuinfo_um *) v - cpu_data;
59 if (!cpu_online(index))
60 return 0;
61 #endif
63 seq_printf(m, "processor\t: %d\n", index);
64 seq_printf(m, "vendor_id\t: User Mode Linux\n");
65 seq_printf(m, "model name\t: UML\n");
66 seq_printf(m, "mode\t\t: skas\n");
67 seq_printf(m, "host\t\t: %s\n", host_info);
68 seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
69 loops_per_jiffy/(500000/HZ),
70 (loops_per_jiffy/(5000/HZ)) % 100);
72 return 0;
75 static void *c_start(struct seq_file *m, loff_t *pos)
77 return *pos < NR_CPUS ? cpu_data + *pos : NULL;
80 static void *c_next(struct seq_file *m, void *v, loff_t *pos)
82 ++*pos;
83 return c_start(m, pos);
86 static void c_stop(struct seq_file *m, void *v)
90 const struct seq_operations cpuinfo_op = {
91 .start = c_start,
92 .next = c_next,
93 .stop = c_stop,
94 .show = show_cpuinfo,
97 /* Set in linux_main */
98 unsigned long uml_physmem;
99 unsigned long uml_reserved; /* Also modified in mem_init */
100 unsigned long start_vm;
101 unsigned long end_vm;
103 /* Set in uml_ncpus_setup */
104 int ncpus = 1;
106 /* Set in early boot */
107 static int have_root __initdata = 0;
109 /* Set in uml_mem_setup and modified in linux_main */
110 long long physmem_size = 32 * 1024 * 1024;
112 static const char *usage_string =
113 "User Mode Linux v%s\n"
114 " available at http://user-mode-linux.sourceforge.net/\n\n";
116 static int __init uml_version_setup(char *line, int *add)
118 printf("%s\n", init_utsname()->release);
119 exit(0);
121 return 0;
124 __uml_setup("--version", uml_version_setup,
125 "--version\n"
126 " Prints the version number of the kernel.\n\n"
129 static int __init uml_root_setup(char *line, int *add)
131 have_root = 1;
132 return 0;
135 __uml_setup("root=", uml_root_setup,
136 "root=<file containing the root fs>\n"
137 " This is actually used by the generic kernel in exactly the same\n"
138 " way as in any other kernel. If you configure a number of block\n"
139 " devices and want to boot off something other than ubd0, you \n"
140 " would use something like:\n"
141 " root=/dev/ubd5\n\n"
144 static int __init no_skas_debug_setup(char *line, int *add)
146 printf("'debug' is not necessary to gdb UML in skas mode - run \n");
147 printf("'gdb linux'\n");
149 return 0;
152 __uml_setup("debug", no_skas_debug_setup,
153 "debug\n"
154 " this flag is not needed to run gdb on UML in skas mode\n\n"
157 #ifdef CONFIG_SMP
158 static int __init uml_ncpus_setup(char *line, int *add)
160 if (!sscanf(line, "%d", &ncpus)) {
161 printf("Couldn't parse [%s]\n", line);
162 return -1;
165 return 0;
168 __uml_setup("ncpus=", uml_ncpus_setup,
169 "ncpus=<# of desired CPUs>\n"
170 " This tells an SMP kernel how many virtual processors to start.\n\n"
172 #endif
174 static int __init Usage(char *line, int *add)
176 const char **p;
178 printf(usage_string, init_utsname()->release);
179 p = &__uml_help_start;
180 while (p < &__uml_help_end) {
181 printf("%s", *p);
182 p++;
184 exit(0);
185 return 0;
188 __uml_setup("--help", Usage,
189 "--help\n"
190 " Prints this message.\n\n"
193 static void __init uml_checksetup(char *line, int *add)
195 struct uml_param *p;
197 p = &__uml_setup_start;
198 while (p < &__uml_setup_end) {
199 size_t n;
201 n = strlen(p->str);
202 if (!strncmp(line, p->str, n) && p->setup_func(line + n, add))
203 return;
204 p++;
208 static void __init uml_postsetup(void)
210 initcall_t *p;
212 p = &__uml_postsetup_start;
213 while (p < &__uml_postsetup_end) {
214 (*p)();
215 p++;
217 return;
220 static int panic_exit(struct notifier_block *self, unsigned long unused1,
221 void *unused2)
223 bust_spinlocks(1);
224 show_regs(&(current->thread.regs));
225 bust_spinlocks(0);
226 uml_exitcode = 1;
227 os_dump_core();
228 return 0;
231 static struct notifier_block panic_exit_notifier = {
232 .notifier_call = panic_exit,
233 .next = NULL,
234 .priority = 0
237 /* Set during early boot */
238 unsigned long task_size;
239 EXPORT_SYMBOL(task_size);
241 unsigned long host_task_size;
243 unsigned long brk_start;
244 unsigned long end_iomem;
245 EXPORT_SYMBOL(end_iomem);
247 #define MIN_VMALLOC (32 * 1024 * 1024)
249 extern char __binary_start;
251 int __init linux_main(int argc, char **argv)
253 unsigned long avail, diff;
254 unsigned long virtmem_size, max_physmem;
255 unsigned long stack;
256 unsigned int i;
257 int add;
258 char * mode;
260 for (i = 1; i < argc; i++) {
261 if ((i == 1) && (argv[i][0] == ' '))
262 continue;
263 add = 1;
264 uml_checksetup(argv[i], &add);
265 if (add)
266 add_arg(argv[i]);
268 if (have_root == 0)
269 add_arg(DEFAULT_COMMAND_LINE);
271 host_task_size = os_get_top_address();
273 * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps
274 * out
276 task_size = host_task_size & PGDIR_MASK;
278 /* OS sanity checks that need to happen before the kernel runs */
279 os_early_checks();
281 can_do_skas();
283 if (proc_mm && ptrace_faultinfo)
284 mode = "SKAS3";
285 else
286 mode = "SKAS0";
288 printf("UML running in %s mode\n", mode);
290 brk_start = (unsigned long) sbrk(0);
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
298 diff = UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end);
299 if (diff > 1024 * 1024) {
300 printf("Adding %ld bytes to physical memory to account for "
301 "exec-shield gap\n", diff);
302 physmem_size += UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end);
305 uml_physmem = (unsigned long) &__binary_start & PAGE_MASK;
307 /* Reserve up to 4M after the current brk */
308 uml_reserved = ROUND_4M(brk_start) + (1 << 22);
310 setup_machinename(init_utsname()->machine);
312 highmem = 0;
313 iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK;
314 max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;
317 * Zones have to begin on a 1 << MAX_ORDER page boundary,
318 * so this makes sure that's true for highmem
320 max_physmem &= ~((1 << (PAGE_SHIFT + MAX_ORDER)) - 1);
321 if (physmem_size + iomem_size > max_physmem) {
322 highmem = physmem_size + iomem_size - max_physmem;
323 physmem_size -= highmem;
324 #ifndef CONFIG_HIGHMEM
325 highmem = 0;
326 printf("CONFIG_HIGHMEM not enabled - physical memory shrunk "
327 "to %Lu bytes\n", physmem_size);
328 #endif
331 high_physmem = uml_physmem + physmem_size;
332 end_iomem = high_physmem + iomem_size;
333 high_memory = (void *) end_iomem;
335 start_vm = VMALLOC_START;
337 setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
338 if (init_maps(physmem_size, iomem_size, highmem)) {
339 printf("Failed to allocate mem_map for %Lu bytes of physical "
340 "memory and %Lu bytes of highmem\n", physmem_size,
341 highmem);
342 exit(1);
345 virtmem_size = physmem_size;
346 stack = (unsigned long) argv;
347 stack &= ~(1024 * 1024 - 1);
348 avail = stack - start_vm;
349 if (physmem_size > avail)
350 virtmem_size = avail;
351 end_vm = start_vm + virtmem_size;
353 if (virtmem_size < physmem_size)
354 printf("Kernel virtual memory size shrunk to %lu bytes\n",
355 virtmem_size);
357 atomic_notifier_chain_register(&panic_notifier_list,
358 &panic_exit_notifier);
360 uml_postsetup();
362 stack_protections((unsigned long) &init_thread_info);
363 os_flush_stdout();
365 return start_uml();
368 void __init setup_arch(char **cmdline_p)
370 paging_init();
371 strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
372 *cmdline_p = command_line;
373 setup_hostinfo(host_info, sizeof host_info);
376 void __init check_bugs(void)
378 arch_check_bugs();
379 os_check_bugs();
382 void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
386 #ifdef CONFIG_SMP
387 void alternatives_smp_module_add(struct module *mod, char *name,
388 void *locks, void *locks_end,
389 void *text, void *text_end)
393 void alternatives_smp_module_del(struct module *mod)
396 #endif