From 68703bf244a10e5281625b0cb1d620d78d6c5cbb Mon Sep 17 00:00:00 2001 From: Alastair Reid Date: Tue, 26 Jun 2018 15:46:57 +0100 Subject: RTS: implement sleep primitives Note that an alternative implementation choice is just to implement them as SAIL functions manipulating a global variable. Not sure which is better. --- lib/rts.c | 18 ++++++++++++++++-- lib/rts.h | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/rts.c b/lib/rts.c index ebfa7c6d..f5426814 100644 --- a/lib/rts.c +++ b/lib/rts.c @@ -25,12 +25,27 @@ unit sail_exit(unit u) return UNIT; } +bool g_sleeping = false; + unit sleep_request(const unit u) { - fprintf(stderr, "Sail model going to sleep\n"); + fprintf(stderr, "Sail CPU model going to sleep\n"); + g_sleeping = true; + return UNIT; +} + +unit wakeup_request(const unit u) +{ + fprintf(stderr, "Sail CPU model waking up\n"); + g_sleeping = false; return UNIT; } +bool sleeping(const unit u) +{ + return g_sleeping; +} + /* ***** Sail memory builtins ***** */ /* @@ -448,7 +463,6 @@ int process_arguments(int argc, char *argv[]) g_elf_entry = elf_entry; } - fprintf(stderr, "Parsed all command line options\n"); return 0; } diff --git a/lib/rts.h b/lib/rts.h index b0e59252..78387ab4 100644 --- a/lib/rts.h +++ b/lib/rts.h @@ -21,12 +21,22 @@ unit sail_assert(bool b, sail_string msg); unit sail_exit(unit); /* - * ASL->Sail model has an EnterLowPowerState() function that calls a - * sleep request builtin. If it gets called we print a message and - * exit the model. + * Put processor to sleep until an external device calls wakeup_request(). */ unit sleep_request(const unit u); +/* + * Stop processor sleeping. + * (Typically called when a device generates an interrupt.) + */ +unit wakeup_request(const unit u); + +/* + * Test whether processor is sleeping. + * (Typically used to disable execution of instructions.) + */ +bool sleeping(const unit u); + /* ***** Memory builtins ***** */ void write_mem(uint64_t, uint64_t); -- cgit v1.2.3