Skip to content

Commit

Permalink
Merge pull request #608 from betrusted-io/coreuser
Browse files Browse the repository at this point in the history
add updated register profile to include the coreuser block
  • Loading branch information
bunnie authored Dec 24, 2024
2 parents 261c5eb + b745307 commit bb09856
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 1 deletion.
148 changes: 147 additions & 1 deletion utralib/cramium/core.svd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2024-12-21 21:24:42]]></description>
<description><![CDATA[Litex SoC 2024-12-25 06:02:35]]></description>

<addressUnitBits>8</addressUnitBits>
<width>32</width>
Expand Down Expand Up @@ -265,6 +265,152 @@ register to disable individual events.]]></description>
<value>21</value>
</interrupt>
</peripheral>
<peripheral>
<name>COREUSER</name>
<baseAddress>0xE0002000</baseAddress>
<groupName>COREUSER</groupName>
<registers>
<register>
<name>CONTROL</name>
<addressOffset>0x0000</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>enable</name>
<msb>0</msb>
<bitRange>[0:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[When set to `1`, mappings are enabled. When `0`, the `CoreUser` value is fixed
to an 8-bit `1` value]]></description>
</field>
<field>
<name>use8bit</name>
<msb>1</msb>
<bitRange>[1:1]</bitRange>
<lsb>1</lsb>
<description><![CDATA[When set to `1`, use the 8-bit version of ASID for `CoreUser`. When `0`, map
`CoreUser value to 1 bit]]></description>
</field>
<field>
<name>shift</name>
<msb>4</msb>
<bitRange>[4:2]</bitRange>
<lsb>2</lsb>
<description><![CDATA[Sets the bit-shift for the 1-bit mapping of `CoreUser`. This field refers
directly to the bit position, and defaults to bit `0`]]></description>
</field>
<field>
<name>privilege</name>
<msb>5</msb>
<bitRange>[5:5]</bitRange>
<lsb>5</lsb>
<description><![CDATA[When set to `1`, requires the current privilege state to match that specified in
`set_privilege.mpp`]]></description>
</field>
<field>
<name>mpp</name>
<msb>7</msb>
<bitRange>[7:6]</bitRange>
<lsb>6</lsb>
<description><![CDATA[Value of `mpp` bit from `mstatus` that must match for code to be trusted]]></description>
</field>
</fields>
</register>
<register>
<name>STATUS</name>
<addressOffset>0x0004</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>coreuser</name>
<msb>7</msb>
<bitRange>[7:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Computed value of the `CoreUser` signal as passed on to the SoC. For debugging.]]></description>
</field>
</fields>
</register>
<register>
<name>MAP_LO</name>
<addressOffset>0x0008</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>lut0</name>
<msb>7</msb>
<bitRange>[7:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
<field>
<name>lut1</name>
<msb>15</msb>
<bitRange>[15:8]</bitRange>
<lsb>8</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
<field>
<name>lut2</name>
<msb>23</msb>
<bitRange>[23:16]</bitRange>
<lsb>16</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
<field>
<name>lut3</name>
<msb>31</msb>
<bitRange>[31:24]</bitRange>
<lsb>24</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
</fields>
</register>
<register>
<name>MAP_HI</name>
<addressOffset>0x000c</addressOffset>
<resetValue>0x00</resetValue>
<size>32</size>
<fields>
<field>
<name>lut4</name>
<msb>7</msb>
<bitRange>[7:0]</bitRange>
<lsb>0</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
<field>
<name>lut5</name>
<msb>15</msb>
<bitRange>[15:8]</bitRange>
<lsb>8</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
<field>
<name>lut6</name>
<msb>23</msb>
<bitRange>[23:16]</bitRange>
<lsb>16</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
<field>
<name>lut7</name>
<msb>31</msb>
<bitRange>[31:24]</bitRange>
<lsb>24</lsb>
<description><![CDATA[Value of `CoreUser` ASID]]></description>
</field>
</fields>
</register>
</registers>
<addressBlock>
<offset>0</offset>
<size>0x10</size>
<usage>registers</usage>
</addressBlock>
</peripheral>
<peripheral>
<name>CSRTEST</name>
<baseAddress>0xE0003000</baseAddress>
Expand Down
118 changes: 118 additions & 0 deletions utralib/src/generated/cramium_soc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ pub const HW_BIO_FIFO3_MEM_LEN: usize = 4096;
// Physical base addresses of registers
pub const HW_D11CTIME_BASE : usize = 0xe0000000;
pub const HW_SUSRES_BASE : usize = 0xe0001000;
pub const HW_COREUSER_BASE : usize = 0xe0002000;
pub const HW_CSRTEST_BASE : usize = 0xe0003000;
pub const HW_IRQARRAY0_BASE : usize = 0xe0004000;
pub const HW_IRQARRAY1_BASE : usize = 0xe0005000;
Expand Down Expand Up @@ -489,6 +490,34 @@ pub mod utra {
pub const HW_SUSRES_BASE: usize = 0xe0001000;
}

pub mod coreuser {
pub const COREUSER_NUMREGS: usize = 4;

pub const CONTROL: crate::Register = crate::Register::new(0, 0xff);
pub const CONTROL_ENABLE: crate::Field = crate::Field::new(1, 0, CONTROL);
pub const CONTROL_USE8BIT: crate::Field = crate::Field::new(1, 1, CONTROL);
pub const CONTROL_SHIFT: crate::Field = crate::Field::new(3, 2, CONTROL);
pub const CONTROL_PRIVILEGE: crate::Field = crate::Field::new(1, 5, CONTROL);
pub const CONTROL_MPP: crate::Field = crate::Field::new(2, 6, CONTROL);

pub const STATUS: crate::Register = crate::Register::new(1, 0xff);
pub const STATUS_COREUSER: crate::Field = crate::Field::new(8, 0, STATUS);

pub const MAP_LO: crate::Register = crate::Register::new(2, 0xffffffff);
pub const MAP_LO_LUT0: crate::Field = crate::Field::new(8, 0, MAP_LO);
pub const MAP_LO_LUT1: crate::Field = crate::Field::new(8, 8, MAP_LO);
pub const MAP_LO_LUT2: crate::Field = crate::Field::new(8, 16, MAP_LO);
pub const MAP_LO_LUT3: crate::Field = crate::Field::new(8, 24, MAP_LO);

pub const MAP_HI: crate::Register = crate::Register::new(3, 0xffffffff);
pub const MAP_HI_LUT4: crate::Field = crate::Field::new(8, 0, MAP_HI);
pub const MAP_HI_LUT5: crate::Field = crate::Field::new(8, 8, MAP_HI);
pub const MAP_HI_LUT6: crate::Field = crate::Field::new(8, 16, MAP_HI);
pub const MAP_HI_LUT7: crate::Field = crate::Field::new(8, 24, MAP_HI);

pub const HW_COREUSER_BASE: usize = 0xe0002000;
}

pub mod csrtest {
pub const CSRTEST_NUMREGS: usize = 2;

Expand Down Expand Up @@ -5603,6 +5632,95 @@ mod tests {
susres_csr.wfo(utra::susres::EV_ENABLE_SOFT_INT, baz);
}

#[test]
#[ignore]
fn compile_check_coreuser_csr() {
use super::*;
let mut coreuser_csr = CSR::new(HW_COREUSER_BASE as *mut u32);

let foo = coreuser_csr.r(utra::coreuser::CONTROL);
coreuser_csr.wo(utra::coreuser::CONTROL, foo);
let bar = coreuser_csr.rf(utra::coreuser::CONTROL_ENABLE);
coreuser_csr.rmwf(utra::coreuser::CONTROL_ENABLE, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::CONTROL_ENABLE, bar);
baz |= coreuser_csr.ms(utra::coreuser::CONTROL_ENABLE, 1);
coreuser_csr.wfo(utra::coreuser::CONTROL_ENABLE, baz);
let bar = coreuser_csr.rf(utra::coreuser::CONTROL_USE8BIT);
coreuser_csr.rmwf(utra::coreuser::CONTROL_USE8BIT, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::CONTROL_USE8BIT, bar);
baz |= coreuser_csr.ms(utra::coreuser::CONTROL_USE8BIT, 1);
coreuser_csr.wfo(utra::coreuser::CONTROL_USE8BIT, baz);
let bar = coreuser_csr.rf(utra::coreuser::CONTROL_SHIFT);
coreuser_csr.rmwf(utra::coreuser::CONTROL_SHIFT, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::CONTROL_SHIFT, bar);
baz |= coreuser_csr.ms(utra::coreuser::CONTROL_SHIFT, 1);
coreuser_csr.wfo(utra::coreuser::CONTROL_SHIFT, baz);
let bar = coreuser_csr.rf(utra::coreuser::CONTROL_PRIVILEGE);
coreuser_csr.rmwf(utra::coreuser::CONTROL_PRIVILEGE, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::CONTROL_PRIVILEGE, bar);
baz |= coreuser_csr.ms(utra::coreuser::CONTROL_PRIVILEGE, 1);
coreuser_csr.wfo(utra::coreuser::CONTROL_PRIVILEGE, baz);
let bar = coreuser_csr.rf(utra::coreuser::CONTROL_MPP);
coreuser_csr.rmwf(utra::coreuser::CONTROL_MPP, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::CONTROL_MPP, bar);
baz |= coreuser_csr.ms(utra::coreuser::CONTROL_MPP, 1);
coreuser_csr.wfo(utra::coreuser::CONTROL_MPP, baz);

let foo = coreuser_csr.r(utra::coreuser::STATUS);
coreuser_csr.wo(utra::coreuser::STATUS, foo);
let bar = coreuser_csr.rf(utra::coreuser::STATUS_COREUSER);
coreuser_csr.rmwf(utra::coreuser::STATUS_COREUSER, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::STATUS_COREUSER, bar);
baz |= coreuser_csr.ms(utra::coreuser::STATUS_COREUSER, 1);
coreuser_csr.wfo(utra::coreuser::STATUS_COREUSER, baz);

let foo = coreuser_csr.r(utra::coreuser::MAP_LO);
coreuser_csr.wo(utra::coreuser::MAP_LO, foo);
let bar = coreuser_csr.rf(utra::coreuser::MAP_LO_LUT0);
coreuser_csr.rmwf(utra::coreuser::MAP_LO_LUT0, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_LO_LUT0, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_LO_LUT0, 1);
coreuser_csr.wfo(utra::coreuser::MAP_LO_LUT0, baz);
let bar = coreuser_csr.rf(utra::coreuser::MAP_LO_LUT1);
coreuser_csr.rmwf(utra::coreuser::MAP_LO_LUT1, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_LO_LUT1, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_LO_LUT1, 1);
coreuser_csr.wfo(utra::coreuser::MAP_LO_LUT1, baz);
let bar = coreuser_csr.rf(utra::coreuser::MAP_LO_LUT2);
coreuser_csr.rmwf(utra::coreuser::MAP_LO_LUT2, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_LO_LUT2, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_LO_LUT2, 1);
coreuser_csr.wfo(utra::coreuser::MAP_LO_LUT2, baz);
let bar = coreuser_csr.rf(utra::coreuser::MAP_LO_LUT3);
coreuser_csr.rmwf(utra::coreuser::MAP_LO_LUT3, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_LO_LUT3, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_LO_LUT3, 1);
coreuser_csr.wfo(utra::coreuser::MAP_LO_LUT3, baz);

let foo = coreuser_csr.r(utra::coreuser::MAP_HI);
coreuser_csr.wo(utra::coreuser::MAP_HI, foo);
let bar = coreuser_csr.rf(utra::coreuser::MAP_HI_LUT4);
coreuser_csr.rmwf(utra::coreuser::MAP_HI_LUT4, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_HI_LUT4, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_HI_LUT4, 1);
coreuser_csr.wfo(utra::coreuser::MAP_HI_LUT4, baz);
let bar = coreuser_csr.rf(utra::coreuser::MAP_HI_LUT5);
coreuser_csr.rmwf(utra::coreuser::MAP_HI_LUT5, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_HI_LUT5, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_HI_LUT5, 1);
coreuser_csr.wfo(utra::coreuser::MAP_HI_LUT5, baz);
let bar = coreuser_csr.rf(utra::coreuser::MAP_HI_LUT6);
coreuser_csr.rmwf(utra::coreuser::MAP_HI_LUT6, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_HI_LUT6, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_HI_LUT6, 1);
coreuser_csr.wfo(utra::coreuser::MAP_HI_LUT6, baz);
let bar = coreuser_csr.rf(utra::coreuser::MAP_HI_LUT7);
coreuser_csr.rmwf(utra::coreuser::MAP_HI_LUT7, bar);
let mut baz = coreuser_csr.zf(utra::coreuser::MAP_HI_LUT7, bar);
baz |= coreuser_csr.ms(utra::coreuser::MAP_HI_LUT7, 1);
coreuser_csr.wfo(utra::coreuser::MAP_HI_LUT7, baz);
}

#[test]
#[ignore]
fn compile_check_csrtest_csr() {
Expand Down

0 comments on commit bb09856

Please sign in to comment.