重写了GD32VF103的启动脚本和链接脚本
生活随笔
收集整理的這篇文章主要介紹了
重写了GD32VF103的启动脚本和链接脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
官方的startup和鏈接腳本有點亂七八糟的,像是調試早期寫的東西。我重新整理了下。
啟動腳本去掉了中斷向量表表部分,能節省一部分代碼空間,后續可以自己定義,只要對齊到512字節(這樣支持最多128個中斷)就可以了。
另外去掉了C的init、C++的構造析構支持。因此不能使用c庫。不使用標準c庫可以省下很多代碼空間。
/* GD32VF103 startup assembly by mengxp */#include "riscv_encoding.h".section .init.globl _start.type _start, @function_start:/* disable global interrupt */csrc CSR_MSTATUS, MSTATUS_MIE/* Jump to the absolute address of 1f */lui ra, %hi(1f)jr %lo(1f)(ra) 1:/* enable FPU */ #ifdef __riscv_flenli t0, MSTATUS_FScsrs mstatus, t0csrw fcsr, x0 #endif/* load stack pointer */la sp, _sp/* load initialized data section */la a0, _sidatala a1, _sdatala a2, _edatabgeu a1, a2, 2f 1:lw t0, (a0)sw t0, (a1)addi a0, a0, 4addi a1, a1, 4bltu a1, a2, 1b 2:/* clear bss section */la a0, _sbssla a1, _ebssbgeu a0, a1, 2f 1:sw zero, (a0)addi a0, a0, 4bltu a0, a1, 1b 2:/* enable mcycle */csrci CSR_MCOUNTINHIBIT, 0x5/* main entry */call main_end:j _end /* GD32VF103 linker script by mengxp */OUTPUT_ARCH("riscv") ENTRY(_start)/* Run in FLASH */ MEMORY {FLASH (rxai!w) : ORIGIN = 0x08000000, LENGTH = 128kRAM (wxa!ri) : ORIGIN = 0x20000000, LENGTH = 32K }/* Run in RAM */ /* MEMORY {FLASH (rxai!w) : ORIGIN = 0x20000000, LENGTH = 24kRAM (wxa!ri) : ORIGIN = 0x20006000, LENGTH = 8K } *//* Required amount of stack */ Stack_Size = 0x400;SECTIONS {/* The startup code goes first into FLASH */.init : {. = ALIGN(4);KEEP(*(.init))} >FLASH/* The program code and other data goes into FLASH */.text : {. = ALIGN(4);*(.text) /* .text sections (code) */*(.text*) /* .text* sections (code) */} >FLASH/* Constant data goes into FLASH */.rodata : {. = ALIGN(4);*(.rodata) /* .rodata sections (constants, strings, etc.) */*(.rodata*) /* .rodata* sections (constants, strings, etc.) */} >FLASH.preinit_array : {. = ALIGN(4);PROVIDE_HIDDEN (__preinit_array_start = .);KEEP (*(.preinit_array*))PROVIDE_HIDDEN (__preinit_array_end = .);} >FLASH.init_array : {. = ALIGN(4);PROVIDE_HIDDEN (__init_array_start = .);KEEP (*(SORT(.init_array.*)))KEEP (*(.init_array*))PROVIDE_HIDDEN (__init_array_end = .);} >FLASH.fini_array : {. = ALIGN(4);PROVIDE_HIDDEN (__fini_array_start = .);KEEP (*(SORT(.fini_array.*)))KEEP (*(.fini_array*))PROVIDE_HIDDEN (__fini_array_end = .);} >FLASH/* used by the startup to initialize data */PROVIDE( _sidata = LOADADDR(.data) );/* Initialized data sections goes into RAM, load LMA copy after code */.data : {. = ALIGN(4);PROVIDE ( _sdata = . ); /* create a global symbol at data start */*(.rdata)*(.data) /* .data sections */*(.data*) /* .data* sections */*(.sdata)*(.sdata*). = ALIGN(4);PROVIDE ( _edata = . ); /* define a global symbol at data end */} >RAM AT> FLASH/* Uninitialized data section */.bss : {. = ALIGN(4);PROVIDE ( _sbss = . ); /* define a global symbol at bss start */*(.bss)*(.bss*)*(COMMON). = ALIGN(4);PROVIDE ( _ebss = . ); /* define a global symbol at bss end */} >RAM.stack ORIGIN(RAM) + LENGTH(RAM) - Stack_Size : {. = Stack_Size; PROVIDE( _sp = . ); } >RAM }?
總結
以上是生活随笔為你收集整理的重写了GD32VF103的启动脚本和链接脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 精简版sprintf适合嵌入式使用
- 下一篇: VMware QueryPerforma