Git Product home page Git Product logo

Comments (18)

sylefeb avatar sylefeb commented on June 3, 2024 1

I'll write about results

Please let us know, hopefully we can make it work as well.

Btw, after a bit of searching, there is a simpler approach! The trick is to let gcc do the link because it knows where the libs are (found the hint at the bottom of the answer: https://stackoverflow.com/questions/64603070/risc-v-linker-cannot-find-lgcc ).

We can then use -lm (for math) and -nostartfiles (to use our custom crt0).

$ARCH-as -march=rv32i -mabi=ilp32 -o crt0.o $BASE/crt0.s
$ARCH-gcc -DICESTICK -nostartfiles -fno-builtin -fno-unroll-loops -O1 -fno-stack-protector -fno-pic -march=rv32i -mabi=ilp32 -T $BASE/config_c.ld -o $DST/code.elf $1 crt0.o -lm

That is way cleaner, I'll update my scripts accordingly.

from silice.

ShervinShokouhi avatar ShervinShokouhi commented on June 3, 2024 1

I compiled my code and tested it.
About your latest compilation script tested, I don't check it yet.
Newlib is fantastic, thank you @sylefeb.

from silice.

sylefeb avatar sylefeb commented on June 3, 2024 1

Thanks for the feedback and tests! I'll close the issue for now but feel free to reopen if needed.

from silice.

rob-ng15 avatar rob-ng15 commented on June 3, 2024

from silice.

ShervinShokouhi avatar ShervinShokouhi commented on June 3, 2024

Thanks for your help, but where is "--specs=nano.specs" inside "https://github.com/sylefeb/Silice/blob/master/projects/ice-v/compile/icestick/compile_c.sh" script?
I used ice-v scripts but caused: undefined reference to __subsf3'

from silice.

rob-ng15 avatar rob-ng15 commented on June 3, 2024

from silice.

sylefeb avatar sylefeb commented on June 3, 2024

Hi @ShervinShokouhi, Hi @rob-ng15,

This missing entry is due to floating point emulation not being found by the linker. I never had to use it (I do fixed point / integer only) but we definitely need that to work. I'll try to look into the issue as soon as possible but @rob-ng15 has definitely more experience on this. Rob, I believe you did compile with floating point emulation in the past, right?

from silice.

rob-ng15 avatar rob-ng15 commented on June 3, 2024

Yes, I believe that the floating point emulation is in the libgcc.a file.

from silice.

rob-ng15 avatar rob-ng15 commented on June 3, 2024

Just realised that I've given the paths to the versions that have hardware floating point support, I think you need to remove the f from the end of ip32

from silice.

rob-ng15 avatar rob-ng15 commented on June 3, 2024

from silice.

ShervinShokouhi avatar ShervinShokouhi commented on June 3, 2024

Hi @sylefeb, @rob-ng15
Thanks for your detailed descriptions, now I'm able to compile C file to O. But in linker stage again asks for MATH functions:

C:\msys64\mingw64\bin\riscv64-unknown-elf-ld.exe: main.c:(.text+0x1e0): undefined reference to `__mulsf3'

How to link newlib library in linker stage?

from silice.

rob-ng15 avatar rob-ng15 commented on June 3, 2024

Have a look in your gcc directories for libgcc and put that path in,ale sue is it for rve2i and ilp32

from silice.

ShervinShokouhi avatar ShervinShokouhi commented on June 3, 2024

Its my gcc command (Toolchain is made for RV32I with NewLib):

riscv32-unknown-elf-gcc -fno-unroll-loops -O1 -fno-stack-protector -fno-pic -march=rv32i -mabi=ilp32 --specs=nano.specs -LF:\Silice\Toolchains\riscv32-unknown-elf\riscv32-unknown-elf\lib\rv32i\ilp32/libc.a -L-LF:\Silice\Toolchains\riscv32-unknown-elf\riscv32-unknown-elf\lib\rv32i\ilp32/libm.a -LF:\Silice\Toolchains\riscv32-unknown-elf\riscv32-unknown-elf\lib\rv32i\ilp32/libg.a -LF:\Silice\Toolchains\riscv32-unknown-elf\newlib-nano\lib\gcc\riscv32-unknown-elf\11.3.0\rv32i\ilp32/libgcc.a -lm -S test.c -o test.s

Generated ASM (or ELF) file again contains "call" to MATH functions.
I create GCC toolchain with crosstool-ng in Ubuntu for use in Windows x64.

Any idea?

from silice.

sylefeb avatar sylefeb commented on June 3, 2024

I could not test beyond compilation yet but this seems to work (*) on my side:
https://gist.github.com/sylefeb/64a0a55681f0680908989724c05e1778

(*) (edit: added this note) by 'seems to work' I mean I could compile code using float on an rv32i setup.

Might need a change in paths, for libgcc in particular as it contains a version number (note: the order of object file / libraries does matter in the ld command line).

from silice.

sylefeb avatar sylefeb commented on June 3, 2024

It works! I was able to run the following on the ice-v (with the scripts I linked above and a small change to the .ld, see comment in the gist:

#include "config.h"
#include <math.h>

void main()
{
  float f = 1.111111f;
  for (int i = 0 ; i < 20 ; ++i) {
    f = f * f;
    *LEDS = (int)round(f);
  }
}

from silice.

ShervinShokouhi avatar ShervinShokouhi commented on June 3, 2024

I also compiled it :)
Thank you @sylefeb
But I have some problem with test it in my custom SOC.
I'll write about results

from silice.

ShervinShokouhi avatar ShervinShokouhi commented on June 3, 2024

Another question: Now generated HEX file contains several sections split by something like "@000001E0", how do you fill them into BRAM for CPU?

from silice.

sylefeb avatar sylefeb commented on June 3, 2024

Hex file: I have updated the preprocessor script to do that: https://github.com/sylefeb/Silice/blob/draft/projects/ice-v/SOCs/pre_include_compiled.lua (could use a rewrite but does the job ;) ).

from silice.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.