view rathaxes_add_a_linux_lkm.patch @ 30:b4ca25b88690

Finish patches on the CMake library and on #includes
author Louis Opter <louis@lse.epitech.net>
date Sat, 07 Jan 2012 21:11:13 +0100
parents 44a25ffd5c8c
children
line wrap: on
line source

# HG changeset patch
# Parent 9006ed3c5074b918e2f824b0053b494e2a82dbb8
rathaxes: add a kernel module sample (for now Linux only)

diff --git a/rathaxes/samples/CMakeLists.txt b/rathaxes/samples/CMakeLists.txt
--- a/rathaxes/samples/CMakeLists.txt
+++ b/rathaxes/samples/CMakeLists.txt
@@ -1,2 +1,3 @@
 ADD_SUBDIRECTORY(helloworld)
+ADD_SUBDIRECTORY(lkm)
 ADD_SUBDIRECTORY(syntax)
diff --git a/rathaxes/samples/lkm/CMakeLists.txt b/rathaxes/samples/lkm/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/rathaxes/samples/lkm/CMakeLists.txt
@@ -0,0 +1,3 @@
+ADD_RATHAXES_SOURCES(lkm lkm.rtx
+                     RTI log.rti lkm.rti
+                     BLT log.blt lkm.blt)
diff --git a/rathaxes/samples/lkm/lkm.blt b/rathaxes/samples/lkm/lkm.blt
new file mode 100644
--- /dev/null
+++ b/rathaxes/samples/lkm/lkm.blt
@@ -0,0 +1,47 @@
+with LKM
+{
+    ${pointcut LKM::includes};
+    ${pointcut LKM::init};
+    ${pointcut LKM::exit};
+
+    template sequence   LKM::init()
+    {
+        chunk   LKM::includes()
+        {
+            #include <linux/module.h>
+            #include <linux/kernel.h>
+            typedef int  lkm_headers_include_stamp;
+
+            MODULE_DESCRIPTION(${config.description});
+            MODULE_AUTHOR(${config.author});
+            MODULE_LICENSE(${config.license});
+        }
+
+        chunk   LKM::init()
+        {
+            /*
+             * Rathaxes doesn't yet support arbitrary "decorators" like __init
+             * or __exit.
+             */
+            static int __attribute__((__section__(.init.text)))  rtx_module_init(void)
+            {
+                ${pointcut ::IMPLEMENTATION};
+            }
+
+            module_init(rtx_module_init);
+        }
+    }
+
+    template sequence   LKM::exit()
+    {
+        chunk   LKM::exit
+        {
+            static void __attribute((__section__(.exit.text)))   rtx_module_exit(void)
+            {
+                ${pointcut ::IMPLEMENTATION};
+            }
+
+            module_exit(rtx_module_init);
+        }
+    }
+}
diff --git a/rathaxes/samples/lkm/lkm.rti b/rathaxes/samples/lkm/lkm.rti
new file mode 100644
--- /dev/null
+++ b/rathaxes/samples/lkm/lkm.rti
@@ -0,0 +1,21 @@
+interface LKM
+{
+    provided pointcut   LKM::includes;
+    provided pointcut   LKM::init;
+    provided pointcut   LKM::exit;
+
+    required variable ::string  LKM::author;
+    required variable ::string  LKM::description;
+    required variable ::string  LKM::license;
+
+    required sequence   LKM::init()
+    {
+        provided chunk  LKM::includes;
+        provided chunk  LKM::init;
+    }
+
+    required sequence   LKM::exit()
+    {
+        provided chunk  LKM::exit;
+    }
+}
diff --git a/rathaxes/samples/lkm/lkm.rtx b/rathaxes/samples/lkm/lkm.rtx
new file mode 100644
--- /dev/null
+++ b/rathaxes/samples/lkm/lkm.rtx
@@ -0,0 +1,19 @@
+device LKM use LKM, Log
+{
+    LKM::init()
+    {
+        Log::info("Hello this is LKM");
+    }
+
+    LKM::exit()
+    {
+        Log::info("Good bye this was LKM");
+    }
+}
+
+configuration
+{
+    LKM::author = "Rathaxes";
+    LKM::description = "Hello World Loadable Kernel Module (LKM)";
+    LKM::license = "BSD";
+}
diff --git a/rathaxes/samples/lkm/log.blt b/rathaxes/samples/lkm/log.blt
new file mode 100644
--- /dev/null
+++ b/rathaxes/samples/lkm/log.blt
@@ -0,0 +1,10 @@
+with Log
+{
+    template sequence   Log::info(::string msg)
+    {
+        chunk   ::CALL
+        {
+            pr_info("%s\n", ${msg});
+        }
+    }
+}
diff --git a/rathaxes/samples/lkm/log.rti b/rathaxes/samples/lkm/log.rti
new file mode 100644
--- /dev/null
+++ b/rathaxes/samples/lkm/log.rti
@@ -0,0 +1,7 @@
+interface Log
+{
+    provided sequence   Log::info(::string)
+    {
+        provided chunk  ::CALL;
+    }
+}