
#define KERNEL
#include "ixemul.h"
#include <sys/ixnet_syscall.h>
#include <stdio.h>
#include <stddef.h>

struct syscall {
  char *name;
  int	vec;
} syscalls[] = {
#define SYSTEM_CALL(func,vec) { #func, vec},
#include <sys/ixnet_syscall.def>
#undef SYSTEM_CALL
};

int nsyscall = sizeof(syscalls) / sizeof (syscalls[0]);

#define NOBASEREL			\
".globl _NET_%s;                        \
_NET_%s: moveal _SysBase, a0;		\
moveal a0@(%d),a0;                      \
moveal a0@(%d),a0;                      \
moveal a0@(%d),a0;                      \
jmp a0@(%d:w)\n"


void usage(void)
{
  fprintf(stderr, "Usage: gen_glue\n");
  exit(1);
}

int main(int argc, char **argv)
{
  FILE *fp;
  struct syscall *sc;
  int i, v;
  int thistask_offset = offsetof(struct ExecBase,ThisTask);
  int trapdata_offset = offsetof(struct Task,tc_TrapData);
  int ixnet_offset = offsetof(struct user,u_ixnetbase);

  if (argc != 1)
    usage();
  for (i = 0, sc = syscalls; i < nsyscall; i++, sc++)
    {
      char name[strlen (sc->name) + 7];

      v = -(sc->vec + 4)*6;
      sprintf (name, "NET_%s.s", sc->name);

      fp = fopen (name, "w");

      if (!fp)
	{
	  perror (sc->name);
	  exit (20);
	}

	fprintf (fp, NOBASEREL, sc->name, sc->name,
	    thistask_offset,trapdata_offset,ixnet_offset, v);
      fclose (fp);
    }
  return (0);
}
