.globl query_bitness
.type query_bitness, @function
.equ MISA, 0x301 #hardware dependent address of MISA register (0x301 for Longan Nano)
--
query_bitness:
csrr t2, MISA #reads MISA register with a system register reading pseudocode command
beqz t2, no_avail #if the register is empty, branch to no_avail
lui t3, 0xC0000 #value 11000000... LUI writes to the highest 20-bits
bgeu t2, t3, is_128 #if MISA is higher or equal than t3's value, must be 128-bit
lui t3, 0x80000 #value 10000000...
bgeu t2, t3, is_64 #if MISA is higher than new t3 value, must be 64-bit
li a0, 32 #otherwise it's 32-bit, a0 is return value's register
jr ra #jump to return address
no_avail:
li a0, 0
jr ra
is_128:
li a0, 128
jr ra
is_64:
li a0, 64
jr ra