OSDN Git Service

* config/freebsd-spec.h (FBSD_CPP_PREDEFINES): Remove.
[pf3gnuchains/gcc-fork.git] / gcc / config / stormy16 / stormy16.c
index 758b977..597c4dd 100644 (file)
@@ -1,5 +1,6 @@
-/* Stormy16 target functions.
-   Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
+/* Xstormy16 target functions.
+   Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
+   Free Software Foundation, Inc.
    Contributed by Red Hat, Inc.
 
 This file is part of GNU CC.
@@ -21,6 +22,8 @@ Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
 #include "system.h"
+#include "coretypes.h"
+#include "tm.h"
 #include "rtl.h"
 #include "regs.h"
 #include "hard-reg-set.h"
@@ -43,18 +46,29 @@ Boston, MA 02111-1307, USA.  */
 #include "target.h"
 #include "target-def.h"
 #include "tm_p.h"
+#include "langhooks.h"
 
 static rtx emit_addhi3_postreload PARAMS ((rtx, rtx, rtx));
+static void xstormy16_asm_out_constructor PARAMS ((rtx, int));
+static void xstormy16_asm_out_destructor PARAMS ((rtx, int));
+static void xstormy16_encode_section_info PARAMS ((tree, int));
+static void xstormy16_asm_output_mi_thunk PARAMS ((FILE *, tree, HOST_WIDE_INT,
+                                                  HOST_WIDE_INT, tree));
+
+static void xstormy16_init_builtins PARAMS ((void));
+static rtx xstormy16_expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
+static bool xstormy16_rtx_costs PARAMS ((rtx, int, int, int *));
+static int xstormy16_address_cost PARAMS ((rtx));
 
 /* Define the information needed to generate branch and scc insns.  This is
    stored from the compare operation.  */
-struct rtx_def * stormy16_compare_op0;
-struct rtx_def * stormy16_compare_op1;
+struct rtx_def * xstormy16_compare_op0;
+struct rtx_def * xstormy16_compare_op1;
 
 /* Return 1 if this is a LT, GE, LTU, or GEU operator.  */
 
 int
-stormy16_ineqsi_operator (op, mode)
+xstormy16_ineqsi_operator (op, mode)
     register rtx op;
     enum machine_mode mode;
 {
@@ -85,6 +99,55 @@ inequality_operator (op, mode)
   return comparison_operator (op, mode) && ! equality_operator (op, mode);
 }
 
+/* Compute a (partial) cost for rtx X.  Return true if the complete
+   cost has been computed, and false if subexpressions should be
+   scanned.  In either case, *TOTAL contains the cost result.  */
+
+static bool
+xstormy16_rtx_costs (x, code, outer_code, total)
+     rtx x;
+     int code, outer_code ATTRIBUTE_UNUSED;
+     int *total;
+{
+  switch (code)
+    {
+    case CONST_INT:
+      if (INTVAL (x) < 16 && INTVAL (x) >= 0)
+        *total = COSTS_N_INSNS (1) / 2;
+      else if (INTVAL (x) < 256 && INTVAL (x) >= 0)
+       *total = COSTS_N_INSNS (1);
+      else
+       *total = COSTS_N_INSNS (2);
+      return true;
+
+    case CONST_DOUBLE:
+    case CONST:
+    case SYMBOL_REF:
+    case LABEL_REF:
+      *total = COSTS_N_INSNS(2);
+      return true;
+
+    case MULT:
+      *total = COSTS_N_INSNS (35 + 6);
+      return true;
+    case DIV:
+      *total = COSTS_N_INSNS (51 - 6);
+      return true;
+
+    default:
+      return false;
+    }
+}
+
+static int
+xstormy16_address_cost (x)
+     rtx x;
+{
+  return (GET_CODE (x) == CONST_INT ? 2
+         : GET_CODE (x) == PLUS ? 7
+         : 5);
+}
+
 /* Branches are handled as follows:
 
    1. HImode compare-and-branches.  The machine supports these
@@ -111,12 +174,12 @@ inequality_operator (op, mode)
 /* Emit a branch of kind CODE to location LOC.  */
 
 void
