From 1f90f9aa63aadddaf1861b2a1fd2624b0e58ca34 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Thu, 30 Sep 2004 23:28:57 +0000 Subject: [PATCH] We do now also generate a header file that defines macros for the syscall numbers. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9133 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tools/gensyscalls/Jamfile | 11 +++++++ src/tools/gensyscalls/gensyscalls.cpp | 41 +++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/tools/gensyscalls/Jamfile b/src/tools/gensyscalls/Jamfile index 5d14463d9f..8979b3af8e 100644 --- a/src/tools/gensyscalls/Jamfile +++ b/src/tools/gensyscalls/Jamfile @@ -44,6 +44,7 @@ UseArchObjectHeaders gensyscalls.cpp : $(OBOS_ARCH) ; # place them where there are needed MakeLocate syscalls.S.inc : [ FObjectsDir src kernel libroot os ] ; MakeLocate syscall_dispatcher.h : [ FObjectsDir src kernel core ] ; +MakeLocate syscall_numbers.h : [ FObjectsDir src kernel core ] ; Depends objects/x86.R1/kernel/core : objects/x86.R1/kernel ; @@ -65,8 +66,18 @@ actions GenSyscallsDispatcher1 { $(2[1]) -d $(1) } +rule GenSyscallsNumbers { + Depends $(1) : gensyscalls ; + GenSyscallsNumbers1 $(1) : gensyscalls ; +} + +actions GenSyscallsNumbers1 { + $(2[1]) -n $(1) +} + GenSyscallsFile syscalls.S.inc ; GenSyscallsDispatcher syscall_dispatcher.h ; +GenSyscallsNumbers syscall_numbers.h ; # preprocess the syscalls header diff --git a/src/tools/gensyscalls/gensyscalls.cpp b/src/tools/gensyscalls/gensyscalls.cpp index 6057870f86..bc6bdcfbe8 100644 --- a/src/tools/gensyscalls/gensyscalls.cpp +++ b/src/tools/gensyscalls/gensyscalls.cpp @@ -14,7 +14,7 @@ extern "C" gensyscall_syscall_info *gensyscall_get_infos(int *count); // usage const char *kUsage = -"Usage: gensyscalls [ -c ] [ -d ]\n" +"Usage: gensyscalls [ -c ] [ -d ] [ -n ]\n" "\n" "The command generates a piece of assembly source file that defines the\n" "actual syscalls and a piece of C source (cases of a switch statement) for" @@ -24,7 +24,9 @@ const char *kUsage = " - Output: The assembly source file implementing the\n" " actual syscalls." " - Output: The C source file to be included by the\n" -" syscall dispatcher source file.\n"; +" syscall dispatcher source file.\n" +" - Output: The C/assembly include files defining the\n" +" syscall numbers.\n"; // print_usage static @@ -47,6 +49,7 @@ public: // parse arguments const char *syscallsFile = NULL; const char *dispatcherFile = NULL; + const char *numbersFile = NULL; for (int argi = 1; argi < argc; argi++) { string arg(argv[argi]); if (arg == "-h" || arg == "--help") { @@ -64,6 +67,12 @@ public: return 1; } dispatcherFile = argv[++argi]; + } else if (arg == "-n") { + if (argi + 1 >= argc) { + print_usage(true); + return 1; + } + numbersFile = argv[++argi]; } else { print_usage(true); return 1; @@ -71,7 +80,7 @@ public: } fSyscallInfos = gensyscall_get_infos(&fSyscallCount); _UpdateSyscallInfos(); - if (!syscallsFile && !dispatcherFile) { + if (!syscallsFile && !dispatcherFile && !numbersFile) { printf("Found %d syscalls.\n", fSyscallCount); return 0; } @@ -80,6 +89,8 @@ public: _WriteSyscallsFile(syscallsFile); if (dispatcherFile) _WriteDispatcherFile(dispatcherFile); + if (numbersFile) + _WriteNumbersFile(numbersFile); return 0; } @@ -149,6 +160,30 @@ public: } } + void _WriteNumbersFile(const char *filename) + { + // open the syscall numbers output file + ofstream file(filename, ofstream::out | ofstream::trunc); + if (!file.is_open()) + throw IOException(string("Failed to open `") + filename + "'."); + // output the defines + const char *prefix = "_user_"; + size_t prefixLen = strlen(prefix); + for (int i = 0; i < fSyscallCount; i++) { + const gensyscall_syscall_info &syscall = fSyscallInfos[i]; + string name(syscall.kernel_name); + // drop the leading "_user_" prefix + if (name.find(prefix) != 0) + throw Exception(string("Bad kernel name: `") + name + "'."); + name = string(name, prefixLen); + // convert to upper case (is there no function for that?) + string defineName; + for (int k = 0; k < (int)name.length(); k++) + defineName += toupper(name[k]); + file << "#define SYSCALL_" << defineName << " " << i << endl; + } + } + static string _GetPointerType(const char *type) { char *parenthesis = strchr(type, ')');