From ef07427e06b1fa868ac7b96b18e77270f2231aed Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 14 Oct 2019 11:30:05 +0800 Subject: [PATCH] bsp: fomu: update Signed-off-by: Sean Cross --- hw/bsp/fomu/bsp.c | 8 ++- hw/bsp/fomu/crt0-vexriscv.S | 14 ++-- hw/bsp/fomu/fomu.ld | 130 ++++++++++++++++++++++++------------ 3 files changed, 98 insertions(+), 54 deletions(-) diff --git a/hw/bsp/fomu/bsp.c b/hw/bsp/fomu/bsp.c index 861c223f..2bba0ce2 100644 --- a/hw/bsp/fomu/bsp.c +++ b/hw/bsp/fomu/bsp.c @@ -116,9 +116,11 @@ int board_uart_read(uint8_t* buf, int len) int board_uart_write(void const * buf, int len) { - (void) buf; - (void) len; - return 0; + int32_t offset = 0; + for (offset = 0; offset < len; offset++) + if (! (messible_status_read() & CSR_MESSIBLE_STATUS_FULL_OFFSET)) + messible_in_write(((uint8_t *)buf)[offset]); + return len; } #if CFG_TUSB_OS == OPT_OS_NONE diff --git a/hw/bsp/fomu/crt0-vexriscv.S b/hw/bsp/fomu/crt0-vexriscv.S index 931d50a0..46dca557 100644 --- a/hw/bsp/fomu/crt0-vexriscv.S +++ b/hw/bsp/fomu/crt0-vexriscv.S @@ -57,13 +57,13 @@ trap_entry: crt_init: - la sp, _fstack + 4 + la sp, _estack - 4 la a0, trap_entry csrw mtvec, a0 bss_init: - la a0, _fbss - la a1, _ebss + la a0, _sbss + la a1, _ebss + 4 bss_loop: beq a0,a1,bss_done sw zero,0(a0) @@ -72,13 +72,13 @@ bss_loop: bss_done: /* Load DATA */ - la t0, _erodata - la t1, _fdata - la t2, _edata + la t0, _etext + la t1, _srelocate + la t2, _erelocate + 4 3: lw t3, 0(t0) sw t3, 0(t1) - /* _edata is aligned to 16 bytes. Use word-xfers. */ + /* _edata is aligned to 4 bytes. Use word-xfers. */ addi t0, t0, 4 addi t1, t1, 4 bltu t1, t2, 3b diff --git a/hw/bsp/fomu/fomu.ld b/hw/bsp/fomu/fomu.ld index 2a3f2376..abc91b8e 100644 --- a/hw/bsp/fomu/fomu.ld +++ b/hw/bsp/fomu/fomu.ld @@ -6,57 +6,99 @@ __DYNAMIC = 0; MEMORY { csr : ORIGIN = 0x60000000, LENGTH = 0x01000000 vexriscv_debug : ORIGIN = 0xf00f0000, LENGTH = 0x00000100 - sram : ORIGIN = 0x10000000, LENGTH = 0x00020000 + ram : ORIGIN = 0x10000000, LENGTH = 0x00020000 rom : ORIGIN = 0x2001a000, LENGTH = 0x00200000 - 0x1a000 } +/* The stack size used by the application. NOTE: you need to adjust according to your application. */ +STACK_SIZE = DEFINED(STACK_SIZE) ? STACK_SIZE : DEFINED(__stack_size__) ? __stack_size__ : 0x2000; + +/* Section Definitions */ SECTIONS { - .text : - { - _ftext = .; + .text : + { + . = ALIGN(4); + _ftext = .; *(.text.start) - *(.text .stub .text.* .gnu.linkonce.t.*) - _etext = .; - } > rom + *(.text .text.* .gnu.linkonce.t.*) + *(.glue_7t) *(.glue_7) + *(.rodata .rodata* .gnu.linkonce.r.*) - .rodata : - { - . = ALIGN(4); - _frodata = .; - *(.rodata .rodata.* .gnu.linkonce.r.*) - *(.rodata1) - *(.srodata) - . = ALIGN(4); - _erodata = .; - } > rom + /* Support C constructors, and C destructors in both user code + and the C library. This also provides support for C++ code. */ + . = ALIGN(4); + KEEP(*(.init)) + . = ALIGN(4); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; - .data : AT (ADDR(.rodata) + SIZEOF (.rodata)) - { - . = ALIGN(4); - _fdata = .; - *(.data .data.* .gnu.linkonce.d.*) - *(.data1) - _gp = ALIGN(16); - *(.sdata .sdata.* .gnu.linkonce.s.* .sdata2 .sdata2.*) - . = ALIGN(16); - _edata = .; /* Make sure _edata is >= _gp. */ - } > sram + . = ALIGN(4); + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; - .bss : - { - _fbss = .; - *(.dynsbss) - *(.sbss .sbss.* .gnu.linkonce.sb.*) - *(.scommon) - *(.dynbss) - *(.bss .bss.* .gnu.linkonce.b.*) - *(COMMON) - . = ALIGN(4); - _ebss = .; - _end = .; - PROVIDE(end = .); - } > sram -} + . = ALIGN(4); + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*crtend.o(.ctors)) -PROVIDE(_fstack = ORIGIN(sram) + LENGTH(sram) - 4); + . = ALIGN(4); + KEEP(*(.fini)) + + . = ALIGN(4); + __fini_array_start = .; + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + __fini_array_end = .; + + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*crtend.o(.dtors)) + } > rom + + . = ALIGN(4); + _etext = .; /* End of text section */ + + .relocate : AT (_etext) + { + . = ALIGN(4); + _srelocate = .; + *(.ramfunc .ramfunc.*); + *(.data .data.*); + . = ALIGN(4); + _erelocate = .; + } > ram + + /* .bss section which is used for uninitialized data */ + .bss (NOLOAD) : + { + . = ALIGN(4); + _sbss = . ; + _szero = .; + *(.bss .bss.*) + *(.sbss .sbss.*) + *(COMMON) + . = ALIGN(4); + _ebss = . ; + _ezero = .; + end = .; + } > ram + + /* stack section */ + .stack (NOLOAD): + { + . = ALIGN(8); + _sstack = .; + . = . + STACK_SIZE; + . = ALIGN(8); + _estack = .; + } > ram + + . = ALIGN(4); + _end = . ; +} \ No newline at end of file