File: mvme.c

package info (click to toggle)
m68k-vme-tftplilo 1.0.0-1
  • links: PTS
  • area: main
  • in suites: slink
  • size: 316 kB
  • ctags: 637
  • sloc: ansic: 5,475; makefile: 78
file content (348 lines) | stat: -rw-r--r-- 7,306 bytes parent folder | download
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 *  VME Linux/m68k TFTP Loader
 *
 *  (c) Copyright 1998 by Nick Holgate
 *
 *  This file is subject to the terms and conditions of the GNU General
 *  Public License.  See the file COPYING for more details.
 */

/*--------------------------------------------------------------------------*/

#include "defs.h"
#include "mvmebug.h"

/*--------------------------------------------------------------------------*/

static NETBOOTINFO	*netbootinfo;
static char			bootargs[65];

/*--------------------------------------------------------------------------*/
/* Board ID data structure
 *
 * Note, bytes 12 and 13 are board no in BCD (0162,0166,0167,0177,etc)
 */

typedef struct {
        char			bdid[4];
        unsigned char	rev, mth, day, yr;
        unsigned short	size, reserved;
        unsigned short	brdno;
        char			brdsuffix[2];
        unsigned long	options;
        unsigned short	clun, dlun, ctype, dnum;
        unsigned long	option2;

} t_bdid, *p_bdid;

/*--------------------------------------------------------------------------*/

static
unsigned long
get_brd_id
(	void
)
{	static unsigned long	brd_id = 0;

	if (brd_id == 0)
	{
		p_bdid				pkt;

		pkt = (p_bdid) MVMEBug_brd_id();

		if (*(unsigned long *)pkt->bdid != 0x42444944)
		{
			panic("Cannot identify board");
		}

		brd_id = (unsigned long) pkt->brdno;
	}

	return brd_id;
}

/*--------------------------------------------------------------------------*/

void
loader_init
(	CALLREGS	*regs
)
{	char		*s;
	char		*d;

	/* save pointer to netboot info */
	netbootinfo = (NETBOOTINFO *) regs->a[2];

	/* copy argument string */
	s = regs->a[3];
	d = bootargs;
	while (s != regs->a[4])
		*d++ = *s++;
	*d = '\0';

	put_str("\nMotorola MVME TFTP Linux Loader V" VERSION "\n\n");
}

/*--------------------------------------------------------------------------*/
/* Print character.
 */

void
put_char
(	const int	c
)
{
	if (c == '\n')
		MVMEBug_putchar('\r');

	MVMEBug_putchar(c);
}

/*--------------------------------------------------------------------------*/

unsigned long
get_time
(	void
)
{	unsigned char buf[8];

	MVMEBug_rtc_read(buf);
	return 	(BCD2BIN(buf[4]) * 24)
		+	(BCD2BIN(buf[5]) * 60)
		+    BCD2BIN(buf[6]);
}

/*--------------------------------------------------------------------------*/
/* Wait for and return character from keyboard.
 */

int
get_char
(	unsigned long	timeout		/* maximum time to wait for character		*/
)
{	unsigned long	start;
	unsigned long	now;

	if (timeout)
	{
		/* get start time */
		start = get_time();

		/* get timeout second */
		timeout += start;

		while (MVMEBug_getchar_status() == 0)
		{
			/* check for wrap at midnight */
			if ((now = get_time()) < start)
			{
				/* adjust */
				now += (60 * 60 * 24);
			}

			/* check for timeout */
			if (now > timeout)
			{
				/* timeout */
				break;
			}
		}

		if (MVMEBug_getchar_status() == 0)
			return -1;
	}

	return MVMEBug_getchar();
}

/*--------------------------------------------------------------------------*/
/* return pointer to string containing specified IP address or NULL
 * if not available.
 */

const char *
get_ip
(	IPTYPE			type
)
{	unsigned long	ip;

	switch (type)
	{
		case IP_CLIENT   : ip = netbootinfo->cipa;       break;
		case IP_SERVER   : ip = netbootinfo->sipa;       break;
		case IP_GATEWAY  : ip = netbootinfo->gipa;       break;
		case IP_BROADCAST: ip = netbootinfo->broadcast;  break;
		case IP_NETMASK  : ip = netbootinfo->subnetmask; break;
		default          : return NULL;
	}
		
	return mkinet(ip);
}

/*--------------------------------------------------------------------------*/
/* return pointer to prototype configuration file name
 */

