Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/9/teg2/devarch.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "u.h"
2
#include "../port/lib.h"
3
#include "mem.h"
4
#include "dat.h"
5
#include "fns.h"
6
#include "../port/error.h"
7
#include "io.h"
8
 
9
#include "../ip/ip.h"
10
 
11
enum {
12
	Qdir = 0,
13
	Qbase,
14
 
15
	Qmax = 16,
16
};
17
 
18
typedef long Rdwrfn(Chan*, void*, long, vlong);
19
 
20
static Rdwrfn *readfn[Qmax];
21
static Rdwrfn *writefn[Qmax];
22
 
23
static Dirtab archdir[Qmax] = {
24
	".",		{ Qdir, 0, QTDIR },	0,	0555,
25
};
26
 
27
Lock archwlock;	/* the lock is only for changing archdir */
28
int narchdir = Qbase;
29
 
30
/*
31
 * Add a file to the #P listing.  Once added, you can't delete it.
32
 * You can't add a file with the same name as one already there,
33
 * and you get a pointer to the Dirtab entry so you can do things
34
 * like change the Qid version.  Changing the Qid path is disallowed.
35
 */
36
Dirtab*
37
addarchfile(char *name, int perm, Rdwrfn *rdfn, Rdwrfn *wrfn)
38
{
39
	int i;
40
	Dirtab d;
41
	Dirtab *dp;
42
 
43
	memset(&d, 0, sizeof d);
44
	strcpy(d.name, name);
45
	d.perm = perm;
46
 
47
	lock(&archwlock);
48
	if(narchdir >= Qmax){
49
		unlock(&archwlock);
50
		return nil;
51
	}
52
 
53
	for(i=0; i<narchdir; i++)
54
		if(strcmp(archdir[i].name, name) == 0){
55
			unlock(&archwlock);
56
			return nil;
57
		}
58
 
59
	d.qid.path = narchdir;
60
	archdir[narchdir] = d;
61
	readfn[narchdir] = rdfn;
62
	writefn[narchdir] = wrfn;
63
	dp = &archdir[narchdir++];
64
	unlock(&archwlock);
65
 
66
	return dp;
67
}
68
 
69
static Chan*
70
archattach(char* spec)
71
{
72
	return devattach('P', spec);
73
}
74
 
75
Walkqid*
76
archwalk(Chan* c, Chan *nc, char** name, int nname)
77
{
78
	return devwalk(c, nc, name, nname, archdir, narchdir, devgen);
79
}
80
 
81
static int
82
archstat(Chan* c, uchar* dp, int n)
83
{
84
	return devstat(c, dp, n, archdir, narchdir, devgen);
85
}
86
 
87
static Chan*
88
archopen(Chan* c, int omode)
89
{
90
	return devopen(c, omode, archdir, narchdir, devgen);
91
}
92
 
93
static void
94
archclose(Chan*)
95
{
96
}
97
 
98
static long
99
archread(Chan *c, void *a, long n, vlong offset)
100
{
101
	Rdwrfn *fn;
102
 
103
	switch((ulong)c->qid.path){
104
	case Qdir:
105
		return devdirread(c, a, n, archdir, narchdir, devgen);
106
 
107
	default:
108
		if(c->qid.path < narchdir && (fn = readfn[c->qid.path]))
109
			return fn(c, a, n, offset);
110
		error(Eperm);
111
		break;
112
	}
113
 
114
	return 0;
115
}
116
 
117
static long
118
archwrite(Chan *c, void *a, long n, vlong offset)
119
{
120
	Rdwrfn *fn;
121
 
122
	if(c->qid.path < narchdir && (fn = writefn[c->qid.path]))
123
		return fn(c, a, n, offset);
124
	error(Eperm);
125
 
126
	return 0;
127
}
128
 
129
void archinit(void);
130
 
131
Dev archdevtab = {
132
	'P',
133
	"arch",
134
 
135
	devreset,
136
	archinit,
137
	devshutdown,
138
	archattach,
139
	archwalk,
140
	archstat,
141
	archopen,
142
	devcreate,
143
	archclose,
144
	archread,
145
	devbread,
146
	archwrite,
147
	devbwrite,
148
	devremove,
149
	devwstat,
150
};
151
 
152
static long
153
cputyperead(Chan*, void *a, long n, vlong offset)
154
{
155
	char name[64], str[128];
156
 
157
	cputype2name(name, sizeof name);
158
	snprint(str, sizeof str, "ARM %s %llud\n", name, m->cpuhz / Mhz);
159
	return readstr(offset, a, n, str);
160
}
161
 
162
static long
163
tbread(Chan*, void *a, long n, vlong offset)
164
{
165
	char str[16];
166
	uvlong tb;
167
 
168
	cycles(&tb);
169
 
170
	snprint(str, sizeof(str), "%16.16llux", tb);
171
	return readstr(offset, a, n, str);
172
}
173
 
174
static long
175
nsread(Chan*, void *a, long n, vlong offset)
176
{
177
	char str[16];
178
	uvlong tb;
179
 
180
	cycles(&tb);
181
 
182
	snprint(str, sizeof(str), "%16.16llux", (tb/700)* 1000);
183
	return readstr(offset, a, n, str);
184
}
185
 
186
void
187
archinit(void)
188
{
189
	addarchfile("cputype", 0444, cputyperead, nil);
190
	addarchfile("timebase",0444, tbread, nil);
191
//	addarchfile("nsec", 0444, nsread, nil);
192
}