This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Add target specific option " -mtinydata " for H8300-ELF target


Hi,

Please find the patch as below for H8/300 (ELF) target, which enhances
the 
existing GCC code to create sections ".tinyrodata",".tinydata" and
".tinybss"  
upon passing a target specific option  "-mtinydata "  on the command
line. 
The .tinyrodata section gets created in the lower most 32KB of the
memory  
from the memory map and the .tinydata  and  .tinybss  get created in the

upper most 32KB of the memory from H8 memory map. All the global
variables are
placed into these sections depending upon whether the variable is
constant,
initialized or uninitialized. 

This patch reduces the code size and it increases the code efficiency.

No new regressions found.

Please note that this patch requires a patch to the "binutils/ld" also, 
which modifies the default linker script generated by the linker.
You may refer to that patch for more details.

=======================Start Of Patch================================
ChangeLog
2005-11-24  Santosh Raktawan <santoshr2@kpitcummins.com>
     	      * config/h8300/h8300.c (h8300_select_section): New
function.
	      * config/h8300/elf.h : Define EXTRA_SECTIONS,
              EXTRA_SECTION_FUNCTIONS,
     	        TINYRODATA_SECTION_FUNCTION, TINYDATA_SECTION_FUNCTION,
              TINYBSS_SECTION_FUNCTION,
            * config/h8300/h8300.opt (TARGET_SWITCHES): Add "tinydata"
to
              create separate sections .tinyrodata , .tinydata and
.tinybss               
              for global variables with different data types.
            * gcc/varasm.c : Placed a one more call to the
"select_section"      
              function for collecting uninitialised variables from the

              variable tree.    
   	      * doc/invoke.texi (H8/300 Options): Document "mtinydata"
              option.
=======================================================================

--- gcc-4.1-20050716/gcc/config/h8300/h8300.c.orig	2005-10-24
12:11:13.000000000 +0530
+++ gcc-4.1-20050716/gcc/config/h8300/h8300.c	2005-11-24
14:01:27.000000000 +0530
@@ -112,6 +112,11 @@ static unsigned int  h8300_bitfield_leng
 static unsigned int  h8300_binary_length          (rtx, const
h8300_length_table *);
 static bool          h8300_short_move_mem_p       (rtx, enum rtx_code);
 static unsigned int  h8300_move_length            (rtx *, const
h8300_length_table *);
+static void h8300_select_section (tree, int, unsigned HOST_WIDE_INT)
+ATTRIBUTE_UNUSED;
+void tiny_rodata_section(void);
+void tiny_data_section(void);
+void tiny_bss_section(void);
 
 /* CPU_TYPE, says what cpu we're compiling for.  */
 int cpu_type;
@@ -337,6 +342,15 @@ h8300_init_once (void)
       error ("-mn is used without -mh or -ms");
       target_flags ^= MASK_NORMAL_MODE;
     }
