[adtools] Need help with adding support for AmigaOS 3.x

  • From: Josef Wegner <Josef.Wegner@xxxxxxxxxxx>
  • To: adtools@xxxxxxxxxxxxx
  • Date: Sun, 16 Oct 2005 20:18:51 +0200

Hi,

I am trying to re-add the support for m68k-amigaos to the lastest
adtools GCC version.

I got surprisingly far for one who has no deep understand of compilers
and GCC in particular.

So I copied AmigaOS 3.x specific files from a modified GCC 3.3.3 version
into my local CVS version of the adtools gcc. I also modified the
config.gcc to re-enable the m68k-amigaos target and started to compile
it.

The compilation worked fine until it tries to compile amigos.c for the
m68k. There I get a lot of problems:


gcc -c   -g -O2  -DIN_GCC -DCROSS_COMPILE  -W -Wall -Wwrite-strings 
-Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long 
-Wno-variadic-macros -Wold -style-definition    -DHAVE_CONFIG_H -I. -I. 
-I../../gcc/gcc -I../../gcc/gcc/. -I../../gcc/gcc/../include 
-I../../gcc/gcc/../libcpp/include     -I. -I. -I../../gcc/gcc -I../../gcc/gcc/. 
-I../../gcc/gcc/../include -I../../gcc/gcc/../libcpp/include  
../../gcc/gcc/config/m68k/amigaos.c -o amigaos.o
In file included from ../../gcc/gcc/rtl.h:27,
                 from ../../gcc/gcc/config/m68k/amigaos.c:26:
../../gcc/gcc/input.h:52: error: syntax error before â(â token
../../gcc/gcc/input.h:59: error: syntax error before â}â token
../../gcc/gcc/input.h:59: warning: ISO C does not allow extra â;â outside 
of a function


and a lot of other errors. If I interpret the error correctly, this is
the root problem:

<snip of input.h with line numbers>

50 #else /* ! USE_MAPPED_LOCATION */
51 
52 struct location_s GTY(()) // 
53 {
54   /* The name of the source file involved.  */
55   const char *file;
56
57   /* The line-location in the source file.  */
58   int line;
59 };
60

</snip>

I used this configure settings:


../gcc/configure --prefix=/usr/local/amiga --target=m68k-amigaos 
--enable-languages=c,c++,objc --enable-haifa --disable-shared 
--enable-sjlj-exceptions


But I do not know why this does not compile. I have attached the files I
copied to the gcc tree. The only other change was config.gcc, where I
added following lines:


m68k-*-amigaos*)
        tmake_file=m68k/t-amigaos
        tm_file="${tm_file} m68k/amigaos.h"
        tm_p_file="${tm_p_file} m68k/amigaos-protos.h"
        tm_defines="TARGET_AMIGAOS TARGET_DEFAULT=0" # 68000, no 68881, no 
bitfield ops
        extra_objs=amigaos.o
        ;;


It would be nice if somebody could help me with this problem.

Thanks very much
-Josef
/* Configuration for GNU C-compiler for m68k Amiga, running AmigaOS.
   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003
   Free Software Foundation, Inc.  
   Contributed by Markus M. Wild (wild@xxxxxxxxxxxxxxxxxxxxx).
   Heavily modified by Kamil Iskra (iskra@xxxxxxxxxxxxxxxxxxxxxx).

This file is part of GNU CC.

GNU CC 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, or (at your option)
any later version.

GNU CC 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 GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#include "config.h"
#include "system.h"
#include "rtl.h"
#include "output.h"
#include "tree.h"
#include "flags.h"
#include "expr.h"
#include "toplev.h"
#include "tm_p.h"

static int amigaos_put_in_text PARAMS ((tree));
static rtx gen_stack_management_call PARAMS ((rtx, rtx, const char *));

/* Baserel support.  */

/* Does operand (which is a symbolic_operand) live in text space? If
   so SYMBOL_REF_FLAG, which is set by ENCODE_SECTION_INFO, will be true.

   This function is used in base relative code generation. */

int
read_only_operand (operand)
     rtx operand;
{
  if (GET_CODE (operand) == CONST)
    operand = XEXP (XEXP (operand, 0), 0);
  if (GET_CODE (operand) == SYMBOL_REF)
    return SYMBOL_REF_FLAG (operand) || CONSTANT_POOL_ADDRESS_P (operand);
  return 1;
}

/* Choose the section to use for DECL.  RELOC is true if its value contains
   any relocatable expression.  */

void
amigaos_select_section (decl, reloc, align)
     tree decl;
     int reloc;
     unsigned HOST_WIDE_INT align ATTRIBUTE_UNUSED;
{
  if (TREE_CODE (decl) == STRING_CST)
    {
      if (!flag_writable_strings)
        readonly_data_section ();
      else
        data_section ();
    }
  else if (TREE_CODE (decl) == VAR_DECL)
    {
      if (TREE_READONLY (decl)
          && ! TREE_THIS_VOLATILE (decl)
          && DECL_INITIAL (decl)
          && (DECL_INITIAL (decl) == error_mark_node
              || TREE_CONSTANT (DECL_INITIAL (decl)))
          && (!flag_pic || (flag_pic<3 && !reloc)
              || SYMBOL_REF_FLAG (XEXP (DECL_RTL (decl), 0))))
        readonly_data_section ();
      else
        data_section ();
    }
  else if ((!flag_pic || (flag_pic<3 && !reloc))
           && SYMBOL_REF_FLAG (XEXP ((!DECL_P(decl)
                ? TREE_CST_RTL (decl) : DECL_RTL (decl)), 0)))
    readonly_data_section ();
  else
    data_section ();
}

/* This function is used while generating a base relative code.
   It returns 1 if a decl is not relocatable, i. e., if it can be put
   in the text section.
   Currently, it's very primitive: it just checks if the object size
   is less than 4 bytes (i. e., if it can hold a pointer).  It also
   supports arrays and floating point types.  */