-stormy16_emit_cbranch (code, loc)
+xstormy16_emit_cbranch (code, loc)
      enum rtx_code code;
      rtx loc;
 {
-  rtx op0 = stormy16_compare_op0;
-  rtx op1 = stormy16_compare_op1;
+  rtx op0 = xstormy16_compare_op0;
+  rtx op1 = xstormy16_compare_op1;
   rtx condition_rtx, loc_ref, branch, cy_clobber;
   rtvec vec;
   enum machine_mode mode;
@@ -130,14 +193,14 @@ stormy16_emit_cbranch (code, loc)
     {
       int unsigned_p = (code == GTU || code == LEU);
       int gt_p = (code == GT || code == GTU);
-      rtx lab;
+      rtx lab = NULL_RTX;
       
       if (gt_p)
        lab = gen_label_rtx ();
-      stormy16_emit_cbranch (unsigned_p ? LTU : LT, gt_p ? lab : loc);
+      xstormy16_emit_cbranch (unsigned_p ? LTU : LT, gt_p ? lab : loc);
       /* This should be generated as a comparison against the temporary
         created by the previous insn, but reload can't handle that.  */
-      stormy16_emit_cbranch (gt_p ? NE : EQ, loc);
+      xstormy16_emit_cbranch (gt_p ? NE : EQ, loc);
       if (gt_p)
        emit_label (lab);
       return;
@@ -146,7 +209,7 @@ stormy16_emit_cbranch (code, loc)
           && (code == NE || code == EQ)
           && op1 != const0_rtx)
     {
-      rtx lab;
+      rtx lab = NULL_RTX;
       int num_words = GET_MODE_BITSIZE (mode) / BITS_PER_WORD;
       int i;
       
@@ -155,17 +218,17 @@ stormy16_emit_cbranch (code, loc)
       
       for (i = 0; i < num_words - 1; i++)
        {
-         stormy16_compare_op0 = simplify_gen_subreg (word_mode, op0, mode, 
+         xstormy16_compare_op0 = simplify_gen_subreg (word_mode, op0, mode, 
                                                      i * UNITS_PER_WORD);
-         stormy16_compare_op1 = simplify_gen_subreg (word_mode, op1, mode, 
+         xstormy16_compare_op1 = simplify_gen_subreg (word_mode, op1, mode, 
                                                      i * UNITS_PER_WORD);
-         stormy16_emit_cbranch (NE, code == EQ ? lab : loc);
+         xstormy16_emit_cbranch (NE, code == EQ ? lab : loc);
        }
-      stormy16_compare_op0 = simplify_gen_subreg (word_mode, op0, mode, 
+      xstormy16_compare_op0 = simplify_gen_subreg (word_mode, op0, mode, 
                                                  i * UNITS_PER_WORD);
-      stormy16_compare_op1 = simplify_gen_subreg (word_mode, op1, mode, 
+      xstormy16_compare_op1 = simplify_gen_subreg (word_mode, op1, mode, 
                                                  i * UNITS_PER_WORD);
-      stormy16_emit_cbranch (code, loc);
+      xstormy16_emit_cbranch (code, loc);
 
       if (code == EQ)
        emit_label (lab);
@@ -210,10 +273,10 @@ stormy16_emit_cbranch (code, loc)
 
 /* Take a SImode conditional branch, one of GT/LE/GTU/LEU, and split
    the arithmetic operation.  Most of the work is done by
-   stormy16_expand_arith.  */
+   xstormy16_expand_arith.  */
 
 void
-stormy16_split_cbranch (mode, label, comparison, dest, carry)
+xstormy16_split_cbranch (mode, label, comparison, dest, carry)
      enum machine_mode mode;
      rtx label;
      rtx comparison;
@@ -222,15 +285,22 @@ stormy16_split_cbranch (mode, label, comparison, dest, carry)
 {
   rtx op0 = XEXP (comparison, 0);
   rtx op1 = XEXP (comparison, 1);
-  rtx seq;
+  rtx seq, last_insn;
   rtx compare;
   
   start_sequence ();
-  stormy16_expand_arith (mode, COMPARE, dest, op0, op1, carry);
-  seq = gen_sequence ();
+  xstormy16_expand_arith (mode, COMPARE, dest, op0, op1, carry);
+  seq = get_insns ();
   end_sequence ();
-  compare = SET_SRC (XVECEXP (PATTERN (XVECEXP (seq, 0, XVECLEN (seq, 0) - 1)),
-                             0, 0));
+
+  if (! INSN_P (seq))
+    abort ();
+
+  last_insn = seq;
+  while (NEXT_INSN (last_insn) != NULL_RTX)
+    last_insn = NEXT_INSN (last_insn);
+
+  compare = SET_SRC (XVECEXP (PATTERN (last_insn), 0, 0));
   PUT_CODE (XEXP (compare, 0), GET_CODE (comparison));
   XEXP (compare, 1) = gen_rtx_LABEL_REF (VOIDmode, label);
   emit_insn (seq);
@@ -242,12 +312,12 @@ stormy16_split_cbranch (mode, label, comparison, dest, carry)
 
    OP is the conditional expression, or NULL for branch-always.
 
-   REVERSED is non-zero if we should reverse the sense of the comparison.
+   REVERSED is nonzero if we should reverse the sense of the comparison.
 
    INSN is the insn.  */
 
 char *
-stormy16_output_cbranch_hi (op, label, reversed, insn)
+xstormy16_output_cbranch_hi (op, label, reversed, insn)
      rtx op;
      const char * label;
      int reversed;
@@ -319,12 +389,12 @@ stormy16_output_cbranch_hi (op, label, reversed, insn)
 
    OP is the conditional expression (OP is never NULL_RTX).
 
-   REVERSED is non-zero if we should reverse the sense of the comparison.
+   REVERSED is nonzero if we should reverse the sense of the comparison.
 
    INSN is the insn.  */
 
 char *
-stormy16_output_cbranch_si (op, label, reversed, insn)
+xstormy16_output_cbranch_si (op, label, reversed, insn)
      rtx op;
      const char * label;
      int reversed;
@@ -395,7 +465,7 @@ stormy16_output_cbranch_si (op, label, reversed, insn)
    registers, but not memory.  Some machines allow copying all registers to and
    from memory, but require a scratch register for stores to some memory
    locations (e.g., those with symbolic address on the RT, and those with
-   certain symbolic address on the Sparc when compiling PIC).  In some cases,
+   certain symbolic address on the SPARC when compiling PIC).  In some cases,
    both an intermediate and a scratch register are required.
 
    You should define these macros to indicate to the reload phase that it may
@@ -438,11 +508,11 @@ stormy16_output_cbranch_si (op, label, reversed, insn)
    registers can only be copied to memory and not to another class of
    registers.  In that case, secondary reload registers are not needed and
    would not be helpful.  Instead, a stack location must be used to perform the
-   copy and the `movM' pattern should use memory as a intermediate storage.
+   copy and the `movM' pattern should use memory as an intermediate storage.
    This case often occurs between floating-point and general registers.  */
 
 enum reg_class
-stormy16_secondary_reload_class (class, mode, x)
+xstormy16_secondary_reload_class (class, mode, x)
      enum reg_class class;
      enum machine_mode mode;
      rtx x;
@@ -458,15 +528,15 @@ stormy16_secondary_reload_class (class, mode, x)
 
   /* When reloading a PLUS, the carry register will be required
      unless the inc or dec instructions can be used.  */
-  if (stormy16_carry_plus_operand (x, mode))
+  if (xstormy16_carry_plus_operand (x, mode))
     return CARRY_REGS;
 
   return NO_REGS;
 }
 
-/* Recognise a PLUS that needs the carry register.  */
+/* Recognize a PLUS that needs the carry register.  */
 int
-stormy16_carry_plus_operand (x, mode)
+xstormy16_carry_plus_operand (x, mode)
      rtx x;
      enum machine_mode mode ATTRIBUTE_UNUSED;
 {
@@ -475,9 +545,32 @@ stormy16_carry_plus_operand (x, mode)
          && (INTVAL (XEXP (x, 1)) < -4 || INTVAL (XEXP (x, 1)) > 4));
 }
 
+/* Detect and error out on out-of-range constants for movhi.  */
+int
+xs_hi_general_operand (x, mode)
+     rtx x;
+     enum machine_mode mode ATTRIBUTE_UNUSED;
+{
+  if ((GET_CODE (x) == CONST_INT) 
+   && ((INTVAL (x) >= 32768) || (INTVAL (x) < -32768)))
+    error ("Constant halfword load operand out of range.");
+  return general_operand (x, mode);
+}
+
+/* Detect and error out on out-of-range constants for addhi and subhi.  */
+int
+xs_hi_nonmemory_operand (x, mode)
+     rtx x;
+     enum machine_mode mode ATTRIBUTE_UNUSED;
+{
+  if ((GET_CODE (x) == CONST_INT) 
+   && ((INTVAL (x) >= 32768) || (INTVAL (x) < -32768)))
+    error ("Constant arithmetic operand out of range.");
+  return nonmemory_operand (x, mode);
+}
 
 enum reg_class
-stormy16_preferred_reload_class (x, class)
+xstormy16_preferred_reload_class (x, class)
      enum reg_class class;
      rtx x;
 {
@@ -499,7 +592,7 @@ stormy16_preferred_reload_class (x, class)
   && (INTVAL (X) + (OFFSET) < 0x100 || INTVAL (X) + (OFFSET) >= 0x7F00))
 
 int
-stormy16_legitimate_address_p (mode, x, strict)
+xstormy16_legitimate_address_p (mode, x, strict)
      enum machine_mode mode ATTRIBUTE_UNUSED;
      rtx x;
      int strict;
@@ -511,7 +604,9 @@ stormy16_legitimate_address_p (mode, x, strict)
       && LEGITIMATE_ADDRESS_INTEGER_P (XEXP (x, 1), 0))
     x = XEXP (x, 0);
   
-  if (GET_CODE (x) == POST_INC
+  if ((GET_CODE (x) == PRE_MODIFY
+       && GET_CODE (XEXP (XEXP (x, 1), 1)) == CONST_INT)
+      || GET_CODE (x) == POST_INC
       || GET_CODE (x) == PRE_DEC)
     x = XEXP (x, 0);
   
@@ -539,7 +634,7 @@ stormy16_legitimate_address_p (mode, x, strict)
    address for DImode or DFmode, or if the address is a post-increment
    or pre-decrement address.  */
 int
-stormy16_mode_dependent_address_p (x)
+xstormy16_mode_dependent_address_p (x)
      rtx x;
 {
   if (LEGITIMATE_ADDRESS_CONST_INT_P (x, 0)
@@ -569,7 +664,7 @@ stormy16_mode_dependent_address_p (x)
    represented by the constraint letter C.  If C is not defined as an extra
    constraint, the value returned should be 0 regardless of VALUE.  */
 int
-stormy16_extra_constraint_p (x, c)
+xstormy16_extra_constraint_p (x, c)
      rtx x;
      int c;
 {
@@ -591,7 +686,7 @@ stormy16_extra_constraint_p (x, c)
     case 'S':
       return (GET_CODE (x) == MEM
              && GET_CODE (XEXP (x, 0)) == CONST_INT
-             && stormy16_legitimate_address_p (VOIDmode, XEXP (x, 0), 0));
+             && xstormy16_legitimate_address_p (VOIDmode, XEXP (x, 0), 0));
 
       /* 'T' is for Rx.  */
     case 'T':
@@ -619,6 +714,17 @@ short_memory_operand (x, mode)
   return (GET_CODE (XEXP (x, 0)) != PLUS);
 }
 
+int
+nonimmediate_nonstack_operand (op, mode)
+     rtx op;
+     enum machine_mode mode;
+{
+  /* 'Q' is for pushes, 'R' for pops.  */
+  return (nonimmediate_operand (op, mode) 
+         && ! xstormy16_extra_constraint_p (op, 'Q')
+         && ! xstormy16_extra_constraint_p (op, 'R'));
+}
+
 /* Splitter for the 'move' patterns, for modes not directly implemeted
    by hardware.  Emit insns to copy a value of mode MODE from SRC to
    DEST.
@@ -627,7 +733,7 @@ short_memory_operand (x, mode)
    */
 
 void 
-stormy16_split_move (mode, dest, src)
+xstormy16_split_move (mode, dest, src)
      enum machine_mode mode;
      rtx dest;
      rtx src;
@@ -639,6 +745,7 @@ stormy16_split_move (mode, dest, src)
   int src_volatile = 0;
   int dest_volatile = 0;
   rtx mem_operand;
+  rtx auto_inc_reg_rtx = NULL_RTX;
   
   /* Check initial conditions.  */
   if (! reload_completed
@@ -671,6 +778,8 @@ stormy16_split_move (mode, dest, src)
     {
       mem_operand = XEXP (dest, 0);
       dest_modifies = side_effects_p (mem_operand);
+      if (auto_inc_p (mem_operand))
+        auto_inc_reg_rtx = XEXP (mem_operand, 0);
       dest_volatile = MEM_VOLATILE_P (dest);
       if (dest_volatile)
        {
@@ -682,6 +791,8 @@ stormy16_split_move (mode, dest, src)
     {
       mem_operand = XEXP (src, 0);
       src_modifies = side_effects_p (mem_operand);
+      if (auto_inc_p (mem_operand))
+        auto_inc_reg_rtx = XEXP (mem_operand, 0);
       src_volatile = MEM_VOLATILE_P (src);
       if (src_volatile)
        {
@@ -731,7 +842,8 @@ stormy16_split_move (mode, dest, src)
   end = direction < 0 ? -1 : num_words;
   for (i = direction < 0 ? num_words - 1 : 0; i != end; i += direction)
     {
-      rtx w_src, w_dest;
+      rtx w_src, w_dest, insn;
+
       if (src_modifies)
        w_src = gen_rtx_MEM (word_mode, mem_operand);
       else
@@ -751,7 +863,11 @@ stormy16_split_move (mode, dest, src)
          || GET_CODE (w_dest) == SUBREG)
        abort ();
       
-      emit_insn (gen_rtx_SET (VOIDmode, w_dest, w_src));
+      insn = emit_insn (gen_rtx_SET (VOIDmode, w_dest, w_src));
+      if (auto_inc_reg_rtx)
+        REG_NOTES (insn) = alloc_EXPR_LIST (REG_INC,
+                                            auto_inc_reg_rtx,
+                                           REG_NOTES (insn));
     }
 }
 
@@ -759,17 +875,40 @@ stormy16_split_move (mode, dest, src)
    mode MODE from SRC to DEST.  */
 
 void 
-stormy16_expand_move (mode, dest, src)
+xstormy16_expand_move (mode, dest, src)
      enum machine_mode mode;
      rtx dest;
      rtx src;
 {
+  if ((GET_CODE (dest) == MEM) && (GET_CODE (XEXP (dest, 0)) == PRE_MODIFY))
+    {
+      rtx pmv      = XEXP (dest, 0);
+      rtx dest_reg = XEXP (pmv, 0);
+      rtx dest_mod = XEXP (pmv, 1);
+      rtx set      = gen_rtx_SET (Pmode, dest_reg, dest_mod);
+      rtx clobber  = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (BImode, 16));
+    
+      dest = gen_rtx_MEM (mode, dest_reg);
+      emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber)));
+    }
+  else if ((GET_CODE (src) == MEM) && (GET_CODE (XEXP (src, 0)) == PRE_MODIFY))
+    {
+      rtx pmv     = XEXP (src, 0);
+      rtx src_reg = XEXP (pmv, 0);
+      rtx src_mod = XEXP (pmv, 1);
+      rtx set     = gen_rtx_SET (Pmode, src_reg, src_mod);
+      rtx clobber = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (BImode, 16));
+    
+      src = gen_rtx_MEM (mode, src_reg);
+      emit_insn (gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, set, clobber)));
+    }
+   
   /* There are only limited immediate-to-memory move instructions.  */
   if (! reload_in_progress
       && ! reload_completed
       && GET_CODE (dest) == MEM
       && (GET_CODE (XEXP (dest, 0)) != CONST_INT
-         || ! stormy16_legitimate_address_p (mode, XEXP (dest, 0), 0))
+         || ! xstormy16_legitimate_address_p (mode, XEXP (dest, 0), 0))
       && GET_CODE (src) != REG
       && GET_CODE (src) != SUBREG)
     src = copy_to_mode_reg (mode, src);
@@ -778,7 +917,7 @@ stormy16_expand_move (mode, dest, src)
   if (reload_completed
       && mode != HImode && mode != QImode)
     {
-      stormy16_split_move (mode, dest, src);
+      xstormy16_split_move (mode, dest, src);
       return;
     }
   
@@ -806,7 +945,7 @@ AP->        Return address (two words)
   instruction.  */
 
 /* A structure to describe the layout.  */
-struct stormy16_stack_layout
+struct xstormy16_stack_layout
 {
   /* Size of the topmost three items on the stack.  */
   int locals_size;
@@ -824,15 +963,16 @@ struct stormy16_stack_layout
 #define REG_NEEDS_SAVE(REGNUM, IFUN)                                   \
   ((regs_ever_live[REGNUM] && ! call_used_regs[REGNUM])                        \
    || (IFUN && ! fixed_regs[REGNUM] && call_used_regs[REGNUM]          \
+       && (REGNO_REG_CLASS (REGNUM) != CARRY_REGS)                     \
        && (regs_ever_live[REGNUM] || ! current_function_is_leaf)))
 
 /* Compute the stack layout.  */
-struct stormy16_stack_layout 
-stormy16_compute_stack_layout ()
+struct xstormy16_stack_layout 
+xstormy16_compute_stack_layout ()
 {
-  struct stormy16_stack_layout layout;
+  struct xstormy16_stack_layout layout;
   int regno;
-  const int ifun = stormy16_interrupt_function_p ();
+  const int ifun = xstormy16_interrupt_function_p ();
 
   layout.locals_size = get_frame_size ();
   
@@ -841,7 +981,7 @@ stormy16_compute_stack_layout ()
     if (REG_NEEDS_SAVE (regno, ifun))
       layout.register_save_size += UNITS_PER_WORD;
   
-  if (current_function_varargs || current_function_stdarg)
+  if (current_function_stdarg)
     layout.stdarg_save_size = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD;
   else
     layout.stdarg_save_size = 0;
@@ -870,13 +1010,13 @@ stormy16_compute_stack_layout ()
 
 /* Determine how all the special registers get eliminated.  */
 int
-stormy16_initial_elimination_offset (from, to)
+xstormy16_initial_elimination_offset (from, to)
      int from, to;
 {
-  struct stormy16_stack_layout layout;
+  struct xstormy16_stack_layout layout;
   int result;
   
-  layout = stormy16_compute_stack_layout ();
+  layout = xstormy16_compute_stack_layout ();
 
   if (from == FRAME_POINTER_REGNUM && to == HARD_FRAME_POINTER_REGNUM)
     result = layout.sp_minus_fp - layout.locals_size;
@@ -906,31 +1046,32 @@ emit_addhi3_postreload (dest, src0, src1)
   return insn;
 }
 
-/* Called after register allocation to add any instructions needed for the
-   prologue.  Using a prologue insn is favored compared to putting all of the
-   instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
-   to intermix instructions with the saves of the caller saved registers.  In
-   some cases, it might be necessary to emit a barrier instruction as the last
-   insn to prevent such scheduling.
+/* Called after register allocation to add any instructions needed for
+   the prologue.  Using a prologue insn is favored compared to putting
+   all of the instructions in the TARGET_ASM_FUNCTION_PROLOGUE macro,
+   since it allows the scheduler to intermix instructions with the
+   saves of the caller saved registers.  In some cases, it might be
+   necessary to emit a barrier instruction as the last insn to prevent
+   such scheduling.
 
    Also any insns generated here should have RTX_FRAME_RELATED_P(insn) = 1
    so that the debug info generation code can handle them properly.  */
 void
-stormy16_expand_prologue ()
+xstormy16_expand_prologue ()
 {
-  struct stormy16_stack_layout layout;
+  struct xstormy16_stack_layout layout;
   int regno;
   rtx insn;
   rtx mem_push_rtx;
-  rtx mem_fake_push_rtx;
-  const int ifun = stormy16_interrupt_function_p ();
+  const int ifun = xstormy16_interrupt_function_p ();
   
   mem_push_rtx = gen_rtx_POST_INC (Pmode, stack_pointer_rtx);
   mem_push_rtx = gen_rtx_MEM (HImode, mem_push_rtx);
-  mem_fake_push_rtx = gen_rtx_PRE_INC (Pmode, stack_pointer_rtx);
-  mem_fake_push_rtx = gen_rtx_MEM (HImode, mem_fake_push_rtx);
     
-  layout = stormy16_compute_stack_layout ();
+  layout = xstormy16_compute_stack_layout ();
+
+  if (layout.locals_size >= 32768)
+    error ("Local variable memory requirements exceed capacity.");
 
   /* Save the argument registers if necessary.  */
   if (layout.stdarg_save_size)
@@ -938,32 +1079,54 @@ stormy16_expand_prologue ()
         regno < FIRST_ARGUMENT_REGISTER + NUM_ARGUMENT_REGISTERS;
         regno++)
       {
+       rtx dwarf;
        rtx reg = gen_rtx_REG (HImode, regno);
+
        insn = emit_move_insn (mem_push_rtx, reg);
        RTX_FRAME_RELATED_P (insn) = 1;
+
+       dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
+       
+       XVECEXP (dwarf, 0, 0) = gen_rtx_SET (VOIDmode,
+                                            gen_rtx_MEM (Pmode, stack_pointer_rtx),
+                                            reg);
+       XVECEXP (dwarf, 0, 1) = gen_rtx_SET (Pmode, stack_pointer_rtx,
+                                            plus_constant (stack_pointer_rtx,
+                                                           GET_MODE_SIZE (Pmode)));
        REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
-                                             gen_rtx_SET (VOIDmode,
-                                                          mem_fake_push_rtx,
-                                                          reg),
+                                             dwarf,
                                              REG_NOTES (insn));
+       RTX_FRAME_RELATED_P (XVECEXP (dwarf, 0, 0)) = 1;
+       RTX_FRAME_RELATED_P (XVECEXP (dwarf, 0, 1)) = 1;
       }
   
   /* Push each of the registers to save.  */
   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
     if (REG_NEEDS_SAVE (regno, ifun))
       {
+       rtx dwarf;
        rtx reg = gen_rtx_REG (HImode, regno);
+
        insn = emit_move_insn (mem_push_rtx, reg);
        RTX_FRAME_RELATED_P (insn) = 1;
+
+       dwarf = gen_rtx_SEQUENCE (VOIDmode, rtvec_alloc (2));
+       
+       XVECEXP (dwarf, 0, 0) = gen_rtx_SET (VOIDmode,
+                                            gen_rtx_MEM (Pmode, stack_pointer_rtx),
+                                            reg);
+       XVECEXP (dwarf, 0, 1) = gen_rtx_SET (Pmode, stack_pointer_rtx,
+                                            plus_constant (stack_pointer_rtx,
+                                                           GET_MODE_SIZE (Pmode)));
        REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_FRAME_RELATED_EXPR,
-                                             gen_rtx_SET (VOIDmode,
-                                                          mem_fake_push_rtx,
-                                                          reg),
+                                             dwarf,
                                              REG_NOTES (insn));
+       RTX_FRAME_RELATED_P (XVECEXP (dwarf, 0, 0)) = 1;
+       RTX_FRAME_RELATED_P (XVECEXP (dwarf, 0, 1)) = 1;
       }
 
   /* It's just possible that the SP here might be what we need for
-     the new FP... */
+     the new FP...  */
   if (frame_pointer_needed && layout.sp_minus_fp == layout.locals_size)
     {
       insn = emit_move_insn (hard_frame_pointer_rtx, stack_pointer_rtx);
@@ -998,28 +1161,29 @@ int
 direct_return ()
 {
   return (reload_completed 
-         && stormy16_compute_stack_layout ().frame_size == 0);
+         && xstormy16_compute_stack_layout ().frame_size == 0);
 }
 
-/* Called after register allocation to add any instructions needed for the
-   epilogue.  Using a epilogue insn is favored compared to putting all of the
-   instructions in the FUNCTION_PROLOGUE macro, since it allows the scheduler
-   to intermix instructions with the saves of the caller saved registers.  In
-   some cases, it might be necessary to emit a barrier instruction as the last
-   insn to prevent such scheduling.  */
+/* Called after register allocation to add any instructions needed for
+   the epilogue.  Using an epilogue insn is favored compared to putting
+   all of the instructions in the TARGET_ASM_FUNCTION_PROLOGUE macro,
+   since it allows the scheduler to intermix instructions with the
+   saves of the caller saved registers.  In some cases, it might be
+   necessary to emit a barrier instruction as the last insn to prevent
+   such scheduling.  */
 
 void
-stormy16_expand_epilogue ()
+xstormy16_expand_epilogue ()
 {
-  struct stormy16_stack_layout layout;
+  struct xstormy16_stack_layout layout;
   rtx mem_pop_rtx;
   int regno;
-  const int ifun = stormy16_interrupt_function_p ();
+  const int ifun = xstormy16_interrupt_function_p ();
   
   mem_pop_rtx = gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx);
   mem_pop_rtx = gen_rtx_MEM (HImode, mem_pop_rtx);
   
-  layout = stormy16_compute_stack_layout ();
+  layout = xstormy16_compute_stack_layout ();
 
   /* Pop the stack for the locals.  */
   if (layout.locals_size)
@@ -1049,12 +1213,12 @@ stormy16_expand_epilogue ()
 }
 
 int
-stormy16_epilogue_uses (regno)
+xstormy16_epilogue_uses (regno)
      int regno;
 {
   if (reload_completed && call_used_regs[regno])
     {
-      const int ifun = stormy16_interrupt_function_p ();
+      const int ifun = xstormy16_interrupt_function_p ();
       return REG_NEEDS_SAVE (regno, ifun);
     }
   return 0;
@@ -1069,10 +1233,10 @@ stormy16_epilogue_uses (regno)
    This function need not do anything if the argument in question was
    passed on the stack.  The compiler knows how to track the amount of
    stack space used for arguments without any special help.  However,
-   it makes life easier for stormy16_build_va_list if it does update
+   it makes life easier for xstormy16_build_va_list if it does update
    the word count.  */
 CUMULATIVE_ARGS
-stormy16_function_arg_advance (cum, mode, type, named)
+xstormy16_function_arg_advance (cum, mode, type, named)
      CUMULATIVE_ARGS cum;
      enum machine_mode mode;
      tree type;
@@ -1082,10 +1246,10 @@ stormy16_function_arg_advance (cum, mode, type, named)
      and partially on the stack, the whole of it is passed on the
      stack.  */
   if (cum < NUM_ARGUMENT_REGISTERS
-      && cum + STORMY16_WORD_SIZE (type, mode) > NUM_ARGUMENT_REGISTERS)
+      && cum + XSTORMY16_WORD_SIZE (type, mode) > NUM_ARGUMENT_REGISTERS)
     cum = NUM_ARGUMENT_REGISTERS;
   
-  cum += STORMY16_WORD_SIZE (type, mode);
+  cum += XSTORMY16_WORD_SIZE (type, mode);
   
   return cum;
 }
@@ -1093,7 +1257,7 @@ stormy16_function_arg_advance (cum, mode, type, named)
 /* Do any needed setup for a variadic function.  CUM has not been updated
    for the last named argument which has type TYPE and mode MODE.  */
 void
-stormy16_setup_incoming_varargs (cum, int_mode, type, pretend_size)
+xstormy16_setup_incoming_varargs (cum, int_mode, type, pretend_size)
      CUMULATIVE_ARGS cum ATTRIBUTE_UNUSED;
      int             int_mode ATTRIBUTE_UNUSED;
      tree            type ATTRIBUTE_UNUSED;
@@ -1110,16 +1274,16 @@ stormy16_setup_incoming_varargs (cum, int_mode, type, pretend_size)
    To keep the layout nice, the pointer is first in the structure.  */
 
 tree
-stormy16_build_va_list ()
+xstormy16_build_va_list ()
 {
   tree f_1, f_2, record, type_decl;
 
-  record = make_lang_type (RECORD_TYPE);
+  record = (*lang_hooks.types.make_type) (RECORD_TYPE);
   type_decl = build_decl (TYPE_DECL, get_identifier ("__va_list_tag"), record);
 
-  f_2 = build_decl (FIELD_DECL, get_identifier ("base"),
+  f_1 = build_decl (FIELD_DECL, get_identifier ("base"),
                      ptr_type_node);
-  f_1 = build_decl (FIELD_DECL, get_identifier ("count"), 
+  f_2 = build_decl (FIELD_DECL, get_identifier ("count"), 
                      unsigned_type_node);
 
   DECL_FIELD_CONTEXT (f_1) = record;
@@ -1135,13 +1299,12 @@ stormy16_build_va_list ()
   return record;
 }
 
-/* Implement the stdarg/varargs va_start macro.  STDARG_P is non-zero if this
+/* Implement the stdarg/varargs va_start macro.  STDARG_P is nonzero if this
    is stdarg.h instead of varargs.h.  VALIST is the tree of the va_list
    variable to initialize.  NEXTARG is the machine independent notion of the
    'next' argument after the variable arguments.  */
 void
-stormy16_expand_builtin_va_start (stdarg_p, valist, nextarg)
-     int stdarg_p ATTRIBUTE_UNUSED;
+xstormy16_expand_builtin_va_start (valist, nextarg)
      tree valist;
      rtx nextarg ATTRIBUTE_UNUSED;
 {
@@ -1149,7 +1312,7 @@ stormy16_expand_builtin_va_start (stdarg_p, valist, nextarg)
   tree base, count;
   tree t;
 
-  if (stormy16_interrupt_function_p ())
+  if (xstormy16_interrupt_function_p ())
     error ("cannot use va_start in interrupt function");
   
   f_base = TYPE_FIELDS (va_list_type_node);
@@ -1172,9 +1335,11 @@ stormy16_expand_builtin_va_start (stdarg_p, valist, nextarg)
 }
 
 /* Implement the stdarg/varargs va_arg macro.  VALIST is the variable
-   of type va_list as a tree, TYPE is the type passed to va_arg.  */
+   of type va_list as a tree, TYPE is the type passed to va_arg.
+   Note:  This algorithm is documented in stormy-abi.  */
+   
 rtx
-stormy16_expand_builtin_va_arg (valist, type)
+xstormy16_expand_builtin_va_arg (valist, type)
      tree valist;
      tree type;
 {
@@ -1183,8 +1348,9 @@ stormy16_expand_builtin_va_arg (valist, type)
   rtx count_rtx, addr_rtx, r;
   rtx lab_gotaddr, lab_fromstack;
   tree t;
-  int size, last_reg_count;
+  int size, size_of_reg_args;
   tree size_tree, count_plus_size;
+  rtx count_plus_size_rtx;
   
   f_base = TYPE_FIELDS (va_list_type_node);
   f_count = TREE_CHAIN (f_base);
@@ -1195,14 +1361,17 @@ stormy16_expand_builtin_va_arg (valist, type)
   size = PUSH_ROUNDING (int_size_in_bytes (type));
   size_tree = round_up (size_in_bytes (type), UNITS_PER_WORD);
   
-  last_reg_count = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD - size;
+  size_of_reg_args = NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD;
 
   count_rtx = expand_expr (count, NULL_RTX, HImode, EXPAND_NORMAL);
   lab_gotaddr = gen_label_rtx ();
   lab_fromstack = gen_label_rtx ();
   addr_rtx = gen_reg_rtx (Pmode);
-  emit_cmp_and_jump_insns (count_rtx, GEN_INT (last_reg_count),
-                         GTU, const1_rtx, HImode, 1, 1, lab_fromstack);
+
+  count_plus_size = build (PLUS_EXPR, TREE_TYPE (count), count, size_tree);
+  count_plus_size_rtx = expand_expr (count_plus_size, NULL_RTX, HImode, EXPAND_NORMAL);
+  emit_cmp_and_jump_insns (count_plus_size_rtx, GEN_INT (size_of_reg_args),
+                          GTU, const1_rtx, HImode, 1, lab_fromstack);
   
   t = build (PLUS_EXPR, ptr_type_node, base, count);
   r = expand_expr (t, addr_rtx, Pmode, EXPAND_NORMAL);
@@ -1221,8 +1390,7 @@ stormy16_expand_builtin_va_arg (valist, type)
       rtx lab_notransition = gen_label_rtx ();
       emit_cmp_and_jump_insns (count_rtx, GEN_INT (NUM_ARGUMENT_REGISTERS 
                                                   * UNITS_PER_WORD),
-                              GEU, const1_rtx, HImode, 1, 1, 
-                              lab_notransition);
+                              GEU, const1_rtx, HImode, 1, lab_notransition);
       
       t = build (MODIFY_EXPR, TREE_TYPE (count), count, 
                 build_int_2 (NUM_ARGUMENT_REGISTERS * UNITS_PER_WORD, 0));
@@ -1257,7 +1425,7 @@ stormy16_expand_builtin_va_arg (valist, type)
    the nested function; STATIC_CHAIN is an RTX for the static chain
    value that should be passed to the function when it is called.  */
 void
-stormy16_initialize_trampoline (addr, fnaddr, static_chain)
+xstormy16_initialize_trampoline (addr, fnaddr, static_chain)
      rtx addr;
      rtx fnaddr;
      rtx static_chain;
@@ -1305,7 +1473,7 @@ stormy16_initialize_trampoline (addr, fnaddr, static_chain)
    because these are returned in another way.  See `STRUCT_VALUE_REGNUM' and
    related macros.  */
 rtx
-stormy16_function_value (valtype, func)
+xstormy16_function_value (valtype, func)
      tree valtype;
      tree func ATTRIBUTE_UNUSED;
 {
@@ -1315,19 +1483,122 @@ stormy16_function_value (valtype, func)
   return gen_rtx_REG (mode, RETURN_VALUE_REGNUM);
 }
 
+/* A C compound statement that outputs the assembler code for a thunk function,
+   used to implement C++ virtual function calls with multiple inheritance.  The
+   thunk acts as a wrapper around a virtual function, adjusting the implicit
+   object parameter before handing control off to the real function.
+
+   First, emit code to add the integer DELTA to the location that contains the
+   incoming first argument.  Assume that this argument contains a pointer, and
+   is the one used to pass the `this' pointer in C++.  This is the incoming
+   argument *before* the function prologue, e.g. `%o0' on a sparc.  The
+   addition must preserve the values of all other incoming arguments.
+
+   After the addition, emit code to jump to FUNCTION, which is a
+   `FUNCTION_DECL'.  This is a direct pure jump, not a call, and does not touch
+   the return address.  Hence returning from FUNCTION will return to whoever
+   called the current `thunk'.
+
+   The effect must be as if @var{function} had been called directly
+   with the adjusted first argument.  This macro is responsible for
+   emitting all of the code for a thunk function;
+   TARGET_ASM_FUNCTION_PROLOGUE and TARGET_ASM_FUNCTION_EPILOGUE are
+   not invoked.
+
+   The THUNK_FNDECL is redundant.  (DELTA and FUNCTION have already been
+   extracted from it.)  It might possibly be useful on some targets, but
+   probably not.  */
+
+static void
+xstormy16_asm_output_mi_thunk (file, thunk_fndecl, delta,
+                              vcall_offset, function)
+     FILE *file;
+     tree thunk_fndecl ATTRIBUTE_UNUSED;
+     HOST_WIDE_INT delta;
+     HOST_WIDE_INT vcall_offset ATTRIBUTE_UNUSED;
+     tree function;
+{
+  int regnum = FIRST_ARGUMENT_REGISTER;
+  
+  /* There might be a hidden first argument for a returned structure.  */
+  if (aggregate_value_p (TREE_TYPE (TREE_TYPE (function))))
+    regnum += 1;
+  
+  fprintf (file, "\tadd %s,#0x%x\n", reg_names[regnum], (int) delta & 0xFFFF);
+  fputs ("\tjmpf ", file);
+  assemble_name (file, XSTR (XEXP (DECL_RTL (function), 0), 0));
+  putc ('\n', file);
+}
+
 /* Mark functions with SYMBOL_REF_FLAG.  */
 
-void
-stormy16_encode_section_info (decl)
+static void
+xstormy16_encode_section_info (decl, first)
      tree decl;
+     int first ATTRIBUTE_UNUSED;
 {
   if (TREE_CODE (decl) == FUNCTION_DECL)
     SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0)) = 1;
 }
+
+/* Output constructors and destructors.  Just like 
+   default_named_section_asm_out_* but don't set the sections writable.  */
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR xstormy16_asm_out_constructor
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR xstormy16_asm_out_destructor
+
+static void
+xstormy16_asm_out_destructor (symbol, priority)
+     rtx symbol;
+     int priority;
+{
+  const char *section = ".dtors";
+  char buf[16];
+
+  /* ??? This only works reliably with the GNU linker.   */
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      sprintf (buf, ".dtors.%.5u",
+              /* Invert the numbering so the linker puts us in the proper
+                 order; constructors are run from right to left, and the
+                 linker sorts in increasing order.  */
+              MAX_INIT_PRIORITY - priority);
+      section = buf;
+    }
+
+  named_section_flags (section, 0);
+  assemble_align (POINTER_SIZE);
+  assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+}
+
+static void
+xstormy16_asm_out_constructor (symbol, priority)
+     rtx symbol;
+     int priority;
+{
+  const char *section = ".ctors";
+  char buf[16];
+
+  /* ??? This only works reliably with the GNU linker.   */
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      sprintf (buf, ".ctors.%.5u",
+              /* Invert the numbering so the linker puts us in the proper
+                 order; constructors are run from right to left, and the
+                 linker sorts in increasing order.  */
+              MAX_INIT_PRIORITY - priority);
+      section = buf;
+    }
+
+  named_section_flags (section, 0);
+  assemble_align (POINTER_SIZE);
+  assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, POINTER_SIZE, 1);
+}
 \f
 /* Print a memory address as an operand to reference that memory location.  */
 void
-stormy16_print_operand_address (file, address)
+xstormy16_print_operand_address (file, address)
      FILE * file;
      rtx    address;
 {
@@ -1383,9 +1654,9 @@ stormy16_print_operand_address (file, address)
   fputc (')', file);
 }
 
-/* Print an operand to a assembler instruction.  */
+/* Print an operand to an assembler instruction.  */
 void
-stormy16_print_operand (file, x, code)
+xstormy16_print_operand (file, x, code)
      FILE * file;
      rtx    x;
      int    code;
@@ -1396,7 +1667,8 @@ stormy16_print_operand (file, x, code)
        /* There is either one bit set, or one bit clear, in X.
           Print it preceded by '#'.  */
       {
-       HOST_WIDE_INT xx, l;
+       HOST_WIDE_INT xx = 1;
+       HOST_WIDE_INT l;
 
        if (GET_CODE (x) == CONST_INT)
          xx = INTVAL (x);
@@ -1418,8 +1690,10 @@ stormy16_print_operand (file, x, code)
       /* Print the symbol without a surrounding @fptr().  */
       if (GET_CODE (x) == SYMBOL_REF)
        assemble_name (file, XSTR (x, 0));
+      else if (GET_CODE (x) == LABEL_REF)
+       output_asm_label (x);
       else
-       stormy16_print_operand_address (file, x);
+       xstormy16_print_operand_address (file, x);
       return;
 
     case 'o':
@@ -1427,7 +1701,7 @@ stormy16_print_operand (file, x, code)
       /* Print the immediate operand less one, preceded by '#'.  
          For 'O', negate it first.  */
       {
-       HOST_WIDE_INT xx;
+       HOST_WIDE_INT xx = 0;
        
        if (GET_CODE (x) == CONST_INT)
          xx = INTVAL (x);
@@ -1447,7 +1721,7 @@ stormy16_print_operand (file, x, code)
       break;
       
     default:
-      output_operand_lossage ("stormy16_print_operand: unknown code");
+      output_operand_lossage ("xstormy16_print_operand: unknown code");
       return;
     }
 
@@ -1458,7 +1732,7 @@ stormy16_print_operand (file, x, code)
       break;
 
     case MEM:
-      stormy16_print_operand_address (file, XEXP (x, 0));
+      xstormy16_print_operand_address (file, XEXP (x, 0));
       break;
 
     default:
@@ -1484,7 +1758,7 @@ stormy16_print_operand (file, x, code)
 */
 
 void 
-stormy16_expand_casesi (index, lower_bound, range, table, default_label)
+xstormy16_expand_casesi (index, lower_bound, range, table, default_label)
      rtx index;
      rtx lower_bound;
      rtx range;
@@ -1500,10 +1774,10 @@ stormy16_expand_casesi (index, lower_bound, range, table, default_label)
     sorry ("switch statement of size %lu entries too large", 
           (unsigned long) range_i);
 
-  index = expand_binop (SImode, sub_optab, index, lower_bound, index, 0,
+  index = expand_binop (SImode, sub_optab, index, lower_bound, NULL_RTX, 0,
                        OPTAB_LIB_WIDEN);
   emit_cmp_and_jump_insns (index, range, GTU, NULL_RTX, SImode, 1,
-                          0, default_label);
+                          default_label);
   int_index = gen_lowpart_common (HImode, index);
   emit_insn (gen_ashlhi3 (int_index, int_index, GEN_INT (2)));
   emit_jump_insn (gen_tablejump_pcrel (int_index, table));
@@ -1518,7 +1792,7 @@ stormy16_expand_casesi (index, lower_bound, range, table, default_label)
    all reach.  */
 
 void
-stormy16_output_addr_vec (file, label, table)
+xstormy16_output_addr_vec (file, label, table)
      FILE *file;
      rtx label ATTRIBUTE_UNUSED;
      rtx table;
@@ -1531,8 +1805,7 @@ stormy16_output_addr_vec (file, label, table)
   for (idx = 0; idx < vlen; idx++)
     {
       fputs ("\tjmpf ", file);
-      stormy16_print_operand_address (file, 
-                                     XEXP (XVECEXP (table, 0, idx), 0));
+      output_asm_label (XEXP (XVECEXP (table, 0, idx), 0));
       fputc ('\n', file);
     }
 }
@@ -1549,7 +1822,7 @@ stormy16_output_addr_vec (file, label, table)
 */
 
 void 
-stormy16_expand_call (retval, dest, counter)
+xstormy16_expand_call (retval, dest, counter)
      rtx retval;
      rtx dest;
      rtx counter;
@@ -1596,10 +1869,10 @@ stormy16_expand_call (retval, dest, counter)
    
    using CARRY as a temporary.  When CODE is COMPARE, a branch
    template is generated (this saves duplicating code in
-   stormy16_split_cbranch).  */
+   xstormy16_split_cbranch).  */
 
 void 
-stormy16_expand_arith (mode, code, dest, src0, src1, carry)
+xstormy16_expand_arith (mode, code, dest, src0, src1, carry)
      enum machine_mode mode;
      enum rtx_code code;
      rtx dest;
@@ -1721,7 +1994,7 @@ shift_operator (op, mode)
    SIZE_R will be a CONST_INT, X will be a hard register.  */
 
 const char * 
-stormy16_output_shift (mode, code, x, size_r, temp)
+xstormy16_output_shift (mode, code, x, size_r, temp)
      enum machine_mode mode;
      enum rtx_code code;
      rtx x;
@@ -1743,7 +2016,6 @@ stormy16_output_shift (mode, code, x, size_r, temp)
 
   r0 = reg_names [REGNO (x)];
   r1 = reg_names [REGNO (x) + 1];
-  rt = reg_names [REGNO (temp)];
 
   /* For shifts of size 1, we can use the rotate instructions.  */
   if (size == 1)
@@ -1808,6 +2080,7 @@ stormy16_output_shift (mode, code, x, size_r, temp)
 
   /* For the rest, we have to do more work.  In particular, we
      need a temporary.  */
+  rt = reg_names [REGNO (temp)];
   switch (code)
     {
     case ASHIFT:
@@ -1838,7 +2111,7 @@ stormy16_output_shift (mode, code, x, size_r, temp)
 
 /* Return nonzero if the function is an interrupt function.  */
 int
-stormy16_interrupt_function_p ()
+xstormy16_interrupt_function_p ()
 {
   tree attributes;
   
@@ -1852,30 +2125,171 @@ stormy16_interrupt_function_p ()
   return lookup_attribute ("interrupt", attributes) != NULL_TREE;
 }
 
-/* If defined, a C function which returns nonzero if IDENTIFIER
-   with arguments ARGS is a valid machine specific attribute for TYPE.
-   The attributes in ATTRIBUTES have previously been assigned to TYPE.  */
-#undef TARGET_VALID_TYPE_ATTRIBUTE
-#define TARGET_VALID_TYPE_ATTRIBUTE stormy16_valid_type_attribute
-static int stormy16_valid_type_attribute PARAMS ((tree TYPE,
-                                                 tree ATTRIBUTES,
-                                                 tree IDENTIFIER,
-                                                 tree ARGS));
+#undef TARGET_ATTRIBUTE_TABLE
+#define TARGET_ATTRIBUTE_TABLE xstormy16_attribute_table
+static tree xstormy16_handle_interrupt_attribute PARAMS ((tree *, tree, tree, int, bool *));
+static const struct attribute_spec xstormy16_attribute_table[] =
+{
+  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */
+  { "interrupt", 0, 0, false, true,  true,  xstormy16_handle_interrupt_attribute },
+  { NULL,        0, 0, false, false, false, NULL }
+};
 
-static int
-stormy16_valid_type_attribute (type, attributes, identifier, args)
-     tree type;
-     tree attributes ATTRIBUTE_UNUSED;
-     tree identifier;
+/* Handle an "interrupt" attribute;
+   arguments as in struct attribute_spec.handler.  */
+static tree
+xstormy16_handle_interrupt_attribute (node, name, args, flags, no_add_attrs)
+     tree *node;
+     tree name;
      tree args ATTRIBUTE_UNUSED;
+     int flags ATTRIBUTE_UNUSED;
+     bool *no_add_attrs;
 {
-  if (TREE_CODE (type) != FUNCTION_TYPE)
-    return 0;
-  
-  if (is_attribute_p ("interrupt", identifier))
-    return 1;
+  if (TREE_CODE (*node) != FUNCTION_TYPE)
+    {
+      warning ("`%s' attribute only applies to functions",
+              IDENTIFIER_POINTER (name));
+      *no_add_attrs = true;
+    }
 
