-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement syscall and 15:30:24 up 5:24, 1 user, load average: 1,05, 1…
…,41, 1,23 application
- Loading branch information
Showing
11 changed files
with
122 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
edition = "2021" | ||
name = "uptime" | ||
version = "0.1.0" | ||
authors = ["Michael Schöttner <[email protected]>, Fabian Ruhland <[email protected]>"] | ||
|
||
[lib] | ||
crate-type = ["staticlib"] | ||
path = "src/uptime.rs" | ||
|
||
[dependencies] | ||
# Local dependencies | ||
runtime = { path = "../../library/runtime" } | ||
io = { path = "../../library/io" } | ||
time = { path = "../../library/time" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[env.development] | ||
CARGO_CFG_TARGET_FAMILY = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/d3os_application.json" | ||
BUILD_DIRECTORY = "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/d3os_application/debug" | ||
CARGO_BUILD_OPTION = "--lib" | ||
|
||
[env.production] | ||
CARGO_CFG_TARGET_FAMILY = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/d3os_application.json" | ||
BUILD_DIRECTORY = "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/d3os_application/release" | ||
CARGO_BUILD_OPTION = "--release" | ||
|
||
[env] | ||
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true | ||
RUST_TARGET_PATH = "${CARGO_MAKE_WORKING_DIRECTORY}" | ||
SOURCE_DIRECOTRY = "${CARGO_MAKE_WORKING_DIRECTORY}/src" | ||
LINKER_FILE = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/os/application/link.ld" | ||
RUST_OBJECT = "${BUILD_DIRECTORY}/lib${CARGO_MAKE_PROJECT_NAME}.a" | ||
APPLICATION = "${INITRD_DIRECTORY}/${CARGO_MAKE_PROJECT_NAME}" | ||
|
||
# Build tasks | ||
|
||
[tasks.default] | ||
alias = "link" | ||
|
||
[tasks.compile] | ||
command = "cargo" | ||
args = [ "build", "-Z", "build-std=core,alloc", "-Z", "build-std-features=compiler-builtins-mem", "--target", "${CARGO_CFG_TARGET_FAMILY}", "${CARGO_BUILD_OPTION}" ] | ||
|
||
[tasks.link] | ||
command = "ld" | ||
args = [ "-n", "-T", "${LINKER_FILE}", "-o", "${APPLICATION}", "${RUST_OBJECT}" ] | ||
dependencies = [ "compile" ] | ||
|
||
# Cleanup tasks | ||
|
||
[tasks.clean] | ||
command = "cargo" | ||
args = [ "clean" ] | ||
dependencies = [ "remove-application" ] | ||
|
||
[tasks.remove-application] | ||
command = "rm" | ||
args = [ "-f", "${APPLICATION}" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#![no_std] | ||
|
||
extern crate alloc; | ||
|
||
#[allow(unused_imports)] | ||
use runtime::*; | ||
use io::{print, println}; | ||
use time::systime; | ||
|
||
#[no_mangle] | ||
pub fn main() { | ||
let systime = systime(); | ||
|
||
if systime.num_seconds() < 60 { | ||
println!("{}", systime.num_seconds()); | ||
} else if systime.num_seconds() < 3600 { | ||
println!("{}:{:0>2}", systime.num_minutes(), systime.num_seconds() % 60); | ||
} else if systime.num_seconds() < 86400 { | ||
let seconds = systime.num_seconds() - (systime.num_minutes() * 60); | ||
println!("{}:{:0>2}:{:0>2}", systime.num_hours(), systime.num_minutes() % 60, seconds); | ||
} else { | ||
let days = systime.num_days(); | ||
let minutes= systime.num_minutes() - (systime.num_hours() % 60); | ||
let seconds = systime.num_seconds() - (systime.num_minutes() * 60); | ||
println!("{} {}, {}:{:0>2}:{:0>2}", days, if days == 1 { "day" } else { "days" }, systime.num_hours(), minutes, seconds); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
edition = "2021" | ||
name = "time" | ||
version = "0.1.0" | ||
authors = ["Michael Schöttner <[email protected]>, Fabian Ruhland <[email protected]>"] | ||
|
||
[dependencies] | ||
# Local dependencies | ||
syscall = { path = "../syscall" } | ||
|
||
# External dependencies | ||
chrono = { version = "0.4.34", default-features = false, features = ["alloc"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![no_std] | ||
|
||
use chrono::Duration; | ||
use syscall::{syscall0, SystemCall}; | ||
|
||
pub fn systime() -> Duration { | ||
let systime = syscall0(SystemCall::SystemTime); | ||
Duration::milliseconds(systime as i64) | ||
} |