const char *
config_filename
(	void
)
{
	/* use boot argument string if set */
	if (bootargs[0])
		return bootargs;

	/* use compiled in default */
	return DEFAULT_CONFIG_FILE_NAME;
}

/*--------------------------------------------------------------------------*/

int
tftp_read
(	const char		*filename,
	unsigned long	count,
	void			*buffer
)
{	NIOPCALL		niop;

	niop.clun    = 0;
	niop.dlun    = 0;
	niop.status  = 0;
	niop.address = (unsigned long) buffer;
	niop.length  = count;
	niop.offset  = 0;
	niop.time    = 0;
	niop.bytes   = 0;
	strncpy(niop.filename, filename, sizeof(niop.filename) - 1);
	niop.filename[sizeof(niop.filename) - 1] = '\0';

	MVMEBug_net_read(&niop);

	if (niop.status)
	{
		printf("TFTP READ FAILED: status=%04x\n", niop.status);
		return FAILURE;
	}

	return niop.bytes;
}

/*--------------------------------------------------------------------------*/

unsigned long
get_compat_booti_version
(	void
)
{
	switch (get_brd_id())
	{
		case 0x0162:
		case 0x0172: return COMPAT_MVME162_BOOTI_VERSION;
		default    : return COMPAT_MVME167_BOOTI_VERSION;
	}
}

/*--------------------------------------------------------------------------*/

unsigned long
get_booti_version
(	void
)
{
	return MVME16x_BOOTI_VERSION;
}

/*--------------------------------------------------------------------------*/

unsigned long
get_compat_machtype
(	void
)
{
	switch (get_brd_id())
	{
		case 0x0162:
		case 0x0172: return COMPAT_MACH_MVME162;
		default    : return COMPAT_MACH_MVME167;
	}
}

/*--------------------------------------------------------------------------*/

unsigned long
get_machtype
(	void
)
{
	return MACH_MVME16x;
}

/*--------------------------------------------------------------------------*/
/*
 *	This assembler code is copied into the base of the stack, and then executed.
 *	It copies the kernel and ramdisk images to their final resting places.
 *
 *	It is called with:
 *
 *      a0 = address of this code (very top of memory)
 *      a1 = kernel destination address (low memory 0x1000)
 *		a2 = kernel source address
 *		a3 = ramdisk destination address (just below this code)
 *		a4 = ramdisk source address
 *		d0 = kernel size + size of bootinfo data rounded up next multiple of 4
 *		d1 = ramdisk size rounded to next multiple of 1K
 *      d2 = non-zero if 16x-Bug should be called
 */

__asm(".text\n"
__ALIGN_STR "\n"
".globl " SYMBOL_NAME_STR(startcode_beg) ";\n"
".globl " SYMBOL_NAME_STR(startcode_end) ";\n"
SYMBOL_NAME_STR(startcode_beg) ":
								| /* copy the ramdisk to the top of memory */
								| /* (from back to front) */
		addl	%d1,%a4			| src   = (u_long *) (rd_src + rd_size);
		movel	%a3,%a5
		addl	%d1,%a5			| dest  = (u_long *) (rd_dest + rd_size);

		bras	2f				| do
1:		movel	-(%a4),-(%a5)	|   *--dest = *--src;
2:		cmpl	%a3,%a5			| while (dest > ramdisk_dest)
		jgt		1b				| 

								| /* copy kernel text and data, and bootinfo */
		movel	%a2,%a4			| limit = (u_long *) (kernel_src + kernel_size);
		addl	%d0,%a4
		movel	%a1,%a5			| dest  = (u_long *) kernel_dest

		bras	2f				| do
1:		movel	(%a2)+,(%a5)+	|  *dest++ = *src++;
2:		cmpl	%a4,%a2			| while (src < limit)
		jlt		1b				|

		dc.w	0xf498			| cinva	ic | invalidate instruction cache

		tstl	%d2				| call monitor?
		jeq		1f				| branch if not

		trap	#15				| return to 16x-Bug
		dc.w	0x0063

1:		jmp		(%a1)			| start kernel
"
SYMBOL_NAME_STR(startcode_end) ":
");

/*--------------------------------------------------------------------------*/

void
print_model
(	int		cpu,
	int		hasfpu
)
{
	printf("MVME%lx", get_brd_id());
}

/*-----------------------------< end of file >------------------------------*/