Giter VIP home page Giter VIP logo

joe-degs / riscv Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gamozolabs/riscv

0.0 1.0 0.0 5.88 MB

A div-less, mul-less, atomic-less `rv64i` compiler toolchain using purely clang, musl, and compiler-rt

Makefile 0.03% CMake 0.93% C++ 19.21% C 77.40% Assembly 1.29% Shell 0.12% Python 0.41% Objective-C++ 0.12% Objective-C 0.08% Batchfile 0.01% Awk 0.35% CSS 0.01% HTML 0.02% sed 0.01% Pawn 0.04%

riscv's Introduction

Intro

Warning, this project has atomics disabled and thus will not produce thread-safe binaries with no warnings, see the Safety section for details

This project is just where I do my RISC-V work. This is capable of building musl and compiler-rt using the -march=rv64i instruction set. This means there are no divides, multiplies, atomics, or anything! This will be able to generate single-threaded binaries using the most basic RISC-V 64-bit instruction set! This is a perfect place to start if you're writing an emulator and want to keep things as simple as possible.

Installation

For absolute beginners who are struggling to install riscv or qemu-riscv64 on debian. You can do the following.

  • Installing clang and llvm tools on StackOverflow

  • Install ld.lld-version number because for some weird reason it does not get installed with the other llvm tools.

      $ sudo apt-get install lld-<version number>
    
  • Installing qemu on debian

      $ sudo apt-get install qemu-system-misc qemu-user-static binfmt-support
    
  • You can do a manual qemu installation by building from source

Usage

This project assumes you have clang 10 installed and in your path. If you want to use a different version of clang, change CLANG_VERSION in the root level Makefile. Note that some versions of clang may not support targeting riscv64.

Simply run make to have a toolchain created for you. Run make clean to remove the toolchain if desired.

Test Application

There is a test C application in the test_app folder, giving an example of how to build and use this created toolchain.

pleb@gamey:~/riscv/test_app$ make
clang-10 -Wall -Werror -O2 -g -nostdlib -target riscv64 -march=rv64i -I../musl_build/install/include -c test_app.c
ld.lld-10 -o test_app \
        ../musl_build/install/lib/crt1.o \
        ../musl_build/install/lib/libc.a \
        ../compiler-rt_build/install/lib/riscv64/libclang_rt.builtins-riscv64.a \
        *.o
pleb@gamey:~/riscv/test_app$ file ./test_app
./test_app: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked, with debug_info, not stripped
pleb@gamey:~/riscv/test_app$ qemu-riscv64 ./test_app
Hello world!

How cool is that!?

Environment

All of this testing has been done using the official Debian pacakges directly from the LLVM project.

Safety

This project is not thread safe in its default configuration. Atomics are not implemented in the base ISA and thus I had to disable atomics in MUSL. The way I disabled atomics in MUSL means that locks will silently pass. This will lead to really confusing bugs, these binaries are meant to be used in an environment where threads are not possible to create (my emulator).

If you want to get back thread safety change the #if 0 in musl-1.2.0/arch/riscv64/atomic_arch.h to an #if 1. This will then give compilation errors unless the march flag passed to MUSL during building is changed from -march=rv64i to -march=rv64ia, to allow the atomics RISC-V extension.

Patches

See the patches folder for more info.

MUSL

Basis: musl-1.2.0

MUSL was slightly modified to have a atomic-less support, abliet unsafely and without checks, check the #if 0 block in musl-1.2.0/arch/riscv64/atomic_arch.h. Other than that, it's identical to the official musl-1.2.0 release.

compiler-rt

Basis: https://github.com/llvm-mirror/compiler-rt @ 69445f095c22aac2388f939bedebf224a6efcdaf

compiler-rt had a bug with rv64i where it would produce multiplies recursively in the C implementation of __muldi3. To avoid this, a new muldi3.S file has been created under the lib/builtins/riscv64 folder. It has then been added to the CMakeLists.txt to ensure it gets used and replaces the __muldi3 C implementation.

riscv's People

Contributors

joe-degs avatar gamozolabs avatar

Watchers

James Cloos avatar

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.