~kris/9p

9hist

ref: f515d58506eb047ce367748e16f824951c5d3758 9hist/port/devboot.c -rw-r--r-- 1.8 KiB
f515d585 — David du Colombier Plan 9 from Bell Labs 1991-04-19 35 years ago
                                                                                
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"errno.h"
#include	"devtab.h"

enum{
	Qdir,
	Qboot,
	Qmem,
};

Dirtab bootdir[]={
	"boot",		{Qboot},	0,	0666,
	"mem",		{Qmem},		0,	0666,
};

#define	NBOOT	(sizeof bootdir/sizeof(Dirtab))

void
bootreset(void)
{
}

void
bootinit(void)
{
}

Chan*
bootattach(char *spec)
{
	return devattach('b', spec);
}

Chan*
bootclone(Chan *c, Chan *nc)
{
	return devclone(c, nc);
}

int	 
bootwalk(Chan *c, char *name)
{
	return devwalk(c, name, bootdir, NBOOT, devgen);
}

Chan*
bootclwalk(Chan *c, char *name)
{
	return devclwalk(c, name);
}

void	 
bootstat(Chan *c, char *dp)
{
	devstat(c, dp, bootdir, NBOOT, devgen);
}

Chan*
bootopen(Chan *c, int omode)
{
	return devopen(c, omode, bootdir, NBOOT, devgen);
}

void	 
bootcreate(Chan *c, char *name, int omode, ulong perm)
{
	error(Eperm);
}

/*
 * sysremove() knows this is a nop
 */
void	 
bootclose(Chan *c)
{
}

long	 
bootread(Chan *c, void *buf, long n, ulong offset)
{
	switch(c->qid.path & ~CHDIR){
	case Qdir:
		return devdirread(c, buf, n, bootdir, NBOOT, devgen);
	}

	error(Egreg);
}

long	 
bootwrite(Chan *c, void *buf, long n, ulong offset)
{
	ulong pc;

	switch(c->qid.path & ~CHDIR){
	case Qmem:
		/* kernel memory.  BUG: shouldn't be so easygoing. BUG: mem mapping? */
		if(offset>=KZERO && offset<KZERO+conf.npage*BY2PG){
/*			print("%ux, %d\n", c->offset, n);/**/
			if(offset+n > KZERO+conf.npage*BY2PG)
				n = KZERO+conf.npage*BY2PG - offset;
			memmove((char*)offset, buf, n);
			return n;
		}
		print("bootwrite: bad addr %lux\n", offset);
		error(Ebadarg);

	case Qboot:
		pc = *(ulong*)buf;
		splhi();
		gotopc(pc);
	}
	print("bootwrite: bad path %d\n", c->qid.path);
	error(Ebadarg);
}

void	 
bootremove(Chan *c)
{
	error(Eperm);
}

void	 
bootwstat(Chan *c, char *dp)
{
	error(Eperm);
}