Skip to contentSkip to conversation

Module support for the PPC

PATCH Marco Gerards 2 participants 4 messages Dec 19, 2004 – Dec 22, 2004

lore
Share & tools
lore
#0 lore raw

Hi,

Here is a patch to add module loading support to the PPC. There is still a small problem with the alignment, but perhaps Timothy's patch will fix that, I have not tried that yet.

After this patch is committed grubof will be really minimal and will be able to load modules. With the upcoming patch from Hollis it will be possible to add a note section and extra modules to it.

Although this patch is not fully tested yet and there are still problems, I still want to commit it ASAP because this makes it easier for us all to debug and develop GRUB 2 for the PPC.

There might be some problems that I caused for the PC port because I moved around some code, but that will all be solved before I commit the patch. I just want to send this patch in this evening so it can be reviewed.

One thing that will seem a bit funny is grub/include/powerpc/libgcc.h. This file contains all symbols from libgcc (that is where they come from, right) that are included in grubof. Or would it be better to remove this and link every module to libgcc?

Please let me know what you think about it.

Thanks,
Marco

2004-12-19 Marco Gerards <[email protected]>

* genmk.rb: Handle the `Program' class in the main loop. Written by Johan Rydberg <[email protected]>. (Program): New class.
* 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.
* kern/powerpc/cache.S: Likewise. Written by Hollis Blanchard <[email protected]>.
* kern/dl.c (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.

Index: genmk.rb
===================================================================
RCS file: /cvsroot/grub/grub2/genmk.rb,v
retrieving revision 1.8

genmk.rb +53 -0
diff -u -p -r1.8 genmk.rb
@@ -205,9 +205,55 @@ MOSTLYCLEANFILES += #{deps_str}
   end
 end
 
+class Program
+  def initialize(dir, name)
+    @dir = dir
+    @name = name
+  end
+  attr_reader :dir, :name
+
+  def rule(sources)
+    prefix = @name.to_var
+    objs = sources.collect do |src|
+      raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
+      prefix + '-' + src.to_obj
+    end
+    objs_str = objs.join(' ');
+    deps = objs.collect {|obj| obj.suffix('d')}
+    deps_str = deps.join(' ');
+
+    "CLEANFILES += #{@name} #{objs_str}
+MOSTLYCLEANFILES += #{deps_str}
+
+#{@name}: #{objs_str}
+	$(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(#{prefix}_LDFLAGS)
+
+" + objs.collect_with_index do |obj, i|
+      src = sources[i]
+      fake_obj = File.basename(src).suffix('o')
+      dep = deps[i]
+      dir = File.dirname(src)
+
+      "#{obj}: #{src}
+	$(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -c -o $@ $<
+
+#{dep}: #{src}
+	set -e; \
+	  $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -M $< \
+	  | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
+	  [ -s $@ ] || rm -f $@
+
+-include #{dep}
+
+"
+    end.join('')
+  end
+end
+
 images = []
 utils = []
 pmodules = []
+programs = []
 
 cont = false
 s = nil
@@ -245,6 +291,11 @@ while l = gets
 	    Utility.new(prefix, util)
 	  end
 
+	when 'PROGRAMS'
+	  programs += args.split(/\s+/).collect do |util|
+	    Program.new(prefix, util)
+	  end
+
 	when 'SOURCES'
 	  if img = images.detect() {|i| i.name.to_var == prefix}
 	    print img.rule(args.split(/\s+/))
@@ -252,6 +303,8 @@ while l = gets
 	    print pmod.rule(args.split(/\s+/))
 	  elsif util = utils.detect() {|u| u.name.to_var == prefix}
 	    print util.rule(args.split(/\s+/))
+	  elsif program = programs.detect() {|u| u.name.to_var == prefix}
+	    print program.rule(args.split(/\s+/))
 	  end
 	end
       end

Index: boot/powerpc/ieee1275/cmain.c
===================================================================
RCS file: /cvsroot/grub/grub2/boot/powerpc/ieee1275/cmain.c,v retrieving revision 1.4

powerpc/ieee1275/cmain.c +3 -11
diff -u -p -r1.4 cmain.c
@@ -21,8 +21,9 @@
 #include <alloca.h>
 #include <stdint.h>
 
-#include "grub/machine/ieee1275.h"
-#include "grub/kernel.h"
+#include <grub/machine/ieee1275.h>
+#include <grub/kernel.h>
+#include <grub/machine/init.h>
 
 struct module_info
 {
@@ -38,15 +39,6 @@ intptr_t (*grub_ieee1275_entry_fn) (void
 grub_uint32_t grub_ieee1275_flags;
 
 
-/* Return a help text for this architecture.  */
-const char *
-help_arch (void)
-{
-  /* No special information.  */
-  return "";
-}
-
-
 /* Setup the argument vector and pass control over to the main
    function.  */
 void

Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.16

powerpc-ieee1275.rmk +100 -12

141 lines not on this page · raw message

Index: disk/powerpc/ieee1275/ofdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/disk/powerpc/ieee1275/ofdisk.c,v retrieving revision 1.5

powerpc/ieee1275/ofdisk.c +3 -0
diff -u -p -r1.5 ofdisk.c
@@ -22,10 +22,13 @@
 #include <grub/disk.h>
 #include <grub/mm.h>
 #include <grub/machine/ieee1275.h>
+#include <grub/machine/init.h>
 
 static int
 grub_ofdisk_iterate (int (*hook) (const char *name))
 {
+  auto int dev_iterate (struct grub_ieee1275_devalias *alias);
+  
   int dev_iterate (struct grub_ieee1275_devalias *alias)
     {
       if (! grub_strcmp (alias->type, "block"))

Index: include/grub/dl.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/dl.h,v
retrieving revision 1.6

grub/dl.h +1 -0
diff -u -p -r1.6 dl.h
@@ -85,6 +85,7 @@ grub_err_t EXPORT_FUNC(grub_dl_register_
 void *EXPORT_FUNC(grub_dl_resolve_symbol) (const char *name);
 
 int grub_arch_dl_check_header (void *ehdr, grub_size_t size);
+void grub_arch_dl_sync_caches (void *address, grub_size_t len);
 grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr);
 
 #endif /* ! GRUB_DL_H */

Index: include/grub/loader.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/loader.h,v retrieving revision 1.6

grub/loader.h +0 -3
diff -u -p -r1.6 loader.h
@@ -26,9 +26,6 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
-extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
-extern grub_size_t EXPORT_VAR(grub_os_area_size);
-
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 void EXPORT_FUNC(grub_loader_set) (grub_err_t (*boot) (void),
 				   grub_err_t (*unload) (void));

Index: include/grub/i386/pc/init.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/i386/pc/init.h,v retrieving revision 1.4

grub/i386/pc/init.h +3 -0
diff -u -p -r1.4 init.h
@@ -27,6 +27,9 @@
 extern grub_size_t EXPORT_VAR(grub_lower_mem);
 extern grub_size_t EXPORT_VAR(grub_upper_mem);
 
+extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
+extern grub_size_t EXPORT_VAR(grub_os_area_size);
+
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
 grub_uint16_t grub_get_memsize (int extended);

Index: include/grub/powerpc/libgcc.h
===================================================================
RCS file: include/grub/powerpc/libgcc.h

grub/powerpc/libgcc.h new file +42 -0

42 lines not on this page · raw message

Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v retrieving revision 1.9

grub/powerpc/ieee1275/ieee1275.h +1 -1
diff -u -p -r1.9 ieee1275.h
@@ -39,7 +39,7 @@ struct grub_ieee1275_mem_region 
   unsigned int size;
 };
 
-extern intptr_t (*grub_ieee1275_entry_fn) (void *);
+extern intptr_t(* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *);
 
 #ifndef IEEE1275_CALL_ENTRY_FN
 #define IEEE1275_CALL_ENTRY_FN(args) (*grub_ieee1275_entry_fn) (args)

Index: include/grub/powerpc/ieee1275/init.h
===================================================================
RCS file: include/grub/powerpc/ieee1275/init.h

grub/powerpc/ieee1275/init.h new file +28 -0
diff -N include/grub/powerpc/ieee1275/init.h
@@ -0,0 +1,28 @@
+/* ieee1275.h - Access the Open Firmware client interface.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  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.
+ */
+
+#ifndef GRUB_INIT_MACHINE_HEADER
+#define GRUB_INIT_MACHINE_HEADER	1
+
+void cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5);
+void grub_ofdisk_init (void);
+void grub_console_init (void);
+
+#endif /* ! GRUB_INIT_MACHINE_HEADER */

Index: kern/dl.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/dl.c,v
retrieving revision 1.7

dl.c +16 -0
diff -u -p -r1.7 dl.c
@@ -479,6 +479,20 @@ grub_dl_unref (grub_dl_t mod)
   return --mod->ref_count;
 }
 
+static void
+grub_dl_flush_cache (grub_dl_t mod)
+{
+  grub_dl_segment_t seg;
+  grub_dl_segment_t segn;
+  
+  for (seg = mod->segment; seg; seg = segn)
+    {
+      segn = seg->next;
+      grub_free (seg->addr);
+      grub_arch_dl_sync_caches (seg->addr, seg->size);
+    }
+}
+
 /* Load a module from core memory.  */
 grub_dl_t
 grub_dl_load_core (void *addr, grub_size_t size)
@@ -515,6 +529,8 @@ grub_dl_load_core (void *addr, grub_size
       return 0;
     }
 
+  grub_dl_flush_cache (mod);
+  
   grub_dl_call_init (mod);
   
   if (grub_dl_add (mod))

Index: kern/powerpc/cache.S
===================================================================
RCS file: kern/powerpc/cache.S

powerpc/cache.S new file +45 -0

45 lines not on this page · raw message

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.10

powerpc/ieee1275/init.c +2 -12
diff -u -p -r1.10 init.c
@@ -29,10 +29,8 @@
 #include <grub/setjmp.h>
 #include <grub/env.h>
 #include <grub/misc.h>
-
-void grub_ofdisk_init (void);
-void grub_console_init (void);
-
+#include <grub/machine/init.h>
+#include <grub/machine/time.h>
 
 /* XXX: Modules are not yet supported.  */
 grub_addr_t grub_end_addr = -1;
@@ -73,14 +71,6 @@ grub_machine_init (void)
   /* XXX: Loadable modules are not supported.  */
   grub_env_set ("prefix", "");
 
-  grub_ext2_init ();
-  grub_normal_init ();
-  grub_boot_init ();
-  grub_linux_init ();
-  grub_linux_normal_init ();
-  grub_pc_partition_map_init ();
-  grub_amiga_partition_map_init ();
-  grub_apple_partition_map_init ();
   grub_ofdisk_init ();
 }
 

Index: kern/powerpc/ieee1275/openfw.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/openfw.c,v retrieving revision 1.5

powerpc/ieee1275/openfw.c +1 -1
diff -u -p -r1.5 openfw.c
@@ -144,7 +144,7 @@ grub_devalias_iterate (int (*hook) (stru
 }
 
 /* Call the "map" method of /chosen/mmu.  */
-int
+static int
 grub_map (grub_addr_t phys, grub_addr_t virt, grub_uint32_t size,
 		   grub_uint8_t mode)
 {
#1 lore raw
Quoted 10 lines · Marco Gerards
dl.c +4 -0
@@ -479,6 +479,20 @@ grub_dl_unref (grub_dl_t mod)
   return --mod->ref_count;
 }
 
+static void
+grub_dl_flush_cache (grub_dl_t mod)
+{
+  grub_dl_segment_t seg;

dl.c grub_dl_unref (grub_dl_t mod) · line 495

Quoted 10 lines
dl.c +10 -0
+  grub_dl_segment_t segn;
+
+  for (seg = mod->segment; seg; seg = segn)
+    {
+      segn = seg->next;
+      grub_free (seg->addr);
+      grub_arch_dl_sync_caches (seg->addr, seg->size);
+    }
+}
+

That for loop confuses me. Couldn't it be written as

	for (seg = mod->segment; seg; seg = seg->next)

?

Also, I'm not sure why grub_free is here. Is that intentional?

Unrelated, I don't like naming the function "grub_arch_dl_sync_caches", since it has nothing to do dl code really; that's just the only user right now. I'd prefer "grub_arch_sync_caches".

Other than that, looks fine to me, and I hope we can get this checked in soon for some holiday hacking. :)

-Hollis

#2 lore raw
Quoted 10 lines · Hollis Blanchard

dl.c grub_dl_unref (grub_dl_t mod) · line 495

Quoted 8 lines
dl.c +8 -0
+  for (seg = mod->segment; seg; seg = segn)
+    {
+      segn = seg->next;
+      grub_free (seg->addr);
+      grub_arch_dl_sync_caches (seg->addr, seg->size);
+    }
+}
+

That for loop confuses me. Couldn't it be written as

Quoted 4 lines
	for (seg = mod->segment; seg; seg = seg->next)

?

Also, I'm not sure why grub_free is here. Is that intentional?

Right! Nice catch! That caused the problem I had. I feel so stupid now... When I added this function I copied it from the function to free a module and quickly added the cache flush there.

Quoted 4 lines

Unrelated, I don't like naming the function "grub_arch_dl_sync_caches", since it has nothing to do dl code really; that's just the only user right now. I'd prefer "grub_arch_sync_caches".

Ok.

Quoted 2 lines

Other than that, looks fine to me, and I hope we can get this checked in soon for some holiday hacking. :)

Same here. :)

If I hear no objections before friday I will check in this patch with the changes I described.

Thanks,
Marco

#3 lore raw
In reply to Marco Gerards
Quoted 3 lines · Marco Gerards

Here is a patch to add module loading support to the PPC. There is still a small problem with the alignment, but perhaps Timothy's patch will fix that, I have not tried that yet.

All known problems are fixed. Here is the new changelog+patch. I still haven't tried compiling it on the PC, but as I said I will do that. Anyway, I really think it is ok to commit it now. But as I said I will wait for Friday. If someone can review this patch, please do.

After that I want to integrate Hollis' grub-mkimage and note patches ASAP. After that there are still some bugs that need to be fixed and some features that should be implemented. Mainly:

- Integrating the patch for a non-fixed console size.

- Writing support for a console emulator.

- Fixing and completing the linux loader.

- Serial console support.

- SFS support.

- Chainloader / Mac OS loader / MorphOS loader

- Setting the prefix correctly.

- Support for fetching the time.

- Study possible framebuffer features.

- Making sure memory management works ok. Should we release memory, close the console, etc?

So there is still enough to do. And this list is far from complete but it is just to give you all a basic idea of what needs to be done, IMHO.

Thanks,
Marco

2004-12-22 Marco Gerards <[email protected]>

* genmk.rb: Handle the `Program' class in the main loop. Written by Johan Rydberg <[email protected]>.
(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.
* kern/powerpc/cache.S: Likewise. Written by Hollis Blanchard <[email protected]>.
* kern/dl.c (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.

Index: genmk.rb
===================================================================
RCS file: /cvsroot/grub/grub2/genmk.rb,v
retrieving revision 1.8

genmk.rb +53 -0
diff -u -p -r1.8 genmk.rb
@@ -205,9 +205,55 @@ MOSTLYCLEANFILES += #{deps_str}
   end
 end
 
+class Program
+  def initialize(dir, name)
+    @dir = dir
+    @name = name
+  end
+  attr_reader :dir, :name
+
+  def rule(sources)
+    prefix = @name.to_var
+    objs = sources.collect do |src|
+      raise "unknown source file `#{src}'" if /\.[cS]$/ !~ src
+      prefix + '-' + src.to_obj
+    end
+    objs_str = objs.join(' ');
+    deps = objs.collect {|obj| obj.suffix('d')}
+    deps_str = deps.join(' ');
+
+    "CLEANFILES += #{@name} #{objs_str}
+MOSTLYCLEANFILES += #{deps_str}
+
+#{@name}: #{objs_str}
+	$(BUILD_CC) -o $@ $^ $(BUILD_LDFLAGS) $(#{prefix}_LDFLAGS)
+
+" + objs.collect_with_index do |obj, i|
+      src = sources[i]
+      fake_obj = File.basename(src).suffix('o')
+      dep = deps[i]
+      dir = File.dirname(src)
+
+      "#{obj}: #{src}
+	$(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -c -o $@ $<
+
+#{dep}: #{src}
+	set -e; \
+	  $(CC) -I#{dir} -I$(srcdir)/#{dir} $(CPPFLAGS) $(CFLAGS) -DGRUB_UTIL=1 $(#{prefix}_CFLAGS) -M $< \
+	  | sed 's,#{Regexp.quote(fake_obj)}[ :]*,#{obj} $@ : ,g' > $@; \
+	  [ -s $@ ] || rm -f $@
+
+-include #{dep}
+
+"
+    end.join('')
+  end
+end
+
 images = []
 utils = []
 pmodules = []
+programs = []
 
 cont = false
 s = nil
@@ -245,6 +291,11 @@ while l = gets
 	    Utility.new(prefix, util)
 	  end
 
+	when 'PROGRAMS'
+	  programs += args.split(/\s+/).collect do |util|
+	    Program.new(prefix, util)
+	  end
+
 	when 'SOURCES'
 	  if img = images.detect() {|i| i.name.to_var == prefix}
 	    print img.rule(args.split(/\s+/))
@@ -252,6 +303,8 @@ while l = gets
 	    print pmod.rule(args.split(/\s+/))
 	  elsif util = utils.detect() {|u| u.name.to_var == prefix}
 	    print util.rule(args.split(/\s+/))
+	  elsif program = programs.detect() {|u| u.name.to_var == prefix}
+	    print program.rule(args.split(/\s+/))
 	  end
 	end
       end

Index: boot/powerpc/ieee1275/cmain.c
===================================================================
RCS file: /cvsroot/grub/grub2/boot/powerpc/ieee1275/cmain.c,v retrieving revision 1.4

powerpc/ieee1275/cmain.c +3 -11
diff -u -p -r1.4 cmain.c
@@ -21,8 +21,9 @@
 #include <alloca.h>
 #include <stdint.h>
 
-#include "grub/machine/ieee1275.h"
-#include "grub/kernel.h"
+#include <grub/machine/ieee1275.h>
+#include <grub/kernel.h>
+#include <grub/machine/init.h>
 
 struct module_info
 {
@@ -38,15 +39,6 @@ intptr_t (*grub_ieee1275_entry_fn) (void
 grub_uint32_t grub_ieee1275_flags;
 
 
-/* Return a help text for this architecture.  */
-const char *
-help_arch (void)
-{
-  /* No special information.  */
-  return "";
-}
-
-
 /* Setup the argument vector and pass control over to the main
    function.  */
 void

Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v retrieving revision 1.16

powerpc-ieee1275.rmk +100 -12

141 lines not on this page · raw message

Index: disk/powerpc/ieee1275/ofdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/disk/powerpc/ieee1275/ofdisk.c,v retrieving revision 1.5

powerpc/ieee1275/ofdisk.c +3 -0
diff -u -p -r1.5 ofdisk.c
@@ -22,10 +22,13 @@
 #include <grub/disk.h>
 #include <grub/mm.h>
 #include <grub/machine/ieee1275.h>
+#include <grub/machine/init.h>
 
 static int
 grub_ofdisk_iterate (int (*hook) (const char *name))
 {
+  auto int dev_iterate (struct grub_ieee1275_devalias *alias);
+  
   int dev_iterate (struct grub_ieee1275_devalias *alias)
     {
       if (! grub_strcmp (alias->type, "block"))

Index: include/grub/dl.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/dl.h,v
retrieving revision 1.6

grub/dl.h +1 -0
diff -u -p -r1.6 dl.h
@@ -85,6 +85,7 @@ grub_err_t EXPORT_FUNC(grub_dl_register_
 void *EXPORT_FUNC(grub_dl_resolve_symbol) (const char *name);
 
 int grub_arch_dl_check_header (void *ehdr, grub_size_t size);
+void grub_arch_dl_sync_caches (void *address, grub_size_t len);
 grub_err_t grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr);
 
 #endif /* ! GRUB_DL_H */

Index: include/grub/loader.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/loader.h,v retrieving revision 1.6

grub/loader.h +0 -3
diff -u -p -r1.6 loader.h
@@ -26,9 +26,6 @@
 #include <grub/err.h>
 #include <grub/types.h>
 
-extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
-extern grub_size_t EXPORT_VAR(grub_os_area_size);
-
 int EXPORT_FUNC(grub_loader_is_loaded) (void);
 void EXPORT_FUNC(grub_loader_set) (grub_err_t (*boot) (void),
 				   grub_err_t (*unload) (void));

Index: include/grub/i386/pc/init.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/i386/pc/init.h,v retrieving revision 1.4

grub/i386/pc/init.h +3 -0
diff -u -p -r1.4 init.h
@@ -27,6 +27,9 @@
 extern grub_size_t EXPORT_VAR(grub_lower_mem);
 extern grub_size_t EXPORT_VAR(grub_upper_mem);
 
+extern grub_addr_t EXPORT_VAR(grub_os_area_addr);
+extern grub_size_t EXPORT_VAR(grub_os_area_size);
+
 /* Get the memory size in KB. If EXTENDED is zero, return conventional
    memory, otherwise return extended memory.  */
 grub_uint16_t grub_get_memsize (int extended);

Index: include/grub/powerpc/libgcc.h
===================================================================
RCS file: include/grub/powerpc/libgcc.h

grub/powerpc/libgcc.h new file +42 -0

42 lines not on this page · raw message

Index: include/grub/powerpc/types.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/types.h,v retrieving revision 1.2

grub/powerpc/types.h +3 -2
diff -u -p -r1.2 types.h
@@ -26,7 +26,8 @@
 /* The size of long.  */
 #define GRUB_HOST_SIZEOF_LONG	4
 
-/* powerpc is little-endian.  */
-#undef GRUB_HOST_WORDS_LITTLEENDIAN
+/* powerpc is big-endian.  */
+#define GRUB_HOST_WORDS_BIGENDIAN	1
+
 
 #endif /* ! GRUB_TYPES_CPU_HEADER */

Index: include/grub/powerpc/ieee1275/ieee1275.h
===================================================================
RCS file: /cvsroot/grub/grub2/include/grub/powerpc/ieee1275/ieee1275.h,v retrieving revision 1.9

grub/powerpc/ieee1275/ieee1275.h +1 -1
diff -u -p -r1.9 ieee1275.h
@@ -39,7 +39,7 @@ struct grub_ieee1275_mem_region 
   unsigned int size;
 };
 
-extern intptr_t (*grub_ieee1275_entry_fn) (void *);
+extern intptr_t(* EXPORT_VAR(grub_ieee1275_entry_fn)) (void *);
 
 #ifndef IEEE1275_CALL_ENTRY_FN
 #define IEEE1275_CALL_ENTRY_FN(args) (*grub_ieee1275_entry_fn) (args)

Index: include/grub/powerpc/ieee1275/init.h
===================================================================
RCS file: include/grub/powerpc/ieee1275/init.h

grub/powerpc/ieee1275/init.h new file +28 -0
diff -N include/grub/powerpc/ieee1275/init.h
@@ -0,0 +1,28 @@
+/* ieee1275.h - Access the Open Firmware client interface.  */
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2004  Free Software Foundation, Inc.
+ *
+ *  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.
+ */
+
+#ifndef GRUB_INIT_MACHINE_HEADER
+#define GRUB_INIT_MACHINE_HEADER	1
+
+void cmain (uint32_t r3, uint32_t r4 __attribute__((unused)), uint32_t r5);
+void grub_ofdisk_init (void);
+void grub_console_init (void);
+
+#endif /* ! GRUB_INIT_MACHINE_HEADER */

Index: kern/dl.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/dl.c,v
retrieving revision 1.7

dl.c +11 -0
diff -u -p -r1.7 dl.c
@@ -479,6 +479,15 @@ grub_dl_unref (grub_dl_t mod)
   return --mod->ref_count;
 }
 
+static void
+grub_dl_flush_cache (grub_dl_t mod)
+{
+  grub_dl_segment_t seg;
+  
+  for (seg = mod->segment; seg; seg = seg->next)
+    grub_arch_dl_sync_caches (seg->addr, seg->size);
+}
+
 /* Load a module from core memory.  */
 grub_dl_t
 grub_dl_load_core (void *addr, grub_size_t size)
@@ -515,6 +524,8 @@ grub_dl_load_core (void *addr, grub_size
       return 0;
     }
 
+  grub_dl_flush_cache (mod);
+  
   grub_dl_call_init (mod);
   
   if (grub_dl_add (mod))

Index: kern/powerpc/cache.S
===================================================================
RCS file: kern/powerpc/cache.S

powerpc/cache.S new file +45 -0

45 lines not on this page · raw message

Index: kern/powerpc/dl.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/dl.c,v
retrieving revision 1.1

powerpc/dl.c +9 -0
diff -u -p -r1.1 dl.c
@@ -135,6 +135,15 @@ grub_arch_dl_relocate_symbols (grub_dl_t
 		  case R_PPC_ADDR32:
 		    *addr = value;
 		    break;
+		    
+		  case R_PPC_REL32:
+		    *addr = value - (Elf32_Word) addr;
+		    break;
+		    
+		  default:
+		    return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+				       "This relocation (%d) is not implemented yet",
+				       ELF32_R_TYPE (rel->r_info));
 		  }
 	      }
 	  }

Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v retrieving revision 1.10

powerpc/ieee1275/init.c +4 -13
diff -u -p -r1.10 init.c
@@ -29,14 +29,13 @@
 #include <grub/setjmp.h>
 #include <grub/env.h>
 #include <grub/misc.h>
-
-void grub_ofdisk_init (void);
-void grub_console_init (void);
-
+#include <grub/machine/init.h>
+#include <grub/machine/time.h>
 
 /* XXX: Modules are not yet supported.  */
-grub_addr_t grub_end_addr = -1;
+//grub_addr_t grub_end_addr = -1;
 grub_addr_t grub_total_module_size = 0;
+grub_addr_t grub_end_addr = -1;
 
 void
 abort (void)
@@ -73,14 +72,6 @@ grub_machine_init (void)
   /* XXX: Loadable modules are not supported.  */
   grub_env_set ("prefix", "");
 
-  grub_ext2_init ();
-  grub_normal_init ();
-  grub_boot_init ();
-  grub_linux_init ();
-  grub_linux_normal_init ();
-  grub_pc_partition_map_init ();
-  grub_amiga_partition_map_init ();
-  grub_apple_partition_map_init ();
   grub_ofdisk_init ();
 }
 

Index: kern/powerpc/ieee1275/openfw.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/openfw.c,v retrieving revision 1.5

powerpc/ieee1275/openfw.c +1 -1
diff -u -p -r1.5 openfw.c
@@ -144,7 +144,7 @@ grub_devalias_iterate (int (*hook) (stru
 }
 
 /* Call the "map" method of /chosen/mmu.  */
-int
+static int
 grub_map (grub_addr_t phys, grub_addr_t virt, grub_uint32_t size,
 		   grub_uint8_t mode)
 {