This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,25 @@
(library
(name mirage_ptime_solo5)
(public_name mirage-ptime.solo5)
(implements mirage-ptime)
(foreign_stubs
(language c)
(names mirage_ptime_stubs)))
(rule
(target mirage_ptime_stubs.c)
(enabled_if
(<> %{context_name} "solo5"))
(deps
(:src mirage_ptime_stubs.default.c))
(action
(copy %{src} %{target})))
(rule
(target mirage_ptime_stubs.c)
(enabled_if
(= %{context_name} "solo5"))
(deps
(:src mirage_ptime_stubs.solo5.c))
(action
(copy %{src} %{target})))

View file

@ -0,0 +1,38 @@
(*
* Copyright (c) 2015 Matt Gray <matthew.thomas.gray@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)
external time : unit -> int64 = "caml_get_wall_clock"
let nsec_per_day = Int64.mul 86_400L 1_000_000_000L
let ps_per_ns = 1_000L
let now_d_ps () =
let nsec = time () in
let days = Int64.div nsec nsec_per_day in
let rem_ns = Int64.rem nsec nsec_per_day in
let rem_ps = Int64.mul rem_ns ps_per_ns in
(Int64.to_int days, rem_ps)
let now () = Ptime.v (now_d_ps ())
let current_tz_offset_s () = None
(* According to
* https://github.com/mirage/mini-os/blob/edfd5aae6ec5ba7d0a8834a3e9dfe5e69424150a/arch/x86/time.c#L194
* the clock period is 1 microsecond
*)
let period = (0, 1_000_000L)
let period_d_ps () = Some period
let period () = Some (Ptime.Span.v period)

View file

@ -0,0 +1,11 @@
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
CAMLprim value
caml_get_wall_clock(value v_unit)
{
CAMLparam1(v_unit);
CAMLreturn(caml_copy_int64(0LL));
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (c) 2010 Anil Madhavapeddy <anil@recoil.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "solo5.h"
#include <sys/time.h>
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/fail.h>
CAMLprim value
caml_get_wall_clock(value v_unit)
{
CAMLparam1(v_unit);
CAMLreturn(caml_copy_int64(solo5_clock_wall()));
}