zig-riscv-embedded

Experimental Zig-based CoAP node for the HiFive1 RISC-V board

git clone https://git.8pit.net/zig-riscv-embedded.git

  1/*
  2 * Copyright (C) 2017, 2019   Ken Rabold
  3 *
  4 * This file is subject to the terms and conditions of the GNU Lesser
  5 * General Public License v2.1. See the file LICENSE in the top level
  6 * directory for more details.
  7 */
  8
  9OUTPUT_ARCH( "riscv" )
 10
 11ENTRY( _start )
 12
 13PHDRS
 14{
 15  flash PT_LOAD;
 16  ram_init PT_LOAD;
 17  ram PT_NULL;
 18}
 19
 20MEMORY
 21{
 22  flash (rx)  : ORIGIN = 0x20400000, LENGTH = 0x1fc00000
 23  ram   (rwx) : ORIGIN = 0x80000000, LENGTH = 0x00004000
 24  itim  (rwx) : ORIGIN = 0x08000000, LENGTH = 0x00002000
 25}
 26
 27SECTIONS
 28{
 29  __stack_size     = DEFINED(__stack_size) ? __stack_size : 256;
 30
 31  .init           :
 32  {
 33    KEEP (*(SORT_NONE(.init)))
 34  } >flash AT>flash :flash
 35
 36  .text           :
 37  {
 38    *(.text.unlikely .text.unlikely.*)
 39    *(.text.startup .text.startup.*)
 40    *(.text .text.*)
 41    *(.gnu.linkonce.t.*)
 42
 43    KEEP(*(.eh_frame*))
 44  } >flash AT>flash :flash
 45
 46  .fini           :
 47  {
 48    KEEP (*(SORT_NONE(.fini)))
 49  } >flash AT>flash :flash
 50
 51  PROVIDE (__etext = .);
 52  PROVIDE (_etext = .);
 53  PROVIDE (etext = .);
 54
 55  .rodata         :
 56  {
 57    *(.rdata)
 58    *(.rodata .rodata.*)
 59    *(.gnu.linkonce.r.*)
 60  } >flash AT>flash :flash
 61
 62  . = ALIGN(4);
 63
 64  .preinit_array  :
 65  {
 66    PROVIDE_HIDDEN (__preinit_array_start = .);
 67    KEEP (*(.preinit_array))
 68    PROVIDE_HIDDEN (__preinit_array_end = .);
 69  } >flash AT>flash :flash
 70
 71  .init_array     :
 72  {
 73    PROVIDE_HIDDEN (__init_array_start = .);
 74    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
 75    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
 76    PROVIDE_HIDDEN (__init_array_end = .);
 77  } >flash AT>flash :flash
 78
 79  .fini_array     :
 80  {
 81    PROVIDE_HIDDEN (__fini_array_start = .);
 82    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
 83    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
 84    PROVIDE_HIDDEN (__fini_array_end = .);
 85  } >flash AT>flash :flash
 86
 87  .ctors          :
 88  {
 89    /* gcc uses crtbegin.o to find the start of
 90       the constructors, so we make sure it is
 91       first.  Because this is a wildcard, it
 92       doesn't matter if the user does not
 93       actually link against crtbegin.o; the
 94       linker won't look for a file to match a
 95       wildcard.  The wildcard also means that it
 96       doesn't matter which directory crtbegin.o
 97       is in.  */
 98    KEEP (*crtbegin.o(.ctors))
 99    KEEP (*crtbegin?.o(.ctors))
100    /* We don't want to include the .ctor section from
101       the crtend.o file until after the sorted ctors.
102       The .ctor section from the crtend file contains the
103       end of ctors marker and it must be last */
104    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
105    KEEP (*(SORT(.ctors.*)))
106    KEEP (*(.ctors))
107  } >flash AT>flash :flash
108
109  .dtors          :
110  {
111    KEEP (*crtbegin.o(.dtors))
112    KEEP (*crtbegin?.o(.dtors))
113    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
114    KEEP (*(SORT(.dtors.*)))
115    KEEP (*(.dtors))
116  } >flash AT>flash :flash
117
118  .lalign         :
119  {
120    . = ALIGN(4);
121    PROVIDE( _data_lma = . );
122  } >flash AT>flash :flash
123
124  .dalign         :
125  {
126    . = ALIGN(4);
127    PROVIDE( _data = . );
128  } >ram AT>flash :ram_init
129
130  .data          :
131  {
132    *(.ramfunc .ramfunc.*)
133    *(.data .data.*)
134    *(.gnu.linkonce.d.*)
135    . = ALIGN(8);
136    PROVIDE( __global_pointer$ = . + 0x800 );
137    *(.sdata .sdata.*)
138    *(.gnu.linkonce.s.*)
139    . = ALIGN(8);
140    *(.srodata.cst16)
141    *(.srodata.cst8)
142    *(.srodata.cst4)
143    *(.srodata.cst2)
144    *(.srodata .srodata.*)
145  } >ram AT>flash :ram_init
146
147  . = ALIGN(4);
148  PROVIDE( _edata = . );
149  PROVIDE( edata = . );
150
151  PROVIDE( _fbss = . );
152  PROVIDE( __bss_start = . );
153  .bss            :
154  {
155    *(.sbss*)
156    *(.gnu.linkonce.sb.*)
157    *(.bss .bss.*)
158    *(.gnu.linkonce.b.*)
159    *(COMMON)
160    . = ALIGN(4);
161  } >ram AT>ram :ram
162
163  . = ALIGN(8);
164  PROVIDE( _end = . );
165  PROVIDE( end = . );
166  PROVIDE( _heap_start = . );
167
168  __StackTop = ORIGIN(ram) + LENGTH(ram);
169  __StackLimit = __StackTop - __stack_size;
170  PROVIDE(__stack = __StackTop);
171}