aboutsummaryrefslogtreecommitdiff
path: root/src/libmach/regs.c
blob: cdab6108d5ec76b5eb3d4d7aed9beb430470af31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <u.h>
#include <libc.h>
#include <mach.h>

Regdesc*
regdesc(char *name)
{
	Regdesc *r;

	for(r=mach->reglist; r->name; r++)
		if(strcmp(r->name, name) == 0)
			return r;
	return nil;
}

int
rput(Regs *regs, char *name, u64int u)
{
	if(regs == nil){
		werrstr("registers not mapped");
		return -1;
	}
	return regs->rw(regs, name, &u, 0);
}

int
rget(Regs *regs, char *name, u64int *u)
{
	if(regs == nil){
		*u = ~(u64int)0;
		werrstr("registers not mapped");
		return -1;
	}
	return regs->rw(regs, name, u, 1);
}

int
_uregrw(Regs *regs, char *name, u64int *u, int isr)
{
	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':
		*u = mach->swap4(*(u32int*)ureg);
		return 0;
	case 'Y':
		*u = mach->swap8(*(u64int*)ureg);
		return 0;
	}
}