cstuff.c 7.7 KB

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