pull-in emu-lite branch

This commit is contained in:
BVK Chaitanya 2010-05-06 12:55:47 +05:30
commit 16321bf9ca
26 changed files with 316 additions and 345 deletions

View file

@ -123,7 +123,7 @@ esac
case "$platform" in
coreboot) machine_CPPFLAGS="-DGRUB_MACHINE_COREBOOT=1" ;;
multiboot) machine_CFLAGS="-DGRUB_MACHINE_MULTIBOOT=1" ;;
multiboot) machine_CPPFLAGS="-DGRUB_MACHINE_MULTIBOOT=1" ;;
efi) machine_CPPFLAGS="-DGRUB_MACHINE_EFI=1" ;;
ieee1275) machine_CPPFLAGS="-DGRUB_MACHINE_IEEE1275=1" ;;
qemu) machine_CPPFLAGS="-DGRUB_MACHINE_QEMU=1" ;;
@ -801,4 +801,3 @@ AM_CONDITIONAL([COND_GRUB_MKFONT], [test x$enable_grub_mkfont = xyes])
AM_CONDITIONAL([COND_HAVE_FONT_SOURCE], [test x$FONT_SOURCE != x])
AM_CONDITIONAL([COND_GRUB_FSTEST], [test x$enable_grub_fstest = xyes])
AM_CONDITIONAL([COND_ENABLE_EFIEMU], [test x$enable_efiemu = xyes])

View file

@ -175,7 +175,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
}
/* Load modules. */
#if defined(GRUB_MACHINE_EMU)
if (! grub_no_autoload)
{
const char *prefix;
prefix = grub_env_get ("prefix");
@ -233,7 +233,6 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)),
/* Ignore errors. */
grub_errno = GRUB_ERR_NONE;
}
#endif
if (argc == 1)
return show_help ();

View file

@ -10,25 +10,23 @@ kernel_img_SOURCES = kern/device.c kern/disk.c kern/dl.c kern/env.c \
kern/parser.c kern/partition.c kern/term.c \
kern/rescue_reader.c kern/rescue_parser.c \
\
util/console.c util/grub-emu.c util/misc.c \
util/hostdisk.c util/getroot.c util/mm.c util/time.c \
kern/emu/main.c kern/emu/mm.c kern/emu/misc.c \
kern/emu/getroot.c kern/emu/time.c kern/emu/hostdisk.c \
kern/emu/hostfs.c kern/emu/console.c \
\
gnulib/progname.c util/hostfs.c disk/host.c
kernel_img_HEADERS += datetime.h util/misc.h
gnulib/progname.c disk/host.c
kernel_img_HEADERS += datetime.h emu/misc.h
kernel_img_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-undef -I$(srcdir)/gnulib
kernel_img_LDFLAGS = $(COMMON_LDFLAGS)
TARGET_NO_STRIP = yes
ifneq ($(TARGET_NO_MODULES), yes)
kernel_img_SOURCES += symlist.c kern/$(target_cpu)/dl.c
ifneq ($(target_cpu), i386)
ifneq ($(target_cpu), x86_64)
kernel_img_SOURCES += kern/$(target_cpu)/cache.S
endif
endif
else
kernel_img_SOURCES += grub_emu_init.c
endif
noinst_MODULES = emu-full.mod
emu_full_mod_SOURCES = kern/emu/full.c
emu_full_mod_CFLAGS = $(COMMON_CFLAGS)
noinst_MODULES = emu-lite.mod
emu_lite_mod_SOURCES = kern/emu/lite.c kern/emu/cache.S symlist.c
emu_lite_mod_CFLAGS = $(COMMON_CFLAGS)
# For halt.mod.
pkglib_MODULES += halt.mod
@ -49,7 +47,7 @@ ifeq ($(enable_grub_emu_usb), yes)
kernel_img_HEADERS += libusb.h
pkglib_MODULES += libusb.mod
libusb_mod_SOURCES = util/usb.c
libusb_mod_SOURCES = bus/usb/emu/usb.c
libusb_mod_CFLAGS =
libusb_mod_LDFLAGS = $(COMMON_LDFLAGS)
@ -76,7 +74,7 @@ endif
ifeq ($(enable_grub_emu_sdl), yes)
pkglib_MODULES += sdl.mod
sdl_mod_SOURCES = util/sdl.c
sdl_mod_SOURCES = video/emu/sdl.c
sdl_mod_CFLAGS =
sdl_mod_LDFLAGS = $(COMMON_LDFLAGS)
grub_emu_LDFLAGS += $(LIBSDL)
@ -85,7 +83,7 @@ endif
ifeq ($(enable_grub_emu_pci), yes)
pkglib_MODULES += pci.mod
pci_mod_SOURCES = util/pci.c commands/lspci.c
pci_mod_SOURCES = bus/emu/pci.c commands/lspci.c
pci_mod_LDFLAGS = $(COMMON_LDFLAGS)
grub_emu_LDFLAGS += $(LIBPCIACCESS)
kernel_img_HEADERS += libpciaccess.h
@ -101,13 +99,16 @@ grub_emu_init.c: genemuinit.sh $(pkglib_MODULES) grub_emu_init.h
rm -f $@; echo $(pkglib_MODULES) | sh $(srcdir)/genemuinit.sh $(NM) > $@
DISTCLEANFILES += grub_emu_init.c
CLEANFILES += grub-emu
ifneq ($(TARGET_NO_MODULES), yes)
grub-emu: $(pkglib_PROGRAMS)
$(CC) -o $@ $(pkglib_PROGRAMS) $(grub_emu_LDFLAGS) $(LDFLAGS)
else
grub-emu: $(pkglib_MODULES) $(pkglib_PROGRAMS)
$(CC) -o $@ $(pkglib_MODULES) $(pkglib_PROGRAMS) $(grub_emu_LDFLAGS) $(LDFLAGS)
endif
GRUB_EMU=grub-emu
grub_emu_init.o: grub_emu_init.c grub_emu_init.h
rm -f $@; $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -DGRUB_FILE=\"grub_init.c\" -c -o $@ $<
CLEANFILES += grub_emu_init.o
CLEANFILES += grub-emu-lite
grub-emu-lite: $(pkglib_PROGRAMS) emu-lite.mod
$(CC) -o $@ $^ $(grub_emu_LDFLAGS) $(LDFLAGS)
GRUB_EMU_LITE=grub-emu-lite
CLEANFILES += grub-emu
grub-emu: $(pkglib_MODULES) $(pkglib_PROGRAMS) emu-full.mod grub_emu_init.o
$(CC) -o $@ $^ $(grub_emu_LDFLAGS) $(LDFLAGS)
GRUB_EMU=grub-emu

