-
-
Notifications
You must be signed in to change notification settings - Fork 170
RISCV support #241
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
Comments
Hello. Definitely, The only possible issues with adding support for RISCV are:
If you're familiar with RISCV and want to help add support for it to this project, you're more than welcome to contribute 😄 |
Lol no I've never done anything with RISCV, I was just wondering if it was possible. But I guess I will fork it and try to do something for RISCV. |
@NathanMcMillan54 assuming the upstream Rust compiler supports the UEFI calling convention on that architecture, yes. It was also necessary to define a target |
Rust doesn't have a |
Same, I haven't done anything with RISCV so this is kinda a bug project for me. |
@orvij I don't care if you make RISCV support and I don't. This issue was really just a question. |
My summer break from school starts at the end of today so I could do literally nothing but work on RISCV support, but you can decide since you seem like you're already working on it. |
Would you not need to modify LLVM for it to generate PE binaries for UEFI? A target file will work but you'll still output ELF. And converting ELF to PE is hacky. |
I've faced some serious issues with LLVM and generating riscv PE/COFF binaries for LLVM, so it would be interesting if it works with Rust. Basically, no matter what I would do llvm would generate an ELF object file for riscv64 uefi and of course fail to link it as a UEFI binary. I've faced this issue both with clang and zig. If someone gets something working, please let me know what you did. |
given my experience your last point is most definitely true: I've never gotten any lang or compiler that uses LLVM to output a riscv PE object. the only solution I've seen employed in the wild is making a custom crt0 in assembly that fakes a PE/COFF header and calls into your code compiled for freestanding, and the whole thing is objcopy'd to a flat binary to expose the PE header. It's not ideal, but it does work |
PE/COFF does support RISC-V (32/64/128). You want to generate a binary for riscv64gc/riscv32gc/riscv128gc, not riscv32/riscv64/riscv128. I don't think LLVM supports this though. |
|
Any update on this? I'm using the bootloader crate from the rust-osdev org and if we can get RISC-V EFI support making that bootloader work with RISC-V would be trivial to do. EFI in general would make life so much easier -- no need to write hacky and nasty asm at all. |
I didn't do any further work on the |
@philipc Yeah you might need to build OVMF. I can't seem to find OvMF for RISC-V in the AUR so I don't know if any other distros have it or not. And I've never built OvMF for anything but x86 so I'd need to poke around but I can probably get you an OVMF image. Maybe. Lol |
I don't think OVMF has been ported for RISC-V yet. At least, https://github.com/riscv-collab/riscv-edk2/tree/master/OvmfPkg doesn't have any relevant commits. It might be possible to use the
|
My current work is at philipc@a8d6c6b. This includes an ELF target for
Those last two commands are in u-boot. It looks like this setup doesn't provide everything that This is all very rough, and I'll clean it up more when I have time, but it'll probably require someone else to do the work to get it integrated here. |
Very nice. It appears that you can't build oVMF for RISCV yet (sad). Using U-boot is an option though. |
I tried to add a target configuration to
where
Any further ideas? |
To be pedantic, |
I'm not clear on why that would never happen. I think adding that support for riscv64+COFF to LLVM is indeed what's needed here, and then adding a riscv64-uefi target to rustc would presumably be reasonably straightforward. |
Fair enough, never is too strong, but it's a lot of work to add riscv64+COFF support to all the places that are required, and that work would need to start somewhere other than in the |
As to where you would start with riscv64+COFF support, it would probably be by adding COFF support in this directory: https://github.com/llvm/llvm-project/tree/main/llvm/lib/Target/RISCV/MCTargetDesc. See other targets for examples. You would need to make your own RISCV COFF relocation definitions, since I don't think anyone has ever used RISCV with COFF before. |
FWIW, in NixOS, I am adding support for OVMF "properly": NixOS/nixpkgs#226485 in order to compile https://github.com/nix-community/lanzaboote for RISCV64GC. I am planning to take a look to adding RISCV COFF relocation defs if I have time (I never did that though in my life.) |
I'm not sure that adding RISCV COFF relocation defs is an option. @luojia65 started on a LLVM patch, and one of the LLVM reviewers said:
|
Uh oh!
There was an error while loading. Please reload this page.
From skimming through this and not looking up anything else, I thought of starting a UEFI application in Rust for RISCV. Could or should this library make support RISCV?
The text was updated successfully, but these errors were encountered: