aout image support

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-02-13 16:26:50 +01:00
parent 6bea3f8983
commit a49217cff7
10 changed files with 122 additions and 81 deletions

View File

@ -129,7 +129,7 @@ bootit:
mov NOTIFICATION_DONE_LEN, %o3
sethi %hi(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o2
jmpl %o2 + %lo(GRUB_BOOT_MACHINE_IMAGE_ADDRESS), %o7
mov CIF_REG, %o0
mov CIF_REG, %o4
1: ba,a 1b
lastlist:

View File

@ -48,7 +48,7 @@ kernel_img_SOURCES = kern/sparc64/ieee1275/crt0.S kern/ieee1275/cmain.c \
symlist.c kern/$(target_cpu)/cache.S
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x200000,-Bstatic,-melf64_sparc -static-libgcc -lgcc
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,0x4400,-Bstatic,-melf64_sparc -static-libgcc -lgcc
kernel_img_FORMAT = binary
symlist.c: $(addprefix include/grub/,$(kernel_img_HEADERS)) config.h gensymlist.sh

View File

@ -102,6 +102,7 @@ union grub_aout_header
#define AOUT_MID_I386 134 /* i386 BSD binary */
#define AOUT_MID_SPARC 138 /* sparc */
#define AOUT_MID_HP200 200 /* hp200 (68010) BSD binary */
#define AOUT_MID_SUN 0x103
#define AOUT_MID_HP300 300 /* hp300 (68020+68881) BSD binary */
#define AOUT_MID_HPUX 0x20C /* hp200/300 HP-UX binary */
#define AOUT_MID_HPUX800 0x20B /* hp800 HP-UX binary */
@ -114,10 +115,14 @@ union grub_aout_header
#define AOUT_GETMID(header) ((header).a_midmag >> 16) & 0x03ff)
#define AOUT_GETFLAG(header) ((header).a_midmag >> 26) & 0x3f)
#ifndef GRUB_UTIL
int EXPORT_FUNC(grub_aout_get_type) (union grub_aout_header *header);
grub_err_t EXPORT_FUNC(grub_aout_load) (grub_file_t file, int offset,
grub_addr_t load_addr, int load_size,
grub_addr_t bss_end_addr);
#endif
#endif /* ! GRUB_AOUT_HEADER */

View File

@ -59,6 +59,8 @@ extern grub_addr_t grub_arch_modules_addr (void);
extern void EXPORT_FUNC(grub_module_iterate) (int (*hook) (struct grub_module_header *));
grub_addr_t grub_modules_get_end (void);
/* The start point of the C code. */
void grub_main (void);

View File

@ -41,8 +41,21 @@
#define GRUB_KERNEL_MACHINE_RAW_SIZE 0
#define GRUB_PLATFORM_IMAGE_FORMATS "raw, aout"
#define GRUB_PLATFORM_IMAGE_DEFAULT_FORMAT "raw"
#define GRUB_PLATFORM_IMAGE_DEFAULT GRUB_PLATFORM_IMAGE_RAW
#ifndef ASM_FILE
typedef enum {
GRUB_PLATFORM_IMAGE_RAW,
GRUB_PLATFORM_IMAGE_AOUT
}
grub_platform_image_format_t;
#define GRUB_PLATFORM_IMAGE_RAW GRUB_PLATFORM_IMAGE_RAW
#define GRUB_PLATFORM_IMAGE_AOUT GRUB_PLATFORM_IMAGE_AOUT
#include <grub/symbol.h>
#include <grub/types.h>

View File

@ -53,6 +53,25 @@ grub_module_iterate (int (*hook) (struct grub_module_header *header))
}
}
/* This is actualy platform-independant but used only on yeeloong and sparc. */
#if defined (GRUB_MACHINE_MIPS_YEELOONG) || defined (GRUB_MACHINE_SPARC64)
grub_addr_t
grub_modules_get_end (void)
{
struct grub_module_info *modinfo;
grub_addr_t modbase;
modbase = grub_arch_modules_addr ();
modinfo = (struct grub_module_info *) modbase;
/* Check if there are any modules. */
if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
return modbase;
return modbase + modinfo->size;
}
#endif
/* Load all modules in core. */
static void
grub_load_modules (void)

View File

@ -63,35 +63,13 @@ grub_machine_mmap_iterate (int NESTED_FUNC_ATTR (*hook) (grub_uint64_t,
return GRUB_ERR_NONE;
}
static void *
get_modules_end (void)
{
struct grub_module_info *modinfo;
struct grub_module_header *header;
grub_addr_t modbase;
modbase = grub_arch_modules_addr ();
modinfo = (struct grub_module_info *) modbase;
/* Check if there are any modules. */
if ((modinfo == 0) || modinfo->magic != GRUB_MODULE_MAGIC)
return modinfo;
for (header = (struct grub_module_header *) (modbase + modinfo->offset);
header < (struct grub_module_header *) (modbase + modinfo->size);
header = (struct grub_module_header *) ((char *) header + header->size));
return header;
}
void
grub_machine_init (void)
{
void *modend;
modend = get_modules_end ();
grub_addr_t modend;
modend = grub_modules_get_end ();
grub_mm_init_region (modend, (grub_arch_memsize << 20)
- (((grub_addr_t) modend) - GRUB_ARCH_LOWMEMVSTART));
- (modend - GRUB_ARCH_LOWMEMVSTART));
/* FIXME: use upper memory as well. */
grub_install_get_time_ms (grub_rtc_get_time_ms);

View File

@ -24,7 +24,7 @@
.globl _start
_start:
ba codestart
nop
mov %o4, %o0
. = EXT_C(_start) + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE

View File

@ -104,7 +104,7 @@ grub_machine_set_prefix (void)
static void
grub_heap_init (void)
{
grub_mm_init_region ((void *)(long)0x4000UL, 0x200000 - 0x4000);
grub_mm_init_region ((void *) grub_modules_get_end (), 0x200000);
}
static void

View File

@ -23,6 +23,7 @@
#include <grub/machine/kernel.h>
#include <grub/machine/memory.h>
#include <grub/elf.h>
#include <grub/aout.h>
#include <grub/i18n.h>
#include <grub/kernel.h>
#include <grub/disk.h>
@ -230,6 +231,36 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
grub_util_info ("the core size is 0x%x", core_size);
#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= grub_host_to_target32 (total_module_size);
#endif
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_host_to_target32 (kernel_size);
#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
= grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
#endif
#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
/* If we included a drive in our prefix, let GRUB know it doesn't have to
prepend the drive told by BIOS. */
if (prefix[0] == '(')
{
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
= grub_host_to_target32 (-2);
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
= grub_host_to_target32 (-2);
}
#endif
#ifdef GRUB_MACHINE_PCBIOS
if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
grub_util_error (_("core image is too big (%p > %p)"),
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
GRUB_MEMORY_MACHINE_UPPER);
#endif
#if defined(GRUB_MACHINE_PCBIOS)
{
unsigned num;
@ -299,62 +330,50 @@ generate_image (const char *dir, char *prefix, FILE *out, char *mods[],
free (boot_path);
}
#elif defined (GRUB_MACHINE_SPARC64)
{
unsigned int num;
char *boot_path, *boot_img;
size_t boot_size;
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
num <<= GRUB_DISK_SECTOR_BITS;
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("diskboot.img is not one sector size");
boot_img = grub_util_read_image (boot_path);
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_host_to_target32 (num);
grub_util_write_image (boot_img, boot_size, out);
free (boot_img);
free (boot_path);
}
#endif
#ifdef GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_TOTAL_MODULE_SIZE))
= grub_host_to_target32 (total_module_size);
#endif
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_KERNEL_IMAGE_SIZE))
= grub_host_to_target32 (kernel_size);
#ifdef GRUB_KERNEL_MACHINE_COMPRESSED_SIZE
*((grub_uint32_t *) (core_img + GRUB_KERNEL_MACHINE_COMPRESSED_SIZE))
= grub_host_to_target32 (core_size - GRUB_KERNEL_MACHINE_RAW_SIZE);
#endif
#if defined(GRUB_KERNEL_MACHINE_INSTALL_DOS_PART) && defined(GRUB_KERNEL_MACHINE_INSTALL_BSD_PART)
/* If we included a drive in our prefix, let GRUB know it doesn't have to
prepend the drive told by BIOS. */
if (prefix[0] == '(')
if (format == GRUB_PLATFORM_IMAGE_AOUT)
{
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_DOS_PART))
= grub_host_to_target32 (-2);
*((grub_int32_t *) (core_img + GRUB_KERNEL_MACHINE_INSTALL_BSD_PART))
= grub_host_to_target32 (-2);
void *aout_img;
size_t aout_size;
struct grub_aout32_header *aout_head;
aout_size = core_size + sizeof (*aout_head);
aout_img = xmalloc (aout_size);
aout_head = aout_img;
aout_head->a_midmag = grub_host_to_target32 ((AOUT_MID_SUN << 16)
| AOUT32_OMAGIC);
aout_head->a_text = grub_host_to_target32 (core_size);
aout_head->a_entry = grub_host_to_target32 (0x4400);
memcpy (aout_img + sizeof (*aout_head), core_img, core_size);
free (core_img);
core_img = aout_img;
core_size = aout_size;
}
#endif
else
{
unsigned int num;
char *boot_path, *boot_img;
size_t boot_size;
#ifdef GRUB_MACHINE_PCBIOS
if (GRUB_KERNEL_MACHINE_LINK_ADDR + core_size > GRUB_MEMORY_MACHINE_UPPER)
grub_util_error (_("core image is too big (%p > %p)"),
GRUB_KERNEL_MACHINE_LINK_ADDR + core_size,
GRUB_MEMORY_MACHINE_UPPER);
#endif
num = ((core_size + GRUB_DISK_SECTOR_SIZE - 1) >> GRUB_DISK_SECTOR_BITS);
num <<= GRUB_DISK_SECTOR_BITS;
#if defined(GRUB_MACHINE_MIPS)
boot_path = grub_util_get_path (dir, "diskboot.img");
boot_size = grub_util_get_image_size (boot_path);
if (boot_size != GRUB_DISK_SECTOR_SIZE)
grub_util_error ("diskboot.img is not one sector size");
boot_img = grub_util_read_image (boot_path);
*((grub_uint32_t *) (boot_img + GRUB_DISK_SECTOR_SIZE
- GRUB_BOOT_MACHINE_LIST_SIZE + 8))
= grub_host_to_target32 (num);
grub_util_write_image (boot_img, boot_size, out);
free (boot_img);
free (boot_path);
}
#elif defined(GRUB_MACHINE_MIPS)
if (format == GRUB_PLATFORM_IMAGE_ELF)
{
char *elf_img;
@ -527,6 +546,11 @@ main (int argc, char *argv[])
if (strcmp (optarg, "elf") == 0)
format = GRUB_PLATFORM_IMAGE_ELF;
else
#endif
#ifdef GRUB_PLATFORM_IMAGE_AOUT
if (strcmp (optarg, "aout") == 0)
format = GRUB_PLATFORM_IMAGE_AOUT;
else
#endif
usage (1);
break;