diff options
| -rw-r--r-- | OpenBSD/386/include/emu.h | 4 | ||||
| -rw-r--r-- | OpenBSD/386/include/lib9.h | 31 | ||||
| -rw-r--r-- | appl/acme/ecmd.b | 4 | ||||
| -rw-r--r-- | appl/cmd/limbo/limbo.y | 4 | ||||
| -rw-r--r-- | appl/cmd/limbo/types.b | 2 | ||||
| -rw-r--r-- | dis/limbo.dis | bin | 343678 -> 343687 bytes | |||
| -rw-r--r-- | emu/Linux/asm-386.S | 52 | ||||
| -rw-r--r-- | emu/Linux/asm-arm.S | 53 | ||||
| -rw-r--r-- | emu/Linux/asm-mips.S | 30 | ||||
| -rw-r--r-- | emu/Linux/asm-power.S | 33 | ||||
| -rw-r--r-- | emu/Linux/asm-spim.S | 29 | ||||
| -rw-r--r-- | emu/Linux/os-clone.c | 531 | ||||
| -rw-r--r-- | emu/OpenBSD/asm-386.S | 2 | ||||
| -rw-r--r-- | emu/OpenBSD/mkfile | 3 | ||||
| -rw-r--r-- | emu/OpenBSD/os.c | 224 | ||||
| -rw-r--r-- | emu/OpenBSD/rfork_thread.S | 104 | ||||
| -rw-r--r-- | emu/port/win-x11a.c | 38 | ||||
| -rw-r--r-- | lib9/setfcr-OpenBSD-386.S | 34 | ||||
| -rw-r--r-- | limbo/limbo.y | 4 | ||||
| -rw-r--r-- | limbo/types.c | 4 | ||||
| -rw-r--r-- | module/draw.m | 2 | ||||
| -rw-r--r-- | utils/8l/l.h | 12 |
22 files changed, 132 insertions, 1068 deletions
diff --git a/OpenBSD/386/include/emu.h b/OpenBSD/386/include/emu.h index 5e03489b..5392e2a4 100644 --- a/OpenBSD/386/include/emu.h +++ b/OpenBSD/386/include/emu.h @@ -15,6 +15,7 @@ struct FPU #define KSTACK (32 * 1024) +#ifndef USE_PTHREADS static __inline Proc *getup(void) { Proc *p; __asm__( "movl %%esp, %%eax\n\t" @@ -22,6 +23,9 @@ static __inline Proc *getup(void) { ); return *(Proc **)((unsigned long)p & ~(KSTACK - 1)); }; +#else +extern Proc* getup(void); +#endif #define up (getup()) diff --git a/OpenBSD/386/include/lib9.h b/OpenBSD/386/include/lib9.h index 69c310e9..377e19f6 100644 --- a/OpenBSD/386/include/lib9.h +++ b/OpenBSD/386/include/lib9.h @@ -1,10 +1,15 @@ /* define _BSD_SOURCE to use ISO C, POSIX, and 4.3BSD things. */ +#define USE_PTHREADS #ifndef _BSD_SOURCE #define _BSD_SOURCE #endif /* these aren't really needed because OpenBSD does the right thing and makes off_t 64 bits, full stop */ #define _LARGEFILE64_SOURCE 1 #define _FILE_OFFSET_BITS 64 + +#ifdef USE_PTHREADS +#define _REENTRANT 1 +#endif #include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> @@ -473,3 +478,29 @@ extern char *argv0; #define setbinmode() +/* FCR */ +#define FPINEX (1<<5) +#define FPUNFL ((1<<4)|(1<<1)) +#define FPOVFL (1<<3) +#define FPZDIV (1<<2) +#define FPINVAL (1<<0) +#define FPRNR (0<<10) +#define FPRZ (3<<10) +#define FPRPINF (2<<10) +#define FPRNINF (1<<10) +#define FPRMASK (3<<10) +#define FPPEXT (3<<8) +#define FPPSGL (0<<8) +#define FPPDBL (2<<8) +#define FPPMASK (3<<8) +/* FSR */ +#define FPAINEX FPINEX +#define FPAOVFL FPOVFL +#define FPAUNFL FPUNFL +#define FPAZDIV FPZDIV +#define FPAINVAL FPINVAL + +extern void setfcr(ulong); +extern void setfsr(ulong); +extern ulong getfcr(void); +extern ulong getfsr(void); diff --git a/appl/acme/ecmd.b b/appl/acme/ecmd.b index e05c4e47..19e38eb3 100644 --- a/appl/acme/ecmd.b +++ b/appl/acme/ecmd.b @@ -1192,7 +1192,7 @@ filematch(f: ref File, r: ref String): int { buf: string; w: ref Window; - match, i, dirty: int; + match, dirty: int; s: Rangeset; # compile expr first so if we get an error, we haven't allocated anything @@ -1203,7 +1203,7 @@ filematch(f: ref File, r: ref String): int dirty = !w.isdir && !w.isscratch && f.mod; buf = sprint("%c%c%c %s\n", " '"[dirty], '+', " ."[curtext!=nil && curtext.file==f], f.name); - (match, s) = rxexecute(nil, buf, 0, i); + (match, s) = rxexecute(nil, buf, 0, len buf); buf = nil; return match; } diff --git a/appl/cmd/limbo/limbo.y b/appl/cmd/limbo/limbo.y index 2f7d3ba8..4eb4af8a 100644 --- a/appl/cmd/limbo/limbo.y +++ b/appl/cmd/limbo/limbo.y @@ -655,13 +655,13 @@ ftype : nids ':' type { $$ = mkids($1.src, enter("junk", 0), $3, nil); $$.store = Darg; - yyerror("illegal argument declaraion"); + yyerror("illegal argument declaration"); } | idterms ':' adtk { $$ = mkids($1.src, enter("junk", 0), $3, nil); $$.store = Darg; - yyerror("illegal argument declaraion"); + yyerror("illegal argument declaration"); } ; diff --git a/appl/cmd/limbo/types.b b/appl/cmd/limbo/types.b index 6b1802e5..2ee207b3 100644 --- a/appl/cmd/limbo/types.b +++ b/appl/cmd/limbo/types.b @@ -1775,7 +1775,7 @@ cycfield(base: ref Type, id: ref Decl) +id.sym.name+" of "+stypeconv(base)); id.cycerr = byte 1; }else if(arc & ArcCyc){ - if((arc & ArcArray) && id.cyc == byte 0 && !(arc & ArcPolycyc)){ + if((arc & ArcArray) && oldcycles && id.cyc == byte 0 && !(arc & ArcPolycyc)){ if(id.cycerr == byte 0) error(base.src.start, "illegal circular reference to type "+typeconv(id.ty) +" in field "+id.sym.name+" of "+stypeconv(base)); diff --git a/dis/limbo.dis b/dis/limbo.dis Binary files differindex b4e3acac..d6e949ed 100644 --- a/dis/limbo.dis +++ b/dis/limbo.dis diff --git a/emu/Linux/asm-386.S b/emu/Linux/asm-386.S index 31946335..fe5ce6c1 100644 --- a/emu/Linux/asm-386.S +++ b/emu/Linux/asm-386.S @@ -1,59 +1,7 @@ .file "asm-Linux-386.S" -#include "syscall.h" .text /* - * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg) - */ - - .type executeonnewstack,@function - .global executeonnewstack -executeonnewstack: - pushl %ebp - movl %esp, %ebp - pushl %esi - - movl 8(%ebp), %esi /* get tos */ - subl $4, %esi - movl 16(%ebp), %eax - movl %eax, (%esi) /* stash arg on new stack */ - subl $4, %esi - movl 12(%ebp), %eax - movl %eax, (%esi) /* stash tramp on new stack */ - mov %esi, %esp /* swap stacks pronto */ - popl %eax /* recover the tramp address */ - subl %ebp, %ebp /* stop stack traceback here */ - call *%eax /* and jump to it (ho ho) */ - - /* if we return here, tramp didn't do its job */ - - addl $8, %esp /* clean up for pose value */ - - leal SYS_exit, %eax - int $0x80 - -/* - * unlockandexit(int *key) - * - * NB: the return status may be garbaged if the stack is reused - * between the unlock and the system call, but this should - * not matter since no task is waiting for the result - */ - - .type unlockandexit,@function - .global unlockandexit -unlockandexit: - pushl %ebp - movl %esp, %ebp - - movl 8(%ebp), %esi /* get the key address */ - pushl $0 /* exit status 0 */ - movl $0, %eax /* unlock the stack allocator */ - movl %eax, (%esi) - leal SYS_exit, %eax /* call exit */ - int $0x80 - -/* * umult(ulong m1, ulong m2, ulong *hi) */ diff --git a/emu/Linux/asm-arm.S b/emu/Linux/asm-arm.S index 90a337ff..5446dde6 100644 --- a/emu/Linux/asm-arm.S +++ b/emu/Linux/asm-arm.S @@ -1,60 +1,7 @@ .file "asm-Linux-arm.S" -#include "syscall.h" .text /* - * void executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg) - */ - - .align 2 - .global executeonnewstack - .type executeonnewstack, %function -executeonnewstack: - @ args = 0, pretend = 0, frame = 12 - @ frame_needed = 1, uses_anonymous_args = 0 - mov ip, sp - stmfd sp!, {fp, ip, lr, pc} - sub fp, ip, #4 - sub sp, sp, #12 - str r0, [fp, #-16] /* store tos */ - str r1, [fp, #-20] /* store tramp */ - str r2, [fp, #-24] /* store arg */ - ldr r0, [fp, #-24] /* get arg */ - ldr r2, [fp, #-16] /* get tos */ - mov sp, r2 /* set new stack */ - mov lr, pc - blx r1 /* call tramp*/ - - /* if we return here, tramp didn't do it's job */ - mov r0, #0 - mov r7, #SYS_exit - swi 0x0 - ldmea fp, {fp, sp, pc} - .size executeonnewstack, .-executeonnewstack - -/* - * void unlockandexit(int *key) - */ - - .align 2 - .global unlockandexit - .type unlockandexit, %function -unlockandexit: - @ args = 0, pretend = 0, frame = 4 - @ frame_needed = 1, uses_anonymous_args = 0 - mov ip, sp - stmfd sp!, {fp, ip, lr, pc} - sub fp, ip, #4 - sub sp, sp, #4 - mov r1, #0 - str r1, [r0] - mov r0, #0 - mov r7, #SYS_exit - swi 0x0 - ldmea fp, {fp, sp, pc} - .size unlockandexit, .-unlockandexit - -/* * ulong umult(ulong m1, ulong m2, ulong *hi) */ diff --git a/emu/Linux/asm-mips.S b/emu/Linux/asm-mips.S index 087b8550..d2780f6a 100644 --- a/emu/Linux/asm-mips.S +++ b/emu/Linux/asm-mips.S @@ -1,37 +1,7 @@ -#include "syscall.h" #include <sys/asm.h> #include <sys/regdef.h> #include <asm/cachectl.h> -/* - * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg) - */ - -LEAF(executeonnewstack) - and a0,a0,~7 - addu sp,a0,-16 - move a0,a2 - move t9,a1 - jalr t9 - - li v0,SYS_exit - li a0,0 - syscall - - END(executeonnewstack) - -/* - * unlockandexit(int *key) - */ - -LEAF(unlockandexit) - lw a1,0(a0) - li v0,SYS_exit - li a0,0 - sw a0,0(a1) - syscall - END(unlockandexit) - LEAF(FPsave) cfc1 t0, $31 sw t0, 0(a0) /* a0 is argument */ diff --git a/emu/Linux/asm-power.S b/emu/Linux/asm-power.S index 6af21fba..7187f938 100644 --- a/emu/Linux/asm-power.S +++ b/emu/Linux/asm-power.S @@ -59,36 +59,3 @@ _tas: 2: sync blr - -/* - * void - * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg) - */ - .align 2 - .global executeonnewstack -executeonnewstack: - mr %r1,%r3 /* change stacks */ - stwu %lr,-16(%r1) /* save lr to aid the traceback */ - li %r0,0 - stw %r0,20(%r1) - mr %r3,%r5 - mtctr %r4 - bctrl /* tramp(arg) */ - br - -/* - * void unlockandexit(int *key) - * - * NB: the return status may be garbaged if the stack is reused - * between the unlock and the system call, but this should - * not matter since no task is waiting for the result - */ - .align 2 - .globl unlockandexit -unlockandexit: - li %r0,0x0 - stw %r0,0(%r3) /* unlock */ - li %r0,1 /* sys exit; 234 is exit group */ - li %r3,0 /* exit status */ - sc - br diff --git a/emu/Linux/asm-spim.S b/emu/Linux/asm-spim.S index 087b8550..77ae3d4c 100644 --- a/emu/Linux/asm-spim.S +++ b/emu/Linux/asm-spim.S @@ -1,36 +1,7 @@ -#include "syscall.h" #include <sys/asm.h> #include <sys/regdef.h> #include <asm/cachectl.h> -/* - * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg) - */ - -LEAF(executeonnewstack) - and a0,a0,~7 - addu sp,a0,-16 - move a0,a2 - move t9,a1 - jalr t9 - - li v0,SYS_exit - li a0,0 - syscall - - END(executeonnewstack) - -/* - * unlockandexit(int *key) - */ - -LEAF(unlockandexit) - lw a1,0(a0) - li v0,SYS_exit - li a0,0 - sw a0,0(a1) - syscall - END(unlockandexit) LEAF(FPsave) cfc1 t0, $31 diff --git a/emu/Linux/os-clone.c b/emu/Linux/os-clone.c deleted file mode 100644 index 992235d4..00000000 --- a/emu/Linux/os-clone.c +++ /dev/null @@ -1,531 +0,0 @@ -#include <sys/types.h> -#include <time.h> -#include <termios.h> -#include <signal.h> -#include <pwd.h> -#include <sched.h> -#include <sys/resource.h> -#include <sys/wait.h> -#include <sys/time.h> - -#include <stdint.h> - -#include "dat.h" -#include "fns.h" -#include "error.h" - -#include <semaphore.h> - -#include <raise.h> - -/* glibc 2.3.3-NTPL messes up getpid() by trying to cache the result, so we'll do it ourselves */ -#include <sys/syscall.h> -#define getpid() syscall(SYS_getpid) - -/* temporarily suppress CLONE_PTRACE so it works on broken Linux kernels */ -#undef CLONE_PTRACE -#define CLONE_PTRACE 0 - -enum -{ - DELETE = 0x7f, - CTRLC = 'C'-'@', - NSTACKSPERALLOC = 16, - X11STACK= 256*1024 -}; -char *hosttype = "Linux"; - -extern void unlockandexit(int*); -extern void executeonnewstack(void*, void (*f)(void*), void*); - -static void *stackalloc(Proc *p, void **tos); -static void stackfreeandexit(void *stack); - -typedef sem_t Sem; - -extern int dflag; - -int gidnobody = -1; -int uidnobody = -1; -static struct termios tinit; - -void -pexit(char *msg, int t) -{ - Osenv *e; - Proc *p; - Sem *sem; - void *kstack; - - lock(&procs.l); - p = up; - if(p->prev) - p->prev->next = p->next; - else - procs.head = p->next; - - if(p->next) - p->next->prev = p->prev; - else - procs.tail = p->prev; - unlock(&procs.l); - - if(0) - print("pexit: %s: %s\n", p->text, msg); - - e = p->env; - if(e != nil) { - closefgrp(e->fgrp); - closepgrp(e->pgrp); - closeegrp(e->egrp); - closesigs(e->sigs); - free(e->user); - } - kstack = p->kstack; - free(p->prog); - sem = p->os; - if(sem != nil) - sem_destroy(sem); - free(p->os); - free(p); - if(kstack != nil) - stackfreeandexit(kstack); -} - -int -tramp(void *arg) -{ - Proc *p; - p = arg; - p->pid = p->sigid = getpid(); - (*p->func)(p->arg); - pexit("{Tramp}", 0); - return 0; /* not reached */ -} - -void -kproc(char *name, void (*func)(void*), void *arg, int flags) -{ - Proc *p; - Pgrp *pg; - Fgrp *fg; - Egrp *eg; - void *tos; - Sem *sem; - - p = newproc(); - if(0) - print("start %s:%#p\n", name, p); - if(p == nil) - panic("kproc(%s): no memory", name); - - sem = malloc(sizeof(*sem)); - if(sem == nil) - panic("can't allocate semaphore"); - sem_init(sem, 0, 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; - - if(flags & KPX11){ - p->kstack = nil; /* never freed; also up not defined */ - tos = (char*)mallocz(X11STACK, 0) + X11STACK - sizeof(vlong); - }else - p->kstack = stackalloc(p, &tos); - - 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(clone(tramp, tos, CLONE_PTRACE|CLONE_VM|CLONE_FS|CLONE_FILES|SIGCHLD, p, nil, nil, nil) <= 0) - panic("kproc: clone failed"); -} - -static void -sysfault(char *what, void *addr) -{ - char buf[64]; - - snprint(buf, sizeof(buf), "sys: %s%#p", what, addr); - disfault(nil, buf); -} - -static void -trapILL(int signo, siginfo_t *si, void *a) -{ - USED(signo); - USED(a); - sysfault("illegal instruction pc=", si->si_addr); -} - -static int -isnilref(siginfo_t *si) -{ - return si != 0 && (si->si_addr == (void*)~(uintptr_t)0 || (uintptr_t)si->si_addr < 512); -} - -static void -trapmemref(int signo, siginfo_t *si, void *a) -{ - USED(a); /* ucontext_t*, could fetch pc in machine-dependent way */ - if(isnilref(si)) - disfault(nil, exNilref); - else if(signo == SIGBUS) - sysfault("bad address addr=", si->si_addr); /* eg, misaligned */ - else - sysfault("segmentation violation addr=", si->si_addr); -} - -static void -trapFPE(int signo, siginfo_t *si, void *a) -{ - char buf[64]; - - USED(signo); - USED(a); - snprint(buf, sizeof(buf), "sys: fp: exception status=%.4lux pc=%#p", getfsr(), si->si_addr); - disfault(nil, buf); -} - -static void -trapUSR1(int signo) -{ - int intwait; - - USED(signo); - - 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 */ -} - -/* called to wake up kproc blocked on a syscall */ -void -oshostintr(Proc *p) -{ - kill(p->sigid, SIGUSR1); -} - -void -osblock(void) -{ - Sem *sem; - - sem = up->os; - while(sem_wait(sem)) - {} /* retry on signals (which shouldn't happen) */ -} - -void -osready(Proc *p) -{ - sem_post(p->os); -} - -void -oslongjmp(void *regs, osjmpbuf env, int val) -{ - USED(regs); - siglongjmp(env, val); -} - -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(); - - kill(0, SIGKILL); - exit(0); -} - -void -osreboot(char *file, char **argv) -{ - if(dflag == 0) - termrestore(); - execvp(file, argv); - error("reboot failure"); -} - -void -libinit(char *imod) -{ - struct sigaction act; - struct passwd *pw; - Proc *p; - void *tos; - char sys[64]; - - setsid(); - - gethostname(sys, sizeof(sys)); - kstrdup(&ossysname, sys); - pw = getpwnam("nobody"); - if(pw != nil) { - uidnobody = pw->pw_uid; - gidnobody = pw->pw_gid; - } - - if(dflag == 0) - termset(); - - memset(&act, 0, sizeof(act)); - act.sa_handler = trapUSR1; - sigaction(SIGUSR1, &act, nil); - - act.sa_handler = SIG_IGN; - sigaction(SIGCHLD, &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(signal(SIGINT, SIG_IGN) != SIG_IGN) - signal(SIGINT, cleanexit); - - if(sflag == 0) { - act.sa_flags = SA_SIGINFO; - act.sa_sigaction = trapILL; - sigaction(SIGILL, &act, nil); - act.sa_sigaction = trapFPE; - sigaction(SIGFPE, &act, nil); - act.sa_sigaction = trapmemref; - sigaction(SIGBUS, &act, nil); - sigaction(SIGSEGV, &act, nil); - act.sa_flags &= ~SA_SIGINFO; - } - - p = newproc(); - p->kstack = stackalloc(p, &tos); - - pw = getpwuid(getuid()); - if(pw != nil) - kstrdup(&eve, pw->pw_name); - else - print("cannot getpwuid\n"); - - p->env->uid = getuid(); - p->env->gid = getgid(); - - executeonnewstack(tos, emuinit, imod); -} - -int -readkbd(void) -{ - int n; - char buf[1]; - - n = read(0, buf, sizeof(buf)); - if(n < 0) - print("keyboard close (n=%d, %s)\n", n, strerror(errno)); - if(n <= 0) - pexit("keyboard thread", 0); - - switch(buf[0]) { - case '\r': - buf[0] = '\n'; - break; - case DELETE: - buf[0] = 'H' - '@'; - break; - case CTRLC: - 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,(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) -{ - struct timespec time; - - time.tv_sec = milsec/1000; - time.tv_nsec= (milsec%1000)*1000000; - nanosleep(&time, NULL); - return 0; -} - -int -limbosleep(ulong milsec) -{ - return osmillisleep(milsec); -} - -void -osyield(void) -{ - sched_yield(); -} - -void -ospause(void) -{ - for(;;) - pause(); -} - -void -oslopri(void) -{ - setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS,0)+4); -} - -static struct { - Lock l; - void *free; -} stacklist; - -static void -_stackfree(void *stack) -{ - *((void **)stack) = stacklist.free; - stacklist.free = stack; -} - -static void -stackfreeandexit(void *stack) -{ - lock(&stacklist.l); - _stackfree(stack); - unlockandexit(&stacklist.l.val); -} - -static void * -stackalloc(Proc *p, void **tos) -{ - void *rv; - lock(&stacklist.l); - if (stacklist.free == 0) { - int x; - /* - * obtain some more by using sbrk() - */ - void *more = sbrk(KSTACK * (NSTACKSPERALLOC + 1)); - if (more == 0) - panic("stackalloc: no more stacks"); - /* - * align to KSTACK - */ - more = (void *)((((unsigned long)more) + (KSTACK - 1)) & ~(KSTACK - 1)); - /* - * free all the new stacks onto the freelist - */ - for (x = 0; x < NSTACKSPERALLOC; x++) - _stackfree((char *)more + KSTACK * x); - } - rv = stacklist.free; - stacklist.free = *(void **)rv; - unlock(&stacklist.l); - *tos = rv + KSTACK - sizeof(vlong); - *(Proc **)rv = p; - return rv; -} diff --git a/emu/OpenBSD/asm-386.S b/emu/OpenBSD/asm-386.S index f3a3f9cf..e7c9fa3e 100644 --- a/emu/OpenBSD/asm-386.S +++ b/emu/OpenBSD/asm-386.S @@ -3,8 +3,6 @@ #include <sys/syscall.h> #include <machine/asm.h> -#include "rfork_thread.S" - /* * executeonnewstack(void *tos, void (*tramp)(void *arg), void *arg) */ diff --git a/emu/OpenBSD/mkfile b/emu/OpenBSD/mkfile index ad4e3155..a030c95e 100644 --- a/emu/OpenBSD/mkfile +++ b/emu/OpenBSD/mkfile @@ -19,6 +19,7 @@ INSTALLDIR=$ROOT/$SYSTARG/$OBJTYPE/bin #path of directory where kernel is instal OBJ=\ asm-$OBJTYPE.$O\ os.$O\ + kproc-pthreads.$O\ win-x11a.$O\ $CONF.root.$O\ lock.$O\ @@ -28,7 +29,7 @@ OBJ=\ HFILES=\ CFLAGS='-DROOT="'$ROOT'"' -DEMU -I. -I../port -I$ROOT/$SYSTARG/$OBJTYPE/include -I$ROOT/include -I$ROOT/libinterp $CTHREADFLAGS $CFLAGS $EMUOPTIONS -SYSLIBS= -lm -lX11 -lXext -lossaudio +SYSLIBS= -lm -lX11 -lXext -lossaudio -lpthread KERNDATE=`{$NDATE} default:V: $O.$CONF diff --git a/emu/OpenBSD/os.c b/emu/OpenBSD/os.c index f45e69d6..fc16cc30 100644 --- a/emu/OpenBSD/os.c +++ b/emu/OpenBSD/os.c @@ -24,60 +24,16 @@ enum }; char *hosttype = "OpenBSD"; -int rfork_thread(int, void *, void (*)(void *), void *); - -extern void unlockandexit(int*); -extern void executeonnewstack(void*, void (*f)(void*), void*); -static void *stackalloc(Proc *p, void **tos); -static void stackfreeandexit(void *stack); - extern int dflag; void -pexit(char *msg, int t) -{ - Osenv *e; - Proc *p; - void *kstack; - - lock(&procs.l); - p = up; - if(p->prev) - p->prev->next = p->next; - else - procs.head = p->next; - - if(up->next) - p->next->prev = p->prev; - else - procs.tail = p->prev; - unlock(&procs.l); - - if(0) - 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); - } - kstack = p->kstack; - free(p->prog); - free(p); - if(kstack != nil) - stackfreeandexit(kstack); -} - -void trapBUS(int signo, siginfo_t *info, void *context) { if(info) print("trapBUS: signo: %d code: %d addr: %lx\n", info->si_signo, info->si_code, info->si_addr); else - print("trapBUS: no info\n"); + print("trapBUS: no info\n"); disfault(nil, "Bus error"); } @@ -135,7 +91,7 @@ setsigs(void) memset(&act, 0 , sizeof(act)); sigemptyset(&initmask); - + signal(SIGPIPE, SIG_IGN); /* prevent signal when devcmd child exits */ if(signal(SIGTERM, SIG_IGN) != SIG_IGN) signal(SIGTERM, cleanexit); @@ -180,101 +136,6 @@ setsigs(void) panic("sigprocmask"); } -static void -tramp(void *arg) -{ - Proc *p; - - p = arg; - p->pid = p->sigid = getpid(); - sigprocmask(SIG_BLOCK, &initmask, nil); /* in 5.3, rfork_thread doesn't copy from parent, contrary to docs? */ - (*p->func)(p->arg); - pexit("{Tramp}", 0); - _exit(0); -} - -void -kproc(char *name, void (*func)(void*), void *arg, int flags) -{ - Proc *p; - Pgrp *pg; - Fgrp *fg; - Egrp *eg; - int pid; - void *tos; - - 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; - unlock(&procs.l); - - if(flags & KPX11){ - p->kstack = nil; /* never freed; also up not defined */ - tos = (char*)mallocz(X11STACK, 0) + X11STACK - sizeof(void*); - }else - p->kstack = stackalloc(p, &tos); - pid = rfork_thread(RFPROC|RFMEM|RFNOWAIT, tos, tramp, p); - if(pid < 0) - panic("rfork"); -} - -void -oshostintr(Proc *p) -{ - kill(p->sigid, SIGUSR1); -} - -void -osblock(void) -{ - sigset_t mask; - - sigprocmask(SIG_SETMASK, NULL, &mask); - sigdelset(&mask, SIGUSR2); - sigsuspend(&mask); -} - -void -osready(Proc *p) -{ - if(kill(p->sigid, SIGUSR2) < 0) - fprint(2, "emu: osready failed: pid %d: %s\n", p->sigid, strerror(errno)); -} - void oslongjmp(void *regs, osjmpbuf env, int val) { @@ -335,7 +196,7 @@ void getnobody() { struct passwd *pwd; - + if(pwd = getpwnam("nobody")) { uidnobody = pwd->pw_uid; gidnobody = pwd->pw_gid; @@ -347,7 +208,6 @@ libinit(char *imod) { struct passwd *pw; Proc *p; - void *tos; char sys[64]; setsid(); @@ -362,18 +222,18 @@ libinit(char *imod) setsigs(); p = newproc(); - p->kstack = stackalloc(p, &tos); + kprocinit(p); pw = getpwuid(getuid()); if(pw != nil) kstrdup(&eve, pw->pw_name); else print("cannot getpwuid\n"); - + p->env->uid = getuid(); p->env->gid = getgid(); - executeonnewstack(tos, emuinit, imod); + emuinit(imod); } int @@ -440,7 +300,7 @@ vlong osusectime(void) { struct timeval t; - + gettimeofday(&t, nil); return (vlong)t.tv_sec * 1000000 + t.tv_usec; } @@ -456,76 +316,6 @@ osmillisleep(ulong milsec) return 0; } -void -osyield(void) -{ - sched_yield(); -} - -void -ospause(void) -{ - for(;;) - pause(); -} - -void -oslopri(void) -{ - setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS,0)+4); -} - -static struct { - Lock l; - void *free; -} stacklist; - -static void -_stackfree(void *stack) -{ - *((void **)stack) = stacklist.free; - stacklist.free = stack; -} - -static void -stackfreeandexit(void *stack) -{ - lock(&stacklist.l); - _stackfree(stack); - unlockandexit(&stacklist.l.val); -} - -static void * -stackalloc(Proc *p, void **tos) -{ - void *rv; - lock(&stacklist.l); - if (stacklist.free == 0) { - int x; - /* - * obtain some more by using sbrk() - */ - void *more = sbrk(KSTACK * (NSTACKSPERALLOC + 1)); - if (more == 0) - panic("stackalloc: no more stacks"); - /* - * align to KSTACK - */ - more = (void *)((((unsigned long)more) + (KSTACK - 1)) & ~(KSTACK - 1)); - /* - * free all the new stacks onto the freelist - */ - for (x = 0; x < NSTACKSPERALLOC; x++) - _stackfree((char *)more + KSTACK * x); - } - rv = stacklist.free; - stacklist.free = *(void **)rv; - unlock(&stacklist.l); - *tos = rv + KSTACK - sizeof(void*); - *(Proc **)rv = p; - return rv; -} - int segflush(void *p, ulong n) { diff --git a/emu/OpenBSD/rfork_thread.S b/emu/OpenBSD/rfork_thread.S deleted file mode 100644 index bb7cd010..00000000 --- a/emu/OpenBSD/rfork_thread.S +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * 8 12 16 20 - * rfork_thread(flags, stack_addr, start_fnc, start_arg); - * - * flags: Flags to rfork system call. See rfork(2). - * stack_addr: Top of stack for thread. - * start_fnc: Address of thread function to call in child. - * start_arg: Argument to pass to the thread function in child. - */ - -ENTRY(rfork_thread) - pushl %ebp - movl %esp, %ebp - pushl %esi - - /* - * Push thread info onto the new thread's stack - */ - movl 12(%ebp), %esi # get stack addr - - subl $4, %esi - movl 20(%ebp), %eax # get start argument - movl %eax, (%esi) - - subl $4, %esi - movl 16(%ebp), %eax # get start thread address - movl %eax, (%esi) - - /* - * Prepare and execute the thread creation syscall - */ - pushl 8(%ebp) - pushl $0 - movl $SYS_rfork, %eax - int $0x80 - jb 2f - - /* - * Check to see if we are in the parent or child - */ - cmpl $0, %edx - jnz 1f - addl $8, %esp - popl %esi - movl %ebp, %esp - popl %ebp - ret - .p2align 2 - - /* - * If we are in the child (new thread), then - * set-up the call to the internal subroutine. If it - * returns, then call __exit. - */ -1: - movl %esi,%esp - popl %eax - call *%eax - addl $4, %esp - - /* - * Exit system call - */ - pushl %eax - pushl $0 - movl $SYS_threxit, %eax - int $0x80 - - /* - * Branch here if the thread creation fails: - */ -2: - addl $8, %esp - popl %esi - movl %ebp, %esp - popl %ebp - PIC_PROLOGUE - jmp PIC_PLT(_C_LABEL(__cerror)) diff --git a/emu/port/win-x11a.c b/emu/port/win-x11a.c index 65e38eed..569287b6 100644 --- a/emu/port/win-x11a.c +++ b/emu/port/win-x11a.c @@ -313,6 +313,33 @@ copy32to32(Rectangle r) } static void +copy16to16(Rectangle r) +{ + int dx, width; + u16int *dp, *wp, *edp, *lp; + + width = Dx(r); + dx = Xsize - width; + dp = (u16int*)(gscreendata + ((r.min.y * Xsize) + r.min.x) * 2); + wp = (u16int*)(xscreendata + ((r.min.y * Xsize) + r.min.x) * 2); + edp = (u16int*)(gscreendata + ((r.max.y * Xsize) + r.max.x) * 2); + + /* The pixel format should be the same as the underlying X display (see + the xtruevisual function) unless a different channel format is + explicitly specified on the command line, so just copy the pixel data + without any processing. */ + + while(dp < edp) { + lp = dp + width; + while(dp < lp){ + *wp++ = *dp++; + } + dp += dx; + wp += dx; + } +} + +static void copy8to32(Rectangle r) { int dx, width; @@ -435,6 +462,17 @@ flushmemscreen(Rectangle r) case 32: copy32to32(r); break; + case 16: + switch(xscreendepth){ + case 16: + copy16to16(r); + break; + default: + fprint(2, "emu: bad display depth %d chan %s xscreendepth %d\n", displaydepth, + chantostr(chanbuf, displaychan), xscreendepth); + cleanexit(0); + } + break; case 8: switch(xscreendepth){ case 24: diff --git a/lib9/setfcr-OpenBSD-386.S b/lib9/setfcr-OpenBSD-386.S new file mode 100644 index 00000000..d981f36a --- /dev/null +++ b/lib9/setfcr-OpenBSD-386.S @@ -0,0 +1,34 @@ + +#define FN(x) .type x,@function; .global x; x +#define ENT subl $16, %esp +#define RET addl $16, %esp; ret + + .file "setfcr-Linux-386.S" +FN(setfcr): + ENT + xorb $0x3f, %al + movl %eax, (%esp) + fwait + fldcw (%esp) + RET + +FN(getfcr): + ENT + fwait + fstcw (%esp) + movw (%esp), %ax + andl $0xffff, %eax + xorb $0x3f, %al + RET + +FN(getfsr): + ENT + fwait + fstsw (%esp) + movw (%esp), %ax + andl $0xffff, %eax + RET + +FN(setfsr): + fclex + ret diff --git a/limbo/limbo.y b/limbo/limbo.y index a6ccab90..f869f01c 100644 --- a/limbo/limbo.y +++ b/limbo/limbo.y @@ -582,13 +582,13 @@ ftype : nids ':' type { $$ = mkids(&$1->src, enter("junk", 0), $3, nil); $$->store = Darg; - yyerror("illegal argument declaraion"); + yyerror("illegal argument declaration"); } | idterms ':' adtk { $$ = mkids(&$1->src, enter("junk", 0), $3, nil); $$->store = Darg; - yyerror("illegal argument declaraion"); + yyerror("illegal argument declaration"); } ; diff --git a/limbo/types.c b/limbo/types.c index 6d231115..c8105d5a 100644 --- a/limbo/types.c +++ b/limbo/types.c @@ -2024,7 +2024,7 @@ cycfield(Type *base, Decl *id) id->sym->name, base); id->cycerr = 1; }else if(arc & ArcCyc){ - if((arc & ArcArray) && id->cyc == 0 && !(arc & ArcPolycyc)){ + if((arc & ArcArray) && oldcycles && id->cyc == 0 && !(arc & ArcPolycyc)){ if(id->cycerr == 0) error(base->src.start, "illegal circular reference to type %T in field %s of %t", id->ty, id->sym->name, base); @@ -3466,7 +3466,7 @@ expandtype(Type *t, Type *instt, Decl *adtt, Tpair **tp) if(t == nil) return nil; -if(debug['w']) print("expandtype %d %lux %T\n", t->kind, (ulong)t, t); +if(debug['w']) print("expandtype %d %#p %T\n", t->kind, t, t); if(!toccurs(t, tp)) return t; if(debug['w']) print("\texpanding\n"); diff --git a/module/draw.m b/module/draw.m index 730e62ac..a9dabd8f 100644 --- a/module/draw.m +++ b/module/draw.m @@ -91,7 +91,7 @@ Draw: module RGB15: con Chans(((CIgnore<<4)|1)<<24 | ((CRed<<4)|5)<<16 | ((CGreen<<4)|5)<<8 | ((CBlue<<4)|5)); RGB16: con Chans(((CRed<<4)|5)<<16 | ((CGreen<<4)|6)<<8 | ((CBlue<<4)|5)); RGB24: con Chans(((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8)); - RGBA32: con Chans((((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8))<<8 | ((CAlpha<<4)|8)); + RGBA32: con Chans((((CRed<<4)|8)<<24 | ((CGreen<<4)|8)<<16 | ((CBlue<<4)|8))<<8 | ((CAlpha<<4)|8)); ARGB32: con Chans(((CAlpha<<4)|8)<<24 | ((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8)); # stupid VGAs XRGB32: con Chans(((CIgnore<<4)|8)<<24 | ((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8)); # stupid VGAs diff --git a/utils/8l/l.h b/utils/8l/l.h index da151014..85964bc3 100644 --- a/utils/8l/l.h +++ b/utils/8l/l.h @@ -195,7 +195,7 @@ EXTERN union uchar obuf[MAXIO]; /* output buffer */ uchar ibuf[MAXIO]; /* input buffer */ } u; - char dbuf[1]; + char dbuf[2*MAXIO]; } buf; #define cbuf u.obuf @@ -236,8 +236,8 @@ EXTERN char debug[128]; EXTERN char literal[32]; EXTERN Prog* etextp; EXTERN Prog* firstp; -EXTERN char fnuxi8[8]; -EXTERN char fnuxi4[4]; +EXTERN uchar fnuxi8[8]; +EXTERN uchar fnuxi4[4]; EXTERN Sym* hash[NHASH]; EXTERN Sym* histfrog[MAXHIST]; EXTERN int histfrogp; @@ -247,9 +247,9 @@ EXTERN char* libraryobj[50]; EXTERN int libraryp; EXTERN int xrefresolv; EXTERN char* hunk; -EXTERN char inuxi1[1]; -EXTERN char inuxi2[2]; -EXTERN char inuxi4[4]; +EXTERN uchar inuxi1[1]; +EXTERN uchar inuxi2[2]; +EXTERN uchar inuxi4[4]; EXTERN char ycover[Ymax*Ymax]; EXTERN uchar* andptr; EXTERN uchar and[30]; |
