cstuff.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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(_vboxrects, 0, "VirtualBox Seamless support",
  122. "(Requires Guest Additions) Enables support for the",
  123. "Seamless Desktop mode in VirtualBox.");
  124. BOOT_OPTION(_vboxpointer, 1, "VirtualBox Pointer",
  125. "(Requires Guest Additions) Enables support for the",
  126. "VirtualBox hardware pointer mapping.");
  127. BOOT_OPTION(_vmware, 1, "VMWare driver",
  128. "Enable the VMware / QEMU absolute mouse pointer,",
  129. "and optional guest scaling.");
  130. BOOT_OPTION(_vmwareres, 1, "VMware guest size",
  131. "(Requires VMware driver) Enables support for",
  132. "automatically setting display size in VMware");
  133. BOOT_OPTION(_sound, 1, "Audio drivers",
  134. "Enable the audio subsystem and AC'97 drivers.",
  135. NULL);
  136. BOOT_OPTION(_net, 1, "Network drivers",
  137. "Enable the IPv4 network subsystem and various",
  138. "network interface drivers.");
  139. BOOT_OPTION(_migrate, 1, "Writable root",
  140. "Migrates the ramdisk from ext2 to an in-memory",
  141. "temporary filesystem at boot.");
  142. BOOT_OPTION(_serialshell, 0, "Debug on serial",
  143. "Start a kernel debug shell on the first",
  144. "serial port.");
  145. BOOT_OPTION(_netinit, 0, "Netinit",
  146. "Downloads a userspace filesystem from a remote",
  147. "server and extracts it at boot.");
  148. #ifdef EFI_PLATFORM
  149. BOOT_OPTION(_efilargest, 0, "Prefer largest mode.",
  150. "When using EFI mode setting, use the largest mode.",
  151. NULL);
  152. BOOT_OPTION(_efi1024, 0, "Prefer 1024x768",
  153. "If a 1024x768x32 mode is found, set that.",
  154. NULL);
  155. BOOT_OPTION(_efi1080p, 0, "Prefer 1080p",
  156. "If a 1920x1080 mode is found, set that.",
  157. NULL);
  158. BOOT_OPTION(_efiask, 0, "Ask for input on each mode.",
  159. "Displays a y/n prompt for each possible mode.",
  160. NULL);
  161. #endif
  162. /* Loop over rendering the menu */
  163. show_menu();
  164. /* Build our command line. */
  165. if (_netinit) {
  166. strcat(cmdline, DEFAULT_NETINIT_CMDLINE);
  167. ramdisk_path = "NETINIT.";
  168. } else {
  169. strcat(cmdline, DEFAULT_ROOT_CMDLINE);
  170. if (_migrate) {
  171. strcat(cmdline, MIGRATE_CMDLINE);
  172. }
  173. }
  174. char * _video_command_line = DEFAULT_VID_CMDLINE;
  175. #ifdef EFI_PLATFORM
  176. _efi_do_mode_set = (_efilargest ? 1 : (_efi1024 ? 2 : (_efi1080p ? 3 : (_efiask ? 4 : 0))));
  177. if (_efi_do_mode_set) {
  178. _video_command_line = DEFAULT_PRESET_VID_CMDLINE;
  179. }
  180. #endif
  181. if (boot_mode == 1) {
  182. strcat(cmdline, DEFAULT_GRAPHICAL_CMDLINE);
  183. strcat(cmdline, _video_command_line);
  184. } else if (boot_mode == 2) {
  185. strcat(cmdline, DEFAULT_TEXT_CMDLINE);
  186. } else if (boot_mode == 3) {
  187. strcat(cmdline, DEFAULT_SINGLE_CMDLINE);
  188. strcat(cmdline, _video_command_line);
  189. } else if (boot_mode == 4) {
  190. strcat(cmdline, DEFAULT_HEADLESS_CMDLINE);
  191. }
  192. if (_debug) {
  193. strcat(cmdline, DEBUG_LOG_CMDLINE);
  194. txt_debug = 1;
  195. }
  196. if (_serialshell) {
  197. strcat(cmdline, DEBUG_SERIAL_CMDLINE);
  198. }
  199. if (_vbox && !_vboxrects) {
  200. strcat(cmdline, "novboxseamless ");
  201. }
  202. if (_vbox && !_vboxpointer) {
  203. strcat(cmdline, "novboxpointer ");
  204. }
  205. if (_vmware && !_vmwareres) {
  206. strcat(cmdline, "novmwareresset ");
  207. }
  208. /* Configure modules */
  209. if (!_normal_ata) {
  210. modules[6] = "NONE";
  211. }
  212. if (_legacy_ata) {
  213. modules[6] = "ATAOLD.KO";
  214. }
  215. if (!_debug_shell) {
  216. modules[3] = "NONE";
  217. modules[14] = "NONE";
  218. }
  219. if (!_video) {
  220. modules[11] = "NONE";
  221. modules[12] = "NONE";
  222. modules[13] = "NONE";
  223. modules[14] = "NONE";
  224. }
  225. if (!_vmware) {
  226. modules[13] = "NONE";
  227. }
  228. if (!_vbox) {
  229. modules[12] = "NONE";
  230. }
  231. if (!_sound) {
  232. modules[16] = "NONE";
  233. modules[17] = "NONE";
  234. }
  235. if (!_net) {
  236. modules[18] = "NONE";
  237. modules[19] = "NONE";
  238. modules[20] = "NONE";
  239. modules[21] = "NONE";
  240. }
  241. boot();
  242. while (1) {}
  243. return 0;
  244. }