Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
737
738
739
740
741
/*	$NetBSD: machdep.c,v 1.17 2020/06/11 19:20:43 ad Exp $	*/

/*
 * Copyright (c) 1988 University of Utah.
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * the Systems Programming Group of the University of Utah Computer
 * Science Department, The Mach Operating System project at
 * Carnegie-Mellon University and Ralph Campbell.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)machdep.c	8.3 (Berkeley) 1/12/94
 * 	from: Utah Hdr: machdep.c 1.63 91/04/24
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.17 2020/06/11 19:20:43 ad Exp $");

#include "opt_ddb.h"

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/extent.h>
#include <sys/kernel.h>
#include <sys/buf.h>
#include <sys/mbuf.h>
#include <sys/reboot.h>
#include <sys/mount.h>
#include <sys/kcore.h>
#include <sys/boot_flag.h>
#include <sys/ksyms.h>
#include <sys/proc.h>
#include <sys/device.h>
#include <sys/cpu.h>

#include <uvm/uvm_extern.h>

#include <dev/cons.h>

#include <ufs/mfs/mfs_extern.h>		/* mfs_initminiroot() */

#include <mips/cache.h>
#include <machine/psl.h>
#include <machine/autoconf.h>
#include <emips/stand/common/prom_iface.h>
#include <machine/sysconf.h>
#include <machine/bootinfo.h>
#include <machine/locore.h>
#include <emips/emips/machdep.h>
#include <machine/emipsreg.h>

#define _EMIPS_BUS_DMA_PRIVATE
#include <machine/bus.h>

#if NKSYMS || defined(DDB) || defined(MODULAR)
#include <machine/db_machdep.h>
#include <ddb/db_extern.h>
#endif

vaddr_t iospace;
vsize_t iospace_size = 64 * 1024; /* BUGBUG make it an option? */

#include "ksyms.h"

/*
 * Extent map to manage I/O register space.  We allocate storage for
 * 32 regions in the map.  iomap_ex_malloc_safe will indicate that it's
 * safe to use malloc() to dynamically allocate region descriptors in
 * case we run out.
 */
static long iomap_ex_storage[EXTENT_FIXED_STORAGE_SIZE(32) / sizeof(long)];
static struct extent *iomap_ex;
static int iomap_ex_malloc_safe;

/* maps for VM objects */
struct vm_map *phys_map = NULL;

int		systype;		    /* mother board type */
char   *bootinfo = NULL;	/* pointer to bootinfo structure */
int		cpuspeed = 30;		/* approx # instr per usec. */
intptr_t	physmem_boardmax;	/* {model,SIMM}-specific bound on physmem */
int		mem_cluster_cnt;
phys_ram_seg_t	mem_clusters[VM_PHYSSEG_MAX];

void	mach_init (int, char *[], int, intptr_t, u_int, char *); /* XXX */

/* Motherboard or system-specific initialization vector */
static void	unimpl_bus_reset(void);
static void	unimpl_cons_init(void);
static void	unimpl_iointr(uint32_t, vaddr_t, uint32_t);
static void	unimpl_intr_establish(device_t, void *, int,
		    int (*)(void *, void *), void *);
static int	unimpl_memsize(void *);

struct platform platform = {
	"iobus not set",
	unimpl_bus_reset,
	unimpl_cons_init,
	unimpl_iointr,
	unimpl_intr_establish,
	unimpl_memsize
};

extern char *esym;			/* XXX */
extern struct consdev promcd;		/* XXX */
extern const struct callback *callv;
extern const struct callback callvec;

/*
 * Do all the stuff that locore normally does before calling main().
 * The first 4 argments are passed by PROM monitor, and remaining two
 * are built on temporary stack by our boot loader.
 */
void
mach_init(int argc, char *argv[], int code, intptr_t cv, u_int bim, char *bip)
{
	char *cp;
	const char *bootinfo_msg;
	u_long first, last;
	int i, howtoboot;
#if NKSYMS || defined(DDB) || defined(MODULAR)
	void *ssym = 0;
	struct btinfo_symtab *bi_syms;
#endif
	void *kernend;
	extern char edata[], end[];	/* XXX */

	/* Set up bootinfo structure looking at stack. */
	if (bim == BOOTINFO_MAGIC) {
		struct btinfo_magic *bi_magic;

		bootinfo = bip;
		bi_magic = lookup_bootinfo(BTINFO_MAGIC);
		if (bi_magic == NULL || bi_magic->magic != BOOTINFO_MAGIC)
			bootinfo_msg =
			    "invalid magic number in bootinfo structure.\n";
		else
			bootinfo_msg = NULL;
	} else
		bootinfo_msg = "invalid bootinfo pointer (old bootblocks?)\n";

	/*
	 * Look at arguments passed to us and compute boothowto.
	 * Do it before we decide to keep symbols.
	 * NB: "boothowto" is in the BSS.
	 */
	howtoboot = 0;
#ifdef KADB
	howtoboot |= RB_KDB;
#endif
	for (i = 1; i < argc; i++) {
		for (cp = argv[i]; *cp; cp++) {
			switch (*cp) {

#define RB_NOSYMBOLS 0x10000000
			case 'e': /* empty the symtable */
				howtoboot |= RB_NOSYMBOLS;
				break;

			case 'n': /* ask for names */
				howtoboot |= RB_ASKNAME;
				break;

			case 'N': /* don't ask for names */
				howtoboot &= ~RB_ASKNAME;
				break;

			default:
				BOOT_FLAG(*cp, howtoboot); /* see sys/boot_flag.h */
				break;
			}
		}
	}

	/* clear the BSS segment */
#if NKSYMS || defined(DDB) || defined(MODULAR)
	bi_syms = lookup_bootinfo(BTINFO_SYMTAB);

	/* Was it a valid bootinfo symtab info? */
	if ((bi_syms != NULL) && (!(howtoboot & RB_NOSYMBOLS))) {
		ssym = (void *)(intptr_t)bi_syms->ssym;
		esym = (void *)(intptr_t)bi_syms->esym;
		kernend = (void *)mips_round_page(esym);
		memset(edata, 0, end - edata);
	} else
#endif
	{
		kernend = (char *)mips_round_page(end);
		/* should be done by bootloader? */
		memset(edata, 0, (char *)kernend - (char *)edata);
	}

	/* Initialize callv so we can do PROM output... */
	callv = (code == PROM_MAGIC) ? (void *)cv : &callvec;

	/* Use PROM console output until we initialize a console driver. */
	cn_tab = &promcd;

#if 1
	if (bootinfo_msg != NULL)
		printf(bootinfo_msg);
#endif
	uvm_md_init();

	/*
	 * Copy exception-dispatch code down to exception vector.
	 * Initialize locore-function vector.
	 * Clear out the I and D caches.
	 */
	mips_vector_init(NULL, false);

	/*
	 * We know the CPU type now.  Initialize our DMA tags (might
	 * need this early, for certain types of console devices!!).
	 */
	emips_bus_dma_init();

	/* Look at argv[0] and compute bootdev */
	makebootdev(argv[0]);

	boothowto = howtoboot & ~RB_NOSYMBOLS;

	/*
	 * Check to see if a mini-root was loaded into memory. It resides
	 * at the start of the next page just after the end of BSS.
	 */
	if (boothowto & RB_MINIROOT)
		kernend = (char *)kernend
		    + round_page(mfs_initminiroot(kernend));

#if NKSYMS || defined(DDB) || defined(MODULAR)
	/* init symbols if present */
	if (esym) {
		ksyms_addsyms_elf((char *)esym - (char *)ssym, ssym, esym);
	}
#endif
#ifdef DDB
	if (boothowto & RB_KDB)
		Debugger();
#endif

	/*
	 * Initialize physmem_boardmax; assume no SIMM-bank limits.
	 * Adjust later in model-specific code if necessary.
	 */
	physmem_boardmax = MIPS_MAX_MEM_ADDR;

	/*
	 * Determine what model of computer we are running on.
	 */
	systype = ((prom_systype() >> 16) & 0xff);
	if (systype >= nsysinit) {
		platform_not_supported();
		/* NOTREACHED */
	}

	/* Machine specific initialization. */
	(*sysinit[systype].init)();

	/* Find out how much memory is available. */
	physmem = (*platform.memsize)(kernend);

	/*
	 * Load the rest of the available pages into the VM system.
	 * NB: The kernel can span multiple segments.
	 */
	for (i = 0, physmem = 0; i < mem_cluster_cnt; ++i) {
		first = mem_clusters[i].start;
		if (first < round_page(MIPS_KSEG0_TO_PHYS(kernend)))
			first = round_page(MIPS_KSEG0_TO_PHYS(kernend));
		last = mem_clusters[i].start + mem_clusters[i].size;
		physmem += atop(mem_clusters[i].size);

		/* if the kernel spans multiple segments (does on ML40x) */
		if (last <= first)
			continue;

		uvm_page_physload(atop(first), atop(last), atop(first),
		    atop(last), VM_FREELIST_DEFAULT);
	}

	/*
	 * Initialize error message buffer (at end of core).
	 */
	mips_init_msgbuf();

	/*
	 * Initialize the virtual memory system.
	 */
	iospace = pmap_limits.virtual_start;
	pmap_limits.virtual_start += iospace_size;
	pmap_bootstrap();

	mips_init_lwp0_uarea();
}

