/* mbchk - a simple checker for the format of a Multiboot kernel */
/*
* Copyright (C) 1999,2001,2002 Free Software Foundation, Inc.
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <multiboot.h>
static int quiet = 0;
{
{0}
};
static void
{
if (status)
else
printf ("Usage: mbchk [OPTION]... [FILE]...\n"
"Check if the format of FILE complies with the Multiboot Specification.\n"
"\n"
"-q, --quiet suppress all normal output\n"
"-h, --help display this help and exit\n"
"-v, --version output version information and exit.\n"
"\n"
"Report bugs to <bug-grub@gnu.org>.\n");
}
static int
{
int i;
{
return 0;
}
for (i = 0; i < 8192 - sizeof (multiboot_header_t); i++)
{
if (magic == MULTIBOOT_HEADER_MAGIC)
{
break;
}
}
if (! mbh)
{
return 0;
}
if (! quiet)
printf ("%s: The Multiboot header is found at the offset %d.\n",
filename, i);
/* Check for the checksum. */
{
"%s: Bad checksum (0x%lx).\n",
return 0;
}
/* Reserved flags must be zero. */
{
"%s: Non-zero is found in reserved flags (0x%lx).\n",
return 0;
}
if (! quiet)
{
printf ("%s: Page alignment is turned %s.\n",
printf ("%s: Memory information is turned %s.\n",
printf ("%s: Address fields is turned %s.\n",
}
/* Check for the address fields. */
{
{
"%s: header_addr is less than "
"load_addr (0x%lx > 0x%lx).\n",
return 0;
}
{
"%s: load_addr is not less than load_end_addr"
" (0x%lx >= 0x%lx).\n",
return 0;
}
{
"%s: load_end_addr is greater than bss_end_addr"
" (0x%lx > 0x%lx).\n",
return 0;
}
{
"%s: load_addr is greater than entry_addr"
" (0x%lx > 0x%lx).\n",
return 0;
}
/* FIXME: It is better to check if the entry address is within the
file, especially when the load end address is zero. */
{
"%s: load_end_addr is not greater than entry_addr"
" (0x%lx <= 0x%lx).\n",
return 0;
}
/* This is a GRUB-specific limitation. */
{
"%s: Cannot be loaded at less than 1MB by GRUB"
" (0x%lx).\n",
return 0;
}
}
if (! quiet)
return 1;
}
int
{
int c;
do
{
switch (c)
{
case EOF:
break;
case 'h':
usage (0);
break;
case 'v':
exit (0);
break;
case 'q':
quiet = 1;
break;
default:
usage (1);
break;
}
}
while (c != EOF);
{
{
if (! fp)
{
exit (1);
}
exit (1);
optind++;
}
}
else
{
exit (1);
}
return 0;
}