diff options
-rw-r--r-- | package.yaml | 3 | ||||
-rw-r--r-- | src/Config.hs | 8 | ||||
-rw-r--r-- | src/Main.hs | 17 | ||||
-rw-r--r-- | src/harness_adapter.c | 35 |
4 files changed, 45 insertions, 18 deletions
diff --git a/package.yaml b/package.yaml index 0dbf9a4..7ecbbc1 100644 --- a/package.yaml +++ b/package.yaml @@ -48,12 +48,13 @@ ghc-options: executables: wtr.so: - main: Main.hs + main: Config.hs source-dirs: src c-sources: src/harness_adapter.c ghc-options: - -shared - -dynamic + - -no-hs-main - -lHSrts-1.0.2-ghc9.4.7 cc-options: - -g3 diff --git a/src/Config.hs b/src/Config.hs new file mode 100644 index 0000000..14326cb --- /dev/null +++ b/src/Config.hs @@ -0,0 +1,8 @@ +module Config () where + +import Wetterhorn.Core + +foreign export ccall wetterhorn :: IO Wetterhorn + +wetterhorn :: IO Wetterhorn +wetterhorn = initWetterhorn defaultConfig diff --git a/src/Main.hs b/src/Main.hs deleted file mode 100644 index 03b5018..0000000 --- a/src/Main.hs +++ /dev/null @@ -1,17 +0,0 @@ -{-# HLINT ignore "Use camelCase" #-} - -module Main (main) where - -import Control.Monad.Writer (MonadWriter (tell), execWriter) -import Text.Printf -import Wetterhorn.Core - -foreign export ccall wetterhorn :: IO Wetterhorn - -wetterhorn :: IO Wetterhorn -wetterhorn = - initWetterhorn - defaultConfig - -main :: IO () -main = putStrLn "This should be dynamically linked!\n" diff --git a/src/harness_adapter.c b/src/harness_adapter.c index 5a9b9a4..6ae8c66 100644 --- a/src/harness_adapter.c +++ b/src/harness_adapter.c @@ -5,8 +5,43 @@ #include "HsFFI.h" #include "plugin_interface.h" +#include <stdio.h> const char *plugin_name = "Wetterhorn"; void plugin_load(int argc, char **argv) { hs_init(&argc, &argv); } void plugin_teardown(opqst_t st) { hs_exit(); } + +const char msg[] = + "Wetterhorn Plugin v 0.01\n" + " This is a mere shared object file, meant to be a plugin for the " + "Wetterhorn" + " Compositor. To use this, please run 'wtr_harness -p [this_file]' to" + " use this plugin.\n"; +const int msg_sz = sizeof(msg); + + +__attribute__((naked)) void _start() { + + // Make system call to print the message + asm( + // Load the address of the string into rsi + "mov %0, %%rsi\n" + // Load the string length into edx + "mov %1, %%edx\n" + // Load the file descriptor for stdout into edi + "mov $1, %%edi\n" + // Load the syscall number for sys_write into eax + "mov $1, %%eax\n" + // Make the syscall + "syscall\n" + + // Exit the program. + "mov $0, %%rdi\n" + "mov $60, %%rax\n" + "syscall\n" + : + : "r"(msg), "r"(msg_sz) // Input: address of msg + : "%rsi", "%edx", "%edi" // Clobbered registers + ); +} |