Skip to content

Commit c35d6a4

Browse files
committed
use builder api
1 parent b7ea359 commit c35d6a4

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

cortex-ar/src/mmu.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl SectionAttributes {
170170
/// Retrieves the corresponding L1 section part without the section base address being set.
171171
const fn l1_section_part(&self) -> L1Section {
172172
L1Section::builder()
173-
.with_base_addr(u12::new(0))
173+
.with_base_addr_upper_bits(u12::new(0))
174174
.with_ng(self.non_global)
175175
.with_s(self.shareable)
176176
.with_apx(self.access.apx())
@@ -208,9 +208,9 @@ impl SectionAttributes {
208208
#[bitbybit::bitfield(u32, default = 0x00)]
209209
#[derive(PartialEq, Eq)]
210210
pub struct L1Section {
211-
/// Section base address.
211+
/// Section base address upper bits.
212212
#[bits(20..=31, rw)]
213-
base_addr: u12,
213+
base_addr_upper_bits: u12,
214214
/// Non-global bit.
215215
#[bit(17, rw)]
216216
ng: bool,
@@ -243,7 +243,7 @@ impl core::fmt::Debug for L1Section {
243243
write!(
244244
f,
245245
"L1Section {{ base_addr={:#x} ng={} s={} apx={} tex={:#b} ap={:#b} domain={:#b} xn={} c={} b={} }}",
246-
self.base_addr(),
246+
self.base_addr_upper_bits(),
247247
self.ng() as u8,
248248
self.s() as u8,
249249
self.apx() as u8,
@@ -272,8 +272,21 @@ impl L1Section {
272272
if phys_addr & 0x000F_FFFF != 0 {
273273
panic!("physical base address for L1 section must be aligned to 1 MB");
274274
}
275-
let higher_bits = phys_addr >> 20;
276-
Self::new_with_raw_value((higher_bits << 20) | section_attrs.l1_section_part().raw_value())
275+
let attrs = section_attrs.l1_section_part();
276+
L1Section::builder()
277+
.with_base_addr_upper_bits(u12::new((phys_addr >> 20) as u16))
278+
.with_ng(attrs.ng())
279+
.with_s(attrs.s())
280+
.with_apx(attrs.apx())
281+
.with_tex(attrs.tex())
282+
.with_ap(attrs.ap())
283+
.with_p_bit(attrs.p_bit())
284+
.with_domain(attrs.domain())
285+
.with_xn(attrs.xn())
286+
.with_c(attrs.c())
287+
.with_b(attrs.b())
288+
.with_entry_type(attrs.entry_type())
289+
.build()
277290
}
278291

279292
/// Retrieve the section attributes.
@@ -285,7 +298,20 @@ impl L1Section {
285298
/// Set the section attributes without changing the address.
286299
#[inline]
287300
pub fn set_section_attrs(&mut self, section_attrs: SectionAttributes) {
288-
self.raw_value =
289-
((self.base_addr().value() as u32) << 20) | section_attrs.l1_section_part().raw_value();
301+
let attrs = section_attrs.l1_section_part();
302+
*self = L1Section::builder()
303+
.with_base_addr_upper_bits(self.base_addr_upper_bits())
304+
.with_ng(attrs.ng())
305+
.with_s(attrs.s())
306+
.with_apx(attrs.apx())
307+
.with_tex(attrs.tex())
308+
.with_ap(attrs.ap())
309+
.with_p_bit(attrs.p_bit())
310+
.with_domain(attrs.domain())
311+
.with_xn(attrs.xn())
312+
.with_c(attrs.c())
313+
.with_b(attrs.b())
314+
.with_entry_type(attrs.entry_type())
315+
.build()
290316
}
291317
}

0 commit comments

Comments
 (0)