summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/arm/gba/startup/linkcmds
blob: 6f54c13efcd65a6cb7f11eb3434faa66e09aa20c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/**
 *  @file linkcmds
 *
 *  GBA BSP linker script
 */
/*
 *  RTEMS GBA BSP
 *
 *  Copyright (c) Jeff Frohwein
 *
 *  Copyright (c) 2003  Jason Wilkins
 *
 *  Copyright (c) 2004  Markku Puro <markku.puro@kopteri.net>
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */

/*****************************************************************************
 * This Linker Script is based on work by Jeff Frohwein and Jason Wilkins
 *****************************************************************************
 * Linker Script v1.3 by Jeff Frohwein
 * :
 * This file is released into the public domain
 * for commercial or non-commercial use with no
 * restrictions placed upon it.
 *****************************************************************************
 * Copyright 2003, Jason Wilkins.  This source code is free for any use except
 * that this copyright notice and the following disclaimers remain intact when
 * the source is distributed.  There are absolutely no restrictions on use of
 * object code generated from this source, but the disclaimers remain in force.
 *
 * THIS CODE WAS NOT MADE IN ASSOCIATION WITH NINTENDO AND DOES NOT MAKE USE OF
 * ANY INTELLECTUAL PROPERTY CLAIMED BY NINTENDO.
 *
 * GAMEBOY ADVANCE IS A TRADEMARK OF NINTENDO.
 *
 * THIS CODE HAS BEEN PROVIDED "AS-IS" WITHOUT A WARRANTY OF ANY KIND, EITHER
 * EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO IMPLIED WARRANTIES OF
 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  THE ENTIRE RISK AS TO THE
 * QUALITY OR PERFORMANCE OF THE CODE IS WITH YOU.
 *
 * IN NO EVENT, UNLESS AGREED TO IN WRITING, WILL ANY COPYRIGHT HOLDER, OR ANY
 * OTHER PARTY, BE HELD LIABLE FOR ANY DAMAGES RESULTING FROM THE USE OR
 * INABILITY TO USE THIS CODE.
 *
 *****************************************************************************/
/* @cond  INCLUDE_ASM */

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)

/*************************************************************************
  The linker script MEMORY directive is not used here due to the fact
  that  __ro_start is not always a fixed value.
 *************************************************************************
MEMORY
{
  rom       : ORIGIN = 0x08000000 , LENGTH = 96M
  iwram     : ORIGIN = 0x03000000 , LENGTH = 32K
  ewram     : ORIGIN = 0x02000000 , LENGTH = 256K
  sram      : ORIGIN = 0x0E000000 , LENGTH = 64K
}
 *************************************************************************/
__gba_ewram_start = 0x02000000;
__gba_ewram_end   = 0x02040000;
__gba_iwram_start = 0x03000000;
__gba_iwram_end   = 0x03008000;
__gba_rom_start   = 0x08000000;
__gba_rom_end     = 0x0E000000;
__gba_sram_start  = 0x0E000000;
__gba_sram_end    = 0x0E010000;

__sp_irq_size     = 0x2A0;
_stack_size       = 0xA00;
__irq_vector      = __gba_iwram_end - 0x0004; /* 0x03007FFC */
__sp_svc          = __gba_iwram_end - 0x0020; /* 0x03007FE0 */
__sp_irq          = __gba_iwram_end - 0x0060; /* 0x03007FA0 */
__sp_usr          = __sp_irq - __sp_irq_size; /* 0x03007D00 */
__sp_limit        = __sp_usr - _stack_size;   /* 0x03007300 */
__heap_limit      = DEFINED(__gba_multiboot) ? __gba_ewram_end : ( DEFINED(__gba_iwram_bss) ? __sp_limit :  __gba_ewram_end ) ;


