123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- /*
- * arm co-processors
- * CP15 (system control) is the one that gets used the most in practice.
- */
- #include "u.h"
- #include "../port/lib.h"
- #include "mem.h"
- #include "dat.h"
- #include "fns.h"
- #include "io.h"
- #include "arm.h"
- #define MAP2PCSPACE(va, pc) ((uintptr)(va) & ~KSEGM | (pc) & KSEGM)
- enum {
- /* alternates: 0xe12fff1e BX (R14); last e is R14 */
- /* 0xe28ef000 B 0(R14); second e is R14 (ken) */
- Retinst = 0xe1a0f00e, /* MOV R14, R15 */
- };
- void
- cpwr(int cp, int op1, int crn, int crm, int op2, ulong val)
- {
- int s;
- volatile ulong instr[2];
- void *pcaddr;
- void (*fp)(ulong);
- s = splhi();
- op1 &= 7;
- op2 &= 7;
- crn &= 017;
- crm &= 017;
- cp &= 017;
- /* MCR. Rt will be R0. */
- instr[0] = 0xee000010 |
- op1 << 21 | crn << 16 | cp << 8 | op2 << 5 | crm;
- instr[1] = Retinst;
- coherence();
- pcaddr = (void *)MAP2PCSPACE(instr, getcallerpc(&cp));
- cachedwbse(pcaddr, sizeof instr);
- cacheiinv();
- fp = (void (*)(ulong))pcaddr;
- (*fp)(val);
- coherence();
- splx(s);
- }
- void
- cpwrsc(int op1, int crn, int crm, int op2, ulong val)
- {
- cpwr(CpSC, op1, crn, crm, op2, val);
- }
- ulong
- cprd(int cp, int op1, int crn, int crm, int op2)
- {
- int s;
- ulong res;
- volatile ulong instr[2];
- void *pcaddr;
- ulong (*fp)(void);
- s = splhi();
- op1 &= 7;
- op2 &= 7;
- crn &= 017;
- crm &= 017;
- /*
- * MRC. return value will be in R0, which is convenient.
- * Rt will be R0.
- */
- instr[0] = 0xee100010 |
- op1 << 21 | crn << 16 | cp << 8 | op2 << 5 | crm;
- instr[1] = Retinst;
- coherence();
- pcaddr = (void *)MAP2PCSPACE(instr, getcallerpc(&cp));
- cachedwbse(pcaddr, sizeof instr);
- cacheiinv();
- fp = (ulong (*)(void))pcaddr;
- res = (*fp)();
- splx(s);
- return res;
- }
- ulong
- cprdsc(int op1, int crn, int crm, int op2)
- {
- return cprd(CpSC, op1, crn, crm, op2);
- }
- /* floating point */
- ulong
- fprd(int fpreg)
- {
- int s;
- ulong res;
- volatile ulong instr[2];
- void *pcaddr;
- ulong (*fp)(void);
- s = splhi();
- fpreg &= 017;
- /*
- * VMRS. return value will be in R0, which is convenient.
- * Rt will be R0.
- */
- instr[0] = 0xeef00a10 | fpreg << 16 | 0 << 12;
- instr[1] = Retinst;
- coherence();
- pcaddr = (void *)MAP2PCSPACE(instr, getcallerpc(&fpreg));
- cachedwbse(pcaddr, sizeof instr);
- cacheiinv();
- fp = (ulong (*)(void))pcaddr;
- res = (*fp)();
- splx(s);
- return res;
- }
- void
- fpwr(int fpreg, ulong val)
- {
- int s;
- volatile ulong instr[2];
- void *pcaddr;
- void (*fp)(ulong);
- s = splhi();
- fpreg &= 017;
- /* VMSR. Rt will be R0. */
- instr[0] = 0xeee00a10 | fpreg << 16 | 0 << 12;
- instr[1] = Retinst;
- coherence();
- pcaddr = (void *)MAP2PCSPACE(instr, getcallerpc(&fpreg));
- cachedwbse(pcaddr, sizeof instr);
- cacheiinv();
- fp = (void (*)(ulong))pcaddr;
- (*fp)(val);
- coherence();
- splx(s);
- }
|