Re: [PATCH] load FreeBSD ELF modules

2009-06-21 Thread Vladimir 'phcoder' Serbinenko
Committed

On Sat, Jun 13, 2009 at 12:23 PM, Vladimir 'phcoder' Serbinenko 
phco...@gmail.com wrote:

 Hello

 On Fri, Jun 12, 2009 at 8:14 PM, Vladimir 'phcoder'
 Serbinenkophco...@gmail.com wrote:
  Hello. Unlike some other types of modules (mfsroot, splash, ..)
  FreeBSD relies on ELF modules being partially parsed by booter. So I
  added new function freebsd_module_elf specifically for loading elf
  modules. I also factorised freebsd_module_add_meta to do only parts
  common to all types of modules and moved module-specific parts to
  corresponding functions. I tested it only with 64-bit kernel. It works
  for 64-bit kernels but doesn't work for 32-bit ones. Dumps show that
  32-bit loader uses quite different format. I'll investigate the issue
 
 I figured 32-bit modules out. It required loading additional elements
 like _DYNAMIC for both kernel and modules.
  --
  Regards
  Vladimir 'phcoder' Serbinenko
 



 --
 Regards
 Vladimir 'phcoder' Serbinenko




-- 
Regards
Vladimir 'phcoder' Serbinenko

Personal git repository: http://repo.or.cz/w/grub2/phcoder.git
___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] load FreeBSD ELF modules

2009-06-13 Thread Vladimir 'phcoder' Serbinenko
Hello

On Fri, Jun 12, 2009 at 8:14 PM, Vladimir 'phcoder'
Serbinenkophco...@gmail.com wrote:
 Hello. Unlike some other types of modules (mfsroot, splash, ..)
 FreeBSD relies on ELF modules being partially parsed by booter. So I
 added new function freebsd_module_elf specifically for loading elf
 modules. I also factorised freebsd_module_add_meta to do only parts
 common to all types of modules and moved module-specific parts to
 corresponding functions. I tested it only with 64-bit kernel. It works
 for 64-bit kernels but doesn't work for 32-bit ones. Dumps show that
 32-bit loader uses quite different format. I'll investigate the issue

I figured 32-bit modules out. It required loading additional elements
like _DYNAMIC for both kernel and modules.
 --
 Regards
 Vladimir 'phcoder' Serbinenko




-- 
Regards
Vladimir 'phcoder' Serbinenko
diff --git a/ChangeLog b/ChangeLog
index b41dd6c..912a6f3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,37 @@
+2009-06-13  Vladimir Serbinenko  phco...@gmail.com
+
+	Load BSD ELF modules
+
+	* conf/i386-pc.rmk (bsd_mod_SOURCES): Add loader/i386/bsd32.c
+	and loader/i386/bsd64.c
+	* include/grub/i386/bsd.h (FREEBSD_MODTYPE_MODULE): Remove
+	(FREEBSD_MODTYPE_ELF_MODULE): New definition
+	(FREEBSD_MODTYPE_ELF_MODULE_OBJ): Likewise
+	(grub_freebsd_load_elfmodule32): New declaration
+	(grub_freebsd_load_elfmoduleobj64): Likewise
+	(grub_freebsd_load_elf_meta32): Likewise
+	(grub_freebsd_load_elf_meta64): Likewise
+	(grub_freebsd_add_meta): Likewise
+	(grub_freebsd_add_meta_module): Likewise
+	* loader/i386/bsd.c (grub_freebsd_add_meta): Make global
+	(grub_freebsd_add_meta_module): Likewise and move module-specific
+	parts to grub_cmd_freebsd and grub_cmd_freebsd_module
+	(grub_cmd_freebsd): Add elf-kernel specific parts
+	based on grub_freebsd_add_meta_module
+	(grub_cmd_freebsd_module): Add type parsing moved from
+	grub_freebsd_add_meta_module
+	(grub_cmd_freebsd_module_elf): New function
+	(cmd_freebsd_module_elf): New variable
+	(GRUB_MOD_INIT): Register freebsd_module_elf
+	* loader/i386/bsd32.c: New file
+	* loader/i386/bsd64.c: Likewise
+	* loader/i386/bsdXX.c: Likewise
+	* kern/elf.c (grub_elf32_load): Let hook decide which pheaders to load
+	(grub_elf64_load): Likewise
+	* include/grub/elfload.h (grub_elf32_load_hook_t): New parameter do_load
+	All users updated
+	(grub_elf64_load_hook_t): Likewise
+
 2009-06-12  Pavel Roskin  pro...@gnu.org
 
 	* Makefile.in (pkgdata_SRCDIR): Remove.  genmodsrc.sh and
diff --git a/conf/i386-pc.rmk b/conf/i386-pc.rmk
index abb6fd5..47427db 100644
--- a/conf/i386-pc.rmk
+++ b/conf/i386-pc.rmk
@@ -328,7 +328,7 @@ aout_mod_CFLAGS = $(COMMON_CFLAGS)
 aout_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For bsd.mod
-bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S
+bsd_mod_SOURCES = loader/i386/bsd.c loader/i386/bsd32.c loader/i386/bsd64.c loader/i386/bsd_helper.S loader/i386/bsd_trampoline.S
 bsd_mod_CFLAGS = $(COMMON_CFLAGS)
 bsd_mod_LDFLAGS = $(COMMON_LDFLAGS)
 bsd_mod_ASFLAGS = $(COMMON_ASFLAGS)
diff --git a/include/grub/elfload.h b/include/grub/elfload.h
index 5d611da..6e09e0d 100644
--- a/include/grub/elfload.h
+++ b/include/grub/elfload.h
@@ -37,9 +37,9 @@ struct grub_elf_file
 typedef struct grub_elf_file *grub_elf_t;
 
 typedef grub_err_t (*grub_elf32_load_hook_t)
-  (Elf32_Phdr *phdr, grub_addr_t *addr);
+  (Elf32_Phdr *phdr, grub_addr_t *addr, int *load);
 typedef grub_err_t (*grub_elf64_load_hook_t)
-  (Elf64_Phdr *phdr, grub_addr_t *addr);
+  (Elf64_Phdr *phdr, grub_addr_t *addr, int *load);
 
 grub_elf_t grub_elf_open (const char *);
 grub_elf_t grub_elf_file (grub_file_t);
diff --git a/include/grub/i386/bsd.h b/include/grub/i386/bsd.h
index 321b31f..3130697 100644
--- a/include/grub/i386/bsd.h
+++ b/include/grub/i386/bsd.h
@@ -86,7 +86,8 @@
 
 #define FREEBSD_MODTYPE_KERNEL		elf kernel
 #define FREEBSD_MODTYPE_KERNEL64	elf64 kernel
-#define FREEBSD_MODTYPE_MODULE		elf module
+#define FREEBSD_MODTYPE_ELF_MODULE	elf module
+#define FREEBSD_MODTYPE_ELF_MODULE_OBJ	elf obj module
 #define FREEBSD_MODTYPE_RAW		raw
 
 struct grub_freebsd_bootinfo
@@ -229,6 +230,21 @@ struct grub_netbsd_btinfo_bootdisk
 
 void grub_unix_real_boot (grub_addr_t entry, ...)
  __attribute__ ((cdecl,noreturn));
+grub_err_t grub_freebsd_load_elfmodule32 (grub_file_t file, int argc,
+	  char *argv[], grub_addr_t *kern_end);
+grub_err_t grub_freebsd_load_elfmodule_obj64 (grub_file_t file, int argc,
+	  char *argv[],
+	  grub_addr_t *kern_end);
+grub_err_t grub_freebsd_load_elf_meta32 (grub_file_t file,
+	 grub_addr_t *kern_end);
+grub_err_t grub_freebsd_load_elf_meta64 (grub_file_t file,
+	 grub_addr_t *kern_end);
+
+grub_err_t grub_freebsd_add_meta (grub_uint32_t type, void *data,
+  grub_uint32_t len);
+grub_err_t grub_freebsd_add_meta_module (char *filename, char *type,
+	 int argc, char **argv,
+	 grub_addr_t addr, grub_uint32_t size);
 
 extern grub_uint8_t