-  return 0;
+  return NULL_TREE;
+}
+\f
+#undef TARGET_INIT_BUILTINS
+#define TARGET_INIT_BUILTINS xstormy16_init_builtins
+#undef TARGET_EXPAND_BUILTIN
+#define TARGET_EXPAND_BUILTIN xstormy16_expand_builtin
+
+static struct {
+  const char *name;
+  int md_code;
+  const char *arg_ops; /* 0..9, t for temp register, r for return value */
+  const char *arg_types; /* s=short,l=long, upper case for unsigned */
+} s16builtins[] = {
+  { "__sdivlh", CODE_FOR_sdivlh, "rt01", "sls" },
+  { "__smodlh", CODE_FOR_sdivlh, "tr01", "sls" },
+  { "__udivlh", CODE_FOR_udivlh, "rt01", "SLS" },
+  { "__umodlh", CODE_FOR_udivlh, "tr01", "SLS" },
+  { 0, 0, 0, 0 }
+};
+
+static void
+xstormy16_init_builtins ()
+{
+  tree args, ret_type, arg;
+  int i, a;
+
+  ret_type = void_type_node;
+
+  for (i=0; s16builtins[i].name; i++)
+    {
+      args = void_list_node;
+      for (a=strlen (s16builtins[i].arg_types)-1; a>=0; a--)
+       {
+         switch (s16builtins[i].arg_types[a])
+           {
+           case 's': arg = short_integer_type_node; break;
+           case 'S': arg = short_unsigned_type_node; break;
+           case 'l': arg = long_integer_type_node; break;
+           case 'L': arg = long_unsigned_type_node; break;
+           default: abort();
+           }
+         if (a == 0)
+           ret_type = arg;
+         else
+           args = tree_cons (NULL_TREE, arg, args);
+       }
+      builtin_function (s16builtins[i].name,
+                       build_function_type (ret_type, args),
+                       i, BUILT_IN_MD, NULL, NULL);
+    }
 }
