From c9665ce5bd0777d4ec6d545a8119ad9cd2a5652c Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 15 Jan 2025 13:14:02 +0100 Subject: [PATCH] Sanity checking when generating usys.S --- user/user.h | 3 +++ user/usys.py | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/user/user.h b/user/user.h index ed10ca8..d889278 100644 --- a/user/user.h +++ b/user/user.h @@ -6,6 +6,9 @@ struct stat; /** * System calls + * + * Note that none of these calls are implemented in C. They are implemented in assembly in [usys.S](./usys.S). This file + * is in turn generated by the [usys.py](./usys.py) script during the build. */ /** Create a child process */ diff --git a/user/usys.py b/user/usys.py index 21ecd2d..896bf6d 100755 --- a/user/usys.py +++ b/user/usys.py @@ -42,6 +42,26 @@ assembly = "\n\n".join(map(genstub, syscalls)) # TODO: Perhaps do some more specific assertions on the code here assert len(assembly) > 0, "No assembly code generated. Something is fishy" +with open("kernel/syscall.h", "r") as sfile: + lines = list(filter(lambda x: x.startswith("#define"), sfile.readlines())) + + header_calls = set([line.split()[1] for line in lines]) + calls = set(["SYS_" + call for call in syscalls]) + + if header_calls == calls: + print("All items match in both sets.") + else: + missing_in_calls = header_calls - calls + missing_in_header_calls = calls - header_calls + + if missing_in_calls: + print("These items are in header_calls but not in calls:", missing_in_calls) + if missing_in_header_calls: + print( + "These items are in calls but not in header_calls:", + missing_in_header_calls, + ) + print("# generated by usys.py - do not edit\n") print('#include "kernel/syscall.h"\n') print(assembly)