Automatically generate syscalls.h and syscalls.c as well
authorcoderain <coderain@sdf.org>
Sun, 24 Dec 2017 21:54:33 +0000 (22:54 +0100)
committercoderain <coderain@sdf.org>
Sun, 24 Dec 2017 21:54:33 +0000 (22:54 +0100)
.gitignore
Makefile
kernel/.gitignore
kernel/Makefile
kernel/src/syscalls.c
library/.gitignore
library/Makefile
library/gen_wrappers.awk [deleted file]
sdk/syscalls.h
syscalls.awk [new file with mode: 0644]

index 674843a1008368cbb642cdea08bbe67eda8c67a7..6a7461890c330a5c694adb711d72361e2c0df985 100644 (file)
@@ -18,3 +18,7 @@
 !manager/*
 !sdk
 !sdk/*
+!syscalls.awk
+
+# Exclude generate files:
+sdk/syscall_enum.h
index a3b23d37a6290ce30876ef7d4fe8de79694f8ec8..b6fdebf65f5d04f59da18548715b28f60a8a5f44 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,14 +1,16 @@
-.PHONY: all clean crt kernel library manager tests
+.PHONY: all clean crt kernel library manager tests generate
+
+GENERATED_SOURCES = sdk/syscall_enum.h kernel/src/syscall_table.inl library/src/wrappers.c
 
 all: livecd.iso tests
 
 crt:
        $(MAKE) -C crt all
 
-kernel: crt
+kernel: generate crt
        $(MAKE) -C kernel all
 
-library: kernel
+library: generate crt
        $(MAKE) -C library all
 
 manager: library
@@ -17,12 +19,20 @@ manager: library
 tests:
        $(MAKE) -C tests all
 
+generate: $(GENERATED_SOURCES)
+
+sdk/syscall_enum.h: $(wildcard sdk/*.h) syscalls.awk
+       @echo 'Generating system call sources/headers...'
+       sort sdk/* | awk -v enum_file=sdk/syscall_enum.h -v table_file=kernel/src/syscall_table.inl -v wrappers_file=library/src/wrappers.c -f syscalls.awk
+
+kernel/src/syscall_table.inl: sdk/syscall_enum.h
+
+library/src/wrappers.c: sdk/syscall_enum.h
+
 livecd.iso: kernel library manager
-       mkdir -p livecd
-       mkdir -p livecd/boot
+       mkdir -p livecd/boot/grub
        cp kernel/monolithium livecd/boot/monolithium
        cp manager/manager livecd/manager
-       mkdir -p livecd/boot/grub
        cp grub.cfg livecd/boot/grub/grub.cfg
        grub-mkrescue -o $@ livecd
 
@@ -32,4 +42,4 @@ clean:
        $(MAKE) -C library clean
        $(MAKE) -C manager clean
        $(MAKE) -C tests clean
-       rm livecd.iso
+       rm -f $(GENERATED_SOURCES) livecd.iso
index ba0ab94411dfb58e130fea3a8af96a22f01c7801..e039312dec8116e68f3003aa165bc425dc724a57 100644 (file)
@@ -8,3 +8,6 @@
 !include/**
 !src
 !src/**
+
+# Exclude generated files:
+src/syscall_table.inl
index 16c0d82d9fdfed3d1e38290ca707ce8103007ece..44941dd22df44ff35c9f8400bb4c2e0ef9ac6605 100644 (file)
@@ -66,7 +66,7 @@ all: $(OBJDIR) $(DEPDIR) monolithium
 clean:
        find $(OBJDIR) -name \*.o -delete
        find $(DEPDIR) -name \*.d -delete
-       rm monolithium
+       rm -f monolithium
 
 -include $(DEPENDS)
 
index 54b7fda26c2666377727512b8de26d4dee3843f5..97cfd328761c041bb5698cdba4da1e405acac804 100644 (file)
 #include <exception.h>
 #include <pipe.h>
 
-extern qword_t syscall_function(const void*, dword_t*, dword_t);
+extern sysret_t syscall_function(const void*, dword_t*, dword_t);
 
-const void *service_table[] =
-{
-    &syscall_alloc_memory,
-    &syscall_clock_get_time,
-    &syscall_clock_set_time,
-    &syscall_close_object,
-    &syscall_commit_memory,
-    &syscall_connect_pipeline,
-    &syscall_create_memory_section,
-    &syscall_create_pipeline,
-    &syscall_create_process,
-    &syscall_create_semaphore,
-    &syscall_create_thread,
-    &syscall_create_user,
-    &syscall_delete_file,
-    &syscall_delete_user,
-    &syscall_device_ioctl,
-    &syscall_duplicate_handle,
-    &syscall_enum_processes,
-    &syscall_flush_memory_section,
-    &syscall_free_memory,
-    &syscall_freeze_thread,
-    &syscall_get_exception_info,
-    &syscall_get_milliseconds,
-    &syscall_get_nanoseconds,
-    &syscall_list_directory,
-    &syscall_listen_pipeline,
-    &syscall_logon_user,
-    &syscall_map_memory_section,
-    &syscall_mount,
-    &syscall_open_file,
-    &syscall_open_memory_section,
-    &syscall_open_pipeline,
-    &syscall_open_process,
-    &syscall_open_semaphore,
-    &syscall_open_thread,
-    &syscall_power_control,
-    &syscall_query_file,
-    &syscall_query_handle,
-    &syscall_query_memory,
-    &syscall_query_process,
-    &syscall_query_thread,
-    &syscall_query_user,
-    &syscall_raise_exception,
-    &syscall_read_file,
-    &syscall_read_memory,
-    &syscall_read_pipe,
-    &syscall_release_semaphore,
-    &syscall_restore_exception_handler,
-    &syscall_revert_user,
-    &syscall_save_exception_handler,
-    &syscall_set_file,
-    &syscall_set_memory_flags,
-    &syscall_set_thread,
-    &syscall_set_user_id,
-    &syscall_sleep,
-    &syscall_terminate,
-    &syscall_terminate_thread,
-    &syscall_thaw_thread,
-    &syscall_uncommit_memory,
-    &syscall_unmount,
-    &syscall_wait_directory_event,
-    &syscall_wait_process,
-    &syscall_wait_semaphore,
-    &syscall_wait_thread,
-    &syscall_write_file,
-    &syscall_write_memory,
-    &syscall_write_pipe,
-    &syscall_yield_quantum,
-};
+#include "syscall_table.inl"
 
 static void system_service_handler(registers_t *regs, byte_t int_num)
 {
index 1d95067dd0b9c0b700ba702c3563447fba735869..b3c20b3a58efee5f91145ea9a38a7d923de59317 100644 (file)
@@ -7,4 +7,5 @@
 !src
 !src/*
 
-src/wrappers.c
\ No newline at end of file
+# Exclude generated files:
+src/wrappers.c
index 7fd43577920b433dbcc0e733e2a27cc359dd1095..c708037c55d9a9927b5146dbb11bf49dfbf6e716 100644 (file)
@@ -40,10 +40,7 @@ else
 endif
 
 # Input and output files
-WRAPPERS = $(SRCDIR)/wrappers.c
-
 SOURCES =  $(wildcard $(SRCDIR)/*.c)
-SOURCES += $(WRAPPERS)
 SOURCES += $(wildcard $(SRCDIR)/*.asm)
 
 DEPENDS = $(shell find $(DEPDIR) -type f -name \*.d)
@@ -61,9 +58,6 @@ $(OBJDIR):
 $(DEPDIR):
        mkdir -p $(DEPDIR)
 
-$(WRAPPERS): $(wildcard ../sdk/*.h)
-       sort $^ | awk -f gen_wrappers.awk > $@
-
 $(OBJDIR)/%.o: $(SRCDIR)/%.c Makefile
        mkdir -p $(dir $@)
        mkdir -p $(dir $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d))
@@ -77,6 +71,5 @@ libmlsys.a: $(OBJECTS)
 
 clean:
        rm -f libmlsys.a
-       rm -f $(SRCDIR)/wrappers.c
        find $(OBJDIR) -name \*.o -delete
        find $(DEPDIR) -name \*.d -delete
diff --git a/library/gen_wrappers.awk b/library/gen_wrappers.awk
deleted file mode 100644 (file)
index d7846ee..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-BEGIN {
-    FS = ",[ ]*";
-
-    print "/*";
-    print " * wrappers.c (Automatically generated)";
-    print " *";
-    print " * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>";
-    print " *";
-    print " * This program is free software: you can redistribute it and/or modify";
-    print " * it under the terms of the GNU Affero General Public License as";
-    print " * published by the Free Software Foundation, either version 3 of the";
-    print " * License, or (at your option) any later version.";
-    print " *";
-    print " * This program is distributed in the hope that it will be useful,";
-    print " * but WITHOUT ANY WARRANTY; without even the implied warranty of";
-    print " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the";
-    print " * GNU Affero General Public License for more details.";
-    print " *";
-    print " * You should have received a copy of the GNU Affero General Public License";
-    print " * along with this program.  If not, see <http://www.gnu.org/licenses/>.";
-    print " */";
-    print "";
-    print "#include <sdk/monolithium.h>";
-    print "";
-}
-
-/sysret_t syscall_[a-zA-Z0-9_]+\(.*\);/ {
-    print substr($0, 1, length - 1);
-    print "{";
-
-    match($0, /\(.*\)/);
-    printf "    return syscall(" toupper(substr($0, 10, RSTART - 10));
-
-    $0 = substr($0, RSTART + 1, RLENGTH - 2);
-
-    if ($0 != "void") {
-        for (i = 1; i <= NF; i++) {
-            match($i, /[a-zA-Z0-9_]*$/);
-            printf ", " substr($i, RSTART);
-        }
-    }
-
-    print ");";
-    print "}";
-    print "";
-}
index 69724d92ce5520a55e81aef514eb175db9ab0948..6b4aa9ec30dffc2d7bded0441d7e166ddf440921 100644 (file)
 #define MAX_PARAMETERS 16
 #define SYSCALL_INTERRUPT 0xE5
 
-typedef enum
-{
-    SYSCALL_ALLOC_MEMORY,
-    SYSCALL_CLOCK_GET_TIME,
-    SYSCALL_CLOCK_SET_TIME,
-    SYSCALL_CLOSE_OBJECT,
-    SYSCALL_COMMIT_MEMORY,
-    SYSCALL_CONNECT_PIPELINE,
-    SYSCALL_CREATE_MEMORY_SECTION,
-    SYSCALL_CREATE_PIPELINE,
-    SYSCALL_CREATE_PROCESS,
-    SYSCALL_CREATE_SEMAPHORE,
-    SYSCALL_CREATE_THREAD,
-    SYSCALL_CREATE_USER,
-    SYSCALL_DELETE_FILE,
-    SYSCALL_DELETE_USER,
-    SYSCALL_DEVICE_IOCTL,
-    SYSCALL_DUPLICATE_HANDLE,
-    SYSCALL_ENUM_PROCESSES,
-    SYSCALL_FLUSH_MEMORY_SECTION,
-    SYSCALL_FREE_MEMORY,
-    SYSCALL_FREEZE_THREAD,
-    SYSCALL_GET_EXCEPTION_INFO,
-    SYSCALL_GET_MILLISECONDS,
-    SYSCALL_GET_NANOSECONDS,
-    SYSCALL_LIST_DIRECTORY,
-    SYSCALL_LISTEN_PIPELINE,
-    SYSCALL_LOGON_USER,
-    SYSCALL_MAP_MEMORY_SECTION,
-    SYSCALL_MOUNT,
-    SYSCALL_OPEN_FILE,
-    SYSCALL_OPEN_MEMORY_SECTION,
-    SYSCALL_OPEN_PIPELINE,
-    SYSCALL_OPEN_PROCESS,
-    SYSCALL_OPEN_SEMAPHORE,
-    SYSCALL_OPEN_THREAD,
-    SYSCALL_POWER_CONTROL,
-    SYSCALL_QUERY_FILE,
-    SYSCALL_QUERY_HANDLE,
-    SYSCALL_QUERY_MEMORY,
-    SYSCALL_QUERY_PROCESS,
-    SYSCALL_QUERY_THREAD,
-    SYSCALL_QUERY_USER,
-    SYSCALL_RAISE_EXCEPTION,
-    SYSCALL_READ_FILE,
-    SYSCALL_READ_MEMORY,
-    SYSCALL_READ_PIPE,
-    SYSCALL_RELEASE_SEMAPHORE,
-    SYSCALL_RESTORE_EXCEPTION_HANDLER,
-    SYSCALL_REVERT_USER,
-    SYSCALL_SAVE_EXCEPTION_HANDLER,
-    SYSCALL_SET_FILE,
-    SYSCALL_SET_MEMORY_FLAGS,
-    SYSCALL_SET_THREAD,
-    SYSCALL_SET_USER_ID,
-    SYSCALL_SLEEP,
-    SYSCALL_TERMINATE,
-    SYSCALL_TERMINATE_THREAD,
-    SYSCALL_THAW_THREAD,
-    SYSCALL_UNCOMMIT_MEMORY,
-    SYSCALL_UNMOUNT,
-    SYSCALL_WAIT_DIRECTORY_EVENT,
-    SYSCALL_WAIT_PROCESS,
-    SYSCALL_WAIT_SEMAPHORE,
-    SYSCALL_WAIT_THREAD,
-    SYSCALL_WRITE_FILE,
-    SYSCALL_WRITE_MEMORY,
-    SYSCALL_WRITE_PIPE,
-    SYSCALL_YIELD_QUANTUM,
-
-    SERVICE_COUNT
-} syscall_number_t;
+#include "syscall_enum.h"
 
 sysret_t syscall(syscall_number_t num, ...);
 
diff --git a/syscalls.awk b/syscalls.awk
new file mode 100644 (file)
index 0000000..7056277
--- /dev/null
@@ -0,0 +1,59 @@
+BEGIN {
+    FS = ",[ ]*";
+
+    if (!wrappers_file || !enum_file || !table_file)
+    {
+        print "Error: One or more filenames have not been specified.";
+        exit 1;
+    }
+
+    print "/* This file has been automatically generated */" > enum_file;
+    print "" >> enum_file;
+    print "typedef enum" >> enum_file;
+    print "{" >> enum_file;
+
+    print "/* This file has been automatically generated */" > table_file;
+    print "" >> table_file;
+    print "const void *service_table[] =" >> table_file;
+    print "{" >> table_file
+
+    print "/* This file has been automatically generated */" > wrappers_file;
+    print "" >> wrappers_file;
+    print "#include <sdk/monolithium.h>" >> wrappers_file;
+    print "" >> wrappers_file;
+}
+
+END {
+    if (enum_file && table_file && wrappers_file) {
+        print "" >> enum_file;
+        print "    SERVICE_COUNT" >> enum_file;
+        print "} syscall_number_t;" >> enum_file;
+
+        print "};" >> table_file;
+    }
+}
+
+/sysret_t syscall_[a-zA-Z0-9_]+\(.*\);/ {
+    print substr($0, 1, length - 1) >> wrappers_file;
+    print "{" >> wrappers_file;
+
+    match($0, /\(.*\)/);
+    name = substr($0, 10, RSTART - 10);
+
+    print "    &" name "," >> table_file;
+    print "    " toupper(name) "," >> enum_file;
+    printf "    return syscall(" toupper(name) >> wrappers_file;
+
+    $0 = substr($0, RSTART + 1, RLENGTH - 2);
+
+    if ($0 != "void") {
+        for (i = 1; i <= NF; i++) {
+            match($i, /[a-zA-Z0-9_]*$/);
+            printf ", " substr($i, RSTART) >> wrappers_file;
+        }
+    }
+
+    print ");" >> wrappers_file;
+    print "}" >> wrappers_file;
+    print "" >> wrappers_file;
+}