|
| 1 | +ENTRY( InterruptVector ) |
| 2 | + |
| 3 | +/* Run from RAM example, small RAM footprint so should run on any CH32V's */ |
| 4 | + |
| 5 | +MEMORY |
| 6 | +{ |
| 7 | +#if TARGET_MCU_LD == 0 /* v003 */ |
| 8 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 2K |
| 9 | +#elif TARGET_MCU_LD == 1 /* v10x */ |
| 10 | + #if MCU_PACKAGE == 1 |
| 11 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K |
| 12 | + #elif MCU_PACKAGE == 2 |
| 13 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K |
| 14 | + #else |
| 15 | + #error "Unknown MCU package" |
| 16 | + #endif |
| 17 | +#elif TARGET_MCU_LD == 2 /* v20x */ |
| 18 | + #if MCU_PACKAGE == 1 |
| 19 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K |
| 20 | + #elif MCU_PACKAGE == 2 |
| 21 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 10K |
| 22 | + #elif MCU_PACKAGE == 3 |
| 23 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K |
| 24 | + #else |
| 25 | + #error "Unknown MCU package" |
| 26 | + #endif |
| 27 | +#elif TARGET_MCU_LD == 3 /* v30x */ |
| 28 | + #if MCU_PACKAGE == 1 |
| 29 | + #if TARGET_MCU_MEMORY_SPLIT == 1 |
| 30 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K |
| 31 | + #elif TARGET_MCU_MEMORY_SPLIT == 2 |
| 32 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 64K |
| 33 | + #elif TARGET_MCU_MEMORY_SPLIT == 3 |
| 34 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K |
| 35 | + #else |
| 36 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K |
| 37 | + #endif |
| 38 | + #elif MCU_PACKAGE == 2 |
| 39 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K |
| 40 | + #else |
| 41 | + #error "Unknown MCU package" |
| 42 | + #endif |
| 43 | +#elif TARGET_MCU_LD == 4 /* x03x */ |
| 44 | + #if MCU_PACKAGE == 1 |
| 45 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K |
| 46 | + #else |
| 47 | + #error "Unknown MCU package" |
| 48 | + #endif |
| 49 | +#elif TARGET_MCU_LD == 5 |
| 50 | + /* CH32V002 */ |
| 51 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 4K |
| 52 | +#elif TARGET_MCU_LD == 6 |
| 53 | + /* CH32V005, CH32V004 */ |
| 54 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 6K |
| 55 | +#elif TARGET_MCU_LD == 7 |
| 56 | + /* CH32V006, CH32V007 */ |
| 57 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 8K |
| 58 | +#elif TARGET_MCU_LD == 8 |
| 59 | + /* CH582/3/4/5 */ |
| 60 | + #if MCU_PACKAGE == 2 || MCU_PACKAGE == 3 |
| 61 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K |
| 62 | + #elif MCU_PACKAGE == 4 |
| 63 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 96K |
| 64 | + #elif MCU_PACKAGE == 5 |
| 65 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 128K |
| 66 | + #else |
| 67 | + #error "Unknown MCU package" |
| 68 | + #endif |
| 69 | +#elif TARGET_MCU_LD == 9 |
| 70 | + /* CH591/2 */ |
| 71 | + #if MCU_PACKAGE == 1 |
| 72 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 26K |
| 73 | + #elif MCU_PACKAGE == 2 |
| 74 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 26K |
| 75 | + #else |
| 76 | + #error "Unknown MCU package" |
| 77 | + #endif |
| 78 | +#elif TARGET_MCU_LD == 10 |
| 79 | + /* CH57x */ |
| 80 | + #if MCU_PACKAGE == 0 || MCU_PACKAGE == 2 |
| 81 | + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 12K |
| 82 | + #elif MCU_PACKAGE == 1 |
| 83 | + RAM (xrw) : ORIGIN = 0x20003800, LENGTH = 18K |
| 84 | + #elif MCU_PACKAGE == 3 |
| 85 | + RAM (xrw) : ORIGIN = 0x20003800, LENGTH = 18K |
| 86 | + #else |
| 87 | + #error "Unknown MCU package" |
| 88 | + #endif |
| 89 | +#elif TARGET_MCU_LD == 11 |
| 90 | + /* CH32H41x */ |
| 91 | + #if MCU_PACKAGE == 1 || MCU_PACKAGE == 3 |
| 92 | + RAM (xrw) : ORIGIN = 0x20100000, LENGTH = 512K |
| 93 | + #elif MCU_PACKAGE == 2 |
| 94 | + RAM (xrw) : ORIGIN = 0x20100000, LENGTH = 512K |
| 95 | + #else |
| 96 | + #error "Unknown MCU package" |
| 97 | + #endif |
| 98 | +#else |
| 99 | + #error "Unknown MCU target" |
| 100 | +#endif |
| 101 | +} |
| 102 | + |
| 103 | +SECTIONS |
| 104 | +{ |
| 105 | + .init : |
| 106 | + { |
| 107 | + _sinit = .; |
| 108 | + . = ALIGN(4); |
| 109 | + KEEP(*(SORT_NONE(.init))) |
| 110 | + . = ALIGN(4); |
| 111 | + _einit = .; |
| 112 | + } >RAM AT>RAM |
| 113 | + |
| 114 | +#if TARGET_MCU_LD == 8 || TARGET_MCU_LD == 9 || TARGET_MCU_LD == 10 |
| 115 | + .highcodelalign : |
| 116 | + { |
| 117 | + . = ALIGN(4); |
| 118 | + PROVIDE(_highcode_lma = .); |
| 119 | + } >RAM AT>RAM |
| 120 | + |
| 121 | + .highcode : |
| 122 | + { |
| 123 | + . = ALIGN(4); |
| 124 | + PROVIDE(_highcode_vma_start = .); |
| 125 | + *(.highcode*) |
| 126 | + . = ALIGN(4); |
| 127 | + PROVIDE(_highcode_vma_end = .); |
| 128 | + } >RAM AT>RAM |
| 129 | + |
| 130 | + .data : |
| 131 | + { |
| 132 | + . = ALIGN(4); |
| 133 | + __global_pointer$ = . + 0x7f8; |
| 134 | + *(.gnu.linkonce.r.*) |
| 135 | + *(.data .data.*) |
| 136 | + *(.gnu.linkonce.d.*) |
| 137 | + . = ALIGN(4); |
| 138 | + *(.sdata .sdata.*) |
| 139 | + *(.sdata2*) |
| 140 | + *(.gnu.linkonce.s.*) |
| 141 | + . = ALIGN(4); |
| 142 | + *(.srodata.cst16) |
| 143 | + *(.srodata.cst8) |
| 144 | + *(.srodata.cst4) |
| 145 | + *(.srodata.cst2) |
| 146 | + *(.srodata .srodata.*) |
| 147 | + . = ALIGN(4); |
| 148 | + PROVIDE( _edata = .); |
| 149 | + } >RAM AT>RAM |
| 150 | +#endif |
| 151 | + |
| 152 | + .text : |
| 153 | + { |
| 154 | + . = ALIGN(4); |
| 155 | + *(.text) |
| 156 | + *(.text.*) |
| 157 | + *(.rodata) |
| 158 | + *(.rodata*) |
| 159 | + *(.gnu.linkonce.t.*) |
| 160 | + . = ALIGN(4); |
| 161 | + } >RAM AT>RAM |
| 162 | + |
| 163 | + .fini : |
| 164 | + { |
| 165 | + KEEP(*(SORT_NONE(.fini))) |
| 166 | + . = ALIGN(4); |
| 167 | + } >RAM AT>RAM |
| 168 | + |
| 169 | + PROVIDE( _etext = . ); |
| 170 | + PROVIDE( _eitcm = . ); |
| 171 | + |
| 172 | + .preinit_array : |
| 173 | + { |
| 174 | + PROVIDE_HIDDEN (__preinit_array_start = .); |
| 175 | + KEEP (*(.preinit_array)) |
| 176 | + PROVIDE_HIDDEN (__preinit_array_end = .); |
| 177 | + } >RAM AT>RAM |
| 178 | + |
| 179 | + .init_array : |
| 180 | + { |
| 181 | + PROVIDE_HIDDEN (__init_array_start = .); |
| 182 | + KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) |
| 183 | + KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) |
| 184 | + PROVIDE_HIDDEN (__init_array_end = .); |
| 185 | + } >RAM AT>RAM |
| 186 | + |
| 187 | + .fini_array : |
| 188 | + { |
| 189 | + PROVIDE_HIDDEN (__fini_array_start = .); |
| 190 | + KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) |
| 191 | + KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) |
| 192 | + PROVIDE_HIDDEN (__fini_array_end = .); |
| 193 | + } >RAM AT>RAM |
| 194 | + |
| 195 | + .ctors : |
| 196 | + { |
| 197 | + /* gcc uses crtbegin.o to find the start of |
| 198 | + the constructors, so we make sure it is |
| 199 | + first. Because this is a wildcard, it |
| 200 | + doesn't matter if the user does not |
| 201 | + actually link against crtbegin.o; the |
| 202 | + linker won't look for a file to match a |
| 203 | + wildcard. The wildcard also means that it |
| 204 | + doesn't matter which directory crtbegin.o |
| 205 | + is in. */ |
| 206 | + KEEP (*crtbegin.o(.ctors)) |
| 207 | + KEEP (*crtbegin?.o(.ctors)) |
| 208 | + /* We don't want to include the .ctor section from |
| 209 | + the crtend.o file until after the sorted ctors. |
| 210 | + The .ctor section from the crtend file contains the |
| 211 | + end of ctors marker and it must be last */ |
| 212 | + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) |
| 213 | + KEEP (*(SORT(.ctors.*))) |
| 214 | + KEEP (*(.ctors)) |
| 215 | + } >RAM AT>RAM |
| 216 | + |
| 217 | + .dtors : |
| 218 | + { |
| 219 | + KEEP (*crtbegin.o(.dtors)) |
| 220 | + KEEP (*crtbegin?.o(.dtors)) |
| 221 | + KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) |
| 222 | + KEEP (*(SORT(.dtors.*))) |
| 223 | + KEEP (*(.dtors)) |
| 224 | + } >RAM AT>RAM |
| 225 | + |
| 226 | + .dalign : |
| 227 | + { |
| 228 | + . = ALIGN(4); |
| 229 | + PROVIDE(_data_vma = .); |
| 230 | + } >RAM AT>RAM |
| 231 | + |
| 232 | + .dlalign : |
| 233 | + { |
| 234 | + . = ALIGN(4); |
| 235 | + PROVIDE(_data_lma = .); |
| 236 | + } >RAM AT>RAM |
| 237 | +#if TARGET_MCU_LD != 8 && TARGET_MCU_LD != 9 && TARGET_MCU_LD != 10 |
| 238 | + .data : |
| 239 | + { |
| 240 | + . = ALIGN(4); |
| 241 | + __global_pointer$ = . + 0x7f8; |
| 242 | + *(.gnu.linkonce.r.*) |
| 243 | + *(.data .data.*) |
| 244 | + *(.gnu.linkonce.d.*) |
| 245 | + . = ALIGN(4); |
| 246 | + *(.sdata .sdata.*) |
| 247 | + *(.sdata2*) |
| 248 | + *(.gnu.linkonce.s.*) |
| 249 | + . = ALIGN(4); |
| 250 | + *(.srodata.cst16) |
| 251 | + *(.srodata.cst8) |
| 252 | + *(.srodata.cst4) |
| 253 | + *(.srodata.cst2) |
| 254 | + *(.srodata .srodata.*) |
| 255 | + . = ALIGN(4); |
| 256 | + PROVIDE( _edata = .); |
| 257 | + } >RAM AT>RAM |
| 258 | +#endif |
| 259 | + .bss : |
| 260 | + { |
| 261 | + . = ALIGN(4); |
| 262 | + PROVIDE( _sbss = .); |
| 263 | + *(.sbss*) |
| 264 | + *(.gnu.linkonce.sb.*) |
| 265 | + *(.bss*) |
| 266 | + *(.gnu.linkonce.b.*) |
| 267 | + *(COMMON*) |
| 268 | + . = ALIGN(4); |
| 269 | + PROVIDE( _ebss = .); |
| 270 | + } >RAM AT>RAM |
| 271 | + |
| 272 | + PROVIDE( _end = _ebss); |
| 273 | + PROVIDE( end = . ); |
| 274 | + |
| 275 | + PROVIDE( _eusrstack = ORIGIN(RAM) + LENGTH(RAM)); |
| 276 | +} |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
0 commit comments