static int
amigaos_put_in_text (decl)
     tree decl;
{
  tree type = TREE_TYPE (decl);
  if (TREE_CODE (type) == ARRAY_TYPE)
    type = TREE_TYPE (type);
  return (TREE_INT_CST_HIGH (TYPE_SIZE (type)) == 0
          && TREE_INT_CST_LOW (TYPE_SIZE (type)) < 32)
         || FLOAT_TYPE_P (type);
}

/* Record properties of a DECL into the associated SYMBOL_REF.  */

void
amigaos_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;
  else
    {
      rtx rtl = (!DECL_P(decl) ? TREE_CST_RTL (decl) : DECL_RTL (decl));
      if ((RTX_UNCHANGING_P (rtl) && !MEM_VOLATILE_P (rtl)
           && (flag_pic<3 || (TREE_CODE (decl) == STRING_CST
                              && !flag_writable_strings)
               || amigaos_put_in_text (decl)))
          || (TREE_CODE (decl) == VAR_DECL
              && DECL_SECTION_NAME (decl) != NULL_TREE))
        SYMBOL_REF_FLAG (XEXP (rtl, 0)) = 1;
    }
}

/* Common routine used to check if a4 should be preserved/restored.  */

int
amigaos_restore_a4 ()
{
  return (flag_pic >= 3 &&
          (TARGET_RESTORE_A4 || TARGET_ALWAYS_RESTORE_A4
           || lookup_attribute ("saveds",
                                TYPE_ATTRIBUTES (TREE_TYPE 
(current_function_decl)))));
}

void
amigaos_alternate_pic_setup (stream)
     FILE *stream;
{
  if (TARGET_RESTORE_A4 || TARGET_ALWAYS_RESTORE_A4)
    asm_fprintf (stream, "\tjbsr %U__restore_a4\n");
  else if (lookup_attribute ("saveds",
                             TYPE_ATTRIBUTES (TREE_TYPE 
(current_function_decl))))
    asm_fprintf (stream, "\tlea %U__a4_init,%Ra4\n");
}

/* Attributes support.  */

#define AMIGA_CHIP_SECTION_NAME ".datachip"

/* Handle a "chip" attribute;
   arguments as in struct attribute_spec.handler.  */

tree
amigaos_handle_decl_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 (*node) == VAR_DECL)
    {
      if (is_attribute_p ("chip", name))
#ifdef TARGET_ASM_NAMED_SECTION
        {
          if (! TREE_STATIC (*node) && ! DECL_EXTERNAL (*node))
            error ("`chip' attribute cannot be specified for local variables");
          else
            {
              /* The decl may have already been given a section attribute from
                 a previous declaration.  Ensure they match.  */
              if (DECL_SECTION_NAME (*node) == NULL_TREE)
                DECL_SECTION_NAME (*node) =
                  build_string (strlen (AMIGA_CHIP_SECTION_NAME) + 1,
                                AMIGA_CHIP_SECTION_NAME);
              else if (strcmp (TREE_STRING_POINTER (DECL_SECTION_NAME (*node)),
                               AMIGA_CHIP_SECTION_NAME) != 0)
                {
                  error_with_decl (*node,
                          "`chip' for `%s' conflicts with previous 
declaration");
                }
            }
        }
#else
        error ("`chip' attribute is not supported for this target");
#endif
    }
  else
    {
      warning ("`%s' attribute only applies to variables",
               IDENTIFIER_POINTER (name));
      *no_add_attrs = true;
    }

  return NULL_TREE;
}

/* Handle a "stackext", "interrupt" or "saveds" attribute;
   arguments as in struct attribute_spec.handler.  */

tree
amigaos_handle_type_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 (*node) == FUNCTION_TYPE || TREE_CODE (*node) == METHOD_TYPE)
    {
      if (is_attribute_p ("stackext", name))
        {
          if (lookup_attribute ("interrupt", TYPE_ATTRIBUTES(*node)))
            {
              error ("`stackext' and `interrupt' are mutually exclusive");
            }
        }
      else if (is_attribute_p ("interrupt", name))
        {
          if (lookup_attribute ("stackext", TYPE_ATTRIBUTES(*node)))
            {
              error ("`stackext' and `interrupt' are mutually exclusive");
            }
        }
      else if (is_attribute_p ("saveds", name))
        {
        }
    }
  else
    {
      warning ("`%s' attribute only applies to functions",
               IDENTIFIER_POINTER (name));
      *no_add_attrs = true;
    }

  return NULL_TREE;
}

/* Stack checking and automatic extension support.  */

void
amigaos_prologue_begin_hook (stream, fsize)
     FILE *stream;
     int fsize;
{
  if (TARGET_STACKCHECK)
    {
      if (fsize < 256)
        asm_fprintf (stream, "\tcmpl %s,%Rsp\n"
                             "\tjcc 0f\n"
                             "\tjra %U__stkovf\n"
                             "\t0:\n",
                     (flag_pic == 3 ? "a4@(___stk_limit:W)" :
                                      (flag_pic == 4 ? "a4@(___stk_limit:L)" :
                                                       "___stk_limit")));
      else
        asm_fprintf (stream, "\tmovel %I%d,%Rd0\n\tjbsr %U__stkchk_d0\n",
                     fsize);
    }
}

void
amigaos_alternate_frame_setup_f (stream, fsize)
     FILE *stream;
     int fsize;
{
  if (fsize < 128)
    asm_fprintf (stream, "\tcmpl %s,%Rsp\n"
                         "\tjcc 0f\n"
                         "\tmoveq %I%d,%Rd0\n"
                         "\tmoveq %I0,%Rd1\n"
                         "\tjbsr %U__stkext_f\n"
                         "0:\tlink %Ra5,%I%d:W\n",
                 (flag_pic == 3 ? "a4@(___stk_limit:W)" :
                                  (flag_pic == 4 ? "a4@(___stk_limit:L)" :
                                                   "___stk_limit")),
                 fsize, -fsize);
  else
    asm_fprintf (stream, "\tmovel %I%d,%Rd0\n\tjbsr %U__link_a5_d0_f\n",
                 fsize);
}

void
amigaos_alternate_frame_setup (stream, fsize)
     FILE *stream;
     int fsize;
{
  if (!fsize)
    asm_fprintf (stream, "\tcmpl %s,%Rsp\n"
                         "\tjcc 0f\n"
                         "\tmoveq %I0,%Rd0\n"
                         "\tmoveq %I0,%Rd1\n"
                         "\tjbsr %U__stkext_f\n"
                         "0:\n",
                 (flag_pic == 3 ? "a4@(___stk_limit:W)" :
                                  (flag_pic == 4 ? "a4@(___stk_limit:L)" :
                                                   "___stk_limit")));
  else if (fsize + 4 < 128)
    asm_fprintf (stream, "\tcmpl %s,%Rsp\n"
                         "\tjcc 0f\n"
                         "\tmoveq %I%d,%Rd0\n"
                         "\tmoveq %I0,%Rd1\n"
                         "\tjbsr %U__stkext_f\n"
                         "0:\taddw %I%d,%Rsp\n",
                 (flag_pic == 3 ? "a4@(___stk_limit:W)" :
                                  (flag_pic == 4 ? "a4@(___stk_limit:L)" :
                                                   "___stk_limit")),
                 fsize + 4, -(fsize + 4));
  else
    asm_fprintf (stream, "\tmovel %I%d,%Rd0\n\tjbsr %U__sub_d0_sp_f\n",
                 fsize + 4);
}

static rtx
gen_stack_management_call (stack_pointer, arg, func)
     rtx stack_pointer;
     rtx arg;
     const char *func;
{
  rtx call_insn, call, seq, name;
  start_sequence ();

  /* Move arg to d0.  */
  emit_move_insn (gen_rtx_REG (SImode, 0), arg);

  /* Generate the function reference.  */
  name = gen_rtx_SYMBOL_REF (Pmode, func);
  SYMBOL_REF_FLAG (name) = 1;
  /* If optimizing, put it in a psedo so that several loads can be merged
     into one.  */
  if (optimize && !flag_no_function_cse)
    name = copy_to_reg (name);

  /* Generate the function call.  */
  call = gen_rtx_CALL (VOIDmode, gen_rtx_MEM (FUNCTION_MODE, name),
                  const0_rtx);
  /* If we are doing stack extension, notify about the sp change.  */
  if (stack_pointer)
    call = gen_rtx_SET (VOIDmode, stack_pointer, call);

  /* Generate the call instruction.  */
  call_insn = emit_call_insn (call);
  /* Stack extension does not change memory in an unpredictable way.  */
  CONST_OR_PURE_CALL_P (call_insn) = 1;
  /* We pass an argument in d0.  */
  CALL_INSN_FUNCTION_USAGE (call_insn) = gen_rtx_EXPR_LIST (VOIDmode,
        gen_rtx_USE (VOIDmode, gen_rtx_REG (SImode, 0)), 0);

  seq = get_insns ();
  end_sequence ();
  return seq;
}

rtx
gen_stack_cleanup_call (stack_pointer, sa)
     rtx stack_pointer;
     rtx sa;
{
  return gen_stack_management_call (stack_pointer, sa, "__move_d0_sp");
}

void
amigaos_alternate_allocate_stack (operands)
     rtx *operands;
{
  if (TARGET_STACKEXTEND)
    emit_insn (gen_stack_management_call (stack_pointer_rtx, operands[1],
                                           "__sub_d0_sp"));
  else
    {
      if (TARGET_STACKCHECK)
        emit_insn (gen_stack_management_call (0, operands[1], "__stkchk_d0"));
      anti_adjust_stack (operands[1]);
    }
  emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
}

/* begin-GG-local: explicit register specification for parameters */

/* Initialize a variable CUM of type CUMULATIVE_ARGS
   for a call to a function whose data type is FNTYPE.
   For a library call, FNTYPE is 0.  */

void
amigaos_init_cumulative_args(cum, fntype)
     CUMULATIVE_ARGS *cum;
     tree fntype;
{
  m68k_init_cumulative_args(cum, fntype);

  if (fntype)
    cum->formal_type=TYPE_ARG_TYPES(fntype);
  else /* Call to compiler-support function. */
    cum->formal_type=0;
}

/* Update the data in CUM to advance over an argument.  */

void
amigaos_function_arg_advance(cum)
     CUMULATIVE_ARGS *cum;
{
  m68k_function_arg_advance(cum);

  if (cum->formal_type)
    cum->formal_type=TREE_CHAIN((tree)cum->formal_type);
}

/* A C expression that controls whether a function argument is passed
   in a register, and which register. */

struct rtx_def *
amigaos_function_arg(cum, mode, type)
     CUMULATIVE_ARGS *cum;
     enum machine_mode mode;
     tree type;
{
  tree asmtree;
  if (cum->formal_type && TREE_VALUE((tree)cum->formal_type)
      && (asmtree=lookup_attribute("asm",
                        TYPE_ATTRIBUTES(TREE_VALUE((tree)cum->formal_type)))))
    {
      int i;
#if 0
      /* See c-decl.c/push_parm_decl for an explanation why this doesn't work.
       */
      cum->last_arg_reg=TREE_INT_CST_LOW(TREE_VALUE(TREE_VALUE(asmtree)));
#else
      cum->last_arg_reg=TREE_INT_CST_LOW(TREE_VALUE(asmtree));
#endif
      cum->last_arg_len=HARD_REGNO_NREGS(cum->last_arg_reg, mode);

      for (i=0; i<cum->last_arg_len; i++)
        if (cum->regs_already_used & (1 << cum->last_arg_reg+i))
          {
            error("two parameters allocated for one register");
            break;
          }
      return gen_rtx_REG (mode, cum->last_arg_reg);
    }
  else
    return m68k_function_arg(cum, mode, type);
}

