Skip to content

Commit 15d39f1

Browse files
committed
Emerald: Implement SystemTime and Instance
This is now implemented with `get_time` system call. This allows us to get the time on 2 timers: 1- unix based time, this is the `real-time`. 2- system boot time, which acts as monotonic time (for now, the kernel treat both as monotonic) The second one, can be not based to any specific start, for our kernel we base on system boot and that's it.
1 parent 467accc commit 15d39f1

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,19 +1193,19 @@ dependencies = [
11931193

11941194
[[package]]
11951195
name = "emerald_kernel_user_link"
1196-
version = "0.2.2"
1196+
version = "0.2.3"
11971197
source = "registry+https://github.com/rust-lang/crates.io-index"
1198-
checksum = "2f12c5d30e528a9a1dbf773e020452dc5339b0167a6fe66c683a02c6bfaffb6c"
1198+
checksum = "553132cab85a2a497d1ea12e887b0c02ad4d1a17f09900ec74640eacdaa87b97"
11991199
dependencies = [
12001200
"compiler_builtins",
12011201
"rustc-std-workspace-core",
12021202
]
12031203

12041204
[[package]]
12051205
name = "emerald_std"
1206-
version = "0.2.3"
1206+
version = "0.2.5"
12071207
source = "registry+https://github.com/rust-lang/crates.io-index"
1208-
checksum = "fa6d6034186e8a218cd75e1481bda7981e4c136c46b8fa11c75fdf8c1cfc1d9b"
1208+
checksum = "b3728e4814248417c26c01de4c514e4c8a675d77e36eae094d41378a22e12223"
12091209
dependencies = [
12101210
"compiler_builtins",
12111211
"emerald_kernel_user_link",

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ r-efi-alloc = { version = "1.0.0", features = ['rustc-dep-of-std']}
5959

6060
[target.'cfg(target_os = "emerald")'.dependencies]
6161
# This is from `https://github.com/Amjad50/Emerald`, i.e. it must be run from that context
62-
emerald_std = { version = "0.2.3", features = ['rustc-dep-of-std'] }
62+
emerald_std = { version = "0.2.5", features = ['rustc-dep-of-std'] }
6363

6464
[features]
6565
backtrace = [

library/std/src/sys/emerald/time.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::time::Duration;
2+
use emerald_std::clock::ClockType;
23

34
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
45
pub struct Instant(Duration);
@@ -8,9 +9,14 @@ pub struct SystemTime(Duration);
89

910
pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
1011

12+
// its a bit confusing, but `SystemTime` refers to the time since boot,
13+
// and `RealTime` refers to the time since the unix epoch
1114
impl Instant {
1215
pub fn now() -> Instant {
13-
panic!("time not implemented on this platform")
16+
let time = unsafe {
17+
emerald_std::clock::get_time(ClockType::SystemTime).expect("Failed to get time")
18+
};
19+
Instant(Duration::new(time.seconds, time.nanoseconds as u32))
1420
}
1521

1622
pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
@@ -28,7 +34,10 @@ impl Instant {
2834

2935
impl SystemTime {
3036
pub fn now() -> SystemTime {
31-
panic!("time not implemented on this platform")
37+
let time = unsafe {
38+
emerald_std::clock::get_time(ClockType::RealTime).expect("Failed to get time")
39+
};
40+
SystemTime(Duration::new(time.seconds, time.nanoseconds as u32))
3241
}
3342

3443
pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {

0 commit comments

Comments
 (0)