SECTIONS
{
/*** read-only sections ***/
/*************************************************************************
  if 'multiboot' allocate prog in __gba_ewram_start (0x02000000-0x0207FFFF)
  else allocate prog in __gba_rom_start (0x08000000-0x0DFFFFFF)
 *************************************************************************/
  __ro_start = DEFINED(__gba_multiboot) ? __gba_ewram_start : __gba_rom_start ;
  PROVIDE(__text_start__ = __ro_start );
  .text  __ro_start :
  {
    CREATE_OBJECT_SYMBOLS
    */start.o(.text)
    *(EXCLUDE_FILE(*.rodata.* *.ewram.o *.iwram.o) .text)
    *(.stub .text.* .gnu.linkonce.t*)

    /*
     * Special FreeBSD sysctl sections.
     */
    . = ALIGN (16);
    __start_set_sysctl_set = .;
    *(set_sysctl_*);
    __stop_set_sysctl_set = ABSOLUTE(.);
    *(set_domain_*);
    *(set_pseudo_*);

    /* .gnu.warning sections are handled specially by elf32.em. */
    *(.gnu.warning)
    *(.glue_7)
    *(.glue_7t)
    . = ALIGN(4);
  } =0xFF

  .init :
  {
    *(.init)
    . = ALIGN(4);
  } =0xFF

  .fini :
  {
    *(.fini)
    . = ALIGN(4);
  } =0xFF

  __rodata_start = . ;
  .rodata :
  {
    *(.rodata1)
    *(EXCLUDE_FILE(*.rodata.* *.ewram.o *.iwram.o) .rodata)
    *(.rodata.* .gnu.linkonce.r*)
    *(.roda) /* deprecated: for compatibility with objcopyroda */
    SORT(CONSTRUCTORS)
    . = ALIGN(4);
  } =0xFF
  __rodata_end = . ;

  .eh_frame :
  {
    KEEP(*(.eh_frame))
    . = ALIGN(4);
  } =0xFF

  .gcc_except_table :
  {
    *(.gcc_except_table*)
    . = ALIGN(4);
  } =0xFF

  .ctors :
  {
    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is first.
       Because this is a wildcard, it doesn't matter
       if the user does not actually link against crtbegin.o;
       the linker won't look for a file to match a wildcard.
       The wildcard also means that it doesn't matter which
       directory crtbegin.o is in.
     */
    KEEP(*crtbegin.o(.ctors))
    /* We don't want to include the .ctor section from
       the crtend.o file until after the sorted ctors.
       The .ctor section from the crtend file contains the
       end of ctors marker and it must be last
     */
     KEEP(*(EXCLUDE_FILE (*crtend.o) .ctors))
     KEEP(*(SORT(.ctors.*)))
     KEEP(*(.ctors))
    . = ALIGN(4);
  } =0xFF

  .dtors :
  {
    KEEP(*crtbegin.o(.dtors))
    KEEP(*(EXCLUDE_FILE (*crtend.o ) .dtors))
    KEEP(*(SORT(.dtors.*)))
    KEEP(*(.dtors))
    . = ALIGN(4);
  } =0xFF

  .jcr :
  {
    *(.jcr)
    . = ALIGN(4);
  } =0xFF

  .ARM.extab : {
    *(.ARM.extab* .gnu.linkonce.armextab.*)
  } =0xff
   __exidx_start = .;
  .ARM.exidx : {
    *(.ARM.exidx* .gnu.linkonce.armexidx.*)
  } =0xff
   __exidx_end = .;
  .preinit_array : {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  } =0xFF
  .init_array : {
     PROVIDE_HIDDEN (__init_array_start = .);
     KEEP (*(SORT(.init_array.*)))
     KEEP (*(.init_array))
     PROVIDE_HIDDEN (__init_array_end = .);
  } =0xFF
  .fini_array : {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(.fini_array))
    KEEP (*(SORT(.fini_array.*)))
    PROVIDE_HIDDEN (__fini_array_end = .);
  } =0xFF

/*************************************************************************
  calculate __ro_end
 *************************************************************************/
  __ro_end =
	ADDR(.text) +
	SIZEOF(.text) +
	SIZEOF(.init) +
	SIZEOF(.fini) +
	SIZEOF(.rodata) +
	SIZEOF(.eh_frame) +
	SIZEOF(.gcc_except_table) +
	SIZEOF(.ctors) +
	SIZEOF(.dtors) +
	SIZEOF(.jcr) +
	SIZEOF(.ARM.extab) +
	SIZEOF(.ARM.exidx) +
	SIZEOF(.preinit_array) +
	SIZEOF(.init_array) +
	SIZEOF(.fini_array);
  PROVIDE(__text_end__ = __ro_end );

/*** IWRAM ***/
/*************************************************************************
  allocate iwram in __gba_iwram_start (0x03000000-0x03003FFF)
 *************************************************************************/
  __load_start_iwram = __ro_end;
  . = __gba_iwram_start ;
  __iwram_start = . ;
  PROVIDE(__iwram_start__ = . );
  .iwram : AT(__load_start_iwram)
  {
    /* put irq_vector_table in stat of iwram  */
    CREATE_OBJECT_SYMBOLS
    _irq_vector_table = .;
    PROVIDE(irq_vector_table = .);
    . += 4;
    . = ALIGN(16 * 4);
    PROVIDE(irq_vector_table_end = .);
    _irq_vector_table_end = .;
    *(.iwram .iwram.*)
    *.iwram.o (.text .rodata .data)
    . = ALIGN(4);
  } =0xFF
  __iwram_end = . ;
  PROVIDE(__iwram_end__ = . );
  __load_stop_iwram = __load_start_iwram + SIZEOF(.iwram);

 _irq_vector_table_size = _irq_vector_table_end - _irq_vector_table;
 PROVIDE(_irq_max_vector = _irq_vector_table_size / 4 );


/*** EWRAM ***/
/*************************************************************************
  if 'multiboot' allocate prog+ewram in __gba_ewram
  else allocate only ewram in __gba_ewram_start
 *************************************************************************/
  . = DEFINED(__gba_multiboot) ? __load_stop_iwram : __gba_ewram_start ;
  __load_start_ewram = __load_stop_iwram;
  __ewram_start = . ;
  PROVIDE(__ewram_start__ = . );
  .ewram : AT(__load_start_ewram)
  {
    *(.ewram .ewram.*)
    *.ewram.o (.text .rodata .data)
    . = ALIGN(4);
  } =0xFF
  __ewram_end = . ;
  PROVIDE(__ewram_end__ = . );
  __load_stop_ewram = __load_start_ewram + SIZEOF(.ewram) ;

/*************************************************************************
    if 'multiboot' allocate prog+ewram+data+bss in __gba_ewram
    else if 'iwram_data' allocate data in __gba_iwram
    else allocate data in __gba_ewram
 *************************************************************************/
  . = DEFINED(__gba_multiboot) ? __load_stop_ewram : (DEFINED(__gba_iwram_data) ? __iwram_end : __ewram_end) ;
  __load_start_data = __load_stop_ewram;
  __data_start = . ;
  PROVIDE(__data_start__ = . );
  .data : AT(__load_start_data)
  {
    *(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
    *(EXCLUDE_FILE(*.rodata.* *.ewram.o *.iwram.o) .data)
    *(.data.* .gnu.linkonce.d.*)
    *(.data1)
    *(.tdata .tdata.* .gnu.linkonce.td.*)
    *(.sdata .sdata.* .gnu.linkonce.s.*)
    . = ALIGN(4);
  } =0xFF
  __data_end = . ;
  PROVIDE(__data_end__ = . );
  __load_stop_data = __load_start_data + SIZEOF(.data);

/*** BSS ***/
/*************************************************************************
    if 'multiboot' allocate prog+ewram+data+bss in __gba_ewram
    else if 'iwram_data' and 'iwram_bss' allocate iwram+data+bss in __gba_iwram
    else if !'iwram_data' and 'iwram_bss' allocate iwram+bss in __gba_iwram
    else allocate data+ewram+bss in  __gba_ewram
 *************************************************************************/
  . = DEFINED(__gba_multiboot) ? __load_stop_data : ( DEFINED(__gba_iwram_data) ? (DEFINED(__gba_iwram_bss) ? __data_end :  __ewram_end) : (DEFINED(__gba_iwram_bss) ? __iwram_end : __data_end) ) ;
  __bss_start = . ;
  PROVIDE(__bss_start__ = . );
  .bss :
  {
    *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)
    *(.tbss .tbss.* .gnu.linkonce.tb.*)
    *(.tcommon)
    *(.sbss .sbss.* .gnu.linkonce.sb.*)
    *(.scommon)
    *(.bss .bss.* .gnu.linkonce.b*)
    *(COMMON)
    . = ALIGN(4);
  }
  __bss_end = . ;
  PROVIDE(__bss_end__ = . );
  PROVIDE(_bss_end__ = . );

  PROVIDE(_end = . );
  PROVIDE(__end__ = _end);
  PROVIDE(end = _end);


/*** debugging info ***/
  /* Stabs debugging sections.  */
  .stab 0 : { *(.stab) }
  .stabstr 0 : { *(.stabstr) }
  .stab.excl 0 : { *(.stab.excl) }
  .stab.exclstr 0 : { *(.stab.exclstr) }
  .stab.index 0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  /* DWARF debug sections.
   Symbols in the DWARF debugging sections are relative to the beginning
   of the section so we begin them at 0.  */
  /* DWARF 1 */
  .debug          0 : { *(.debug) }
  .line           0 : { *(.line) }
  /* GNU DWARF 1 extensions */
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
  .debug_sfnames  0 : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2 */
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  /* DWARF 2 */
  .debug_info     0 : { *(.debug_info) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
  .comment        0 : { *(.comment) }
  /* SGI/MIPS DWARF 2 extensions */
  .debug_weaknames 0 : { *(.debug_weaknames) }
  .debug_funcnames 0 : { *(.debug_funcnames) }
  .debug_typenames 0 : { *(.debug_typenames) }
  .debug_varnames  0 : { *(.debug_varnames) }
  /* DWARF 3 */
  .debug_pubtypes 0 : { *(.debug_pubtypes) }
  .debug_ranges   0 : { *(.debug_ranges) }
  .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }
  .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
  /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}
/* @endcond */