Re: Definition of the CSRs

From: Mitchell Horne <mhorne_at_freebsd.org>
Date: Mon, 06 Jan 2025 18:51:55 UTC

On 12/23/24 07:35, Himanshu Chauhan wrote:
> 
> 
>> On 23 Dec 2024, at 16:55, Himanshu Chauhan <himanshu@thechauhan.dev> wrote:
>>
>> Hi,
>>
>> I see the following in the code:
>>
>> csr_read(sstatus)
>> csr_read(stval)
>>
>> But I can’t figure out where these sstatus and stval are defined. I want to define CSRs for IMSIC. I am using hard coded values for now but want to get rid of them. How can I do that?
>>

The given argument is used plainly as the CSR name in the resulting 
instruction.

e.g.:

register_t sstatus = csr_read(sstatus);

becomes:

csrr a0, sstatus

So there is no need to define CSRs based on index, at present. You can 
just use its name.

Cheers,
Mitchell

> 
> Something like this in my C file works okay:
> 
> #define IMSIC_CSR_SISELECT      0x150
> #define IMSIC_CSR_SIREG            0x151
> #define IMSIC_CSR_STOPEI          0x15c
> #define IMSIC_CSR_STOPI            0xdb0
> 
> #ifdef DECLARE_CSR
> DECLARE_CSR(siselect, IMSIC_SISELCT)
> DECLARE_CSR(sireg, IMSIC_SIREG)
> DECLARE_CSR(stopei, IMSIC_STOPEI)
> DECLARE_CSR(stopi, IMSIC_STOPI)
> #endif
> 
> Is this the right way to do it?
> 
>> Regards
>> Himanshu
>>
> 
>