Blob Blame Raw
From 9fb5d59797c2de5670f1c2044a1323fc410eb125 Mon Sep 17 00:00:00 2001
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date: Wed, 24 Apr 2013 13:54:17 +0200
Subject: [PATCH 334/364] 	Move mips-arc link address. Previous link
 address was chosen 	in belief that RAM on SGI platforms grows down while
 in fact it 	grows up from an unusual base.

---
 ChangeLog                      |  6 ++++++
 grub-core/Makefile.core.def    |  6 +++---
 grub-core/kern/mips/arc/init.c | 14 +++++++++-----
 grub-core/kern/mips/startup.S  |  2 --
 include/grub/mips/arc/memory.h |  2 +-
 include/grub/offsets.h         |  2 +-
 util/grub-mkimage.c            | 11 ++++-------
 7 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2150d3d..39bb827 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-04-24  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	Move mips-arc link address. Previous link address was chosen
+	in belief that RAM on SGI platforms grows down while in fact it
+	grows up from an unusual base.
+
 2013-04-21  Vladimir Serbinenko  <phcoder@gmail.com>
 
 	* grub-core/disk/arc/arcdisk.c (grub_arcdisk_iterate_iter):
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 7269609..8f36ea0 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -73,7 +73,7 @@ kernel = {
   mips_loongson_ldflags    = '-Wl,-Ttext,0x80200000';
   powerpc_ieee1275_ldflags = '-Wl,-Ttext,0x200000';
   sparc64_ieee1275_ldflags = '-Wl,-Ttext,0x4400';
-  mips_arc_ldflags    = '-Wl,-Ttext,0x8bd00000';
+  mips_arc_ldflags    = '-Wl,-Ttext,0x88200000';
   mips_qemu_mips_ldflags    = '-Wl,-Ttext,0x80200000';
 
   mips_loongson_cppflags = '-DUSE_ASCII_FAILBACK';
@@ -372,7 +372,7 @@ image = {
   objcopyflags = '-O binary';
   mips_loongson_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
   mips_qemu_mips_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
-  mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x8bc00000';
+  mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x88100000';
   ldadd = '-lgcc';
   cflags = '-Wno-unreachable-code -static-libgcc';
   enable = mips;
@@ -388,7 +388,7 @@ image = {
   objcopyflags = '-O binary';
   mips_loongson_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
   mips_qemu_mips_ldflags = '-static-libgcc -Wl,-Ttext,0x80100000';
-  mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x8bc00000';
+  mips_arc_ldflags = '-static-libgcc -Wl,-Ttext,0x88100000';
   ldadd = '-lgcc';
   cflags = '-static-libgcc';
   enable = mips;
diff --git a/grub-core/kern/mips/arc/init.c b/grub-core/kern/mips/arc/init.c
index f63ac6d..011c63f 100644
--- a/grub-core/kern/mips/arc/init.c
+++ b/grub-core/kern/mips/arc/init.c
@@ -128,12 +128,16 @@ grub_machine_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
 extern grub_uint32_t grub_total_modules_size __attribute__ ((section(".text")));
 grub_addr_t grub_modbase;
 
+extern char _end[];
+
 void
 grub_machine_init (void)
 {
   struct grub_arc_memory_descriptor *cur = NULL;
+  grub_addr_t modend;
 
-  grub_modbase = GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size;
+  grub_modbase = ALIGN_UP ((grub_addr_t) _end, GRUB_KERNEL_MACHINE_MOD_ALIGN);
+  modend = grub_modbase + grub_total_modules_size;
   grub_console_init_early ();
 
   /* FIXME: measure this.  */
@@ -153,10 +157,10 @@ grub_machine_init (void)
       start = ((grub_uint64_t) cur->start_page) << 12;
       end = ((grub_uint64_t) cur->num_pages)  << 12;
       end += start;
-      if ((grub_uint64_t) end > ((GRUB_KERNEL_MIPS_ARC_LINK_ADDR
-				  - grub_total_modules_size) & 0x1fffffff))
-	end = ((GRUB_KERNEL_MIPS_ARC_LINK_ADDR - grub_total_modules_size)
-	       & 0x1fffffff);
+      if ((grub_uint64_t) start < (modend & 0x1fffffff))
+	start = (modend & 0x1fffffff);
+      if ((grub_uint64_t) end > 0x20000000)
+	end = 0x20000000;
       if (end > start)
 	grub_mm_init_region ((void *) (grub_addr_t) (start | 0x80000000),
 			     end - start);
diff --git a/grub-core/kern/mips/startup.S b/grub-core/kern/mips/startup.S
index 2476038..35a11bc 100644
--- a/grub-core/kern/mips/startup.S
+++ b/grub-core/kern/mips/startup.S
@@ -73,7 +73,6 @@ cont:
 #endif
 
 	/* Move the modules out of BSS.  */
-#ifndef GRUB_MACHINE_ARC
 	lui $t2, %hi(__bss_start)
 	addiu $t2, %lo(__bss_start)
 	
@@ -103,7 +102,6 @@ modulesmovcont:
 	b modulesmovcont
 	 addiu $t3, $t3, -1
 modulesmovdone:
-#endif
 
 	/* Clean BSS.  */
 	
diff --git a/include/grub/mips/arc/memory.h b/include/grub/mips/arc/memory.h
index b960d2a..68b425f 100644
--- a/include/grub/mips/arc/memory.h
+++ b/include/grub/mips/arc/memory.h
@@ -19,7 +19,7 @@
 #ifndef GRUB_MEMORY_MACHINE_HEADER
 #define GRUB_MEMORY_MACHINE_HEADER	1
 
-#define GRUB_MACHINE_MEMORY_STACK_HIGH       0x8bfffff0
+#define GRUB_MACHINE_MEMORY_STACK_HIGH       0x881ffff0
 
 #ifndef ASM_FILE
 
diff --git a/include/grub/offsets.h b/include/grub/offsets.h
index bce755d..1e673d5 100644
--- a/include/grub/offsets.h
+++ b/include/grub/offsets.h
@@ -80,7 +80,7 @@
 #define GRUB_DECOMPRESSOR_MIPS_QEMU_MIPS_UNCOMPRESSED_ADDR        0x10
 #define GRUB_KERNEL_MIPS_QEMU_MIPS_TOTAL_MODULE_SIZE	0x08
 
-#define GRUB_KERNEL_MIPS_ARC_LINK_ADDR         0x8bd00000
+#define GRUB_KERNEL_MIPS_ARC_LINK_ADDR         0x88200000
 
 #define GRUB_KERNEL_MIPS_ARC_LINK_ALIGN  32
 
diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c
index 0acc61e..41f795a 100644
--- a/util/grub-mkimage.c
+++ b/util/grub-mkimage.c
@@ -387,8 +387,7 @@ struct image_target_desc image_targets[] =
       .voidp_sizeof = 4,
       .bigendian = 1,
       .id = IMAGE_MIPS_ARC, 
-      .flags = (PLATFORM_FLAGS_DECOMPRESSORS
-		| PLATFORM_FLAGS_MODULES_BEFORE_KERNEL),
+      .flags = PLATFORM_FLAGS_DECOMPRESSORS,
       .total_module_size = GRUB_KERNEL_MIPS_ARC_TOTAL_MODULE_SIZE,
       .decompressor_compressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_COMPRESSED_SIZE,
       .decompressor_uncompressed_size = GRUB_DECOMPRESSOR_MIPS_LOONGSON_UNCOMPRESSED_SIZE,
@@ -1522,12 +1521,10 @@ generate_image (const char *dir, const char *prefix,
 
 	program_size = ALIGN_ADDR (core_size);
 	if (comp == COMPRESSION_NONE)
-	  target_addr = (image_target->link_addr 
-			 - total_module_size - decompress_size);
+	  target_addr = (image_target->link_addr - decompress_size);
 	else
-	  target_addr = (image_target->link_addr 
-			 - ALIGN_UP(total_module_size + core_size, 1048576)
-			 - (1 << 20));
+	  target_addr = ALIGN_UP (image_target->link_addr
+				  + kernel_size + total_module_size, 32);
 
 	ecoff_img = xmalloc (program_size + sizeof (*head) + sizeof (*section));
 	grub_memset (ecoff_img, 0, program_size + sizeof (*head) + sizeof (*section));
-- 
1.8.1.4