void
mips_machdep_cache_config(void)
{
}

void
consinit(void)
{
	/*
	 * Init I/O memory extent map. Must be done before cninit()
	 * is called; we may want to use iospace in the console routines.
	 */
	KASSERT(iospace != 0);
	iomap_ex = extent_create("iomap", iospace,
	    iospace + iospace_size - 1,
	    (void *) iomap_ex_storage, sizeof(iomap_ex_storage),
	    EX_NOCOALESCE|EX_NOWAIT);

	/*
	 * Up until now we have kept the TLB disabled,
	 * and that allowed the "PROM" to work.
	 * Specifically, romputc() and the debugger's getc() functions worked.
	 * Now is the last chance we get to turn it on.
	 * That means no more console I/O until autoconf() [sigh!], or..
	 * The platform-specific code will have to map [1:1 probably]
	 * the I/O registers.
	 */
	register_t s = mips_cp0_status_read();
	s &= ~MIPS_SR_TS;
	mips_cp0_status_write(s);

	(*platform.cons_init)();

	/*
	 * Do NOT call cninit(); It will clobber cn_tab using constab[]
	 * which we do not use
	 */
}

/*
 * Allocates a virtual range suitable for mapping in physical memory.
 * Uses resource maps when allocating space, which is allocated from 
 * the IOMAP submap. SIZE is a linear range (NOT vax-pages like the VAX).
 * If the page requested is bigger than a logical page, space is
 * allocated from the kernel map instead.
 */
vaddr_t
mips_map_physmem(paddr_t phys, vsize_t size)
{
	vaddr_t addr;
	int error;
	static int warned = 0;

	size += phys & PAGE_MASK;
	if (size >= PAGE_SIZE) {
		addr = uvm_km_alloc(kernel_map, size, 0, UVM_KMF_VAONLY);
		if (addr == 0)
			panic("mips_map_physmem: kernel map full");
	} else {
		error = extent_alloc(iomap_ex, size, PAGE_SIZE, 0,
		    EX_FAST | EX_NOWAIT |
		    (iomap_ex_malloc_safe ? EX_MALLOCOK : 0), (u_long *)&addr);
		if (error) {
			if (warned++ == 0) /* Warn only once */
				printf("mips_map_physmem: iomap too small");
			return 0;
		}
	}
	ioaccess(addr, phys, size);
#ifdef PHYSMEMDEBUG
	printf("mips_map_physmem: alloc'ed %lx bytes for paddr %lx, at %lx\n",
	    size, phys, addr);
#endif
	return addr | (phys & PAGE_MASK);
}

/*
 * Unmaps the previous mapped (addr, size) pair.
 */
void
mips_unmap_physmem(vaddr_t addr, vsize_t size)
{
#ifdef PHYSMEMDEBUG
	printf("mips_unmap_physmem: unmapping %lx bytes at addr %lx\n", 
	    size, addr);
#endif
	size += addr & PAGE_MASK;
	addr &= ~PAGE_MASK;

	iounaccess(addr, size);
	if (size >= PAGE_SIZE)
		uvm_km_free(kernel_map, addr, size, UVM_KMF_VAONLY);
	else if (extent_free(iomap_ex, addr, size,
	    EX_NOWAIT | (iomap_ex_malloc_safe ? EX_MALLOCOK : 0)))
		printf("mips_unmap_physmem: addr 0x%llx size %llx: "
		    "can't free region\n", (long long)addr, (long long)size);
}

/*
 * Machine-dependent startup code: allocate memory for variable-sized
 * tables.
 */
void
cpu_startup(void)
{
	vaddr_t minaddr, maxaddr;
	char pbuf[9];
#ifdef DEBUG
	extern int pmapdebug;		/* XXX */
	int opmapdebug = pmapdebug;

	pmapdebug = 0;
#endif

	/*
	 * Good {morning,afternoon,evening,night}.
	 */
	printf("%s%s", copyright, version);
	printf("%s\n", cpu_getmodel());
	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
	printf("total memory = %s\n", pbuf);

	minaddr = 0;

	/*
	 * Allocate a submap for physio
	 */
	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
				   VM_PHYS_SIZE, 0, false, NULL);

	/*
	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
	 * are allocated via the pool allocator, and we use KSEG to
	 * map those pages.
	 */

	iomap_ex_malloc_safe = 1;

#ifdef DEBUG
	pmapdebug = opmapdebug;
#endif
	format_bytes(pbuf, sizeof(pbuf), ptoa(uvm_availmem(false)));
	printf("avail memory = %s\n", pbuf);
}

/*
 * Look up information in bootinfo of boot loader.
 */
void *
lookup_bootinfo(int type)
{
	struct btinfo_common *bt;
	char *help = bootinfo;

	/* Check for a bootinfo record first. */
	if (help == NULL)
		return (NULL);

	do {
		bt = (struct btinfo_common *)help;
		if (bt->type == type)
			return ((void *)help);
		help += bt->next;
	} while (bt->next != 0 &&
		(size_t)help < (size_t)bootinfo + BOOTINFO_SIZE);

	return (NULL);
}

void
cpu_reboot(volatile int howto,	/* XXX volatile to keep gcc happy */
           char *bootstr)
{

	/* take a snap shot before clobbering any registers */
	if (curlwp)
		savectx(curpcb);

#ifdef DEBUG
	if (panicstr)
		stacktrace();
#endif

	/* If system is cold, just halt. */
	if (cold) {
		howto |= RB_HALT;
		goto haltsys;
	}

	/* If "always halt" was specified as a boot flag, obey. */
	if ((boothowto & RB_HALT) != 0)
		howto |= RB_HALT;

	boothowto = howto;
	if ((howto & RB_NOSYNC) == 0) {
		/*
		 * Synchronize the disks....
		 */
		vfs_shutdown();

		/*
		 * If we've been adjusting the clock, the todr
		 * will be out of synch; adjust it now.
		 */
		resettodr();
	}

	/* Disable interrupts. */
	splhigh();

	/* If rebooting and a dump is requested do it. */
	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
		dumpsys();

haltsys:
	/* run any shutdown hooks */
	doshutdownhooks();

	pmf_system_shutdown(boothowto);

	/* Finally, halt/reboot the system. */
	printf("%s\n\n", ((howto & RB_HALT) != 0) ? "halted." : "rebooting...");

	prom_halt(howto);
	for (;;) ;
	/*NOTREACHED*/
}

#if defined(MIPS_4GB_PHYSICAL_MEMORY)
#define trim_memory(n) n
#else
#if 0
#define TOO_MUCH (MIPS_PHYS_MASK+1)
#else
#define TOO_MUCH (2*64*1024*1024)
#endif
u_long trim_memory(uint32_t nbytes);/*cheat*/
u_long trim_memory(uint32_t nbytes)
{
	int i;
	u_long first, last;

	nbytes *= 4096;
	if (nbytes <= TOO_MUCH)
		return nbytes;

	/* We have more memory than we can handle */

	mem_clusters[mem_cluster_cnt].start = 0;/* sentinel record */
	mem_clusters[mem_cluster_cnt].size = 0;
	for (i = 0; i < mem_cluster_cnt;) {
		first = mem_clusters[i].start;
		last = mem_clusters[i].start + mem_clusters[i].size;

		if (first > TOO_MUCH) {
			printf("Too much memory, ignoring memory "
			    "range %08lx..%08lx\n", first, last);
			memcpy(mem_clusters+i,mem_clusters+i+1,
			    (sizeof(mem_clusters[0])*(mem_cluster_cnt-i)));
			mem_cluster_cnt--;
			continue;
		}

		if (last > TOO_MUCH) {
			last = TOO_MUCH;
			printf("Too much memory in cluster %d, trimming "
			   "memory to range %08lx..%08lx\n", 
			   i, first, last);
			mem_clusters[i].size = last - mem_clusters[i].start;
		}
		i++;
	}
	return TOO_MUCH;
}
#endif

