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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/* $OpenBSD: bugio.c,v 1.7 2004/11/15 11:01:35 miod Exp $ */
/*
* bug routines -- assumes that the necessary sections of memory
* are preserved.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/types.h>
#include <machine/bugio.h>
#include <machine/cpu.h>
int bugenvsz(void);
/*
* BUG register preserving
*/
register_t sprg0, sprg1, sprg2, sprg3;
register_t bugsprg3;
#define BUGCTXT(msr) \
do { \
msr = ppc_mfmsr(); \
sprg0 = ppc_mfsprg0(); \
sprg1 = ppc_mfsprg1(); \
sprg2 = ppc_mfsprg2(); \
sprg3 = ppc_mfsprg3(); \
ppc_mtsprg3(bugsprg3); \
ppc_mtmsr(((msr | PSL_IP) & ~(PSL_EE | PSL_IR | PSL_DR))); \
} while (0)
#define OSCTXT(msr) \
do { \
bugsprg3 = ppc_mfsprg3(); \
ppc_mtsprg0(sprg0); \
ppc_mtsprg1(sprg1); \
ppc_mtsprg2(sprg2); \
ppc_mtsprg3(sprg3); \
ppc_mtmsr(msr); \
} while (0)
/* Invoke the BUG */
#define MVMEPROM_CALL(x) \
__asm__ __volatile__ ("addi %r10,%r0," __STRING(x)); \
__asm__ __volatile__ ("sc");
void
buginit()
{
bugsprg3 = ppc_mfsprg3();
}
/* BUG - query board routines */
void
mvmeprom_brdid(id)
struct mvmeprom_brdid *id;
{
unsigned long msr;
BUGCTXT(msr);
MVMEPROM_CALL(MVMEPROM_BRD_ID);
asm volatile ("mr %0, 3": "=r" (id):);
OSCTXT(msr);
}
/* returns 0 if no characters ready to read */
int
mvmeprom_getchar()
{
int ret;
unsigned long msr;
BUGCTXT(msr);
MVMEPROM_CALL(MVMEPROM_INCHR);
asm volatile ("mr %0, 3" : "=r" (ret));
OSCTXT(msr);
return ret;
}
/* returns 0 if no characters ready to read */
int
mvmeprom_instat()
{
int ret;
unsigned long msr;
BUGCTXT(msr);
MVMEPROM_CALL(MVMEPROM_INSTAT);
asm volatile ("mr %0, 3" : "=r" (ret));
OSCTXT(msr);
return (!(ret & 0x4));
}
void
mvmeprom_outln(start, end)
char *start, *end;
{
unsigned long msr;
BUGCTXT(msr);
asm volatile ("mr 3, %0": : "r" (start));
asm volatile ("mr 4, %0": : "r" (end));
MVMEPROM_CALL(MVMEPROM_OUTLN);
OSCTXT(msr);
}
void
mvmeprom_outstr(start, end)
char *start, *end;
{
unsigned long msr;
BUGCTXT(msr);
asm volatile ("mr 3, %0": : "r" (start));
asm volatile ("mr 4, %0": : "r" (end));
MVMEPROM_CALL(MVMEPROM_OUTSTR);
OSCTXT(msr);
}
void
mvmeprom_outchar(c)
int c;
{
unsigned long msr;
BUGCTXT(msr);
asm volatile ("mr 3, %0" :: "r" (c));
MVMEPROM_CALL(MVMEPROM_OUTCHR);
OSCTXT(msr);
}
/* BUG - return to bug routine */
void
mvmeprom_return()
{
unsigned long msr;
BUGCTXT(msr);
MVMEPROM_CALL(MVMEPROM_RETURN);
OSCTXT(msr);
/*NOTREACHED*/
}
void
mvmeprom_rtc_rd(ptime)
struct mvmeprom_time *ptime;
{
unsigned long msr;
BUGCTXT(msr);
asm volatile ("mr 3, %0": : "r" (ptime));
MVMEPROM_CALL(MVMEPROM_RTC_RD);
OSCTXT(msr);
}
int
bugenvsz(void)
{
register int ret;
char tmp[1];
void *ptr = tmp;
unsigned long msr;
BUGCTXT(msr);
asm volatile ("mr 3, %0": : "r" (ptr));
asm volatile ("li 5, 0x1");
asm volatile ("li 5, 0x0"); /* get size */
MVMEPROM_CALL(MVMEPROM_ENVIRON);
asm volatile ("mr %0, 3" : "=r" (ret));
OSCTXT(msr);
return(ret);
}
struct bugenviron bugenviron;
int bugenv_init = 0;
char bugenv_buf[1024];
#ifdef BUG_DEBUG
void bug_printenv(void);
void
bug_printenv(void)
{
printf("Startup Mode: %c\n", bugenviron.s.s_mode);
printf("Startup Menu: %c\n", bugenviron.s.s_menu);
printf("Remote Start: %c\n", bugenviron.s.s_remotestart);
printf("Probe Devs: %c\n", bugenviron.s.s_probe);
printf("Negate Sysfail: %c\n", bugenviron.s.s_negsysfail);
printf("Reset SCSI Bus: %c\n", bugenviron.s.s_resetscsi);
printf("Ignore CFNA Block: %c\n", bugenviron.s.s_nocfblk);
printf("SCSI sync method: %c\n", bugenviron.s.s_scsisync);
printf("Auto Boot Enable: %c\n", bugenviron.b.b_enable);
printf("Auto Boot on power-up Only: %c\n", bugenviron.b.b_poweruponly);
printf("Auto Boot CLUN: %02x\n", bugenviron.b.b_clun);
printf("Auto Boot DLUN: %02x\n", bugenviron.b.b_dlun);
printf("Auto Boot Delay: %02x\n", bugenviron.b.b_delay);
printf("Auto Boot String: %s\n", bugenviron.b.b_string);
printf("ROM Boot Enable: %c\n", bugenviron.r.r_enable);
printf("ROM Boot on power-up Only: %c\n", bugenviron.r.r_poweruponly);
printf("ROM Boot Scan VME bus: %c\n", bugenviron.r.r_bootvme);
printf("ROM Boot Delay: %02x\n", bugenviron.r.r_delay);
printf("ROM Boot Start: %08x\n", bugenviron.r.r_start);
printf("ROM Boot End: %08x\n", bugenviron.r.r_end);
printf("Net Boot Enable: %c\n", bugenviron.n.n_enable);
printf("Net Boot on power-up Only: %c\n", bugenviron.n.n_poweruponly);
printf("Net Boot CLUN: %02x\n", bugenviron.n.n_clun);
printf("Net Boot DLUN: %02x\n", bugenviron.n.n_dlun);
printf("Net Boot Delay: %02x\n", bugenviron.n.n_delay);
printf("Net Boot CFG param pointer: %08x\n", bugenviron.n.n_param);
printf("Memory Size Enable: %c\n", bugenviron.m.m_sizeenable);
printf("Memory Start: %08x\n", bugenviron.m.m_start);
printf("Memory End: %08x\n", bugenviron.m.m_end);
Debugger();
}
#else
#define bug_printenv()
#endif
struct bugenviron *
mvmeprom_envrd(void)
{
register int ret;
char *ptr, *dptr, *ptr_end;
int env_size = 0;
int pkt_typ, pkt_len;
unsigned long msr;
env_size = bugenvsz();
bzero(&bugenviron, sizeof(struct bugenviron));
bzero(&bugenv_buf[0], 1024);
ptr = bugenv_buf;
if (ptr != NULL) {
BUGCTXT(msr);
asm volatile ("mr 3, %0": : "r" (ptr));
asm volatile ("mr 4, %0": : "r" (env_size));
asm volatile ("li 5, 0x2");
MVMEPROM_CALL(MVMEPROM_ENVIRON);
asm volatile ("mr %0, 3" : "=r" (ret));
OSCTXT(msr);
if (ret)
return NULL;
ptr_end = ptr + env_size;
while (ptr <= ptr_end) {
pkt_typ = *ptr++;
pkt_len = *ptr++;
dptr = ptr;
switch (pkt_typ) {
case BUG_ENV_END:
bugenv_init = 1; /* we have read the env */
bug_printenv();
return(&bugenviron);
break;
case BUG_STARTUP_PARAM:
/* All chars. We can use bcopy. */
bcopy(dptr, &bugenviron.s.s_mode, pkt_len);
break;
case BUG_AUTOBOOT_INFO:
/* All chars. We can use bcopy. */
bcopy(dptr, &bugenviron.b.b_enable, pkt_len);
break;
case BUG_ROMBOOT_INFO:
/* This data stream has integer info that
* may not be word aligned. We can't use
* bcopy for the whole struct in this
* instance. */
bcopy(dptr, &bugenviron.r.r_enable, 4);
dptr+=4;
bcopy(dptr, &bugenviron.r.r_start, 4);
dptr+=4;
bcopy(dptr, &bugenviron.r.r_end, 4);
break;
case BUG_NETBOOT_INFO:
/* This data stream has integer info that
* may not be word aligned. We can't use
* bcopy for the whole struct in this
* instance. */
bcopy(dptr, &bugenviron.n.n_enable, 5);
dptr+=5;
bcopy(dptr, &bugenviron.n.n_param, 4);
break;
case BUG_MEMORY_INFO:
bugenviron.m.m_sizeenable = *dptr++;
bcopy(dptr, &bugenviron.m.m_start, 4);
dptr+=4;
bcopy(dptr, &bugenviron.m.m_end, 4);
break;
}
ptr += pkt_len;
}
}
return NULL;
}
|