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