File: bvmbug.h

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 (736 lines) | stat: -rw-r--r-- 16,513 bytes parent folder | download | duplicates (3)
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/*
 *  VME Linux/m68k Loader
 *
 *  (c) Copyright 1997 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.
 */

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

#define BVMBugEntry			(0xE8000404)

#define BB_PUTCHAR			0
#define BB_PUTSTR			1
#define BB_PRINT			2
#define BB_FORMAT			3
#define BB_GETCHAR			4
#define BB_GETCHAR_NW		5
#define BB_GETSTR			6
#define BB_ATOI				7
#define BB_MALLOC			8
#define BB_FREE				9
#define BB_MEMCMP			10
#define BB_MEMSET			11
#define BB_MEMMOVE			12
#define BB_DISK_OPEN		13
#define BB_DISK_READ		14
#define BB_DISK_CLOSE		15
#define BB_FILE_OPEN		16
#define BB_FILE_READ		17
#define BB_FILE_CLOSE		18
#define BB_GETTIME			19
#define BB_DEFINE_SYM		20
#define BB_DELETE_SYM		21
#define BB_ENTER			22
#define BB_TFTP_READ		23
#define BB_NETBOOTINFO		24
#define BB_BOOTARGS			25
#define BB_BRD_ID			26

/*--------------------------------------------------------------------------*/
/* BVMBug error codes
 */

#define DISK_READ_ERROR		1		/* Disk Read Error						*/
#define OUT_OF_MEMORY		2		/* Out of memory						*/
#define INVALID_FILE_MAP	3		/* File map array contains invalid data	*/
#define ILLEGAL_SYMBOL_NAME	4		/* Illegal symbol name					*/
#define FILE_NOT_FOUND		5		/* Illegal or missing file				*/
#define NET_READ_ERROR		6		/* Network Read Error					*/
#define USER_ABORTED		7		/* Aborted by user						*/

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

typedef struct {
	char		boot_id[8];				/* id string "BVM LTD"				*/
#define BOOT_BLOCK_ID  "BVM LTD"

	unsigned long boot_start_block;		/* linear bootfile start block addr	*/
										/* if zero boot_data[] holds user	*/
										/* code or file map of non-linear	*/
										/* bootfile							*/

	unsigned long boot_block_count;		/* number of blocks in linear and	*/
										/* non-linear bootfiles		 		*/
										/* zero indicates boot_data[] holds	*/
										/* machine instructions	which are	*/
										/* moved to the load address and	*/
										/* executed							*/
										
	unsigned long boot_load_address;	/* address to load bootfile	or user	*/
										/* code, if -1 the data is stored	*/
										/* in memory allocated from BVMBug's*/
										/* local memory pool				*/
#define BOOT_ALLOC_MEM		(0xffffffff)

	unsigned long boot_run_offset;		/* offset from load address to		*/
										/* begin execution					*/
										/* if -1 take SP and PC from start	*/
										/*       of loaded data				*/
#define BOOT_RUN_VECTORED	(0xffffffff)

	char		boot_message[32];		/* message to display				*/

#define BOOT_DATA_SZ		(390)
	unsigned char boot_data[BOOT_DATA_SZ];
										/* boot data area:					*/
										/* may contain a file map describing*/
										/* the location of the bootfile or	*/
										/* it may contain user startup code */

} BOOTBLOCK;

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

typedef struct netbootinfo {
	unsigned long	cipa;				/* client IP address				*/
	unsigned long	sipa;				/* server IP address				*/
	unsigned long	gipa;				/* gateway IP address				*/
	unsigned long	subnetmask;			/* subnet IP address mask			*/
	unsigned long	reserved;			/* reserved for broadcast IP		*/
	char			bootfile[128];		/* bootfile name					*/

} NETBOOTINFO; 

/*--------------------------------------------------------------------------*/
/* Call BVMBug putchar subroutine.
 */

static
__inline__
void
BVMBug_putchar
(	int		c
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_PUTCHAR;
	register unsigned long	d1 asm("d1") = (unsigned long) c;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0), "r" (d1)
					: "d0", "d1"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug putstr subroutine.
 */

static
__inline__
void
BVMBug_putstr
(	const char		*str
)
{	register unsigned long	 d0 asm("d0") = (unsigned long) BB_PUTSTR;
	register void			*a0 asm("a0") = (void *) str;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0), "r" (a0)
					: "d0", "a0"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug print subroutine.
 */

