Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2345214

Browse files
Various minor improvements
1 parent b22b0b1 commit 2345214

File tree

50 files changed

+407
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+407
-381
lines changed

‎07_timestamps/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/time.rs 07_timestamps/src/_arch/
302302
+// Private Code
303303
+//--------------------------------------------------------------------------------------------------
304304
+
305+
+fn arch_timer_counter_frequency() -> NonZeroU32 {
306+
+ // Read volatile is needed here to prevent the compiler from optimizing
307+
+ // ARCH_TIMER_COUNTER_FREQUENCY away.
308+
+ //
309+
+ // This is safe, because all the safety requirements as stated in read_volatile()'s
310+
+ // documentation are fulfilled.
311+
+ unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
312+
+}
313+
+
305314
+impl GenericTimerCounterValue {
306315
+ pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
307316
+}
@@ -320,13 +329,7 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/time.rs 07_timestamps/src/_arch/
320329
+ return Duration::ZERO;
321330
+ }
322331
+
323-
+ // Read volatile is needed here to prevent the compiler from optimizing
324-
+ // ARCH_TIMER_COUNTER_FREQUENCY away.
325-
+ //
326-
+ // This is safe, because all the safety requirements as stated in read_volatile()'s
327-
+ // documentation are fulfilled.
328-
+ let frequency: NonZeroU64 =
329-
+ unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
332+
+ let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
330333
+
331334
+ // Div<NonZeroU64> implementation for u64 cannot panic.
332335
+ let secs = counter_value.0.div(frequency);
@@ -361,10 +364,7 @@ diff -uNr 06_uart_chainloader/src/_arch/aarch64/time.rs 07_timestamps/src/_arch/
361364
+ return Err("Conversion error. Duration too big");
362365
+ }
363366
+
364-
+ // This is safe, because all the safety requirements as stated in read_volatile()'s
365-
+ // documentation are fulfilled.
366-
+ let frequency: u128 =
367-
+ unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
367+
+ let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
368368
+ let duration: u128 = duration.as_nanos();
369369
+
370370
+ // This is safe, because frequency can never be greater than u32::MAX, and

‎07_timestamps/src/_arch/aarch64/time.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static ARCH_TIMER_COUNTER_FREQUENCY: NonZeroU32 = NonZeroU32::MIN;
4242
// Private Code
4343
//--------------------------------------------------------------------------------------------------
4444

45+
fn arch_timer_counter_frequency() -> NonZeroU32 {
46+
// Read volatile is needed here to prevent the compiler from optimizing
47+
// ARCH_TIMER_COUNTER_FREQUENCY away.
48+
//
49+
// This is safe, because all the safety requirements as stated in read_volatile()'s
50+
// documentation are fulfilled.
51+
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
52+
}
53+
4554
impl GenericTimerCounterValue {
4655
pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
4756
}
@@ -60,13 +69,7 @@ impl From<GenericTimerCounterValue> for Duration {
6069
return Duration::ZERO;
6170
}
6271

63-
// Read volatile is needed here to prevent the compiler from optimizing
64-
// ARCH_TIMER_COUNTER_FREQUENCY away.
65-
//
66-
// This is safe, because all the safety requirements as stated in read_volatile()'s
67-
// documentation are fulfilled.
68-
let frequency: NonZeroU64 =
69-
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
72+
let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
7073

7174
// Div<NonZeroU64> implementation for u64 cannot panic.
7275
let secs = counter_value.0.div(frequency);
@@ -101,10 +104,7 @@ impl TryFrom<Duration> for GenericTimerCounterValue {
101104
return Err("Conversion error. Duration too big");
102105
}
103106

104-
// This is safe, because all the safety requirements as stated in read_volatile()'s
105-
// documentation are fulfilled.
106-
let frequency: u128 =
107-
unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
107+
let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
108108
let duration: u128 = duration.as_nanos();
109109

110110
// This is safe, because frequency can never be greater than u32::MAX, and

‎08_hw_debug_JTAG/src/_arch/aarch64/time.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static ARCH_TIMER_COUNTER_FREQUENCY: NonZeroU32 = NonZeroU32::MIN;
4242
// Private Code
4343
//--------------------------------------------------------------------------------------------------
4444

45+
fn arch_timer_counter_frequency() -> NonZeroU32 {
46+
// Read volatile is needed here to prevent the compiler from optimizing
47+
// ARCH_TIMER_COUNTER_FREQUENCY away.
48+
//
49+
// This is safe, because all the safety requirements as stated in read_volatile()'s
50+
// documentation are fulfilled.
51+
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
52+
}
53+
4554
impl GenericTimerCounterValue {
4655
pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
4756
}
@@ -60,13 +69,7 @@ impl From<GenericTimerCounterValue> for Duration {
6069
return Duration::ZERO;
6170
}
6271

63-
// Read volatile is needed here to prevent the compiler from optimizing
64-
// ARCH_TIMER_COUNTER_FREQUENCY away.
65-
//
66-
// This is safe, because all the safety requirements as stated in read_volatile()'s
67-
// documentation are fulfilled.
68-
let frequency: NonZeroU64 =
69-
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
72+
let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
7073

7174
// Div<NonZeroU64> implementation for u64 cannot panic.
7275
let secs = counter_value.0.div(frequency);
@@ -101,10 +104,7 @@ impl TryFrom<Duration> for GenericTimerCounterValue {
101104
return Err("Conversion error. Duration too big");
102105
}
103106

104-
// This is safe, because all the safety requirements as stated in read_volatile()'s
105-
// documentation are fulfilled.
106-
let frequency: u128 =
107-
unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
107+
let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
108108
let duration: u128 = duration.as_nanos();
109109

110110
// This is safe, because frequency can never be greater than u32::MAX, and

‎09_privilege_level/src/_arch/aarch64/time.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static ARCH_TIMER_COUNTER_FREQUENCY: NonZeroU32 = NonZeroU32::MIN;
4242
// Private Code
4343
//--------------------------------------------------------------------------------------------------
4444

45+
fn arch_timer_counter_frequency() -> NonZeroU32 {
46+
// Read volatile is needed here to prevent the compiler from optimizing
47+
// ARCH_TIMER_COUNTER_FREQUENCY away.
48+
//
49+
// This is safe, because all the safety requirements as stated in read_volatile()'s
50+
// documentation are fulfilled.
51+
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
52+
}
53+
4554
impl GenericTimerCounterValue {
4655
pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
4756
}
@@ -60,13 +69,7 @@ impl From<GenericTimerCounterValue> for Duration {
6069
return Duration::ZERO;
6170
}
6271

63-
// Read volatile is needed here to prevent the compiler from optimizing
64-
// ARCH_TIMER_COUNTER_FREQUENCY away.
65-
//
66-
// This is safe, because all the safety requirements as stated in read_volatile()'s
67-
// documentation are fulfilled.
68-
let frequency: NonZeroU64 =
69-
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
72+
let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
7073

7174
// Div<NonZeroU64> implementation for u64 cannot panic.
7275
let secs = counter_value.0.div(frequency);
@@ -101,10 +104,7 @@ impl TryFrom<Duration> for GenericTimerCounterValue {
101104
return Err("Conversion error. Duration too big");
102105
}
103106

104-
// This is safe, because all the safety requirements as stated in read_volatile()'s
105-
// documentation are fulfilled.
106-
let frequency: u128 =
107-
unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
107+
let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
108108
let duration: u128 = duration.as_nanos();
109109

110110
// This is safe, because frequency can never be greater than u32::MAX, and

‎10_virtual_mem_part1_identity_mapping/src/_arch/aarch64/time.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static ARCH_TIMER_COUNTER_FREQUENCY: NonZeroU32 = NonZeroU32::MIN;
4242
// Private Code
4343
//--------------------------------------------------------------------------------------------------
4444

45+
fn arch_timer_counter_frequency() -> NonZeroU32 {
46+
// Read volatile is needed here to prevent the compiler from optimizing
47+
// ARCH_TIMER_COUNTER_FREQUENCY away.
48+
//
49+
// This is safe, because all the safety requirements as stated in read_volatile()'s
50+
// documentation are fulfilled.
51+
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
52+
}
53+
4554
impl GenericTimerCounterValue {
4655
pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
4756
}
@@ -60,13 +69,7 @@ impl From<GenericTimerCounterValue> for Duration {
6069
return Duration::ZERO;
6170
}
6271

63-
// Read volatile is needed here to prevent the compiler from optimizing
64-
// ARCH_TIMER_COUNTER_FREQUENCY away.
65-
//
66-
// This is safe, because all the safety requirements as stated in read_volatile()'s
67-
// documentation are fulfilled.
68-
let frequency: NonZeroU64 =
69-
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
72+
let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
7073

7174
// Div<NonZeroU64> implementation for u64 cannot panic.
7275
let secs = counter_value.0.div(frequency);
@@ -101,10 +104,7 @@ impl TryFrom<Duration> for GenericTimerCounterValue {
101104
return Err("Conversion error. Duration too big");
102105
}
103106

104-
// This is safe, because all the safety requirements as stated in read_volatile()'s
105-
// documentation are fulfilled.
106-
let frequency: u128 =
107-
unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
107+
let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
108108
let duration: u128 = duration.as_nanos();
109109

110110
// This is safe, because frequency can never be greater than u32::MAX, and

‎11_exceptions_part1_groundwork/src/_arch/aarch64/time.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static ARCH_TIMER_COUNTER_FREQUENCY: NonZeroU32 = NonZeroU32::MIN;
4242
// Private Code
4343
//--------------------------------------------------------------------------------------------------
4444

45+
fn arch_timer_counter_frequency() -> NonZeroU32 {
46+
// Read volatile is needed here to prevent the compiler from optimizing
47+
// ARCH_TIMER_COUNTER_FREQUENCY away.
48+
//
49+
// This is safe, because all the safety requirements as stated in read_volatile()'s
50+
// documentation are fulfilled.
51+
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
52+
}
53+
4554
impl GenericTimerCounterValue {
4655
pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
4756
}
@@ -60,13 +69,7 @@ impl From<GenericTimerCounterValue> for Duration {
6069
return Duration::ZERO;
6170
}
6271

63-
// Read volatile is needed here to prevent the compiler from optimizing
64-
// ARCH_TIMER_COUNTER_FREQUENCY away.
65-
//
66-
// This is safe, because all the safety requirements as stated in read_volatile()'s
67-
// documentation are fulfilled.
68-
let frequency: NonZeroU64 =
69-
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
72+
let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
7073

7174
// Div<NonZeroU64> implementation for u64 cannot panic.
7275
let secs = counter_value.0.div(frequency);
@@ -101,10 +104,7 @@ impl TryFrom<Duration> for GenericTimerCounterValue {
101104
return Err("Conversion error. Duration too big");
102105
}
103106

104-
// This is safe, because all the safety requirements as stated in read_volatile()'s
105-
// documentation are fulfilled.
106-
let frequency: u128 =
107-
unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
107+
let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
108108
let duration: u128 = duration.as_nanos();
109109

110110
// This is safe, because frequency can never be greater than u32::MAX, and

‎12_integrated_testing/kernel/src/_arch/aarch64/time.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ static ARCH_TIMER_COUNTER_FREQUENCY: NonZeroU32 = NonZeroU32::MIN;
4242
// Private Code
4343
//--------------------------------------------------------------------------------------------------
4444

45+
fn arch_timer_counter_frequency() -> NonZeroU32 {
46+
// Read volatile is needed here to prevent the compiler from optimizing
47+
// ARCH_TIMER_COUNTER_FREQUENCY away.
48+
//
49+
// This is safe, because all the safety requirements as stated in read_volatile()'s
50+
// documentation are fulfilled.
51+
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }
52+
}
53+
4554
impl GenericTimerCounterValue {
4655
pub const MAX: Self = GenericTimerCounterValue(u64::MAX);
4756
}
@@ -60,13 +69,7 @@ impl From<GenericTimerCounterValue> for Duration {
6069
return Duration::ZERO;
6170
}
6271

63-
// Read volatile is needed here to prevent the compiler from optimizing
64-
// ARCH_TIMER_COUNTER_FREQUENCY away.
65-
//
66-
// This is safe, because all the safety requirements as stated in read_volatile()'s
67-
// documentation are fulfilled.
68-
let frequency: NonZeroU64 =
69-
unsafe { core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY) }.into();
72+
let frequency: NonZeroU64 = arch_timer_counter_frequency().into();
7073

7174
// Div<NonZeroU64> implementation for u64 cannot panic.
7275
let secs = counter_value.0.div(frequency);
@@ -101,10 +104,7 @@ impl TryFrom<Duration> for GenericTimerCounterValue {
101104
return Err("Conversion error. Duration too big");
102105
}
103106

104-
// This is safe, because all the safety requirements as stated in read_volatile()'s
105-
// documentation are fulfilled.
106-
let frequency: u128 =
107-
unsafe { u32::from(core::ptr::read_volatile(&ARCH_TIMER_COUNTER_FREQUENCY)) as u128 };
107+
let frequency: u128 = u32::from(arch_timer_counter_frequency()) as u128;
108108
let duration: u128 = duration.as_nanos();
109109

110110
// This is safe, because frequency can never be greater than u32::MAX, and

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /