toaruos/boot/cstuff.c

306 lines
7.7 KiB
C
Raw Normal View History

2018-07-06 17:53:14 +03:00
#ifdef EFI_PLATFORM
# include <efi.h>
# include <efilib.h>
EFI_HANDLE ImageHandleIn;
#else
# include <stdint.h>
# include <stddef.h>
2018-07-06 17:53:14 +03:00
#endif
2018-03-06 13:43:01 +03:00
2021-04-08 12:07:08 +03:00
#define _BOOT_LOADER
2018-03-06 12:18:53 +03:00
#include "ata.h"
#include "text.h"
#include "util.h"
2018-07-11 04:23:56 +03:00
#ifndef EFI_PLATFORM
2018-03-06 12:18:53 +03:00
#include "atapi_imp.h"
#include "iso9660.h"
2018-07-11 04:23:56 +03:00
#endif
2018-03-06 12:18:53 +03:00
#include "elf.h"
#include "multiboot.h"
#include "kbd.h"
#include "options.h"
#include "inflate.h"
2018-03-06 12:18:53 +03:00
/* Basic text strings */
2018-10-06 15:28:43 +03:00
#define BASE_VERSION "ToaruOS Bootloader v2.1"
2018-07-07 04:56:14 +03:00
#ifdef EFI_PLATFORM
# if defined(__x86_64__)
2018-07-12 08:54:58 +03:00
# define VERSION_TEXT BASE_VERSION " (EFI, X64)"
# else
2018-07-12 08:54:58 +03:00
# define VERSION_TEXT BASE_VERSION " (EFI, IA32)"
# endif
2018-07-07 04:56:14 +03:00
#else
2018-07-12 08:54:58 +03:00
# define VERSION_TEXT BASE_VERSION " (BIOS)"
2018-07-07 04:56:14 +03:00
#endif
2018-06-30 07:29:11 +03:00
#define HELP_TEXT "Press <Enter> or select a menu option with \030/\031/\032/\033."
#define COPYRIGHT_TEXT "ToaruOS is free software under the NCSA license."
#define LINK_TEXT "https://toaruos.org - https://github.com/klange/toaruos"
/* Boot command line strings */
#define DEFAULT_ROOT_CMDLINE "root=/dev/ram0 root_type=tar "
2018-06-09 12:05:09 +03:00
#define DEFAULT_GRAPHICAL_CMDLINE "start=live-session "
#define DEFAULT_SINGLE_CMDLINE "start=terminal\037-F "
2018-06-09 10:36:48 +03:00
#define DEFAULT_TEXT_CMDLINE "start=--vga "
#define DEFAULT_VID_CMDLINE "vid=auto,1440,900 "
2018-07-12 04:53:36 +03:00
#define DEFAULT_PRESET_VID_CMDLINE "vid=preset "
2018-09-04 04:17:59 +03:00
#define DEFAULT_NETINIT_CMDLINE "init=/dev/ram0 "
#define NETINIT_REMOTE_URL "args=http://toaruos.org/ramdisk-1.9.3.img "
2018-08-12 10:36:56 +03:00
#define MIGRATE_CMDLINE "migrate "
#define DEBUG_LOG_CMDLINE "logtoserial=warning "
2018-06-30 07:29:11 +03:00
#define DEBUG_SERIAL_CMDLINE "kdebug "
2018-07-06 04:40:49 +03:00
#define DEFAULT_HEADLESS_CMDLINE "start=--headless "
2018-06-09 10:36:48 +03:00
char * module_dir = "MOD";
char * kernel_path = "KERNEL.";
2021-04-08 12:07:08 +03:00
char * ramdisk_path = "RAMDISK.IGZ";
2018-06-09 13:19:21 +03:00
2018-07-12 04:53:36 +03:00
#ifdef EFI_PLATFORM
int _efi_do_mode_set = 0;
#endif
/* Module file names - need to be ordered. */
2018-03-06 12:52:57 +03:00
static char * modules[] = {
2018-03-06 17:47:42 +03:00
"ZERO.KO", // 0
"RANDOM.KO", // 1
"SERIAL.KO", // 2
"DEBUG_SH.KO", // 3
"PROCFS.KO", // 4
"TMPFS.KO", // 5
"ATA.KO", // 6
"EXT2.KO", // 7
"ISO9660.KO", // 8
"PS2KBD.KO", // 9
"PS2MOUSE.KO", // 10
"LFBVIDEO.KO", // 11
2018-07-11 04:23:56 +03:00
"VBOX.KO", // 12
2018-03-06 17:47:42 +03:00
"VMWARE.KO", // 13
"VIDSET.KO", // 14
"PACKETFS.KO", // 15
"SND.KO", // 16
"AC97.KO", // 17
"NET.KO", // 18
"PCNET.KO", // 19
"RTL.KO", // 20
"E1000.KO", // 21
2018-05-04 07:11:06 +03:00
"PCSPKR.KO", // 22
2018-09-28 07:59:14 +03:00
"PORTIO.KO", // 23
"TARFS.KO", // 24
2018-03-06 12:18:53 +03:00
0
};
2018-03-06 12:52:57 +03:00
/* Names of the available boot modes. */
2018-07-07 04:56:14 +03:00
static struct bootmode boot_mode_names[] = {
{1, "normal", "Normal Boot"},
#ifndef EFI_PLATFORM
{2, "vga", "VGA Text Mode"},
#endif
{3, "single", "Single-User Graphical Terminal"},
{4, "headless", "Headless"},
2018-06-09 11:58:29 +03:00
};
/* More bootloader implementation that depends on the module config */
#include "moremultiboot.h"
2018-06-09 11:58:29 +03:00
2018-07-06 17:53:14 +03:00
#ifdef EFI_PLATFORM
EFI_STATUS
EFIAPI
efi_main (EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
{
InitializeLib(ImageHandle, SystemTable);
ST = SystemTable;
ImageHandleIn = ImageHandle;
#else
extern char _bss_start[];
extern char _bss_end[];
2018-03-05 17:12:24 +03:00
int kmain() {
memset(&_bss_start,0,(uintptr_t)&_bss_end-(uintptr_t)&_bss_start);
2018-07-06 17:53:14 +03:00
#endif
2018-03-06 17:47:42 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_debug, 0, "Debug output",
2018-07-06 17:53:14 +03:00
"Enable debug output in the bootloader and enable the",
"serial debug log in the operating system itself.");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_legacy_ata, 0, "Legacy ATA driver",
2018-07-06 17:53:14 +03:00
"Enable the legacy ATA driver, which does not support",
"ATAPI or use DMA. May be necessary in some virtual machines.");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_normal_ata, 1, "DMA ATA driver",
2018-07-06 17:53:14 +03:00
"Enable the normal, DMA-capable ATA driver. This is the default.",
NULL);
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_debug_shell, 1, "Debug shell",
2018-07-06 17:53:14 +03:00
"Enable the kernel debug shell. This can be accessed using",
"the `kdebug` application.");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_video, 1, "Video modules",
2018-07-06 17:53:14 +03:00
"Enable the video modules. These are needed to modeset",
"and provide a framebuffer for the UI.");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_vbox, 1, "VirtualBox Guest Additions",
2018-07-06 17:53:14 +03:00
"Enable integration with VirtualBox, including",
"automatic mode setting and absolute mouse pointer.");
2018-06-09 11:58:29 +03:00
2018-09-28 18:48:15 +03:00
BOOT_OPTION(_vboxrects, 0, "VirtualBox Seamless support",
"(Requires Guest Additions) Enables support for the",
"Seamless Desktop mode in VirtualBox.");
BOOT_OPTION(_vboxpointer, 1, "VirtualBox Pointer",
"(Requires Guest Additions) Enables support for the",
"VirtualBox hardware pointer mapping.");
BOOT_OPTION(_vmware, 1, "VMWare driver",
"Enable the VMware / QEMU absolute mouse pointer,",
"and optional guest scaling.");
BOOT_OPTION(_vmwareres, 0, "VMware guest size",
2018-09-28 18:48:15 +03:00
"(Requires VMware driver) Enables support for",
"automatically setting display size in VMware");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_sound, 1, "Audio drivers",
2018-07-06 17:53:14 +03:00
"Enable the audio subsystem and AC'97 drivers.",
NULL);
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_net, 1, "Network drivers",
2018-07-06 17:53:14 +03:00
"Enable the IPv4 network subsystem and various",
"network interface drivers.");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_migrate, 1, "Writable root",
"Migrates the ramdisk from tarball to an in-memory",
"temporary filesystem at boot. Needed for packages.");
2018-06-09 11:58:29 +03:00
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_serialshell, 0, "Debug on serial",
2018-07-06 17:53:14 +03:00
"Start a kernel debug shell on the first",
"serial port.");
2018-06-30 07:29:11 +03:00
BOOT_OPTION(_netinit, 0, "Netinit (QEMU local)",
"Downloads a userspace filesystem from a local",
"HTTP server and extracts it at boot.");
BOOT_OPTION(_netinitr, 0, "Netinit (toaruos.org)",
2018-07-06 17:53:14 +03:00
"Downloads a userspace filesystem from a remote",
"HTTP server and extracts it at boot.");
2018-07-12 04:53:36 +03:00
#ifdef EFI_PLATFORM
BOOT_OPTION(_efilargest, 0, "Prefer largest mode.",
"When using EFI mode setting, use the largest mode.",
NULL);
BOOT_OPTION(_efi1024, 0, "Prefer 1024x768",
"If a 1024x768x32 mode is found, set that.",
NULL);
BOOT_OPTION(_efi1080p, 0, "Prefer 1080p",
"If a 1920x1080 mode is found, set that.",
NULL);
BOOT_OPTION(_efiask, 0, "Ask for input on each mode.",
"Displays a y/n prompt for each possible mode.",
NULL);
#endif
/* Loop over rendering the menu */
show_menu();
2018-06-09 10:36:48 +03:00
/* Build our command line. */
if (_netinit || _netinitr) {
strcat(cmdline, DEFAULT_NETINIT_CMDLINE);
ramdisk_path = "NETINIT.";
if (_netinitr) {
strcat(cmdline, NETINIT_REMOTE_URL);
}
} else {
strcat(cmdline, DEFAULT_ROOT_CMDLINE);
2018-12-03 05:04:06 +03:00
}
2018-12-03 05:04:06 +03:00
if (_migrate) {
strcat(cmdline, MIGRATE_CMDLINE);
2018-06-09 10:36:48 +03:00
}
2018-07-12 04:53:36 +03:00
char * _video_command_line = DEFAULT_VID_CMDLINE;
#ifdef EFI_PLATFORM
_efi_do_mode_set = (_efilargest ? 1 : (_efi1024 ? 2 : (_efi1080p ? 3 : (_efiask ? 4 : 0))));
if (_efi_do_mode_set) {
_video_command_line = DEFAULT_PRESET_VID_CMDLINE;
}
#endif
2018-07-07 04:56:14 +03:00
if (boot_mode == 1) {
2018-06-09 10:36:48 +03:00
strcat(cmdline, DEFAULT_GRAPHICAL_CMDLINE);
2018-07-12 04:53:36 +03:00
strcat(cmdline, _video_command_line);
2018-06-09 11:33:23 +03:00
} else if (boot_mode == 2) {
2018-07-07 04:56:14 +03:00
strcat(cmdline, DEFAULT_TEXT_CMDLINE);
} else if (boot_mode == 3) {
2018-06-09 11:33:23 +03:00
strcat(cmdline, DEFAULT_SINGLE_CMDLINE);
2018-07-12 04:53:36 +03:00
strcat(cmdline, _video_command_line);
2018-07-07 04:56:14 +03:00
} else if (boot_mode == 4) {
2018-07-06 04:40:49 +03:00
strcat(cmdline, DEFAULT_HEADLESS_CMDLINE);
2018-03-06 17:47:42 +03:00
}
2018-06-09 10:36:48 +03:00
if (_debug) {
strcat(cmdline, DEBUG_LOG_CMDLINE);
2018-07-06 17:53:14 +03:00
txt_debug = 1;
2018-06-09 10:36:48 +03:00
}
2018-06-30 07:29:11 +03:00
if (_serialshell) {
strcat(cmdline, DEBUG_SERIAL_CMDLINE);
}
if (_vbox && !_vboxrects) {
strcat(cmdline, "novboxseamless ");
}
if (_vbox && !_vboxpointer) {
strcat(cmdline, "novboxpointer ");
}
2018-09-28 18:48:15 +03:00
if (_vmware && !_vmwareres) {
strcat(cmdline, "novmwareresset ");
}
/* Configure modules */
2018-03-06 17:47:42 +03:00
if (!_normal_ata) {
modules[6] = "NONE";
}
if (_legacy_ata) {
modules[6] = "ATAOLD.KO";
}
if (!_debug_shell) {
modules[3] = "NONE";
modules[14] = "NONE";
}
if (!_video) {
modules[11] = "NONE";
modules[12] = "NONE";
modules[13] = "NONE";
2018-03-07 07:34:31 +03:00
modules[14] = "NONE";
2018-03-06 17:47:42 +03:00
}
if (!_vmware) {
modules[13] = "NONE";
}
if (!_vbox) {
modules[12] = "NONE";
}
if (!_sound) {
modules[16] = "NONE";
modules[17] = "NONE";
}
if (!_net) {
modules[18] = "NONE";
modules[19] = "NONE";
modules[20] = "NONE";
modules[21] = "NONE";
}
boot();
2018-07-06 17:53:14 +03:00
while (1) {}
return 0;
2018-03-05 17:12:24 +03:00
}