-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vexriscv SaxonSoc Linux Version #1
Comments
Thanks for you links, I was not aware of them. Great to hear, that the backend is used and more, it is worked on it. |
Hi Michael, |
Hi Paul, |
I was looking at function() quite a bit the other day. I think there may be some double counting in the stack offsets. Take the following C code:
This translates to:
x12 and x13 appear to be saved in the caller's stack frame. Is that what was intended? I would have expected something like:
but it would seem that something different is happening. |
Hi Paul, |
Hi Michael, there is discussion about the progress of the SaxonSoc Linux port on the Ulx3s gitter, if you would like to join in at any time - https://gitter.im/ulx3s/Lobby. Currently I am trying to support a lot of Linux system calls. |
OK, my new understanding is as follows:
If correct, why is x8 (the frame pointer) not saved with the other registers (like x1)? |
The local variables are located above new x8. The x8 location is just caused |
Hi Michael, Paul may know better, but I think the changes that you might want to integrate into the main repository are part of this commit - lawrie@1b5d2e3. There is a one-line change to dof.c which allows the relocation section to be printed. The two-line change to as.c supports ecall. The changes to riscv32.md were experimental and have been reverted. I think the changes to ld.c for elf output are all driven by the -e flag, so you might want to take those. The changes to linux.c are partly specific to the layout we are using on SaxonSoc Linux (LCCDIR) and partly to produce elf output, but they do enable us to compile and link things with The rest of the changes we have made are to the C RTL, and I think that is likely to diverge quite a bit from your version as it uses Linux system calls. There is a further change to ld.c in this commit, but it might be linux-specific - 47c084c |
Hi Michael, Thanks - updated the figure and I think I have it correct now. I am uncertain as why x8 is pointing so low in the stack frame, the LCC front end seems to assume it being at or around "old x2" (args have positive offsets, locals negative). For a moment I thought that RiscV may not support negative displacements, but that is not true. Further to Lawrie's summary above:
Also some general remarks:
What were your plans with this project when you wrote it? Any current plans? |
Hi Paul, hi Lawrie, |
Ah, had not considered the compressed instruction formats and that these indeed only support positive offsets. Now the placement of the x8 frame pointer makes sense. What is the rationale for setting the minimum size of the argument area at 4 when there are no function calls made and at 24 when there are? |
Hi Paul, |
Thanks! And the rationale for 4 when there are no function calls made? Is something else stored there? And a nitpick: in |
I am not aware that the 4 bytes are used, I think it's more an alignment to word size. |
Sorry to keep posting, but another question (and maybe bug report): What if the original maxargoffset is 20? Then it will not get increased to 24 and that may interfere with the variadic code? I realize that the frame will get scaled up to the next multiple of 16, but the register save block locations would still overlap with the minimum argument space that the variadic code expects. (we seem to have a hard to diagnose bug with printf) |
You maybe right, I am not aware of an reason, why the comparison is done with "<16". |
It may be a left over from the MIPS code, which has "if (<16) set to 16" in that spot. I was confused over the minimum 4 size, it is rounded up to 4, i.e. just an alignment thing. I can confirm that calling a variadic function with 4 or 5 arguments (e.g. printf with 3 or 4 arguments after the format string) causes a crash, also in simulation. Changing the comparison to <24 fixes this. The printf issue we had on SaxonSoc seems non-repeatable, which makes it hard to diagnose - it may be different from this bug. I will let you know once I know more. |
Hi Michael, The argument fix seems to have cleared the compiler issues. Still a lot of work in the c library and making it work with RiscV32 Linux. It seems derived from a BSD library, but I cannot quite find the version you used as a base. It seems to sit between 4.3 Reno and 4.4. What base did you use? |
Hi Paul, |
Yes we have that. Currently lcc is working fine on SaxonSoc for small experimental programs. Most of the current effort is rounding out the C library with functions and system calls as and when the need comes up. As an experiment, we let lcc compile its own assembler and that worked out OK. The resulting binary is even a bit smaller than the output of gcc-riscv. I had a quick look at letting lcc compile itself, but was surprised to see that it had compile errors that at first glance were not the result of missing or incompatible include files. Did you try to let lcc-riscv compile its own sources? |
Hi Paul, |
Looking at self-hosting bit by bit. lburg and cpp appear to compile & work. ucpp appears to need work to compile with lcc-riscv. What was the reason for using ucpp instead of the lcc provided cpp? Also wondering about the following. Compiling
whereas compiling
It would seem to me that the code in the target() function in the backend that tries to optimize register x0 as a fixed zero when loading constants is a holdover from MIPS and not really working for the RiscV32 rules, making the generated code worse instead of better. What do you think? |
Hi Paul, |
The chainrule was not the reason, please have a look at the latest change. |
Yeah, that makes sense. Thanks! I haven't worked with lcc in 20+ years (present work excluded) and never with version 4.x, but I read the patch as: |
Correct, this is how the mips port does it, and it also works for riscv32.. |
Thanks Paul and Lawrie. Feel free to reopen it for further discussion. |
I don't know if you are interested but Paul Ruiz (https://gitlab.com/pnru) and myself have got a version of this project working with SaxonSoc Linux in this fork - https://github.com/lawrie/riscv32_lcc
SaxonSoc is a more recent SoC written by @Dolu1990, the author of SpinalHDL, VexRiscv and the Murax SoC, which you use.
We have it running on the hardware of the Ulx3s ECP5 FPGA board, - see recent discussion on https://gitter.im/ulx3s/Lobby.
To make it run on SaxonSoc Linux, ELF output has been added to ld, and risc-v assembler added for crt0.s and syscall.s (replacing syscall.c). A few other changes/fixes have been applied (including a fix to dof to print object files correctly).
It is still work in progress, particularly in the area or the runtime library and system calls.
The text was updated successfully, but these errors were encountered: