/*
* arm co-processors
* mainly to cope with arm hard-wiring register numbers into instructions.
*
* CP15 (system control) is the one that gets used the most in practice.
* these routines must be callable from KZERO space or the 0 segment.
*/
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "io.h"
#include "arm.h"
enum {
/* alternates: 0xe12fff1e BX (R14); last e is R14 */
/* 0xe28ef000 B 0(R14); second e is R14 (ken) */
Retinst = 0xe1a0f00e, /* MOV R14, R15 */
ulong
cprd(int cp, int op1, int crn, int crm, int op2)
{
int s, r;
volatile ulong instr[2];
Pufv fp;
s = splhi();
/*
* MRC. return value will be in R0, which is convenient.
* Rt will be R0.
*/
setupcpop(instr, 0xee100010, cp, op1, crn, crm, op2);
fp = (Pufv)instr;
r = fp();
splx(s);
return r;
}
void
cpwr(int cp, int op1, int crn, int crm, int op2, ulong val)
{
int s;
volatile ulong instr[2];
Pvfu fp;
if (!m->fpon) {
dumpstack();
panic("fprd: cpu%d fpu off", m->machno);
}
s = splhi();
/*
* VMRS. return value will be in R0, which is convenient.
* Rt will be R0.
*/
setupfpctlop(instr, 0xeef00010, fpreg);
fp = (Pufv)instr;
r = fp();
splx(s);
return r;
}
/* fpu might be off and this VMSR might enable it */
s = splhi();
setupfpctlop(instr, 0xeee00010, fpreg); /* VMSR, Rt is R0 */
fp = (Pvfu)instr;
fp(val);
coherence();
splx(s);
}
/* fp register access; don't bother with single precision */
static void
setupfpop(ulong instr[2], int opcode, int fpreg)
{
ulong instrsz[2];
instr[0] = opcode | 0 << 16 | (fpreg & (16 - 1)) << 12;
if (fpreg >= 16)
instr[0] |= 1 << 22; /* high bit of dfp reg # */
instr[1] = Retinst;
if (!m->fpon)
panic("fpsavereg: cpu%d fpu off", m->machno);
s = splhi();
/*
* VSTR. pointer will be in R0, which is convenient.
* Rt will be R0.
*/
setupfpop(instr, 0xed000000 | CpDFP << 8, fpreg);
fp = (ulong (*)(uvlong *))instr;
r = fp(fpp);
splx(s);
coherence();
return r; /* not too meaningful */
}