summaryrefslogtreecommitdiffstats
path: root/tests/tcg/aarch64
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tcg/aarch64')
-rw-r--r--tests/tcg/aarch64/Makefile.target17
-rw-r--r--tests/tcg/aarch64/system/semiheap.c93
2 files changed, 110 insertions, 0 deletions
diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target
index 1d967901bd..ac07acde66 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -50,6 +50,23 @@ sysregs: CFLAGS+=-march=armv8.1-a+sve
AARCH64_TESTS += sve-ioctls
sve-ioctls: CFLAGS+=-march=armv8.1-a+sve
+# Vector SHA1
+sha1-vector: CFLAGS=-O3
+sha1-vector: sha1.c
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
+run-sha1-vector: sha1-vector run-sha1
+ $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)")
+ $(call diff-out, sha1-vector, sha1.out)
+
+TESTS += sha1-vector
+
+# Vector versions of sha512 (-O3 triggers vectorisation)
+sha512-vector: CFLAGS=-O3
+sha512-vector: sha512.c
+ $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
+
+TESTS += sha512-vector
+
ifneq ($(HAVE_GDB_BIN),)
GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
diff --git a/tests/tcg/aarch64/system/semiheap.c b/tests/tcg/aarch64/system/semiheap.c
new file mode 100644
index 0000000000..4ed258476d
--- /dev/null
+++ b/tests/tcg/aarch64/system/semiheap.c
@@ -0,0 +1,93 @@
+/*
+ * Semihosting System HEAPINFO Test
+ *
+ * Copyright (c) 2021 Linaro Ltd
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <inttypes.h>
+#include <stddef.h>
+#include <minilib.h>
+
+#define SYS_HEAPINFO 0x16
+
+uintptr_t __semi_call(uintptr_t type, uintptr_t arg0)
+{
+ register uintptr_t t asm("x0") = type;
+ register uintptr_t a0 asm("x1") = arg0;
+ asm("hlt 0xf000"
+ : "=r" (t)
+ : "r" (t), "r" (a0)
+ : "memory" );
+
+ return t;
+}
+
+int main(int argc, char *argv[argc])
+{
+ struct {
+ void *heap_base;
+ void *heap_limit;
+ void *stack_base;
+ void *stack_limit;
+ } info = { };
+ void *ptr_to_info = (void *) &info;
+ uint32_t *ptr_to_heap;
+ int i;
+
+ ml_printf("Semihosting Heap Info Test\n");
+
+ __semi_call(SYS_HEAPINFO, (uintptr_t) &ptr_to_info);
+
+ if (info.heap_base == NULL || info.heap_limit == NULL) {
+ ml_printf("null heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ return -1;
+ }
+
+ /* Error if heap base is above limit */
+ if ((uintptr_t) info.heap_base >= (uintptr_t) info.heap_limit) {
+ ml_printf("heap base %p >= heap_limit %p\n",
+ info.heap_base, info.heap_limit);
+ return -2;
+ }
+
+ if (info.stack_base == NULL) {
+ ml_printf("null stack: %p -> %p\n", info.stack_base, info.stack_limit);
+ return -3;
+ }
+
+ /*
+ * boot.S put our stack somewhere inside the data segment of the
+ * ELF file, and we know that SYS_HEAPINFO won't pick a range
+ * that overlaps with part of a loaded ELF file. So the info
+ * struct (on the stack) should not be inside the reported heap.
+ */
+ if (ptr_to_info > info.heap_base && ptr_to_info < info.heap_limit) {
+ ml_printf("info appears to be inside the heap: %p in %p:%p\n",
+ ptr_to_info, info.heap_base, info.heap_limit);
+ return -4;
+ }
+
+ ml_printf("heap: %p -> %p\n", info.heap_base, info.heap_limit);
+ ml_printf("stack: %p <- %p\n", info.stack_limit, info.stack_base);
+
+ /* finally can we read/write the heap */
+ ptr_to_heap = (uint32_t *) info.heap_base;
+ for (i = 0; i < 512; i++) {
+ *ptr_to_heap++ = i;
+ }
+ ptr_to_heap = (uint32_t *) info.heap_base;
+ for (i = 0; i < 512; i++) {
+ uint32_t tmp = *ptr_to_heap;
+ if (tmp != i) {
+ ml_printf("unexpected value in heap: %d @ %p", tmp, ptr_to_heap);
+ return -5;
+ }
+ ptr_to_heap++;
+ }
+ ml_printf("r/w to heap upto %p\n", ptr_to_heap);
+
+ ml_printf("Passed HeapInfo checks\n");
+ return 0;
+}