micropack: add tools to find and build syscall bank map dynamically
authorAlan Cox <alan@etchedpixels.co.uk>
Tue, 27 Oct 2015 16:51:03 +0000 (16:51 +0000)
committerAlan Cox <alan@etchedpixels.co.uk>
Tue, 27 Oct 2015 16:51:03 +0000 (16:51 +0000)
We dont yet use it!

Kernel/Makefile
Kernel/platform-micropack/Makefile
Kernel/platform-micropack/syscall_bank.c [new file with mode: 0644]
Kernel/tools/map_syscall.c [new file with mode: 0644]

index 06fee8b..551862c 100644 (file)
@@ -171,6 +171,8 @@ version.c: makeversion
 
 tools/filesizes: tools/filesizes.c
 
+tools/map_syscall: tools/map_syscall.c
+
 tools/make4x6: tools/make4x6.c
 
 font4x6.c: tools/make4x6
index e4100b5..0070958 100644 (file)
@@ -1,6 +1,6 @@
 
 DSRCS = ../dev/z80pack/devlpr.c ../dev/z80pack/devfd.c
-CSRCS = devices.c main.c devtty.c
+CSRCS = devices.c main.c devtty.c syscall_bank.c
 
 ASRCS = crt0.s z80pack.s
 ASRCS += tricks.s commonmem.s
@@ -17,6 +17,11 @@ JUNK = *.rel *.lst *.asm *.sym *.rst
 
 all:   $(OBJS)
 
+syscall_bank.h: ../include/syscall_name.h ../syscall_fs.c ../syscall_fs2.c ../syscall_fs3.c ../syscall_other.c ../syscall_exec16.c
+       ../tools/map_syscall ../syscall_fs.c ../syscall_fs2.c ../syscall_fs3.c ../syscall_other.c ../syscall_exec16.c >syscall_bank.h
+
+syscall_bank.c: syscall_bank.h
+
 $(AOBJS): %.rel: %.s
        $(CROSS_AS) $(ASOPTS) $<
 
diff --git a/Kernel/platform-micropack/syscall_bank.c b/Kernel/platform-micropack/syscall_bank.c
new file mode 100644 (file)
index 0000000..034bf2f
--- /dev/null
@@ -0,0 +1,5 @@
+#include "cpu.h"
+const uint8_t syscall_bank[] = {
+#include "syscall_bank.h"
+};
+
diff --git a/Kernel/tools/map_syscall.c b/Kernel/tools/map_syscall.c
new file mode 100644 (file)
index 0000000..f1847d5
--- /dev/null
@@ -0,0 +1,60 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "../include/syscall_name.h"
+
+int syscall_bank[NR_SYSCALL];
+
+void located_function(const char *func, int code)
+{
+  int i;
+  for (i = 0; i < NR_SYSCALL; i++) {
+    if (strcmp(func, syscall_name[i]) == 0 ||
+        strcmp(func + 1, syscall_name[i]) == 0) {
+      if (syscall_bank[i])
+        fprintf(stderr, "%s is in bank %d and %d\n", func, code, 
+                          syscall_bank[i]);
+      else
+        syscall_bank[i] = code;
+      return;
+    }
+  }
+  fprintf(stderr, "%s is confusing me\n", func);
+}
+
+int scan_c_file(const char *name, int code)
+{
+  char buf[256];
+  char *t;
+  FILE *f = fopen(name, "r");
+  if (!f) {
+    perror(name);
+    exit(1);
+  }
+  while(fgets(buf, 256, f)) {
+    if (memcmp(buf, "arg_t _", 7))
+      continue;
+    t = strtok(buf + 6, " (\t\n");
+    if (t == NULL)
+      continue;
+    located_function(t, code);
+  }
+  fclose(f);
+}
+
+void output_banks(void)
+{
+  int i;
+  for (i = 0; i < NR_SYSCALL; i++)
+    printf("\t%d, /* %s */\n", syscall_bank[i], syscall_name[i]);
+}
+
+int main(int argc, char *argv[])
+{
+  int i = 1;
+  while (*++argv)
+    scan_c_file(*argv, i++);
+  output_banks();
+  return 0;
+}