• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/arch/um/kernel/
1/*
2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
4 */
5
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"
23
24#define DEFAULT_COMMAND_LINE "root=98:0"
25
26/* Changed in add_arg and setup_arch, which run before SMP is started */
27static char __initdata command_line[COMMAND_LINE_SIZE] = { 0 };
28
29static void __init add_arg(char *arg)
30{
31	if (strlen(command_line) + strlen(arg) + 1 > COMMAND_LINE_SIZE) {
32		printf("add_arg: Too many command line arguments!\n");
33		exit(1);
34	}
35	if (strlen(command_line) > 0)
36		strcat(command_line, " ");
37	strcat(command_line, arg);
38}
39
40struct cpuinfo_um boot_cpu_data = {
41	.loops_per_jiffy	= 0,
42	.ipi_pipe		= { -1, -1 }
43};
44
45unsigned long thread_saved_pc(struct task_struct *task)
46{
47	return os_process_pc(userspace_pid[0]);
48}
49
50/* Changed in setup_arch, which is called in early boot */
51static char host_info[(__NEW_UTS_LEN + 1) * 5];
52
53static int show_cpuinfo(struct seq_file *m, void *v)
54{
55	int index = 0;
56
57#ifdef CONFIG_SMP
58	index = (struct cpuinfo_um *) v - cpu_data;
59	if (!cpu_online(index))
60		return 0;
61#endif
62
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);
71
72	return 0;
73}
74
75static void *c_start(struct seq_file *m, loff_t *pos)
76{
77	return *pos < NR_CPUS ? cpu_data + *pos : NULL;
78}
79
80static void *c_next(struct seq_file *m, void *v, loff_t *pos)
81{
82	++*pos;
83	return c_start(m, pos);
84}
85
86static void c_stop(struct seq_file *m, void *v)
87{
88}
89
90const struct seq_operations cpuinfo_op = {
91	.start	= c_start,
92	.next	= c_next,
93	.stop	= c_stop,
94	.show	= show_cpuinfo,
95};
96
97/* Set in linux_main */
98unsigned long uml_physmem;
99unsigned long uml_reserved; /* Also modified in mem_init */
100unsigned long start_vm;
101unsigned long end_vm;
102
103/* Set in uml_ncpus_setup */
104int ncpus = 1;
105
106/* Set in early boot */
107static int have_root __initdata = 0;
108
109/* Set in uml_mem_setup and modified in linux_main */
110long long physmem_size = 32 * 1024 * 1024;
111
112static const char *usage_string =
113"User Mode Linux v%s\n"
114"	available at http://user-mode-linux.sourceforge.net/\n\n";
115
116static int __init uml_version_setup(char *line, int *add)
117{
118	printf("%s\n", init_utsname()->release);
119	exit(0);
120
121	return 0;
122}
123
124__uml_setup("--version", uml_version_setup,
125"--version\n"
126"    Prints the version number of the kernel.\n\n"
127);
128
129static int __init uml_root_setup(char *line, int *add)
130{
131	have_root = 1;
132	return 0;
133}
134
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"
142);
143
144static int __init no_skas_debug_setup(char *line, int *add)
145{
146	printf("'debug' is not necessary to gdb UML in skas mode - run \n");
147	printf("'gdb linux'\n");
148
149	return 0;
150}
151
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"
155);
156
157#ifdef CONFIG_SMP
158static int __init uml_ncpus_setup(char *line, int *add)
159{
160	if (!sscanf(line, "%d", &ncpus)) {
161		printf("Couldn't parse [%s]\n", line);
162		return -1;
163	}
164
165	return 0;
166}
167
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"
171);
172#endif
173
174static int __init Usage(char *line, int *add)
175{
176	const char **p;
177
178	printf(usage_string, init_utsname()->release);
179	p = &__uml_help_start;
180	while (p < &__uml_help_end) {
181		printf("%s", *p);
182		p++;
183	}
184	exit(0);
185	return 0;
186}
187
188__uml_setup("--help", Usage,
189"--help\n"
190"    Prints this message.\n\n"
191);
192
193static void __init uml_checksetup(char *line, int *add)
194{
195	struct uml_param *p;
196
197	p = &__uml_setup_start;
198	while (p < &__uml_setup_end) {
199		size_t n;
200
201		n = strlen(p->str);
202		if (!strncmp(line, p->str, n) && p->setup_func(line + n, add))
203			return;
204		p++;
205	}
206}
207
208static void __init uml_postsetup(void)
209{
210	initcall_t *p;
211
212	p = &__uml_postsetup_start;
213	while (p < &__uml_postsetup_end) {
214		(*p)();
215		p++;
216	}
217	return;
218}
219
220static int panic_exit(struct notifier_block *self, unsigned long unused1,
221		      void *unused2)
222{
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;
229}
230
231static struct notifier_block panic_exit_notifier = {
232	.notifier_call 		= panic_exit,
233	.next 			= NULL,
234	.priority 		= 0
235};
236
237/* Set during early boot */
238unsigned long task_size;
239EXPORT_SYMBOL(task_size);
240
241unsigned long host_task_size;
242
243unsigned long brk_start;
244unsigned long end_iomem;
245EXPORT_SYMBOL(end_iomem);
246
247#define MIN_VMALLOC (32 * 1024 * 1024)
248
249extern char __binary_start;
250
251int __init linux_main(int argc, char **argv)
252{
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;
259
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]);
267	}
268	if (have_root == 0)
269		add_arg(DEFAULT_COMMAND_LINE);
270
271	host_task_size = os_get_top_address();
272	/*
273	 * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps
274	 * out
275	 */
276	task_size = host_task_size & PGDIR_MASK;
277
278	/* OS sanity checks that need to happen before the kernel runs */
279	os_early_checks();
280
281	can_do_skas();
282
283	if (proc_mm && ptrace_faultinfo)
284		mode = "SKAS3";
285	else
286		mode = "SKAS0";
287
288	printf("UML running in %s mode\n", mode);
289
290	brk_start = (unsigned long) sbrk(0);
291
292	/*
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
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);
303	}
304
305	uml_physmem = (unsigned long) &__binary_start & PAGE_MASK;
306
307	/* Reserve up to 4M after the current brk */
308	uml_reserved = ROUND_4M(brk_start) + (1 << 22);
309
310	setup_machinename(init_utsname()->machine);
311
312	highmem = 0;
313	iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK;
314	max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;
315
316	/*
317	 * Zones have to begin on a 1 << MAX_ORDER page boundary,
318	 * so this makes sure that's true for highmem
319	 */
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
329	}
330
331	high_physmem = uml_physmem + physmem_size;
332	end_iomem = high_physmem + iomem_size;
333	high_memory = (void *) end_iomem;
334
335	start_vm = VMALLOC_START;
336
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);
343	}
344
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;
352
353	if (virtmem_size < physmem_size)
354		printf("Kernel virtual memory size shrunk to %lu bytes\n",
355		       virtmem_size);
356
357	atomic_notifier_chain_register(&panic_notifier_list,
358				       &panic_exit_notifier);
359
360	uml_postsetup();
361
362	stack_protections((unsigned long) &init_thread_info);
363	os_flush_stdout();
364
365	return start_uml();
366}
367
368void __init setup_arch(char **cmdline_p)
369{
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);
374}
375
376void __init check_bugs(void)
377{
378	arch_check_bugs();
379	os_check_bugs();
380}
381
382void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
383{
384}
385
386#ifdef CONFIG_SMP
387void alternatives_smp_module_add(struct module *mod, char *name,
388				 void *locks, void *locks_end,
389				 void *text,  void *text_end)
390{
391}
392
393void alternatives_smp_module_del(struct module *mod)
394{
395}
396#endif
397