diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 17:07:39 +0000 |
| commit | 37da2899f40661e3e9631e497da8dc59b971cbd0 (patch) | |
| tree | cbc6d4680e347d906f5fa7fca73214418741df72 /emu/Solaris | |
| parent | 54bc8ff236ac10b3eaa928fd6bcfc0cdb2ba46ae (diff) | |
20060303a
Diffstat (limited to 'emu/Solaris')
| -rw-r--r-- | emu/Solaris/asm-386.s | 72 | ||||
| -rw-r--r-- | emu/Solaris/asm-sparc.s | 76 | ||||
| -rw-r--r-- | emu/Solaris/audio.c | 593 | ||||
| -rw-r--r-- | emu/Solaris/cmd.c | 205 | ||||
| -rw-r--r-- | emu/Solaris/deveia.c | 38 | ||||
| -rw-r--r-- | emu/Solaris/devfs.c | 1 | ||||
| -rw-r--r-- | emu/Solaris/emu | 106 | ||||
| -rw-r--r-- | emu/Solaris/mkfile | 47 | ||||
| -rw-r--r-- | emu/Solaris/os.c | 437 |
9 files changed, 1575 insertions, 0 deletions
diff --git a/emu/Solaris/asm-386.s b/emu/Solaris/asm-386.s new file mode 100644 index 00000000..60dc44eb --- /dev/null +++ b/emu/Solaris/asm-386.s @@ -0,0 +1,72 @@ + .section .bss + .align 4 +.L4_.bss: + .align 4 +Solaris_Asm_IntP: / Offset 0 + .type Solaris_Asm_IntP,@object + .size Solaris_Asm_IntP,4 + .set .,.+4 +Solaris_Asm_VoidP: / Offset 4 + .type Solaris_Asm_VoidP,@object + .size Solaris_Asm_VoidP,4 + .set .,.+4 + .section .text + .align 4 +.L1_.text: + +/==================== +/ FPsave +/-------------------- + .align 4 + .align 4 + .globl FPsave +FPsave: + pushl %ebp + movl %esp,%ebp + movl 8(%ebp),%eax + movl %eax,Solaris_Asm_VoidP + fstenv (%eax) + leave + ret + .align 4 + .type FPsave,@function + .size FPsave,.-FPsave + +/==================== +/ FPrestore +/-------------------- + .align 4 + .globl FPrestore +FPrestore: + pushl %ebp + movl %esp,%ebp + movl 8(%ebp),%eax + movl %eax,Solaris_Asm_VoidP + fldenv (%eax) + leave + ret + .align 4 + .type FPrestore,@function + .size FPrestore,.-FPrestore + + +/==================== +/ getcallerpc +/-------------------- + .align 4 + .globl getcallerpc +getcallerpc: + movl 4(%ebp),%eax + ret + .align 4 + .type getcallerpc,@function + .size getcallerpc,.-getcallerpc + +/ test-and-set + .align 4 + .globl _tas +_tas: + movl $1, %eax + movl 4(%esp), %ecx + xchgl %eax, 0(%ecx) + ret diff --git a/emu/Solaris/asm-sparc.s b/emu/Solaris/asm-sparc.s new file mode 100644 index 00000000..c53a0bc0 --- /dev/null +++ b/emu/Solaris/asm-sparc.s @@ -0,0 +1,76 @@ + + .section ".text", #alloc, #execinstr + .align 8 + .skip 16 + .global segflush + .type segflush,2 + + ! The flush instruction works on 8-byte chunks. + ! We truncate the pointer and increase the count + ! to make sure we flush the right range. + + ! SPARC requires 5 instructions after flush to + ! let the caches settle. The loop code supplies + ! the delay instructions. + +segflush: ! int segflush(void *p, ulong len) + + and %o0,-8,%o0 ! clear low 3 bits of p + add %o1, 7, %o1 ! len += 7 +1: + flush %o0 ! synchronize cache + sub %o1, 8, %o1 ! len -= 8 + cmp %o1, 0 ! if len > 0, repeat + bg 1b + add %o0, 8, %o0 ! p += 8 in delay slot + + retl + add %g0, %g0, %o0 ! return 0 + .size segflush,(.-segflush) + + + .section ".text", #alloc, #execinstr + .align 8 + .skip 16 + .global FPsave + .type FPsave,2 +FPsave: + retl + st %fsr,[%o0] + .size FPsave,(.-FPsave) + + + .section ".text", #alloc, #execinstr + .align 8 + .skip 16 + .global FPrestore + .type FPrestore,2 +FPrestore: + retl + ld [%o0],%fsr + .size FPrestore,(.-FPrestore) + + + .section ".text", #alloc, #execinstr + .align 8 + .skip 16 + .global getcallerpc + .type getcallerpc, 2 +getcallerpc: ! ignore argument + retl + add %i7,0,%o0 + + .size getcallerpc,(.-getcallerpc) + + + .section ".text", #alloc, #execinstr + .align 8 + .skip 16 + .global _tas + .type _tas, 2 +_tas: + or %g0,1,%o1 + swap [%o0],%o1 + retl + or %g0,%o1,%o0 + .size _tas,(.-_tas) diff --git a/emu/Solaris/audio.c b/emu/Solaris/audio.c new file mode 100644 index 00000000..91ffd8d6 --- /dev/null +++ b/emu/Solaris/audio.c @@ -0,0 +1,593 @@ +#include "dat.h" +#include "fns.h" +#include "error.h" +#define __EXTENSIONS__ +#include <sys/time.h> +#include <time.h> +#include <fcntl.h> +#include <stropts.h> +#include <sys/audioio.h> +#include <sys/ioctl.h> +#include <sys/filio.h> +#include "audio.h" +#include <sys/audioio.h> + +#define Audio_Mic_Val AUDIO_MICROPHONE +#define Audio_Linein_Val AUDIO_LINE_IN + +#define Audio_Speaker_Val AUDIO_SPEAKER +#define Audio_Headphone_Val AUDIO_HEADPHONE +#define Audio_Lineout_Val AUDIO_LINE_OUT + +#define Audio_Pcm_Val AUDIO_ENCODING_LINEAR +#define Audio_Ulaw_Val AUDIO_ENCODING_ULAW +#define Audio_Alaw_Val AUDIO_ENCODING_ALAW + +#include "audio-tbls.c" + +#define min(a,b) ((a) < (b) ? (a) : (b)) +static int debug = 0; + +extern int nanosleep(const struct timespec *, struct timespec *); + +#define AUDIO_FILE_STRING "/dev/audio" + +enum { + A_Pause, + A_UnPause +}; + +enum { + A_In, + A_Out +}; + +static QLock inlock; +static QLock outlock; + +static int audio_file_in = -1; /* file in */ +static int audio_file_out = -1; /* file out */ + +static int audio_swap_flag = 0; /* endian swap */ + +static int audio_in_pause = A_UnPause; + +static Audio_t av; + +static int audio_enforce(Audio_t*); +static int audio_open_in(void); +static int audio_open_out(void); +static int audio_pause_in(int, int); +static int audio_flush(int, int); +static int audio_pause_out(int); +static int audio_set_blocking(int); +static int audio_set_info(int, Audio_d*, int); +static void audio_swap_endian(char*, int); + +void +audio_file_init(void) +{ + static ushort flag = 1; + audio_swap_flag = *((uchar*)&flag) == 0; /* big-endian? */ + audio_info_init(&av); +} + +void +audio_file_open(Chan *c, int omode) +{ + switch(omode){ + case OREAD: + qlock(&inlock); + if(waserror()){ + qunlock(&inlock); + nexterror(); + } + + if(audio_file_in >= 0) + error(Einuse); + if((audio_file_in = audio_open_in()) < 0) + oserror(); + + poperror(); + qunlock(&inlock); + break; + case OWRITE: + qlock(&outlock); + if(waserror()){ + qunlock(&outlock); + nexterror(); + } + if(audio_file_out >= 0) + error(Einuse); + if((audio_file_out = audio_open_out() ) < 0) + oserror(); + poperror(); + qunlock(&outlock); + break; + case ORDWR: + qlock(&inlock); + qlock(&outlock); + if(waserror()){ + qunlock(&inlock); + qunlock(&outlock); + nexterror(); + } + if(audio_file_in >= 0 || audio_file_out >= 0) + error(Einuse); + + if((audio_file_in = audio_open_in()) < 0) + oserror(); + if(waserror()){ + close(audio_file_in); + audio_file_in = -1; + nexterror(); + } + if((audio_file_out = audio_open_out()) < 0) + oserror(); + poperror(); + + poperror(); + qunlock(&inlock); + qunlock(&outlock); + break; + } +} + +void +audio_file_close(Chan *c) +{ + switch(c->mode){ + case OREAD: + qlock(&inlock); + close(audio_file_in); + audio_file_in = -1; + qunlock(&inlock); + break; + case OWRITE: + qlock(&outlock); + close(audio_file_out); + audio_file_out = -1; + qunlock(&outlock); + break; + case ORDWR: + qlock(&inlock); + close(audio_file_in); + audio_file_in = -1; + qunlock(&inlock); + qlock(&outlock); + close(audio_file_out); + audio_file_out = -1; + qunlock(&outlock); + break; + } +} + +long +audio_file_read(Chan *c, void *va, long count, vlong offset) +{ + struct timespec time; + long ba, status, chunk, total; + char *pva = (char *) va; + + qlock(&inlock); + if(waserror()){ + qunlock(&inlock); + nexterror(); + } + + if(audio_file_in < 0) + error(Eperm); + + /* check block alignment */ + ba = av.in.bits * av.in.chan / Bits_Per_Byte; + + if(count % ba) + error(Ebadarg); + + if(!audio_pause_in(audio_file_in, A_UnPause)) + error(Eio); + + total = 0; + while(total < count) { + chunk = count - total; + osenter(); + status = read(audio_file_in, pva + total, chunk); + osleave(); + if(status < 0) + error(Eio); + total += status; + } + + if(total != count) + error(Eio); + + if(audio_swap_flag && av.out.bits == 16) + audio_swap_endian(pva, count); + + poperror(); + qunlock(&inlock); + + time.tv_sec = 0; /* hack around broken thread scheduler in Solaris */ + time.tv_nsec= 1; + nanosleep(&time,nil); + + return count; +} + +long +audio_file_write(Chan *c, void *va, long count, vlong offset) +{ + struct timespec time; + long status = -1; + long ba, total, chunk, bufsz; + + qlock(&outlock); + if(waserror()){ + qunlock(&outlock); + nexterror(); + } + + if(audio_file_out < 0) + error(Eperm); + + /* check block alignment */ + ba = av.out.bits * av.out.chan / Bits_Per_Byte; + + if(count % ba) + error(Ebadarg); + + if(audio_swap_flag && av.out.bits == 16) + audio_swap_endian(va, count); + + total = 0; + bufsz = av.out.buf * Audio_Max_Buf / Audio_Max_Val; + + if(bufsz == 0) + error(Ebadarg); + + while(total < count) { + chunk = min(bufsz, count - total); + osenter(); + status = write(audio_file_out, va, chunk); + osleave(); + if(status <= 0) + error(Eio); + total += status; + } + + poperror(); + qunlock(&outlock); + + time.tv_sec = 0; /* hack around broken thread scheduler in Solaris */ + time.tv_nsec= 1; + nanosleep(&time,nil); + + return count; +} + +int +audio_open_in(void) +{ + int fd; + + /* open non-blocking in case someone already has it open */ + /* otherwise we would block until they close! */ + fd = open(AUDIO_FILE_STRING, O_RDONLY|O_NONBLOCK); + + if(fd < 0) + oserror(); + + /* change device to be blocking */ + if(!audio_set_blocking(fd)) { + close(fd); + error(Eio); + } + + if(!audio_pause_in(fd, A_Pause)) { + close(fd); + error(Eio); + } + + if(!audio_flush(fd, A_In)) { + close(fd); + error(Eio); + } + + /* set audio info */ + av.in.flags = ~0; + av.out.flags = 0; + + if(!audio_set_info(fd, &av.in, A_In)) { + close(fd); + error(Ebadarg); + } + + av.in.flags = 0; + + /* tada, we're open, blocking, paused and flushed */ + return fd; +} + +int +audio_open_out(void) +{ + int fd; + struct audio_info hdr; + + /* open non-blocking in case someone already has it open */ + /* otherwise we would block until they close! */ + fd = open(AUDIO_FILE_STRING, O_WRONLY|O_NONBLOCK); + + if(fd < 0) + oserror(); + + /* change device to be blocking */ + if(!audio_set_blocking(fd)) { + close(fd); + error("cannot set blocking mode"); + } + + /* set audio info */ + av.in.flags = 0; + av.out.flags = ~0; + + if(!audio_set_info(fd, &av.out, A_Out)) { + close(fd); + error(Ebadarg); + } + + av.out.flags = 0; + + return fd; +} + +long +audio_ctl_write(Chan *c, void *va, long count, vlong offset) +{ + int fd; + int ff; + Audio_t tmpav = av; + + tmpav.in.flags = 0; + tmpav.out.flags = 0; + + if (!audioparse(va, count, &tmpav)) + error(Ebadarg); + + if (!audio_enforce(&tmpav)) + error(Ebadarg); + + qlock(&inlock); + if (waserror()) { + qunlock(&inlock); + nexterror(); + } + + if (audio_file_in >= 0 && (tmpav.in.flags & AUDIO_MOD_FLAG)) { + if (!audio_pause_in(audio_file_in, A_Pause)) + error(Ebadarg); + if (!audio_flush(audio_file_in, A_In)) + error(Ebadarg); + if (!audio_set_info(audio_file_in, &tmpav.in, A_In)) + error(Ebadarg); + } + poperror(); + qunlock(&inlock); + + qlock(&outlock); + if (waserror()) { + qunlock(&outlock); + nexterror(); + } + if (audio_file_out >= 0 && (tmpav.out.flags & AUDIO_MOD_FLAG)){ + if (!audio_pause_out(audio_file_out)) + error(Ebadarg); + if (!audio_set_info(audio_file_out, &tmpav.out, A_Out)) + error(Ebadarg); + } + poperror(); + qunlock(&outlock); + + tmpav.in.flags = 0; + tmpav.out.flags = 0; + + av = tmpav; + + return count; +} + +static int +audio_set_blocking(int fd) +{ + int val; + + if((val = fcntl(fd, F_GETFL, 0)) == -1) + return 0; + + val &= ~O_NONBLOCK; + + if(fcntl(fd, F_SETFL, val) < 0) + return 0; + + return 1; +} + +static int +audio_set_info(int fd, Audio_d *i, int d) +{ + int status; + int unequal_stereo = 0; + audio_info_t info; + audio_prinfo_t *dev; + + if(fd < 0) + return 0; + + /* devitialize header */ + AUDIO_INITINFO(&info); + + if(d == A_In) + dev = &info.record; + else + dev = &info.play; + + /* sample rate */ + if(i->flags & AUDIO_RATE_FLAG) + dev->sample_rate = i->rate; + + /* channels */ + if(i->flags & AUDIO_CHAN_FLAG) + dev->channels = i->chan; + + /* precision */ + if(i->flags & AUDIO_BITS_FLAG) + dev->precision = i->bits; + + /* encoding */ + if(i->flags & AUDIO_ENC_FLAG) + dev->encoding = i->enc; + + /* devices */ + if(i->flags & AUDIO_DEV_FLAG) + dev->port = i->dev; + + /* dev volume */ + if(i->flags & (AUDIO_LEFT_FLAG|AUDIO_VOL_FLAG)) { + dev->gain = (i->left * AUDIO_MAX_GAIN) / Audio_Max_Val; + + /* do left first then right later */ + if(i->left == i->right) + dev->balance = AUDIO_MID_BALANCE; + else { + dev->balance = AUDIO_LEFT_BALANCE; + if(i->chan != 1) + unequal_stereo = 1; + } + } + + osenter(); + status = ioctl(fd, AUDIO_SETINFO, &info); /* qlock and load general stuff */ + osleave(); + + if(status == -1) { + if(debug) print("audio_set_info 1 failed: fd = %d errno = %d\n", fd, errno); + return 0; + } + + /* check for different right and left for dev */ + if(unequal_stereo) { + + /* re-init header */ + AUDIO_INITINFO(&info); + + dev->gain = (i->right * AUDIO_MAX_GAIN) / Audio_Max_Val; + dev->balance == AUDIO_RIGHT_BALANCE; + + osenter(); + status = ioctl(fd, AUDIO_SETINFO, &info); + osleave(); + + if(status == -1) { + if(debug) print("audio_set_info 2 failed: fd = %d errno = %d\n",fd, errno); + return 0; + } + } + + return 1; +} + +void +audio_swap_endian(char *p, int n) +{ + int b; + + while (n > 1) { + b = p[0]; + p[0] = p[1]; + p[1] = b; + p += 2; + n -= 2; + } +} + +static int +audio_pause_out(int fd) +{ + audio_info_t info; + int foo = 0; + int status; + + osenter(); + status = ioctl(fd, AUDIO_DRAIN, &foo); + osleave(); + + if(status == -1) + return 0; + return 1; +} + +static int +audio_pause_in(int fd, int f) +{ + audio_info_t info; + int status; + + if(fd < 0) + return 0; + + if(audio_in_pause == f) + return 1; + + /* initialize header */ + AUDIO_INITINFO(&info); + + /* unpause input */ + if(f == A_Pause) + info.record.pause = 1; + else + info.record.pause = 0; + + osenter(); + status = ioctl(fd, AUDIO_SETINFO, &info); + osleave(); + + if(status == -1) + return 0; + + audio_in_pause = f; + + return 1; +} + +static int +audio_flush(int fd, int d) +{ + int flag = d==A_In? FLUSHR: FLUSHW; + int status; + + osenter(); + status = ioctl(fd, I_FLUSH, flag); /* drain anything already put into buffer */ + osleave(); + + if(status == -1) + return 0; + return 1; +} + +static int +audio_enforce(Audio_t *t) +{ + if((t->in.enc == Audio_Ulaw_Val || t->in.enc == Audio_Alaw_Val) && + (t->in.rate != 8000 || t->in.chan != 1)) + return 0; + if((t->out.enc == Audio_Ulaw_Val || t->out.enc == Audio_Alaw_Val) && + (t->out.rate != 8000 || t->out.chan != 1)) + return 0; + return 1; +} + +Audio_t* +getaudiodev(void) +{ + return &av; +} diff --git a/emu/Solaris/cmd.c b/emu/Solaris/cmd.c new file mode 100644 index 00000000..897490c7 --- /dev/null +++ b/emu/Solaris/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 = fork1()) { + 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/Solaris/deveia.c b/emu/Solaris/deveia.c new file mode 100644 index 00000000..884411ac --- /dev/null +++ b/emu/Solaris/deveia.c @@ -0,0 +1,38 @@ +/* + * Solaris serial port definitions + */ + +static char *sysdev[] = { + "/dev/term/a", + "/dev/term/b" +}; + +#include "deveia-posix.c" +#include "deveia-bsd.c" + +static struct tcdef_t bps[] = { + {0, B0}, + {50, B50}, + {75, B75}, + {110, B110}, + {134, B134}, + {150, B150}, + {200, B200}, + {300, B300}, + {600, B600}, + {1200, B1200}, + {1800, B1800}, + {2400, B2400}, + {4800, B4800}, + {9600, B9600}, + {19200, B19200}, + {38400, B38400}, + {57600, B57600}, + {76800, B76800}, + {115200, B115200}, + {153600, B153600}, + {230400, B230400}, + {307200, B307200}, + {460800, B460800}, + {-1, -1} +}; diff --git a/emu/Solaris/devfs.c b/emu/Solaris/devfs.c new file mode 100644 index 00000000..9017c3fc --- /dev/null +++ b/emu/Solaris/devfs.c @@ -0,0 +1 @@ +#include "devfs-posix.c" diff --git a/emu/Solaris/emu b/emu/Solaris/emu new file mode 100644 index 00000000..89f7637b --- /dev/null +++ b/emu/Solaris/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/Solaris/mkfile b/emu/Solaris/mkfile new file mode 100644 index 00000000..498a4e86 --- /dev/null +++ b/emu/Solaris/mkfile @@ -0,0 +1,47 @@ +SYSTARG=Solaris +OBJTYPE=sparc +<../../mkconfig +SYSTARG=Solaris +OBJTYPE=sparc + +#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\ + +HFILES=\ + +CFLAGS='-DROOT="'$ROOT'"' -DEMU -I. -I../port -I$ROOT/$SYSTARG/$OBJTYPE/include -I$ROOT/include -I$ROOT/libinterp $CTHREADFLAGS $CFLAGS $EMUOPTIONS +SYSLIBS=$EMULIBS +KERNDATE=`{$NDATE} + +default:V: $O.$CONF + +<../port/portmkfile + +$O.$CONF: $OBJ $CONF.c $CONF.root.h $LIBFILES + $CC $CFLAGS '-DKERNDATE='$KERNDATE $CONF.c + $LD $LDFLAGS -o $target $OBJ $CONF.$O $LIBFILES $SYSLIBS + +install:V: $O.$CONF + cp $O.$CONF $INSTALLDIR/$CONF + +devfs.$O: ../port/devfs-posix.c diff --git a/emu/Solaris/os.c b/emu/Solaris/os.c new file mode 100644 index 00000000..02862220 --- /dev/null +++ b/emu/Solaris/os.c @@ -0,0 +1,437 @@ +#include "dat.h" +#include "fns.h" +#include "error.h" +#undef _POSIX_C_SOURCE +#undef getwd +#include <unistd.h> +#include <thread.h> +#include <time.h> +#include <termios.h> +#include <signal.h> +#include <pwd.h> +#include <sys/resource.h> +#include <sys/time.h> + +enum +{ + DELETE = 0x7F +}; +char *hosttype = "Solaris"; + +static thread_key_t prdakey; + +static siginfo_t siginfo; + +extern int dflag; + +Proc* +getup(void) +{ + void *vp; + + if (thr_getspecific(prdakey, &vp)) + return nil; + return vp; +} + +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; + 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); + sema_destroy(up->os); + free(up->os); + free(up); + thr_exit(0); +} + +static void * +tramp(void *v) +{ + struct Proc *Up; + + if(thr_setspecific(prdakey, v)) { + print("set specific data failed in tramp\n"); + thr_exit(0); + } + Up = v; + Up->sigid = thr_self(); + Up->func(Up->arg); + pexit("", 0); +} + +int +kproc(char *name, void (*func)(void*), void *arg, int flags) +{ + thread_t thread; + Proc *p; + Pgrp *pg; + Fgrp *fg; + Egrp *eg; + sema_t *sem; + + p = newproc(); + + sem = malloc(sizeof(*sem)); + if(sem == nil) + panic("can't allocate semaphore"); + sema_init(sem, 0, USYNC_THREAD, 0); + p->os = sem; + + 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; + unlock(&procs.l); + + if(thr_create(0, 0, &tramp, p, THR_BOUND|THR_DETACHED, &thread)) + panic("thr_create failed\n"); + thr_yield(); + return(thread); +} + +/* to get pc on trap use siginfo.si_pc field and define all trap handlers + as printILL - have to set sa_sigaction, sa_flags not sa_handler +*/ + +static 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 its a sync error */ + disfault(nil, Eintr); /* Should never happen */ +} + +static void +trapILL(void) +{ + disfault(nil, "Illegal instruction"); +} + +static void +printILL(int sig, siginfo_t *siginfo, void *v) +{ + panic("Illegal instruction with code=%d at address=%x, opcode=%x.\n", + siginfo->si_code, siginfo->si_addr,*(char*)siginfo->si_addr); +} + +static void +trapBUS(void) +{ + disfault(nil, "Bus error"); +} + +static void +trapSEGV(void) +{ + disfault(nil, "Segmentation violation"); +} + +static void +trapFPE(void) +{ + disfault(nil, "Floating point exception"); +} + +void +oshostintr(Proc *p) +{ + thr_kill(p->sigid, SIGUSR1); +} + +void +osblock(void) +{ + while(sema_wait(up->os)) + ; /* retry on signals */ +} + +void +osready(Proc *p) +{ + sema_post(p->os); +} + +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); +} + +void +cleanexit(int x) +{ + USED(x); + + if(up->intwait) { + up->intwait = 0; + return; + } + + if(dflag == 0) + termrestore(); + exit(0); +} + +int gidnobody= -1, uidnobody= -1; + +void +getnobody(void) +{ + struct passwd *pwd; + + if (pwd=getpwnam("nobody")) { + 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 Proc *Up; + struct sigaction act; + struct passwd *pw; + char sys[64]; + + setsid(); + + if(dflag == 0) + termset(); + + gethostname(sys, sizeof(sys)); + kstrdup(&ossysname, sys); + getnobody(); + + memset(&act, 0 , sizeof(act)); + act.sa_handler=trapUSR1; + sigaction(SIGUSR1, &act, nil); + /* + * For the correct functioning of devcmd in the + * face of exiting slaves + */ + signal(SIGPIPE, SIG_IGN); + if(signal(SIGTERM, SIG_IGN) != SIG_IGN) + signal(SIGTERM, cleanexit); + 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); + act.sa_handler = trapFPE; + sigaction(SIGFPE, &act, nil); + if(signal(SIGINT, SIG_IGN) != SIG_IGN) + signal(SIGINT, cleanexit); + } else{ + act.sa_sigaction = printILL; + act.sa_flags=SA_SIGINFO; + sigaction(SIGILL, &act, nil); + } + + if(thr_keycreate(&prdakey,NULL)) + print("keycreate failed\n"); + + Up = newproc(); + if(thr_setspecific(prdakey,Up)) + panic("set specific thread data failed\n"); + + pw = getpwuid(getuid()); + if(pw != nil) + kstrdup(&eve, pw->pw_name); + else + print("cannot getpwuid\n"); + + 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: %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]; +} + +/* + * Return an abitrary millisecond clock time + */ +long +osmillisec(void) +{ + static long sec0 = 0, usec0; + struct timeval t; + + if(gettimeofday(&t, NULL)<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) +{ + struct timespec time; + + time.tv_sec = milsec/1000; + time.tv_nsec= (milsec%1000)*1000000; + nanosleep(&time,nil); + return 0; +} + +int +limbosleep(ulong milsec) +{ + return osmillisleep(milsec); +} + +void +osyield(void) +{ + thr_yield(); +} + +void +ospause(void) +{ + for(;;) + pause(); +} + +void +oslopri(void) +{ + setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS,0)+4); +} |