+
+static rtx
+xstormy16_expand_builtin(exp, target, subtarget, mode, ignore)
+     tree exp;
+     rtx target;
+     rtx subtarget ATTRIBUTE_UNUSED;
+     enum machine_mode mode ATTRIBUTE_UNUSED;
+     int ignore ATTRIBUTE_UNUSED;
+{
+  rtx op[10], args[10], pat, copyto[10], retval = 0;
+  tree fndecl, argtree;
+  int i, a, o, code;
+
+  fndecl = TREE_OPERAND (TREE_OPERAND (exp, 0), 0);
+  argtree = TREE_OPERAND (exp, 1);
+  i = DECL_FUNCTION_CODE (fndecl);
+  code = s16builtins[i].md_code;
+
+  for (a = 0; a < 10 && argtree; a++)
+    {
+      args[a] = expand_expr (TREE_VALUE (argtree), NULL_RTX, VOIDmode, 0);
+      argtree = TREE_CHAIN (argtree);
+    }
+
+  for (o = 0; s16builtins[i].arg_ops[o]; o++)
+    {
+      char ao = s16builtins[i].arg_ops[o];
+      char c = insn_data[code].operand[o].constraint[0];
+      int omode;
+
+      copyto[o] = 0;
+
+      omode = insn_data[code].operand[o].mode;
+      if (ao == 'r')
+       op[o] = target ? target : gen_reg_rtx (omode);
+      else if (ao == 't')
+       op[o] = gen_reg_rtx (omode);
+      else
+       op[o] = args[(int) hex_value (ao)];
+
+      if (! (*insn_data[code].operand[o].predicate) (op[o], GET_MODE (op[o])))
+       {
+         if (c == '+' || c == '=')
+           {
+             copyto[o] = op[o];
+             op[o] = gen_reg_rtx (omode);
+           }
+         else
+           op[o] = copy_to_mode_reg (omode, op[o]);
+       }
+
+      if (ao == 'r')
+       retval = op[o];
+    }
+
+  pat = GEN_FCN (code) (op[0], op[1], op[2], op[3], op[4],
+                       op[5], op[6], op[7], op[8], op[9]);
+  emit_insn (pat);
+
+  for (o = 0; s16builtins[i].arg_ops[o]; o++)
+    if (copyto[o])
+      {
+       emit_move_insn (copyto[o], op[o]);
+       if (op[o] == retval)
+         retval = copyto[o];
+      }
+
+  return retval;
+}
+
 \f
+#undef TARGET_ASM_ALIGNED_HI_OP
+#define TARGET_ASM_ALIGNED_HI_OP "\t.hword\t"
+#undef TARGET_ASM_ALIGNED_SI_OP
+#define TARGET_ASM_ALIGNED_SI_OP "\t.word\t"
+#undef TARGET_ENCODE_SECTION_INFO
+#define TARGET_ENCODE_SECTION_INFO xstormy16_encode_section_info
+
+#undef TARGET_ASM_OUTPUT_MI_THUNK
+#define TARGET_ASM_OUTPUT_MI_THUNK xstormy16_asm_output_mi_thunk
+#undef TARGET_ASM_CAN_OUTPUT_MI_THUNK
+#define TARGET_ASM_CAN_OUTPUT_MI_THUNK default_can_output_mi_thunk_no_vcall
+
+#undef TARGET_RTX_COSTS
+#define TARGET_RTX_COSTS xstormy16_rtx_costs
+#undef TARGET_ADDRESS_COST
+#define TARGET_ADDRESS_COST xstormy16_address_cost
+
 struct gcc_target targetm = TARGET_INITIALIZER;