1 #include "u.h" 2 #include "../port/lib.h" 3 #include "mem.h" 4 #include "dat.h" 5 #include "fns.h" 6 7 /* 8 * we pre-compile an array of get/putdcr functions, 9 * later indexed by DCR number by getdcr and putdcr in l.s, 10 * because the DCR number is part of the instruction, 11 * and cannot be read from a register 12 */ 13 14 #define MAXDCR 0x500 15 16 #define DCRF(n) ((((n)>>5)&0x1F)|(((n)&0x1F)<<5)) 17 #define MTDCR(s,n) ((31<<26)|((s)<<21)|(DCRF(n)<<11)|(451<<1)) 18 #define MFDCR(n,t) ((31<<26)|((t)<<21)|(DCRF(n)<<11)|(323<<1)) 19 #define RETURN 0x4e800020 /* BR (LR) */ 20 21 ulong _getdcr[MAXDCR][2]; 22 ulong _putdcr[MAXDCR][2]; 23 24 void dcrcompile(void)25dcrcompile(void) 26 { 27 ulong *p; 28 int i; 29 30 for(i=0; i<MAXDCR; i++){ 31 p = _getdcr[i]; 32 p[0] = MFDCR(i, 3); 33 p[1] = RETURN; 34 p = _putdcr[i]; 35 p[0] = MTDCR(3, i); 36 p[1] = RETURN; 37 } 38 dcflush(PTR2UINT(_getdcr), sizeof(_getdcr)); 39 dcflush(PTR2UINT(_putdcr), sizeof(_putdcr)); 40 /* no need to flush icache since they won't be there */ 41 } 42