/* Return zero if the attributes on TYPE1 and TYPE2 are incompatible,
   one if they are compatible, and two if they are nearly compatible
   (which causes a warning to be generated). */

int
amigaos_comp_type_attributes (type1, type2)
     tree type1, type2;
{
  /* Functions or methods are incompatible if they specify mutually exclusive
     ways of passing arguments. */
  if (TREE_CODE(type1)==FUNCTION_TYPE || TREE_CODE(type1)==METHOD_TYPE)
    {
      tree arg1, arg2;
      arg1=TYPE_ARG_TYPES(type1);
      arg2=TYPE_ARG_TYPES(type2);
      for (; arg1 && arg2; arg1=TREE_CHAIN(arg1), arg2=TREE_CHAIN(arg2))
        if (TREE_VALUE(arg1) && TREE_VALUE(arg2))
          {
            tree asm1, asm2;
            asm1=lookup_attribute("asm", TYPE_ATTRIBUTES(TREE_VALUE(arg1)));
            asm2=lookup_attribute("asm", TYPE_ATTRIBUTES(TREE_VALUE(arg2)));
            if (asm1 && asm2)
              {
                if (TREE_INT_CST_LOW(TREE_VALUE(asm1))!=
                    TREE_INT_CST_LOW(TREE_VALUE(asm2)))
                  return 0; /* Two different registers specified. */
              }
            else
              if (asm1 || asm2)
                return 0; /* "asm" used in only one type. */
          }
    }
  return 1;
}

/* end-GG-local */
/* Configuration for GNU C-compiler for m68k Amiga, running AmigaOS.
   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003
   Free Software Foundation, Inc.  
   Contributed by Markus M. Wild (wild@xxxxxxxxxxxxxxxxxxxxx).
   Heavily modified by Kamil Iskra (iskra@xxxxxxxxxxxxxxxxxxxxxx).

This file is part of GNU CC.

GNU CC 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, or (at your option)
any later version.

GNU CC 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 GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */


/* Specs, switches.  */

/* amiga/amigaos are the new "standard" defines for the Amiga.
   MCH_AMIGA, AMIGA, __chip etc. are used in other compilers and are
   provided for compatibility reasons.
   When creating shared libraries, use different 'errno'.  */

#undef TARGET_OS_CPP_BUILTINS
#define TARGET_OS_CPP_BUILTINS()                                        \
  do                                                                    \
    {                                                                   \
      builtin_define ("__chip=__attribute__((__chip__))");              \
      builtin_define ("__saveds=__attribute__((__saveds__))");          \
      builtin_define ("__interrupt=__attribute__((__interrupt__))");    \
      builtin_define ("__stackext=__attribute__((__stackext__))");      \
      builtin_define ("__regargs=__attribute__((__regparm__))");        \
      builtin_define ("__stdargs=__attribute__((__stkparm__))");        \
      builtin_define ("__aligned=__attribute__((__aligned__(4)))");     \
      if (target_flags & (MASK_RESTORE_A4|MASK_ALWAYS_RESTORE_A4))      \
        builtin_define ("errno=(*ixemul_errno)");                       \
      builtin_define_std ("amiga");                                     \
      builtin_define_std ("amigaos");                                   \
      builtin_define_std ("AMIGA");                                     \
      builtin_define_std ("MCH_AMIGA");                                 \
      builtin_assert ("system=amigaos");                                \
    }                                                                   \
  while (0)

/* Inform the program which CPU we compile for.  */

#undef TARGET_CPU_CPP_BUILTINS
#define TARGET_CPU_CPP_BUILTINS()                                       \
  do                                                                    \
    {                                                                   \
      if (TARGET_68040_ONLY)                                            \
        {                                                               \
          if (TARGET_68060)                                             \
            builtin_define_std ("mc68060");                             \
          else                                                          \
            builtin_define_std ("mc68040");                             \
        }                                                               \
      else if (TARGET_68020)                                            \
        builtin_define_std ("mc68020");                                 \
      builtin_define_std ("mc68000");                                   \
      builtin_assert ("cpu=m68k");                                      \
      builtin_assert ("machine=m68k");                                  \
    }                                                                   \
  while (0)

/* Define __HAVE_68881__ in preprocessor according to the -m flags.
   This will control the use of inline 68881 insns in certain macros.
   Note: it should be set in TARGET_CPU_CPP_BUILTINS but TARGET_68881
         isn't the same -m68881 since its also true for -m680[46]0 ...
   Differentiate between libnix and ixemul.  */

#define CPP_SPEC                                                        \
  "%{m68881:-D__HAVE_68881__} "                                         \
  "%{noixemul:%{!ansi:%{!std=*:-Dlibnix}%{std=gnu*:-Dlibnix}} -D__libnix 
-D__libnix__} " \
  "%{!noixemul:%{!ansi:%{!std=*:-Dixemul}%{std=gnu*:-Dixemul}} -D__ixemul 
-D__ixemul__}"

/* Translate '-resident' to '-fbaserel' (they differ in linking stage only).
   Don't put function addresses in registers for PC-relative code.  */

#define CC1_SPEC                                                        \
  "%{resident:-fbaserel} "                                              \
  "%{resident32:-fbaserel32} "                                          \
  "%{msmall-code:-fno-function-cse}"

/* Various -m flags require special flags to the assembler.  */

#define ASM_SPEC                                                        \
  "%(asm_cpu) %(asm_cpu_default) %{msmall-code:-sc}"

