-
Notifications
You must be signed in to change notification settings - Fork 185
add a bunch of setter for mstatus #77
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
Conversation
src/register/mstatus.rs
Outdated
impl Mstatus { | ||
/// User Interrupt Enable | ||
#[inline] | ||
pub fn set_uie(&mut self, value: bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very rusty atm (pun not intended) not being working on these things for some time, but shouldn't these setters be unsafe
to not hide the fact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emmm, these does not actually change the mstatus
register, these just change the bits
field in the Mstatus
structure.
I do not think an unsafe
is necessary.
I'm not sure if I followed you correctly, could you please elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for the use case like, you want to store mstatus
in a context, but you do not want to actually change the mstatus
register.
So you can set up Mstatus
struct and use asmebly or perhaps a new function to write the Mstatus
into the mstatus
register later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, your original statement But I do concern about the amibigiouty of these instance method comparing to the register setters.
makes perfect sense now :D I guess I fell into that trap nicely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
XD, So do you think this is a good add-on?
I'm not so sure, but I do feel this useful and makes my code more clear when writing code.
After all, without this, you can only write something like
let later_mstatus = flag_A | flag_B;
/* a bunch of code */
asm!("
csrw mstatus, a0
mret
")
which is tedious, and too much like C.
Perhaps we need a better naming for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to de-confuse this somehow.
Right now the mstatus::set_mpp(MPP)
and your mstatus::set_mpp(&mut self, MPP)
are just too confusing (just to provide an example).
Maybe the methods that don't apply should be called something else, more obvious to keep things clear. I'm not quite sure about the naming tho. Perhaps bitset
instead of set
prefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bitset
is pretty good, as it is similar to the bit_field
naming.
I also added a new method called apply
to apply the changes in self.bits
to the actual mstatus
register and added a bunch of comments in the latest commit.
If this is ok, I'd like to add this bitset
for other registers, like mideleg
and medeleg
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Disasm any strong opinions? I'm inclined to think this is good now
…d an function to apply the bits into register
I think these methods are confusing as they don't modify the CSR until you call
|
emmmm, I hope to have something that will not take immediate effect in the |
@Disasm |
Sorry, I don't understand your use case. Why do you need to store the mstatus value for a long time? Why not set all the bits when you need it? And if you need to save/restore mstatus, you don't even need the setters, you can save the raw value. |
@Disasm Yes, I can save the raw value but it will look like
and that is what I hope to avoid as it is easy to make mistake setting these raw values. |
I'm not sure we should use |
Co-authored-by: Vadim Kaushan <[email protected]>
I don't know, is there similar cases like ours? |
Is |
What if we introduce a We won't need to change |
Great Idea, I'll see what I can do. |
I'm not sure if it changes too much, if we take this approach, the But I do concern this will have compatibility issue. |
May be a PR for other registers like |
It might not be a good idea to remove let mut mstatus_value: MstatusValue = mstatus::read().into();
mstatus_value.set_mie();
mstatus::write(mstatus_value.into()); |
Yes that's what I was aiming for. As a side note, maybe name it |
If it's for compatibility, then I think |
I will rework on this issue.
|
77: use --target for CI checks r=Disasm a=almindor Co-authored-by: Ales Katona <[email protected]>
As the inner structure of
Mstatus
is private, it's inconvient to prepare/keep track of amstatus
for a certain kind of supervisor runtime.Especially when prepare for
mstatus
, if the interrupt bit likeMIE
is enabled, then a interrupt maybe triggered unwantedly.So I think it's maybe a good idea to add some setter for these fields.
But I do concern about the amibigiouty of these instance method comparing to the register setters.