code:
#	$OpenBSD: Makefile.inc,v 1.3 2014/07/16 20:08:25 okan Exp $
#	$NetBSD: Makefile.inc,v 1.5 1996/09/30 16:01:18 ws Exp $
#
#	NOTE: $S must correspond to the top of the 'sys' tree
SADIR=	$S/lib/libsa

SADST?=	lib/sa
SAREL?=	../../
SALIB?=	${SADST}/libsa.a

SAMAKE= \
	cd ${SADST} && ${MAKE} -f ${SAREL}${SADIR}/Makefile \
	  CC="${CC}" XCFLAGS="${CFLAGS}" \
	  AS='${AS}' XAFLAGS='${AFLAGS}' \
	  LD='${LD}' \
	  SAREL="${SAREL}" \
	  SADIR="${SADIR}" \
	  EXTRACFLAGS="${EXTRACFLAGS}"
.if defined(NO_NET)
SAMAKE+= NO_NET=""
.endif
.if defined(SA_ZLIB)
SAMAKE+= SA_ZLIB=""
.endif

${SALIB}:		.NOTMAIN __always_make_salib
	@echo making sure the stand-alone library is up to date...
	@${SAMAKE} libsa.a

clean:	 		.NOTMAIN __always_make_salib
	@echo cleaning the stand-alone library objects
	@${SAMAKE} clean

depend:			.NOTMAIN __always_make_salib
	@echo depending the standalone library objects
	@${SAMAKE} depend

__always_make_salib:	.NOTMAIN
	@([ -d ${SADST} ] || mkdir -p ${SADST})


code:
/Makefile/1.1/Mon May  5 06:01:58 1997//TOPENBSD_5_8_BASE
/Makefile.inc/1.1/Mon May  5 06:01:58 1997//TOPENBSD_5_8_BASE
D

path: sys/arch/alpha/stand/libz/CVS/Entries

license: unknown


path: sys/arch/alpha/stand/libz/CVS/Tag


code:
#	$OpenBSD: Makefile,v 1.1 1997/05/05 06:01:58 millert Exp $

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

path: sys/arch/alpha/stand/libz/Makefile


code:
#	$OpenBSD: Makefile.inc,v 1.1 1997/05/05 06:01:58 millert Exp $
#	$NetBSD: Makefile.inc,v 1.2 1997/01/23 22:29:09 cgd Exp $
#
#	Configuration variables (default values are below):
#
#	S	must be set to the top of the 'sys' tree.
#	ZDST	may be set to the location of the directory where library
#		objects are to be built.  Defaults to ${.OBJDIR}/lib/z.
#	Z_AS	may be set to 'obj' to build a object from the library's
#		object files.  (Otherwise, a library will be built.)
#		Defaults to 'library'.
#	ZMISCMAKEFLAGS
#		Miscellaneous flags to be passed to the library's Makefile when
#		building.  See library's Makefile for more details about
#		supported flags and their default values.

# Default values:
ZDST?=		${.OBJDIR}/lib/z
Z_AS?=		library

ZDIR=		$S/lib/libz
.if (${Z_AS} == "obj")
ZLIB=		${ZDST}/libz.o
ZLIB_PROF=	${ZDST}/libz.po
.else
ZLIB=		${ZDST}/libz.a
ZLIB_PROF=	${ZDST}/libz_p.a
.endif

ZMAKE= \
	cd ${ZDIR} && MAKEOBJDIR=${ZDST} ${MAKE} \
	    CC="${CC}" CFLAGS="${CFLAGS}" \
	    AS=${AS} AFLAGS="${AFLAGS}" \
	    LD=${LD} STRIP=${STRIP} \
	    MACHINE=${MACHINE} MACHINE_ARCH=${MACHINE_ARCH} \
	    ZCPPFLAGS="${CPPFLAGS:S@^-I.@-I../../.@g}" \
	    ${ZMISCMAKEFLAGS}

${ZLIB}:		.NOTMAIN __always_make_zlib
	@echo making sure the z library is up to date...
.if (${Z_AS} == "library")
	${ZMAKE} libz.a
.else
	@${ZMAKE} libz.o
.endif

${ZLIB_PROF}:		.NOTMAIN __always_make_zlib
	@echo making sure the profiled z library is up to date...
.if (${Z_AS} == "library")
	@${ZMAKE} libz_p.a
.else
	@${ZMAKE} libz.po
.endif

clean:			.NOTMAIN cleanzlib
cleanzlib:		.NOTMAIN __always_make_zlib
	@echo cleaning the z library objects
	@${ZMAKE} clean

cleandir:		.NOTMAIN cleandirzlib
cleandirzlib:		.NOTMAIN __always_make_zlib
	@echo cleandiring the z library objects
	@${ZMAKE} cleandir

depend:			.NOTMAIN dependzlib
dependzlib:		.NOTMAIN __always_make_zlib
	@echo depending the z library objects
	@${ZMAKE} depend

__always_make_zlib:	.NOTMAIN
	@mkdir -p ${ZDST}


code:
/*	$OpenBSD: loadfile_subr.c,v 1.3 2013/03/21 21:50:59 deraadt Exp $	*/

/*
 * Copyright (c) 2010 Miodrag Vallat.
 *
 * 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 <sys/systm.h>
#include <lib/libkern/libkern.h>

#include <sys/exec_elf.h>
#include <lib/libsa/loadfile.h>

#include <machine/alpha_cpu.h>
#include <machine/rpb.h>

#define	ptoa(a)	((a) << PAGE_SHIFT)

/*
 * Prevent loading a kernel if it would overlap the SRM.
 */
int
check_phdr(void *hdr)
{
	Elf64_Phdr *phdr = (Elf64_Phdr *)hdr;
	struct rpb *hwrpb = (struct rpb *)HWRPB_ADDR;
	struct mddt *mddtp;
	struct mddt_cluster *memc;
	u_int64_t cstart, cend;
	u_int64_t i;

	mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
	for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
		memc = &mddtp->mddt_clusters[i];
		if (memc->mddt_usage & MDDT_PALCODE) {
			cstart = ALPHA_PHYS_TO_K0SEG(ptoa(memc->mddt_pfn));
			cend = cstart + ptoa(memc->mddt_pg_cnt);

			if (phdr->p_vaddr + phdr->p_memsz <= cstart ||
			    phdr->p_vaddr >= cend)
				continue;

			printf("SRM console and kernel image would overlap.\n"
			    "Please report this to <alpha@openbsd.org>, "
			    "with the following values:\n"
			    "SRM range: %p-%p\n"
			    "kernel range: %p-%p\n",
			    cstart, cend, phdr->p_vaddr,
			    phdr->p_vaddr + phdr->p_memsz);
			return 1;
		}
	}

	return 0;
}


path: sys/arch/alpha/stand/netboot/CVS/Tag


code:
#	$OpenBSD: Makefile,v 1.13 2014/12/13 14:45:34 miod Exp $
#	$NetBSD: Makefile,v 1.11 1997/04/17 07:27:50 thorpej Exp $

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

.PATH: ${.CURDIR}/.. ${.CURDIR}/../boot

PROG = netboot

SRCS = start.S boot.c prom.c prom_disp.S OSFpal.c prom_swpal.S
SRCS+= rpcc.S
SRCS+= dev_net.c conf.c devopen.c
SRCS+= if_prom.c getsecs.c
SRCS+= loadfile_subr.c
NOMAN=
INSTALL_STRIP=
BINMODE= 444

BOOT_RELOC = ${PRIMARY_LOAD_ADDRESS}

CLEANFILES+= vers.c vers.o ${PROG}.sym ${PROG}.nosym

.PATH:  ${S}/lib/libkern/arch/alpha ${S}/lib/libkern
SRCS+=  bzero.c __divqu.S strlen.c __remqu.S

.PATH:	${S}/lib/libkern/arch/alpha ${S}/lib/libsa
SRCS+=	loadfile.c

DEFNS= -DPRIMARY_BOOTBLOCK -DSUN_BOOTPARAMS

AFLAGS += -DASSEMBLER ${DEFNS} -fno-pie
CPPFLAGS += -I${.CURDIR}/../.. -I${S} ${DEFNS}
CFLAGS = -Werror -mno-fp-regs -fno-pie

${PROG}.nosym: ${PROG}.sym
	cp ${PROG}.sym ${PROG}.nosym
	strip ${PROG}.nosym

${PROG} ${PROG}.mop: ${PROG}.nosym
	objcopy --output-target=binary ${PROG}.nosym ${PROG}
	mopa.out ${PROG}.nosym ${PROG}.mop

realinstall:
	${INSTALL} ${INSTALL_COPY} -S ${INSTALL_STRIP} \
	    -o ${BINOWN} -g ${BINGRP} \
	    -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR}/${PROG}
	${INSTALL} ${INSTALL_COPY} -S ${INSTALL_STRIP} \
	    -o ${BINOWN} -g ${BINGRP} \
	    -m ${BINMODE} ${PROG}.mop ${DESTDIR}${BINDIR}/${PROG}.mop

# no lint here (yet?)
lint:

.include <bsd.prog.mk>

### find out what to use for libz
Z_AS=		library
ZDST=		${.CURDIR}/../libz/${__objdir}
.include "${.CURDIR}/../libz/Makefile.inc"
LIBZ=		${ZLIB}

### find out what to use for libsa
SA_AS=		library
SADST=		${.CURDIR}/../libsa/${__objdir}
SAREL=
SA_ZLIB=	yes
.include "${.CURDIR}/../libsa/Makefile.inc"
LIBSA=		${SALIB}

${PROG}.sym: ${OBJS} ${LIBSA} ${LIBZ}
	sh ${.CURDIR}/newvers.sh ${.CURDIR}/version
	${COMPILE.c} vers.c
	${LD} -nopie -Ttext ${BOOT_RELOC} -N -e start -o ${PROG}.sym \
	    ${OBJS} vers.o ${LIBSA} ${LIBZ} ${LIBSA}
	size ${PROG}.sym

