Skip to content
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

feat: add 64-bit RISC-V support #441

Merged
merged 1 commit into from
Nov 2, 2023
Merged

Conversation

mkroening
Copy link
Member

@mkroening mkroening commented Jul 20, 2023

This is a rebase and squash of simonschoening@4768570.

This is using the riscv64gc-unknown-hermit target from hermitcore/rust/riscv64gc-unknown-hermit.

CC: @simonschoening

@mkroening mkroening force-pushed the riscv branch 7 times, most recently from e1cd2d8 to d687904 Compare July 20, 2023 15:16
@simonschoening
Copy link
Contributor

I actually found my old files and there seem to be local changes that I did not yet commit.

I will try to commit and push all changes as soon as possible and explain how to run the examples with QEMU.

While trying out the code with a current QEMU version I also ran into a page fault.
After some debugging I found out that the fault was caused by setting the Accessed and Dirty Flags for non-leaf page table entries. These flags are reserved for future use and should not be set. Newer versions of the RISC-V specifications require the implementation (e. g. QEMU) to raise a page-fault exception when one of those bits is set. I will also commit the fix for this bug to libhermit-rs.

@mkroening
Copy link
Member Author

mkroening commented Jul 21, 2023

I will try to commit and push all changes as soon as possible and explain how to run the examples with QEMU.

For me, rusty-demo runs fine. :)
No page faults and successful shutdown on QEMU 8.0.3.

Getting your fixes would be wonderful, but I assume they will be easy to apply on a rebased version of your work?
That way, I can continue rebasing and adjusting your code to my changes, and you can improve your old code at the same time.
I'll wait for you before merging anything.
What do you think? :)

Edit: The kernel does not compile when enabling network (tries to do a bunch of x86-specific pci and rtl network card stuff) if that's what you mean.

@mkroening mkroening changed the title Add riscv64 support Add 64-bit RISC-V support Jul 21, 2023
@mkroening mkroening force-pushed the riscv branch 12 times, most recently from 7656297 to c08bc87 Compare July 22, 2023 14:04
@simonschoening
Copy link
Contributor

simonschoening commented Jul 24, 2023

Yes, the fix for the page table is very simple and should be easy to apply.

The local changes I mentioned were unfinished rebases of libhermit-rs and rusty-hermit. The rebase of libhermit-rs can be found here: https://github.com/simonschoening/libhermit-rs/tree/riscv_rebase), but I think the "riscv_neu" branch is more recent. I also tried to rebase the rusty-hermit repository using a JSON file to define the target (https://github.com/simonschoening/rusty-hermit/tree/riscv_rebase). But this will not be necessary since the riscv64gc-unknown-hermit target was already merged?

I really would like to try out your rebase. What command do you use to compile the examples?

About networking: The pci feature never worked, I always used --no-default-features --features smp,tcp.

To build and run the https://github.com/simonschoening/rusty-hermit/tree/riscv_rebase repository, the following commands should work:
HERMIT_LOG_LEVEL_FILTER=Info cargo build -Z build-std=std,core,alloc,panic_abort -Z build-std-features=compiler-builtins-mem --target ./targets/riscv64gc-unknown-hermit.json --no-default-features --features smp,tcp

qemu-system-riscv64 -cpu rv64 -machine virt -nographic -m 2048 -smp 4 -kernel loader/target/riscv64imac-unknown-none-elf/debug/rusty-loader -initrd target/riscv64gc-unknown-hermit/debug/httpd -global virtio-mmio.force-legacy=off -netdev tap,id=tap10,ifname=tap10,script=no,downscript=no -device virtio-net-device,netdev=tap10

The loader can be build with cargo build --target riscv64imac-unknown-none-elf.

@mkroening
Copy link
Member Author

Thanks for your reply! :)

hermit-os/kernel#800 is my rebase of your riscv_neu with quite a few adjustments. Together some loader version of yours, that I built (haven't got into the loader yet), this runs rusty_demo (without any enabled crate features) successfully.

To reproduce, build the latest Rust commit (RISC-V target is merged now, and you are a contributor to the Rust compiler 🥳). A description is now live at *-unknown-hermit - The rustc book.
For building rusty_demo, I used the following command:

cargo +dev1 build \
    --target riscv64gc-unknown-hermit \
    --no-default-features \
    --package rusty_demo

This assumes the newly built Rust toolchain registered as dev1, and my kernel PR checked out. This PR should not matter, since it got very small.

Regarding SMP: This seems stubbed, right? So no real SMP support in riscv_neu, right? See simonschoening/libhermit-rs/riscv_neu/src/lib.rs#L357.

Regarding networking: I did not test that yet, but I'll give your config a try. We moved the TCP stack into the kernel meanwhile, so maybe some things broke during my rebase, but maybe not. 🤷

Anyway, I'll be busy with other stuff for the next two weeks, but after that, I'll work on this again. :)

Please don't hesitate to reach out if you have further questions. :)

@simonschoening
Copy link
Contributor

simonschoening commented Jul 25, 2023

SMP should work, I moved the add_current_core call : https://github.com/simonschoening/libhermit-rs/blob/011b34df2eb5e0f6c9ee3cd652a1644f1b9a27d7/src/arch/riscv/kernel/mod.rs#L274.

I can't remember the reason behind this. Maybe there is no technical reason at all 😅 .

@mkroening
Copy link
Member Author

Ah, good to know. :)

@mkroening mkroening force-pushed the riscv branch 2 times, most recently from 72f37d6 to 77ba183 Compare August 8, 2023 13:04
@mkroening mkroening changed the title Add 64-bit RISC-V support feat: add 64-bit RISC-V support Aug 11, 2023
Co-authored-by: Martin Kröning <[email protected]>
Signed-off-by: Martin Kröning <[email protected]>
@mkroening mkroening marked this pull request as ready for review November 2, 2023 15:47
@mkroening mkroening added this pull request to the merge queue Nov 2, 2023
@mkroening mkroening self-assigned this Nov 2, 2023
Merged via the queue into hermit-os:main with commit ddc15ee Nov 2, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants