2006-04-30 Yoshinori K. Okuji <okuji@enbug.org>

Extend the loader so that GRUB can accept a loader which comes
        back to GRUB when a loaded image exits. Also, this change adds
        support for a chainloader on EFI.

        * term/efi/console.c: Include grub/misc.h.
        (grub_console_checkkey): Display a scan code on the top for
        debugging. This will be removed once the EFI port gets stable.
        Correct the scan code mapping.

        * kern/efi/mm.c (sort_memory_map): Sort in a descending order to
        allocate memory from larger regions, in order to reduce the number
        of allocated regions. Otherwise, the MacOSX loader panics.
        (filter_memory_map): Avoid less than 1MB for compatibility with
        other loaders.
        (add_memory_regions): Allocate from the tail of a region, if
        possible, to avoid allocating a region near to 1MB, for the MacOSX
        loader.

        * kern/efi/init.c (grub_efi_set_prefix): Specify
        GRUB_EFI_IMAGE_HANDLE to grub_efi_get_loaded_image.

        * kern/efi/efi.c (grub_efi_get_loaded_image): Accept a new
        argument IMAGE_HANDLE and specify it to get a loaded image.
        (grub_arch_modules_addr): Specify GRUB_EFI_IMAGE_HANDLE to
        grub_efi_get_loaded_image.
        (grub_efi_get_filename): Divide the legnth by the size of
        grub_efi_char16_t.
        (grub_efi_get_device_path): New function.
        (grub_efi_print_device_path): Print End Device Path nodes. Divide
        the length by the size of grub_efi_char16_t for a file path device
        path node.

        * kern/loader.c (grub_loader_noreturn): New variable.
        (grub_loader_set): Accept a new argument NORETURN. Set
        GRUB_LOADER_NORETURN to NORETURN.
        All callers changed.
        (grub_loader_boot): If GRUB_LOADER_NORETURN is false, do not call
        grub_machine_fini.

        * include/grub/efi/efi.h (grub_efi_get_device_path): New
        prototype.
        (grub_efi_get_loaded_image): Take an argument to specify an image
        handle.

        * include/grub/loader.h (grub_loader_set): Added one more argument
        NORETURN.

        * disk/efi/efidisk.c (make_devices): Use grub_efi_get_device_path
        instead of grub_efi_open_protocol.
        (grub_efidisk_get_device_name): Likewise.
        (grub_efidisk_close): Print a newline.
        (grub_efidisk_get_device_handle): Fixed to use
        GRUB_EFI_DEVICE_PATH_SUBTYPE instead of
        GRUB_EFI_DEVICE_PATH_TYPE.

        * disk/efi/efidisk.c (device_path_guid): Moved to ...
        * kern/efi/efi.c (device_path_guid): ... here.

        * conf/i386-efi.rmk (pkgdata_MODULES): Added _chain.mod and
        chain.mod.
        (kernel_mod_HEADERS): Added efi/disk.h.
        (_chain_mod_SOURCES): New variable.
        (_chain_mod_CFLAGS): Likewise.
        (_chain_mod_LDFLAGS): Likewise.
        (chain_mod_SOURCES): Likewise.
        (chain_mod_CFLAGS): Likewise.
        (chain_mod_LDFLAGS): Likewise.

        * DISTLIST: Added include/grub/efi/chainloader.h,
        loader/efi/chainloader.c and loader/efi/chainloader_normal.c.

        * include/grub/efi/chainloader.h: New file.
        * loader/efi/chainloader.c: Likewise.
        * loader/efi/chainloader_normal.c: Likewise.
This commit is contained in:
okuji 2006-04-30 21:09:37 +00:00
parent c0111d6e92
commit 7f362539b7
19 changed files with 743 additions and 64 deletions

View file

@ -18,6 +18,7 @@
*/
#include <grub/term.h>
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/efi/efi.h>
@ -70,12 +71,40 @@ grub_console_checkkey (void)
{
grub_efi_simple_input_interface_t *i;
grub_efi_input_key_t key;
grub_efi_status_t status;
if (read_key >= 0)
return 1;
i = grub_efi_system_table->con_in;
if (i->read_key_stroke (i, &key) == GRUB_EFI_SUCCESS)
status = i->read_key_stroke (i, &key);
#if 1
switch (status)
{
case GRUB_EFI_SUCCESS:
{
grub_uint16_t xy;
xy = grub_getxy ();
grub_gotoxy (0, 0);
grub_printf ("scan_code=%x,unicode_char=%x ",
(unsigned) key.scan_code,
(unsigned) key.unicode_char);
grub_gotoxy (xy >> 8, xy & 0xff);
}
break;
case GRUB_EFI_NOT_READY:
//grub_printf ("not ready ");
break;
default:
//grub_printf ("device error ");
break;
}
#endif
if (status == GRUB_EFI_SUCCESS)
{
switch (key.scan_code)
{
@ -83,45 +112,41 @@ grub_console_checkkey (void)
read_key = key.unicode_char;
break;
case 0x01:
read_key = GRUB_CONSOLE_KEY_UP;
read_key = 16;
break;
case 0x02:
read_key = GRUB_CONSOLE_KEY_DOWN;
read_key = 14;
break;
case 0x03:
read_key = GRUB_CONSOLE_KEY_RIGHT;
read_key = 6;
break;
case 0x04:
read_key = GRUB_CONSOLE_KEY_LEFT;
read_key = 2;
break;
case 0x05:
read_key = GRUB_CONSOLE_KEY_HOME;
read_key = 1;
break;
case 0x06:
read_key = GRUB_CONSOLE_KEY_END;
read_key = 5;
break;
case 0x07:
read_key = GRUB_CONSOLE_KEY_IC;
break;
case 0x08:
read_key = GRUB_CONSOLE_KEY_DC;
read_key = 4;
break;
case 0x09:
read_key = GRUB_CONSOLE_KEY_PPAGE;
break;
case 0x0a:
read_key = GRUB_CONSOLE_KEY_NPAGE;
break;
case 0x17:
read_key = '\e';
break;
default:
return 0;
break;
}
return 1;
}
return 0;
return read_key >= 0;
}
static int
@ -147,7 +172,7 @@ grub_console_getkey (void)
{
status = b->wait_for_event (1, &(i->wait_for_key), &index);
if (status != GRUB_EFI_SUCCESS)
return -1;
return -1;
grub_console_checkkey ();
}