File: bvme.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 (266 lines) | stat: -rw-r--r-- 5,806 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
/*
 *  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 "bvmbug.h"

/*--------------------------------------------------------------------------*/
/* Loader bootblock
 */

static const union {
	BOOTBLOCK	bootblock;
	char		pad[512];
} boot __attribute__ ((section (".boot")))
 =	{{
		BOOT_BLOCK_ID,				/* BVM LTD\0							*/
		0,							/* start_block (unused for TFTP)		*/
		0,							/* block_count (unused for TFTP)		*/
		0x00010000,					/* load address for following data		*/
		0x00000000,					/* run offset (start at load address)	*/
		{0},						/* no boot message						*/
		{0}							/* no boot data							*/
 }};

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

void
loader_init
(	CALLREGS	*regs
)
{
	put_str("BVME4000/6000 TFTP Linux Loader V" VERSION "\n\n");
}

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

void
put_char
(	const int	c
)
{
	BVMBug_putchar(c);
}

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

unsigned long
get_time
(	void
)
{	unsigned long	date;

	BVMBug_gettime(NULL, &date);
	return date;
}

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

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

	if (timeout)
	{
		/* get timeout second */
		timeout += get_time();

		while ((c = BVMBug_getchar_nowait()) == -1)
		{
			/* check for timeout */
			if (get_time() > timeout)
			{
				/* timeout */
				break;
			}
		}

		return c;
	}

	return BVMBug_getchar();
}

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

const char *
get_ip
(	IPTYPE				type
)
{	unsigned long		ip;
	const NETBOOTINFO	*nbi = BVMBug_netbootinfo();

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

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

const char *
config_filename
(	void
)
{	const char	*bootargs = BVMBug_bootargs();

	/* use BVMBug boot argument string if set */
	if (bootargs && bootargs[0])
		return bootargs;

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

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

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

	if ((status = BVMBug_tftp_read(filename, &count, buffer, 0)) != SUCCESS)
	{
		printf ("TFTP READ FAILED: BVMBug error #%d\n", status);
		return FAILURE;
	}

	return count;
}

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

unsigned long
get_compat_booti_version
(	void
)
{
	return COMPAT_BVME6000_BOOTI_VERSION;
}

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

unsigned long
get_booti_version
(	void
)
{
	return BVME6000_BOOTI_VERSION;
}

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

unsigned long
get_compat_machtype
(	void
)
{
	return COMPAT_MACH_BVME6000;
}

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

unsigned long
get_machtype
(	void
)
{
	return MACH_BVME6000;
}

/*--------------------------------------------------------------------------*/
/*
 *	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 BVMBug 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 BVMbug?
		jeq		1f				| branch if not

		moveq	#22,%d0			| BVMBug enter
		trap	#15

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

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

void
print_model
(	int		cpu,
	int		hasfpu
)
{
	printf("BVME%d00", cpu);
}

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