code:
/*	$OpenBSD: Locore.c,v 1.16 2014/07/12 21:54:58 jasper Exp $	*/
/*	$NetBSD: Locore.c,v 1.1 1997/04/16 20:29:11 thorpej Exp $	*/

/*
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */

#include <lib/libsa/stand.h>
#include <macppc/stand/openfirm.h>
#include <dev/cons.h>

/*
#include "machine/cpu.h"
*/

#define ENABLE_DECREMENTER_WORKAROUND
void patch_dec_intr();

static int (*openfirmware)(void *);

static void setup(void);

asm (".text; .globl _entry; _entry: .long _start,0,0");
asm("   .text			\n"
"	.globl	bat_init	\n"
"bat_init:			\n"
"				\n"
"	mfmsr   8		\n"
"	li      0,0		\n"
"	mtmsr   0		\n"
"	isync			\n"
"				\n"
"	mtibatu 0,0		\n"
"	mtibatu 1,0		\n"
"	mtibatu 2,0		\n"
"	mtibatu 3,0		\n"
"	mtdbatu 0,0		\n"
"	mtdbatu 1,0		\n"
"	mtdbatu 2,0		\n"
"	mtdbatu 3,0		\n"
"				\n"
"	li      9,0x12         	\n"	 /* BATL(0, BAT_M, BAT_PP_RW) */
"	mtibatl 0,9		\n"
"	mtdbatl 0,9		\n"
"	li      9,0x1ffe        \n"	/* BATU(0, BAT_BL_256M, BAT_Vs) */
"	mtibatu 0,9		\n"
"	mtdbatu 0,9		\n"
"	isync			\n"
"				\n"
"	mtmsr 8  		\n"
"	isync			\n"
"	blr			\n");

#ifdef XCOFF_GLUE
static int stack[8192/4 + 4] __attribute__((__used__));
#endif

__dead void
_start(void *vpd, int res, int (*openfirm)(void *), char *arg, int argl)
{
	extern char etext[];

#ifdef XCOFF_GLUE
	asm(
	"sync			\n"
	"isync			\n"
	"lis	%r1,stack@ha	\n"
	"addi	%r1,%r1,stack@l	\n"
	"addi	%r1,%r1,8192	\n");
#endif
	syncicache((void *)RELOC, etext - (char *)RELOC);

	bat_init();
	openfirmware = openfirm;	/* Save entry to Open Firmware */
#ifdef ENABLE_DECREMENTER_WORKAROUND
	patch_dec_intr();
#endif
	setup();
	main(arg, argl);
	exit();
}

#ifdef ENABLE_DECREMENTER_WORKAROUND
void handle_decr_intr();
__asm (	"	.globl handle_decr_intr\n"
	"	.type handle_decr_intr@function\n"
	"handle_decr_intr:\n"
	"	rfi\n");

void
patch_dec_intr()
{
	int time;
	unsigned int *decr_intr = (unsigned int *)0x900;
	unsigned int br_instr;

	/* this hack is to prevent unexpected Decrementer Exceptions
	 * when Apple openfirmware enables interrupts
	 */
	time = 0x40000000;
	asm("mtdec %0" :: "r"(time));

	/* we assume that handle_decr_intr is in the first 128 Meg */
	br_instr = (18 << 23) | (unsigned int)handle_decr_intr;
	*decr_intr = br_instr;
}
#endif

__dead void
_rtt()
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
	} args = {
		"exit",
		0,
		0
	};

	openfirmware(&args);
	while (1);			/* just in case */
}

int
OF_finddevice(char *name)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		char *device;
		int phandle;
	} args = {
		"finddevice",
		1,
		1,
	};

	args.device = name;
	if (openfirmware(&args) == -1)
		return -1;
	return args.phandle;
}

int
OF_instance_to_package(int ihandle)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int ihandle;
		int phandle;
	} args = {
		"instance-to-package",
		1,
		1,
	};

	args.ihandle = ihandle;
	if (openfirmware(&args) == -1)
		return -1;
	return args.phandle;
}

int
OF_getprop(int handle, char *prop, void *buf, int buflen)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int phandle;
		char *prop;
		void *buf;
		int buflen;
		int size;
	} args = {
		"getprop",
		4,
		1,
	};

	args.phandle = handle;
	args.prop = prop;
	args.buf = buf;
	args.buflen = buflen;
	if (openfirmware(&args) == -1)
		return -1;
	return args.size;
}

int
OF_open(char *dname)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		char *dname;
		int handle;
	} args = {
		"open",
		1,
		1,
	};

	args.dname = dname;
	if (openfirmware(&args) == -1)
		return -1;
	return args.handle;
}

void
OF_close(int handle)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int handle;
	} args = {
		"close",
		1,
		0,
	};

	args.handle = handle;
	openfirmware(&args);
}

int
OF_write(int handle, void *addr, int len)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int ihandle;
		void *addr;
		int len;
		int actual;
	} args = {
		"write",
		3,
		1,
	};

	args.ihandle = handle;
	args.addr = addr;
	args.len = len;
	if (openfirmware(&args) == -1)
		return -1;
	return args.actual;
}

int
OF_read(int handle, void *addr, int len)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int ihandle;
		void *addr;
		int len;
		int actual;
	} args = {
		"read",
		3,
		1,
	};

	args.ihandle = handle;
	args.addr = addr;
	args.len = len;
	if (openfirmware(&args) == -1)
		return -1;
	return args.actual;
}

int
OF_seek(int handle, u_quad_t pos)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int handle;
		int poshi;
		int poslo;
		int status;
	} args = {
		"seek",
		3,
		1,
	};

	args.handle = handle;
	args.poshi = (int)(pos >> 32);
	args.poslo = (int)pos;
	if (openfirmware(&args) == -1)
		return -1;
	return args.status;
}

void *
OF_claim(void *virt, u_int size, u_int align)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		void *virt;
		u_int size;
		u_int align;
		void *baseaddr;
	} args = {
		"claim",
		3,
		1,
	};

	args.virt = virt;
	args.size = size;
	args.align = align;
	if (openfirmware(&args) == -1)
		return (void *)-1;
	if (virt != 0)
		return virt;
	return args.baseaddr;
}

void
OF_release(void *virt, u_int size)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		void *virt;
		u_int size;
	} args = {
		"release",
		2,
		0,
	};

	args.virt = virt;
	args.size = size;
	openfirmware(&args);
}

int
OF_milliseconds()
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		int ms;
	} args = {
		"milliseconds",
		0,
		1,
	};

	openfirmware(&args);
	return args.ms;
}

#ifdef __notyet__
void
OF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
{
	static struct {
		char *name;
		int nargs;
		int nreturns;
		void *virt;
		u_int size;
		void (*entry)();
		void *arg;
		u_int len;
	} args = {
		"chain",
		5,
		0,
	};

	args.virt = virt;
	args.size = size;
	args.entry = entry;
	args.arg = arg;
	args.len = len;
	openfirmware(&args);
}
#else
void
OF_chain(void *virt, u_int size, void (*entry)(), void *arg, u_int len)
{
	/*
	 * This is a REALLY dirty hack till the firmware gets this going
	OF_release(virt, size);
	 */
	entry(0, 0, openfirmware, arg, len);
}
#endif

int
OF_call_method(char *method, int ihandle, int nargs, int nreturns, ...)
{
	va_list ap;
	static struct {
		char *name;
		int nargs;
		int nreturns;
		char *method;
		int ihandle;
		int args_n_results[12];
	} args = {
		"call-method",
		2,
		1,
	};
	int *ip, n;

	if (nargs > 6)
		return -1;
	args.nargs = nargs + 2;
	args.nreturns = nreturns + 1;
	args.method = method;
	args.ihandle = ihandle;
	va_start(ap, nreturns);
	for (ip = args.args_n_results + (n = nargs); --n >= 0;)
		*--ip = va_arg(ap, int);

	if (openfirmware(&args) == -1) {
		va_end(ap);
		return -1;
	}
	if (args.args_n_results[nargs]) {
		va_end(ap);
		return args.args_n_results[nargs];
	}
	for (ip = args.args_n_results + nargs + (n = args.nreturns); --n > 0;)
		*va_arg(ap, int *) = *--ip;
	va_end(ap);
	return 0;
}

static int stdin;
static int stdout;

static void
setup()
{
	int chosen;

	if ((chosen = OF_finddevice("/chosen")) == -1)
		_rtt();
	if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) != sizeof(stdin)
	    || OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) !=
	    sizeof(stdout))
		_rtt();
	if (stdout == 0) {
		/* screen should be console, but it is not open */
		stdout = OF_open("screen");
	}
}

void
putchar(int c)
{
	char ch = c;
	if (c == '\177') {
		ch = '\b';
		OF_write(stdout, &ch, 1);
		ch = ' ';
		OF_write(stdout, &ch, 1);
		ch = '\b';
	}
	if (c == '\n')
		putchar('\r');
	OF_write(stdout, &ch, 1);
}

void
ofc_probe(struct consdev *cn)
{
	cn->cn_pri = CN_LOWPRI;
	cn->cn_dev = makedev(0,0); /* WTF */
}

void
ofc_init(struct consdev *cn)
{
}

char buffered_char;
int
ofc_getc(dev_t dev)
{
	u_int8_t ch;
	int l;

	if (dev & 0x80)  {
		if (buffered_char != 0)
			return 1;

		l = OF_read(stdin, &ch, 1);
		if (l == 1) {
			buffered_char = ch;
			return 1;
		}
		return 0;
	}

	if (buffered_char != 0) {
		ch = buffered_char;
		buffered_char = 0;
		return ch;
	}

	while ((l = OF_read(stdin, &ch, 1)) != 1)
		if (l != -2 && l != 0)
			return 0;
	return ch;

}

void
ofc_putc(dev_t dev, int c)
{
	char ch;

	ch = 'a';
	OF_write(stdout, &ch, 1);
	ch = c;
	if (c == '\177' && c == '\b') {
		ch = 'A';
	}
	OF_write(stdout, &ch, 1);
}

void
machdep()
{
	cninit();
}


code:
#	$OpenBSD: Makefile,v 1.8 2014/07/13 21:11:40 deraadt Exp $
#	$NetBSD: Makefile,v 1.1 1996/09/30 16:34:59 ws Exp $

MANSUBDIR=macppc
MAN=boot.8
MLINKS?=	boot.8 boot.conf.5

.if ${MACHINE} == "macppc"
SUBDIR=	ofwboot boot.mac mbr tbxidata

SAREL=
KERNREL=
KERN_AS=library
Z_AS=library
SA_ZLIB=smth
USE_LOADFILE=yes

.include "Makefile.inc"
.include "$S/lib/libz/Makefile.inc"
.include "$S/lib/libsa/Makefile.inc"

all:	${ZLIB} ${SALIB} _SUBDIRUSE

libdep:
	@echo ${.OBJDIR}/${SALIB} ${ZLIB}

${PROG}:

clean::	_SUBDIRUSE

cleandir:	_SUBDIRUSE

depend::	_SUBDIRUSE
.endif

.include <bsd.obj.mk>
.include <bsd.subdir.mk>
.include <bsd.man.mk>

path: sys/arch/macppc/stand/Makefile

license: unknown


code:
#	$OpenBSD: Makefile.inc,v 1.12 2013/10/27 04:49:52 deraadt Exp $
#	$NetBSD: Makefile.inc,v 1.1 1996/09/30 16:34:59 ws Exp $

.if !defined(__stand_makefile_inc)
__stand_makefile_inc=1

KERN_AS=	library

S=$(.CURDIR)/../../../$(R)

.if !make(libdep) && !make(sadep) && !make(salibdir) && !make(obj) && !defined(NOMACHINE)
.BEGIN:
	@([ -h machine ] || ln -s $(S)/arch/$(MACHINE)/include machine)
.endif

#
EXTRACFLAGS=	-msoft-float
REAL_VIRT?=	-v
ENTRY?=	_start

INCLUDES+=	-I. -I$(.OBJDIR) -I$(.CURDIR)/.. -I$(S)/arch -I$(S)
INCLUDES+=	-I$(S)/lib/libsa
DEFS+=		-DSTANDALONE
CFLAGS+=	$(INCLUDES) $(DEFS) $(EXTRACFLAGS)
CFLAGS+=	-fno-stack-protector
CFLAGS+=	-fno-builtin -fno-pie
AFLAGS+=	-fno-pie
LDFLAGS?=	-X -N -Ttext $(RELOC) -e $(ENTRY)

cleandir:
	rm -rf lib machine

.endif


code:
/*	$OpenBSD: alloc.c,v 1.8 2014/02/23 06:16:45 jsg Exp $	*/
/*	$NetBSD: alloc.c,v 1.1 1997/04/16 20:29:16 thorpej Exp $	*/

/*
 * Copyright (c) 1997 Jason R. Thorpe.  All rights reserved.
 * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
 * Copyright (c) 1996
 *	Matthias Drochner.  All rights reserved.
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */

/*
 * Dynamic memory allocator suitable for use with OpenFirmware.
 *
 * Compile options:
 *
 *	ALLOC_TRACE	enable tracing of allocations/deallocations
 *
 *	ALLOC_FIRST_FIT	use a first-fit allocation algorithm, rather than
 *			the default best-fit algorithm.
 *
 *	DEBUG		enable debugging sanity checks.
 */

#include <sys/param.h>
#include <sys/queue.h>

#include <lib/libsa/stand.h>

#include <macppc/stand/openfirm.h>

/*
 * Each block actually has ALIGN(struct ml) + ALIGN(size) bytes allocated
 * to it, as follows:
 *
 * 0 ... (sizeof(struct ml) - 1)
 *	allocated or unallocated: holds size of user-data part of block.
 *
 * sizeof(struct ml) ... (ALIGN(sizeof(struct ml)) - 1)
 *	allocated: unused
 *	unallocated: depends on packing of struct fl
 *
 * ALIGN(sizeof(struct ml)) ... (ALIGN(sizeof(struct ml)) +
 *   ALIGN(data size) - 1)
 *	allocated: user data
 *	unallocated: depends on packing of struct fl
 *
 * 'next' is only used when the block is unallocated (i.e. on the free list).
 * However, note that ALIGN(sizeof(struct ml)) + ALIGN(data size) must
 * be at least 'sizeof(struct fl)', so that blocks can be used as structures
 * when on the free list.
 */

/*
 * Memory lists.
 */
struct ml {
	unsigned	size;
	LIST_ENTRY(ml)	list;
};

LIST_HEAD(, ml) freelist = LIST_HEAD_INITIALIZER(freelist);
LIST_HEAD(, ml) allocatedlist = LIST_HEAD_INITIALIZER(allocatedlist);

#define	OVERHEAD	ALIGN(sizeof (struct ml))	/* shorthand */

void *
alloc(unsigned size)
{
	struct ml *f, *bestf = NULL;
	unsigned bestsize = 0xffffffff;	/* greater than any real size */
	char *help;
	int failed;

#ifdef ALLOC_TRACE
	printf("alloc(%u)", size);
#endif

	/*
	 * Account for overhead now, so that we don't get an
	 * "exact fit" which doesn't have enough space.
	 */
	size = ALIGN(size) + OVERHEAD;

#ifdef ALLOC_FIRST_FIT
	/* scan freelist */
	LIST_FOREACH(f, &freelist, list)
		if (f->size >= size)
			break;
	bestf = f;
	failed = (bestf == (struct fl *)0);
#else
	/* scan freelist */
	LIST_FOREACH(f, &freelist, list) {
		if (f->size >= size) {
			if (f->size == size)	/* exact match */
				goto found;

			if (f->size < bestsize) {
				/* keep best fit */
				bestf = f;
				bestsize = f->size;
			}
		}
	}

	/* no match in freelist if bestsize unchanged */
	failed = (bestsize == 0xffffffff);
#endif

	if (failed) {	/* nothing found */
		/*
		 * Allocate memory from the OpenFirmware, rounded
		 * to page size, and record the chunk size.
		 */
		size = roundup(size, PAGE_SIZE);
		help = OF_claim(0, size, PAGE_SIZE);
		if (help == (char *)-1)
			panic("alloc: out of memory");

		f = (struct ml *)help;
		f->size = size;
#ifdef ALLOC_TRACE
		printf("=%lx (new chunk size %u)\n",
		    (u_long)(help + OVERHEAD), f->size);
#endif
		goto out;
	}

	/* we take the best fit */
	f = bestf;

found:
	/* remove from freelist */
	LIST_REMOVE(f, list);
	help = (char *)f;
#ifdef ALLOC_TRACE
	printf("=%lx (origsize %u)\n", (u_long)(help + OVERHEAD), f->size);
#endif
out:
	/* place on allocated list */
	LIST_INSERT_HEAD(&allocatedlist, f, list);
	return (help + OVERHEAD);
}

void
free(void *ptr, unsigned size)
{
	register struct ml *a = (struct ml *)((char *)ptr - OVERHEAD);

#ifdef ALLOC_TRACE
	printf("free(%lx, %u) (origsize %u)\n", (u_long)ptr, size, a->size);
#endif
#ifdef DEBUG
	if (size > a->size)
		printf("free %u bytes @%lx, should be <=%u\n",
		    size, (u_long)ptr, a->size);
#endif

	/* Remove from allocated list, place on freelist. */
	LIST_REMOVE(a, list);
	LIST_INSERT_HEAD(&freelist, a, list);
}

void
freeall()
{
#ifdef __notyet__		/* Firmware bug ?! */
	struct ml *m;

	/* Release chunks on freelist... */
	while ((m = LIST_FIRST(&freelist)) != NULL) {
		LIST_REMOVE(m, list);
		OF_release(m, m->size);
	}

	/* ...and allocated list. */
	while ((m = LIST_FIRST(&allocated)) != NULL) {
		LIST_REMOVE(m, list);
		OF_release(m, m->size);
	}
#endif /* __notyet__ */
}


