3 ms·
Jonesforth Port to RISC-V
- KMag 6y agoThe original Jonesforth is very cool, and I'm happy it's being ported to RISC-V. However, the in-code documentation[0] clearly has some errors due to blind find-replace: > On the right hand side I've written the actual RISC-V machine code. ... followed by a bunch of 5-byte x86 instructions (E8 followed by 4-byte addresses), and '"E8" is the x86 machine code to "CALL" a function'. > On an RISC-V machine it turns out that we can write this interpreter rather easily, in just two assembly instructions which turn into just 3 bytes of machine code. Uncompressed RISC-V instructions are 4 bytes. Compressed instructions are 2 bytes. Without some completely unanticipated extension that goes against the current design, there will be no way to make a 3-byte instruction sequence for RISC-V. From what I can tell, the actual RISC-V implementation is 4 instructions, .macro NEXT ld a0, 0(s1) addi s1, s1, 8 ld t0, 0(a0) jalr t0 .endm taking 16 bytes on machines that don't support the compressed instructions extension. If all 4 can be compressed, that's still 8 bytes. [0]https://github.com/jjyr/jonesforth_riscv/blob/master/jonesforth.S https://github.com/jjyr/jonesforth_riscv/blob/master/jonesfo...
- fwee 6y agoThanks for correcting. Compared to the original, the documentation is just replaced with some keywords. It needs more works to do to make it a useful tutorial.
- 082349872349872 6y agoWhere there are 3 forthers, there will be 4 FORTHs.
- thu 6y agoWhat a coincidence, I was trying to compile it yesterday but for instance, the `fp` register is not recognized. I can rename it to `s0` (a synonym) but I'm wondering what should I do to avoid this error: jonesforth.S:540: Error: illegal operands `addi fp,fp,-8' Any idea? For those interested, I'm using the nixpkgs cross-toolchain. Some documentation is here[0]. Here is a possible `shell.nix` file content: { pkgs ? import <nixpkgs> {} }: let riscv64-pkgs = import <nixpkgs> { crossSystem = (import <nixpkgs/lib>).systems.examples.riscv64; }; in { riscv64 = riscv64-pkgs.mkShell { buildInputs = [ ]; nativeBuildInputs = [ riscv64-pkgs.buildPackages.gdb ]; }; } This works well enough to compile my hello-world example (available here[1]) but I'd like to use that `fp` register naming... [0]: https://nixos.wiki/wiki/Cross_Compiling https://nixos.wiki/wiki/Cross_Compiling [1]: https://github.com/noteed/riscv-hello-asm https://github.com/noteed/riscv-hello-asm
- rwmj 6y agoFWIW I was able to compile it on RISC-V hardware (the SiFive Unleashed) running recent Fedora. $ make gcc -I /usr/include -I. -g -nostdlib -static -o jonesforth jonesforth.S $ gcc --version gcc (GCC) 10.0.1 20200121 (Red Hat 10.0.1-0.4) $ as --version GNU assembler version 2.34-2.fc32 The tests don't all pass, but the basic system seems to work.
- thu 6y agoBTW, thanks a lot for writing jonesforth.S, it's a joy to read ! I read it a year or two ago, and I was revisiting it these days, hoping to write some RISC-V assembly when I found the repository you just submitted.
- turminal 6y agoLooks amazing, but the fact that `make qemu` uses docker to run qemu and the readme almost (there is a warning about image size) fails to mention it is somewhat off-putting.
- rwmj 6y agoYou probably want to read the original (i386 version) instead if you're using it for learning: https://github.com/nornagon/jonesforth/blob/master/jonesforth.S https://github.com/nornagon/jonesforth/blob/master/jonesfort...