From 944a30a1b19b3d7e97815e426101563f8e7c7815 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 12 Aug 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-08-12 --- gnot/fault68020.c | 1 - gnot/main.c | 6 ++-- gnot/trap.c | 2 +- pc/main.c | 4 ++- port/devcons.c | 9 ++--- port/fault.c | 2 +- port/portfns.h | 2 +- port/streboot.c | 2 +- power/clock.c | 2 +- power/main.c | 3 +- ss/faultsparc.c | 1 - ss/fns.h | 3 +- ss/l.s | 12 +++++-- ss/main.c | 86 +++++++++++++++++++++++++++++++---------------- ss/mem.h | 29 ++++++++-------- ss/mmu.c | 51 ++++++++++++++++++---------- ss/screen.c | 16 +++++---- ss/scsi.c | 5 +-- 18 files changed, 146 insertions(+), 90 deletions(-) diff --git a/gnot/fault68020.c b/gnot/fault68020.c index ba6f00bd6c82c514ac5fd46219b50abaf8a15760..8f2b1fd7025840b06ee72058106c1b7121f1268e 100644 --- a/gnot/fault68020.c +++ b/gnot/fault68020.c @@ -99,7 +99,6 @@ fault68020(Ureg *ur, FFrame *f) } dumpregs(ur); panic("fault: 0x%lux", badvaddr); - exit(); } u->p->insyscall = insyscall; } diff --git a/gnot/main.c b/gnot/main.c index 90f5f3c765f1a8b5fc59678f94cdb3e2d6a9476a..6a5b8542447c74d947c7f5106b4ccaaaa525d10b 100644 --- a/gnot/main.c +++ b/gnot/main.c @@ -259,7 +259,7 @@ bootargs(ulong base) } void -exit(void) +exit(int ispanic) { int i; @@ -269,6 +269,8 @@ exit(void) for(i=0; i<1000; i++) ; splhi(); + if(ispanic) + for(;;); firmware(); } @@ -332,7 +334,7 @@ confinit(void) conf.nimage = 50; conf.copymode = 0; /* copy on write */ conf.portispaged = 0; - conf.nconc = 2; + confinit1(mul); } /* diff --git a/gnot/trap.c b/gnot/trap.c index a9277f8d8c4597b61cd7013a6e4356c7ddb63369..bf172c737fe2cc74ec877526db12e0b38e1737ea 100644 --- a/gnot/trap.c +++ b/gnot/trap.c @@ -121,7 +121,7 @@ trap(Ureg *ur) }else{ print("kernel trap %s pc=0x%lux\n", excname(ur->vo, ur->pc), ur->pc); dumpregs(ur); - exit(); + exit(1); } if(user) diff --git a/pc/main.c b/pc/main.c index 075490a06384f883539d8ed91f28986e8b79821e..81753b566fae26a2bccd4cf230019f4b6c8e1c5a 100644 --- a/pc/main.c +++ b/pc/main.c @@ -411,10 +411,12 @@ meminit(void) * reset the i387 chip */ void -exit(void) +exit(int ispanic) { u = 0; print("exiting\n"); + if(ispanic) + for(;;); switch(machtype){ case Attnsx: headreset(); /* via headland chip */ diff --git a/port/devcons.c b/port/devcons.c index 9ba151eb34bff9fb51a58f6917e5f620c8a0ba89..bb560a394970c5b9845ef4c969b49cdd2b2784ce 100644 --- a/port/devcons.c +++ b/port/devcons.c @@ -171,10 +171,7 @@ panic(char *fmt, ...) buf[n] = '\n'; putstrn(buf, n+1); dumpstack(); - if(cpuserver) - exit(); - else - for(;;); + exit(1); } int pprint(char *fmt, ...) @@ -218,7 +215,7 @@ echo(Rune r, char *buf, int n) * ^p hack */ if(r==0x10 && cpuserver) - panic("^p"); + exit(0); /* * ^t hack BUG @@ -241,7 +238,7 @@ echo(Rune r, char *buf, int n) procdump(); return; case 'r': - exit(); + exit(0); break; } }else if(r == 0x14){ diff --git a/port/fault.c b/port/fault.c index 60694a1b9f73f12d81c6b5edcc35194b95679122..de1b4916a4a08ef28ba66b9f132475763694a7a6 100644 --- a/port/fault.c +++ b/port/fault.c @@ -282,7 +282,7 @@ okaddr(ulong addr, ulong len, int write) return 1; } } - pprint("suicide: invalid address 0x%lux in sys call pc=0x%.8lux\n", addr, userpc()); + pprint("suicide: invalid address 0x%lux in sys call pc=0x%lux\n", addr, userpc()); return 0; } diff --git a/port/portfns.h b/port/portfns.h index aec3ecad5460e976bf84ef5ebea6a8c23ace26b0..84632b6bb1d32ec1949d37569156ef6d488591a4 100644 --- a/port/portfns.h +++ b/port/portfns.h @@ -56,7 +56,7 @@ int eqqid(Qid, Qid); void error(char*); long execregs(ulong, ulong, ulong); void exhausted(char*); -void exit(void); +void exit(int); Block* expandb(Block*, int); int fault(ulong, int); void fdclose(int, int); diff --git a/port/streboot.c b/port/streboot.c index 9cdaba65b241d7bc86c40319708202023c7e3fd9..a5cd6b9d5dc7675666100265ef4b9d866d89e153 100644 --- a/port/streboot.c +++ b/port/streboot.c @@ -42,7 +42,7 @@ rebootiput(Queue *q, Block *bp) { if(bp->type == M_HANGUP){ print("lost connection to fs, rebooting"); - exit(); + exit(0); } PUTNEXT(q, bp); } diff --git a/power/clock.c b/power/clock.c index 67dd5f71d785de6640cf1196bc1a3f9f36d1ddc5..ff3b8c37a46f9e05157e15a7623c380a2ac6a017 100644 --- a/power/clock.c +++ b/power/clock.c @@ -110,7 +110,7 @@ clock(Ureg *ur) duartslave(); if(active.exiting && active.machs&(1<machno)){ print("someone's exiting\n"); - exit(); + exit(0); } checkalarms(); kproftimer(ur->pc); diff --git a/power/main.c b/power/main.c index cbae89f275234d3db5e43112ab23015989be0a3f..94dbb07a1b73e8fd6dd8a5832a4daa6428be70e7 100644 --- a/power/main.c +++ b/power/main.c @@ -328,10 +328,11 @@ online(void) } void -exit(void) +exit(int ispanic) { int i; + USED(ispanic); u = 0; lock(&active); active.machs &= ~(1<machno); diff --git a/ss/faultsparc.c b/ss/faultsparc.c index d2255ec93c0bca70ce59f784113004664918ad0f..8707601329c5abdd871d1f13ff8c89afab069b8f 100644 --- a/ss/faultsparc.c +++ b/ss/faultsparc.c @@ -52,7 +52,6 @@ faultsparc(Ureg *ur) } dumpregs(ur); panic("fault: 0x%lux", badvaddr); - exit(); } splhi(); } diff --git a/ss/fns.h b/ss/fns.h index 9042e413ce89d27b6bc56140e2cb41ff1f7f09d6..a55c753da9b70e960d6e1eb62b13e430329e3f2d 100644 --- a/ss/fns.h +++ b/ss/fns.h @@ -34,6 +34,7 @@ KMap* kmap(Page*); void kmapinit(void); KMap* kmappa(ulong, ulong); KMap* kmapperm(Page*); +ulong kmapregion(ulong, ulong, ulong); int kprint(char*, ...); void kproftimer(ulong); void kunmap(KMap*); @@ -55,7 +56,7 @@ void puttbr(ulong); void putw4(ulong, ulong); /* needed only at boot time */ void systemreset(void); void restfpregs(FPsave*, ulong); -void screeninit(void); +void screeninit(char*); void screenputc(int); void screenputs(char*, int); void scsiintr(void); diff --git a/ss/l.s b/ss/l.s index 2b51fa8b60c55d692110a2ed1917c8376a4c9865..148f01a834d56487dce4568fb7f2963cf206fe5f 100644 --- a/ss/l.s +++ b/ss/l.s @@ -15,6 +15,7 @@ TEXT start(SB), $-4 MOVB R9, (R7, 3) /* now mapped correctly. jmpl to where we want to be */ MOVW $setSB(SB), R2 + MOVW $startvirt(SB), R7 JMPL (R7) MOVW $_mul(SB), R0 /* touch _mul etc.; doesn't need to execute */ @@ -25,6 +26,12 @@ TEXT startvirt(SB), $-4 MOVW $rom(SB), R7 MOVW R8, (R7) /* romvec passed in %i0==R8 */ + /* turn off the cache */ + MOVW $ENAB, R7 + MOVB (R7, 2), R8 + ANDN $ENABCACHE, R8 + MOVB R8, (R7, 2) + MOVW $BOOTSTACK, R1 MOVW $(SPL(0xF)|PSREF|PSRSUPER), R7 @@ -461,8 +468,9 @@ GLOBL mach0+0(SB), $MACHSIZE GLOBL fsr+0(SB), $BY2WD /* - * Interface to ROM. Must save and restore state because - * of different calling conventions. + * Interface to OPEN BOOT ROM. Must save and restore state because + * of different calling conventions. We don't use it, but it's here + * for reference.. */ TEXT call(SB), $16 diff --git a/ss/main.c b/ss/main.c index 7ce2a7f0dab708e8960fda14869b9413423e1b22..e0282caf059fe9832672ee0e20d20dd73924aad2 100644 --- a/ss/main.c +++ b/ss/main.c @@ -16,21 +16,20 @@ int cpuserver; ulong romputcxsegm; ulong bank[2]; char mempres[256]; -ulong fbsz; char fbstr[32]; -char fbcrap[BY2PG]; Label catch; +int NKLUDGE; typedef struct Sysparam Sysparam; struct Sysparam { int id; /* Model type from id prom */ char *name; /* System name */ - char ss2; /* Is sparcstation 2 ? */ + char ss2; /* Is Sparcstation 2? */ int vacsize; /* Cache size */ int vacline; /* Cache line size */ int ncontext; /* Number of MMU contexts */ - int npmeg; /* Number of process maps */ + int npmeg; /* Number of page map entry groups */ char cachebug; /* Machine needs cache bug work around */ int memscan; /* Number of Meg to scan looking for memory */ } @@ -60,9 +59,10 @@ main(void) confinit(); xinit(); mmuinit(); - screeninit(); - printinit(); kmapinit(); + if(conf.monitor) + screeninit(fbstr); + printinit(); ioinit(); if(conf.monitor == 0) sccspecial(2, &printq, &kbdq, 9600); @@ -138,7 +138,8 @@ init0(void) print("Sun Sparcstation %s\n", sparam->name); print("bank 0: %dM 1: %dM\n", bank[0], bank[1]); - print("frame buffer id %lux %lux %s\n", conf.monitor, fbsz, fbstr); + print("frame buffer id %lux %s\n", conf.monitor, fbstr); + print("NKLUDGE %d\n", NKLUDGE); u->slash = (*devtab[0].attach)(0); u->dot = clone(u->slash, 0); @@ -223,7 +224,7 @@ userinit(void) } void -exit(void) +exit(int ispanic) { int i; @@ -234,6 +235,8 @@ exit(void) for(i=0; i<1000; i++) ; splhi(); + if(ispanic) + for(;;); systemreset(); } @@ -282,36 +285,44 @@ confinit(void) /* map id prom */ va = 1*MB-BY2PG; - putw4(va, PPN(EEPROM)|PTEVALID|PTEKERNEL|PTENOCACHE|PTEIO); + putw4(va, PPN(EEPROM)|PTEPROBEIO); memmove(idprom, (char*)(va+0x7d8), 32); if(idprom[0]!=1 || (idprom[1]&0xF0)!=0x50) *(ulong*)va = 0; putw4(va, INVALIDPTE); /* map frame buffer id; we expect it to be in SBUS slot 3 */ - putw4(va, ((FRAMEBUFID>>PGSHIFT)&0xFFFF)|PTEVALID|PTEKERNEL|PTENOCACHE|PTEIO); + putw4(va, ((FRAMEBUFID>>PGSHIFT)&0xFFFF)|PTEPROBEIO); conf.monitor = 0; /* if frame buffer not present, we will trap, so prepare to catch it */ if(setlabel(&catch) == 0){ conf.monitor = *(ulong*)va; -putw4(va, (((FRAMEBUFID+BY2PG)>>PGSHIFT)&0xFFFF)|PTEVALID|PTEKERNEL|PTENOCACHE|PTEIO); -memmove(fbcrap, (void*)va, BY2PG); - j = *(ulong*)(va+4); - fbsz = j; - j = BY2PG - 8; /* for safety */ - for(i=0; i BY2PG-8) + j = BY2PG - 8; /* -8 for safety */ + for(i=0; ivacsize; conf.vaclinesize = sparam->vacline; conf.ncontext = sparam->ncontext; + if(conf.ncontext > 8) + conf.ncontext = 8; /* BUG to enlarge NKLUDGE */ conf.npmeg = sparam->npmeg; conf.ss2cachebug = sparam->cachebug; @@ -353,7 +366,22 @@ memmove(fbcrap, (void*)va, BY2PG); bank[0] = conf.npage0*BY2PG/MB; bank[1] = conf.npage1*BY2PG/MB; - + + if(bank[1] == 0){ + /* + * This split of memory into 2 banks fools the allocator into + * allocating low memory pages from bank 0 for the ethernet since + * it has only a 24bit address counter. + * NB. Suns must have at LEAST 8Mbytes. + */ + conf.npage1 = conf.npage0 - (4*MB)/BY2PG; + conf.base1 = 4*MB; + conf.npage0 = (4*MB)/BY2PG; + conf.base0 = 0; + bank[1] = bank[0]-4; + bank[0] = 4; + } + conf.npage = conf.npage0+conf.npage1; conf.upages = (conf.npage*70)/100; if(cpuserver){ diff --git a/ss/mem.h b/ss/mem.h index 780578c2396b3711ca60d975264801d976c519dd..83f17f224879d9244b07e679eea2bd4728eaca5b 100644 --- a/ss/mem.h +++ b/ss/mem.h @@ -67,16 +67,14 @@ */ #define INVALIDSEGM 0xFFFC0000 /* highest seg of VA reserved as invalid */ #define INVALIDPMEG (conf.npmeg-1) -#define SCREENSEGM 0xFFF80000 -#define SCREENPMEG (conf.npmeg-2) +#define ROMPMEG (conf.npmeg-2) #define ROMSEGM 0xFFE80000 #define ROMEND 0xFFEC0000 #define PG2ROM ((ROMEND-ROMSEGM)/BY2PG) -#define IOSEGM0 ROMSEGM /* see mmuinit() */ -#define NIOSEGM ((SCREENSEGM-ROMSEGM)/BY2SEGM) -#define IOPMEG0 (SCREENPMEG-NIOSEGM) -#define IOSEGM ROMEND -#define IOEND SCREENSEGM +#define NIOSEGM ((MB/BY2SEGM) + 4) /* 1M for screen + overhead */ +#define IOSEGM0 (ROMSEGM-NIOSEGM*BY2SEGM) +#define IOPMEG0 (ROMPMEG-NIOSEGM) +#define IOEND ROMSEGM #define TOPPMEG IOPMEG0 /* @@ -92,6 +90,7 @@ #define PTEACCESS (1<<25) #define PTEMODIFY (1<<24) #define PTEPROBEMEM (PTEVALID|PTEKERNEL|PTENOCACHE|PTEWRITE|PTEMAINMEM) +#define PTEPROBEIO (PTEVALID|PTEKERNEL|PTENOCACHE|PTEWRITE|PTEIO) #define PTEUNCACHED 0 #define PTEMAPMEM (1024*1024) @@ -102,15 +101,15 @@ #define PPN(pa) ((pa>>12)&0xFFFF) /* - * Weird addresses in various ASI's + * Weird addresses etc. in System ASI (2) */ -#define CACHETAGS 0x80000000 /* ASI 2 */ -#define CACHEDATA 0x90000000 /* ASI 2 */ -#define SER 0x60000000 /* ASI 2 */ -#define SEVAR 0x60000004 /* ASI 2 */ -#define ASER 0x60000008 /* ASI 2 */ -#define ASEVAR 0x6000000C /* ASI 2 */ -#define ENAB 0x40000000 /* ASI 2 */ +#define CACHETAGS 0x80000000 +#define CACHEDATA 0x90000000 +#define SER 0x60000000 +#define SEVAR 0x60000004 +#define ASER 0x60000008 +#define ASEVAR 0x6000000C +#define ENAB 0x40000000 #define ENABRESET 0x04 #define ENABCACHE 0x10 #define ENABDMA 0x20 diff --git a/ss/mmu.c b/ss/mmu.c index a8df18488cbf78356ee7aed34b98e0c849550af2..0d3c0e08d9037e4a5574ec7a6d2c5d6b296cc636 100644 --- a/ss/mmu.c +++ b/ss/mmu.c @@ -24,10 +24,10 @@ struct Lock; int lowpmeg; KMap *free; - KMap arena[(IOEND-IOSEGM)/BY2PG]; + KMap arena[(IOEND-IOSEGM0)/BY2PG]; }kmapalloc; -#define NKLUDGE 11 /* <= ((TOPPMEG-kmap.lowpmeg)/NCONTEXT) */ +int NKLUDGE; /* * On SPARC, tlbpid i == context i-1 so that 0 means unallocated @@ -163,6 +163,8 @@ mmuinit(void) putcxsegm(c, KZERO+i*BY2SEGM, i); kmapalloc.lowpmeg = i; + if(PADDR(ktop) & (BY2SEGM-1)) + kmapalloc.lowpmeg++; /* * Make sure cache is turned on for kernel @@ -189,19 +191,9 @@ mmuinit(void) putsegm(l, INVALIDPMEG); /* - * One segment for screen + * Map ROM */ - putsegm(SCREENSEGM, SCREENPMEG); - if(c == 0){ - pte = PTEVALID|PTEWRITE|PTEKERNEL|PTENOCACHE| - PTEIO|((DISPLAYRAM>>PGSHIFT)&0xFFFF); - for(i=0; i>PGSHIFT)&0xFFFF); @@ -211,9 +203,9 @@ mmuinit(void) putpmeg(IOSEGM0+i*BY2PG, INVALIDPTE); } /* - * Remaining segments for IO and kmap + * Segments for IO and kmap */ - for(j=1; j11)NKLUDGE=11; } void @@ -331,8 +325,8 @@ kmapinit(void) kmapalloc.free = 0; k = kmapalloc.arena; - for(i=0; i<(IOEND-IOSEGM)/BY2PG; i++,k++){ - k->va = IOSEGM+i*BY2PG; + for(i=0; i<(IOEND-IOSEGM0)/BY2PG; i++,k++){ + k->va = IOSEGM0+i*BY2PG; kunmap(k); } } @@ -358,6 +352,27 @@ kmappa(ulong pa, ulong flag) return k; } +ulong +kmapregion(ulong pa, ulong n, ulong flag) +{ + KMap *k; + ulong va; + int i, j; + + /* + * kmap's are initially in reverse order so rearrange them. + */ + i = (n+(BY2PG-1))/BY2PG; + va = 0; + for(j=i-1; j>=0; j--){ + k = kmappa(pa+j*BY2PG, flag); + if(va && va != k->va+BY2PG) + systemreset(); + va = k->va; + } + return va; +} + KMap* kmap(Page *pg) { diff --git a/ss/screen.c b/ss/screen.c index 8c3d601c11ad81e2e33659d194325f65fe0cc922..ba4274dc5a94de9e4ee3796eeaebffea739a2641 100644 --- a/ss/screen.c +++ b/ss/screen.c @@ -26,24 +26,27 @@ GBitmap gscreen; struct screens { - ulong type; + char *type; int x; int y; int ld; }screens[] = { - { 0xFE010104, 1152, 900, 0 }, + { "bwtwo", 1152, 900, 0 }, + { "cgsix", 1152, 900, 3 }, + { "cgthree", 1152, 900, 3 }, 0 }; Lock screenlock; void -screeninit(void) +screeninit(char *str) { struct screens *s; + ulong n; for(s=screens; s->type; s++) - if(s->type == conf.monitor) + if(strcmp(s->type, str) == 0) goto found; /* default is 0th element of table */ if(conf.monitor){ @@ -54,9 +57,10 @@ screeninit(void) return; found: - gscreen.base = (ulong*)SCREENSEGM; gscreen.zero = 0; - gscreen.width = (s->x<ld)/32; + gscreen.width = (s->x<ld)/(8*sizeof(ulong)); + n = sizeof(ulong) * gscreen.width * s->y; + gscreen.base = (ulong*)kmapregion(DISPLAYRAM, n, PTENOCACHE|PTEIO); gscreen.ldepth = s->ld; gscreen.r = Rect(0, 0, s->x, s->y); gscreen.clipr = gscreen.r; diff --git a/ss/scsi.c b/ss/scsi.c index 30a44667ae829a7999b9b620920979612e0fc4de..4c2c8b0410626934a09410f85ebbe97ae6d0a0b8 100644 --- a/ss/scsi.c +++ b/ss/scsi.c @@ -89,7 +89,9 @@ resetscsi(void) dma = ioaddr.dma; dev->cmd = Reset; - dev->cmd = Nop; + dev->cmd = Dma|Nop; /* 2 are necessary */ + dev->cmd = Dma|Nop; + dev->countlo = 0; dev->counthi = 0; dev->timeout = 146; @@ -106,7 +108,6 @@ resetscsi(void) dmatype = (dma->csr>>28) & 0xF; putenab(getenab()|ENABDMA); /**/ -print("scsi config #%2.2ux\n", dev->config); } void