^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kmsg_dump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <as-layout.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <arch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <kern.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <kern_util.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <mem_user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <os.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define DEFAULT_COMMAND_LINE "root=98:0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /* Changed in add_arg and setup_arch, which run before SMP is started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static char __initdata command_line[COMMAND_LINE_SIZE] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static void __init add_arg(char *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) if (strlen(command_line) + strlen(arg) + 1 > COMMAND_LINE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) os_warn("add_arg: Too many command line arguments!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) exit(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (strlen(command_line) > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) strcat(command_line, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) strcat(command_line, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * These fields are initialized at boot time and not changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * XXX This structure is used only in the non-SMP case. Maybe this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * should be moved to smp.c.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct cpuinfo_um boot_cpu_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) .loops_per_jiffy = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) .ipi_pipe = { -1, -1 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) union thread_union cpu0_irqstack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) __section(".data..init_irqstack") =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) { .thread_info = INIT_THREAD_INFO(init_task) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* Changed in setup_arch, which is called in early boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static char host_info[(__NEW_UTS_LEN + 1) * 5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static int show_cpuinfo(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) seq_printf(m, "processor\t: %d\n", index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) seq_printf(m, "vendor_id\t: User Mode Linux\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) seq_printf(m, "model name\t: UML\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) seq_printf(m, "mode\t\t: skas\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) seq_printf(m, "host\t\t: %s\n", host_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) seq_printf(m, "bogomips\t: %lu.%02lu\n\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) loops_per_jiffy/(500000/HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) (loops_per_jiffy/(5000/HZ)) % 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static void *c_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return *pos < NR_CPUS ? cpu_data + *pos : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static void *c_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return c_start(m, pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void c_stop(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) const struct seq_operations cpuinfo_op = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .start = c_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .next = c_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .stop = c_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .show = show_cpuinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* Set in linux_main */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) unsigned long uml_physmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) EXPORT_SYMBOL(uml_physmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned long uml_reserved; /* Also modified in mem_init */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned long start_vm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) unsigned long end_vm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /* Set in uml_ncpus_setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int ncpus = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* Set in early boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int have_root __initdata = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) /* Set in uml_mem_setup and modified in linux_main */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) long long physmem_size = 32 * 1024 * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) EXPORT_SYMBOL(physmem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static const char *usage_string =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) "User Mode Linux v%s\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) " available at http://user-mode-linux.sourceforge.net/\n\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static int __init uml_version_setup(char *line, int *add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* Explicitly use printf() to show version in stdout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) printf("%s\n", init_utsname()->release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) __uml_setup("--version", uml_version_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) "--version\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) " Prints the version number of the kernel.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int __init uml_root_setup(char *line, int *add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) have_root = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) __uml_setup("root=", uml_root_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) "root=<file containing the root fs>\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) " This is actually used by the generic kernel in exactly the same\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) " way as in any other kernel. If you configure a number of block\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) " devices and want to boot off something other than ubd0, you \n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) " would use something like:\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) " root=/dev/ubd5\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int __init no_skas_debug_setup(char *line, int *add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) os_warn("'debug' is not necessary to gdb UML in skas mode - run\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) os_warn("'gdb linux'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) __uml_setup("debug", no_skas_debug_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) "debug\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) " this flag is not needed to run gdb on UML in skas mode\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static int __init Usage(char *line, int *add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) const char **p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) printf(usage_string, init_utsname()->release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) p = &__uml_help_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /* Explicitly use printf() to show help in stdout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) while (p < &__uml_help_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) printf("%s", *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) __uml_setup("--help", Usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) "--help\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) " Prints this message.\n\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static void __init uml_checksetup(char *line, int *add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct uml_param *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) p = &__uml_setup_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) while (p < &__uml_setup_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) size_t n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) n = strlen(p->str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (!strncmp(line, p->str, n) && p->setup_func(line + n, add))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static void __init uml_postsetup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) initcall_t *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) p = &__uml_postsetup_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) while (p < &__uml_postsetup_end) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) (*p)();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) p++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int panic_exit(struct notifier_block *self, unsigned long unused1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) void *unused2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) kmsg_dump(KMSG_DUMP_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) bust_spinlocks(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) bust_spinlocks(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) uml_exitcode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) os_dump_core();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static struct notifier_block panic_exit_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .notifier_call = panic_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) .next = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .priority = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void uml_finishsetup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) atomic_notifier_chain_register(&panic_notifier_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) &panic_exit_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) uml_postsetup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) new_thread_handler();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Set during early boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) unsigned long task_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) EXPORT_SYMBOL(task_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned long host_task_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) unsigned long brk_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) unsigned long end_iomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) EXPORT_SYMBOL(end_iomem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define MIN_VMALLOC (32 * 1024 * 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int __init linux_main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) unsigned long avail, diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned long virtmem_size, max_physmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned long stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) for (i = 1; i < argc; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if ((i == 1) && (argv[i][0] == ' '))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) add = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) uml_checksetup(argv[i], &add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (add)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) add_arg(argv[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (have_root == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) add_arg(DEFAULT_COMMAND_LINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) host_task_size = os_get_top_address();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * TASK_SIZE needs to be PGDIR_SIZE aligned or else exit_mmap craps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) task_size = host_task_size & PGDIR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) /* OS sanity checks that need to happen before the kernel runs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) os_early_checks();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) brk_start = (unsigned long) sbrk(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * Increase physical memory size for exec-shield users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * so they actually get what they asked for. This should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * add zero for non-exec shield users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) diff = UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (diff > 1024 * 1024) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) os_info("Adding %ld bytes to physical memory to account for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) "exec-shield gap\n", diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) physmem_size += UML_ROUND_UP(brk_start) - UML_ROUND_UP(&_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) uml_physmem = (unsigned long) __binary_start & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* Reserve up to 4M after the current brk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) uml_reserved = ROUND_4M(brk_start) + (1 << 22);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) setup_machinename(init_utsname()->machine);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) highmem = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) iomem_size = (iomem_size + PAGE_SIZE - 1) & PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) max_physmem = TASK_SIZE - uml_physmem - iomem_size - MIN_VMALLOC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * Zones have to begin on a 1 << MAX_ORDER page boundary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * so this makes sure that's true for highmem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) max_physmem &= ~((1 << (PAGE_SHIFT + MAX_ORDER)) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (physmem_size + iomem_size > max_physmem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) highmem = physmem_size + iomem_size - max_physmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) physmem_size -= highmem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) high_physmem = uml_physmem + physmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) end_iomem = high_physmem + iomem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) high_memory = (void *) end_iomem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) start_vm = VMALLOC_START;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) virtmem_size = physmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) stack = (unsigned long) argv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) stack &= ~(1024 * 1024 - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) avail = stack - start_vm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (physmem_size > avail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) virtmem_size = avail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) end_vm = start_vm + virtmem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (virtmem_size < physmem_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) os_info("Kernel virtual memory size shrunk to %lu bytes\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) virtmem_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) os_flush_stdout();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return start_uml();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) int __init __weak read_initrd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) void __init setup_arch(char **cmdline_p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) stack_protections((unsigned long) &init_thread_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) setup_physmem(uml_physmem, uml_reserved, physmem_size, highmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) mem_total_pages(physmem_size, iomem_size, highmem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) read_initrd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) paging_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) strlcpy(boot_command_line, command_line, COMMAND_LINE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) *cmdline_p = command_line;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) setup_hostinfo(host_info, sizeof host_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) void __init check_bugs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) arch_check_bugs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) os_check_bugs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) void apply_alternatives(struct alt_instr *start, struct alt_instr *end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) void *text_poke(void *addr, const void *opcode, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * In UML, the only reference to this function is in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * apply_relocate_add(), which shouldn't ever actually call this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * because UML doesn't have live patching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return memcpy(addr, opcode, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) void text_poke_sync(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }