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

eir/riscv: Add ISA checks for RVA22 compliance #753

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marv7000
Copy link
Contributor

This PR adds a check in initProcessorEarly for riscv64 to confirm that the machine we're running on is actually RVA22 compliant and can execute thor.

@marv7000 marv7000 marked this pull request as ready for review November 17, 2024 01:35
Comment on lines 10 to 13
// All bits need to be enabled to ensure RVA22 compliance
struct RiscVBits {
bool i, m, a, f, d, c, zicsr, zicntr, ziccif, ziccrse, ziccamoa, zicclsm, za64rs, zihpm, zihintpause, zic64b, zicbom, zicbop, zicboz;
};
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be nicer to use an enum to assign an index to these extensions. Then we can use a boolean array with n entries instead of n separate bools.

That would also simplify the if (!(bits.i && bits.m && bits.a && bits.f && bits.d && bits.c && bits.zicsr && bits.zicntr && bits.ziccif && bits.ziccrse && bits.ziccamoa && bits.zicclsm && bits.za64rs && bits.zihpm && bits.zihintpause && bits.zic64b && bits.zicbom && bits.zicbop && bits.zicboz)) (e.g., you could use a loop or std::all_of to check against a static array of extensions needed for RVA22).

if (total >= data_.size())
return frg::null_opt;
}
return frg::string_view{off total};
Copy link
Member

Choose a reason for hiding this comment

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

This does not do a bounds check - I guess we'd need to do something like strnlen(off total, data_.size() - total).

@@ -192,6 194,17 @@ struct DeviceTreeProperty {
return v.load();
}

frg::optional<frg::string_view> asString(size_t index = 0) {
size_t total = 0;
const char* off = reinterpret_cast<const char*>(data_.data());
Copy link
Member

Choose a reason for hiding this comment

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

We right-align pointers :^)

return frg::string_view(node.name()) == "cpus";
}, [&](auto cpus) {
cpus.discoverSubnodes([](auto node) {
return frg::string_view(node.name()).starts_with("cpu@");
Copy link
Member

Choose a reason for hiding this comment

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

This logic is probably fine for now where we'll assume all cores support the same set of base extensions, but it might be nice to look for the correct one using the HART ID that gets provided by the boot protocol somehow - on UEFI, it's a configuration table (RISCV_EFI_BOOT_PROTOCOL, GUID { 0xccd15fec, 0x6f73, 0x4eec, { 0x83, 0x95, 0x3e, 0x69, 0xe4, 0xb9, 0x40, 0xbf } })

bits.zicsr && bits.zicntr && bits.ziccif && bits.ziccrse &&
bits.ziccamoa && bits.zicclsm && bits.za64rs && bits.zihpm &&
bits.zihintpause && bits.zic64b && bits.zicbom && bits.zicbop && bits.zicboz)) {
panicLogger() << "Processor doesn't support all RVA22 extensions!" << frg::endlog;
Copy link
Member

Choose a reason for hiding this comment

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

required

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.

3 participants