From 053dbeba5918b1ef5e5e7ed947208a45df4d7b22 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Wed, 6 Sep 2000 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2000-09-06 --- bitsy/devuart.c | 5 +- bitsy/fns.h | 8 ++- bitsy/io.h | 4 +- bitsy/l.s | 12 +++- bitsy/main.c | 3 +- bitsy/mem.h | 147 +++++++++++++++++++++++++++++++++++++++-------- bitsy/mmu.c | 44 ++++++++++++++ pc/sd53c8xx.c | 12 +--- pc/sdmylex.c | 14 +---- pc/vgamach64xx.c | 2 + 10 files changed, 192 insertions(+), 59 deletions(-) diff --git a/bitsy/devuart.c b/bitsy/devuart.c index efcff9fda892b8c1a9b8a004c345d9bf94e02940..0b6b1592cddc8158a09e92ece1d4f869710b4739 100644 --- a/bitsy/devuart.c +++ b/bitsy/devuart.c @@ -28,7 +28,8 @@ struct Uartregs ulong status0; ulong status1; }; -#define UART3REGS IOA(Uartregs, 0x50000) + +static Uartregs *uart3regs = UART3REGS; /* ctl0 bits */ enum @@ -497,7 +498,7 @@ serialputs(char *str, int n) { Uartregs *ur; - ur = UART3REGS; + ur = uart3regs; while(n-- > 0){ /* wait for output ready */ while((ur->status1 & XmitNotFull) == 0) diff --git a/bitsy/fns.h b/bitsy/fns.h index 6c78164d4ad0006202f9cd7763408d4b49074012..cc95eb0481e6cc0566d9a2fdc578c7daa4128a91 100644 --- a/bitsy/fns.h +++ b/bitsy/fns.h @@ -8,6 +8,8 @@ void clockintrsched(void); void (*coherence)(void); void delay(int); void evenaddr(ulong); +ulong getfar(void); +ulong getfsr(void); #define getpgcolor(a) 0 void idle(void); #define idlehands() /* nothing to do in the runproc */ @@ -17,7 +19,9 @@ void mmuinit(void); #define procrestore(p) void procsave(Proc*); void procsetup(Proc*); -void putuartstr(char*); +void putdac(ulong); +void putttb(ulong); +void putpid(ulong); void screeninit(void); int screenprint(char*, ...); /* debugging */ void (*screenputs)(char*, int); @@ -29,6 +33,6 @@ void wbflush(void); #define waserror() (up->nerrlab++, setlabel(&up->errlab[up->nerrlab-1])) #define KADDR(a) ((void*)((ulong)(a)|KZERO)) -#define PADDR(a) ((ulong)(a)&~KZERO) +#define PADDR(a) ((ulong)(a)) #define dcflush(a, b) diff --git a/bitsy/io.h b/bitsy/io.h index 6f32142dfbe829652e5aaecfc82c053bdbefba3f..827cf09ebe2866f9523df0ec251f6bfcef1850fa 100644 --- a/bitsy/io.h +++ b/bitsy/io.h @@ -1,5 +1,3 @@ /* - * all register offsets are relative to 0x8000000 so that - * IOZERO can be changed at some future point + * Definitions for IO devices. Used only in C. */ -#define IOA(t, x) ((t*)(IOZERO|x)) diff --git a/bitsy/l.s b/bitsy/l.s index a505fbb64e94b96b40c32f0a949e96a6e6082857..433f40e25a0f281c20526e47b93cf6639430d006 100644 --- a/bitsy/l.s +++ b/bitsy/l.s @@ -1,6 +1,4 @@ #include "mem.h" -#include "sa1110.h" -#include "io.h" /* * Entered here from Compaq's bootldr with MMU disabled. @@ -87,9 +85,17 @@ TEXT getfar(SB), $-4 RET /* set the translation table base */ -TEXT setttb(SB), $-4 +TEXT putttb(SB), $-4 MCR CpMMU, 0, R0, C(CpTTB), C(0x0) +/* set the translation table base */ +TEXT putdac(SB), $-4 + MCR CpMMU, 0, R0, C(CpDAC), C(0x0) + +/* set the translation table base */ +TEXT putpid(SB), $-4 + MCR CpMMU, 0, R0, C(CpPID), C(0x0) + /* * set the stack value for the mode passed in R0 */ diff --git a/bitsy/main.c b/bitsy/main.c index 0135a1d23013aacfc9239105966c9ad5c52f60b4..d2a0d63f9bbebc277bf742ac83906301b18511f3 100644 --- a/bitsy/main.c +++ b/bitsy/main.c @@ -8,8 +8,6 @@ #include "init.h" #include "pool.h" -#include "sa1110.h" - Mach *m; Conf conf; @@ -18,6 +16,7 @@ main(void) { iprint("bitsy kernel\n"); confinit(); + xinit(); mmuinit(); } diff --git a/bitsy/mem.h b/bitsy/mem.h index d5c81f3c01eb304b56116699f8c71fba456efe4f..b66513dcd7382f41a3246735f3f62c8f4459d82a 100644 --- a/bitsy/mem.h +++ b/bitsy/mem.h @@ -28,34 +28,30 @@ #define MS2TK(t) ((((ulong)(t))*HZ)/1000) /* milliseconds to ticks */ /* - * Fundamental addresses - */ -#define MACHADDR (KZERO+0x00001000) - -/* - * Address spaces: + * Virtual addresses: + * + * We direct map all discovered DRAM and the area twixt 0xe0000000 and + * 0xe8000000 used to provide zeros for cache flushing. * - * We've direct mapped the DRAM's and all the - * special use space. Since the DRAM's lie at - * 0xc0000000 and since the Compaq boot loader - * copies the kernel to the start of DRAM, we've - * made KZERO 0xc0000000. We've also direct mapped - * the special use io space between 0x8000000 and KZERO. - * That means we can leave the MMU off till we're pretty - * far into the boot. + * Flash is mapped to 0xb0000000 and special registers are mapped + * on demand to areas starting at 0xa0000000. * - * Both these decisions can be changed by putting an MMU setup in - * l.s and changing the definitions below. + * The direct mapping is convenient but not necessary. It means + * that we don't have to turn on the MMU till well into the + * kernel. This can be changed by providing a mapping in l.s + * before calling main. */ #define UZERO 0 /* base of user address space */ #define UTZERO (UZERO+BY2PG) /* first address in user text */ #define KZERO 0xC0000000 /* base of kernel address space */ #define KTZERO 0xC0008000 /* first address in kernel text */ -#define IOZERO 0x80000000 /* 1 gig of special regs */ -#define USTKTOP (IOZERO-BY2PG) /* byte just beyond user stack */ +#define REGZERO 0xA0000000 /* 256 meg for special regs */ +#define FLASHZERO 0xB0000000 /* 256 meg for flash */ +#define USTKTOP (REGZERO-BY2PG) /* byte just beyond user stack */ #define USTKSIZE (16*1024*1024) /* size of user stack */ #define TSTKTOP (USTKTOP-USTKSIZE) /* end of new stack in sysexec */ #define TSTKSIZ 100 +#define MACHADDR (KZERO+0x00001000) #define KSTACK (16*1024) /* Size of kernel stack */ @@ -69,10 +65,115 @@ #define PPN(x) ((x)&~(BY2PG-1)) /* - * physical MMU + * SA1110 definitions + */ + +/* + * memory physical addresses + */ +#define PHYSFLASH0 0x00000000 +#define PHYSDRAM0 0xC0000000 +#define PHYSNULL0 0xE0000000 + +/* + * peripheral control module physical addresses + */ +#define LCDREGS 0xB0100000 /* display */ +#define USBREGS 0x80000000 /* serial port 0 - USB */ +#define UART1REGS 0x80010000 /* serial port 1 - UART */ +#define GPCLKREGS 0x80020060 /* serial port 1 - general purpose clock */ +#define UART2REGS 0x80030000 /* serial port 2 - low speed IR */ +#define HSSPREGS 0x80040060 /* serial port 2 - high speed IR */ +#define UART3REGS 0x80050000 /* serial port 3 - RS232 UART */ +#define MCPREGS 0x80060000 /* serial port 4 - multimedia comm port */ +#define SSPREGS 0x80070060 /* serial port 4 - synchronous serial port */ +#define PPCREGS 0x90060000 /* peripheral pin controller */ +#define GPIOREGS 0x90040000 /* 28 general purpose IO pins */ + +/* + * Program Status Registers + */ +#define PsrMusr 0x00000010 /* mode */ +#define PsrMfiq 0x00000011 +#define PsrMirq 0x00000012 +#define PsrMsvc 0x00000013 +#define PsrMabt 0x00000017 +#define PsrMund 0x0000001B +#define PsrMask 0x0000001F + +#define PsrDfiq 0x00000040 /* disable FIQ interrupts */ +#define PsrDirq 0x00000080 /* disable IRQ interrupts */ + +#define PsrV 0x10000000 /* overflow */ +#define PsrC 0x20000000 /* carry/borrow/extend */ +#define PsrZ 0x40000000 /* zero */ +#define PsrN 0x80000000 /* negative/less than */ + +/* + * Coprocessors + */ +#define CpMMU 15 + +/* + * Internal MMU coprocessor registers + */ +#define CpCPUID 0 /* R: */ +#define CpControl 1 /* R: */ +#define CpTTB 2 /* RW: translation table base */ +#define CpDAC 3 /* RW: domain access control */ +#define CpFSR 5 /* RW: fault status */ +#define CpFAR 6 /* RW: fault address */ +#define CpCacheFlush 7 /* W: cache flushing, wb draining*/ +#define CpTLBFlush 8 /* W: TLB flushing */ +#define CpRBFlush 9 /* W: Read Buffer ops */ +#define CpPID 13 /* RW: PID for virtual mapping */ +#define CpBpt 14 /* W: Breakpoint register */ +#define CpTest 15 /* W: Test, CLock and Idle Control */ + +/* + * CpControl */ -#define PTEVALID 0 -#define PTERONLY 0 -#define PTEWRITE 0 -#define PTEUNCACHED 0 +#define CpCmmu 0x00000001 /* M: MMU enable */ +#define CpCalign 0x00000002 /* A: alignment fault enable */ +#define CpCdcache 0x00000004 /* C: data cache on */ +#define CpCwb 0x00000008 /* W: write buffer turned on */ +#define CpCi32 0x00000010 /* P: 32-bit program space */ +#define CpCd32 0x00000020 /* D: 32-bit data space */ +#define CpCbe 0x00000080 /* B: big-endian operation */ +#define CpCsystem 0x00000100 /* S: system permission */ +#define CpCrom 0x00000200 /* R: ROM permission */ +#define CpCicache 0x00001000 /* I: instruction cache on */ +#define CpCvivec 0x00002000 /* X: virtual interrupt vector adjust */ +/* + * fault codes + */ +#define FCterm 0x2 /* terminal */ +#define FCvec 0x0 /* vector */ +#define FCalignf 0x1 /* unaligned full word data access */ +#define FCalignh 0x3 /* unaligned half word data access */ +#define FCl1abort 0xc /* level 1 external abort on translation */ +#define FCl2abort 0xe /* level 2 external abort on translation */ +#define FCtransSec 0x5 /* section translation */ +#define FCtransPage 0x7 /* page translation */ +#define FCdomainSec 0x9 /* section domain */ +#define FCdomainPage 0x11 /* page domain */ +#define FCpermSec 0x9 /* section permissions */ +#define FCpermPage 0x11 /* page permissions */ +#define FCabortLFSec 0x4 /* external abort on linefetch for section */ +#define FCabortLFPage 0x6 /* external abort on linefetch for page */ +#define FCabortNLFSec 0x8 /* external abort on non-linefetch for section */ +#define FCabortNLFPage 0xa /* external abort on non-linefetch for page */ + +/* + * PTE bits used by fault.h. mmu.c translates them to real values. + */ +#define PTEVALID (1<<0) +#define PTERONLY 0 /* this is implied by the absence of PTEWRITE */ +#define PTEWRITE (1<<1) +#define PTEUNCACHED (1<<2) + +/* + * H3650 specific definitions + */ +#define EGPIOREGS 0x49000000 /* Additional GPIO register */ diff --git a/bitsy/mmu.c b/bitsy/mmu.c index 0b29eb3f5f3bfad63955d04d66f77e2129d41da7..f849da4367bd3105743f8a89498ba9696a0162c9 100644 --- a/bitsy/mmu.c +++ b/bitsy/mmu.c @@ -7,9 +7,53 @@ #include "ureg.h" #include "../port/error.h" +/* real protection bits */ +enum +{ + Small_Page= (2<<0), + Large_Page= (1<<0), + Cached= (1<<3), + Buffered= (1<<2), + UserRO= (0xAA<<4), + UserRW= (0xFF<<4), + KernelRW= (0x55<<4), +}; + + +/* + * table to map fault.c bits to physical bits + */ +static ulong phystrans[8] = +{ + [PTEVALID] Small_Page|Cached|Buffered|UserRO, + [PTEVALID|PTEWRITE] Small_Page|Cached|Buffered|UserRW, + [PTEVALID|UNCACHED] Small_Page|UserRO, + [PTEVALID|UNCACHED|PTEWRITE] Small_Page|UserRW, +}; + +ulong *l1page; + +/* + * We map all of memory, flash, and the zeros area with sections. + * Special use space is mapped on the fly with regmap. + */ void mmuinit(void) { + ulong a, e; + + /* set up the domain register to cause all domains to obey pte access bits */ + putdac(0x55555555); + + /* get a prototype level 1 page */ + l1page = xspanalloc(BY2PG, 16*1024, 0); + memset(l1page, 0, BY2PG); + + /* map DRAM */ + e = PHYSDRAM0 + BY2PG*con + for( + /* map zeros */ + /* map flash */ } void diff --git a/pc/sd53c8xx.c b/pc/sd53c8xx.c index d1c23f3a57048714b19753921fbc320421cc7f7d..0255afd71dab093c0ea5554aa8992298287842a4 100644 --- a/pc/sd53c8xx.c +++ b/pc/sd53c8xx.c @@ -1732,19 +1732,9 @@ docheck: while(waserror()) ; - tsleep(d, done, d, 30 * 1000); + sleep(d, done, d); poperror(); - if (!done(d)) { - KPRINT(PRINTPREFIX "%d/%d: exec: Timed out\n", target, r->lun); - dumpncrregs(c, 0); - dsafree(c, d); - reset(c); - qunlock(&c->q[target]); - r->status = SDtimeout; - return r->status = SDtimeout; /* assign */ - } - if((status = d->p9status) == SDeio) c->s[target] = NeitherDone; if (d->parityerror) { diff --git a/pc/sdmylex.c b/pc/sdmylex.c index 44a5ad10cdbc84f54a47551af39b14deda9f4740..c9ff5c320fa2db542a9558eadac0a74acbdf892e 100644 --- a/pc/sdmylex.c +++ b/pc/sdmylex.c @@ -409,21 +409,9 @@ mylex24rio(SDreq* r) */ while(waserror()) ; - tsleep(ccb, done24, ccb, 30*1000); + sleep(ccb, done24, ccb); poperror(); - if(!done24(ccb)){ - print("%s: %d/%d: sd24rio timeout\n", - ctlr->sdev->name, target, r->lun); - if(ccb->data != nil){ - free(data); - ccb->data = nil; - } - ccbfree(ctlr, (Ccb*)ccb); - - return SDtimeout; - } - /* * Save the status and patch up the number of * bytes actually transferred. diff --git a/pc/vgamach64xx.c b/pc/vgamach64xx.c index baf50841de039d30db127e74e71ffe3c316691a8..77fdb48874df3ea492e39ea3280a50b946cce05e 100644 --- a/pc/vgamach64xx.c +++ b/pc/vgamach64xx.c @@ -21,6 +21,7 @@ static ushort mach64xxdid[] = { ('G'<<8)|'B', ('G'<<8)|'D', ('G'<<8)|'I', + ('G'<<8)|'M', ('G'<<8)|'P', ('G'<<8)|'Q', ('G'<<8)|'T', @@ -799,3 +800,4 @@ VGAcur vgamach64xxcur = { 1 /* doespanning */ }; +