summaryrefslogtreecommitdiff
path: root/lib/rts.c
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-06-15 15:11:13 +0100
committerAlasdair Armstrong2018-06-15 15:12:24 +0100
commite2da03c11fa37f82d24f3a11c93aca7537a97f6a (patch)
treea43a199ee2b448f7c970dc155ae8bc88fac8fe49 /lib/rts.c
parent5dc3ee5029f6e828b7e77a176a67894e8fa00696 (diff)
Fixes for C RTS for aarch64 no it's split into multiple files
Fix a bug involving indentifers on the left hand side of assignment statements not being shadowed correctly within foreach loops. Make the different between different types of integer division explicit in at least the C compilation for now. fdiv_int is division rounding towards -infinity (floor). while tdiv_int is truncating towards zero. Same for fmod_int and tmod_int.
Diffstat (limited to 'lib/rts.c')
-rw-r--r--lib/rts.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/lib/rts.c b/lib/rts.c
index b098ae0e..61f772cf 100644
--- a/lib/rts.c
+++ b/lib/rts.c
@@ -16,6 +16,18 @@ unit sail_assert(bool b, sail_string msg)
exit(EXIT_FAILURE);
}
+unit sail_exit(unit u)
+{
+ exit(EXIT_SUCCESS);
+ return UNIT;
+}
+
+unit sleep_request(const unit u)
+{
+ fprintf(stderr, "Sail model going to sleep\n");
+ exit(EXIT_SUCCESS);
+}
+
/* ***** Sail memory builtins ***** */
/*
@@ -151,6 +163,19 @@ void read_ram(sail_bits *data,
mpz_clear(byte);
}
+unit load_raw(mach_bits addr, const sail_string file)
+{
+ FILE *fp = fopen(file, "r");
+
+ uint64_t byte;
+ while ((byte = (uint64_t)fgetc(fp)) != EOF) {
+ write_mem(addr, byte);
+ addr++;
+ }
+
+ return UNIT;
+}
+
void load_image(char *file) {
FILE *fp = fopen(file, "r");
@@ -201,7 +226,12 @@ unit disable_tracing(const unit u)
return UNIT;
}
-void trace_uint64_t(const uint64_t x) {
+bool is_tracing(const unit u)
+{
+ return g_trace_enabled;
+}
+
+void trace_mach_bits(const mach_bits x) {
if (g_trace_enabled) fprintf(stderr, "0x%" PRIx64, x);
}
@@ -209,10 +239,18 @@ void trace_unit(const unit u) {
if (g_trace_enabled) fputs("()", stderr);
}
-void trace_mpz_t(const mpz_t op) {
+void trace_sail_string(const sail_string str) {
+ if (g_trace_enabled) fputs(str, stderr);
+}
+
+void trace_sail_int(const sail_int op) {
if (g_trace_enabled) mpz_out_str(stderr, 10, op);
}
+void trace_sail_bits(const sail_bits op) {
+ if (g_trace_enabled) fprint_bits("", op, "", stderr);
+}
+
void trace_bool(const bool b) {
if (g_trace_enabled) {
if (b) {
@@ -247,6 +285,7 @@ void trace_start(char *name)
fprintf(stderr, "%s", "| ");
}
fprintf(stderr, "%s(", name);
+ g_trace_depth++;
}
}
@@ -257,9 +296,20 @@ void trace_end(void)
for (int64_t i = 0; i < g_trace_depth; ++i) {
fprintf(stderr, "%s", "| ");
}
+ g_trace_depth--;
}
}
+/* ***** ELF functions ***** */
+
+void elf_entry(mpz_t *rop, const unit u) {
+ mpz_set_ui(*rop, g_elf_entry);
+}
+
+void elf_tohost(mpz_t *rop, const unit u) {
+ mpz_set_ui(*rop, 0x0ul);
+}
+
/* ***** Setup and cleanup functions for RTS ***** */
void setup_rts(void)