AWK = @AWK@
LIBCURSES = @LIBCURSES@
LIBUSB = @LIBUSB@
+LIBSDL = @LIBSDL@
+ LIBPCIACCESS = @LIBPCIACCESS@
YACC = @YACC@
FONT_SOURCE = @FONT_SOURCE@
# Options.
enable_grub_emu_usb = @enable_grub_emu_usb@
+enable_grub_emu_sdl = @enable_grub_emu_sdl@
+ enable_grub_emu_pci = @enable_grub_emu_pci@
enable_grub_fstest = @enable_grub_fstest@
enable_grub_pe2elf = @enable_grub_pe2elf@
enable_grub_mkfont = @enable_grub_mkfont@
grub_emu_LDFLAGS += $(LIBCURSES) $(LIBUSB)
endif
+ifeq ($(enable_grub_emu_sdl), yes)
+grub_emu_SOURCES += util/sdl.c
+grub_emu_LDFLAGS += $(LIBSDL)
+endif
+
+ ifeq ($(enable_grub_emu_pci), yes)
+ grub_emu_SOURCES += util/pci.c commands/lspci.c
+ grub_emu_LDFLAGS += $(LIBPCIACCESS)
+ endif
+
grub_emu_init.lst: geninit.sh $(filter-out grub_emu_init.c,$(grub_emu_SOURCES))
rm -f $@; grep GRUB_MOD_INIT $(filter %.c,$^) /dev/null > $@
DISTCLEANFILES += grub_emu_init.lst
[AS_HELP_STRING([--enable-grub-emu-usb],
[build and install the `grub-emu' debugging utility with USB support (default=guessed)])])
+AC_ARG_ENABLE([grub-emu-sdl],
+ [AS_HELP_STRING([--enable-grub-emu-sdl],
+ [build and install the `grub-emu' debugging utility with SDL support (default=guessed)])])
+
+ AC_ARG_ENABLE([grub-emu-pci],
+ [AS_HELP_STRING([--enable-grub-emu-pci],
+ [build and install the `grub-emu' debugging utility with PCI support (potentially dangerous) (default=no)])])
+
if test "$platform" = emu; then
missing_ncurses=
[# Check for curses libraries.]
enable_grub_emu_usb=no
fi
+if test x"$enable_grub_emu_sdl" = xno ; then
+ grub_emu_sdl_excuse="explicitely disabled"
+fi
+[if [ x"$grub_emu_sdl_excuse" = x ]; then
+ # Check for libSDL libraries.]
+AC_CHECK_LIB([SDL], [SDL_Init], [LIBSDL="-lSDL"],
+ [grub_emu_sdl_excuse=["libSDL libraries are required to build \`grub-emu' with SDL support"]])
+ AC_SUBST([LIBSDL])
+[fi]
++
+[if [ x"$grub_emu_sdl_excuse" = x ]; then
+ # Check for headers.]
+ AC_CHECK_HEADERS([SDL/SDL.h], [],
+ [grub_emu_sdl_excuse=["libSDL header file is required to build \`grub-emu' with SDL support"]])
+[fi]
++
+if test x"enable_grub_emu_sdl" = xyes && test x"$grub_emu_sdl_excuse" != x ; then
+ AC_MSG_ERROR([SDL support for grub-emu was explicitely requested but can't be compiled])
+fi
+if test x"$grub_emu_sdl_excuse" = x ; then
+enable_grub_emu_sdl=yes
+else
+enable_grub_emu_sdl=no
+fi
+
+ if test x"$enable_grub_emu_pci" != xyes ; then
+ grub_emu_pci_excuse="not enabled"
+ fi
+
+ if test x"$enable_grub_emu_usb" = xyes ; then
+ grub_emu_pci_excuse="conflicts with USB support"
+ fi
+
+ [if [ x"$grub_emu_pci_excuse" = x ]; then
+ # Check for libpci libraries.]
+ AC_CHECK_LIB([pciaccess], [pci_system_init], [LIBPCIACCESS="-lpciaccess"],
+ [grub_emu_pci_excuse=["need libpciaccess library"]])
+ AC_SUBST([LIBPCIACCESS])
+ [fi]
+ [if [ x"$grub_emu_pci_excuse" = x ]; then
+ # Check for headers.]
+ AC_CHECK_HEADERS([pci/pci.h], [],
+ [grub_emu_pci_excuse=["need libpciaccess headers"]])
+ [fi]
+
+ if test x"$grub_emu_pci_excuse" = x ; then
+ enable_grub_emu_pci=yes
+ else
++
+ enable_grub_emu_pci=no
+ fi
+
+AC_SUBST([enable_grub_emu_sdl])
AC_SUBST([enable_grub_emu_usb])
+ AC_SUBST([enable_grub_emu_pci])
fi
AC_ARG_ENABLE([grub-fstest],
else
echo USB support for grub-emu: No "($grub_emu_usb_excuse)"
fi
+if [ x"$grub_emu_sdl_excuse" = x ]; then
+echo SDL support for grub-emu: Yes
+else
+echo SDL support for grub-emu: No "($grub_emu_sdl_excuse)"
+fi
+ if [ x"$grub_emu_pci_excuse" = x ]; then
+ echo PCI support for grub-emu: Yes
+ else
+ echo PCI support for grub-emu: No "($grub_emu_pci_excuse)"
+ fi
fi
if [ x"$enable_mm_debug" = xyes ]; then
echo With memory debugging: Yes
grub_err_t grub_xnu_load_kext_from_dir (char *dirname, char *osbundlerequired,
int maxrecursion);
void *grub_xnu_heap_malloc (int size);
+ grub_err_t grub_xnu_fill_devicetree (void);
extern grub_uint32_t grub_xnu_heap_real_start;
extern grub_size_t grub_xnu_heap_size;
- extern char *grub_xnu_heap_start;
+ extern void *grub_xnu_heap_start;
extern struct grub_video_bitmap *grub_xnu_bitmap;
+typedef enum {GRUB_XNU_BITMAP_CENTER, GRUB_XNU_BITMAP_STRETCH}
+ grub_xnu_bitmap_mode_t;
+extern grub_xnu_bitmap_mode_t grub_xnu_bitmap_mode;
+ extern int grub_xnu_is_64bit;
#endif
#include <grub/gzio.h>
#include <grub/command.h>
#include <grub/misc.h>
+#include <grub/extcmd.h>
+ #include <grub/env.h>
struct grub_xnu_devtree_key *grub_xnu_devtree_root = 0;
static int driverspackagenum = 0;
}
}
+ static inline int
+ hextoval (char c)
+ {
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ if (c >= 'a' && c <= 'z')
+ return c - 'a' + 10;
+ if (c >= 'A' && c <= 'Z')
+ return c - 'A' + 10;
+ return 0;
+ }
+
+ static inline void
+ unescape (char *name, char *curdot, char *nextdot, int *len)
+ {
+ char *ptr, *dptr;
+ dptr = name;
+ for (ptr = curdot; ptr < nextdot;)
+ if (ptr + 2 < nextdot && *ptr == '%')
+ {
+ *dptr = (hextoval (ptr[1]) << 4) | (hextoval (ptr[2]));
+ ptr += 3;
+ dptr++;
+ }
+ else
+ {
+ *dptr = *ptr;
+ ptr++;
+ dptr++;
+ }
+ *len = dptr - name;
+ }
+
+ grub_err_t
+ grub_xnu_fill_devicetree (void)
+ {
+ auto int iterate_env (struct grub_env_var *var);
+ int iterate_env (struct grub_env_var *var)
+ {
+ char *nextdot = 0, *curdot;
+ struct grub_xnu_devtree_key **curkey = &grub_xnu_devtree_root;
+ struct grub_xnu_devtree_key *curvalue;
+ char *name = 0, *data;
+ int len;
+
+ if (grub_memcmp (var->name, "XNU.DeviceTree.",
+ sizeof ("XNU.DeviceTree.") - 1) != 0)
+ return 0;
+
+ curdot = var->name + sizeof ("XNU.DeviceTree.") - 1;
+ nextdot = grub_strchr (curdot, '.');
+ if (nextdot)
+ nextdot++;
+ while (nextdot)
+ {
+ name = grub_realloc (name, nextdot - curdot + 1);
+
+ if (!name)
+ return 1;
+
+ unescape (name, curdot, nextdot, &len);
+ name[len - 1] = 0;
+
+ curkey = &(grub_xnu_create_key (curkey, name)->first_child);
+
+ curdot = nextdot;
+ nextdot = grub_strchr (nextdot, '.');
+ if (nextdot)
+ nextdot++;
+ }
+
+ nextdot = curdot + grub_strlen (curdot) + 1;
+
+ name = grub_realloc (name, nextdot - curdot + 1);
+
+ if (!name)
+ return 1;
+
+ unescape (name, curdot, nextdot, &len);
+ name[len] = 0;
+
+ curvalue = grub_xnu_create_value (curkey, name);
+ grub_free (name);
+
+ data = grub_malloc (grub_strlen (var->value) + 1);
+ if (!data)
+ return 1;
+
+ unescape (data, var->value, var->value + grub_strlen (var->value),
+ &len);
+ curvalue->datasize = len;
+ curvalue->data = data;
+
+ return 0;
+ }
+
+ grub_env_iterate (iterate_env);
+
+ return grub_errno;
+ }
+
struct grub_video_bitmap *grub_xnu_bitmap = 0;
+grub_xnu_bitmap_mode_t grub_xnu_bitmap_mode;
+
+/* Option array indices. */
+#define XNU_SPLASH_CMD_ARGINDEX_MODE 0
+
+static const struct grub_arg_option xnu_splash_cmd_options[] =
+ {
+ {"mode", 'm', 0, "Background image mode.", "stretch|normal",
+ ARG_TYPE_STRING},
+ {0, 0, 0, 0, 0, 0}
+ };
static grub_err_t
-grub_cmd_xnu_splash (grub_command_t cmd __attribute__ ((unused)),
+grub_cmd_xnu_splash (grub_extcmd_t cmd,
int argc, char *args[])
{
grub_err_t err;
locked = 0;
}
- static grub_command_t cmd_kernel, cmd_mkext, cmd_kext;
- static grub_command_t cmd_devtree;
+ static grub_command_t cmd_kernel64, cmd_kernel, cmd_mkext, cmd_kext;
-static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume, cmd_splash;
+static grub_command_t cmd_kextdir, cmd_ramdisk, cmd_resume;
+static grub_extcmd_t cmd_splash;
GRUB_MOD_INIT(xnu)
{
cmd_ramdisk = grub_register_command ("xnu_ramdisk", grub_cmd_xnu_ramdisk, 0,
"Load XNU ramdisk. "
"It will be seen as md0");
- cmd_devtree = grub_register_command ("xnu_devtree", grub_cmd_xnu_devtree, 0,
- "Load XNU devtree");
- cmd_splash = grub_register_command ("xnu_splash", grub_cmd_xnu_splash, 0,
- "Load a splash image for XNU");
+ cmd_splash = grub_register_extcmd ("xnu_splash",
+ grub_cmd_xnu_splash,
+ GRUB_COMMAND_FLAG_BOTH, 0,
+ "Load a splash image for XNU",
+ xnu_splash_cmd_options);
#ifndef GRUB_UTIL
cmd_resume = grub_register_command ("xnu_resume", grub_cmd_xnu_resume,
grub_unregister_command (cmd_mkext);
grub_unregister_command (cmd_kext);
grub_unregister_command (cmd_kextdir);
- grub_unregister_command (cmd_devtree);
grub_unregister_command (cmd_ramdisk);
grub_unregister_command (cmd_kernel);
- grub_unregister_command (cmd_splash);
+ grub_unregister_extcmd (cmd_splash);
+ grub_unregister_command (cmd_kernel64);
+
+ grub_cpu_xnu_fini ();
}
cl_print (lpos, echo_char);
cl_set_pos ();
}
-
- grub_refresh ();
}
- plen = grub_strlen (prompt);
+ plen = grub_strlen (prompt_translated);
lpos = llen = 0;
buf[0] = '\0';
print_message (nested, edit);
}
-/* Get the entry number from the variable NAME. */
-static int
-get_entry_number (const char *name)
-{
- char *val;
- int entry;
-
- val = grub_env_get (name);
- if (! val)
- return -1;
-
- grub_error_push ();
-
- entry = (int) grub_strtoul (val, 0, 0);
-
- if (grub_errno != GRUB_ERR_NONE)
- {
- grub_errno = GRUB_ERR_NONE;
- entry = -1;
- }
-
- grub_error_pop ();
-
- return entry;
-}
-
static void
- print_timeout (int timeout, int offset, int second_stage)
+ print_timeout (int timeout, int offset)
{
- /* NOTE: Do not remove the trailing space characters.
- They are required to clear the line. */
- char *msg = " The highlighted entry will be booted automatically in %ds. ";
- char *msg_end = grub_strchr (msg, '%');
+ const char *msg =
+ _("The highlighted entry will be booted automatically in %ds.");
+
+ grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
+
+ char *msg_translated =
+ grub_malloc (sizeof (char) * grub_strlen (msg) + 5);
+
+ grub_sprintf (msg_translated, msg, timeout);
+ grub_print_message_indented (msg_translated, 3, 0);
+
+ int posx;
+ posx = grub_getxy() >> 8;
+ print_spaces (GRUB_TERM_WIDTH - posx - 1);
- grub_gotoxy (second_stage ? (msg_end - msg) : 0, GRUB_TERM_HEIGHT - 3);
- grub_printf (second_stage ? msg_end : msg, timeout);
grub_gotoxy (GRUB_TERM_CURSOR_X, GRUB_TERM_FIRST_ENTRY_Y + offset);
grub_refresh ();
- };
+ }
/* Show the menu and handle menu entry selection. Returns the menu entry
index that should be executed or -1 if no entry should be executed (e.g.,
timeout = grub_menu_get_timeout ();
if (timeout > 0)
- print_timeout (timeout, offset, 0);
+ print_timeout (timeout, offset);
- while (1)
+ while (! grub_menu_viewer_should_return ())
{
int c;
timeout = grub_menu_get_timeout ();