2004-04-04 Yoshinori K. Okuji <okuji@enbug.org>
All symbols prefixed with PUPA_ and pupa_ are renamed to GRUB_ and grub_, respectively. Because the conversion is trivial and mechanical, I omit the details here. Please refer to the CVS if you need more information.
This commit is contained in:
parent
6a1425510d
commit
4b13b216f4
125 changed files with 6198 additions and 6181 deletions
|
@ -1,9 +1,9 @@
|
|||
/* device.c - device manager */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,62 +14,62 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/device.h>
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/net.h>
|
||||
#include <pupa/fs.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <grub/device.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
static char *pupa_device_root;
|
||||
static char *grub_device_root;
|
||||
|
||||
pupa_err_t
|
||||
pupa_device_set_root (const char *name)
|
||||
grub_err_t
|
||||
grub_device_set_root (const char *name)
|
||||
{
|
||||
pupa_free (pupa_device_root);
|
||||
pupa_device_root = pupa_strdup (name);
|
||||
return pupa_errno;
|
||||
grub_free (grub_device_root);
|
||||
grub_device_root = grub_strdup (name);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
const char *
|
||||
pupa_device_get_root (void)
|
||||
grub_device_get_root (void)
|
||||
{
|
||||
if (! pupa_device_root)
|
||||
pupa_error (PUPA_ERR_BAD_DEVICE, "no root device");
|
||||
if (! grub_device_root)
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "no root device");
|
||||
|
||||
return pupa_device_root;
|
||||
return grub_device_root;
|
||||
}
|
||||
|
||||
pupa_device_t
|
||||
pupa_device_open (const char *name)
|
||||
grub_device_t
|
||||
grub_device_open (const char *name)
|
||||
{
|
||||
pupa_disk_t disk = 0;
|
||||
pupa_device_t dev = 0;
|
||||
grub_disk_t disk = 0;
|
||||
grub_device_t dev = 0;
|
||||
|
||||
if (! name)
|
||||
{
|
||||
if (! pupa_device_root)
|
||||
if (! grub_device_root)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_DEVICE, "no device is set");
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "no device is set");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
name = pupa_device_root;
|
||||
name = grub_device_root;
|
||||
}
|
||||
|
||||
dev = pupa_malloc (sizeof (*dev));
|
||||
dev = grub_malloc (sizeof (*dev));
|
||||
if (! dev)
|
||||
goto fail;
|
||||
|
||||
/* Try to open a disk. */
|
||||
disk = pupa_disk_open (name);
|
||||
disk = grub_disk_open (name);
|
||||
if (! disk)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_DEVICE, "unknown device");
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "unknown device");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
@ -80,20 +80,20 @@ pupa_device_open (const char *name)
|
|||
|
||||
fail:
|
||||
if (disk)
|
||||
pupa_disk_close (disk);
|
||||
grub_disk_close (disk);
|
||||
|
||||
pupa_free (dev);
|
||||
grub_free (dev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_device_close (pupa_device_t device)
|
||||
grub_err_t
|
||||
grub_device_close (grub_device_t device)
|
||||
{
|
||||
if (device->disk)
|
||||
pupa_disk_close (device->disk);
|
||||
grub_disk_close (device->disk);
|
||||
|
||||
pupa_free (device);
|
||||
grub_free (device);
|
||||
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
}
|
||||
|
|
344
kern/disk.c
344
kern/disk.c
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -13,27 +13,27 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/machine/partition.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/machine/time.h>
|
||||
#include <pupa/file.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/machine/partition.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/machine/time.h>
|
||||
#include <grub/file.h>
|
||||
|
||||
#define PUPA_CACHE_TIMEOUT 2
|
||||
#define GRUB_CACHE_TIMEOUT 2
|
||||
|
||||
/* The last time the disk was used. */
|
||||
static unsigned long pupa_last_time = 0;
|
||||
static unsigned long grub_last_time = 0;
|
||||
|
||||
|
||||
/* Disk cache. */
|
||||
struct pupa_disk_cache
|
||||
struct grub_disk_cache
|
||||
{
|
||||
unsigned long id;
|
||||
unsigned long sector;
|
||||
|
@ -41,142 +41,142 @@ struct pupa_disk_cache
|
|||
int lock;
|
||||
};
|
||||
|
||||
static struct pupa_disk_cache pupa_disk_cache_table[PUPA_DISK_CACHE_NUM];
|
||||
static struct grub_disk_cache grub_disk_cache_table[GRUB_DISK_CACHE_NUM];
|
||||
|
||||
#if 0
|
||||
static unsigned long pupa_disk_cache_hits;
|
||||
static unsigned long pupa_disk_cache_misses;
|
||||
static unsigned long grub_disk_cache_hits;
|
||||
static unsigned long grub_disk_cache_misses;
|
||||
|
||||
void
|
||||
pupa_disk_cache_get_performance (unsigned long *hits, unsigned long *misses)
|
||||
grub_disk_cache_get_performance (unsigned long *hits, unsigned long *misses)
|
||||
{
|
||||
*hits = pupa_disk_cache_hits;
|
||||
*misses = pupa_disk_cache_misses;
|
||||
*hits = grub_disk_cache_hits;
|
||||
*misses = grub_disk_cache_misses;
|
||||
}
|
||||
#endif
|
||||
|
||||
static unsigned
|
||||
pupa_disk_cache_get_index (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_get_index (unsigned long id, unsigned long sector)
|
||||
{
|
||||
return ((id * 2606459 + (sector >> PUPA_DISK_CACHE_BITS))
|
||||
% PUPA_DISK_CACHE_NUM);
|
||||
return ((id * 2606459 + (sector >> GRUB_DISK_CACHE_BITS))
|
||||
% GRUB_DISK_CACHE_NUM);
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_disk_cache_invalidate (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_invalidate (unsigned long id, unsigned long sector)
|
||||
{
|
||||
unsigned index;
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
|
||||
sector &= ~(PUPA_DISK_CACHE_SIZE - 1);
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
sector &= ~(GRUB_DISK_CACHE_SIZE - 1);
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
if (cache->id == id && cache->sector == sector && cache->data)
|
||||
{
|
||||
cache->lock = 1;
|
||||
pupa_free (cache->data);
|
||||
grub_free (cache->data);
|
||||
cache->data = 0;
|
||||
cache->lock = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pupa_disk_cache_invalidate_all (void)
|
||||
grub_disk_cache_invalidate_all (void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < PUPA_DISK_CACHE_NUM; i++)
|
||||
for (i = 0; i < GRUB_DISK_CACHE_NUM; i++)
|
||||
{
|
||||
struct pupa_disk_cache *cache = pupa_disk_cache_table + i;
|
||||
struct grub_disk_cache *cache = grub_disk_cache_table + i;
|
||||
|
||||
if (cache->data && ! cache->lock)
|
||||
{
|
||||
pupa_free (cache->data);
|
||||
grub_free (cache->data);
|
||||
cache->data = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
pupa_disk_cache_fetch (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_fetch (unsigned long id, unsigned long sector)
|
||||
{
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
unsigned index;
|
||||
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
if (cache->id == id && cache->sector == sector)
|
||||
{
|
||||
cache->lock = 1;
|
||||
#if 0
|
||||
pupa_disk_cache_hits++;
|
||||
grub_disk_cache_hits++;
|
||||
#endif
|
||||
return cache->data;
|
||||
}
|
||||
|
||||
#if 0
|
||||
pupa_disk_cache_misses++;
|
||||
grub_disk_cache_misses++;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_disk_cache_unlock (unsigned long id, unsigned long sector)
|
||||
grub_disk_cache_unlock (unsigned long id, unsigned long sector)
|
||||
{
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
unsigned index;
|
||||
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
if (cache->id == id && cache->sector == sector)
|
||||
cache->lock = 0;
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_disk_cache_store (unsigned long id, unsigned long sector,
|
||||
static grub_err_t
|
||||
grub_disk_cache_store (unsigned long id, unsigned long sector,
|
||||
const char *data)
|
||||
{
|
||||
unsigned index;
|
||||
struct pupa_disk_cache *cache;
|
||||
struct grub_disk_cache *cache;
|
||||
|
||||
pupa_disk_cache_invalidate (id, sector);
|
||||
grub_disk_cache_invalidate (id, sector);
|
||||
|
||||
index = pupa_disk_cache_get_index (id, sector);
|
||||
cache = pupa_disk_cache_table + index;
|
||||
index = grub_disk_cache_get_index (id, sector);
|
||||
cache = grub_disk_cache_table + index;
|
||||
|
||||
cache->data = pupa_malloc (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS);
|
||||
cache->data = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
if (! cache->data)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
pupa_memcpy (cache->data, data,
|
||||
PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS);
|
||||
grub_memcpy (cache->data, data,
|
||||
GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
cache->id = id;
|
||||
cache->sector = sector;
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static pupa_disk_dev_t pupa_disk_dev_list;
|
||||
static grub_disk_dev_t grub_disk_dev_list;
|
||||
|
||||
void
|
||||
pupa_disk_dev_register (pupa_disk_dev_t dev)
|
||||
grub_disk_dev_register (grub_disk_dev_t dev)
|
||||
{
|
||||
dev->next = pupa_disk_dev_list;
|
||||
pupa_disk_dev_list = dev;
|
||||
dev->next = grub_disk_dev_list;
|
||||
grub_disk_dev_list = dev;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_disk_dev_unregister (pupa_disk_dev_t dev)
|
||||
grub_disk_dev_unregister (grub_disk_dev_t dev)
|
||||
{
|
||||
pupa_disk_dev_t *p, q;
|
||||
grub_disk_dev_t *p, q;
|
||||
|
||||
for (p = &pupa_disk_dev_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
for (p = &grub_disk_dev_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (q == dev)
|
||||
{
|
||||
*p = q->next;
|
||||
|
@ -185,25 +185,25 @@ pupa_disk_dev_unregister (pupa_disk_dev_t dev)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_disk_dev_iterate (int (*hook) (const char *name))
|
||||
grub_disk_dev_iterate (int (*hook) (const char *name))
|
||||
{
|
||||
pupa_disk_dev_t p;
|
||||
grub_disk_dev_t p;
|
||||
|
||||
for (p = pupa_disk_dev_list; p; p = p->next)
|
||||
for (p = grub_disk_dev_list; p; p = p->next)
|
||||
if ((p->iterate) (hook))
|
||||
break;
|
||||
}
|
||||
|
||||
pupa_disk_t
|
||||
pupa_disk_open (const char *name)
|
||||
grub_disk_t
|
||||
grub_disk_open (const char *name)
|
||||
{
|
||||
char *p;
|
||||
pupa_disk_t disk;
|
||||
pupa_disk_dev_t dev;
|
||||
grub_disk_t disk;
|
||||
grub_disk_dev_t dev;
|
||||
char *raw = (char *) name;
|
||||
unsigned long current_time;
|
||||
|
||||
disk = (pupa_disk_t) pupa_malloc (sizeof (*disk));
|
||||
disk = (grub_disk_t) grub_malloc (sizeof (*disk));
|
||||
if (! disk)
|
||||
return 0;
|
||||
|
||||
|
@ -211,67 +211,67 @@ pupa_disk_open (const char *name)
|
|||
disk->read_hook = 0;
|
||||
disk->partition = 0;
|
||||
disk->data = 0;
|
||||
disk->name = pupa_strdup (name);
|
||||
disk->name = grub_strdup (name);
|
||||
if (! disk->name)
|
||||
goto fail;
|
||||
|
||||
p = pupa_strchr (name, ',');
|
||||
p = grub_strchr (name, ',');
|
||||
if (p)
|
||||
{
|
||||
pupa_size_t len = p - name;
|
||||
grub_size_t len = p - name;
|
||||
|
||||
raw = pupa_malloc (len + 1);
|
||||
raw = grub_malloc (len + 1);
|
||||
if (! raw)
|
||||
goto fail;
|
||||
|
||||
pupa_memcpy (raw, name, len);
|
||||
grub_memcpy (raw, name, len);
|
||||
raw[len] = '\0';
|
||||
}
|
||||
|
||||
for (dev = pupa_disk_dev_list; dev; dev = dev->next)
|
||||
for (dev = grub_disk_dev_list; dev; dev = dev->next)
|
||||
{
|
||||
if ((dev->open) (raw, disk) == PUPA_ERR_NONE)
|
||||
if ((dev->open) (raw, disk) == GRUB_ERR_NONE)
|
||||
break;
|
||||
else if (pupa_errno == PUPA_ERR_UNKNOWN_DEVICE)
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
else if (grub_errno == GRUB_ERR_UNKNOWN_DEVICE)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
else
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (! dev)
|
||||
{
|
||||
pupa_error (PUPA_ERR_UNKNOWN_DEVICE, "no such disk");
|
||||
grub_error (GRUB_ERR_UNKNOWN_DEVICE, "no such disk");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (p && ! disk->has_partitions)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_DEVICE, "no partition on this disk");
|
||||
grub_error (GRUB_ERR_BAD_DEVICE, "no partition on this disk");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
disk->dev = dev;
|
||||
|
||||
if (p)
|
||||
disk->partition = pupa_partition_probe (disk, p + 1);
|
||||
disk->partition = grub_partition_probe (disk, p + 1);
|
||||
|
||||
/* The cache will be invalidated about 2 seconds after a device was
|
||||
closed. */
|
||||
current_time = pupa_get_rtc ();
|
||||
current_time = grub_get_rtc ();
|
||||
|
||||
if (current_time > pupa_last_time + PUPA_CACHE_TIMEOUT * PUPA_TICKS_PER_SECOND)
|
||||
pupa_disk_cache_invalidate_all ();
|
||||
if (current_time > grub_last_time + GRUB_CACHE_TIMEOUT * GRUB_TICKS_PER_SECOND)
|
||||
grub_disk_cache_invalidate_all ();
|
||||
|
||||
pupa_last_time = current_time;
|
||||
grub_last_time = current_time;
|
||||
|
||||
fail:
|
||||
|
||||
if (raw && raw != name)
|
||||
pupa_free (raw);
|
||||
grub_free (raw);
|
||||
|
||||
if (pupa_errno != PUPA_ERR_NONE)
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
{
|
||||
pupa_disk_close (disk);
|
||||
grub_disk_close (disk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -279,64 +279,64 @@ pupa_disk_open (const char *name)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_disk_close (pupa_disk_t disk)
|
||||
grub_disk_close (grub_disk_t disk)
|
||||
{
|
||||
if (disk->dev && disk->dev->close)
|
||||
(disk->dev->close) (disk);
|
||||
|
||||
/* Reset the timer. */
|
||||
pupa_last_time = pupa_get_rtc ();
|
||||
grub_last_time = grub_get_rtc ();
|
||||
|
||||
pupa_free (disk->partition);
|
||||
pupa_free ((void *) disk->name);
|
||||
pupa_free (disk);
|
||||
grub_free (disk->partition);
|
||||
grub_free ((void *) disk->name);
|
||||
grub_free (disk);
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_disk_check_range (pupa_disk_t disk, unsigned long *sector,
|
||||
unsigned long *offset, pupa_ssize_t size)
|
||||
static grub_err_t
|
||||
grub_disk_check_range (grub_disk_t disk, unsigned long *sector,
|
||||
unsigned long *offset, grub_ssize_t size)
|
||||
{
|
||||
*sector += *offset >> PUPA_DISK_SECTOR_BITS;
|
||||
*offset &= PUPA_DISK_SECTOR_SIZE - 1;
|
||||
*sector += *offset >> GRUB_DISK_SECTOR_BITS;
|
||||
*offset &= GRUB_DISK_SECTOR_SIZE - 1;
|
||||
|
||||
if (disk->partition)
|
||||
{
|
||||
unsigned long start, len;
|
||||
|
||||
start = pupa_partition_get_start (disk->partition);
|
||||
len = pupa_partition_get_len (disk->partition);
|
||||
start = grub_partition_get_start (disk->partition);
|
||||
len = grub_partition_get_len (disk->partition);
|
||||
|
||||
if (*sector >= len
|
||||
|| len - *sector < ((*offset + size + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS))
|
||||
return pupa_error (PUPA_ERR_OUT_OF_RANGE, "out of partition");
|
||||
|| len - *sector < ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS))
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of partition");
|
||||
|
||||
*sector += start;
|
||||
}
|
||||
|
||||
if (disk->total_sectors <= *sector
|
||||
|| ((*offset + size + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS) > disk->total_sectors - *sector)
|
||||
return pupa_error (PUPA_ERR_OUT_OF_RANGE, "out of disk");
|
||||
|| ((*offset + size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS) > disk->total_sectors - *sector)
|
||||
return grub_error (GRUB_ERR_OUT_OF_RANGE, "out of disk");
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Read data from the disk. */
|
||||
pupa_err_t
|
||||
pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
||||
grub_err_t
|
||||
grub_disk_read (grub_disk_t disk, unsigned long sector,
|
||||
unsigned long offset, unsigned long size, char *buf)
|
||||
{
|
||||
char *tmp_buf;
|
||||
|
||||
/* First of all, check if the region is within the disk. */
|
||||
if (pupa_disk_check_range (disk, §or, &offset, size) != PUPA_ERR_NONE)
|
||||
return pupa_errno;
|
||||
if (grub_disk_check_range (disk, §or, &offset, size) != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
/* Allocate a temporary buffer. */
|
||||
tmp_buf = pupa_malloc (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS);
|
||||
tmp_buf = grub_malloc (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS);
|
||||
if (! tmp_buf)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
/* Until SIZE is zero... */
|
||||
while (size)
|
||||
|
@ -347,54 +347,54 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
unsigned long pos;
|
||||
|
||||
/* For reading bulk data. */
|
||||
start_sector = sector & ~(PUPA_DISK_CACHE_SIZE - 1);
|
||||
pos = (sector - start_sector) << PUPA_DISK_SECTOR_BITS;
|
||||
len = (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS) - pos - offset;
|
||||
start_sector = sector & ~(GRUB_DISK_CACHE_SIZE - 1);
|
||||
pos = (sector - start_sector) << GRUB_DISK_SECTOR_BITS;
|
||||
len = (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS) - pos - offset;
|
||||
if (len > size)
|
||||
len = size;
|
||||
|
||||
/* Fetch the cache. */
|
||||
data = pupa_disk_cache_fetch (disk->id, start_sector);
|
||||
data = grub_disk_cache_fetch (disk->id, start_sector);
|
||||
if (data)
|
||||
{
|
||||
/* Just copy it! */
|
||||
pupa_memcpy (buf, data + pos + offset, len);
|
||||
pupa_disk_cache_unlock (disk->id, start_sector);
|
||||
grub_memcpy (buf, data + pos + offset, len);
|
||||
grub_disk_cache_unlock (disk->id, start_sector);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise read data from the disk actually. */
|
||||
if ((disk->dev->read) (disk, start_sector,
|
||||
PUPA_DISK_CACHE_SIZE, tmp_buf)
|
||||
!= PUPA_ERR_NONE)
|
||||
GRUB_DISK_CACHE_SIZE, tmp_buf)
|
||||
!= GRUB_ERR_NONE)
|
||||
{
|
||||
/* Uggh... Failed. Instead, just read necessary data. */
|
||||
unsigned num;
|
||||
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
/* If more data is required, no way. */
|
||||
if (pos + size
|
||||
>= (PUPA_DISK_SECTOR_SIZE << PUPA_DISK_CACHE_BITS))
|
||||
>= (GRUB_DISK_SECTOR_SIZE << GRUB_DISK_CACHE_BITS))
|
||||
goto finish;
|
||||
|
||||
num = ((size + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS);
|
||||
num = ((size + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS);
|
||||
if ((disk->dev->read) (disk, sector, num, tmp_buf))
|
||||
goto finish;
|
||||
|
||||
pupa_memcpy (buf, tmp_buf + offset, size);
|
||||
grub_memcpy (buf, tmp_buf + offset, size);
|
||||
|
||||
/* Call the read hook, if any. */
|
||||
if (disk->read_hook)
|
||||
while (size)
|
||||
{
|
||||
(disk->read_hook) (sector, offset,
|
||||
((size > PUPA_DISK_SECTOR_SIZE)
|
||||
? PUPA_DISK_SECTOR_SIZE
|
||||
((size > GRUB_DISK_SECTOR_SIZE)
|
||||
? GRUB_DISK_SECTOR_SIZE
|
||||
: size));
|
||||
sector++;
|
||||
size -= PUPA_DISK_SECTOR_SIZE - offset;
|
||||
size -= GRUB_DISK_SECTOR_SIZE - offset;
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
|
@ -403,8 +403,8 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
}
|
||||
|
||||
/* Copy it and store it in the disk cache. */
|
||||
pupa_memcpy (buf, tmp_buf + pos + offset, len);
|
||||
pupa_disk_cache_store (disk->id, start_sector, tmp_buf);
|
||||
grub_memcpy (buf, tmp_buf + pos + offset, len);
|
||||
grub_disk_cache_store (disk->id, start_sector, tmp_buf);
|
||||
}
|
||||
|
||||
/* Call the read hook, if any. */
|
||||
|
@ -416,20 +416,20 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
while (l)
|
||||
{
|
||||
(disk->read_hook) (s, offset,
|
||||
((l > PUPA_DISK_SECTOR_SIZE)
|
||||
? PUPA_DISK_SECTOR_SIZE
|
||||
((l > GRUB_DISK_SECTOR_SIZE)
|
||||
? GRUB_DISK_SECTOR_SIZE
|
||||
: l));
|
||||
|
||||
if (l < PUPA_DISK_SECTOR_SIZE - offset)
|
||||
if (l < GRUB_DISK_SECTOR_SIZE - offset)
|
||||
break;
|
||||
|
||||
s++;
|
||||
l -= PUPA_DISK_SECTOR_SIZE - offset;
|
||||
l -= GRUB_DISK_SECTOR_SIZE - offset;
|
||||
offset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sector = start_sector + PUPA_DISK_CACHE_SIZE;
|
||||
sector = start_sector + GRUB_DISK_CACHE_SIZE;
|
||||
buf += len;
|
||||
size -= len;
|
||||
offset = 0;
|
||||
|
@ -437,38 +437,38 @@ pupa_disk_read (pupa_disk_t disk, unsigned long sector,
|
|||
|
||||
finish:
|
||||
|
||||
pupa_free (tmp_buf);
|
||||
grub_free (tmp_buf);
|
||||
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_disk_write (pupa_disk_t disk, unsigned long sector,
|
||||
grub_err_t
|
||||
grub_disk_write (grub_disk_t disk, unsigned long sector,
|
||||
unsigned long offset, unsigned long size, const char *buf)
|
||||
{
|
||||
if (pupa_disk_check_range (disk, §or, &offset, size) != PUPA_ERR_NONE)
|
||||
if (grub_disk_check_range (disk, §or, &offset, size) != GRUB_ERR_NONE)
|
||||
return -1;
|
||||
|
||||
while (size)
|
||||
{
|
||||
if (offset != 0 || (size < PUPA_DISK_SECTOR_SIZE && size != 0))
|
||||
if (offset != 0 || (size < GRUB_DISK_SECTOR_SIZE && size != 0))
|
||||
{
|
||||
char tmp_buf[PUPA_DISK_SECTOR_SIZE];
|
||||
char tmp_buf[GRUB_DISK_SECTOR_SIZE];
|
||||
unsigned long len;
|
||||
|
||||
if (pupa_disk_read (disk, sector, 0, PUPA_DISK_SECTOR_SIZE, tmp_buf)
|
||||
!= PUPA_ERR_NONE)
|
||||
if (grub_disk_read (disk, sector, 0, GRUB_DISK_SECTOR_SIZE, tmp_buf)
|
||||
!= GRUB_ERR_NONE)
|
||||
goto finish;
|
||||
|
||||
len = PUPA_DISK_SECTOR_SIZE - offset;
|
||||
len = GRUB_DISK_SECTOR_SIZE - offset;
|
||||
if (len > size)
|
||||
len = size;
|
||||
|
||||
pupa_memcpy (tmp_buf + offset, buf, len);
|
||||
grub_memcpy (tmp_buf + offset, buf, len);
|
||||
|
||||
pupa_disk_cache_invalidate (disk->id, sector);
|
||||
grub_disk_cache_invalidate (disk->id, sector);
|
||||
|
||||
if ((disk->dev->write) (disk, sector, 1, tmp_buf) != PUPA_ERR_NONE)
|
||||
if ((disk->dev->write) (disk, sector, 1, tmp_buf) != GRUB_ERR_NONE)
|
||||
goto finish;
|
||||
|
||||
sector++;
|
||||
|
@ -481,14 +481,14 @@ pupa_disk_write (pupa_disk_t disk, unsigned long sector,
|
|||
unsigned long len;
|
||||
unsigned long n;
|
||||
|
||||
len = size & ~(PUPA_DISK_SECTOR_SIZE - 1);
|
||||
n = size >> PUPA_DISK_SECTOR_BITS;
|
||||
len = size & ~(GRUB_DISK_SECTOR_SIZE - 1);
|
||||
n = size >> GRUB_DISK_SECTOR_BITS;
|
||||
|
||||
if ((disk->dev->write) (disk, sector, n, buf) != PUPA_ERR_NONE)
|
||||
if ((disk->dev->write) (disk, sector, n, buf) != GRUB_ERR_NONE)
|
||||
goto finish;
|
||||
|
||||
while (n--)
|
||||
pupa_disk_cache_invalidate (disk->id, sector++);
|
||||
grub_disk_cache_invalidate (disk->id, sector++);
|
||||
|
||||
buf += len;
|
||||
size -= len;
|
||||
|
@ -497,46 +497,46 @@ pupa_disk_write (pupa_disk_t disk, unsigned long sector,
|
|||
|
||||
finish:
|
||||
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_print_partinfo (pupa_device_t disk, char *partname)
|
||||
grub_err_t
|
||||
grub_print_partinfo (grub_device_t disk, char *partname)
|
||||
{
|
||||
pupa_fs_t fs = 0;
|
||||
pupa_device_t part;
|
||||
grub_fs_t fs = 0;
|
||||
grub_device_t part;
|
||||
char devname[20];
|
||||
|
||||
pupa_sprintf (devname, "%s,%s", disk->disk->name, partname);
|
||||
part = pupa_device_open (devname);
|
||||
grub_sprintf (devname, "%s,%s", disk->disk->name, partname);
|
||||
part = grub_device_open (devname);
|
||||
if (!part)
|
||||
pupa_printf ("\tPartition num:%s, Filesystem cannot be accessed",
|
||||
grub_printf ("\tPartition num:%s, Filesystem cannot be accessed",
|
||||
partname);
|
||||
else
|
||||
{
|
||||
char *label;
|
||||
|
||||
fs = pupa_fs_probe (part);
|
||||
fs = grub_fs_probe (part);
|
||||
/* Ignore all errors. */
|
||||
pupa_errno = 0;
|
||||
grub_errno = 0;
|
||||
|
||||
pupa_printf ("\tPartition num:%s, Filesystem type %s",
|
||||
grub_printf ("\tPartition num:%s, Filesystem type %s",
|
||||
partname, fs ? fs->name : "Unknown");
|
||||
|
||||
if (fs)
|
||||
{
|
||||
(fs->label) (part, &label);
|
||||
if (pupa_errno == PUPA_ERR_NONE)
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
{
|
||||
if (label && pupa_strlen (label))
|
||||
pupa_printf (", Label: %s", label);
|
||||
pupa_free (label);
|
||||
if (label && grub_strlen (label))
|
||||
grub_printf (", Label: %s", label);
|
||||
grub_free (label);
|
||||
}
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
pupa_device_close (part);
|
||||
grub_device_close (part);
|
||||
}
|
||||
|
||||
pupa_printf ("\n");
|
||||
return pupa_errno;
|
||||
grub_printf ("\n");
|
||||
return grub_errno;
|
||||
}
|
||||
|
|
382
kern/dl.c
382
kern/dl.c
|
@ -1,9 +1,9 @@
|
|||
/* dl.c - loadable module support */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,22 +14,22 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <pupa/elf.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/symbol.h>
|
||||
#include <pupa/file.h>
|
||||
#include <pupa/env.h>
|
||||
#include <grub/elf.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
#if PUPA_HOST_SIZEOF_VOID_P == 4
|
||||
#if GRUB_HOST_SIZEOF_VOID_P == 4
|
||||
|
||||
typedef Elf32_Word Elf_Word;
|
||||
typedef Elf32_Addr Elf_Addr;
|
||||
|
@ -40,7 +40,7 @@ typedef Elf32_Sym Elf_Sym;
|
|||
# define ELF_ST_BIND(val) ELF32_ST_BIND (val)
|
||||
# define ELF_ST_TYPE(val) ELF32_ST_TYPE (val)
|
||||
|
||||
#elif PUPA_HOST_SIZEOF_VOID_P == 8
|
||||
#elif GRUB_HOST_SIZEOF_VOID_P == 8
|
||||
|
||||
typedef Elf64_Word Elf_Word;
|
||||
typedef Elf64_Addr Elf_Addr;
|
||||
|
@ -55,132 +55,132 @@ typedef Elf64_Sym Elf_Sym;
|
|||
|
||||
|
||||
|
||||
struct pupa_dl_list
|
||||
struct grub_dl_list
|
||||
{
|
||||
struct pupa_dl_list *next;
|
||||
pupa_dl_t mod;
|
||||
struct grub_dl_list *next;
|
||||
grub_dl_t mod;
|
||||
};
|
||||
typedef struct pupa_dl_list *pupa_dl_list_t;
|
||||
typedef struct grub_dl_list *grub_dl_list_t;
|
||||
|
||||
static pupa_dl_list_t pupa_dl_head;
|
||||
static grub_dl_list_t grub_dl_head;
|
||||
|
||||
static pupa_err_t
|
||||
pupa_dl_add (pupa_dl_t mod)
|
||||
static grub_err_t
|
||||
grub_dl_add (grub_dl_t mod)
|
||||
{
|
||||
pupa_dl_list_t l;
|
||||
grub_dl_list_t l;
|
||||
|
||||
if (pupa_dl_get (mod->name))
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE,
|
||||
if (grub_dl_get (mod->name))
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"`%s' is already loaded", mod->name);
|
||||
|
||||
l = (pupa_dl_list_t) pupa_malloc (sizeof (*l));
|
||||
l = (grub_dl_list_t) grub_malloc (sizeof (*l));
|
||||
if (! l)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
l->mod = mod;
|
||||
l->next = pupa_dl_head;
|
||||
pupa_dl_head = l;
|
||||
l->next = grub_dl_head;
|
||||
grub_dl_head = l;
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_dl_remove (pupa_dl_t mod)
|
||||
grub_dl_remove (grub_dl_t mod)
|
||||
{
|
||||
pupa_dl_list_t *p, q;
|
||||
grub_dl_list_t *p, q;
|
||||
|
||||
for (p = &pupa_dl_head, q = *p; q; p = &q->next, q = *p)
|
||||
for (p = &grub_dl_head, q = *p; q; p = &q->next, q = *p)
|
||||
if (q->mod == mod)
|
||||
{
|
||||
*p = q->next;
|
||||
pupa_free (q);
|
||||
grub_free (q);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
pupa_dl_t
|
||||
pupa_dl_get (const char *name)
|
||||
grub_dl_t
|
||||
grub_dl_get (const char *name)
|
||||
{
|
||||
pupa_dl_list_t l;
|
||||
grub_dl_list_t l;
|
||||
|
||||
for (l = pupa_dl_head; l; l = l->next)
|
||||
if (pupa_strcmp (name, l->mod->name) == 0)
|
||||
for (l = grub_dl_head; l; l = l->next)
|
||||
if (grub_strcmp (name, l->mod->name) == 0)
|
||||
return l->mod;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_dl_iterate (int (*hook) (pupa_dl_t mod))
|
||||
grub_dl_iterate (int (*hook) (grub_dl_t mod))
|
||||
{
|
||||
pupa_dl_list_t l;
|
||||
grub_dl_list_t l;
|
||||
|
||||
for (l = pupa_dl_head; l; l = l->next)
|
||||
for (l = grub_dl_head; l; l = l->next)
|
||||
if (hook (l->mod))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct pupa_symbol
|
||||
struct grub_symbol
|
||||
{
|
||||
struct pupa_symbol *next;
|
||||
struct grub_symbol *next;
|
||||
const char *name;
|
||||
void *addr;
|
||||
pupa_dl_t mod; /* The module to which this symbol belongs. */
|
||||
grub_dl_t mod; /* The module to which this symbol belongs. */
|
||||
};
|
||||
typedef struct pupa_symbol *pupa_symbol_t;
|
||||
typedef struct grub_symbol *grub_symbol_t;
|
||||
|
||||
/* The size of the symbol table. */
|
||||
#define PUPA_SYMTAB_SIZE 509
|
||||
#define GRUB_SYMTAB_SIZE 509
|
||||
|
||||
/* The symbol table (using an open-hash). */
|
||||
static struct pupa_symbol *pupa_symtab[PUPA_SYMTAB_SIZE];
|
||||
static struct grub_symbol *grub_symtab[GRUB_SYMTAB_SIZE];
|
||||
|
||||
/* Simple hash function. */
|
||||
static unsigned
|
||||
pupa_symbol_hash (const char *s)
|
||||
grub_symbol_hash (const char *s)
|
||||
{
|
||||
unsigned key = 0;
|
||||
|
||||
while (*s)
|
||||
key = key * 65599 + *s++;
|
||||
|
||||
return (key + (key >> 5)) % PUPA_SYMTAB_SIZE;
|
||||
return (key + (key >> 5)) % GRUB_SYMTAB_SIZE;
|
||||
}
|
||||
|
||||
/* Resolve the symbol name NAME and return the address.
|
||||
Return NULL, if not found. */
|
||||
void *
|
||||
pupa_dl_resolve_symbol (const char *name)
|
||||
grub_dl_resolve_symbol (const char *name)
|
||||
{
|
||||
pupa_symbol_t sym;
|
||||
grub_symbol_t sym;
|
||||
|
||||
for (sym = pupa_symtab[pupa_symbol_hash (name)]; sym; sym = sym->next)
|
||||
if (pupa_strcmp (sym->name, name) == 0)
|
||||
for (sym = grub_symtab[grub_symbol_hash (name)]; sym; sym = sym->next)
|
||||
if (grub_strcmp (sym->name, name) == 0)
|
||||
return sym->addr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Register a symbol with the name NAME and the address ADDR. */
|
||||
pupa_err_t
|
||||
pupa_dl_register_symbol (const char *name, void *addr, pupa_dl_t mod)
|
||||
grub_err_t
|
||||
grub_dl_register_symbol (const char *name, void *addr, grub_dl_t mod)
|
||||
{
|
||||
pupa_symbol_t sym;
|
||||
grub_symbol_t sym;
|
||||
unsigned k;
|
||||
|
||||
sym = (pupa_symbol_t) pupa_malloc (sizeof (*sym));
|
||||
sym = (grub_symbol_t) grub_malloc (sizeof (*sym));
|
||||
if (! sym)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
if (mod)
|
||||
{
|
||||
sym->name = pupa_strdup (name);
|
||||
sym->name = grub_strdup (name);
|
||||
if (! sym->name)
|
||||
{
|
||||
pupa_free (sym);
|
||||
return pupa_errno;
|
||||
grub_free (sym);
|
||||
return grub_errno;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -189,34 +189,34 @@ pupa_dl_register_symbol (const char *name, void *addr, pupa_dl_t mod)
|
|||
sym->addr = addr;
|
||||
sym->mod = mod;
|
||||
|
||||
k = pupa_symbol_hash (name);
|
||||
sym->next = pupa_symtab[k];
|
||||
pupa_symtab[k] = sym;
|
||||
k = grub_symbol_hash (name);
|
||||
sym->next = grub_symtab[k];
|
||||
grub_symtab[k] = sym;
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* Unregister all the symbols defined in the module MOD. */
|
||||
static void
|
||||
pupa_dl_unregister_symbols (pupa_dl_t mod)
|
||||
grub_dl_unregister_symbols (grub_dl_t mod)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (! mod)
|
||||
pupa_fatal ("core symbols cannot be unregistered");
|
||||
grub_fatal ("core symbols cannot be unregistered");
|
||||
|
||||
for (i = 0; i < PUPA_SYMTAB_SIZE; i++)
|
||||
for (i = 0; i < GRUB_SYMTAB_SIZE; i++)
|
||||
{
|
||||
pupa_symbol_t sym, *p, q;
|
||||
grub_symbol_t sym, *p, q;
|
||||
|
||||
for (p = &pupa_symtab[i], sym = *p; sym; sym = q)
|
||||
for (p = &grub_symtab[i], sym = *p; sym; sym = q)
|
||||
{
|
||||
q = sym->next;
|
||||
if (sym->mod == mod)
|
||||
{
|
||||
*p = q;
|
||||
pupa_free ((void *) sym->name);
|
||||
pupa_free (sym);
|
||||
grub_free ((void *) sym->name);
|
||||
grub_free (sym);
|
||||
}
|
||||
else
|
||||
p = &sym->next;
|
||||
|
@ -226,9 +226,9 @@ pupa_dl_unregister_symbols (pupa_dl_t mod)
|
|||
|
||||
/* Return the address of a section whose index is N. */
|
||||
static void *
|
||||
pupa_dl_get_section_addr (pupa_dl_t mod, unsigned n)
|
||||
grub_dl_get_section_addr (grub_dl_t mod, unsigned n)
|
||||
{
|
||||
pupa_dl_segment_t seg;
|
||||
grub_dl_segment_t seg;
|
||||
|
||||
for (seg = mod->segment; seg; seg = seg->next)
|
||||
if (seg->section == n)
|
||||
|
@ -238,8 +238,8 @@ pupa_dl_get_section_addr (pupa_dl_t mod, unsigned n)
|
|||
}
|
||||
|
||||
/* Load all segments from memory specified by E. */
|
||||
static pupa_err_t
|
||||
pupa_dl_load_segments (pupa_dl_t mod, const Elf_Ehdr *e)
|
||||
static grub_err_t
|
||||
grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
|
||||
{
|
||||
unsigned i;
|
||||
Elf_Shdr *s;
|
||||
|
@ -250,30 +250,30 @@ pupa_dl_load_segments (pupa_dl_t mod, const Elf_Ehdr *e)
|
|||
{
|
||||
if (s->sh_flags & SHF_ALLOC)
|
||||
{
|
||||
pupa_dl_segment_t seg;
|
||||
grub_dl_segment_t seg;
|
||||
|
||||
seg = (pupa_dl_segment_t) pupa_malloc (sizeof (*seg));
|
||||
seg = (grub_dl_segment_t) grub_malloc (sizeof (*seg));
|
||||
if (! seg)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
if (s->sh_size)
|
||||
{
|
||||
void *addr;
|
||||
|
||||
addr = pupa_memalign (s->sh_addralign, s->sh_size);
|
||||
addr = grub_memalign (s->sh_addralign, s->sh_size);
|
||||
if (! addr)
|
||||
{
|
||||
pupa_free (seg);
|
||||
return pupa_errno;
|
||||
grub_free (seg);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
switch (s->sh_type)
|
||||
{
|
||||
case SHT_PROGBITS:
|
||||
pupa_memcpy (addr, (char *) e + s->sh_offset, s->sh_size);
|
||||
grub_memcpy (addr, (char *) e + s->sh_offset, s->sh_size);
|
||||
break;
|
||||
case SHT_NOBITS:
|
||||
pupa_memset (addr, 0, s->sh_size);
|
||||
grub_memset (addr, 0, s->sh_size);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -289,11 +289,11 @@ pupa_dl_load_segments (pupa_dl_t mod, const Elf_Ehdr *e)
|
|||
}
|
||||
}
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_dl_resolve_symbols (pupa_dl_t mod, Elf_Ehdr *e)
|
||||
static grub_err_t
|
||||
grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
|
||||
{
|
||||
unsigned i;
|
||||
Elf_Shdr *s;
|
||||
|
@ -308,7 +308,7 @@ pupa_dl_resolve_symbols (pupa_dl_t mod, Elf_Ehdr *e)
|
|||
break;
|
||||
|
||||
if (i == e->e_shnum)
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE, "no symbol table");
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "no symbol table");
|
||||
|
||||
sym = (Elf_Sym *) ((char *) e + s->sh_offset);
|
||||
size = s->sh_size;
|
||||
|
@ -331,9 +331,9 @@ pupa_dl_resolve_symbols (pupa_dl_t mod, Elf_Ehdr *e)
|
|||
/* Resolve a global symbol. */
|
||||
if (sym->st_name != 0 && sym->st_shndx == 0)
|
||||
{
|
||||
sym->st_value = (Elf_Addr) pupa_dl_resolve_symbol (name);
|
||||
sym->st_value = (Elf_Addr) grub_dl_resolve_symbol (name);
|
||||
if (! sym->st_value)
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE,
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"the symbol `%s' not found", name);
|
||||
}
|
||||
else
|
||||
|
@ -341,28 +341,28 @@ pupa_dl_resolve_symbols (pupa_dl_t mod, Elf_Ehdr *e)
|
|||
break;
|
||||
|
||||
case STT_OBJECT:
|
||||
sym->st_value += (Elf_Addr) pupa_dl_get_section_addr (mod,
|
||||
sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod,
|
||||
sym->st_shndx);
|
||||
if (bind != STB_LOCAL)
|
||||
if (pupa_dl_register_symbol (name, (void *) sym->st_value, mod))
|
||||
return pupa_errno;
|
||||
if (grub_dl_register_symbol (name, (void *) sym->st_value, mod))
|
||||
return grub_errno;
|
||||
break;
|
||||
|
||||
case STT_FUNC:
|
||||
sym->st_value += (Elf_Addr) pupa_dl_get_section_addr (mod,
|
||||
sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod,
|
||||
sym->st_shndx);
|
||||
if (bind != STB_LOCAL)
|
||||
if (pupa_dl_register_symbol (name, (void *) sym->st_value, mod))
|
||||
return pupa_errno;
|
||||
if (grub_dl_register_symbol (name, (void *) sym->st_value, mod))
|
||||
return grub_errno;
|
||||
|
||||
if (pupa_strcmp (name, "pupa_mod_init") == 0)
|
||||
mod->init = (void (*) (pupa_dl_t)) sym->st_value;
|
||||
else if (pupa_strcmp (name, "pupa_mod_fini") == 0)
|
||||
if (grub_strcmp (name, "grub_mod_init") == 0)
|
||||
mod->init = (void (*) (grub_dl_t)) sym->st_value;
|
||||
else if (grub_strcmp (name, "grub_mod_fini") == 0)
|
||||
mod->fini = (void (*) (void)) sym->st_value;
|
||||
break;
|
||||
|
||||
case STT_SECTION:
|
||||
sym->st_value = (Elf_Addr) pupa_dl_get_section_addr (mod,
|
||||
sym->st_value = (Elf_Addr) grub_dl_get_section_addr (mod,
|
||||
sym->st_shndx);
|
||||
break;
|
||||
|
||||
|
@ -371,23 +371,23 @@ pupa_dl_resolve_symbols (pupa_dl_t mod, Elf_Ehdr *e)
|
|||
break;
|
||||
|
||||
default:
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE,
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"unknown symbol type `%d'", (int) type);
|
||||
}
|
||||
}
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_dl_call_init (pupa_dl_t mod)
|
||||
grub_dl_call_init (grub_dl_t mod)
|
||||
{
|
||||
if (mod->init)
|
||||
(mod->init) (mod);
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_dl_resolve_name (pupa_dl_t mod, Elf_Ehdr *e)
|
||||
static grub_err_t
|
||||
grub_dl_resolve_name (grub_dl_t mod, Elf_Ehdr *e)
|
||||
{
|
||||
Elf_Shdr *s;
|
||||
const char *str;
|
||||
|
@ -399,22 +399,22 @@ pupa_dl_resolve_name (pupa_dl_t mod, Elf_Ehdr *e)
|
|||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (pupa_strcmp (str + s->sh_name, ".modname") == 0)
|
||||
if (grub_strcmp (str + s->sh_name, ".modname") == 0)
|
||||
{
|
||||
mod->name = pupa_strdup ((char *) e + s->sh_offset);
|
||||
mod->name = grub_strdup ((char *) e + s->sh_offset);
|
||||
if (! mod->name)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == e->e_shnum)
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE, "no module name found");
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "no module name found");
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
static pupa_err_t
|
||||
pupa_dl_resolve_dependencies (pupa_dl_t mod, Elf_Ehdr *e)
|
||||
static grub_err_t
|
||||
grub_dl_resolve_dependencies (grub_dl_t mod, Elf_Ehdr *e)
|
||||
{
|
||||
Elf_Shdr *s;
|
||||
const char *str;
|
||||
|
@ -426,74 +426,74 @@ pupa_dl_resolve_dependencies (pupa_dl_t mod, Elf_Ehdr *e)
|
|||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (pupa_strcmp (str + s->sh_name, ".moddeps") == 0)
|
||||
if (grub_strcmp (str + s->sh_name, ".moddeps") == 0)
|
||||
{
|
||||
const char *name = (char *) e + s->sh_offset;
|
||||
const char *max = name + s->sh_size;
|
||||
|
||||
while (name < max)
|
||||
{
|
||||
pupa_dl_t m;
|
||||
pupa_dl_dep_t dep;
|
||||
grub_dl_t m;
|
||||
grub_dl_dep_t dep;
|
||||
|
||||
m = pupa_dl_load (name);
|
||||
m = grub_dl_load (name);
|
||||
if (! m)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
pupa_dl_ref (m);
|
||||
grub_dl_ref (m);
|
||||
|
||||
dep = (pupa_dl_dep_t) pupa_malloc (sizeof (*dep));
|
||||
dep = (grub_dl_dep_t) grub_malloc (sizeof (*dep));
|
||||
if (! dep)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
dep->mod = m;
|
||||
dep->next = mod->dep;
|
||||
mod->dep = dep;
|
||||
|
||||
name += pupa_strlen (name) + 1;
|
||||
name += grub_strlen (name) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
int
|
||||
pupa_dl_ref (pupa_dl_t mod)
|
||||
grub_dl_ref (grub_dl_t mod)
|
||||
{
|
||||
pupa_dl_dep_t dep;
|
||||
grub_dl_dep_t dep;
|
||||
|
||||
for (dep = mod->dep; dep; dep = dep->next)
|
||||
pupa_dl_ref (dep->mod);
|
||||
grub_dl_ref (dep->mod);
|
||||
|
||||
return ++mod->ref_count;
|
||||
}
|
||||
|
||||
int
|
||||
pupa_dl_unref (pupa_dl_t mod)
|
||||
grub_dl_unref (grub_dl_t mod)
|
||||
{
|
||||
pupa_dl_dep_t dep;
|
||||
grub_dl_dep_t dep;
|
||||
|
||||
for (dep = mod->dep; dep; dep = dep->next)
|
||||
pupa_dl_unref (dep->mod);
|
||||
grub_dl_unref (dep->mod);
|
||||
|
||||
return --mod->ref_count;
|
||||
}
|
||||
|
||||
/* Load a module from core memory. */
|
||||
pupa_dl_t
|
||||
pupa_dl_load_core (void *addr, pupa_size_t size)
|
||||
grub_dl_t
|
||||
grub_dl_load_core (void *addr, grub_size_t size)
|
||||
{
|
||||
Elf_Ehdr *e;
|
||||
pupa_dl_t mod;
|
||||
grub_dl_t mod;
|
||||
|
||||
e = addr;
|
||||
if (! pupa_arch_dl_check_header (e, size))
|
||||
if (! grub_arch_dl_check_header (e, size))
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_MODULE, "invalid ELF header");
|
||||
grub_error (GRUB_ERR_BAD_MODULE, "invalid ELF header");
|
||||
return 0;
|
||||
}
|
||||
|
||||
mod = (pupa_dl_t) pupa_malloc (sizeof (*mod));
|
||||
mod = (grub_dl_t) grub_malloc (sizeof (*mod));
|
||||
if (! mod)
|
||||
return 0;
|
||||
|
||||
|
@ -504,22 +504,22 @@ pupa_dl_load_core (void *addr, pupa_size_t size)
|
|||
mod->init = 0;
|
||||
mod->fini = 0;
|
||||
|
||||
if (pupa_dl_resolve_name (mod, e)
|
||||
|| pupa_dl_resolve_dependencies (mod, e)
|
||||
|| pupa_dl_load_segments (mod, e)
|
||||
|| pupa_dl_resolve_symbols (mod, e)
|
||||
|| pupa_arch_dl_relocate_symbols (mod, e))
|
||||
if (grub_dl_resolve_name (mod, e)
|
||||
|| grub_dl_resolve_dependencies (mod, e)
|
||||
|| grub_dl_load_segments (mod, e)
|
||||
|| grub_dl_resolve_symbols (mod, e)
|
||||
|| grub_arch_dl_relocate_symbols (mod, e))
|
||||
{
|
||||
mod->fini = 0;
|
||||
pupa_dl_unload (mod);
|
||||
grub_dl_unload (mod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pupa_dl_call_init (mod);
|
||||
grub_dl_call_init (mod);
|
||||
|
||||
if (pupa_dl_add (mod))
|
||||
if (grub_dl_add (mod))
|
||||
{
|
||||
pupa_dl_unload (mod);
|
||||
grub_dl_unload (mod);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -527,75 +527,75 @@ pupa_dl_load_core (void *addr, pupa_size_t size)
|
|||
}
|
||||
|
||||
/* Load a module from the file FILENAME. */
|
||||
pupa_dl_t
|
||||
pupa_dl_load_file (const char *filename)
|
||||
grub_dl_t
|
||||
grub_dl_load_file (const char *filename)
|
||||
{
|
||||
pupa_file_t file;
|
||||
pupa_ssize_t size;
|
||||
grub_file_t file;
|
||||
grub_ssize_t size;
|
||||
void *core = 0;
|
||||
pupa_dl_t mod = 0;
|
||||
grub_dl_t mod = 0;
|
||||
|
||||
file = pupa_file_open (filename);
|
||||
file = grub_file_open (filename);
|
||||
if (! file)
|
||||
return 0;
|
||||
|
||||
size = pupa_file_size (file);
|
||||
core = pupa_malloc (size);
|
||||
size = grub_file_size (file);
|
||||
core = grub_malloc (size);
|
||||
if (! core)
|
||||
goto failed;
|
||||
|
||||
if (pupa_file_read (file, core, size) != (int) size)
|
||||
if (grub_file_read (file, core, size) != (int) size)
|
||||
goto failed;
|
||||
|
||||
mod = pupa_dl_load_core (core, size);
|
||||
mod = grub_dl_load_core (core, size);
|
||||
mod->ref_count = 0;
|
||||
|
||||
failed:
|
||||
pupa_file_close (file);
|
||||
pupa_free (core);
|
||||
grub_file_close (file);
|
||||
grub_free (core);
|
||||
|
||||
return mod;
|
||||
}
|
||||
|
||||
/* Load a module using a symbolic name. */
|
||||
pupa_dl_t
|
||||
pupa_dl_load (const char *name)
|
||||
grub_dl_t
|
||||
grub_dl_load (const char *name)
|
||||
{
|
||||
char *filename;
|
||||
pupa_dl_t mod;
|
||||
char *pupa_dl_dir = pupa_env_get ("prefix");
|
||||
grub_dl_t mod;
|
||||
char *grub_dl_dir = grub_env_get ("prefix");
|
||||
|
||||
mod = pupa_dl_get (name);
|
||||
mod = grub_dl_get (name);
|
||||
if (mod)
|
||||
return mod;
|
||||
|
||||
if (! pupa_dl_dir)
|
||||
pupa_fatal ("module dir is not initialized yet");
|
||||
if (! grub_dl_dir)
|
||||
grub_fatal ("module dir is not initialized yet");
|
||||
|
||||
filename = (char *) pupa_malloc (pupa_strlen (pupa_dl_dir) + 1
|
||||
+ pupa_strlen (name) + 4 + 1);
|
||||
filename = (char *) grub_malloc (grub_strlen (grub_dl_dir) + 1
|
||||
+ grub_strlen (name) + 4 + 1);
|
||||
if (! filename)
|
||||
return 0;
|
||||
|
||||
pupa_sprintf (filename, "%s/%s.mod", pupa_dl_dir, name);
|
||||
mod = pupa_dl_load_file (filename);
|
||||
pupa_free (filename);
|
||||
grub_sprintf (filename, "%s/%s.mod", grub_dl_dir, name);
|
||||
mod = grub_dl_load_file (filename);
|
||||
grub_free (filename);
|
||||
|
||||
if (! mod)
|
||||
return 0;
|
||||
|
||||
if (pupa_strcmp (mod->name, name) != 0)
|
||||
pupa_error (PUPA_ERR_BAD_MODULE, "mismatched names");
|
||||
if (grub_strcmp (mod->name, name) != 0)
|
||||
grub_error (GRUB_ERR_BAD_MODULE, "mismatched names");
|
||||
|
||||
return mod;
|
||||
}
|
||||
|
||||
/* Unload the module MOD. */
|
||||
int
|
||||
pupa_dl_unload (pupa_dl_t mod)
|
||||
grub_dl_unload (grub_dl_t mod)
|
||||
{
|
||||
pupa_dl_dep_t dep, depn;
|
||||
pupa_dl_segment_t seg, segn;
|
||||
grub_dl_dep_t dep, depn;
|
||||
grub_dl_segment_t seg, segn;
|
||||
|
||||
if (mod->ref_count > 0)
|
||||
return 0;
|
||||
|
@ -603,44 +603,44 @@ pupa_dl_unload (pupa_dl_t mod)
|
|||
if (mod->fini)
|
||||
(mod->fini) ();
|
||||
|
||||
pupa_dl_remove (mod);
|
||||
pupa_dl_unregister_symbols (mod);
|
||||
grub_dl_remove (mod);
|
||||
grub_dl_unregister_symbols (mod);
|
||||
|
||||
for (dep = mod->dep; dep; dep = depn)
|
||||
{
|
||||
depn = dep->next;
|
||||
|
||||
if (! pupa_dl_unref (dep->mod))
|
||||
pupa_dl_unload (dep->mod);
|
||||
if (! grub_dl_unref (dep->mod))
|
||||
grub_dl_unload (dep->mod);
|
||||
|
||||
pupa_free (dep);
|
||||
grub_free (dep);
|
||||
}
|
||||
|
||||
for (seg = mod->segment; seg; seg = segn)
|
||||
{
|
||||
segn = seg->next;
|
||||
pupa_free (seg->addr);
|
||||
pupa_free (seg);
|
||||
grub_free (seg->addr);
|
||||
grub_free (seg);
|
||||
}
|
||||
|
||||
pupa_free (mod->name);
|
||||
pupa_free (mod);
|
||||
grub_free (mod->name);
|
||||
grub_free (mod);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Unload unneeded modules. */
|
||||
void
|
||||
pupa_dl_unload_unneeded (void)
|
||||
grub_dl_unload_unneeded (void)
|
||||
{
|
||||
/* Because pupa_dl_remove modifies the list of modules, this
|
||||
/* Because grub_dl_remove modifies the list of modules, this
|
||||
implementation is tricky. */
|
||||
pupa_dl_list_t p = pupa_dl_head;
|
||||
grub_dl_list_t p = grub_dl_head;
|
||||
|
||||
while (p)
|
||||
{
|
||||
if (pupa_dl_unload (p->mod))
|
||||
if (grub_dl_unload (p->mod))
|
||||
{
|
||||
p = pupa_dl_head;
|
||||
p = grub_dl_head;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -650,17 +650,17 @@ pupa_dl_unload_unneeded (void)
|
|||
|
||||
/* Unload all modules. */
|
||||
void
|
||||
pupa_dl_unload_all (void)
|
||||
grub_dl_unload_all (void)
|
||||
{
|
||||
while (pupa_dl_head)
|
||||
while (grub_dl_head)
|
||||
{
|
||||
pupa_dl_list_t p;
|
||||
grub_dl_list_t p;
|
||||
|
||||
pupa_dl_unload_unneeded ();
|
||||
grub_dl_unload_unneeded ();
|
||||
|
||||
/* Force to decrement the ref count. This will purge pre-loaded
|
||||
modules and manually inserted modules. */
|
||||
for (p = pupa_dl_head; p; p = p->next)
|
||||
for (p = grub_dl_head; p; p = p->next)
|
||||
p->mod->ref_count--;
|
||||
}
|
||||
}
|
||||
|
|
126
kern/env.c
126
kern/env.c
|
@ -1,9 +1,9 @@
|
|||
/* env.c - Environment variables */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,25 +14,25 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/env.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <grub/env.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
|
||||
/* XXX: What would be a good size for the hashtable? */
|
||||
#define HASHSZ 123
|
||||
|
||||
/* A hashtable for quick lookup of variables. */
|
||||
static struct pupa_env_var *pupa_env[HASHSZ];
|
||||
static struct grub_env_var *grub_env[HASHSZ];
|
||||
|
||||
/* The variables in a sorted list. */
|
||||
static struct pupa_env_var *pupa_env_sorted;
|
||||
static struct grub_env_var *grub_env_sorted;
|
||||
|
||||
/* Return the hash representation of the string S. */
|
||||
static unsigned int pupa_env_hashval (const char *s)
|
||||
static unsigned int grub_env_hashval (const char *s)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
|
@ -43,73 +43,73 @@ static unsigned int pupa_env_hashval (const char *s)
|
|||
return i % HASHSZ;
|
||||
}
|
||||
|
||||
static struct pupa_env_var *
|
||||
pupa_env_find (const char *name)
|
||||
static struct grub_env_var *
|
||||
grub_env_find (const char *name)
|
||||
{
|
||||
struct pupa_env_var *var;
|
||||
int idx = pupa_env_hashval (name);
|
||||
struct grub_env_var *var;
|
||||
int idx = grub_env_hashval (name);
|
||||
|
||||
for (var = pupa_env[idx]; var; var = var->next)
|
||||
if (! pupa_strcmp (var->name, name))
|
||||
for (var = grub_env[idx]; var; var = var->next)
|
||||
if (! grub_strcmp (var->name, name))
|
||||
return var;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_env_set (const char *var, const char *val)
|
||||
grub_err_t
|
||||
grub_env_set (const char *var, const char *val)
|
||||
{
|
||||
int idx = pupa_env_hashval (var);
|
||||
struct pupa_env_var *env;
|
||||
struct pupa_env_var *sort;
|
||||
struct pupa_env_var **sortp;
|
||||
int idx = grub_env_hashval (var);
|
||||
struct grub_env_var *env;
|
||||
struct grub_env_var *sort;
|
||||
struct grub_env_var **sortp;
|
||||
|
||||
/* If the variable does already exist, just update the variable. */
|
||||
env = pupa_env_find (var);
|
||||
env = grub_env_find (var);
|
||||
if (env)
|
||||
{
|
||||
char *old = env->value;
|
||||
env->value = pupa_strdup (val);
|
||||
env->value = grub_strdup (val);
|
||||
if (! env->name)
|
||||
{
|
||||
env->value = old;
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
if (env->write_hook)
|
||||
(env->write_hook) (env);
|
||||
|
||||
pupa_free (old);
|
||||
grub_free (old);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The variable does not exist, create it. */
|
||||
env = pupa_malloc (sizeof (struct pupa_env_var));
|
||||
env = grub_malloc (sizeof (struct grub_env_var));
|
||||
if (! env)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
pupa_memset (env, 0, sizeof (struct pupa_env_var));
|
||||
grub_memset (env, 0, sizeof (struct grub_env_var));
|
||||
|
||||
env->name = pupa_strdup (var);
|
||||
env->name = grub_strdup (var);
|
||||
if (! env->name)
|
||||
goto fail;
|
||||
|
||||
env->value = pupa_strdup (val);
|
||||
env->value = grub_strdup (val);
|
||||
if (! env->name)
|
||||
goto fail;
|
||||
|
||||
/* Insert it in the hashtable. */
|
||||
env->prevp = &pupa_env[idx];
|
||||
env->next = pupa_env[idx];
|
||||
if (pupa_env[idx])
|
||||
pupa_env[idx]->prevp = &env->next;
|
||||
pupa_env[idx] = env;
|
||||
env->prevp = &grub_env[idx];
|
||||
env->next = grub_env[idx];
|
||||
if (grub_env[idx])
|
||||
grub_env[idx]->prevp = &env->next;
|
||||
grub_env[idx] = env;
|
||||
|
||||
/* Insert it in the sorted list. */
|
||||
sortp = &pupa_env_sorted;
|
||||
sort = pupa_env_sorted;
|
||||
sortp = &grub_env_sorted;
|
||||
sort = grub_env_sorted;
|
||||
while (sort)
|
||||
{
|
||||
if (pupa_strcmp (sort->name, var) > 0)
|
||||
if (grub_strcmp (sort->name, var) > 0)
|
||||
break;
|
||||
|
||||
sortp = &sort->sort_next;
|
||||
|
@ -122,21 +122,21 @@ pupa_env_set (const char *var, const char *val)
|
|||
*sortp = env;
|
||||
|
||||
fail:
|
||||
if (pupa_errno)
|
||||
if (grub_errno)
|
||||
{
|
||||
pupa_free (env->name);
|
||||
pupa_free (env->value);
|
||||
pupa_free (env);
|
||||
grub_free (env->name);
|
||||
grub_free (env->value);
|
||||
grub_free (env);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *
|
||||
pupa_env_get (const char *name)
|
||||
grub_env_get (const char *name)
|
||||
{
|
||||
struct pupa_env_var *env;
|
||||
env = pupa_env_find (name);
|
||||
struct grub_env_var *env;
|
||||
env = grub_env_find (name);
|
||||
if (! env)
|
||||
return 0;
|
||||
|
||||
|
@ -152,10 +152,10 @@ pupa_env_get (const char *name)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_env_unset (const char *name)
|
||||
grub_env_unset (const char *name)
|
||||
{
|
||||
struct pupa_env_var *env;
|
||||
env = pupa_env_find (name);
|
||||
struct grub_env_var *env;
|
||||
env = grub_env_find (name);
|
||||
if (! env)
|
||||
return;
|
||||
|
||||
|
@ -172,38 +172,38 @@ pupa_env_unset (const char *name)
|
|||
if (env->sort_next)
|
||||
env->sort_next->sort_prevp = env->sort_prevp;
|
||||
|
||||
pupa_free (env->name);
|
||||
pupa_free (env->value);
|
||||
pupa_free (env);
|
||||
grub_free (env->name);
|
||||
grub_free (env->value);
|
||||
grub_free (env);
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_env_iterate (int (* func) (struct pupa_env_var *var))
|
||||
grub_env_iterate (int (* func) (struct grub_env_var *var))
|
||||
{
|
||||
struct pupa_env_var *env;
|
||||
struct grub_env_var *env;
|
||||
|
||||
for (env = pupa_env_sorted; env; env = env->sort_next)
|
||||
for (env = grub_env_sorted; env; env = env->sort_next)
|
||||
if (func (env))
|
||||
return;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_register_variable_hook (const char *var,
|
||||
pupa_err_t (*read_hook) (struct pupa_env_var *var, char **),
|
||||
pupa_err_t (*write_hook) (struct pupa_env_var *var))
|
||||
grub_err_t
|
||||
grub_register_variable_hook (const char *var,
|
||||
grub_err_t (*read_hook) (struct grub_env_var *var, char **),
|
||||
grub_err_t (*write_hook) (struct grub_env_var *var))
|
||||
{
|
||||
struct pupa_env_var *env = pupa_env_find (var);
|
||||
struct grub_env_var *env = grub_env_find (var);
|
||||
|
||||
if (! env)
|
||||
if (pupa_env_set (var, "") != PUPA_ERR_NONE)
|
||||
return pupa_errno;
|
||||
if (grub_env_set (var, "") != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
env = pupa_env_find (var);
|
||||
env = grub_env_find (var);
|
||||
/* XXX Insert an assertion? */
|
||||
|
||||
env->read_hook = read_hook;
|
||||
env->write_hook = write_hook;
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
36
kern/err.c
36
kern/err.c
|
@ -1,9 +1,9 @@
|
|||
/* err.c - error handling routines */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,48 +14,48 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define PUPA_MAX_ERRMSG 256
|
||||
#define GRUB_MAX_ERRMSG 256
|
||||
|
||||
pupa_err_t pupa_errno;
|
||||
char pupa_errmsg[PUPA_MAX_ERRMSG];
|
||||
grub_err_t grub_errno;
|
||||
char grub_errmsg[GRUB_MAX_ERRMSG];
|
||||
|
||||
pupa_err_t
|
||||
pupa_error (pupa_err_t n, const char *fmt, ...)
|
||||
grub_err_t
|
||||
grub_error (grub_err_t n, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
pupa_errno = n;
|
||||
grub_errno = n;
|
||||
|
||||
va_start (ap, fmt);
|
||||
pupa_vsprintf (pupa_errmsg, fmt, ap);
|
||||
grub_vsprintf (grub_errmsg, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_fatal (const char *fmt, ...)
|
||||
grub_fatal (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start (ap, fmt);
|
||||
pupa_vprintf (fmt, ap);
|
||||
grub_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
pupa_stop ();
|
||||
grub_stop ();
|
||||
}
|
||||
|
||||
void
|
||||
pupa_print_error (void)
|
||||
grub_print_error (void)
|
||||
{
|
||||
if (pupa_errno != PUPA_ERR_NONE)
|
||||
pupa_printf ("error: %s\n", pupa_errmsg);
|
||||
if (grub_errno != GRUB_ERR_NONE)
|
||||
grub_printf ("error: %s\n", grub_errmsg);
|
||||
}
|
||||
|
|
84
kern/file.c
84
kern/file.c
|
@ -1,9 +1,9 @@
|
|||
/* file.c - file I/O functions */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,37 +14,37 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/file.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/fs.h>
|
||||
#include <pupa/device.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/device.h>
|
||||
|
||||
/* Get the device part of the filename NAME. It is enclosed by parentheses. */
|
||||
char *
|
||||
pupa_file_get_device_name (const char *name)
|
||||
grub_file_get_device_name (const char *name)
|
||||
{
|
||||
if (name[0] == '(')
|
||||
{
|
||||
char *p = pupa_strchr (name, ')');
|
||||
char *p = grub_strchr (name, ')');
|
||||
char *ret;
|
||||
|
||||
if (! p)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_FILENAME, "missing `)'");
|
||||
grub_error (GRUB_ERR_BAD_FILENAME, "missing `)'");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = (char *) pupa_malloc (p - name);
|
||||
ret = (char *) grub_malloc (p - name);
|
||||
if (! ret)
|
||||
return 0;
|
||||
|
||||
pupa_memcpy (ret, name + 1, p - name - 1);
|
||||
grub_memcpy (ret, name + 1, p - name - 1);
|
||||
ret[p - name - 1] = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
@ -52,31 +52,31 @@ pupa_file_get_device_name (const char *name)
|
|||
return 0;
|
||||
}
|
||||
|
||||
pupa_file_t
|
||||
pupa_file_open (const char *name)
|
||||
grub_file_t
|
||||
grub_file_open (const char *name)
|
||||
{
|
||||
pupa_device_t device;
|
||||
pupa_file_t file = 0;
|
||||
grub_device_t device;
|
||||
grub_file_t file = 0;
|
||||
char *device_name;
|
||||
char *file_name;
|
||||
|
||||
device_name = pupa_file_get_device_name (name);
|
||||
if (pupa_errno)
|
||||
device_name = grub_file_get_device_name (name);
|
||||
if (grub_errno)
|
||||
return 0;
|
||||
|
||||
/* Get the file part of NAME. */
|
||||
file_name = pupa_strchr (name, ')');
|
||||
file_name = grub_strchr (name, ')');
|
||||
if (file_name)
|
||||
file_name++;
|
||||
else
|
||||
file_name = (char *) name;
|
||||
|
||||
device = pupa_device_open (device_name);
|
||||
pupa_free (device_name);
|
||||
device = grub_device_open (device_name);
|
||||
grub_free (device_name);
|
||||
if (! device)
|
||||
goto fail;
|
||||
|
||||
file = (pupa_file_t) pupa_malloc (sizeof (*file));
|
||||
file = (grub_file_t) grub_malloc (sizeof (*file));
|
||||
if (! file)
|
||||
goto fail;
|
||||
|
||||
|
@ -87,34 +87,34 @@ pupa_file_open (const char *name)
|
|||
|
||||
if (device->disk && file_name[0] != '/')
|
||||
/* This is a block list. */
|
||||
file->fs = &pupa_fs_blocklist;
|
||||
file->fs = &grub_fs_blocklist;
|
||||
else
|
||||
{
|
||||
file->fs = pupa_fs_probe (device);
|
||||
file->fs = grub_fs_probe (device);
|
||||
if (! file->fs)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if ((file->fs->open) (file, file_name) != PUPA_ERR_NONE)
|
||||
if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE)
|
||||
goto fail;
|
||||
|
||||
return file;
|
||||
|
||||
fail:
|
||||
if (device)
|
||||
pupa_device_close (device);
|
||||
grub_device_close (device);
|
||||
|
||||
/* if (net) pupa_net_close (net); */
|
||||
/* if (net) grub_net_close (net); */
|
||||
|
||||
pupa_free (file);
|
||||
grub_free (file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pupa_ssize_t
|
||||
pupa_file_read (pupa_file_t file, char *buf, pupa_ssize_t len)
|
||||
grub_ssize_t
|
||||
grub_file_read (grub_file_t file, char *buf, grub_ssize_t len)
|
||||
{
|
||||
pupa_ssize_t res;
|
||||
grub_ssize_t res;
|
||||
|
||||
if (len == 0 || len > file->size - file->offset)
|
||||
len = file->size - file->offset;
|
||||
|
@ -129,25 +129,25 @@ pupa_file_read (pupa_file_t file, char *buf, pupa_ssize_t len)
|
|||
return res;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_file_close (pupa_file_t file)
|
||||
grub_err_t
|
||||
grub_file_close (grub_file_t file)
|
||||
{
|
||||
if (file->fs->close)
|
||||
(file->fs->close) (file);
|
||||
|
||||
pupa_device_close (file->device);
|
||||
pupa_free (file);
|
||||
return pupa_errno;
|
||||
grub_device_close (file->device);
|
||||
grub_free (file);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
pupa_ssize_t
|
||||
pupa_file_seek (pupa_file_t file, pupa_ssize_t offset)
|
||||
grub_ssize_t
|
||||
grub_file_seek (grub_file_t file, grub_ssize_t offset)
|
||||
{
|
||||
pupa_ssize_t old;
|
||||
grub_ssize_t old;
|
||||
|
||||
if (offset < 0 || offset >= file->size)
|
||||
{
|
||||
pupa_error (PUPA_ERR_OUT_OF_RANGE,
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE,
|
||||
"attempt to seek outside of the file");
|
||||
return -1;
|
||||
}
|
||||
|
|
132
kern/fs.c
132
kern/fs.c
|
@ -1,9 +1,9 @@
|
|||
/* fs.c - filesystem manager */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,35 +14,35 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/net.h>
|
||||
#include <pupa/fs.h>
|
||||
#include <pupa/file.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/term.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/net.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/term.h>
|
||||
|
||||
static pupa_fs_t pupa_fs_list;
|
||||
static grub_fs_t grub_fs_list;
|
||||
|
||||
void
|
||||
pupa_fs_register (pupa_fs_t fs)
|
||||
grub_fs_register (grub_fs_t fs)
|
||||
{
|
||||
fs->next = pupa_fs_list;
|
||||
pupa_fs_list = fs;
|
||||
fs->next = grub_fs_list;
|
||||
grub_fs_list = fs;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_fs_unregister (pupa_fs_t fs)
|
||||
grub_fs_unregister (grub_fs_t fs)
|
||||
{
|
||||
pupa_fs_t *p, q;
|
||||
grub_fs_t *p, q;
|
||||
|
||||
for (p = &pupa_fs_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
for (p = &grub_fs_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (q == fs)
|
||||
{
|
||||
*p = q->next;
|
||||
|
@ -51,19 +51,19 @@ pupa_fs_unregister (pupa_fs_t fs)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_fs_iterate (int (*hook) (const pupa_fs_t fs))
|
||||
grub_fs_iterate (int (*hook) (const grub_fs_t fs))
|
||||
{
|
||||
pupa_fs_t p;
|
||||
grub_fs_t p;
|
||||
|
||||
for (p = pupa_fs_list; p; p = p->next)
|
||||
for (p = grub_fs_list; p; p = p->next)
|
||||
if (hook (p))
|
||||
break;
|
||||
}
|
||||
|
||||
pupa_fs_t
|
||||
pupa_fs_probe (pupa_device_t device)
|
||||
grub_fs_t
|
||||
grub_fs_probe (grub_device_t device)
|
||||
{
|
||||
pupa_fs_t p;
|
||||
grub_fs_t p;
|
||||
auto int dummy_func (const char *filename, int dir);
|
||||
|
||||
int dummy_func (const char *filename __attribute__ ((unused)),
|
||||
|
@ -74,22 +74,22 @@ pupa_fs_probe (pupa_device_t device)
|
|||
|
||||
if (device->disk)
|
||||
{
|
||||
for (p = pupa_fs_list; p; p = p->next)
|
||||
for (p = grub_fs_list; p; p = p->next)
|
||||
{
|
||||
(p->dir) (device, "/", dummy_func);
|
||||
if (pupa_errno == PUPA_ERR_NONE)
|
||||
if (grub_errno == GRUB_ERR_NONE)
|
||||
return p;
|
||||
|
||||
if (pupa_errno != PUPA_ERR_BAD_FS)
|
||||
if (grub_errno != GRUB_ERR_BAD_FS)
|
||||
return 0;
|
||||
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
}
|
||||
else if (device->net->fs)
|
||||
return device->net->fs;
|
||||
|
||||
pupa_error (PUPA_ERR_UNKNOWN_FS, "unknown filesystem");
|
||||
grub_error (GRUB_ERR_UNKNOWN_FS, "unknown filesystem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -97,31 +97,31 @@ pupa_fs_probe (pupa_device_t device)
|
|||
|
||||
/* Block list support routines. */
|
||||
|
||||
struct pupa_fs_block
|
||||
struct grub_fs_block
|
||||
{
|
||||
unsigned long offset;
|
||||
unsigned long length;
|
||||
};
|
||||
|
||||
static pupa_err_t
|
||||
pupa_fs_blocklist_open (pupa_file_t file, const char *name)
|
||||
static grub_err_t
|
||||
grub_fs_blocklist_open (grub_file_t file, const char *name)
|
||||
{
|
||||
char *p = (char *) name;
|
||||
unsigned num = 0;
|
||||
unsigned i;
|
||||
pupa_disk_t disk = file->device->disk;
|
||||
struct pupa_fs_block *blocks;
|
||||
grub_disk_t disk = file->device->disk;
|
||||
struct grub_fs_block *blocks;
|
||||
|
||||
/* First, count the number of blocks. */
|
||||
do
|
||||
{
|
||||
num++;
|
||||
p = pupa_strchr (p, ',');
|
||||
p = grub_strchr (p, ',');
|
||||
}
|
||||
while (p);
|
||||
|
||||
/* Allocate a block list. */
|
||||
blocks = pupa_malloc (sizeof (struct pupa_fs_block) * (num + 1));
|
||||
blocks = grub_malloc (sizeof (struct grub_fs_block) * (num + 1));
|
||||
if (! blocks)
|
||||
return 0;
|
||||
|
||||
|
@ -131,10 +131,10 @@ pupa_fs_blocklist_open (pupa_file_t file, const char *name)
|
|||
{
|
||||
if (*p != '+')
|
||||
{
|
||||
blocks[i].offset = pupa_strtoul (p, &p, 0);
|
||||
if (pupa_errno != PUPA_ERR_NONE || *p != '+')
|
||||
blocks[i].offset = grub_strtoul (p, &p, 0);
|
||||
if (grub_errno != GRUB_ERR_NONE || *p != '+')
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_FILENAME,
|
||||
grub_error (GRUB_ERR_BAD_FILENAME,
|
||||
"invalid file name `%s'", name);
|
||||
goto fail;
|
||||
}
|
||||
|
@ -143,68 +143,68 @@ pupa_fs_blocklist_open (pupa_file_t file, const char *name)
|
|||
blocks[i].offset = 0;
|
||||
|
||||
p++;
|
||||
blocks[i].length = pupa_strtoul (p, &p, 0);
|
||||
if (pupa_errno != PUPA_ERR_NONE
|
||||
blocks[i].length = grub_strtoul (p, &p, 0);
|
||||
if (grub_errno != GRUB_ERR_NONE
|
||||
|| blocks[i].length == 0
|
||||
|| (*p && *p != ',' && ! pupa_isspace (*p)))
|
||||
|| (*p && *p != ',' && ! grub_isspace (*p)))
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_FILENAME,
|
||||
grub_error (GRUB_ERR_BAD_FILENAME,
|
||||
"invalid file name `%s'", name);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (disk->total_sectors < blocks[i].offset + blocks[i].length)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_FILENAME, "beyond the total sectors");
|
||||
grub_error (GRUB_ERR_BAD_FILENAME, "beyond the total sectors");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
file->size += (blocks[i].length << PUPA_DISK_SECTOR_BITS);
|
||||
file->size += (blocks[i].length << GRUB_DISK_SECTOR_BITS);
|
||||
p++;
|
||||
}
|
||||
|
||||
blocks[i].length = 0;
|
||||
file->data = blocks;
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
|
||||
fail:
|
||||
pupa_free (blocks);
|
||||
return pupa_errno;
|
||||
grub_free (blocks);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
static pupa_ssize_t
|
||||
pupa_fs_blocklist_read (pupa_file_t file, char *buf, pupa_ssize_t len)
|
||||
static grub_ssize_t
|
||||
grub_fs_blocklist_read (grub_file_t file, char *buf, grub_ssize_t len)
|
||||
{
|
||||
struct pupa_fs_block *p;
|
||||
struct grub_fs_block *p;
|
||||
unsigned long sector;
|
||||
unsigned long offset;
|
||||
pupa_ssize_t ret = 0;
|
||||
grub_ssize_t ret = 0;
|
||||
|
||||
if (len > file->size - file->offset)
|
||||
len = file->size - file->offset;
|
||||
|
||||
sector = (file->offset >> PUPA_DISK_SECTOR_BITS);
|
||||
offset = (file->offset & (PUPA_DISK_SECTOR_SIZE - 1));
|
||||
sector = (file->offset >> GRUB_DISK_SECTOR_BITS);
|
||||
offset = (file->offset & (GRUB_DISK_SECTOR_SIZE - 1));
|
||||
for (p = file->data; p->length && len > 0; p++)
|
||||
{
|
||||
if (sector < p->length)
|
||||
{
|
||||
pupa_ssize_t size;
|
||||
grub_ssize_t size;
|
||||
|
||||
size = len;
|
||||
if (((size + offset + PUPA_DISK_SECTOR_SIZE - 1)
|
||||
>> PUPA_DISK_SECTOR_BITS) > p->length - sector)
|
||||
size = ((p->length - sector) << PUPA_DISK_SECTOR_BITS) - offset;
|
||||
if (((size + offset + GRUB_DISK_SECTOR_SIZE - 1)
|
||||
>> GRUB_DISK_SECTOR_BITS) > p->length - sector)
|
||||
size = ((p->length - sector) << GRUB_DISK_SECTOR_BITS) - offset;
|
||||
|
||||
if (pupa_disk_read (file->device->disk, p->offset + sector, offset,
|
||||
size, buf) != PUPA_ERR_NONE)
|
||||
if (grub_disk_read (file->device->disk, p->offset + sector, offset,
|
||||
size, buf) != GRUB_ERR_NONE)
|
||||
return -1;
|
||||
|
||||
ret += size;
|
||||
len -= size;
|
||||
sector -= ((size + offset) >> PUPA_DISK_SECTOR_BITS);
|
||||
offset = ((size + offset) & (PUPA_DISK_SECTOR_SIZE - 1));
|
||||
sector -= ((size + offset) >> GRUB_DISK_SECTOR_BITS);
|
||||
offset = ((size + offset) & (GRUB_DISK_SECTOR_SIZE - 1));
|
||||
}
|
||||
else
|
||||
sector -= p->length;
|
||||
|
@ -213,12 +213,12 @@ pupa_fs_blocklist_read (pupa_file_t file, char *buf, pupa_ssize_t len)
|
|||
return ret;
|
||||
}
|
||||
|
||||
struct pupa_fs pupa_fs_blocklist =
|
||||
struct grub_fs grub_fs_blocklist =
|
||||
{
|
||||
.name = "blocklist",
|
||||
.dir = 0,
|
||||
.open = pupa_fs_blocklist_open,
|
||||
.read = pupa_fs_blocklist_read,
|
||||
.open = grub_fs_blocklist_open,
|
||||
.read = grub_fs_blocklist_read,
|
||||
.close = 0,
|
||||
.next = 0
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/* dl-386.c - arch-dependent part of loadable module support */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,18 +14,18 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/elf.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/elf.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/err.h>
|
||||
|
||||
/* Check if EHDR is a valid ELF header. */
|
||||
int
|
||||
pupa_arch_dl_check_header (void *ehdr, unsigned size)
|
||||
grub_arch_dl_check_header (void *ehdr, unsigned size)
|
||||
{
|
||||
Elf32_Ehdr *e = ehdr;
|
||||
|
||||
|
@ -53,8 +53,8 @@ pupa_arch_dl_check_header (void *ehdr, unsigned size)
|
|||
}
|
||||
|
||||
/* Relocate symbols. */
|
||||
pupa_err_t
|
||||
pupa_arch_dl_relocate_symbols (pupa_dl_t mod, void *ehdr)
|
||||
grub_err_t
|
||||
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
|
||||
{
|
||||
Elf32_Ehdr *e = ehdr;
|
||||
Elf32_Shdr *s;
|
||||
|
@ -70,7 +70,7 @@ pupa_arch_dl_relocate_symbols (pupa_dl_t mod, void *ehdr)
|
|||
break;
|
||||
|
||||
if (i == e->e_shnum)
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE, "no symtab found");
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found");
|
||||
|
||||
symtab = (Elf32_Sym *) ((char *) e + s->sh_offset);
|
||||
entsize = s->sh_entsize;
|
||||
|
@ -80,7 +80,7 @@ pupa_arch_dl_relocate_symbols (pupa_dl_t mod, void *ehdr)
|
|||
i++, s = (Elf32_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (s->sh_type == SHT_REL)
|
||||
{
|
||||
pupa_dl_segment_t seg;
|
||||
grub_dl_segment_t seg;
|
||||
|
||||
/* Find the target segment. */
|
||||
for (seg = mod->segment; seg; seg = seg->next)
|
||||
|
@ -100,7 +100,7 @@ pupa_arch_dl_relocate_symbols (pupa_dl_t mod, void *ehdr)
|
|||
Elf32_Sym *sym;
|
||||
|
||||
if (seg->size < rel->r_offset)
|
||||
return pupa_error (PUPA_ERR_BAD_MODULE,
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"reloc offset is out of the segment");
|
||||
|
||||
addr = (Elf32_Word *) ((char *) seg->addr + rel->r_offset);
|
||||
|
@ -122,5 +122,5 @@ pupa_arch_dl_relocate_symbols (pupa_dl_t mod, void *ehdr)
|
|||
}
|
||||
}
|
||||
|
||||
return PUPA_ERR_NONE;
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -17,24 +17,24 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/kernel.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/machine/init.h>
|
||||
#include <pupa/machine/memory.h>
|
||||
#include <pupa/machine/console.h>
|
||||
#include <pupa/machine/biosdisk.h>
|
||||
#include <pupa/machine/kernel.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/loader.h>
|
||||
#include <pupa/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/machine/init.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/machine/biosdisk.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
struct mem_region
|
||||
{
|
||||
pupa_addr_t addr;
|
||||
pupa_size_t size;
|
||||
grub_addr_t addr;
|
||||
grub_size_t size;
|
||||
};
|
||||
|
||||
#define MAX_REGIONS 32
|
||||
|
@ -42,9 +42,9 @@ struct mem_region
|
|||
static struct mem_region mem_regions[MAX_REGIONS];
|
||||
static int num_regions;
|
||||
|
||||
pupa_addr_t pupa_os_area_addr;
|
||||
pupa_size_t pupa_os_area_size;
|
||||
pupa_size_t pupa_lower_mem, pupa_upper_mem;
|
||||
grub_addr_t grub_os_area_addr;
|
||||
grub_size_t grub_os_area_size;
|
||||
grub_size_t grub_lower_mem, grub_upper_mem;
|
||||
|
||||
static char *
|
||||
make_install_device (void)
|
||||
|
@ -52,25 +52,25 @@ make_install_device (void)
|
|||
/* XXX: This should be enough. */
|
||||
char dev[100];
|
||||
|
||||
pupa_sprintf (dev, "(%cd%u",
|
||||
(pupa_boot_drive & 0x80) ? 'h' : 'f',
|
||||
pupa_boot_drive & 0x7f);
|
||||
grub_sprintf (dev, "(%cd%u",
|
||||
(grub_boot_drive & 0x80) ? 'h' : 'f',
|
||||
grub_boot_drive & 0x7f);
|
||||
|
||||
if (pupa_install_dos_part >= 0)
|
||||
pupa_sprintf (dev + pupa_strlen (dev), ",%u", pupa_install_dos_part);
|
||||
if (grub_install_dos_part >= 0)
|
||||
grub_sprintf (dev + grub_strlen (dev), ",%u", grub_install_dos_part);
|
||||
|
||||
if (pupa_install_bsd_part >= 0)
|
||||
pupa_sprintf (dev + pupa_strlen (dev), ",%c", pupa_install_bsd_part + 'a');
|
||||
if (grub_install_bsd_part >= 0)
|
||||
grub_sprintf (dev + grub_strlen (dev), ",%c", grub_install_bsd_part + 'a');
|
||||
|
||||
pupa_sprintf (dev + pupa_strlen (dev), ")%s", pupa_prefix);
|
||||
pupa_strcpy (pupa_prefix, dev);
|
||||
grub_sprintf (dev + grub_strlen (dev), ")%s", grub_prefix);
|
||||
grub_strcpy (grub_prefix, dev);
|
||||
|
||||
return pupa_prefix;
|
||||
return grub_prefix;
|
||||
}
|
||||
|
||||
/* Add a memory region. */
|
||||
static void
|
||||
add_mem_region (pupa_addr_t addr, pupa_size_t size)
|
||||
add_mem_region (grub_addr_t addr, grub_size_t size)
|
||||
{
|
||||
if (num_regions == MAX_REGIONS)
|
||||
/* Ignore. */
|
||||
|
@ -108,44 +108,44 @@ compact_mem_regions (void)
|
|||
mem_regions[i].size = (mem_regions[j].addr + mem_regions[j].size
|
||||
- mem_regions[i].addr);
|
||||
|
||||
pupa_memmove (mem_regions + j, mem_regions + j + 1,
|
||||
grub_memmove (mem_regions + j, mem_regions + j + 1,
|
||||
(num_regions - j - 1) * sizeof (struct mem_region));
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pupa_machine_init (void)
|
||||
grub_machine_init (void)
|
||||
{
|
||||
pupa_uint32_t cont;
|
||||
struct pupa_machine_mmap_entry *entry
|
||||
= (struct pupa_machine_mmap_entry *) PUPA_MEMORY_MACHINE_SCRATCH_ADDR;
|
||||
pupa_addr_t end_addr = pupa_get_end_addr ();
|
||||
grub_uint32_t cont;
|
||||
struct grub_machine_mmap_entry *entry
|
||||
= (struct grub_machine_mmap_entry *) GRUB_MEMORY_MACHINE_SCRATCH_ADDR;
|
||||
grub_addr_t end_addr = grub_get_end_addr ();
|
||||
int i;
|
||||
|
||||
/* Initialize the console as early as possible. */
|
||||
pupa_console_init ();
|
||||
grub_console_init ();
|
||||
|
||||
pupa_lower_mem = pupa_get_memsize (0) << 10;
|
||||
grub_lower_mem = grub_get_memsize (0) << 10;
|
||||
|
||||
/* Sanity check. */
|
||||
if (pupa_lower_mem < PUPA_MEMORY_MACHINE_RESERVED_END)
|
||||
pupa_fatal ("too small memory");
|
||||
if (grub_lower_mem < GRUB_MEMORY_MACHINE_RESERVED_END)
|
||||
grub_fatal ("too small memory");
|
||||
|
||||
#if 0
|
||||
/* Turn on Gate A20 to access >1MB. */
|
||||
pupa_gate_a20 (1);
|
||||
grub_gate_a20 (1);
|
||||
#endif
|
||||
|
||||
/* Add the lower memory into free memory. */
|
||||
if (pupa_lower_mem >= PUPA_MEMORY_MACHINE_RESERVED_END)
|
||||
add_mem_region (PUPA_MEMORY_MACHINE_RESERVED_END,
|
||||
pupa_lower_mem - PUPA_MEMORY_MACHINE_RESERVED_END);
|
||||
if (grub_lower_mem >= GRUB_MEMORY_MACHINE_RESERVED_END)
|
||||
add_mem_region (GRUB_MEMORY_MACHINE_RESERVED_END,
|
||||
grub_lower_mem - GRUB_MEMORY_MACHINE_RESERVED_END);
|
||||
|
||||
add_mem_region (end_addr, PUPA_MEMORY_MACHINE_RESERVED_START - end_addr);
|
||||
add_mem_region (end_addr, GRUB_MEMORY_MACHINE_RESERVED_START - end_addr);
|
||||
|
||||
/* Check if pupa_get_mmap_entry works. */
|
||||
cont = pupa_get_mmap_entry (entry, 0);
|
||||
/* Check if grub_get_mmap_entry works. */
|
||||
cont = grub_get_mmap_entry (entry, 0);
|
||||
|
||||
if (entry->size)
|
||||
do
|
||||
|
@ -163,13 +163,13 @@ pupa_machine_init (void)
|
|||
/* Ignore >4GB. */
|
||||
if (entry->addr <= 0xFFFFFFFF && entry->type == 1)
|
||||
{
|
||||
pupa_addr_t addr;
|
||||
pupa_size_t len;
|
||||
grub_addr_t addr;
|
||||
grub_size_t len;
|
||||
|
||||
addr = (pupa_addr_t) entry->addr;
|
||||
addr = (grub_addr_t) entry->addr;
|
||||
len = ((addr + entry->len > 0xFFFFFFFF)
|
||||
? 0xFFFFFFFF - addr
|
||||
: (pupa_size_t) entry->len);
|
||||
: (grub_size_t) entry->len);
|
||||
add_mem_region (addr, len);
|
||||
}
|
||||
|
||||
|
@ -177,12 +177,12 @@ pupa_machine_init (void)
|
|||
if (! cont)
|
||||
break;
|
||||
|
||||
cont = pupa_get_mmap_entry (entry, cont);
|
||||
cont = grub_get_mmap_entry (entry, cont);
|
||||
}
|
||||
while (entry->size);
|
||||
else
|
||||
{
|
||||
pupa_uint32_t eisa_mmap = pupa_get_eisa_mmap ();
|
||||
grub_uint32_t eisa_mmap = grub_get_eisa_mmap ();
|
||||
|
||||
if (eisa_mmap)
|
||||
{
|
||||
|
@ -195,7 +195,7 @@ pupa_machine_init (void)
|
|||
}
|
||||
}
|
||||
else
|
||||
add_mem_region (0x100000, pupa_get_memsize (1) << 10);
|
||||
add_mem_region (0x100000, grub_get_memsize (1) << 10);
|
||||
}
|
||||
|
||||
compact_mem_regions ();
|
||||
|
@ -206,24 +206,24 @@ pupa_machine_init (void)
|
|||
for (i = 0; i < num_regions; i++)
|
||||
if (mem_regions[i].addr == 0x100000)
|
||||
{
|
||||
pupa_size_t quarter = mem_regions[i].size >> 2;
|
||||
grub_size_t quarter = mem_regions[i].size >> 2;
|
||||
|
||||
pupa_upper_mem = mem_regions[i].size;
|
||||
pupa_os_area_addr = mem_regions[i].addr;
|
||||
pupa_os_area_size = mem_regions[i].size - quarter;
|
||||
pupa_mm_init_region ((void *) (pupa_os_area_addr + pupa_os_area_size),
|
||||
grub_upper_mem = mem_regions[i].size;
|
||||
grub_os_area_addr = mem_regions[i].addr;
|
||||
grub_os_area_size = mem_regions[i].size - quarter;
|
||||
grub_mm_init_region ((void *) (grub_os_area_addr + grub_os_area_size),
|
||||
quarter);
|
||||
}
|
||||
else
|
||||
pupa_mm_init_region ((void *) mem_regions[i].addr, mem_regions[i].size);
|
||||
grub_mm_init_region ((void *) mem_regions[i].addr, mem_regions[i].size);
|
||||
|
||||
if (! pupa_os_area_addr)
|
||||
pupa_fatal ("no upper memory");
|
||||
if (! grub_os_area_addr)
|
||||
grub_fatal ("no upper memory");
|
||||
|
||||
/* The memory system was initialized, thus register built-in devices. */
|
||||
pupa_biosdisk_init ();
|
||||
grub_biosdisk_init ();
|
||||
|
||||
|
||||
/* Initialize the prefix. */
|
||||
pupa_env_set ("prefix", make_install_device ());
|
||||
grub_env_set ("prefix", make_install_device ());
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
|
||||
* Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
|
@ -21,7 +21,7 @@
|
|||
/*
|
||||
* This code was stolen from the files enter.sh, leave.sh, lzo1x_d.sh,
|
||||
* lzo1x_f.s and lzo_asm.h in LZO version 1.08, and was heavily modified
|
||||
* to adapt it to PUPA's requirement.
|
||||
* to adapt it to GRUB's requirement.
|
||||
*
|
||||
* See <http://www.oberhumer.com/opensource/lzo/>, for more information
|
||||
* about LZO.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -35,7 +35,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Note: PUPA is compiled with the options -mrtd and -mregparm=3.
|
||||
* Note: GRUB is compiled with the options -mrtd and -mregparm=3.
|
||||
* So the first three arguments are passed in %eax, %edx, and %ecx,
|
||||
* respectively, and if a function has a fixed number of arguments
|
||||
* and the number if greater than three, the function must return
|
||||
|
@ -43,16 +43,16 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <pupa/symbol.h>
|
||||
#include <pupa/boot.h>
|
||||
#include <pupa/machine/boot.h>
|
||||
#include <pupa/machine/memory.h>
|
||||
#include <pupa/machine/console.h>
|
||||
#include <pupa/machine/linux.h>
|
||||
#include <pupa/machine/kernel.h>
|
||||
#include <pupa/machine/multiboot.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/boot.h>
|
||||
#include <grub/machine/boot.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/machine/console.h>
|
||||
#include <grub/machine/linux.h>
|
||||
#include <grub/machine/kernel.h>
|
||||
#include <grub/machine/multiboot.h>
|
||||
|
||||
#define ABS(x) ((x) - EXT_C(start) + PUPA_BOOT_MACHINE_KERNEL_ADDR + 0x200)
|
||||
#define ABS(x) ((x) - EXT_C(start) + GRUB_BOOT_MACHINE_KERNEL_ADDR + 0x200)
|
||||
|
||||
.file "startup.S"
|
||||
|
||||
|
@ -77,7 +77,7 @@ _start:
|
|||
* DO NOT MOVE !!!
|
||||
*/
|
||||
. = EXT_C(start) + 0x6
|
||||
.byte PUPA_BOOT_VERSION_MAJOR, PUPA_BOOT_VERSION_MINOR
|
||||
.byte GRUB_BOOT_VERSION_MAJOR, GRUB_BOOT_VERSION_MINOR
|
||||
|
||||
/*
|
||||
* This is a special data area 8 bytes from the beginning.
|
||||
|
@ -85,18 +85,18 @@ _start:
|
|||
|
||||
. = EXT_C(start) + 0x8
|
||||
|
||||
VARIABLE(pupa_total_module_size)
|
||||
VARIABLE(grub_total_module_size)
|
||||
.long 0
|
||||
VARIABLE(pupa_kernel_image_size)
|
||||
VARIABLE(grub_kernel_image_size)
|
||||
.long 0
|
||||
VARIABLE(pupa_compressed_size)
|
||||
VARIABLE(grub_compressed_size)
|
||||
.long 0
|
||||
VARIABLE(pupa_install_dos_part)
|
||||
VARIABLE(grub_install_dos_part)
|
||||
.long 0xFFFFFFFF
|
||||
VARIABLE(pupa_install_bsd_part)
|
||||
VARIABLE(grub_install_bsd_part)
|
||||
.long 0xFFFFFFFF
|
||||
VARIABLE(pupa_prefix)
|
||||
.string "/boot/pupa"
|
||||
VARIABLE(grub_prefix)
|
||||
.string "/boot/grub"
|
||||
|
||||
/*
|
||||
* Leave some breathing room for the prefix.
|
||||
|
@ -115,13 +115,13 @@ codestart:
|
|||
movw %ax, %es
|
||||
|
||||
/* set up the real mode/BIOS stack */
|
||||
movl $PUPA_MEMORY_MACHINE_REAL_STACK, %ebp
|
||||
movl $GRUB_MEMORY_MACHINE_REAL_STACK, %ebp
|
||||
movl %ebp, %esp
|
||||
|
||||
sti /* we're safe again */
|
||||
|
||||
/* save boot drive reference */
|
||||
ADDR32 movb %dl, EXT_C(pupa_boot_drive)
|
||||
ADDR32 movb %dl, EXT_C(grub_boot_drive)
|
||||
|
||||
/* reset disk system (%ah = 0) */
|
||||
int $0x13
|
||||
|
@ -133,14 +133,14 @@ codestart:
|
|||
.code32
|
||||
|
||||
incl %eax
|
||||
call EXT_C(pupa_gate_a20)
|
||||
call EXT_C(grub_gate_a20)
|
||||
|
||||
/* decompress the compressed part and put the result at 1MB */
|
||||
movl $0x100000, %esi
|
||||
movl $(START_SYMBOL + PUPA_KERNEL_MACHINE_RAW_SIZE), %edi
|
||||
movl $(START_SYMBOL + GRUB_KERNEL_MACHINE_RAW_SIZE), %edi
|
||||
|
||||
pushl %esi
|
||||
pushl EXT_C(pupa_compressed_size)
|
||||
pushl EXT_C(grub_compressed_size)
|
||||
pushl %edi
|
||||
call lzo1x_decompress
|
||||
addl $12, %esp
|
||||
|
@ -152,8 +152,8 @@ codestart:
|
|||
movsb
|
||||
|
||||
/* copy modules before cleaning out the bss */
|
||||
movl EXT_C(pupa_total_module_size), %ecx
|
||||
movl EXT_C(pupa_kernel_image_size), %esi
|
||||
movl EXT_C(grub_total_module_size), %ecx
|
||||
movl EXT_C(grub_kernel_image_size), %esi
|
||||
addl %ecx, %esi
|
||||
addl $START_SYMBOL, %esi
|
||||
decl %esi
|
||||
|
@ -180,7 +180,7 @@ codestart:
|
|||
/*
|
||||
* Call the start of main body of C code.
|
||||
*/
|
||||
call EXT_C(pupa_main)
|
||||
call EXT_C(grub_main)
|
||||
|
||||
|
||||
/*
|
||||
|
@ -190,18 +190,18 @@ codestart:
|
|||
.p2align 2 /* force 4-byte alignment */
|
||||
|
||||
protstack:
|
||||
.long PUPA_MEMORY_MACHINE_PROT_STACK
|
||||
.long GRUB_MEMORY_MACHINE_PROT_STACK
|
||||
|
||||
VARIABLE(pupa_boot_drive)
|
||||
VARIABLE(grub_boot_drive)
|
||||
.long 0
|
||||
|
||||
VARIABLE(pupa_start_addr)
|
||||
VARIABLE(grub_start_addr)
|
||||
.long START_SYMBOL
|
||||
|
||||
VARIABLE(pupa_end_addr)
|
||||
VARIABLE(grub_end_addr)
|
||||
.long END_SYMBOL
|
||||
|
||||
VARIABLE(pupa_apm_bios_info)
|
||||
VARIABLE(grub_apm_bios_info)
|
||||
.word 0 /* version */
|
||||
.word 0 /* cseg */
|
||||
.long 0 /* offset */
|
||||
|
@ -275,16 +275,16 @@ real_to_prot:
|
|||
|
||||
/* turn on protected mode */
|
||||
movl %cr0, %eax
|
||||
orl $PUPA_MEMORY_MACHINE_CR0_PE_ON, %eax
|
||||
orl $GRUB_MEMORY_MACHINE_CR0_PE_ON, %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
/* jump to relocation, flush prefetch queue, and reload %cs */
|
||||
DATA32 ljmp $PUPA_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg
|
||||
DATA32 ljmp $GRUB_MEMORY_MACHINE_PROT_MODE_CSEG, $protcseg
|
||||
|
||||
.code32
|
||||
protcseg:
|
||||
/* reload other segment registers */
|
||||
movw $PUPA_MEMORY_MACHINE_PROT_MODE_DSEG, %ax
|
||||
movw $GRUB_MEMORY_MACHINE_PROT_MODE_DSEG, %ax
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
movw %ax, %fs
|
||||
|
@ -293,7 +293,7 @@ protcseg:
|
|||
|
||||
/* put the return address in a known safe location */
|
||||
movl (%esp), %eax
|
||||
movl %eax, PUPA_MEMORY_MACHINE_REAL_STACK
|
||||
movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK
|
||||
|
||||
/* get protected mode stack */
|
||||
movl protstack, %eax
|
||||
|
@ -301,7 +301,7 @@ protcseg:
|
|||
movl %eax, %ebp
|
||||
|
||||
/* get return address onto the right stack */
|
||||
movl PUPA_MEMORY_MACHINE_REAL_STACK, %eax
|
||||
movl GRUB_MEMORY_MACHINE_REAL_STACK, %eax
|
||||
movl %eax, (%esp)
|
||||
|
||||
/* zero %eax */
|
||||
|
@ -321,15 +321,15 @@ prot_to_real:
|
|||
|
||||
/* get the return address */
|
||||
movl (%esp), %eax
|
||||
movl %eax, PUPA_MEMORY_MACHINE_REAL_STACK
|
||||
movl %eax, GRUB_MEMORY_MACHINE_REAL_STACK
|
||||
|
||||
/* set up new stack */
|
||||
movl $PUPA_MEMORY_MACHINE_REAL_STACK, %eax
|
||||
movl $GRUB_MEMORY_MACHINE_REAL_STACK, %eax
|
||||
movl %eax, %esp
|
||||
movl %eax, %ebp
|
||||
|
||||
/* set up segment limits */
|
||||
movw $PUPA_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax
|
||||
movw $GRUB_MEMORY_MACHINE_PSEUDO_REAL_DSEG, %ax
|
||||
movw %ax, %ds
|
||||
movw %ax, %es
|
||||
movw %ax, %fs
|
||||
|
@ -338,14 +338,14 @@ prot_to_real:
|
|||
|
||||
/* this might be an extra step */
|
||||
/* jump to a 16 bit segment */
|
||||
ljmp $PUPA_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg
|
||||
ljmp $GRUB_MEMORY_MACHINE_PSEUDO_REAL_CSEG, $tmpcseg
|
||||
|
||||
tmpcseg:
|
||||
.code16
|
||||
|
||||
/* clear the PE bit of CR0 */
|
||||
movl %cr0, %eax
|
||||
andl $(~PUPA_MEMORY_MACHINE_CR0_PE_ON), %eax
|
||||
andl $(~GRUB_MEMORY_MACHINE_CR0_PE_ON), %eax
|
||||
movl %eax, %cr0
|
||||
|
||||
/* flush prefetch queue, reload %cs */
|
||||
|
@ -374,7 +374,7 @@ realcseg:
|
|||
|
||||
|
||||
/*
|
||||
* pupa_gate_a20(int on)
|
||||
* grub_gate_a20(int on)
|
||||
*
|
||||
* Gate address-line 20 for high memory.
|
||||
*
|
||||
|
@ -383,7 +383,7 @@ realcseg:
|
|||
* It also eats any keystrokes in the keyboard buffer. :-(
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_gate_a20)
|
||||
FUNCTION(grub_gate_a20)
|
||||
movl %eax, %ecx
|
||||
|
||||
call gloop1
|
||||
|
@ -437,7 +437,7 @@ gloop2ret:
|
|||
* hang at this point!
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_stop)
|
||||
FUNCTION(grub_stop)
|
||||
call prot_to_real
|
||||
|
||||
/*
|
||||
|
@ -446,29 +446,29 @@ FUNCTION(pupa_stop)
|
|||
* mode, so think about it before changing it.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_hard_stop)
|
||||
FUNCTION(grub_hard_stop)
|
||||
hlt
|
||||
jmp EXT_C(pupa_hard_stop)
|
||||
jmp EXT_C(grub_hard_stop)
|
||||
|
||||
|
||||
/*
|
||||
* pupa_stop_floppy()
|
||||
* grub_stop_floppy()
|
||||
*
|
||||
* Stop the floppy drive from spinning, so that other software is
|
||||
* jumped to with a known state.
|
||||
*/
|
||||
FUNCTION(pupa_stop_floppy)
|
||||
FUNCTION(grub_stop_floppy)
|
||||
movw $0x3F2, %dx
|
||||
xorb %al, %al
|
||||
outb %al, %dx
|
||||
ret
|
||||
|
||||
/*
|
||||
* pupa_reboot()
|
||||
* grub_reboot()
|
||||
*
|
||||
* Reboot the system. At the moment, rely on BIOS.
|
||||
*/
|
||||
FUNCTION(pupa_reboot)
|
||||
FUNCTION(grub_reboot)
|
||||
call prot_to_real
|
||||
.code16
|
||||
/* cold boot */
|
||||
|
@ -478,15 +478,15 @@ FUNCTION(pupa_reboot)
|
|||
.code32
|
||||
|
||||
/*
|
||||
* pupa_halt(int no_apm)
|
||||
* grub_halt(int no_apm)
|
||||
*
|
||||
* Halt the system, using APM if possible. If NO_APM is true, don't use
|
||||
* APM even if it is available.
|
||||
*/
|
||||
FUNCTION(pupa_halt)
|
||||
FUNCTION(grub_halt)
|
||||
/* see if zero */
|
||||
testl %eax, %eax
|
||||
jnz EXT_C(pupa_stop)
|
||||
jnz EXT_C(grub_stop)
|
||||
|
||||
call prot_to_real
|
||||
.code16
|
||||
|
@ -495,7 +495,7 @@ FUNCTION(pupa_halt)
|
|||
movw $0x5300, %ax
|
||||
xorw %bx, %bx
|
||||
int $0x15
|
||||
jc EXT_C(pupa_hard_stop)
|
||||
jc EXT_C(grub_hard_stop)
|
||||
/* don't check %bx for buggy BIOSes... */
|
||||
|
||||
/* disconnect APM first */
|
||||
|
@ -507,14 +507,14 @@ FUNCTION(pupa_halt)
|
|||
movw $0x5301, %ax
|
||||
xorw %bx, %bx
|
||||
int $0x15
|
||||
jc EXT_C(pupa_hard_stop)
|
||||
jc EXT_C(grub_hard_stop)
|
||||
|
||||
/* set APM protocol level - 1.1 or bust. (this covers APM 1.2 also) */
|
||||
movw $0x530E, %ax
|
||||
xorw %bx, %bx
|
||||
movw $0x0101, %cx
|
||||
int $0x15
|
||||
jc EXT_C(pupa_hard_stop)
|
||||
jc EXT_C(grub_hard_stop)
|
||||
|
||||
/* set the power state to off */
|
||||
movw $0x5307, %ax
|
||||
|
@ -523,21 +523,21 @@ FUNCTION(pupa_halt)
|
|||
int $0x15
|
||||
|
||||
/* shouldn't reach here */
|
||||
jmp EXT_C(pupa_hard_stop)
|
||||
jmp EXT_C(grub_hard_stop)
|
||||
.code32
|
||||
|
||||
|
||||
/*
|
||||
* void pupa_chainloader_real_boot (int drive, void *part_addr)
|
||||
* void grub_chainloader_real_boot (int drive, void *part_addr)
|
||||
*
|
||||
* This starts another boot loader.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_chainloader_real_boot)
|
||||
FUNCTION(grub_chainloader_real_boot)
|
||||
pushl %edx
|
||||
pushl %eax
|
||||
|
||||
call EXT_C(pupa_dl_unload_all)
|
||||
call EXT_C(grub_dl_unload_all)
|
||||
|
||||
/* set up to pass boot drive */
|
||||
popl %edx
|
||||
|
@ -547,44 +547,44 @@ FUNCTION(pupa_chainloader_real_boot)
|
|||
|
||||
/* Turn off Gate A20 */
|
||||
xorl %eax, %eax
|
||||
call EXT_C(pupa_gate_a20)
|
||||
call EXT_C(grub_gate_a20)
|
||||
|
||||
call prot_to_real
|
||||
.code16
|
||||
ljmp $0, $PUPA_MEMORY_MACHINE_BOOT_LOADER_ADDR
|
||||
ljmp $0, $GRUB_MEMORY_MACHINE_BOOT_LOADER_ADDR
|
||||
.code32
|
||||
|
||||
|
||||
/*
|
||||
* void pupa_linux_boot_zimage (void)
|
||||
* void grub_linux_boot_zimage (void)
|
||||
*/
|
||||
VARIABLE(pupa_linux_prot_size)
|
||||
VARIABLE(grub_linux_prot_size)
|
||||
.long 0
|
||||
VARIABLE(pupa_linux_tmp_addr)
|
||||
VARIABLE(grub_linux_tmp_addr)
|
||||
.long 0
|
||||
VARIABLE(pupa_linux_real_addr)
|
||||
VARIABLE(grub_linux_real_addr)
|
||||
.long 0
|
||||
|
||||
FUNCTION(pupa_linux_boot_zimage)
|
||||
FUNCTION(grub_linux_boot_zimage)
|
||||
/* copy the kernel */
|
||||
movl EXT_C(pupa_linux_prot_size), %ecx
|
||||
movl EXT_C(grub_linux_prot_size), %ecx
|
||||
addl $3, %ecx
|
||||
shrl $2, %ecx
|
||||
movl $PUPA_LINUX_BZIMAGE_ADDR, %esi
|
||||
movl $PUPA_LINUX_ZIMAGE_ADDR, %edi
|
||||
movl $GRUB_LINUX_BZIMAGE_ADDR, %esi
|
||||
movl $GRUB_LINUX_ZIMAGE_ADDR, %edi
|
||||
cld
|
||||
rep
|
||||
movsl
|
||||
|
||||
FUNCTION(pupa_linux_boot_bzimage)
|
||||
call EXT_C(pupa_dl_unload_all)
|
||||
FUNCTION(grub_linux_boot_bzimage)
|
||||
call EXT_C(grub_dl_unload_all)
|
||||
|
||||
movl EXT_C(pupa_linux_real_addr), %ebx
|
||||
movl EXT_C(grub_linux_real_addr), %ebx
|
||||
|
||||
/* copy the real mode code */
|
||||
movl EXT_C(pupa_linux_tmp_addr), %esi
|
||||
movl EXT_C(grub_linux_tmp_addr), %esi
|
||||
movl %ebx, %edi
|
||||
movl $PUPA_LINUX_SETUP_MOVE_SIZE, %ecx
|
||||
movl $GRUB_LINUX_SETUP_MOVE_SIZE, %ecx
|
||||
cld
|
||||
rep
|
||||
movsb
|
||||
|
@ -597,7 +597,7 @@ FUNCTION(pupa_linux_boot_bzimage)
|
|||
|
||||
/* XXX new stack pointer in safe area for calling functions */
|
||||
movl $0x4000, %esp
|
||||
call EXT_C(pupa_stop_floppy)
|
||||
call EXT_C(grub_stop_floppy)
|
||||
|
||||
/* final setup for linux boot */
|
||||
call prot_to_real
|
||||
|
@ -605,7 +605,7 @@ FUNCTION(pupa_linux_boot_bzimage)
|
|||
|
||||
cli
|
||||
movw %bx, %ss
|
||||
movw $PUPA_LINUX_SETUP_STACK, %sp
|
||||
movw $GRUB_LINUX_SETUP_STACK, %sp
|
||||
|
||||
movw %bx, %ds
|
||||
movw %bx, %es
|
||||
|
@ -624,34 +624,34 @@ linux_setup_seg:
|
|||
* This starts the multiboot kernel.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_multiboot_real_boot)
|
||||
FUNCTION(grub_multiboot_real_boot)
|
||||
/* Push the entry address on the stack. */
|
||||
pushl %eax
|
||||
/* Move the address of the multiboot information structure to ebx. */
|
||||
movl %edx,%ebx
|
||||
|
||||
/* Unload all modules and stop the floppy driver. */
|
||||
call EXT_C(pupa_dl_unload_all)
|
||||
call EXT_C(pupa_stop_floppy)
|
||||
call EXT_C(grub_dl_unload_all)
|
||||
call EXT_C(grub_stop_floppy)
|
||||
|
||||
/* Interrupts should be disabled. */
|
||||
cli
|
||||
|
||||
/* Move the magic value into eax and jump to the kernel. */
|
||||
movl $PUPA_MB_MAGIC2,%eax
|
||||
movl $GRUB_MB_MAGIC2,%eax
|
||||
popl %ecx
|
||||
jmp *%ecx
|
||||
|
||||
|
||||
/*
|
||||
* int pupa_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
|
||||
* int grub_biosdisk_rw_int13_extensions (int ah, int drive, void *dap)
|
||||
*
|
||||
* Call IBM/MS INT13 Extensions (int 13 %ah=AH) for DRIVE. DAP
|
||||
* is passed for disk address packet. If an error occurs, return
|
||||
* non-zero, otherwise zero.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_biosdisk_rw_int13_extensions)
|
||||
FUNCTION(grub_biosdisk_rw_int13_extensions)
|
||||
pushl %ebp
|
||||
pushl %esi
|
||||
|
||||
|
@ -685,7 +685,7 @@ FUNCTION(pupa_biosdisk_rw_int13_extensions)
|
|||
ret
|
||||
|
||||
/*
|
||||
* int pupa_biosdisk_rw_standard (int ah, int drive, int coff, int hoff,
|
||||
* int grub_biosdisk_rw_standard (int ah, int drive, int coff, int hoff,
|
||||
* int soff, int nsec, int segment)
|
||||
*
|
||||
* Call standard and old INT13 (int 13 %ah=AH) for DRIVE. Read/write
|
||||
|
@ -693,7 +693,7 @@ FUNCTION(pupa_biosdisk_rw_int13_extensions)
|
|||
* return non-zero, otherwise zero.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_biosdisk_rw_standard)
|
||||
FUNCTION(grub_biosdisk_rw_standard)
|
||||
pushl %ebp
|
||||
movl %esp, %ebp
|
||||
|
||||
|
@ -759,13 +759,13 @@ FUNCTION(pupa_biosdisk_rw_standard)
|
|||
|
||||
|
||||
/*
|
||||
* int pupa_biosdisk_check_int13_extensions (int drive)
|
||||
* int grub_biosdisk_check_int13_extensions (int drive)
|
||||
*
|
||||
* Check if LBA is supported for DRIVE. If it is supported, then return
|
||||
* the major version of extensions, otherwise zero.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_biosdisk_check_int13_extensions)
|
||||
FUNCTION(grub_biosdisk_check_int13_extensions)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
|
||||
|
@ -806,13 +806,13 @@ FUNCTION(pupa_biosdisk_check_int13_extensions)
|
|||
|
||||
|
||||
/*
|
||||
* int pupa_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp)
|
||||
* int grub_biosdisk_get_diskinfo_int13_extensions (int drive, void *drp)
|
||||
*
|
||||
* Return the geometry of DRIVE in a drive parameters, DRP. If an error
|
||||
* occurs, then return non-zero, otherwise zero.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_biosdisk_get_diskinfo_int13_extensions)
|
||||
FUNCTION(grub_biosdisk_get_diskinfo_int13_extensions)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
|
@ -849,7 +849,7 @@ FUNCTION(pupa_biosdisk_get_diskinfo_int13_extensions)
|
|||
|
||||
|
||||
/*
|
||||
* int pupa_biosdisk_get_diskinfo_standard (int drive,
|
||||
* int grub_biosdisk_get_diskinfo_standard (int drive,
|
||||
* unsigned long *cylinders,
|
||||
* unsigned long *heads,
|
||||
* unsigned long *sectors)
|
||||
|
@ -858,7 +858,7 @@ FUNCTION(pupa_biosdisk_get_diskinfo_int13_extensions)
|
|||
* error occurs, then return non-zero, otherwise zero.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_biosdisk_get_diskinfo_standard)
|
||||
FUNCTION(grub_biosdisk_get_diskinfo_standard)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %edi
|
||||
|
@ -922,9 +922,9 @@ FUNCTION(pupa_biosdisk_get_diskinfo_standard)
|
|||
|
||||
|
||||
/*
|
||||
* int pupa_biosdisk_get_num_floppies (void)
|
||||
* int grub_biosdisk_get_num_floppies (void)
|
||||
*/
|
||||
FUNCTION(pupa_biosdisk_get_num_floppies)
|
||||
FUNCTION(grub_biosdisk_get_num_floppies)
|
||||
pushl %ebp
|
||||
|
||||
xorl %edx, %edx
|
||||
|
@ -960,7 +960,7 @@ FUNCTION(pupa_biosdisk_get_num_floppies)
|
|||
|
||||
/*
|
||||
*
|
||||
* pupa_get_memsize(i) : return the memory size in KB. i == 0 for conventional
|
||||
* grub_get_memsize(i) : return the memory size in KB. i == 0 for conventional
|
||||
* memory, i == 1 for extended memory
|
||||
* BIOS call "INT 12H" to get conventional memory size
|
||||
* BIOS call "INT 15H, AH=88H" to get extended memory size
|
||||
|
@ -968,7 +968,7 @@ FUNCTION(pupa_biosdisk_get_num_floppies)
|
|||
*
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_get_memsize)
|
||||
FUNCTION(grub_get_memsize)
|
||||
pushl %ebp
|
||||
|
||||
movl %eax, %edx
|
||||
|
@ -1000,7 +1000,7 @@ xdone:
|
|||
|
||||
/*
|
||||
*
|
||||
* pupa_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is
|
||||
* grub_get_eisa_mmap() : return packed EISA memory map, lower 16 bits is
|
||||
* memory between 1M and 16M in 1K parts, upper 16 bits is
|
||||
* memory above 16M in 64K parts. If error, return zero.
|
||||
* BIOS call "INT 15H, AH=E801H" to get EISA memory map,
|
||||
|
@ -1009,7 +1009,7 @@ xdone:
|
|||
*
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_get_eisa_mmap)
|
||||
FUNCTION(grub_get_eisa_mmap)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
|
||||
|
@ -1037,7 +1037,7 @@ xnoteisa:
|
|||
|
||||
/*
|
||||
*
|
||||
* pupa_get_mmap_entry(addr, cont) : address and old continuation value (zero to
|
||||
* grub_get_mmap_entry(addr, cont) : address and old continuation value (zero to
|
||||
* start), for the Query System Address Map BIOS call.
|
||||
*
|
||||
* Sets the first 4-byte int value of "addr" to the size returned by
|
||||
|
@ -1046,7 +1046,7 @@ xnoteisa:
|
|||
* Returns: new (non-zero) continuation value, 0 if done.
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_get_mmap_entry)
|
||||
FUNCTION(grub_get_mmap_entry)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %edi
|
||||
|
@ -1113,7 +1113,7 @@ xsmap:
|
|||
|
||||
|
||||
/*
|
||||
* void pupa_console_real_putchar (int c)
|
||||
* void grub_console_real_putchar (int c)
|
||||
*
|
||||
* Put the character C on the console. Because GRUB wants to write a
|
||||
* character with an attribute, this implementation is a bit tricky.
|
||||
|
@ -1126,10 +1126,10 @@ xsmap:
|
|||
* get the height of the screen, and the TELETYPE OUPUT BIOS call doesn't
|
||||
* support setting a background attribute.
|
||||
*/
|
||||
FUNCTION(pupa_console_real_putchar)
|
||||
FUNCTION(grub_console_real_putchar)
|
||||
movl %eax, %edx
|
||||
pusha
|
||||
movb EXT_C(pupa_console_cur_color), %bl
|
||||
movb EXT_C(grub_console_cur_color), %bl
|
||||
|
||||
call prot_to_real
|
||||
.code16
|
||||
|
@ -1197,7 +1197,7 @@ FUNCTION(pupa_console_real_putchar)
|
|||
|
||||
|
||||
/*
|
||||
* int pupa_console_getkey (void)
|
||||
* int grub_console_getkey (void)
|
||||
* BIOS call "INT 16H Function 00H" to read character from keyboard
|
||||
* Call with %ah = 0x0
|
||||
* Return: %ah = keyboard scan code
|
||||
|
@ -1206,16 +1206,16 @@ FUNCTION(pupa_console_real_putchar)
|
|||
|
||||
/* this table is used in translate_keycode below */
|
||||
translation_table:
|
||||
.word PUPA_CONSOLE_KEY_LEFT, 2
|
||||
.word PUPA_CONSOLE_KEY_RIGHT, 6
|
||||
.word PUPA_CONSOLE_KEY_UP, 16
|
||||
.word PUPA_CONSOLE_KEY_DOWN, 14
|
||||
.word PUPA_CONSOLE_KEY_HOME, 1
|
||||
.word PUPA_CONSOLE_KEY_END, 5
|
||||
.word PUPA_CONSOLE_KEY_DC, 4
|
||||
.word PUPA_CONSOLE_KEY_BACKSPACE, 8
|
||||
.word PUPA_CONSOLE_KEY_PPAGE, 7
|
||||
.word PUPA_CONSOLE_KEY_NPAGE, 3
|
||||
.word GRUB_CONSOLE_KEY_LEFT, 2
|
||||
.word GRUB_CONSOLE_KEY_RIGHT, 6
|
||||
.word GRUB_CONSOLE_KEY_UP, 16
|
||||
.word GRUB_CONSOLE_KEY_DOWN, 14
|
||||
.word GRUB_CONSOLE_KEY_HOME, 1
|
||||
.word GRUB_CONSOLE_KEY_END, 5
|
||||
.word GRUB_CONSOLE_KEY_DC, 4
|
||||
.word GRUB_CONSOLE_KEY_BACKSPACE, 8
|
||||
.word GRUB_CONSOLE_KEY_PPAGE, 7
|
||||
.word GRUB_CONSOLE_KEY_NPAGE, 3
|
||||
.word 0
|
||||
|
||||
/*
|
||||
|
@ -1248,7 +1248,7 @@ translate_keycode:
|
|||
|
||||
.code32
|
||||
|
||||
FUNCTION(pupa_console_getkey)
|
||||
FUNCTION(grub_console_getkey)
|
||||
pushl %ebp
|
||||
|
||||
call prot_to_real
|
||||
|
@ -1269,7 +1269,7 @@ FUNCTION(pupa_console_getkey)
|
|||
|
||||
|
||||
/*
|
||||
* int pupa_console_checkkey (void)
|
||||
* 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
|
||||
|
@ -1281,7 +1281,7 @@ FUNCTION(pupa_console_getkey)
|
|||
* else
|
||||
* Zero flag = set
|
||||
*/
|
||||
FUNCTION(pupa_console_checkkey)
|
||||
FUNCTION(grub_console_checkkey)
|
||||
pushl %ebp
|
||||
xorl %edx, %edx
|
||||
|
||||
|
@ -1310,7 +1310,7 @@ pending:
|
|||
|
||||
|
||||
/*
|
||||
* pupa_uint16_t pupa_console_getxy (void)
|
||||
* grub_uint16_t grub_console_getxy (void)
|
||||
* BIOS call "INT 10H Function 03h" to get cursor position
|
||||
* Call with %ah = 0x03
|
||||
* %bh = page
|
||||
|
@ -1321,7 +1321,7 @@ pending:
|
|||
*/
|
||||
|
||||
|
||||
FUNCTION(pupa_console_getxy)
|
||||
FUNCTION(grub_console_getxy)
|
||||
pushl %ebp
|
||||
pushl %ebx /* save EBX */
|
||||
|
||||
|
@ -1344,7 +1344,7 @@ FUNCTION(pupa_console_getxy)
|
|||
|
||||
|
||||
/*
|
||||
* void pupa_console_gotoxy(pupa_uint8_t x, pupa_uint8_t y)
|
||||
* void grub_console_gotoxy(grub_uint8_t x, grub_uint8_t y)
|
||||
* BIOS call "INT 10H Function 02h" to set cursor position
|
||||
* Call with %ah = 0x02
|
||||
* %bh = page
|
||||
|
@ -1353,7 +1353,7 @@ FUNCTION(pupa_console_getxy)
|
|||
*/
|
||||
|
||||
|
||||
FUNCTION(pupa_console_gotoxy)
|
||||
FUNCTION(grub_console_gotoxy)
|
||||
pushl %ebp
|
||||
pushl %ebx /* save EBX */
|
||||
|
||||
|
@ -1376,7 +1376,7 @@ FUNCTION(pupa_console_gotoxy)
|
|||
|
||||
|
||||
/*
|
||||
* void pupa_console_cls (void)
|
||||
* void grub_console_cls (void)
|
||||
* BIOS call "INT 10H Function 09h" to write character and attribute
|
||||
* Call with %ah = 0x09
|
||||
* %al = (character)
|
||||
|
@ -1385,7 +1385,7 @@ FUNCTION(pupa_console_gotoxy)
|
|||
* %cx = (number of times)
|
||||
*/
|
||||
|
||||
FUNCTION(pupa_console_cls)
|
||||
FUNCTION(grub_console_cls)
|
||||
pushl %ebp
|
||||
pushl %ebx /* save EBX */
|
||||
|
||||
|
@ -1417,7 +1417,7 @@ FUNCTION(pupa_console_cls)
|
|||
|
||||
|
||||
/*
|
||||
* void pupa_console_setcursor (int on)
|
||||
* void grub_console_setcursor (int on)
|
||||
* BIOS call "INT 10H Function 01h" to set cursor type
|
||||
* Call with %ah = 0x01
|
||||
* %ch = cursor starting scanline
|
||||
|
@ -1429,7 +1429,7 @@ console_cursor_state:
|
|||
console_cursor_shape:
|
||||
.word 0
|
||||
|
||||
FUNCTION(pupa_console_setcursor)
|
||||
FUNCTION(grub_console_setcursor)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
|
||||
|
@ -1474,7 +1474,7 @@ FUNCTION(pupa_console_setcursor)
|
|||
ret
|
||||
|
||||
/*
|
||||
* pupa_getrtsecs()
|
||||
* grub_getrtsecs()
|
||||
* if a seconds value can be read, read it and return it (BCD),
|
||||
* otherwise return 0xFF
|
||||
* BIOS call "INT 1AH Function 02H" to check whether a character is pending
|
||||
|
@ -1491,7 +1491,7 @@ FUNCTION(pupa_console_setcursor)
|
|||
* (this indicates that the clock is updating, or
|
||||
* that it isn't running)
|
||||
*/
|
||||
FUNCTION(pupa_getrtsecs)
|
||||
FUNCTION(grub_getrtsecs)
|
||||
pushl %ebp
|
||||
|
||||
call prot_to_real /* enter real mode */
|
||||
|
@ -1515,11 +1515,11 @@ gottime:
|
|||
|
||||
|
||||
/*
|
||||
* pupa_get_rtc()
|
||||
* grub_get_rtc()
|
||||
* return the real time in ticks, of which there are about
|
||||
* 18-20 per second
|
||||
*/
|
||||
FUNCTION(pupa_get_rtc)
|
||||
FUNCTION(grub_get_rtc)
|
||||
pushl %ebp
|
||||
|
||||
call prot_to_real /* enter real mode */
|
||||
|
@ -1540,9 +1540,9 @@ FUNCTION(pupa_get_rtc)
|
|||
|
||||
|
||||
/*
|
||||
* unsigned char pupa_vga_set_mode (unsigned char mode)
|
||||
* unsigned char grub_vga_set_mode (unsigned char mode)
|
||||
*/
|
||||
FUNCTION(pupa_vga_set_mode)
|
||||
FUNCTION(grub_vga_set_mode)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
movl %eax, %ecx
|
||||
|
@ -1570,9 +1570,9 @@ FUNCTION(pupa_vga_set_mode)
|
|||
|
||||
|
||||
/*
|
||||
* unsigned char *pupa_vga_get_font (void)
|
||||
* unsigned char *grub_vga_get_font (void)
|
||||
*/
|
||||
FUNCTION(pupa_vga_get_font)
|
||||
FUNCTION(grub_vga_get_font)
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -13,51 +13,51 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/loader.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/err.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
|
||||
static pupa_err_t (*pupa_loader_boot_func) (void);
|
||||
static pupa_err_t (*pupa_loader_unload_func) (void);
|
||||
static grub_err_t (*grub_loader_boot_func) (void);
|
||||
static grub_err_t (*grub_loader_unload_func) (void);
|
||||
|
||||
static int pupa_loader_loaded;
|
||||
static int grub_loader_loaded;
|
||||
|
||||
void
|
||||
pupa_loader_set (pupa_err_t (*boot) (void),
|
||||
pupa_err_t (*unload) (void))
|
||||
grub_loader_set (grub_err_t (*boot) (void),
|
||||
grub_err_t (*unload) (void))
|
||||
{
|
||||
if (pupa_loader_loaded && pupa_loader_unload_func)
|
||||
pupa_loader_unload_func ();
|
||||
if (grub_loader_loaded && grub_loader_unload_func)
|
||||
grub_loader_unload_func ();
|
||||
|
||||
pupa_loader_boot_func = boot;
|
||||
pupa_loader_unload_func = unload;
|
||||
grub_loader_boot_func = boot;
|
||||
grub_loader_unload_func = unload;
|
||||
|
||||
pupa_loader_loaded = 1;
|
||||
grub_loader_loaded = 1;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_loader_unset(void)
|
||||
grub_loader_unset(void)
|
||||
{
|
||||
if (pupa_loader_loaded && pupa_loader_unload_func)
|
||||
pupa_loader_unload_func ();
|
||||
if (grub_loader_loaded && grub_loader_unload_func)
|
||||
grub_loader_unload_func ();
|
||||
|
||||
pupa_loader_boot_func = 0;
|
||||
pupa_loader_unload_func = 0;
|
||||
grub_loader_boot_func = 0;
|
||||
grub_loader_unload_func = 0;
|
||||
|
||||
pupa_loader_loaded = 0;
|
||||
grub_loader_loaded = 0;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_loader_boot (void)
|
||||
grub_err_t
|
||||
grub_loader_boot (void)
|
||||
{
|
||||
if (! pupa_loader_loaded)
|
||||
return pupa_error (PUPA_ERR_NO_KERNEL, "no loaded kernel");
|
||||
if (! grub_loader_loaded)
|
||||
return grub_error (GRUB_ERR_NO_KERNEL, "no loaded kernel");
|
||||
|
||||
return (pupa_loader_boot_func) ();
|
||||
return (grub_loader_boot_func) ();
|
||||
}
|
||||
|
||||
|
|
86
kern/main.c
86
kern/main.c
|
@ -1,6 +1,6 @@
|
|||
/* main.c - the kernel main routine */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -18,104 +18,104 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/kernel.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/symbol.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/term.h>
|
||||
#include <pupa/rescue.h>
|
||||
#include <pupa/file.h>
|
||||
#include <pupa/device.h>
|
||||
#include <pupa/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/symbol.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/rescue.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/device.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
/* Return the end of the core image. */
|
||||
pupa_addr_t
|
||||
pupa_get_end_addr (void)
|
||||
grub_addr_t
|
||||
grub_get_end_addr (void)
|
||||
{
|
||||
return pupa_total_module_size + pupa_end_addr;
|
||||
return grub_total_module_size + grub_end_addr;
|
||||
}
|
||||
|
||||
/* Load all modules in core. */
|
||||
static void
|
||||
pupa_load_modules (void)
|
||||
grub_load_modules (void)
|
||||
{
|
||||
struct pupa_module_header *header;
|
||||
struct grub_module_header *header;
|
||||
|
||||
for (header = (struct pupa_module_header *) pupa_end_addr;
|
||||
header < (struct pupa_module_header *) pupa_get_end_addr ();
|
||||
header = (struct pupa_module_header *) ((char *) header + header->size))
|
||||
for (header = (struct grub_module_header *) grub_end_addr;
|
||||
header < (struct grub_module_header *) grub_get_end_addr ();
|
||||
header = (struct grub_module_header *) ((char *) header + header->size))
|
||||
{
|
||||
if (! pupa_dl_load_core ((char *) header + header->offset,
|
||||
if (! grub_dl_load_core ((char *) header + header->offset,
|
||||
(header->size - header->offset)))
|
||||
pupa_fatal ("%s", pupa_errmsg);
|
||||
grub_fatal ("%s", grub_errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add the region where modules reside into dynamic memory. */
|
||||
static void
|
||||
pupa_add_unused_region (void)
|
||||
grub_add_unused_region (void)
|
||||
{
|
||||
if (pupa_total_module_size)
|
||||
pupa_mm_init_region ((void *) pupa_end_addr, pupa_total_module_size);
|
||||
if (grub_total_module_size)
|
||||
grub_mm_init_region ((void *) grub_end_addr, grub_total_module_size);
|
||||
}
|
||||
|
||||
/* Set the root device according to the dl prefix. */
|
||||
static void
|
||||
pupa_set_root_dev (void)
|
||||
grub_set_root_dev (void)
|
||||
{
|
||||
const char *prefix;
|
||||
|
||||
prefix = pupa_env_get ("prefix");
|
||||
prefix = grub_env_get ("prefix");
|
||||
|
||||
if (prefix)
|
||||
{
|
||||
char *dev;
|
||||
|
||||
dev = pupa_file_get_device_name (prefix);
|
||||
dev = grub_file_get_device_name (prefix);
|
||||
if (dev)
|
||||
{
|
||||
pupa_device_set_root (dev);
|
||||
pupa_free (dev);
|
||||
grub_device_set_root (dev);
|
||||
grub_free (dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load the normal mode module and execute the normal mode if possible. */
|
||||
static void
|
||||
pupa_load_normal_mode (void)
|
||||
grub_load_normal_mode (void)
|
||||
{
|
||||
/* Load the module. */
|
||||
pupa_dl_load ("normal");
|
||||
grub_dl_load ("normal");
|
||||
|
||||
/* Ignore any error, because we have the rescue mode anyway. */
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
/* The main routine. */
|
||||
void
|
||||
pupa_main (void)
|
||||
grub_main (void)
|
||||
{
|
||||
/* First of all, initialize the machine. */
|
||||
pupa_machine_init ();
|
||||
grub_machine_init ();
|
||||
|
||||
/* Hello. */
|
||||
pupa_setcolorstate (PUPA_TERM_COLOR_HIGHLIGHT);
|
||||
pupa_printf ("Welcome to PUPA!\n\n");
|
||||
pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
||||
grub_printf ("Welcome to GRUB!\n\n");
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||
|
||||
/* It is better to set the root device as soon as possible,
|
||||
for convenience. */
|
||||
pupa_set_root_dev ();
|
||||
grub_set_root_dev ();
|
||||
|
||||
/* Load pre-loaded modules and free the space. */
|
||||
pupa_register_exported_symbols ();
|
||||
pupa_load_modules ();
|
||||
pupa_add_unused_region ();
|
||||
grub_register_exported_symbols ();
|
||||
grub_load_modules ();
|
||||
grub_add_unused_region ();
|
||||
|
||||
/* Load the normal mode module. */
|
||||
pupa_load_normal_mode ();
|
||||
grub_load_normal_mode ();
|
||||
|
||||
/* Enter the rescue mode. */
|
||||
pupa_enter_rescue_mode ();
|
||||
grub_enter_rescue_mode ();
|
||||
}
|
||||
|
|
198
kern/misc.c
198
kern/misc.c
|
@ -1,9 +1,9 @@
|
|||
/* misc.c - definitions of misc functions */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,19 +14,19 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <stdarg.h>
|
||||
#include <pupa/term.h>
|
||||
#include <pupa/env.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
void *
|
||||
pupa_memmove (void *dest, const void *src, pupa_size_t n)
|
||||
grub_memmove (void *dest, const void *src, grub_size_t n)
|
||||
{
|
||||
char *d = (char *) dest;
|
||||
const char *s = (const char *) src;
|
||||
|
@ -46,11 +46,11 @@ pupa_memmove (void *dest, const void *src, pupa_size_t n)
|
|||
return dest;
|
||||
}
|
||||
/* GCC emits references to memcpy() for struct copies etc. */
|
||||
void *memcpy (void *dest, const void *src, pupa_size_t n)
|
||||
__attribute__ ((alias ("pupa_memmove")));
|
||||
void *memcpy (void *dest, const void *src, grub_size_t n)
|
||||
__attribute__ ((alias ("grub_memmove")));
|
||||
|
||||
char *
|
||||
pupa_strcpy (char *dest, const char *src)
|
||||
grub_strcpy (char *dest, const char *src)
|
||||
{
|
||||
char *p = dest;
|
||||
|
||||
|
@ -61,7 +61,7 @@ pupa_strcpy (char *dest, const char *src)
|
|||
}
|
||||
|
||||
char *
|
||||
pupa_strncpy (char *dest, const char *src, int c)
|
||||
grub_strncpy (char *dest, const char *src, int c)
|
||||
{
|
||||
char *p = dest;
|
||||
int pos = 0;
|
||||
|
@ -73,7 +73,7 @@ pupa_strncpy (char *dest, const char *src, int c)
|
|||
}
|
||||
|
||||
char *
|
||||
pupa_stpcpy (char *dest, const char *src)
|
||||
grub_stpcpy (char *dest, const char *src)
|
||||
{
|
||||
char *d = dest;
|
||||
const char *s = src;
|
||||
|
@ -86,7 +86,7 @@ pupa_stpcpy (char *dest, const char *src)
|
|||
}
|
||||
|
||||
char *
|
||||
pupa_strcat (char *dest, const char *src)
|
||||
grub_strcat (char *dest, const char *src)
|
||||
{
|
||||
char *p = dest;
|
||||
|
||||
|
@ -100,26 +100,26 @@ pupa_strcat (char *dest, const char *src)
|
|||
}
|
||||
|
||||
int
|
||||
pupa_printf (const char *fmt, ...)
|
||||
grub_printf (const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = pupa_vprintf (fmt, ap);
|
||||
ret = grub_vprintf (fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
pupa_vprintf (const char *fmt, va_list args)
|
||||
grub_vprintf (const char *fmt, va_list args)
|
||||
{
|
||||
return pupa_vsprintf (0, fmt, args);
|
||||
return grub_vsprintf (0, fmt, args);
|
||||
}
|
||||
|
||||
int
|
||||
pupa_memcmp (const void *s1, const void *s2, pupa_size_t n)
|
||||
grub_memcmp (const void *s1, const void *s2, grub_size_t n)
|
||||
{
|
||||
const char *t1 = s1;
|
||||
const char *t2 = s2;
|
||||
|
@ -137,7 +137,7 @@ pupa_memcmp (const void *s1, const void *s2, pupa_size_t n)
|
|||
}
|
||||
|
||||
int
|
||||
pupa_strcmp (const char *s1, const char *s2)
|
||||
grub_strcmp (const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && *s2)
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ pupa_strcmp (const char *s1, const char *s2)
|
|||
}
|
||||
|
||||
int
|
||||
pupa_strncmp (const char *s1, const char *s2, int c)
|
||||
grub_strncmp (const char *s1, const char *s2, int c)
|
||||
{
|
||||
int p = 1;
|
||||
|
||||
|
@ -170,7 +170,7 @@ pupa_strncmp (const char *s1, const char *s2, int c)
|
|||
}
|
||||
|
||||
char *
|
||||
pupa_strchr (const char *s, int c)
|
||||
grub_strchr (const char *s, int c)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
|
@ -183,7 +183,7 @@ pupa_strchr (const char *s, int c)
|
|||
}
|
||||
|
||||
char *
|
||||
pupa_strrchr (const char *s, int c)
|
||||
grub_strrchr (const char *s, int c)
|
||||
{
|
||||
char *p = 0;
|
||||
|
||||
|
@ -198,37 +198,37 @@ pupa_strrchr (const char *s, int c)
|
|||
}
|
||||
|
||||
int
|
||||
pupa_isspace (int c)
|
||||
grub_isspace (int c)
|
||||
{
|
||||
return (c == '\n' || c == '\r' || c == ' ' || c == '\t');
|
||||
}
|
||||
|
||||
int
|
||||
pupa_isprint (int c)
|
||||
grub_isprint (int c)
|
||||
{
|
||||
return (c >= ' ' && c <= '~');
|
||||
}
|
||||
|
||||
int
|
||||
pupa_isalpha (int c)
|
||||
grub_isalpha (int c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
int
|
||||
pupa_isdigit (int c)
|
||||
grub_isdigit (int c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
int
|
||||
pupa_isgraph (int c)
|
||||
grub_isgraph (int c)
|
||||
{
|
||||
return (c >= '!' && c <= '~');
|
||||
}
|
||||
|
||||
int
|
||||
pupa_tolower (int c)
|
||||
grub_tolower (int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return c - 'A' + 'a';
|
||||
|
@ -237,13 +237,13 @@ pupa_tolower (int c)
|
|||
}
|
||||
|
||||
unsigned long
|
||||
pupa_strtoul (const char *str, char **end, int base)
|
||||
grub_strtoul (const char *str, char **end, int base)
|
||||
{
|
||||
unsigned long num = 0;
|
||||
int found = 0;
|
||||
|
||||
/* Skip white spaces. */
|
||||
while (*str && pupa_isspace (*str))
|
||||
while (*str && grub_isspace (*str))
|
||||
str++;
|
||||
|
||||
/* Guess the base, if not specified. The prefix `0x' means 16, and
|
||||
|
@ -269,7 +269,7 @@ pupa_strtoul (const char *str, char **end, int base)
|
|||
{
|
||||
unsigned long digit;
|
||||
|
||||
digit = pupa_tolower (*str) - '0';
|
||||
digit = grub_tolower (*str) - '0';
|
||||
if (digit > 9)
|
||||
{
|
||||
digit += '0' - 'a' + 10;
|
||||
|
@ -281,7 +281,7 @@ pupa_strtoul (const char *str, char **end, int base)
|
|||
|
||||
if (num > (~0UL - digit) / base)
|
||||
{
|
||||
pupa_error (PUPA_ERR_OUT_OF_RANGE, "overflow is detected");
|
||||
grub_error (GRUB_ERR_OUT_OF_RANGE, "overflow is detected");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ pupa_strtoul (const char *str, char **end, int base)
|
|||
|
||||
if (! found)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_NUMBER, "unrecognized number");
|
||||
grub_error (GRUB_ERR_BAD_NUMBER, "unrecognized number");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -302,38 +302,38 @@ pupa_strtoul (const char *str, char **end, int base)
|
|||
}
|
||||
|
||||
char *
|
||||
pupa_strdup (const char *s)
|
||||
grub_strdup (const char *s)
|
||||
{
|
||||
pupa_size_t len;
|
||||
grub_size_t len;
|
||||
char *p;
|
||||
|
||||
len = pupa_strlen (s) + 1;
|
||||
p = (char *) pupa_malloc (len);
|
||||
len = grub_strlen (s) + 1;
|
||||
p = (char *) grub_malloc (len);
|
||||
if (! p)
|
||||
return 0;
|
||||
|
||||
return pupa_memcpy (p, s, len);
|
||||
return grub_memcpy (p, s, len);
|
||||
}
|
||||
|
||||
char *
|
||||
pupa_strndup (const char *s, pupa_size_t n)
|
||||
grub_strndup (const char *s, grub_size_t n)
|
||||
{
|
||||
pupa_size_t len = 0;
|
||||
grub_size_t len = 0;
|
||||
char *p = (char *) s;
|
||||
|
||||
while (*(p++) && len < n)
|
||||
len++;
|
||||
|
||||
len = pupa_strlen (s) + 1;
|
||||
p = (char *) pupa_malloc (len);
|
||||
len = grub_strlen (s) + 1;
|
||||
p = (char *) grub_malloc (len);
|
||||
if (! p)
|
||||
return 0;
|
||||
|
||||
return pupa_memcpy (p, s, len);
|
||||
return grub_memcpy (p, s, len);
|
||||
}
|
||||
|
||||
void *
|
||||
pupa_memset (void *s, int c, pupa_size_t n)
|
||||
grub_memset (void *s, int c, grub_size_t n)
|
||||
{
|
||||
unsigned char *p = (unsigned char *) s;
|
||||
|
||||
|
@ -343,8 +343,8 @@ pupa_memset (void *s, int c, pupa_size_t n)
|
|||
return s;
|
||||
}
|
||||
|
||||
pupa_size_t
|
||||
pupa_strlen (const char *s)
|
||||
grub_size_t
|
||||
grub_strlen (const char *s)
|
||||
{
|
||||
const char *p = s;
|
||||
|
||||
|
@ -355,9 +355,9 @@ pupa_strlen (const char *s)
|
|||
}
|
||||
|
||||
static inline void
|
||||
pupa_reverse (char *str)
|
||||
grub_reverse (char *str)
|
||||
{
|
||||
char *p = str + pupa_strlen (str) - 1;
|
||||
char *p = str + grub_strlen (str) - 1;
|
||||
|
||||
while (str < p)
|
||||
{
|
||||
|
@ -372,7 +372,7 @@ pupa_reverse (char *str)
|
|||
}
|
||||
|
||||
static char *
|
||||
pupa_itoa (char *str, int c, unsigned n)
|
||||
grub_itoa (char *str, int c, unsigned n)
|
||||
{
|
||||
unsigned base = (c == 'x') ? 16 : 10;
|
||||
char *p;
|
||||
|
@ -392,12 +392,12 @@ pupa_itoa (char *str, int c, unsigned n)
|
|||
while (n /= base);
|
||||
*p = 0;
|
||||
|
||||
pupa_reverse (str);
|
||||
grub_reverse (str);
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *
|
||||
pupa_ftoa (char *str, double f, int round)
|
||||
grub_ftoa (char *str, double f, int round)
|
||||
{
|
||||
unsigned int intp;
|
||||
unsigned int fractp;
|
||||
|
@ -410,12 +410,12 @@ pupa_ftoa (char *str, double f, int round)
|
|||
intp = f;
|
||||
fractp = (f - (float) intp) * power;
|
||||
|
||||
pupa_sprintf (str, "%d.%d", intp, fractp);
|
||||
grub_sprintf (str, "%d.%d", intp, fractp);
|
||||
return str;
|
||||
}
|
||||
|
||||
int
|
||||
pupa_vsprintf (char *str, const char *fmt, va_list args)
|
||||
grub_vsprintf (char *str, const char *fmt, va_list args)
|
||||
{
|
||||
char c;
|
||||
int count = 0;
|
||||
|
@ -428,7 +428,7 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
|
|||
if (str)
|
||||
*str++ = ch;
|
||||
else
|
||||
pupa_putchar (ch);
|
||||
grub_putchar (ch);
|
||||
|
||||
count++;
|
||||
}
|
||||
|
@ -468,29 +468,29 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
|
|||
|
||||
p = (char *) fmt;
|
||||
/* Read formatting parameters. */
|
||||
while (*p && pupa_isdigit (*p))
|
||||
while (*p && grub_isdigit (*p))
|
||||
p++;
|
||||
|
||||
if (p > fmt)
|
||||
{
|
||||
char s[p - fmt];
|
||||
pupa_strncpy (s, fmt, p - fmt);
|
||||
grub_strncpy (s, fmt, p - fmt);
|
||||
if (s[0] == '0')
|
||||
zerofill = '0';
|
||||
format1 = pupa_strtoul (s, 0, 10);
|
||||
format1 = grub_strtoul (s, 0, 10);
|
||||
fmt = p;
|
||||
if (*p && *p == '.')
|
||||
{
|
||||
p++;
|
||||
fmt++;
|
||||
while (*p && pupa_isdigit (*p))
|
||||
while (*p && grub_isdigit (*p))
|
||||
p++;
|
||||
|
||||
if (p > fmt)
|
||||
{
|
||||
char fstr[p - fmt];
|
||||
pupa_strncpy (fstr, fmt, p - fmt);
|
||||
format2 = pupa_strtoul (fstr, 0, 10);
|
||||
grub_strncpy (fstr, fmt, p - fmt);
|
||||
format2 = grub_strtoul (fstr, 0, 10);
|
||||
fmt = p;
|
||||
}
|
||||
}
|
||||
|
@ -508,12 +508,12 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
|
|||
case 'u':
|
||||
case 'd':
|
||||
n = va_arg (args, int);
|
||||
pupa_itoa (tmp, c, n);
|
||||
if (!rightfill && pupa_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - pupa_strlen (tmp));
|
||||
grub_itoa (tmp, c, n);
|
||||
if (!rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
write_str (tmp);
|
||||
if (rightfill && pupa_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - pupa_strlen (tmp));
|
||||
if (rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
|
@ -525,18 +525,18 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
|
|||
{
|
||||
float f;
|
||||
f = va_arg (args, double);
|
||||
pupa_ftoa (tmp, f, format2);
|
||||
if (!rightfill && pupa_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - pupa_strlen (tmp));
|
||||
grub_ftoa (tmp, f, format2);
|
||||
if (!rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
write_str (tmp);
|
||||
if (rightfill && pupa_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - pupa_strlen (tmp));
|
||||
if (rightfill && grub_strlen (tmp) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (tmp));
|
||||
break;
|
||||
}
|
||||
|
||||
case 'C':
|
||||
{
|
||||
pupa_uint32_t code = va_arg (args, pupa_uint32_t);
|
||||
grub_uint32_t code = va_arg (args, grub_uint32_t);
|
||||
int shift;
|
||||
unsigned mask;
|
||||
|
||||
|
@ -588,13 +588,13 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
|
|||
p = va_arg (args, char *);
|
||||
if (p)
|
||||
{
|
||||
if (!rightfill && pupa_strlen (p) < format1)
|
||||
write_fill (zerofill, format1 - pupa_strlen (p));
|
||||
if (!rightfill && grub_strlen (p) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (p));
|
||||
|
||||
write_str (p);
|
||||
|
||||
if (rightfill && pupa_strlen (p) < format1)
|
||||
write_fill (zerofill, format1 - pupa_strlen (p));
|
||||
if (rightfill && grub_strlen (p) < format1)
|
||||
write_fill (zerofill, format1 - grub_strlen (p));
|
||||
}
|
||||
else
|
||||
write_str ("(null)");
|
||||
|
@ -612,26 +612,26 @@ pupa_vsprintf (char *str, const char *fmt, va_list args)
|
|||
*str = '\0';
|
||||
|
||||
if (count && !str)
|
||||
pupa_refresh ();
|
||||
grub_refresh ();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int
|
||||
pupa_sprintf (char *str, const char *fmt, ...)
|
||||
grub_sprintf (char *str, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int ret;
|
||||
|
||||
va_start (ap, fmt);
|
||||
ret = pupa_vsprintf (str, fmt, ap);
|
||||
ret = grub_vsprintf (str, fmt, ap);
|
||||
va_end (ap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *argc, char ***argv)
|
||||
grub_err_t
|
||||
grub_split_cmdline (const char *cmdline, grub_err_t (* getline) (char **), int *argc, char ***argv)
|
||||
{
|
||||
/* XXX: Fixed size buffer, perhaps this buffer should be dynamically
|
||||
allocated. */
|
||||
|
@ -651,7 +651,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
/* Get one character from the commandline. If the caller reads
|
||||
beyond the end of the string a new line will be read. This
|
||||
function will not chech for errors, the caller has to check for
|
||||
pupa_errno. */
|
||||
grub_errno. */
|
||||
char getchar (void)
|
||||
{
|
||||
int c;
|
||||
|
@ -703,7 +703,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
{
|
||||
/* XXX: An env. variable can have characters and digits in
|
||||
its name, are more characters allowed here? */
|
||||
while (c && (pupa_isalpha (c) || pupa_isdigit (c)))
|
||||
while (c && (grub_isalpha (c) || grub_isdigit (c)))
|
||||
{
|
||||
*(p++) = c;
|
||||
c = getchar ();
|
||||
|
@ -713,7 +713,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
*p = '\0';
|
||||
|
||||
/* The variable does not exist. */
|
||||
val = pupa_env_get (varname);
|
||||
val = grub_env_get (varname);
|
||||
if (! val)
|
||||
return;
|
||||
|
||||
|
@ -724,7 +724,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
|
||||
/* Read one argument. Return 1 if no variables can be read anymore,
|
||||
otherwise return 0. If there is an error, return 1, the caller
|
||||
has to check pupa_errno. */
|
||||
has to check grub_errno. */
|
||||
int getarg (void)
|
||||
{
|
||||
char c;
|
||||
|
@ -741,7 +741,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
/* Double quote. */
|
||||
while ((c = getchar ()))
|
||||
{
|
||||
if (pupa_errno)
|
||||
if (grub_errno)
|
||||
return 1;
|
||||
/* Read in an escaped character. */
|
||||
if (c == '\\')
|
||||
|
@ -766,7 +766,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
/* Single quote. */
|
||||
while ((c = getchar ()) != '\'')
|
||||
{
|
||||
if (pupa_errno)
|
||||
if (grub_errno)
|
||||
return 1;
|
||||
|
||||
*(bp++) = c;
|
||||
|
@ -779,8 +779,8 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
|
||||
default:
|
||||
/* A normal option. */
|
||||
while (c && (pupa_isalpha (c)
|
||||
|| pupa_isdigit (c) || pupa_isgraph (c)))
|
||||
while (c && (grub_isalpha (c)
|
||||
|| grub_isdigit (c) || grub_isgraph (c)))
|
||||
{
|
||||
/* Read in an escaped character. */
|
||||
if (c == '\\')
|
||||
|
@ -804,7 +804,7 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
|
||||
break;
|
||||
}
|
||||
} while (! pupa_isspace (c) && c != '\'' && c != '"');
|
||||
} while (! grub_isspace (c) && c != '\'' && c != '"');
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -820,20 +820,20 @@ pupa_split_cmdline (const char *cmdline, pupa_err_t (* getline) (char **), int *
|
|||
}
|
||||
|
||||
/* Check if there were no errors. */
|
||||
if (pupa_errno)
|
||||
return pupa_errno;
|
||||
if (grub_errno)
|
||||
return grub_errno;
|
||||
|
||||
/* Reserve memory for the return values. */
|
||||
args = pupa_malloc (bp - buffer);
|
||||
args = grub_malloc (bp - buffer);
|
||||
if (! args)
|
||||
return pupa_errno;
|
||||
pupa_memcpy (args, buffer, bp - buffer);
|
||||
return grub_errno;
|
||||
grub_memcpy (args, buffer, bp - buffer);
|
||||
|
||||
*argv = pupa_malloc (sizeof (char *) * (*argc + 1));
|
||||
*argv = grub_malloc (sizeof (char *) * (*argc + 1));
|
||||
if (! *argv)
|
||||
{
|
||||
pupa_free (args);
|
||||
return pupa_errno;
|
||||
grub_free (args);
|
||||
return grub_errno;
|
||||
}
|
||||
|
||||
/* The arguments are separated with 0's, setup argv so it points to
|
||||
|
|
210
kern/mm.c
210
kern/mm.c
|
@ -1,9 +1,9 @@
|
|||
/* mm.c - functions for memory manager */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -14,66 +14,66 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/types.h>
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/dl.h>
|
||||
|
||||
/* Magic words. */
|
||||
#define PUPA_MM_FREE_MAGIC 0x2d3c2808
|
||||
#define PUPA_MM_ALLOC_MAGIC 0x6db08fa4
|
||||
#define GRUB_MM_FREE_MAGIC 0x2d3c2808
|
||||
#define GRUB_MM_ALLOC_MAGIC 0x6db08fa4
|
||||
|
||||
typedef struct pupa_mm_header
|
||||
typedef struct grub_mm_header
|
||||
{
|
||||
struct pupa_mm_header *next;
|
||||
pupa_size_t size;
|
||||
pupa_size_t magic;
|
||||
#if PUPA_CPU_SIZEOF_VOID_P == 4
|
||||
struct grub_mm_header *next;
|
||||
grub_size_t size;
|
||||
grub_size_t magic;
|
||||
#if GRUB_CPU_SIZEOF_VOID_P == 4
|
||||
char padding[4];
|
||||
#elif PUPA_CPU_SIZEOF_VOID_P == 8
|
||||
#elif GRUB_CPU_SIZEOF_VOID_P == 8
|
||||
char padding[8];
|
||||
#else
|
||||
# error "unknown word size"
|
||||
#endif
|
||||
}
|
||||
*pupa_mm_header_t;
|
||||
*grub_mm_header_t;
|
||||
|
||||
#if PUPA_CPU_SIZEOF_VOID_P == 4
|
||||
# define PUPA_MM_ALIGN_LOG2 4
|
||||
#elif PUPA_CPU_SIZEOF_VOID_P == 8
|
||||
# define PUPA_MM_ALIGN_LOG2 8
|
||||
#if GRUB_CPU_SIZEOF_VOID_P == 4
|
||||
# define GRUB_MM_ALIGN_LOG2 4
|
||||
#elif GRUB_CPU_SIZEOF_VOID_P == 8
|
||||
# define GRUB_MM_ALIGN_LOG2 8
|
||||
#endif
|
||||
|
||||
#define PUPA_MM_ALIGN (1 << PUPA_MM_ALIGN_LOG2)
|
||||
#define GRUB_MM_ALIGN (1 << GRUB_MM_ALIGN_LOG2)
|
||||
|
||||
typedef struct pupa_mm_region
|
||||
typedef struct grub_mm_region
|
||||
{
|
||||
struct pupa_mm_header *first;
|
||||
struct pupa_mm_region *next;
|
||||
pupa_addr_t addr;
|
||||
pupa_size_t size;
|
||||
struct grub_mm_header *first;
|
||||
struct grub_mm_region *next;
|
||||
grub_addr_t addr;
|
||||
grub_size_t size;
|
||||
}
|
||||
*pupa_mm_region_t;
|
||||
*grub_mm_region_t;
|
||||
|
||||
|
||||
|
||||
static pupa_mm_region_t base;
|
||||
static grub_mm_region_t base;
|
||||
|
||||
/* Get a header from the pointer PTR, and set *P and *R to a pointer
|
||||
to the header and a pointer to its region, respectively. PTR must
|
||||
be allocated. */
|
||||
static void
|
||||
get_header_from_pointer (void *ptr, pupa_mm_header_t *p, pupa_mm_region_t *r)
|
||||
get_header_from_pointer (void *ptr, grub_mm_header_t *p, grub_mm_region_t *r)
|
||||
{
|
||||
if ((unsigned) ptr & (PUPA_MM_ALIGN - 1))
|
||||
pupa_fatal ("unaligned pointer %p", ptr);
|
||||
if ((unsigned) ptr & (GRUB_MM_ALIGN - 1))
|
||||
grub_fatal ("unaligned pointer %p", ptr);
|
||||
|
||||
for (*r = base; *r; *r = (*r)->next)
|
||||
if ((unsigned) ptr > (*r)->addr
|
||||
|
@ -81,42 +81,42 @@ get_header_from_pointer (void *ptr, pupa_mm_header_t *p, pupa_mm_region_t *r)
|
|||
break;
|
||||
|
||||
if (! *r)
|
||||
pupa_fatal ("out of range pointer %p", ptr);
|
||||
grub_fatal ("out of range pointer %p", ptr);
|
||||
|
||||
*p = (pupa_mm_header_t) ptr - 1;
|
||||
if ((*p)->magic != PUPA_MM_ALLOC_MAGIC)
|
||||
pupa_fatal ("alloc magic is broken at %p", *p);
|
||||
*p = (grub_mm_header_t) ptr - 1;
|
||||
if ((*p)->magic != GRUB_MM_ALLOC_MAGIC)
|
||||
grub_fatal ("alloc magic is broken at %p", *p);
|
||||
}
|
||||
|
||||
/* Initialize a region starting from ADDR and whose size is SIZE,
|
||||
to use it as free space. */
|
||||
void
|
||||
pupa_mm_init_region (void *addr, pupa_size_t size)
|
||||
grub_mm_init_region (void *addr, grub_size_t size)
|
||||
{
|
||||
pupa_mm_header_t h;
|
||||
pupa_mm_region_t r, *p, q;
|
||||
grub_mm_header_t h;
|
||||
grub_mm_region_t r, *p, q;
|
||||
|
||||
#if 0
|
||||
pupa_printf ("%s:%d: addr=%p, size=%u\n", __FILE__, __LINE__, addr, size);
|
||||
grub_printf ("%s:%d: addr=%p, size=%u\n", __FILE__, __LINE__, addr, size);
|
||||
#endif
|
||||
|
||||
/* If this region is too small, ignore it. */
|
||||
if (size < PUPA_MM_ALIGN * 2)
|
||||
if (size < GRUB_MM_ALIGN * 2)
|
||||
return;
|
||||
|
||||
/* Allocate a region from the head. */
|
||||
r = (pupa_mm_region_t) (((pupa_addr_t) addr + PUPA_MM_ALIGN - 1)
|
||||
& (~(PUPA_MM_ALIGN - 1)));
|
||||
r = (grub_mm_region_t) (((grub_addr_t) addr + GRUB_MM_ALIGN - 1)
|
||||
& (~(GRUB_MM_ALIGN - 1)));
|
||||
size -= (char *) r - (char *) addr + sizeof (*r);
|
||||
|
||||
h = (pupa_mm_header_t) ((char *) r + PUPA_MM_ALIGN);
|
||||
h = (grub_mm_header_t) ((char *) r + GRUB_MM_ALIGN);
|
||||
h->next = h;
|
||||
h->magic = PUPA_MM_FREE_MAGIC;
|
||||
h->size = (size >> PUPA_MM_ALIGN_LOG2);
|
||||
h->magic = GRUB_MM_FREE_MAGIC;
|
||||
h->size = (size >> GRUB_MM_ALIGN_LOG2);
|
||||
|
||||
r->first = h;
|
||||
r->addr = (pupa_addr_t) h;
|
||||
r->size = (h->size << PUPA_MM_ALIGN_LOG2);
|
||||
r->addr = (grub_addr_t) h;
|
||||
r->size = (h->size << GRUB_MM_ALIGN_LOG2);
|
||||
|
||||
/* Find where to insert this region. Put a smaller one before bigger ones,
|
||||
to prevent fragmentations. */
|
||||
|
@ -132,47 +132,47 @@ pupa_mm_init_region (void *addr, pupa_size_t size)
|
|||
buffer starting from *FIRST. ALIGN must be a power of two. Return a
|
||||
non-NULL if successful, otherwise return NULL. */
|
||||
static void *
|
||||
pupa_real_malloc (pupa_mm_header_t *first, pupa_size_t n, pupa_size_t align)
|
||||
grub_real_malloc (grub_mm_header_t *first, grub_size_t n, grub_size_t align)
|
||||
{
|
||||
pupa_mm_header_t p, q;
|
||||
grub_mm_header_t p, q;
|
||||
|
||||
if ((*first)->magic == PUPA_MM_ALLOC_MAGIC)
|
||||
if ((*first)->magic == GRUB_MM_ALLOC_MAGIC)
|
||||
return 0;
|
||||
|
||||
for (q = *first, p = q->next; ; q = p, p = p->next)
|
||||
{
|
||||
pupa_off_t extra;
|
||||
grub_off_t extra;
|
||||
|
||||
extra = ((pupa_addr_t) (p + 1) >> PUPA_MM_ALIGN_LOG2) % align;
|
||||
extra = ((grub_addr_t) (p + 1) >> GRUB_MM_ALIGN_LOG2) % align;
|
||||
if (extra)
|
||||
extra = align - extra;
|
||||
|
||||
if (! p)
|
||||
pupa_fatal ("null in the ring");
|
||||
grub_fatal ("null in the ring");
|
||||
|
||||
if (p->magic != PUPA_MM_FREE_MAGIC)
|
||||
pupa_fatal ("free magic is broken at %p: 0x%x", p, p->magic);
|
||||
if (p->magic != GRUB_MM_FREE_MAGIC)
|
||||
grub_fatal ("free magic is broken at %p: 0x%x", p, p->magic);
|
||||
|
||||
if (p->size >= n + extra)
|
||||
{
|
||||
if (extra == 0 && p->size == n)
|
||||
{
|
||||
q->next = p->next;
|
||||
p->magic = PUPA_MM_ALLOC_MAGIC;
|
||||
p->magic = GRUB_MM_ALLOC_MAGIC;
|
||||
}
|
||||
else if (extra == 0 || p->size == n + extra)
|
||||
{
|
||||
p->size -= n;
|
||||
p += p->size;
|
||||
p->size = n;
|
||||
p->magic = PUPA_MM_ALLOC_MAGIC;
|
||||
p->magic = GRUB_MM_ALLOC_MAGIC;
|
||||
}
|
||||
else
|
||||
{
|
||||
pupa_mm_header_t r;
|
||||
grub_mm_header_t r;
|
||||
|
||||
r = p + extra + n;
|
||||
r->magic = PUPA_MM_FREE_MAGIC;
|
||||
r->magic = GRUB_MM_FREE_MAGIC;
|
||||
r->size = p->size - extra - n;
|
||||
r->next = p->next;
|
||||
|
||||
|
@ -180,7 +180,7 @@ pupa_real_malloc (pupa_mm_header_t *first, pupa_size_t n, pupa_size_t align)
|
|||
p->next = r;
|
||||
p += extra;
|
||||
p->size = n;
|
||||
p->magic = PUPA_MM_ALLOC_MAGIC;
|
||||
p->magic = GRUB_MM_ALLOC_MAGIC;
|
||||
}
|
||||
|
||||
*first = q;
|
||||
|
@ -197,13 +197,13 @@ pupa_real_malloc (pupa_mm_header_t *first, pupa_size_t n, pupa_size_t align)
|
|||
|
||||
/* Allocate SIZE bytes with the alignment ALIGN and return the pointer. */
|
||||
void *
|
||||
pupa_memalign (pupa_size_t align, pupa_size_t size)
|
||||
grub_memalign (grub_size_t align, grub_size_t size)
|
||||
{
|
||||
pupa_mm_region_t r;
|
||||
pupa_size_t n = ((size + PUPA_MM_ALIGN - 1) >> PUPA_MM_ALIGN_LOG2) + 1;
|
||||
grub_mm_region_t r;
|
||||
grub_size_t n = ((size + GRUB_MM_ALIGN - 1) >> GRUB_MM_ALIGN_LOG2) + 1;
|
||||
int count = 0;
|
||||
|
||||
align = (align >> PUPA_MM_ALIGN_LOG2);
|
||||
align = (align >> GRUB_MM_ALIGN_LOG2);
|
||||
if (align == 0)
|
||||
align = 1;
|
||||
|
||||
|
@ -213,7 +213,7 @@ pupa_memalign (pupa_size_t align, pupa_size_t size)
|
|||
{
|
||||
void *p;
|
||||
|
||||
p = pupa_real_malloc (&(r->first), n, align);
|
||||
p = grub_real_malloc (&(r->first), n, align);
|
||||
if (p)
|
||||
return p;
|
||||
}
|
||||
|
@ -223,13 +223,13 @@ pupa_memalign (pupa_size_t align, pupa_size_t size)
|
|||
{
|
||||
case 0:
|
||||
/* Invalidate disk caches. */
|
||||
pupa_disk_cache_invalidate_all ();
|
||||
grub_disk_cache_invalidate_all ();
|
||||
count++;
|
||||
goto again;
|
||||
|
||||
case 1:
|
||||
/* Unload unneeded modules. */
|
||||
pupa_dl_unload_unneeded ();
|
||||
grub_dl_unload_unneeded ();
|
||||
count++;
|
||||
goto again;
|
||||
|
||||
|
@ -237,43 +237,43 @@ pupa_memalign (pupa_size_t align, pupa_size_t size)
|
|||
break;
|
||||
}
|
||||
|
||||
pupa_error (PUPA_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
grub_error (GRUB_ERR_OUT_OF_MEMORY, "out of memory");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate SIZE bytes and return the pointer. */
|
||||
void *
|
||||
pupa_malloc (pupa_size_t size)
|
||||
grub_malloc (grub_size_t size)
|
||||
{
|
||||
return pupa_memalign (0, size);
|
||||
return grub_memalign (0, size);
|
||||
}
|
||||
|
||||
/* Deallocate the pointer PTR. */
|
||||
void
|
||||
pupa_free (void *ptr)
|
||||
grub_free (void *ptr)
|
||||
{
|
||||
pupa_mm_header_t p;
|
||||
pupa_mm_region_t r;
|
||||
grub_mm_header_t p;
|
||||
grub_mm_region_t r;
|
||||
|
||||
if (! ptr)
|
||||
return;
|
||||
|
||||
get_header_from_pointer (ptr, &p, &r);
|
||||
|
||||
if (r->first->magic == PUPA_MM_ALLOC_MAGIC)
|
||||
if (r->first->magic == GRUB_MM_ALLOC_MAGIC)
|
||||
{
|
||||
p->magic = PUPA_MM_FREE_MAGIC;
|
||||
p->magic = GRUB_MM_FREE_MAGIC;
|
||||
r->first = p->next = p;
|
||||
}
|
||||
else
|
||||
{
|
||||
pupa_mm_header_t q;
|
||||
grub_mm_header_t q;
|
||||
|
||||
#if 0
|
||||
q = r->first;
|
||||
do
|
||||
{
|
||||
pupa_printf ("%s:%d: q=%p, q->size=0x%x, q->magic=0x%x\n",
|
||||
grub_printf ("%s:%d: q=%p, q->size=0x%x, q->magic=0x%x\n",
|
||||
__FILE__, __LINE__, q, q->size, q->magic);
|
||||
q = q->next;
|
||||
}
|
||||
|
@ -282,14 +282,14 @@ pupa_free (void *ptr)
|
|||
|
||||
for (q = r->first; q >= p || q->next <= p; q = q->next)
|
||||
{
|
||||
if (q->magic != PUPA_MM_FREE_MAGIC)
|
||||
pupa_fatal ("free magic is broken at %p: 0x%x", q, q->magic);
|
||||
if (q->magic != GRUB_MM_FREE_MAGIC)
|
||||
grub_fatal ("free magic is broken at %p: 0x%x", q, q->magic);
|
||||
|
||||
if (q >= q->next && (q < p || q->next > p))
|
||||
break;
|
||||
}
|
||||
|
||||
p->magic = PUPA_MM_FREE_MAGIC;
|
||||
p->magic = GRUB_MM_FREE_MAGIC;
|
||||
p->next = q->next;
|
||||
q->next = p;
|
||||
|
||||
|
@ -314,67 +314,67 @@ pupa_free (void *ptr)
|
|||
/* Reallocate SIZE bytes and return the pointer. The contents will be
|
||||
the same as that of PTR. */
|
||||
void *
|
||||
pupa_realloc (void *ptr, pupa_size_t size)
|
||||
grub_realloc (void *ptr, grub_size_t size)
|
||||
{
|
||||
pupa_mm_header_t p;
|
||||
pupa_mm_region_t r;
|
||||
grub_mm_header_t p;
|
||||
grub_mm_region_t r;
|
||||
void *q;
|
||||
pupa_size_t n;
|
||||
grub_size_t n;
|
||||
|
||||
if (! ptr)
|
||||
return pupa_malloc (size);
|
||||
return grub_malloc (size);
|
||||
|
||||
if (! size)
|
||||
{
|
||||
pupa_free (ptr);
|
||||
grub_free (ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* FIXME: Not optimal. */
|
||||
n = ((size + PUPA_MM_ALIGN - 1) >> PUPA_MM_ALIGN_LOG2) + 1;
|
||||
n = ((size + GRUB_MM_ALIGN - 1) >> GRUB_MM_ALIGN_LOG2) + 1;
|
||||
get_header_from_pointer (ptr, &p, &r);
|
||||
|
||||
if (p->size >= n)
|
||||
return p;
|
||||
|
||||
q = pupa_malloc (size);
|
||||
q = grub_malloc (size);
|
||||
if (! q)
|
||||
return q;
|
||||
|
||||
pupa_memcpy (q, ptr, size);
|
||||
pupa_free (ptr);
|
||||
grub_memcpy (q, ptr, size);
|
||||
grub_free (ptr);
|
||||
return q;
|
||||
}
|
||||
|
||||
#if MM_DEBUG
|
||||
void
|
||||
pupa_mm_dump (unsigned lineno)
|
||||
grub_mm_dump (unsigned lineno)
|
||||
{
|
||||
pupa_mm_region_t r;
|
||||
grub_mm_region_t r;
|
||||
|
||||
pupa_printf ("called at line %u\n", lineno);
|
||||
grub_printf ("called at line %u\n", lineno);
|
||||
for (r = base; r; r = r->next)
|
||||
{
|
||||
pupa_mm_header_t p;
|
||||
grub_mm_header_t p;
|
||||
|
||||
for (p = (pupa_mm_header_t) ((r->addr + PUPA_MM_ALIGN - 1)
|
||||
& (~(PUPA_MM_ALIGN - 1)));
|
||||
(pupa_addr_t) p < r->addr + r->size;
|
||||
for (p = (grub_mm_header_t) ((r->addr + GRUB_MM_ALIGN - 1)
|
||||
& (~(GRUB_MM_ALIGN - 1)));
|
||||
(grub_addr_t) p < r->addr + r->size;
|
||||
p++)
|
||||
{
|
||||
switch (p->magic)
|
||||
{
|
||||
case PUPA_MM_FREE_MAGIC:
|
||||
pupa_printf ("F:%p:%u:%p\n",
|
||||
p, p->size << PUPA_MM_ALIGN_LOG2, p->next);
|
||||
case GRUB_MM_FREE_MAGIC:
|
||||
grub_printf ("F:%p:%u:%p\n",
|
||||
p, p->size << GRUB_MM_ALIGN_LOG2, p->next);
|
||||
break;
|
||||
case PUPA_MM_ALLOC_MAGIC:
|
||||
pupa_printf ("A:%p:%u\n", p, p->size << PUPA_MM_ALIGN_LOG2);
|
||||
case GRUB_MM_ALLOC_MAGIC:
|
||||
grub_printf ("A:%p:%u\n", p, p->size << GRUB_MM_ALIGN_LOG2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pupa_printf ("\n");
|
||||
grub_printf ("\n");
|
||||
}
|
||||
#endif /* MM_DEBUG */
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* init.c -- Initialize PUPA on the newworld mac (PPC). */
|
||||
/* init.c -- Initialize GRUB on the newworld mac (PPC). */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -18,24 +18,24 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/kernel.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/machine/partition.h>
|
||||
#include <pupa/machine/ieee1275.h>
|
||||
#include <pupa/normal.h>
|
||||
#include <pupa/fs.h>
|
||||
#include <pupa/setjmp.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/machine/partition.h>
|
||||
#include <grub/machine/ieee1275.h>
|
||||
#include <grub/normal.h>
|
||||
#include <grub/fs.h>
|
||||
#include <grub/setjmp.h>
|
||||
#include <env.h>
|
||||
|
||||
void pupa_ofdisk_init (void);
|
||||
void pupa_console_init (void);
|
||||
void grub_ofdisk_init (void);
|
||||
void grub_console_init (void);
|
||||
|
||||
|
||||
/* XXX: Modules are not yet supported. */
|
||||
pupa_addr_t pupa_end_addr = -1;
|
||||
pupa_addr_t pupa_total_module_size = 0;
|
||||
grub_addr_t grub_end_addr = -1;
|
||||
grub_addr_t grub_total_module_size = 0;
|
||||
|
||||
void
|
||||
abort (void)
|
||||
|
@ -44,63 +44,63 @@ abort (void)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_machine_init (void)
|
||||
grub_machine_init (void)
|
||||
{
|
||||
void *mem;
|
||||
|
||||
if (pupa_ieee1275_claim ((void *) 0x300000, 0x150000, 0, &mem) == -1)
|
||||
if (grub_ieee1275_claim ((void *) 0x300000, 0x150000, 0, &mem) == -1)
|
||||
abort (); /* Damn, we are in trouble! */
|
||||
|
||||
/* The memory allocations were copied from yaboot. */
|
||||
pupa_mm_init_region ((void *) 0x300000, 0x150000);
|
||||
grub_mm_init_region ((void *) 0x300000, 0x150000);
|
||||
|
||||
/* XXX: Loadable modules are not supported. */
|
||||
pupa_env_set ("prefix", "");
|
||||
grub_env_set ("prefix", "");
|
||||
|
||||
pupa_ext2_init ();
|
||||
pupa_ofdisk_init ();
|
||||
pupa_console_init ();
|
||||
grub_ext2_init ();
|
||||
grub_ofdisk_init ();
|
||||
grub_console_init ();
|
||||
}
|
||||
|
||||
int
|
||||
pupa_arch_dl_check_header (void *ehdr __attribute ((unused)),
|
||||
pupa_size_t size __attribute ((unused)))
|
||||
grub_arch_dl_check_header (void *ehdr __attribute ((unused)),
|
||||
grub_size_t size __attribute ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_arch_dl_relocate_symbols (pupa_dl_t mod __attribute ((unused)),
|
||||
grub_err_t
|
||||
grub_arch_dl_relocate_symbols (grub_dl_t mod __attribute ((unused)),
|
||||
void *ehdr __attribute ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_stop (void)
|
||||
grub_stop (void)
|
||||
{
|
||||
for (;;);
|
||||
}
|
||||
|
||||
void
|
||||
pupa_register_exported_symbols (void)
|
||||
grub_register_exported_symbols (void)
|
||||
{
|
||||
}
|
||||
|
||||
pupa_uint32_t
|
||||
pupa_get_rtc (void)
|
||||
grub_uint32_t
|
||||
grub_get_rtc (void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
pupa_setjmp (pupa_jmp_buf env __attribute ((unused)))
|
||||
grub_setjmp (grub_jmp_buf env __attribute ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_longjmp (pupa_jmp_buf env __attribute ((unused)),
|
||||
grub_longjmp (grub_jmp_buf env __attribute ((unused)),
|
||||
int val __attribute ((unused)))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* openfw.c -- Open firmware support funtions. */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2003, 2004 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -18,59 +18,59 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/machine/ieee1275.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/machine/ieee1275.h>
|
||||
|
||||
/* Iterate through all device aliasses. Thisfunction can be used to
|
||||
find a device of a specific type. */
|
||||
pupa_err_t
|
||||
pupa_devalias_iterate (int (*hook) (struct pupa_ieee1275_devalias *alias))
|
||||
grub_err_t
|
||||
grub_devalias_iterate (int (*hook) (struct grub_ieee1275_devalias *alias))
|
||||
{
|
||||
pupa_ieee1275_phandle_t devalias;
|
||||
grub_ieee1275_phandle_t devalias;
|
||||
char aliasname[32];
|
||||
int actual;
|
||||
struct pupa_ieee1275_devalias alias;
|
||||
struct grub_ieee1275_devalias alias;
|
||||
|
||||
if (pupa_ieee1275_finddevice ("/aliases", &devalias))
|
||||
if (grub_ieee1275_finddevice ("/aliases", &devalias))
|
||||
return -1;
|
||||
|
||||
/* XXX: Is this the right way to find the first property? */
|
||||
aliasname[0] = '\0';
|
||||
|
||||
/* XXX: Are the while conditions correct? */
|
||||
while (pupa_ieee1275_next_property (devalias, aliasname, aliasname, &actual)
|
||||
while (grub_ieee1275_next_property (devalias, aliasname, aliasname, &actual)
|
||||
|| actual)
|
||||
{
|
||||
pupa_ieee1275_phandle_t dev;
|
||||
pupa_size_t pathlen;
|
||||
grub_ieee1275_phandle_t dev;
|
||||
grub_size_t pathlen;
|
||||
char *devpath;
|
||||
/* XXX: This should be large enough for any possible case. */
|
||||
char devtype[64];
|
||||
|
||||
pupa_ieee1275_get_property_length (devalias, aliasname, &pathlen);
|
||||
devpath = pupa_malloc (pathlen);
|
||||
grub_ieee1275_get_property_length (devalias, aliasname, &pathlen);
|
||||
devpath = grub_malloc (pathlen);
|
||||
if (! devpath)
|
||||
return pupa_errno;
|
||||
return grub_errno;
|
||||
|
||||
if (pupa_ieee1275_get_property (devalias, aliasname, devpath, pathlen,
|
||||
if (grub_ieee1275_get_property (devalias, aliasname, devpath, pathlen,
|
||||
&actual))
|
||||
{
|
||||
pupa_free (devpath);
|
||||
grub_free (devpath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pupa_ieee1275_finddevice (devpath, &dev))
|
||||
if (grub_ieee1275_finddevice (devpath, &dev))
|
||||
{
|
||||
pupa_free (devpath);
|
||||
grub_free (devpath);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pupa_ieee1275_get_property (dev, "device_type", devtype, sizeof devtype,
|
||||
if (grub_ieee1275_get_property (dev, "device_type", devtype, sizeof devtype,
|
||||
&actual))
|
||||
{
|
||||
pupa_free (devpath);
|
||||
grub_free (devpath);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ pupa_devalias_iterate (int (*hook) (struct pupa_ieee1275_devalias *alias))
|
|||
alias.type = devtype;
|
||||
hook (&alias);
|
||||
|
||||
pupa_free (devpath);
|
||||
grub_free (devpath);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
464
kern/rescue.c
464
kern/rescue.c
|
@ -1,6 +1,6 @@
|
|||
/* rescue.c - rescue mode */
|
||||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
|
@ -18,43 +18,43 @@
|
|||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/kernel.h>
|
||||
#include <pupa/rescue.h>
|
||||
#include <pupa/term.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <pupa/disk.h>
|
||||
#include <pupa/file.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/loader.h>
|
||||
#include <pupa/dl.h>
|
||||
#include <pupa/machine/partition.h>
|
||||
#include <pupa/env.h>
|
||||
#include <grub/kernel.h>
|
||||
#include <grub/rescue.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/file.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/loader.h>
|
||||
#include <grub/dl.h>
|
||||
#include <grub/machine/partition.h>
|
||||
#include <grub/env.h>
|
||||
|
||||
#define PUPA_RESCUE_BUF_SIZE 256
|
||||
#define PUPA_RESCUE_MAX_ARGS 20
|
||||
#define GRUB_RESCUE_BUF_SIZE 256
|
||||
#define GRUB_RESCUE_MAX_ARGS 20
|
||||
|
||||
struct pupa_rescue_command
|
||||
struct grub_rescue_command
|
||||
{
|
||||
const char *name;
|
||||
void (*func) (int argc, char *argv[]);
|
||||
const char *message;
|
||||
struct pupa_rescue_command *next;
|
||||
struct grub_rescue_command *next;
|
||||
};
|
||||
typedef struct pupa_rescue_command *pupa_rescue_command_t;
|
||||
typedef struct grub_rescue_command *grub_rescue_command_t;
|
||||
|
||||
static char linebuf[PUPA_RESCUE_BUF_SIZE];
|
||||
static char linebuf[GRUB_RESCUE_BUF_SIZE];
|
||||
|
||||
static pupa_rescue_command_t pupa_rescue_command_list;
|
||||
static grub_rescue_command_t grub_rescue_command_list;
|
||||
|
||||
void
|
||||
pupa_rescue_register_command (const char *name,
|
||||
grub_rescue_register_command (const char *name,
|
||||
void (*func) (int argc, char *argv[]),
|
||||
const char *message)
|
||||
{
|
||||
pupa_rescue_command_t cmd;
|
||||
grub_rescue_command_t cmd;
|
||||
|
||||
cmd = (pupa_rescue_command_t) pupa_malloc (sizeof (*cmd));
|
||||
cmd = (grub_rescue_command_t) grub_malloc (sizeof (*cmd));
|
||||
if (! cmd)
|
||||
return;
|
||||
|
||||
|
@ -62,42 +62,42 @@ pupa_rescue_register_command (const char *name,
|
|||
cmd->func = func;
|
||||
cmd->message = message;
|
||||
|
||||
cmd->next = pupa_rescue_command_list;
|
||||
pupa_rescue_command_list = cmd;
|
||||
cmd->next = grub_rescue_command_list;
|
||||
grub_rescue_command_list = cmd;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_rescue_unregister_command (const char *name)
|
||||
grub_rescue_unregister_command (const char *name)
|
||||
{
|
||||
pupa_rescue_command_t *p, q;
|
||||
grub_rescue_command_t *p, q;
|
||||
|
||||
for (p = &pupa_rescue_command_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (pupa_strcmp (name, q->name) == 0)
|
||||
for (p = &grub_rescue_command_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (grub_strcmp (name, q->name) == 0)
|
||||
{
|
||||
*p = q->next;
|
||||
pupa_free (q);
|
||||
grub_free (q);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Prompt to input a command and read the line. */
|
||||
static void
|
||||
pupa_rescue_get_command_line (const char *prompt)
|
||||
grub_rescue_get_command_line (const char *prompt)
|
||||
{
|
||||
int c;
|
||||
int pos = 0;
|
||||
|
||||
pupa_printf (prompt);
|
||||
pupa_memset (linebuf, 0, PUPA_RESCUE_BUF_SIZE);
|
||||
grub_printf (prompt);
|
||||
grub_memset (linebuf, 0, GRUB_RESCUE_BUF_SIZE);
|
||||
|
||||
while ((c = PUPA_TERM_ASCII_CHAR (pupa_getkey ())) != '\n' && c != '\r')
|
||||
while ((c = GRUB_TERM_ASCII_CHAR (grub_getkey ())) != '\n' && c != '\r')
|
||||
{
|
||||
if (pupa_isprint (c))
|
||||
if (grub_isprint (c))
|
||||
{
|
||||
if (pos < PUPA_RESCUE_BUF_SIZE - 1)
|
||||
if (pos < GRUB_RESCUE_BUF_SIZE - 1)
|
||||
{
|
||||
linebuf[pos++] = c;
|
||||
pupa_putchar (c);
|
||||
grub_putchar (c);
|
||||
}
|
||||
}
|
||||
else if (c == '\b')
|
||||
|
@ -105,45 +105,45 @@ pupa_rescue_get_command_line (const char *prompt)
|
|||
if (pos > 0)
|
||||
{
|
||||
linebuf[--pos] = 0;
|
||||
pupa_putchar (c);
|
||||
pupa_putchar (' ');
|
||||
pupa_putchar (c);
|
||||
grub_putchar (c);
|
||||
grub_putchar (' ');
|
||||
grub_putchar (c);
|
||||
}
|
||||
}
|
||||
pupa_refresh ();
|
||||
grub_refresh ();
|
||||
}
|
||||
|
||||
pupa_putchar ('\n');
|
||||
pupa_refresh ();
|
||||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
}
|
||||
|
||||
/* boot */
|
||||
static void
|
||||
pupa_rescue_cmd_boot (int argc __attribute__ ((unused)),
|
||||
grub_rescue_cmd_boot (int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
pupa_loader_boot ();
|
||||
grub_loader_boot ();
|
||||
}
|
||||
|
||||
/* cat FILE */
|
||||
static void
|
||||
pupa_rescue_cmd_cat (int argc, char *argv[])
|
||||
grub_rescue_cmd_cat (int argc, char *argv[])
|
||||
{
|
||||
pupa_file_t file;
|
||||
char buf[PUPA_DISK_SECTOR_SIZE];
|
||||
pupa_ssize_t size;
|
||||
grub_file_t file;
|
||||
char buf[GRUB_DISK_SECTOR_SIZE];
|
||||
grub_ssize_t size;
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no file specified");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
|
||||
return;
|
||||
}
|
||||
|
||||
file = pupa_file_open (argv[0]);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return;
|
||||
|
||||
while ((size = pupa_file_read (file, buf, sizeof (buf))) > 0)
|
||||
while ((size = grub_file_read (file, buf, sizeof (buf))) > 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
@ -151,136 +151,136 @@ pupa_rescue_cmd_cat (int argc, char *argv[])
|
|||
{
|
||||
unsigned char c = buf[i];
|
||||
|
||||
if (pupa_isprint (c) || pupa_isspace (c))
|
||||
pupa_putchar (c);
|
||||
if (grub_isprint (c) || grub_isspace (c))
|
||||
grub_putchar (c);
|
||||
else
|
||||
{
|
||||
pupa_setcolorstate (PUPA_TERM_COLOR_HIGHLIGHT);
|
||||
pupa_printf ("<%x>", (int) c);
|
||||
pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
||||
grub_printf ("<%x>", (int) c);
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pupa_putchar ('\n');
|
||||
pupa_refresh ();
|
||||
pupa_file_close (file);
|
||||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
grub_file_close (file);
|
||||
}
|
||||
|
||||
static int
|
||||
pupa_rescue_print_disks (const char *name)
|
||||
grub_rescue_print_disks (const char *name)
|
||||
{
|
||||
pupa_device_t dev;
|
||||
auto int print_partition (const pupa_partition_t p);
|
||||
grub_device_t dev;
|
||||
auto int print_partition (const grub_partition_t p);
|
||||
|
||||
int print_partition (const pupa_partition_t p)
|
||||
int print_partition (const grub_partition_t p)
|
||||
{
|
||||
char *pname = pupa_partition_get_name (p);
|
||||
char *pname = grub_partition_get_name (p);
|
||||
|
||||
if (pname)
|
||||
{
|
||||
pupa_printf ("(%s,%s) ", name, pname);
|
||||
pupa_free (pname);
|
||||
grub_printf ("(%s,%s) ", name, pname);
|
||||
grub_free (pname);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev = pupa_device_open (name);
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
dev = grub_device_open (name);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
if (dev)
|
||||
{
|
||||
pupa_printf ("(%s) ", name);
|
||||
grub_printf ("(%s) ", name);
|
||||
|
||||
if (dev->disk && dev->disk->has_partitions)
|
||||
{
|
||||
pupa_partition_iterate (dev->disk, print_partition);
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_partition_iterate (dev->disk, print_partition);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
pupa_device_close (dev);
|
||||
grub_device_close (dev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
pupa_rescue_print_files (const char *filename, int dir)
|
||||
grub_rescue_print_files (const char *filename, int dir)
|
||||
{
|
||||
pupa_printf ("%s%s ", filename, dir ? "/" : "");
|
||||
grub_printf ("%s%s ", filename, dir ? "/" : "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ls [ARG] */
|
||||
static void
|
||||
pupa_rescue_cmd_ls (int argc, char *argv[])
|
||||
grub_rescue_cmd_ls (int argc, char *argv[])
|
||||
{
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_disk_dev_iterate (pupa_rescue_print_disks);
|
||||
pupa_putchar ('\n');
|
||||
pupa_refresh ();
|
||||
grub_disk_dev_iterate (grub_rescue_print_disks);
|
||||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
}
|
||||
else
|
||||
{
|
||||
char *device_name;
|
||||
pupa_device_t dev;
|
||||
pupa_fs_t fs;
|
||||
grub_device_t dev;
|
||||
grub_fs_t fs;
|
||||
char *path;
|
||||
|
||||
device_name = pupa_file_get_device_name (argv[0]);
|
||||
dev = pupa_device_open (device_name);
|
||||
device_name = grub_file_get_device_name (argv[0]);
|
||||
dev = grub_device_open (device_name);
|
||||
if (! dev)
|
||||
goto fail;
|
||||
|
||||
fs = pupa_fs_probe (dev);
|
||||
path = pupa_strchr (argv[0], '/');
|
||||
fs = grub_fs_probe (dev);
|
||||
path = grub_strchr (argv[0], '/');
|
||||
|
||||
if (! path && ! device_name)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "invalid argument");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid argument");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (! path)
|
||||
{
|
||||
if (pupa_errno == PUPA_ERR_UNKNOWN_FS)
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
pupa_printf ("(%s): Filesystem is %s.\n",
|
||||
grub_printf ("(%s): Filesystem is %s.\n",
|
||||
device_name, fs ? fs->name : "unknown");
|
||||
}
|
||||
else if (fs)
|
||||
{
|
||||
(fs->dir) (dev, path, pupa_rescue_print_files);
|
||||
pupa_putchar ('\n');
|
||||
pupa_refresh ();
|
||||
(fs->dir) (dev, path, grub_rescue_print_files);
|
||||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
}
|
||||
|
||||
fail:
|
||||
if (dev)
|
||||
pupa_device_close (dev);
|
||||
grub_device_close (dev);
|
||||
|
||||
pupa_free (device_name);
|
||||
grub_free (device_name);
|
||||
}
|
||||
}
|
||||
|
||||
/* help */
|
||||
static void
|
||||
pupa_rescue_cmd_help (int argc __attribute__ ((unused)),
|
||||
grub_rescue_cmd_help (int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
pupa_rescue_command_t p, q;
|
||||
grub_rescue_command_t p, q;
|
||||
|
||||
/* Sort the commands. This is not a good algorithm, but this is enough,
|
||||
because rescue mode has a small number of commands. */
|
||||
for (p = pupa_rescue_command_list; p; p = p->next)
|
||||
for (p = grub_rescue_command_list; p; p = p->next)
|
||||
for (q = p->next; q; q = q->next)
|
||||
if (pupa_strcmp (p->name, q->name) > 0)
|
||||
if (grub_strcmp (p->name, q->name) > 0)
|
||||
{
|
||||
struct pupa_rescue_command tmp;
|
||||
struct grub_rescue_command tmp;
|
||||
|
||||
tmp.name = p->name;
|
||||
tmp.func = p->func;
|
||||
|
@ -296,323 +296,323 @@ pupa_rescue_cmd_help (int argc __attribute__ ((unused)),
|
|||
}
|
||||
|
||||
/* Print them. */
|
||||
for (p = pupa_rescue_command_list; p; p = p->next)
|
||||
pupa_printf ("%s\t%s\n", p->name, p->message);
|
||||
for (p = grub_rescue_command_list; p; p = p->next)
|
||||
grub_printf ("%s\t%s\n", p->name, p->message);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
pupa_rescue_cmd_info (void)
|
||||
grub_rescue_cmd_info (void)
|
||||
{
|
||||
extern void pupa_disk_cache_get_performance (unsigned long *,
|
||||
extern void grub_disk_cache_get_performance (unsigned long *,
|
||||
unsigned long *);
|
||||
unsigned long hits, misses;
|
||||
|
||||
pupa_disk_cache_get_performance (&hits, &misses);
|
||||
pupa_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
|
||||
grub_disk_cache_get_performance (&hits, &misses);
|
||||
grub_printf ("Disk cache: hits = %u, misses = %u ", hits, misses);
|
||||
if (hits + misses)
|
||||
{
|
||||
unsigned long ratio = hits * 10000 / (hits + misses);
|
||||
pupa_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
|
||||
grub_printf ("(%u.%u%%)\n", ratio / 100, ratio % 100);
|
||||
}
|
||||
else
|
||||
pupa_printf ("(N/A)\n");
|
||||
grub_printf ("(N/A)\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* root [DEVICE] */
|
||||
static void
|
||||
pupa_rescue_cmd_root (int argc, char *argv[])
|
||||
grub_rescue_cmd_root (int argc, char *argv[])
|
||||
{
|
||||
pupa_device_t dev;
|
||||
pupa_fs_t fs;
|
||||
grub_device_t dev;
|
||||
grub_fs_t fs;
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
char *device_name = pupa_file_get_device_name (argv[0]);
|
||||
char *device_name = grub_file_get_device_name (argv[0]);
|
||||
if (! device_name)
|
||||
return;
|
||||
|
||||
pupa_device_set_root (device_name);
|
||||
pupa_free (device_name);
|
||||
grub_device_set_root (device_name);
|
||||
grub_free (device_name);
|
||||
}
|
||||
|
||||
dev = pupa_device_open (0);
|
||||
dev = grub_device_open (0);
|
||||
if (! dev)
|
||||
return;
|
||||
|
||||
fs = pupa_fs_probe (dev);
|
||||
if (pupa_errno == PUPA_ERR_UNKNOWN_FS)
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
fs = grub_fs_probe (dev);
|
||||
if (grub_errno == GRUB_ERR_UNKNOWN_FS)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
pupa_printf ("(%s): Filesystem is %s.\n",
|
||||
pupa_device_get_root (), fs ? fs->name : "unknown");
|
||||
grub_printf ("(%s): Filesystem is %s.\n",
|
||||
grub_device_get_root (), fs ? fs->name : "unknown");
|
||||
|
||||
pupa_device_close (dev);
|
||||
grub_device_close (dev);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void
|
||||
pupa_rescue_cmd_testload (int argc, char *argv[])
|
||||
grub_rescue_cmd_testload (int argc, char *argv[])
|
||||
{
|
||||
pupa_file_t file;
|
||||
grub_file_t file;
|
||||
char *buf;
|
||||
pupa_ssize_t size;
|
||||
pupa_ssize_t pos;
|
||||
grub_ssize_t size;
|
||||
grub_ssize_t pos;
|
||||
auto void read_func (unsigned long sector, unsigned offset, unsigned len);
|
||||
|
||||
void read_func (unsigned long sector __attribute__ ((unused)),
|
||||
unsigned offset __attribute__ ((unused)),
|
||||
unsigned len __attribute__ ((unused)))
|
||||
{
|
||||
pupa_putchar ('.');
|
||||
pupa_refresh ();
|
||||
grub_putchar ('.');
|
||||
grub_refresh ();
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no file specified");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no file specified");
|
||||
return;
|
||||
}
|
||||
|
||||
file = pupa_file_open (argv[0]);
|
||||
file = grub_file_open (argv[0]);
|
||||
if (! file)
|
||||
return;
|
||||
|
||||
size = pupa_file_size (file) & ~(PUPA_DISK_SECTOR_SIZE - 1);
|
||||
size = grub_file_size (file) & ~(GRUB_DISK_SECTOR_SIZE - 1);
|
||||
if (size == 0)
|
||||
{
|
||||
pupa_file_close (file);
|
||||
grub_file_close (file);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = pupa_malloc (size);
|
||||
buf = grub_malloc (size);
|
||||
if (! buf)
|
||||
goto fail;
|
||||
|
||||
pupa_printf ("Reading %s sequentially", argv[0]);
|
||||
grub_printf ("Reading %s sequentially", argv[0]);
|
||||
file->read_hook = read_func;
|
||||
if (pupa_file_read (file, buf, size) != size)
|
||||
if (grub_file_read (file, buf, size) != size)
|
||||
goto fail;
|
||||
pupa_printf (" Done.\n");
|
||||
grub_printf (" Done.\n");
|
||||
|
||||
/* Read sequentially again. */
|
||||
pupa_printf ("Reading %s sequentially again", argv[0]);
|
||||
if (pupa_file_seek (file, 0) < 0)
|
||||
grub_printf ("Reading %s sequentially again", argv[0]);
|
||||
if (grub_file_seek (file, 0) < 0)
|
||||
goto fail;
|
||||
|
||||
for (pos = 0; pos < size; pos += PUPA_DISK_SECTOR_SIZE)
|
||||
for (pos = 0; pos < size; pos += GRUB_DISK_SECTOR_SIZE)
|
||||
{
|
||||
char sector[PUPA_DISK_SECTOR_SIZE];
|
||||
char sector[GRUB_DISK_SECTOR_SIZE];
|
||||
|
||||
if (pupa_file_read (file, sector, PUPA_DISK_SECTOR_SIZE)
|
||||
!= PUPA_DISK_SECTOR_SIZE)
|
||||
if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE)
|
||||
!= GRUB_DISK_SECTOR_SIZE)
|
||||
goto fail;
|
||||
|
||||
if (pupa_memcmp (sector, buf + pos, PUPA_DISK_SECTOR_SIZE) != 0)
|
||||
if (grub_memcmp (sector, buf + pos, GRUB_DISK_SECTOR_SIZE) != 0)
|
||||
{
|
||||
pupa_printf ("\nDiffers in %d\n", pos);
|
||||
grub_printf ("\nDiffers in %d\n", pos);
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
pupa_printf (" Done.\n");
|
||||
grub_printf (" Done.\n");
|
||||
|
||||
/* Read backwards and compare. */
|
||||
pupa_printf ("Reading %s backwards", argv[0]);
|
||||
grub_printf ("Reading %s backwards", argv[0]);
|
||||
pos = size;
|
||||
while (pos > 0)
|
||||
{
|
||||
char sector[PUPA_DISK_SECTOR_SIZE];
|
||||
char sector[GRUB_DISK_SECTOR_SIZE];
|
||||
|
||||
pos -= PUPA_DISK_SECTOR_SIZE;
|
||||
pos -= GRUB_DISK_SECTOR_SIZE;
|
||||
|
||||
if (pupa_file_seek (file, pos) < 0)
|
||||
if (grub_file_seek (file, pos) < 0)
|
||||
goto fail;
|
||||
|
||||
if (pupa_file_read (file, sector, PUPA_DISK_SECTOR_SIZE)
|
||||
!= PUPA_DISK_SECTOR_SIZE)
|
||||
if (grub_file_read (file, sector, GRUB_DISK_SECTOR_SIZE)
|
||||
!= GRUB_DISK_SECTOR_SIZE)
|
||||
goto fail;
|
||||
|
||||
if (pupa_memcmp (sector, buf + pos, PUPA_DISK_SECTOR_SIZE) != 0)
|
||||
if (grub_memcmp (sector, buf + pos, GRUB_DISK_SECTOR_SIZE) != 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
pupa_printf ("\nDiffers in %d\n", pos);
|
||||
grub_printf ("\nDiffers in %d\n", pos);
|
||||
|
||||
for (i = 0; i < PUPA_DISK_SECTOR_SIZE; i++)
|
||||
pupa_putchar (buf[pos + i]);
|
||||
for (i = 0; i < GRUB_DISK_SECTOR_SIZE; i++)
|
||||
grub_putchar (buf[pos + i]);
|
||||
|
||||
if (i)
|
||||
pupa_refresh ();
|
||||
grub_refresh ();
|
||||
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
pupa_printf (" Done.\n");
|
||||
grub_printf (" Done.\n");
|
||||
|
||||
fail:
|
||||
|
||||
pupa_file_close (file);
|
||||
pupa_free (buf);
|
||||
grub_file_close (file);
|
||||
grub_free (buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* dump ADDRESS [SIZE] */
|
||||
static void
|
||||
pupa_rescue_cmd_dump (int argc, char *argv[])
|
||||
grub_rescue_cmd_dump (int argc, char *argv[])
|
||||
{
|
||||
pupa_uint8_t *addr;
|
||||
pupa_size_t size = 4;
|
||||
grub_uint8_t *addr;
|
||||
grub_size_t size = 4;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no address specified");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no address specified");
|
||||
return;
|
||||
}
|
||||
|
||||
addr = (pupa_uint8_t *) pupa_strtoul (argv[0], 0, 0);
|
||||
if (pupa_errno)
|
||||
addr = (grub_uint8_t *) grub_strtoul (argv[0], 0, 0);
|
||||
if (grub_errno)
|
||||
return;
|
||||
|
||||
if (argc > 1)
|
||||
size = (pupa_size_t) pupa_strtoul (argv[1], 0, 0);
|
||||
size = (grub_size_t) grub_strtoul (argv[1], 0, 0);
|
||||
|
||||
while (size--)
|
||||
{
|
||||
pupa_printf ("%x%x ", *addr >> 4, *addr & 0xf);
|
||||
grub_printf ("%x%x ", *addr >> 4, *addr & 0xf);
|
||||
addr++;
|
||||
}
|
||||
}
|
||||
|
||||
/* insmod MODULE */
|
||||
static void
|
||||
pupa_rescue_cmd_insmod (int argc, char *argv[])
|
||||
grub_rescue_cmd_insmod (int argc, char *argv[])
|
||||
{
|
||||
char *p;
|
||||
pupa_dl_t mod;
|
||||
grub_dl_t mod;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no module specified");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
|
||||
return;
|
||||
}
|
||||
|
||||
p = pupa_strchr (argv[0], '/');
|
||||
p = grub_strchr (argv[0], '/');
|
||||
if (! p)
|
||||
mod = pupa_dl_load (argv[0]);
|
||||
mod = grub_dl_load (argv[0]);
|
||||
else
|
||||
mod = pupa_dl_load_file (argv[0]);
|
||||
mod = grub_dl_load_file (argv[0]);
|
||||
|
||||
if (mod)
|
||||
pupa_dl_ref (mod);
|
||||
grub_dl_ref (mod);
|
||||
}
|
||||
|
||||
/* rmmod MODULE */
|
||||
static void
|
||||
pupa_rescue_cmd_rmmod (int argc, char *argv[])
|
||||
grub_rescue_cmd_rmmod (int argc, char *argv[])
|
||||
{
|
||||
pupa_dl_t mod;
|
||||
grub_dl_t mod;
|
||||
|
||||
if (argc == 0)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no module specified");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no module specified");
|
||||
return;
|
||||
}
|
||||
|
||||
mod = pupa_dl_get (argv[0]);
|
||||
mod = grub_dl_get (argv[0]);
|
||||
if (! mod)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no such module");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no such module");
|
||||
return;
|
||||
}
|
||||
|
||||
if (! pupa_dl_unref (mod))
|
||||
pupa_dl_unload (mod);
|
||||
if (! grub_dl_unref (mod))
|
||||
grub_dl_unload (mod);
|
||||
}
|
||||
|
||||
/* lsmod */
|
||||
static void
|
||||
pupa_rescue_cmd_lsmod (int argc __attribute__ ((unused)),
|
||||
grub_rescue_cmd_lsmod (int argc __attribute__ ((unused)),
|
||||
char *argv[] __attribute__ ((unused)))
|
||||
{
|
||||
auto int print_module (pupa_dl_t mod);
|
||||
auto int print_module (grub_dl_t mod);
|
||||
|
||||
int print_module (pupa_dl_t mod)
|
||||
int print_module (grub_dl_t mod)
|
||||
{
|
||||
pupa_dl_dep_t dep;
|
||||
grub_dl_dep_t dep;
|
||||
|
||||
pupa_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
|
||||
grub_printf ("%s\t%d\t\t", mod->name, mod->ref_count);
|
||||
for (dep = mod->dep; dep; dep = dep->next)
|
||||
{
|
||||
if (dep != mod->dep)
|
||||
pupa_putchar (',');
|
||||
grub_putchar (',');
|
||||
|
||||
pupa_printf ("%s", dep->mod->name);
|
||||
grub_printf ("%s", dep->mod->name);
|
||||
}
|
||||
pupa_putchar ('\n');
|
||||
pupa_refresh ();
|
||||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pupa_printf ("Name\tRef Count\tDependencies\n");
|
||||
pupa_dl_iterate (print_module);
|
||||
grub_printf ("Name\tRef Count\tDependencies\n");
|
||||
grub_dl_iterate (print_module);
|
||||
}
|
||||
|
||||
/* set ENVVAR=VALUE */
|
||||
static void
|
||||
pupa_rescue_cmd_set (int argc, char *argv[])
|
||||
grub_rescue_cmd_set (int argc, char *argv[])
|
||||
{
|
||||
char *var;
|
||||
char *val;
|
||||
|
||||
auto int print_env (struct pupa_env_var *env);
|
||||
auto int print_env (struct grub_env_var *env);
|
||||
|
||||
int print_env (struct pupa_env_var *env)
|
||||
int print_env (struct grub_env_var *env)
|
||||
{
|
||||
pupa_printf ("%s=%s\n", env->name, env->value);
|
||||
grub_printf ("%s=%s\n", env->name, env->value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_env_iterate (print_env);
|
||||
grub_env_iterate (print_env);
|
||||
return;
|
||||
}
|
||||
|
||||
var = argv[0];
|
||||
val = pupa_strchr (var, '=');
|
||||
val = grub_strchr (var, '=');
|
||||
if (! val)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "not an assignment");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "not an assignment");
|
||||
return;
|
||||
}
|
||||
|
||||
val[0] = 0;
|
||||
pupa_env_set (var, val + 1);
|
||||
grub_env_set (var, val + 1);
|
||||
val[0] = '=';
|
||||
}
|
||||
|
||||
static void
|
||||
pupa_rescue_cmd_unset (int argc, char *argv[])
|
||||
grub_rescue_cmd_unset (int argc, char *argv[])
|
||||
{
|
||||
if (argc < 1)
|
||||
{
|
||||
pupa_error (PUPA_ERR_BAD_ARGUMENT, "no environment variable specified");
|
||||
grub_error (GRUB_ERR_BAD_ARGUMENT, "no environment variable specified");
|
||||
return;
|
||||
}
|
||||
|
||||
pupa_env_unset (argv[0]);
|
||||
grub_env_unset (argv[0]);
|
||||
}
|
||||
|
||||
static void
|
||||
attempt_normal_mode (void)
|
||||
{
|
||||
pupa_rescue_command_t cmd;
|
||||
grub_rescue_command_t cmd;
|
||||
|
||||
for (cmd = pupa_rescue_command_list; cmd; cmd = cmd->next)
|
||||
for (cmd = grub_rescue_command_list; cmd; cmd = cmd->next)
|
||||
{
|
||||
if (pupa_strcmp ("normal", cmd->name) == 0)
|
||||
if (grub_strcmp ("normal", cmd->name) == 0)
|
||||
{
|
||||
(cmd->func) (0, 0);
|
||||
break;
|
||||
|
@ -622,13 +622,13 @@ attempt_normal_mode (void)
|
|||
|
||||
/* Enter the rescue mode. */
|
||||
void
|
||||
pupa_enter_rescue_mode (void)
|
||||
grub_enter_rescue_mode (void)
|
||||
{
|
||||
auto pupa_err_t getline (char **line);
|
||||
auto grub_err_t getline (char **line);
|
||||
|
||||
pupa_err_t getline (char **line)
|
||||
grub_err_t getline (char **line)
|
||||
{
|
||||
pupa_rescue_get_command_line ("> ");
|
||||
grub_rescue_get_command_line ("> ");
|
||||
*line = linebuf;
|
||||
return 0;
|
||||
}
|
||||
|
@ -636,29 +636,29 @@ pupa_enter_rescue_mode (void)
|
|||
/* First of all, attempt to execute the normal mode. */
|
||||
attempt_normal_mode ();
|
||||
|
||||
pupa_printf ("Entering into rescue mode...\n");
|
||||
grub_printf ("Entering into rescue mode...\n");
|
||||
|
||||
pupa_rescue_register_command ("boot", pupa_rescue_cmd_boot,
|
||||
grub_rescue_register_command ("boot", grub_rescue_cmd_boot,
|
||||
"boot an operating system");
|
||||
pupa_rescue_register_command ("cat", pupa_rescue_cmd_cat,
|
||||
grub_rescue_register_command ("cat", grub_rescue_cmd_cat,
|
||||
"show the contents of a file");
|
||||
pupa_rescue_register_command ("help", pupa_rescue_cmd_help,
|
||||
grub_rescue_register_command ("help", grub_rescue_cmd_help,
|
||||
"show this message");
|
||||
pupa_rescue_register_command ("ls", pupa_rescue_cmd_ls,
|
||||
grub_rescue_register_command ("ls", grub_rescue_cmd_ls,
|
||||
"list devices or files");
|
||||
pupa_rescue_register_command ("root", pupa_rescue_cmd_root,
|
||||
grub_rescue_register_command ("root", grub_rescue_cmd_root,
|
||||
"set the root device");
|
||||
pupa_rescue_register_command ("dump", pupa_rescue_cmd_dump,
|
||||
grub_rescue_register_command ("dump", grub_rescue_cmd_dump,
|
||||
"dump memory");
|
||||
pupa_rescue_register_command ("insmod", pupa_rescue_cmd_insmod,
|
||||
grub_rescue_register_command ("insmod", grub_rescue_cmd_insmod,
|
||||
"insert a module");
|
||||
pupa_rescue_register_command ("rmmod", pupa_rescue_cmd_rmmod,
|
||||
grub_rescue_register_command ("rmmod", grub_rescue_cmd_rmmod,
|
||||
"remove a module");
|
||||
pupa_rescue_register_command ("lsmod", pupa_rescue_cmd_lsmod,
|
||||
grub_rescue_register_command ("lsmod", grub_rescue_cmd_lsmod,
|
||||
"show loaded modules");
|
||||
pupa_rescue_register_command ("set", pupa_rescue_cmd_set,
|
||||
grub_rescue_register_command ("set", grub_rescue_cmd_set,
|
||||
"set an environment variable");
|
||||
pupa_rescue_register_command ("unset", pupa_rescue_cmd_unset,
|
||||
grub_rescue_register_command ("unset", grub_rescue_cmd_unset,
|
||||
"remove an environment variable");
|
||||
|
||||
while (1)
|
||||
|
@ -666,26 +666,26 @@ pupa_enter_rescue_mode (void)
|
|||
char *line = linebuf;
|
||||
char *name;
|
||||
int n;
|
||||
pupa_rescue_command_t cmd;
|
||||
grub_rescue_command_t cmd;
|
||||
char **args;
|
||||
|
||||
/* Print an error, if any. */
|
||||
pupa_print_error ();
|
||||
pupa_errno = PUPA_ERR_NONE;
|
||||
grub_print_error ();
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
|
||||
/* Get a command line. */
|
||||
pupa_rescue_get_command_line ("pupa rescue> ");
|
||||
grub_rescue_get_command_line ("grub rescue> ");
|
||||
|
||||
if (pupa_split_cmdline (line, getline, &n, &args))
|
||||
if (grub_split_cmdline (line, getline, &n, &args))
|
||||
continue;
|
||||
|
||||
/* In case of an assignment set the environment accordingly
|
||||
instead of calling a function. */
|
||||
if (n == 0 && pupa_strchr (line, '='))
|
||||
if (n == 0 && grub_strchr (line, '='))
|
||||
{
|
||||
char *val = pupa_strchr (args[0], '=');
|
||||
char *val = grub_strchr (args[0], '=');
|
||||
val[0] = 0;
|
||||
pupa_env_set (args[0], val + 1);
|
||||
grub_env_set (args[0], val + 1);
|
||||
val[0] = '=';
|
||||
continue;
|
||||
}
|
||||
|
@ -698,9 +698,9 @@ pupa_enter_rescue_mode (void)
|
|||
continue;
|
||||
|
||||
/* Find the command and execute it. */
|
||||
for (cmd = pupa_rescue_command_list; cmd; cmd = cmd->next)
|
||||
for (cmd = grub_rescue_command_list; cmd; cmd = cmd->next)
|
||||
{
|
||||
if (pupa_strcmp (name, cmd->name) == 0)
|
||||
if (grub_strcmp (name, cmd->name) == 0)
|
||||
{
|
||||
(cmd->func) (n, &args[1]);
|
||||
break;
|
||||
|
@ -710,8 +710,8 @@ pupa_enter_rescue_mode (void)
|
|||
/* If not found, print an error message. */
|
||||
if (! cmd)
|
||||
{
|
||||
pupa_printf ("Unknown command `%s'\n", name);
|
||||
pupa_printf ("Try `help' for usage\n");
|
||||
grub_printf ("Unknown command `%s'\n", name);
|
||||
grub_printf ("Try `help' for usage\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
170
kern/term.c
170
kern/term.c
|
@ -1,8 +1,8 @@
|
|||
/*
|
||||
* PUPA -- Preliminary Universal Programming Architecture for GRUB
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2003 Free Software Foundation, Inc.
|
||||
*
|
||||
* PUPA is free software; you can redistribute it and/or modify
|
||||
* 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
|
@ -13,40 +13,40 @@
|
|||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with PUPA; if not, write to the Free Software
|
||||
* along with GRUB; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <pupa/term.h>
|
||||
#include <pupa/err.h>
|
||||
#include <pupa/mm.h>
|
||||
#include <pupa/misc.h>
|
||||
#include <grub/term.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
|
||||
/* The list of terminals. */
|
||||
static pupa_term_t pupa_term_list;
|
||||
static grub_term_t grub_term_list;
|
||||
|
||||
/* The current terminal. */
|
||||
static pupa_term_t pupa_cur_term;
|
||||
static grub_term_t grub_cur_term;
|
||||
|
||||
/* The amount of lines counted by the pager. */
|
||||
static int pupa_more_lines;
|
||||
static int grub_more_lines;
|
||||
|
||||
/* If the more pager is active. */
|
||||
static int pupa_more;
|
||||
static int grub_more;
|
||||
|
||||
void
|
||||
pupa_term_register (pupa_term_t term)
|
||||
grub_term_register (grub_term_t term)
|
||||
{
|
||||
term->next = pupa_term_list;
|
||||
pupa_term_list = term;
|
||||
term->next = grub_term_list;
|
||||
grub_term_list = term;
|
||||
}
|
||||
|
||||
void
|
||||
pupa_term_unregister (pupa_term_t term)
|
||||
grub_term_unregister (grub_term_t term)
|
||||
{
|
||||
pupa_term_t *p, q;
|
||||
grub_term_t *p, q;
|
||||
|
||||
for (p = &pupa_term_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
for (p = &grub_term_list, q = *p; q; p = &(q->next), q = q->next)
|
||||
if (q == term)
|
||||
{
|
||||
*p = q->next;
|
||||
|
@ -55,83 +55,83 @@ pupa_term_unregister (pupa_term_t term)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_term_iterate (int (*hook) (pupa_term_t term))
|
||||
grub_term_iterate (int (*hook) (grub_term_t term))
|
||||
{
|
||||
pupa_term_t p;
|
||||
grub_term_t p;
|
||||
|
||||
for (p = pupa_term_list; p; p = p->next)
|
||||
for (p = grub_term_list; p; p = p->next)
|
||||
if (hook (p))
|
||||
break;
|
||||
}
|
||||
|
||||
pupa_err_t
|
||||
pupa_term_set_current (pupa_term_t term)
|
||||
grub_err_t
|
||||
grub_term_set_current (grub_term_t term)
|
||||
{
|
||||
if (pupa_cur_term && pupa_cur_term->fini)
|
||||
if ((pupa_cur_term->fini) () != PUPA_ERR_NONE)
|
||||
return pupa_errno;
|
||||
if (grub_cur_term && grub_cur_term->fini)
|
||||
if ((grub_cur_term->fini) () != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
if (term->init)
|
||||
if ((term->init) () != PUPA_ERR_NONE)
|
||||
return pupa_errno;
|
||||
if ((term->init) () != GRUB_ERR_NONE)
|
||||
return grub_errno;
|
||||
|
||||
pupa_cur_term = term;
|
||||
pupa_cls ();
|
||||
return PUPA_ERR_NONE;
|
||||
grub_cur_term = term;
|
||||
grub_cls ();
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
pupa_term_t
|
||||
pupa_term_get_current (void)
|
||||
grub_term_t
|
||||
grub_term_get_current (void)
|
||||
{
|
||||
return pupa_cur_term;
|
||||
return grub_cur_term;
|
||||
}
|
||||
|
||||
/* Put a Unicode character. */
|
||||
void
|
||||
pupa_putcode (pupa_uint32_t code)
|
||||
grub_putcode (grub_uint32_t code)
|
||||
{
|
||||
if (code == '\t' && pupa_cur_term->getxy)
|
||||
if (code == '\t' && grub_cur_term->getxy)
|
||||
{
|
||||
int n;
|
||||
|
||||
n = 8 - ((pupa_getxy () >> 8) & 7);
|
||||
n = 8 - ((grub_getxy () >> 8) & 7);
|
||||
while (n--)
|
||||
pupa_putcode (' ');
|
||||
grub_putcode (' ');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
(pupa_cur_term->putchar) (code);
|
||||
(grub_cur_term->putchar) (code);
|
||||
|
||||
if (code == '\n')
|
||||
{
|
||||
pupa_putcode ('\r');
|
||||
grub_putcode ('\r');
|
||||
|
||||
pupa_more_lines++;
|
||||
grub_more_lines++;
|
||||
/* XXX: Don't use a fixed height! */
|
||||
if (pupa_more && pupa_more_lines == 24 - 1)
|
||||
if (grub_more && grub_more_lines == 24 - 1)
|
||||
{
|
||||
char key;
|
||||
int pos = pupa_getxy ();
|
||||
int pos = grub_getxy ();
|
||||
|
||||
/* Show --MORE-- on the lower left side of the screen. */
|
||||
pupa_gotoxy (1, 24 - 1);
|
||||
pupa_setcolorstate (PUPA_TERM_COLOR_HIGHLIGHT);
|
||||
pupa_printf ("--MORE--");
|
||||
pupa_setcolorstate (PUPA_TERM_COLOR_STANDARD);
|
||||
grub_gotoxy (1, 24 - 1);
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_HIGHLIGHT);
|
||||
grub_printf ("--MORE--");
|
||||
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
||||
|
||||
key = pupa_getkey ();
|
||||
key = grub_getkey ();
|
||||
|
||||
/* Remove the message. */
|
||||
pupa_gotoxy (1, 24 -1);
|
||||
pupa_printf (" ");
|
||||
pupa_gotoxy (pos >> 8, pos & 0xFF);
|
||||
grub_gotoxy (1, 24 -1);
|
||||
grub_printf (" ");
|
||||
grub_gotoxy (pos >> 8, pos & 0xFF);
|
||||
|
||||
/* Scroll one lines or an entire page, depending on the key. */
|
||||
if (key == '\r' || key =='\n')
|
||||
pupa_more_lines--;
|
||||
grub_more_lines--;
|
||||
else
|
||||
pupa_more_lines = 0;
|
||||
grub_more_lines = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -139,9 +139,9 @@ pupa_putcode (pupa_uint32_t code)
|
|||
/* Put a character. C is one byte of a UTF-8 stream.
|
||||
This function gathers bytes until a valid Unicode character is found. */
|
||||
void
|
||||
pupa_putchar (int c)
|
||||
grub_putchar (int c)
|
||||
{
|
||||
static pupa_uint32_t code = 0;
|
||||
static grub_uint32_t code = 0;
|
||||
static int count = 0;
|
||||
|
||||
if (count)
|
||||
|
@ -197,68 +197,68 @@ pupa_putchar (int c)
|
|||
/* Not finished yet. */
|
||||
return;
|
||||
|
||||
pupa_putcode (code);
|
||||
grub_putcode (code);
|
||||
}
|
||||
|
||||
int
|
||||
pupa_getkey (void)
|
||||
grub_getkey (void)
|
||||
{
|
||||
return (pupa_cur_term->getkey) ();
|
||||
return (grub_cur_term->getkey) ();
|
||||
}
|
||||
|
||||
int
|
||||
pupa_checkkey (void)
|
||||
grub_checkkey (void)
|
||||
{
|
||||
return (pupa_cur_term->checkkey) ();
|
||||
return (grub_cur_term->checkkey) ();
|
||||
}
|
||||
|
||||
pupa_uint16_t
|
||||
pupa_getxy (void)
|
||||
grub_uint16_t
|
||||
grub_getxy (void)
|
||||
{
|
||||
return (pupa_cur_term->getxy) ();
|
||||
return (grub_cur_term->getxy) ();
|
||||
}
|
||||
|
||||
void
|
||||
pupa_gotoxy (pupa_uint8_t x, pupa_uint8_t y)
|
||||
grub_gotoxy (grub_uint8_t x, grub_uint8_t y)
|
||||
{
|
||||
(pupa_cur_term->gotoxy) (x, y);
|
||||
(grub_cur_term->gotoxy) (x, y);
|
||||
}
|
||||
|
||||
void
|
||||
pupa_cls (void)
|
||||
grub_cls (void)
|
||||
{
|
||||
if (pupa_cur_term->flags & PUPA_TERM_DUMB)
|
||||
if (grub_cur_term->flags & GRUB_TERM_DUMB)
|
||||
{
|
||||
pupa_putchar ('\n');
|
||||
pupa_refresh ();
|
||||
grub_putchar ('\n');
|
||||
grub_refresh ();
|
||||
}
|
||||
else
|
||||
(pupa_cur_term->cls) ();
|
||||
(grub_cur_term->cls) ();
|
||||
}
|
||||
|
||||
void
|
||||
pupa_setcolorstate (pupa_term_color_state state)
|
||||
grub_setcolorstate (grub_term_color_state state)
|
||||
{
|
||||
if (pupa_cur_term->setcolorstate)
|
||||
(pupa_cur_term->setcolorstate) (state);
|
||||
if (grub_cur_term->setcolorstate)
|
||||
(grub_cur_term->setcolorstate) (state);
|
||||
}
|
||||
|
||||
void
|
||||
pupa_setcolor (pupa_uint8_t normal_color, pupa_uint8_t highlight_color)
|
||||
grub_setcolor (grub_uint8_t normal_color, grub_uint8_t highlight_color)
|
||||
{
|
||||
if (pupa_cur_term->setcolor)
|
||||
(pupa_cur_term->setcolor) (normal_color, highlight_color);
|
||||
if (grub_cur_term->setcolor)
|
||||
(grub_cur_term->setcolor) (normal_color, highlight_color);
|
||||
}
|
||||
|
||||
int
|
||||
pupa_setcursor (int on)
|
||||
grub_setcursor (int on)
|
||||
{
|
||||
static int prev = 1;
|
||||
int ret = prev;
|
||||
|
||||
if (pupa_cur_term->setcursor)
|
||||
if (grub_cur_term->setcursor)
|
||||
{
|
||||
(pupa_cur_term->setcursor) (on);
|
||||
(grub_cur_term->setcursor) (on);
|
||||
prev = on;
|
||||
}
|
||||
|
||||
|
@ -266,19 +266,19 @@ pupa_setcursor (int on)
|
|||
}
|
||||
|
||||
void
|
||||
pupa_refresh (void)
|
||||
grub_refresh (void)
|
||||
{
|
||||
if (pupa_cur_term->refresh)
|
||||
(pupa_cur_term->refresh) ();
|
||||
if (grub_cur_term->refresh)
|
||||
(grub_cur_term->refresh) ();
|
||||
}
|
||||
|
||||
void
|
||||
pupa_set_more (int onoff)
|
||||
grub_set_more (int onoff)
|
||||
{
|
||||
if (onoff == 1)
|
||||
pupa_more++;
|
||||
grub_more++;
|
||||
else
|
||||
pupa_more--;
|
||||
grub_more--;
|
||||
|
||||
pupa_more_lines = 0;
|
||||
grub_more_lines = 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue