Skip to content

Commit

Permalink
Plan 9 from Bell Labs 2014-05-15
Browse files Browse the repository at this point in the history
  • Loading branch information
0intro committed May 15, 2014
1 parent 6d3b63b commit bd0c933
Show file tree
Hide file tree
Showing 27 changed files with 234 additions and 110 deletions.
4 changes: 2 additions & 2 deletions sys/doc/backup.ms
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ as the term is used by everyone but disk manufacturers.
In the case of BDs,
even that is an exaggeration, with the actual capacity being
closer to $48.44 times 10 sup 9$ bytes,
so the claimed capacity should be read as `50 VAX-gigabytes',
so the claimed capacity should be read as `50 BD-gigabytes',
where a
.I VAX-gigabyte
.I BD-gigabyte
is 968,800,338 bytes.
The default
.I venti
Expand Down
Binary file added sys/doc/backup.pdf
Binary file not shown.
Binary file modified sys/doc/backup.ps
Binary file not shown.
19 changes: 14 additions & 5 deletions sys/man/2/time
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,27 @@ should be stored in and treated as
.BR ulong s;
this extends the range of valid times into the year 2106.
.PP
These functions work by reading
.I Time
simply calls
.I nsec
and returns the value divided by 1000000000.
.PP
.I Nsec
is a system call.
Previous implementations read
.BR /dev/bintime ,
opening that file when they are first called.
opening that file when first called,
and maintaining a static file descriptor;
however,
the maintenance of file descriptors in the face
of process forks is overly complex and prone to error.
.SH SOURCE
.B /sys/src/libc/9sys/time.c
.br
.B /sys/src/libc/9sys/nsec.c
.B /sys/src/libc/9syscall
.SH SEE ALSO
.IR cputime (2),
.IR cons (3)
.SH DIAGNOSTICS
Sets
.IR errstr .
.SH BUGS
These routines maintain a static file descriptor.
2 changes: 1 addition & 1 deletion sys/src/9/bcm/fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ extern int fpuemu(Ureg*);
extern void delay(int); /* only scheddump() */
extern int islo(void);
extern void microdelay(int); /* only edf.c */
extern void evenaddr(uintptr);
extern void idlehands(void);
extern void setkernur(Ureg*, Proc*); /* only devproc.c */
extern void* sysexecregs(uintptr, ulong, int);
extern void sysprocsetup(Proc*);
extern void validalign(uintptr, unsigned);

extern void kexit(Ureg*);

Expand Down
31 changes: 24 additions & 7 deletions sys/src/9/kw/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ setkernur(Ureg* ureg, Proc* p)
}

/*
* called in sysfile.c
* called in syscallfmt.c, sysfile.c, sysproc.c
*/
void
evenaddr(uintptr addr)
{
if(addr & 3){
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
}
validalign(uintptr addr, unsigned align)
{
/*
* Plan 9 is a 32-bit O/S, and the hardware it runs on
* does not usually have instructions which move 64-bit
* quantities directly, synthesizing the operations
* with 32-bit move instructions. Therefore, the compiler
* (and hardware) usually only enforce 32-bit alignment,
* if at all.
*
* Take this out if the architecture warrants it.
*/
if(align == sizeof(vlong))
align = sizeof(long);

/*
* Check align is a power of 2, then addr alignment.
*/
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
return;
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
/*NOTREACHED*/
}

/* go to user space */
Expand Down
2 changes: 1 addition & 1 deletion sys/src/9/kw/fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ extern Block* uciallocb(int);
extern void delay(int); /* only scheddump() */
extern int islo(void);
extern void microdelay(int); /* only edf.c */
extern void evenaddr(uintptr);
extern void idlehands(void);
extern void setkernur(Ureg*, Proc*); /* only devproc.c */
extern void spldone(void);
extern int splfhi(void);
extern int splflo(void);
extern void sysprocsetup(Proc*);
extern void validalign(uintptr, unsigned);

/*
* PCI
Expand Down
2 changes: 1 addition & 1 deletion sys/src/9/mtx/fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ void delay(int);
void dumpregs(Ureg*);
void delayloopinit(void);
void eieio(void);
void evenaddr(ulong);
void faultpower(Ureg*, ulong addr, int read);
void fprestore(FPsave*);
void fpsave(FPsave*);
Expand Down Expand Up @@ -103,6 +102,7 @@ void trapvec(void);
void tlbflush(ulong);
void tlbflushall(void);
#define userureg(ur) (((ur)->status & MSR_PR) != 0)
void validalign(uintptr, unsigned);
void watchreset(void);

#define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
Expand Down
29 changes: 23 additions & 6 deletions sys/src/9/mtx/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,32 @@ kprocchild(Proc *p, void (*func)(void*), void *arg)
}

/*
* called in sysfile.c
* called in syscallfmt.c, sysfile.c, sysproc.c
*/
void
evenaddr(ulong addr)
validalign(uintptr addr, unsigned align)
{
if(addr & 3){
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
}
/*
* Plan 9 is a 32-bit O/S, and the hardware it runs on
* does not usually have instructions which move 64-bit
* quantities directly, synthesizing the operations
* with 32-bit move instructions. Therefore, the compiler
* (and hardware) usually only enforce 32-bit alignment,
* if at all.
*
* Take this out if the architecture warrants it.
*/
if(align == sizeof(vlong))
align = sizeof(long);

/*
* Check align is a power of 2, then addr alignment.
*/
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
return;
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
/*NOTREACHED*/
}

long
Expand Down
31 changes: 24 additions & 7 deletions sys/src/9/omap/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ setkernur(Ureg* ureg, Proc* p)
}

/*
* called in sysfile.c
* called in syscallfmt.c, sysfile.c, sysproc.c
*/
void
evenaddr(uintptr addr)
{
if(addr & 3){
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
}
validalign(uintptr addr, unsigned align)
{
/*
* Plan 9 is a 32-bit O/S, and the hardware it runs on
* does not usually have instructions which move 64-bit
* quantities directly, synthesizing the operations
* with 32-bit move instructions. Therefore, the compiler
* (and hardware) usually only enforce 32-bit alignment,
* if at all.
*
* Take this out if the architecture warrants it.
*/
if(align == sizeof(vlong))
align = sizeof(long);

/*
* Check align is a power of 2, then addr alignment.
*/
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
return;
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
/*NOTREACHED*/
}

/* go to user space */
Expand Down
2 changes: 1 addition & 1 deletion sys/src/9/omap/fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ extern void ucfreeb(Block*);
extern void delay(int); /* only scheddump() */
extern int islo(void);
extern void microdelay(int); /* only edf.c */
extern void evenaddr(uintptr);
extern void idlehands(void);
extern void setkernur(Ureg*, Proc*); /* only devproc.c */
extern void* sysexecregs(uintptr, ulong, int);
extern void sysprocsetup(Proc*);
extern void validalign(uintptr, unsigned);

/*
* PCI stuff.
Expand Down
5 changes: 4 additions & 1 deletion sys/src/9/pc/fns.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ int dmadone(int);
void dmaend(int);
int dmainit(int, int);
long dmasetup(int, void*, long, int);
#define evenaddr(x) /* x86 doesn't care */
void fpclear(void);
void fpenv(FPsave*);
void fpinit(void);
Expand Down Expand Up @@ -182,6 +181,7 @@ ulong upaalloc(int, int);
void upafree(ulong, int);
void upareserve(ulong, int);
#define userureg(ur) (((ur)->cs & 0xFFFF) == UESEL)
void validalign(uintptr, unsigned);
void vectortable(void);
void* vmap(ulong, int);
int vmapsync(ulong);
Expand All @@ -190,6 +190,9 @@ void wbinvd(void);
void wrmsr(int, vlong);
int xchgw(ushort*, int);

#define PTR2UINT(p) ((uintptr)(p))
#define UINT2PTR(i) ((void*)(i))

#define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1]))
#define KADDR(a) kaddr(a)
#define PADDR(a) paddr((void*)(a))
Expand Down
26 changes: 26 additions & 0 deletions sys/src/9/pc/trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,32 @@ if(0) print("%s %lud: noted %.8lux %.8lux\n",
}
}

void
validalign(uintptr addr, unsigned align)
{
/*
* Plan 9 is a 32-bit O/S, and the hardware it runs on
* does not usually have instructions which move 64-bit
* quantities directly, synthesizing the operations
* with 32-bit move instructions. Therefore, the compiler
* (and hardware) usually only enforce 32-bit alignment,
* if at all.
*
* Take this out if the architecture warrants it.
*/
if(align == sizeof(vlong))
align = sizeof(long);

/*
* Check align is a power of 2, then addr alignment.
*/
if((align != 0 && !(align & (align-1))) && !(addr & (align-1)))
return;
postnote(up, 1, "sys: odd address", NDebug);
error(Ebadarg);
/*NOTREACHED*/
}

long
execregs(ulong entry, ulong ssize, ulong nargs)
{
Expand Down
9 changes: 8 additions & 1 deletion sys/src/9/port/syscallfmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ syscallfmt(int syscallno, ulong pc, va_list list)
a = va_arg(list, char*);
fmtuserstring(&fmt, a, "");
argv = va_arg(list, char**);
evenaddr(PTR2UINT(argv));
validalign(PTR2UINT(argv), sizeof(char*));
for(;;){
validaddr((ulong)argv, sizeof(char**), 0);
a = *(char **)argv;
Expand Down Expand Up @@ -299,6 +299,10 @@ syscallfmt(int syscallno, ulong pc, va_list list)
fmtprint(&fmt, " %lld", vl);
}
break;
case NSEC:
v = va_arg(list, vlong*);
fmtprint(&fmt, "%#p", v);
break;
}

up->syscalltrace = fmtstrflush(&fmt);
Expand Down Expand Up @@ -400,6 +404,9 @@ sysretfmt(int syscallno, va_list list, long ret, uvlong start, uvlong stop)
}
fmtprint(&fmt, " = %ld", ret);
break;
case NSEC:
fmtprint(&fmt, " = %ld", ret); /* FoV */
break;
}
fmtprint(&fmt, " %s %#llud %#llud\n", errstr, start, stop);
up->syscalltrace = fmtstrflush(&fmt);
Expand Down
11 changes: 6 additions & 5 deletions sys/src/9/port/sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ syspipe(ulong *arg)
Dev *d;
static char *datastr[] = {"data", "data1"};

validaddr(arg[0], 2*BY2WD, 1);
evenaddr(arg[0]);
validaddr(arg[0], sizeof(fd), 1);
validalign(arg[0], sizeof(int));
d = devtab[devno('|', 0)];
c[0] = namec("#|", Atodir, 0, 0);
c[1] = 0;
Expand All @@ -215,8 +215,8 @@ syspipe(ulong *arg)
error(Enofd);
poperror();

((long*)arg[0])[0] = fd[0];
((long*)arg[0])[1] = fd[1];
((int*)arg[0])[0] = fd[0];
((int*)arg[0])[1] = fd[1];
return 0;
}

Expand Down Expand Up @@ -859,7 +859,8 @@ sseek(ulong *arg)
long
sysseek(ulong *arg)
{
validaddr(arg[0], BY2V, 1);
validaddr(arg[0], sizeof(vlong), 1);
validalign(arg[0], sizeof(vlong));
sseek(arg);
return 0;
}
Expand Down

0 comments on commit bd0c933

Please sign in to comment.