]> gitweb.factorcode.org Git - factor.git/commitdiff
vm: Add more arm files.
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 24 Nov 2020 01:42:08 +0000 (19:42 -0600)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 24 Nov 2020 01:42:08 +0000 (19:42 -0600)
vm/os-linux-arm.32.cpp [new file with mode: 0644]
vm/os-linux-arm.32.hpp [new file with mode: 0644]
vm/os-linux-arm.64.cpp [new file with mode: 0644]
vm/os-linux-arm.64.hpp [new file with mode: 0644]
vm/os-macosx-arm64.hpp [new file with mode: 0644]

diff --git a/vm/os-linux-arm.32.cpp b/vm/os-linux-arm.32.cpp
new file mode 100644 (file)
index 0000000..13ef08c
--- /dev/null
@@ -0,0 +1,27 @@
+#include "master.hpp"
+
+namespace factor {
+
+void flush_icache(cell start, cell len) {
+  int result;
+
+  // XXX: why doesn't this work on Nokia n800? It should behave
+  //      identically to the below assembly.
+  // result = syscall(__ARM_NR_cacheflush,start,start + len,0);
+
+  // Assembly swiped from
+  // http://lists.arm.linux.org.uk/pipermail/linux-arm/2002-July/003931.html
+  __asm__ __volatile__("mov     r0, %1\n"
+                       "sub     r1, %2, #1\n"
+                       "mov     r2, #0\n"
+                       "swi     " __sys1(__ARM_NR_cacheflush) "\n"
+                                                              "mov     %0, r0\n"
+                       : "=r"(result)
+                       : "r"(start), "r"(start + len)
+                       : "r0", "r1", "r2");
+
+  if (result < 0)
+    critical_error("flush_icache() failed", result);
+}
+
+}
diff --git a/vm/os-linux-arm.32.hpp b/vm/os-linux-arm.32.hpp
new file mode 100644 (file)
index 0000000..74bf6d9
--- /dev/null
@@ -0,0 +1,18 @@
+#include <ucontext.h>
+#include <asm/unistd.h>
+#include <sys/syscall.h>
+
+namespace factor {
+
+void flush_icache(cell start, cell len);
+
+#define UAP_STACK_POINTER(ucontext) \
+  (((ucontext_t*)ucontext)->uc_mcontext.arm_sp)
+#define UAP_PROGRAM_COUNTER(ucontext) \
+  (((ucontext_t*)ucontext)->uc_mcontext.arm_pc)
+
+#define CODE_TO_FUNCTION_POINTER(code) (void)0
+#define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
+#define FUNCTION_CODE_POINTER(ptr) ptr
+#define FUNCTION_TOC_POINTER(ptr) ptr
+}
diff --git a/vm/os-linux-arm.64.cpp b/vm/os-linux-arm.64.cpp
new file mode 100644 (file)
index 0000000..e708766
--- /dev/null
@@ -0,0 +1,6 @@
+#include "master.hpp"
+
+namespace factor {
+
+
+}
diff --git a/vm/os-linux-arm.64.hpp b/vm/os-linux-arm.64.hpp
new file mode 100644 (file)
index 0000000..9ba9587
--- /dev/null
@@ -0,0 +1,110 @@
+#include <ucontext.h>
+#include <asm/unistd.h>
+#include <sys/syscall.h>
+
+namespace factor {
+
+#define CALLSTACK_BOTTOM(ctx) \
+  (ctx->callstack_seg->end - sizeof(cell) * 5)
+
+static const fixnum xt_tail_pic_offset = 4 + 1;
+
+#define UAP_STACK_POINTER(ucontext) \
+  (((ucontext_t*)ucontext)->uc_mcontext.sp)
+#define UAP_PROGRAM_COUNTER(ucontext) \
+  (((ucontext_t*)ucontext)->uc_mcontext.pc)
+
+// #define CODE_TO_FUNCTION_POINTER(code) (void)0
+// #define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
+// #define FUNCTION_CODE_POINTER(ptr) ptr
+// #define FUNCTION_TOC_POINTER(ptr) ptr
+
+inline static unsigned int uap_fpu_status(void* uap) {
+  // ucontext_t* ucontext = (ucontext_t*)uap;
+  // return ucontext->uc_mcontext.fpregs->swd |
+  //        ucontext->uc_mcontext.fpregs->mxcsr;
+  return 0;
+}
+
+inline static void uap_clear_fpu_status(void* uap) {
+  // ucontext_t* ucontext = (ucontext_t*)uap;
+  // ucontext->uc_mcontext.fpregs->swd = 0;
+  // ucontext->uc_mcontext.fpregs->mxcsr &= 0xffffffc0;
+}
+
+inline static unsigned int fpu_status(unsigned int status) {
+  unsigned int r = 0;
+
+  if (status & 0x01)
+    r |= FP_TRAP_INVALID_OPERATION;
+  if (status & 0x04)
+    r |= FP_TRAP_ZERO_DIVIDE;
+  if (status & 0x08)
+    r |= FP_TRAP_OVERFLOW;
+  if (status & 0x10)
+    r |= FP_TRAP_UNDERFLOW;
+  if (status & 0x20)
+    r |= FP_TRAP_INEXACT;
+
+  return r;
+}
+  // FP_TRAP_INVALID_OPERATION = 1 << 0,
+  // FP_TRAP_OVERFLOW = 1 << 1,
+  // FP_TRAP_UNDERFLOW = 1 << 2,
+  // FP_TRAP_ZERO_DIVIDE = 1 << 3,
+  // FP_TRAP_INEXACT = 1 << 4,
+
+
+// #define UAP_STACK_POINTER(ucontext) \
+//   (((ucontext_t*)ucontext)->uc_mcontext.regs[15])
+// #define UAP_PROGRAM_COUNTER(ucontext) \
+//   (((ucontext_t*)ucontext)->uc_mcontext.regs[16])
+
+#define CODE_TO_FUNCTION_POINTER(code) (void)0
+#define CODE_TO_FUNCTION_POINTER_CALLBACK(vm, code) (void)0
+#define FUNCTION_CODE_POINTER(ptr) ptr
+#define FUNCTION_TOC_POINTER(ptr) ptr
+
+// Must match the stack-frame-size constant in
+// bootstrap/assembler/x86.64.unix.factor
+static const unsigned JIT_FRAME_SIZE = 32;
+
+
+static const unsigned char call_opcode = 0xe8;
+static const unsigned char jmp_opcode = 0xe9;
+
+inline static unsigned char call_site_opcode(cell return_address) {
+  return *(unsigned char*)(return_address - 5);
+}
+
+inline static void check_call_site(cell return_address) {
+  unsigned char opcode = call_site_opcode(return_address);
+  FACTOR_ASSERT(opcode == call_opcode || opcode == jmp_opcode);
+  (void)opcode; // suppress warning when compiling without assertions
+}
+
+inline static void* get_call_target(cell return_address) {
+  check_call_site(return_address);
+  return (void*)(*(int*)(return_address - 4) + return_address);
+}
+
+inline static void set_call_target(cell return_address, cell target) {
+  check_call_site(return_address);
+  *(int*)(return_address - 4) = (uint32_t)(target - return_address);
+}
+
+inline static bool tail_call_site_p(cell return_address) {
+  switch (call_site_opcode(return_address)) {
+    case jmp_opcode:
+      return true;
+    case call_opcode:
+      return false;
+    default:
+      abort();
+      return false;
+  }
+}
+
+static const unsigned SIGNAL_HANDLER_STACK_FRAME_SIZE = 192;
+
+}
diff --git a/vm/os-macosx-arm64.hpp b/vm/os-macosx-arm64.hpp
new file mode 100644 (file)
index 0000000..bebf47c
--- /dev/null
@@ -0,0 +1,154 @@
+#include <sys/ucontext.h>
+
+namespace factor {
+
+// Fault handler information.  MacOSX version.
+// Copyright (C) 1993-1999, 2002-2003  Bruno Haible <clisp.org at bruno>
+// Copyright (C) 2003  Paolo Bonzini <gnu.org at bonzini>
+
+// Used under BSD license with permission from Paolo Bonzini and Bruno Haible,
+// 2005-03-10:
+
+// http://sourceforge.net/mailarchive/message.php?msg_name=200503102200.32002.bruno%40clisp.org
+
+// Modified for Factor by Slava Pestov and Daniel Ehrenberg
+// Modified for arm64 by Doug Coleman
+
+/*
+#define MACH_EXC_STATE_TYPE x86_exception_state64_t
+#define MACH_EXC_STATE_FLAVOR x86_EXCEPTION_STATE64
+#define MACH_EXC_STATE_COUNT x86_EXCEPTION_STATE64_COUNT
+
+#define MACH_EXC_INTEGER_DIV EXC_I386_DIV
+
+#define MACH_THREAD_STATE_TYPE x86_thread_state64_t
+#define MACH_THREAD_STATE_FLAVOR x86_THREAD_STATE64
+#define MACH_THREAD_STATE_COUNT MACHINE_THREAD_STATE_COUNT
+
+#define MACH_FLOAT_STATE_TYPE x86_float_state64_t
+#define MACH_FLOAT_STATE_FLAVOR x86_FLOAT_STATE64
+#define MACH_FLOAT_STATE_COUNT x86_FLOAT_STATE64_COUNT
+
+#if __DARWIN_UNIX03
+#define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->__faultvaddr
+#define MACH_STACK_POINTER(thr_state) (thr_state)->__rsp
+#define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->__rip
+#define UAP_SS(ucontext) &(((ucontext_t*)(ucontext))->uc_mcontext->__ss)
+#define UAP_FS(ucontext) &(((ucontext_t*)(ucontext))->uc_mcontext->__fs)
+
+#define MXCSR(float_state) (float_state)->__fpu_mxcsr
+#define X87SW(float_state) (float_state)->__fpu_fsw
+#else
+#define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->faultvaddr
+#define MACH_STACK_POINTER(thr_state) (thr_state)->rsp
+#define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->rip
+#define UAP_SS(ucontext) &(((ucontext_t*)(ucontext))->uc_mcontext->ss)
+#define UAP_FS(ucontext) &(((ucontext_t*)(ucontext))->uc_mcontext->fs)
+
+#define MXCSR(float_state) (float_state)->fpu_mxcsr
+#define X87SW(float_state) (float_state)->fpu_fsw
+#endif
+
+#define UAP_PROGRAM_COUNTER(ucontext) MACH_PROGRAM_COUNTER(UAP_SS(ucontext))
+
+inline static unsigned int mach_fpu_status(x86_float_state64_t* float_state) {
+  unsigned short x87sw;
+  memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw));
+  return MXCSR(float_state) | x87sw;
+}
+
+inline static unsigned int uap_fpu_status(void* uap) {
+  return mach_fpu_status(UAP_FS(uap));
+}
+
+inline static void mach_clear_fpu_status(x86_float_state64_t* float_state) {
+  MXCSR(float_state) &= 0xffffffc0;
+  memset(&X87SW(float_state), 0, sizeof(X87SW(float_state)));
+}
+
+inline static void uap_clear_fpu_status(void* uap) {
+  mach_clear_fpu_status(UAP_FS(uap));
+}
+
+// Must match the stack-frame-size constant in
+// basis/bootstrap/assembler/x86.64.unix.factor
+static const unsigned JIT_FRAME_SIZE = 32;
+
+*/
+
+#define MACH_EXC_STATE_TYPE _STRUCT_ARM_EXCEPTION_STATE64 // arm_exception_state64_t
+#define MACH_EXC_STATE_FAULT(exc_state) (exc_state)->__far
+#define MACH_EXC_STATE_COUNT ARM_EXCEPTION_STATE64_COUNT
+#define MACH_EXC_STATE_FLAVOR ARM_EXCEPTION_STATE64
+
+//#define MACH_EXC_INTEGER_DIV undefined on arm? https://opensource.apple.com/source/lldb/lldb-112/source/Plugins/Process/Utility/StopInfoMachException.cpp.auto.html
+
+#define MACH_THREAD_STATE_TYPE _STRUCT_ARM_THREAD_STATE64
+#define MACH_THREAD_STATE_COUNT MACHINE_THREAD_STATE_COUNT
+#define MACH_THREAD_STATE_FLAVOR ARM_THREAD_STATE64
+
+#define MACH_FLOAT_STATE_TYPE _STRUCT_ARM_NEON_STATE64
+#define MACH_FLOAT_STATE_COUNT ARM_NEON_STATE64_COUNT
+#define MACH_FLOAT_STATE_FLAVOR ARM_NEON_STATE64
+
+#define MACH_STACK_POINTER(thr_state) (thr_state)->__sp
+
+
+#define MACH_PROGRAM_COUNTER(thr_state) (thr_state)->__pc
+#define UAP_PROGRAM_COUNTER(ucontext) MACH_PROGRAM_COUNTER(UAP_SS(ucontext))
+
+#define UAP_SS(ucontext) &(((ucontext_t*)(ucontext))->uc_mcontext->__ss)
+#define UAP_FS(ucontext) &(((ucontext_t*)(ucontext))->uc_mcontext->__ns)
+
+// omg
+inline static unsigned int mach_fpu_status(_STRUCT_ARM_NEON_STATE64* float_state) {
+  // unsigned short x87sw;
+  // memcpy(&x87sw, &X87SW(float_state), sizeof(x87sw));
+  // return MXCSR(float_state) | x87sw;
+  return float_state->__fpsr;
+}
+
+// omg
+inline static unsigned int uap_fpu_status(void* uap) {
+  return mach_fpu_status(UAP_FS(uap));
+}
+
+// omg
+inline static void uap_clear_fpu_status(void* uap) {
+  // mach_clear_fpu_status(UAP_FS(uap));
+}
+
+
+inline static void mach_clear_fpu_status(arm_neon_state64_t* float_state) {
+  // MXCSR(float_state) &= 0xffffffc0; // omg
+  // memset(&X87SW(float_state), 0, sizeof(X87SW(float_state))); // omg
+}
+
+// omg
+inline static unsigned int fpu_status(unsigned int status) {
+  unsigned int r = 0;
+
+/*
+  if (status & 0x01)
+    r |= FP_TRAP_INVALID_OPERATION;
+  if (status & 0x04)
+    r |= FP_TRAP_ZERO_DIVIDE;
+  if (status & 0x08)
+    r |= FP_TRAP_OVERFLOW;
+  if (status & 0x10)
+    r |= FP_TRAP_UNDERFLOW;
+  if (status & 0x20)
+    r |= FP_TRAP_INEXACT;
+*/
+  return r;
+}
+
+
+static const unsigned JIT_FRAME_SIZE = 32; // omg
+
+
+
+
+
+
+}
\ No newline at end of file