#define ASM_CPU_SPEC                                                    \
  "%{m68000|mc68000:-m68010} "                                          \
  "%{m6802*|mc68020:-m68020} "                                          \
  "%{m68030} "                                                          \
  "%{m68040} "                                                          \
  "%{m68060}"

#define ASM_CPU_DEFAULT_SPEC                                            \
  "%{!m680*:%{!mc680*:-m68010}}"

/* If debugging, tell the linker to output amiga-hunk symbols *and* a BSD
   compatible debug hunk.
   Also, pass appropriate linker flavours depending on user-supplied
   commandline options.  */

#define LINK_SPEC                                                       \
  "%{noixemul:-fl libnix} "                                             \
  "%{resident*:-amiga-datadata-reloc} "                                 \
  "%{resident|fbaserel:-m amiga_bss -fl libb} "                         \
  "%{resident32|fbaserel32:-m amiga_bss -fl libb32} "                   \
  "%{g:-amiga-debug-hunk} "                                             \
  "%(link_cpu)"

#define LINK_CPU_SPEC                                                   \
  "%{m6802*|mc68020|m68030|m68040|m68060:-fl libm020} "                 \
  "%{m68881:-fl libm881}"

/* Choose the right startup file, depending on whether we use base relative
   code, base relative code with automatic relocation (-resident), their
   32-bit versions, libnix, profiling or plain crt0.o.  */

#define STARTFILE_SPEC                                                  \
  "%{!noixemul:"                                                        \
    "%{fbaserel:%{!resident:bcrt0.o%s}}"                                \
    "%{resident:rcrt0.o%s}"                                             \
    "%{fbaserel32:%{!resident32:lcrt0.o%s}}"                            \
    "%{resident32:scrt0.o%s}"                                           \
    "%{!resident:%{!fbaserel:%{!resident32:%{!fbaserel32:"              \
      "%{pg:gcrt0.o%s}%{!pg:%{p:mcrt0.o%s}%{!p:crt0.o%s}}}}}}}"         \
  "%{noixemul:"                                                         \
    "%{resident:libnix/nrcrt0.o%s} "                                    \
    "%{!resident:%{fbaserel:libnix/nbcrt0.o%s}%{!fbaserel:libnix/ncrt0.o%s}}}"

#define ENDFILE_SPEC                                                    \
  "%{noixemul:-lstubs}"

/* Automatically search libamiga.a for AmigaOS specific functions.  Note
   that we first search the standard C library to resolve as much as
   possible from there, since it has names that are duplicated in libamiga.a
   which we *don't* want from there.  Then search libamiga.a for any calls
   that were not generated inline, and finally search the standard C library
   again to resolve any references that libamiga.a might have generated.
   This may only be a temporary solution since it might be better to simply
   remove the things from libamiga.a that should be pulled in from libc.a
   instead, which would eliminate the first reference to libc.a.  Note that
   if we don't search it automatically, it is very easy for the user to try
   to put in a -lamiga himself and get it in the wrong place, so that (for
   example) calls like sprintf come from -lamiga rather than -lc. */

#define LIB_SPEC                                                        \
  "%{!noixemul:"                                                        \
    "%{p|pg:-lc_p}"                                                     \
    "%{!p:%{!pg:-lc -lamiga -lc}}}"                                     \
  "%{noixemul:"                                                         \
    "-lnixmain -lnix -lamiga %{mstackcheck|mstackextend:-lstack}}"

/* This macro defines names of additional specifications to put in the specs
   that can be used in various specifications like CC1_SPEC.  Its definition
   is an initializer with a subgrouping for each command option.

   Each subgrouping contains a string constant, that defines the
   specification name, and a string constant that used by the GNU CC driver
   program.

   Do not define this macro if it does not need to do anything.  */

#define EXTRA_SPECS                                                     \
  { "asm_cpu",          ASM_CPU_SPEC },                                 \
  { "asm_cpu_default",  ASM_CPU_DEFAULT_SPEC },                         \
  { "link_cpu",         LINK_CPU_SPEC }

/* Compile with stack extension.  */

#define MASK_STACKEXTEND 0x40000000 /* 1 << 30 */
#define TARGET_STACKEXTEND (((target_flags & MASK_STACKEXTEND)          \
  && !lookup_attribute ("interrupt",                                    \
                        TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))) \
  || lookup_attribute ("stackext",                                      \
                       TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))

/* Compile with stack checking.  */

#define MASK_STACKCHECK 0x20000000 /* 1 << 29 */
#define TARGET_STACKCHECK ((target_flags & MASK_STACKCHECK)             \
  && !(target_flags & MASK_STACKEXTEND)                                 \
  && !lookup_attribute ("interrupt",                                    \
                        TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))) \
  && !lookup_attribute ("stackext",                                     \
                        TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl))))

/* Compile with a4 restoring in public functions.  */

#define MASK_RESTORE_A4 0x10000000 /* 1 << 28 */
#define TARGET_RESTORE_A4                                               \
  ((target_flags & MASK_RESTORE_A4) && TREE_PUBLIC (current_function_decl))

/* Compile with a4 restoring in all functions.  */

#define MASK_ALWAYS_RESTORE_A4 0x8000000 /* 1 << 27 */
#define TARGET_ALWAYS_RESTORE_A4 (target_flags & MASK_ALWAYS_RESTORE_A4)

/* Provide a dummy entry for the '-msmall-code' switch.  This is used by
   the assembler and '*_SPEC'.  */

