init.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Types.h>
  7. #include <Kernel/Arch/InterruptManagement.h>
  8. #include <Kernel/Arch/Processor.h>
  9. #include <Kernel/Boot/BootInfo.h>
  10. #include <Kernel/Boot/CommandLine.h>
  11. #include <Kernel/Boot/Multiboot.h>
  12. #include <Kernel/Bus/PCI/Access.h>
  13. #include <Kernel/Bus/PCI/Initializer.h>
  14. #include <Kernel/Bus/USB/Drivers/USBDriver.h>
  15. #include <Kernel/Bus/USB/USBManagement.h>
  16. #include <Kernel/Bus/VirtIO/Device.h>
  17. #include <Kernel/Bus/VirtIO/Transport/PCIe/Detect.h>
  18. #include <Kernel/Devices/Audio/Management.h>
  19. #include <Kernel/Devices/DeviceManagement.h>
  20. #include <Kernel/Devices/GPU/Console/BootFramebufferConsole.h>
  21. #include <Kernel/Devices/GPU/Management.h>
  22. #include <Kernel/Devices/Generic/DeviceControlDevice.h>
  23. #include <Kernel/Devices/Generic/FullDevice.h>
  24. #include <Kernel/Devices/Generic/MemoryDevice.h>
  25. #include <Kernel/Devices/Generic/NullDevice.h>
  26. #include <Kernel/Devices/Generic/PCSpeakerDevice.h>
  27. #include <Kernel/Devices/Generic/RandomDevice.h>
  28. #include <Kernel/Devices/Generic/SelfTTYDevice.h>
  29. #include <Kernel/Devices/Generic/ZeroDevice.h>
  30. #include <Kernel/Devices/HID/Management.h>
  31. #include <Kernel/Devices/KCOVDevice.h>
  32. #include <Kernel/Devices/PCISerialDevice.h>
  33. #include <Kernel/Devices/SerialDevice.h>
  34. #include <Kernel/Devices/Storage/StorageManagement.h>
  35. #include <Kernel/Devices/TTY/ConsoleManagement.h>
  36. #include <Kernel/Devices/TTY/PTYMultiplexer.h>
  37. #include <Kernel/Devices/TTY/VirtualConsole.h>
  38. #include <Kernel/FileSystem/SysFS/Registry.h>
  39. #include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
  40. #include <Kernel/FileSystem/VirtualFileSystem.h>
  41. #include <Kernel/Firmware/ACPI/Initialize.h>
  42. #include <Kernel/Firmware/ACPI/Parser.h>
  43. #include <Kernel/Heap/kmalloc.h>
  44. #include <Kernel/KSyms.h>
  45. #include <Kernel/Library/Panic.h>
  46. #include <Kernel/Memory/MemoryManager.h>
  47. #include <Kernel/Net/NetworkTask.h>
  48. #include <Kernel/Net/NetworkingManagement.h>
  49. #include <Kernel/Prekernel/Prekernel.h>
  50. #include <Kernel/Sections.h>
  51. #include <Kernel/Security/Random.h>
  52. #include <Kernel/Tasks/FinalizerTask.h>
  53. #include <Kernel/Tasks/Process.h>
  54. #include <Kernel/Tasks/Scheduler.h>
  55. #include <Kernel/Tasks/SyncTask.h>
  56. #include <Kernel/Tasks/WorkQueue.h>
  57. #include <Kernel/Time/TimeManagement.h>
  58. #include <Kernel/kstdio.h>
  59. #if ARCH(X86_64)
  60. # include <Kernel/Arch/x86_64/Hypervisor/VMWareBackdoor.h>
  61. # include <Kernel/Arch/x86_64/Interrupts/APIC.h>
  62. # include <Kernel/Arch/x86_64/Interrupts/PIC.h>
  63. # include <Kernel/Devices/GPU/Console/VGATextModeConsole.h>
  64. #elif ARCH(AARCH64)
  65. # include <Kernel/Arch/aarch64/RPi/Framebuffer.h>
  66. # include <Kernel/Arch/aarch64/RPi/Mailbox.h>
  67. # include <Kernel/Arch/aarch64/RPi/MiniUART.h>
  68. #endif
  69. // Defined in the linker script
  70. typedef void (*ctor_func_t)();
  71. extern ctor_func_t start_heap_ctors[];
  72. extern ctor_func_t end_heap_ctors[];
  73. extern ctor_func_t start_ctors[];
  74. extern ctor_func_t end_ctors[];
  75. extern uintptr_t __stack_chk_guard;
  76. READONLY_AFTER_INIT uintptr_t __stack_chk_guard __attribute__((used));
  77. #if ARCH(X86_64)
  78. extern "C" u8 start_of_safemem_text[];
  79. extern "C" u8 end_of_safemem_text[];
  80. extern "C" u8 start_of_safemem_atomic_text[];
  81. extern "C" u8 end_of_safemem_atomic_text[];
  82. #endif
  83. extern "C" USB::DriverInitFunction driver_init_table_start[];
  84. extern "C" USB::DriverInitFunction driver_init_table_end[];
  85. extern "C" u8 end_of_kernel_image[];
  86. multiboot_module_entry_t multiboot_copy_boot_modules_array[16];
  87. size_t multiboot_copy_boot_modules_count;
  88. READONLY_AFTER_INIT bool g_in_early_boot;
  89. namespace Kernel {
  90. [[noreturn]] static void init_stage2(void*);
  91. static void setup_serial_debug();
  92. // boot.S expects these functions to exactly have the following signatures.
  93. // We declare them here to ensure their signatures don't accidentally change.
  94. extern "C" void init_finished(u32 cpu) __attribute__((used));
  95. extern "C" [[noreturn]] void init_ap(FlatPtr cpu, Processor* processor_info);
  96. extern "C" [[noreturn]] void init(BootInfo const&);
  97. READONLY_AFTER_INIT VirtualConsole* tty0;
  98. ProcessID g_init_pid { 0 };
  99. ALWAYS_INLINE static Processor& bsp_processor()
  100. {
  101. // This solves a problem where the bsp Processor instance
  102. // gets "re"-initialized in init() when we run all global constructors.
  103. alignas(Processor) static u8 bsp_processor_storage[sizeof(Processor)];
  104. return (Processor&)bsp_processor_storage;
  105. }
  106. // SerenityOS Kernel C++ entry point :^)
  107. //
  108. // This is where C++ execution begins, after boot.S transfers control here.
  109. //
  110. // The purpose of init() is to start multi-tasking. It does the bare minimum
  111. // amount of work needed to start the scheduler.
  112. //
  113. // Once multi-tasking is ready, we spawn a new thread that starts in the
  114. // init_stage2() function. Initialization continues there.
  115. extern "C" {
  116. READONLY_AFTER_INIT PhysicalAddress start_of_prekernel_image;
  117. READONLY_AFTER_INIT PhysicalAddress end_of_prekernel_image;
  118. READONLY_AFTER_INIT size_t physical_to_virtual_offset;
  119. READONLY_AFTER_INIT FlatPtr kernel_mapping_base;
  120. READONLY_AFTER_INIT FlatPtr kernel_load_base;
  121. READONLY_AFTER_INIT PhysicalAddress boot_pml4t;
  122. READONLY_AFTER_INIT PhysicalAddress boot_pdpt;
  123. READONLY_AFTER_INIT PhysicalAddress boot_pd0;
  124. READONLY_AFTER_INIT PhysicalAddress boot_pd_kernel;
  125. READONLY_AFTER_INIT Memory::PageTableEntry* boot_pd_kernel_pt1023;
  126. READONLY_AFTER_INIT StringView kernel_cmdline;
  127. READONLY_AFTER_INIT u32 multiboot_flags;
  128. READONLY_AFTER_INIT multiboot_memory_map_t* multiboot_memory_map;
  129. READONLY_AFTER_INIT size_t multiboot_memory_map_count;
  130. READONLY_AFTER_INIT multiboot_module_entry_t* multiboot_modules;
  131. READONLY_AFTER_INIT size_t multiboot_modules_count;
  132. READONLY_AFTER_INIT PhysicalAddress multiboot_framebuffer_addr;
  133. READONLY_AFTER_INIT u32 multiboot_framebuffer_pitch;
  134. READONLY_AFTER_INIT u32 multiboot_framebuffer_width;
  135. READONLY_AFTER_INIT u32 multiboot_framebuffer_height;
  136. READONLY_AFTER_INIT u8 multiboot_framebuffer_bpp;
  137. READONLY_AFTER_INIT u8 multiboot_framebuffer_type;
  138. }
  139. Atomic<Graphics::Console*> g_boot_console;
  140. #if ARCH(AARCH64)
  141. READONLY_AFTER_INIT static u8 s_command_line_buffer[512];
  142. #endif
  143. extern "C" [[noreturn]] UNMAP_AFTER_INIT void init([[maybe_unused]] BootInfo const& boot_info)
  144. {
  145. g_in_early_boot = true;
  146. #if ARCH(X86_64)
  147. start_of_prekernel_image = PhysicalAddress { boot_info.start_of_prekernel_image };
  148. end_of_prekernel_image = PhysicalAddress { boot_info.end_of_prekernel_image };
  149. physical_to_virtual_offset = boot_info.physical_to_virtual_offset;
  150. kernel_mapping_base = boot_info.kernel_mapping_base;
  151. kernel_load_base = boot_info.kernel_load_base;
  152. gdt64ptr = boot_info.gdt64ptr;
  153. code64_sel = boot_info.code64_sel;
  154. boot_pml4t = PhysicalAddress { boot_info.boot_pml4t };
  155. boot_pdpt = PhysicalAddress { boot_info.boot_pdpt };
  156. boot_pd0 = PhysicalAddress { boot_info.boot_pd0 };
  157. boot_pd_kernel = PhysicalAddress { boot_info.boot_pd_kernel };
  158. boot_pd_kernel_pt1023 = (Memory::PageTableEntry*)boot_info.boot_pd_kernel_pt1023;
  159. char const* cmdline = (char const*)boot_info.kernel_cmdline;
  160. kernel_cmdline = StringView { cmdline, strlen(cmdline) };
  161. multiboot_flags = boot_info.multiboot_flags;
  162. multiboot_memory_map = (multiboot_memory_map_t*)boot_info.multiboot_memory_map;
  163. multiboot_memory_map_count = boot_info.multiboot_memory_map_count;
  164. multiboot_modules = (multiboot_module_entry_t*)boot_info.multiboot_modules;
  165. multiboot_modules_count = boot_info.multiboot_modules_count;
  166. multiboot_framebuffer_addr = PhysicalAddress { boot_info.multiboot_framebuffer_addr };
  167. multiboot_framebuffer_pitch = boot_info.multiboot_framebuffer_pitch;
  168. multiboot_framebuffer_width = boot_info.multiboot_framebuffer_width;
  169. multiboot_framebuffer_height = boot_info.multiboot_framebuffer_height;
  170. multiboot_framebuffer_bpp = boot_info.multiboot_framebuffer_bpp;
  171. multiboot_framebuffer_type = boot_info.multiboot_framebuffer_type;
  172. #elif ARCH(AARCH64)
  173. // FIXME: For the aarch64 platforms, we should get the information by parsing a device tree instead of using multiboot.
  174. auto [ram_base, ram_size] = RPi::Mailbox::the().query_lower_arm_memory_range();
  175. auto [vcmem_base, vcmem_size] = RPi::Mailbox::the().query_videocore_memory_range();
  176. multiboot_memory_map_t mmap[] = {
  177. {
  178. sizeof(struct multiboot_mmap_entry) - sizeof(u32),
  179. (u64)ram_base,
  180. (u64)ram_size,
  181. MULTIBOOT_MEMORY_AVAILABLE,
  182. },
  183. {
  184. sizeof(struct multiboot_mmap_entry) - sizeof(u32),
  185. (u64)vcmem_base,
  186. (u64)vcmem_size,
  187. MULTIBOOT_MEMORY_RESERVED,
  188. },
  189. // FIXME: VideoCore only reports the first 1GB of RAM, the rest only shows up in the device tree.
  190. };
  191. multiboot_memory_map = mmap;
  192. multiboot_memory_map_count = 2;
  193. multiboot_modules = nullptr;
  194. multiboot_modules_count = 0;
  195. // FIXME: Read the /chosen/bootargs property.
  196. kernel_cmdline = RPi::Mailbox::the().query_kernel_command_line(s_command_line_buffer);
  197. #elif ARCH(RISCV64)
  198. // FIXME: Get the actual memory map from the device tree.
  199. static multiboot_memory_map_t mmap[] = {
  200. {
  201. // We currently can't get the actual size of firmware-reserved memory, so mark the first 0x20'0000 bytes as reserved.
  202. // This reserved memory region should be large enough for now.
  203. sizeof(multiboot_mmap_entry) - sizeof(u32),
  204. 0x8000'0000,
  205. 0x20'0000,
  206. MULTIBOOT_MEMORY_RESERVED,
  207. },
  208. {
  209. sizeof(multiboot_mmap_entry) - sizeof(u32),
  210. 0x8020'0000,
  211. 1 * GiB - 0x20'0000,
  212. MULTIBOOT_MEMORY_AVAILABLE,
  213. },
  214. };
  215. multiboot_memory_map = mmap;
  216. multiboot_memory_map_count = array_size(mmap);
  217. multiboot_modules = nullptr;
  218. multiboot_modules_count = 0;
  219. kernel_cmdline = "serial_debug"sv;
  220. #endif
  221. setup_serial_debug();
  222. // We need to copy the command line before kmalloc is initialized,
  223. // as it may overwrite parts of multiboot!
  224. CommandLine::early_initialize(kernel_cmdline);
  225. if (multiboot_modules_count > 0) {
  226. VERIFY(multiboot_modules);
  227. memcpy(multiboot_copy_boot_modules_array, multiboot_modules, multiboot_modules_count * sizeof(multiboot_module_entry_t));
  228. }
  229. multiboot_copy_boot_modules_count = multiboot_modules_count;
  230. new (&bsp_processor()) Processor();
  231. bsp_processor().early_initialize(0);
  232. // Invoke the constructors needed for the kernel heap
  233. for (ctor_func_t* ctor = start_heap_ctors; ctor < end_heap_ctors; ctor++)
  234. (*ctor)();
  235. kmalloc_init();
  236. load_kernel_symbol_table();
  237. bsp_processor().initialize(0);
  238. CommandLine::initialize();
  239. Memory::MemoryManager::initialize(0);
  240. #if ARCH(AARCH64)
  241. auto firmware_version = RPi::Mailbox::the().query_firmware_version();
  242. dmesgln("RPi: Firmware version: {}", firmware_version);
  243. RPi::Framebuffer::initialize();
  244. #endif
  245. // NOTE: If the bootloader provided a framebuffer, then set up an initial console.
  246. // If the bootloader didn't provide a framebuffer, then set up an initial text console.
  247. // We do so we can see the output on the screen as soon as possible.
  248. if (!kernel_command_line().is_early_boot_console_disabled()) {
  249. if ((multiboot_flags & MULTIBOOT_INFO_FRAMEBUFFER_INFO) && !multiboot_framebuffer_addr.is_null() && multiboot_framebuffer_type == MULTIBOOT_FRAMEBUFFER_TYPE_RGB) {
  250. g_boot_console = &try_make_lock_ref_counted<Graphics::BootFramebufferConsole>(multiboot_framebuffer_addr, multiboot_framebuffer_width, multiboot_framebuffer_height, multiboot_framebuffer_pitch).value().leak_ref();
  251. } else {
  252. #if ARCH(X86_64)
  253. g_boot_console = &Graphics::VGATextModeConsole::initialize().leak_ref();
  254. #else
  255. dbgln("No early framebuffer console available");
  256. #endif
  257. }
  258. }
  259. dmesgln("Starting SerenityOS...");
  260. #if ARCH(X86_64)
  261. MM.unmap_prekernel();
  262. // Ensure that the safemem sections are not empty. This could happen if the linker accidentally discards the sections.
  263. VERIFY(+start_of_safemem_text != +end_of_safemem_text);
  264. VERIFY(+start_of_safemem_atomic_text != +end_of_safemem_atomic_text);
  265. #endif
  266. // Invoke all static global constructors in the kernel.
  267. // Note that we want to do this as early as possible.
  268. for (ctor_func_t* ctor = start_ctors; ctor < end_ctors; ctor++)
  269. (*ctor)();
  270. InterruptManagement::initialize();
  271. ACPI::initialize();
  272. // Initialize TimeManagement before using randomness!
  273. TimeManagement::initialize(0);
  274. DeviceManagement::initialize();
  275. SysFSComponentRegistry::initialize();
  276. DeviceManagement::the().attach_null_device(*NullDevice::must_initialize());
  277. DeviceManagement::the().attach_console_device(*ConsoleDevice::must_create());
  278. DeviceManagement::the().attach_device_control_device(*DeviceControlDevice::must_create());
  279. __stack_chk_guard = get_fast_random<uintptr_t>();
  280. Process::initialize();
  281. Scheduler::initialize();
  282. #if ARCH(X86_64)
  283. // FIXME: Add an abstraction for the smp related functions, instead of using ifdefs in this file.
  284. if (APIC::initialized() && APIC::the().enabled_processor_count() > 1) {
  285. // We must set up the AP boot environment before switching to a kernel process,
  286. // as pages below address USER_RANGE_BASE are only accessible through the kernel
  287. // page directory.
  288. APIC::the().setup_ap_boot_environment();
  289. }
  290. #endif
  291. MUST(Process::create_kernel_process("init_stage2"sv, init_stage2, nullptr, THREAD_AFFINITY_DEFAULT, Process::RegisterProcess::No));
  292. Scheduler::start();
  293. VERIFY_NOT_REACHED();
  294. }
  295. #if ARCH(X86_64)
  296. //
  297. // This is where C++ execution begins for APs, after boot.S transfers control here.
  298. //
  299. // The purpose of init_ap() is to initialize APs for multi-tasking.
  300. //
  301. extern "C" [[noreturn]] UNMAP_AFTER_INIT void init_ap(FlatPtr cpu, Processor* processor_info)
  302. {
  303. processor_info->early_initialize(cpu);
  304. processor_info->initialize(cpu);
  305. Memory::MemoryManager::initialize(cpu);
  306. Scheduler::set_idle_thread(APIC::the().get_idle_thread(cpu));
  307. Scheduler::start();
  308. VERIFY_NOT_REACHED();
  309. }
  310. //
  311. // This method is called once a CPU enters the scheduler and its idle thread
  312. // At this point the initial boot stack can be freed
  313. //
  314. extern "C" UNMAP_AFTER_INIT void init_finished(u32 cpu)
  315. {
  316. if (cpu == 0) {
  317. // TODO: we can reuse the boot stack, maybe for kmalloc()?
  318. } else {
  319. APIC::the().init_finished(cpu);
  320. TimeManagement::initialize(cpu);
  321. }
  322. }
  323. #endif
  324. void init_stage2(void*)
  325. {
  326. // This is a little bit of a hack. We can't register our process at the time we're
  327. // creating it, but we need to be registered otherwise finalization won't be happy.
  328. // The colonel process gets away without having to do this because it never exits.
  329. Process::register_new(Process::current());
  330. WorkQueue::initialize();
  331. #if ARCH(X86_64)
  332. if (kernel_command_line().is_smp_enabled() && APIC::initialized() && APIC::the().enabled_processor_count() > 1) {
  333. // We can't start the APs until we have a scheduler up and running.
  334. // We need to be able to process ICI messages, otherwise another
  335. // core may send too many and end up deadlocking once the pool is
  336. // exhausted
  337. APIC::the().boot_aps();
  338. }
  339. #endif
  340. // Initialize the PCI Bus as early as possible, for early boot (PCI based) serial logging
  341. PCI::initialize();
  342. if (!PCI::Access::is_disabled()) {
  343. PCISerialDevice::detect();
  344. }
  345. VirtualFileSystem::initialize();
  346. #if ARCH(X86_64)
  347. if (!is_serial_debug_enabled())
  348. (void)SerialDevice::must_create(0).leak_ref();
  349. (void)SerialDevice::must_create(1).leak_ref();
  350. (void)SerialDevice::must_create(2).leak_ref();
  351. (void)SerialDevice::must_create(3).leak_ref();
  352. #elif ARCH(AARCH64)
  353. (void)MUST(RPi::MiniUART::create()).leak_ref();
  354. #endif
  355. (void)PCSpeakerDevice::must_create().leak_ref();
  356. #if ARCH(X86_64)
  357. VMWareBackdoor::the(); // don't wait until first mouse packet
  358. #endif
  359. MUST(HIDManagement::initialize());
  360. GraphicsManagement::the().initialize();
  361. ConsoleManagement::the().initialize();
  362. SyncTask::spawn();
  363. FinalizerTask::spawn();
  364. auto boot_profiling = kernel_command_line().is_boot_profiling_enabled();
  365. if (!PCI::Access::is_disabled()) {
  366. USB::USBManagement::initialize();
  367. }
  368. SysFSFirmwareDirectory::initialize();
  369. if (!PCI::Access::is_disabled()) {
  370. VirtIO::detect_pci_instances();
  371. }
  372. NetworkingManagement::the().initialize();
  373. #ifdef ENABLE_KERNEL_COVERAGE_COLLECTION
  374. (void)KCOVDevice::must_create().leak_ref();
  375. #endif
  376. (void)MemoryDevice::must_create().leak_ref();
  377. (void)ZeroDevice::must_create().leak_ref();
  378. (void)FullDevice::must_create().leak_ref();
  379. (void)RandomDevice::must_create().leak_ref();
  380. (void)SelfTTYDevice::must_create().leak_ref();
  381. PTYMultiplexer::initialize();
  382. AudioManagement::the().initialize();
  383. // Initialize all USB Drivers
  384. for (auto* init_function = driver_init_table_start; init_function != driver_init_table_end; init_function++)
  385. (*init_function)();
  386. StorageManagement::the().initialize(kernel_command_line().is_force_pio(), kernel_command_line().is_nvme_polling_enabled());
  387. for (int i = 0; i < 5; ++i) {
  388. if (StorageManagement::the().determine_boot_device(kernel_command_line().root_device()))
  389. break;
  390. dbgln_if(STORAGE_DEVICE_DEBUG, "Boot device {} not found, sleeping 2 seconds", kernel_command_line().root_device());
  391. (void)Thread::current()->sleep(Duration::from_seconds(2));
  392. }
  393. if (VirtualFileSystem::the().mount_root(StorageManagement::the().root_filesystem()).is_error()) {
  394. PANIC("VirtualFileSystem::mount_root failed");
  395. }
  396. // Switch out of early boot mode.
  397. g_in_early_boot = false;
  398. // NOTE: Everything marked READONLY_AFTER_INIT becomes non-writable after this point.
  399. MM.protect_readonly_after_init_memory();
  400. // NOTE: Everything in the .ksyms section becomes read-only after this point.
  401. MM.protect_ksyms_after_init();
  402. // NOTE: Everything marked UNMAP_AFTER_INIT becomes inaccessible after this point.
  403. MM.unmap_text_after_init();
  404. auto userspace_init = kernel_command_line().userspace_init();
  405. auto init_args = kernel_command_line().userspace_init_args();
  406. dmesgln("Running first user process: {}", userspace_init);
  407. dmesgln("Init (first) process args: {}", init_args);
  408. auto init_or_error = Process::create_user_process(userspace_init, UserID(0), GroupID(0), move(init_args), {}, tty0);
  409. if (init_or_error.is_error())
  410. PANIC("init_stage2: Error spawning init process: {}", init_or_error.error());
  411. auto [init_process, init_thread] = init_or_error.release_value();
  412. g_init_pid = init_process->pid();
  413. init_thread->set_priority(THREAD_PRIORITY_HIGH);
  414. NetworkTask::spawn();
  415. // NOTE: All kernel processes must be created before enabling boot profiling.
  416. // This is so profiling_enable() can emit process created performance events for them.
  417. if (boot_profiling) {
  418. dbgln("Starting full system boot profiling");
  419. MutexLocker mutex_locker(Process::current().big_lock());
  420. auto const enable_all = ~(u64)0;
  421. auto result = Process::current().profiling_enable(-1, enable_all);
  422. VERIFY(!result.is_error());
  423. }
  424. Process::current().sys$exit(0);
  425. VERIFY_NOT_REACHED();
  426. }
  427. UNMAP_AFTER_INIT void setup_serial_debug()
  428. {
  429. // serial_debug will output all the dbgln() data to COM1 at
  430. // 8-N-1 57600 baud. this is particularly useful for debugging the boot
  431. // process on live hardware.
  432. if (kernel_cmdline.contains("serial_debug"sv)) {
  433. set_serial_debug_enabled(true);
  434. }
  435. }
  436. // Define some Itanium C++ ABI methods to stop the linker from complaining.
  437. // If we actually call these something has gone horribly wrong
  438. void* __dso_handle __attribute__((visibility("hidden")));
  439. }