3 * mainly to cope with arm hard-wiring register numbers into instructions.
5 * CP15 (system control) is the one that gets used the most in practice.
7 * these routines must be callable from KZERO.
9 * on a multiprocessor, process switching to another cpu is assumed
10 * to be inhibited by the caller as these registers are local to the cpu.
13 #include "../port/lib.h"
22 /* alternates: 0xe12fff1e BX (R14); last e is R14 */
23 /* 0xe28ef000 B 0(R14); second e is R14 (ken) */
24 Retinst = 0xe1a0f00e, /* MOV R14, R15 */
33 static ulong ib[256], *ep[MAXMACH+1];
38 for(ip = ib; ip < ie; ip += 2)
44 for(; ip < ie; ip += 2)
47 if(ip >= &ib[nelem(ib)])
48 panic("mkinstr: out of instrucuction buffer");
51 ep[MAXMACH] = ie = ip + 2;
52 cachedwbse(ip, 2*sizeof(*ip));
62 setupcpop(ulong opcode, int cp, int op1, int crn, int crm,
70 return mkinstr(opcode | op1 << 21 | crn << 16 | cp << 8 | op2 << 5 | crm);
74 cprd(int cp, int op1, int crn, int crm, int op2)
77 * MRC. return value will be in R0, which is convenient.
80 ulong (*fp)(void) = setupcpop(0xee100010, cp, op1, crn, crm, op2);
85 cpwr(int cp, int op1, int crn, int crm, int op2, ulong val)
88 void (*fp)(ulong) = setupcpop(0xee000010, cp, op1, crn, crm, op2);
93 cprdsc(int op1, int crn, int crm, int op2)
95 return cprd(CpSC, op1, crn, crm, op2);
99 cpwrsc(int op1, int crn, int crm, int op2, ulong val)
101 cpwr(CpSC, op1, crn, crm, op2, val);
106 /* fp coproc control */
108 setupfpctlop(int opcode, int fpctlreg)
110 fpctlreg &= Nfpctlregs - 1;
111 return mkinstr(opcode | fpctlreg << 16 | 0 << 12 | CpFP << 8);
118 * VMRS. return value will be in R0, which is convenient.
121 ulong (*fp)(void) = setupfpctlop(0xeef00010, fpreg);
126 fpwr(int fpreg, ulong val)
129 * fpu might be off and this VMSR might enable it
132 void (*fp)(ulong) = setupfpctlop(0xeee00010, fpreg);
136 /* fp register access; don't bother with single precision */
138 setupfpop(int opcode, int fpreg)
140 ulong wd = opcode | 0 << 16 | (fpreg & (16 - 1)) << 12;
142 wd |= 1 << 22; /* high bit of dfp reg # */
147 fpsavereg(int fpreg, uvlong *fpp)
150 * VSTR. pointer will be in R0, which is convenient.
153 ulong (*fp)(uvlong *) = setupfpop(0xed000000 | CpDFP << 8, fpreg);
158 fprestreg(int fpreg, uvlong val)
161 void (*fp)(uvlong *) = setupfpop(0xed100000 | CpDFP << 8, fpreg);