From 533c8fde8ba8496ebd67e72bca9b983a026d6666 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 15 Aug 2001 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2001-08-15 --- bitsy/devpcmcia.c | 2 + bitsy/fns.h | 1 + bitsy/l.s | 49 ++++++++++++++--------- bitsy/mmu.c | 2 +- bitsy/power.c | 99 ++++++++++++++++++++++++++++++++++++----------- 5 files changed, 111 insertions(+), 42 deletions(-) diff --git a/bitsy/devpcmcia.c b/bitsy/devpcmcia.c index aa8e744b3fd7f721b99e234e3a9e1c0a5ce3e839..036af58a9810b001bbec36116cf03ed245b45d16 100644 --- a/bitsy/devpcmcia.c +++ b/bitsy/devpcmcia.c @@ -495,6 +495,7 @@ slotmap(int slotno, ulong regs, ulong attr, ulong mem) sp->regs = mapspecial(regs, 32*1024); } + PCMmap* pcmmap(int slotno, ulong, int, int attr) { @@ -505,6 +506,7 @@ pcmmap(int slotno, ulong, int, int attr) else return &slot[slotno].memmap; } + void pcmunmap(int, PCMmap*) { diff --git a/bitsy/fns.h b/bitsy/fns.h index ed33918d5914d7c9fa256c7631f05fb601646008..f6b6edcb2c99eb255751e9052520f1fccdd7dd72 100644 --- a/bitsy/fns.h +++ b/bitsy/fns.h @@ -23,6 +23,7 @@ void (*doze)(void); void egpiobits(ulong, int); void evenaddr(ulong); void exppackpower(int); +ulong findva(ulong, ulong, ulong); void flashprogpower(int); void flushmmu(void); int fpiarm(Ureg *ur); diff --git a/bitsy/l.s b/bitsy/l.s index 365f135d52b9d8dab0f63afd123c4f6a076d214f..1475bebe9843a9ee4c90fa995e2a91f4f2c08819 100644 --- a/bitsy/l.s +++ b/bitsy/l.s @@ -563,15 +563,6 @@ TEXT sa1100_power_resume(SB), $-4 /* SVC mode, interrupts disabled */ MOVW $(PsrDirq|PsrDfiq|PsrMsvc), R1 MOVW R1, CPSR - /* flush caches */ - MCR CpMMU, 0, R0, C(CpCacheFlush), C(0x7), 0 - /* drain prefetch */ - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - MOVW R0,R0 - /* drain write buffer */ - MCR CpMMU, 0, R0, C(CpCacheFlush), C(0xa), 4 /* gotopowerlabel() */ /* svc */ @@ -581,23 +572,45 @@ TEXT sa1100_power_resume(SB), $-4 MOVW R1, SPSR MOVW R2, CPSR /* copro */ - MOVW 148(R0), R3 - MCR CpMMU, 0, R3, C(CpTTB), C(0x0) + /* flush caches */ + MCR CpMMU, 0, R0, C(CpCacheFlush), C(0x7), 0 + /* drain prefetch */ + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + /* drain write buffer */ + MCR CpMMU, 0, R0, C(CpCacheFlush), C(0xa), 4 + MCR CpMMU, 0, R0, C(CpTLBFlush), C(0x7) MOVW 144(R0), R3 MCR CpMMU, 0, R3, C(CpDAC), C(0x0) - MOVW 152(R0), R3 - MCR CpMMU, 0, R3, C(CpControl), C(0x0) /* Enable cache */ - MOVW R0, R0 - MOVW R0, R0 - MOVW R0, R0 - MOVW R0, R0 + MOVW 148(R0), R3 + MCR CpMMU, 0, R3, C(CpTTB), C(0x0) MOVW 156(R0), R3 MCR CpMMU, 0, R3, C(CpFSR), C(0x0) MOVW 160(R0), R3 MCR CpMMU, 0, R3, C(CpFAR), C(0x0) MOVW 164(R0), R3 MCR CpMMU, 0, R3, C(CpPID), C(0x0) - MCR CpMMU, 0, R0, C(CpTLBFlush), C(0x7) + MOVW 152(R0), R3 + MCR CpMMU, 0, R3, C(CpControl), C(0x0) /* Enable cache */ + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + /* flush i&d caches */ + MCR CpMMU, 0, R0, C(CpCacheFlush), C(0x7), 0 + /* drain prefetch */ + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + /* flush tlb */ + MCR CpMMU, 0, R0, C(CpTLBFlush), C(0x7), 0 + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 + MOVW R0,R0 /* irq */ BIC $(PsrMask), R2, R3 ORR $(PsrDirq|PsrMirq), R3 diff --git a/bitsy/mmu.c b/bitsy/mmu.c index d6af78c3944f61b8eaad6a2075ac07d5f0ce8cf1..23839f00a76b8c33945f3d8a20f4aabbb9b1577c 100644 --- a/bitsy/mmu.c +++ b/bitsy/mmu.c @@ -260,7 +260,7 @@ mmu_paddr(ulong va) } /* map a physical address to a virtual one */ -static ulong +ulong findva(ulong pa, ulong zero, ulong top) { int i; diff --git a/bitsy/power.c b/bitsy/power.c index 4f3b8adfeafd40950f61c3daf3b35d15747a23db..8ef97a0cb5a5f570f80f9eb0df0f92c5cb751122 100644 --- a/bitsy/power.c +++ b/bitsy/power.c @@ -27,9 +27,62 @@ Intrregs savedintrregs; #define R(p) ((Uartregs*)((p)->regs)) +uchar *savedtext; + +static void +checkflash(void) +{ + ulong *p; + ulong s; + + s = 0; + for (p = (ulong*)FLASHZERO; p < (ulong*)(FLASHZERO+8*1024*1024); p++) + s += *p; + iprint("flash checksum is 0x%lux\n", s); +} + +static void +checkpagetab(void) +{ + extern ulong l1table; + ulong *p; + ulong s; + + s = 0; + for (p = (ulong*)l1table; p < (ulong*)(l1table+16*1024); p++) + s += *p; + iprint("page table checksum is 0x%lux\n", s); +} + +static void +checkktext(void) +{ + /* check the kernel text */ + ulong *p, *q; + ulong s; + + s = 0; + if (savedtext == nil){ + savedtext=malloc((ulong)etext-(ulong)_start); + if (savedtext == nil) + iprint("can't malloc savedtext\n"); + memmove(savedtext, _start, (ulong)etext-(ulong)_start); + }else{ + for (p = (ulong*)_start, q = (ulong*)savedtext; p < (ulong*)(etext); p++,q++) { + if (*p != *q) { + iprint("0x%lux: 0x%lux != 0x%lux\n", p, *p, *q); + s++; + } + } + if (s == 0) iprint("ktext ok\n"); + } +} + static void dumpitall(void) { + extern ulong l1table; + iprint("intr: icip %lux iclr %lux iccr %lux icmr %lux\n", intrregs->icip, intrregs->iclr, intrregs->iccr, intrregs->icmr ); @@ -51,11 +104,15 @@ dumpitall(void) iprint("dram: mdcnfg msc %lux %lux %lux mecr %lux\n", memconfregs->msc0, memconfregs->msc1,memconfregs->msc2, memconfregs->mecr); - iprint("mmu: CpControl %lux CpTTB %lux CpDAC %lux\n", - getcontrol(), getttb(), getdac()); + iprint("mmu: CpControl %lux CpTTB %lux CpDAC %lux l1table 0x%lux\n", + getcontrol(), getttb(), getdac(), l1table); iprint("powerregs: pmcr %lux pssr %lux pcfr %lux ppcr %lux pwer %lux pspr %lux pgsr %lux posr %lux\n", powerregs->pmcr, powerregs->pssr, powerregs->pcfr, powerregs->ppcr, powerregs->pwer, powerregs->pspr, powerregs->pgsr, powerregs->posr); + checkpagetab(); + checkflash(); +// checkktext(); + iprint("\n\n"); } static void @@ -111,9 +168,11 @@ sa1100_power_off(void) //sa1100_power_resume(); /* set lowest clock; delay to avoid resume hangs on fast sa1110 */ -// delay(90); -// powerregs->ppcr = 0; -// delay(90); +/* Doesn't work [sjm] + delay(90); + powerregs->ppcr = 0; + delay(90); +*/ /* set all GPIOs to input mode */ gpioregs->direction = 0; @@ -144,24 +203,16 @@ powerdown(void *) void deepsleep(void) { static int power_pl; - ulong xsp, xlink; - int i; - extern ulong l1table; + ulong xsp, xlink, mecr; + power_pl = splhi(); xlink = getcallerpc(&xlink); - iprint("l1table at 0x%8.8lux\n", l1table); - setpowerlabel(); - for (i = 0; i < 168/4; i++){ - if (i % 4 == 0) iprint("\n"); - iprint("%3d: 0x%8.8lux ", i*4, power_resume[i]); - } /* Power down */ irpower(0); audiopower(0); screenpower(0); µcpower(0); - power_pl = splhi(); - iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%lux\n\n", &xsp, xlink, power_pl); + iprint("entering suspend mode, sp = 0x%lux, pc = 0x%lux, psw = 0x%ux\n", &xsp, xlink, power_pl); dumpitall(); delay(100); uartpower(0); @@ -171,9 +222,14 @@ deepsleep(void) { intrcpy(&savedintrregs, intrregs); cacheflush(); delay(50); + mecr = memconfregs->mecr; if(setpowerlabel()){ + /* return here with mmu back on */ + /* Turn off memory auto power */ - memconfregs->mdrefr &= ~0x30000000; +// memconfregs->mdrefr &= ~0x30000000; + memconfregs->mecr = mecr; + gpiorestore(gpioregs, &savedgpioregs); delay(50); intrcpy(intrregs, &savedintrregs); @@ -183,7 +239,6 @@ deepsleep(void) { intrregs->icip = (1<r0 = 1<<0; rs232power(1); @@ -191,18 +246,16 @@ deepsleep(void) { dumpitall(); delay(100); xlink = getcallerpc(&xlink); - iprint("\nresuming execution, sp = 0x%lux, pc = 0x%lux, psw = 0x%lux\n", &xsp, xlink, splhi()); - splx(power_pl); + iprint("\nresuming execution, sp = 0x%lux, pc = 0x%lux, psw = 0x%ux\n", &xsp, xlink, splhi()); // irpower(1); // audiopower(1); µcpower(1); screenpower(1); + splx(power_pl); return; } - wbflush(); + cacheflush(); delay(50); - mmuinvalidate(); - delay(10); sa1100_power_off(); /* no return */ }