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;

View file

@ -21,7 +21,7 @@
* Note: These functions defined in this file may be called from C.
* Be careful of that you must not modify some registers. Quote
* from gcc-2.95.2/gcc/config/i386/i386.h:
1 for registers not available across function calls.
These must include the FIXED_REGISTERS and also any
registers that can be used without being saved.
@ -46,7 +46,7 @@
*/
.p2align 2 /* force 4-byte alignment */
/*
* void grub_linux_boot_zimage (void)
*/
@ -58,7 +58,7 @@ VARIABLE(grub_linux_real_addr)
.long 0
VARIABLE(grub_linux_is_bzimage)
.long 0
FUNCTION(grub_linux_boot)
/* Must be done before zImage copy. */
call EXT_C(grub_dl_unload_all)
@ -118,7 +118,7 @@ linux_setup_seg:
.word 0
.code32
/*
* This starts the multiboot kernel.
*/
@ -128,14 +128,14 @@ FUNCTION(grub_multiboot_real_boot)
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(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 $MULTIBOOT_MAGIC2,%eax
popl %ecx
@ -159,6 +159,30 @@ FUNCTION(grub_multiboot2_real_boot)
cli
/* Move the magic value into eax and jump to the kernel. */
movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
movl $MULTIBOOT2_BOOTLOADER_MAGIC,%eax
popl %ecx
jmp *%ecx
/*
* Use cdecl calling convention for *BSD kernels.
*/
FUNCTION(grub_unix_real_boot)
call EXT_C(grub_dl_unload_all)
call EXT_C(grub_stop_floppy)
/* Interrupts should be disabled. */
cli
/* Discard `grub_unix_real_boot' return address. */
popl %eax
/* Fetch `entry' address ... */
popl %eax
/*
* ... and put our return address in its place. The kernel will
* ignore it, but it expects %esp to point to it.
*/
call *%eax