plan9port/src/libmach/regs.c

60 lines
855 B
C
Raw Normal View History

2004-04-19 19:29:25 +00:00
#include <u.h>
#include <libc.h>
#include <mach.h>
2005-01-07 04:02:28 +00:00
Regdesc*
regdesc(char *name)
{
Regdesc *r;
for(r=mach->reglist; r->name; r++)
if(strcmp(r->name, name) == 0)
return r;
return nil;
}
2004-04-19 19:29:25 +00:00
int
2004-06-11 12:52:08 +00:00
rput(Regs *regs, char *name, ulong u)
2004-04-19 19:29:25 +00:00
{
if(regs == nil){
werrstr("registers not mapped");
return -1;
}
return regs->rw(regs, name, &u, 0);
}
int
2004-06-11 12:52:08 +00:00
rget(Regs *regs, char *name, ulong *u)
2004-04-19 19:29:25 +00:00
{
if(regs == nil){
*u = ~(ulong)0;
werrstr("registers not mapped");
return -1;
}
return regs->rw(regs, name, u, 1);
}
int
2004-06-11 12:52:08 +00:00
_uregrw(Regs *regs, char *name, ulong *u, int isr)
2004-04-19 19:29:25 +00:00
{
Regdesc *r;
uchar *ureg;
if(!isr){
werrstr("cannot write registers");
return -1;
}
if((r = regdesc(name)) == nil)
return -1;
ureg = ((UregRegs*)regs)->ureg + r->offset;
switch(r->format){
default:
case 'X':
2004-06-11 12:52:08 +00:00
*u = mach->swap4(*(u32int*)ureg);
2004-04-19 19:29:25 +00:00
return 0;
}
}