code:
.\"	$OpenBSD: boot.8,v 1.2 2015/06/22 18:31:49 jmc Exp $
.\"
.\" Copyright (c) 1997-2001 Michael Shalayeff
.\" All rights reserved.
.\"
.\" 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.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR OR HIS RELATIVES 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 MIND, 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.
.\"
.\"
.Dd $Mdocdate: June 22 2015 $
.Dt BOOT 8 macppc
.Os
.Sh NAME
.Nm boot ,
.Nm boot.conf
.Nd macppc-specific bootstrap
.Sh DESCRIPTION
The main purpose of this program is to load the system kernel.
.Pp
As described in
.Xr boot_macppc 8 ,
this program is loaded by the
firmware
and provides a convenient way to load the kernel.
This program acts as an enhanced boot monitor for macppc systems, providing
a common interface for the kernel to start from.
.Pp
Basic operations include:
.Pp
.Bl -bullet -compact
.It
Loading kernels from hard disk.
.It
Loading kernels compressed by
.Xr gzip 1 .
.It
Providing an interactive command line.
.El
.Pp
The sequence of its operation is as follows: initialization,
parsing the configuration file, then an interactive command line.
While at the command line you have 5 seconds to type any commands, if needed.
If time expires, the kernel will be loaded according to
the current variable settings (see the
.Nm set
command).
Each time a kernel load fails, the timeout is increased by one second.
The sequence of
.Nm
operations is as follows:
.Bl -enum
.It
If the file
.Pa /etc/boot.conf
.\" XXX BEWARE! wd0 only, so text change...
.\" exists on the filesystem
.\" .Nm
.\" was loaded from, open and parse it.
exists on the filesystem in slice
.Sq a
on the first disk drive
.Pq wd0 ,
open and parse it.
Lines beginning with the
.Sq #
character,
as well as whitespace at the beginning of lines,
are ignored.
The file may contain any commands
.Nm
accepts at the interactive prompt.
Though default settings usually suffice, they can be changed here.
.\" XXX CHECK_SKIP_CONF is not defined...
.\" .Pp
.\" .Pa boot.conf
.\" processing can be skipped by holding down either Control key as
.\" .Nm
.\" starts.
.It
The header line
.Pp
.Dl >> OpenBSD/macppc BOOT [x.xx]
.Pp
is displayed to the active console, where
.Ar x.xx
is the version number of the
.Nm
program, followed by the
.Pp
.Dl boot>
.Pp
prompt, which means you are in interactive mode and may enter commands.
If you do not,
.Nm
will proceed to load the kernel with the current parameters after the
timeout period has expired.
.El
.Pp
By default,
.Nm
attempts to load the kernel executable
.Pa /bsd .
If it fails to find the kernel and no alternative kernel image has
been specified, the system will be unable to boot.
.Sh COMMANDS
The following commands are accepted at the
.Nm
prompt:
.Bl -tag -width shorten
.It boot Op Ar image Op Fl acds
Boots the kernel image specified by
.Ar image
with any options given.
Image specification consists of a pair
.Ar device : Ns Ar filename ;
either or both can be omitted (`:' is not needed if both are omitted),
in which case values from
.Nm
variables will be used.
.Pp
The only bootable devices, at the moment, are IDE devices connected to
the internal controller;
they are detected as
.Sq wd
devices.
Therefore, to boot kernel
.Pa /bsd
from slice
.Sq a
on the first hard drive,
specify
.Dq boot wd0a:/bsd .
.Bl -tag -width _a_
.It Fl a
Causes the kernel to ask for the
.Nm root
device to use.
.It Fl c
Causes the kernel to go into
.Xr boot_config 8
before performing
.Xr autoconf 4
procedures.
.It Fl d
Causes the kernel to drop into
.Xr ddb 4
at the earliest convenient point.
.It Fl s
Causes the kernel to boot single-user.
.El
.It echo Op Ar args
Displays
.Ar args
on the console device.
.It help
Prints a list of available commands.
.It ls Op Ar directory
Prints contents of the specified
.Ar directory
in long format including: attributes and file type, owner, group,
size, filename.
.It reboot
Reboots the machine by initiating a warm boot procedure.
.It set Op Ar varname Op Ar value
If invoked without arguments, prints a list of variables and their values.
If only
.Ar varname
is specified, displays contents of that variable.
If
.Ar varname
and
.Ar value
are both specified, sets that variable to the given value.
Variables include:
.Pp
.Bl -tag -compact -width boothow
.It Nm addr
Address at which to load the kernel.
.It Nm debug
Debug flag if
.Nm
was compiled with DEBUG defined.
.It Nm device
Boot device name (e.g.,
.Li wd0a ,
.Li wd1a ) .
.It Nm howto
Options to pass to the loaded kernel.
.It Nm image
File name containing the kernel image.
.It Nm timeout
Number of seconds boot will wait for human intervention before
booting the default kernel image.
.\" .It Nm tty
.\" Active console device name (e.g.,
.\" .Li com0 ) .
.\" Currently, only the first serial port
.\" .Pq Li com0
.\" is supported for console on macppc.
.El
.\" XXX ignored, so don't document it.
.\" .It stty Op Ar device Op Ar speed
.\" Displays or sets the
.\" .Ar speed
.\" for a console
.\" .Ar device .
.\" If changing the baudrate for the currently active console,
.\" .Nm
.\" offers you five seconds of grace time before committing the change
.\" to allow you to change your terminal's speed to match.
.\" If changing speed
.\" .Em not
.\" for the active console, the baudrate is set for the
.\" .Em next
.\" time you switch to a serial console.
.\" .Pp
.\" The default baudrate is 9600bps.
.It time
Displays system time and date.
.El
.Sh FILES
.Bl -tag -width /etc/boot.conf -compact
.It Pa /usr/mdec/boot
system bootstrap
.It Pa /etc/boot.conf
system bootstrap's startup file
.It Pa /bsd
kernel image
.It Pa /bsd.rd
kernel image for installation/recovery
.El
.Sh EXAMPLES
Boot the default kernel:
.Pp
.Dl boot> boot
.Pp
Remove the 5 second pause at boot-time permanently, causing
.Nm
to load the kernel immediately without prompting:
.Pp
.Dl # echo \&"boot\&" > /etc/boot.conf
.Pp
Boot the kernel named
.Pa /bsd
from the second hard disk in
.Dq User Kernel Configuration
mode (see
.Xr boot_config 8 ) .
This mechanism allows for the explicit enabling and disabling of devices
during the current boot sequence, as well as the modification
of device parameters.
Once booted, such changes can be made permanent by using
.Xr config 8 Ns 's
.Fl e
option.
.Pp
.Dl boot> boot wd1a:/bsd -c
.Sh SEE ALSO
.Xr gzip 1 ,
.Xr autoconf 4 ,
.Xr ddb 4 ,
.Xr boot_config 8 ,
.Xr boot_macppc 8 ,
.Xr fdisk 8 ,
.Xr reboot 8
.Sh HISTORY
This program was written by Michael Shalayeff for
.Ox 2.1
on the i386 platform, and was later ported to the macppc platform.


code:
#	$OpenBSD: Makefile,v 1.12 2014/11/19 20:02:46 miod Exp $
#       $NetBSD: Makefile,v 1.1 1996/09/30 16:35:05 ws Exp $

S=      ${.CURDIR}/../../../..
R=              ..
.PATH:          $(.CURDIR)/$(R)
RELOC=		E00000
ENTRY=		_entry
NOMAN=
PROG=           boot.mac
SRCS=           Locore.c main.c ofdev.c net.c netif_of.c netudp.c
SRCS+=		alloc.c cache.c hfs.c
SRCS+=          boot.c conf.c cmd.c vars.c ctime.c strtol.c

INSTALL_STRIP=
BINDIR=         /usr/mdec
OBJCOPY?=	objcopy
OBJCOPY_ARGS=	-O aixcoff-rs6000 -R .comment -R .note
LDFLAGS=	-nopie -X -Ttext ${RELOC} -e $(ENTRY)
LDFLAGS+=	-T ${.CURDIR}/elf32_powerpc_merge.x -Bstatic

.PATH:          ${S}/stand/boot
.PATH:          ${S}/lib/libsa
SRCS+=		getchar.c

.PATH:		${S}/lib/libkern/arch/powerpc ${S}/lib/libkern
SRCS+=		strlcpy.c memcpy.c strlen.c strrchr.c strlcat.c ashrdi3.c
SRCS+=		moddi3.c

CPPFLAGS+=	-I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../..
CPPFLAGS+=	-DRELOC=0x${RELOC} -DCONSPEED=57600
# for booting PCI Powermacs
CPPFLAGS+=	-DXCOFF_GLUE
CFLAGS+=	-fno-pie

LIBS!=          cd $(.CURDIR)/$(R); $(MAKE) libdep
CLEANFILES=	fixcoff

$(PROG):        $(OBJS) $(LIBS) fixcoff
	$(LD) $(LDFLAGS) $(OBJS) $(LIBS) -o ${.TARGET}
	${OBJCOPY} ${OBJCOPY_ARGS} ${.TARGET}
	${.OBJDIR}/fixcoff ${.TARGET}

fixcoff:	fixcoff.c
	${HOSTCC} -I${.CURDIR} -o fixcoff ${.CURDIR}/fixcoff.c

.include <bsd.prog.mk>


code:
/* $OpenBSD: elf32_powerpc_merge.x,v 1.2 2013/07/16 08:03:18 mpi Exp $ */
OUTPUT_ARCH(powerpc)
SECTIONS
{
  /* Read-only sections, merged into text segment: */
  . = + SIZEOF_HEADERS;
  .interp : { *(.interp) }
  .hash          : { *(.hash)		}
  .dynsym        : { *(.dynsym)		}
  .dynstr        : { *(.dynstr)		}
  .rel.text      : { *(.rel.text)		}
  .rela.text     : { *(.rela.text) 	}
  .rel.data      : { *(.rel.data)		}
  .rela.data     : { *(.rela.data) 	}
  .rel.rodata    : { *(.rel.rodata) 	}
  .rela.rodata   : { *(.rela.rodata) 	}
  .rel.got       : { *(.rel.got)		}
  .rela.got      : { *(.rela.got)		}
  .rel.ctors     : { *(.rel.ctors)	}
  .rela.ctors    : { *(.rela.ctors)	}
  .rel.dtors     : { *(.rel.dtors)	}
  .rela.dtors    : { *(.rela.dtors)	}
  .rel.bss       : { *(.rel.bss)		}
  .rela.bss      : { *(.rela.bss)		}
  .rel.plt       : { *(.rel.plt)		}
  .rela.plt      : { *(.rela.plt)		}
  .init          : { *(.init)	} =0
  .plt : { *(.plt) }
  .text      :
  {
    *(.text)
    *(.rodata)
    *(.rodata.*)
    *(.rodata1)
    *(.got1)
  }
  .fini      : { *(.fini)    } =0
  .ctors     : { *(.ctors)   }
  .dtors     : { *(.dtors)   }
  _etext = .;
  PROVIDE (etext = .);
  /* Read-write section, merged into data segment: */
  . = (. + 0x0FFF) & 0xFFFFF000;
  .data    :
  {
    *(.data)
    *(.data1)
    *(.sdata)
    *(.sdata2)
    *(.got.plt) *(.got)
    *(.dynamic)
    CONSTRUCTORS
  }
  _edata  =  .;
  PROVIDE (edata = .);
  __bss_start = .;
  .bss       :
  {
   *(.sbss) *(.scommon)
   *(.dynbss)
   *(.bss)
   *(COMMON)
  }
  _end = . ;
  PROVIDE (end = .);
}


code:
/*	$OpenBSD: fixcoff.c,v 1.2 2013/07/16 08:03:18 mpi Exp $ */
/*	$NetBSD: fixcoff.c,v 1.10 2006/04/07 02:34:55 gdamore Exp $ */

/*
 * Copyright (c) 1999 National Aeronautics & Space Administration
 * All rights reserved.
 *
 * This software was written by William Studenmund of the
 * Numerical Aerospace Similation Facility, NASA Ames Research Center.
 *
 * 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 National Aeronautics & Space Administration
 *    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 NATIONAL AERONAUTICS & SPACE ADMINISTRATION
 * ``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 ADMINISTRATION OR CONTRIB-
 * UTORS 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.
 */

/*
 * This program fixes up the extended xcoff headers generated when an elf
 * file is turned into an xcoff one with the current objcopy. It should
 * go away someday, when objcopy will correctly fix up the output xcoff
 *
 * Partially inspired by hack-coff, written by Paul Mackerras.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

#include <sys/endian.h>

struct filehdr {
#define U802WRMAGIC     0730
#define U802ROMAGIC     0735
#define U802TOCMAGIC    0737
	char f_magic[2];
	char f_nsect[2];
	char f_time[4];
	char f_symtab[4];
	char f_nsyms[4];
	char f_opthdr[2];
	char f_flags[2];
};

struct sectionhdr {
	char	s_name[8];
	char	s_paddr[4];
	char	s_vaddr[4];
	char	s_size[4];
	char	s_section[4];
	char	s_reloc[4];
	char	s_lineno[4];
	char	s_nreloc[2];
	char	s_nlineno[2];
	char	s_flags[4];
};

struct aouthdr {
	char	magic[2];
	char	vstamp[2];
	char	tsize[4];
	char	dsize[4];
	char	bsize[4];
	char	entry[4];
	char	text_start[4];
	char	data_start[4];
#define SMALL_AOUTSZ	28
	char	o_toc[4];
	char	o_snentry[2];
	char	o_sntext[2];
	char	o_sndata[2];
	char	o_sntoc[2];
	char	o_snloader[2];
	char	o_snbss[2];
	char	o_algntext[2];
	char	o_algndata[2];
	char	o_modtype[2];
	char	o_cputype[2];
	char	o_maxstack[4];
	char	o_maxdata[4];
	char	o_resv2[12];
};
#define RS6K_AOUTHDR_ZMAGIC     0x010B

char *progname;

void
usage(char *prog)
{
	fprintf(stderr, "Usage: %s [-h] | [<file to fix>]\n", prog);
}

void
help(char *prog)
{
	fprintf(stderr, "%s\tis designed to fix the xcoff headers in a\n",prog);
	fprintf(stderr,
"\tbinary generated using objcopy from a non-xcoff source.\n");
	usage(prog);
	exit(0);
}

main(int argc, char *argv[])
{
	int	fd, i, n, ch;
	struct	filehdr	fh;
	struct	aouthdr aoh;
	struct	sectionhdr sh;

	progname = argv[0];
	while ((ch = getopt(argc, argv, "h")) != -1)
	    switch (ch) {
		case 'h':
		help(progname);
	}

	argc -= optind;
	argv += optind;

	if (argc != 1) {
		usage(progname);
		exit(1);
	}

	if ((fd = open(argv[0], O_RDWR, 0)) == -1)
		err(1, "%s", argv[0]);

	/*
	 * Make sure it looks like an xcoff file..
	 */
	if (read(fd, &fh, sizeof(fh)) != sizeof(fh))
		err(1, "%s reading header", argv[0]);

	i = betoh16(*(uint16_t *)fh.f_magic);
	if ((i != U802WRMAGIC) && (i != U802ROMAGIC) && (i != U802TOCMAGIC))
		errx(1, "%s: not a valid xcoff file", argv[0]);

	/* Does the AOUT "Optional header" make sense? */
	i = betoh16(*(uint16_t *)fh.f_opthdr);

	if (i == SMALL_AOUTSZ)
		errx(1, "%s: file has small \"optional\" header, inappropriate for use with %s", argv[0], progname);
	else if (i != sizeof(aoh))
		errx(1, "%s: invalid \"optional\" header", argv[0]);

	if (read(fd, &aoh, i) != i)
		err(1, "%s reading \"optional\" header", argv[0]);

	/* Now start filing in the AOUT header */
	*(uint16_t *)aoh.magic = htobe16(RS6K_AOUTHDR_ZMAGIC);
	n = betoh16(*(uint16_t *)fh.f_nsect);

	for (i = 0; i < n; i++) {
		if (read(fd, &sh, sizeof(sh)) != sizeof(sh))
			err(1, "%s reading section headers", argv[0]);
		if (strcmp(sh.s_name, ".text") == 0) {
			*(uint16_t *)(aoh.o_snentry) = htobe16(i+1);
			*(uint16_t *)(aoh.o_sntext) = htobe16(i+1);
		} else if (strcmp(sh.s_name, ".data") == 0) {
			*(uint16_t *)(aoh.o_sndata) = htobe16(i+1);
		} else if (strcmp(sh.s_name, ".bss") == 0) {
			*(uint16_t *)(aoh.o_snbss) = htobe16(i+1);
		}
	}

	/* now write it out */
	if (pwrite(fd, &aoh, sizeof(aoh), sizeof(struct filehdr)) !=
	    sizeof(aoh))
		err(1, "%s writing modified header", argv[0]);
	close(fd);
	exit(0);
}


code:
/*	$OpenBSD: cache.c,v 1.2 2003/10/16 04:30:09 drahn Exp $	*/
#define CACHELINESIZE   32                      /* For now              XXX */

void
syncicache(void *from, int len)
{
	int l = len;
	void *p = from;

	do {
		asm volatile ("dcbf %1,%0" :: "r"(p), "r"(0));
		p += CACHELINESIZE;
	} while ((l -= CACHELINESIZE) > 0);
	asm volatile ("sync");
	do {
		asm volatile ("icbi %1,%0" :: "r"(from), "r"(0));
		from += CACHELINESIZE;
	} while ((len -= CACHELINESIZE) > 0);
	asm volatile ("isync");
}


code:
/*	$OpenBSD: conf.c,v 1.7 2015/03/23 20:18:52 miod Exp $	*/
/*
 * Copyright (c) 2007 Dale Rahn <drahn@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */
#include <sys/param.h>

#include <dev/cons.h>

#include <lib/libsa/stand.h>

const char version[] = "1.5";
int     debug = 0;

void ofc_probe(struct consdev *);
void ofc_init(struct consdev *);
int ofc_getc(dev_t);
void ofc_putc(dev_t, int);

struct consdev *cn_tab;

struct consdev constab[] = {
	{ ofc_probe, ofc_init, ofc_getc, ofc_putc },
	{ NULL }
};


code:
/*	$OpenBSD: hfs.c,v 1.6 2015/03/14 20:52:41 miod Exp $	*/
/*	$NetBSD: hfs.c,v 1.1 2000/11/14 11:25:35 tsubai Exp $	*/

/*-
 * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
 *
 * 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. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
 */

#include <sys/param.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>

#include <openfirm.h>
#include <hfs.h>

static int OF_fd;	/* XXX */

int
hfs_open(char *path, struct open_file *f)
{
	int chosen;
	char bootpath[128], *cp;

	if ((chosen = OF_finddevice("/chosen")) == -1)
		return ENXIO;
	bzero(bootpath, sizeof bootpath);
	OF_getprop(chosen, "bootpath", bootpath, sizeof bootpath);

	cp = strrchr(bootpath, ',');
	if (cp == NULL)
		return ENXIO;

	strlcpy(cp + 1, path, bootpath + sizeof bootpath - (cp + 1));
	OF_fd = OF_open(bootpath);
	if (OF_fd == -1)
		return ENOENT;
	return 0;
}

int
hfs_close(struct open_file *f)
{
	OF_close(OF_fd);
	return 0;
}

int
hfs_read(struct open_file *f, void *start, size_t size, size_t *resid)
{
	int len;

	len = OF_read(OF_fd, start, size);
	if (len == -1)
		return EIO;
	size -= len;
	if (resid)
		*resid = size;
	return 0;
}

int
hfs_write(struct open_file *f, void *start, size_t size, size_t *resid)
{
	printf("hfs_write\n");
	return ENXIO;
}

off_t
hfs_seek(struct open_file *f, off_t offset, int where)
{
	switch (where) {
	case SEEK_SET:
		return OF_seek(OF_fd, offset);
	case SEEK_CUR:
	case SEEK_END:
	default:
		return -1;
	}
}

int
hfs_stat(struct open_file *f, struct stat *sb)
{
	return 0;
}

int
hfs_readdir(struct open_file *f, char *name)
{
	return ENXIO;
}


code:
/*	$OpenBSD: hfs.h,v 1.2 2015/03/14 20:52:41 miod Exp $	*/
/*	$NetBSD: hfs.h,v 1.1 2000/11/14 11:25:35 tsubai Exp $	*/

int hfs_open(char *, struct open_file *);
int hfs_close(struct open_file *);
int hfs_read(struct open_file *, void *, size_t, size_t *);
int hfs_write(struct open_file *, void *, size_t, size_t *);
off_t hfs_seek(struct open_file *, off_t, int);
int hfs_stat(struct open_file *, struct stat *);
int hfs_readdir(struct open_file *, char *);


code:
/*      $OpenBSD: libsa.h,v 1.1 2007/06/13 02:17:32 drahn Exp $      */

/*
 * Copyright (c) 2006 Mark Kettenis
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <lib/libsa/stand.h>

#define DEFAULT_KERNEL_ADDRESS  0


code:
/*	$OpenBSD: main.c,v 1.8 2013/03/21 21:51:00 deraadt Exp $	*/
/*	$NetBSD: boot.c,v 1.1 1997/04/16 20:29:17 thorpej Exp $	*/

/*
 * Copyright (c) 1997 Jason R. Thorpe.  All rights reserved.
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * ELF support derived from NetBSD/alpha's boot loader, written
 * by Christopher G. Demetriou.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */

/*
 * First try for the boot code
 *
 * Input syntax is:
 *	[promdev[{:|,}partition]]/[filename] [flags]
 */

#define	ELFSIZE		32		/* We use 32-bit ELF. */

#include <sys/param.h>
#include <sys/exec.h>
#include <sys/exec_elf.h>
#include <sys/reboot.h>
#include <sys/disklabel.h>

#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
#include <lib/libsa/loadfile.h>
#include <stand/boot/cmd.h>

#include <machine/cpu.h>

#include <macppc/stand/ofdev.h>
#include <macppc/stand/openfirm.h>

char bootdev[128];
int boothowto;
int debug;

void
get_alt_bootdev(char *, size_t, char *, size_t);

static void
prom2boot(char *dev)
{
	char *cp, *lp = 0;

	for (cp = dev; *cp; cp++)
		if (*cp == ':')
			lp = cp;
	if (!lp)
		lp = cp;
	*lp = 0;
}

static void
chain(void (*entry)(), char *args, void *ssym, void *esym)
{
	extern char end[];
	int l;
#ifdef __notyet__
	int machine_tag;
#endif

	freeall();

	/*
	 * Stash pointer to end of symbol table after the argument
	 * strings.
	 */
	l = strlen(args) + 1;
	bcopy(&ssym, args + l, sizeof(ssym));
	l += sizeof(ssym);
	bcopy(&esym, args + l, sizeof(esym));
	l += sizeof(esym);

#ifdef __notyet__
	/*
	 * Tell the kernel we're an OpenFirmware system.
	 */
	machine_tag = POWERPC_MACHINE_OPENFIRMWARE;
	bcopy(&machine_tag, args + l, sizeof(machine_tag));
	l += sizeof(machine_tag);
#endif

	OF_chain((void *)RELOC, end - (char *)RELOC, entry, args, l);
	panic("chain");
}

/*
 * XXX This limits the maximum size of the (uncompressed) bsd.rd to a
 * little under 11MB.
 */
#define CLAIM_LIMIT	0x00c00000

char bootline[512];

extern char *kernelfile;
int
main()
{
	int chosen;

	/*
	 * Get the boot arguments from Openfirmware
	 */
	if ((chosen = OF_finddevice("/chosen")) == -1 ||
	    OF_getprop(chosen, "bootpath", bootdev, sizeof bootdev) < 0 ||
	    OF_getprop(chosen, "bootargs", bootline, sizeof bootline) < 0) {
		printf("Invalid Openfirmware environment\n");
		exit();
	}
	prom2boot(bootdev);
	get_alt_bootdev(bootdev, sizeof(bootdev), bootline, sizeof(bootline));
	if (bootline[0] != '\0')
		kernelfile = bootline;

	OF_claim((void *)0x00100000, CLAIM_LIMIT, 0); /* XXX */
	boot(0);
	return 0;
}

void
get_alt_bootdev(char *dev, size_t devsz, char *line, size_t linesz)
{
	char *p;
	int len;
	/*
	 * if the kernel image specified contains a ':' it is
	 * [device]:[kernel], so separate the two fields.
	 */
	p = strrchr(line, ':');
	if (p == NULL)
		return;
	/* user specified boot device for kernel */
	len = p - line + 1; /* str len plus nil */
	strlcpy(dev, line, len > devsz ? devsz : len);

	strlcpy(line, p+1, linesz); /* rest of string after ':' */
}

void
devboot(dev_t dev, char *p)
{
	strlcpy(p, bootdev, BOOTDEVLEN);
}

int
run_loadfile(u_long *marks, int howto)
{
	char bootline[512];		/* Should check size? */
	u_int32_t entry;
	char *cp;
	void *ssym, *esym;

	strlcpy(bootline, opened_name, sizeof bootline);
	cp = bootline + strlen(bootline);
	*cp++ = ' ';
        *cp = '-';
        if (howto & RB_ASKNAME)
                *++cp = 'a';
        if (howto & RB_CONFIG)
                *++cp = 'c';
        if (howto & RB_SINGLE)
                *++cp = 's';
        if (howto & RB_KDB)
                *++cp = 'd';
        if (*cp == '-')
		*--cp = 0;
	else
		*++cp = 0;

	entry = marks[MARK_ENTRY];
	ssym = (void *)marks[MARK_SYM];
	esym = (void *)marks[MARK_END];
	{
		u_int32_t lastpage;
		lastpage = roundup(marks[MARK_END], PAGE_SIZE);
		OF_release((void*)lastpage, CLAIM_LIMIT - lastpage);
	}

	chain((void *)entry, bootline, ssym, esym);

	_rtt();
	return 0;
}

int
cnspeed(dev_t dev, int sp)
{
	return CONSPEED;
}

char ttyname_buf[8];

char *
ttyname(int fd)
{
        snprintf(ttyname_buf, sizeof ttyname_buf, "ofc0");
	return ttyname_buf;
}

dev_t
ttydev(char *name)
{
	return makedev(0,0);
}


path: sys/arch/macppc/stand/mbr/CVS/Entries


path: sys/arch/macppc/stand/mbr/CVS/Tag


code:
#	$OpenBSD: Makefile,v 1.4 2012/10/14 04:12:05 deraadt Exp $

CLEANFILES= mbr

all: mbr

mbr: mbr.uu
	uudecode ${.CURDIR}/mbr.uu

realinstall:
	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 444 mbr ${DESTDIR}/usr/mdec

.include <bsd.prog.mk>

path: sys/arch/macppc/stand/mbr/Makefile


code:
/*	$OpenBSD: net.c,v 1.5 2014/08/21 14:24:08 mpi Exp $	*/
/*	$NetBSD: net.c,v 1.1 1997/04/16 20:29:18 thorpej Exp $	*/

/*
 * Copyright (C) 1995 Wolfgang Solfrank.
 * Copyright (C) 1995 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */

/*
 * This module implements a "raw device" interface suitable for
 * use by the stand-alone I/O library NFS code.  This interface
 * does not support any "block" access, and exists only for the
 * purpose of initializing the network interface, getting boot
 * parameters, and performing the NFS mount.
 *
 * At open time, this does:
 *
 * find interface	- netif_open()
 * BOOTP		- bootp()
 * RPC/mountd		- nfs_mount()
 *
 * The root file handle from mountd is saved in a global
 * for use by the NFS open code (NFS/lookup).
 *
 * Note: this is based in part on sys/arch/sparc/stand/net.c
 */

#include <sys/param.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>

#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>

char	rootpath[FNAME_SIZE];

static	int netdev_sock = -1;
static	int open_count;

/*
 * Called by devopen after it sets f->f_dev to our devsw entry.
 * This opens the low-level device and sets f->f_devdata.
 */
int
net_open(struct of_dev *op)
{
	int error = 0;

	/*
	 * On first open, do netif open, mount, etc.
	 */
	if (open_count == 0) {
		/* Find network interface. */
		if ((netdev_sock = netif_open(op)) < 0) {
			error = errno;
			goto bad;
		}
		if ((error = net_mountroot()) != 0)
			goto bad;
	}
	open_count++;
bad:
	if (netdev_sock >= 0 && open_count == 0) {
		netif_close(netdev_sock);
		netdev_sock = -1;
	}
	return error;
}

int
net_close(struct of_dev *op)
{
	/*
	 * On last close, do netif close, etc.
	 */
	if (open_count > 0)
		if (--open_count == 0) {
			netif_close(netdev_sock);
			netdev_sock = -1;
		}
}

int
net_mountroot()
{

#ifdef	DEBUG
	printf("net_mountroot\n");
#endif

	/*
	 * Get info for NFS boot: our IP address, out hostname,
	 * server IP address, and our root path on the server.
	 * We use BOOTP (RFC951, RFC1532) exclusively as mandated
	 * by PowerPC Reference Platform Specification I.4.2
	 */

	bootp(netdev_sock);

	if (myip.s_addr == 0)
		return ETIMEDOUT;

	printf("Using IP address: %s\n", inet_ntoa(myip));

#ifdef	DEBUG
	printf("myip: %s (%s)", hostname, inet_ntoa(myip));
	if (gateip.s_addr)
		printf(", gateip: %s", inet_ntoa(gateip));
	if (netmask)
		printf(", netmask: %s", intoa(netmask));
	printf("\n");
#endif
	printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);

	/*
	 * Get the NFS file handle (mount).
	 */
	if (nfs_mount(netdev_sock, rootip, rootpath) < 0)
		return errno;
	return 0;
}


code:
/*	$OpenBSD: netif_of.c,v 1.6 2014/08/21 14:24:08 mpi Exp $	*/
/*	$NetBSD: netif_of.c,v 1.1 1997/04/16 20:29:19 thorpej Exp $	*/

/*
 * Copyright (C) 1995 Wolfgang Solfrank.
 * Copyright (C) 1995 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */

/*
 * Open Firmware does most of the job for interfacing to the hardware,
 * so it is easiest to just replace the netif module with
 * this adaptation to the PROM network interface.
 *
 * Note: this is based in part on sys/arch/sparc/stand/netif_sun.c
 */

#include <sys/param.h>
#include <sys/socket.h>

#if 0			/* XXX thorpej */
#include <string.h>
#include <time.h>
#endif

#include <net/if.h>

#include <netinet/in.h>
#include <netinet/if_ether.h>

#include <lib/libsa/stand.h>
#include <lib/libsa/net.h>
#include <lib/libsa/netif.h>

#include <macppc/stand/ofdev.h>
#include <macppc/stand/openfirm.h>

static struct netif netif_of;

struct iodesc sockets[SOPEN_MAX];

struct iodesc *
socktodesc(int sock)
{
	if (sock != 0)
		return NULL;
	return sockets;
}

int
netif_open(void *machdep_hint)
{
	struct of_dev *op = machdep_hint;
	struct iodesc *io;

#ifdef	NETIF_DEBUG
	printf("netif_open...");
#endif
	/* find a free socket */
	io = sockets;
	if (io->io_netif) {
#ifdef	NETIF_DEBUG
		printf("device busy\n");
#endif
		errno = ENFILE;
		return -1;
	}
	bzero(io, sizeof *io);

	netif_of.nif_devdata = op;
	io->io_netif = &netif_of;

	/* Put our ethernet address in io->myea */
	OF_getprop(OF_instance_to_package(op->handle),
		   "local-mac-address", io->myea, sizeof io->myea) == -1 &&
	OF_getprop(OF_instance_to_package(op->handle),
		   "mac-address", io->myea, sizeof io->myea);

#ifdef	NETIF_DEBUG
	printf("OK\n");
#endif
	return 0;
}

int
netif_close(int fd)
{
	struct iodesc *io;
	struct netif *ni;

#ifdef	NETIF_DEBUG
	printf("netif_close(%x)...", fd);
#endif
	if (fd != 0) {
#ifdef	NETIF_DEBUG
		printf("EBADF\n");
#endif
		errno = EBADF;
		return -1;
	}

	io = &sockets[fd];
	ni = io->io_netif;
	if (ni != NULL) {
		ni->nif_devdata = NULL;
		io->io_netif = NULL;
	}
#ifdef	NETIF_DEBUG
	printf("OK\n");
#endif
	return 0;
}

/*
 * Send a packet.  The ether header is already there.
 * Return the length sent (or -1 on error).
 */
ssize_t
netif_put(struct iodesc *desc, void *pkt, size_t len)
{
	struct of_dev *op;
	ssize_t rv;
	size_t sendlen;

	op = desc->io_netif->nif_devdata;

#ifdef	NETIF_DEBUG
	{
		struct ether_header *eh;

		printf("netif_put: desc=0x%x pkt=0x%x len=%d\n",
		       desc, pkt, len);
		eh = pkt;
		printf("dst: %s ", ether_sprintf(eh->ether_dhost));
		printf("src: %s ", ether_sprintf(eh->ether_shost));
		printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
	}
#endif

	sendlen = len;
	if (sendlen < 60) {
		sendlen = 60;
#ifdef	NETIF_DEBUG
		printf("netif_put: length padded to %d\n", sendlen);
#endif
	}

	if (op->dmabuf) {
		bcopy(pkt, op->dmabuf, sendlen);
		pkt = op->dmabuf;
	}
	rv = OF_write(op->handle, pkt, sendlen);

#ifdef	NETIF_DEBUG
	printf("netif_put: xmit returned %d\n", rv);
#endif

	return rv;
}

/*
 * Receive a packet, including the ether header.
 * Return the total length received (or -1 on error).
 */
ssize_t
netif_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timo)
{
	struct of_dev *op;
	int tick0, tmo_ms;
	int len;

	op = desc->io_netif->nif_devdata;

#ifdef	NETIF_DEBUG
	printf("netif_get: pkt=0x%x, maxlen=%d, tmo=%d\n",
	   pkt, maxlen, timo);
#endif

	tmo_ms = timo * 1000;
	tick0 = OF_milliseconds();

	do {
		len = OF_read(op->handle, pkt, maxlen);
	} while ((len == -2 || len == 0) &&
	     ((OF_milliseconds() - tick0) < tmo_ms));

#ifdef	NETIF_DEBUG
	printf("netif_get: received len=%d\n", len);
#endif

	if (len < 12)
		return -1;

#ifdef	NETIF_DEBUG
	{
		struct ether_header *eh = pkt;

		printf("dst: %s ", ether_sprintf(eh->ether_dhost));
		printf("src: %s ", ether_sprintf(eh->ether_shost));
		printf("type: 0x%x\n", eh->ether_type & 0xFFFF);
	}
#endif

	return len;
}

/*
 * Shouldn't really be here, but is used solely for networking, so...
 */
time_t
getsecs()
{
	return OF_milliseconds() / 1000;
}


code:
/*	$OpenBSD: ofdev.c,v 1.22 2015/03/23 20:18:52 miod Exp $	*/
/*	$NetBSD: ofdev.c,v 1.1 1997/04/16 20:29:20 thorpej Exp $	*/

/*
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */
/*
 * Device I/O routines using Open Firmware
 */
#include <sys/param.h>
#include <lib/libkern/libkern.h>
#include <sys/disklabel.h>
#include <netinet/in.h>

#include <lib/libsa/stand.h>
#include <lib/libsa/ufs.h>
#include <lib/libsa/cd9660.h>
#include <lib/libsa/nfs.h>
#include <hfs.h>

#include <macppc/stand/ofdev.h>

extern char bootdev[];

char opened_name[256];

/*
 * this function is passed [device specifier]:[kernel]
 * however a device specifier may contain a ':'
 */
static int
parsename(char *str, char **file)
{
	char *cp;
	int aliases;
	size_t len;

	cp = strrchr(str, ':');
	if (cp == NULL)
		return 1;

	*cp++ = 0;

	if ((aliases = OF_finddevice("/aliases")) == -1 ||
	    OF_getprop(aliases, str, opened_name, sizeof opened_name) < 0)
		strlcpy(opened_name, str, sizeof opened_name);

	len = strlcat(opened_name, ":", sizeof opened_name);
	if (*cp != '/')
		strlcat(opened_name, "/", sizeof opened_name);

	if (strlcat(opened_name, cp, sizeof opened_name) >= sizeof opened_name)
		return 1;

	*file = opened_name + len + 1;

	return 0;
}

static int
strategy(void *devdata, int rw, daddr32_t blk, size_t size, void *buf,
    size_t *rsize)
{
	struct of_dev *dev = devdata;
	u_quad_t pos;
	int n;

	if (rw != F_READ)
		return EPERM;
	if (dev->type != OFDEV_DISK)
		panic("strategy");

	pos = (u_quad_t)(blk + dev->partoff) * dev->bsize;

	for (;;) {
		if (OF_seek(dev->handle, pos) < 0)
			break;
		n = OF_read(dev->handle, buf, size);
		if (n == -2)
			continue;
		if (n < 0)
			break;
		*rsize = n;
		return 0;
	}
	return EIO;
}

static int
devclose(struct open_file *of)
{
	struct of_dev *op = of->f_devdata;

	if (op->type == OFDEV_NET)
		net_close(op);
	if (op->dmabuf)
		OF_call_method("dma-free", op->handle, 2, 0,
		    op->dmabuf, MAXBSIZE);

	OF_close(op->handle);
	free(op, sizeof *op);
}

struct devsw devsw[1] = {
	"OpenFirmware",
	strategy,
	(int (*)(struct open_file *, ...))nodev,
	devclose,
	noioctl
};
int ndevs = sizeof devsw / sizeof devsw[0];

static struct fs_ops file_system_ufs = {
	ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat,
	ufs_readdir
};
static struct fs_ops file_system_cd9660 = {
	cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek,
	cd9660_stat, cd9660_readdir
};
static struct fs_ops file_system_hfs = {
	hfs_open, hfs_close, hfs_read, hfs_write, hfs_seek, hfs_stat,
	hfs_readdir
};
static struct fs_ops file_system_nfs = {
	nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat,
	nfs_readdir
};

struct fs_ops file_system[3];
int nfsys;

static u_long
get_long(p)
	const void *p;
{
	const unsigned char *cp = p;

	return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
}

int
read_mac_label(struct of_dev *devp, char *buf, struct disklabel *lp)
{
	struct part_map_entry *part;
	size_t read;
	int part_cnt;
	int i;
	char *s;

	if ((strategy(devp, F_READ, 1, DEV_BSIZE, buf, &read) != 0) ||
	    (read != DEV_BSIZE))
		return ERDLAB;

	part = (struct part_map_entry *)buf;

	/* if first partition is not valid, assume not HFS/DPME partitioned */
	if (part->pmSig != PART_ENTRY_MAGIC)
		return ERDLAB;

	part_cnt = part->pmMapBlkCnt;

	/* first search for "OpenBSD" partition type
	 * standard bsd disklabel lives inside at offset 0
	 * otherwise, we should fake a bsd partition
	 * with first HFS partition starting at 'i'
	 * ? will this cause problems with booting bsd.rd from hfs
	 */
	for (i = 0; i < part_cnt; i++) {
		/* read the appropriate block */
		if ((strategy(devp, F_READ, 1+i, DEV_BSIZE, buf, &read) != 0)
		   || (read != DEV_BSIZE))
			return ERDLAB;

		part = (struct part_map_entry *)buf;
		/* toupper the string, in case caps are different... */
		for (s = part->pmPartType; *s; s++)
			if ((*s >= 'a') && (*s <= 'z'))
				*s = (*s - 'a' + 'A');

		if (0 == strcmp(part->pmPartType, PART_TYPE_OPENBSD)) {
			/* FOUND OUR PARTITION!!! */
			if(strategy(devp, F_READ, part->pmPyPartStart,
				DEV_BSIZE, buf, &read) == 0
				&& read == DEV_BSIZE)
			{
				if (!getdisklabel(buf, lp))
					return 0;

				/* If we have an OpenBSD region
				 * but no valid parition table,
				 * we cannot load a kernel from
				 * it, punt.
				 * should not have more than one
				 * OpenBSD of DPME type.
				 */
				return ERDLAB;
			}
		}
	}
	return ERDLAB;
}

/*
 * Find a valid disklabel.
 */
static int
search_label(devp, off, buf, lp, off0)
	struct of_dev *devp;
	u_long off;
	char *buf;
	struct disklabel *lp;
	u_long off0;
{
	size_t read;
	struct dos_partition *p;
	int i;
	u_long poff;
	static int recursion;

	if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read) ||
	    read != DEV_BSIZE)
		return ERDLAB;

	if (buf[510] != 0x55 || buf[511] != 0xaa)
		return ERDLAB;

	if (recursion++ <= 1)
		off0 += off;
	for (p = (struct dos_partition *)(buf + DOSPARTOFF), i = 4;
	    --i >= 0; p++) {
		if (p->dp_typ == DOSPTYP_OPENBSD) {
			poff = get_long(&p->dp_start) + off0;
			if (strategy(devp, F_READ, poff + LABELSECTOR,
			    DEV_BSIZE, buf, &read) == 0
			    && read == DEV_BSIZE) {
				if (!getdisklabel(buf, lp)) {
					recursion--;
					return 0;
				}
			}
			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
			    || read != DEV_BSIZE) {
				recursion--;
				return ERDLAB;
			}
		} else if (p->dp_typ == DOSPTYP_EXTEND) {
			poff = get_long(&p->dp_start);
			if (!search_label(devp, poff, buf, lp, off0)) {
				recursion--;
				return 0;
			}
			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
			    || read != DEV_BSIZE) {
				recursion--;
				return ERDLAB;
			}
		}
	}
	recursion--;
	return ERDLAB;
}

int
devopen(struct open_file *of, const char *name, char **file)
{
	struct of_dev *ofdev;
	char fname[256];
	char buf[DEV_BSIZE];
	struct disklabel label;
	int handle, part;
	size_t read;
	int error = 0;

	if (of->f_flags != F_READ)
		return EPERM;

	strlcpy(fname, name, sizeof fname);
	if (parsename(fname, file))
		return ENOENT;

	if ((handle = OF_finddevice(fname)) == -1)
		return ENOENT;
	if (OF_getprop(handle, "name", buf, sizeof buf) < 0)
		return ENXIO;
	if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0)
		return ENXIO;
	if (!strcmp(buf, "block"))
		/*
		 * For block devices, indicate raw partition
		 * (:0 in OpenFirmware)
		 */
		strlcat(fname, ":0", sizeof fname);
	if ((ofdev = alloc(sizeof *ofdev)) == NULL)
		return ENOMEM;
	bzero(ofdev, sizeof *ofdev);

	if ((handle = OF_open(fname)) == -1) {
		free(ofdev, sizeof *ofdev);
		return ENXIO;
	}

	ofdev->handle = handle;
	ofdev->dmabuf = NULL;
	OF_call_method("dma-alloc", handle, 1, 1, MAXBSIZE, &ofdev->dmabuf);
	if (!strcmp(buf, "block")) {
		ofdev->type = OFDEV_DISK;
		ofdev->bsize = DEV_BSIZE;
		/* First try to find a disklabel without MBR partitions */
		if (strategy(ofdev, F_READ,
		    LABELSECTOR, DEV_BSIZE, buf, &read) != 0 ||
		    read != DEV_BSIZE ||
		    getdisklabel(buf, &label)) {
			/* Else try MBR partitions */
			error = read_mac_label(ofdev, buf, &label);
			if (error == ERDLAB)
				error = search_label(ofdev, 0, buf, &label, 0);

			if (error && error != ERDLAB)
				goto bad;
		}

		if (error == ERDLAB) {
			/* No label, just use complete disk */
			ofdev->partoff = 0;
		} else {
			part = 0; /* how to pass this parameter */
			ofdev->partoff = label.d_partitions[part].p_offset;
		}

		of->f_dev = devsw;
		of->f_devdata = ofdev;
		bcopy(&file_system_ufs, file_system, sizeof file_system[0]);
		bcopy(&file_system_cd9660, file_system + 1,
		    sizeof file_system[0]);
		bcopy(&file_system_hfs, file_system + 2,
		    sizeof file_system[0]);
		nfsys = 3;
		return 0;
	}
	if (!strcmp(buf, "network")) {
		ofdev->type = OFDEV_NET;
		of->f_dev = devsw;
		of->f_devdata = ofdev;
		bcopy(&file_system_nfs, file_system, sizeof file_system[0]);
		nfsys = 1;
		if (error = net_open(ofdev))
			goto bad;
		return 0;
	}
	error = EFTYPE;
bad:
	OF_close(handle);
	free(ofdev, sizeof *ofdev);
	return error;
}


code:
/*	$OpenBSD: ofdev.h,v 1.1 2001/09/01 15:39:02 drahn Exp $	*/
/*	$NetBSD: ofdev.h,v 1.1 1997/04/16 20:29:22 thorpej Exp $	*/

/*
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */
#ifndef	_STAND_DEV_H_
#define	_STAND_DEV_H_

struct of_dev {
	int handle;
	int type;
	u_long partoff;
	int bsize;
	void *dmabuf;
};

/* Known types: */
#define	OFDEV_NET	1
#define	OFDEV_DISK	2

#define	DEFAULT_KERNEL	"/bsd"

extern char opened_name[];

#endif


code: src/sys/arch/macppc/stand/ofwboot


path: sys/arch/macppc/stand/ofwboot/CVS/Tag


code:
#	$OpenBSD: Makefile,v 1.13 2014/11/19 20:02:50 miod Exp $
#	$NetBSD: Makefile,v 1.2 1997/04/17 07:46:24 thorpej Exp $

S=	${.CURDIR}/../../../..
R=../

PROG=		ofwboot
SRCS=		Locore.c main.c ofdev.c net.c netif_of.c netudp.c
SRCS+=		alloc.c cache.c hfs.c
SRCS+=		boot.c conf.c cmd.c vars.c ctime.c strtol.c
.PATH:		${S}/arch/macppc/stand
SRCS+=		ofwmagic.S
#CFLAGS+=	-DDEBUG -DNETIF_DEBUG
CFLAGS+=	-fno-pie
NOMAN=
STRIPFLAG=
BINMODE=	444
OBJCOPY?=	objcopy
SAREL=
BINDIR=         /usr/mdec

.PATH:          ${S}/stand/boot
.PATH:          ${S}/lib/libsa

.PATH:		${S}/lib/libkern/arch/powerpc ${S}/lib/libkern
SRCS+=		getchar.c strlcpy.c memcpy.c strlen.c strrchr.c \
		strlcat.c ashrdi3.c
SRCS+=		moddi3.c

NEWVERSWHAT=	"OpenFirmware Boot"

# For now...
RELOC=		20000

ENTRY=		_start

CPPFLAGS+=	-I. -I${.CURDIR}/../../.. -I${.CURDIR}/../../../..
CPPFLAGS+=	-DRELOC=0x${RELOC} -DCONSPEED=57600

LIBS!=          cd $(.CURDIR)/$(R); $(MAKE) libdep

${PROG}: ${OBJS} ${LIBSA} ${LIBZ}
	${LD} -nopie -N -X -Ttext ${RELOC} -e ${ENTRY} -o ${PROG} \
	    ${OBJS} ${LIBS}

.include <bsd.prog.mk>

path: sys/arch/macppc/stand/ofwboot/Makefile


code:
/*	$OpenBSD: ofwmagic.S,v 1.2 2008/06/26 05:42:12 ray Exp $	*/
/*	$NetBSD: ofwmagic.S,v 1.1 1997/04/16 21:19:00 thorpej Exp $	*/

/*-
 * Copyright (c) 1997 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jason R. Thorpe.
 *
 * 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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.
 */

/*
 * Magic note section used by OpenFirmware.
 */

	.section ".note"

	# note header

	# length of name
	.long	8

	# note descriptor size
	.long	20

	# note type (IEEE 1275)
	.long	0x1275

	# name of owner
	.asciz	"PowerPC"
	.balign	4

	# note descriptor

	# real mode (-1) or virtual mode (0)
	.long	0

	# real-base
	.long	-1
	# real-size
	.long	-1

	# virt-base
	.long	-1
	# virt-size
	.long	-1


code:
/*	$OpenBSD: openfirm.h,v 1.4 2012/12/05 23:20:13 deraadt Exp $	*/
/*	$NetBSD: openfirm.h,v 1.1 1997/04/16 20:29:23 thorpej Exp $	*/

/*
 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
 * Copyright (C) 1995, 1996 TooLs GmbH.
 * All rights reserved.
 *
 * 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. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by TooLs GmbH.
 * 4. The name of TooLs GmbH may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``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 TOOLS GMBH 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.
 */
/*
 * Prototypes for Openfirmware Interface Routines
 */

#include <sys/types.h>

int OF_finddevice(char *name);
int OF_instance_to_package(int ihandle);
int OF_getprop(int handle, char *prop, void *buf, int buflen);
#ifdef	__notyet__
int OF_setprop(int handle, char *prop, void *buf, int len);
#endif
int OF_open(char *dname);
void OF_close(int handle);
int OF_write(int handle, void *addr, int len);
int OF_read(int handle, void *addr, int len);
int OF_seek(int handle, u_quad_t pos);
void *OF_claim(void *virt, u_int size, u_int align);
void OF_release(void *virt, u_int size);
int OF_milliseconds(void);
void OF_chain(void *addr, u_int size, void (*entry)(), void *parm, u_int parmlen);


code: src/sys/arch/macppc/stand/tbxidata


path: sys/arch/macppc/stand/tbxidata/CVS/Tag


code:
#       $OpenBSD: Makefile,v 1.4 2014/07/13 21:13:30 jasper Exp $

NOMACHINE=
FILES=	bsd.tbxi
NOOBJ=	noobj

install:
	${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${FILES} \
	    ${DESTDIR}/usr/mdec

.include <bsd.prog.mk>

path: sys/arch/macppc/stand/tbxidata/Makefile


code:
<CHRP-BOOT>
<LICENSE>
/*      $OpenBSD: bsd.tbxi,v 1.35 2015/06/17 22:32:08 deraadt Exp $      */
/*
 * Copyright (c) 2001 Dale Rahn.
 * All rights reserved.
 *
 *
 * 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.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
 */
</LICENSE>
<COMPATIBLE>
MacRISC MacRISC3 MacRISC4
</COMPATIBLE>
<DESCRIPTION>
OpenBSD/macppc bootloader
</DESCRIPTION>
<BOOT-SCRIPT>
boot cd:,ofwboot /5.8/macppc/bsd.rd
</BOOT-SCRIPT>
<OS-BADGE-ICONS>
201B
[encoded data, 5184 characters]
</OS-BADGE-ICONS>
</CHRP-BOOT>


code:
D/conf////
D/dev////
D/include////
D/mips64////


code:
#	$OpenBSD: files.mips64,v 1.24 2015/07/17 22:52:28 tedu Exp $

file	arch/mips64/mips64/arcbios.c		arcbios
file	arch/mips64/mips64/clock.c		clock
file	arch/mips64/mips64/cpu.c
file	arch/mips64/mips64/interrupt.c
file	arch/mips64/mips64/mem.c
file	arch/mips64/mips64/mips64_machdep.c
file	arch/mips64/mips64/pmap.c
file	arch/mips64/mips64/process_machdep.c
file	arch/mips64/mips64/sendsig.c
file	arch/mips64/mips64/softintr.c
file	arch/mips64/mips64/sys_machdep.c
file	arch/mips64/mips64/trap.c
file	arch/mips64/mips64/vm_machdep.c
file	arch/mips64/mips64/mutex.c

file	arch/mips64/mips64/cache_loongson2.c	cpu_loongson2
file	arch/mips64/mips64/cache_octeon.c	cpu_octeon
file	arch/mips64/mips64/cache_r4k.c		cpu_r4000
file	arch/mips64/mips64/cache_r5k.c		cpu_r5000 | cpu_rm7000
file	arch/mips64/mips64/cache_r10k.c		cpu_r10000
file	arch/mips64/mips64/cache_tfp.c		cpu_r8000
file	arch/mips64/mips64/cache_tfp_subr.S	cpu_r8000
file	arch/mips64/mips64/context.S
file	arch/mips64/mips64/cp0access.S
file	arch/mips64/mips64/exception.S		!cpu_r8000
file	arch/mips64/mips64/exception_tfp.S	cpu_r8000
file	arch/mips64/mips64/fp_emulate.c
file	arch/mips64/mips64/lcore_access.S
file	arch/mips64/mips64/lcore_float.S
file	arch/mips64/mips64/r4000_errata.c	cpu_r4000
file	arch/mips64/mips64/tlbhandler.S		!cpu_r8000
file	arch/mips64/mips64/tlb_tfp.S		cpu_r8000

file	arch/mips64/mips64/db_disasm.c		ddb
file	arch/mips64/mips64/db_machdep.c		ddb
file	arch/mips64/mips64/lcore_ddb.S		ddb|debug

file	arch/mips64/mips64/ipifuncs.c           multiprocessor

file	netinet/in_cksum.c
file	netinet/in4_cksum.c

file	lib/libkern/softfloat.c


code:
/clockvar.h/1.5/Mon Apr  7 22:36:24 2008//TOPENBSD_5_8_BASE
D


code:
/*	$OpenBSD: clockvar.h,v 1.5 2008/04/07 22:36:24 miod Exp $	*/

/*
 * Copyright (c) 1994, 1995 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 * Adopted for r4400: Per Fogelstrom
 *
 * Permission to use, copy, modify and distribute this software and
 * its documentation is hereby granted, provided that both the copyright
 * notice and this permission notice appear in all copies of the
 * software, derivative works or modified versions, and any portions
 * thereof, and that both notices appear in supporting documentation.
 *
 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
 * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
 *
 * Carnegie Mellon requests users of this software to return to
 *
 *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
 *  School of Computer Science
 *  Carnegie Mellon University
 *  Pittsburgh PA 15213-3890
 *
 * any improvements or extensions that they make and grant Carnegie the
 * rights to redistribute these changes.
 */

/*
 * Definitions for "cpu-independent" clock handling.
 */

/*
 * tod_time structure:
 *
 * structure passed to TOD clocks when setting them.  broken out this
 * way, so that the time_t -> field conversion can be shared.
 */
struct tod_time {
	int	year;			/* year 1900.... */
	int	mon;			/* month (1 - 12) */
	int	day;			/* day (1 - 31) */
	int	hour;			/* hour (0 - 23) */
	int	min;			/* minute (0 - 59) */
	int	sec;			/* second (0 - 59) */
	int	dow;			/* day of week (0 - 6; 0 = Sunday) */
};

/*
 * tod_desc structure:
 *
 * provides tod-specific functions to do necessary operations.
 */

struct tod_desc {
	void	*tod_cookie;
	void	(*tod_get)(void *, time_t, struct tod_time *);
	void	(*tod_set)(void *, struct tod_time *);
	int	tod_valid;
};

extern struct tod_desc sys_tod;


code:
/*	$OpenBSD: _float.h,v 1.1 2012/06/26 16:12:44 deraadt Exp $	*/

/*
 * Copyright (c) 1989, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * 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.
 */

#ifndef _MACHINE__FLOAT_H_
#define _MACHINE__FLOAT_H_

#define __FLT_RADIX		2		/* b */
#define __FLT_ROUNDS		__flt_rounds()
#define __FLT_EVAL_METHOD	0		/* no promotions */

#define __FLT_MANT_DIG		24		/* p */
#define __FLT_EPSILON		1.19209290E-07F	/* b**(1-p) */
#define __FLT_DIG		6		/* floor((p-1)*log10(b))+(b == 10) */
#define __FLT_MIN_EXP		(-125)		/* emin */
#define __FLT_MIN		1.17549435E-38F	/* b**(emin-1) */
#define __FLT_MIN_10_EXP	(-37)		/* ceil(log10(b**(emin-1))) */
#define __FLT_MAX_EXP		128		/* emax */
#define __FLT_MAX		3.40282347E+38F	/* (1-b**(-p))*b**emax */
#define __FLT_MAX_10_EXP	38		/* floor(log10((1-b**(-p))*b**emax)) */

#define __DBL_MANT_DIG		53
#define __DBL_EPSILON		2.2204460492503131E-16
#define __DBL_DIG		15
#define __DBL_MIN_EXP		(-1021)
#define __DBL_MIN		2.2250738585072014E-308
#define __DBL_MIN_10_EXP	(-307)
#define __DBL_MAX_EXP		1024
#define __DBL_MAX		1.7976931348623157E+308
#define __DBL_MAX_10_EXP	308

#define __LDBL_MANT_DIG		113
#define __LDBL_EPSILON		1.92592994438723585305597794258492732e-34L
#define __LDBL_DIG		33
#define __LDBL_MIN_EXP		(-16381)
#define __LDBL_MIN		3.36210314311209350626267781732175260e-4932L
#define __LDBL_MIN_10_EXP	(-4931)
#define __LDBL_MAX_EXP		16384
#define __LDBL_MAX		1.18973149535723176508575932662800702e+4932L
#define __LDBL_MAX_10_EXP	4932

#define __DECIMAL_DIG		36

#endif /* _MACHINE__FLOAT_H_ */


code:
/*	$OpenBSD: _types.h,v 1.19 2014/03/19 05:14:13 guenther Exp $	*/

/*-
 * Copyright (c) 1990, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * 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.
 *
 *	@(#)types.h	8.3 (Berkeley) 1/5/94
 *	@(#)ansi.h	8.2 (Berkeley) 1/4/94
 */

#ifndef _MIPS64__TYPES_H_
#define _MIPS64__TYPES_H_

/*
 * _ALIGN(p) rounds p (pointer or byte index) up to a correctly-aligned
 * value for all data types (int, long, ...).   The result is an
 * unsigned long and must be cast to any desired pointer type.
 *
 * _ALIGNED_POINTER is a boolean macro that checks whether an address
 * is valid to fetch data elements of type t from on this architecture.
 * This does not reflect the optimal alignment, just the possibility
 * (within reasonable limits).
 */
#define	_ALIGNBYTES		7
#define	_STACKALIGNBYTES	15
#define	_ALIGN(p)		(((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
#define	_ALIGNED_POINTER(p,t)	((((unsigned long)(p)) & (sizeof(t) - 1)) == 0)

/*
 *  We need to handle the various ISA levels for sizes.
 */
#define	_MIPS_ISA_MIPS1	1	/* R2000/R3000 */
#define	_MIPS_ISA_MIPS2	2	/* R4000/R6000 */
#define	_MIPS_ISA_MIPS3	3	/* R4000 */
#define	_MIPS_ISA_MIPS4	4	/* TFP (R1x000) */

/* 7.18.1.1 Exact-width integer types */
typedef	signed char		__int8_t;
typedef	unsigned char		__uint8_t;
typedef	short			__int16_t;
typedef	unsigned short		__uint16_t;
typedef	int			__int32_t;
typedef	unsigned int		__uint32_t;
/* LONGLONG */
typedef	long long		__int64_t;
/* LONGLONG */
typedef	unsigned long long	__uint64_t;

/* 7.18.1.2 Minimum-width integer types */
typedef	__int8_t		__int_least8_t;
typedef	__uint8_t		__uint_least8_t;
typedef	__int16_t		__int_least16_t;
typedef	__uint16_t		__uint_least16_t;
typedef	__int32_t		__int_least32_t;
typedef	__uint32_t		__uint_least32_t;
typedef	__int64_t		__int_least64_t;
typedef	__uint64_t		__uint_least64_t;

/* 7.18.1.3 Fastest minimum-width integer types */
typedef	__int32_t		__int_fast8_t;
typedef	__uint32_t		__uint_fast8_t;
typedef	__int32_t		__int_fast16_t;
typedef	__uint32_t		__uint_fast16_t;
typedef	__int32_t		__int_fast32_t;
typedef	__uint32_t		__uint_fast32_t;
typedef	__int64_t		__int_fast64_t;
typedef	__uint64_t		__uint_fast64_t;
#define	__INT_FAST8_MIN		INT32_MIN
#define	__INT_FAST16_MIN	INT32_MIN
#define	__INT_FAST32_MIN	INT32_MIN
#define	__INT_FAST64_MIN	INT64_MIN
#define	__INT_FAST8_MAX		INT32_MAX
#define	__INT_FAST16_MAX	INT32_MAX
#define	__INT_FAST32_MAX	INT32_MAX
#define	__INT_FAST64_MAX	INT64_MAX
#define	__UINT_FAST8_MAX	UINT32_MAX
#define	__UINT_FAST16_MAX	UINT32_MAX
#define	__UINT_FAST32_MAX	UINT32_MAX
#define	__UINT_FAST64_MAX	UINT64_MAX

/* 7.18.1.4 Integer types capable of holding object pointers */
typedef	long			__intptr_t;
typedef	unsigned long		__uintptr_t;

/* 7.18.1.5 Greatest-width integer types */
typedef	__int64_t		__intmax_t;
typedef	__uint64_t		__uintmax_t;

/* Register size */
typedef long			__register_t;
typedef long			f_register_t;	/* XXX */

/* VM system types */
typedef unsigned long		__vaddr_t;
typedef unsigned long		__paddr_t;
typedef unsigned long		__vsize_t;
typedef unsigned long		__psize_t;

/* Standard system types */
typedef double			__double_t;
typedef float			__float_t;
typedef long			__ptrdiff_t;
typedef	unsigned long		__size_t;
typedef	long			__ssize_t;
#if defined(__GNUC__) && __GNUC__ >= 3
typedef	__builtin_va_list	__va_list;
#else
typedef	char *			__va_list;
#endif

/* Wide character support types */
#ifndef __cplusplus
typedef	int			__wchar_t;
#endif
typedef int			__wint_t;
typedef	int			__rune_t;
typedef	void *			__wctrans_t;
typedef	void *			__wctype_t;

#if defined(_KERNEL)
typedef struct label_t {
	long val[14];
} label_t;
#endif

/* XXX check why this still has to be defined. pmap.c issue? */
#define __SWAP_BROKEN

/* Feature test macros */
#define	__HAVE_EXEC_MD_MAP

#endif	/* _MIPS64__TYPES_H_ */