#undef SUBTARGET_SWITCHES
#define SUBTARGET_SWITCHES                                              \
    { "small-code", 0,                                                  \
      "" /* Undocumented. */ },                                         \
    { "stackcheck", MASK_STACKCHECK,                                    \
      N_("Generate stack-check code") },                                \
    { "no-stackcheck", - MASK_STACKCHECK,                               \
      N_("Do not generate stack-check code") },                         \
    { "stackextend", MASK_STACKEXTEND,                                  \
      N_("Generate stack-extension code") },                            \
    { "no-stackextend", - MASK_STACKEXTEND,                             \
      N_("Do not generate stack-extension code") },                     \
    { "fixedstack", - (MASK_STACKCHECK|MASK_STACKEXTEND),               \
      N_("Do not generate stack-check/stack-extension code") },         \
    { "restore-a4", MASK_RESTORE_A4,                                    \
      N_("Restore a4 in public functions") },                           \
    { "no-restore-a4", - MASK_RESTORE_A4,                               \
      N_("Do not restore a4 in public functions") },                    \
    { "always-restore-a4", MASK_ALWAYS_RESTORE_A4,                      \
      N_("Restore a4 in all functions") },                              \
    { "no-always-restore-a4", - MASK_ALWAYS_RESTORE_A4,                 \
      N_("Do not restore a4 in all functions") },

#undef SUBTARGET_OVERRIDE_OPTIONS
#define SUBTARGET_OVERRIDE_OPTIONS                                      \
do                                                                      \
  {                                                                     \
    if (!TARGET_68020 && flag_pic==4)                                   \
      error ("-fbaserel32 is not supported on the 68000 or 68010\n");   \
  }                                                                     \
while (0)

/* Various ABI issues.  */

/* This is (almost;-) BSD, so it wants DBX format.  */

#define DBX_DEBUGGING_INFO

/* GDB goes mad if it sees the function end marker.  */

#define NO_DBX_FUNCTION_END 1

/* Allow folding division by zero.  */

#define REAL_INFINITY

/* Don't try using XFmode since we don't have appropriate runtime software
   support.  */
#undef LONG_DOUBLE_TYPE_SIZE
#define LONG_DOUBLE_TYPE_SIZE 64

/* Use A5 as framepointer instead of A6, since the AmigaOS ABI requires A6
   to be used as a shared library base pointer in direct library calls.  */

#undef FRAME_POINTER_REGNUM
#define FRAME_POINTER_REGNUM 13
#undef ARG_POINTER_REGNUM
#define ARG_POINTER_REGNUM 13

/* We use A4 for the PIC pointer, not A5, which is the framepointer.  */

#undef PIC_OFFSET_TABLE_REGNUM
#define PIC_OFFSET_TABLE_REGNUM (flag_pic ? 12 : INVALID_REGNUM)

/* The AmigaOS ABI does not define how structures should be returned, so,
   contrary to 'm68k.h', we prefer a multithread-safe solution.  */

#undef PCC_STATIC_STRUCT_RETURN

/* Setup a default shell return value for those (gazillion..) programs that
   (inspite of ANSI-C) declare main() to be void (or even VOID...) and thus
   cause the shell to randomly caugh upon executing such programs (contrary
   to Unix, AmigaOS scripts are terminated with an error if a program returns
   with an error code above the `error' or even `failure' level
   (which is configurable with the FAILAT command)).

   No longer supported in GCC 4.x ...
   BTW: using void main is no good coding style either...

#define DEFAULT_MAIN_RETURN c_expand_return (integer_zero_node) */

#undef WCHAR_TYPE
#define WCHAR_TYPE "unsigned int"

/* XXX: section support */
#if 0 
/* Support sections in chip memory, currently '.datachip' only.  */
#undef TARGET_ASM_NAMED_SECTION
#define TARGET_ASM_NAMED_SECTION amiga_named_section

/* We define TARGET_ASM_NAMED_SECTION, but we don't support arbitrary sections,
   including '.gcc_except_table', so we emulate the standard behaviour.  */
#undef TARGET_ASM_EXCEPTION_SECTION
#define TARGET_ASM_EXCEPTION_SECTION amiga_exception_section

#undef TARGET_ASM_EH_FRAME_SECTION
#define TARGET_ASM_EH_FRAME_SECTION amiga_eh_frame_section
#endif

/* Use sjlj exceptions until problems with DWARF2 unwind info on a.out
   targets using GNU ld are fixed.  */
/*
#define DWARF2_UNWIND_INFO      0
*/
#define NO_DWARF2_UNWIND_INFO

/* GAS supports alignment up to 32768 bytes.  */
#undef ASM_OUTPUT_ALIGN
#define ASM_OUTPUT_ALIGN(FILE, LOG)                                     \
do                                                                      \
  {                                                                     \
    if ((LOG) == 1)                                                     \
      fprintf ((FILE), "\t.even\n");                                    \
    else                                                                \
      fprintf ((FILE), "\t.align %d\n", (LOG));                         \
  }                                                                     \
while (0)

#define MAX_OFILE_ALIGNMENT ((1 << 15)*BITS_PER_UNIT)

/* It is not uncommon to use a custom startup code on AmigaOS.  The OS
   starts an application by jumping to the first byte of the text section,
   so we prefer the constants to be put after the functions.  */
/* FIXME: Disabled for now, it's buggy.  */

/* #define CONSTANT_AFTER_FUNCTION_P(EXP) 1 */ /**/

/* Call __flush_cache() after building the trampoline: it will call
   an appropriate OS cache-clearing routine.  */

#undef FINALIZE_TRAMPOLINE
#define FINALIZE_TRAMPOLINE(TRAMP)                                      \
  emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "__flush_cache"),       \
                     0, VOIDmode, 2, (TRAMP), Pmode,                    \
                     GEN_INT (TRAMPOLINE_SIZE), SImode)

/* Baserel support.  */

/* Given that symbolic_operand(X), return TRUE if no special
   base relative relocation is necessary */

#define LEGITIMATE_BASEREL_OPERAND_P(X)                                 \
  (flag_pic >= 3 && read_only_operand (X))

#undef LEGITIMATE_PIC_OPERAND_P
#define LEGITIMATE_PIC_OPERAND_P(X)                                     \
  (! symbolic_operand (X, VOIDmode) || LEGITIMATE_BASEREL_OPERAND_P (X))

