/* Initialize the screen. */ void grub_normal_init_page (struct grub_term_output *term) { int msg_len; int posx; const char *msg = _("GNU GRUB version %s"); char *msg_formatted; grub_uint32_t *unicode_msg; grub_uint32_t *last_position; grub_term_cls (term); msg_formatted = grub_xasprintf (msg, PACKAGE_VERSION); if (!msg_formatted) return; msg_len = grub_utf8_to_ucs4_alloc (msg_formatted, &unicode_msg, &last_position); grub_free (msg_formatted); if (msg_len < 0) { return; } posx = grub_getstringwidth (unicode_msg, last_position, term); posx = (grub_term_width (term) - posx) / 2; grub_term_gotoxy (term, posx, 1); grub_print_ucs4 (unicode_msg, last_position, 0, 0, term); grub_putcode ('\n', term); grub_putcode ('\n', term); grub_free (unicode_msg); }
static grub_err_t grub_linux_boot (void) { struct linux_kernel_params *params; struct linux_kernel_header *lh; char *prot_code; char *bootpath; grub_ssize_t len; bootpath = grub_env_get ("root"); if (bootpath) grub_ieee1275_set_property (grub_ieee1275_chosen, "bootpath", bootpath, grub_strlen (bootpath) + 1, &len); params = (struct linux_kernel_params *) GRUB_OFW_LINUX_PARAMS_ADDR; lh = (struct linux_kernel_header *) params; grub_memset ((char *) params, 0, GRUB_OFW_LINUX_CL_OFFSET); params->alt_mem = grub_mmap_get_upper () >> 10; params->ext_mem = params->alt_mem; lh->cmd_line_ptr = (char *) (GRUB_OFW_LINUX_PARAMS_ADDR + GRUB_OFW_LINUX_CL_OFFSET); params->cl_magic = GRUB_LINUX_CL_MAGIC; params->cl_offset = GRUB_OFW_LINUX_CL_OFFSET; { grub_term_output_t term; int found = 0; FOR_ACTIVE_TERM_OUTPUTS(term) if (grub_strcmp (term->name, "ofconsole") == 0) { grub_uint16_t pos = grub_term_getxy (term); params->video_cursor_x = pos >> 8; params->video_cursor_y = pos & 0xff; params->video_width = grub_term_width (term); params->video_height = grub_term_height (term); found = 1; break; } if (!found) { params->video_cursor_x = 0; params->video_cursor_y = 0; params->video_width = 80; params->video_height = 25; } }
static grub_err_t grub_linux_boot (void) { grub_err_t err = 0; const char *modevar; char *tmp; struct grub_relocator32_state state; void *real_mode_mem; struct grub_linux_boot_ctx ctx = { .real_mode_target = 0 }; grub_size_t mmap_size; grub_size_t cl_offset; #ifdef GRUB_MACHINE_IEEE1275 { const char *bootpath; grub_ssize_t len; bootpath = grub_env_get ("root"); if (bootpath) grub_ieee1275_set_property (grub_ieee1275_chosen, "bootpath", bootpath, grub_strlen (bootpath) + 1, &len); linux_params.ofw_signature = GRUB_LINUX_OFW_SIGNATURE; linux_params.ofw_num_items = 1; linux_params.ofw_cif_handler = (grub_uint32_t) grub_ieee1275_entry_fn; linux_params.ofw_idt = 0; } #endif modevar = grub_env_get ("gfxpayload"); /* Now all graphical modes are acceptable. May change in future if we have modes without framebuffer. */ if (modevar && *modevar != 0) { tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_errno; #if ACCEPTS_PURE_TEXT err = grub_video_set_mode (tmp, 0, 0); #else err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); #endif grub_free (tmp); } else /* We can't go back to text mode from coreboot fb. */ #ifdef GRUB_MACHINE_COREBOOT if (grub_video_get_driver_id () == GRUB_VIDEO_DRIVER_COREBOOT) err = GRUB_ERR_NONE; else #endif { #if ACCEPTS_PURE_TEXT err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0, 0); #else err = grub_video_set_mode (DEFAULT_VIDEO_MODE, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); #endif } if (err) { grub_print_error (); grub_puts_ (N_("Booting in blind mode")); grub_errno = GRUB_ERR_NONE; } if (grub_linux_setup_video (&linux_params)) { #if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) linux_params.have_vga = GRUB_VIDEO_LINUX_TYPE_TEXT; linux_params.video_mode = 0x3; #else linux_params.have_vga = 0; linux_params.video_mode = 0; linux_params.video_width = 0; linux_params.video_height = 0; #endif } #ifndef GRUB_MACHINE_IEEE1275 if (linux_params.have_vga == GRUB_VIDEO_LINUX_TYPE_TEXT) #endif { grub_term_output_t term; int found = 0; FOR_ACTIVE_TERM_OUTPUTS(term) if (grub_strcmp (term->name, "vga_text") == 0 || grub_strcmp (term->name, "console") == 0 || grub_strcmp (term->name, "ofconsole") == 0) { struct grub_term_coordinate pos = grub_term_getxy (term); linux_params.video_cursor_x = pos.x; linux_params.video_cursor_y = pos.y; linux_params.video_width = grub_term_width (term); linux_params.video_height = grub_term_height (term); found = 1; break; } if (!found) { linux_params.video_cursor_x = 0; linux_params.video_cursor_y = 0; linux_params.video_width = 80; linux_params.video_height = 25; } } mmap_size = find_mmap_size (); /* Make sure that each size is aligned to a page boundary. */ cl_offset = ALIGN_UP (mmap_size + sizeof (linux_params), 4096); if (cl_offset < ((grub_size_t) linux_params.setup_sects << GRUB_DISK_SECTOR_BITS)) cl_offset = ALIGN_UP ((grub_size_t) (linux_params.setup_sects << GRUB_DISK_SECTOR_BITS), 4096); ctx.real_size = ALIGN_UP (cl_offset + maximal_cmdline_size, 4096); #ifdef GRUB_MACHINE_EFI efi_mmap_size = find_efi_mmap_size (); if (efi_mmap_size == 0) return grub_errno; #endif grub_dprintf ("linux", "real_size = %x, mmap_size = %x\n", (unsigned) ctx.real_size, (unsigned) mmap_size); #ifdef GRUB_MACHINE_EFI grub_efi_mmap_iterate (grub_linux_boot_mmap_find, &ctx, 1); if (! ctx.real_mode_target) grub_efi_mmap_iterate (grub_linux_boot_mmap_find, &ctx, 0); #else grub_mmap_iterate (grub_linux_boot_mmap_find, &ctx); #endif grub_dprintf ("linux", "real_mode_target = %lx, real_size = %x, efi_mmap_size = %x\n", (unsigned long) ctx.real_mode_target, (unsigned) ctx.real_size, (unsigned) efi_mmap_size); if (! ctx.real_mode_target) return grub_error (GRUB_ERR_OUT_OF_MEMORY, "cannot allocate real mode pages"); { grub_relocator_chunk_t ch; err = grub_relocator_alloc_chunk_addr (relocator, &ch, ctx.real_mode_target, (ctx.real_size + efi_mmap_size)); if (err) return err; real_mode_mem = get_virtual_current_address (ch); } efi_mmap_buf = (grub_uint8_t *) real_mode_mem + ctx.real_size; grub_dprintf ("linux", "real_mode_mem = %p\n", real_mode_mem); ctx.params = real_mode_mem; *ctx.params = linux_params; ctx.params->cmd_line_ptr = ctx.real_mode_target + cl_offset; grub_memcpy ((char *) ctx.params + cl_offset, linux_cmdline, maximal_cmdline_size); grub_dprintf ("linux", "code32_start = %x\n", (unsigned) ctx.params->code32_start); ctx.e820_num = 0; if (grub_mmap_iterate (grub_linux_boot_mmap_fill, &ctx)) return grub_errno; ctx.params->mmap_size = ctx.e820_num; #ifdef GRUB_MACHINE_EFI { grub_efi_uintn_t efi_desc_size; grub_size_t efi_mmap_target; grub_efi_uint32_t efi_desc_version; err = grub_efi_finish_boot_services (&efi_mmap_size, efi_mmap_buf, NULL, &efi_desc_size, &efi_desc_version); if (err) return err; /* Note that no boot services are available from here. */ efi_mmap_target = ctx.real_mode_target + ((grub_uint8_t *) efi_mmap_buf - (grub_uint8_t *) real_mode_mem); /* Pass EFI parameters. */ if (grub_le_to_cpu16 (ctx.params->version) >= 0x0208) { ctx.params->v0208.efi_mem_desc_size = efi_desc_size; ctx.params->v0208.efi_mem_desc_version = efi_desc_version; ctx.params->v0208.efi_mmap = efi_mmap_target; ctx.params->v0208.efi_mmap_size = efi_mmap_size; #ifdef __x86_64__ ctx.params->v0208.efi_mmap_hi = (efi_mmap_target >> 32); #endif } else if (grub_le_to_cpu16 (ctx.params->version) >= 0x0206)
static grub_err_t grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, char **args) { int cnt = 0; char *currarg; auto int print_command_info (grub_command_t cmd); auto int print_command_help (grub_command_t cmd); int print_command_info (grub_command_t cmd) { if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)) { struct grub_term_output *term; const char *summary_translated = _(cmd->summary); char *command_help; grub_uint32_t *unicode_command_help; grub_uint32_t *unicode_last_position; command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated); if (!command_help) return 1; grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help, &unicode_last_position); FOR_ACTIVE_TERM_OUTPUTS(term) { unsigned stringwidth; grub_uint32_t *unicode_last_screen_position; unicode_last_screen_position = unicode_command_help; stringwidth = 0; while (unicode_last_screen_position < unicode_last_position && stringwidth < ((grub_term_width (term) / 2) - 2)) { stringwidth += grub_term_getcharwidth (term, *unicode_last_screen_position); unicode_last_screen_position++; } grub_print_ucs4 (unicode_command_help, unicode_last_screen_position, term); if (!(cnt % 2)) grub_print_spaces (term, grub_term_width (term) / 2 - stringwidth); } if (cnt % 2) grub_printf ("\n"); cnt++; grub_free (command_help); grub_free (unicode_command_help); } return 0; } int print_command_help (grub_command_t cmd) { if (cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) { if (! grub_strncmp (cmd->name, currarg, grub_strlen (currarg))) { if (cnt++ > 0) grub_printf ("\n\n"); if (cmd->flags & GRUB_COMMAND_FLAG_EXTCMD) grub_arg_show_help ((grub_extcmd_t) cmd->data); else grub_printf ("%s %s %s\n%s\b", _("Usage:"), cmd->name, _(cmd->summary), _(cmd->description)); } } return 0; } if (argc == 0) { grub_command_iterate (print_command_info); if (!(cnt % 2)) grub_printf ("\n"); } else { int i; for (i = 0; i < argc; i++) { currarg = args[i]; grub_command_iterate (print_command_help); } } return 0; }
static grub_err_t grub_cmd_help (grub_extcmd_t ext __attribute__ ((unused)), int argc, char **args) { int cnt = 0; char *currarg; if (argc == 0) { grub_command_t cmd; FOR_COMMANDS(cmd) { if ((cmd->prio & GRUB_PRIO_LIST_FLAG_ACTIVE) && (cmd->flags & GRUB_COMMAND_FLAG_CMDLINE)) { struct grub_term_output *term; const char *summary_translated = _(cmd->summary); char *command_help; grub_uint32_t *unicode_command_help; grub_uint32_t *unicode_last_position; command_help = grub_xasprintf ("%s %s", cmd->name, summary_translated); if (!command_help) break; grub_utf8_to_ucs4_alloc (command_help, &unicode_command_help, &unicode_last_position); FOR_ACTIVE_TERM_OUTPUTS(term) { unsigned stringwidth; grub_uint32_t *unicode_last_screen_position; unicode_last_screen_position = unicode_command_help; stringwidth = 0; while (unicode_last_screen_position < unicode_last_position && stringwidth < ((grub_term_width (term) / 2) - 2)) { struct grub_unicode_glyph glyph; unicode_last_screen_position += grub_unicode_aglomerate_comb (unicode_last_screen_position, unicode_last_position - unicode_last_screen_position, &glyph); stringwidth += grub_term_getcharwidth (term, &glyph); } grub_print_ucs4 (unicode_command_help, unicode_last_screen_position, 0, 0, term); if (!(cnt % 2)) grub_print_spaces (term, grub_term_width (term) / 2 - stringwidth); } if (cnt % 2) grub_printf ("\n"); cnt++; grub_free (command_help); grub_free (unicode_command_help); } } if (!(cnt % 2)) grub_printf ("\n"); }
static grub_err_t grub_linux_boot (void) { grub_err_t err = 0; const char *modevar; char *tmp; struct grub_relocator32_state state; void *real_mode_mem; struct grub_linux_boot_ctx ctx = { .real_mode_target = 0 }; grub_size_t mmap_size; grub_size_t cl_offset; #ifdef GRUB_MACHINE_IEEE1275 { const char *bootpath; grub_ssize_t len; bootpath = grub_env_get ("root"); if (bootpath) grub_ieee1275_set_property (grub_ieee1275_chosen, "bootpath", bootpath, grub_strlen (bootpath) + 1, &len); linux_params.ofw_signature = GRUB_LINUX_OFW_SIGNATURE; linux_params.ofw_num_items = 1; linux_params.ofw_cif_handler = (grub_uint32_t) grub_ieee1275_entry_fn; linux_params.ofw_idt = 0; } #endif modevar = grub_env_get ("gfxpayload"); /* Now all graphical modes are acceptable. May change in future if we have modes without framebuffer. */ if (modevar && *modevar != 0) { tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); if (! tmp) return grub_errno; #if ACCEPTS_PURE_TEXT err = grub_video_set_mode (tmp, 0, 0); #else err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); #endif grub_free (tmp); } else /* We can't go back to text mode from coreboot fb. */ #ifdef GRUB_MACHINE_COREBOOT if (grub_video_get_driver_id () == GRUB_VIDEO_DRIVER_COREBOOT) err = GRUB_ERR_NONE; else #endif { #if ACCEPTS_PURE_TEXT err = grub_video_set_mode (DEFAULT_VIDEO_MODE, 0, 0); #else err = grub_video_set_mode (DEFAULT_VIDEO_MODE, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); #endif } if (err) { grub_print_error (); grub_puts_ (N_("Booting in blind mode")); grub_errno = GRUB_ERR_NONE; } if (grub_linux_setup_video (&linux_params)) { #if defined (GRUB_MACHINE_PCBIOS) || defined (GRUB_MACHINE_COREBOOT) || defined (GRUB_MACHINE_QEMU) linux_params.have_vga = GRUB_VIDEO_LINUX_TYPE_TEXT; linux_params.video_mode = 0x3; #else linux_params.have_vga = 0; linux_params.video_mode = 0; linux_params.video_width = 0; linux_params.video_height = 0; #endif } #ifndef GRUB_MACHINE_IEEE1275 if (linux_params.have_vga == GRUB_VIDEO_LINUX_TYPE_TEXT) #endif { grub_term_output_t term; int found = 0; FOR_ACTIVE_TERM_OUTPUTS(term) if (grub_strcmp (term->name, "vga_text") == 0 || grub_strcmp (term->name, "console") == 0 || grub_strcmp (term->name, "ofconsole") == 0) { grub_uint16_t pos = grub_term_getxy (term); linux_params.video_cursor_x = pos >> 8; linux_params.video_cursor_y = pos & 0xff; linux_params.video_width = grub_term_width (term); linux_params.video_height = grub_term_height (term); found = 1; break; } if (!found) { linux_params.video_cursor_x = 0; linux_params.video_cursor_y = 0; linux_params.video_width = 80; linux_params.video_height = 25; } }