View file

@ -6,7 +6,7 @@ script/lexer.c_DEPENDENCIES = grub_script.tab.h
sbin_UTILITIES += grub-mkdevicemap
grub_mkdevicemap_SOURCES = gnulib/progname.c util/grub-mkdevicemap.c \
util/deviceiter.c \
util/misc.c
util/misc.c kern/emu/misc.c
ifeq ($(target_cpu)-$(platform), sparc64-ieee1275)
grub_mkdevicemap_SOURCES += util/ieee1275/ofpath.c util/ieee1275/devicemap.c
@ -16,16 +16,15 @@ endif
# For grub-mkelfimage.
bin_UTILITIES += grub-mkelfimage
grub_mkelfimage_SOURCES = gnulib/progname.c \
util/elf/grub-mkimage.c util/misc.c \
util/resolve.c
grub_mkelfimage_SOURCES = gnulib/progname.c util/elf/grub-mkimage.c \
util/misc.c kern/emu/misc.c util/resolve.c
util/elf/grub-mkimage.c_DEPENDENCIES = Makefile
# For grub-probe.
sbin_UTILITIES += grub-probe
util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c \
util/hostdisk.c util/misc.c util/getroot.c util/mm.c \
kern/emu/hostdisk.c util/misc.c kern/emu/misc.c kern/emu/getroot.c kern/emu/mm.c \
kern/device.c kern/disk.c kern/err.c kern/misc.c \
kern/parser.c kern/partition.c kern/file.c kern/list.c \
\
@ -60,8 +59,8 @@ grub_mkisofs_CFLAGS = -D_FILE_OFFSET_BITS=64 \
# For grub-fstest.
util/grub-fstest.c_DEPENDENCIES = grub_fstest_init.h
grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \
util/misc.c util/mm.c \
grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c kern/emu/hostfs.c \
util/misc.c kern/emu/misc.c kern/emu/mm.c \
kern/file.c kern/device.c kern/disk.c kern/err.c kern/misc.c \
disk/host.c disk/loopback.c kern/list.c kern/command.c \
lib/arg.c commands/extcmd.c normal/datetime.c normal/misc.c \
@ -83,14 +82,14 @@ grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c util/hostfs.c \
# For grub-mkfont.
ifeq ($(enable_grub_mkfont), yes)
bin_UTILITIES += grub-mkfont
grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c
grub_mkfont_SOURCES = gnulib/progname.c util/grub-mkfont.c util/misc.c kern/emu/misc.c
grub_mkfont_CFLAGS = $(freetype_cflags)
grub_mkfont_LDFLAGS = $(freetype_libs)
endif
# For grub-mkrelpath.
bin_UTILITIES += grub-mkrelpath
grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c
grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c kern/emu/misc.c
bin_UTILITIES += grub-bin2h
grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.c
@ -104,7 +103,7 @@ DISTCLEANFILES += grub_script.yy.c grub_script.yy.h
bin_UTILITIES += grub-script-check
util/grub-script-check.c_DEPENDENCIES = grub_script_check_init.h
grub_script_check_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c \
util/grub-script-check.c util/misc.c util/mm.c \
util/grub-script-check.c util/misc.c kern/emu/misc.c kern/emu/mm.c \
script/main.c script/script.c script/function.c script/lexer.c \
kern/handler.c kern/err.c kern/parser.c kern/list.c \
kern/misc.c kern/env.c grub_script_check_init.c grub_script.tab.c \
@ -187,7 +186,7 @@ DISTCLEANFILES += grub_fstest_init.c
# for grub-editenv
bin_UTILITIES += grub-editenv
grub_editenv_SOURCES = gnulib/progname.c util/grub-editenv.c lib/envblk.c util/misc.c util/mm.c kern/misc.c kern/err.c
grub_editenv_SOURCES = gnulib/progname.c util/grub-editenv.c lib/envblk.c util/misc.c kern/emu/misc.c kern/emu/mm.c kern/misc.c kern/err.c
CLEANFILES += grub-editenv
# Needed for genmk.rb to work
@ -195,7 +194,7 @@ ifeq (0,1)
bin_UTILITIES += grub-macho2img grub-pe2elf
endif
grub_pe2elf_SOURCES = gnulib/progname.c util/grub-pe2elf.c util/misc.c
grub_pe2elf_SOURCES = gnulib/progname.c util/grub-pe2elf.c util/misc.c kern/emu/misc.c
CLEANFILES += grub-pe2elf
grub_macho2img_SOURCES = util/grub-macho2img.c
@ -861,7 +860,7 @@ boot_mod_CFLAGS = $(COMMON_CFLAGS)
boot_mod_LDFLAGS = $(COMMON_LDFLAGS)
bin_UTILITIES += grub-mkpasswd-pbkdf2
grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c util/mm.c kern/err.c
grub_mkpasswd_pbkdf2_SOURCES = gnulib/progname.c gnulib/getdelim.c gnulib/getline.c util/grub-mkpasswd-pbkdf2.c lib/crypto.c lib/libgcrypt-grub/cipher/sha512.c lib/pbkdf2.c util/misc.c kern/emu/misc.c kern/emu/mm.c kern/err.c
grub_mkpasswd_pbkdf2_CFLAGS += -Wno-missing-field-initializers -Wno-error -I$(srcdir)/lib/libgcrypt_wrap -DGRUB_MKPASSWD=1
include $(srcdir)/conf/gcry.mk

