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

How could we get the value of the misa register? #710

Closed
zhengxiaolinX opened this issue May 19, 2021 · 4 comments
Closed

How could we get the value of the misa register? #710

zhengxiaolinX opened this issue May 19, 2021 · 4 comments

Comments

@zhengxiaolinX
Copy link

zhengxiaolinX commented May 19, 2021

Hi,

I've tried

int misa;
asm volatile("csrr x0, misa" : "=r" (misa));
printf("%x\n", misa);

and got an An illegal instruction was executed! message in spike. I wonder how can I get the value of this register, or how could we get CPU features of the current simulator, e.g. whether the C extension is supported. Did I get something wrong? I am not so familiar with this, and thanks in advance.

@aswaterman
Copy link
Collaborator

aswaterman commented May 19, 2021

misa is only readable in M-mode. If you are running a user program using pk, your program is running in U-mode, so it is impossible to directly read that register.

@zhengxiaolinX
Copy link
Author

misa is only readable in M-mode. If you are running a user program using pk, your program is running in U-mode, so it is impossible to directly read that register.

Thank you @aswaterman for replying to this!
Just one more question, I wonder how to detect whether the C extension is supported on the current core by using some instructions. Thanks!

@aswaterman
Copy link
Collaborator

There isn't a straightforward way to check. You can try executing a C-extension instruction and see if you get an exception.

On RISC-V Linux, a program's ELF header indicates whether it requires the C extension, and the kernel's ELF loader will refuse to load the program if the processor does not support C.

@zhengxiaolinX
Copy link
Author

zhengxiaolinX commented May 19, 2021

There isn't a straightforward way to check. You can try executing a C-extension instruction and see if you get an exception.

On RISC-V Linux, a program's ELF header indicates whether it requires the C extension, and the kernel's ELF loader will refuse to load the program if the processor does not support C.

Thank you. I really appreciate your help and the details.

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

No branches or pull requests

2 participants