summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2020-05-16 17:11:15 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2020-05-16 17:11:15 +0000
commit5df2a273475dc953afcc4b50947f3fa052bc5c9e (patch)
treea3b6e6730b304127546e159866888b7370932d27 /sys/arch
parent154cd99aae028cd6a36f4d9937092bb2a88b5b6a (diff)
Planting the first seed for OpenBSD/powerpc64.
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/powerpc64/compile/GENERIC/Makefile1
-rw-r--r--sys/arch/powerpc64/compile/Makefile7
-rw-r--r--sys/arch/powerpc64/compile/Makefile.inc19
-rw-r--r--sys/arch/powerpc64/conf/GENERIC18
-rw-r--r--sys/arch/powerpc64/conf/Makefile.powerpc64183
-rw-r--r--sys/arch/powerpc64/conf/files.powerpc6431
-rw-r--r--sys/arch/powerpc64/conf/ld.script55
-rw-r--r--sys/arch/powerpc64/include/_types.h145
-rw-r--r--sys/arch/powerpc64/include/atomic.h292
-rw-r--r--sys/arch/powerpc64/include/bus.h13
-rw-r--r--sys/arch/powerpc64/include/cdefs.h21
-rw-r--r--sys/arch/powerpc64/include/conf.h1
-rw-r--r--sys/arch/powerpc64/include/cpu.h60
-rw-r--r--sys/arch/powerpc64/include/db_machdep.h19
-rw-r--r--sys/arch/powerpc64/include/disklabel.h26
-rw-r--r--sys/arch/powerpc64/include/endian.h103
-rw-r--r--sys/arch/powerpc64/include/exec.h30
-rw-r--r--sys/arch/powerpc64/include/fpu.h0
-rw-r--r--sys/arch/powerpc64/include/frame.h1
-rw-r--r--sys/arch/powerpc64/include/intr.h32
-rw-r--r--sys/arch/powerpc64/include/limits.h55
-rw-r--r--sys/arch/powerpc64/include/mutex.h3
-rw-r--r--sys/arch/powerpc64/include/param.h85
-rw-r--r--sys/arch/powerpc64/include/pcb.h8
-rw-r--r--sys/arch/powerpc64/include/pmap.h17
-rw-r--r--sys/arch/powerpc64/include/proc.h44
-rw-r--r--sys/arch/powerpc64/include/psl.h0
-rw-r--r--sys/arch/powerpc64/include/ptrace.h44
-rw-r--r--sys/arch/powerpc64/include/reg.h76
-rw-r--r--sys/arch/powerpc64/include/signal.h71
-rw-r--r--sys/arch/powerpc64/include/softintr.h99
-rw-r--r--sys/arch/powerpc64/include/spinlock.h26
-rw-r--r--sys/arch/powerpc64/include/tcb.h42
-rw-r--r--sys/arch/powerpc64/include/vmparam.h47
-rw-r--r--sys/arch/powerpc64/powerpc64/autoconf.c43
-rw-r--r--sys/arch/powerpc64/powerpc64/conf.c43
-rw-r--r--sys/arch/powerpc64/powerpc64/cpu.c3
-rw-r--r--sys/arch/powerpc64/powerpc64/disksubr.c132
-rw-r--r--sys/arch/powerpc64/powerpc64/genassym.cf1
-rw-r--r--sys/arch/powerpc64/powerpc64/locore.S171
-rw-r--r--sys/arch/powerpc64/powerpc64/locore0.S71
-rw-r--r--sys/arch/powerpc64/powerpc64/machdep.c320
-rw-r--r--sys/arch/powerpc64/powerpc64/pmap.c133
-rw-r--r--sys/arch/powerpc64/powerpc64/process_machdep.c186
-rw-r--r--sys/arch/powerpc64/powerpc64/softintr.c195
-rw-r--r--sys/arch/powerpc64/powerpc64/sys_machdep.c70
-rw-r--r--sys/arch/powerpc64/powerpc64/syscall.c13
-rw-r--r--sys/arch/powerpc64/powerpc64/vm_machdep.c188
48 files changed, 3243 insertions, 0 deletions
diff --git a/sys/arch/powerpc64/compile/GENERIC/Makefile b/sys/arch/powerpc64/compile/GENERIC/Makefile
new file mode 100644
index 00000000000..01b5f23410c
--- /dev/null
+++ b/sys/arch/powerpc64/compile/GENERIC/Makefile
@@ -0,0 +1 @@
+.include "../Makefile.inc"
diff --git a/sys/arch/powerpc64/compile/Makefile b/sys/arch/powerpc64/compile/Makefile
new file mode 100644
index 00000000000..f433ccc6045
--- /dev/null
+++ b/sys/arch/powerpc64/compile/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1 2020/05/16 17:11:14 kettenis Exp $
+
+.if make(obj) || make(clean) || make(cleandir)
+SUBDIR!=find . -type d -maxdepth 1 \! \( -name . -o -name CVS \) | cut -b3-
+.endif
+
+.include <bsd.subdir.mk>
diff --git a/sys/arch/powerpc64/compile/Makefile.inc b/sys/arch/powerpc64/compile/Makefile.inc
new file mode 100644
index 00000000000..9e9e38f1ed1
--- /dev/null
+++ b/sys/arch/powerpc64/compile/Makefile.inc
@@ -0,0 +1,19 @@
+SYSDIR != cd ${.CURDIR}/../../../..; pwd
+CONFDIR != cd ${.CURDIR}/../../conf; pwd
+
+.if ${.CURDIR} == ${.OBJDIR}
+.PHONY: config
+config:
+ @echo make obj required first >&2
+ @false
+.else
+.PHONY: config clean
+config:
+ config ${.CURDIR:M*.PROF:C/.*/-p/} -b ${.OBJDIR} \
+ -s ${SYSDIR} ${CONFDIR}/${.CURDIR:T:S/.PROF$//}
+.endif
+
+cleandir clean:
+
+.include <bsd.obj.mk>
+
diff --git a/sys/arch/powerpc64/conf/GENERIC b/sys/arch/powerpc64/conf/GENERIC
new file mode 100644
index 00000000000..c725e808f33
--- /dev/null
+++ b/sys/arch/powerpc64/conf/GENERIC
@@ -0,0 +1,18 @@
+# $OpenBSD: GENERIC,v 1.1 2020/05/16 17:11:14 kettenis Exp $
+#
+# For further information on compiling OpenBSD kernels, see the config(8)
+# man page.
+#
+# For further information on hardware support for this architecture, see
+# the intro(4) man page. For further information about kernel options
+# for this architecture, see the options(4) man page. For an explanation
+# of each device driver in this file see the section 4 man page for the
+# device.
+
+machine powerpc64
+include "../../../conf/GENERIC"
+maxusers 80
+
+config bsd swap generic
+
+mainbus0 at root
diff --git a/sys/arch/powerpc64/conf/Makefile.powerpc64 b/sys/arch/powerpc64/conf/Makefile.powerpc64
new file mode 100644
index 00000000000..7c339bc98fa
--- /dev/null
+++ b/sys/arch/powerpc64/conf/Makefile.powerpc64
@@ -0,0 +1,183 @@
+# $OpenBSD: Makefile.powerpc64,v 1.1 2020/05/16 17:11:14 kettenis Exp $
+
+# For instructions on building kernels consult the config(8) and options(4)
+# manual pages.
+#
+# N.B.: NO DEPENDENCIES ON FOLLOWING FLAGS ARE VISIBLE TO MAKEFILE
+# IF YOU CHANGE THE DEFINITION OF ANY OF THESE RECOMPILE EVERYTHING
+# DEBUG is set to -g by config if debugging is requested (config -g).
+# PROF is set to -pg by config if profiling is requested (config -p).
+
+.include <bsd.own.mk>
+
+# XXX cross compiler
+CC= /usr/local/bin/clang -target powerpc64-openbsd
+LD= ld.lld
+
+SIZE?= size
+STRIP?= ctfstrip
+
+# source tree is located via $S relative to the compilation directory
+.ifndef S
+S!= cd ../../../..; pwd
+.endif
+
+_machdir?= $S/arch/${_mach}
+_archdir?= $S/arch/${_arch}
+
+INCLUDES= -nostdinc -I$S -I${.OBJDIR} -I$S/arch \
+ -I$S/dev/pci/drm/include \
+ -I$S/dev/pci/drm/include/uapi \
+ -I$S/dev/pci/drm/amd/include/asic_reg \
+ -I$S/dev/pci/drm/amd/include \
+ -I$S/dev/pci/drm/amd/amdgpu \
+ -I$S/dev/pci/drm/amd/display \
+ -I$S/dev/pci/drm/amd/display/include \
+ -I$S/dev/pci/drm/amd/display/dc \
+ -I$S/dev/pci/drm/amd/display/amdgpu_dm \
+ -I$S/dev/pci/drm/amd/powerplay/inc \
+ -I$S/dev/pci/drm/amd/powerplay/smumgr \
+ -I$S/dev/pci/drm/amd/powerplay/hwmgr \
+ -I$S/dev/pci/drm/amd/display/dc/inc \
+ -I$S/dev/pci/drm/amd/display/dc/inc/hw \
+ -I$S/dev/pci/drm/amd/display/modules/inc
+CPPFLAGS= ${INCLUDES} ${IDENT} ${PARAM} -D_KERNEL -MD -MP
+CWARNFLAGS= -Werror -Wall -Wimplicit-function-declaration \
+ -Wno-uninitialized -Wno-pointer-sign \
+ -Wno-constant-conversion -Wno-address-of-packed-member \
+ -Wframe-larger-than=2047
+
+CMACHFLAGS= -mabi=elfv2
+CMACHFLAGS+= -ffreestanding
+SORTR= sort -R
+.if ${IDENT:M-DNO_PROPOLICE}
+CMACHFLAGS+= -fno-stack-protector
+.endif
+.if ${IDENT:M-DSMALL_KERNEL}
+SORTR= cat
+COPTS?= -Oz
+.endif
+
+DEBUG?= -g
+COPTS?= -O2
+CFLAGS= ${DEBUG} ${CWARNFLAGS} ${CMACHFLAGS} ${COPTS} ${PIPE}
+AFLAGS= -D_LOCORE -x assembler-with-cpp ${CWARNFLAGS} ${CMACHFLAGS}
+LINKFLAGS= -T ld.script -X --warn-common -pie
+
+HOSTCC?= ${CC}
+HOSTED_CPPFLAGS=${CPPFLAGS:S/^-nostdinc$//}
+HOSTED_CFLAGS= ${CFLAGS}
+HOSTED_C= ${HOSTCC} ${HOSTED_CFLAGS} ${HOSTED_CPPFLAGS} -c $<
+
+NORMAL_C_NOP= ${CC} ${CFLAGS} ${CPPFLAGS} -fno-ret-protector -c $<
+NORMAL_C= ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c $<
+NORMAL_S= ${CC} ${AFLAGS} ${CPPFLAGS} ${PROF} -c $<
+
+%OBJS
+
+%CFILES
+
+%SFILES
+
+# load lines for config "xxx" will be emitted as:
+# xxx: ${SYSTEM_DEP} swapxxx.o
+# ${SYSTEM_LD_HEAD}
+# ${SYSTEM_LD} swapxxx.o
+# ${SYSTEM_LD_TAIL}
+SYSTEM_HEAD= locore0.o gap.o
+SYSTEM_OBJ= ${SYSTEM_HEAD} ${OBJS} param.o ioconf.o
+SYSTEM_DEP= Makefile ${SYSTEM_OBJ} ld.script
+SYSTEM_LD_HEAD= @rm -f $@
+SYSTEM_LD= @echo ${LD} ${LINKFLAGS} -o $@ '$${SYSTEM_HEAD} vers.o $${OBJS}'; \
+ umask 007; \
+ echo ${OBJS} param.o ioconf.o vers.o | tr " " "\n" | ${SORTR} > lorder; \
+ ${LD} ${LINKFLAGS} -o $@ ${SYSTEM_HEAD} `cat lorder`
+SYSTEM_LD_TAIL= @${SIZE} $@
+
+.if ${DEBUG} == "-g"
+STRIPFLAGS= -S
+SYSTEM_LD_TAIL+=; umask 007; \
+ echo mv $@ $@.gdb; rm -f $@.gdb; mv $@ $@.gdb; \
+ echo ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb; \
+ ${STRIP} ${STRIPFLAGS} -o $@ $@.gdb
+.else
+LINKFLAGS+= -S
+.endif
+
+%LOAD
+
+# cc's -MD puts the source and output paths in the dependency file;
+# since those are temp files here we need to fix it up. It also
+# puts the file in /tmp, so we use -MF to put it in the current
+# directory as assym.P and then generate assym.d from it with a
+# good target name
+assym.h: $S/kern/genassym.sh Makefile \
+ ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf
+ cat ${_archdir}/${_arch}/genassym.cf ${_machdir}/${_mach}/genassym.cf | \
+ sh $S/kern/genassym.sh ${CC} ${CFLAGS} ${CPPFLAGS} -no-integrated-as -MF assym.P > assym.h.tmp
+ sed '1s/.*/assym.h: \\/' assym.P > assym.d
+ sort -u assym.h.tmp > assym.h
+
+param.c: $S/conf/param.c
+ rm -f param.c
+ cp $S/conf/param.c .
+
+param.o: param.c Makefile
+ ${NORMAL_C}
+
+mcount.o: $S/lib/libkern/mcount.c Makefile
+ ${NORMAL_C_NOP}
+
+ioconf.o: ioconf.c
+ ${NORMAL_C}
+
+ld.script: ${_machdir}/conf/ld.script
+ cp ${_machdir}/conf/ld.script $@
+
+gapdummy.o:
+ echo '__asm(".section .rodata,\"a\"");' > gapdummy.c
+ ${CC} -c ${CFLAGS} ${CPPFLAGS} gapdummy.c -o $@
+
+makegap.sh:
+ cp $S/conf/makegap.sh $@
+
+MAKE_GAP = LD="${LD}" sh makegap.sh 0x00000000 gapdummy.o
+
+gap.o: Makefile makegap.sh gapdummy.o vers.o
+ ${MAKE_GAP}
+
+vers.o: ${SYSTEM_DEP:Ngap.o}
+ sh $S/conf/newvers.sh
+ ${CC} ${CFLAGS} ${CPPFLAGS} ${PROF} -c vers.c
+
+clean:
+ rm -f *bsd *bsd.gdb *.[dio] [a-z]*.s assym.* \
+ gap.link gapdummy.c ld.script lorder makegap.sh param.c
+
+cleandir: clean
+ rm -f Makefile *.h ioconf.c options machine ${_mach} vers.c
+
+depend obj:
+
+locore0.o: ${_machdir}/${_mach}/locore0.S assym.h
+
+hardlink-obsd:
+ [[ ! -f /bsd ]] || cmp -s bsd /bsd || ln -f /bsd /obsd
+
+newinstall:
+ install -F -m 700 bsd /bsd && sha256 -h /var/db/kernel.SHA256 /bsd
+
+install: update-link hardlink-obsd newinstall
+
+# pull in the dependency information
+.ifnmake clean
+. for o in ${SYSTEM_OBJ:Ngap.o} assym.h
+. if exists(${o:R}.d)
+. include "${o:R}.d"
+. elif exists($o)
+ .PHONY: $o
+. endif
+. endfor
+.endif
+
+%RULES
diff --git a/sys/arch/powerpc64/conf/files.powerpc64 b/sys/arch/powerpc64/conf/files.powerpc64
new file mode 100644
index 00000000000..4d767b0b933
--- /dev/null
+++ b/sys/arch/powerpc64/conf/files.powerpc64
@@ -0,0 +1,31 @@
+# $OpenBSD: files.powerpc64,v 1.1 2020/05/16 17:11:14 kettenis Exp $
+
+maxpartitions 16
+maxusers 2 8 128
+
+define fdt {[early = 0]}
+
+define mainbus {}
+device mainbus: fdt
+attach mainbus at root
+
+# FDT support
+include "dev/ofw/files.ofw"
+
+include "scsi/files.scsi"
+
+file arch/powerpc64/powerpc64/locore.S
+file arch/powerpc64/powerpc64/autoconf.c
+file arch/powerpc64/powerpc64/conf.c
+file arch/powerpc64/powerpc64/cpu.c
+file arch/powerpc64/powerpc64/disksubr.c
+file arch/powerpc64/powerpc64/machdep.c
+file arch/powerpc64/powerpc64/pmap.c
+file arch/powerpc64/powerpc64/process_machdep.c
+file arch/powerpc64/powerpc64/softintr.c
+file arch/powerpc64/powerpc64/syscall.c
+file arch/powerpc64/powerpc64/sys_machdep.c
+file arch/powerpc64/powerpc64/vm_machdep.c
+
+file netinet/in_cksum.c
+file netinet/in4_cksum.c
diff --git a/sys/arch/powerpc64/conf/ld.script b/sys/arch/powerpc64/conf/ld.script
new file mode 100644
index 00000000000..9fafeef6564
--- /dev/null
+++ b/sys/arch/powerpc64/conf/ld.script
@@ -0,0 +1,55 @@
+/* $OpenBSD: ld.script,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2013 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+ENTRY(_start)
+
+PHDRS
+{
+ text PT_LOAD;
+ dynamic PT_DYNAMIC;
+}
+
+SECTIONS
+{
+ . = 0x00100000;
+ .text :
+ {
+ *(.text)
+ *(.rodata*)
+ } :text
+ PROVIDE (etext = .);
+
+ .hash : { *(.hash) }
+
+ . = ALIGN(4096);
+ .data :
+ {
+ *(.data)
+ }
+
+ . = ALIGN(4096);
+ .got : { *(.got) }
+ .toc : { *(.toc) }
+
+ PROVIDE (__bss_start = .);
+ .bss :
+ {
+ *(.bss)
+ }
+ PROVIDE (end = .);
+}
diff --git a/sys/arch/powerpc64/include/_types.h b/sys/arch/powerpc64/include/_types.h
new file mode 100644
index 00000000000..bc2cc00c0d5
--- /dev/null
+++ b/sys/arch/powerpc64/include/_types.h
@@ -0,0 +1,145 @@
+/* $OpenBSD: _types.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)types.h 8.3 (Berkeley) 1/5/94
+ * @(#)ansi.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _MACHINE__TYPES_H_
+#define _MACHINE__TYPES_H_
+
+#if defined(_KERNEL)
+typedef struct label_t {
+ long val[13];
+} label_t;
+#endif
+
+/*
+ * _ALIGN(p) rounds p (pointer or byte index) up to a correctly-aligned
+ * value for all data types (int, long, ...). The result is an
+ * unsigned long and must be cast to any desired pointer type.
+ *
+ * _ALIGNED_POINTER is a boolean macro that checks whether an address
+ * is valid to fetch data elements of type t from on this architecture.
+ * This does not reflect the optimal alignment, just the possibility
+ * (within reasonable limits).
+ */
+#define _ALIGNBYTES (sizeof(long) - 1)
+#define _STACKALIGNBYTES 15
+#define _ALIGN(p) (((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
+#define _ALIGNED_POINTER(p,t) ((((unsigned long)(p)) & (sizeof(t) - 1)) == 0)
+#define _MAX_PAGE_SHIFT 12 /* same as PAGE_SHIFT */
+
+/* 7.18.1.1 Exact-width integer types */
+typedef signed char __int8_t;
+typedef unsigned char __uint8_t;
+typedef short __int16_t;
+typedef unsigned short __uint16_t;
+typedef int __int32_t;
+typedef unsigned int __uint32_t;
+/* LONGLONG */
+typedef long long __int64_t;
+/* LONGLONG */
+typedef unsigned long long __uint64_t;
+
+/* 7.18.1.2 Minimum-width integer types */
+typedef __int8_t __int_least8_t;
+typedef __uint8_t __uint_least8_t;
+typedef __int16_t __int_least16_t;
+typedef __uint16_t __uint_least16_t;
+typedef __int32_t __int_least32_t;
+typedef __uint32_t __uint_least32_t;
+typedef __int64_t __int_least64_t;
+typedef __uint64_t __uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef __int32_t __int_fast8_t;
+typedef __uint32_t __uint_fast8_t;
+typedef __int32_t __int_fast16_t;
+typedef __uint32_t __uint_fast16_t;
+typedef __int32_t __int_fast32_t;
+typedef __uint32_t __uint_fast32_t;
+typedef __int64_t __int_fast64_t;
+typedef __uint64_t __uint_fast64_t;
+#define __INT_FAST8_MIN INT32_MIN
+#define __INT_FAST16_MIN INT32_MIN
+#define __INT_FAST32_MIN INT32_MIN
+#define __INT_FAST64_MIN INT64_MIN
+#define __INT_FAST8_MAX INT32_MAX
+#define __INT_FAST16_MAX INT32_MAX
+#define __INT_FAST32_MAX INT32_MAX
+#define __INT_FAST64_MAX INT64_MAX
+#define __UINT_FAST8_MAX UINT32_MAX
+#define __UINT_FAST16_MAX UINT32_MAX
+#define __UINT_FAST32_MAX UINT32_MAX
+#define __UINT_FAST64_MAX UINT64_MAX
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+typedef long __intptr_t;
+typedef unsigned long __uintptr_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+typedef __int64_t __intmax_t;
+typedef __uint64_t __uintmax_t;
+
+/* Register size */
+typedef long __register_t;
+
+/* VM system types */
+typedef unsigned long __vaddr_t;
+typedef unsigned long __paddr_t;
+typedef unsigned long __vsize_t;
+typedef unsigned long __psize_t;
+
+/* Standard system types */
+typedef double __double_t;
+typedef float __float_t;
+typedef long __ptrdiff_t;
+typedef unsigned long __size_t;
+typedef long __ssize_t;
+#if defined(__GNUC__) && __GNUC__ >= 3
+typedef __builtin_va_list __va_list;
+#else
+typedef char * __va_list;
+#endif
+
+/* Wide character support types */
+#ifndef __cplusplus
+#ifdef __WCHAR_UNSIGNED__
+typedef unsigned int __wchar_t;
+#else
+typedef int __wchar_t;
+#endif
+#endif
+typedef int __wint_t;
+typedef int __rune_t;
+typedef void * __wctrans_t;
+typedef void * __wctype_t;
+
+#endif /* _MACHINE__TYPES_H_ */
diff --git a/sys/arch/powerpc64/include/atomic.h b/sys/arch/powerpc64/include/atomic.h
new file mode 100644
index 00000000000..913b88fc2f0
--- /dev/null
+++ b/sys/arch/powerpc64/include/atomic.h
@@ -0,0 +1,292 @@
+/* $OpenBSD: atomic.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2015 Martin Pieuchot
+ *
+ * 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.
+ */
+
+
+#ifndef _MACHINE_ATOMIC_H_
+#define _MACHINE_ATOMIC_H_
+
+#if defined(_KERNEL)
+
+static __inline void
+atomic_setbits_int(volatile unsigned int *uip, unsigned int v)
+{
+ unsigned int tmp;
+
+ __asm volatile (
+ "1: lwarx %0, 0, %2 \n"
+ " or %0, %1, %0 \n"
+ " stwcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ " sync" : "=&r" (tmp) : "r" (v), "r" (uip) : "cc", "memory");
+}
+
+static __inline void
+atomic_clearbits_int(volatile unsigned int *uip, unsigned int v)
+{
+ unsigned int tmp;
+
+ __asm volatile (
+ "1: lwarx %0, 0, %2 \n"
+ " andc %0, %0, %1 \n"
+ " stwcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ " sync" : "=&r" (tmp) : "r" (v), "r" (uip) : "cc", "memory");
+}
+
+#endif /* defined(_KERNEL) */
+
+static inline unsigned int
+_atomic_cas_uint(volatile unsigned int *p, unsigned int o, unsigned int n)
+{
+ unsigned int rv;
+
+ __asm volatile (
+ "1: lwarx %0, 0, %2 \n"
+ " cmpw 0, %0, %4 \n"
+ " bne- 2f \n"
+ " stwcx. %3, 0, %2 \n"
+ " bne- 1b \n"
+ "2: \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (n), "r" (o)
+ : "cc");
+
+ return (rv);
+}
+#define atomic_cas_uint(_p, _o, _n) _atomic_cas_uint((_p), (_o), (_n))
+
+static inline unsigned long
+_atomic_cas_ulong(volatile unsigned long *p, unsigned long o, unsigned long n)
+{
+ unsigned long rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " cmpd 0, %0, %4 \n"
+ " bne- 2f \n"
+ " stdcx. %3, 0, %2 \n"
+ " bne- 1b \n"
+ "2: \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (n), "r" (o)
+ : "cc");
+
+ return (rv);
+}
+#define atomic_cas_ulong(_p, _o, _n) _atomic_cas_ulong((_p), (_o), (_n))
+
+static inline void *
+_atomic_cas_ptr(volatile void *pp, void *o, void *n)
+{
+ void * volatile *p = pp;
+ void *rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " cmpd 0, %0, %4 \n"
+ " bne- 2f \n"
+ " stdcx. %3, 0, %2 \n"
+ " bne- 1b \n"
+ "2: \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (n), "r" (o)
+ : "cc");
+
+ return (rv);
+}
+#define atomic_cas_ptr(_p, _o, _n) _atomic_cas_ptr((_p), (_o), (_n))
+
+static inline unsigned int
+_atomic_swap_uint(volatile unsigned int *p, unsigned int v)
+{
+ unsigned int rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " stdcx. %3, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc");
+
+ return (rv);
+}
+#define atomic_swap_uint(_p, _v) _atomic_swap_uint((_p), (_v))
+
+static inline unsigned long
+_atomic_swap_ulong(volatile unsigned long *p, unsigned long v)
+{
+ unsigned long rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " stdcx. %3, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc");
+
+ return (rv);
+}
+#define atomic_swap_ulong(_p, _v) _atomic_swap_ulong((_p), (_v))
+
+static inline void *
+_atomic_swap_ptr(volatile void *pp, void *v)
+{
+ void * volatile *p = pp;
+ void *rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " stdcx. %3, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc");
+
+ return (rv);
+}
+#define atomic_swap_ptr(_p, _v) _atomic_swap_ptr((_p), (_v))
+
+static inline unsigned int
+_atomic_add_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ unsigned int rv;
+
+ __asm volatile (
+ "1: lwarx %0, 0, %2 \n"
+ " add %0, %3, %0 \n"
+ " stwcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc", "xer");
+
+ return (rv);
+}
+#define atomic_add_int_nv(_p, _v) _atomic_add_int_nv((_p), (_v))
+
+static inline unsigned long
+_atomic_add_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ unsigned long rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " add %0, %3, %0 \n"
+ " stdcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc", "xer");
+
+ return (rv);
+}
+#define atomic_add_long_nv(_p, _v) _atomic_add_long_nv((_p), (_v))
+
+static inline unsigned int
+_atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ unsigned int rv;
+
+ __asm volatile (
+ "1: lwarx %0, 0, %2 \n"
+ " subf %0, %3, %0 \n"
+ " stwcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc", "xer");
+
+ return (rv);
+}
+#define atomic_sub_int_nv(_p, _v) _atomic_sub_int_nv((_p), (_v))
+
+static inline unsigned long
+_atomic_sub_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ unsigned long rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " subf %0, %3, %0 \n"
+ " stdcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "r" (v)
+ : "cc", "xer");
+
+ return (rv);
+}
+#define atomic_sub_long_nv(_p, _v) _atomic_sub_long_nv((_p), (_v))
+
+static inline unsigned int
+_atomic_addic_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ unsigned int rv;
+
+ __asm volatile (
+ "1: lwarx %0, 0, %2 \n"
+ " addic %0, %0, %3 \n"
+ " stwcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "i" (v)
+ : "cc", "xer");
+
+ return (rv);
+}
+#define atomic_inc_int_nv(_p) _atomic_addic_int_nv((_p), 1)
+#define atomic_dec_int_nv(_p) _atomic_addic_int_nv((_p), -1)
+
+static inline unsigned long
+_atomic_addic_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ unsigned long rv;
+
+ __asm volatile (
+ "1: ldarx %0, 0, %2 \n"
+ " addic %0, %0, %3 \n"
+ " stdcx. %0, 0, %2 \n"
+ " bne- 1b \n"
+ : "=&r" (rv), "+m" (*p)
+ : "r" (p), "i" (v)
+ : "cc", "xer");
+
+ return (rv);
+}
+#define atomic_inc_long_nv(_p) _atomic_addic_long_nv((_p), 1)
+#define atomic_dec_long_nv(_p) _atomic_addic_long_nv((_p), -1)
+
+#define __membar(_f) do { __asm __volatile(_f ::: "memory"); } while (0)
+
+#if defined(MULTIPROCESSOR) || !defined(_KERNEL)
+#define membar_enter() __membar("isync")
+#define membar_exit() __membar("sync")
+#define membar_producer() __membar("sync")
+#define membar_consumer() __membar("isync")
+#define membar_sync() __membar("sync")
+#else
+#define membar_enter() __membar("")
+#define membar_exit() __membar("")
+#define membar_producer() __membar("")
+#define membar_consumer() __membar("")
+#define membar_sync() __membar("")
+#endif
+
+#endif /* _MACHINE_ATOMIC_H_ */
diff --git a/sys/arch/powerpc64/include/bus.h b/sys/arch/powerpc64/include/bus.h
new file mode 100644
index 00000000000..2ed5a1df9b1
--- /dev/null
+++ b/sys/arch/powerpc64/include/bus.h
@@ -0,0 +1,13 @@
+#ifndef _MACHINE_BUS_H_
+#define _MACHINE_BUS_H_
+
+struct bus_space;
+typedef u_long bus_addr_t;
+typedef u_long bus_size_t;
+typedef u_long bus_space_handle_t;
+typedef struct bus_space *bus_space_tag_t;
+
+#define bus_space_write_4(t, h, o, v)
+#define bus_space_read_4(t, h, o) 0xffffffff
+
+#endif /* _MACHINE_BUS_H_ */
diff --git a/sys/arch/powerpc64/include/cdefs.h b/sys/arch/powerpc64/include/cdefs.h
new file mode 100644
index 00000000000..395f533f88f
--- /dev/null
+++ b/sys/arch/powerpc64/include/cdefs.h
@@ -0,0 +1,21 @@
+/* $OpenBSD: cdefs.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.
+ * Public domain.
+ */
+
+#ifndef _MACHINE_CDEFS_H_
+#define _MACHINE_CDEFS_H_
+
+#define __strong_alias(alias,sym) \
+ __asm__(".global " __STRING(alias) " ; " __STRING(alias) \
+ " = " __STRING(sym))
+#define __weak_alias(alias,sym) \
+ __asm__(".weak " __STRING(alias) " ; " __STRING(alias) \
+ " = " __STRING(sym))
+#define __warn_references(sym,msg) \
+ __asm__(".section .gnu.warning." __STRING(sym) \
+ " ; .ascii \"" msg "\" ; .text")
+
+#endif /* !_MACHINE_CDEFS_H_ */
diff --git a/sys/arch/powerpc64/include/conf.h b/sys/arch/powerpc64/include/conf.h
new file mode 100644
index 00000000000..611ce00bb3c
--- /dev/null
+++ b/sys/arch/powerpc64/include/conf.h
@@ -0,0 +1 @@
+#include <sys/conf.h>
diff --git a/sys/arch/powerpc64/include/cpu.h b/sys/arch/powerpc64/include/cpu.h
new file mode 100644
index 00000000000..ceeabbe510c
--- /dev/null
+++ b/sys/arch/powerpc64/include/cpu.h
@@ -0,0 +1,60 @@
+#ifndef _MACHINE_CPU_H_
+#define _MACHINE_CPU_H_
+
+#include <machine/intr.h>
+#include <machine/frame.h>
+
+#include <sys/device.h>
+#include <sys/sched.h>
+
+struct cpu_info {
+ struct device *ci_dev;
+ struct cpu_info *ci_next;
+ struct schedstate_percpu ci_schedstate;
+
+ struct proc *ci_curproc;
+
+ uint32_t ci_ipending;
+#ifdef DIAGNOSTIC
+ int ci_mutex_level;
+#endif
+ int ci_want_resched;
+
+ uint32_t ci_randseed;
+};
+
+extern struct cpu_info cpu_info_primary;
+
+#define curcpu() (&cpu_info_primary)
+
+#define MAXCPUS 1
+#define CPU_IS_PRIMARY(ci) 1
+#define CPU_INFO_UNIT(ci) 0
+#define CPU_INFO_ITERATOR int
+#define CPU_INFO_FOREACH(cii, ci) \
+ for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL)
+
+
+#define CLKF_INTR(frame) 0
+#define CLKF_USERMODE(frame) 0
+#define CLKF_PC(frame) 0
+
+#define aston(p) ((p)->p_md.md_astpending = 1)
+#define need_proftick(p) aston(p)
+
+#define cpu_kick(ci)
+#define cpu_unidle(ci)
+#define signotify(p) setsoftast()
+
+void need_resched(struct cpu_info *);
+#define clear_resched(ci) ((ci)->ci_want_resched = 0)
+
+void delay(u_int);
+#define DELAY(x) delay(x)
+
+#define setsoftast() aston(curcpu()->ci_curproc)
+
+#define PROC_STACK(p) 0
+#define PROC_PC(p) 0
+
+#endif /* _MACHINE_CPU_H_ */
diff --git a/sys/arch/powerpc64/include/db_machdep.h b/sys/arch/powerpc64/include/db_machdep.h
new file mode 100644
index 00000000000..7aa0e7160cc
--- /dev/null
+++ b/sys/arch/powerpc64/include/db_machdep.h
@@ -0,0 +1,19 @@
+typedef long db_expr_t;
+
+typedef long db_regs_t;
+
+extern db_regs_t ddb_regs;
+
+#define PC_REGS(regs) (*regs)
+
+#define BKPT_SIZE 4
+#define BKPT_SET(inst) 0xdeadbeef
+
+// ALL BROKEN!!!
+#define inst_trap_return(ins) ((ins) == 0 && (ins) == 1)
+#define inst_return(ins) ((ins) == 0 && (ins) == 1)
+
+#define inst_call(ins) ((ins) == 0 && (ins) == 1)
+#define inst_branch(ins) ((ins) == 0 && (ins) == 1)
+#define inst_unconditional_flow_transfer(ins) (0)
+
diff --git a/sys/arch/powerpc64/include/disklabel.h b/sys/arch/powerpc64/include/disklabel.h
new file mode 100644
index 00000000000..f41e521e844
--- /dev/null
+++ b/sys/arch/powerpc64/include/disklabel.h
@@ -0,0 +1,26 @@
+/* $OpenBSD: disklabel.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
+ *
+ * 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.
+ */
+
+#ifndef _MACHINE_DISKLABEL_H_
+#define _MACHINE_DISKLABEL_H_
+
+#define LABELSECTOR 1 /* sector containing label */
+#define LABELOFFSET 0 /* offset of label in sector */
+#define MAXPARTITIONS 16 /* number of partitions */
+
+#endif /* _MACHINE_DISKLABEL_H_ */
diff --git a/sys/arch/powerpc64/include/endian.h b/sys/arch/powerpc64/include/endian.h
new file mode 100644
index 00000000000..d638e3446ae
--- /dev/null
+++ b/sys/arch/powerpc64/include/endian.h
@@ -0,0 +1,103 @@
+/* $OpenBSD: endian.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _MACHINE_ENDIAN_H_
+#define _MACHINE_ENDIAN_H_
+
+#ifdef _KERNEL
+
+static inline __uint16_t
+__mswap16(volatile const __uint16_t *m)
+{
+ __uint16_t v;
+
+ __asm("lhbrx %0, 0, %1"
+ : "=r" (v)
+ : "r" (m), "m" (*m));
+
+ return (v);
+}
+
+static inline __uint32_t
+__mswap32(volatile const __uint32_t *m)
+{
+ __uint32_t v;
+
+ __asm("lwbrx %0, 0, %1"
+ : "=r" (v)
+ : "r" (m), "m" (*m));
+
+ return (v);
+}
+
+static inline __uint64_t
+__mswap64(volatile const __uint64_t *m)
+{
+ __uint32_t *a = (__uint32_t *)m;
+ __uint64_t v;
+
+ v = (__uint64_t)__mswap32(a + 1) << 32 |
+ (__uint64_t)__mswap32(a);
+
+ return (v);
+}
+
+static inline void
+__swapm16(volatile __uint16_t *m, __uint16_t v)
+{
+ __asm("sthbrx %1, 0, %2"
+ : "=m" (*m)
+ : "r" (v), "r" (m));
+}
+
+static inline void
+__swapm32(volatile __uint32_t *m, __uint32_t v)
+{
+ __asm("stwbrx %1, 0, %2"
+ : "=m" (*m)
+ : "r" (v), "r" (m));
+}
+
+static inline void
+__swapm64(volatile __uint64_t *m, __uint64_t v)
+{
+ __uint32_t *a = (__uint32_t *)m;
+
+ __swapm32(a + 1, v >> 32);
+ __swapm32(a, v);
+}
+
+#define __HAVE_MD_SWAPIO
+#endif /* _KERNEL */
+
+#undef _BIG_ENDIAN /* XXX - gcc may define _BIG_ENDIAN too */
+#define _BYTE_ORDER _BIG_ENDIAN
+
+#ifndef __FROM_SYS__ENDIAN
+#include <sys/endian.h>
+#endif
+
+#endif /* _MACHINE_ENDIAN_H_ */
diff --git a/sys/arch/powerpc64/include/exec.h b/sys/arch/powerpc64/include/exec.h
new file mode 100644
index 00000000000..a65ac47da72
--- /dev/null
+++ b/sys/arch/powerpc64/include/exec.h
@@ -0,0 +1,30 @@
+/* $OpenBSD: exec.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
+ *
+ * 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.
+ */
+
+#ifndef _MACHINE_EXEC_H_
+#define _MACHINE_EXEC_H_
+
+#define __LDPGSZ 4096
+
+#define ARCH_ELFSIZE 64
+
+#define ELF_TARG_CLASS ELFCLASS64
+#define ELF_TARG_DATA ELFDATA2LSB
+#define ELF_TARG_MACH EM_AARCH64
+
+#endif
diff --git a/sys/arch/powerpc64/include/fpu.h b/sys/arch/powerpc64/include/fpu.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/arch/powerpc64/include/fpu.h
diff --git a/sys/arch/powerpc64/include/frame.h b/sys/arch/powerpc64/include/frame.h
new file mode 100644
index 00000000000..04f8a5b4377
--- /dev/null
+++ b/sys/arch/powerpc64/include/frame.h
@@ -0,0 +1 @@
+#define trapframe(p) ((struct trapframe *)NULL)
diff --git a/sys/arch/powerpc64/include/intr.h b/sys/arch/powerpc64/include/intr.h
new file mode 100644
index 00000000000..12b7ad42374
--- /dev/null
+++ b/sys/arch/powerpc64/include/intr.h
@@ -0,0 +1,32 @@
+#define IPL_NONE 0
+#define IPL_SOFTCLOCK 2
+#define IPL_SOFTNET 3
+#define IPL_SOFTTTY 4
+#define IPL_BIO 5
+#define IPL_NET 6
+#define IPL_TTY 7
+#define IPL_VM 8
+#define IPL_AUDIO 9
+#define IPL_CLOCK 10
+#define IPL_STATCLOCK IPL_CLOCK
+#define IPL_HIGH 15
+#define IPL_MPFLOOR IPL_TTY
+
+#define spl0() 9
+#define splsoftclock() 0
+#define splsoftnet() 0
+#define splsofttty() 0
+#define splbio() 0
+#define splnet() 0
+#define spltty() 0
+#define splvm() 0
+#define splclock() 0
+#define splstatclock() 0
+#define splsched() 0
+#define splhigh() 0
+#define splraise(s) 0
+#define splx(s) (void)s
+
+#define splassert(x)
+
+#include <machine/softintr.h>
diff --git a/sys/arch/powerpc64/include/limits.h b/sys/arch/powerpc64/include/limits.h
new file mode 100644
index 00000000000..285192fefe9
--- /dev/null
+++ b/sys/arch/powerpc64/include/limits.h
@@ -0,0 +1,55 @@
+/* $OpenBSD: limits.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 1988 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.
+ *
+ * from: @(#)limits.h 7.2 (Berkeley) 6/28/90
+ */
+
+#ifndef _MACHINE_LIMITS_H_
+#define _MACHINE_LIMITS_H_
+
+#include <sys/cdefs.h>
+
+#if __POSIX_VISIBLE || __XPG_VISIBLE
+#ifndef SIZE_MAX
+#define SIZE_MAX ULONG_MAX /* max value for a size_t */
+#endif
+#define SSIZE_MAX LONG_MAX /* max value for a ssize_t */
+#endif
+
+#if __BSD_VISIBLE
+#define SIZE_T_MAX ULONG_MAX /* max value for a size_t (historic) */
+
+#define UQUAD_MAX 0xffffffffffffffffULL /* max unsigned quad */
+#define QUAD_MAX 0x7fffffffffffffffLL /* max signed quad */
+#define QUAD_MIN (-0x7fffffffffffffffLL-1) /* min signed quad */
+
+#endif /* __BSD_VISIBLE */
+
+#endif /* _MACHINE_LIMITS_H_ */
diff --git a/sys/arch/powerpc64/include/mutex.h b/sys/arch/powerpc64/include/mutex.h
new file mode 100644
index 00000000000..b4381414adf
--- /dev/null
+++ b/sys/arch/powerpc64/include/mutex.h
@@ -0,0 +1,3 @@
+/* $OpenBSD: mutex.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+#define __USE_MI_MUTEX
diff --git a/sys/arch/powerpc64/include/param.h b/sys/arch/powerpc64/include/param.h
new file mode 100644
index 00000000000..7596a0b913f
--- /dev/null
+++ b/sys/arch/powerpc64/include/param.h
@@ -0,0 +1,85 @@
+/* $OpenBSD: param.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _MACHINE_PARAM_H_
+#define _MACHINE_PARAM_H_
+
+#ifdef _KERNEL
+#ifndef _LOCORE
+#include <machine/cpu.h>
+#endif
+#endif
+
+#define _MACHINE powerpc64
+#define MACHINE "powerpc64"
+#define _MACHINE_ARCH powerpc64
+#define MACHINE_ARCH "powerpc64"
+#define MID_MACHINE MID_POWERPC64
+
+#define PAGE_SHIFT 12
+#define PAGE_SIZE (1 << PAGE_SHIFT)
+#define PAGE_MASK (PAGE_SIZE - 1)
+
+#define KERNBASE 0xffffff8000000000ULL /* start of kernel virtual space */
+
+#ifdef _KERNEL
+
+#define NBPG PAGE_SIZE /* bytes/page */
+#define PGSHIFT PAGE_SHIFT /* LOG2(PAGE_SIZE) */
+#define PGOFSET PAGE_MASK /* byte offset into page */
+
+#define UPAGES 5 /* pages of u-area */
+#define USPACE (UPAGES * PAGE_SIZE) /* total size of u-area */
+#define USPACE_ALIGN 0 /* u-area alignment 0-none */
+
+#define NMBCLUSTERS (64 * 1024) /* max cluster allocation */
+
+#ifndef MSGBUFSIZE
+#define MSGBUFSIZE (16 * PAGE_SIZE) /* default message buffer size */
+#endif
+
+/*
+ * Maximum size of the kernel malloc arena in PAGE_SIZE-sized
+ * logical pages.
+ */
+#define NKMEMPAGES_MAX_DEFAULT ((128 * 1024 * 1024) >> PAGE_SHIFT)
+
+#define STACKALIGNBYTES (32 - 1)
+#define STACKALIGN(p) ((u_long)(p) &~ STACKALIGNBYTES)
+
+#define __HAVE_FDT
+
+#endif /* _KERNEL */
+
+#endif /* _MACHINE_PARAM_H_ */
diff --git a/sys/arch/powerpc64/include/pcb.h b/sys/arch/powerpc64/include/pcb.h
new file mode 100644
index 00000000000..f6bf78bd428
--- /dev/null
+++ b/sys/arch/powerpc64/include/pcb.h
@@ -0,0 +1,8 @@
+#ifndef _MACHINE_PCB_H_
+#define _MACHINE_PCB_H_
+
+struct pcb {
+ u_int pcb_flags;
+};
+
+#endif /* _MACHINE_PCB_H_ */
diff --git a/sys/arch/powerpc64/include/pmap.h b/sys/arch/powerpc64/include/pmap.h
new file mode 100644
index 00000000000..d14b13aea88
--- /dev/null
+++ b/sys/arch/powerpc64/include/pmap.h
@@ -0,0 +1,17 @@
+#ifndef _MACHINE_PMAP_H_
+#define _MACHINE_PMAP_H_
+
+typedef struct pmap *pmap_t;
+
+struct vm_page_md {
+};
+
+#define VM_MDPAGE_INIT(pg) do { } while (0)
+
+#define pmap_kernel() ((struct pmap *)NULL)
+#define pmap_resident_count(pm) 0
+#define pmap_unuse_final(p)
+#define pmap_remove_holes(vm)
+#define pmap_update(pm)
+
+#endif /* _MACHINE_PMAP_H_ */
diff --git a/sys/arch/powerpc64/include/proc.h b/sys/arch/powerpc64/include/proc.h
new file mode 100644
index 00000000000..0fe31ea20c9
--- /dev/null
+++ b/sys/arch/powerpc64/include/proc.h
@@ -0,0 +1,44 @@
+/* $OpenBSD: proc.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 1991 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.
+ *
+ * @(#)proc.h 7.1 (Berkeley) 5/15/91
+ */
+
+#ifndef _MACHINE_PROC_H_
+#define _MACHINE_PROC_H_
+
+/*
+ * Machine-dependent part of the proc structure for arm64.
+ */
+struct mdproc {
+ volatile int md_astpending;
+};
+
+#endif /* _MACHINE_PROC_H_ */
diff --git a/sys/arch/powerpc64/include/psl.h b/sys/arch/powerpc64/include/psl.h
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/sys/arch/powerpc64/include/psl.h
diff --git a/sys/arch/powerpc64/include/ptrace.h b/sys/arch/powerpc64/include/ptrace.h
new file mode 100644
index 00000000000..ce896378b62
--- /dev/null
+++ b/sys/arch/powerpc64/include/ptrace.h
@@ -0,0 +1,44 @@
+/* $OpenBSD: ptrace.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 1993 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.
+ * 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.
+ */
+#ifndef _POWERPC_PTRACE_H_
+#define _POWERPC_PTRACE_H_
+
+/*
+ * powerpc64-dependent ptrace definitions
+ */
+#define PT_STEP (PT_FIRSTMACH + 0)
+#define PT_GETREGS (PT_FIRSTMACH + 1)
+#define PT_SETREGS (PT_FIRSTMACH + 2)
+#define PT_GETFPREGS (PT_FIRSTMACH + 3)
+#define PT_SETFPREGS (PT_FIRSTMACH + 4)
+
+#endif /* !_POWERPC_PTRACE_H_ */
diff --git a/sys/arch/powerpc64/include/reg.h b/sys/arch/powerpc64/include/reg.h
new file mode 100644
index 00000000000..34491514b65
--- /dev/null
+++ b/sys/arch/powerpc64/include/reg.h
@@ -0,0 +1,76 @@
+/* $OpenBSD: reg.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * 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.
+ *
+ * @(#)reg.h 5.5 (Berkeley) 1/18/91
+ */
+
+#ifndef _POWERPC_REG_H_
+#define _POWERPC_REG_H_
+
+/*
+ * Struct reg, used for ptrace and in signal contexts
+ * Note that in signal contexts, it's represented as an array.
+ * That array has to look exactly like 'struct reg' though.
+ */
+
+struct reg {
+ u_int32_t gpr[32];
+ u_int64_t fpr[32];
+ u_int32_t pc;
+ u_int32_t ps;
+ u_int32_t cnd;
+ u_int32_t lr;
+ u_int32_t cnt;
+ u_int32_t xer;
+ u_int32_t mq;
+};
+
+struct fpreg {
+ u_int64_t fpr[32];
+ u_int32_t fpscr;
+};
+
+struct vreg {
+ u_int32_t vreg[32][4];
+ u_int64_t vscr;
+ u_int32_t vrsave;
+ u_int32_t pad;
+};
+
+#ifdef _KERNEL
+void save_vec(struct proc *);
+void enable_vec(struct proc *);
+extern struct proc *ppc_vecproc;
+extern struct pool ppc_vecpl;
+#endif /* _KERNEL */
+#endif /* !_POWERPC_REG_H_ */
diff --git a/sys/arch/powerpc64/include/signal.h b/sys/arch/powerpc64/include/signal.h
new file mode 100644
index 00000000000..21293a220c2
--- /dev/null
+++ b/sys/arch/powerpc64/include/signal.h
@@ -0,0 +1,71 @@
+/* $OpenBSD: signal.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _POWERPC_SIGNAL_H_
+#define _POWERPC_SIGNAL_H_
+
+#include <sys/cdefs.h>
+
+typedef int sig_atomic_t;
+
+#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
+#include <machine/_types.h>
+
+/*
+ * We have to save all registers on every trap, because
+ * 1. user could attach this process every time
+ * 2. we must be able to restore all user registers in case of fork
+ * Actually, we do not save the fp registers on trap, since
+ * these are not used by the kernel. They are saved only when switching
+ * between processes using the FPU.
+ *
+ */
+struct trapframe {
+ __register_t fixreg[32];
+ __register_t lr;
+ __register_t cr;
+ __register_t xer;
+ __register_t ctr;
+ int srr0;
+ int srr1;
+ int dar; /* dar & dsisr are only filled on a DSI trap */
+ int dsisr;
+ __register_t exc;
+};
+
+struct sigcontext {
+ long sc_cookie;
+ int sc_mask; /* saved signal mask */
+ struct trapframe sc_frame; /* saved registers */
+};
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
+#endif /* _POWERPC_SIGNAL_H_ */
diff --git a/sys/arch/powerpc64/include/softintr.h b/sys/arch/powerpc64/include/softintr.h
new file mode 100644
index 00000000000..5131abc4379
--- /dev/null
+++ b/sys/arch/powerpc64/include/softintr.h
@@ -0,0 +1,99 @@
+/* $OpenBSD: softintr.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Charles M. Hannum, and by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 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.
+ */
+
+#ifndef _MACHINE_SOFTINTR_H_
+#define _MACHINE_SOFTINTR_H_
+
+#ifdef _KERNEL
+
+#include <sys/mutex.h>
+#include <sys/queue.h>
+
+/*
+ * Generic software interrupt support for all AArch64 platforms.
+ *
+ * To use this code, include <machine/softintr.h> from your platform's
+ * <machine/intr.h>.
+ */
+
+#define SIR_SOFT 0 /* for IPL_SOFT */
+#define SIR_CLOCK 1 /* for IPL_SOFTCLOCK */
+#define SIR_NET 2 /* for IPL_SOFTNET */
+#define SIR_TTY 3 /* for IPL_SOFTTTY */
+
+#define SI_NSOFTINTR 4
+
+struct soft_intrhand {
+ TAILQ_ENTRY(soft_intrhand)
+ sih_q;
+ struct soft_intr *sih_intrhead;
+ void (*sih_fn)(void *);
+ void (*sih_fnwrap)(void *);
+ void *sih_arg;
+ void *sih_argwrap;
+ int sih_pending;
+};
+
+struct soft_intr {
+ TAILQ_HEAD(, soft_intrhand)
+ softintr_q;
+ int softintr_ssir;
+ struct mutex softintr_lock;
+};
+
+#define SOFTINTR_ESTABLISH_MPSAFE 0x01
+void *softintr_establish_flags(int, void (*)(void *), void *, int);
+#define softintr_establish(i, f, a) \
+ softintr_establish_flags(i, f, a, 0)
+#define softintr_establish_mpsafe(i, f, a) \
+ softintr_establish_flags(i, f, a, SOFTINTR_ESTABLISH_MPSAFE)
+void softintr_disestablish(void *);
+void softintr_init(void);
+void softintr_dispatch(int);
+void softintr(int);
+
+#define softintr_schedule(arg) \
+do { \
+ struct soft_intrhand *__sih = (arg); \
+ struct soft_intr *__si = __sih->sih_intrhead; \
+ \
+ mtx_enter(&__si->softintr_lock); \
+ if (__sih->sih_pending == 0) { \
+ TAILQ_INSERT_TAIL(&__si->softintr_q, __sih, sih_q); \
+ __sih->sih_pending = 1; \
+ softintr(__si->softintr_ssir); \
+ } \
+ mtx_leave(&__si->softintr_lock); \
+} while (/*CONSTCOND*/ 0)
+
+#endif /* _KERNEL */
+
+#endif /* _MACHINE_SOFTINTR_H_ */
diff --git a/sys/arch/powerpc64/include/spinlock.h b/sys/arch/powerpc64/include/spinlock.h
new file mode 100644
index 00000000000..4e047bac741
--- /dev/null
+++ b/sys/arch/powerpc64/include/spinlock.h
@@ -0,0 +1,26 @@
+/* $OpenBSD: spinlock.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
+ *
+ * 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.
+ */
+
+#ifndef _MACHINE_SPINLOCK_H_
+#define _MACHINE_SPINLOCK_H_
+
+#define _ATOMIC_LOCK_UNLOCKED (0)
+#define _ATOMIC_LOCK_LOCKED (1)
+typedef int _atomic_lock_t;
+
+#endif
diff --git a/sys/arch/powerpc64/include/tcb.h b/sys/arch/powerpc64/include/tcb.h
new file mode 100644
index 00000000000..26646141826
--- /dev/null
+++ b/sys/arch/powerpc64/include/tcb.h
@@ -0,0 +1,42 @@
+/* $OpenBSD: tcb.h,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2011 Philip Guenther <guenther@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#ifndef _MACHINE_TCB_H_
+#define _MACHINE_TCB_H_
+
+#ifdef _KERNEL
+
+#define TCB_GET(p) \
+ ((void *)trapframe(p)->fixreg[2])
+#define TCB_SET(p, addr) \
+ (trapframe(p)->fixreg[2] = (__register_t)(addr))
+
+#else /* _KERNEL */
+
+/* ELF TLS ABI calls for small TCB, with static TLS data after it */
+#define TLS_VARIANT 1
+
+/* powerpc offsets the TCB pointer 0x7000 bytes after the data */
+#define TCB_OFFSET 0x7000
+
+register void *__tcb __asm__ ("r2");
+#define TCB_GET() (__tcb)
+#define TCB_SET(tcb) ((__tcb) = (tcb))
+
+#endif /* _KERNEL */
+#endif /* _MACHINE_TCB_H_ */
diff --git a/sys/arch/powerpc64/include/vmparam.h b/sys/arch/powerpc64/include/vmparam.h
new file mode 100644
index 00000000000..c1f722a4202
--- /dev/null
+++ b/sys/arch/powerpc64/include/vmparam.h
@@ -0,0 +1,47 @@
+/*
+ * Machine dependent constants for powerpc64.
+ */
+
+#define USRSTACK VM_MAXUSER_ADDRESS
+
+/*
+ * Virtual memory related constants, all in bytes
+ */
+#define MAXTSIZ ((paddr_t)256*1024*1024) /* max text size */
+#ifndef DFLDSIZ
+#define DFLDSIZ ((paddr_t)512*1024*1024) /* initial data size limit */
+#endif
+#ifndef MAXDSIZ
+#define MAXDSIZ ((paddr_t)16*1024*1024*1024) /* max data size */
+#endif
+#ifndef BRKSIZ
+#define BRKSIZ ((paddr_t)16*1024*1024*1024) /* heap gap size */
+#endif
+#ifndef DFLSSIZ
+#define DFLSSIZ ((paddr_t)2*1024*1024) /* initial stack size limit */
+#endif
+#ifndef MAXSSIZ
+#define MAXSSIZ ((paddr_t)32*1024*1024) /* max stack size */
+#endif
+
+#define STACKGAP_RANDOM 256*1024
+
+/*
+ * Size of shared memory map
+ */
+#ifndef SHMMAXPGS
+#define SHMMAXPGS 1024
+#endif
+
+/*
+ * Size of User Raw I/O map
+ */
+#define USRIOSIZE 300
+
+#define VM_PHYSSEG_MAX 32
+
+#define VM_MIN_ADDRESS ((vaddr_t)PAGE_SIZE)
+#define VM_MAXUSER_ADDRESS 0xbfffffffffffffffUL
+#define VM_MAX_ADDRESS 0xffffffffffffffffUL
+#define VM_MIN_KERNEL_ADDRESS 0xc000000000000000UL
+#define VM_MAX_KERNEL_ADDRESS VM_MAX_ADDRESS
diff --git a/sys/arch/powerpc64/powerpc64/autoconf.c b/sys/arch/powerpc64/powerpc64/autoconf.c
new file mode 100644
index 00000000000..0da46fde63c
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/autoconf.c
@@ -0,0 +1,43 @@
+#include <sys/param.h>
+#include <sys/device.h>
+
+void
+cpu_configure(void)
+{
+}
+
+void
+diskconf(void)
+{
+}
+
+void
+device_register(struct device *dev, void *aux)
+{
+}
+
+struct nam2blk nam2blk[] = {
+ { NULL, -1 }
+};
+
+int mainbus_match(struct device *, void *, void *);
+void mainbus_attach(struct device *, struct device *, void *);
+
+struct cfattach mainbus_ca = {
+ sizeof(struct device), mainbus_match, mainbus_attach
+};
+
+struct cfdriver mainbus_cd = {
+ NULL, "mainbus", DV_DULL
+};
+
+int
+mainbus_match(struct device *parent, void *cfdata, void *aux)
+{
+ return 1;
+}
+
+void
+mainbus_attach(struct device *parent, struct device *self, void *aux)
+{
+}
diff --git a/sys/arch/powerpc64/powerpc64/conf.c b/sys/arch/powerpc64/powerpc64/conf.c
new file mode 100644
index 00000000000..41e9ff8f2b6
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/conf.c
@@ -0,0 +1,43 @@
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/vnode.h>
+
+#include <machine/conf.h>
+
+struct bdevsw bdevsw[] =
+{
+ bdev_notdef(),
+};
+int nblkdev = nitems(bdevsw);
+
+struct cdevsw cdevsw[] =
+{
+ cdev_notdef(),
+};
+int nchrdev = nitems(cdevsw);
+
+dev_t swapdev;
+
+int
+iskmemdev(dev_t dev)
+{
+ return 0;
+}
+
+int
+iszerodev(dev_t dev)
+{
+ return 0;
+}
+
+dev_t
+getnulldev(void)
+{
+ return makedev(0, 0);
+}
+
+int chrtoblktbl[] = {
+ NODEV,
+};
+int nchrtoblktbl = nitems(chrtoblktbl);
diff --git a/sys/arch/powerpc64/powerpc64/cpu.c b/sys/arch/powerpc64/powerpc64/cpu.c
new file mode 100644
index 00000000000..9dfcf2c8bad
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/cpu.c
@@ -0,0 +1,3 @@
+char cpu_model[64];
+
+struct cpu_info *cpu_info_primary;
diff --git a/sys/arch/powerpc64/powerpc64/disksubr.c b/sys/arch/powerpc64/powerpc64/disksubr.c
new file mode 100644
index 00000000000..337949b421e
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/disksubr.c
@@ -0,0 +1,132 @@
+/* $OpenBSD: disksubr.c,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+/* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */
+
+/*
+ * Copyright (c) 1996 Theo de Raadt
+ * Copyright (c) 1982, 1986, 1988 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.
+ */
+
+#include <sys/param.h>
+#include <sys/buf.h>
+#include <sys/disklabel.h>
+#include <sys/disk.h>
+
+/*
+ * Attempt to read a disk label from a device
+ * using the indicated strategy routine.
+ * The label must be partly set up before this:
+ * secpercyl, secsize and anything required for a block i/o read
+ * operation in the driver's strategy/start routines
+ * must be filled in before calling us.
+ *
+ * If dos partition table requested, attempt to load it and
+ * find disklabel inside a DOS partition.
+ *
+ * We would like to check if each MBR has a valid DOSMBR_SIGNATURE, but
+ * we cannot because it doesn't always exist. So.. we assume the
+ * MBR is valid.
+ */
+int
+readdisklabel(dev_t dev, void (*strat)(struct buf *),
+ struct disklabel *lp, int spoofonly)
+{
+ struct buf *bp = NULL;
+ int error;
+
+ if ((error = initdisklabel(lp)))
+ goto done;
+
+ /* get a buffer and initialize it */
+ bp = geteblk(lp->d_secsize);
+ bp->b_dev = dev;
+
+ error = readdoslabel(bp, strat, lp, NULL, spoofonly);
+ if (error == 0)
+ goto done;
+
+#if defined(CD9660)
+ error = iso_disklabelspoof(dev, strat, lp);
+ if (error == 0)
+ goto done;
+#endif
+#if defined(UDF)
+ error = udf_disklabelspoof(dev, strat, lp);
+ if (error == 0)
+ goto done;
+#endif
+
+done:
+ if (bp) {
+ bp->b_flags |= B_INVAL;
+ brelse(bp);
+ }
+ disk_change = 1;
+ return (error);
+}
+
+/*
+ * Write disk label back to device after modification.
+ */
+int
+writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp)
+{
+ daddr_t partoff = -1;
+ int error = EIO;
+ int offset;
+ struct disklabel *dlp;
+ struct buf *bp = NULL;
+
+ /* get a buffer and initialize it */
+ bp = geteblk(lp->d_secsize);
+ bp->b_dev = dev;
+
+ if (readdoslabel(bp, strat, lp, &partoff, 1) != 0)
+ goto done;
+
+ /* Read it in, slap the new label in, and write it back out */
+ error = readdisksector(bp, strat, lp, DL_BLKTOSEC(lp, partoff +
+ DOS_LABELSECTOR));
+ if (error)
+ goto done;
+ offset = DL_BLKOFFSET(lp, partoff + DOS_LABELSECTOR);
+
+ dlp = (struct disklabel *)(bp->b_data + offset);
+ *dlp = *lp;
+ CLR(bp->b_flags, B_READ | B_WRITE | B_DONE);
+ SET(bp->b_flags, B_BUSY | B_WRITE | B_RAW);
+ (*strat)(bp);
+ error = biowait(bp);
+
+done:
+ if (bp) {
+ bp->b_flags |= B_INVAL;
+ brelse(bp);
+ }
+ disk_change = 1;
+ return (error);
+}
diff --git a/sys/arch/powerpc64/powerpc64/genassym.cf b/sys/arch/powerpc64/powerpc64/genassym.cf
new file mode 100644
index 00000000000..e75ee5cd8fa
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/genassym.cf
@@ -0,0 +1 @@
+include <sys/param.h>
diff --git a/sys/arch/powerpc64/powerpc64/locore.S b/sys/arch/powerpc64/powerpc64/locore.S
new file mode 100644
index 00000000000..bf03ebc4b7b
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/locore.S
@@ -0,0 +1,171 @@
+/* $OpenBSD: locore.S,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#define OPAL_TEST 0
+#define OPAL_CONSOLE_WRITE 1
+#define OPAL_CEC_POWER_DOWN 5
+#define OPAL_CEC_REBOOT 6
+
+ .abiversion 2
+
+ .rodata
+
+ .globl sigcode
+ .globl sigcoderet
+sigcode:
+sigcoderet:
+ blr
+ .globl esigcode
+esigcode:
+
+ .globl sigfill
+sigfill:
+ .long 0
+esigfill:
+ .globl sigfillsiz
+sigfillsiz:
+ .long esigfill - sigfill
+
+ .text
+
+ .globl cpu_idle_enter
+cpu_idle_enter:
+ blr
+
+ .globl cpu_idle_cycle
+cpu_idle_cycle:
+ blr
+
+ .globl cpu_idle_leave
+cpu_idle_leave:
+ blr
+
+ .globl cpu_switchto
+cpu_switchto:
+ blr
+
+ .data
+
+ .globl opal_base
+opal_base:
+ .quad 0
+ .globl opal_entry
+opal_entry:
+ .quad 0
+
+ .text
+
+ .globl opal_test
+opal_test:
+ mflr %r0
+ std %r0, 16(%r1)
+ stdu %r1, -32(%r1)
+ std %r2, 24(%r1)
+
+ addis %r11, %r2, opal_base@toc@ha
+ addi %r11, %r11, opal_base@toc@l
+ addis %r12, %r2, opal_entry@toc@ha
+ addi %r12, %r12, opal_entry@toc@l
+ ld %r11, 0(%r11)
+ ld %r12, 0(%r12)
+
+ li %r0, OPAL_TEST
+ mr %r2, %r11
+ mtctr %r12
+ bctrl
+
+ ld %r2, 24(%r1)
+ addi %r1, %r1, 32
+ ld %r0, 16(%r1)
+ mtlr %r0
+ blr
+
+ .globl opal_console_write
+opal_console_write:
+ mflr %r0
+ std %r0, 16(%r1)
+ stdu %r1, -32(%r1)
+ std %r2, 24(%r1)
+
+ addis %r11, %r2, opal_base@toc@ha
+ addi %r11, %r11, opal_base@toc@l
+ addis %r12, %r2, opal_entry@toc@ha
+ addi %r12, %r12, opal_entry@toc@l
+ ld %r11, 0(%r11)
+ ld %r12, 0(%r12)
+
+ li %r0, OPAL_CONSOLE_WRITE
+ mr %r2, %r11
+ mtctr %r12
+ bctrl
+
+ ld %r2, 24(%r1)
+ addi %r1, %r1, 32
+ ld %r0, 16(%r1)
+ mtlr %r0
+ blr
+
+ .globl opal_cec_power_down
+opal_cec_power_down:
+ mflr %r0
+ std %r0, 16(%r1)
+ stdu %r1, -32(%r1)
+ std %r2, 24(%r1)
+
+ addis %r11, %r2, opal_base@toc@ha
+ addi %r11, %r11, opal_base@toc@l
+ addis %r12, %r2, opal_entry@toc@ha
+ addi %r12, %r12, opal_entry@toc@l
+ ld %r11, 0(%r11)
+ ld %r12, 0(%r12)
+
+ li %r0, OPAL_CEC_POWER_DOWN
+ mr %r2, %r11
+ mtctr %r12
+ bctrl
+
+ ld %r2, 24(%r1)
+ addi %r1, %r1, 32
+ ld %r0, 16(%r1)
+ mtlr %r0
+ blr
+
+ .globl opal_cec_reboot
+opal_cec_reboot:
+ mflr %r0
+ std %r0, 16(%r1)
+ stdu %r1, -32(%r1)
+ std %r2, 24(%r1)
+
+ addis %r11, %r2, opal_base@toc@ha
+ addi %r11, %r11, opal_base@toc@l
+ addis %r12, %r2, opal_entry@toc@ha
+ addi %r12, %r12, opal_entry@toc@l
+ ld %r11, 0(%r11)
+ ld %r12, 0(%r12)
+
+ li %r0, OPAL_CEC_REBOOT
+ mr %r2, %r11
+ mtctr %r12
+ bctrl
+
+ ld %r2, 24(%r1)
+ addi %r1, %r1, 32
+ ld %r0, 16(%r1)
+ mtlr %r0
+ blr
diff --git a/sys/arch/powerpc64/powerpc64/locore0.S b/sys/arch/powerpc64/powerpc64/locore0.S
new file mode 100644
index 00000000000..58fa78a70ad
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/locore0.S
@@ -0,0 +1,71 @@
+/* $OpenBSD: locore0.S,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "assym.h"
+
+#include <machine/param.h>
+
+ .abiversion 2
+
+ .text
+
+ .globl _start
+_start:
+ mr %r14, %r3 /* device tree */
+
+ bl 1f
+1: mflr %r30
+
+ addis %r1, %r30, (initstack_end - 1b)@ha
+ addi %r1, %r1, (initstack_end - 1b)@l
+ addi %r1, %r1, -32
+
+ /*
+ * Not all kexec(8) flavours actually pass the OPAL entry point.
+ * We will overwrite these values later with information from the
+ * FDT.
+ */
+ addis %r3, %r30, (opal_base - 1b)@ha
+ addi %r3, %r3, (opal_base - 1b)@l
+ addis %r4, %r30, (opal_entry - 1b)@ha
+ addi %r4, %r4, (opal_entry - 1b)@l
+ std %r8, 0(%r3) /* OPAL base */
+ std %r9, 0(%r4) /* OPAL entry */
+
+ /* Initialize TOC pointer. */
+ addis %r2, %r30, (.TOC. - 1b)@ha
+ addi %r2, %r2, (.TOC. - 1b)@l
+
+ /* Process ELF relocations. */
+ addis %r3, %r30, (_DYNAMIC - 1b)@ha
+ addi %r3, %r3, (_DYNAMIC - 1b)@l
+ ld %r4, -0x8000(%r2)
+ subf %r4, %r4, %r2
+ bl self_reloc
+
+ mr %r3, %r14 /* device tree */
+ bl init_powernv
+
+ b .
+
+ .data
+
+ .align PAGE_SHIFT
+initstack:
+ .space USPACE
+initstack_end:
diff --git a/sys/arch/powerpc64/powerpc64/machdep.c b/sys/arch/powerpc64/powerpc64/machdep.c
new file mode 100644
index 00000000000..bc264cadc34
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/machdep.c
@@ -0,0 +1,320 @@
+/* $OpenBSD: machdep.c,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2020 Mark Kettenis <kettenis@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/exec.h>
+#include <sys/exec_elf.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <dev/ofw/fdt.h>
+#include <dev/cons.h>
+
+struct uvm_constraint_range dma_constraint = { 0x0, (paddr_t)-1 };
+struct uvm_constraint_range *uvm_md_constraints[] = { NULL };
+
+int cold = 1;
+int safepri = 0;
+int physmem;
+
+struct vm_map *exec_map;
+struct vm_map *phys_map;
+
+char machine[] = MACHINE;
+
+struct user *proc0paddr;
+
+caddr_t esym;
+
+extern void opal_console_write(int64_t, int64_t *, const uint8_t *);
+extern void opal_cec_reboot(void);
+
+void opal_printf(const char *fmt, ...);
+
+extern char __bss_start[];
+extern char end[];
+
+extern uint64_t opal_base;
+extern uint64_t opal_entry;
+
+void
+init_powernv(void *fdt)
+{
+ char *prop;
+ void *node;
+
+ /* Clear BSS. */
+ memset(__bss_start, 0, end - __bss_start);
+
+ if (!fdt_init(fdt) || fdt_get_size(fdt) == 0)
+ panic("%s: no FDT\r\n", __func__);
+
+ node = fdt_find_node("/ibm,opal");
+ if (node) {
+ fdt_node_property(node, "opal-base-address", &prop);
+ opal_base = bemtoh64((uint64_t *)prop);
+ fdt_node_property(node, "opal-entry-address", &prop);
+ opal_entry = bemtoh64((uint64_t *)prop);
+ fdt_node_property(node, "compatible", &prop);
+ printf("%s\n", prop);
+ }
+
+ node = fdt_find_node("/");
+ fdt_node_property(node, "compatible", &prop);
+ printf("%s\n", prop);
+
+ fdt_node_property(node, "model", &prop);
+ printf("%s\n", prop);
+
+ uint32_t pvr;
+ __asm volatile("mfspr %0,287" : "=r"(pvr));
+ printf("PVR %x\n", pvr);
+
+ uint32_t hid;
+ __asm volatile("mfspr %0,1008" : "=r"(hid));
+ printf("HID %x\n", hid);
+
+ uint64_t lpcr;
+ __asm volatile("mfspr %0,318" : "=r"(lpcr));
+ printf("LPCR %llx\n", lpcr);
+
+ uint64_t lpidr;
+ __asm volatile("mfspr %0,319" : "=r"(lpidr));
+ printf("LPIDR %llx\n", lpidr);
+
+ uint64_t msr;
+ __asm volatile("mfmsr %0" : "=r"(msr));
+ printf("MSR %llx\n", msr);
+
+ uint64_t toc;
+ __asm volatile("mr %0, %%r2" : "=r"(toc));
+ printf("TOC %llx\n", toc);
+
+ printf("Hello, World!\n");
+ opal_cec_reboot();
+}
+
+#define R_PPC64_RELATIVE 22
+#define ELF_R_TYPE_RELATIVE R_PPC64_RELATIVE
+
+/*
+ * Disable optimization for this function to prevent clang from
+ * generating jump tables that need relocation.
+ */
+__attribute__((optnone)) void
+self_reloc(Elf_Dyn *dynamic, Elf_Addr base)
+{
+ Elf_Word relasz = 0, relaent = sizeof(Elf_RelA);
+ Elf_RelA *rela = NULL;
+ Elf_Addr *addr;
+ Elf_Dyn *dynp;
+
+ for (dynp = dynamic; dynp->d_tag != DT_NULL; dynp++) {
+ switch (dynp->d_tag) {
+ case DT_RELA:
+ rela = (Elf_RelA *)(dynp->d_un.d_ptr + base);
+ break;
+ case DT_RELASZ:
+ relasz = dynp->d_un.d_val;
+ break;
+ case DT_RELAENT:
+ relaent = dynp->d_un.d_val;
+ break;
+ }
+ }
+
+ while (relasz > 0) {
+ switch (ELF_R_TYPE(rela->r_info)) {
+ case ELF_R_TYPE_RELATIVE:
+ addr = (Elf_Addr *)(base + rela->r_offset);
+ *addr = base + rela->r_addend;
+ break;
+ }
+ rela = (Elf_RelA *)((caddr_t)rela + relaent);
+ relasz -= relaent;
+ }
+}
+
+void
+opal_printf(const char *fmt, ...)
+{
+ static char buf[256];
+ uint64_t len;
+ va_list ap;
+
+ va_start(ap, fmt);
+ len = vsnprintf(buf, sizeof(buf), fmt, ap);
+ if (len == (uint64_t)-1)
+ len = 0;
+ else if (len >= sizeof(buf))
+ len = sizeof(buf) - 1;
+ va_end(ap);
+
+ opal_console_write(0, &len, buf);
+}
+
+void
+opal_cnprobe(struct consdev *cd)
+{
+}
+
+void
+opal_cninit(struct consdev *cd)
+{
+}
+
+int
+opal_cngetc(dev_t dev)
+{
+ return -1;
+}
+
+void
+opal_cnputc(dev_t dev, int c)
+{
+ uint64_t len = 1;
+ char ch = c;
+
+ opal_console_write(0, &len, &ch);
+}
+
+void
+opal_cnpollc(dev_t dev, int on)
+{
+}
+
+struct consdev opal_consdev = {
+ .cn_probe = opal_cnprobe,
+ .cn_init = opal_cninit,
+ .cn_getc = opal_cngetc,
+ .cn_putc = opal_cnputc,
+ .cn_pollc = opal_cnpollc,
+};
+
+struct consdev *cn_tab = &opal_consdev;
+
+int
+copyin(const void *src, void *dst, size_t size)
+{
+ return EFAULT;
+}
+
+int
+copyout(const void *src, void *dst, size_t size)
+{
+ return EFAULT;
+}
+
+int
+copystr(const void *src, void *dst, size_t len, size_t *lenp)
+{
+ return EFAULT;
+}
+
+int
+copyinstr(const void *src, void *dst, size_t size, size_t *lenp)
+{
+ return EFAULT;
+}
+
+int
+copyoutstr(const void *src, void *dst, size_t size, size_t *lenp)
+{
+ return EFAULT;
+}
+
+int
+kcopy(const void *src, void *dst, size_t size)
+{
+ return EFAULT;
+}
+
+void
+need_resched(struct cpu_info *ci)
+{
+ ci->ci_want_resched = 1;
+}
+
+void
+delay(u_int us)
+{
+}
+
+void
+cpu_startup(void)
+{
+}
+
+void
+cpu_initclocks(void)
+{
+}
+
+void
+setstatclockrate(int new)
+{
+}
+
+void
+setregs(struct proc *p, struct exec_package *pack, u_long stack,
+ register_t *retval)
+{
+}
+
+void
+sendsig(sig_t catcher, int sig, sigset_t mask, const siginfo_t *ksip)
+{
+}
+
+int
+sys_sigreturn(struct proc *p, void *v, register_t *retval)
+{
+ return EJUSTRETURN;
+}
+
+/*
+ * machine dependent system variables.
+ */
+
+int
+cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
+ size_t newlen, struct proc *p)
+{
+ /* All sysctl names at this level are terminal. */
+ if (namelen != 1)
+ return ENOTDIR; /* overloaded */
+
+ switch (name[0]) {
+ default:
+ return EOPNOTSUPP;
+ }
+ /* NOTREACHED */
+}
+
+void
+consinit(void)
+{
+}
+
+__dead void
+boot(int howto)
+{
+ for (;;)
+ continue;
+ /* NOTREACHED */
+}
diff --git a/sys/arch/powerpc64/powerpc64/pmap.c b/sys/arch/powerpc64/powerpc64/pmap.c
new file mode 100644
index 00000000000..565c8ae2694
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/pmap.c
@@ -0,0 +1,133 @@
+#include <sys/param.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/pmap.h>
+
+void
+pmap_virtual_space(vaddr_t *start, vaddr_t *end)
+{
+}
+
+pmap_t
+pmap_create(void)
+{
+ return NULL;
+}
+
+void
+pmap_reference(pmap_t pm)
+{
+}
+
+void
+pmap_destroy(pmap_t pm)
+{
+}
+
+void
+pmap_init(void)
+{
+}
+
+void
+pmap_copy(pmap_t dst_pmap, pmap_t src_pmap, vaddr_t dst_addr,
+ vsize_t len, vaddr_t src_addr)
+{
+}
+
+int
+pmap_enter(pmap_t pm, vaddr_t va, paddr_t pa, vm_prot_t prot, int flags)
+{
+ return ENOMEM;
+}
+
+void
+pmap_remove(pmap_t pm, vaddr_t sva, vaddr_t eva)
+{
+}
+
+void
+pmap_protect(pmap_t pm, vaddr_t sva, vaddr_t eva, vm_prot_t prot)
+{
+}
+
+void
+pmap_page_protect(struct vm_page *pg, vm_prot_t prot)
+{
+}
+
+void
+pmap_kenter_pa(vaddr_t va, paddr_t pa, vm_prot_t prot)
+{
+}
+
+void
+pmap_kremove(vaddr_t va, vsize_t len)
+{
+}
+
+int
+pmap_is_referenced(struct vm_page *pg)
+{
+ return 0;
+}
+
+int
+pmap_is_modified(struct vm_page *pg)
+{
+ return 0;
+}
+
+int
+pmap_clear_reference(struct vm_page *pg)
+{
+ return 0;
+}
+
+int
+pmap_clear_modify(struct vm_page *pg)
+{
+ return 0;
+}
+
+int
+pmap_extract(pmap_t pm, vaddr_t va, paddr_t *pa)
+{
+ return 0;
+}
+
+void
+pmap_activate(struct proc *p)
+{
+}
+
+void
+pmap_deactivate(struct proc *p)
+{
+}
+
+void
+pmap_unwire(pmap_t pm, vaddr_t va)
+{
+}
+
+void
+pmap_collect(pmap_t pm)
+{
+}
+
+void
+pmap_zero_page(struct vm_page *pg)
+{
+}
+
+void
+pmap_copy_page(struct vm_page *srcpg, struct vm_page *dstpg)
+{
+}
+
+void
+pmap_proc_iflush(struct process *pr, vaddr_t va, vsize_t len)
+{
+}
diff --git a/sys/arch/powerpc64/powerpc64/process_machdep.c b/sys/arch/powerpc64/powerpc64/process_machdep.c
new file mode 100644
index 00000000000..112d3b9ee55
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/process_machdep.c
@@ -0,0 +1,186 @@
+/* $OpenBSD: process_machdep.c,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+/* $NetBSD: process_machdep.c,v 1.1 1996/09/30 16:34:53 ws Exp $ */
+
+/*
+ * Copyright (C) 1995, 1996 Wolfgang Solfrank.
+ * Copyright (C) 1995, 1996 TooLs GmbH.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by TooLs GmbH.
+ * 4. The name of TooLs GmbH may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/ptrace.h>
+#include <sys/user.h>
+
+#include <machine/fpu.h>
+#include <machine/pcb.h>
+#include <machine/psl.h>
+#include <machine/reg.h>
+
+int
+process_read_regs(struct proc *p, struct reg *regs)
+{
+#if 0
+ struct cpu_info *ci = curcpu();
+ struct trapframe *tf = trapframe(p);
+ struct pcb *pcb = &p->p_addr->u_pcb;
+
+ bcopy(tf->fixreg, regs->gpr, sizeof(regs->gpr));
+
+ if (!(pcb->pcb_flags & PCB_FPU)) {
+ bzero(regs->fpr, sizeof(regs->fpr));
+ } else {
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc)
+ save_fpu();
+ bcopy(pcb->pcb_fpu.fpr, regs->fpr, sizeof(regs->fpr));
+ }
+
+ regs->pc = tf->srr0;
+ regs->ps = tf->srr1; /* is this the correct value for this ? */
+ regs->cnd = tf->cr;
+ regs->lr = tf->lr;
+ regs->cnt = tf->ctr;
+ regs->xer = tf->xer;
+ regs->mq = 0; /* what should this really be? */
+#endif
+
+ return 0;
+}
+
+int
+process_read_fpregs(struct proc *p, struct fpreg *regs)
+{
+#if 0
+ struct cpu_info *ci = curcpu();
+ struct pcb *pcb = &p->p_addr->u_pcb;
+
+ if (!(pcb->pcb_flags & PCB_FPU)) {
+ bzero(regs->fpr, sizeof(regs->fpr));
+ regs->fpscr = 0;
+ } else {
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc)
+ save_fpu();
+ bcopy(pcb->pcb_fpu.fpr, regs->fpr, sizeof(regs->fpr));
+ regs->fpscr = *(u_int64_t *)&pcb->pcb_fpu.fpcsr;
+ }
+#endif
+
+ return 0;
+}
+
+#ifdef PTRACE
+
+/*
+ * Set the process's program counter.
+ */
+int
+process_set_pc(struct proc *p, caddr_t addr)
+{
+ struct trapframe *tf = trapframe(p);
+
+ tf->srr0 = (u_int32_t)addr;
+ return 0;
+
+}
+
+int
+process_sstep(struct proc *p, int sstep)
+{
+#if 0
+ struct trapframe *tf = trapframe(p);
+
+ if (sstep)
+ tf->srr1 |= PSL_SE;
+ else
+ tf->srr1 &= ~PSL_SE;
+#endif
+ return 0;
+}
+
+int
+process_write_regs(struct proc *p, struct reg *regs)
+{
+#if 0
+ struct cpu_info *ci = curcpu();
+ struct trapframe *tf = trapframe(p);
+ struct pcb *pcb = &p->p_addr->u_pcb;
+
+ if ((regs->ps ^ tf->srr1) & PSL_USERSTATIC)
+ return EINVAL;
+
+ bcopy(regs->gpr, tf->fixreg, sizeof(regs->gpr));
+
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc) { /* release the fpu */
+ save_fpu();
+ ci->ci_fpuproc = NULL;
+ }
+
+ bcopy(regs->fpr, pcb->pcb_fpu.fpr, sizeof(regs->fpr));
+ if (!(pcb->pcb_flags & PCB_FPU)) {
+ pcb->pcb_fpu.fpcsr = 0;
+ pcb->pcb_flags |= PCB_FPU;
+ }
+
+ tf->srr0 = regs->pc;
+ tf->srr1 = regs->ps; /* is this the correct value for this ? */
+ tf->cr = regs->cnd;
+ tf->lr = regs->lr;
+ tf->ctr = regs->cnt;
+ tf->xer = regs->xer;
+ /* regs->mq = 0; what should this really be? */
+#endif
+
+ return 0;
+}
+
+int
+process_write_fpregs(struct proc *p, struct fpreg *regs)
+{
+#if 0
+ struct cpu_info *ci = curcpu();
+ struct pcb *pcb = &p->p_addr->u_pcb;
+ u_int64_t fpscr = regs->fpscr;
+
+ /* XXX What if the state is on the other cpu? */
+ if (p == ci->ci_fpuproc) { /* release the fpu */
+ save_fpu();
+ ci->ci_fpuproc = NULL;
+ }
+
+ bcopy(regs->fpr, pcb->pcb_fpu.fpr, sizeof(regs->fpr));
+ pcb->pcb_fpu.fpcsr = *(double *)&fpscr;
+ pcb->pcb_flags |= PCB_FPU;
+#endif
+
+ return 0;
+}
+
+#endif /* PTRACE */
diff --git a/sys/arch/powerpc64/powerpc64/softintr.c b/sys/arch/powerpc64/powerpc64/softintr.c
new file mode 100644
index 00000000000..767496f4015
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/softintr.c
@@ -0,0 +1,195 @@
+/* $OpenBSD: softintr.c,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+/* $NetBSD: softintr.c,v 1.1 2003/02/26 21:26:12 fvdl Exp $ */
+
+/*-
+ * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 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.
+ */
+
+/*
+ * Generic soft interrupt implementation
+ */
+
+#include <sys/param.h>
+#include <sys/malloc.h>
+
+#include <machine/intr.h>
+
+#include <uvm/uvm_extern.h>
+
+struct soft_intr soft_intrs[SI_NSOFTINTR];
+
+const int soft_intr_to_ssir[SI_NSOFTINTR] = {
+ SIR_SOFT,
+ SIR_CLOCK,
+ SIR_NET,
+ SIR_TTY,
+};
+
+void softintr_biglock_wrap(void *);
+
+/*
+ * softintr_init:
+ *
+ * Initialize the software interrupt system.
+ */
+void
+softintr_init(void)
+{
+ struct soft_intr *si;
+ int i;
+
+ for (i = 0; i < SI_NSOFTINTR; i++) {
+ si = &soft_intrs[i];
+ TAILQ_INIT(&si->softintr_q);
+ mtx_init(&si->softintr_lock, IPL_HIGH);
+ si->softintr_ssir = soft_intr_to_ssir[i];
+ }
+}
+
+/*
+ * softintr_dispatch:
+ *
+ * Process pending software interrupts.
+ */
+void
+softintr_dispatch(int which)
+{
+ struct soft_intr *si = &soft_intrs[which];
+ struct soft_intrhand *sih;
+ void *arg;
+ void (*fn)(void *);
+
+ for (;;) {
+ mtx_enter(&si->softintr_lock);
+ sih = TAILQ_FIRST(&si->softintr_q);
+ if (sih == NULL) {
+ mtx_leave(&si->softintr_lock);
+ break;
+ }
+ TAILQ_REMOVE(&si->softintr_q, sih, sih_q);
+ sih->sih_pending = 0;
+
+ uvmexp.softs++;
+ arg = sih->sih_arg;
+ fn = sih->sih_fn;
+ mtx_leave(&si->softintr_lock);
+
+ (*fn)(arg);
+ }
+}
+
+#ifdef MULTIPROCESSOR
+void
+softintr_biglock_wrap(void *arg)
+{
+ struct soft_intrhand *sih = arg;
+
+ KERNEL_LOCK();
+ sih->sih_fnwrap(sih->sih_argwrap);
+ KERNEL_UNLOCK();
+}
+#endif
+
+/*
+ * softintr_establish: [interface]
+ *
+ * Register a software interrupt handler.
+ */
+void *
+softintr_establish_flags(int ipl, void (*func)(void *), void *arg, int flags)
+{
+ struct soft_intr *si;
+ struct soft_intrhand *sih;
+ int which;
+
+ switch (ipl) {
+ case IPL_SOFTCLOCK:
+ which = SIR_CLOCK;
+ break;
+
+ case IPL_SOFTNET:
+ which = SIR_NET;
+ break;
+
+ case IPL_TTY:
+ case IPL_SOFTTTY:
+ which = SIR_TTY;
+ break;
+
+ default:
+ panic("softintr_establish");
+ }
+
+ si = &soft_intrs[which];
+
+ sih = malloc(sizeof(*sih), M_DEVBUF, M_NOWAIT | M_ZERO);
+ if (__predict_true(sih != NULL)) {
+ sih->sih_intrhead = si;
+#ifdef MULTIPROCESSOR
+ if (flags & SOFTINTR_ESTABLISH_MPSAFE) {
+#endif
+ sih->sih_fn = func;
+ sih->sih_arg = arg;
+#ifdef MULTIPROCESSOR
+ } else {
+ sih->sih_fnwrap = func;
+ sih->sih_argwrap = arg;
+ sih->sih_fn = softintr_biglock_wrap;
+ sih->sih_arg = sih;
+ }
+#endif
+ }
+ return (sih);
+}
+
+/*
+ * softintr_disestablish: [interface]
+ *
+ * Unregister a software interrupt handler.
+ */
+void
+softintr_disestablish(void *arg)
+{
+ struct soft_intrhand *sih = arg;
+ struct soft_intr *si = sih->sih_intrhead;
+
+ mtx_enter(&si->softintr_lock);
+ if (sih->sih_pending) {
+ TAILQ_REMOVE(&si->softintr_q, sih, sih_q);
+ sih->sih_pending = 0;
+ }
+ mtx_leave(&si->softintr_lock);
+
+ free(sih, M_DEVBUF, 0);
+}
+
+void
+softintr(int intrq)
+{
+ curcpu()->ci_ipending |= (1 << intrq);
+}
diff --git a/sys/arch/powerpc64/powerpc64/sys_machdep.c b/sys/arch/powerpc64/powerpc64/sys_machdep.c
new file mode 100644
index 00000000000..ea2820ccfd4
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/sys_machdep.c
@@ -0,0 +1,70 @@
+/* $OpenBSD: sys_machdep.c,v 1.1 2020/05/16 17:11:14 kettenis 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ * @(#)sys_machdep.c 8.1 (Berkeley) 6/10/93
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/time.h>
+#include <sys/proc.h>
+#include <sys/kernel.h>
+#include <sys/buf.h>
+
+#include <sys/mount.h>
+#include <sys/syscallargs.h>
+
+#include <uvm/uvm_extern.h>
+
+int
+sys_sysarch(struct proc *p, void *v, register_t *retval)
+{
+ struct sys_sysarch_args /* {
+ syscallarg(int) op;
+ syscallarg(void *) parms;
+ } */ *uap = v;
+ int error = 0;
+
+ switch(SCARG(uap, op)) {
+ default:
+ error = EINVAL;
+ break;
+ }
+
+ return (error);
+}
diff --git a/sys/arch/powerpc64/powerpc64/syscall.c b/sys/arch/powerpc64/powerpc64/syscall.c
new file mode 100644
index 00000000000..6e3cedc78c6
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/syscall.c
@@ -0,0 +1,13 @@
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/user.h>
+#include <sys/syscall.h>
+#include <sys/syscall_mi.h>
+
+void
+child_return(void *arg)
+{
+ struct proc *p = (struct proc *)arg;
+
+ mi_child_return(p);
+}
diff --git a/sys/arch/powerpc64/powerpc64/vm_machdep.c b/sys/arch/powerpc64/powerpc64/vm_machdep.c
new file mode 100644
index 00000000000..62ac3db8305
--- /dev/null
+++ b/sys/arch/powerpc64/powerpc64/vm_machdep.c
@@ -0,0 +1,188 @@
+/* $OpenBSD: vm_machdep.c,v 1.1 2020/05/16 17:11:14 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
+ * Copyright (c) 1982, 1986 The Regents of the University of California.
+ * Copyright (c) 1989, 1990 William Jolitz
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department, and William Jolitz.
+ *
+ * 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.
+ *
+ * @(#)vm_machdep.c 7.3 (Berkeley) 5/13/91
+ */
+
+/*
+ * Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+#include <sys/vnode.h>
+#include <sys/buf.h>
+#include <sys/user.h>
+#include <sys/exec.h>
+#include <sys/ptrace.h>
+#include <sys/signalvar.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/cpu.h>
+#include <machine/reg.h>
+
+/*
+ * Finish a fork operation, with process p2 nearly set up.
+ * Copy and update the kernel stack and pcb, making the child
+ * ready to run, and marking it so that it can return differently
+ * than the parent. Returns 1 in the child process, 0 in the parent.
+ */
+void
+cpu_fork(struct proc *p1, struct proc *p2, void *stack, void *tcb,
+ void (*func)(void *), void *arg)
+{
+#if 0
+ struct pcb *pcb = &p2->p_addr->u_pcb;
+ struct trapframe *tf;
+ struct switchframe *sf;
+
+ // Does any flushing need to be done if process was running?
+
+ /* Copy the pcb. */
+ *pcb = p1->p_addr->u_pcb;
+ pcb->pcb_fpcpu = NULL;
+
+ pmap_activate(p2);
+
+ tf = (struct trapframe *)((u_long)p2->p_addr
+ + USPACE
+ - sizeof(struct trapframe)
+ - 0x10);
+
+ tf = (struct trapframe *)STACKALIGN(tf);
+ pcb->pcb_tf = tf;
+ *tf = *p1->p_addr->u_pcb.pcb_tf;
+
+ if (stack != NULL)
+ tf->tf_sp = STACKALIGN(stack);
+ if (tcb != NULL)
+ pcb->pcb_tcb = tcb;
+
+ sf = (struct switchframe *)tf - 1;
+ sf->sf_x19 = (uint64_t)func;
+ sf->sf_x20 = (uint64_t)arg;
+ sf->sf_lr = (u_int64_t)&proc_trampoline;
+ pcb->pcb_sp = (uint64_t)sf;
+#endif
+}
+
+/*
+ * cpu_exit is called as the last action during exit.
+ *
+ * We clean up a little and then call sched_exit() with the old proc as an
+ * argument.
+ */
+void
+cpu_exit(struct proc *p)
+{
+#if 0
+ /* If we were using the FPU, forget about it. */
+ if (p->p_addr->u_pcb.pcb_fpcpu != NULL)
+ vfp_discard(p);
+#endif
+
+ pmap_deactivate(p);
+ sched_exit(p);
+}
+
+struct kmem_va_mode kv_physwait = {
+ .kv_map = &phys_map,
+ .kv_wait = 1,
+};
+
+/*
+ * Map a user I/O request into kernel virtual address space.
+ * Note: the pages are already locked by uvm_vslock(), so we
+ * do not need to pass an access_type to pmap_enter().
+ */
+void
+vmapbuf(struct buf *bp, vsize_t len)
+{
+ vaddr_t faddr, taddr, off;
+ paddr_t fpa;
+
+ if ((bp->b_flags & B_PHYS) == 0)
+ panic("vmapbuf");
+ faddr = trunc_page((vaddr_t)(bp->b_saveaddr = bp->b_data));
+ off = (vaddr_t)bp->b_data - faddr;
+ len = round_page(off + len);
+ taddr = (vaddr_t)km_alloc(len, &kv_physwait, &kp_none, &kd_waitok);
+ bp->b_data = (caddr_t)(taddr + off);
+ /*
+ * The region is locked, so we expect that pmap_pte() will return
+ * non-NULL.
+ * XXX: unwise to expect this in a multithreaded environment.
+ * anything can happen to a pmap between the time we lock a
+ * region, release the pmap lock, and then relock it for
+ * the pmap_extract().
+ *
+ * no need to flush TLB since we expect nothing to be mapped
+ * where we we just allocated (TLB will be flushed when our
+ * mapping is removed).
+ */
+ while (len) {
+ (void) pmap_extract(vm_map_pmap(&bp->b_proc->p_vmspace->vm_map),
+ faddr, &fpa);
+ pmap_kenter_pa(taddr, fpa, PROT_READ | PROT_WRITE);
+ faddr += PAGE_SIZE;
+ taddr += PAGE_SIZE;
+ len -= PAGE_SIZE;
+ }
+ pmap_update(pmap_kernel());
+}
+
+/*
+ * Unmap a previously-mapped user I/O request.
+ */
+void
+vunmapbuf(struct buf *bp, vsize_t len)
+{
+ vaddr_t addr, off;
+
+ if ((bp->b_flags & B_PHYS) == 0)
+ panic("vunmapbuf");
+ addr = trunc_page((vaddr_t)bp->b_data);
+ off = (vaddr_t)bp->b_data - addr;
+ len = round_page(off + len);
+ pmap_kremove(addr, len);
+ pmap_update(pmap_kernel());
+ km_free((void *)addr, len, &kv_physwait, &kp_none);
+ bp->b_data = bp->b_saveaddr;
+ bp->b_saveaddr = 0;
+}