initial cut at sys structure for pc. it's done in an ugly way, and we're not using the stack and mach0 that we say we are, but at least all the pieces are in the right place. give up on different ticks for different machines. we don't have a light panel for each processor. :-) Reference: /n/atom/patch/applied2013/fspcsys Date: Tue Aug 27 15:28:28 CES 2013 Signed-off-by: quanstro@quanstro.net --- /sys/src/fs/pc/l.s Tue Aug 27 15:27:22 2013 +++ /sys/src/fs/pc/l.s Tue Aug 27 15:27:23 2013 @@ -86,6 +86,7 @@ MOVL $0,0(SP) ADDL $(MACHSIZE-4),SP /* start stack under machine struct */ MOVL $0, u(SB) + MOVL $sys0(SB),sys(SB) /* * clear flags @@ -102,7 +103,9 @@ GLOBL mach0+0(SB), $MACHSIZE GLOBL u(SB), $4 GLOBL m(SB), $4 +GLOBL sys(SB), $4 GLOBL tpt(SB), $(BY2PG*3) +GLOBL sys0(SB), $(MACHSTKSZ+MACHSZ+4*KiB+4*KiB+8*KiB) /* * gdt to get us to 32-bit/segmented/unpaged mode @@ -548,9 +551,10 @@ POPFL RET -TEXT getstatus(SB),$0 +TEXT islo(SB),$0 PUSHFL POPL AX + ANDL $IFLAG, AX RET TEXT _cycles(SB), $0 /* time stamp counter; cycles since power up */ --- /sys/src/fs/pc/archdat.h Tue Aug 27 15:27:24 2013 +++ /sys/src/fs/pc/archdat.h Tue Aug 27 15:27:24 2013 @@ -13,6 +13,7 @@ typedef u32int Mpl; typedef struct Pcidev Pcidev; typedef struct Segdesc Segdesc; +typedef struct Sys Sys; typedef ulong uintmem; #pragma incomplete Pcidev @@ -47,7 +48,7 @@ struct Mach { int machno; /* physical id of processor */ - long ticks; /* of the clock since boot time */ +// long ticks; /* of the clock since boot time */ int lights; /* light lights, this processor */ Filter idle; @@ -88,11 +89,35 @@ ulong topofmem; }; +struct Sys { + uchar machstk[MACHSTKSZ]; + + union { + Mach mach; + uchar machpage[MACHSZ]; + }; + union { + struct { + long ticks; /* convert to u64int for tsc? */ + u64int epoch; /* tsc synchronization */ + }; + uchar syspage[4*KiB]; + }; + union { + Mach* machptr[MACHMAX]; + uchar ptrpage[4*KiB]; + }; + uchar pad[2][4096]; +}; + +extern Sys* sys; extern Mach mach0; extern Mconf mconf; extern char nvrfile[128]; extern /*register*/ Mach* m; extern /*register*/ User* u; -#define MACHP(n) ((Mach*)(MACHADDR+n*BY2PG)) -#define Ticks MACHP(0)->ticks +//#define MACHP(n) ((Mach*)(MACHADDR+n*BY2PG)) +//#define Ticks MACHP(0)->ticks +#define MACHP(n) sys->machptr[n] +#define Ticks sys->ticks --- /sys/src/fs/pc/8253.c Tue Aug 27 15:27:25 2013 +++ /sys/src/fs/pc/8253.c Tue Aug 27 15:27:26 2013 @@ -168,7 +168,7 @@ static void simplecycles(uvlong*x) { - *x = m->ticks; + *x = Ticks; } void (*cycles)(uvlong*) = simplecycles; --- /sys/src/fs/pc/ata.c Tue Aug 27 15:27:28 2013 +++ /sys/src/fs/pc/ata.c Tue Aug 27 15:27:30 2013 @@ -401,7 +401,7 @@ } /* else we're in predawn with no u */ x = spllo(); - for (start = m->ticks; TK2MS(Ticks - start) < msec && !fn(v); ) + for (start = Ticks; TK2MS(Ticks - start) < msec && !fn(v); ) continue; splx(x); } --- /sys/src/fs/pc/lock.c Tue Aug 27 15:27:30 2013 +++ /sys/src/fs/pc/lock.c Tue Aug 27 15:27:31 2013 @@ -64,7 +64,7 @@ if(u) dumpstack(u); dotrace(0); - if(getstatus() & IFLAG) + if(islo()) sched(); else print("ilock deadlock\n"); @@ -82,7 +82,7 @@ if(u && _xdec(&u->nlock) == 0) if(u->delaysched) - if(getstatus() & IFLAG){ + if(islo()){ /* * Call sched if the need arose while locks were held * But, don't do it from interrupt routines, hence the islo() test @@ -126,7 +126,7 @@ while(l->sbsem) ; #else - if(getstatus() & IFLAG) + if(islo()) sched(); else panic("ilock: locked & splhi\n"); @@ -155,7 +155,7 @@ panic("iunlock nolock: pc %#p", getcallerpc(&l)); if(l->isilock == 0) print("iunlock lock: pc %#p held by %#p\n", getcallerpc(&l), l->pc); - if((getstatus()&IFLAG) != 0) + if(islo()) print("iunlock lo: %#p held by %#p\n", getcallerpc(&l), l->pc); sr = l->sr; --- /sys/src/fs/pc/fns.h Tue Aug 27 15:27:32 2013 +++ /sys/src/fs/pc/fns.h Tue Aug 27 15:27:32 2013 @@ -1,17 +1,15 @@ #include "../port/portfns.h" void aamloop(int); +int atainit(void); void cgaputc(int); void cgaputs(char*, int); void cmd_e820(int, char**); void (*coherence)(void); void cpuid(char*, ulong*, ulong*); +void (*cycles)(uvlong*); void etherinit(void); void etherstart(void); -int floppyinit(void); -void floppyproc(void); -Off floppyread(int, void*, long, Devsize); -Off floppywrite(int, void*, long, Devsize); void fpinit(void); vlong getatapartoff(int, char*); char* getconf(char*); @@ -20,22 +18,19 @@ ulong getcr3(void); ulong getcr4(void); int getfields(char*, char**, int, int, char*); -ulong getstatus(void); -int atainit(void); -Off ataread(int, void*, long, Devsize); -Off atawrite(int, void*, long, Devsize); void i8042a20(void); void i8042reset(void); void idle(void); int inb(int); +ulong inl(int); void insb(int, void*, int); ushort ins(int); -void inss(int, void*, int); -ulong inl(int); void insl(int, void*, int); +void inss(int, void*, int); +int islo(void); +int kbdgetc(void); void kbdinit(void); int kbdintr0(void); -int kbdgetc(void); ulong* mapaddr(ulong); void mb386(void); void mb586(void); @@ -44,42 +39,55 @@ void mmuinit(void); uchar nvramread(int); void outb(int, int); +void outl(int, ulong); void outsb(int, void*, int); void outs(int, ushort); -void outss(int, void*, int); -void outl(int, ulong); void outsl(int, void*, int); +void outss(int, void*, int); void printcpufreq(void); -void putgdt(Segdesc*, int); -void putidt(Segdesc*, int); void putcr3(ulong); void putcr4(ulong); +void putgdt(Segdesc*, int); +void putidt(Segdesc*, int); void puttr(ulong); void rdmsr(int, vlong*); -void wrmsr(int, vlong); -void (*cycles)(uvlong*); -void scsiinit(void); -Off scsiread(int, void*, long); -Devsize scsiseek(int, Devsize); -Off scsiwrite(int, void*, long); -int setatapart(int, char*); -int setscsipart(int, char*); void setvec(int, void (*)(Ureg*, void*), void*); -int splhi(void); -int spllo(void); -void splx(int); +Mpl splhi(void); +Mpl spllo(void); +void splx(Mpl); int tas(Lock*); void trapinit(void); -void uartspecial(int, void (*)(int), int (*)(void), int); int uartgetc(void); void uartputc(int); void uartputs(char*); +void uartspecial(int, void (*)(int), int (*)(void), int); void* vmap(ulong, int); +void wrmsr(int, vlong); + +#define PTR2UINT(p) ((uintptr)(p)) +#define UINT2PTR(i) ((void*)(i))\ #define PADDR(a) ((uintptr)(a)-KZERO) #define PCIWADDR(a) PADDR(a) #define Pciwaddrl(a) PADDR(a) #define Pciwaddrh(a) 0 + +/* old ata */ +//Off ataread(int, void*, long, Devsize); +//Off atawrite(int, void*, long, Devsize); + +/* floppy */ +//int floppyinit(void); +//void floppyproc(void); +//Off floppyread(int, void*, long, Devsize); +//Off floppywrite(int, void*, long, Devsize); + +/* scsi */ +void scsiinit(void); +Off scsiread(int, void*, long); +Devsize scsiseek(int, Devsize); +Off scsiwrite(int, void*, long); +int setatapart(int, char*); /* pata */ void ideinit(Device*); --- /sys/src/fs/port/auth.c Tue Aug 27 15:27:33 2013 +++ /sys/src/fs/port/auth.c Tue Aug 27 15:27:34 2013 @@ -236,7 +236,7 @@ if(*why) print("authentication failed: %s: %s\n", phasename[s->phase], why); - srand((uintptr)s + m->ticks); + srand((uintptr)s + Ticks); for(i = 0; i < CHALLEN; i++) s->tr.chal[i] = nrand(256); s->uid = -1; --- /sys/src/fs/port/clock.c Tue Aug 27 15:27:34 2013 +++ /sys/src/fs/port/clock.c Tue Aug 27 15:27:35 2013 @@ -96,7 +96,7 @@ clockreload(n); if(m->machno == 0) - m->ticks++; /* wrong */ + sys->ticks++; if(cons.profile) { cons.profbuf[0] += TK2MS(1); @@ -123,7 +123,7 @@ f.cons = -1; } - lights(Lreal, (m->ticks>>6)&1); + lights(Lreal, (sys->ticks>>6)&1); f.time += TK2MS(1); while(f.time >= 1000) {