OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [ld/] [emultempl/] [open8elf.em] - Blame information for rev 231

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 khays
# This shell script emits a C file. -*- C -*-
2
#   Copyright 2006, 2007, 2008, 2009, 2011
3
#   Free Software Foundation, Inc.
4
#
5
# This file is part of the GNU Binutils.
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
# MA 02110-1301, USA.
21
 
22
 
23
# This file is sourced from elf32.em, and defines extra open8-elf specific
24
# routines.
25
 
26
fragment <
27
 
28
#include "elf32-open8.h"
29
#include "ldctor.h"
30
 
31
/* The fake file and it's corresponding section meant to hold
32
   the linker stubs if needed.  */
33
 
34
static lang_input_statement_type *stub_file;
35
static asection *open8_stub_section;
36
 
37
/* Variables set by the command-line parameters and transfered
38
   to the bfd without use of global shared variables.  */
39
 
40
static bfd_boolean open8_no_stubs = FALSE;
41
static bfd_boolean open8_debug_relax = FALSE;
42
static bfd_boolean open8_debug_stubs = FALSE;
43
static bfd_boolean open8_replace_call_ret_sequences = TRUE;
44
static bfd_vma open8_pc_wrap_around = 0x10000000;
45
 
46
/* Transfers information to the bfd frontend.  */
47
 
48
static void
49
open8_elf_set_global_bfd_parameters (void)
50
{
51
  elf32_open8_setup_params (& link_info,
52
                          stub_file->the_bfd,
53
                          open8_stub_section,
54
                          open8_no_stubs,
55
                          open8_debug_stubs,
56
                          open8_debug_relax,
57
                          open8_pc_wrap_around,
58
                          open8_replace_call_ret_sequences);
59
}
60
 
61
 
62
/* Makes a conservative estimate of the trampoline section size that could
63
   be corrected later on.  */
64
 
65
static void
66
open8_elf_${EMULATION_NAME}_before_allocation (void)
67
{
68
  int ret;
69
 
70
  gld${EMULATION_NAME}_before_allocation ();
71
 
72
  /* No stubs support for the Open8 at this time.  */
73
  open8_no_stubs = TRUE;
74
 
75
  open8_elf_set_global_bfd_parameters ();
76
 
77
  /* If generating a relocatable output file, then
78
     we don't  have to generate the trampolines.  */
79
  if (link_info.relocatable)
80
    open8_no_stubs = TRUE;
81
 
82
  if (open8_no_stubs)
83
    return;
84
 
85
  ret = elf32_open8_setup_section_lists (link_info.output_bfd, &link_info);
86
 
87
  if (ret < 0)
88
    einfo ("%X%P: can not setup the input section list: %E\n");
89
 
90
  if (ret <= 0)
91
    return;
92
 
93
  /* Call into the BFD backend to do the real "stub"-work.  */
94
  if (! elf32_open8_size_stubs (link_info.output_bfd, &link_info, TRUE))
95
    einfo ("%X%P: can not size stub section: %E\n");
96
}
97
 
98
/* This is called before the input files are opened.  We create a new
99
   fake input file to hold the stub section and generate the section itself.  */
100
 
101
static void
102
open8_elf_create_output_section_statements (void)
103
{
104
  flagword flags;
105
 
106
  stub_file = lang_add_input_file ("linker stubs",
107
                                   lang_input_file_is_fake_enum,
108
                                   NULL);
109
 
110
  stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd);
111
  if (stub_file->the_bfd == NULL
112
      || !bfd_set_arch_mach (stub_file->the_bfd,
113
                             bfd_get_arch (link_info.output_bfd),
114
                             bfd_get_mach (link_info.output_bfd)))
115
    {
116
      einfo ("%X%P: can not create stub BFD %E\n");
117
      return;
118
    }
119
 
120
  /* Now we add the stub section.  */
121
 
122
  flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
123
           | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
124
  open8_stub_section = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
125
                                                         ".trampolines",
126
                                                         flags);
127
  if (open8_stub_section == NULL)
128
    goto err_ret;
129
 
130
  open8_stub_section->alignment_power = 1;
131
 
132
  ldlang_add_file (stub_file);
133
 
134
  return;
135
 
136
  err_ret:
137
   einfo ("%X%P: can not make stub section: %E\n");
138
   return;
139
}
140
 
141
/* Re-calculates the size of the stubs so that we won't waste space.  */
142
 
143
static void
144
open8_elf_after_allocation (void)
145
{
146
  if (!open8_no_stubs && ! RELAXATION_ENABLED)
147
    {
148
      /* If relaxing, elf32_open8_size_stubs will be called from
149
         elf32_open8_relax_section.  */
150
      if (!elf32_open8_size_stubs (link_info.output_bfd, &link_info, FALSE))
151
        einfo ("%X%P: can not size stub section: %E\n");
152
    }
153
 
154
  gld${EMULATION_NAME}_after_allocation ();
155
 
156
  /* Now build the linker stubs.  */
157
  if (!open8_no_stubs)
158
    {
159
      if (!elf32_open8_build_stubs (&link_info))
160
        einfo ("%X%P: can not build stubs: %E\n");
161
    }
162
}
163
 
164
 
165
EOF
166
 
167
 
168
PARSE_AND_LIST_PROLOGUE='
169
 
170
#define OPTION_NO_CALL_RET_REPLACEMENT 301
171
#define OPTION_PMEM_WRAP_AROUND        302
172
#define OPTION_NO_STUBS                303
173
#define OPTION_DEBUG_STUBS             304
174
#define OPTION_DEBUG_RELAX             305
175
'
176
 
177
PARSE_AND_LIST_LONGOPTS='
178
  { "no-call-ret-replacement", no_argument,
179
     NULL, OPTION_NO_CALL_RET_REPLACEMENT},
180
  { "pmem-wrap-around", required_argument,
181
    NULL, OPTION_PMEM_WRAP_AROUND},
182
  { "no-stubs", no_argument,
183
    NULL, OPTION_NO_STUBS},
184
  { "debug-stubs", no_argument,
185
    NULL, OPTION_DEBUG_STUBS},
186
  { "debug-relax", no_argument,
187
    NULL, OPTION_DEBUG_RELAX},
188
'
189
 
190
PARSE_AND_LIST_OPTIONS='
191
  fprintf (file, _("  --no-call-ret-replacement   "
192
                   "The relaxation machine normally will\n"
193
                   "                              "
194
                   "  substitute two immediately following call/ret\n"
195
                   "                              "
196
                   "  instructions by a single jump instruction.\n"
197
                   "                              "
198
                   "  This option disables this optimization.\n"));
199
  fprintf (file, _("  --debug-stubs               "
200
                   "Used for debugging open8-ld.\n"));
201
  fprintf (file, _("  --debug-relax               "
202
                   "Used for debugging open8-ld.\n"));
203
'
204
 
205
PARSE_AND_LIST_ARGS_CASES='
206
 
207
    case OPTION_PMEM_WRAP_AROUND:
208
      {
209
        /* This variable is defined in the bfd library.  */
210
        if ((!strcmp (optarg,"32k"))      || (!strcmp (optarg,"32K")))
211
          open8_pc_wrap_around = 32768;
212
        else if ((!strcmp (optarg,"8k")) || (!strcmp (optarg,"8K")))
213
          open8_pc_wrap_around = 8192;
214
        else if ((!strcmp (optarg,"16k")) || (!strcmp (optarg,"16K")))
215
          open8_pc_wrap_around = 16384;
216
        else if ((!strcmp (optarg,"64k")) || (!strcmp (optarg,"64K")))
217
          open8_pc_wrap_around = 0x10000;
218
        else
219
          return FALSE;
220
      }
221
      break;
222
 
223
    case OPTION_DEBUG_STUBS:
224
      open8_debug_stubs = TRUE;
225
      break;
226
 
227
    case OPTION_DEBUG_RELAX:
228
      open8_debug_relax = TRUE;
229
      break;
230
 
231
    case OPTION_NO_STUBS:
232
      open8_no_stubs = TRUE;
233
      break;
234
 
235
    case OPTION_NO_CALL_RET_REPLACEMENT:
236
      {
237
        /* This variable is defined in the bfd library.  */
238
        open8_replace_call_ret_sequences = FALSE;
239
      }
240
      break;
241
'
242
 
243
#
244
# Put these extra open8-elf routines in ld_${EMULATION_NAME}_emulation
245
#
246
LDEMUL_BEFORE_ALLOCATION=open8_elf_${EMULATION_NAME}_before_allocation
247
LDEMUL_AFTER_ALLOCATION=open8_elf_after_allocation
248
LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=\
249
open8_elf_create_output_section_statements

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.