cstuff.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. #ifdef EFI_PLATFORM
  2. # include <efi.h>
  3. # include <efilib.h>
  4. EFI_HANDLE ImageHandleIn;
  5. #else
  6. # include "types.h"
  7. #endif
  8. #include "ata.h"
  9. #include "text.h"
  10. #include "util.h"
  11. #ifndef EFI_PLATFORM
  12. #include "atapi_imp.h"
  13. #include "iso9660.h"
  14. #endif
  15. #include "elf.h"
  16. #include "multiboot.h"
  17. #include "kbd.h"
  18. #include "options.h"
  19. /* Basic text strings */
  20. #define BASE_VERSION "ToaruOS-NIH Bootloader v2.1"
  21. #ifdef EFI_PLATFORM
  22. # if defined(__x86_64__)
  23. # define VERSION_TEXT BASE_VERSION " (EFI, X64)"
  24. # else
  25. # define VERSION_TEXT BASE_VERSION " (EFI, IA32)"
  26. # endif
  27. #else
  28. # define VERSION_TEXT BASE_VERSION " (BIOS)"
  29. #endif
  30. #define HELP_TEXT "Press <Enter> or select a menu option with \030/\031/\032/\033."
  31. #define COPYRIGHT_TEXT "ToaruOS is free software under the NCSA license."
  32. #define LINK_TEXT "https://toaruos.org - https://gitlab.com/toaruos"
  33. /* Boot command line strings */
  34. #define DEFAULT_ROOT_CMDLINE "root=/dev/ram0,nocache "
  35. #define DEFAULT_GRAPHICAL_CMDLINE "start=live-session "
  36. #define DEFAULT_SINGLE_CMDLINE "start=terminal\037-F "
  37. #define DEFAULT_TEXT_CMDLINE "start=--vga "
  38. #define DEFAULT_VID_CMDLINE "vid=auto,1440,900 "
  39. #define DEFAULT_PRESET_VID_CMDLINE "vid=preset "
  40. #define DEFAULT_NETINIT_CMDLINE "init=/dev/ram0 "
  41. #define MIGRATE_CMDLINE "migrate "
  42. #define DEBUG_LOG_CMDLINE "logtoserial=warning "
  43. #define DEBUG_SERIAL_CMDLINE "kdebug "
  44. #define DEFAULT_HEADLESS_CMDLINE "start=--headless "
  45. char * module_dir = "MOD";
  46. char * kernel_path = "KERNEL.";
  47. char * ramdisk_path = "RAMDISK.IMG";
  48. #ifdef EFI_PLATFORM
  49. int _efi_do_mode_set = 0;
  50. #endif
  51. /* Where to dump kernel data while loading */
  52. #define KERNEL_LOAD_START 0x300000
  53. /* Module file names - need to be ordered. */
  54. static char * modules[] = {
  55. "ZERO.KO", // 0
  56. "RANDOM.KO", // 1
  57. "SERIAL.KO", // 2
  58. "DEBUG_SH.KO", // 3
  59. "PROCFS.KO", // 4
  60. "TMPFS.KO", // 5
  61. "ATA.KO", // 6
  62. "EXT2.KO", // 7
  63. "ISO9660.KO", // 8
  64. "PS2KBD.KO", // 9
  65. "PS2MOUSE.KO", // 10
  66. "LFBVIDEO.KO", // 11
  67. "VBOX.KO", // 12
  68. "VMWARE.KO", // 13
  69. "VIDSET.KO", // 14
  70. "PACKETFS.KO", // 15
  71. "SND.KO", // 16
  72. "AC97.KO", // 17
  73. "NET.KO", // 18
  74. "PCNET.KO", // 19
  75. "RTL.KO", // 20
  76. "E1000.KO", // 21
  77. "PCSPKR.KO", // 22
  78. "PORTIO.KO", // 23
  79. 0
  80. };
  81. /* Names of the available boot modes. */
  82. static struct bootmode boot_mode_names[] = {
  83. {1, "normal", "Normal Boot"},
  84. #ifndef EFI_PLATFORM
  85. {2, "vga", "VGA Text Mode"},
  86. #endif
  87. {3, "single", "Single-User Graphical Terminal"},
  88. {4, "headless", "Headless"},
  89. };
  90. /* More bootloader implementation that depends on the module config */
  91. #include "moremultiboot.h"
  92. #ifdef EFI_PLATFORM
  93. EFI_STATUS
  94. EFIAPI
  95. efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
  96. {
  97. InitializeLib(ImageHandle, SystemTable);
  98. ST = SystemTable;
  99. ImageHandleIn = ImageHandle;
  100. #else
  101. int kmain() {
  102. #endif
  103. BOOT_OPTION(_debug, 0, "Debug output",
  104. "Enable debug output in the bootloader and enable the",
  105. "serial debug log in the operating system itself.");
  106. BOOT_OPTION(_legacy_ata, 0, "Legacy ATA driver",
  107. "Enable the legacy ATA driver, which does not support",
  108. "ATAPI or use DMA. May be necessary in some virtual machines.");
  109. BOOT_OPTION(_normal_ata, 1, "DMA ATA driver",
  110. "Enable the normal, DMA-capable ATA driver. This is the default.",
  111. NULL);
  112. BOOT_OPTION(_debug_shell, 1, "Debug shell",
  113. "Enable the kernel debug shell. This can be accessed using",
  114. "the `kdebug` application.");
  115. BOOT_OPTION(_video, 1, "Video modules",
  116. "Enable the video modules. These are needed to modeset",
  117. "and provide a framebuffer for the UI.");
  118. BOOT_OPTION(_vbox, 1, "VirtualBox Guest Additions",
  119. "Enable integration with VirtualBox, including",
  120. "automatic mode setting and absolute mouse pointer.");
  121. BOOT_OPTION(_vmware, 1, "VMWare mouse driver",
  122. "Enable the VMware / QEMU absolute mouse pointer.",
  123. NULL);
  124. BOOT_OPTION(_sound, 1, "Audio drivers",
  125. "Enable the audio subsystem and AC'97 drivers.",
  126. NULL);
  127. BOOT_OPTION(_net, 1, "Network drivers",
  128. "Enable the IPv4 network subsystem and various",
  129. "network interface drivers.");
  130. BOOT_OPTION(_migrate, 1, "Writable root",
  131. "Migrates the ramdisk from ext2 to an in-memory",
  132. "temporary filesystem at boot.");
  133. BOOT_OPTION(_serialshell, 0, "Debug on serial",
  134. "Start a kernel debug shell on the first",
  135. "serial port.");
  136. BOOT_OPTION(_netinit, 0, "Netinit",
  137. "Downloads a userspace filesystem from a remote",
  138. "server and extracts it at boot.");
  139. BOOT_OPTION(_vboxrects, 0, "VirtualBox Seamless support",
  140. "(Requires Guest Additions) Enables support for the",
  141. "Seamless Desktop mode in VirtualBox.");
  142. BOOT_OPTION(_vboxpointer, 1, "VirtualBox Pointer",
  143. "(Requires Guest Additions) Enables support for the",
  144. "VirtualBox hardware pointer mapping.");
  145. #ifdef EFI_PLATFORM
  146. BOOT_OPTION(_efilargest, 0, "Prefer largest mode.",
  147. "When using EFI mode setting, use the largest mode.",
  148. NULL);
  149. BOOT_OPTION(_efi1024, 0, "Prefer 1024x768",
  150. "If a 1024x768x32 mode is found, set that.",
  151. NULL);
  152. BOOT_OPTION(_efi1080p, 0, "Prefer 1080p",
  153. "If a 1920x1080 mode is found, set that.",
  154. NULL);
  155. BOOT_OPTION(_efiask, 0, "Ask for input on each mode.",
  156. "Displays a y/n prompt for each possible mode.",
  157. NULL);
  158. #endif
  159. /* Loop over rendering the menu */
  160. show_menu();
  161. /* Build our command line. */
  162. if (_netinit) {
  163. strcat(cmdline, DEFAULT_NETINIT_CMDLINE);
  164. ramdisk_path = "NETINIT.";
  165. } else {
  166. strcat(cmdline, DEFAULT_ROOT_CMDLINE);
  167. if (_migrate) {
  168. strcat(cmdline, MIGRATE_CMDLINE);
  169. }
  170. }
  171. char * _video_command_line = DEFAULT_VID_CMDLINE;
  172. #ifdef EFI_PLATFORM
  173. _efi_do_mode_set = (_efilargest ? 1 : (_efi1024 ? 2 : (_efi1080p ? 3 : (_efiask ? 4 : 0))));
  174. if (_efi_do_mode_set) {
  175. _video_command_line = DEFAULT_PRESET_VID_CMDLINE;
  176. }
  177. #endif
  178. if (boot_mode == 1) {
  179. strcat(cmdline, DEFAULT_GRAPHICAL_CMDLINE);
  180. strcat(cmdline, _video_command_line);
  181. } else if (boot_mode == 2) {
  182. strcat(cmdline, DEFAULT_TEXT_CMDLINE);
  183. } else if (boot_mode == 3) {
  184. strcat(cmdline, DEFAULT_SINGLE_CMDLINE);
  185. strcat(cmdline, _video_command_line);
  186. } else if (boot_mode == 4) {
  187. strcat(cmdline, DEFAULT_HEADLESS_CMDLINE);
  188. }
  189. if (_debug) {
  190. strcat(cmdline, DEBUG_LOG_CMDLINE);
  191. txt_debug = 1;
  192. }
  193. if (_serialshell) {
  194. strcat(cmdline, DEBUG_SERIAL_CMDLINE);
  195. }
  196. if (_vbox && !_vboxrects) {
  197. strcat(cmdline, "novboxseamless ");
  198. }
  199. if (_vbox && !_vboxpointer) {
  200. strcat(cmdline, "novboxpointer ");
  201. }
  202. /* Configure modules */
  203. if (!_normal_ata) {
  204. modules[6] = "NONE";
  205. }
  206. if (_legacy_ata) {
  207. modules[6] = "ATAOLD.KO";
  208. }
  209. if (!_debug_shell) {
  210. modules[3] = "NONE";
  211. modules[14] = "NONE";
  212. }
  213. if (!_video) {
  214. modules[11] = "NONE";
  215. modules[12] = "NONE";
  216. modules[13] = "NONE";
  217. modules[14] = "NONE";
  218. }
  219. if (!_vmware) {
  220. modules[13] = "NONE";
  221. }
  222. if (!_vbox) {
  223. modules[12] = "NONE";
  224. }
  225. if (!_sound) {
  226. modules[16] = "NONE";
  227. modules[17] = "NONE";
  228. }
  229. if (!_net) {
  230. modules[18] = "NONE";
  231. modules[19] = "NONE";
  232. modules[20] = "NONE";
  233. modules[21] = "NONE";
  234. }
  235. boot();
  236. while (1) {}
  237. return 0;
  238. }