View file

@ -25,7 +25,7 @@
#include <grub/lvm.h>
#ifdef GRUB_UTIL
#include <grub/util/misc.h>
#include <grub/emu/misc.h>
#endif
static struct grub_lvm_vg *vg_list;

View file

@ -105,13 +105,13 @@ int EXPORT_FUNC(grub_dl_ref) (grub_dl_t mod);
int EXPORT_FUNC(grub_dl_unref) (grub_dl_t mod);
void EXPORT_FUNC(grub_dl_iterate) (int (*hook) (grub_dl_t mod));
grub_dl_t EXPORT_FUNC(grub_dl_get) (const char *name);
grub_err_t grub_dl_register_symbol (const char *name, void *addr,
grub_err_t EXPORT_FUNC(grub_dl_register_symbol) (const char *name, void *addr,
grub_dl_t mod);
grub_err_t grub_arch_dl_check_header (void *ehdr);
grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr);
#if defined (_mips)
#if defined (_mips) && ! GRUB_MACHINE_EMU
#define GRUB_LINKER_HAVE_INIT 1
void grub_arch_dl_init_linker (void);
#endif

View file

@ -4,12 +4,24 @@
#include <grub/symbol.h>
#include <grub/types.h>
#ifdef __NetBSD__
/* NetBSD uses /boot for its boot block. */
# define DEFAULT_DIRECTORY "/grub"
#else
# define DEFAULT_DIRECTORY "/boot/grub"
#endif
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
extern int verbosity;
extern const char *program_name;
void grub_emu_init (void);
void grub_init_all (void);
void grub_fini_all (void);
char *grub_make_system_path_relative_to_its_root (const char *path);
void * EXPORT_FUNC(xmalloc) (grub_size_t size);
void * EXPORT_FUNC(xrealloc) (void *ptr, grub_size_t size);
char * EXPORT_FUNC(xstrdup) (const char *str);
@ -19,4 +31,14 @@ void EXPORT_FUNC(grub_util_warn) (const char *fmt, ...);
void EXPORT_FUNC(grub_util_info) (const char *fmt, ...);
void EXPORT_FUNC(grub_util_error) (const char *fmt, ...) __attribute__ ((noreturn));
#ifndef HAVE_VASPRINTF
int EXPORT_FUNC(vasprintf) (char **buf, const char *fmt, va_list ap);
#endif
#ifndef HAVE_ASPRINTF
int EXPORT_FUNC(asprintf) (char **buf, const char *fmt, ...);
#endif
char * EXPORT_FUNC(xasprintf) (const char *fmt, ...);
#endif /* GRUB_EMU_MISC_H */

