M gnot/lock.c => gnot/lock.c +3 -12
@@ 12,24 12,15 @@ lock(Lock *l)
{
int i;
- /*
- * Try the fast grab first
- */
- if(tas(&l->key) == 0){
- if(u)
- u->p->hasspin = 1;
- l->pc = ((ulong*)&l)[PCOFF];
- return;
- }
- for(i = 0; i < 100000; i++){
- if(u && u->p->state == Running)
- sched();
+ for(i = 0; i < 1000000; i++){
if (tas(&l->key) == 0){
if(u)
u->p->hasspin = 1;
l->pc = ((ulong*)&l)[PCOFF];
return;
}
+ if(u && u->p->state == Running)
+ sched();
}
i = l->key;
l->key = 0;
M gnot/mem.h => gnot/mem.h +1 -0
@@ 14,6 14,7 @@
#define PGSHIFT 13 /* log(BY2PG) */
#define PGROUND(s) (((s)+(BY2PG-1))&~(BY2PG-1))
#define ICACHESIZE 0
+#define MB4 (4*1024*1024) /* Lots of things are 4Mb in size */
#define MAXMACH 1 /* max # cpus system can run */
M gnot/mmu.c => gnot/mmu.c +9 -11
@@ 9,7 9,7 @@ struct
Lock;
int init;
KMap *free;
- KMap arena[4*1024*1024/BY2PG]; /* kernel mmu maps up to 4MB */
+ KMap arena[MB4/BY2PG]; /* kernel mmu maps up to 4MB */
}kmapalloc;
/*
@@ 120,15 120,18 @@ kmapinit(void)
if(kmapalloc.init == 0){
k = &kmapalloc.arena[0];
- k->va = KZERO|(4*1024*1024-256*1024-BY2PG);
+ k->va = KZERO|(MB4-256*1024-BY2PG);
k->next = 0;
kmapalloc.free = k;
kmapalloc.init = 1;
return;
}
- e = (4*1024*1024 - 256*1024)/BY2PG; /* screen lives at top 256K */
+
+ e = (MB4 - 256*1024)/BY2PG; /* screen lives at top 256K */
i = PGROUND(((ulong)ialloc(0, 0))&~KZERO)/BY2PG;
+
print("%lud free map registers\n", e-i);
+
kmapalloc.free = 0;
for(k=&kmapalloc.arena[i]; i<e; i++,k++){
k->va = i*BY2PG|KZERO;
@@ 140,12 143,7 @@ KMap*
kmap(Page *pg)
{
KMap *k;
- int s;
- if(u && u->p){
- s = u->p->state;
- u->p->state = MMUing;
- }
lock(&kmapalloc);
k = kmapalloc.free;
if(k == 0){
@@ 154,10 152,9 @@ kmap(Page *pg)
}
kmapalloc.free = k->next;
unlock(&kmapalloc);
+
k->pa = pg->pa;
putkmmu(k->va, PPN(k->pa) | PTEVALID | PTEKERNEL);
- if(u && u->p)
- u->p->state = s;
return k;
}
@@ 165,10 162,11 @@ void
kunmap(KMap *k)
{
k->pa = 0;
+ putkmmu(k->va, INVALIDPTE);
+
lock(&kmapalloc);
k->next = kmapalloc.free;
kmapalloc.free = k;
- putkmmu(k->va, INVALIDPTE);
unlock(&kmapalloc);
}
M gnot/trap.c => gnot/trap.c +1 -1
@@ 131,7 131,7 @@ dumpregs(Ureg *ur)
l = &ur->r0;
for(i=0; i<sizeof regname/sizeof(char*); i+=2, l+=2)
print("%s\t%.8lux\t%s\t%.8lux\n", regname[i], l[0], regname[i+1], l[1]);
- for(;;);
+
dumpstack();
}
M pc/devhard.c => pc/devhard.c +20 -20
@@ 41,11 41,11 @@ enum
Qdir= 0,
Maxxfer= 4*1024, /* maximum transfer size/cmd */
- Npart= 8+2, /* 8 sub partitions, disk, and partiiton */
+ Npart= 8+2, /* 8 sub partitions, disk, and partition */
};
-#define PART(x) ((x)&0x3)
-#define DRIVE(x) (((x)>>3)&0x7)
-#define MKQID(d,p) (((d)<<3) | (p))
+#define PART(x) ((x)&0xF)
+#define DRIVE(x) (((x)>>4)&0x7)
+#define MKQID(d,p) (((d)<<4) | (p))
/*
* ident sector from drive
@@ 166,15 166,14 @@ hardgen(Chan *c, Dirtab *tab, long ntab, long s, Dir *dirp)
return -1;
dp = &hard[drive];
- if(s < dp->npart){
- pp = &dp->p[s];
- sprint(name, "hd%d%s", drive, pp->name);
- name[NAMELEN] = 0;
- qid.path = MKQID(drive, s);
- l = (pp->end - pp->start) * dp->bytes;
- } else
+ if(s >= dp->npart)
return 0;
+ pp = &dp->p[s];
+ sprint(name, "hd%d%s", drive, pp->name);
+ name[NAMELEN] = 0;
+ qid.path = MKQID(drive, s);
+ l = (pp->end - pp->start) * dp->bytes;
devdir(c, qid, name, l, 0600, dirp);
return 1;
}
@@ 319,13 318,6 @@ hardread(Chan *c, void *a, long n)
i -= skip;
if(i > n - rv)
i = n - rv;
-{int j;
-
- print("0x%lux(%d) <- ", aa+rv, i);
- for(j = 0; j<32; j++)
- print("%.2ux ", cp->buf[j+skip]);
- print("\n");
-}
memmove(aa+rv, cp->buf + skip, i);
skip = 0;
}
@@ 482,7 474,8 @@ hardxfer(Drive *dp, Partition *pp, int cmd, long start, long len)
cp->cmd = cmd;
cp->dp = dp;
cp->sofar = 0;
-print("xfer:\ttcyl %d, tsec %d, thead %d\n", cp->tcyl, cp->tsec, cp->thead);
+ cp->status = 0;
+/*print("xfer:\ttcyl %d, tsec %d, thead %d\n", cp->tcyl, cp->tsec, cp->thead);
print("\tnsecs %d, sofar %d\n", cp->nsecs, cp->sofar);/**/
outb(cp->pbase+Pcount, cp->nsecs);
outb(cp->pbase+Psector, cp->tsec);
@@ 654,6 647,9 @@ hardintr(Ureg *ur)
Controller *cp;
Drive *dp;
long loop;
+ int x;
+
+ x = spllo(); /* let in other interrupts */
/*
* BUG!! if there is ever more than one controller, we need a way to
@@ 662,7 658,10 @@ hardintr(Ureg *ur)
cp = &hardc[0];
dp = cp->dp;
- cp->status = inb(cp->pbase+Pstatus);
+ loop = 0;
+ while((cp->status = inb(cp->pbase+Pstatus)) & Sbusy)
+ if(++loop > 10000)
+ panic("hardintr 0");
switch(cp->cmd){
case Cwrite:
if(cp->status & Serr){
@@ 673,6 672,7 @@ hardintr(Ureg *ur)
}
cp->sofar++;
if(cp->sofar < cp->nsecs){
+ loop = 0;
while((inb(cp->pbase+Pstatus) & Sdrq) == 0)
if(++loop > 10000)
panic("hardintr 1");
M pc/kbd.c => pc/kbd.c +1 -0
@@ 418,6 418,7 @@ kbdintr0(void)
}
if(esc1){
+print("\nescape1 %lux\n", c);
c = kbtabesc1[c];
esc1 = 0;
} else if(esc2){
M pc/l.s => pc/l.s +2 -0
@@ 219,6 219,7 @@ TEXT inss(SB),$0
MOVL p+0(FP),DX
MOVL a+4(FP),DI
MOVL c+8(FP),CX
+ CLD
REP; OP16; INSL
RET
@@ 229,6 230,7 @@ TEXT outss(SB),$0
MOVL p+0(FP),DX
MOVL a+4(FP),SI
MOVL c+8(FP),CX
+ CLD
REP; OP16; OUTSL
RET
M pc/main.c => pc/main.c +1 -1
@@ 175,7 175,7 @@ confinit(void)
/*
* the last 128k belongs to the roms
*/
- conf.npage1 = (i)*1024/4;
+ conf.npage1 = (i-1)*1024/4;
conf.base1 = 1024*1024;
conf.npage = conf.npage0 + conf.npage1;
M pc/mmu.c => pc/mmu.c +8 -6
@@ 102,7 102,7 @@ mmudump(void)
void
mmuinit(void)
{
- int i, n, nkpt;
+ int i, nkpt, npage, nbytes;
ulong x;
ulong y;
@@ 124,13 124,15 @@ mmuinit(void)
*/
/* allocate and fill low level page tables for kernel mem */
- nkpt = ROUNDUP(conf.npage, 4*1024);
- nkpt = nkpt/(4*1024);
- kpt = ialloc(nkpt*BY2PG, 1);
- n = ROUNDUP(conf.npage, 1024);
- for(i = 0; i < n; i++)
+ npage = (1024*1024)/BY2PG + conf.npage1;
+ nbytes = PGROUND(npage*BY2WD); /* words of page map */
+ nkpt = nbytes/BY2PG; /* pages of page map */
+ kpt = ialloc(nbytes, 1);
+ for(i = 0; i < npage; i++)
kpt[i] = (i<<PGSHIFT) | PTEVALID | PTEKERNEL | PTEWRITE;
+print("%d low level pte's, %d high level pte's\n", npage, nkpt);
+
/* allocate page table for u-> */
upt = ialloc(BY2PG, 1);
M ss/clock.c => ss/clock.c +6 -2
@@ 57,8 57,12 @@ clock(Ureg *ur)
kbdclock();
mouseclock();
if((ur->psr&SPL(0xF))==0 && p && p->state==Running){
- if(anyready())
- sched();
+ if(anyready()){
+ if(p->hasspin)
+ p->hasspin = 0;
+ else
+ sched();
+ }
if((ur->psr&PSRPSUPER) == 0){
/* *(ulong*)(USTKTOP-BY2WD) += TK2MS(1); /**/
if(u->nnote)