GithubHelp home page GithubHelp logo

Comments (2)

ckirsch avatar ckirsch commented on May 12, 2024

This is nice. Thanks a lot! Feel free to open a PR. I will then review that and see what we can do to get this into the repo.

from selfie.

andreasbaumann avatar andreasbaumann commented on May 12, 2024

Just wanted to keep you up to date, there is now a combined branch supporting 64-bit and 32-bit
in parallel, see https://github.com/andreasbaumann/selfie/tree/risccombi.

In short:

make ARCH=RISCV64 selfie
gcc -O0 -m64 -g -Duint_t='unsigned long long' \
	-DARCHITECTURE=1 \
	-DCPUBITWIDTH=64 -DREGISTERSIZE=8 \
	-DSIZEOFUINT=8 -DSIZEOFUINTSTAR=8 \
	-DWORDSIZE=4 -DWORDSIZEINBITS=32 \
	-DINSTRUCTIONSIZE=4 -DALIGNBITS=3 \
	selfie.c -o selfie
make ARCH=RISCV32 selfie
gcc -O0 -g -m32 -D'uint_t=unsigned int' \
	-DARCHITECTURE=2 \
	-DCPUBITWIDTH=32 -DREGISTERSIZE=4 \
	-DSIZEOFUINT=4 -DSIZEOFUINTSTAR=4\
	-DWORDSIZE=4 -DWORDSIZEINBITS=32 \
	-DINSTRUCTIONSIZE=4 -DALIGNBITS=2 \
	selfie.c -o selfie

So, the basic ideas and thoughts are:

  • I'm assuming that the address space is addressed with the dominant integer of the processor,
    32-bit on RISCV32, 64-bit on RISCV64.
  • Provide platform constants when compiling selfie on the host, use a typedef to the one datatype
    (uint32_t or uint64_t). Once built, selfie is only able to run and compile on the same platform
    (I didn't manage to get it capable of cross-compiling).
  • There is a new constant ALIGNBITS (representing the 2^3 or 2^2 when doing pointer
    arithmetic). All other constants where there before and are simply used from outside when
    building the corresponding platforms
  • Another new constand ARCHITECTURE (1=RISCV64, 2=RISCV32) is used to do some setup
    correctly (in set_compile_architecture to populate the compiler with the correct global symbols).
  • There is no need for a pre-processor.
  • target for RISCV32 is RVE32I (with 32 registers), reducing to 16 registers poses some problems
    when allocating registers for certain functions.
  • LW/LD and SW/SD are the only opcodes which differ, I made a pair LX/SX which I'm setting
    correctly depending on the target architecture (same for print_sx, etc.)
  • I didn't go into the SAT-solver or formal verification, things might not be adapted there (I'm
    really not good at this kind of stuff :-) )
  • String constants are padded to 4 or 8 bytes, 8 bits per char
    hard-coded (this looks a little bit like in the 'B' language. Not sure if
    a string library is overkill.
  • the ELF32 and ELF64 headers are constructed in two completely different functions as
    the format is quite different.
  • avoid 32-bit overflow of adress spaces on 32-bit:
    uint32_t VIRTUALMEMORYSIZE = 4294963200; // 4GB - one page of virtual memory
    decrease 2^32 by one PAGE (4k)
  • the makefile has a ARCH variable to build and run the two platforms (make ARCH=RISCV32 and make ARCH=RISCV64). This requires a GNU make.
  • I couldn't test spike yet as 'pk' is not really available (yet) for RISCV32
  • escape.c and hello-world*.c shows trouble ahead with string constants and arithmentic on
    strings. There might be the need for string functions in the library. The registerrize (4, 8)
    should maybe be a REGISTERSIZE available via libcstar.
  • symbolic.c: malloc(4) or malloc(8) => malloc(REGISTERSIZE).
  • As the code differs quite heavily in a diff, there is an easy way to do some sedfu on
    the master version to get a version of selfie.c which is easier comparable to the
    risc32 or risccombi version.
# convert 64 -> 32
sed -i 's/uint64_t/uint32_t/g' 64.c
sed -i 's/SIZEOFUINT64/SIZEOFUINT32/g' 64.c
sed -i 's/SIZEOFUINT64STAR/SIZEOFUINT32STAR/g' 64.c
sed -i 's/UINT64_MAX/UINT32_MAX/g' 64.c
sed -i 's/SD/SW/g' 64.c
sed -i 's/LD/LW/g' 64.c
sed -i 's/_ld/_lw/g' 64.c
sed -i 's/_sd/_sw/g' 64.c
sed -i 's/UINT64_T/UINT32_T/g' 64.c
sed -i 's/UINT64STAR_T/UINT32STAR_T/g' 64.c
sed -i 's/INT64_MAX/INT32_MAX/g' 64.c
sed -i 's/INT64_MIN/INT32_MIN/g' 64.c
sed -i 's/64-bit/32-bit/g' 64.c
sed -i 's/SYM_UINT64/SYM_UINT32/g' 64.c
sed -i 's/F3_LD/F3_LW/g' 64.c
sed -i 's/F3_SD/F3_SW/g' 64.c
# convert 64 -> combi
sed -i 's/uint64_t/uint_t/g' selfie.c
sed -i 's/SIZEOFUINT64/SIZEOFUINT/g' selfie.c
sed -i 's/SIZEOFUINT64STAR/SIZEOFUINTSTAR/g' selfie.c
sed -i 's/UINT64_MAX/UINT_MAX/g' selfie.c
sed -i 's/SD/SX/g' selfie.c
sed -i 's/LD/LX/g' selfie.c
sed -i 's/_ld/_lx/g' selfie.c
sed -i 's/_sd/_sx/g' selfie.c
sed -i 's/UINT64_T/UINT_T/g' selfie.c
sed -i 's/UINT64STAR_T/UINTSTAR_T/g' selfie.c
sed -i 's/INT64_MAX/INT_MAX/g' selfie.c
sed -i 's/INT64_MIN/INT_MIN/g' selfie.c
sed -i 's/SYM_UINT64/SYM_UINT/g' selfie.c
sed -i 's/F3_LD/F3_LX/g' selfie.c
sed -i 's/F3_SD/F3_SX/g' selfie.c
  • Also note: I didn't adapt the risc32 branch.

from selfie.

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.