/* Define this macro if references to a symbol must be treated
   differently depending on something about the variable or
   function named by the symbol (such as what section it is in).

   The macro definition, if any, is executed immediately after the
   rtl for DECL or other node is created.
   The value of the rtl will be a `mem' whose address is a
   `symbol_ref'.

   The usual thing for this macro to do is to a flag in the
   `symbol_ref' (such as `SYMBOL_REF_FLAG') or to store a modified
   name string in the `symbol_ref' (if one bit is not enough
   information).

   On the Amiga we use this to indicate if references to a symbol should be
   absolute or base relative.  */

#undef TARGET_ENCODE_SECTION_INFO
#define TARGET_ENCODE_SECTION_INFO amigaos_encode_section_info

#define LIBCALL_ENCODE_SECTION_INFO(FUN)                                \
do                                                                      \
  {                                                                     \
    if (flag_pic >= 3)                                                  \
      SYMBOL_REF_FLAG (FUN) = 1;                                        \
  }                                                                     \
while (0)

/* Select and switch to a section for EXP.  */

#undef TARGET_ASM_SELECT_SECTION
#define TARGET_ASM_SELECT_SECTION amigaos_select_section

/* Preserve A4 for baserel code if necessary.  */

#define EXTRA_SAVE_REG(REGNO)                                           \
do {                                                                    \
  if (flag_pic && flag_pic >= 3 && REGNO == PIC_OFFSET_TABLE_REGNUM     \
      && amigaos_restore_a4())                                          \
    return 1;                                                           \
} while (0)

/* Predicate for ALTERNATE_PIC_SETUP.  */

#define HAVE_ALTERNATE_PIC_SETUP (flag_pic >= 3)

/* Make a4 point at data hunk.  */

#define ALTERNATE_PIC_SETUP(STREAM)                                     \
  (amigaos_alternate_pic_setup (STREAM))

/* If preserving a4, let the code generator know about it.  */

#undef SUBTARGET_INITIAL_FP_OFFSET
#define SUBTARGET_INITIAL_FP_OFFSET(OFFSET)                             \
do                                                                      \
  {                                                                     \
    if (amigaos_restore_a4 ())                                          \
      (OFFSET) += 4;                                                    \
  }                                                                     \
while (0)

/* Attribute support.  */

/* Generate the test of d0 before return to set cc register in 'interrupt'
   function.  */

#define EPILOGUE_END_HOOK(STREAM)                                       \
do                                                                      \
  {                                                                     \
    if (lookup_attribute ("interrupt",                                  \
                          TYPE_ATTRIBUTES (TREE_TYPE (current_function_decl)))) 
\
      asm_fprintf ((STREAM), "\ttstl %Rd0\n");                          \
  }                                                                     \
while (0)

/* begin-GG-local: explicit register specification for parameters */

/* Note: this is an extension of m68k_args */
struct amigaos_args
{
  int num_of_regs;
  long regs_already_used;
  int last_arg_reg;
  int last_arg_len;
  void *formal_type; /* New field: formal type of the current argument.  */
};

/* A C type for declaring a variable that is used as the first
   argument of `FUNCTION_ARG' and other related values.  */

#undef CUMULATIVE_ARGS
#define CUMULATIVE_ARGS struct amigaos_args

/* Initialize a variable CUM of type CUMULATIVE_ARGS
   for a call to a function whose data type is FNTYPE.
   For a library call, FNTYPE is 0.  */

#undef INIT_CUMULATIVE_ARGS
#define INIT_CUMULATIVE_ARGS(CUM,FNTYPE,LIBNAME,INDIRECT,N_NAMED_ARGS)          
\
  (amigaos_init_cumulative_args(&(CUM), (FNTYPE)))

/* Update the data in CUM to advance over an argument
   of mode MODE and data type TYPE.
   (TYPE is null for libcalls where that information may not be available.)  */

#undef FUNCTION_ARG_ADVANCE
#define FUNCTION_ARG_ADVANCE(CUM, MODE, TYPE, NAMED)                    \
  (amigaos_function_arg_advance (&(CUM)))

/* A C expression that controls whether a function argument is passed
   in a register, and which register. */

#undef FUNCTION_ARG
#define FUNCTION_ARG(CUM, MODE, TYPE, NAMED) \
  (amigaos_function_arg (&(CUM), (MODE), (TYPE)))

/* end-GG-local */

/* Stack checking and automatic extension support.  */

#define PROLOGUE_BEGIN_HOOK(STREAM, FSIZE)                              \
  (amigaos_prologue_begin_hook ((STREAM), (FSIZE)))

#define HAVE_ALTERNATE_FRAME_SETUP_F(FSIZE) TARGET_STACKEXTEND

#define ALTERNATE_FRAME_SETUP_F(STREAM, FSIZE)                          \
  (amigaos_alternate_frame_setup_f ((STREAM), (FSIZE)))

#define HAVE_ALTERNATE_FRAME_SETUP(FSIZE) TARGET_STACKEXTEND

#define ALTERNATE_FRAME_SETUP(STREAM, FSIZE)                            \
  (amigaos_alternate_frame_setup ((STREAM), (FSIZE)))

#define HAVE_ALTERNATE_FRAME_DESTR_F(FSIZE)                             \
  (TARGET_STACKEXTEND && current_function_calls_alloca)

#define ALTERNATE_FRAME_DESTR_F(STREAM, FSIZE)                          \
  (asm_fprintf ((STREAM), "\tjra %U__unlk_a5_rts\n"))

#define HAVE_ALTERNATE_RETURN                                           \
  (TARGET_STACKEXTEND && frame_pointer_needed &&                        \
   current_function_calls_alloca)

#define ALTERNATE_RETURN(STREAM)

