summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/alpha/stand/nboot/Makefile67
-rw-r--r--sys/arch/alpha/stand/nboot/conf.c70
-rw-r--r--sys/arch/alpha/stand/nboot/devopen.c43
-rw-r--r--sys/arch/alpha/stand/nboot/disk.c166
-rw-r--r--sys/arch/alpha/stand/nboot/libsa.h36
-rw-r--r--sys/arch/alpha/stand/nboot/machdep.c218
-rw-r--r--sys/arch/alpha/stand/nboot/prom.c74
-rw-r--r--sys/arch/alpha/stand/nboot/prom_swpal.S136
-rw-r--r--sys/arch/alpha/stand/nboot/promcons.c96
-rw-r--r--sys/arch/alpha/stand/nboot/rpcc.S10
10 files changed, 916 insertions, 0 deletions
diff --git a/sys/arch/alpha/stand/nboot/Makefile b/sys/arch/alpha/stand/nboot/Makefile
new file mode 100644
index 00000000000..ee2409cead6
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/Makefile
@@ -0,0 +1,67 @@
+# $OpenBSD: Makefile,v 1.1 2023/03/11 20:56:01 miod Exp $
+# $NetBSD: Makefile,v 1.17 1997/04/17 07:27:46 thorpej Exp $
+
+S= ${.CURDIR}/../../../..
+
+PROG= boot
+NOMAN=
+INSTALL_STRIP=
+BINMODE= 444
+
+# Needs to be first
+SRCS= start.S
+
+SRCS+= conf.c devopen.c disk.c machdep.c prom.c promcons.c \
+ prom_swpal.S rpcc.S
+
+BOOT_RELOC = ${SECONDARY_LOAD_ADDRESS}
+
+CLEANFILES+= ${PROG}.sym ${PROG}.nosym
+
+.PATH: ${.CURDIR}/..
+SRCS+= OSFpal.c loadfile_subr.c prom_disp.S
+
+.PATH: ${S}/stand/boot
+SRCS+= boot.c cmd.c vars.c
+
+.PATH: ${S}/lib/libkern/arch/alpha ${S}/lib/libkern
+SRCS+= __divlu.S __remqu.S __reml.S strlen.c bzero.c __divl.S __divqu.S \
+ __remlu.S __divq.S __remq.S
+SRCS+= strlcpy.c
+
+.PATH: ${S}/lib/libkern/arch/alpha ${S}/lib/libsa
+SRCS+= loadfile.c arc4.c ctime.c hexdump.c strtol.c strtoll.c ufs2.c
+
+DEFNS= -DCOMPAT_UFS
+
+AFLAGS += -DASSEMBLER ${DEFNS} -fno-pie
+CPPFLAGS += -I${.CURDIR}/../.. -I${.CURDIR} -I${S} ${DEFNS}
+CFLAGS = -Oz -Werror -mno-fp-regs -fno-pie -msmall-data -msmall-text
+
+${PROG}.nosym: ${PROG}.sym
+ cp ${PROG}.sym ${PROG}.nosym
+ ${STRIP} ${PROG}.nosym
+
+${PROG}: ${PROG}.nosym
+ ${OBJCOPY} --output-target=binary ${PROG}.nosym ${PROG}
+
+.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}
+ ${LD} -nopie -znorelro -Ttext ${BOOT_RELOC} -N -e start \
+ -o ${PROG}.sym ${OBJS} ${LIBSA} ${LIBZ} ${LIBSA}
+ size ${PROG}.sym
diff --git a/sys/arch/alpha/stand/nboot/conf.c b/sys/arch/alpha/stand/nboot/conf.c
new file mode 100644
index 00000000000..d4ebe809cc3
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/conf.c
@@ -0,0 +1,70 @@
+/* $OpenBSD: conf.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */
+/* $NetBSD: conf.c,v 1.3 1995/11/23 02:39:31 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.
+ *
+ * @(#)conf.c 8.1 (Berkeley) 6/10/93
+ */
+
+#include "libsa.h"
+
+#include <lib/libsa/ufs.h>
+#include <lib/libsa/ufs2.h>
+#include <lib/libsa/cd9660.h>
+#include <dev/cons.h>
+
+const char version[] = "2.0";
+#ifdef DEBUG
+int debug = 0;
+#endif
+
+struct fs_ops file_system[] = {
+ { ufs_open, ufs_close, ufs_read, ufs_write,
+ ufs_seek, ufs_stat, ufs_readdir, ufs_fchmod },
+ { ufs2_open, ufs2_close, ufs2_read, ufs2_write,
+ ufs2_seek, ufs2_stat, ufs2_readdir, ufs2_fchmod },
+ { cd9660_open, cd9660_close, cd9660_read, cd9660_write,
+ cd9660_seek, cd9660_stat, cd9660_readdir }
+};
+int nfsys = sizeof(file_system) / sizeof(file_system[0]);
+
+struct devsw devsw[] = {
+ { "disk",
+ diskstrategy, diskopen, diskclose, diskioctl }
+};
+int ndevs = sizeof(devsw) / sizeof(devsw[0]);
+
+struct consdev constab[] = {
+ { prom_cnprobe, prom_cninit, prom_cngetc, prom_cnputc },
+ { NULL }
+};
+struct consdev *cn_tab;
diff --git a/sys/arch/alpha/stand/nboot/devopen.c b/sys/arch/alpha/stand/nboot/devopen.c
new file mode 100644
index 00000000000..d6c9ed90175
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/devopen.c
@@ -0,0 +1,43 @@
+/* $OpenBSD: devopen.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */
+
+/*
+ * Copyright (c) 2023 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 "libsa.h"
+
+int
+devopen(struct open_file *f, const char *fname, char **file)
+{
+ struct devsw *dp;
+ const char *s;
+
+ /*
+ * Unfortunately for us, the BOOTDEF_DEV environment variable
+ * contents does not match the DKA/DQA/DRA/DVA/MKA/EWA... SRM
+ * device names, and we can't convert between them.
+ * So we can only boot files from the same device the boot loader
+ * was loaded from, and ignore any device specification here.
+ */
+ s = strchr(fname, ':');
+ if (s != NULL)
+ *file = (char *)++s;
+ else
+ *file = (char *)fname;
+
+ dp = &devsw[0];
+ f->f_dev = dp;
+ return (*dp->dv_open)(f);
+}
diff --git a/sys/arch/alpha/stand/nboot/disk.c b/sys/arch/alpha/stand/nboot/disk.c
new file mode 100644
index 00000000000..2f0d83d0031
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/disk.c
@@ -0,0 +1,166 @@
+/* $OpenBSD: disk.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */
+/* $NetBSD: disk.c,v 1.6 1997/04/06 08:40:33 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
+ * Van Jacobson of Lawrence Berkeley Laboratory and Ralph Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)rz.c 8.1 (Berkeley) 6/10/93
+ */
+
+#include "libsa.h"
+
+#include <sys/param.h>
+#include <sys/disklabel.h>
+
+#include <machine/rpb.h>
+#include <machine/prom.h>
+
+struct disk_softc {
+ int sc_fd; /* PROM channel number */
+ int sc_part; /* disk partition number */
+ struct disklabel sc_label; /* disk label for this disk */
+};
+
+int
+diskstrategy(void *devdata, int rw, daddr_t bn, size_t reqcnt, void *addrvoid,
+ size_t *cnt)
+{
+ char *addr = addrvoid;
+ struct disk_softc *sc;
+ struct partition *pp;
+ prom_return_t ret;
+ int s;
+
+#ifdef DEBUG
+ if ((reqcnt & 0xffffff) != reqcnt || reqcnt == 0)
+ asm("call_pal 0");
+#endif
+
+ twiddle();
+
+ /* Partial-block transfers not handled. */
+ if (reqcnt & (DEV_BSIZE - 1)) {
+ *cnt = 0;
+ return (EINVAL);
+ }
+
+ sc = (struct disk_softc *)devdata;
+ pp = &sc->sc_label.d_partitions[sc->sc_part];
+ bn += DL_GETPOFFSET(pp);
+
+ if (rw == F_READ)
+ ret.bits = prom_read(sc->sc_fd, reqcnt, addr, bn);
+ else
+ ret.bits = prom_write(sc->sc_fd, reqcnt, addr, bn);
+ if (ret.u.status)
+ return (EIO);
+ if (cnt)
+ *cnt = ret.u.retval;
+ return (0);
+}
+
+int
+diskopen(struct open_file *f, ...)
+{
+ struct disklabel *lp;
+ prom_return_t ret;
+ size_t cnt, devlen;
+ int i;
+ char *msg, buf[DEV_BSIZE];
+ struct disk_softc *sc;
+ va_list ap;
+ unsigned int part = 0;
+ char devname[128];
+
+ /* See devopen() - we always use the device we're booted off here. */
+ ret.bits = prom_getenv(PROM_E_BOOTED_DEV, devname, sizeof(devname));
+ devlen = ret.u.retval;
+
+ ret.bits = prom_open((u_int64_t)devname, devlen);
+ if (ret.u.status == 2)
+ return (ENXIO);
+ if (ret.u.status == 3)
+ return (EIO);
+
+ sc = alloc(sizeof(struct disk_softc));
+ bzero(sc, sizeof(struct disk_softc));
+ f->f_devdata = (void *)sc;
+
+ sc->sc_fd = ret.u.retval;
+ sc->sc_part = part;
+
+ /* Try to read disk label and partition table information. */
+ lp = &sc->sc_label;
+ lp->d_secsize = DEV_BSIZE;
+ lp->d_secpercyl = 1;
+ lp->d_npartitions = MAXPARTITIONS;
+ DL_SETPOFFSET(&lp->d_partitions[part], 0);
+ DL_SETPSIZE(&lp->d_partitions[part], -1LL);
+ i = diskstrategy(sc, F_READ, LABELSECTOR, DEV_BSIZE, buf, &cnt);
+ if (i || cnt != DEV_BSIZE) {
+ printf("%s: error reading disk label\n", __func__);
+ goto bad;
+ } else if (((struct disklabel *)(buf + LABELOFFSET))->d_magic !=
+ DISKMAGIC) {
+ /* No label at all. Fake all partitions as whole disk. */
+ for (i = 0; i < MAXPARTITIONS; i++) {
+ DL_SETPOFFSET(&lp->d_partitions[part], 0);
+ DL_SETPSIZE(&lp->d_partitions[part], -1LL);
+ }
+ } else {
+ msg = getdisklabel(buf + LABELOFFSET, lp);
+ if (msg) {
+ printf("%s: %s\n", __func__, msg);
+ goto bad;
+ }
+ }
+
+ if (part >= lp->d_npartitions ||
+ DL_GETPSIZE(&lp->d_partitions[part]) == 0) {
+bad:
+ free(sc, sizeof(struct disk_softc));
+ return (ENXIO);
+ }
+ return (0);
+}
+
+int
+diskclose(struct open_file *f)
+{
+ struct disk_softc *sc;
+
+ sc = f->f_devdata;
+ (void)prom_close(sc->sc_fd);
+
+ free(sc, sizeof(struct disk_softc));
+ f->f_devdata = NULL;
+ return (0);
+}
diff --git a/sys/arch/alpha/stand/nboot/libsa.h b/sys/arch/alpha/stand/nboot/libsa.h
new file mode 100644
index 00000000000..ff34856d6c7
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/libsa.h
@@ -0,0 +1,36 @@
+/* $OpenBSD: libsa.h,v 1.1 2023/03/11 20:56:01 miod Exp $ */
+
+/*
+ * Copyright (c) 2023 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 <lib/libsa/stand.h>
+
+/*
+ * MD interfaces for MI boot(9)
+ */
+void devboot(dev_t, char *);
+void machdep(void);
+void run_loadfile(uint64_t *, int);
+
+int diskopen(struct open_file *, ...);
+int diskstrategy(void *, int, daddr_t, size_t, void *, size_t *);
+int diskclose(struct open_file *);
+#define diskioctl noioctl
+
+void prom_cnprobe(struct consdev *);
+void prom_cninit(struct consdev *);
+int prom_cngetc(dev_t);
+void prom_cnputc(dev_t, int);
diff --git a/sys/arch/alpha/stand/nboot/machdep.c b/sys/arch/alpha/stand/nboot/machdep.c
new file mode 100644
index 00000000000..7f7b25a09c4
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/machdep.c
@@ -0,0 +1,218 @@
+/* $OpenBSD: machdep.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */
+/* $NetBSD: boot.c,v 1.10 1997/01/18 01:58:33 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 <sys/param.h>
+#include <lib/libkern/libkern.h>
+#include <lib/libsa/stand.h>
+#include <lib/libsa/loadfile.h>
+#include <stand/boot/cmd.h>
+
+#include <sys/exec.h>
+#include <sys/stat.h>
+#include <sys/reboot.h>
+
+#include <machine/rpb.h>
+#include <machine/prom.h>
+#include <machine/autoconf.h>
+
+void init_prom_calls(void);
+void OSFpal(void);
+void halt(void);
+long alpha_rpcc(void);
+
+int
+main()
+{
+#ifdef DEBUG
+ struct rpb *r;
+ struct mddt *mddtp;
+ struct mddt_cluster *memc;
+ int i;
+#endif
+ static char boot_file[128];
+ extern char *kernelfile;
+ char *s;
+ int uppercase = 1;
+
+ /* Init prom callback vector. */
+ init_prom_calls();
+
+ cninit();
+
+ /* switch to OSF pal code. */
+ OSFpal();
+
+#ifdef DEBUG
+ r = (struct rpb *)HWRPB_ADDR;
+ mddtp = (struct mddt *)(HWRPB_ADDR + r->rpb_memdat_off);
+ printf("%d memory clusters\n", mddtp->mddt_cluster_cnt);
+ for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
+ memc = &mddtp->mddt_clusters[i];
+ printf("%d: (%d) %lx-%lx\n", i, memc->mddt_usage,
+ memc->mddt_pfn << PAGE_SHIFT,
+ (memc->mddt_pfn + memc->mddt_pg_cnt) << PAGE_SHIFT);
+ }
+#endif
+
+ prom_getenv(PROM_E_BOOTED_FILE, boot_file, sizeof(boot_file));
+
+ if (boot_file[0] != '\0') {
+ /*
+ * If boot_file is all caps, then we are likely on an old
+ * (DEC 3000) prom which upper cases everything.
+ */
+ for (s = boot_file; *s != '\0'; s++) {
+ if (islower(*s)) {
+ uppercase = 0;
+ break;
+ }
+ }
+ if (uppercase) {
+ for (s = boot_file; *s != '\0'; s++)
+ *s = tolower(*s);
+ }
+ kernelfile = boot_file;
+ /*
+ * Unfortunately there doesn't seem to be a way to tell apart
+ * a kernel file provided via "boot -fi" (in which case we
+ * ought to boot immediately by setting bootprompt to zero)
+ * from a kernel file provided via the SRM environment (in
+ * which case we want to default to interactive operation).
+ */
+ }
+
+ boot(0);
+}
+
+void
+devboot(dev_t dev /* ignored */, char *path)
+{
+ /*
+ * Although there is unfortunately no way to use SRM device names
+ * here, we need to provide a dummy device name since the boot loader
+ * code relies upon "device:path" syntax.
+ */
+ snprintf(path, BOOTDEVLEN, "disk");
+}
+
+void
+machdep()
+{
+ /* Nothing to do - everything done in main() already */
+}
+
+void
+run_loadfile(uint64_t *marks, int howto)
+{
+ extern paddr_t ptbr_save;
+ static struct bootinfo_v1 bootinfo_v1;
+ u_int64_t entry;
+ char boot_flags[128];
+
+ /*
+ * Fill in the bootinfo for the kernel.
+ */
+ bzero(&bootinfo_v1, sizeof(bootinfo_v1));
+ bootinfo_v1.ssym = marks[MARK_SYM];
+ bootinfo_v1.esym = marks[MARK_END];
+// bcopy(name, bootinfo_v1.booted_kernel,
+// sizeof(bootinfo_v1.booted_kernel));
+ prom_getenv(PROM_E_BOOTED_OSFLAGS, boot_flags, sizeof(boot_flags));
+ bcopy(boot_flags, bootinfo_v1.boot_flags,
+ sizeof(bootinfo_v1.boot_flags));
+ bootinfo_v1.hwrpb = (void *)HWRPB_ADDR;
+ bootinfo_v1.hwrpbsize = ((struct rpb *)HWRPB_ADDR)->rpb_size;
+ bootinfo_v1.cngetc = NULL;
+ bootinfo_v1.cnputc = NULL;
+ bootinfo_v1.cnpollc = NULL;
+ bootinfo_v1.howto = howto;
+
+ entry = marks[MARK_START];
+ (*(void (*)(u_int64_t, u_int64_t, u_int64_t, void *, u_int64_t,
+ u_int64_t))entry)(0, ptbr_save, BOOTINFO_MAGIC, &bootinfo_v1, 1, 0);
+}
+
+/*
+ * "machine tty" command to select a different console is not supported,
+ */
+
+int
+cnspeed(dev_t dev, int sp)
+{
+ return 9600;
+}
+
+char *
+ttyname(int fd)
+{
+ return "console";
+}
+
+dev_t
+ttydev(char *name)
+{
+ return NODEV;
+}
+
+time_t
+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);
+}
diff --git a/sys/arch/alpha/stand/nboot/prom.c b/sys/arch/alpha/stand/nboot/prom.c
new file mode 100644
index 00000000000..df8c867b523
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/prom.c
@@ -0,0 +1,74 @@
+/* $OpenBSD: prom.c,v 1.1 2023/03/11 20:56:01 miod 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>
+
+void
+init_prom_calls()
+{
+ extern struct prom_vec prom_dispatch_v;
+ struct rpb *r;
+ struct crb *c;
+
+ 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;
+}
+
+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, (u_int64_t)abuf, 128, 0);
+ 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);
+}
diff --git a/sys/arch/alpha/stand/nboot/prom_swpal.S b/sys/arch/alpha/stand/nboot/prom_swpal.S
new file mode 100644
index 00000000000..8fc1707856e
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/prom_swpal.S
@@ -0,0 +1,136 @@
+/* $OpenBSD: prom_swpal.S,v 1.1 2023/03/11 20:56:01 miod Exp $ */
+/* $NetBSD: prom_swpal.S,v 1.4 1996/10/17 02:50:41 cgd Exp $ */
+
+/*
+ * Copyright (c) 1994, 1995 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Keith Bostic
+ *
+ * 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 "../../include/asm.h"
+#include "../../include/prom.h"
+#include "../../include/rpb.h"
+
+/* Offsets from base of HWRPB. */
+#define RPB_SELFREF 0x00
+#define RPB_SLOTSIZE 0x98
+#define RPB_PERCPU_OFF 0xA0
+
+/* Offsets in a boot PCB. */
+#define PCB_KSP 0x00
+#define PCB_PTBR 0x10
+#define PCB_ASN 0x1c
+#define PCB_FEN 0x28
+
+/* Pal values. */
+#define PAL_RESERVED 0 /* Reserved to Digital. */
+#define PAL_VMS 1 /* VMS */
+#define PAL_OSF 2 /* OSF */
+
+/*
+ * PAL code switch routine.
+ */
+#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 PALSW_FRAME_SIZE (14*8)
+#define PALSW_REGS IM_RA|IM_S0|IM_S1|IM_S2|IM_S3|IM_S4|IM_S5
+
+ .comm ptbr_save,8
+
+ .text
+ .align 4
+
+NESTED(switch_palcode, 0, PALSW_FRAME_SIZE, ra, PALSW_REGS, 0)
+ LDGP(pv)
+/* ldgp gp, 0(pv)*/
+
+ lda sp, -PALSW_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 pv, 0(sp)
+ stq gp, 8(sp)
+
+ ldiq s0, HWRPB_ADDR /* s0 HWRPB_ADDR */
+ ldq s1, RPB_SLOTSIZE(s0)
+ call_pal PAL_VMS_mfpr_whami
+ mulq s1, v0, s1 /* s1 per_cpu offset from base */
+ ldq s2, RPB_PERCPU_OFF(s0)
+ addq s0, s2, s2
+ addq s2, s1, s2 /* s2 PCB (virtual) */
+
+ call_pal PAL_VMS_mfpr_ptbr
+ stq v0, PCB_PTBR(s2)
+ stq v0, ptbr_save /* save PTBR for the kernel */
+ stl zero, PCB_ASN(s2)
+ stq zero, PCB_FEN(s2)
+ stq sp, PCB_KSP(s2)
+
+ ldq t0, RPB_SELFREF(s0) /* HWRBP base (physical) */
+ ldq t1, RPB_PERCPU_OFF(s0)
+ addq t0, t1, t0
+ addq t0, s1, t0 /* PCB base (phys) */
+ stq t0, 16(sp)
+
+ call_pal PAL_VMS_mfpr_vptb
+ mov v0, a3
+ ldiq a0, PAL_OSF
+ lda a1, contin
+ ldq a2, 16(sp)
+
+ call_pal PAL_swppal /* a0, a1, a2, a3 */
+
+contin: ldq pv, 0(sp)
+ ldq gp, 8(sp)
+
+ 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)
+ lda sp, PALSW_FRAME_SIZE(sp)
+ RET
+END(switch_palcode)
+
+#undef D_RA
+#undef D_S0
+#undef D_S1
+#undef D_S2
+#undef D_S3
+#undef D_S4
+#undef D_S5
+#undef PALSW_FRAME_SIZE
+#undef PALSW_REGS
diff --git a/sys/arch/alpha/stand/nboot/promcons.c b/sys/arch/alpha/stand/nboot/promcons.c
new file mode 100644
index 00000000000..aab4cbad9bc
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/promcons.c
@@ -0,0 +1,96 @@
+/* $OpenBSD: promcons.c,v 1.1 2023/03/11 20:56:01 miod 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 <sys/types.h>
+#include <machine/rpb.h>
+#include <machine/prom.h>
+#include <dev/cons.h>
+
+#include "libsa.h"
+
+void
+prom_cnprobe(struct consdev *cn)
+{
+ char buf[4];
+ int console;
+
+ /* Look for console tty. */
+ prom_getenv(PROM_E_TTY_DEV, buf, 4);
+ console = buf[0] - '0';
+
+ cn->cn_pri = CN_MIDPRI;
+ cn->cn_dev = makedev(0, console);
+}
+
+void
+prom_cninit(struct consdev *cn)
+{
+}
+
+int
+prom_cngetc(dev_t dev)
+{
+ static int stash = 0;
+ int unit = dev & ~0x80;
+ int poll = (dev & 0x80) != 0;
+ int c;
+ prom_return_t ret;
+
+ if (stash != 0) {
+ c = stash;
+ if (!poll)
+ stash = 0;
+ return c;
+ }
+
+ for (;;) {
+ ret.bits = prom_dispatch(PROM_R_GETC, unit, 0, 0, 0);
+ if (ret.u.status == 0 || ret.u.status == 1) {
+ c = ret.u.retval;
+ if (poll)
+ stash = c;
+ return c;
+ }
+ if (poll)
+ return 0;
+ }
+}
+
+void
+prom_cnputc(dev_t dev, int c)
+{
+ int unit = dev & ~0x80;
+ prom_return_t ret;
+ char cbuf = c;
+
+ do {
+ ret.bits = prom_dispatch(PROM_R_PUTS, unit,
+ (u_int64_t)&cbuf, 1, 0);
+ } while ((ret.u.retval & 1) == 0);
+}
diff --git a/sys/arch/alpha/stand/nboot/rpcc.S b/sys/arch/alpha/stand/nboot/rpcc.S
new file mode 100644
index 00000000000..eebef3b312d
--- /dev/null
+++ b/sys/arch/alpha/stand/nboot/rpcc.S
@@ -0,0 +1,10 @@
+/* $OpenBSD: rpcc.S,v 1.1 2023/03/11 20:56:01 miod 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)