static
__inline__
int
BVMBug_print
(	const char		*str,
	void			*vap
)
{	register unsigned long	 d0 asm("d0") = (unsigned long) BB_PRINT;
	register void			*a0 asm("a0") = (void *) str;
	register void			*a1 asm("a1") = (void *) vap;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (a0), "r" (a1)
					: "d0", "a0", "a1"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug format subroutine.
 */

static
__inline__
int
BVMBug_format
(	char			*buf,
	const char		*str,
	void			*vap
)
{	register unsigned long	 d0 asm("d0") = (unsigned long) BB_FORMAT;
	register void			*a0 asm("a0") = (void *) str;
	register void			*a1 asm("a1") = (void *) vap;
	register void			*a2 asm("a2") = (void *) buf;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (a0), "r" (a1), "r" (a2)
					: "d0", "a0", "a1", "a2", "memory"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug getchar subroutine.
 */

static
__inline__
int
BVMBug_getchar
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_GETCHAR;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0)
					: "d0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug getchar_nowait subroutine.
 */

static
__inline__
int
BVMBug_getchar_nowait
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_GETCHAR_NW;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0)
					: "d0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug getstr subroutine.
 */

static
__inline__
int
BVMBug_getstr
(	void	*buffer,
	int		maxlen
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_GETSTR;
	register unsigned long	d1 asm("d1") = (unsigned long) maxlen;
	register void*			a0 asm("a0") = (void *) buffer;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (d1), "r" (a0)
					: "d0", "d1", "a0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug atoi subroutine.
 */

static
__inline__
int
BVMBug_atoi
(	char	*string,
	int		base,
	unsigned long	*result
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_ATOI;
	register unsigned long	d1 asm("d1");
	register unsigned long	d2 asm("d2") = (unsigned long) base;
	register void *			a0 asm("a0") = (void *) string;

	asm volatile (	"trap #15"
					: "=r" (d0), "=r" (d1)
					: "r" (d0), "r" (d2), "r" (a0)
					: "d0", "d1", "d2", "a0"
	);

	*result = d1;
	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug malloc subroutine.
 */

static
__inline__
void *
BVMBug_malloc
(	unsigned long	count
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_MALLOC;
	register unsigned long	d1 asm("d1") = (unsigned long) count;
	register void *			a0 asm("a0");

	asm volatile (	"trap #15"
					: "=r" (a0)
					: "r" (d0), "r" (d1)
					: "d0", "d1", "a0"
	);

	return a0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug free subroutine.
 */

static
__inline__
void
BVMBug_free
(	void	*memptr
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_FREE;
	register void *			a0 asm("a0") = (void *) memptr;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0), "r" (a0)
					: "d0", "a0"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug memcmp subroutine.
 */

static
__inline__
int
BVMBug_memcmp
(	void			*ptr1,
	void			*ptr2,
	unsigned long	siz
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_MEMCMP;
	register unsigned long	d1 asm("d1") = (unsigned long) siz;
	register void *			a0 asm("a0") = (void *) ptr1;
	register void *			a1 asm("a1") = (void *) ptr2;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (d1), "r" (a0), "r" (a1)
					: "d0", "d1", "a0", "a1", "memory"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug memset subroutine.
 */

static
__inline__
void
BVMBug_memset
(	void	*dst,
	int		val,
	unsigned long	siz
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_MEMSET;
	register unsigned long	d1 asm("d1") = (unsigned long) val;
	register unsigned long	d2 asm("d2") = (unsigned long) siz;
	register void *			a0 asm("a0") = (void *) dst;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0), "r" (d1), "r" (d2), "r" (a0)
					: "d0", "d1", "d2", "a0", "memory"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug memmove subroutine.
 */

static
__inline__
void
BVMBug_memmove
(	void		*dst,
	const void	*src,
	unsigned long		siz
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_MEMMOVE;
	register unsigned long	d1 asm("d1") = (unsigned long) siz;
	register void *			a0 asm("a0") = (void *) dst;
	register void *			a1 asm("a1") = (void *) src;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0), "r" (d1), "r" (a0), "r" (a1)
					: "d0", "d1", "a0", "a1", "memory"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug disk_open subroutine.
 */

static
__inline__
int
BVMBug_disk_open
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_DISK_OPEN;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0)
					: "d0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug disk_read subroutine.
 */

static
__inline__
int
BVMBug_disk_read
(	void			*buffer,
	unsigned long	block,
	unsigned long	count
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_DISK_READ;
	register unsigned long	d1 asm("d1") = (unsigned long) count;
	register unsigned long	d2 asm("d2") = (unsigned long) block;
	register void *			a0 asm("a0") = (void *) buffer;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (d1), "r" (d2), "r" (a0)
					: "d0", "d1", "d2", "a0", "memory"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug disk_close subroutine.
 */

static
__inline__
void
BVMBug_disk_close
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_DISK_CLOSE;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0)
					: "d0"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug file_open subroutine.
 */

static
__inline__
int
BVMBug_file_open
(	unsigned long	file_size,
	unsigned long	map_entries,
	const void		*map
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_FILE_OPEN;
	register unsigned long	d1 asm("d1") = (unsigned long) file_size;
	register unsigned long	d2 asm("d2") = (unsigned long) map_entries;
	register void * 		a0 asm("a0") = (void *) map;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (d1), "r" (d2), "r" (a0)
					: "d0", "d1", "d2", "a0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug file_read subroutine.
 */

static
__inline__
int
BVMBug_file_read
(	void			*buffer,
	unsigned long	offset,
	unsigned long	count
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_FILE_READ;
	register unsigned long	d1 asm("d1") = (unsigned long) count;
	register unsigned long	d2 asm("d2") = (unsigned long) offset;
	register void *			a0 asm("a0") = (void *) buffer;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (d1), "r" (d2), "r" (a0)
					: "d0", "d1", "d2", "a0", "memory"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug file_close subroutine.
 */

static
__inline__
void
BVMBug_file_close
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_FILE_CLOSE;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0)
					: "d0"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug gettime subroutine.
 */

static
__inline__
void
BVMBug_gettime
(	unsigned long	*time,
	unsigned long	*date
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_GETTIME;
	register unsigned long	d1 asm("d1");

	asm volatile (	"trap #15"
					: "=r" (d0), "=r" (d1)
					: "r" (d0)
					: "d0", "d1"
	);

	if (time) *time = d0;
	if (date) *date = d1;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug define symbol subroutine.
 */

static
__inline__
int
BVMBug_define_symbol
(	const char		*name,
	unsigned long	value,
	unsigned long	type	/* 0 = code, 1 = data		*/
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_DEFINE_SYM;
	register unsigned long	d1 asm("d1") = (unsigned long) value;
	register unsigned long	d2 asm("d2") = (unsigned long) type;
	register void * 		a0 asm("a0") = (void *) name;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (d1), "r" (d2), "r" (a0)
					: "d0", "d1", "d2", "a0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug delete symbol subroutine.
 */

static
__inline__
int
BVMBug_delete_symbol
(	const char	*name		/* symbol name or NULL for all symbols			*/
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_DELETE_SYM;
	register void * 		a0 asm("a0") = (void *) name;

	asm volatile (	"trap #15"
					: "=r" (d0)
					: "r" (d0), "r" (a0)
					: "d0", "a0"
	);

	return d0;
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug.
 */

static
__inline__
void
BVMBug_enter
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_ENTER;

	asm volatile (	"trap #15"
					: /* no outputs */
					: "r" (d0)
					: "d0", "d1", "d2", "d3", "d4", "d5", "d6",
					  "a0", "a1", "a2", "a3", "a4", "memory"
	);
}

/*--------------------------------------------------------------------------*/
/* Call BVMBug reset entry.
 */

static __inline__ void BVMBug_reset(void) __attribute((noreturn));

static
__inline__ 
void
BVMBug_reset
(	void
)
{
	asm volatile (
	"
		move.w	#0x2700,%%sr	/* mask interrupts							*/
		move.l	4(%0),%%a0		/* get reset PC								*/
		move.l	(%0),%%a7		/* get reset SP								*/
		moveq	#0,%%d0			/* clear cache control register				*/
		movec	%%d0,%%cacr
		cinva	%%bc			/* invalidate data and instruction caches	*/
		jmp		(%%a0)
	"
	: /* no outputs */
	: "a" (BVMBugEntry & 0xff000000)
	: "a0", "d0"
	);

	/* stop compiler complaining that we will return */
	while (1)
		;
}

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

static
__inline__
int
BVMBug_tftp_read
(	const char		*filename,
	unsigned long	*count,
	void			*buffer,
	unsigned long	flags
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_TFTP_READ;
	register unsigned long	d1 asm("d1") = (unsigned long) *count;
	register unsigned long	d2 asm("d2") = (unsigned long) flags;
	register void * 		a0 asm("a0") = (void *) filename;
	register void *			a1 asm("a1") = (void *) buffer;

	asm volatile (	"trap #15"
					: "=r" (d0), "=r" (d1)
					: "r" (d0), "r" (d1), "r" (d2), "r" (a0), "r" (a1)
					: "d0", "d1", "d2", "a0", "a1", "memory"
	);
	*count = d1;

	return d0;
}

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

static
__inline__
const NETBOOTINFO *
BVMBug_netbootinfo
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_NETBOOTINFO;
	register NETBOOTINFO *	a0 asm("a0");

	asm volatile (	"trap #15"
					: "=r" (a0)
					: "r" (d0)
					: "d0", "a0"
	);

	return a0;
}

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

static
__inline__
const char *
BVMBug_bootargs
(	void
)
{	register unsigned long	d0 asm("d0") = (unsigned long) BB_BOOTARGS;
	register const char *	a0 asm("a0");

	asm volatile (	"trap #15"
					: "=r" (a0)
					: "r" (d0)
					: "d0", "a0"
	);

	return a0;
}

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