2004-03-28 21:52:02 +00:00
|
|
|
|
/* cmain.c - Startup code for the PowerPC. */
|
|
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2005-01-03 17:44:25 +00:00
|
|
|
|
* Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc.
|
2004-03-28 21:52:02 +00:00
|
|
|
|
*
|
|
|
|
|
* This program 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.
|
|
|
|
|
*
|
|
|
|
|
* 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 <alloca.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
2004-12-27 Marco Gerards <metgerards@student.han.nl>
* genmk.rb: Handle the `Program' class in the main loop. Written
by Johan Rydberg <jrydberg@gnu.org>.
(Program): New class.
(programs): New variable.
* boot/powerpc/ieee1275/cmain.c: Include <grub/machine/ieee1275.h>
instead of "grub/machine/ieee1275.h". Include <grub/kernel.h>
instead of "grub/kernel.h". Include <grub/machine/init.h>.
(help_arch): Function removed.
* conf/powerpc-ieee1275.rmk (grubof_HEADERS): Add
`powerpc/libgcc.h' and `loader.h'.
(pkgdata_PROGRAMS): New variable.
(sbin_UTILITIES): Variable removed.
(grub_emu_SOURCES): Added kern/powerpc/cache.S.
(grubof_SOURCES): Variable re-defined so it only includes the
core functionality.
(grubof_CFLAGS): Remove `-DGRUBOF'.
(pkgdata_MODULES, fshelp_mod_SOURCES, fshelp_mod_CFLAGS,
(fat_mod_SOURCES, fat_mod_CFLAGS, ext2_mod_SOURCES)
(ext2_mod_CFLAGS, ufs_mod_SOURCES, ufs_mod_CFLAGS)
(minix_mod_SOURCES, minix_mod_CFLAGS, hfs_mod_SOURCES)
(hfs_mod_CFLAGS, jfs_mod_SOURCES, jfs_mod_CFLAGS)
(iso9660_mod_SOURCES, iso9660_mod_CFLAGS, _linux_mod_SOURCES)
(_linux_mod_CFLAGS, linux_mod_SOURCES, linux_mod_CFLAGS)
(normal_mod_SOURCES, normal_mod_CFLAGS, normal_mod_ASFLAGS)
(hello_mod_SOURCES, hello_mod_CFLAGS, boot_mod_SOURCES)
(boot_mod_CFLAGS, terminal_mod_SOURCES, terminal_mod_CFLAGS)
(ls_mod_SOURCES, ls_mod_CFLAGS, cmp_mod_SOURCES, cmp_mod_CFLAGS)
(cat_mod_SOURCES, cat_mod_CFLAGS, font_mod_SOURCES)
(font_mod_CFLAGS, amiga_mod_SOURCES, amiga_mod_CFLAGS)
(apple_mod_SOURCES, apple_mod_CFLAGS, pc_mod_SOURCES)
(pc_mod_CFLAGS): New variables.
* disk/powerpc/ieee1275/ofdisk.c: Include <grub/machine/init.h>.
(grub_ofdisk_iterate): Add a prototype for `dev_iterate'.
* include/grub/dl.h (grub_arch_dl_sync_caches): New prototype.
* include/grub/loader.h (grub_os_area_addr, grub_os_area_size):
Moved from here...
* include/grub/i386/pc/init.h (grub_os_area_addr)
(rub_os_area_size): ... to here.
* include/grub/powerpc/ieee1275/ieee1275.h
(grub_ieee1275_entry_fn): Export symbol.
* include/grub/powerpc/ieee1275/init.h: New file.
* include/grub/powerpc/libgcc.h: Likewise.
* include/grub/cache.h: Likewise.
* kern/powerpc/cache.S: Likewise. Written by Hollis Blanchard
<hollis@penguinppc.org>.
* kern/dl.c: Include <grub/cache.h>.
(grub_dl_flush_cache): New function.
(grub_dl_load_core): Call `grub_dl_flush_cache' to flush the cache
for this module.
* kern/powerpc/ieee1275/init.c (grub_ofdisk_init)
(grub_console_init): Removed prototypes.
(grub_machine_init): Don't initialize the modules anymore.
* kern/powerpc/ieee1275/openfw.c (grub_map): Make the function
static.
* include/grub/powerpc/types.h (GRUB_HOST_WORDS_LITTLEENDIAN):
Macro undef removed.
(GRUB_HOST_WORDS_BIGENDIAN): New macro.
* kern/powerpc/dl.c (grub_arch_dl_relocate_symbols): Add
relocation `R_PPC_REL32'. Return an error when the relocation is
unknown.
* Makefile.in (DATA): Add `$(pkgdata_PROGRAMS)'.
* kern/i386/pc/init.c (grub_arch_sync_caches): New function.
* util/misc.c (grub_arch_sync_caches): Likewise.
2004-12-27 13:46:20 +00:00
|
|
|
|
#include <grub/machine/ieee1275.h>
|
|
|
|
|
#include <grub/kernel.h>
|
|
|
|
|
#include <grub/machine/init.h>
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
|
|
|
|
struct module_info
|
|
|
|
|
{
|
|
|
|
|
uint32_t start;
|
|
|
|
|
uint32_t end;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define roundup(a, s) (((a) + ((s) - 1)) & ~((s) - 1))
|
|
|
|
|
|
|
|
|
|
/* OpenFirmware entry point passed to us from the real bootloader. */
|
2004-04-04 13:46:03 +00:00
|
|
|
|
intptr_t (*grub_ieee1275_entry_fn) (void *);
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
2004-10-12 03:56:10 +00:00
|
|
|
|
grub_uint32_t grub_ieee1275_flags;
|
2005-01-03 17:44:25 +00:00
|
|
|
|
int grub_ieee1275_realmode;
|
2004-10-12 03:56:10 +00:00
|
|
|
|
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
2005-01-03 17:44:25 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
find_options (void)
|
|
|
|
|
{
|
|
|
|
|
grub_ieee1275_phandle_t options;
|
|
|
|
|
|
|
|
|
|
grub_ieee1275_finddevice ("/options", &options);
|
|
|
|
|
grub_ieee1275_get_property (options, "real-mode?", &grub_ieee1275_realmode,
|
|
|
|
|
sizeof (grub_ieee1275_realmode), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-28 21:52:02 +00:00
|
|
|
|
/* Setup the argument vector and pass control over to the main
|
|
|
|
|
function. */
|
|
|
|
|
void
|
2004-10-12 03:56:10 +00:00
|
|
|
|
cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5)
|
2004-03-28 21:52:02 +00:00
|
|
|
|
{
|
|
|
|
|
char **argv, args[256];
|
2004-04-04 13:46:03 +00:00
|
|
|
|
grub_ieee1275_phandle_t chosen;
|
2004-03-28 21:52:02 +00:00
|
|
|
|
int argc = 0, actual;
|
|
|
|
|
|
2004-10-12 03:56:10 +00:00
|
|
|
|
if (r5 == 0xdeadbeef)
|
|
|
|
|
{
|
|
|
|
|
/* Entered from Old World stage1. */
|
|
|
|
|
extern char _start;
|
|
|
|
|
extern char _end;
|
|
|
|
|
|
|
|
|
|
grub_ieee1275_entry_fn = (intptr_t (*)(void *)) r3;
|
|
|
|
|
|
|
|
|
|
grub_ieee1275_flags = GRUB_IEEE1275_NO_PARTITION_0;
|
|
|
|
|
|
|
|
|
|
/* Old World Open Firmware may use 4M-5M without claiming it. */
|
|
|
|
|
grub_ieee1275_claim (0x00400000, 0x00100000, 0, 0);
|
|
|
|
|
|
|
|
|
|
/* Need to claim ourselves so we don't cannibalize our memory later. */
|
|
|
|
|
if (grub_ieee1275_claim ((grub_addr_t) &_start, (grub_addr_t) &_end
|
|
|
|
|
- (grub_addr_t) &_start, 0, 0))
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Assume we were entered from Open Firmware. */
|
|
|
|
|
grub_ieee1275_entry_fn = (intptr_t (*)(void *)) r5;
|
|
|
|
|
}
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
2005-01-03 17:44:25 +00:00
|
|
|
|
find_options ();
|
|
|
|
|
|
2004-03-28 21:52:02 +00:00
|
|
|
|
/* If any argument was passed to the kernel (us), they are
|
|
|
|
|
put in the bootargs property of /chosen. The string can
|
|
|
|
|
be null (just the nul-character), so check that the size
|
|
|
|
|
is actually greater than one. */
|
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
|
grub_ieee1275_finddevice ("/chosen", &chosen);
|
|
|
|
|
if (grub_ieee1275_get_property (chosen, "bootargs", args,
|
2004-03-28 21:52:02 +00:00
|
|
|
|
sizeof args, &actual) == 0
|
|
|
|
|
&& actual > 1)
|
|
|
|
|
{
|
|
|
|
|
/* A command line was passed. */
|
|
|
|
|
char *str = args;
|
|
|
|
|
int nr = 1;
|
|
|
|
|
|
|
|
|
|
/* First time around we count the number of arguments. */
|
|
|
|
|
argc = 2;
|
|
|
|
|
while (*str && *str == ' ')
|
|
|
|
|
str++;
|
|
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
|
if (*(str++) == ' ')
|
|
|
|
|
{
|
|
|
|
|
while (*str && *str == ' ')
|
|
|
|
|
str++;
|
|
|
|
|
if (*str)
|
|
|
|
|
argc++;
|
|
|
|
|
}
|
|
|
|
|
argv = alloca (sizeof (char *) * (argc + 2));
|
|
|
|
|
|
|
|
|
|
/* The bootargs property does not contain the program
|
|
|
|
|
name, just the arguments. */
|
2004-04-04 13:46:03 +00:00
|
|
|
|
argv[0] = "grub";
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
|
|
|
|
/* Second time around we fill in the argv. */
|
|
|
|
|
str = args;
|
|
|
|
|
|
|
|
|
|
while (*str && *str == ' ')
|
|
|
|
|
str++;
|
|
|
|
|
argv[nr++] = str;
|
|
|
|
|
|
|
|
|
|
while (*str)
|
|
|
|
|
{
|
|
|
|
|
if (*str == ' ')
|
|
|
|
|
{
|
|
|
|
|
*(str++) = '\0';
|
|
|
|
|
while (*str && *str == ' ')
|
|
|
|
|
str++;
|
|
|
|
|
if (*str)
|
|
|
|
|
argv[nr++] = str;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
str++;
|
|
|
|
|
}
|
|
|
|
|
argv[nr] = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
argv = alloca (sizeof (char *) * 2);
|
2004-04-04 13:46:03 +00:00
|
|
|
|
argv[0] = "grub";
|
2004-03-28 21:52:02 +00:00
|
|
|
|
argv[1] = 0;
|
|
|
|
|
argc = 1;
|
|
|
|
|
}
|
|
|
|
|
/* Now invoke the main function. */
|
2004-04-04 13:46:03 +00:00
|
|
|
|
/* XXX: grub_main does not parse arguments yet. */
|
|
|
|
|
grub_main ();
|
2004-03-28 21:52:02 +00:00
|
|
|
|
|
|
|
|
|
/* Never reached. */
|
|
|
|
|
}
|