merge mainline into jail
This commit is contained in:
commit
1b71d7500b
338 changed files with 36948 additions and 4504 deletions
|
@ -135,28 +135,28 @@ grub_device_iterate (int (*hook) (const char *name))
|
|||
|
||||
int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
|
||||
{
|
||||
char *partition_name;
|
||||
struct part_ent *p;
|
||||
|
||||
partition_name = grub_partition_get_name (partition);
|
||||
if (! partition_name)
|
||||
return 1;
|
||||
char *part_name;
|
||||
|
||||
p = grub_malloc (sizeof (*p));
|
||||
if (!p)
|
||||
{
|
||||
grub_free (partition_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p->name = grub_xasprintf ("%s,%s", disk->name, partition_name);
|
||||
if (!p->name)
|
||||
part_name = grub_partition_get_name (partition);
|
||||
if (!part_name)
|
||||
{
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
p->name = grub_xasprintf ("%s,%s", disk->name, part_name);
|
||||
grub_free (part_name);
|
||||
if (!p->name)
|
||||
{
|
||||
grub_free (partition_name);
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
grub_free (partition_name);
|
||||
|
||||
p->next = ents;
|
||||
ents = p;
|
||||
|
|
|
@ -248,10 +248,6 @@ grub_disk_open (const char *name)
|
|||
if (! disk)
|
||||
return 0;
|
||||
|
||||
disk->name = grub_strdup (name);
|
||||
if (! disk->name)
|
||||
goto fail;
|
||||
|
||||
p = find_part_sep (name);
|
||||
if (p)
|
||||
{
|
||||
|
@ -263,7 +259,13 @@ grub_disk_open (const char *name)
|
|||
|
||||
grub_memcpy (raw, name, len);
|
||||
raw[len] = '\0';
|
||||
disk->name = grub_strdup (raw);
|
||||
}
|
||||
else
|
||||
disk->name = grub_strdup (name);
|
||||
if (! disk->name)
|
||||
goto fail;
|
||||
|
||||
|
||||
for (dev = grub_disk_dev_list; dev; dev = dev->next)
|
||||
{
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <config-util.h>
|
||||
|
||||
/* For compatibility. */
|
||||
#ifndef A_NORMAL
|
||||
|
@ -37,6 +38,8 @@
|
|||
# include <ncurses.h>
|
||||
#elif defined(HAVE_CURSES_H)
|
||||
# include <curses.h>
|
||||
#else
|
||||
#error What the hell?
|
||||
#endif
|
||||
|
||||
static int grub_console_attr = A_NORMAL;
|
||||
|
@ -102,63 +105,32 @@ grub_ncurses_setcolorstate (struct grub_term_output *term,
|
|||
}
|
||||
}
|
||||
|
||||
static int saved_char = ERR;
|
||||
|
||||
static int
|
||||
grub_ncurses_checkkey (struct grub_term_input *term __attribute__ ((unused)))
|
||||
{
|
||||
int c;
|
||||
|
||||
/* Check for SAVED_CHAR. This should not be true, because this
|
||||
means checkkey is called twice continuously. */
|
||||
if (saved_char != ERR)
|
||||
return saved_char;
|
||||
|
||||
wtimeout (stdscr, 100);
|
||||
c = getch ();
|
||||
/* If C is not ERR, then put it back in the input queue. */
|
||||
if (c != ERR)
|
||||
{
|
||||
saved_char = c;
|
||||
return c;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
||||
{
|
||||
int c;
|
||||
|
||||
/* If checkkey has already got a character, then return it. */
|
||||
if (saved_char != ERR)
|
||||
{
|
||||
c = saved_char;
|
||||
saved_char = ERR;
|
||||
}
|
||||
else
|
||||
{
|
||||
wtimeout (stdscr, -1);
|
||||
c = getch ();
|
||||
}
|
||||
wtimeout (stdscr, 100);
|
||||
c = getch ();
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case ERR:
|
||||
return -1;
|
||||
case KEY_LEFT:
|
||||
c = GRUB_TERM_LEFT;
|
||||
c = GRUB_TERM_KEY_LEFT;
|
||||
break;
|
||||
|
||||
case KEY_RIGHT:
|
||||
c = GRUB_TERM_RIGHT;
|
||||
c = GRUB_TERM_KEY_RIGHT;
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
c = GRUB_TERM_UP;
|
||||
c = GRUB_TERM_KEY_UP;
|
||||
break;
|
||||
|
||||
case KEY_DOWN:
|
||||
c = GRUB_TERM_DOWN;
|
||||
c = GRUB_TERM_KEY_DOWN;
|
||||
break;
|
||||
|
||||
case KEY_IC:
|
||||
|
@ -166,30 +138,30 @@ grub_ncurses_getkey (struct grub_term_input *term __attribute__ ((unused)))
|
|||
break;
|
||||
|
||||
case KEY_DC:
|
||||
c = GRUB_TERM_DC;
|
||||
c = GRUB_TERM_KEY_DC;
|
||||
break;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
/* XXX: For some reason ncurses on xterm does not return
|
||||
KEY_BACKSPACE. */
|
||||
case 127:
|
||||
c = GRUB_TERM_BACKSPACE;
|
||||
c = '\b';
|
||||
break;
|
||||
|
||||
case KEY_HOME:
|
||||
c = GRUB_TERM_HOME;
|
||||
c = GRUB_TERM_KEY_HOME;
|
||||
break;
|
||||
|
||||
case KEY_END:
|
||||
c = GRUB_TERM_END;
|
||||
c = GRUB_TERM_KEY_END;
|
||||
break;
|
||||
|
||||
case KEY_NPAGE:
|
||||
c = GRUB_TERM_NPAGE;
|
||||
c = GRUB_TERM_KEY_NPAGE;
|
||||
break;
|
||||
|
||||
case KEY_PPAGE:
|
||||
c = GRUB_TERM_PPAGE;
|
||||
c = GRUB_TERM_KEY_PPAGE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -288,7 +260,6 @@ grub_ncurses_fini (struct grub_term_output *term __attribute__ ((unused)))
|
|||
static struct grub_term_input grub_ncurses_term_input =
|
||||
{
|
||||
.name = "console",
|
||||
.checkkey = grub_ncurses_checkkey,
|
||||
.getkey = grub_ncurses_getkey,
|
||||
};
|
||||
|
||||
|
|
|
@ -228,8 +228,8 @@ find_root_device_from_libzfs (const char *dir)
|
|||
|
||||
#ifdef __MINGW32__
|
||||
|
||||
static char *
|
||||
find_root_device (const char *dir __attribute__ ((unused)),
|
||||
char *
|
||||
grub_find_device (const char *dir __attribute__ ((unused)),
|
||||
dev_t dev __attribute__ ((unused)))
|
||||
{
|
||||
return 0;
|
||||
|
@ -237,13 +237,22 @@ find_root_device (const char *dir __attribute__ ((unused)),
|
|||
|
||||
#elif ! defined(__CYGWIN__)
|
||||
|
||||
static char *
|
||||
find_root_device (const char *dir, dev_t dev)
|
||||
char *
|
||||
grub_find_device (const char *dir, dev_t dev)
|
||||
{
|
||||
DIR *dp;
|
||||
char *saved_cwd;
|
||||
struct dirent *ent;
|
||||
|
||||
if (! dir)
|
||||
{
|
||||
#ifdef __CYGWIN__
|
||||
return NULL;
|
||||
#else
|
||||
dir = "/dev";
|
||||
#endif
|
||||
}
|
||||
|
||||
dp = opendir (dir);
|
||||
if (! dp)
|
||||
return 0;
|
||||
|
@ -292,7 +301,7 @@ find_root_device (const char *dir, dev_t dev)
|
|||
/* Find it recursively. */
|
||||
char *res;
|
||||
|
||||
res = find_root_device (ent->d_name, dev);
|
||||
res = grub_find_device (ent->d_name, dev);
|
||||
|
||||
if (res)
|
||||
{
|
||||
|
@ -402,8 +411,8 @@ get_bootsec_serial (const char *os_dev, int mbr)
|
|||
return serial;
|
||||
}
|
||||
|
||||
static char *
|
||||
find_cygwin_root_device (const char *path, dev_t dev)
|
||||
char *
|
||||
grub_find_device (const char *path, dev_t dev)
|
||||
{
|
||||
/* No root device for /cygdrive. */
|
||||
if (dev == (DEV_CYGDRIVE_MAJOR << 16))
|
||||
|
@ -424,7 +433,7 @@ find_cygwin_root_device (const char *path, dev_t dev)
|
|||
|
||||
/* Cygwin returns the partition serial number in stat.st_dev.
|
||||
This is never identical to the device number of the emulated
|
||||
/dev/sdXN device, so above find_root_device () does not work.
|
||||
/dev/sdXN device, so above grub_find_device () does not work.
|
||||
Search the partition with the same serial in boot sector instead. */
|
||||
char devpath[sizeof ("/dev/sda15") + 13]; /* Size + Paranoia. */
|
||||
int d;
|
||||
|
@ -529,12 +538,12 @@ grub_guess_root_device (const char *dir)
|
|||
|
||||
#ifdef __CYGWIN__
|
||||
/* Cygwin specific function. */
|
||||
os_dev = find_cygwin_root_device (dir, st.st_dev);
|
||||
os_dev = grub_find_device (dir, st.st_dev);
|
||||
|
||||
#else
|
||||
|
||||
/* This might be truly slow, but is there any better way? */
|
||||
os_dev = find_root_device ("/dev", st.st_dev);
|
||||
os_dev = grub_find_device ("/dev", st.st_dev);
|
||||
#endif
|
||||
#endif /* !__GNU__ */
|
||||
|
||||
|
|
|
@ -102,9 +102,15 @@ struct hd_geometry
|
|||
# include <libdevmapper.h>
|
||||
#endif
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
# define HAVE_DIOCGDINFO
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/disklabel.h> /* struct disklabel */
|
||||
#else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */
|
||||
# undef HAVE_DIOCGDINFO
|
||||
#endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
|
||||
|
||||
#if defined(__NetBSD__)
|
||||
# ifdef HAVE_GETRAWPARTITION
|
||||
# include <util.h> /* getrawpartition */
|
||||
# endif /* HAVE_GETRAWPARTITION */
|
||||
|
@ -328,17 +334,17 @@ device_is_mapped (const char *dev)
|
|||
}
|
||||
#endif /* HAVE_DEVICE_MAPPER */
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__) || defined(__NetBSD__)
|
||||
#if defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO)
|
||||
static grub_disk_addr_t
|
||||
find_partition_start (const char *dev)
|
||||
{
|
||||
int fd;
|
||||
# if !defined(__NetBSD__)
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
struct hd_geometry hdg;
|
||||
# else /* defined(__NetBSD__) */
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
struct disklabel label;
|
||||
int p_index;
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
|
||||
# ifdef HAVE_DEVICE_MAPPER
|
||||
if (grub_device_mapper_supported () && device_is_mapped (dev)) {
|
||||
|
@ -412,36 +418,38 @@ devmapper_fail:
|
|||
if (fd == -1)
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
# if !defined(__NetBSD__)
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
"cannot open `%s' while attempting to get disk geometry", dev);
|
||||
# else /* defined(__NetBSD__) */
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
"cannot open `%s' while attempting to get disk label", dev);
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
return 0;
|
||||
}
|
||||
|
||||
# if !defined(__NetBSD__)
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
if (ioctl (fd, HDIO_GETGEO, &hdg))
|
||||
# else /* defined(__NetBSD__) */
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
# if defined(__NetBSD__)
|
||||
configure_device_driver (fd);
|
||||
# endif /* defined(__NetBSD__) */
|
||||
if (ioctl (fd, DIOCGDINFO, &label) == -1)
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
{
|
||||
grub_error (GRUB_ERR_BAD_DEVICE,
|
||||
# if !defined(__NetBSD__)
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
"cannot get disk geometry of `%s'", dev);
|
||||
# else /* defined(__NetBSD__) */
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
"cannot get disk label of `%s'", dev);
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
close (fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
# if !defined(__NetBSD__)
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
return hdg.start;
|
||||
# else /* defined(__NetBSD__) */
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
p_index = dev[strlen(dev) - 1] - 'a';
|
||||
|
||||
if (p_index >= label.d_npartitions)
|
||||
|
@ -451,9 +459,9 @@ devmapper_fail:
|
|||
return 0;
|
||||
}
|
||||
return (grub_disk_addr_t) label.d_partitions[p_index].p_offset;
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
}
|
||||
#endif /* __linux__ || __CYGWIN__ */
|
||||
#endif /* __linux__ || __CYGWIN__ || HAVE_DIOCGDINFO */
|
||||
|
||||
#ifdef __linux__
|
||||
/* Cache of partition start sectors for each disk. */
|
||||
|
@ -955,13 +963,16 @@ read_device_map (const char *dev_map)
|
|||
#ifdef __linux__
|
||||
/* On Linux, the devfs uses symbolic links horribly, and that
|
||||
confuses the interface very much, so use realpath to expand
|
||||
symbolic links. */
|
||||
map[drive].device = xmalloc (PATH_MAX);
|
||||
if (! realpath (p, map[drive].device))
|
||||
grub_util_error ("cannot get the real path of `%s'", p);
|
||||
#else
|
||||
map[drive].device = xstrdup (p);
|
||||
symbolic links. Leave /dev/mapper/ alone, though. */
|
||||
if (strncmp (p, "/dev/mapper/", 12) != 0)
|
||||
{
|
||||
map[drive].device = xmalloc (PATH_MAX);
|
||||
if (! realpath (p, map[drive].device))
|
||||
grub_util_error ("cannot get the real path of `%s'", p);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
map[drive].device = xstrdup (p);
|
||||
}
|
||||
|
||||
fclose (fp);
|
||||
|
@ -993,8 +1004,7 @@ grub_util_biosdisk_fini (void)
|
|||
|
||||
/*
|
||||
* Note: we do not use the new partition naming scheme as dos_part does not
|
||||
* necessarily correspond to an msdos partition. See e.g. the FreeBSD code
|
||||
* in function grub_util_biosdisk_get_grub_dev.
|
||||
* necessarily correspond to an msdos partition.
|
||||
*/
|
||||
static char *
|
||||
make_device_name (int drive, int dos_part, int bsd_part)
|
||||
|
@ -1153,22 +1163,22 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
|
|||
}
|
||||
|
||||
#ifdef HAVE_DEVICE_MAPPER
|
||||
/* If this is a DM-RAID device. */
|
||||
if ((strncmp ("mapper/", p, 7) == 0))
|
||||
/* If this is a DM-RAID device.
|
||||
Compare os_dev rather than path here, since nodes under
|
||||
/dev/mapper/ are often symlinks. */
|
||||
if ((strncmp ("/dev/mapper/", os_dev, 12) == 0))
|
||||
{
|
||||
static struct dm_tree *tree = NULL;
|
||||
struct dm_tree *tree;
|
||||
uint32_t maj, min;
|
||||
struct dm_tree_node *node, *child;
|
||||
struct dm_tree_node *node = NULL, *child;
|
||||
void *handle;
|
||||
const char *node_uuid, *mapper_name, *child_uuid, *child_name;
|
||||
|
||||
if (! tree)
|
||||
tree = dm_tree_create ();
|
||||
const char *node_uuid, *mapper_name = NULL, *child_uuid, *child_name;
|
||||
|
||||
tree = dm_tree_create ();
|
||||
if (! tree)
|
||||
{
|
||||
grub_dprintf ("hostdisk", "dm_tree_create failed\n");
|
||||
return NULL;
|
||||
goto devmapper_out;
|
||||
}
|
||||
|
||||
maj = major (st->st_rdev);
|
||||
|
@ -1176,29 +1186,30 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
|
|||
if (! dm_tree_add_dev (tree, maj, min))
|
||||
{
|
||||
grub_dprintf ("hostdisk", "dm_tree_add_dev failed\n");
|
||||
return NULL;
|
||||
goto devmapper_out;
|
||||
}
|
||||
|
||||
node = dm_tree_find_node (tree, maj, min);
|
||||
if (! node)
|
||||
{
|
||||
grub_dprintf ("hostdisk", "dm_tree_find_node failed\n");
|
||||
return NULL;
|
||||
goto devmapper_out;
|
||||
}
|
||||
node_uuid = dm_tree_node_get_uuid (node);
|
||||
if (! node_uuid)
|
||||
{
|
||||
grub_dprintf ("hostdisk", "%s has no DM uuid\n", path);
|
||||
return NULL;
|
||||
node = NULL;
|
||||
goto devmapper_out;
|
||||
}
|
||||
else if (strncmp (node_uuid, "DMRAID-", 7) != 0)
|
||||
{
|
||||
grub_dprintf ("hostdisk", "%s is not DM-RAID\n", path);
|
||||
return NULL;
|
||||
node = NULL;
|
||||
goto devmapper_out;
|
||||
}
|
||||
|
||||
handle = NULL;
|
||||
mapper_name = NULL;
|
||||
/* Counter-intuitively, device-mapper refers to the disk-like
|
||||
device containing a DM-RAID partition device as a "child" of
|
||||
the partition device. */
|
||||
|
@ -1228,17 +1239,20 @@ convert_system_partition_to_system_disk (const char *os_dev, struct stat *st)
|
|||
mapper_name = child_name;
|
||||
|
||||
devmapper_out:
|
||||
if (! mapper_name)
|
||||
if (! mapper_name && node)
|
||||
{
|
||||
/* This is a DM-RAID disk, not a partition. */
|
||||
mapper_name = dm_tree_node_get_name (node);
|
||||
if (! mapper_name)
|
||||
{
|
||||
grub_dprintf ("hostdisk", "%s has no DM name\n", path);
|
||||
return NULL;
|
||||
}
|
||||
grub_dprintf ("hostdisk", "%s has no DM name\n", path);
|
||||
}
|
||||
return xasprintf ("/dev/mapper/%s", mapper_name);
|
||||
if (tree)
|
||||
dm_tree_free (tree);
|
||||
free (path);
|
||||
if (mapper_name)
|
||||
return xasprintf ("/dev/mapper/%s", mapper_name);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
#endif /* HAVE_DEVICE_MAPPER */
|
||||
}
|
||||
|
@ -1342,6 +1356,27 @@ device_is_wholedisk (const char *os_dev)
|
|||
}
|
||||
#endif /* defined(__NetBSD__) */
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
static int
|
||||
device_is_wholedisk (const char *os_dev)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (strncmp (os_dev, "/dev/", sizeof ("/dev/") - 1) != 0)
|
||||
return 0;
|
||||
|
||||
for (p = os_dev + sizeof ("/dev/") - 1; *p; ++p)
|
||||
if (grub_isdigit (*p))
|
||||
{
|
||||
if (strchr (p, 's'))
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif /* defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
|
||||
|
||||
static int
|
||||
find_system_device (const char *os_dev, struct stat *st, int add)
|
||||
{
|
||||
|
@ -1415,7 +1450,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
#endif
|
||||
return make_device_name (drive, -1, -1);
|
||||
|
||||
#if defined(__linux__) || defined(__CYGWIN__) || defined(__NetBSD__)
|
||||
#if defined(__linux__) || defined(__CYGWIN__) || defined(HAVE_DIOCGDINFO)
|
||||
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
|
||||
partition, so mapping them to GRUB devices is not trivial.
|
||||
Here, get the start sector of a partition by HDIO_GETGEO, and
|
||||
|
@ -1425,8 +1460,8 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
does not count the extended partition and missing primary
|
||||
partitions. Use same method as on Linux here.
|
||||
|
||||
For NetBSD, proceed as for Linux, except that the start sector is
|
||||
obtained from the disk label. */
|
||||
For NetBSD and FreeBSD, proceed as for Linux, except that the start
|
||||
sector is obtained from the disk label. */
|
||||
{
|
||||
char *name, *partname;
|
||||
grub_disk_t disk;
|
||||
|
@ -1454,13 +1489,13 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
|
||||
name = make_device_name (drive, -1, -1);
|
||||
|
||||
# if !defined(__NetBSD__)
|
||||
# if !defined(HAVE_DIOCGDINFO)
|
||||
if (MAJOR (st.st_rdev) == FLOPPY_MAJOR)
|
||||
return name;
|
||||
# else /* defined(__NetBSD__) */
|
||||
# else /* defined(HAVE_DIOCGDINFO) */
|
||||
/* Since os_dev and convert_system_partition_to_system_disk (os_dev) are
|
||||
* different, we know that os_dev cannot be a floppy device. */
|
||||
# endif /* !defined(__NetBSD__) */
|
||||
# endif /* !defined(HAVE_DIOCGDINFO) */
|
||||
|
||||
start = find_partition_start (os_dev);
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
|
@ -1529,41 +1564,6 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
|
|||
return make_device_name (drive, dos_part, bsd_part);
|
||||
}
|
||||
|
||||
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__)
|
||||
/* FreeBSD uses "/dev/[a-z]+[0-9]+([sp][0-9]+[a-z]?)?". */
|
||||
{
|
||||
int dos_part = -1;
|
||||
int bsd_part = -1;
|
||||
|
||||
if (strncmp ("/dev/", os_dev, 5) == 0)
|
||||
{
|
||||
const char *p;
|
||||
char *q;
|
||||
long int n;
|
||||
|
||||
for (p = os_dev + 5; *p; ++p)
|
||||
if (grub_isdigit(*p))
|
||||
{
|
||||
p = strpbrk (p, "sp"); /* msdos or apple (or ... ?) partition map */
|
||||
if (p)
|
||||
{
|
||||
p++;
|
||||
n = strtol (p, &q, 10);
|
||||
if (p != q && n != GRUB_LONG_MIN && n != GRUB_LONG_MAX)
|
||||
{
|
||||
dos_part = (int) n - 1;
|
||||
|
||||
if (*q >= 'a' && *q <= 'g')
|
||||
bsd_part = *q - 'a';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return make_device_name (drive, dos_part, bsd_part);
|
||||
}
|
||||
|
||||
#else
|
||||
# warning "The function `grub_util_biosdisk_get_grub_dev' might not work on your OS correctly."
|
||||
return make_device_name (drive, -1, -1);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config-util.h>
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -160,7 +161,7 @@ vasprintf (char **buf, const char *fmt, va_list ap)
|
|||
/* Should be large enough. */
|
||||
*buf = xmalloc (512);
|
||||
|
||||
return vsprintf (*buf, fmt, ap);
|
||||
return vsnprintf (*buf, 512, fmt, ap);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -174,7 +175,7 @@ asprintf (char **buf, const char *fmt, ...)
|
|||
va_list ap;
|
||||
|
||||
va_start (ap, fmt);
|
||||
status = vasprintf (*buf, fmt, ap);
|
||||
status = vasprintf (buf, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return status;
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config-util.h>
|
||||
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
grub_err_t grub_errno;
|
||||
char grub_errmsg[GRUB_MAX_ERRMSG];
|
||||
int grub_err_printed_errors;
|
||||
|
||||
static struct
|
||||
{
|
||||
|
@ -122,7 +123,10 @@ grub_print_error (void)
|
|||
do
|
||||
{
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
grub_err_printf (_("error: %s.\n"), grub_errmsg);
|
||||
{
|
||||
grub_err_printf (_("error: %s.\n"), grub_errmsg);
|
||||
grub_err_printed_errors++;
|
||||
}
|
||||
}
|
||||
while (grub_error_pop ());
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <grub/machine/time.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
|
@ -64,8 +65,10 @@ grub_machine_init (void)
|
|||
/* Initialize the console as early as possible. */
|
||||
grub_vga_text_init ();
|
||||
|
||||
auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t, grub_uint64_t, grub_uint32_t);
|
||||
int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
|
||||
auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t, grub_uint64_t,
|
||||
grub_memory_type_t);
|
||||
int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t size,
|
||||
grub_memory_type_t type)
|
||||
{
|
||||
#if GRUB_CPU_SIZEOF_VOID_P == 4
|
||||
/* Restrict ourselves to 32-bit memory space. */
|
||||
|
@ -75,7 +78,7 @@ grub_machine_init (void)
|
|||
size = GRUB_ULONG_MAX - addr;
|
||||
#endif
|
||||
|
||||
if (type != GRUB_MACHINE_MEMORY_AVAILABLE)
|
||||
if (type != GRUB_MEMORY_AVAILABLE)
|
||||
return 0;
|
||||
|
||||
/* Avoid the lower memory. */
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/lbio.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
|
@ -74,7 +75,7 @@ signature_found:
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
mem_region_t mem_region;
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
/* For stack parameters. */
|
||||
#include <grub/i386/pc/memory.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/cpu/linux.h>
|
||||
#include <grub/offsets.h>
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/cpu/linux.h>
|
||||
#include <multiboot.h>
|
||||
#include <multiboot2.h>
|
||||
|
|
|
@ -22,8 +22,6 @@
|
|||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
grub_size_t grub_lower_mem, grub_upper_mem;
|
||||
|
||||
/* A pointer to the MBI in its initial location. */
|
||||
struct multiboot_info *startup_multiboot_info;
|
||||
|
||||
|
@ -56,21 +54,10 @@ grub_machine_mmap_init ()
|
|||
}
|
||||
grub_memmove (mmap_entries, (void *) kern_multiboot_info.mmap_addr, kern_multiboot_info.mmap_length);
|
||||
kern_multiboot_info.mmap_addr = (grub_uint32_t) mmap_entries;
|
||||
|
||||
if ((kern_multiboot_info.flags & MULTIBOOT_INFO_MEMORY) == 0)
|
||||
{
|
||||
grub_lower_mem = GRUB_MEMORY_MACHINE_LOWER_USABLE;
|
||||
grub_upper_mem = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
grub_lower_mem = kern_multiboot_info.mem_lower * 1024;
|
||||
grub_upper_mem = kern_multiboot_info.mem_upper * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
struct multiboot_mmap_entry *entry = (void *) kern_multiboot_info.mmap_addr;
|
||||
|
||||
|
|
|
@ -181,8 +181,10 @@ grub_machine_init (void)
|
|||
grub_lower_mem - GRUB_MEMORY_MACHINE_RESERVED_END);
|
||||
#endif
|
||||
|
||||
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t, grub_uint32_t);
|
||||
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, grub_uint32_t type)
|
||||
auto int NESTED_FUNC_ATTR hook (grub_uint64_t, grub_uint64_t,
|
||||
grub_memory_type_t);
|
||||
int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size,
|
||||
grub_memory_type_t type)
|
||||
{
|
||||
/* Avoid the lower memory. */
|
||||
if (addr < 0x100000)
|
||||
|
@ -195,7 +197,7 @@ grub_machine_init (void)
|
|||
}
|
||||
|
||||
/* Ignore >4GB. */
|
||||
if (addr <= 0xFFFFFFFF && type == GRUB_MACHINE_MEMORY_AVAILABLE)
|
||||
if (addr <= 0xFFFFFFFF && type == GRUB_MEMORY_AVAILABLE)
|
||||
{
|
||||
grub_size_t len;
|
||||
|
||||
|
|
|
@ -22,6 +22,20 @@
|
|||
#include <grub/types.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
struct grub_machine_mmap_entry
|
||||
{
|
||||
grub_uint32_t size;
|
||||
grub_uint64_t addr;
|
||||
grub_uint64_t len;
|
||||
#define GRUB_MACHINE_MEMORY_AVAILABLE 1
|
||||
#define GRUB_MACHINE_MEMORY_RESERVED 2
|
||||
#define GRUB_MACHINE_MEMORY_ACPI 3
|
||||
#define GRUB_MACHINE_MEMORY_NVS 4
|
||||
#define GRUB_MACHINE_MEMORY_BADRAM 5
|
||||
grub_uint32_t type;
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/*
|
||||
* grub_get_ext_memsize() : return the extended memory size in KB.
|
||||
* BIOS call "INT 15H, AH=88H" to get extended memory size
|
||||
|
@ -109,7 +123,7 @@ grub_get_mmap_entry (struct grub_machine_mmap_entry *entry,
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
grub_uint32_t cont;
|
||||
struct grub_machine_mmap_entry *entry
|
||||
|
@ -124,9 +138,9 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uin
|
|||
do
|
||||
{
|
||||
if (hook (entry->addr, entry->len,
|
||||
/* Multiboot mmaps have been defined to match with the E820 definition.
|
||||
/* GRUB mmaps have been defined to match with the E820 definition.
|
||||
Therefore, we can just pass type through. */
|
||||
entry->type))
|
||||
((entry->type <= GRUB_MACHINE_MEMORY_BADRAM) && (entry->type >= GRUB_MACHINE_MEMORY_AVAILABLE)) ? entry->type : GRUB_MEMORY_RESERVED))
|
||||
break;
|
||||
|
||||
if (! cont)
|
||||
|
@ -143,11 +157,12 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uin
|
|||
|
||||
if (eisa_mmap)
|
||||
{
|
||||
if (hook (0x100000, (eisa_mmap & 0xFFFF) << 10, GRUB_MACHINE_MEMORY_AVAILABLE) == 0)
|
||||
hook (0x1000000, eisa_mmap & ~0xFFFF, GRUB_MACHINE_MEMORY_AVAILABLE);
|
||||
if (hook (0x100000, (eisa_mmap & 0xFFFF) << 10,
|
||||
GRUB_MEMORY_AVAILABLE) == 0)
|
||||
hook (0x1000000, eisa_mmap & ~0xFFFF, GRUB_MEMORY_AVAILABLE);
|
||||
}
|
||||
else
|
||||
hook (0x100000, grub_get_ext_memsize () << 10, GRUB_MACHINE_MEMORY_AVAILABLE);
|
||||
hook (0x100000, grub_get_ext_memsize () << 10, GRUB_MEMORY_AVAILABLE);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -576,62 +576,29 @@ FUNCTION(grub_console_putchar)
|
|||
ret
|
||||
|
||||
|
||||
LOCAL(bypass_table):
|
||||
.word 0x0100 | '\e',0x0f00 | '\t', 0x0e00 | '\b', 0x1c00 | '\r'
|
||||
.word 0x1c00 | '\n'
|
||||
LOCAL(bypass_table_end):
|
||||
|
||||
/*
|
||||
* int grub_console_getkey (void)
|
||||
* if there is a character pending, return it; otherwise return -1
|
||||
* BIOS call "INT 16H Function 01H" to check whether a character is pending
|
||||
* Call with %ah = 0x1
|
||||
* Return:
|
||||
* If key waiting to be input:
|
||||
* %ah = keyboard scan code
|
||||
* %al = ASCII character
|
||||
* Zero flag = clear
|
||||
* else
|
||||
* Zero flag = set
|
||||
* BIOS call "INT 16H Function 00H" to read character from keyboard
|
||||
* Call with %ah = 0x0
|
||||
* Return: %ah = keyboard scan code
|
||||
* %al = ASCII character
|
||||
*/
|
||||
|
||||
/* this table is used in translate_keycode below */
|
||||
LOCAL (translation_table):
|
||||
.word GRUB_CONSOLE_KEY_LEFT, GRUB_TERM_LEFT
|
||||
.word GRUB_CONSOLE_KEY_RIGHT, GRUB_TERM_RIGHT
|
||||
.word GRUB_CONSOLE_KEY_UP, GRUB_TERM_UP
|
||||
.word GRUB_CONSOLE_KEY_DOWN, GRUB_TERM_DOWN
|
||||
.word GRUB_CONSOLE_KEY_HOME, GRUB_TERM_HOME
|
||||
.word GRUB_CONSOLE_KEY_END, GRUB_TERM_END
|
||||
.word GRUB_CONSOLE_KEY_DC, GRUB_TERM_DC
|
||||
.word GRUB_CONSOLE_KEY_BACKSPACE, GRUB_TERM_BACKSPACE
|
||||
.word GRUB_CONSOLE_KEY_PPAGE, GRUB_TERM_PPAGE
|
||||
.word GRUB_CONSOLE_KEY_NPAGE, GRUB_TERM_NPAGE
|
||||
.word 0
|
||||
|
||||
/*
|
||||
* translate_keycode translates the key code %dx to an ascii code.
|
||||
*/
|
||||
.code16
|
||||
|
||||
translate_keycode:
|
||||
pushw %bx
|
||||
pushw %si
|
||||
|
||||
#ifdef __APPLE__
|
||||
movw $(ABS(LOCAL (translation_table)) - 0x10000), %si
|
||||
#else
|
||||
movw $ABS(LOCAL (translation_table)), %si
|
||||
#endif
|
||||
|
||||
1: lodsw
|
||||
/* check if this is the end */
|
||||
testw %ax, %ax
|
||||
jz 2f
|
||||
/* load the ascii code into %ax */
|
||||
movw %ax, %bx
|
||||
lodsw
|
||||
/* check if this matches the key code */
|
||||
cmpw %bx, %dx
|
||||
jne 1b
|
||||
/* translate %dx, if successful */
|
||||
movw %ax, %dx
|
||||
|
||||
2: popw %si
|
||||
popw %bx
|
||||
ret
|
||||
|
||||
.code32
|
||||
|
||||
FUNCTION(grub_console_getkey)
|
||||
pushl %ebp
|
||||
|
||||
|
@ -645,70 +612,54 @@ FUNCTION(grub_console_getkey)
|
|||
* INT 16/AH = 1 before calling INT 16/AH = 0.
|
||||
*/
|
||||
|
||||
1:
|
||||
movb $1, %ah
|
||||
int $0x16
|
||||
jnz 2f
|
||||
hlt
|
||||
jmp 1b
|
||||
|
||||
2:
|
||||
jz notpending
|
||||
|
||||
movb $0, %ah
|
||||
int $0x16
|
||||
|
||||
xorl %edx, %edx
|
||||
movw %ax, %dx /* real_to_prot uses %eax */
|
||||
call translate_keycode
|
||||
|
||||
DATA32 call real_to_prot
|
||||
.code32
|
||||
|
||||
movw %dx, %ax
|
||||
|
||||
popl %ebp
|
||||
ret
|
||||
|
||||
|
||||
/*
|
||||
* int grub_console_checkkey (void)
|
||||
* if there is a character pending, return it; otherwise return -1
|
||||
* BIOS call "INT 16H Function 01H" to check whether a character is pending
|
||||
* Call with %ah = 0x1
|
||||
* Return:
|
||||
* If key waiting to be input:
|
||||
* %ah = keyboard scan code
|
||||
* %al = ASCII character
|
||||
* Zero flag = clear
|
||||
* else
|
||||
* Zero flag = set
|
||||
*/
|
||||
FUNCTION(grub_console_checkkey)
|
||||
pushl %ebp
|
||||
xorl %edx, %edx
|
||||
|
||||
call prot_to_real /* enter real mode */
|
||||
.code16
|
||||
|
||||
movb $0x1, %ah
|
||||
int $0x16
|
||||
|
||||
jz notpending
|
||||
|
||||
movw %ax, %dx
|
||||
DATA32 jmp pending
|
||||
|
||||
notpending:
|
||||
decl %edx
|
||||
|
||||
pending:
|
||||
DATA32 call real_to_prot
|
||||
.code32
|
||||
movl $0xff, %eax
|
||||
testl %eax, %edx
|
||||
jz 1f
|
||||
|
||||
andl %edx, %eax
|
||||
cmp %eax, 0x20
|
||||
ja 2f
|
||||
movl %edx, %eax
|
||||
leal LOCAL(bypass_table), %esi
|
||||
movl $((LOCAL(bypass_table_end) - LOCAL(bypass_table)) / 2), %ecx
|
||||
repne cmpsw
|
||||
jz 3f
|
||||
|
||||
addl $('a' - 1 | GRUB_TERM_CTRL), %eax
|
||||
jmp 2f
|
||||
3:
|
||||
andl $0xff, %eax
|
||||
jmp 2f
|
||||
|
||||
1: movl %edx, %eax
|
||||
shrl $8, %eax
|
||||
orl $GRUB_TERM_EXTENDED, %eax
|
||||
2:
|
||||
popl %ebp
|
||||
ret
|
||||
|
||||
notpending:
|
||||
.code16
|
||||
DATA32 call real_to_prot
|
||||
.code32
|
||||
#if GRUB_TERM_NO_KEY != 0
|
||||
#error Fix this asm code
|
||||
#endif
|
||||
jmp 2b
|
||||
|
||||
|
||||
/*
|
||||
* grub_uint16_t grub_console_getxy (void)
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/i386/memory.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/cmos.h>
|
||||
#include <grub/offsets.h>
|
||||
|
||||
#define QEMU_CMOS_MEMSIZE_HIGH 0x35
|
||||
#define QEMU_CMOS_MEMSIZE_LOW 0x34
|
||||
|
@ -60,38 +62,38 @@ grub_machine_mmap_init ()
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
if (hook (0x0,
|
||||
(grub_addr_t) _start,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE))
|
||||
GRUB_MEMORY_AVAILABLE))
|
||||
return 1;
|
||||
|
||||
if (hook ((grub_addr_t) _end,
|
||||
0xa0000 - (grub_addr_t) _end,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE))
|
||||
GRUB_MEMORY_AVAILABLE))
|
||||
return 1;
|
||||
|
||||
if (hook (GRUB_MEMORY_MACHINE_UPPER,
|
||||
0x100000 - GRUB_MEMORY_MACHINE_UPPER,
|
||||
GRUB_MACHINE_MEMORY_RESERVED))
|
||||
GRUB_MEMORY_RESERVED))
|
||||
return 1;
|
||||
|
||||
/* Everything else is free. */
|
||||
if (hook (0x100000,
|
||||
min (mem_size, (grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE) - 0x100000,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE))
|
||||
GRUB_MEMORY_AVAILABLE))
|
||||
return 1;
|
||||
|
||||
/* Protect boot.img, which contains the gdt. It is mapped at the top of memory
|
||||
(it is also mapped below 0x100000, but we already reserved that area). */
|
||||
if (hook ((grub_uint32_t) -GRUB_BOOT_MACHINE_SIZE,
|
||||
GRUB_BOOT_MACHINE_SIZE,
|
||||
GRUB_MACHINE_MEMORY_RESERVED))
|
||||
GRUB_MEMORY_RESERVED))
|
||||
return 1;
|
||||
|
||||
if (above_4g != 0 && hook (0x100000000ULL, above_4g,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE))
|
||||
GRUB_MEMORY_AVAILABLE))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
#include <config.h>
|
||||
#include <grub/symbol.h>
|
||||
|
||||
#include <grub/i386/pc/memory.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <grub/ieee1275/ofdisk.h>
|
||||
#include <grub/ieee1275/ieee1275.h>
|
||||
#include <grub/offsets.h>
|
||||
#include <grub/memory.h>
|
||||
|
||||
/* The minimal heap size we can live with. */
|
||||
#define HEAP_MIN_SIZE (unsigned long) (2 * 1024 * 1024)
|
||||
|
@ -126,8 +127,10 @@ static void grub_claim_heap (void)
|
|||
{
|
||||
unsigned long total = 0;
|
||||
|
||||
auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type);
|
||||
int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type)
|
||||
auto int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len,
|
||||
grub_memory_type_t type);
|
||||
int NESTED_FUNC_ATTR heap_init (grub_uint64_t addr, grub_uint64_t len,
|
||||
grub_memory_type_t type)
|
||||
{
|
||||
if (type != 1)
|
||||
return 0;
|
||||
|
@ -189,31 +192,6 @@ static void grub_claim_heap (void)
|
|||
grub_machine_mmap_iterate (heap_init);
|
||||
}
|
||||
|
||||
#ifdef __i386__
|
||||
|
||||
grub_uint32_t grub_upper_mem;
|
||||
|
||||
/* We need to call this before grub_claim_memory. */
|
||||
static void
|
||||
grub_get_extended_memory (void)
|
||||
{
|
||||
auto int NESTED_FUNC_ATTR find_ext_mem (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type);
|
||||
int NESTED_FUNC_ATTR find_ext_mem (grub_uint64_t addr, grub_uint64_t len, grub_uint32_t type)
|
||||
{
|
||||
if (type == 1 && addr == 0x100000)
|
||||
{
|
||||
grub_upper_mem = len;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
grub_machine_mmap_iterate (find_ext_mem);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static grub_uint64_t ieee1275_get_time_ms (void);
|
||||
|
||||
void
|
||||
|
@ -225,9 +203,6 @@ grub_machine_init (void)
|
|||
grub_ieee1275_init ();
|
||||
|
||||
grub_console_init_early ();
|
||||
#ifdef __i386__
|
||||
grub_get_extended_memory ();
|
||||
#endif
|
||||
grub_claim_heap ();
|
||||
grub_console_init_lately ();
|
||||
grub_ofdisk_init ();
|
||||
|
|
|
@ -16,12 +16,12 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/ieee1275/ieee1275.h>
|
||||
#include <grub/types.h>
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uint64_t, grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
grub_ieee1275_phandle_t root;
|
||||
grub_ieee1275_phandle_t memory;
|
||||
|
@ -66,7 +66,7 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t, grub_uin
|
|||
if (size_cells == 2)
|
||||
size = (size << 32) | available[i++];
|
||||
|
||||
if (hook (address, size, GRUB_MACHINE_MEMORY_AVAILABLE))
|
||||
if (hook (address, size, GRUB_MEMORY_AVAILABLE))
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,11 +51,8 @@ grub_reboot (void)
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
|
||||
grub_uint64_t,
|
||||
grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
hook (0, RAMSIZE,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE);
|
||||
hook (0, RAMSIZE, GRUB_MEMORY_AVAILABLE);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <grub/time.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/memory.h>
|
||||
#include <grub/mips/loongson.h>
|
||||
#include <grub/cs5536.h>
|
||||
#include <grub/term.h>
|
||||
|
@ -39,6 +40,7 @@ extern void grub_gfxterm_init (void);
|
|||
extern void grub_at_keyboard_init (void);
|
||||
extern void grub_serial_init (void);
|
||||
extern void grub_terminfo_init (void);
|
||||
extern void grub_keylayouts_init (void);
|
||||
|
||||
/* FIXME: use interrupt to count high. */
|
||||
grub_uint64_t
|
||||
|
@ -57,14 +59,12 @@ grub_get_rtc (void)
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
|
||||
grub_uint64_t,
|
||||
grub_uint32_t))
|
||||
grub_machine_mmap_iterate (grub_memory_hook_t hook)
|
||||
{
|
||||
hook (GRUB_ARCH_LOWMEMPSTART, grub_arch_memsize << 20,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE);
|
||||
GRUB_MEMORY_AVAILABLE);
|
||||
hook (GRUB_ARCH_HIGHMEMPSTART, grub_arch_highmemsize << 20,
|
||||
GRUB_MACHINE_MEMORY_AVAILABLE);
|
||||
GRUB_MEMORY_AVAILABLE);
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
@ -205,6 +205,7 @@ grub_machine_init (void)
|
|||
grub_font_init ();
|
||||
grub_gfxterm_init ();
|
||||
|
||||
grub_keylayouts_init ();
|
||||
grub_at_keyboard_init ();
|
||||
|
||||
grub_terminfo_init ();
|
||||
|
|
|
@ -999,7 +999,7 @@ grub_abort (void)
|
|||
void abort (void) __attribute__ ((alias ("grub_abort")));
|
||||
#endif
|
||||
|
||||
#if defined(NEED_ENABLE_EXECUTE_STACK) && !defined(GRUB_UTIL) && !defined(GRUB_MACHINE_EMU)
|
||||
#if NEED_ENABLE_EXECUTE_STACK && !defined(GRUB_UTIL) && !defined(GRUB_MACHINE_EMU)
|
||||
/* Some gcc versions generate a call to this function
|
||||
in trampolines for nested functions. */
|
||||
void __enable_execute_stack (void *addr __attribute__ ((unused)))
|
||||
|
@ -1007,7 +1007,7 @@ void __enable_execute_stack (void *addr __attribute__ ((unused)))
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined (NEED_REGISTER_FRAME_INFO) && !defined(GRUB_UTIL)
|
||||
#if NEED_REGISTER_FRAME_INFO && !defined(GRUB_UTIL)
|
||||
void __register_frame_info (void)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ grub_rescue_read_line (char **line, int cont)
|
|||
grub_printf ((cont) ? "> " : "grub rescue> ");
|
||||
grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
|
||||
|
||||
while ((c = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && c != '\r')
|
||||
while ((c = grub_getkey ()) != '\n' && c != '\r')
|
||||
{
|
||||
if (grub_isprint (c))
|
||||
{
|
||||
|
|
|
@ -78,65 +78,48 @@ grub_xputs_dumb (const char *str)
|
|||
|
||||
void (*grub_xputs) (const char *str) = grub_xputs_dumb;
|
||||
|
||||
int
|
||||
grub_getkey (void)
|
||||
{
|
||||
grub_term_input_t term;
|
||||
|
||||
grub_refresh ();
|
||||
|
||||
while (1)
|
||||
{
|
||||
if (grub_term_poll_usb)
|
||||
grub_term_poll_usb ();
|
||||
|
||||
FOR_ACTIVE_TERM_INPUTS(term)
|
||||
{
|
||||
int key = term->checkkey (term);
|
||||
if (key != -1)
|
||||
return term->getkey (term);
|
||||
}
|
||||
|
||||
grub_cpu_idle ();
|
||||
}
|
||||
}
|
||||
static int pending_key = GRUB_TERM_NO_KEY;
|
||||
|
||||
int
|
||||
grub_checkkey (void)
|
||||
{
|
||||
grub_term_input_t term;
|
||||
|
||||
if (pending_key != GRUB_TERM_NO_KEY)
|
||||
return pending_key;
|
||||
|
||||
if (grub_term_poll_usb)
|
||||
grub_term_poll_usb ();
|
||||
|
||||
FOR_ACTIVE_TERM_INPUTS(term)
|
||||
{
|
||||
int key = term->checkkey (term);
|
||||
if (key != -1)
|
||||
return key;
|
||||
pending_key = term->getkey (term);
|
||||
if (pending_key != GRUB_TERM_NO_KEY)
|
||||
return pending_key;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
grub_getkeystatus (void)
|
||||
grub_getkey (void)
|
||||
{
|
||||
int status = 0;
|
||||
grub_term_input_t term;
|
||||
int ret;
|
||||
|
||||
if (grub_term_poll_usb)
|
||||
grub_term_poll_usb ();
|
||||
grub_refresh ();
|
||||
|
||||
FOR_ACTIVE_TERM_INPUTS(term)
|
||||
{
|
||||
if (term->getkeystatus)
|
||||
status |= term->getkeystatus (term);
|
||||
}
|
||||
|
||||
return status;
|
||||
grub_checkkey ();
|
||||
while (pending_key == GRUB_TERM_NO_KEY)
|
||||
{
|
||||
grub_cpu_idle ();
|
||||
grub_checkkey ();
|
||||
}
|
||||
ret = pending_key;
|
||||
pending_key = GRUB_TERM_NO_KEY;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
grub_refresh (void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue