diff options
author | dzwdz | 2023-08-14 18:51:07 +0200 |
---|---|---|
committer | dzwdz | 2023-08-14 18:51:07 +0200 |
commit | 642b5fb0007b64c77d186fcb018d571152ee1d47 (patch) | |
tree | 1c466461f3602d306be309a053edae558ef2568e /src/libc/syscall.c.awk | |
parent | 8050069c57b729c18c19b1a03ab6e4bf63b4735e (diff) |
reorganization: first steps
Diffstat (limited to 'src/libc/syscall.c.awk')
-rw-r--r-- | src/libc/syscall.c.awk | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/libc/syscall.c.awk b/src/libc/syscall.c.awk new file mode 100644 index 0000000..591a6f0 --- /dev/null +++ b/src/libc/syscall.c.awk @@ -0,0 +1,51 @@ +BEGIN { + print "\ +/* generated by syscall.c.awk\n\ + * don't modify manually, instead run:\n\ + * make src/user/lib/syscall.c\n\ + */\n\ +#include <camellia/syscalls.h>\n\ +\n"; +} + +/_syscall\(/ { next; } # skipping _syscall(), it's implemented elsewhere + +/\);/ { + sub(/;/, " {"); + print $0; + + name = substr($0, match($0, /_sys_[^(]+/), RLENGTH); + rets = substr($0, 0, RSTART - 1); + sub(/ *$/, "", rets) + + params = substr($0, match($0, /\(.+\)/) + 1, RLENGTH - 2); + gsub(/\[[^\]]\]/, "", params); + if (params == "void") params = "" + + split(params, p, /,/); + for (i = 0; i < 6; i += 1) { + if (p[i]) { + # p[i] is a parameter, convert it into an expression to pass to _syscall() + sub(/^ */, "", p[i]); # strip + split(p[i], words, / /); + if (length(words) != 1) { + var = words[length(words)]; + sub(/\*/, "", var); + if (words[1] != "long") var = "(long)" var; + } + p[i] = var; + } else { + p[i] = 0; + } + } + + printf "\t"; + if (!index($0, "_Noreturn")) { + printf "return "; + if (rets != "long") printf "(%s)", rets; + } + printf "_syscall(%s, %s, %s, %s, %s, %s);\n", toupper(name), p[1], p[2], p[3], p[4], p[5]; + if (index($0, "_Noreturn")) print "\t__builtin_unreachable();"; + + print "}\n"; +} |