View file

@ -50,6 +50,9 @@
/* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */
#define grub_memcpy(d,s,n) grub_memmove ((d), (s), (n))
/* Flag to control module autoloading in normal mode. */
extern int EXPORT_VAR(grub_no_autoload);
void *EXPORT_FUNC(grub_memmove) (void *dest, const void *src, grub_size_t n);
char *EXPORT_FUNC(grub_strcpy) (char *dest, const char *src);
char *EXPORT_FUNC(grub_strncpy) (char *dest, const char *src, int c);

View file

@ -28,15 +28,7 @@
#include <config.h>
#include <grub/types.h>
#include <grub/symbol.h>
#ifdef __NetBSD__
/* NetBSD uses /boot for its boot block. */
# define DEFAULT_DIRECTORY "/grub"
#else
# define DEFAULT_DIRECTORY "/boot/grub"
#endif
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
#include <grub/emu/misc.h>
char *grub_util_get_path (const char *dir, const char *file);
size_t grub_util_get_fp_size (FILE *fp);
@ -48,18 +40,6 @@ void grub_util_write_image (const char *img, size_t size, FILE *out);
void grub_util_write_image_at (const void *img, size_t size, off_t offset,
FILE *out);
#ifndef HAVE_VASPRINTF
int vasprintf (char **buf, const char *fmt, va_list ap);
#endif
#ifndef HAVE_ASPRINTF
int asprintf (char **buf, const char *fmt, ...);
#endif
#ifdef __MINGW32__
#define fseeko fseeko64

View file

@ -474,7 +474,8 @@ grub_dl_ref (grub_dl_t mod)
{
grub_dl_dep_t dep;
if (!mod) return 0;
if (!mod)
return 0;
for (dep = mod->dep; dep; dep = dep->next)
grub_dl_ref (dep->mod);
@ -487,7 +488,8 @@ grub_dl_unref (grub_dl_t mod)
{
grub_dl_dep_t dep;
if (!mod) return 0;
if (!mod)
return 0;
for (dep = mod->dep; dep; dep = dep->next)
grub_dl_unref (dep->mod);

View file

@ -2,15 +2,17 @@
#error "This source is only meant for grub-emu platform"
#endif
#if GRUB_CPU_I386
#elif GRUB_CPU_X86_64
#elif GRUB_CPU_SPARC64
#if defined(GRUB_CPU_I386)
/* Nothing is necessary. */
#elif defined(GRUB_CPU_X86_64)
/* Nothing is necessary. */
#elif defined(GRUB_CPU_SPARC64)
#include "../sparc64/cache.S"
#elif GRUB_CPU_MIPS
#elif defined(GRUB_CPU_MIPS)
#include "../mips/cache.S"
#elif GRUB_CPU_MIPSEL
#elif defined(GRUB_CPU_MIPSEL)
#include "../mips/cache.S"
#elif GRUB_CPU_POWERPC
#elif defined(GRUB_CPU_POWERPC)
#include "../powerpc/cache.S"
#else
#error "No target cpu type is defined"

View file

@ -1,19 +0,0 @@
#ifndef GRUB_MACHINE_EMU
#error "This source is only meant for grub-emu platform"
#endif
#if GRUB_CPU_I386
#include "../i386/dl.c"
#elif GRUB_CPU_X86_64
#include "../x86_64/dl.c"
#elif GRUB_CPU_SPARC64
#include "../sparc64/dl.c"
#elif GRUB_CPU_MIPS
#include "../mips/dl.c"
#elif GRUB_CPU_MIPSEL
#include "../mips/dl.c"
#elif GRUB_CPU_POWERPC
#include "../powerpc/dl.c"
#else
#error "No target cpu type is defined"
#endif

View file

@ -1,26 +0,0 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2010 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <grub/kernel.h>
#include <grub/emu/misc.h>
void
grub_register_exported_symbols (void)
{
}

View file

@ -18,12 +18,20 @@
#include <config.h>
#include <grub/dl.h>
#include <grub/env.h>
#include <grub/kernel.h>
#include <grub/misc.h>
#include <grub/emu/misc.h>
void
grub_register_exported_symbols (void)
{
}
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
(void) ehdr;
return GRUB_ERR_BAD_MODULE;
}
@ -32,20 +40,11 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
{
(void) mod;
(void) ehdr;
return GRUB_ERR_BAD_MODULE;
}
/* int */
/* grub_dl_ref (grub_dl_t mod) */
/* { */
/* (void) mod; */
/* return 0; */
/* } */
/* int */
/* grub_dl_unref (grub_dl_t mod) */
/* { */
/* (void) mod; */
/* return 0; */
/* } */
void
grub_emu_init (void)
{
grub_no_autoload = 1;
}

View file

@ -27,13 +27,6 @@
#include <stdlib.h>
#include <stdint.h>
#ifdef __CYGWIN__
# include <sys/fcntl.h>
# include <sys/cygwin.h>
# include <limits.h>
# define DEV_CYGDRIVE_MAJOR 98
#endif
#ifdef __GNU__
#include <hurd.h>
#include <hurd/lookup.h>
@ -546,101 +539,3 @@ grub_util_check_char_device (const char *blk_dev)
else
return 0;
}
/* This function never prints trailing slashes (so that its output
can be appended a slash unconditionally). */
char *
grub_make_system_path_relative_to_its_root (const char *path)
{
struct stat st;
char *p, *buf, *buf2, *buf3;
uintptr_t offset = 0;
dev_t num;
size_t len;
/* canonicalize. */
p = canonicalize_file_name (path);
if (p == NULL)
grub_util_error ("failed to get canonical path of %s", path);
len = strlen (p) + 1;
buf = xstrdup (p);
free (p);
if (stat (buf, &st) < 0)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
buf2 = xstrdup (buf);
num = st.st_dev;
/* This loop sets offset to the number of chars of the root
directory we're inspecting. */
while (1)
{
p = strrchr (buf, '/');
if (p == NULL)
/* This should never happen. */
grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)");
if (p != buf)
*p = 0;
else
*++p = 0;
if (stat (buf, &st) < 0)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
/* buf is another filesystem; we found it. */
if (st.st_dev != num)
{
/* offset == 0 means path given is the mount point.
This works around special-casing of "/" in Un*x. This function never
prints trailing slashes (so that its output can be appended a slash
unconditionally). Each slash in is considered a preceding slash, and
therefore the root directory is an empty string. */
if (offset == 0)
{
free (buf);
free (buf2);
return xstrdup ("");
}
else
break;
}
offset = p - buf;
/* offset == 1 means root directory. */
if (offset == 1)
{
/* Include leading slash. */
offset = 0;
break;
}
}
free (buf);
buf3 = xstrdup (buf2 + offset);
free (buf2);
#ifdef __CYGWIN__
if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
{
/* Reached some mount point not below /cygdrive.
GRUB does not know Cygwin's emulated mounts,
convert to Win32 path. */
grub_util_info ("Cygwin path = %s\n", buf3);
char * temp = get_win32_path (buf3);
free (buf3);
buf3 = temp;
}
#endif
/* Remove trailing slashes, return empty string if root directory. */
len = strlen (buf3);
while (len > 0 && buf3[len - 1] == '/')
{
buf3[len - 1] = '\0';
len--;
}
return buf3;
}

View file

@ -1,6 +1,26 @@
#include <config.h>
#include <grub/emu/misc.h>
#ifndef GRUB_MACHINE_EMU
#error "This source is only meant for grub-emu platform"
#endif
#if defined(GRUB_CPU_I386)
#include "../i386/dl.c"
#elif defined(GRUB_CPU_X86_64)
#include "../x86_64/dl.c"
#elif defined(GRUB_CPU_SPARC64)
#include "../sparc64/dl.c"
#elif defined(GRUB_CPU_MIPS)
#include "../mips/dl.c"
#elif defined(GRUB_CPU_MIPSEL)
#include "../mips/dl.c"
#elif defined(GRUB_CPU_POWERPC)
#include "../powerpc/dl.c"
#else
#error "No target cpu type is defined"
#endif
/* grub-emu-lite supports dynamic module loading, so it won't have any
embedded modules. */
void
@ -14,3 +34,9 @@ grub_fini_all(void)
{
return;
}
void
grub_emu_init (void)
{
return;
}

View file

@ -27,6 +27,7 @@
#include <sys/types.h>
#include <unistd.h>
#include <grub/dl.h>
#include <grub/mm.h>
#include <grub/setjmp.h>
#include <grub/fs.h>
@ -34,7 +35,6 @@
#include <grub/time.h>
#include <grub/emu/console.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/kernel.h>
#include <grub/normal.h>
#include <grub/emu/getroot.h>
@ -136,6 +136,7 @@ void grub_hostfs_init (void);
void grub_hostfs_fini (void);
void grub_host_init (void);
void grub_host_fini (void);
void grub_emu_init (void);
int
main (int argc, char *argv[])
@ -194,6 +195,7 @@ main (int argc, char *argv[])
}
signal (SIGINT, SIG_IGN);
grub_emu_init ();
grub_console_init ();
grub_host_init ();
grub_hostfs_init ();

View file

@ -3,8 +3,12 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <grub/mm.h>
#include <grub/err.h>
@ -62,70 +66,14 @@ grub_util_error (const char *fmt, ...)
exit (1);
}
void *
grub_malloc (grub_size_t size)
{
return malloc (size);
}
void *
grub_zalloc (grub_size_t size)
{
void *ret;
ret = malloc (size);
memset (ret, 0, size);
return ret;
}
void
grub_free (void *ptr)
{
free (ptr);
}
void *
grub_realloc (void *ptr, grub_size_t size)
{
return realloc (ptr, size);
}
void *
grub_memalign (grub_size_t align, grub_size_t size)
{
void *p;
#if defined(HAVE_POSIX_MEMALIGN)
if (align < sizeof (void *))
align = sizeof (void *);
else if (align % sizeof (void *))
grub_fatal ("bad alignment");
if (posix_memalign (&p, align, size) != 0)
p = 0;
#elif defined(HAVE_MEMALIGN)
p = memalign (align, size);
#else
(void) align;
(void) size;
grub_fatal ("grub_memalign is not supported");
#endif
if (! p)
grub_fatal ("out of memory");
return p;
}
void *
xmalloc (grub_size_t size)
{
void *p;
p = grub_malloc (size);
p = malloc (size);
if (! p)
grub_fatal ("out of memory");
grub_util_error ("out of memory");
return p;
}
@ -133,9 +81,9 @@ xmalloc (grub_size_t size)
void *
xrealloc (void *ptr, grub_size_t size)
{
ptr = grub_realloc (ptr, size);
ptr = realloc (ptr, size);
if (! ptr)
grub_fatal ("out of memory");
grub_util_error ("out of memory");
return ptr;
}
@ -146,13 +94,43 @@ xstrdup (const char *str)
size_t len;
char *newstr;
len = grub_strlen (str);
len = strlen (str);
newstr = (char *) xmalloc (len + 1);
grub_memcpy (newstr, str, len + 1);
memcpy (newstr, str, len + 1);
return newstr;
}
#ifndef HAVE_VASPRINTF
int
vasprintf (char **buf, const char *fmt, va_list ap)
{
/* Should be large enough. */
*buf = xmalloc (512);
return vsprintf (*buf, fmt, ap);
}
#endif
#ifndef HAVE_ASPRINTF
int
asprintf (char **buf, const char *fmt, ...)
{
int status;
va_list ap;
va_start (ap, fmt);
status = vasprintf (*buf, fmt, ap);
va_end (ap);
return status;
}
#endif
char *
xasprintf (const char *fmt, ...)
{
@ -197,3 +175,102 @@ grub_get_rtc (void)
+ (((tv.tv_sec % GRUB_TICKS_PER_SECOND) * 1000000 + tv.tv_usec)
* GRUB_TICKS_PER_SECOND / 1000000));
}
/* This function never prints trailing slashes (so that its output
can be appended a slash unconditionally). */
char *
grub_make_system_path_relative_to_its_root (const char *path)
{
struct stat st;
char *p, *buf, *buf2, *buf3;
uintptr_t offset = 0;
dev_t num;
size_t len;
/* canonicalize. */
p = canonicalize_file_name (path);
if (p == NULL)
grub_util_error ("failed to get canonical path of %s", path);
len = strlen (p) + 1;
buf = xstrdup (p);
free (p);
if (stat (buf, &st) < 0)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
buf2 = xstrdup (buf);
num = st.st_dev;
/* This loop sets offset to the number of chars of the root
directory we're inspecting. */
while (1)
{
p = strrchr (buf, '/');
if (p == NULL)
/* This should never happen. */
grub_util_error ("FIXME: no / in buf. (make_system_path_relative_to_its_root)");
if (p != buf)
*p = 0;
else
*++p = 0;
if (stat (buf, &st) < 0)
grub_util_error ("cannot stat %s: %s", buf, strerror (errno));
/* buf is another filesystem; we found it. */
if (st.st_dev != num)
{
/* offset == 0 means path given is the mount point.
This works around special-casing of "/" in Un*x. This function never
prints trailing slashes (so that its output can be appended a slash
unconditionally). Each slash in is considered a preceding slash, and
therefore the root directory is an empty string. */
if (offset == 0)
{
free (buf);
free (buf2);
return xstrdup ("");
}
else
break;
}
offset = p - buf;
/* offset == 1 means root directory. */
if (offset == 1)
{
/* Include leading slash. */
offset = 0;
break;
}
}
free (buf);
buf3 = xstrdup (buf2 + offset);
free (buf2);
#ifdef __CYGWIN__
if (st.st_dev != (DEV_CYGDRIVE_MAJOR << 16))
{
/* Reached some mount point not below /cygdrive.
GRUB does not know Cygwin's emulated mounts,
convert to Win32 path. */
grub_util_info ("Cygwin path = %s\n", buf3);
char * temp = get_win32_path (buf3);
free (buf3);
buf3 = temp;
}
#endif
/* Remove trailing slashes, return empty string if root directory. */
len = strlen (buf3);
while (len > 0 && buf3[len - 1] == '/')
{
buf3[len - 1] = '\0';
len--;
}
return buf3;
}

View file

@ -30,6 +30,8 @@
#include <grub/reader.h>
#include <grub/parser.h>
int grub_no_autoload;
void
grub_module_iterate (int (*hook) (struct grub_module_header *header))
{

View file

@ -15,6 +15,8 @@ kernel = {
mips_yeeloong_cppflags = '-DUSE_ASCII_FAILBACK';
i386_qemu_cppflags = '-DGRUB_BOOT_MACHINE_LINK_ADDR=$(GRUB_BOOT_MACHINE_LINK_ADDR)';
i386_qemu_ccasflags = '-DGRUB_KERNEL_MACHINE_LINK_ADDR=$(GRUB_KERNEL_MACHINE_LINK_ADDR)';
emu_cflags = '$(CFLAGS_GNULIB)';
emu_cppflags = '$(CPPFLAGS_GNULIB)';
mips_ldadd = '-lgcc';
powerpc_ldadd = '-lgcc';
@ -187,6 +189,8 @@ kernel = {
sparc64_ieee1275 = disk/ieee1275/ofdisk.c;
sparc64_ieee1275 = term/ieee1275/ofconsole.c;
emu = kern/emu/mm.c;
emu = kern/emu/main.c;
emu = kern/emu/misc.c;
emu = kern/emu/getroot.c;
emu = kern/emu/time.c;
@ -194,6 +198,7 @@ kernel = {
emu = kern/emu/hostfs.c;
emu = kern/emu/console.c;
emu = disk/host.c;
emu = gnulib/progname.c;
image_nostrip = { emu; };
image_strip_keep_kernel = { i386_efi; x86_64_efi; };
@ -205,16 +210,9 @@ program = {
name = grub-emu;
mansection = 1;
source = kern/emu/main.c;
source = kern/emu/dummy/dl.c;
source = kern/emu/dummy/symlist.c;
source = gnulib/progname.c;
source = kern/emu/full.c;
nodist = grub_emu_init.c;
cflags = '$(CFLAGS_GNULIB)';
cppflags = '$(CPPFLAGS_GNULIB)';
ldadd = kernel.exec;
ldadd = '$(MODULE_FILES)';
ldadd = '$(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS)';
@ -225,16 +223,10 @@ program = {
program = {
name = grub-emu-lite;
source = kern/emu/main.c;
source = kern/emu/lite.c;
source = kern/emu/dl.c;
source = kern/emu/cache.S;
source = gnulib/progname.c;
nodist = symlist.c;
cflags = '$(CFLAGS_GNULIB)';
cppflags = '$(CPPFLAGS_GNULIB)';
ldadd = kernel.exec;
ldadd = '$(LIBCURSES) $(LIBSDL) $(LIBUSB) $(LIBPCIACCESS)';

View file

@ -475,12 +475,15 @@ grub_normal_init_page (struct grub_term_output *term)
static void
read_lists (const char *val)
{
if (! grub_no_autoload)
{
read_command_list (val);
read_fs_list (val);
read_crypto_list (val);
read_terminal_list (val);
}
}
static char *
read_lists_hook (struct grub_env_var *var __attribute__ ((unused)),

View file

@ -19,6 +19,7 @@ library = {
source = util/misc.c;
source = grub-core/kern/misc.c;
source = grub-core/kern/emu/mm.c;
source = grub-core/kern/emu/misc.c;
source = grub-core/kern/emu/hostfs.c;
source = grub-core/kern/emu/getroot.c;

View file

@ -17,8 +17,9 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <grub/util/misc.h>
#include <grub/emu/getroot.h>
#include <grub/emu/misc.h>
#include <grub/i18n.h>
#include <getopt.h>

View file

@ -21,6 +21,7 @@
#include <grub/types.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/util/misc.h>
#include <grub/device.h>
#include <grub/disk.h>
#include <grub/file.h>

View file

@ -278,7 +278,34 @@ grub_mm_init_region (void *addr __attribute__ ((unused)),
{
}
#if !(defined (__i386__) || defined (__x86_64__))
void
grub_register_exported_symbols (void)
{
}
#ifdef __MINGW32__
void
grub_millisleep (grub_uint32_t ms)
{
Sleep (ms);
}
#else
void
grub_millisleep (grub_uint32_t ms)
{
struct timespec ts;
ts.tv_sec = ms / 1000;
ts.tv_nsec = (ms % 1000) * 1000000;
nanosleep (&ts, NULL);
}
#endif
#if !(defined (__i386__) || defined (__x86_64__)) && GRUB_MACHINE_EMU
void
grub_arch_sync_caches (void *address __attribute__ ((unused)),
grub_size_t len __attribute__ ((unused)))
@ -286,23 +313,6 @@ grub_arch_sync_caches (void *address __attribute__ ((unused)),
}
#endif
#ifndef HAVE_ASPRINTF
int
asprintf (char **buf, const char *fmt, ...)
{
int status;
va_list ap;
va_start (ap, fmt);
status = vasprintf (*buf, fmt, ap);
va_end (ap);
return status;
}
#endif
#ifdef __MINGW32__
void sync (void)