Skip to content

Initial cut at assembly hybrid / purecap unification. - #2606

Open
qwattash wants to merge 12 commits into
devfrom
cheri-rv64y-asm-refactor
Open

Initial cut at assembly hybrid / purecap unification.#2606
qwattash wants to merge 12 commits into
devfrom
cheri-rv64y-asm-refactor

Conversation

@qwattash

@qwattash qwattash commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Move towards a unified assembly implementation that relies more heavily on compiler aliases and asm.h definitions to abstract away ISAv9-specific bits.

NOTE: requires compiler patches for

@jrtc27
jrtc27 self-requested a review March 20, 2026 01:07

@arichardson arichardson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not managed to review everything in detail but this cleanup is great 👍

Comment thread sys/riscv/riscv/copyinout.S Outdated
sb a4, 0(a1) /* Store byte in dest */
addi a1, a1, 1
#endif
CLB a4, 0(CAP(a0)) /* Load byte from src */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a plain lb here? Or does the compiler not accept that yet?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the same for the other ones

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it appears that aliasing lb to lb.cap is much more involved than anticipated. I think I will leave these definitions here.

Another ways of doing this would be to always mode switch and avoid using .cap instructions at all, but mode switching is more involved in ISAv9 than RVY and I'm worried about perturbation to the hybrid kernel syscall performance measurement.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah did not realize this needed to be hybrid compatible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is a bit annoying. At some point all this will become simpler, hopefully.

Comment thread sys/riscv/riscv/locore.S Outdated
Comment thread libexec/rtld-elf/riscv/rtld_start.S Outdated
@qwattash

Copy link
Copy Markdown
Contributor Author

I think for the purposes of this patch I 'd like to split the ASM unification refactor from the RVY-specific bits, which is admittedly not straightforward because we rely on some of the compiler aliases that make assumptions about the RVY instruction mnemonics.

In the RVY branch I have macros for all the capability instructions. One of the reasons for splitting the patches is that those macros should be relatively easy to revert and replace with compiler aliases once we have the frozen mnemonics.

Another thing I'd like to do here is to pretend that xxx.cap instructions don't exist and instead have a mode-switch, in the same way we would do on RVY. The problem with that is that on ISAv9 it adds a significant number of instructions in some cases (like fuword/fuecap).

@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from fb8b664 to 09b28bc Compare March 23, 2026 15:32
@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from 09b28bc to d1dd6e8 Compare April 1, 2026 12:19
@qwattash
qwattash marked this pull request as ready for review April 1, 2026 12:20
@qwattash
qwattash requested review from brooksdavis and bsdjhb April 1, 2026 12:20
@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from d1dd6e8 to 480d75a Compare April 1, 2026 14:28
@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from bcc3863 to 34a0120 Compare May 9, 2026 10:45

@brooksdavis brooksdavis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple comments before I get on a flight without wifi. I've made it up do "cheri riscv: Implement MODESW macros"

Comment thread lib/libc/riscv/gen/setjmp.S Outdated
Comment thread sys/riscv/riscv/locore.S Outdated
Comment thread lib/libc/riscv/gen/setjmp.S Outdated
@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from 34a0120 to 2675da5 Compare May 19, 2026 10:11
Comment thread lib/libsys/riscv/cerror.S Outdated

@arichardson arichardson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great but we will need to use something like ADD_PTR for RVY compatibility

Comment thread lib/libc/riscv/gen/_setjmp.S Outdated
Comment thread lib/libc/riscv/gen/_setjmp.S Outdated
Comment thread lib/libc/riscv/gen/_setjmp.S Outdated
Comment thread lib/libc/riscv/gen/_setjmp.S Outdated
Comment thread lib/libc/riscv/gen/_setjmp.S Outdated
Comment thread lib/libc/riscv/gen/setjmp.S Outdated
Comment thread sys/riscv/include/asm.h
Comment thread sys/riscv/include/asm.h Outdated
Comment thread sys/riscv/riscv/locore.S Outdated
csetaddr CAP(t1), CAP(t1), t0
li t0, 1
csetflags CAP(t1), CAP(t1), t0
cspecialw stcc, ct1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could write to ct0 and then share the set_stvec between modes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to see if I can simplify this with some LLVM support, which we would need to replace cspecialrw with csrrrw

@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from 2675da5 to 7ab8cfb Compare June 25, 2026 07:39
@qwattash

Copy link
Copy Markdown
Contributor Author

The CSR story is still a bit sad here, as I can't easily use csrrw for xcheri without more compiler changes. This could be done, I think, in the same way Zcheri LLVM.

@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch 2 times, most recently from 285c65f to 822d3be Compare June 25, 2026 14:54
@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from 822d3be to 2fec88b Compare July 28, 2026 17:07
qwattash added 8 commits July 28, 2026 18:29
Unify copyin/out assembly for hybrid and purecap.
Use the new machine/asm.h macros and rely on complier mnemonic aliases.
Unify support.S assembly for hybrid and purecap.
Rely on asm.h macros and compiler mnemonic aliases.

Partial patch, no csr registers yet.
Unify locore assembly for hybrid and purecap.
This reduces the amount of ifdefs and relies on both
asm.h definitions and compilier mnemonic aliases.
Unify context switch assembly hybrid and purecap.
Rely on asm.h and compiler mnemonic aliases.
Unify hybrid and purecap assembly for exception handling.
Rely on compiler mnemonic aliases and asm.h macros.
Unify bus space assembly for hybrid and purecap.
Comment thread sys/riscv/riscv/sigtramp.S
Comment thread sys/riscv/include/asm.h Outdated
Comment thread sys/riscv/include/asm.h
#define ADD_CAP yadd
#define ADDI_CAP yaddi
/* Note: xcheri */
#define MODESW_CAP(tmp, tmp1) \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should distinguish between modesw that are always enabled and those that only exist when building for hybrid. Most of them really exist only for hybrid.

qwattash added 4 commits July 28, 2026 21:11
These are used to abstract away switching between hybrid and purecap
encodings in the hybrid kernel.
This patch facilitates migration to cheri-rv64y.
@qwattash
qwattash force-pushed the cheri-rv64y-asm-refactor branch from 2fec88b to 5d562e9 Compare July 28, 2026 20:18
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.

4 participants