2008-02-19 Bean <bean123ch@gmail.com>

* conf/i386-pc.rmk (pkglib_MODULES): Add aout.mod _bsd.mod and bsd.mod.
	(aout_mod_SOURCES): New variable.
	(aout_mod_CFLAGS): Likewise.
	(aout_mod_LDFLAGS): Likewise.
	(_bsd_mod_SOURCES): New variable.
	(_bsd_mod_CFLAGS): Likewise.
	(_bsd_mod_LDFLAGS): Likewise.
	(bsd_mod_SOURCES): New variable.
	(bsd_mod_CFLAGS): Likewise.
	(bsd_mod_LDFLAGS): Likewise.

	* include/grub/aout.h: New file.

	* include/grub/i386/loader.h (grub_unix_real_boot): New function.

	* include/grub/i386/bsd.h: New file.

	* include/grub/i386/pc/init.h (grub_get_mmap_entry): Use EXPORT_FUNC
	to make it public.

	* kern/elf.c (grub_elf32_load): Get the physical address after the hook
	function is called, so that it's possible to change it inside the hook.
	(grub_elf64_load): Likewise.
	(grub_elf_file): Don't close the file if elf header is not found.
	(grub_elf_close): Close the file if grub_elf_file fails (The new
	grub_elf_file won't close it).
	(grub_elf32_size): Use NESTED_FUNC_ATTR for nested function calcsize.
	(grub_elf64_size): Likewise.

	* kern/i386/loader.S (grub_unix_real_boot): New function.

	* loader/aout.c: New file.

	* loader/i386/bsd.c: New file.

	* loader/i386/bsd_normal.c: New file.

	* loader/i386/pc/multiboot.c (grub_multiboot): Handle a.out format.

	* loader/multiboot2.c (grub_multiboot2): Reset grub_errno so that it
	can test othe formats.
This commit is contained in:
bean 2008-02-19 16:40:45 +00:00
parent 865bede901
commit d38e24c285
14 changed files with 1571 additions and 50 deletions

View file

@ -85,9 +85,8 @@ grub_elf_file (grub_file_t file)
return elf;
fail:
grub_error_push ();
grub_elf_close (elf);
grub_error_pop ();
grub_free (elf->phdrs);
grub_free (elf);
return 0;
}
@ -95,12 +94,17 @@ grub_elf_t
grub_elf_open (const char *name)
{
grub_file_t file;
grub_elf_t elf;
file = grub_gzfile_open (name, 1);
if (! file)
return 0;
return grub_elf_file (file);
elf = grub_elf_file (file);
if (! elf)
grub_file_close (file);
return elf;
}
@ -177,8 +181,8 @@ grub_elf32_size (grub_elf_t elf)
/* Run through the program headers to calculate the total memory size we
* should claim. */
auto int calcsize (grub_elf_t _elf, Elf32_Phdr *phdr, void *_arg);
int calcsize (grub_elf_t UNUSED _elf, Elf32_Phdr *phdr, void UNUSED *_arg)
auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf32_Phdr *phdr, void *_arg);
int NESTED_FUNC_ATTR calcsize (grub_elf_t UNUSED _elf, Elf32_Phdr *phdr, void UNUSED *_arg)
{
/* Only consider loadable segments. */
if (phdr->p_type != PT_LOAD)
@ -228,9 +232,9 @@ grub_elf32_load (grub_elf_t _elf, grub_elf32_load_hook_t _load_hook,
if (phdr->p_type != PT_LOAD)
return 0;
load_addr = phdr->p_paddr;
if (load_hook && load_hook (phdr, &load_addr))
return 1;
load_addr = phdr->p_paddr;
if (load_addr < load_base)
load_base = load_addr;
@ -355,8 +359,8 @@ grub_elf64_size (grub_elf_t elf)
/* Run through the program headers to calculate the total memory size we
* should claim. */
auto int calcsize (grub_elf_t _elf, Elf64_Phdr *phdr, void *_arg);
int calcsize (grub_elf_t UNUSED _elf, Elf64_Phdr *phdr, void UNUSED *_arg)
auto int NESTED_FUNC_ATTR calcsize (grub_elf_t _elf, Elf64_Phdr *phdr, void *_arg);
int NESTED_FUNC_ATTR calcsize (grub_elf_t UNUSED _elf, Elf64_Phdr *phdr, void UNUSED *_arg)
{
/* Only consider loadable segments. */
if (phdr->p_type != PT_LOAD)
@ -407,9 +411,9 @@ grub_elf64_load (grub_elf_t _elf, grub_elf64_load_hook_t _load_hook,
if (phdr->p_type != PT_LOAD)
return 0;
load_addr = phdr->p_paddr;
if (load_hook && load_hook (phdr, &load_addr))
return 1;
load_addr = phdr->p_paddr;
if (load_addr < load_base)
load_base = load_addr;