xref: /plan9-contrib/sys/src/9k/k10/crap.c (revision 9ef1f84b659abcb917c5c090acbce0772e494f21)
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 
7 /*
8 Conf conf;
9 char *confname[1] = {
10 	"console",
11 };
12 char *confval[1] = {
13 	"0 b115200",
14 };
15 int nconf = nelem(confname);
16  */
17 
18 /*
19  * Where configuration info is left for the loaded programme.
20  * This will turn into a structure as more is done by the boot loader
21  * (e.g. why parse the .ini file twice?).
22  * There are 3584 bytes available at CONFADDR.
23  */
24 #define	CONFADDR	PTR2UINT(KADDR(0x0001200))
25 
26 #define BOOTLINE	((char*)CONFADDR)
27 #define BOOTLINELEN	64
28 #define BOOTARGS	((char*)(CONFADDR+BOOTLINELEN))
29 #define	BOOTARGSLEN	(4096-0x200-BOOTLINELEN)
30 #define	MAXCONF		64
31 
32 char *confname[MAXCONF];
33 char *confval[MAXCONF];
34 int nconf;
35 
36 void
crapoptions(void)37 crapoptions(void)
38 {
39 	long i, n;
40 	char *cp, *line[MAXCONF], *p, *q;
41 
42 	/*
43 	 *  parse configuration args from dos file plan9.ini
44 	 */
45 	cp = BOOTARGS;	/* where b.com leaves its config */
46 	cp[BOOTARGSLEN-1] = 0;
47 
48 	/*
49 	 * Strip out '\r', change '\t' -> ' '.
50 	 */
51 	p = cp;
52 	for(q = cp; *q; q++){
53 		if(*q == '\r')
54 			continue;
55 		if(*q == '\t')
56 			*q = ' ';
57 		*p++ = *q;
58 	}
59 	*p = 0;
60 
61 	n = getfields(cp, line, MAXCONF, 1, "\n");
62 	for(i = 0; i < n; i++){
63 		if(*line[i] == '#')
64 			continue;
65 		cp = strchr(line[i], '=');
66 		if(cp == nil)
67 			continue;
68 		*cp++ = '\0';
69 		confname[nconf] = line[i];
70 		confval[nconf] = cp;
71 		nconf++;
72 	}
73 }
74 
75 char*
getconf(char * name)76 getconf(char *name)
77 {
78 	int i;
79 
80 	for(i = 0; i < nconf; i++)
81 		if(cistrcmp(confname[i], name) == 0)
82 			return confval[i];
83 	return 0;
84 }
85 
86 void
confsetenv(void)87 confsetenv(void)
88 {
89 	int i;
90 
91 	for(i = 0; i < nconf; i++){
92 		if(confname[i][0] != '*')
93 			ksetenv(confname[i], confval[i], 0);
94 		ksetenv(confname[i], confval[i], 1);
95 	}
96 }
97 
98 int
isaconfig(char * class,int ctlrno,ISAConf * isa)99 isaconfig(char *class, int ctlrno, ISAConf *isa)
100 {
101 	char cc[32], *p;
102 	int i;
103 
104 	snprint(cc, sizeof cc, "%s%d", class, ctlrno);
105 	p = getconf(cc);
106 	if(p == nil)
107 		return 0;
108 
109 	isa->type = "";
110 	isa->nopt = tokenize(p, isa->opt, NISAOPT);
111 	for(i = 0; i < isa->nopt; i++){
112 		p = isa->opt[i];
113 		if(cistrncmp(p, "type=", 5) == 0)
114 			isa->type = p + 5;
115 		else if(cistrncmp(p, "port=", 5) == 0)
116 			isa->port = strtoul(p+5, &p, 0);
117 		else if(cistrncmp(p, "irq=", 4) == 0)
118 			isa->irq = strtoul(p+4, &p, 0);
119 		else if(cistrncmp(p, "dma=", 4) == 0)
120 			isa->dma = strtoul(p+4, &p, 0);
121 		else if(cistrncmp(p, "mem=", 4) == 0)
122 			isa->mem = strtoul(p+4, &p, 0);
123 		else if(cistrncmp(p, "size=", 5) == 0)
124 			isa->size = strtoul(p+5, &p, 0);
125 		else if(cistrncmp(p, "freq=", 5) == 0)
126 			isa->freq = strtoul(p+5, &p, 0);
127 	}
128 	return 1;
129 }
130