Skip to content

ume: Add interpolation to rv64ume and custom template tags#834

Open
arcane-quill wants to merge 18 commits into
masterfrom
wip/ume-viam-def
Open

ume: Add interpolation to rv64ume and custom template tags#834
arcane-quill wants to merge 18 commits into
masterfrom
wip/ume-viam-def

Conversation

@arcane-quill
Copy link
Copy Markdown

@arcane-quill arcane-quill commented Mar 22, 2026

PR for issue #757 (and #761, #759)
interpolated hardcoded rv64ume files from linux-user
created UmeHardcodedRiscvDefinitionPass and UmeTemplateRenderingPass to add custom template tags (e.g. registers, exceptions..) with hardcoded values that later get filled in by the vadl file
added VIAM definition UserModeEmulation

@flofriday
Copy link
Copy Markdown
Contributor

flofriday commented Mar 22, 2026

I think the branch of this PR isn't cleanly based on a fresh master, because it contains some of my commits that are already on master.

So let's rebase on master with (on your branch):

git fetch
git rebase origin/master

There might be some conflicts but if you execute these commands in IntelliJ you'll get some help resolving the conflicts in a nice UI. 😉

@arcane-quill
Copy link
Copy Markdown
Author

I think the branch of this PR isn't cleanly based on a fresh master, because it contains some of my commits that are already on master.

So let's rebase on master with (on your branch):

git fetch
git rebase origin/master

There might be some conflicts but if you execute these commands in IntelliJ you'll get some help resolving the conflicts in a nice UI. 😉

I tried to rebase twice now but it doesnt seem to be fixed @flofriday

@flofriday
Copy link
Copy Markdown
Contributor

Yeah sometimes rebasing still contains some weired artifacts, but I just tried it on my machine and it (mostly) worked. I'll send you a DM (on matrix), let's figure it out there.

@arcane-quill arcane-quill force-pushed the wip/ume-viam-def branch 2 times, most recently from ce9eaf4 to 0d64625 Compare March 22, 2026 19:08
@arcane-quill arcane-quill changed the title Wip/ume viam def ume: Add interpolation to rv64ume and custom template tags Mar 23, 2026
@arcane-quill arcane-quill force-pushed the wip/ume-viam-def branch 2 times, most recently from 4d6afb8 to f54e597 Compare April 12, 2026 01:50
Comment thread vadl/main/vadl/ast/AstVisitor.java
Copy link
Copy Markdown
Contributor

@Jozott00 Jozott00 left a comment

Choose a reason for hiding this comment

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

Unfortunately the current state is too RISC-V specific and needs an overhaul. Please take a closer look at other VIAM definitions and how they are handled in the code emission.

Comment thread vadl/main/resources/templates/iss/linux-user/gen-arch/cpu_loop.c
Comment thread vadl/main/resources/templates/iss/linux-user/gen-arch/cpu_loop.c Outdated
Comment thread vadl/main/resources/templates/iss/linux-user/gen-arch/cpu_loop.c Outdated
Comment thread vadl/main/resources/templates/iss/linux-user/gen-arch/cpu_loop.c Outdated
Comment thread vadl/main/resources/templates/iss/linux-user/gen-arch/signal.c Outdated
Comment thread vadl/main/resources/templates/iss/linux-user/gen-arch/signal.c Outdated
Comment thread vadl/main/vadl/iss/passes/UmeTemplateRenderingPass.java Outdated
Comment thread vadl/main/vadl/pass/PassOrders.java Outdated
Comment thread vadl/main/vadl/viam/UserModeEmulation.java Outdated
Comment thread vadl/main/vadl/viam/UserModeEmulation.java Outdated
@arcane-quill
Copy link
Copy Markdown
Author

Unfortunately the current state is too RISC-V specific and needs an overhaul. Please take a closer look at other VIAM definitions and how they are handled in the code emission.

Thanks for the extensive review, I'm working on it now

@arcane-quill
Copy link
Copy Markdown
Author

hi @Jozott00 I resolved the stuff that was missing, hopefully we can get this merged now

and do u know why passorders keeps telling me there is a merge conflict despite none of it showing up locally, even after rebasing?

@arcane-quill arcane-quill requested a review from Jozott00 May 9, 2026 10:55
@flofriday
Copy link
Copy Markdown
Contributor

flofriday commented May 9, 2026

and do u know why passorders keeps telling me there is a merge conflict despite none of it showing up locally, even after rebasing?

Mostly guesses here but I assume you are not syncing your local branches with the remote (GitHub).

For example

git rebase master

Isn't good enough to rebase with the newest changes from GitHub.
This is mostly because master on your machine isn't updated and is stuck on an old commit.

The long way is to do:

git checkout master
git pull # (download from the remote, and also update the current master branch to the newest version from the remote)
git checkout <your-branch>
git rebase master

But you can even shorten this a bit with

git fetch # Downloads the branches from the remote but does not update the local branches only the branches prefixed with origin will be updated, so master is still stuck on an old commit but origin/master is synced with the remote
git rebase origin/master

Copy link
Copy Markdown
Contributor

@Jozott00 Jozott00 left a comment

Choose a reason for hiding this comment

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

I think there are still some important things to change. Mostly, what and how the VIAM definition stores specification details.

I also think, that we should reduce the scope for the PR a bit, as signals are just a bit too much to start with. Therefore, let's completely remove all logic that is related to signals.

The UME generation requires quite a bit of information from the ABI definition and could share some constructs (like alias registers and special register references). Therefore, I will do a little ABI refactoring, so you can use RegisterRef instead of defining you own RegisterLocation as mentioned in a comment below.

EDIT: Also note, that this PR won't fully close #761 as there is still RISC-V specific stuff in the template files.


private final Identifier excCauseVar;
private final RegisterTensor mainRegisterFile;
private final RegisterUtils.Register sysReg;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

major: Using vadl.lcb.templateUtils.RegisterUtils.Register is the wrong abstraction

First, it is part of the LCB and should not be referenced by the vadl.viam package, second, it is a rendering utility, not a VIAM construct. It does not contain the original RegisterTensor and has exactly one index.

Instead, add a new class in the vadl.viam package:

public record RegisterLocation(
    RegisterResource resource,
    List<Constant.Value> indices,
    SourceLocation location
) implements WithLocation {
}

And use it instead. This will model those register references/locations much better and remains generic.

private final ExceptionDef breakpointExcName;
private final ExceptionDef illegalInstrExcName;
private final Identifier initialPc;
private final Identifier initialSp;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: What is the initialPC and initialSp? Can you give me an example, cause I am confused how its value can be represented as Identifier.

From what I understand, this can be removed, as it can be synthesized later by the generator.

Comment on lines +83 to +89
if (args == null || args.isEmpty()) {
throw new IllegalArgumentException("args must not be null/empty");
}

if (excIds == null || excIds.isEmpty()) {
throw new IllegalArgumentException("excIds must not be null/empty");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: We use nullaway, so null checking of arguments that are not annoated with @Nullable isn't necessary.

Comment on lines +83 to +89
if (args == null || args.isEmpty()) {
throw new IllegalArgumentException("args must not be null/empty");
}

if (excIds == null || excIds.isEmpty()) {
throw new IllegalArgumentException("excIds must not be null/empty");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: Is there a reason why you require the args to be non-empty? From the generator side, it shouldn't matter if there is any argument.

private final Map<String, Integer> excIds;
private final Instruction syscallInstr;
private final ExceptionDef syscallException;
private final ExceptionDef breakpointExcName;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: Should be breakpointExc instead of breakpointExcName

(same below)

Comment on lines +60 to +74
[# th:if="${config.hasIcacheFlush}"]
if (env->[(${config.mainRegisterFile})][ [(${config.sysReg})] ] == TARGET_NR_[(${gen_arch_lower})]_flush_icache) {
/* no-op in QEMU; TB invalidation is automatic */
ret = 0;
} else {
[/]
ret = do_syscall(env,
env->x[RV64UME_REG_A7],
env->x[RV64UME_REG_A0],
env->x[RV64UME_REG_A1],
env->x[RV64UME_REG_A2],
env->x[RV64UME_REG_A3],
env->x[RV64UME_REG_A4],
env->x[RV64UME_REG_A5],
0, 0);
env->[(${config.mainRegisterFile})][ [(${config.sysReg})] ],
[# th:each="arg : ${config.args}"]
env->[(${config.mainRegisterFile})][ [(${arg})] ],
[/]
0, 0);
[# th:if="${config.hasIcacheFlush}"]
}
[/]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

major: Just assume there is no icache-flush

exit(EXIT_FAILURE);
}
[/]
[# th:if="${#strings.isEmpty(config.excCauseVar)}"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

major: This check is unnecessary, as exceptions in the ISS are always rendered as cause variables in the state.

env->pc = regs->sepc;
env->x[RV64UME_REG_SP] = regs->sp;
env->[(${pc_reg.name_lower})] = regs->[(${config.initialPc})];
env->[(${config.mainRegisterFile})][ [(${config.spReg})] ] = regs->[(${config.initalSp})];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

major: As we just hardcode the target_pt_regs anyway, just use regs->pc and regs->sp instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: This whole table is currently hardcoded. However, I think we should do the dynamic interpolation in a separate PR.

if (inputPath != null && inputPath.getFileName().endsWith("rv64ume.vadl")) {
order
.add(new UmeHardcodedRiscvDefinitionPass(config))
.add(new UmeTemplateRenderingPass(config, "cpu_loop.c"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

major: The cpu_loop.c is now emitted twice

Jozott00 added a commit that referenced this pull request May 11, 2026
…` interface (#948)

This PR extracts most of the `Abi.RegisterRef` to
`vadl.viam.RegisterRef`, so the datastructure can be reused in other
definitions like the UME (#834).

Additionally, it removes the `GeneratesRegisterFileName` which does not
fit into the VIAM hierarchy and is already covered by the
`RegisterResource` class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

frontend This is frontend related iss This is ISS related lcb This is LCB related

Projects

None yet

3 participants