path: sys/arch/alpha/stand/netboot/Makefile


code:
/*	$OpenBSD: conf.c,v 1.2 1997/05/05 06:01:59 millert Exp $	*/
/*	$NetBSD: conf.c,v 1.4 1997/04/06 08:41:23 cgd Exp $	*/

#include <sys/types.h>
#include <netinet/in.h>

#include <lib/libsa/stand.h>
#include <lib/libsa/nfs.h>
#include "dev_net.h"

struct fs_ops file_system[] = {
	{ nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat },
};
int nfsys = 1;

struct devsw devsw[] = {
	{ "net",  net_strategy,  net_open,  net_close,  net_ioctl },
};
int	ndevs = 1;

extern struct netif_driver prom_netif_driver;

struct netif_driver *netif_drivers[] = {
	&prom_netif_driver,
};
int	n_netif_drivers = (sizeof(netif_drivers) / sizeof(netif_drivers[0]));


code:
/*	$OpenBSD: dev_net.c,v 1.4 2014/07/13 15:31:20 mpi Exp $	*/
/*	$NetBSD: dev_net.c,v 1.4 1997/04/06 08:41:24 cgd Exp $	*/

/*
 * Copyright (c) 1995 Gordon W. Ross
 * 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.
 * 4. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Gordon W. Ross
 *
 * 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.
 */

/*
 * 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()
 * RARP for IP address - rarp_getipaddress()
 * RPC/bootparams      - callrpc(d, RPC_BOOTPARAMS, ...)
 * RPC/mountd          - nfs_mount(sock, ip, path)
 *
 * the root file handle from mountd is saved in a global
 * for use by the NFS open code (NFS/lookup).
 */

#include <stdarg.h>
#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>
#include <lib/libsa/bootparam.h>
#include "dev_net.h"

extern int debug;
extern int nfs_root_node[];	/* XXX - get from nfs_mount() */

/*
 * Various globals needed by the network code:
 */

#if 0
/* for arp.c, rarp.c */
u_char bcea[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
#endif

struct	in_addr myip;		/* my ip address */
struct	in_addr rootip;		/* root ip address */
struct	in_addr gateip;		/* swap ip address */
u_int32_t	netmask;		/* subnet or net mask */

char rootpath[FNAME_SIZE];

int hostnamelen;
char hostname[FNAME_SIZE];

int domainnamelen;
char domainname[FNAME_SIZE];

/*
 * Local things...
 */
static int netdev_sock = -1;
static int netdev_opens;

/*
 * Called by devopen after it sets f->f_dev to our devsw entry.
 * This opens the low-level device and sets f->f_devdata.
 * This is declared with variable arguments...
 */
int
net_open(struct open_file *f, ...)
{
	va_list ap;
	char *devname;		/* Device part of file name (or NULL). */
	int error = 0;

	va_start(ap, f);
	devname = va_arg(ap, char *);
	va_end(ap);

#ifdef	NETIF_DEBUG
	if (debug)
		printf("net_open: %s\n", devname);
#endif

	/* On first open, do netif open, mount, etc. */
	if (netdev_opens == 0) {
		/* Find network interface. */
		if (netdev_sock < 0) {
			netdev_sock = netif_open(devname);
			if (netdev_sock < 0) {
				printf("net_open: netif_open() failed\n");
				return (ENXIO);
			}
			if (debug)
				printf("net_open: netif_open() succeeded\n");
		}
		if (rootip.s_addr == 0) {
			/* Get root IP address, and path, etc. */
			error = net_getparams(netdev_sock);
			if (error) {
				/* getparams makes its own noise */
				goto fail;
			}
			/* Get the NFS file handle (mountd). */
			error = nfs_mount(netdev_sock, rootip, rootpath);
			if (error) {
				printf("net_open: NFS mount error=%d\n", error);
				rootip.s_addr = 0;
			fail:
				netif_close(netdev_sock);
				netdev_sock = -1;
				return (error);
			}
			if (debug)
				printf("net_open: NFS mount succeeded\n");
		}
	}
	netdev_opens++;
	f->f_devdata = nfs_root_node;
	return (error);
}

int
net_close(f)
	struct open_file *f;
{

#ifdef	NETIF_DEBUG
	if (debug)
		printf("net_close: opens=%d\n", netdev_opens);
#endif

	/* On last close, do netif close, etc. */
	f->f_devdata = NULL;
	/* Extra close call? */
	if (netdev_opens <= 0)
		return (0);
	netdev_opens--;
	/* Not last close? */
	if (netdev_opens > 0)
		return(0);
	rootip.s_addr = 0;
	if (netdev_sock >= 0) {
		if (debug)
			printf("net_close: calling netif_close()\n");
		netif_close(netdev_sock);
		netdev_sock = -1;
	}
	return (0);
}

int
net_ioctl()
{
	return EIO;
}

int
net_strategy()
{
	return EIO;
}

int
net_getparams(sock)
	int sock;
{
	/*
	 * Get info for NFS boot: our IP address, our hostname,
	 * server IP address, and our root path on the server.
	 * There are two ways to do this:  The old, Sun way,
	 * and the more modern, BOOTP way. (RFC951, RFC1048)
	 */

#ifdef	SUN_BOOTPARAMS
	/* Get our IP address.  (rarp.c) */
	if (rarp_getipaddress(sock)) {
		printf("net_open: RARP failed\n");
		return (EIO);
	}
#else	/* BOOTPARAMS */
	/*
	 * Get boot info using BOOTP. (RFC951, RFC1048)
	 * This also gets the server IP address, gateway,
	 * root path, etc.
	 */
	bootp(sock);
	if (myip.s_addr == 0) {
		printf("net_open: BOOTP failed\n");
		return (EIO);
	}
#endif	/* BOOTPARAMS */

	printf("boot: client addr: %s\n", inet_ntoa(myip));

#ifdef	SUN_BOOTPARAMS
	/* Get our hostname, server IP address, gateway. */
	if (bp_whoami(sock)) {
		printf("net_open: bootparam/whoami RPC failed\n");
		return (EIO);
	}
#endif	/* BOOTPARAMS */

	printf("boot: client name: %s\n", hostname);
	if (gateip.s_addr) {
		printf("boot: subnet mask: %s\n", intoa(netmask));
		printf("boot: net gateway: %s\n", inet_ntoa(gateip));
	}

#ifdef	SUN_BOOTPARAMS
	/* Get the root pathname. */
	if (bp_getfile(sock, "root", &rootip, rootpath)) {
		printf("net_open: bootparam/getfile RPC failed\n");
		return (EIO);
	}
#endif	/* BOOTPARAMS */

	printf("boot: server addr: %s\n", inet_ntoa(rootip));
	printf("boot: server path: %s\n", rootpath);

	return (0);
}


code:
/*	$OpenBSD: dev_net.h,v 1.2 2002/03/14 01:26:27 millert Exp $	*/

int	net_open(struct open_file *, ...);
int	net_close(struct open_file *);
int	net_ioctl();
int	net_strategy();


code:
/*	$OpenBSD: devopen.c,v 1.5 2011/06/05 21:49:36 miod Exp $	*/
/*	$NetBSD: devopen.c,v 1.3 1997/04/06 08:41:25 cgd Exp $	*/

/*-
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * 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.
 *
 *	@(#)devopen.c	8.1 (Berkeley) 6/10/93
 */

#include <lib/libsa/stand.h>

/*
 * Decode the string 'fname', open the device and return the remaining
 * file name if any.
 */
int
devopen(f, fname, file)
	struct open_file *f;
	const char *fname;
	char **file;	/* out */
{
	register char *cp;
	register char *ncp;
	register struct devsw *dp;
#if 0
	register int c, i;
#endif
	int ctlr = 0, unit = 0, part = 0;
	char namebuf[20];
	int rc;

	cp = (char *)fname;
	ncp = namebuf;

#if 0
	/* look for a string like '5/rz0/vmunix' or '5/rz3f/vmunix */
	if ((c = *cp) >= '0' && c <= '9') {
		ctlr = c - '0';
		/* skip the '/' */
		if (*++cp != '/')
			return (ENXIO);
		cp++;
		while ((c = *cp) != '\0') {
			if (c == '/')
				break;
			if (c >= '0' && c <= '9') {
				/* read unit number */
				unit = c - '0';

				/* look for a partition */
				if ((c = *++cp) >= 'a' && c <= 'h') {
					part = c - 'a';
					c = *++cp;
				}
				if (c != '/')
					return (ENXIO);
				break;
			}
			if (ncp < namebuf + sizeof(namebuf) - 1)
				*ncp++ = c;
			cp++;
		}
		*ncp = '\0';
	} else if (strchr(cp, '(')) {
		/* expect a string like 'rz(0,0,0)vmunix' */
		while ((c = *cp) != '\0') {
			if (c == '(') {
				cp++;
				break;
			}
			if (ncp < namebuf + sizeof(namebuf) - 1)
				*ncp++ = c;
			cp++;
		}

		/* get controller number */
		if ((c = *cp) >= '0' && c <= '9') {
			ctlr = c - '0';
			c = *++cp;
		}

		if (c == ',') {
			/* get SCSI device number */
			if ((c = *++cp) >= '0' && c <= '9') {
				unit = c - '0';
				c = *++cp;
			}

			if (c == ',') {
				/* get partition number */
				if ((c = *++cp) >= '0' && c <= '9') {
					part = c - '0';
					c = *++cp;
				}
			}
		}
		if (c != ')')
			return (ENXIO);
		cp++;
		*ncp = '\0';
	} else {
#endif
		dp = devsw;
		ctlr = unit = part = 0;
		goto fnd;
#if 0
	}

	for (dp = devsw, i = 0; i < ndevs; dp++, i++)
		if (dp->dv_name && strcmp(namebuf, dp->dv_name) == 0)
			goto fnd;
	printf("Unknown device '%s'\nKnown devices are:", namebuf);
	for (dp = devsw, i = 0; i < ndevs; dp++, i++)
		if (dp->dv_name)
			printf(" %s", dp->dv_name);
	printf("\n");
	return (ENXIO);
#endif

fnd:
	rc = (dp->dv_open)(f, ctlr, unit, part);
	if (rc)
		return (rc);

	f->f_dev = dp;
	if (file && *cp != '\0')
		*file = cp;
	return (0);
}


code:
/*	$OpenBSD: getsecs.c,v 1.3 2011/06/05 21:49:36 miod Exp $	*/

#include <sys/param.h>
#include "include/rpb.h"
#include "include/prom.h"

int
getsecs()
{
	static long tnsec;
	static long lastpcc, wrapsecs;
	long curpcc;

	if (tnsec == 0) {
		tnsec = 1;
		lastpcc = alpha_rpcc() & 0xffffffff;
		wrapsecs = (0xffffffff /
		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq) + 1;

#if 0
		printf("getsecs: cc freq = %d, time to wrap = %d\n",
		    ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq, wrapsecs);
#endif
	}

	curpcc = alpha_rpcc() & 0xffffffff;
	if (curpcc < lastpcc)
		curpcc += 0x100000000;

	tnsec += ((curpcc - lastpcc) * 1000000000) / ((struct rpb *)HWRPB_ADDR)->rpb_cc_freq;
	lastpcc = curpcc;

	return (tnsec / 1000000000);
}


code:
/*	$OpenBSD: if_prom.c,v 1.7 2015/07/17 16:13:26 miod Exp $	*/
/*	$NetBSD: if_prom.c,v 1.9 1997/04/06 08:41:26 cgd Exp $	*/

/*
 * Copyright (c) 1997 Christopher G. Demetriou.  All rights reserved.
 * Copyright (c) 1993 Adam Glass.  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 Adam Glass.
 * 4. 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 Adam Glass ``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.
 */

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

#include <netinet/in.h>

#include <include/rpb.h>
#include <include/prom.h>

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

#include "stand/bbinfo.h"

int	prom_match(struct netif *, void *);
int	prom_probe(struct netif *, void *);
void	prom_init(struct iodesc *, void *);
int	prom_get(struct iodesc *, void *, size_t, time_t);
int	prom_put(struct iodesc *, void *, size_t);
void	prom_end(struct netif *);

extern struct netif_stats	prom_stats[];

struct netif_dif prom_ifs[] = {
/*	dif_unit	dif_nsel	dif_stats	dif_private	*/
{	0,		1,		&prom_stats[0],	0,		},
};

struct netif_stats prom_stats[nitems(prom_ifs)];

struct netbbinfo netbbinfo = {
	0xfeedbabedeadbeef,			/* magic number */
	0,					/* set */
	0, 0, 0, 0, 0, 0,			/* ether address */
	0,					/* force */
	{ 0, },					/* pad2 */
	0,					/* cksum */
	0xfeedbeefdeadbabe,			/* magic number */
};

struct netif_driver prom_netif_driver = {
	"prom",			/* netif_bname */
	prom_match,		/* netif_match */
	prom_probe,		/* netif_probe */
	prom_init,		/* netif_init */
	prom_get,		/* netif_get */
	prom_put,		/* netif_put */
	prom_end,		/* netif_end */
	prom_ifs,		/* netif_ifs */
	nitems(prom_ifs)	/* netif_nifs */
};

int netfd, broken_firmware;

int
prom_match(struct netif *nif, void *machdep_hint)
{

	return (1);
}

int
prom_probe(struct netif *nif, void *machdep_hint)
{

	return 0;
}

int
prom_put(struct iodesc *desc, void *pkt, size_t len)
{

	prom_write(netfd, len, pkt, 0);

	return len;
}

int
prom_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
{
	prom_return_t ret;
	time_t t;
	ssize_t cc;
	char hate[2000];

	t = getsecs();
	cc = 0;
	while (((getsecs() - t) < timeout) && !cc) {
		if (broken_firmware)
			ret.bits = prom_read(netfd, 0, hate, 0);
		else
			ret.bits = prom_read(netfd, sizeof hate, hate, 0);
		if (ret.u.status == 0)
			cc = ret.u.retval;
	}
	if (broken_firmware)
		cc = lmin(cc, len);
	else
		cc = len;
	bcopy(hate, pkt, cc);

	return cc;
}

extern char *strchr();

void
prom_init(struct iodesc *desc, void *machdep_hint)
{
	prom_return_t ret;
	char devname[64];
	int devlen, i, netbbinfovalid;
	char *enet_addr;
	u_int64_t *qp, csum;

	broken_firmware = 0;

	csum = 0;
	for (i = 0, qp = (u_int64_t *)&netbbinfo;
	    i < (sizeof netbbinfo / sizeof (u_int64_t)); i++, qp++)
		csum += *qp;
	netbbinfovalid = (csum == 0);
	if (netbbinfovalid)
		netbbinfovalid = netbbinfo.set;

#if 0
	printf("netbbinfo ");
	if (!netbbinfovalid)
		printf("invalid\n");
	else
		printf("valid: force = %d, ea = %s\n", netbbinfo.force,
		    ether_sprintf(netbbinfo.ether_addr));
#endif

	ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
	devlen = ret.u.retval;

	/* Ethernet address is the 9th component of the booted_dev string. */
	enet_addr = devname;
	for (i = 0; i < 8; i++) {
		enet_addr = strchr(enet_addr, ' ');
		if (enet_addr == NULL) {
			printf("boot: boot device name does not contain ethernet address.\n");
			goto punt;
		}
		enet_addr++;
	}
	if (enet_addr != NULL) {
		int hv, lv;

#define	dval(c)	(((c) >= '0' && (c) <= '9') ? ((c) - '0') : \
		 (((c) >= 'A' && (c) <= 'F') ? (10 + (c) - 'A') : \
		  (((c) >= 'a' && (c) <= 'f') ? (10 + (c) - 'a') : -1)))

		for (i = 0; i < 6; i++) {
			hv = dval(*enet_addr); enet_addr++;
			lv = dval(*enet_addr); enet_addr++;
			enet_addr++;

			if (hv == -1 || lv == -1) {
				printf("boot: boot device name contains bogus ethernet address.\n");
				goto punt;
			}

			desc->myea[i] = (hv << 4) | lv;
		}
#undef dval
	}

	if (netbbinfovalid && netbbinfo.force) {
		printf("boot: using hard-coded ethernet address (forced).\n");
		bcopy(netbbinfo.ether_addr, desc->myea, sizeof desc->myea);
	}

gotit:
	printf("boot: ethernet address: %s\n", ether_sprintf(desc->myea));

	ret.bits = prom_open(devname, devlen + 1);
	if (ret.u.status) {
		printf("prom_init: open failed: %d\n", ret.u.status);
		goto reallypunt;
	}
	netfd = ret.u.retval;
	return;

punt:
	broken_firmware = 1;
	if (netbbinfovalid) {
		printf("boot: using hard-coded ethernet address.\n");
		bcopy(netbbinfo.ether_addr, desc->myea, sizeof desc->myea);
		goto gotit;
	}

reallypunt:
	printf("\n");
	printf("Boot device name was: \"%s\"\n", devname);
	printf("\n");
	printf("Your firmware may be too old to network-boot OpenBSD/alpha,\n");
	printf("or you might have to hard-code an ethernet address into\n");
	printf("your network boot block with setnetbootinfo(8).\n");
	halt();
}

void
prom_end(struct netif *nif)
{

	prom_close(netfd);
}


code:
/*	$OpenBSD: netboot.c,v 1.8 2011/06/05 21:49:36 miod Exp $	*/
/*	$NetBSD: netboot.c,v 1.1 1996/09/18 20:03:12 cgd Exp $	*/

/*
 * Copyright (c) 1992, 1993
 *	The Regents of the University of California.  All rights reserved.
 *
 * This code is derived from software contributed to Berkeley by
 * 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.
 *
 *	@(#)boot.c	8.1 (Berkeley) 6/10/93
 */

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

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

#include <machine/rpb.h>
#include <machine/prom.h>

char boot_file[128];
char boot_flags[128];

extern char bootprog_name[], bootprog_rev[];

vaddr_t ptbr_save;

int debug;

void
main()
{
	u_int64_t entry;
	u_long marks[MARK_MAX];
	int rc;

	/* Init prom callback vector. */
	init_prom_calls();

	/* print a banner */
	printf("%s %s\n", bootprog_name, bootprog_rev);

	/* switch to OSF pal code. */
	OSFpal();

	prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
	prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));

	if (boot_file[0] == '\0')
		bcopy("bsd", boot_file, sizeof "bsd");
	else
		(void)printf("Boot: %s %s\n", boot_file, boot_flags);

	(void)printf("Loading %s...\n", boot_file);
	marks[MARK_START] = 0;
	rc = loadfile(boot_file, &marks, LOAD_KERNEL | COUNT_KERNEL);
	(void)printf("\n");
	if (rc == 0) {
		entry = marks[MARK_START];
		(void)printf("Entering kernel at 0x%lx...\n", entry);
		(*(void (*)(u_int64_t, u_int64_t, u_int64_t))entry)
		    (0, ptbr_save, 0);
	}

	(void)printf("Boot failed!  Halting...\n");
	halt();
}


code:
#!/bin/sh -
#
#	$OpenBSD: newvers.sh,v 1.4 2008/03/09 12:03:03 sobrado Exp $
#	$NetBSD: newvers.sh,v 1.1 1996/09/18 20:03:13 cgd Exp $
#
# Copyright (c) 1984, 1986, 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.
#
#	@(#)newvers.sh	8.1 (Berkeley) 4/20/94

