summaryrefslogtreecommitdiff
path: root/emu/Irix
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 17:07:39 +0000
commit37da2899f40661e3e9631e497da8dc59b971cbd0 (patch)
treecbc6d4680e347d906f5fa7fca73214418741df72 /emu/Irix
parent54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff)
20060303a
Diffstat (limited to 'emu/Irix')
-rw-r--r--emu/Irix/NOTE1
-rw-r--r--emu/Irix/asm-mips.s31
-rw-r--r--emu/Irix/cmd.c205
-rw-r--r--emu/Irix/devfs.c1
-rw-r--r--emu/Irix/emu106
-rw-r--r--emu/Irix/mkfile50
-rw-r--r--emu/Irix/mkfile-Irix14
-rw-r--r--emu/Irix/os.c477
8 files changed, 885 insertions, 0 deletions
diff --git a/emu/Irix/NOTE b/emu/Irix/NOTE
new file mode 100644
index 00000000..d317c90e
--- /dev/null
+++ b/emu/Irix/NOTE
@@ -0,0 +1 @@
+for some strange reason, it lacks deveia!
diff --git a/emu/Irix/asm-mips.s b/emu/Irix/asm-mips.s
new file mode 100644
index 00000000..394baa36
--- /dev/null
+++ b/emu/Irix/asm-mips.s
@@ -0,0 +1,31 @@
+#include <sys/regdef.h>
+#include <sys/asm.h>
+
+LEAF(FPsave)
+ cfc1 t0, $31
+ sw t0, 0(a0) /* a0 is argument */
+ j $31
+ END(FPsave)
+
+LEAF(FPrestore)
+ lw t0, 0(a0) /* a0 is argument */
+ ctc1 t0, $31
+ j $31
+ END(FPrestore)
+
+
+/*
+ * lock from r4000 book
+ */
+LEAF(_tas)
+ .set noreorder
+1:
+ ll v0,0(a0) /* a0 is argument */
+ or t1, v0, 1
+ sc t1,0(a0)
+ beq t1,zero,1b
+ nop
+ j $31 /* lock held */
+ nop
+ .set reorder
+ END(_tas)
diff --git a/emu/Irix/cmd.c b/emu/Irix/cmd.c
new file mode 100644
index 00000000..97e303ac
--- /dev/null
+++ b/emu/Irix/cmd.c
@@ -0,0 +1,205 @@
+#include <sys/types.h>
+#include <signal.h>
+#include <pwd.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include <fcntl.h>
+
+#include "dat.h"
+#include "fns.h"
+#include "error.h"
+
+enum
+{
+ Debug = 0
+};
+
+/*
+ * os-specific devcmd support.
+ * this version should be reasonably portable across Unix systems.
+ */
+typedef struct Targ Targ;
+struct Targ
+{
+ int fd[2]; /* fd[0] is standard input, fd[1] is standard output */
+ char** args;
+ char* dir;
+ int pid;
+ int wfd; /* child writes errors that occur after the fork or on exec */
+ int uid;
+ int gid;
+};
+
+extern int gidnobody;
+extern int uidnobody;
+
+static int
+childproc(Targ *t)
+{
+ int i, nfd;
+
+ if(Debug)
+ print("devcmd: '%s'", t->args[0]);
+
+ nfd = getdtablesize();
+ for(i = 0; i < nfd; i++)
+ if(i != t->fd[0] && i != t->fd[1] && i != t->wfd)
+ close(i);
+
+ dup2(t->fd[0], 0);
+ dup2(t->fd[1], 1);
+ dup2(t->fd[1], 2);
+ close(t->fd[0]);
+ close(t->fd[1]);
+
+ if(t->gid != -1){
+ if(setgid(t->gid) < 0 && getegid() == 0){
+ fprint(t->wfd, "can't set gid %d: %s", t->gid, strerror(errno));
+ _exit(1);
+ }
+ }
+
+ if(t->uid != -1){
+ if(setuid(t->uid) < 0 && geteuid() == 0){
+ fprint(t->wfd, "can't set uid %d: %s", t->uid, strerror(errno));
+ _exit(1);
+ }
+ }
+
+ if(t->dir != nil && chdir(t->dir) < 0){
+ fprint(t->wfd, "can't chdir to %s: %s", t->dir, strerror(errno));
+ _exit(1);
+ }
+
+ signal(SIGPIPE, SIG_DFL);
+
+ execvp(t->args[0], t->args);
+ if(Debug)
+ print("execvp: %s\n",strerror(errno));
+ fprint(t->wfd, "exec failed: %s", strerror(errno));
+
+ _exit(1);
+}
+
+void*
+oscmd(char **args, int nice, char *dir, int *rfd, int *sfd)
+{
+ Dir *d;
+ Targ *t;
+ int r, fd0[2], fd1[2], wfd[2], n, pid;
+
+ t = mallocz(sizeof(*t), 1);
+ if(t == nil)
+ return nil;
+
+ fd0[0] = fd0[1] = -1;
+ fd1[0] = fd1[1] = -1;
+ wfd[0] = wfd[1] = -1;
+ if(pipe(fd0) < 0 || pipe(fd1) < 0 || pipe(wfd) < 0)
+ goto Error;
+ if(fcntl(wfd[1], F_SETFD, FD_CLOEXEC) < 0) /* close on exec to give end of file on success */
+ goto Error;
+
+ t->fd[0] = fd0[0];
+ t->fd[1] = fd1[1];
+ t->wfd = wfd[1];
+ t->args = args;
+ t->dir = dir;
+ t->gid = up->env->gid;
+ if(t->gid == -1)
+ t->gid = gidnobody;
+ t->uid = up->env->uid;
+ if(t->uid == -1)
+ t->uid = uidnobody;
+
+ signal(SIGCHLD, SIG_DFL);
+ switch(pid = fork()) {
+ case -1:
+ goto Error;
+ case 0:
+ setpgrp();
+ if(nice)
+ oslopri();
+ childproc(t);
+ _exit(1);
+ default:
+ t->pid = pid;
+ if(Debug)
+ print("cmd pid %d\n", t->pid);
+ break;
+ }
+
+ close(fd0[0]);
+ close(fd1[1]);
+ close(wfd[1]);
+
+ n = read(wfd[0], up->genbuf, sizeof(up->genbuf)-1);
+ close(wfd[0]);
+ if(n > 0){
+ close(fd0[1]);
+ close(fd1[0]);
+ free(t);
+ up->genbuf[n] = 0;
+ if(Debug)
+ print("oscmd: bad exec: %q\n", up->genbuf);
+ error(up->genbuf);
+ return nil;
+ }
+
+ *sfd = fd0[1];
+ *rfd = fd1[0];
+ return t;
+
+Error:
+ r = errno;
+ if(Debug)
+ print("oscmd: %q\n",strerror(r));
+ close(fd0[0]);
+ close(fd0[1]);
+ close(fd1[0]);
+ close(fd1[1]);
+ close(wfd[0]);
+ close(wfd[1]);
+ error(strerror(r));
+ return nil;
+}
+
+int
+oscmdkill(void *a)
+{
+ Targ *t = a;
+
+ if(Debug)
+ print("kill: %d\n", t->pid);
+ return kill(-t->pid, SIGTERM);
+}
+
+int
+oscmdwait(void *a, char *buf, int n)
+{
+ Targ *t = a;
+ int s;
+
+ if(waitpid(t->pid, &s, 0) == -1){
+ if(Debug)
+ print("wait error: %d [in %d] %q\n", t->pid, getpid(), strerror(errno));
+ return -1;
+ }
+ if(WIFEXITED(s)){
+ if(WEXITSTATUS(s) == 0)
+ return snprint(buf, n, "%d 0 0 0 ''", t->pid);
+ return snprint(buf, n, "%d 0 0 0 'exit: %d'", t->pid, WEXITSTATUS(s));
+ }
+ if(WIFSIGNALED(s)){
+ if(WTERMSIG(s) == SIGTERM || WTERMSIG(s) == SIGKILL)
+ return snprint(buf, n, "%d 0 0 0 killed", t->pid);
+ return snprint(buf, n, "%d 0 0 0 'signal: %d'", t->pid, WTERMSIG(s));
+ }
+ return snprint(buf, n, "%d 0 0 0 'odd status: 0x%x'", t->pid, s);
+}
+
+void
+oscmdfree(void *a)
+{
+ free(a);
+}
diff --git a/emu/Irix/devfs.c b/emu/Irix/devfs.c
new file mode 100644
index 00000000..9017c3fc
--- /dev/null
+++ b/emu/Irix/devfs.c
@@ -0,0 +1 @@
+#include "devfs-posix.c"
diff --git a/emu/Irix/emu b/emu/Irix/emu
new file mode 100644
index 00000000..f689662e
--- /dev/null
+++ b/emu/Irix/emu
@@ -0,0 +1,106 @@
+dev
+ root
+ cons
+ env
+ mnt
+ pipe
+ prog
+ prof
+ srv
+ dup
+ ssl
+ cap
+ fs
+ cmd cmd
+ indir
+
+ draw
+ pointer
+ snarf
+
+ ip ipif-posix ipaux
+# eia
+# audio audio
+ mem
+
+lib
+ interp
+ tk
+ freetype
+ math
+ draw
+
+ memlayer
+ memdraw
+ keyring
+ sec
+ mp
+
+ 9
+
+link
+
+mod
+ sys
+ draw
+
+ tk
+ math
+ srv srv
+ keyring
+ loader
+ freetype
+
+port
+ alloc
+ cache
+ chan
+ dev
+ dial
+ dis
+ discall
+ env
+ error
+ errstr
+ exception
+ exportfs
+ inferno
+ latin1
+ main
+ parse
+ pgrp
+ print
+ proc
+ qio
+ random
+ sysfile
+ uqid
+
+code
+
+init
+ emuinit
+
+root
+ /dev /
+ /fd /
+ /prog /
+ /net /
+ /net.alt /
+ /chan /
+ /nvfs /
+ /env /
+# /chan
+# /dev
+# /dis
+# /env
+# /n
+# /net
+# /nvfs /
+# /prog
+# /icons
+# /osinit.dis
+# /dis/emuinit.dis
+# /dis/lib/auth.dis
+# /dis/lib/ssl.dis
+# /n/local /
diff --git a/emu/Irix/mkfile b/emu/Irix/mkfile
new file mode 100644
index 00000000..5d121eea
--- /dev/null
+++ b/emu/Irix/mkfile
@@ -0,0 +1,50 @@
+SYSTARG=Irix
+OBJTYPE=mips
+<../../mkconfig
+SYSTARG=Irix
+OBJTYPE=mips
+
+#Configurable parameters
+
+CONF=emu #default configuration
+CONFLIST=emu
+CLEANCONFLIST=
+
+INSTALLDIR=$ROOT/$SYSTARG/$OBJTYPE/bin #path of directory where kernel is installed
+
+#end configurable parameters
+
+<$ROOT/mkfiles/mkfile-$SYSTARG-$OBJTYPE #set vars based on target system
+
+<| $SHELLNAME ../port/mkdevlist $CONF #sets $IP, $DEVS, $PORT, $LIBS
+
+OBJ=\
+ asm-$OBJTYPE.$O\
+ os.$O\
+ win-x11a.$O\
+ $CONF.root.$O\
+ lock.$O\
+ $DEVS\
+ $PORT\
+
+LIBNAMES=${LIBS:%=lib%.a}
+#libs=${LIBS:%=$ROOT/$OBJDIR/lib/lib%.a}
+
+HFILES=\
+
+CFLAGS='-DROOT="'$ROOT'"' -DEMU -I. -I../port -I$ROOT/$SYSTARG/$OBJTYPE/include -I$ROOT/include -I$ROOT/libinterp $CTHREADFLAGS $CFLAGS $EMUOPTIONS
+SYSLIBS= -lfpe -lm -lX11 -lXext
+KERNDATE=`{$NDATE}
+
+default:V: $O.$CONF
+
+$O.$CONF: $OBJ $CONF.c $CONF.root.h $LIBNAMES
+ $CC $CFLAGS '-DKERNDATE='$KERNDATE $CONF.c
+ $LD $LDFLAGS -o $target $OBJ $CONF.$O $LIBFILES $SYSLIBS
+
+install:V: $O.$CONF
+ cp $O.$CONF $INSTALLDIR/$CONF
+
+<../port/portmkfile
+
+devfs.$O: ../port/devfs-posix.c
diff --git a/emu/Irix/mkfile-Irix b/emu/Irix/mkfile-Irix
new file mode 100644
index 00000000..1d1bbdc3
--- /dev/null
+++ b/emu/Irix/mkfile-Irix
@@ -0,0 +1,14 @@
+#
+# architecture-dependent files for IRIX
+#
+
+TARGFILES=asm-Irix.$O\
+ devfs-posix.$O\
+ devip.$O\
+ ipif-posix.$O\
+ os-Irix.$O\
+ win-x11.$O\
+ srv.$O\
+ lock.$O\
+
+SYSLIBS= -lfpe -lm -lX11
diff --git a/emu/Irix/os.c b/emu/Irix/os.c
new file mode 100644
index 00000000..42bcf99b
--- /dev/null
+++ b/emu/Irix/os.c
@@ -0,0 +1,477 @@
+/* Link with -lfpe. See man pages for fpc
+ * and /usr/include/sigfpe.h, sys/fpu.h.
+ */
+#include "dat.h"
+#include "fns.h"
+#include "error.h"
+#include <time.h>
+#include <ulocks.h>
+#include <termios.h>
+#include <sigfpe.h>
+#include <sys/prctl.h>
+#include <sys/fpu.h>
+#include <sys/cachectl.h>
+#undef _POSIX_SOURCE /* SGI incompetence */
+#include <signal.h>
+#define _BSD_TIME
+/* for gettimeofday(), which isn't POSIX,
+ * but is fairly common
+ */
+#include <sys/time.h>
+#define _POSIX_SOURCE
+#include <pwd.h>
+
+extern int rebootargc;
+extern char** rebootargv;
+
+int gidnobody = -1;
+int uidnobody = -1;
+Proc** Xup;
+
+#define MAXSPROC 30000 /* max procs == MAXPID */
+static int sproctbl[MAXSPROC];
+
+enum
+{
+ KSTACK = 64*1024,
+ DELETE = 0x7F
+};
+char *hosttype = "Irix";
+char *cputype = "mips";
+
+extern int dflag;
+
+void
+pexit(char *msg, int t)
+{
+ Osenv *e;
+
+ lock(&procs.l);
+ if(up->prev)
+ up->prev->next = up->next;
+ else
+ procs.head = up->next;
+
+ if(up->next)
+ up->next->prev = up->prev;
+ else
+ procs.tail = up->prev;
+
+ sproctbl[getpid()] = -1;
+
+ unlock(&procs.l);
+
+/* print("pexit: %s: %s\n", up->text, msg); /**/
+ e = up->env;
+ if(e != nil) {
+ closefgrp(e->fgrp);
+ closepgrp(e->pgrp);
+ closeegrp(e->egrp);
+ closesigs(e->sigs);
+ }
+ free(up->prog);
+ free(up);
+ exit(0);
+}
+
+static void
+tramp(void *p, size_t stacksz)
+{
+ up = p;
+ up->sigid = getpid();
+ up->func(up->arg);
+ pexit("", 0);
+}
+
+int
+kproc(char *name, void (*func)(void*), void *arg, int flags)
+{
+ Proc *p;
+ Pgrp *pg;
+ Fgrp *fg;
+ Egrp *eg;
+ int pid;
+ int id;
+ int i;
+
+ p = newproc();
+
+ if(flags & KPDUPPG) {
+ pg = up->env->pgrp;
+ incref(&pg->r);
+ p->env->pgrp = pg;
+ }
+ if(flags & KPDUPFDG) {
+ fg = up->env->fgrp;
+ incref(&fg->r);
+ p->env->fgrp = fg;
+ }
+ if(flags & KPDUPENVG) {
+ eg = up->env->egrp;
+ incref(&eg->r);
+ p->env->egrp = eg;
+ }
+
+ p->env->uid = up->env->uid;
+ p->env->gid = up->env->gid;
+ kstrdup(&p->env->user, up->env->user);
+
+ strcpy(p->text, name);
+
+ p->func = func;
+ p->arg = arg;
+
+ lock(&procs.l);
+ if(procs.tail != nil) {
+ p->prev = procs.tail;
+ procs.tail->next = p;
+ }
+ else {
+ procs.head = p;
+ p->prev = nil;
+ }
+ procs.tail = p;
+
+ for(i = 1; i < MAXSPROC; i++) {
+ if(sproctbl[i] == -1) {
+ break;
+ }
+ }
+
+ if(i==MAXSPROC)
+ return -1;
+
+ sproctbl[i] = -i - 1; /* temporary hold of table index outside of lock */
+
+ unlock(&procs.l);
+
+ pid = sprocsp(tramp, PR_SALL, p, 0, KSTACK);
+
+ if(-1 < pid)
+ sproctbl[i] = pid;
+ else
+ sproctbl[i] = -1;
+
+ return pid;
+}
+
+void
+osblock(void)
+{
+ blockproc(up->sigid);
+}
+
+void
+osready(Proc *p)
+{
+ unblockproc(p->sigid);
+}
+
+void
+trapUSR1(void)
+{
+ int intwait;
+
+ intwait = up->intwait;
+ up->intwait = 0; /* clear it to let proc continue in osleave */
+
+ if(up->type != Interp) /* Used to unblock pending I/O */
+ return;
+
+ if(intwait == 0) /* Not posted so it's a sync error */
+ disfault(nil, Eintr); /* Should never happen */
+}
+
+void
+trapILL(void)
+{
+ disfault(nil, "Illegal instruction");
+}
+
+void
+trapBUS(void)
+{
+ disfault(nil, "Bus error");
+}
+
+void
+trapSEGV(void)
+{
+ disfault(nil, "Segmentation violation");
+}
+
+/*
+ * This is not a signal handler but rather a vector from real/FPcontrol-Irix.c
+ */
+void
+trapFPE(unsigned exception[5], int value[2])
+{
+ disfault(nil, "Floating point exception");
+}
+
+void
+oshostintr(Proc *p)
+{
+ kill(p->sigid, SIGUSR1);
+}
+
+void
+oslongjmp(void *regs, osjmpbuf env, int val)
+{
+ USED(regs);
+ siglongjmp(env, val);
+}
+
+static struct termios tinit;
+
+static void
+termset(void)
+{
+ struct termios t;
+
+ tcgetattr(0, &t);
+ tinit = t;
+ t.c_lflag &= ~(ICANON|ECHO|ISIG);
+ t.c_cc[VMIN] = 1;
+ t.c_cc[VTIME] = 0;
+ tcsetattr(0, TCSANOW, &t);
+}
+
+static void
+termrestore(void)
+{
+ tcsetattr(0, TCSANOW, &tinit);
+
+/* if(sproctbl[0] < 0)
+ panic("corrupt sproc tbl");
+
+ kill(sproctbl[0], SIGUSR2);
+ sginap(10000); */
+}
+
+void
+trapUSR2(void)
+{
+ int i;
+
+ for(i = MAXSPROC - 1; i > 0; i--) {
+ if(sproctbl[i] != -1)
+ kill(sproctbl[i], SIGKILL);
+ sproctbl[i] = -1;
+ }
+
+ execvp(rebootargv[0], rebootargv);
+ panic("reboot failure");
+}
+
+void
+cleanexit(int x)
+{
+ USED(x);
+
+ if(up->intwait) {
+ up->intwait = 0;
+ return;
+ }
+
+ if(dflag == 0)
+ termrestore();
+ kill(0, SIGKILL);
+ exit(0);
+}
+
+void
+getnobody(void)
+{
+ struct passwd *pwd;
+
+ pwd = getpwnam("nobody");
+ if(pwd != nil) {
+ uidnobody = pwd->pw_uid;
+ gidnobody = pwd->pw_gid;
+ }
+}
+
+void
+osreboot(char *file, char **argv)
+{
+ if(dflag == 0)
+ termrestore();
+ execvp(file, argv);
+ panic("reboot failure");
+}
+
+void
+libinit(char *imod)
+{
+ struct sigaction act;
+ struct passwd *pw;
+ int i;
+ char sys[64];
+
+ setsid();
+
+ for(i=0; i<MAXSPROC; i++)
+ sproctbl[i] = -1;
+
+ sproctbl[0] = getpid();
+
+ gethostname(sys, sizeof(sys));
+ kstrdup(&ossysname, sys);
+
+ if(dflag == 0)
+ termset();
+
+ if(signal(SIGTERM, SIG_IGN) != SIG_IGN)
+ signal(SIGTERM, cleanexit);
+ if(signal(SIGINT, SIG_IGN) != SIG_IGN)
+ signal(SIGINT, cleanexit);
+ signal(SIGUSR2, trapUSR2);
+ /* For the correct functioning of devcmd in the
+ * face of exiting slaves
+ */
+ signal(SIGCLD, SIG_IGN);
+ signal(SIGPIPE, SIG_IGN);
+ memset(&act, 0 , sizeof(act));
+ act.sa_handler=trapUSR1;
+ sigaction(SIGUSR1, &act, nil);
+ if(sflag == 0) {
+ act.sa_handler=trapBUS;
+ sigaction(SIGBUS, &act, nil);
+ act.sa_handler=trapILL;
+ sigaction(SIGILL, &act, nil);
+ act.sa_handler=trapSEGV;
+ sigaction(SIGSEGV, &act, nil);
+ }
+
+ if(usconfig(CONF_INITUSERS, 1000) < 0)
+ panic("usconfig");
+
+ Xup = (Proc**)PRDA->usr_prda.fill;
+ up = newproc();
+
+ pw = getpwuid(getuid());
+ if(pw != nil) {
+ if (strlen(pw->pw_name) + 1 <= KNAMELEN)
+ strcpy(eve, pw->pw_name);
+ else
+ print("pw_name too long\n");
+ }
+ else
+ print("cannot getpwuid\n");
+
+ /* after setting up, since this takes locks */
+ getnobody();
+ up->env->uid = getuid();
+ up->env->gid = getgid();
+ emuinit(imod);
+}
+
+int
+readkbd(void)
+{
+ int n;
+ char buf[1];
+
+ n = read(0, buf, sizeof(buf));
+ if(n < 0)
+ fprint(2, "keyboard read error: %s\n", strerror(errno));
+ if(n <= 0)
+ pexit("keyboard thread", 0);
+ switch(buf[0]) {
+ case '\r':
+ buf[0] = '\n';
+ break;
+ case DELETE:
+ cleanexit(0);
+ break;
+ }
+ return buf[0];
+}
+
+int
+segflush(void *a, ulong n)
+{
+ cacheflush(a, n, BCACHE);
+ return 0;
+}
+
+/*
+ * Return an abitrary millisecond clock time
+ */
+long
+osmillisec(void)
+{
+ static long sec0 = 0, usec0;
+ struct timeval t;
+
+ if(gettimeofday(&t,(struct timezone*)0)<0)
+ return(0);
+ if(sec0==0){
+ sec0 = t.tv_sec;
+ usec0 = t.tv_usec;
+ }
+ return((t.tv_sec-sec0)*1000+(t.tv_usec-usec0+500)/1000);
+}
+
+/*
+ * Return the time since the epoch in nanoseconds and microseconds
+ * The epoch is defined at 1 Jan 1970
+ */
+vlong
+osnsec(void)
+{
+ struct timeval t;
+
+ gettimeofday(&t, nil);
+ return (vlong)t.tv_sec*1000000000L + t.tv_usec*1000;
+}
+
+vlong
+osusectime(void)
+{
+ struct timeval t;
+
+ gettimeofday(&t, nil);
+ return (vlong)t.tv_sec * 1000000 + t.tv_usec;
+}
+
+int
+osmillisleep(ulong milsec)
+{
+ static int tick;
+
+ /*
+ * Posix-conforming CLK_TCK implementations tend to call sysconf,
+ * and we don't need the overhead.
+ */
+ if(tick == 0)
+ tick = CLK_TCK;
+ sginap((tick*milsec)/1000);
+ return 0;
+}
+
+int
+limbosleep(ulong milsec)
+{
+ return osmillisleep(milsec);
+}
+
+void
+osyield(void)
+{
+ sginap(0);
+}
+
+void
+ospause(void)
+{
+ for(;;)
+ pause();
+}
+
+void
+oslopri(void)
+{
+ nice(2);
+}