/*
 * Find out how much memory is available by testing memory.
 */
int
memsize_scan(void *first)
{
	int i, mem;
	char *cp;

	mem = btoc((paddr_t)first - MIPS_KSEG0_START);
	cp = (char *)MIPS_PHYS_TO_KSEG1(mem << PGSHIFT);
	while (cp < (char *)physmem_boardmax) {
	  	int j;
		if (badaddr(cp, 4))
			break;
		i = *(int *)cp;
		j = ((int *)cp)[4];
		*(int *)cp = 0xa5a5a5a5;
		/*
		 * Data will persist on the bus if we read it right away.
		 * Have to be tricky here.
		 */
		((int *)cp)[4] = 0x5a5a5a5a;
		wbflush();
		if (*(int *)cp != 0xa5a5a5a5)
			break;
		*(int *)cp = i;
		((int *)cp)[4] = j;
		cp += PAGE_SIZE;
		mem++;
	}

	/*
	 * Now that we know how much memory we have, initialize the
	 * mem cluster array.
	 */
	mem_clusters[0].start = 0;		/* XXX is this correct? */
	mem_clusters[0].size  = ctob(mem);
	mem_cluster_cnt = 1;

	/* clear any memory error conditions possibly caused by probe */
	(*platform.bus_reset)();
	return (mem);
}

/*
 * Find out how much memory is available by testing memory, starting at first.
 * Returns the total number of pages.
 */
int
memsize_pmt(void * first)
{
	int i, mem;
	struct _Pmt *Pmt = ThePmt;
	struct _Sram *ram;
	uint32_t addr, len;

	/*
	 * Build the RAM memory map from the PMT.
	 */
	mem = 0;
	for (i = 0; i < VM_PHYSSEG_MAX; Pmt--) {
		uint16_t tag = Pmt->Tag;

		if (tag == PMTTAG_END_OF_TABLE)
			break;

		if ((tag != PMTTAG_SRAM) && (tag != PMTTAG_DDRAM))
			continue;

		/*
		 * Got a memory controller segment,
		 * scan all the controllers in it
		 */
		ram = (struct _Sram *)(Pmt->TopOfPhysicalAddress << 16);

		for (;(ram->BaseAddressAndTag & SRAMBT_TAG) == tag;) {
			addr = ram->BaseAddressAndTag & SRAMBT_BASE;
			len  = ram->Control & SRAMST_SIZE;

			mem_clusters[i].start = addr;
			mem_clusters[i].size  = len;
			printf("memory segment %2d start %08lx size %08lx\n", i,
			    (long)mem_clusters[i].start,
			    (long)mem_clusters[i].size);
			i++;
			mem += len;

			/* SRAM and DDRAM have different sizes */
			ram = (tag == PMTTAG_SRAM) ? ram+1 : ram+2;
		}
	}
	mem_cluster_cnt = i;

	return trim_memory(btoc(mem));
}
/*
 *  Ensure all platform vectors are always initialized.
 */
static void
unimpl_bus_reset(void)
{

	panic("sysconf.init didn't set bus_reset");
}

static void
unimpl_cons_init(void)
{

	panic("sysconf.init didn't set cons_init");
}

static void
unimpl_iointr(uint32_t status, vaddr_t pc, uint32_t ipending)
{

	panic("sysconf.init didn't set intr");
}

static void
unimpl_intr_establish(device_t dev, void *cookie, int level,
                      int (*handler) (void *,void *), void *arg)
{

	panic("sysconf.init didn't set intr_establish");
}

static int
unimpl_memsize(void * first)
{

	panic("sysconf.init didn't set memsize");
}

/*
 * Wait "n" microseconds.
 */
void
delay(int n)
{

	DELAY(n);
}