#define HAVE_restore_stack_nonlocal TARGET_STACKEXTEND
#define gen_restore_stack_nonlocal gen_stack_cleanup_call

#define HAVE_restore_stack_function TARGET_STACKEXTEND
#define gen_restore_stack_function gen_stack_cleanup_call

#define HAVE_restore_stack_block TARGET_STACKEXTEND
#define gen_restore_stack_block gen_stack_cleanup_call

#undef TARGET_ALTERNATE_ALLOCATE_STACK
#define TARGET_ALTERNATE_ALLOCATE_STACK 1

#define ALTERNATE_ALLOCATE_STACK(OPERANDS)                              \
do                                                                      \
  {                                                                     \
    amigaos_alternate_allocate_stack (OPERANDS);                        \
    DONE;                                                               \
  }                                                                     \
while (0)

/* begin-GG-local: dynamic libraries */

extern int amigaos_do_collecting PARAMS ((void));
extern void amigaos_gccopts_hook PARAMS ((const char *));
extern void amigaos_libname_hook PARAMS ((const char* arg));
extern void amigaos_collect2_cleanup PARAMS ((void));
extern void amigaos_prelink_hook PARAMS ((const char **, int *));
extern void amigaos_postlink_hook PARAMS ((const char *));

/* This macro is used to check if all collect2 facilities should be used.
   We need a few special ones, like stripping after linking.  */

#define DO_COLLECTING (do_collecting || amigaos_do_collecting())

/* This macro is called in collect2 for every GCC argument name.
   ARG is a part of commandline (without '\0' at the end).  */

#define COLLECT2_GCC_OPTIONS_HOOK(ARG) amigaos_gccopts_hook(ARG)

/* This macro is called in collect2 for every ld's "-l" or "*.o" or "*.a"
   argument.  ARG is a complete argument, with '\0' at the end.  */

#define COLLECT2_LIBNAME_HOOK(ARG) amigaos_libname_hook(ARG)

/* This macro is called at collect2 exit, to clean everything up.  */

#define COLLECT2_EXTRA_CLEANUP amigaos_collect2_cleanup

/* This macro is called just before the first linker invocation.
   LD1_ARGV is "char** argv", which will be passed to "ld".  STRIP is an
   *address* of "strip_flag" variable.  */

#define COLLECT2_PRELINK_HOOK(LD1_ARGV, STRIP) \
amigaos_prelink_hook((LD1_ARGV), (STRIP))

/* This macro is called just after the first linker invocation, in place of
   "nm" and "ldd".  OUTPUT_FILE is the executable's filename.  */

#define COLLECT2_POSTLINK_HOOK(OUTPUT_FILE) amigaos_postlink_hook(OUTPUT_FILE)
/* end-GG-local */
/* Configuration for GNU C-compiler for m68k Amiga, running AmigaOS.
   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2003
   Free Software Foundation, Inc.  
   Contributed by Markus M. Wild (wild@xxxxxxxxxxxxxxxxxxxxx).
   Heavily modified by Kamil Iskra (iskra@xxxxxxxxxxxxxxxxxxxxxx).

This file is part of GNU CC.

GNU CC 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, or (at your option)
any later version.

GNU CC 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 GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

extern int amigaos_restore_a4 PARAMS ((void));
#ifdef RTX_CODE
extern int read_only_operand PARAMS ((rtx));
extern void amigaos_select_section PARAMS ((tree, int, unsigned HOST_WIDE_INT));
extern void amigaos_encode_section_info PARAMS ((tree, int));
extern void amigaos_alternate_pic_setup PARAMS ((FILE *));
extern void amigaos_prologue_begin_hook PARAMS ((FILE *, int));
extern void amigaos_alternate_frame_setup_f PARAMS ((FILE *, int));
extern void amigaos_alternate_frame_setup PARAMS ((FILE *, int));
extern struct rtx_def* gen_stack_cleanup_call PARAMS ((rtx, rtx));
extern void amigaos_alternate_allocate_stack PARAMS ((rtx *));
#ifdef TREE_CODE
extern void amigaos_init_cumulative_args PARAMS ((CUMULATIVE_ARGS *, tree));
extern void amigaos_function_arg_advance PARAMS ((CUMULATIVE_ARGS *));
extern struct rtx_def *amigaos_function_arg PARAMS ((CUMULATIVE_ARGS *, enum 
machine_mode, tree));
#endif
#endif
#ifdef TREE_CODE
extern tree amigaos_handle_decl_attribute PARAMS ((tree *, tree, tree, int, 
bool *));
extern tree amigaos_handle_type_attribute PARAMS ((tree *, tree, tree, int, 
bool *));
extern int amigaos_comp_type_attributes PARAMS ((tree, tree));
#endif
# Makefile fragment for AmigaOS target.

# Extra object file linked to the cc1* executables.
amigaos.o: $(srcdir)/config/m68k/amigaos.c $(CONFIG_H)
        $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< $(OUTPUT_OPTION)

# Additional target dependent options for compiling libgcc.a.  This just
# ensures that we don't compile libgcc* with anything other than a
# fixed stack.

TARGET_LIBGCC2_CFLAGS = -mfixedstack

# Support for building multiple version of libgcc.

LIBGCC_MULTI =  .; \
                libb;@fbaserel \
                libm020;@m68020 \
                libb/libm020;@fbaserel@m68020 \
                libb32/libm020;@fbaserel32@m68020

### begin-GG-local: dynamic libraries
# Extra objects that get compiled and linked to collect2

EXTRA_COLLECT2_OBJS = amigacollect2.o

# Build supplimentary AmigaOS target support file for collect2
amigacollect2.o: amigacollect2.c
        $(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
        -DA2IXDIR_PREFIX=\"$(prefix)/share/a2ixlibrary\" $< $(OUTPUT_OPTION)
### end-GG-local

Other related posts: