reorganized grub-emu sources to suite upcoming automake build system

This commit is contained in:
BVK Chaitanya 2010-04-27 10:50:28 +05:30
parent bc4a2d832b
commit 840b61d8f0
20 changed files with 378 additions and 22 deletions

View file

@ -10,11 +10,11 @@ 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/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
@ -49,7 +49,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 +76,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)
@ -106,8 +106,13 @@ ifneq ($(TARGET_NO_MODULES), yes)
grub-emu: $(pkglib_PROGRAMS)
$(CC) -o $@ $(pkglib_PROGRAMS) $(grub_emu_LDFLAGS) $(LDFLAGS)
else
pkglib_MODULES += emu.mod
emu_mod_SOURCES = kern/emu/main.c
emu_mod_CFLAGS = -I$(srcdir)/gnulib
grub-emu: $(pkglib_MODULES) $(pkglib_PROGRAMS)
$(CC) -o $@ $(pkglib_MODULES) $(pkglib_PROGRAMS) $(grub_emu_LDFLAGS) $(LDFLAGS)
$(CC) -o $@ $^ $(grub_emu_LDFLAGS) $(LDFLAGS)
endif
GRUB_EMU=grub-emu

View file

@ -25,7 +25,7 @@ util/elf/grub-mkimage.c_DEPENDENCIES = Makefile
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/getroot.c util/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,7 +60,7 @@ 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 \
grub_fstest_SOURCES = gnulib/progname.c util/grub-fstest.c kern/emu/hostfs.c \
util/misc.c util/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 \

31
include/grub/emu/misc.h Normal file
View file

@ -0,0 +1,31 @@
#ifndef GRUB_EMU_MISC_H
#define GRUB_EMU_MISC_H 1
#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_init_all (void);
void grub_fini_all (void);
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);
char * EXPORT_FUNC(xasprintf) (const char *fmt, ...);
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));
#endif /* GRUB_EMU_MISC_H */

17
kern/emu/cache.S Normal file
View file

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

View file

@ -27,7 +27,7 @@
# define A_STANDOUT 0
#endif /* ! A_STANDOUT */
#include <grub/util/console.h>
#include <grub/emu/console.h>
#include <grub/term.h>
#include <grub/types.h>

51
kern/emu/dummy/dl.c Normal file
View file

@ -0,0 +1,51 @@
/*
* 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/dl.h>
grub_err_t
grub_arch_dl_check_header (void *ehdr)
{
(void) ehdr;
return GRUB_ERR_BAD_MODULE;
}
grub_err_t
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; */
/* } */

View file

@ -22,6 +22,8 @@
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __CYGWIN__
# include <sys/fcntl.h>
@ -36,9 +38,11 @@
#include <hurd/fs.h>
#endif
#include <grub/util/misc.h>
#include <grub/util/hostdisk.h>
#include <grub/util/getroot.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/emu/misc.h>
#include <grub/emu/hostdisk.h>
#include <grub/emu/getroot.h>
static void
strip_extra_slashes (char *dir)

View file

@ -22,8 +22,8 @@
#include <grub/msdos_partition.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/util/misc.h>
#include <grub/util/hostdisk.h>
#include <grub/emu/misc.h>
#include <grub/emu/hostdisk.h>
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/list.h>

16
kern/emu/lite.c Normal file
View file

@ -0,0 +1,16 @@
#include <config.h>
#include <grub/emu/misc.h>
/* grub-emu-lite supports dynamic module loading, so it won't have any
embedded modules. */
void
grub_init_all(void)
{
return;
}
void
grub_fini_all(void)
{
return;
}

View file

@ -16,7 +16,10 @@
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <sys/stat.h>
#include <getopt.h>
#include <string.h>
@ -27,13 +30,13 @@
#include <grub/mm.h>
#include <grub/setjmp.h>
#include <grub/fs.h>
#include <grub/util/hostdisk.h>
#include <grub/dl.h>
#include <grub/util/console.h>
#include <grub/util/misc.h>
#include <grub/emu/hostdisk.h>
#include <grub/time.h>
#include <grub/emu/console.h>
#include <grub/emu/misc.h>
#include <grub/kernel.h>
#include <grub/normal.h>
#include <grub/util/getroot.h>
#include <grub/emu/getroot.h>
#include <grub/env.h>
#include <grub/partition.h>
#include <grub/i18n.h>
@ -261,3 +264,32 @@ main (int argc, char *argv[])
return 0;
}
#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 GRUB_NO_MODULES
void
grub_register_exported_symbols (void)
{
}
#endif

199
kern/emu/misc.c Normal file
View file

@ -0,0 +1,199 @@
#include <config.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <grub/mm.h>
#include <grub/err.h>
#include <grub/env.h>
#include <grub/types.h>
#include <grub/misc.h>
#include <grub/i18n.h>
#include <grub/time.h>
#include <grub/emu/misc.h>
int verbosity;
void
grub_util_warn (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, _("%s: warn:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fprintf (stderr, ".\n");
fflush (stderr);
}
void
grub_util_info (const char *fmt, ...)
{
if (verbosity > 0)
{
va_list ap;
fprintf (stderr, _("%s: info:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fprintf (stderr, ".\n");
fflush (stderr);
}
}
void
grub_util_error (const char *fmt, ...)
{
va_list ap;
fprintf (stderr, _("%s: error:"), program_name);
fprintf (stderr, " ");
va_start (ap, fmt);
vfprintf (stderr, fmt, ap);
va_end (ap);
fprintf (stderr, ".\n");
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);
if (! p)
grub_fatal ("out of memory");
return p;
}
void *
xrealloc (void *ptr, grub_size_t size)
{
ptr = grub_realloc (ptr, size);
if (! ptr)
grub_fatal ("out of memory");
return ptr;
}
char *
xstrdup (const char *str)
{
size_t len;
char *newstr;
len = grub_strlen (str);
newstr = (char *) xmalloc (len + 1);
grub_memcpy (newstr, str, len + 1);
return newstr;
}
char *
xasprintf (const char *fmt, ...)
{
va_list ap;
char *result;
va_start (ap, fmt);
if (vasprintf (&result, fmt, ap) < 0)
{
if (errno == ENOMEM)
grub_util_error ("out of memory");
return NULL;
}
return result;
}
void
grub_exit (void)
{
exit (1);
}
grub_uint64_t
grub_get_time_ms (void)
{
struct timeval tv;
gettimeofday (&tv, 0);
return (tv.tv_sec * 1000 + tv.tv_usec / 1000);
}
grub_uint32_t
grub_get_rtc (void)
{
struct timeval tv;
gettimeofday (&tv, 0);
return (tv.tv_sec * GRUB_TICKS_PER_SECOND
+ (((tv.tv_sec % GRUB_TICKS_PER_SECOND) * 1000000 + tv.tv_usec)
* GRUB_TICKS_PER_SECOND / 1000000));
}

View file

@ -19,6 +19,7 @@
#include <config.h>
#include <grub/types.h>
#include <grub/emu/misc.h>
#include <grub/util/misc.h>
#include <grub/device.h>
#include <grub/disk.h>
@ -26,8 +27,8 @@
#include <grub/fs.h>
#include <grub/partition.h>
#include <grub/msdos_partition.h>
#include <grub/util/hostdisk.h>
#include <grub/util/getroot.h>
#include <grub/emu/hostdisk.h>
#include <grub/emu/getroot.h>
#include <grub/term.h>
#include <grub/env.h>
#include <grub/raid.h>