mirror of
https://github.com/Fishwaldo/opensbi.git
synced 2025-06-28 17:18:37 +00:00
lib: Fix CPU capabilities detection function
On some platforms, misa may not be implemented. On such a platform, reading misa will get 0. At this time, platform is required to implement a non-standard function to detect the CPU's capabilities. Therefore, this modification add interfaces for non-standard function. The MXL field of misa is always at the highest two bits, whether it is a 32-bit 64-bit or a 128-bit machine. Therefore, this modification fixes the use of a fixed offset to detect the machine length. Signed-off-by: Xiang Wang <merle@hardenedlinux.org> Signed-off-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
parent
75f903dd78
commit
c96cc03fcc
4 changed files with 89 additions and 12 deletions
|
@ -159,22 +159,18 @@ void csr_write_num(int csr_num, unsigned long val);
|
|||
__asm__ __volatile__("wfi" ::: "memory"); \
|
||||
} while (0)
|
||||
|
||||
static inline int misa_extension(char ext)
|
||||
{
|
||||
return csr_read(CSR_MISA) & (1 << (ext - 'A'));
|
||||
}
|
||||
/* Determine CPU extension, return non-zero support */
|
||||
int misa_extension(char ext);
|
||||
|
||||
static inline int misa_xlen(void)
|
||||
{
|
||||
return ((long)csr_read(CSR_MISA) < 0) ? 64 : 32;
|
||||
}
|
||||
/* Get MXL field of misa, return -1 on error */
|
||||
int misa_xlen(void);
|
||||
|
||||
static inline void misa_string(char *out, unsigned int out_sz)
|
||||
{
|
||||
unsigned long i, val = csr_read(CSR_MISA);
|
||||
unsigned long i;
|
||||
|
||||
for (i = 0; i < 26; i++) {
|
||||
if (val & (1 << i)) {
|
||||
if (misa_extension('A' + i)) {
|
||||
*out = 'A' + i;
|
||||
out++;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue