From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id B540A3858412 for ; Wed, 8 Mar 2023 01:23:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B540A3858412 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-x536.google.com with SMTP id q189so8746413pga.9 for ; Tue, 07 Mar 2023 17:23:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678238621; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=1Mvnz0jmyemF1HvUZ0GcnrSRe7bzPTaZkakj1OhdPIA=; b=POg1dzMBDy1Dn2xJl9T8JOGXat9ag9hf8zPL2Gr4tg97dH8IbInQKQrd+FIDOPoawB 1+5uLRLGwCfDUcfTds4T/7JMAp73bHvb1INHLKFqTYmF6uvev9vB5K5RD/XvYJsGvS7l FeN7tMR4YDbW+ODVY1clQi2WVfNvbAj0UBkfYHmvHpvOx+o3KgNf7MshWulJQY05/Ioh O1aws6WTlnNOQf4tB3gvSUVR5LX5yQVhliAb5wXkJ4CnXsl5SJM07J2QyCXm8aNkarV/ qnVi27GTVC+1aTc8HutdJaMr4YEV1RQhN/YJi1ttKUDydfjh6oQgSizpLqGarseKHWcB P0gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678238621; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=1Mvnz0jmyemF1HvUZ0GcnrSRe7bzPTaZkakj1OhdPIA=; b=0H8PKc8lBpCit+7HRY3i34AGkvRmQuMS5XIYIeHEP0VkaiUCx3X7//5cDsGINCNqD9 HuoEoie7z3habnKwgd8aVYvUeVW5dB/ZX6KYFFZu+K/U1v/jeTyJmio2eoHMC8Dph6BS Oqqrjs/mOJT1qY1WKzu5iZC8Lk2Pgfzrj9A0nUcCfQc4csB/79CzYOafU+brUK1cX3ky JIy9RfJupf7BHpTMwyVz9ET9fWm8tD+37WDdGQGTPiFgJRs2psuZGmuRKSlu7aZ+B8S9 cwfy5q8ODRjw92NmKbrXxfOE4IVtD2w2EY0frK0wJZ3DGcQrSs4CtYRSzV9fYxjrpohY xeEg== X-Gm-Message-State: AO0yUKVJkReenh8i/SU0kJ4MfrJ+jSSJFueyQ9K8JcZTkvcYAZ1ubnvF QOyUdwslEVW1CZKW4d16R7xzM07OiVRSpHDZW87Pm/mnr5+54Q== X-Google-Smtp-Source: AK7set+slWeuL4EE6lAtUgw9c6AGxuu2aE9P9q43HsfRGFF6TnqR0JfezuHh185LebbdDm4x7Nv4fwm7t16V1qY9V0s= X-Received: by 2002:a63:3504:0:b0:502:fd15:2ad6 with SMTP id c4-20020a633504000000b00502fd152ad6mr6121105pga.2.1678238621447; Tue, 07 Mar 2023 17:23:41 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Damien Towning Date: Wed, 8 Mar 2023 12:23:04 +1100 Message-ID: Subject: Re: Problem with SBRK not returning from call on bare metal risk To: Dave Nadler Cc: newlib@sourceware.org Content-Type: multipart/alternative; boundary="000000000000e13d6c05f65960a4" X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000e13d6c05f65960a4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you for the helpful response and the link. Having understood this helped a lot. I went back to using my own _sbrk and the newlib malloc seems to work okay with it. I think this is mostly about the variable names for heap and stack matching what the newlib expects _and_ avoiding any of the re-entrant stuff. Am able to load up and free complex memory blocks out of the heap. Now what prompted my question to start with is that I am concerned about implementing functions I do not ( or should not ) implement myself. So for example I have had to implement the srand and rand functions myself because those appear to be re-entrant in the newlib. I've now moved on and got another question to ask now about the math library which I think I will put in a separate post :) On Tue, Mar 7, 2023 at 12:24=E2=80=AFAM Dave Nadler wrote: > Hi Damien - You need to verify the sbrk you're using actually provides the > correct addresses. > In cases I'm familiar with, sbrk is provided by the chip-specific > toolchain and not newlib. > Providing your own sbrk is not all bad... > Also, you need to be sure how newlib was built in the toolchain you are > using; > you didn't show us the newlib configuration? > This might provide some help: > https://nadler.com/embedded/newlibAndFreeRTOS.html > Hope this helps! > Best Regards, Dave > > On 3/6/2023 2:36 AM, Damien Towning wrote: > > So a bit of a background. I have the bonfire Risc-V 32 core running on a > T-35 FPGA board. The metal part of this is working great. The processor > runs. I've got it to turn around the segment display on the board. I've > also implemented my own _sbrk and got that to work I think consistently > with malloc. Now in my Risc-v 32 toolchain I have the newlib and I have > brought that in and with my own wrapped _sbrk I am able to use the system > defined malloc. But I am not entirely happy with this because I don't want > to be wrapping every function I encounter. So for example today I found > myself wrapping srand and rand. So I am pretty sure the reason my > nano_newlib isn't working is something to do with either not having the > correct variable names in my firmware.ld or something to do with disabling > the re-entrant behaviour of newlib. I've included in this email my > firmware.ld,platform.h,c code example. What happens is I call the _sbrk(0) > and ( in the simulator I am also running this in ) I never see a bad opco= de > generated. It just seems like the processor goes away and never comes bac= k. > Does anybody have any suggestions as to what might cause this sort of > problem ? I'd like to use the sbrk and other funcitons within the newlib > itself if possible without rolling my own. > > ------------- firmware.ld > MEMORY > { > > RAM (rwx) : ORIGIN =3D 0x0C000000, LENGTH =3D 512K > } > > ENTRY(_start) > > SECTIONS > { > _rombase =3D 0x0C000000; > > . =3D 0x0; > > .text : { > *(.init) > *(.text.*) > > } > RAM > > .data ALIGN(4) : { > *(.rodata.*) > *(.rodata) > *(.eh_frame) > *(.sdata) > *(.data) > *(.sbss) > *(.sbss.*) > *(.gnu.linkonce.sb.*) > *(.bss) > *(.bss.*) > *(.gnu.linkonce.b.*) > *(COMMON) > > end =3D .; _end =3D .; __end =3D .; > > } > RAM > > _heap_end =3D _end; > _heap_prev_end =3D _end; > > } > > PROVIDE(__heap_end =3D _end); > PROVIDE(__prev_heap_end =3D _end); > PROVIDE(__heap_start =3D _end+128K); > > PROVIDE(__stack_top =3D ORIGIN(RAM) + LENGTH(RAM)); > PROVIDE(__stack_start =3D ORIGIN(RAM) + LENGTH(RAM)); > > PROVIDE(__heap_size =3D 128K ); > PROVIDE(__stack_size =3D 128K ); > > > > /* > 0x0C000000 +-------------------+ > | | > | ROM / Flash | > 0x0C080000 +-------------------+ > | | > | .data | > |-------------------| > | .bss / .sbss | > |-------------------| > | _end | > |-------------------| > | Heap | > |-------------------| > | Stack | > 0xXXXXXXXX +-------------------+ > */ > -------------------------------------------------------------------------= ------------- > > ---------platform.h > ---------------------------------------------------------------- > #ifndef BASIC_PLATFORM_H > #define BASIC_PLATFORM_H > > // New Defintions for new bonfire-soc-io core > #define IO_BASE 0x04000000 > #define SOC_IO_OFFSET 0x10000 // Offset from one I/O Device to the next > (64K range) > > #define UART0_BASE IO_BASE > #define SPIFLASH_BASE (IO_BASE+SOC_IO_OFFSET) > #define GPIO_BASE (IO_BASE+3*SOC_IO_OFFSET) > #define UART1_BASE (IO_BASE+2*SOC_IO_OFFSET) > > #define UART_BASE UART0_BASE // Backwards compatiblity > > #define MTIME_BASE 0x0FFFF0000 > > #define DRAM_BASE 0x0 > #define DRAM_SIZE 0 > #define DRAM_TOP (DRAM_BASE+DRAM_SIZE-1) > #define SRAM_BASE 0x0C000000 > #define SRAM_SIZE 524288 > #define SRAM_TOP (SRAM_BASE+SRAM_SIZE-1) > > //#define SYSCLK 12000000 > //#define SYSCLK 33333333 > //#define SYSCLK 24997500 > //#define SYSCLK 88786000 > #define EXT_SYSCLK 89015000 > > #define SYSCLK 24997500 > > //#define EXT_SYSCLK 92370000 /* For reasons not clear to me when any > change is made to the interface */ > /* configuration in Efinity and a new synthesis is done a clock time wi= ll > */ > /* be calculated so you must build your efinity project. Take that new > */ > /* time value. Update it here. Rebuild your hex file. Then rebuild your > */ > /* efinity project AGAIN > */ > > > #define TIME_UNIT 1e+9; // A billion > > #ifndef SIMULATOR > #define SCALAR 1 // Relative Scalar division for efinity build > #define BAUD_SCALAR 1 // Relative Scalar division for efinity build > #else > #define SCALAR 10000 // Relative Scalar division for simulator. Use for > any of your own timing since > #define BAUD_SCALAR 20 // simulator runs slower than real hardware > #endif > > #define CLK_PERIOD (TIME_UNIT / EXT_SYSCLK) // in ns... > > //#define DCACHE_SIZE 0 // (2048*4) // DCache Size in Bytes > > // Parameters for SPI Flash > > #define FLASHSIZE (8192*1024) > #define MAX_FLASH_IMAGESIZE (2024*1024) // Max 2MB of flash used for boot > image > #define FLASH_IMAGEBASE (1024*3072) // Boot Image starts at 3MB in Flash > > #define PLATFORM_BAUDRATE (115200*BAUD_SCALAR) > > #define NO_RECURSION > #define NO_SYSCALL > #define NO_FLASH > #define NO_XMODEM > #define NO_DRAMTEST > > //#define GPIO_TEST > > #endif > -------------------------------------------------------------------------= -------------------- > > ---- sim_hello.c > ------------------------------------------------------------------------ > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > // T35 S100 Module Test Code > // Damien Towning - 2022 > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > #include running on a T-35 FPGA board. The metal part of this is working great. The > processor runs. I've got it to turn around the segment display on the > board. I've also implemented my own _sbrk and got that to work I think > consistently with malloc. Now in my Risc-v 32 toolchain I have the newlib > and I have brought that in and with my own wrapped _sbrk I am able to use > the system defined malloc. But I am not entirely happy with this because I > don't want to be wrapping every function I encounter. So for example today > I found myself wrapping srand and rand. So I am pretty sure the reason my > nano_newlib isn't working is something to do with either not having the > correct variable names in my firmware.ld or something to do with disabling > the re-entrant behaviour of newlib. I've included in this email my > firmware.ld,platform.h,c code example. What happens is I call the _sbrk(0) > and ( in the simulator I am also running this in ) I never see a bad opco= de > generated. It just seems like the processor goes away and never comes bac= k. > Does anybody have any suggestions as to what might cause this sort of > problem ? I'd like to use the sbrk and other funcitons within the newlib > itself if possible without rolling my own. > > ------------- firmware.ld > MEMORY > { > > RAM (rwx) : ORIGIN =3D 0x0C000000, LENGTH =3D 512K > } > > ENTRY(_start) > > SECTIONS > { > _rombase =3D 0x0C000000; > > . =3D 0x0; > > .text : { > *(.init) > *(.text.*) > > } > RAM > > .data ALIGN(4) : { > *(.rodata.*) > *(.rodata) > *(.eh_frame) > *(.sdata) > *(.data) > *(.sbss) > *(.sbss.*) > *(.gnu.linkonce.sb.*) > *(.bss) > *(.bss.*) > *(.gnu.linkonce.b.*) > *(COMMON) > > end =3D .; _end =3D .; __end =3D .; > > } > RAM > > _heap_end =3D _end; > _heap_prev_end =3D _end; > > } > > PROVIDE(__heap_end =3D _end); > PROVIDE(__prev_heap_end =3D _end); > PROVIDE(__heap_start =3D _end+128K); > > PROVIDE(__stack_top =3D ORIGIN(RAM) + LENGTH(RAM)); > PROVIDE(__stack_start =3D ORIGIN(RAM) + LENGTH(RAM)); > > PROVIDE(__heap_size =3D 128K ); > PROVIDE(__stack_size =3D 128K ); > > > > /* > 0x0C000000 +-------------------+ > | | > | ROM / Flash | > 0x0C080000 +-------------------+ > | | > | .data | > |-------------------| > | .bss / .sbss | > |-------------------| > | _end | > |-------------------| > | Heap | > |-------------------| > | Stack | > 0xXXXXXXXX +-------------------+ > */ > -------------------------------------------------------------------------= ------------- > > ---------platform.h > ---------------------------------------------------------------- > #ifndef BASIC_PLATFORM_H > #define BASIC_PLATFORM_H > > // New Defintions for new bonfire-soc-io core > #define IO_BASE 0x04000000 > #define SOC_IO_OFFSET 0x10000 // Offset from one I/O Device to the next > (64K range) > > #define UART0_BASE IO_BASE > #define SPIFLASH_BASE (IO_BASE+SOC_IO_OFFSET) > #define GPIO_BASE (IO_BASE+3*SOC_IO_OFFSET) > #define UART1_BASE (IO_BASE+2*SOC_IO_OFFSET) > > #define UART_BASE UART0_BASE // Backwards compatiblity > > #define MTIME_BASE 0x0FFFF0000 > > #define DRAM_BASE 0x0 > #define DRAM_SIZE 0 > #define DRAM_TOP (DRAM_BASE+DRAM_SIZE-1) > #define SRAM_BASE 0x0C000000 > #define SRAM_SIZE 524288 > #define SRAM_TOP (SRAM_BASE+SRAM_SIZE-1) > > //#define SYSCLK 12000000 > //#define SYSCLK 33333333 > //#define SYSCLK 24997500 > //#define SYSCLK 88786000 > #define EXT_SYSCLK 89015000 > > #define SYSCLK 24997500 > > //#define EXT_SYSCLK 92370000 /* For reasons not clear to me when any > change is made to the interface */ > /* configuration in Efinity and a new synthesis is done a clock time wi= ll > */ > /* be calculated so you must build your efinity project. Take that new > */ > /* time value. Update it here. Rebuild your hex file. Then rebuild your > */ > /* efinity project AGAIN > */ > > > #define TIME_UNIT 1e+9; // A billion > > #ifndef SIMULATOR > #define SCALAR 1 // Relative Scalar division for efinity build > #define BAUD_SCALAR 1 // Relative Scalar division for efinity build > #else > #define SCALAR 10000 // Relative Scalar division for simulator. Use for > any of your own timing since > #define BAUD_SCALAR 20 // simulator runs slower than real hardware > #endif > > #define CLK_PERIOD (TIME_UNIT / EXT_SYSCLK) // in ns... > > //#define DCACHE_SIZE 0 // (2048*4) // DCache Size in Bytes > > // Parameters for SPI Flash > > #define FLASHSIZE (8192*1024) > #define MAX_FLASH_IMAGESIZE (2024*1024) // Max 2MB of flash used for boot > image > #define FLASH_IMAGEBASE (1024*3072) // Boot Image starts at 3MB in Flash > > #define PLATFORM_BAUDRATE (115200*BAUD_SCALAR) > > #define NO_RECURSION > #define NO_SYSCALL > #define NO_FLASH > #define NO_XMODEM > #define NO_DRAMTEST > > //#define GPIO_TEST > > #endif > -------------------------------------------------------------------------= -------------------- > > ---- sim_hello.c > ------------------------------------------------------------------------ > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > // T35 S100 Module Test Code > // Damien Towning - 2022 > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > #include > #include > > //#include > //#include > #include > #include > #include > #include "bonfire.h" > #include "uart.h" > #include "bonfire_gpio.h" > #include "mem_rw.h" > #include "console.h" > > extern void* sbrk(incr); > > > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > // Main function > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > int main() { > > setBaudRate(PLATFORM_BAUDRATE); > > caddr_t *ptr =3D sbrk(0); > // code never returns from sbrk > if (ptr =3D=3D (void *)-1) { > printk("Failed to allocate memory\r\n"); > } > else { > printk("Allocated memory at : %p\r\n", (void *) &ptr); > } > return 0; > } > -------------------------------------------------------------------------= ----------- > --- Makefile > -------------------------------------------------------------------- > > .PHONY: all clean > > ARCH ?=3D rv32ia > ABI=3Dilp32 > PLATFORM ?=3D S100_T35 > > #TARGET_PREFIX ?=3D riscv32-unknown-linux-gnu > TARGET_PREFIX ?=3D riscv32-unknown-elf > TARGET_CC :=3D $(TARGET_PREFIX)-gcc > TARGET_LD :=3D $(TARGET_PREFIX)-gcc > TARGET_SIZE :=3D $(TARGET_PREFIX)-size > TARGET_OBJCOPY :=3D $(TARGET_PREFIX)-objcopy > HEXDUMP ?=3D hexdump > DATA2MEM =3D /opt/Xilinx/14.7/ISE_DS/ISE/bin/lin64/data2mem > > #PROJROOT =3D ../../.. > #TOPLEVEL =3D ~/riscv/ise/bonfire/papilio_pro_dram_toplevel.bit > PLATFORMDIR=3D../platform > > LINKDEF?=3D$(PLATFORMDIR)/$(PLATFORM)/firmware.ld > > TARGET_CFLAGS +=3D -march=3D$(ARCH) -mabi=3D$(ABI) -Wall -Os -g > -fomit-frame-pointer \ > -ffreestanding -fno-builtin \ > -Wall -Werror=3Dimplicit-function-declaration \ > -D$(PLATFORM) > > ifeq ($(SIMULATOR), 1) > TARGET_CFLAGS+=3D-DSIMULATOR > endif > > TARGET_CFLAGS+=3D-I$(PLATFORMDIR) -I$(PLATFORMDIR)/$(PLATFORM) -I../riscv > > # If we wish to build with no newlib > #TARGET_LDFLAGS +=3D -march=3D$(ARCH) -mabi=3D$(ABI) -nostartfiles \ > -Wl,-m,elf32lriscv,--wrap=3Dmalloc,--wrap=3Dsbrk --specs=3Dnosys.specs > -Wl,-T$(LINKDEF) \ > -Wl,--gc-sections > > TARGET_LDFLAGS +=3D -march=3D$(ARCH) -mabi=3D$(ABI) -nostartfiles \ > -Wl,-m,elf32lriscv,--wrap=3D_srand,--wrap=3D_rand --specs=3Dnano.specs > -Wl,-Map=3Doutput.map,-T$(LINKDEF) \ > -Wl,--gc-sections > > all: sim_hello.hex memtest.hex nanotest.hex > > %.o : %.S > $(TARGET_CC) $(TARGET_CFLAGS) -c $< > > %.o : %.c > $(TARGET_CC) $(TARGET_CFLAGS) -c $< > > %.hex : %.elf > $(TARGET_OBJCOPY) -S -O binary $< $(basename $@).bin > $(HEXDUMP) -v -e '1/4 "%08x\n"' $(basename $@).bin >$@ > $(TARGET_PREFIX)-objdump -S -d $< >$(basename $@).lst > #$(TARGET_PREFIX)-objdump -D $< >$(basename $@).S > $(TARGET_PREFIX)-objdump -s $< >$(basename $@).dmp > $(TARGET_PREFIX)-size $< > > #sbrk.o: libwrap/sbrk.c > # $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c libwrap/sbrk.c > > rand.o: libwrap/rand.c > $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c libwrap/rand.c > > uart.o: uart.c > $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c uart.c > > #sim_hello.o : sim_hello.c > # $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c sim_hello.c > > sim_hello.elf: start.o uart.o sim_hello.o snprintf.o console.o rand.o > $(TARGET_LD) -o $@ $(TARGET_LDFLAGS) start.o uart.o sim_hello.o snprintf.o > console.o rand.o > > #memtest.elf: start.o uart.o memtest.o snprintf.o console.o mempattern.o > sbrk.o > # $(TARGET_LD) -o $@ $(TARGET_LDFLAGS) start.o uart.o memtest.o snprintf.o > console.o mempattern.o sbrk.o > > #nanotest.elf: start.o uart.o nanotest.o snprintf.o console.o mempattern.o > sbrk.o > # $(TARGET_LD) -o $@ $(TARGET_LDFLAGS) start.o uart.o nanotest.o snprintf= .o > console.o mempattern.o sbrk.o > > #jump0.elf : jump0.S > # $(TARGET_LD) -o $@ -march=3DRV32IM -nostartfiles -Wl,-T$(BOOTLINK) $< > > clean: > rm -f *.o > -------------------------------------------------------------------------= --------------------.h> > #include > > //#include > //#include > #include > #include > #include > #include "bonfire.h" > #include "uart.h" > #include "bonfire_gpio.h" > #include "mem_rw.h" > #include "console.h" > > extern void* sbrk(incr); > > > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > // Main function > // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > int main() { > > setBaudRate(PLATFORM_BAUDRATE); > > caddr_t *ptr =3D sbrk(0); > // code never returns from sbrk > if (ptr =3D=3D (void *)-1) { > printk("Failed to allocate memory\r\n"); > } > else { > printk("Allocated memory at : %p\r\n", (void *) &ptr); > } > return 0; > } > -------------------------------------------------------------------------= ----------- > --- Makefile > -------------------------------------------------------------------- > > .PHONY: all clean > > ARCH ?=3D rv32ia > ABI=3Dilp32 > PLATFORM ?=3D S100_T35 > > #TARGET_PREFIX ?=3D riscv32-unknown-linux-gnu > TARGET_PREFIX ?=3D riscv32-unknown-elf > TARGET_CC :=3D $(TARGET_PREFIX)-gcc > TARGET_LD :=3D $(TARGET_PREFIX)-gcc > TARGET_SIZE :=3D $(TARGET_PREFIX)-size > TARGET_OBJCOPY :=3D $(TARGET_PREFIX)-objcopy > HEXDUMP ?=3D hexdump > DATA2MEM =3D /opt/Xilinx/14.7/ISE_DS/ISE/bin/lin64/data2mem > > #PROJROOT =3D ../../.. > #TOPLEVEL =3D ~/riscv/ise/bonfire/papilio_pro_dram_toplevel.bit > PLATFORMDIR=3D../platform > > LINKDEF?=3D$(PLATFORMDIR)/$(PLATFORM)/firmware.ld > > TARGET_CFLAGS +=3D -march=3D$(ARCH) -mabi=3D$(ABI) -Wall -Os -g > -fomit-frame-pointer \ > -ffreestanding -fno-builtin \ > -Wall -Werror=3Dimplicit-function-declaration \ > -D$(PLATFORM) > > ifeq ($(SIMULATOR), 1) > TARGET_CFLAGS+=3D-DSIMULATOR > endif > > TARGET_CFLAGS+=3D-I$(PLATFORMDIR) -I$(PLATFORMDIR)/$(PLATFORM) -I../riscv > > # If we wish to build with no newlib > #TARGET_LDFLAGS +=3D -march=3D$(ARCH) -mabi=3D$(ABI) -nostartfiles \ > -Wl,-m,elf32lriscv,--wrap=3Dmalloc,--wrap=3Dsbrk --specs=3Dnosys.specs > -Wl,-T$(LINKDEF) \ > -Wl,--gc-sections > > TARGET_LDFLAGS +=3D -march=3D$(ARCH) -mabi=3D$(ABI) -nostartfiles \ > -Wl,-m,elf32lriscv,--wrap=3D_srand,--wrap=3D_rand --specs=3Dnano.specs > -Wl,-Map=3Doutput.map,-T$(LINKDEF) \ > -Wl,--gc-sections > > all: sim_hello.hex memtest.hex nanotest.hex > > %.o : %.S > $(TARGET_CC) $(TARGET_CFLAGS) -c $< > > %.o : %.c > $(TARGET_CC) $(TARGET_CFLAGS) -c $< > > %.hex : %.elf > $(TARGET_OBJCOPY) -S -O binary $< $(basename $@).bin > $(HEXDUMP) -v -e '1/4 "%08x\n"' $(basename $@).bin >$@ > $(TARGET_PREFIX)-objdump -S -d $< >$(basename $@).lst > #$(TARGET_PREFIX)-objdump -D $< >$(basename $@).S > $(TARGET_PREFIX)-objdump -s $< >$(basename $@).dmp > $(TARGET_PREFIX)-size $< > > #sbrk.o: libwrap/sbrk.c > # $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c libwrap/sbrk.c > > rand.o: libwrap/rand.c > $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c libwrap/rand.c > > uart.o: uart.c > $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c uart.c > > #sim_hello.o : sim_hello.c > # $(TARGET_CC) $(TARGET_CFLAGS) -DSIM -c sim_hello.c > > sim_hello.elf: start.o uart.o sim_hello.o snprintf.o console.o rand.o > $(TARGET_LD) -o $@ $(TARGET_LDFLAGS) start.o uart.o sim_hello.o snprintf.o > console.o rand.o > > #memtest.elf: start.o uart.o memtest.o snprintf.o console.o mempattern.o > sbrk.o > # $(TARGET_LD) -o $@ $(TARGET_LDFLAGS) start.o uart.o memtest.o snprintf.o > console.o mempattern.o sbrk.o > > #nanotest.elf: start.o uart.o nanotest.o snprintf.o console.o mempattern.o > sbrk.o > # $(TARGET_LD) -o $@ $(TARGET_LDFLAGS) start.o uart.o nanotest.o snprintf= .o > console.o mempattern.o sbrk.o > > #jump0.elf : jump0.S > # $(TARGET_LD) -o $@ -march=3DRV32IM -nostartfiles -Wl,-T$(BOOTLINK) $< > > clean: > rm -f *.o > -------------------------------------------------------------------------= -------------------- > > > -- > Dave Nadler, USA East Coast voice (978) 263-0097, drn@nadler.com, Skype > Dave.Nadler1 > > --=20 Damien Towning --000000000000e13d6c05f65960a4--