u=${USER-root} h=`hostname` t=`date`
r=`awk ' { print $3 ; exit } ' < $1`

echo "char bootprog_name[] = \"OpenBSD/alpha Network Boot\";" > vers.c
echo "char bootprog_rev[] = \"${r}\";" >> vers.c
echo "char bootprog_date[] = \"${t}\";" >> vers.c
echo "char bootprog_maker[] = \"${u}@${h}\";" >> vers.c


code:
/*	$OpenBSD: rpcc.S,v 1.1 1996/10/30 22:40:59 niklas Exp $	*/
/*	$NetBSD: rpcc.S,v 1.2 1996/10/02 21:18:50 cgd Exp $	*/

#include <machine/asm.h>

	.text
LEAF(alpha_rpcc,1)
	rpcc	v0
	RET
	END(alpha_rpcc)


code:
$OpenBSD: version,v 1.4 2013/12/22 18:31:29 miod Exp $
$NetBSD: version,v 1.6 1997/01/23 23:10:41 cgd Exp $

1.1:	Initial version
1.2:	Cleaned and polished a bit
(OpenBSD 1.1)

1.3:	Use libsa and libkern rather than building the objects locally.
1.4:	Allow ethernet address to be hardcoded with setnetbootinfo(8).
1.5:	Search for a kernel, if none specified.
1.6:	Add support for gzipped kernels.
(OpenBSD 1.2)

1.3:	Use MI loadfile, warn if kernel image would overlap SRM
1.4:	Better PALcode switching sequence

path: sys/arch/alpha/stand/netboot/version


code:
/*	$OpenBSD: prom.c,v 1.8 2010/05/14 21:08:28 naddy Exp $	*/
/*	$NetBSD: prom.c,v 1.2 1996/11/25 16:18:16 cgd Exp $	*/

/*
 * Mach Operating System
 * Copyright (c) 1992 Carnegie Mellon University
 * All Rights Reserved.
 *
 * 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 Mellon
 * the rights to redistribute these changes.
 */

#include <lib/libsa/stand.h>

#include <sys/types.h>

#include <machine/rpb.h>
#include <machine/prom.h>

int console;

void
init_prom_calls()
{
	extern struct prom_vec prom_dispatch_v;
	struct rpb *r;
	struct crb *c;
	char buf[4];

	r = (struct rpb *)HWRPB_ADDR;
	c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);

	prom_dispatch_v.routine_arg = c->crb_v_dispatch;
	prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;

	/* Look for console tty. */
	prom_getenv(PROM_E_TTY_DEV, buf, 4);
	console = buf[0] - '0';
}

int
getchar()
{
	prom_return_t ret;

	for (;;) {
		ret.bits = prom_dispatch(PROM_R_GETC, console);
		if (ret.u.status == 0 || ret.u.status == 1)
			return (ret.u.retval);
	}
}

void
putchar(c)
	int c;
{
	prom_return_t ret;
	char cbuf;

	if (c == '\r' || c == '\n') {
		cbuf = '\r';
		do {
			ret.bits = prom_dispatch(PROM_R_PUTS, console,
			    &cbuf, 1);
		} while ((ret.u.retval & 1) == 0);
		cbuf = '\n';
	} else
		cbuf = c;
	do {
		ret.bits = prom_dispatch(PROM_R_PUTS, console, &cbuf, 1);
	} while ((ret.u.retval & 1) == 0);
}

int
prom_getenv(id, buf, len)
	int id, len;
	char *buf;
{
	/*
	 * On at least some systems, the GETENV call requires a
	 * 8-byte-aligned buffer, or it bails out with a "kernel stack
	 * not valid halt". Provide a local, aligned buffer here and
	 * then copy to the caller's buffer.
	 */
	static char abuf[128] __attribute__ ((aligned (8)));
	prom_return_t ret;

	ret.bits = prom_dispatch(PROM_R_GETENV, id, abuf, 128);
	if (ret.u.status & 0x4)
		ret.u.retval = 0;
	len--;
	if (len > ret.u.retval)
		len = ret.u.retval;
	memcpy(buf, abuf, len);
	buf[len] = '\0';

	return (len);
}


code:
/*	$OpenBSD: prom_disp.S,v 1.4 1996/10/30 22:40:34 niklas Exp $	*/
/*	$NetBSD: prom_disp.S,v 1.5 1996/10/17 02:50:39 cgd Exp $	*/

/*
 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 *
 * 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.
 */

#ifndef _LOCORE
#include "include/asm.h"
#include "include/prom.h"
#include "include/rpb.h"
#endif

	.globl	prom_dispatch_v
	.comm	prom_dispatch_v,16

	.text
	.align	4

/*
 * Dispatcher routine.  Implements prom's calling machinery, saves our
 * callee-saved registers as required by C.
 */
#define	D_RA			 (7*8)
#define	D_S0			 (8*8)
#define	D_S1			 (9*8)
#define	D_S2			(10*8)
#define	D_S3			(11*8)
#define	D_S4			(12*8)
#define	D_S5			(13*8)
#define	D_S6			(14*8)
#define	DISPATCH_FRAME_SIZE	(15*8)
#define	DISPATCH_REGS		IM_RA|IM_S0|IM_S1|IM_S2|IM_S3|IM_S4|IM_S5|IM_S6

NESTED(prom_dispatch, 5, DISPATCH_FRAME_SIZE, ra, DISPATCH_REGS, 0)
	LDGP(pv)

	lda	sp, -DISPATCH_FRAME_SIZE(sp)
	stq	ra, D_RA(sp)
	stq	s0, D_S0(sp)
	stq	s1, D_S1(sp)
	stq	s2, D_S2(sp)
	stq	s3, D_S3(sp)
	stq	s4, D_S4(sp)
	stq	s5, D_S5(sp)
	stq	s6, D_S6(sp)

	/* Lord have mercy because.. I would not. */
/* #define	STUPID_PROM_IS_32_BITS */
#ifdef	STUPID_PROM_IS_32_BITS
	ldah	s0, 0x2000(zero)	/* hack for hack */
	lda	s0, (0x2000-8)(s0)

	stq	sp, 0(s0)
	or	s0, zero, sp
#endif	/* STUPID_PROM_IS_32_BITS */

	lda	pv, prom_dispatch_v
	ldq	v0, 0(pv)		/* routine */
	ldq	pv, 8(pv)		/* routine_arg */

	jsr	ra, (v0)

#ifdef	STUPID_PROM_IS_32_BITS
	ldah	s0, 0x2000(zero)	/* hack for hack */
	lda	s0, (0x2000-8)(s0)

	ldq	sp, 0(s0)
#endif	/* STUPID_PROM_IS_32_BITS */

	ldq	ra, D_RA(sp)
	ldq	s0, D_S0(sp)
	ldq	s1, D_S1(sp)
	ldq	s2, D_S2(sp)
	ldq	s3, D_S3(sp)
	ldq	s4, D_S4(sp)
	ldq	s5, D_S5(sp)
	ldq	s6, D_S6(sp)
	lda	sp, DISPATCH_FRAME_SIZE(sp)
	RET
END(prom_dispatch)

#undef	D_RA
#undef	D_S0
#undef	D_S1
#undef	D_S2
#undef	D_S3
#undef	D_S4
#undef	D_S5
#undef	D_S6
#undef	DISPATCH_FRAME_SIZE
#undef	DISPATCH_REGS


code:
/*	$OpenBSD: puts.c,v 1.3 1996/10/30 22:40:35 niklas Exp $	*/

void
puts(s)
	char *s;
{

	while (*s)
		putchar(*s++);
}


code:
/Makefile/1.3/Sat Jul 19 00:03:51 2003//TOPENBSD_5_8_BASE
/setnetbootinfo.8/1.8/Sun Feb  1 10:48:57 2009//TOPENBSD_5_8_BASE
/setnetbootinfo.c/1.4/Sat Jul 12 19:01:49 2014//TOPENBSD_5_8_BASE
D


code: src/sys/arch/alpha/stand/setnetbootinfo


code:
#	$OpenBSD: Makefile,v 1.3 2003/07/19 00:03:51 david Exp $
#	$NetBSD: Makefile,v 1.4 1997/04/06 08:41:36 cgd Exp $

.PATH:	${.CURDIR}/..

MAN=	setnetbootinfo.8
MANSUBDIR=alpha

.if ${MACHINE} == "alpha"
PROG=	setnetbootinfo
BINDIR=	/usr/mdec

CFLAGS+= -I${.CURDIR}/..
LDSTATIC=-static
.else
NOPROG=
.endif

.include <bsd.prog.mk>


code:
.\"	$OpenBSD: setnetbootinfo.8,v 1.8 2009/02/01 10:48:57 sobrado Exp $
.\"	$NetBSD: setnetbootinfo.8,v 1.2 1997/04/06 08:41:36 cgd Exp $
.\"
.\" Copyright (c) 1997 Christopher G. Demetriou.  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 Christopher G. Demetriou
.\"      for the NetBSD Project.
.\" 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.
.\"
.Dd $Mdocdate: February 1 2009 $
.Dt SETNETBOOTINFO 8 alpha
.Os
.Sh NAME
.Nm setnetbootinfo
.Nd configure network bootstrap program
.Sh SYNOPSIS
.Nm setnetbootinfo
.Op Fl vf
.Op Fl o Ar infile
.Oo
.Fl a Ar ether-address | Fl h Ar ether-host
.Oc
.Ar netboot
.Nm setnetbootinfo
.Op Fl v
.Fl u o Ar outfile Ar infile
.Sh DESCRIPTION
The
.Nm setnetbootinfo
utility configures the OpenBSD/alpha network bootstrap program so
that it can be used to bootstrap systems with old firmware revisions.
.Pp
The OpenBSD/alpha network bootstrap program needs to have the Ethernet
address of the interface being used to boot the system available when
querying other hosts on the network for bootstrapping information.
Alpha systems with old firmware revisions provide no way for
network bootstrap programs to determine the Ethernet address of
the interface that they are booting from, and so the OpenBSD/alpha
network bootstrap program must find that information in another way.
(Newer firmware revisions include the Ethernet address in the name of
the device that is being booted from.)
The
.Nm
utility encodes an Ethernet address (and other information) directly
into the network bootstrap program.
.Pp
The options recognized by
.Nm
are as follows:
.Bl -tag -width flag
.It Fl a Ar ether-address
Encode the given Ethernet address into the network bootstrap program.
(This option and the
.Fl h
option are mutually exclusive.)
.It Fl f
Force the address information being encoded in the bootstrap
program to be used regardless of whether or not the bootstrap
program can get address information from the booting system's
firmware.
.It Fl h Ar ether-host
Encode the Ethernet address of the specified host into the network
bootstrap program.
The host's name is translated to an Ethernet address using the
.Xr ether_hostton 3
function.
(This option and the
.Fl a
option are mutually exclusive.)
.It Fl o Ar outfile
Output the resulting bootstrap program into the file named by
.Ar outfile ,
replacing it if it already exists.
If the
.Fl o
flag is not specified, the output file name will be
the name of the input bootstrap program concatenated with a
period and the digits of the Ethernet address being encoded.
For instance, if the input file is named
.Pa /usr/mdec/netboot
and is being configured to encode the Ethernet address
.Li 08:00:2b:bd:5d:fd ,
then the default output file name would be
.Pa /usr/mdec/netboot.08002bbd5dfd .
It is safe to set the output file name to be the same as the
input file name; the input file is read in its entirety before
the output file is modified.
.It Fl u
Remove configuration information from the specified network
bootstrap program.
If this option is used, an output file name must be specified with the
.Fl o
option, and neither the
.Fl a
or the
.Fl h
options may be specified.
.It Fl v
Verbose mode.
.El
.Sh SEE ALSO
.Xr dhcpd 8
.Sh HISTORY
The alpha
.Nm
command first appeared in
.Nx 1.2b .


code:
/*	$OpenBSD: setnetbootinfo.c,v 1.4 2014/07/12 19:01:49 tedu Exp $	*/
/*	$NetBSD: setnetbootinfo.c,v 1.5 1997/04/06 08:41:37 cgd Exp $	*/

/*
 * Copyright (c) 1997 Christopher G. Demetriou
 * 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 Christopher G. Demetriou
 *	for the NetBSD Project.
 * 4. 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 <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <sys/socket.h>						/* XXX */
#include <net/if.h>						/* XXX */
#include <netinet/in.h>
#include <netinet/if_ether.h>

#include "bbinfo.h"

int	verbose, force, unset;
char	*netboot, *outfile, *addr, *host;

char	*outfilename;

struct ether_addr *ether_addr, _ether_addr;

static void
usage()
{

	(void)fprintf(stderr, "usage:\n");
	(void)fprintf(stderr, "\tsetnetboot [-v] [-f] [-o outfile] \\\n");
	(void)fprintf(stderr, "\t    [-a ether-address | -h ether-host] infile\n");
	(void)fprintf(stderr, "\tsetnetboot [-v] -u -o outfile infile\n");
	exit(1);
}

int
main(argc, argv)
	int argc;
	char *argv[];
{
	struct netbbinfo *netbbinfop;
	struct stat sb;
	u_int64_t *qp, csum;
	char *netbb;
	int c, fd, i;

	while ((c = getopt(argc, argv, "a:fh:o:uv")) != -1) {
		switch (c) {
		case 'a':
			/* use the argument as an ethernet address */
			addr = optarg;
			break;
		case 'f':
			/* set force flag in network boot block */
			force = 1;
			break;
		case 'h':
			/* use the argument as a host to find in /etc/ethers */
			host = optarg;
			break;
		case 'o':
			/* use the argument as the output file name */
			outfile = optarg;
			break;
		case 'u':
			/* remove configuration information */
			unset = 1;
			break;
		case 'v':
			/* Chat */
			verbose = 1;
			break;
		default:
			usage();
		}
	}

	if ((argc - optind) != 1)
		usage();
	netboot = argv[optind];

	if (unset && (force || host != NULL || addr != NULL))
		errx(1, "-u can't be used with -f, -h, or -a");

	if (unset) {
		if (force || host != NULL || addr != NULL)
			errx(1, "-u can't be used with -f, -h, or -a");
		if (outfile == NULL)
			errx(1, "-u cannot be used without -o");
	} else {
		if ((host == NULL && addr == NULL) ||
		    (host != NULL && addr != NULL))
			usage();

		if (host != NULL) {
			if (ether_hostton(host, &_ether_addr) == -1)
				errx(1, "ethernet address couldn't be found for \"%s\"",
				    host);
			ether_addr = &_ether_addr;
		} else { /* addr != NULL */
			ether_addr = ether_aton(addr);
			if (ether_addr == NULL)
				errx(1, "ethernet address \"%s\" is invalid",
				    addr);
		}
	}

	if (outfile != NULL)
		outfilename = outfile;
	else {
		/* name + 12 for enet addr + '.' before enet addr + NUL */
		size_t len = strlen(netboot) + 14;

		outfilename = malloc(len);
		if (outfilename == NULL)
			err(1, "malloc of output file name failed");
		snprintf(outfilename, len,
		    "%s.%02x%02x%02x%02x%02x%02x", netboot,
		    ether_addr->ether_addr_octet[0],
		    ether_addr->ether_addr_octet[1],
		    ether_addr->ether_addr_octet[2],
		    ether_addr->ether_addr_octet[3],
		    ether_addr->ether_addr_octet[4],
		    ether_addr->ether_addr_octet[5]);
	}

	if (verbose) {
		printf("netboot: %s\n", netboot);
		if (unset)
			printf("unsetting configuration\n");
		else
			printf("ethernet address: %s (%s), force = %d\n",
			    ether_ntoa(ether_addr), host ? host : addr, force);
		printf("output netboot: %s\n", outfilename);
	}

	if (verbose)
		printf("opening %s...\n", netboot);
	if ((fd = open(netboot, O_RDONLY, 0)) == -1)
		err(1, "open: %s", netboot);
	if (fstat(fd, &sb) == -1)
		err(1, "fstat: %s", netboot);
	if (!S_ISREG(sb.st_mode))
		errx(1, "%s must be a regular file", netboot);

	if (verbose)
		printf("reading %s...\n", netboot);
	netbb = malloc(sb.st_size);
	if (netbb == NULL)
		err(1, "malloc of %lu for %s failed",
		    (unsigned long)sb.st_size, netboot);
	if (read(fd, netbb, sb.st_size) != sb.st_size)
		err(1, "read of %lu from %s failed",
		    (unsigned long)sb.st_size, netboot);

	if (verbose)
		printf("closing %s...\n", netboot);
	close(fd);

	if (verbose)
		printf("looking for netbbinfo...\n");
	netbbinfop = NULL;
	for (qp = (u_int64_t *)netbb; qp < (u_int64_t *)(netbb + sb.st_size);
	    qp++) {
		if (((struct netbbinfo *)qp)->magic1 == 0xfeedbabedeadbeef &&
		    ((struct netbbinfo *)qp)->magic2 == 0xfeedbeefdeadbabe) {
			netbbinfop = (struct netbbinfo *)qp;
			break;
		}
	}
	if (netbbinfop == NULL)
		errx(1, "netboot information structure not found in %s",
		    netboot);
	if (verbose)
		printf("found netbbinfo structure at offset 0x%lx.\n",
		    (unsigned long)((char *)netbbinfop - netbb));

	if (verbose)
		printf("setting netbbinfo structure...\n");
	bzero(netbbinfop, sizeof *netbbinfop);
	netbbinfop->magic1 = 0xfeedbabedeadbeef;
	netbbinfop->magic2 = 0xfeedbeefdeadbabe;
	netbbinfop->set = unset ? 0 : 1;
	if (netbbinfop->set) {
		for (i = 0; i < 6; i++)
			netbbinfop->ether_addr[i] =
			    ether_addr->ether_addr_octet[i];
		netbbinfop->force = force;
	}
	netbbinfop->cksum = 0;

	if (verbose)
		printf("setting netbbinfo checksum...\n");
	csum = 0;
	for (i = 0, qp = (u_int64_t *)netbbinfop;
	    i < (sizeof *netbbinfop / sizeof (u_int64_t)); i++, qp++)
		csum += *qp;
	netbbinfop->cksum = -csum;

	if (verbose)
		printf("opening %s...\n", outfilename);
	if ((fd = open(outfilename, O_WRONLY | O_CREAT, 0666)) == -1)
		err(1, "open: %s", outfilename);

	if (verbose)
		printf("writing %s...\n", outfilename);
	if (write(fd, netbb, sb.st_size) != sb.st_size)
		err(1, "write of %lu to %s failed",
		    (unsigned long)sb.st_size, outfilename);

	if (verbose)
		printf("closing %s...\n", outfilename);
	close(fd);

	free(netbb);
	if (outfile == NULL)
		free(outfilename);

	exit (0);
}


code:
/*	$OpenBSD: start.S,v 1.6 2011/06/05 21:49:36 miod Exp $	*/
/*	$NetBSD: start.S,v 1.4 1996/10/17 02:50:40 cgd Exp $	*/

/*
 * Mach Operating System
 * Copyright (c) 1992 Carnegie Mellon University
 * All Rights Reserved.
 *
 * 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 Mellon
 * the rights to redistribute these changes.
 */

#include "include/asm.h"

/*
 * start --
 *	Entry point for boot/standalone programs.
 *
 * Arguments:
 *	a0				long (first free physical page)
 *
 * This is where the prom comes to.  Leaves all exception and interrupts
 * to prom, runs off prom's stack too.  No return values.
 */
	.text
	.set	noreorder		/* don't reorder instructions */

#define ENTRY_FRAME	32

NESTED(start, 1, ENTRY_FRAME, ra, 0, 0)
	br	pv,Lstartgp
Lstartgp:
	LDGP(pv)

	lda	sp,start
#ifdef PRIMARY_BOOTBLOCK
	lda	sp,0x30000-ENTRY_FRAME(sp)
#else
	lda	sp,-ENTRY_FRAME(sp)	/* start stack below text */
#endif

	or	a0,zero,s0
	lda	a0,_edata
	lda	a1,_end
	subq	a1,a0,a1
	CALL(bzero)
	or	s0,zero,a0

	CALL(main)			/* transfer to C */

XLEAF(_rtt, 0)
XLEAF(halt, 0)
	call_pal PAL_halt		/* halt if we ever return */
END(start)

/*
 * Dummy routine for GCC2.
 */
LEAF(__main,0)
	RET
END(__main)

/*
 * cpu_number
 *	Return the cpu number, using the whami instruction.
 */
LEAF(cpu_number, 0)
	call_pal PAL_VMS_mfpr_whami
	RET
END(cpu_number)


code: src/sys/arch/alpha/tc

path: sys/arch/alpha/tc/CVS/Repository


code:
/*	$OpenBSD: cfb.c,v 1.23 2013/10/20 20:07:22 miod Exp $	*/
/*	$NetBSD: cfb.c,v 1.7 1996/12/05 01:39:39 cgd Exp $	*/

/*
 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 *
 * 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.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/buf.h>
#include <sys/conf.h>
#include <sys/ioctl.h>

#include <uvm/uvm_extern.h>

#include <machine/bus.h>
#include <machine/intr.h>

#include <dev/tc/tcvar.h>
#include <machine/cfbreg.h>
#include <alpha/tc/cfbvar.h>

#include <dev/rcons/raster.h>
#include <dev/wscons/wscons_raster.h>
#include <dev/wscons/wsdisplayvar.h>
#include <machine/fbio.h>

#include <machine/autoconf.h>
#include <machine/pte.h>

int	cfbmatch(struct device *, void *, void *);
void	cfbattach(struct device *, struct device *, void *);

struct cfattach cfb_ca = {
	sizeof(struct cfb_softc), cfbmatch, cfbattach,
};

struct cfdriver cfb_cd = {
	NULL, "cfb", DV_DULL,
};

void	cfb_getdevconfig(tc_addr_t dense_addr, struct cfb_devconfig *dc);
struct cfb_devconfig cfb_console_dc;
tc_addr_t cfb_consaddr;

struct wsdisplay_emulops cfb_emulfuncs = {
	rcons_cursor,			/* could use hardware cursor; punt */
	rcons_mapchar,
	rcons_putchar,
	rcons_copycols,
	rcons_erasecols,
	rcons_copyrows,
	rcons_eraserows,
	rcons_alloc_attr
};

struct wsscreen_descr cfb_stdscreen = {
        "std",
        0, 0,        /* will be filled in -- XXX shouldn't, it's global */
        &cfb_emulfuncs,
        0, 0
};

const struct wsscreen_descr *_cfb_scrlist[] = {
        &cfb_stdscreen,
        /* XXX other formats, graphics screen? */
};

struct wsscreen_list cfb_screenlist = {
        sizeof(_cfb_scrlist) / sizeof(struct wsscreen_descr *), _cfb_scrlist
};

int	cfbioctl(void *, u_long, caddr_t, int, struct proc *);
paddr_t	cfbmmap(void *, off_t, int);

int	cfbintr(void *);
static int      cfb_alloc_screen(void *, const struct wsscreen_descr *,
		    void **, int *, int *, long *);
static void     cfb_free_screen(void *, void *);
static int      cfb_show_screen(void *, void *, int,
		    void (*) (void *, int, int), void *);

struct wsdisplay_accessops cfb_accessops = {
	.ioctl = cfbioctl,
	.mmap = cfbmmap,
	.alloc_screen = cfb_alloc_screen,
	.free_screen = cfb_free_screen,
	.show_screen = cfb_show_screen
};

int
cfbmatch(parent, match, aux)
	struct device *parent;
	void *match;
	void *aux;
{
	struct tc_attach_args *ta = aux;

	if (strncmp("PMAG-BA ", ta->ta_modname, TC_ROM_LLEN) != 0)
		return (0);

	return (10);
}

void
cfb_getdevconfig(dense_addr, dc)
	tc_addr_t dense_addr;
	struct cfb_devconfig *dc;
{
	struct raster *rap;
	struct rcons *rcp;
	char *ramdacregp;
	int i;

	dc->dc_vaddr = dense_addr;
	dc->dc_paddr = ALPHA_K0SEG_TO_PHYS(dc->dc_vaddr);	/* XXX */
	dc->dc_size = CFB_SIZE;

	ramdacregp = (char *)dc->dc_vaddr + CFB_RAMDAC_OFFSET;

	dc->dc_wid = 1024;
	dc->dc_ht = 864;
	dc->dc_depth = 8;			/* 8 plane */
	dc->dc_rowbytes = dc->dc_wid * (dc->dc_depth / 8);

	dc->dc_videobase = dc->dc_vaddr + CFB_FB_OFFSET;

	/* Initialize the RAMDAC/colormap */
	/* start XXX XXX XXX */
	(*(volatile u_int32_t *)(ramdacregp + CFB_RAMDAC_ADDRLOW)) = 0;
	(*(volatile u_int32_t *)(ramdacregp + CFB_RAMDAC_ADDRHIGH)) = 0;
	tc_wmb();
	for (i = 0; i < 256; i++) {
		(*(volatile u_int32_t *)(ramdacregp + CFB_RAMDAC_CMAPDATA)) =
		    i ? 0xff : 0;
		tc_wmb();
		(*(volatile u_int32_t *)(ramdacregp + CFB_RAMDAC_CMAPDATA)) =
		    i ? 0xff : 0;
		tc_wmb();
		(*(volatile u_int32_t *)(ramdacregp + CFB_RAMDAC_CMAPDATA)) =
		    i ? 0xff : 0;
		tc_wmb();
	}
	/* end XXX XXX XXX */

	/* clear the screen */
	for (i = 0; i < dc->dc_ht * dc->dc_rowbytes; i += sizeof(u_int32_t))
		*(u_int32_t *)(dc->dc_videobase + i) = 0x00000000;

	rap = &dc->dc_raster;
	rap->width = dc->dc_wid;
	rap->height = dc->dc_ht;
	rap->depth = 8;
	rap->linelongs = dc->dc_rowbytes / sizeof(u_int32_t);
	rap->pixels = (u_int32_t *)dc->dc_videobase;

	/* initialize the raster console blitter */
	rcp = &dc->dc_rcons;
	rcp->rc_sp = rap;
	rcp->rc_crow = rcp->rc_ccol = -1;
	rcp->rc_crowp = &rcp->rc_crow;
	rcp->rc_ccolp = &rcp->rc_ccol;
	rcons_init(rcp, 34, 80);

	cfb_stdscreen.nrows = dc->dc_rcons.rc_maxrow;
	cfb_stdscreen.ncols = dc->dc_rcons.rc_maxcol;
}

void
cfbattach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct cfb_softc *sc = (struct cfb_softc *)self;
	struct tc_attach_args *ta = aux;
	struct wsemuldisplaydev_attach_args waa;
	int console;

	console = (ta->ta_addr == cfb_consaddr);
	if (console) {
		sc->sc_dc = &cfb_console_dc;
		sc->nscreens = 1;
	} else {
		sc->sc_dc = (struct cfb_devconfig *)
		    malloc(sizeof(struct cfb_devconfig), M_DEVBUF, M_WAITOK);
		cfb_getdevconfig(ta->ta_addr, sc->sc_dc);
	}
	if (sc->sc_dc->dc_vaddr == NULL) {
		printf(": can't map mem space\n");
		return;
	}
	printf(": %d x %d, %dbpp\n", sc->sc_dc->dc_wid, sc->sc_dc->dc_ht,
	    sc->sc_dc->dc_depth);

	/* Establish an interrupt handler, and clear any pending interrupts */
        tc_intr_establish(parent, ta->ta_cookie, IPL_TTY, cfbintr, sc,
	    self->dv_xname);
	*(volatile u_int32_t *)(sc->sc_dc->dc_vaddr + CFB_IREQCTRL_OFFSET) = 0;

	/* initialize the raster */
	waa.console = console;
	waa.scrdata = &cfb_screenlist;
	waa.accessops = &cfb_accessops;
	waa.accesscookie = sc;
	waa.defaultscreens = 0;

	config_found(self, &waa, wsemuldisplaydevprint);
}

int
cfbioctl(v, cmd, data, flag, p)
	void *v;
	u_long cmd;
	caddr_t data;
	int flag;
	struct proc *p;
{
	struct cfb_softc *sc = v;
	struct cfb_devconfig *dc = sc->sc_dc;

	switch (cmd) {
	case FBIOGTYPE:
#define fbt ((struct fbtype *)data)
		fbt->fb_type = FBTYPE_CFB;
		fbt->fb_height = sc->sc_dc->dc_ht;
		fbt->fb_width = sc->sc_dc->dc_wid;
		fbt->fb_depth = sc->sc_dc->dc_depth;
		fbt->fb_cmsize = 256;		/* XXX ??? */
		fbt->fb_size = sc->sc_dc->dc_size;
#undef fbt
		return (0);

#if 0
	case FBIOPUTCMAP:
		return (*tgar->tgar_set_cmap)(dc, (struct fbcmap *)data);

	case FBIOGETCMAP:
		return (*tgar->tgar_get_cmap)(dc, (struct fbcmap *)data);
#endif

	case FBIOGATTR:
		return (ENOTTY);			/* XXX ? */

#if 0
	case FBIOSVIDEO:
		if (*(int *)data == FBVIDEO_OFF)
			cfb_blank(sc->sc_dc);
		else
			cfb_unblank(sc->sc_dc);
		return (0);
#endif

	case FBIOGVIDEO:
		*(int *)data = dc->dc_blanked ? FBVIDEO_OFF : FBVIDEO_ON;
		return (0);

#if 0
	case FBIOSCURSOR:
		return (*tgar->tgar_set_cursor)(dc, (struct fbcursor *)data);

	case FBIOGCURSOR:
		return (*tgar->tgar_get_cursor)(dc, (struct fbcursor *)data);

	case FBIOSCURPOS:
		return (*tgar->tgar_set_curpos)(dc, (struct fbcurpos *)data);

	case FBIOGCURPOS:
		return (*tgar->tgar_get_curpos)(dc, (struct fbcurpos *)data);

	case FBIOGCURMAX:
		return (*tgar->tgar_get_curmax)(dc, (struct fbcurpos *)data);
#endif
	}
	return (-1);
}

paddr_t
cfbmmap(v, offset, prot)
	void *v;
	off_t offset;
	int prot;
{
	struct cfb_softc *sc = v;

	if (offset > CFB_SIZE)
		return (-1);
	return sc->sc_dc->dc_paddr + offset;
}

int
cfbintr(v)
	void *v;
{
	struct cfb_softc *sc = v;

	*(volatile u_int32_t *)(sc->sc_dc->dc_vaddr + CFB_IREQCTRL_OFFSET) = 0;

	return (1);
}

int
cfb_alloc_screen(v, type, cookiep, curxp, curyp, attrp)
	void *v;
	const struct wsscreen_descr *type;
	void **cookiep;
	int *curxp, *curyp;
	long *attrp;
{
	struct cfb_softc *sc = v;
	long defattr;

	if (sc->nscreens > 0)
		return (ENOMEM);

	*cookiep = &sc->sc_dc->dc_rcons; /* one and only for now */
	*curxp = 0;
	*curyp = 0;
	rcons_alloc_attr(&sc->sc_dc->dc_rcons, 0, 0, 0, &defattr);
	*attrp = defattr;
	sc->nscreens++;
	return(0);
}

void
cfb_free_screen(v, cookie)
	void *v;
	void *cookie;
{
	struct cfb_softc *sc = v;

	if (sc->sc_dc == &cfb_console_dc)
		panic("cfb_free_screen: console");

	sc->nscreens--;
}

int
cfb_show_screen(v, cookie, waitok, cb, cbarg)
	void *v;
	void *cookie;
	int waitok;
	void (*cb)(void *, int, int);
	void *cbarg;
{
	return (0);
}

#if 0
int
cfb_cnattach(addr)
	tc_addr_t addr;
{
	struct cfb_devconfig *dc = &cfb_console_dc;
	long defattr;

	cfb_getdevconfig(addr, dcp);

	rcons_alloc_attr(&dcp->dc_rcons, 0, 0, 0, &defattr);

	wsdisplay_cnattach(&cfb_stdscreen, &dcp->dc_rcons,
		0,0, defattr;);

	cfb_consaddr = addr;
	return (0);
}
#endif


code:
/*	$OpenBSD: cfbvar.h,v 1.7 2005/12/17 07:31:25 miod Exp $	*/
/*	$NetBSD: cfbvar.h,v 1.1 1996/05/01 23:25:04 cgd Exp $	*/

/*
 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 *
 * 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.
 */

#include <machine/cfbreg.h>
#include <dev/rcons/raster.h>
#include <dev/wscons/wscons_raster.h>

struct cfb_devconfig;
struct fbcmap;
struct fbcursor;
struct fbcurpos;

struct cfb_devconfig {
	vaddr_t dc_vaddr;		/* memory space virtual base address */
	paddr_t dc_paddr;		/* memory space physical base address */
	vsize_t dc_size;		/* size of slot memory */

	int	    dc_wid;		/* width of frame buffer */
	int	    dc_ht;		/* height of frame buffer */
	int	    dc_depth;		/* depth, bits per pixel */
	int	    dc_rowbytes;	/* bytes in a FB scan line */

	vaddr_t	dc_videobase;		/* base of flat frame buffer */

	struct raster	dc_raster;	/* raster description */
	struct rcons	dc_rcons;	/* raster blitter control info */

	int	    dc_blanked;		/* currently has video disabled */
};

struct cfb_softc {
	struct device sc_dev;

	struct cfb_devconfig *sc_dc;	/* device configuration */

	int nscreens;
};

#if 0
int cfb_cnattach(tc_addr_t);
#endif


code:
/* $OpenBSD: ioasic.c,v 1.17 2010/09/20 06:33:46 matthew Exp $ */
/* $NetBSD: ioasic.c,v 1.34 2000/07/18 06:10:06 thorpej Exp $ */

/*-
 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Jason R. Thorpe of the Numerical Aerospace Simulation 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.
 *
 * 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 FOUNDATION 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.
 */

/*
 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Keith Bostic, Chris G. Demetriou
 *
 * 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.
 */

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/timeout.h>

#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/pte.h>
#include <machine/rpb.h>

#include <dev/tc/tcvar.h>
#include <dev/tc/ioasicreg.h>
#include <dev/tc/ioasicvar.h>
#ifdef DEC_3000_300
#include <alpha/tc/tc_3000_300.h>
#endif

/* Definition of the driver for autoconfig. */
int	ioasicmatch(struct device *, void *, void *);
void	ioasicattach(struct device *, struct device *, void *);

struct cfattach ioasic_ca = {
	sizeof(struct ioasic_softc), ioasicmatch, ioasicattach,
};

struct cfdriver ioasic_cd = {
	NULL, "ioasic", DV_DULL,
};

int	ioasic_intr(void *);
int	ioasic_intrnull(void *);

#define	C(x)	((void *)(u_long)(x))
#define	KV(x)	(ALPHA_PHYS_TO_K0SEG(x))

#define	IOASIC_DEV_LANCE	0
#define	IOASIC_DEV_SCC0		1
#define	IOASIC_DEV_SCC1		2
#define	IOASIC_DEV_ISDN		3

#define	IOASIC_DEV_BOGUS	-1

#define	IOASIC_NCOOKIES		4

struct ioasic_dev ioasic_devs[] = {
	{ "PMAD-BA ", IOASIC_SLOT_3_START, C(IOASIC_DEV_LANCE),
	  IOASIC_INTR_LANCE, },
	{ "z8530   ", IOASIC_SLOT_4_START, C(IOASIC_DEV_SCC0),
	  IOASIC_INTR_SCC_0, },
	{ "z8530   ", IOASIC_SLOT_6_START, C(IOASIC_DEV_SCC1),
	  IOASIC_INTR_SCC_1, },
	{ "TOY_RTC ", IOASIC_SLOT_8_START, C(IOASIC_DEV_BOGUS),
	  0, },
	{ "AMD79c30", IOASIC_SLOT_9_START, C(IOASIC_DEV_ISDN),
	  IOASIC_INTR_ISDN_TXLOAD | IOASIC_INTR_ISDN_RXLOAD,  },
};
int ioasic_ndevs = sizeof(ioasic_devs) / sizeof(ioasic_devs[0]);

struct ioasicintr {
	int	(*iai_func)(void *);
	void	*iai_arg;
	struct evcount iai_count;
} ioasicintrs[IOASIC_NCOOKIES];

tc_addr_t ioasic_base;		/* XXX XXX XXX */

/* There can be only one. */
int ioasicfound;

int
ioasicmatch(parent, cfdata, aux)
	struct device *parent;
	void *cfdata, *aux;
{
	struct tc_attach_args *ta = aux;

	/* Make sure that we're looking for this type of device. */
	if (strncmp("FLAMG-IO", ta->ta_modname, TC_ROM_LLEN))
		return (0);

	/* Check that it can actually exist. */
	if ((cputype != ST_DEC_3000_500) && (cputype != ST_DEC_3000_300))
		panic("ioasicmatch: how did we get here?");

	if (ioasicfound)
		return (0);

	return (1);
}

void
ioasicattach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct ioasic_softc *sc = (struct ioasic_softc *)self;
	struct tc_attach_args *ta = aux;
#ifdef DEC_3000_300
	u_long ssr;
#endif
	u_long i, imsk;

	ioasicfound = 1;

	sc->sc_bst = ta->ta_memt;
	if (bus_space_map(ta->ta_memt, ta->ta_addr,
			0x400000, 0, &sc->sc_bsh)) {
		printf("%s: unable to map device\n", sc->sc_dv.dv_xname);
		return;
	}
	sc->sc_dmat = ta->ta_dmat;

	ioasic_base = sc->sc_base = ta->ta_addr; /* XXX XXX XXX */

#ifdef DEC_3000_300
	if (cputype == ST_DEC_3000_300) {
		ssr = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR);
		ssr |= IOASIC_CSR_FASTMODE;
		bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_CSR, ssr);
		printf(": slow mode\n");
	} else
#endif
		printf(": fast mode\n");

	/*
	 * Turn off all device interrupt bits.
	 * (This does _not_ include 3000/300 TC option slot bits).
	 */
	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
	for (i = 0; i < ioasic_ndevs; i++)
		imsk &= ~ioasic_devs[i].iad_intrbits;
	bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);

	/*
	 * Set up interrupt handlers.
	 */
	for (i = 0; i < IOASIC_NCOOKIES; i++) {
		ioasicintrs[i].iai_func = ioasic_intrnull;
		ioasicintrs[i].iai_arg = (void *)i;
	}
	tc_intr_establish(parent, ta->ta_cookie, IPL_NONE, ioasic_intr, sc,
	    NULL);

	/*
	 * Try to configure each device.
	 */
	ioasic_attach_devs(sc, ioasic_devs, ioasic_ndevs);
}

void
ioasic_intr_establish(ioa, cookie, level, func, arg, name)
	struct device *ioa;
	void *cookie, *arg;
	int level;
	int (*func)(void *);
	const char *name;
{
	struct ioasic_softc *sc = (void *)ioasic_cd.cd_devs[0];
	u_long dev, i, imsk;

	dev = (u_long)cookie;
#ifdef DIAGNOSTIC
	/* XXX check cookie. */
#endif

	if (ioasicintrs[dev].iai_func != ioasic_intrnull)
		panic("ioasic_intr_establish: cookie %lu twice", dev);

	ioasicintrs[dev].iai_func = func;
	ioasicintrs[dev].iai_arg = arg;
	evcount_attach(&ioasicintrs[dev].iai_count, name, NULL);

	/* Enable interrupts for the device. */
	for (i = 0; i < ioasic_ndevs; i++)
		if (ioasic_devs[i].iad_cookie == cookie)
			break;
	if (i == ioasic_ndevs)
		panic("ioasic_intr_establish: invalid cookie.");

	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
        imsk |= ioasic_devs[i].iad_intrbits;
        bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);
}

void
ioasic_intr_disestablish(ioa, cookie)
	struct device *ioa;
	void *cookie;
{
	struct ioasic_softc *sc = (void *)ioasic_cd.cd_devs[0];
	u_long dev, i, imsk;

	dev = (u_long)cookie;
#ifdef DIAGNOSTIC
	/* XXX check cookie. */
#endif

	if (ioasicintrs[dev].iai_func == ioasic_intrnull)
		panic("ioasic_intr_disestablish: cookie %lu missing intr", dev);

	/* Enable interrupts for the device. */
	for (i = 0; i < ioasic_ndevs; i++)
		if (ioasic_devs[i].iad_cookie == cookie)
			break;
	if (i == ioasic_ndevs)
		panic("ioasic_intr_disestablish: invalid cookie.");

	imsk = bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK);
	imsk &= ~ioasic_devs[i].iad_intrbits;
	bus_space_write_4(sc->sc_bst, sc->sc_bsh, IOASIC_IMSK, imsk);

	ioasicintrs[dev].iai_func = ioasic_intrnull;
	ioasicintrs[dev].iai_arg = (void *)dev;
	evcount_detach(&ioasicintrs[dev].iai_count);
}

int
ioasic_intrnull(val)
	void *val;
{

	panic("ioasic_intrnull: uncaught IOASIC intr for cookie %ld",
	    (u_long)val);
}

/*
 * ASIC interrupt handler.
 */
int
ioasic_intr(val)
	void *val;
{
	register struct ioasic_softc *sc = val;
	register int ifound;
	int gifound;
	u_int32_t sir, osir;

	gifound = 0;
	do {
		ifound = 0;
		tc_syncbus();

		osir = sir =
		    bus_space_read_4(sc->sc_bst, sc->sc_bsh, IOASIC_INTR);

		/* XXX DUPLICATION OF INTERRUPT BIT INFORMATION... */
#define	CHECKINTR(slot, bits, clear)					\
		if (sir & (bits)) {					\
			ifound = 1;					\
			ioasicintrs[slot].iai_count.ec_count++;		\
			(*ioasicintrs[slot].iai_func)			\
			    (ioasicintrs[slot].iai_arg);		\
			if (clear)					\
				sir &= ~(bits);				\
		}
		CHECKINTR(IOASIC_DEV_SCC0, IOASIC_INTR_SCC_0, 0);
		CHECKINTR(IOASIC_DEV_SCC1, IOASIC_INTR_SCC_1, 0);
		CHECKINTR(IOASIC_DEV_LANCE, IOASIC_INTR_LANCE, 0);
		CHECKINTR(IOASIC_DEV_ISDN, IOASIC_INTR_ISDN_TXLOAD |
		    IOASIC_INTR_ISDN_RXLOAD | IOASIC_INTR_ISDN_OVRUN, 1);

		if (sir != osir)
			bus_space_write_4(sc->sc_bst, sc->sc_bsh,
			    IOASIC_INTR, sir);

		gifound |= ifound;
	} while (ifound);

	return (gifound);
}

/*
 * Blink leds
 */

struct {
	int		patpos;
	struct timeout	tmo;
} led_blink_state;

static const uint8_t led_pattern8[] = {
	0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
	0x40, 0x20, 0x10, 0x08, 0x04, 0x02
};

void
ioasic_led_blink(void *unused)
{
	extern int alpha_led_blink;
	vaddr_t rw_csr;
	u_int32_t pattern;
	int display_loadavg;

	if (alpha_led_blink == 0) {
		pattern = 0;	/* all clear */
		led_blink_state.patpos = 0;
	} else {
#ifdef DEC_3000_300
		if (cputype == ST_DEC_3000_300)
			display_loadavg = 0;
		else
#endif
		switch (hwrpb->rpb_variation & SV_ST_MASK) {
		case SV_ST_FLAMINGO:
		case SV_ST_HOTPINK:
		case SV_ST_FLAMINGOPLUS:
		case SV_ST_ULTRA:
		case SV_ST_FLAMINGO45:
			/* 500/800/900, 2 7-segment display, display loadavg */
			display_loadavg = 1;
			break;
		case SV_ST_SANDPIPER:
		case SV_ST_SANDPLUS:
		case SV_ST_SANDPIPER45:
		default:
			/* 400/600/700, 8 leds, display moving pattern */
			display_loadavg = 0;
			break;
		}

		if (display_loadavg)
			pattern = averunnable.ldavg[0] >> FSHIFT;
		else {
			pattern = led_pattern8[led_blink_state.patpos];
			led_blink_state.patpos =
			    (led_blink_state.patpos + 1) % sizeof(led_pattern8);
		}
	}

	/*
	 * The low 8 bits, controlling the leds, are read-only in the
	 * CSR register, but read-write in its image at CSR + 4.
	 *
	 * On model 300, however, the internal 8 leds are at a different
	 * address, but the (better visible) power supply led is actually
	 * bit 5 in CSR (active low).
	 */
#ifdef DEC_3000_300
	if (cputype == ST_DEC_3000_300) {
		rw_csr = KV(0x1a0000000 + IOASIC_CSR + 4);

		*(volatile uint32_t *)TC_3000_300_LED =
		    (*(volatile uint32_t *)TC_3000_300_LED & ~(0xff << 16)) |
		     (pattern << 16);
		/*
		 * Blink the power supply led 8x slower.  This relies
		 * on led_pattern8[] being a < 16 element array.
		 */
		*(volatile uint32_t *)rw_csr =
		    (*(volatile uint32_t *)rw_csr & ~(1 << 5)) ^
		    ((led_blink_state.patpos >> 3) << 5);
	} else
#endif
	{
		rw_csr = KV(0x1e0000000 + IOASIC_CSR + 4);

		*(volatile uint32_t *)rw_csr =
		    (*(volatile uint32_t *)rw_csr & ~0xff) | pattern;
	}

	if (alpha_led_blink != 0) {
		timeout_set(&led_blink_state.tmo, ioasic_led_blink, NULL);
		timeout_add(&led_blink_state.tmo,
		    (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 3)));
	}
}


code:
/* $OpenBSD: mcclock_ioasic.c,v 1.6 2002/05/02 22:56:06 miod Exp $ */
/* $NetBSD: mcclock_ioasic.c,v 1.9 2000/07/04 02:37:51 nisimura Exp $ */

/*
 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
 * All rights reserved.
 *
 * Author: Chris G. Demetriou
 *
 * 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.
 */

#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <dev/dec/clockvar.h>
#include <dev/dec/mcclockvar.h>
#include <dev/ic/mc146818reg.h>
#include <dev/tc/tcvar.h>
#include <dev/tc/ioasicvar.h>                   /* XXX */

struct mcclock_ioasic_clockdatum {
	u_char	datum;
	char	pad[3];
};

struct mcclock_ioasic_softc {
	struct mcclock_softc	sc_mcclock;

	struct mcclock_ioasic_clockdatum *sc_dp;
};

int	mcclock_ioasic_match(struct device *, void *, void *);
void	mcclock_ioasic_attach(struct device *, struct device *, void *);

struct cfattach mcclock_ioasic_ca = {
	sizeof (struct mcclock_ioasic_softc), mcclock_ioasic_match,
	    mcclock_ioasic_attach,
};

void	mcclock_ioasic_write(struct mcclock_softc *, u_int, u_int);
u_int	mcclock_ioasic_read(struct mcclock_softc *, u_int);

const struct mcclock_busfns mcclock_ioasic_busfns = {
	mcclock_ioasic_write, mcclock_ioasic_read,
};

int
mcclock_ioasic_match(parent, match, aux)
	struct device *parent;
	void *match, *aux;
{
	struct ioasicdev_attach_args *d = aux;

	if (strncmp("TOY_RTC ", d->iada_modname, TC_ROM_LLEN))
		return (0);

	return (1);
}

void
mcclock_ioasic_attach(parent, self, aux)
	struct device *parent, *self;
	void *aux;
{
	struct ioasicdev_attach_args *ioasicdev = aux;
	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)self;

	sc->sc_dp = (struct mcclock_ioasic_clockdatum *)ioasicdev->iada_addr;

	mcclock_attach(&sc->sc_mcclock, &mcclock_ioasic_busfns);
}

void
mcclock_ioasic_write(dev, reg, datum)
	struct mcclock_softc *dev;
	u_int reg, datum;
{
	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;

	sc->sc_dp[reg].datum = datum;
}

u_int
mcclock_ioasic_read(dev, reg)
	struct mcclock_softc *dev;
	u_int reg;
{
	struct mcclock_ioasic_softc *sc = (struct mcclock_ioasic_softc *)dev;

	return (sc->sc_dp[reg].datum);
}