+  if (TARGET_TINYDATA)
+    {
+      if (TARGET_NORMAL_MODE || TARGET_H8300)
+    	   {
+      	warning (0, " Normal mode does not support Tiny Data - Option
ignored! ");
+    	      target_flags ^= MASK_TINYDATA ;
+        }
+    }
+       
 
   /* Some of the shifts are optimized for speed by default.
      See http://gcc.gnu.org/ml/gcc-patches/2002-07/msg01858.html
@@ -5330,6 +5344,9 @@ h8300_encode_section_info (tree decl, rt
 	extra_flags = SYMBOL_FLAG_EIGHTBIT_DATA;
       else if (first && h8300_tiny_data_p (decl))
 	extra_flags = SYMBOL_FLAG_TINY_DATA;
+      else if (TARGET_TINYDATA && TREE_CODE (decl) == VAR_DECL
+        && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)))
+        extra_flags = SYMBOL_FLAG_TINY_DATA;
     }
 
   if (extra_flags)
@@ -5712,6 +5729,44 @@ h8300_return_in_memory (tree type, tree 
   return (TYPE_MODE (type) == BLKmode
 	  || GET_MODE_SIZE (TYPE_MODE (type)) > (TARGET_H8300 ? 4 : 8));
 }
+
+/*
+This function creates tinyrodata ,tinydata and tinybss sections on
passing "-mtinydata" commandline option. All the global variables will
be placed into these 16 bit addressible tiny area of the H8 memory.  
+*/
+static void
+h8300_select_section (tree decl, int reloc,
+	 unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED)
+{
+ if ( TARGET_TINYDATA )  /*  Check for "tinyData" Command line option*/
+  {
+
+                if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
+                  {
+
+                     if (TREE_READONLY (decl))
+
+                         tiny_rodata_section();  /* Creates tinyrodata
section.*/
+
+                     else if (DECL_INITIAL (decl))
+
+                         tiny_data_section();  /* Creates tinydata
section. */
+
+                     else if (decl && TREE_CODE (decl) == VAR_DECL
+                              && DECL_INITIAL (decl) == NULL_TREE)
+
+                         tiny_bss_section();  /* Creates tinybss
section.*/
+                  }
+   }  
+else
+     {
+	
+	#if __ELF__
+        	default_elf_select_section (decl, reloc, align);
+	#else
+        	default_select_section (decl, reloc, align);
+	#endif
+     }
+ }
 

 /* Initialize the GCC target structure.  */
 #undef TARGET_ATTRIBUTE_TABLE



--- gcc-4.1-20050716/gcc/config/h8300/h8300.opt.orig	2005-10-19
11:43:03.000000000 +0530
+++ gcc-4.1-20050716/gcc/config/h8300/h8300.opt	2005-10-20
13:49:55.000000000 +0530
@@ -61,3 +61,7 @@ Enable the normal mode
 malign-300
 Target RejectNegative Mask(ALIGN_300)
 Use H8/300 alignment rules
+
+mtinydata
+Target RejectNegative Mask(TINYDATA)
+Generate separate sections for variables with different data types

--- gcc-4.1-20050716/gcc/config/h8300/elf.h.orig	2005-10-19
12:16:47.000000000 +0530
+++ gcc-4.1-20050716/gcc/config/h8300/elf.h	2005-10-19
14:02:10.000000000 +0530
@@ -42,4 +42,55 @@ Boston, MA 02110-1301, USA.  */
 #undef LINK_SPEC
 #define LINK_SPEC "%{mh:%{mn:-m h8300hnelf}} %{mh:%{!mn:-m h8300helf}}
%{ms:%{mn:-m h8300snelf}} %{ms:%{!mn:-m h8300self}} %{msx:%{mn:-m
h8300sxnelf;:-m h8300sxelf}}"
 
+#undef  TARGET_ASM_SELECT_SECTION
+#define TARGET_ASM_SELECT_SECTION  h8300_select_section
+
+#define TINY_DATA_SECTION_ASM_OP	"\t.section\t.tinydata,\"aw\""
+#define TINY_BSS_SECTION_ASM_OP
"\t.section\t.tinybss,\"aw\""
+#define TINY_RODATA_SECTION_ASM_OP	"\t.section\t.tinyrodata,\"ax\""
+
+#define EXTRA_SECTIONS in_tinydata, in_tinyrodata,in_tinybss
+
+extern void tiny_rodata_section(void);
+extern void tiny_data_section(void);
+extern void tiny_bss_section(void);
+
+#define EXTRA_SECTION_FUNCTIONS		\
+ 	TINY_RODATA_SECTION_FUNCTION	\
+	TINY_DATA_SECTION_FUNCTION	\
+	TINY_BSS_SECTION_FUNCTION
+
+#define TINY_RODATA_SECTION_FUNCTION   \
+void                                   \
+tiny_rodata_section()                  \
+{                                      \
+  if (in_section != in_tinyrodata)     \
+    {                                  \
+      fprintf (asm_out_file, "%s\n", TINY_RODATA_SECTION_ASM_OP);
\
+      in_section=in_tinyrodata;        \
+    }                                  \
+}
+ 
+#define TINY_DATA_SECTION_FUNCTION     \
+void                                   \
+tiny_data_section()                    \
+{                                      \
+  if (in_section != in_tinydata)       \
+    {                                  \
+      fprintf (asm_out_file, "%s\n", TINY_DATA_SECTION_ASM_OP);
\
+      in_section = in_tinydata;        \
+    }                                  \
+}
+
+#define TINY_BSS_SECTION_FUNCTION      \
+void                                   \
+tiny_bss_section()                     \
+{                                      \
+  if (in_section != in_tinybss)        \
+    {                                  \
+      fprintf (asm_out_file, "%s\n", TINY_BSS_SECTION_ASM_OP);
\
+      in_section = in_tinybss;         \
+    }                                  \
+}
+
 #endif /* h8300/elf.h */

--- gcc-4.1-20050716/gcc/varasm.c.orig	2005-10-19 13:51:56.000000000
+0530
+++ gcc-4.1-20050716/gcc/varasm.c	2005-10-19 14:02:13.000000000
+0530
@@ -1750,7 +1750,10 @@ assemble_variable (tree decl, int top_le
 
       /* If the target cannot output uninitialized but not common
global data
 	 in .bss, then we have to use .data, so fall through.  */
-      if (asm_emit_uninitialised (decl, name, size, rounded))
+      if (decl && TREE_CODE (decl) == VAR_DECL
+               && DECL_INITIAL (decl) == NULL_TREE)
+           targetm.asm_out.select_section (decl, reloc, DECL_ALIGN
(decl));
+      else if (asm_emit_uninitialised (decl, name, size, rounded))
 	return;
     }

--- gcc-4.1-20050716/gcc/doc/invoke.texi.orig	2005-10-24
14:25:29.000000000 +0530
+++ gcc-4.1-20050716/gcc/doc/invoke.texi	2005-10-24
15:32:21.000000000 +0530
@@ -488,7 +488,7 @@ Objective-C and Objective-C++ Dialects}.
 -mcpu=@var{cpu}}
 
 @emph{H8/300 Options}
-@gccoptlist{-mrelax  -mh  -ms  -mn  -mint32  -malign-300}
+@gccoptlist{-mrelax  -mh  -ms  -mn  -mint32  -malign-300 -mtinydata}
 
 @emph{HPPA Options}
 @gccoptlist{-march=@var{architecture-type} @gol
@@ -8533,6 +8533,10 @@ The default for the H8/300H and H8S is t
 byte boundaries.
 @option{-malign-300} causes them to be aligned on 2 byte boundaries.
 This option has no effect on the H8/300.
+
+@item -mtinydata
+@opindex mtinydata
+By passing this option, compiler generates .tinyrodata, .tinydata and 
+.tinybss sections. While using default linker script, .tinyrodata will
+be placed in lower 32KB of memory and .tinydata, .tinybss will be
placed
+in upper 32KB of memory. The variables stored in these sections are 16
bit
+addressable. While using custom linker script, user has to allocate
these 
+sections in lower or upper 32 KB of memory to get 16 bit
addressability.
 @end table
 
 @node HPPA Options

=======================End Of Patch================================

Regards,

Santosh Raktawan.
KPIT Cummins Infosystems Ltd, 
Pune ( INDIA ) 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH and H8 Series.
The following site also offers free technical support to its users. 
Visit http://www.kpitgnutools.com for details. 
Latest versions of KPIT GNU tools were released on October 12, 2005.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]