From f69be88d7408ccd35f3331f8e9c0763c6a162e33 Mon Sep 17 00:00:00 2001 From: iskamag Date: Sat, 18 Nov 2023 15:50:08 +0500 Subject: [PATCH 1/4] added a couple functions and intrinsics --- runtime/llvm-runtime.lisp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/runtime/llvm-runtime.lisp b/runtime/llvm-runtime.lisp index 291bd2d..0fcd7bc 100644 --- a/runtime/llvm-runtime.lisp +++ b/runtime/llvm-runtime.lisp @@ -627,6 +627,10 @@ PERSONALITY is bound to the context's personality object." (ash (ldb (byte 8 16) value) 8) (ldb (byte 8 24) value))) +(define-llvm-function |llvm.bswap.i32| ((value)) + (logior (ash (ldb (byte 8 0) value) 8) + (ldb (byte 8 8) value))) + (define-llvm-function |llvm.flt.rounds| (()) ;; Rounding mode 1, round to nearest. 1) @@ -666,6 +670,16 @@ PERSONALITY is bound to the context's personality object." (define-llvm-function |llvm.memcpy.p0i8.p0i8.i32| ((d s n align is-volatile)) (real-memmove llvm-context d s n)) +(define-llvm-function |llvm.memcpy.p0i8.p0i8.i64| ((d s n align is-volatile)) + (real-memmove llvm-context d s n)) + + +;;this is just a de brujin sequence from wikipedia +;;TODO: most architectures have a clz function, maybe use that +(define-llvm-function |llvm.ctlz.i32| ((value zero-error-p)) + (- 32 (integer-length values))) + + ;;; It's a UNIX system! I know this! (defun align-stack (context) @@ -944,6 +958,15 @@ Assumes the context is freshly created." (ensure-directories-exist (parse-unix-path unix path :ensure-directory t)) 0)) +;;we don't have hardlinks implemented, so we're just gonna copy. +;;hope this works well enough +(define-llvm-function |link| ((oldpath newpath)) + (let ((old (parse-unix-path unix oldpath)) + (new (parse-unix-path unix new))) + (unless (probe-file new) + (uiop:copy-file old new) + 0))) + (define-llvm-function |gettimeofday| ((tv tz)) (let* ((unix-epoch (encode-universal-time 0 0 0 1 1 1970 0)) (current-time (/ (get-internal-real-time) @@ -966,3 +989,7 @@ Assumes the context is freshly created." (store.i32 0 rem) (store.i32 0 (+ rem 4))) 0) + +(define-llvm-function |usleep| ((usec)) + (sleep (/ usec (* 1000 1000))) + 0) From c5ea30d45aec605059225bd8fcaec94dd64becf6 Mon Sep 17 00:00:00 2001 From: iskamag Date: Sat, 18 Nov 2023 15:50:59 +0500 Subject: [PATCH 2/4] fix sdlquake build --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index b1416de..771e744 100755 --- a/build.sh +++ b/build.sh @@ -39,7 +39,7 @@ touch sdlquake-1.0.9/Makefile.in mkdir sdlquake-build pushd sdlquake-build CC="${TOOLDIR}/bin/clang -Wl,-optimize=speed+\(safety+0\)+\(debug+0\)+\(space+0\)+\(compilation-speed+0\),-package=:sdlquake" ../sdlquake-1.0.9/configure --host=le32-iota --prefix=${TOOLDIR}/le32-iota --disable-sdltest --with-sdl-prefix=${TOOLDIR}/le32-iota -touch sdlquake-1.0.9/Makefile.in +touch ../sdlquake-1.0.9/Makefile.in make ${MAKEFLAGS} popd cp sdlquake-build/sdlquake sdlquake.lisp From eeff8b2f688b5076a3d0409e046f8bddc814b950 Mon Sep 17 00:00:00 2001 From: iskamag Date: Tue, 21 Nov 2023 22:44:34 +0500 Subject: [PATCH 3/4] oops, outdated comment --- runtime/llvm-runtime.lisp | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/llvm-runtime.lisp b/runtime/llvm-runtime.lisp index 0fcd7bc..63c4028 100644 --- a/runtime/llvm-runtime.lisp +++ b/runtime/llvm-runtime.lisp @@ -674,8 +674,6 @@ PERSONALITY is bound to the context's personality object." (real-memmove llvm-context d s n)) -;;this is just a de brujin sequence from wikipedia -;;TODO: most architectures have a clz function, maybe use that (define-llvm-function |llvm.ctlz.i32| ((value zero-error-p)) (- 32 (integer-length values))) From c1ef0250392b801de87d4d1c620a17013d90f388 Mon Sep 17 00:00:00 2001 From: iskamag Date: Wed, 6 Dec 2023 12:48:36 +0500 Subject: [PATCH 4/4] oops, forgot a few things --- iota-provided-symbols | 5 +++++ runtime/llvm-runtime.lisp | 2 +- runtime/package.lisp | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/iota-provided-symbols b/iota-provided-symbols index bd50052..a719fc8 100644 --- a/iota-provided-symbols +++ b/iota-provided-symbols @@ -17,6 +17,9 @@ llvm.memmove.p0i8.p0i8.i32 memcpy llvm.memcpy.p0i8.p0i8.i32 _exit +llvm.bswap.i16 +llvm.ctlz.i32 +llvm.memcpy.p0i8.p0i8.i64 # Unix support sbrk @@ -31,6 +34,8 @@ access mkdir gettimeofday nanosleep +usleep +link # SDL support _iota_video_init diff --git a/runtime/llvm-runtime.lisp b/runtime/llvm-runtime.lisp index 63c4028..9bffed3 100644 --- a/runtime/llvm-runtime.lisp +++ b/runtime/llvm-runtime.lisp @@ -627,7 +627,7 @@ PERSONALITY is bound to the context's personality object." (ash (ldb (byte 8 16) value) 8) (ldb (byte 8 24) value))) -(define-llvm-function |llvm.bswap.i32| ((value)) +(define-llvm-function |llvm.bswap.i16| ((value)) (logior (ash (ldb (byte 8 0) value) 8) (ldb (byte 8 8) value))) diff --git a/runtime/package.lisp b/runtime/package.lisp index f9ab3b2..60dc3ab 100644 --- a/runtime/package.lisp +++ b/runtime/package.lisp @@ -390,15 +390,20 @@ #:|llvm.memmove.p0i8.p0i8.i32| #:|llvm.memset.p0i8.i32| #:|llvm.memset.p0i8.i64| + #:|llvm.memcpy.p0i8.p0i8.i64| + #:|llvm.bswap.i32| + #:|llvm.ctlz.i32| #:|longjmp| #:|lseek| #:|mkdir| #:|nanosleep| + #:|usleep| #:|open| #:|read| #:|sbrk| #:|setjmp| #:|write| + #:|link| ;; SDL support functions. #:|_iota_video_init| #:|_iota_video_quit|